96dc79cfe6
- Convert all require()/module.exports to import/export across 260+ files - Add "type": "module" to package.json to enable ESM by default - Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible - Convert eslint.config.js to ESM with sourceType: "module" - Replace __dirname/__filename with import.meta.dirname/import.meta.filename - Replace require.main === module with process.argv[1] === import.meta.filename - Remove 'use strict' directives (implicit in ESM) - Convert dynamic require() in switch statements to static import lookup maps (dns.js, domains.js, backupformats.js, backupsites.js, network.js) - Extract self-referencing exports.CONSTANT patterns into standalone const declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.) - Lazify SERVICES object in services.js to avoid circular dependency TDZ issues - Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests - Add _setMockApp() to ldapserver.js for ESM-safe test mocking - Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests - Convert backupupload.js to use dynamic imports so --check exits before loading the module graph (which requires BOX_ENV) - Update check-install to use ESM import for infra_version.js - Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations) - All 1315 tests passing Migration stats (AI-assisted using Cursor with Claude): - Wall clock time: ~3-4 hours - Assistant completions: ~80-100 - Estimated token usage: ~1-2M tokens Co-authored-by: Cursor <cursoragent@cursor.com>
56 lines
2.0 KiB
JavaScript
56 lines
2.0 KiB
JavaScript
import assert from 'node:assert';
|
|
import path from 'node:path';
|
|
|
|
class DataLayout {
|
|
constructor(localRoot, dirMap) {
|
|
assert.strictEqual(typeof localRoot, 'string');
|
|
assert(path.isAbsolute(localRoot));
|
|
assert(Array.isArray(dirMap), 'Expecting layout to be an array');
|
|
|
|
this._localRoot = localRoot;
|
|
this._dirMap = dirMap;
|
|
this._remoteRegexps = dirMap.map((l) => new RegExp('^\\./' + l.remoteDir + '/?'));
|
|
this._localRegexps = dirMap.map((l) => new RegExp('^' + l.localDir + '/?'));
|
|
}
|
|
// returns absolute path
|
|
toLocalPath(remoteName) {
|
|
assert.strictEqual(typeof remoteName, 'string');
|
|
|
|
for (let i = 0; i < this._remoteRegexps.length; i++) {
|
|
if (!remoteName.match(this._remoteRegexps[i])) continue;
|
|
return remoteName.replace(this._remoteRegexps[i], this._dirMap[i].localDir + '/'); // make paths absolute
|
|
}
|
|
return remoteName.replace(new RegExp('^\\.'), this._localRoot);
|
|
}
|
|
toRemotePath(localName) {
|
|
assert.strictEqual(typeof localName, 'string');
|
|
|
|
for (let i = 0; i < this._localRegexps.length; i++) {
|
|
if (!localName.match(this._localRegexps[i])) continue;
|
|
return localName.replace(this._localRegexps[i], './' + this._dirMap[i].remoteDir + '/'); // make paths relative
|
|
}
|
|
return localName.replace(new RegExp('^' + this._localRoot + '/?'), './');
|
|
}
|
|
localRoot() {
|
|
return this._localRoot;
|
|
}
|
|
getBasename() { // used to generate cache file names
|
|
return path.basename(this._localRoot);
|
|
}
|
|
toString() {
|
|
return JSON.stringify({ localRoot: this._localRoot, layout: this._dirMap });
|
|
}
|
|
localPaths() {
|
|
return [ this._localRoot ].concat(this._dirMap.map((l) => l.localDir));
|
|
}
|
|
directoryMap() {
|
|
return this._dirMap;
|
|
}
|
|
static fromString(str) {
|
|
const obj = JSON.parse(str);
|
|
return new DataLayout(obj.localRoot, obj.layout);
|
|
}
|
|
}
|
|
|
|
export default DataLayout;
|