Merge pull request #16671 from Snuffleupagus/esm-parseDefaultPreferences

[ESM] Convert the "default preferences"-handling to use `import()` syntax
This commit is contained in:
Tim van der Meij 2023-07-09 15:38:30 +02:00 committed by GitHub
commit 35202ec0f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -770,32 +770,52 @@ function buildDefaultPreferences(defines, dir) {
const bundleDefines = builder.merge(defines, { const bundleDefines = builder.merge(defines, {
LIB: true, LIB: true,
SKIP_BABEL: false,
BUNDLE_VERSION: 0, // Dummy version
BUNDLE_BUILD: 0, // Dummy build
TESTING: defines.TESTING ?? process.env.TESTING === "true", TESTING: defines.TESTING ?? process.env.TESTING === "true",
}); });
const inputStream = merge([ const defaultPreferencesConfig = createWebpackConfig(
gulp.src(["web/app_options.js"], {
base: ".",
}),
]);
return buildLibHelper(
bundleDefines, bundleDefines,
inputStream, {
DEFAULT_PREFERENCES_DIR + dir filename: "app_options.mjs",
library: {
type: "module",
},
},
{
disableVersionInfo: true,
}
);
return gulp
.src("web/app_options.js")
.pipe(webpack2Stream(defaultPreferencesConfig))
.pipe(gulp.dest(DEFAULT_PREFERENCES_DIR + dir));
}
async function parseDefaultPreferences(dir) {
console.log();
console.log("### Parsing default preferences");
// eslint-disable-next-line no-unsanitized/method
const { AppOptions, OptionKind } = await import(
"./" + DEFAULT_PREFERENCES_DIR + dir + "app_options.mjs"
);
const prefs = AppOptions.getAll(OptionKind.PREFERENCE);
if (Object.keys(prefs).length === 0) {
throw new Error("No default preferences found.");
}
fs.writeFileSync(
DEFAULT_PREFERENCES_DIR + dir + "default_preferences.json",
JSON.stringify(prefs)
); );
} }
function getDefaultPreferences(dir) { function getDefaultPreferences(dir) {
const { AppOptions, OptionKind } = require("./" + const str = fs
DEFAULT_PREFERENCES_DIR + .readFileSync(DEFAULT_PREFERENCES_DIR + dir + "default_preferences.json")
dir + .toString();
"web/app_options.js"); return JSON.parse(str);
return AppOptions.getAll(OptionKind.PREFERENCE);
} }
gulp.task("locale", function () { gulp.task("locale", function () {
@ -948,6 +968,9 @@ gulp.task(
createTemporaryScriptingBundle(defines), createTemporaryScriptingBundle(defines),
]); ]);
}, },
async function prefsGeneric() {
await parseDefaultPreferences("generic/");
},
function createGeneric() { function createGeneric() {
console.log(); console.log();
console.log("### Creating generic viewer"); console.log("### Creating generic viewer");
@ -975,6 +998,9 @@ gulp.task(
createTemporaryScriptingBundle(defines), createTemporaryScriptingBundle(defines),
]); ]);
}, },
async function prefsGenericLegacy() {
await parseDefaultPreferences("generic-legacy/");
},
function createGenericLegacy() { function createGenericLegacy() {
console.log(); console.log();
console.log("### Creating generic (legacy) viewer"); console.log("### Creating generic (legacy) viewer");
@ -1186,6 +1212,9 @@ gulp.task(
createTemporaryScriptingBundle(defines), createTemporaryScriptingBundle(defines),
]); ]);
}, },
async function prefsMinified() {
await parseDefaultPreferences("minified/");
},
function createMinified() { function createMinified() {
console.log(); console.log();
console.log("### Creating minified viewer"); console.log("### Creating minified viewer");
@ -1216,6 +1245,9 @@ gulp.task(
createTemporaryScriptingBundle(defines), createTemporaryScriptingBundle(defines),
]); ]);
}, },
async function prefsMinifiedLegacy() {
await parseDefaultPreferences("minified-legacy/");
},
function createMinifiedLegacy() { function createMinifiedLegacy() {
console.log(); console.log();
console.log("### Creating minified (legacy) viewer"); console.log("### Creating minified (legacy) viewer");
@ -1268,6 +1300,9 @@ gulp.task(
const defines = builder.merge(DEFINES, { MOZCENTRAL: true }); const defines = builder.merge(DEFINES, { MOZCENTRAL: true });
return buildDefaultPreferences(defines, "mozcentral/"); return buildDefaultPreferences(defines, "mozcentral/");
}, },
async function prefsMozcentral() {
await parseDefaultPreferences("mozcentral/");
},
function createMozcentral() { function createMozcentral() {
console.log(); console.log();
console.log("### Building mozilla-central extension"); console.log("### Building mozilla-central extension");
@ -1365,6 +1400,9 @@ gulp.task(
createTemporaryScriptingBundle(defines), createTemporaryScriptingBundle(defines),
]); ]);
}, },
async function prefsChromium() {
await parseDefaultPreferences("chromium/");
},
function createChromium() { function createChromium() {
console.log(); console.log();
console.log("### Building Chromium extension"); console.log("### Building Chromium extension");
@ -1589,6 +1627,9 @@ gulp.task(
createTemporaryScriptingBundle(defines), createTemporaryScriptingBundle(defines),
]); ]);
}, },
async function prefsLib() {
await parseDefaultPreferences("lib/");
},
function createLib() { function createLib() {
const defines = builder.merge(DEFINES, { GENERIC: true, LIB: true }); const defines = builder.merge(DEFINES, { GENERIC: true, LIB: true });
@ -1615,6 +1656,9 @@ gulp.task(
createTemporaryScriptingBundle(defines), createTemporaryScriptingBundle(defines),
]); ]);
}, },
async function prefsLibLegacy() {
await parseDefaultPreferences("lib-legacy/");
},
function createLibLegacy() { function createLibLegacy() {
const defines = builder.merge(DEFINES, { const defines = builder.merge(DEFINES, {
GENERIC: true, GENERIC: true,
@ -1927,6 +1971,9 @@ gulp.task(
}); });
return buildDefaultPreferences(defines, "lint-chromium/"); return buildDefaultPreferences(defines, "lint-chromium/");
}, },
async function prefsLintChromium() {
await parseDefaultPreferences("lint-chromium/");
},
function runLintChromium(done) { function runLintChromium(done) {
console.log(); console.log();
console.log("### Checking supplemental Chromium files"); console.log("### Checking supplemental Chromium files");