Skip to content

Commit

Permalink
Merge pull request mozilla#16671 from Snuffleupagus/esm-parseDefaultP…
Browse files Browse the repository at this point in the history
…references

[ESM] Convert the "default preferences"-handling to use `import()` syntax
  • Loading branch information
timvandermeij authored Jul 9, 2023
2 parents 1972b73 + 6c601d3 commit 35202ec
Showing 1 changed file with 65 additions and 18 deletions.
83 changes: 65 additions & 18 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,32 +770,52 @@ function buildDefaultPreferences(defines, dir) {

const bundleDefines = builder.merge(defines, {
LIB: true,
SKIP_BABEL: false,
BUNDLE_VERSION: 0, // Dummy version
BUNDLE_BUILD: 0, // Dummy build
TESTING: defines.TESTING ?? process.env.TESTING === "true",
});

const inputStream = merge([
gulp.src(["web/app_options.js"], {
base: ".",
}),
]);

return buildLibHelper(
const defaultPreferencesConfig = createWebpackConfig(
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));
}

function getDefaultPreferences(dir) {
const { AppOptions, OptionKind } = require("./" +
DEFAULT_PREFERENCES_DIR +
dir +
"web/app_options.js");
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.");
}

return AppOptions.getAll(OptionKind.PREFERENCE);
fs.writeFileSync(
DEFAULT_PREFERENCES_DIR + dir + "default_preferences.json",
JSON.stringify(prefs)
);
}

function getDefaultPreferences(dir) {
const str = fs
.readFileSync(DEFAULT_PREFERENCES_DIR + dir + "default_preferences.json")
.toString();
return JSON.parse(str);
}

gulp.task("locale", function () {
Expand Down Expand Up @@ -948,6 +968,9 @@ gulp.task(
createTemporaryScriptingBundle(defines),
]);
},
async function prefsGeneric() {
await parseDefaultPreferences("generic/");
},
function createGeneric() {
console.log();
console.log("### Creating generic viewer");
Expand Down Expand Up @@ -975,6 +998,9 @@ gulp.task(
createTemporaryScriptingBundle(defines),
]);
},
async function prefsGenericLegacy() {
await parseDefaultPreferences("generic-legacy/");
},
function createGenericLegacy() {
console.log();
console.log("### Creating generic (legacy) viewer");
Expand Down Expand Up @@ -1186,6 +1212,9 @@ gulp.task(
createTemporaryScriptingBundle(defines),
]);
},
async function prefsMinified() {
await parseDefaultPreferences("minified/");
},
function createMinified() {
console.log();
console.log("### Creating minified viewer");
Expand Down Expand Up @@ -1216,6 +1245,9 @@ gulp.task(
createTemporaryScriptingBundle(defines),
]);
},
async function prefsMinifiedLegacy() {
await parseDefaultPreferences("minified-legacy/");
},
function createMinifiedLegacy() {
console.log();
console.log("### Creating minified (legacy) viewer");
Expand Down Expand Up @@ -1268,6 +1300,9 @@ gulp.task(
const defines = builder.merge(DEFINES, { MOZCENTRAL: true });
return buildDefaultPreferences(defines, "mozcentral/");
},
async function prefsMozcentral() {
await parseDefaultPreferences("mozcentral/");
},
function createMozcentral() {
console.log();
console.log("### Building mozilla-central extension");
Expand Down Expand Up @@ -1365,6 +1400,9 @@ gulp.task(
createTemporaryScriptingBundle(defines),
]);
},
async function prefsChromium() {
await parseDefaultPreferences("chromium/");
},
function createChromium() {
console.log();
console.log("### Building Chromium extension");
Expand Down Expand Up @@ -1589,6 +1627,9 @@ gulp.task(
createTemporaryScriptingBundle(defines),
]);
},
async function prefsLib() {
await parseDefaultPreferences("lib/");
},
function createLib() {
const defines = builder.merge(DEFINES, { GENERIC: true, LIB: true });

Expand All @@ -1615,6 +1656,9 @@ gulp.task(
createTemporaryScriptingBundle(defines),
]);
},
async function prefsLibLegacy() {
await parseDefaultPreferences("lib-legacy/");
},
function createLibLegacy() {
const defines = builder.merge(DEFINES, {
GENERIC: true,
Expand Down Expand Up @@ -1927,6 +1971,9 @@ gulp.task(
});
return buildDefaultPreferences(defines, "lint-chromium/");
},
async function prefsLintChromium() {
await parseDefaultPreferences("lint-chromium/");
},
function runLintChromium(done) {
console.log();
console.log("### Checking supplemental Chromium files");
Expand Down

0 comments on commit 35202ec

Please sign in to comment.