mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-04 22:25:50 +02:00
Update to Babel 8
This commit is contained in:
parent
25eae30e4e
commit
b9609d0365
@ -319,6 +319,16 @@ function babelPluginStripSrcPath() {
|
||||
};
|
||||
}
|
||||
|
||||
function babelPluginAddHeaderComment(babel, { header }) {
|
||||
return {
|
||||
visitor: {
|
||||
Program(path) {
|
||||
path.addComment("leading", header);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function preprocessPDFJSCode(ctx, content) {
|
||||
return transformSync(content, {
|
||||
configFile: false,
|
||||
@ -327,6 +337,7 @@ function preprocessPDFJSCode(ctx, content) {
|
||||
}
|
||||
|
||||
export {
|
||||
babelPluginAddHeaderComment,
|
||||
babelPluginPDFJSPreprocessor,
|
||||
babelPluginStripSrcPath,
|
||||
preprocessPDFJSCode,
|
||||
|
||||
43
gulpfile.mjs
43
gulpfile.mjs
@ -13,7 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import * as babel from "@babel/core";
|
||||
import {
|
||||
babelPluginAddHeaderComment,
|
||||
babelPluginPDFJSPreprocessor,
|
||||
babelPluginStripSrcPath,
|
||||
preprocessPDFJSCode,
|
||||
@ -24,7 +26,6 @@ import {
|
||||
} from "./external/ccov/coverage_format.mjs";
|
||||
import { exec, execSync, spawn, spawnSync } from "child_process";
|
||||
import autoprefixer from "autoprefixer";
|
||||
import babel from "@babel/core";
|
||||
import { buildPrefsSchema } from "./external/chromium/prefs.mjs";
|
||||
import crypto from "crypto";
|
||||
import { finished } from "stream/promises";
|
||||
@ -104,11 +105,11 @@ const AUTOPREFIXER_CONFIG = {
|
||||
// Default Babel targets used for generic, components, minified-pre
|
||||
const BABEL_TARGETS = ENV_TARGETS.join(", ");
|
||||
|
||||
const BABEL_PRESET_ENV_OPTS = Object.freeze({
|
||||
corejs: "3.49.0",
|
||||
const BABEL_COREJS_OPTS = Object.freeze({
|
||||
method: "usage-global",
|
||||
version: "3.49.0",
|
||||
exclude: ["web.structured-clone"],
|
||||
shippedProposals: true,
|
||||
useBuiltIns: "usage",
|
||||
});
|
||||
|
||||
const DEFINES = Object.freeze({
|
||||
@ -325,9 +326,7 @@ function createWebpackConfig(
|
||||
/node_modules[\\/]core-js/,
|
||||
];
|
||||
|
||||
const babelPresets = skipBabel
|
||||
? undefined
|
||||
: [["@babel/preset-env", BABEL_PRESET_ENV_OPTS]];
|
||||
const babelPresets = skipBabel ? undefined : ["@babel/preset-env"];
|
||||
const babelPlugins = [
|
||||
[
|
||||
babelPluginPDFJSPreprocessor,
|
||||
@ -337,6 +336,9 @@ function createWebpackConfig(
|
||||
},
|
||||
],
|
||||
];
|
||||
if (!skipBabel) {
|
||||
babelPlugins.push(["babel-plugin-polyfill-corejs3", BABEL_COREJS_OPTS]);
|
||||
}
|
||||
if (bundleDefines.COVERAGE) {
|
||||
babelPlugins.push("babel-plugin-istanbul");
|
||||
}
|
||||
@ -1683,9 +1685,9 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
|
||||
const licenseHeader = fs
|
||||
.readFileSync("./src/license_header.js")
|
||||
.toString()
|
||||
.split("\n")
|
||||
.slice(1, -2)
|
||||
.map(line => line.replace(/^\s*\*\s?/, ""));
|
||||
.trim()
|
||||
.replace(/^\/\*/, "")
|
||||
.replace(/\*\/$/, "");
|
||||
|
||||
const ctx = {
|
||||
rootPath: __dirname,
|
||||
@ -1725,6 +1727,9 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
|
||||
[babelPluginPDFJSPreprocessor, ctx],
|
||||
[babelPluginStripSrcPath],
|
||||
];
|
||||
if (!skipBabel) {
|
||||
plugins.push(["babel-plugin-polyfill-corejs3", BABEL_COREJS_OPTS]);
|
||||
}
|
||||
if (enableCoverage) {
|
||||
plugins.push([
|
||||
"babel-plugin-istanbul",
|
||||
@ -1734,28 +1739,16 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
|
||||
},
|
||||
]);
|
||||
}
|
||||
plugins.push([
|
||||
"add-header-comment",
|
||||
{
|
||||
header: licenseHeader,
|
||||
},
|
||||
]);
|
||||
plugins.push([babelPluginAddHeaderComment, { header: licenseHeader }]);
|
||||
|
||||
const result = babel.transform(file.contents.toString(), {
|
||||
const result = babel.transformSync(file.contents.toString(), {
|
||||
...(enableCoverage && {
|
||||
filename: file.path,
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
}),
|
||||
sourceType: "module",
|
||||
presets: skipBabel
|
||||
? undefined
|
||||
: [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{ ...BABEL_PRESET_ENV_OPTS, loose: false, modules: false },
|
||||
],
|
||||
],
|
||||
presets: skipBabel ? undefined : ["@babel/preset-env"],
|
||||
plugins,
|
||||
targets: BABEL_TARGETS,
|
||||
sourceMaps: enableSourceMaps,
|
||||
|
||||
3143
package-lock.json
generated
3143
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -2,9 +2,9 @@
|
||||
"name": "pdf.js",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.29.7",
|
||||
"@babel/preset-env": "^7.29.7",
|
||||
"@babel/runtime": "^7.29.7",
|
||||
"@babel/core": "^8.0.1",
|
||||
"@babel/preset-env": "^8.0.2",
|
||||
"@babel/runtime": "^8.0.0",
|
||||
"@eslint/json": "^2.0.0",
|
||||
"@fluent/bundle": "^0.19.1",
|
||||
"@fluent/dom": "^0.10.2",
|
||||
@ -14,8 +14,8 @@
|
||||
"@types/node": "^26.0.0",
|
||||
"autoprefixer": "^10.5.1",
|
||||
"babel-loader": "^10.1.1",
|
||||
"babel-plugin-add-header-comment": "^1.0.3",
|
||||
"babel-plugin-istanbul": "^8.0.2",
|
||||
"babel-plugin-polyfill-corejs3": "^1.0.0",
|
||||
"cached-iterable": "^0.3.0",
|
||||
"caniuse-lite": "^1.0.30001799",
|
||||
"core-js": "^3.49.0",
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
// PLEASE NOTE: This code is intended for development purposes only and
|
||||
// should NOT be used in production environments.
|
||||
|
||||
import babel from "@babel/core";
|
||||
import * as babel from "@babel/core";
|
||||
import fs from "fs";
|
||||
import fsPromises from "fs/promises";
|
||||
import http from "http";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user