Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions external/builder/babel-plugin-pdfjs-preprocessor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -327,6 +337,7 @@ function preprocessPDFJSCode(ctx, content) {
}

export {
babelPluginAddHeaderComment,
babelPluginPDFJSPreprocessor,
babelPluginStripSrcPath,
preprocessPDFJSCode,
Expand Down
43 changes: 18 additions & 25 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* limitations under the License.
*/

import * as babel from "@babel/core";
import {
babelPluginAddHeaderComment,
babelPluginPDFJSPreprocessor,
babelPluginStripSrcPath,
preprocessPDFJSCode,
Expand All @@ -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";
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -327,9 +328,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,
Expand All @@ -339,6 +338,9 @@ function createWebpackConfig(
},
],
];
if (!skipBabel) {
babelPlugins.push(["babel-plugin-polyfill-corejs3", BABEL_COREJS_OPTS]);
}
if (bundleDefines.COVERAGE) {
babelPlugins.push("babel-plugin-istanbul");
}
Expand Down Expand Up @@ -1685,9 +1687,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,
Expand Down Expand Up @@ -1727,6 +1729,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",
Expand All @@ -1736,28 +1741,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,
Expand Down
Loading
Loading