Exclude process shim (#12149)

This commit is contained in:
fisker Cheung authored and GitHub committed 2022-01-26 19:08:55 +08:00
1 parent 7fbd4fcab3
commit d5bf36060f
6 files changed
+25 -18

No files matched your search

-1
View File
@@ -91,7 +91,6 @@
"@babel/core": "7.16.12",
"@babel/preset-env": "7.16.11",
"@babel/types": "7.16.8",
"@esbuild-plugins/node-globals-polyfill": "0.1.1",
"@esbuild-plugins/node-modules-polyfill": "0.1.4",
"@glimmer/reference": "0.83.1",
"@types/estree": "0.0.50",
+15 -11
View File
@@ -5,7 +5,6 @@ import builtinModules from "builtin-modules";
import * as babel from "@babel/core";
import esbuild from "esbuild";
import { NodeModulesPolyfillPlugin as esbuildPluginNodeModulePolyfills } from "@esbuild-plugins/node-modules-polyfill";
import { NodeGlobalsPolyfillPlugin as esbuildPluginNodeGlobalsPolyfills } from "@esbuild-plugins/node-globals-polyfill";
import esbuildPluginTextReplace from "esbuild-plugin-text-replace";
import browserslistToEsbuild from "browserslist-to-esbuild";
import { PROJECT_ROOT, DIST_DIR } from "../utils/index.mjs";
@@ -69,24 +68,29 @@ function getBabelConfig(bundle) {
async function* getEsbuildOptions(bundle, options) {
const replaceStrings = {
"process.env.PRETTIER_TARGET": JSON.stringify(bundle.target),
"process.env.NODE_ENV": JSON.stringify("production"),
// `tslib` exports global variables
"createExporter(root": "createExporter({}",
};
const define = {
"process.env.PRETTIER_TARGET": JSON.stringify(bundle.target),
"process.env.NODE_ENV": JSON.stringify("production"),
};
if (bundle.target === "universal") {
// We can't reference `process` in UMD bundles and this is
// an undocumented "feature"
replaceStrings["process.env.PRETTIER_DEBUG"] = "global.PRETTIER_DEBUG";
// `rollup-plugin-node-globals` replace `__dirname` with the real dirname
// `parser-typescript.js` will contain a path of working directory
replaceStrings["process.env.PRETTIER_DEBUG"] = "globalThis.PRETTIER_DEBUG";
define.process = JSON.stringify({ env: {}, argv: [] });
// Replace `__dirname` and `__filename` with a fake value
// So `parser-typescript.js` won't contain a path of working directory
// See #8268
replaceStrings.__filename = JSON.stringify(
define.__filename = JSON.stringify(
"/prettier-security-filename-placeholder.js"
);
replaceStrings.__dirname = JSON.stringify(
"/prettier-security-dirname-placeholder"
);
define.__dirname = JSON.stringify("/prettier-security-dirname-placeholder");
}
const replaceModule = {};
@@ -139,12 +143,12 @@ async function* getEsbuildOptions(bundle, options) {
const esbuildOptions = {
entryPoints: [path.join(PROJECT_ROOT, bundle.input)],
define,
bundle: true,
metafile: true,
plugins: [
esbuildPluginEvaluate(),
esbuildPluginReplaceModule({ ...replaceModule, ...bundle.replaceModule }),
bundle.target === "universal" && esbuildPluginNodeGlobalsPolyfills(),
bundle.target === "universal" && esbuildPluginNodeModulePolyfills(),
esbuildPluginTextReplace({
include: /\.[cm]?js$/,
+5 -1
View File
@@ -43,7 +43,8 @@ const parsers = [
'require("globby")': "{}",
"extra.projects = prepareAndTransformProjects(":
"extra.projects = [] || prepareAndTransformProjects(",
"process.versions.node": "'999.999.999'",
"process.versions.node": JSON.stringify("999.999.999"),
"process.cwd()": JSON.stringify("/prettier-security-dirname-placeholder"),
// `rollup-plugin-polyfill-node` don't have polyfill for these modules
'require("perf_hooks")': "{}",
'require("inspector")': "{}",
@@ -59,6 +60,9 @@ const parsers = [
"typescriptVersionIsAtLeast[version] = semverCheck(version);":
"typescriptVersionIsAtLeast[version] = true;",
},
replaceModule: {
[require.resolve("debug")]: require.resolve("./shims/debug.cjs"),
},
},
{
input: "src/language-js/parse/espree.js",
+2
View File
@@ -1,3 +1,5 @@
"use strict";
const assert = () => {};
assert.ok = assert;
assert.strictEqual = assert;
+3
View File
@@ -0,0 +1,3 @@
"use strict";
module.exports = () => () => {};
-5
View File
@@ -1188,11 +1188,6 @@
resolved "https://registry.yarnpkg.com/@cspell/dict-vue/-/dict-vue-2.0.1.tgz#7514875f760ae755d2a6ef1fd00917d107682fe1"
integrity sha512-n9So2C2Zw+uSDRzb2h9wq3PjZBqoHx+vBvu6a34H2qpumNjZ6HaEronrzX5tXJJXzOtocIQYrLxdd128TAU3+g==
"@esbuild-plugins/node-globals-polyfill@0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@esbuild-plugins/node-globals-polyfill/-/node-globals-polyfill-0.1.1.tgz#a313ab3efbb2c17c8ce376aa216c627c9b40f9d7"
integrity sha512-MR0oAA+mlnJWrt1RQVQ+4VYuRJW/P2YmRTv1AsplObyvuBMnPHiizUF95HHYiSsMGLhyGtWufaq2XQg6+iurBg==
"@esbuild-plugins/node-modules-polyfill@0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@esbuild-plugins/node-modules-polyfill/-/node-modules-polyfill-0.1.4.tgz#eb2f55da11967b2986c913f1a7957d1c868849c0"