mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-06 07:05:48 +02:00
Stop pre-building the preference defaults, to simplify the build scripts
This is a left-over from before the introduction of `AppOptions`, but is no longer necessary now.
This commit is contained in:
parent
35e78f7f11
commit
06cf7dd7b0
103
gulpfile.mjs
103
gulpfile.mjs
@ -284,7 +284,6 @@ function createWebpackConfig(
|
|||||||
disableVersionInfo = false,
|
disableVersionInfo = false,
|
||||||
disableSourceMaps = false,
|
disableSourceMaps = false,
|
||||||
disableLicenseHeader = false,
|
disableLicenseHeader = false,
|
||||||
defaultPreferencesDir = null,
|
|
||||||
} = {}
|
} = {}
|
||||||
) {
|
) {
|
||||||
const versionInfo = !disableVersionInfo
|
const versionInfo = !disableVersionInfo
|
||||||
@ -295,9 +294,6 @@ function createWebpackConfig(
|
|||||||
BUNDLE_VERSION: versionInfo.version,
|
BUNDLE_VERSION: versionInfo.version,
|
||||||
BUNDLE_BUILD: versionInfo.commit,
|
BUNDLE_BUILD: versionInfo.commit,
|
||||||
TESTING: defines.TESTING ?? process.env.TESTING === "true",
|
TESTING: defines.TESTING ?? process.env.TESTING === "true",
|
||||||
DEFAULT_PREFERENCES: defaultPreferencesDir
|
|
||||||
? getDefaultPreferences(defaultPreferencesDir)
|
|
||||||
: {},
|
|
||||||
DEFAULT_FTL: defines.GENERIC ? getDefaultFtl() : "",
|
DEFAULT_FTL: defines.GENERIC ? getDefaultFtl() : "",
|
||||||
};
|
};
|
||||||
const licenseHeaderLibre = fs
|
const licenseHeaderLibre = fs
|
||||||
@ -546,36 +542,24 @@ function createWorkerBundle(defines) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createWebBundle(defines, options) {
|
function createWebBundle(defines, options) {
|
||||||
const viewerFileConfig = createWebpackConfig(
|
const viewerFileConfig = createWebpackConfig(defines, {
|
||||||
defines,
|
filename: "viewer.mjs",
|
||||||
{
|
library: {
|
||||||
filename: "viewer.mjs",
|
type: "module",
|
||||||
library: {
|
|
||||||
type: "module",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
});
|
||||||
defaultPreferencesDir: options.defaultPreferencesDir,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return gulp
|
return gulp
|
||||||
.src("./web/viewer.js", { encoding: false })
|
.src("./web/viewer.js", { encoding: false })
|
||||||
.pipe(webpack2Stream(viewerFileConfig));
|
.pipe(webpack2Stream(viewerFileConfig));
|
||||||
}
|
}
|
||||||
|
|
||||||
function createGVWebBundle(defines, options) {
|
function createGVWebBundle(defines, options) {
|
||||||
const viewerFileConfig = createWebpackConfig(
|
const viewerFileConfig = createWebpackConfig(defines, {
|
||||||
defines,
|
filename: "viewer-geckoview.mjs",
|
||||||
{
|
library: {
|
||||||
filename: "viewer-geckoview.mjs",
|
type: "module",
|
||||||
library: {
|
|
||||||
type: "module",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
});
|
||||||
defaultPreferencesDir: options.defaultPreferencesDir,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return gulp
|
return gulp
|
||||||
.src("./web/viewer-geckoview.js", { encoding: false })
|
.src("./web/viewer-geckoview.js", { encoding: false })
|
||||||
.pipe(webpack2Stream(viewerFileConfig));
|
.pipe(webpack2Stream(viewerFileConfig));
|
||||||
@ -1063,11 +1047,7 @@ function buildGeneric(defines, dir) {
|
|||||||
createMainBundle(defines).pipe(gulp.dest(dir + "build")),
|
createMainBundle(defines).pipe(gulp.dest(dir + "build")),
|
||||||
createWorkerBundle(defines).pipe(gulp.dest(dir + "build")),
|
createWorkerBundle(defines).pipe(gulp.dest(dir + "build")),
|
||||||
createSandboxBundle(defines).pipe(gulp.dest(dir + "build")),
|
createSandboxBundle(defines).pipe(gulp.dest(dir + "build")),
|
||||||
createWebBundle(defines, {
|
createWebBundle(defines).pipe(gulp.dest(dir + "web")),
|
||||||
defaultPreferencesDir: defines.SKIP_BABEL
|
|
||||||
? "generic/"
|
|
||||||
: "generic-legacy/",
|
|
||||||
}).pipe(gulp.dest(dir + "web")),
|
|
||||||
gulp
|
gulp
|
||||||
.src(COMMON_WEB_FILES, { base: "web/", encoding: false })
|
.src(COMMON_WEB_FILES, { base: "web/", encoding: false })
|
||||||
.pipe(gulp.dest(dir + "web")),
|
.pipe(gulp.dest(dir + "web")),
|
||||||
@ -1111,13 +1091,7 @@ gulp.task(
|
|||||||
"locale",
|
"locale",
|
||||||
function scriptingGeneric() {
|
function scriptingGeneric() {
|
||||||
const defines = { ...DEFINES, GENERIC: true };
|
const defines = { ...DEFINES, GENERIC: true };
|
||||||
return ordered([
|
return createTemporaryScriptingBundle(defines);
|
||||||
buildDefaultPreferences(defines, "generic/"),
|
|
||||||
createTemporaryScriptingBundle(defines),
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
async function prefsGeneric() {
|
|
||||||
await parseDefaultPreferences("generic/");
|
|
||||||
},
|
},
|
||||||
function createGeneric() {
|
function createGeneric() {
|
||||||
console.log();
|
console.log();
|
||||||
@ -1138,13 +1112,7 @@ gulp.task(
|
|||||||
"locale",
|
"locale",
|
||||||
function scriptingGenericLegacy() {
|
function scriptingGenericLegacy() {
|
||||||
const defines = { ...DEFINES, GENERIC: true, SKIP_BABEL: false };
|
const defines = { ...DEFINES, GENERIC: true, SKIP_BABEL: false };
|
||||||
return ordered([
|
return createTemporaryScriptingBundle(defines);
|
||||||
buildDefaultPreferences(defines, "generic-legacy/"),
|
|
||||||
createTemporaryScriptingBundle(defines),
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
async function prefsGenericLegacy() {
|
|
||||||
await parseDefaultPreferences("generic-legacy/");
|
|
||||||
},
|
},
|
||||||
function createGenericLegacy() {
|
function createGenericLegacy() {
|
||||||
console.log();
|
console.log();
|
||||||
@ -1258,13 +1226,7 @@ gulp.task(
|
|||||||
"locale",
|
"locale",
|
||||||
function scriptingMinified() {
|
function scriptingMinified() {
|
||||||
const defines = { ...DEFINES, MINIFIED: true, GENERIC: true };
|
const defines = { ...DEFINES, MINIFIED: true, GENERIC: true };
|
||||||
return ordered([
|
return createTemporaryScriptingBundle(defines);
|
||||||
buildDefaultPreferences(defines, "minified/"),
|
|
||||||
createTemporaryScriptingBundle(defines),
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
async function prefsMinified() {
|
|
||||||
await parseDefaultPreferences("minified/");
|
|
||||||
},
|
},
|
||||||
function createMinified() {
|
function createMinified() {
|
||||||
console.log();
|
console.log();
|
||||||
@ -1288,13 +1250,7 @@ gulp.task(
|
|||||||
GENERIC: true,
|
GENERIC: true,
|
||||||
SKIP_BABEL: false,
|
SKIP_BABEL: false,
|
||||||
};
|
};
|
||||||
return ordered([
|
return createTemporaryScriptingBundle(defines);
|
||||||
buildDefaultPreferences(defines, "minified-legacy/"),
|
|
||||||
createTemporaryScriptingBundle(defines),
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
async function prefsMinifiedLegacy() {
|
|
||||||
await parseDefaultPreferences("minified-legacy/");
|
|
||||||
},
|
},
|
||||||
function createMinifiedLegacy() {
|
function createMinifiedLegacy() {
|
||||||
console.log();
|
console.log();
|
||||||
@ -1389,12 +1345,12 @@ gulp.task(
|
|||||||
createWorkerBundle(defines).pipe(
|
createWorkerBundle(defines).pipe(
|
||||||
gulp.dest(MOZCENTRAL_CONTENT_DIR + "build")
|
gulp.dest(MOZCENTRAL_CONTENT_DIR + "build")
|
||||||
),
|
),
|
||||||
createWebBundle(defines, { defaultPreferencesDir: "mozcentral/" }).pipe(
|
createWebBundle(defines).pipe(
|
||||||
|
gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")
|
||||||
|
),
|
||||||
|
createGVWebBundle(gvDefines).pipe(
|
||||||
gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")
|
gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")
|
||||||
),
|
),
|
||||||
createGVWebBundle(gvDefines, {
|
|
||||||
defaultPreferencesDir: "mozcentral/",
|
|
||||||
}).pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")),
|
|
||||||
gulp
|
gulp
|
||||||
.src(MOZCENTRAL_WEB_FILES, { base: "web/", encoding: false })
|
.src(MOZCENTRAL_WEB_FILES, { base: "web/", encoding: false })
|
||||||
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")),
|
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")),
|
||||||
@ -1499,7 +1455,7 @@ gulp.task(
|
|||||||
createSandboxBundle(defines).pipe(
|
createSandboxBundle(defines).pipe(
|
||||||
gulp.dest(CHROME_BUILD_CONTENT_DIR + "build")
|
gulp.dest(CHROME_BUILD_CONTENT_DIR + "build")
|
||||||
),
|
),
|
||||||
createWebBundle(defines, { defaultPreferencesDir: "chromium/" }).pipe(
|
createWebBundle(defines).pipe(
|
||||||
gulp.dest(CHROME_BUILD_CONTENT_DIR + "web")
|
gulp.dest(CHROME_BUILD_CONTENT_DIR + "web")
|
||||||
),
|
),
|
||||||
gulp
|
gulp
|
||||||
@ -1634,9 +1590,6 @@ function buildLib(defines, dir) {
|
|||||||
BUNDLE_VERSION: versionInfo.version,
|
BUNDLE_VERSION: versionInfo.version,
|
||||||
BUNDLE_BUILD: versionInfo.commit,
|
BUNDLE_BUILD: versionInfo.commit,
|
||||||
TESTING: defines.TESTING ?? process.env.TESTING === "true",
|
TESTING: defines.TESTING ?? process.env.TESTING === "true",
|
||||||
DEFAULT_PREFERENCES: getDefaultPreferences(
|
|
||||||
defines.SKIP_BABEL ? "lib/" : "lib-legacy/"
|
|
||||||
),
|
|
||||||
DEFAULT_FTL: getDefaultFtl(),
|
DEFAULT_FTL: getDefaultFtl(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1667,13 +1620,7 @@ gulp.task(
|
|||||||
createBuildNumber,
|
createBuildNumber,
|
||||||
function scriptingLib() {
|
function scriptingLib() {
|
||||||
const defines = { ...DEFINES, GENERIC: true, LIB: true };
|
const defines = { ...DEFINES, GENERIC: true, LIB: true };
|
||||||
return ordered([
|
return createTemporaryScriptingBundle(defines);
|
||||||
buildDefaultPreferences(defines, "lib/"),
|
|
||||||
createTemporaryScriptingBundle(defines),
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
async function prefsLib() {
|
|
||||||
await parseDefaultPreferences("lib/");
|
|
||||||
},
|
},
|
||||||
function createLib() {
|
function createLib() {
|
||||||
const defines = { ...DEFINES, GENERIC: true, LIB: true };
|
const defines = { ...DEFINES, GENERIC: true, LIB: true };
|
||||||
@ -1697,13 +1644,7 @@ gulp.task(
|
|||||||
LIB: true,
|
LIB: true,
|
||||||
SKIP_BABEL: false,
|
SKIP_BABEL: false,
|
||||||
};
|
};
|
||||||
return ordered([
|
return createTemporaryScriptingBundle(defines);
|
||||||
buildDefaultPreferences(defines, "lib-legacy/"),
|
|
||||||
createTemporaryScriptingBundle(defines),
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
async function prefsLibLegacy() {
|
|
||||||
await parseDefaultPreferences("lib-legacy/");
|
|
||||||
},
|
},
|
||||||
function createLibLegacy() {
|
function createLibLegacy() {
|
||||||
const defines = {
|
const defines = {
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { AppOptions, OptionKind } from "../../web/app_options.js";
|
import { AppOptions, OptionKind } from "../../web/app_options.js";
|
||||||
|
import { BasePreferences } from "../../web/preferences.js";
|
||||||
import { objectSize } from "../../src/shared/util.js";
|
import { objectSize } from "../../src/shared/util.js";
|
||||||
|
|
||||||
describe("AppOptions", function () {
|
describe("AppOptions", function () {
|
||||||
@ -39,3 +40,20 @@ describe("AppOptions", function () {
|
|||||||
expect(objectSize(options)).toBeLessThanOrEqual(MAX_NUMBER_OF_PREFS);
|
expect(objectSize(options)).toBeLessThanOrEqual(MAX_NUMBER_OF_PREFS);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("BasePreferences", function () {
|
||||||
|
it("checks that preference defaults are correct", async function () {
|
||||||
|
const TestPreferences = class extends BasePreferences {
|
||||||
|
async _readFromStorage(prefObj) {
|
||||||
|
return { prefs: Object.create(null) };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const testPrefs = new TestPreferences();
|
||||||
|
await testPrefs.initializedPromise;
|
||||||
|
|
||||||
|
expect(testPrefs.defaults).toEqual(
|
||||||
|
AppOptions.getAll(OptionKind.PREFERENCE, /* defaultOnly = */ true)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -22,9 +22,7 @@ import { AppOptions, OptionKind } from "./app_options.js";
|
|||||||
*/
|
*/
|
||||||
class BasePreferences {
|
class BasePreferences {
|
||||||
#defaults = Object.freeze(
|
#defaults = Object.freeze(
|
||||||
typeof PDFJSDev === "undefined"
|
AppOptions.getAll(OptionKind.PREFERENCE, /* defaultOnly = */ true)
|
||||||
? AppOptions.getAll(OptionKind.PREFERENCE, /* defaultOnly = */ true)
|
|
||||||
: PDFJSDev.eval("DEFAULT_PREFERENCES")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
#initializedPromise = null;
|
#initializedPromise = null;
|
||||||
@ -37,14 +35,6 @@ class BasePreferences {
|
|||||||
throw new Error("Cannot initialize BasePreferences.");
|
throw new Error("Cannot initialize BasePreferences.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) {
|
|
||||||
Object.defineProperty(this, "defaults", {
|
|
||||||
get() {
|
|
||||||
return this.#defaults;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.#initializedPromise = this._readFromStorage(this.#defaults).then(
|
this.#initializedPromise = this._readFromStorage(this.#defaults).then(
|
||||||
({ browserPrefs, prefs }) => {
|
({ browserPrefs, prefs }) => {
|
||||||
if (
|
if (
|
||||||
@ -135,6 +125,10 @@ class BasePreferences {
|
|||||||
return AppOptions.get(name);
|
return AppOptions.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get defaults() {
|
||||||
|
return this.#defaults;
|
||||||
|
}
|
||||||
|
|
||||||
get initializedPromise() {
|
get initializedPromise() {
|
||||||
return this.#initializedPromise;
|
return this.#initializedPromise;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user