Enable the ESLint no-var rule in gulpfile.js

Given that `let`/`const` is already used here and there in this file, converting the rest of the `var` occurrences shouldn't be a problem.

Note that the majority of these changes were done automatically, by using the `gulp lint --fix` command, and the manual changes were limited to the following diff:

```diff
diff --git a/gulpfile.js b/gulpfile.js
index e2360c8ec..905420c33 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -676,8 +676,8 @@ gulp.task("default_preferences-pre", function () {
       ],
     }).code;
   }
-  var babel = require("@babel/core");
-  var ctx = {
+  const babel = require("@babel/core");
+  const ctx = {
     rootPath: __dirname,
     saveComments: false,
     defines: builder.merge(DEFINES, {
@@ -690,7 +690,7 @@ gulp.task("default_preferences-pre", function () {
       "pdfjs-lib": "../pdf",
     },
   };
-  var preprocessor2 = require("./external/builder/preprocessor2.js");
+  const preprocessor2 = require("./external/builder/preprocessor2.js");
   return merge([
     gulp.src(["web/{app_options,viewer_compatibility}.js"], {
       base: ".",
@@ -1418,14 +1418,14 @@ function buildLib(defines, dir) {
     });
     return licenseHeaderLibre + content;
   }
-  var babel = require("@babel/core");
+  const babel = require("@babel/core");
   const versionInfo = getVersionJSON();
-  var bundleDefines = builder.merge(defines, {
+  const bundleDefines = builder.merge(defines, {
     BUNDLE_VERSION: versionInfo.version,
     BUNDLE_BUILD: versionInfo.commit,
     TESTING: process.env.TESTING === "true",
   });
-  var ctx = {
+  const ctx = {
     rootPath: __dirname,
     saveComments: false,
     defines: bundleDefines,
@@ -1433,10 +1433,10 @@ function buildLib(defines, dir) {
       "pdfjs-lib": "../pdf",
     },
   };
-  var licenseHeaderLibre = fs
+  const licenseHeaderLibre = fs
     .readFileSync("./src/license_header_libre.js")
     .toString();
-  var preprocessor2 = require("./external/builder/preprocessor2.js");
+  const preprocessor2 = require("./external/builder/preprocessor2.js");
   return merge([
     gulp.src(
       [
```
This commit is contained in:
Jonas Jenwald 2021-03-13 11:42:40 +01:00
parent 61318c42aa
commit f58fee0956

View File

@ -13,70 +13,71 @@
* limitations under the License. * limitations under the License.
*/ */
/* eslint-env node */ /* eslint-env node */
/* eslint no-var: error */
/* globals target */ /* globals target */
"use strict"; "use strict";
var autoprefixer = require("autoprefixer"); const autoprefixer = require("autoprefixer");
var calc = require("postcss-calc"); const calc = require("postcss-calc");
var fs = require("fs"); const fs = require("fs");
var gulp = require("gulp"); const gulp = require("gulp");
var postcss = require("gulp-postcss"); const postcss = require("gulp-postcss");
var rename = require("gulp-rename"); const rename = require("gulp-rename");
var replace = require("gulp-replace"); const replace = require("gulp-replace");
var mkdirp = require("mkdirp"); const mkdirp = require("mkdirp");
var path = require("path"); const path = require("path");
var rimraf = require("rimraf"); const rimraf = require("rimraf");
var stream = require("stream"); const stream = require("stream");
var exec = require("child_process").exec; const exec = require("child_process").exec;
var spawn = require("child_process").spawn; const spawn = require("child_process").spawn;
var spawnSync = require("child_process").spawnSync; const spawnSync = require("child_process").spawnSync;
var streamqueue = require("streamqueue"); const streamqueue = require("streamqueue");
var merge = require("merge-stream"); const merge = require("merge-stream");
var zip = require("gulp-zip"); const zip = require("gulp-zip");
var webpack2 = require("webpack"); const webpack2 = require("webpack");
var webpackStream = require("webpack-stream"); const webpackStream = require("webpack-stream");
var Vinyl = require("vinyl"); const Vinyl = require("vinyl");
var vfs = require("vinyl-fs"); const vfs = require("vinyl-fs");
var through = require("through2"); const through = require("through2");
var BUILD_DIR = "build/"; const BUILD_DIR = "build/";
var L10N_DIR = "l10n/"; const L10N_DIR = "l10n/";
var TEST_DIR = "test/"; const TEST_DIR = "test/";
var EXTENSION_SRC_DIR = "extensions/"; const EXTENSION_SRC_DIR = "extensions/";
var BASELINE_DIR = BUILD_DIR + "baseline/"; const BASELINE_DIR = BUILD_DIR + "baseline/";
var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + "mozcentral.baseline/"; const MOZCENTRAL_BASELINE_DIR = BUILD_DIR + "mozcentral.baseline/";
var GENERIC_DIR = BUILD_DIR + "generic/"; const GENERIC_DIR = BUILD_DIR + "generic/";
var GENERIC_LEGACY_DIR = BUILD_DIR + "generic-legacy/"; const GENERIC_LEGACY_DIR = BUILD_DIR + "generic-legacy/";
var COMPONENTS_DIR = BUILD_DIR + "components/"; const COMPONENTS_DIR = BUILD_DIR + "components/";
var COMPONENTS_LEGACY_DIR = BUILD_DIR + "components-legacy/"; const COMPONENTS_LEGACY_DIR = BUILD_DIR + "components-legacy/";
var IMAGE_DECODERS_DIR = BUILD_DIR + "image_decoders/"; const IMAGE_DECODERS_DIR = BUILD_DIR + "image_decoders/";
var IMAGE_DECODERS_LEGACY_DIR = BUILD_DIR + "image_decoders-legacy/"; const IMAGE_DECODERS_LEGACY_DIR = BUILD_DIR + "image_decoders-legacy/";
var DEFAULT_PREFERENCES_DIR = BUILD_DIR + "default_preferences/"; const DEFAULT_PREFERENCES_DIR = BUILD_DIR + "default_preferences/";
var MINIFIED_DIR = BUILD_DIR + "minified/"; const MINIFIED_DIR = BUILD_DIR + "minified/";
var MINIFIED_LEGACY_DIR = BUILD_DIR + "minified-legacy/"; const MINIFIED_LEGACY_DIR = BUILD_DIR + "minified-legacy/";
var JSDOC_BUILD_DIR = BUILD_DIR + "jsdoc/"; const JSDOC_BUILD_DIR = BUILD_DIR + "jsdoc/";
var GH_PAGES_DIR = BUILD_DIR + "gh-pages/"; const GH_PAGES_DIR = BUILD_DIR + "gh-pages/";
var SRC_DIR = "src/"; const SRC_DIR = "src/";
var LIB_DIR = BUILD_DIR + "lib/"; const LIB_DIR = BUILD_DIR + "lib/";
var DIST_DIR = BUILD_DIR + "dist/"; const DIST_DIR = BUILD_DIR + "dist/";
var TYPES_DIR = BUILD_DIR + "types/"; const TYPES_DIR = BUILD_DIR + "types/";
const TMP_DIR = BUILD_DIR + "tmp/"; const TMP_DIR = BUILD_DIR + "tmp/";
var TYPESTEST_DIR = BUILD_DIR + "typestest/"; const TYPESTEST_DIR = BUILD_DIR + "typestest/";
var COMMON_WEB_FILES = ["web/images/*.{png,svg,gif,cur}", "web/debugger.js"]; const COMMON_WEB_FILES = ["web/images/*.{png,svg,gif,cur}", "web/debugger.js"];
var MOZCENTRAL_DIFF_FILE = "mozcentral.diff"; const MOZCENTRAL_DIFF_FILE = "mozcentral.diff";
var REPO = "git@github.com:mozilla/pdf.js.git"; const REPO = "git@github.com:mozilla/pdf.js.git";
var DIST_REPO_URL = "https://github.com/mozilla/pdfjs-dist"; const DIST_REPO_URL = "https://github.com/mozilla/pdfjs-dist";
var builder = require("./external/builder/builder.js"); const builder = require("./external/builder/builder.js");
var CONFIG_FILE = "pdfjs.config"; const CONFIG_FILE = "pdfjs.config";
var config = JSON.parse(fs.readFileSync(CONFIG_FILE).toString()); const config = JSON.parse(fs.readFileSync(CONFIG_FILE).toString());
// Default Autoprefixer config used for generic, components, minified-pre // Default Autoprefixer config used for generic, components, minified-pre
var AUTOPREFIXER_CONFIG = { const AUTOPREFIXER_CONFIG = {
overrideBrowserslist: [ overrideBrowserslist: [
"last 2 versions", "last 2 versions",
"Chrome >= 49", // Last supported on Windows XP "Chrome >= 49", // Last supported on Windows XP
@ -105,7 +106,7 @@ const DEFINES = Object.freeze({
function transform(charEncoding, transformFunction) { function transform(charEncoding, transformFunction) {
return through.obj(function (vinylFile, enc, done) { return through.obj(function (vinylFile, enc, done) {
var transformedFile = vinylFile.clone(); const transformedFile = vinylFile.clone();
transformedFile.contents = Buffer.from( transformedFile.contents = Buffer.from(
transformFunction(transformedFile.contents), transformFunction(transformedFile.contents),
charEncoding charEncoding
@ -126,7 +127,7 @@ function safeSpawnSync(command, parameters, options) {
return '"' + param.replace(/([$\\"`])/g, "\\$1") + '"'; return '"' + param.replace(/([$\\"`])/g, "\\$1") + '"';
}); });
var result = spawnSync(command, parameters, options); const result = spawnSync(command, parameters, options);
if (result.status !== 0) { if (result.status !== 0) {
console.log( console.log(
'Error: command "' + 'Error: command "' +
@ -152,7 +153,7 @@ function startNode(args, options) {
} }
function createStringSource(filename, content) { function createStringSource(filename, content) {
var source = stream.Readable({ objectMode: true }); const source = stream.Readable({ objectMode: true });
source._read = function () { source._read = function () {
this.push( this.push(
new Vinyl({ new Vinyl({
@ -177,21 +178,21 @@ function createWebpackConfig(
const versionInfo = !disableVersionInfo const versionInfo = !disableVersionInfo
? getVersionJSON() ? getVersionJSON()
: { version: 0, commit: 0 }; : { version: 0, commit: 0 };
var bundleDefines = builder.merge(defines, { const bundleDefines = builder.merge(defines, {
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",
}); });
var licenseHeaderLibre = fs const licenseHeaderLibre = fs
.readFileSync("./src/license_header_libre.js") .readFileSync("./src/license_header_libre.js")
.toString(); .toString();
var enableSourceMaps = const enableSourceMaps =
!bundleDefines.MOZCENTRAL && !bundleDefines.MOZCENTRAL &&
!bundleDefines.CHROME && !bundleDefines.CHROME &&
!bundleDefines.LIB && !bundleDefines.LIB &&
!bundleDefines.TESTING && !bundleDefines.TESTING &&
!disableSourceMaps; !disableSourceMaps;
var skipBabel = bundleDefines.SKIP_BABEL; const skipBabel = bundleDefines.SKIP_BABEL;
// `core-js` (see https://github.com/zloirock/core-js/issues/514), // `core-js` (see https://github.com/zloirock/core-js/issues/514),
// `web-streams-polyfill` (already using a transpiled file), and // `web-streams-polyfill` (already using a transpiled file), and
@ -284,20 +285,20 @@ function getVersionJSON() {
} }
function checkChromePreferencesFile(chromePrefsPath, webPrefsPath) { function checkChromePreferencesFile(chromePrefsPath, webPrefsPath) {
var chromePrefs = JSON.parse(fs.readFileSync(chromePrefsPath).toString()); const chromePrefs = JSON.parse(fs.readFileSync(chromePrefsPath).toString());
var chromePrefsKeys = Object.keys(chromePrefs.properties); let chromePrefsKeys = Object.keys(chromePrefs.properties);
chromePrefsKeys = chromePrefsKeys.filter(function (key) { chromePrefsKeys = chromePrefsKeys.filter(function (key) {
var description = chromePrefs.properties[key].description; const description = chromePrefs.properties[key].description;
// Deprecated keys are allowed in the managed preferences file. // Deprecated keys are allowed in the managed preferences file.
// The code maintained is responsible for adding migration logic to // The code maintained is responsible for adding migration logic to
// extensions/chromium/options/migration.js and web/chromecom.js . // extensions/chromium/options/migration.js and web/chromecom.js .
return !description || !description.startsWith("DEPRECATED."); return !description || !description.startsWith("DEPRECATED.");
}); });
chromePrefsKeys.sort(); chromePrefsKeys.sort();
var webPrefs = JSON.parse(fs.readFileSync(webPrefsPath).toString()); const webPrefs = JSON.parse(fs.readFileSync(webPrefsPath).toString());
var webPrefsKeys = Object.keys(webPrefs); const webPrefsKeys = Object.keys(webPrefs);
webPrefsKeys.sort(); webPrefsKeys.sort();
var telemetryIndex = chromePrefsKeys.indexOf("disableTelemetry"); const telemetryIndex = chromePrefsKeys.indexOf("disableTelemetry");
if (telemetryIndex >= 0) { if (telemetryIndex >= 0) {
chromePrefsKeys.splice(telemetryIndex, 1); chromePrefsKeys.splice(telemetryIndex, 1);
} else { } else {
@ -342,10 +343,10 @@ function replaceJSRootName(amdName, jsName) {
} }
function createMainBundle(defines) { function createMainBundle(defines) {
var mainAMDName = "pdfjs-dist/build/pdf"; const mainAMDName = "pdfjs-dist/build/pdf";
var mainOutputName = "pdf.js"; const mainOutputName = "pdf.js";
var mainFileConfig = createWebpackConfig(defines, { const mainFileConfig = createWebpackConfig(defines, {
filename: mainOutputName, filename: mainOutputName,
library: mainAMDName, library: mainAMDName,
libraryTarget: "umd", libraryTarget: "umd",
@ -359,10 +360,10 @@ function createMainBundle(defines) {
} }
function createScriptingBundle(defines, extraOptions = undefined) { function createScriptingBundle(defines, extraOptions = undefined) {
var scriptingAMDName = "pdfjs-dist/build/pdf.scripting"; const scriptingAMDName = "pdfjs-dist/build/pdf.scripting";
var scriptingOutputName = "pdf.scripting.js"; const scriptingOutputName = "pdf.scripting.js";
var scriptingFileConfig = createWebpackConfig( const scriptingFileConfig = createWebpackConfig(
defines, defines,
{ {
filename: scriptingOutputName, filename: scriptingOutputName,
@ -409,8 +410,8 @@ function createTemporaryScriptingBundle(defines, extraOptions = undefined) {
} }
function createSandboxBundle(defines, extraOptions = undefined) { function createSandboxBundle(defines, extraOptions = undefined) {
var sandboxAMDName = "pdfjs-dist/build/pdf.sandbox"; const sandboxAMDName = "pdfjs-dist/build/pdf.sandbox";
var sandboxOutputName = "pdf.sandbox.js"; const sandboxOutputName = "pdf.sandbox.js";
const scriptingPath = TMP_DIR + "pdf.scripting.js"; const scriptingPath = TMP_DIR + "pdf.scripting.js";
// Insert the source as a string to be `eval`-ed in the sandbox. // Insert the source as a string to be `eval`-ed in the sandbox.
@ -419,7 +420,7 @@ function createSandboxBundle(defines, extraOptions = undefined) {
}); });
fs.unlinkSync(scriptingPath); fs.unlinkSync(scriptingPath);
var sandboxFileConfig = createWebpackConfig( const sandboxFileConfig = createWebpackConfig(
sandboxDefines, sandboxDefines,
{ {
filename: sandboxOutputName, filename: sandboxOutputName,
@ -438,10 +439,10 @@ function createSandboxBundle(defines, extraOptions = undefined) {
} }
function createWorkerBundle(defines) { function createWorkerBundle(defines) {
var workerAMDName = "pdfjs-dist/build/pdf.worker"; const workerAMDName = "pdfjs-dist/build/pdf.worker";
var workerOutputName = "pdf.worker.js"; const workerOutputName = "pdf.worker.js";
var workerFileConfig = createWebpackConfig(defines, { const workerFileConfig = createWebpackConfig(defines, {
filename: workerOutputName, filename: workerOutputName,
library: workerAMDName, library: workerAMDName,
libraryTarget: "umd", libraryTarget: "umd",
@ -455,19 +456,19 @@ function createWorkerBundle(defines) {
} }
function createWebBundle(defines) { function createWebBundle(defines) {
var viewerOutputName = "viewer.js"; const viewerOutputName = "viewer.js";
var viewerFileConfig = createWebpackConfig(defines, { const viewerFileConfig = createWebpackConfig(defines, {
filename: viewerOutputName, filename: viewerOutputName,
}); });
return gulp.src("./web/viewer.js").pipe(webpack2Stream(viewerFileConfig)); return gulp.src("./web/viewer.js").pipe(webpack2Stream(viewerFileConfig));
} }
function createComponentsBundle(defines) { function createComponentsBundle(defines) {
var componentsAMDName = "pdfjs-dist/web/pdf_viewer"; const componentsAMDName = "pdfjs-dist/web/pdf_viewer";
var componentsOutputName = "pdf_viewer.js"; const componentsOutputName = "pdf_viewer.js";
var componentsFileConfig = createWebpackConfig(defines, { const componentsFileConfig = createWebpackConfig(defines, {
filename: componentsOutputName, filename: componentsOutputName,
library: componentsAMDName, library: componentsAMDName,
libraryTarget: "umd", libraryTarget: "umd",
@ -481,10 +482,10 @@ function createComponentsBundle(defines) {
} }
function createImageDecodersBundle(defines) { function createImageDecodersBundle(defines) {
var imageDecodersAMDName = "pdfjs-dist/image_decoders/pdf.image_decoders"; const imageDecodersAMDName = "pdfjs-dist/image_decoders/pdf.image_decoders";
var imageDecodersOutputName = "pdf.image_decoders.js"; const imageDecodersOutputName = "pdf.image_decoders.js";
var componentsFileConfig = createWebpackConfig(defines, { const componentsFileConfig = createWebpackConfig(defines, {
filename: imageDecodersOutputName, filename: imageDecodersOutputName,
library: imageDecodersAMDName, library: imageDecodersAMDName,
libraryTarget: "umd", libraryTarget: "umd",
@ -499,7 +500,7 @@ function createImageDecodersBundle(defines) {
function checkFile(filePath) { function checkFile(filePath) {
try { try {
var stat = fs.lstatSync(filePath); const stat = fs.lstatSync(filePath);
return stat.isFile(); return stat.isFile();
} catch (e) { } catch (e) {
return false; return false;
@ -508,7 +509,7 @@ function checkFile(filePath) {
function checkDir(dirPath) { function checkDir(dirPath) {
try { try {
var stat = fs.lstatSync(dirPath); const stat = fs.lstatSync(dirPath);
return stat.isDirectory(); return stat.isDirectory();
} catch (e) { } catch (e) {
return false; return false;
@ -516,27 +517,27 @@ function checkDir(dirPath) {
} }
function replaceInFile(filePath, find, replacement) { function replaceInFile(filePath, find, replacement) {
var content = fs.readFileSync(filePath).toString(); let content = fs.readFileSync(filePath).toString();
content = content.replace(find, replacement); content = content.replace(find, replacement);
fs.writeFileSync(filePath, content); fs.writeFileSync(filePath, content);
} }
function getTempFile(prefix, suffix) { function getTempFile(prefix, suffix) {
mkdirp.sync(BUILD_DIR + "tmp/"); mkdirp.sync(BUILD_DIR + "tmp/");
var bytes = require("crypto").randomBytes(6).toString("hex"); const bytes = require("crypto").randomBytes(6).toString("hex");
var filePath = BUILD_DIR + "tmp/" + prefix + bytes + suffix; const filePath = BUILD_DIR + "tmp/" + prefix + bytes + suffix;
fs.writeFileSync(filePath, ""); fs.writeFileSync(filePath, "");
return filePath; return filePath;
} }
function createTestSource(testsName, bot) { function createTestSource(testsName, bot) {
var source = stream.Readable({ objectMode: true }); const source = stream.Readable({ objectMode: true });
source._read = function () { source._read = function () {
console.log(); console.log();
console.log("### Running " + testsName + " tests"); console.log("### Running " + testsName + " tests");
var PDF_TEST = process.env.PDF_TEST || "test_manifest.json"; const PDF_TEST = process.env.PDF_TEST || "test_manifest.json";
var args = ["test.js"]; const args = ["test.js"];
switch (testsName) { switch (testsName) {
case "browser": case "browser":
args.push("--reftest", "--manifestFile=" + PDF_TEST); args.push("--reftest", "--manifestFile=" + PDF_TEST);
@ -564,7 +565,7 @@ function createTestSource(testsName, bot) {
args.push("--noChrome"); args.push("--noChrome");
} }
var testProcess = startNode(args, { cwd: TEST_DIR, stdio: "inherit" }); const testProcess = startNode(args, { cwd: TEST_DIR, stdio: "inherit" });
testProcess.on("close", function (code) { testProcess.on("close", function (code) {
source.push(null); source.push(null);
}); });
@ -577,7 +578,7 @@ function makeRef(done, bot) {
console.log(); console.log();
console.log("### Creating reference images"); console.log("### Creating reference images");
var args = ["test.js", "--masterMode"]; const args = ["test.js", "--masterMode"];
if (bot) { if (bot) {
args.push("--noPrompts", "--strictVerify"); args.push("--noPrompts", "--strictVerify");
} }
@ -585,7 +586,7 @@ function makeRef(done, bot) {
args.push("--noChrome"); args.push("--noChrome");
} }
var testProcess = startNode(args, { cwd: TEST_DIR, stdio: "inherit" }); const testProcess = startNode(args, { cwd: TEST_DIR, stdio: "inherit" });
testProcess.on("close", function (code) { testProcess.on("close", function (code) {
done(); done();
}); });
@ -593,7 +594,7 @@ function makeRef(done, bot) {
gulp.task("default", function (done) { gulp.task("default", function (done) {
console.log("Available tasks:"); console.log("Available tasks:");
var tasks = Object.keys(gulp.registry().tasks()); const tasks = Object.keys(gulp.registry().tasks());
tasks.sort(); tasks.sort();
tasks.forEach(function (taskName) { tasks.forEach(function (taskName) {
console.log(" " + taskName); console.log(" " + taskName);
@ -608,7 +609,7 @@ gulp.task("buildnumber", function (done) {
exec( exec(
"git log --format=oneline " + config.baseVersion + "..", "git log --format=oneline " + config.baseVersion + "..",
function (err, stdout, stderr) { function (err, stdout, stderr) {
var buildNumber = 0; let buildNumber = 0;
if (!err) { if (!err) {
// Build number is the number of commits since base version // Build number is the number of commits since base version
buildNumber = stdout ? stdout.match(/\n/g).length : 0; buildNumber = stdout ? stdout.match(/\n/g).length : 0;
@ -620,10 +621,10 @@ gulp.task("buildnumber", function (done) {
console.log("Extension build number: " + buildNumber); console.log("Extension build number: " + buildNumber);
var version = config.versionPrefix + buildNumber; const version = config.versionPrefix + buildNumber;
exec('git log --format="%h" -n 1', function (err2, stdout2, stderr2) { exec('git log --format="%h" -n 1', function (err2, stdout2, stderr2) {
var buildCommit = ""; let buildCommit = "";
if (!err2) { if (!err2) {
buildCommit = stdout2.replace("\n", ""); buildCommit = stdout2.replace("\n", "");
} }
@ -675,8 +676,8 @@ gulp.task("default_preferences-pre", function () {
], ],
}).code; }).code;
} }
var babel = require("@babel/core"); const babel = require("@babel/core");
var ctx = { const ctx = {
rootPath: __dirname, rootPath: __dirname,
saveComments: false, saveComments: false,
defines: builder.merge(DEFINES, { defines: builder.merge(DEFINES, {
@ -689,7 +690,7 @@ gulp.task("default_preferences-pre", function () {
"pdfjs-lib": "../pdf", "pdfjs-lib": "../pdf",
}, },
}; };
var preprocessor2 = require("./external/builder/preprocessor2.js"); const preprocessor2 = require("./external/builder/preprocessor2.js");
return merge([ return merge([
gulp.src(["web/{app_options,viewer_compatibility}.js"], { gulp.src(["web/{app_options,viewer_compatibility}.js"], {
base: ".", base: ".",
@ -702,11 +703,11 @@ gulp.task("default_preferences-pre", function () {
gulp.task( gulp.task(
"default_preferences", "default_preferences",
gulp.series("default_preferences-pre", function (done) { gulp.series("default_preferences-pre", function (done) {
var AppOptionsLib = require("./" + const AppOptionsLib = require("./" +
DEFAULT_PREFERENCES_DIR + DEFAULT_PREFERENCES_DIR +
"lib/web/app_options.js"); "lib/web/app_options.js");
var AppOptions = AppOptionsLib.AppOptions; const AppOptions = AppOptionsLib.AppOptions;
var OptionKind = AppOptionsLib.OptionKind; const OptionKind = AppOptionsLib.OptionKind;
createStringSource( createStringSource(
"default_preferences.json", "default_preferences.json",
@ -718,7 +719,7 @@ gulp.task(
); );
gulp.task("locale", function () { gulp.task("locale", function () {
var VIEWER_LOCALE_OUTPUT = "web/locale/"; const VIEWER_LOCALE_OUTPUT = "web/locale/";
console.log(); console.log();
console.log("### Building localization files"); console.log("### Building localization files");
@ -726,13 +727,13 @@ gulp.task("locale", function () {
rimraf.sync(VIEWER_LOCALE_OUTPUT); rimraf.sync(VIEWER_LOCALE_OUTPUT);
mkdirp.sync(VIEWER_LOCALE_OUTPUT); mkdirp.sync(VIEWER_LOCALE_OUTPUT);
var subfolders = fs.readdirSync(L10N_DIR); const subfolders = fs.readdirSync(L10N_DIR);
subfolders.sort(); subfolders.sort();
var viewerOutput = ""; let viewerOutput = "";
var locales = []; const locales = [];
for (var i = 0; i < subfolders.length; i++) { for (let i = 0; i < subfolders.length; i++) {
var locale = subfolders[i]; const locale = subfolders[i];
var dirPath = L10N_DIR + locale; const dirPath = L10N_DIR + locale;
if (!checkDir(dirPath)) { if (!checkDir(dirPath)) {
continue; continue;
} }
@ -769,8 +770,8 @@ gulp.task("locale", function () {
}); });
gulp.task("cmaps", function (done) { gulp.task("cmaps", function (done) {
var CMAP_INPUT = "external/cmaps"; const CMAP_INPUT = "external/cmaps";
var VIEWER_CMAP_OUTPUT = "external/bcmaps"; const VIEWER_CMAP_OUTPUT = "external/bcmaps";
console.log(); console.log();
console.log("### Building cmaps"); console.log("### Building cmaps");
@ -789,34 +790,34 @@ gulp.task("cmaps", function (done) {
} }
}); });
var compressCmaps = require("./external/cmapscompress/compress.js") const compressCmaps = require("./external/cmapscompress/compress.js")
.compressCmaps; .compressCmaps;
compressCmaps(CMAP_INPUT, VIEWER_CMAP_OUTPUT, true); compressCmaps(CMAP_INPUT, VIEWER_CMAP_OUTPUT, true);
done(); done();
}); });
function preprocessCSS(source, mode, defines, cleanup) { function preprocessCSS(source, mode, defines, cleanup) {
var outName = getTempFile("~preprocess", ".css"); const outName = getTempFile("~preprocess", ".css");
builder.preprocessCSS(mode, source, outName); builder.preprocessCSS(mode, source, outName);
var out = fs.readFileSync(outName).toString(); let out = fs.readFileSync(outName).toString();
fs.unlinkSync(outName); fs.unlinkSync(outName);
if (cleanup) { if (cleanup) {
// Strip out all license headers in the middle. // Strip out all license headers in the middle.
var reg = /\n\/\* Copyright(.|\n)*?Mozilla Foundation(.|\n)*?\*\//g; const reg = /\n\/\* Copyright(.|\n)*?Mozilla Foundation(.|\n)*?\*\//g;
out = out.replace(reg, ""); out = out.replace(reg, "");
} }
var i = source.lastIndexOf("/"); const i = source.lastIndexOf("/");
return createStringSource(source.substr(i + 1), out); return createStringSource(source.substr(i + 1), out);
} }
function preprocessHTML(source, defines) { function preprocessHTML(source, defines) {
var outName = getTempFile("~preprocess", ".html"); const outName = getTempFile("~preprocess", ".html");
builder.preprocess(source, outName, defines); builder.preprocess(source, outName, defines);
var out = fs.readFileSync(outName).toString(); const out = fs.readFileSync(outName).toString();
fs.unlinkSync(outName); fs.unlinkSync(outName);
var i = source.lastIndexOf("/"); const i = source.lastIndexOf("/");
return createStringSource(source.substr(i + 1), `${out.trimEnd()}\n`); return createStringSource(source.substr(i + 1), `${out.trimEnd()}\n`);
} }
@ -860,13 +861,13 @@ gulp.task(
"default_preferences", "default_preferences",
"locale", "locale",
function scripting() { function scripting() {
var defines = builder.merge(DEFINES, { GENERIC: true }); const defines = builder.merge(DEFINES, { GENERIC: true });
return createTemporaryScriptingBundle(defines); return createTemporaryScriptingBundle(defines);
}, },
function () { function () {
console.log(); console.log();
console.log("### Creating generic viewer"); console.log("### Creating generic viewer");
var defines = builder.merge(DEFINES, { GENERIC: true }); const defines = builder.merge(DEFINES, { GENERIC: true });
return buildGeneric(defines, GENERIC_DIR); return buildGeneric(defines, GENERIC_DIR);
} }
@ -882,7 +883,7 @@ gulp.task(
"default_preferences", "default_preferences",
"locale", "locale",
function scripting() { function scripting() {
var defines = builder.merge(DEFINES, { const defines = builder.merge(DEFINES, {
GENERIC: true, GENERIC: true,
SKIP_BABEL: false, SKIP_BABEL: false,
}); });
@ -891,7 +892,7 @@ gulp.task(
function () { function () {
console.log(); console.log();
console.log("### Creating generic (legacy) viewer"); console.log("### Creating generic (legacy) viewer");
var defines = builder.merge(DEFINES, { const defines = builder.merge(DEFINES, {
GENERIC: true, GENERIC: true,
SKIP_BABEL: false, SKIP_BABEL: false,
}); });
@ -904,7 +905,7 @@ gulp.task(
function buildComponents(defines, dir) { function buildComponents(defines, dir) {
rimraf.sync(dir); rimraf.sync(dir);
var COMPONENTS_IMAGES = [ const COMPONENTS_IMAGES = [
"web/images/annotation-*.svg", "web/images/annotation-*.svg",
"web/images/loading-icon.gif", "web/images/loading-icon.gif",
"web/images/shadow.png", "web/images/shadow.png",
@ -924,7 +925,7 @@ gulp.task(
gulp.series("buildnumber", function () { gulp.series("buildnumber", function () {
console.log(); console.log();
console.log("### Creating generic components"); console.log("### Creating generic components");
var defines = builder.merge(DEFINES, { COMPONENTS: true, GENERIC: true }); const defines = builder.merge(DEFINES, { COMPONENTS: true, GENERIC: true });
return buildComponents(defines, COMPONENTS_DIR); return buildComponents(defines, COMPONENTS_DIR);
}) })
@ -935,7 +936,7 @@ gulp.task(
gulp.series("buildnumber", function () { gulp.series("buildnumber", function () {
console.log(); console.log();
console.log("### Creating generic (legacy) components"); console.log("### Creating generic (legacy) components");
var defines = builder.merge(DEFINES, { const defines = builder.merge(DEFINES, {
COMPONENTS: true, COMPONENTS: true,
GENERIC: true, GENERIC: true,
SKIP_BABEL: false, SKIP_BABEL: false,
@ -950,7 +951,7 @@ gulp.task(
gulp.series("buildnumber", function () { gulp.series("buildnumber", function () {
console.log(); console.log();
console.log("### Creating image decoders"); console.log("### Creating image decoders");
var defines = builder.merge(DEFINES, { const defines = builder.merge(DEFINES, {
GENERIC: true, GENERIC: true,
IMAGE_DECODERS: true, IMAGE_DECODERS: true,
}); });
@ -966,7 +967,7 @@ gulp.task(
gulp.series("buildnumber", function () { gulp.series("buildnumber", function () {
console.log(); console.log();
console.log("### Creating (legacy) image decoders"); console.log("### Creating (legacy) image decoders");
var defines = builder.merge(DEFINES, { const defines = builder.merge(DEFINES, {
GENERIC: true, GENERIC: true,
IMAGE_DECODERS: true, IMAGE_DECODERS: true,
SKIP_BABEL: false, SKIP_BABEL: false,
@ -1019,13 +1020,13 @@ gulp.task(
"default_preferences", "default_preferences",
"locale", "locale",
function scripting() { function scripting() {
var defines = builder.merge(DEFINES, { MINIFIED: true, GENERIC: true }); const defines = builder.merge(DEFINES, { MINIFIED: true, GENERIC: true });
return createTemporaryScriptingBundle(defines); return createTemporaryScriptingBundle(defines);
}, },
function () { function () {
console.log(); console.log();
console.log("### Creating minified viewer"); console.log("### Creating minified viewer");
var defines = builder.merge(DEFINES, { MINIFIED: true, GENERIC: true }); const defines = builder.merge(DEFINES, { MINIFIED: true, GENERIC: true });
return buildMinified(defines, MINIFIED_DIR); return buildMinified(defines, MINIFIED_DIR);
} }
@ -1039,7 +1040,7 @@ gulp.task(
"default_preferences", "default_preferences",
"locale", "locale",
function scripting() { function scripting() {
var defines = builder.merge(DEFINES, { const defines = builder.merge(DEFINES, {
MINIFIED: true, MINIFIED: true,
GENERIC: true, GENERIC: true,
SKIP_BABEL: false, SKIP_BABEL: false,
@ -1049,7 +1050,7 @@ gulp.task(
function () { function () {
console.log(); console.log();
console.log("### Creating minified (legacy) viewer"); console.log("### Creating minified (legacy) viewer");
var defines = builder.merge(DEFINES, { const defines = builder.merge(DEFINES, {
MINIFIED: true, MINIFIED: true,
GENERIC: true, GENERIC: true,
SKIP_BABEL: false, SKIP_BABEL: false,
@ -1061,15 +1062,17 @@ gulp.task(
); );
async function parseMinified(dir) { async function parseMinified(dir) {
var pdfFile = fs.readFileSync(dir + "/build/pdf.js").toString(); const pdfFile = fs.readFileSync(dir + "/build/pdf.js").toString();
var pdfWorkerFile = fs.readFileSync(dir + "/build/pdf.worker.js").toString(); const pdfWorkerFile = fs
var pdfSandboxFile = fs .readFileSync(dir + "/build/pdf.worker.js")
.toString();
const pdfSandboxFile = fs
.readFileSync(dir + "/build/pdf.sandbox.js") .readFileSync(dir + "/build/pdf.sandbox.js")
.toString(); .toString();
var pdfImageDecodersFile = fs const pdfImageDecodersFile = fs
.readFileSync(dir + "/image_decoders/pdf.image_decoders.js") .readFileSync(dir + "/image_decoders/pdf.image_decoders.js")
.toString(); .toString();
var viewerFiles = { const viewerFiles = {
"pdf.js": pdfFile, "pdf.js": pdfFile,
"viewer.js": fs.readFileSync(dir + "/web/viewer.js").toString(), "viewer.js": fs.readFileSync(dir + "/web/viewer.js").toString(),
}; };
@ -1077,8 +1080,8 @@ async function parseMinified(dir) {
console.log(); console.log();
console.log("### Minifying js files"); console.log("### Minifying js files");
var Terser = require("terser"); const Terser = require("terser");
var options = { const options = {
compress: { compress: {
// V8 chokes on very long sequences, work around that. // V8 chokes on very long sequences, work around that.
sequences: false, sequences: false,
@ -1146,11 +1149,11 @@ gulp.task(
); );
function preprocessDefaultPreferences(content) { function preprocessDefaultPreferences(content) {
var preprocessor2 = require("./external/builder/preprocessor2.js"); const preprocessor2 = require("./external/builder/preprocessor2.js");
var licenseHeader = fs.readFileSync("./src/license_header.js").toString(); const licenseHeader = fs.readFileSync("./src/license_header.js").toString();
var GLOBALS = "/* eslint-disable */\n"; const GLOBALS = "/* eslint-disable */\n";
var MODIFICATION_WARNING = const MODIFICATION_WARNING =
"//\n// THIS FILE IS GENERATED AUTOMATICALLY, DO NOT EDIT MANUALLY!\n//\n"; "//\n// THIS FILE IS GENERATED AUTOMATICALLY, DO NOT EDIT MANUALLY!\n//\n";
content = preprocessor2.preprocessPDFJSCode( content = preprocessor2.preprocessPDFJSCode(
@ -1178,9 +1181,9 @@ gulp.task(
gulp.series("buildnumber", "default_preferences", function () { gulp.series("buildnumber", "default_preferences", function () {
console.log(); console.log();
console.log("### Building mozilla-central extension"); console.log("### Building mozilla-central extension");
var defines = builder.merge(DEFINES, { MOZCENTRAL: true }); const defines = builder.merge(DEFINES, { MOZCENTRAL: true });
var MOZCENTRAL_DIR = BUILD_DIR + "mozcentral/", const MOZCENTRAL_DIR = BUILD_DIR + "mozcentral/",
MOZCENTRAL_EXTENSION_DIR = MOZCENTRAL_DIR + "browser/extensions/pdfjs/", MOZCENTRAL_EXTENSION_DIR = MOZCENTRAL_DIR + "browser/extensions/pdfjs/",
MOZCENTRAL_CONTENT_DIR = MOZCENTRAL_EXTENSION_DIR + "content/", MOZCENTRAL_CONTENT_DIR = MOZCENTRAL_EXTENSION_DIR + "content/",
FIREFOX_EXTENSION_DIR = "extensions/firefox/", FIREFOX_EXTENSION_DIR = "extensions/firefox/",
@ -1190,8 +1193,8 @@ gulp.task(
// Clear out everything in the firefox extension build directory // Clear out everything in the firefox extension build directory
rimraf.sync(MOZCENTRAL_DIR); rimraf.sync(MOZCENTRAL_DIR);
var versionJSON = getVersionJSON(); const versionJSON = getVersionJSON();
var version = versionJSON.version, const version = versionJSON.version,
commit = versionJSON.commit; commit = versionJSON.commit;
// Ignore the fallback cursor images, since they're unnecessary in Firefox. // Ignore the fallback cursor images, since they're unnecessary in Firefox.
@ -1258,21 +1261,27 @@ gulp.task(
"default_preferences", "default_preferences",
"locale", "locale",
function scripting() { function scripting() {
var defines = builder.merge(DEFINES, { CHROME: true, SKIP_BABEL: false }); const defines = builder.merge(DEFINES, {
CHROME: true,
SKIP_BABEL: false,
});
return createTemporaryScriptingBundle(defines); return createTemporaryScriptingBundle(defines);
}, },
function () { function () {
console.log(); console.log();
console.log("### Building Chromium extension"); console.log("### Building Chromium extension");
var defines = builder.merge(DEFINES, { CHROME: true, SKIP_BABEL: false }); const defines = builder.merge(DEFINES, {
CHROME: true,
SKIP_BABEL: false,
});
var CHROME_BUILD_DIR = BUILD_DIR + "/chromium/", const CHROME_BUILD_DIR = BUILD_DIR + "/chromium/",
CHROME_BUILD_CONTENT_DIR = CHROME_BUILD_DIR + "/content/"; CHROME_BUILD_CONTENT_DIR = CHROME_BUILD_DIR + "/content/";
// Clear out everything in the chrome extension build directory // Clear out everything in the chrome extension build directory
rimraf.sync(CHROME_BUILD_DIR); rimraf.sync(CHROME_BUILD_DIR);
var version = getVersionJSON().version; const version = getVersionJSON().version;
return merge([ return merge([
createMainBundle(defines).pipe( createMainBundle(defines).pipe(
@ -1337,11 +1346,11 @@ gulp.task("jsdoc", function (done) {
console.log(); console.log();
console.log("### Generating documentation (JSDoc)"); console.log("### Generating documentation (JSDoc)");
var JSDOC_FILES = ["src/doc_helper.js", "src/display/api.js"]; const JSDOC_FILES = ["src/doc_helper.js", "src/display/api.js"];
rimraf(JSDOC_BUILD_DIR, function () { rimraf(JSDOC_BUILD_DIR, function () {
mkdirp(JSDOC_BUILD_DIR).then(function () { mkdirp(JSDOC_BUILD_DIR).then(function () {
var command = const command =
'"node_modules/.bin/jsdoc" -d ' + '"node_modules/.bin/jsdoc" -d ' +
JSDOC_BUILD_DIR + JSDOC_BUILD_DIR +
" " + " " +
@ -1384,7 +1393,7 @@ function buildLib(defines, dir) {
}; };
} }
function preprocess(content) { function preprocess(content) {
var skipBabel = const skipBabel =
bundleDefines.SKIP_BABEL || /\/\*\s*no-babel-preset\s*\*\//.test(content); bundleDefines.SKIP_BABEL || /\/\*\s*no-babel-preset\s*\*\//.test(content);
content = preprocessor2.preprocessPDFJSCode(ctx, content); content = preprocessor2.preprocessPDFJSCode(ctx, content);
content = babel.transform(content, { content = babel.transform(content, {
@ -1403,20 +1412,20 @@ function buildLib(defines, dir) {
babelPluginReplaceNonWebPackRequire, babelPluginReplaceNonWebPackRequire,
], ],
}).code; }).code;
var removeCjsSrc = /^(var\s+\w+\s*=\s*(_interopRequireDefault\()?require\(".*?)(?:\/src)(\/[^"]*"\)\)?;)$/gm; const removeCjsSrc = /^(var\s+\w+\s*=\s*(_interopRequireDefault\()?require\(".*?)(?:\/src)(\/[^"]*"\)\)?;)$/gm;
content = content.replace(removeCjsSrc, (all, prefix, interop, suffix) => { content = content.replace(removeCjsSrc, (all, prefix, interop, suffix) => {
return prefix + suffix; return prefix + suffix;
}); });
return licenseHeaderLibre + content; return licenseHeaderLibre + content;
} }
var babel = require("@babel/core"); const babel = require("@babel/core");
var versionInfo = getVersionJSON(); const versionInfo = getVersionJSON();
var bundleDefines = builder.merge(defines, { const bundleDefines = builder.merge(defines, {
BUNDLE_VERSION: versionInfo.version, BUNDLE_VERSION: versionInfo.version,
BUNDLE_BUILD: versionInfo.commit, BUNDLE_BUILD: versionInfo.commit,
TESTING: process.env.TESTING === "true", TESTING: process.env.TESTING === "true",
}); });
var ctx = { const ctx = {
rootPath: __dirname, rootPath: __dirname,
saveComments: false, saveComments: false,
defines: bundleDefines, defines: bundleDefines,
@ -1424,10 +1433,10 @@ function buildLib(defines, dir) {
"pdfjs-lib": "../pdf", "pdfjs-lib": "../pdf",
}, },
}; };
var licenseHeaderLibre = fs const licenseHeaderLibre = fs
.readFileSync("./src/license_header_libre.js") .readFileSync("./src/license_header_libre.js")
.toString(); .toString();
var preprocessor2 = require("./external/builder/preprocessor2.js"); const preprocessor2 = require("./external/builder/preprocessor2.js");
return merge([ return merge([
gulp.src( gulp.src(
[ [
@ -1453,11 +1462,11 @@ gulp.task(
"buildnumber", "buildnumber",
"default_preferences", "default_preferences",
function scripting() { function scripting() {
var defines = builder.merge(DEFINES, { GENERIC: true, LIB: true }); const defines = builder.merge(DEFINES, { GENERIC: true, LIB: true });
return createTemporaryScriptingBundle(defines); return createTemporaryScriptingBundle(defines);
}, },
function () { function () {
var defines = builder.merge(DEFINES, { GENERIC: true, LIB: true }); const defines = builder.merge(DEFINES, { GENERIC: true, LIB: true });
return merge([ return merge([
buildLib(defines, "build/lib/"), buildLib(defines, "build/lib/"),
@ -1473,7 +1482,7 @@ gulp.task(
"buildnumber", "buildnumber",
"default_preferences", "default_preferences",
function scripting() { function scripting() {
var defines = builder.merge(DEFINES, { const defines = builder.merge(DEFINES, {
GENERIC: true, GENERIC: true,
LIB: true, LIB: true,
SKIP_BABEL: false, SKIP_BABEL: false,
@ -1481,7 +1490,7 @@ gulp.task(
return createTemporaryScriptingBundle(defines); return createTemporaryScriptingBundle(defines);
}, },
function () { function () {
var defines = builder.merge(DEFINES, { const defines = builder.merge(DEFINES, {
GENERIC: true, GENERIC: true,
LIB: true, LIB: true,
SKIP_BABEL: false, SKIP_BABEL: false,
@ -1508,7 +1517,7 @@ function compressPublish(targetName, dir) {
gulp.task( gulp.task(
"publish", "publish",
gulp.series("generic", "generic-legacy", function (done) { gulp.series("generic", "generic-legacy", function (done) {
var version = JSON.parse( const version = JSON.parse(
fs.readFileSync(BUILD_DIR + "version.json").toString() fs.readFileSync(BUILD_DIR + "version.json").toString()
).version; ).version;
@ -1640,19 +1649,19 @@ gulp.task("baseline", function (done) {
console.log(); console.log();
console.log("### Creating baseline environment"); console.log("### Creating baseline environment");
var baselineCommit = process.env.BASELINE; const baselineCommit = process.env.BASELINE;
if (!baselineCommit) { if (!baselineCommit) {
done(new Error("Missing baseline commit. Specify the BASELINE variable.")); done(new Error("Missing baseline commit. Specify the BASELINE variable."));
return; return;
} }
var initializeCommand = "git fetch origin"; let initializeCommand = "git fetch origin";
if (!checkDir(BASELINE_DIR)) { if (!checkDir(BASELINE_DIR)) {
mkdirp.sync(BASELINE_DIR); mkdirp.sync(BASELINE_DIR);
initializeCommand = "git clone ../../ ."; initializeCommand = "git clone ../../ .";
} }
var workingDirectory = path.resolve(process.cwd(), BASELINE_DIR); const workingDirectory = path.resolve(process.cwd(), BASELINE_DIR);
exec(initializeCommand, { cwd: workingDirectory }, function (error) { exec(initializeCommand, { cwd: workingDirectory }, function (error) {
if (error) { if (error) {
done(new Error("Baseline clone/fetch failed.")); done(new Error("Baseline clone/fetch failed."));
@ -1678,11 +1687,11 @@ gulp.task("baseline", function (done) {
gulp.task( gulp.task(
"unittestcli", "unittestcli",
gulp.series("testing-pre", "lib-legacy", function (done) { gulp.series("testing-pre", "lib-legacy", function (done) {
var options = [ const options = [
"node_modules/jasmine/bin/jasmine", "node_modules/jasmine/bin/jasmine",
"JASMINE_CONFIG_PATH=test/unit/clitests.json", "JASMINE_CONFIG_PATH=test/unit/clitests.json",
]; ];
var jasmineProcess = startNode(options, { stdio: "inherit" }); const jasmineProcess = startNode(options, { stdio: "inherit" });
jasmineProcess.on("close", function (code) { jasmineProcess.on("close", function (code) {
if (code !== 0) { if (code !== 0) {
done(new Error("Unit tests failed.")); done(new Error("Unit tests failed."));
@ -1800,8 +1809,8 @@ gulp.task(
console.log(); console.log();
console.log("### Starting local server"); console.log("### Starting local server");
var WebServer = require("./test/webserver.js").WebServer; const WebServer = require("./test/webserver.js").WebServer;
var server = new WebServer(); const server = new WebServer();
server.port = 8888; server.port = 8888;
server.start(); server.start();
}) })
@ -1815,9 +1824,9 @@ gulp.task("clean", function (done) {
}); });
gulp.task("makefile", function () { gulp.task("makefile", function () {
var makefileContent = "help:\n\tgulp\n\n"; let makefileContent = "help:\n\tgulp\n\n";
var targetsNames = []; const targetsNames = [];
for (var i in target) { for (const i in target) {
makefileContent += i + ":\n\tgulp " + i + "\n\n"; makefileContent += i + ":\n\tgulp " + i + "\n\n";
targetsNames.push(i); targetsNames.push(i);
} }
@ -1826,7 +1835,7 @@ gulp.task("makefile", function () {
}); });
gulp.task("importl10n", function (done) { gulp.task("importl10n", function (done) {
var locales = require("./external/importL10n/locales.js"); const locales = require("./external/importL10n/locales.js");
console.log(); console.log();
console.log("### Importing translations from mozilla-central"); console.log("### Importing translations from mozilla-central");
@ -1861,8 +1870,8 @@ gulp.task("gh-pages-prepare", function () {
}); });
gulp.task("wintersmith", function (done) { gulp.task("wintersmith", function (done) {
var wintersmith = require("wintersmith"); const wintersmith = require("wintersmith");
var env = wintersmith("docs/config.json"); const env = wintersmith("docs/config.json");
env.build(GH_PAGES_DIR, function (error) { env.build(GH_PAGES_DIR, function (error) {
if (error) { if (error) {
done(error); done(error);
@ -1915,8 +1924,8 @@ gulp.task("wintersmith", function (done) {
}); });
gulp.task("gh-pages-git", function (done) { gulp.task("gh-pages-git", function (done) {
var VERSION = getVersionJSON().version; const VERSION = getVersionJSON().version;
var reason = process.env.PDFJS_UPDATE_REASON; const reason = process.env.PDFJS_UPDATE_REASON;
safeSpawnSync("git", ["init"], { cwd: GH_PAGES_DIR }); safeSpawnSync("git", ["init"], { cwd: GH_PAGES_DIR });
safeSpawnSync("git", ["remote", "add", "origin", REPO], { safeSpawnSync("git", ["remote", "add", "origin", REPO], {
@ -1954,16 +1963,16 @@ gulp.task(
); );
function packageBowerJson() { function packageBowerJson() {
var VERSION = getVersionJSON().version; const VERSION = getVersionJSON().version;
var DIST_NAME = "pdfjs-dist"; const DIST_NAME = "pdfjs-dist";
var DIST_DESCRIPTION = "Generic build of Mozilla's PDF.js library."; const DIST_DESCRIPTION = "Generic build of Mozilla's PDF.js library.";
var DIST_KEYWORDS = ["Mozilla", "pdf", "pdf.js"]; const DIST_KEYWORDS = ["Mozilla", "pdf", "pdf.js"];
var DIST_HOMEPAGE = "http://mozilla.github.io/pdf.js/"; const DIST_HOMEPAGE = "http://mozilla.github.io/pdf.js/";
var DIST_BUGS_URL = "https://github.com/mozilla/pdf.js/issues"; const DIST_BUGS_URL = "https://github.com/mozilla/pdf.js/issues";
var DIST_LICENSE = "Apache-2.0"; const DIST_LICENSE = "Apache-2.0";
var npmManifest = { const npmManifest = {
name: DIST_NAME, name: DIST_NAME,
version: VERSION, version: VERSION,
main: "build/pdf.js", main: "build/pdf.js",
@ -1991,7 +2000,7 @@ function packageBowerJson() {
}, },
}; };
var bowerManifest = { const bowerManifest = {
name: DIST_NAME, name: DIST_NAME,
version: VERSION, version: VERSION,
main: ["build/pdf.js", "build/pdf.worker.js"], main: ["build/pdf.js", "build/pdf.worker.js"],
@ -2031,7 +2040,7 @@ gulp.task(
rimraf.sync(path.join(DIST_DIR, "*")); rimraf.sync(path.join(DIST_DIR, "*"));
// Rebuilding manifests // Rebuilding manifests
var [packageJsonSrc, bowerJsonSrc] = packageBowerJson(); const [packageJsonSrc, bowerJsonSrc] = packageBowerJson();
return merge([ return merge([
packageJsonSrc.pipe(gulp.dest(DIST_DIR)), packageJsonSrc.pipe(gulp.dest(DIST_DIR)),
@ -2117,9 +2126,9 @@ gulp.task(
gulp.task( gulp.task(
"dist-install", "dist-install",
gulp.series("dist-pre", function (done) { gulp.series("dist-pre", function (done) {
var distPath = DIST_DIR; let distPath = DIST_DIR;
var opts = {}; const opts = {};
var installPath = process.env.PDFJS_INSTALL_PATH; const installPath = process.env.PDFJS_INSTALL_PATH;
if (installPath) { if (installPath) {
opts.cwd = installPath; opts.cwd = installPath;
distPath = path.relative(installPath, distPath); distPath = path.relative(installPath, distPath);
@ -2132,15 +2141,15 @@ gulp.task(
gulp.task( gulp.task(
"dist-repo-git", "dist-repo-git",
gulp.series("dist-pre", function (done) { gulp.series("dist-pre", function (done) {
var VERSION = getVersionJSON().version; const VERSION = getVersionJSON().version;
console.log(); console.log();
console.log("### Committing changes"); console.log("### Committing changes");
var reason = process.env.PDFJS_UPDATE_REASON; let reason = process.env.PDFJS_UPDATE_REASON;
// Attempt to work-around the broken link, see https://github.com/mozilla/pdf.js/issues/10391 // Attempt to work-around the broken link, see https://github.com/mozilla/pdf.js/issues/10391
if (typeof reason === "string") { if (typeof reason === "string") {
var reasonParts = /^(See )(mozilla\/pdf\.js)@tags\/(v\d+\.\d+\.\d+)\s*$/.exec( const reasonParts = /^(See )(mozilla\/pdf\.js)@tags\/(v\d+\.\d+\.\d+)\s*$/.exec(
reason reason
); );
@ -2153,7 +2162,8 @@ gulp.task(
reasonParts[3]; reasonParts[3];
} }
} }
var message = "PDF.js version " + VERSION + (reason ? " - " + reason : ""); const message =
"PDF.js version " + VERSION + (reason ? " - " + reason : "");
safeSpawnSync("git", ["add", "*"], { cwd: DIST_DIR }); safeSpawnSync("git", ["add", "*"], { cwd: DIST_DIR });
safeSpawnSync("git", ["commit", "-am", message], { cwd: DIST_DIR }); safeSpawnSync("git", ["commit", "-am", message], { cwd: DIST_DIR });
safeSpawnSync("git", ["tag", "-a", "v" + VERSION, "-m", message], { safeSpawnSync("git", ["tag", "-a", "v" + VERSION, "-m", message], {
@ -2181,7 +2191,7 @@ gulp.task(
// Create a mozcentral build. // Create a mozcentral build.
rimraf.sync(BASELINE_DIR + BUILD_DIR); rimraf.sync(BASELINE_DIR + BUILD_DIR);
var workingDirectory = path.resolve(process.cwd(), BASELINE_DIR); const workingDirectory = path.resolve(process.cwd(), BASELINE_DIR);
safeSpawnSync("gulp", ["mozcentral"], { safeSpawnSync("gulp", ["mozcentral"], {
env: process.env, env: process.env,
cwd: workingDirectory, cwd: workingDirectory,
@ -2225,7 +2235,7 @@ gulp.task(
.pipe(gulp.dest(MOZCENTRAL_BASELINE_DIR)) .pipe(gulp.dest(MOZCENTRAL_BASELINE_DIR))
.on("end", function () { .on("end", function () {
safeSpawnSync("git", ["add", "-A"], { cwd: MOZCENTRAL_BASELINE_DIR }); safeSpawnSync("git", ["add", "-A"], { cwd: MOZCENTRAL_BASELINE_DIR });
var diff = safeSpawnSync( const diff = safeSpawnSync(
"git", "git",
["diff", "--binary", "--cached", "--unified=8"], ["diff", "--binary", "--cached", "--unified=8"],
{ cwd: MOZCENTRAL_BASELINE_DIR } { cwd: MOZCENTRAL_BASELINE_DIR }