From 76d9ecc7a9a4f8ba27e2a2342afac795ea22077d Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 18 Mar 2022 11:49:53 +0800 Subject: [PATCH 01/14] Test Issue 12338 --- .eslintignore | 1 + .eslintrc.js | 6 +- .github/workflows/prod-test.yml | 26 + .gitignore | 10 +- .prettierignore | 1 + .../index.js | 71 +++ .../package.json | 12 + .../yarn.lock | 489 ++++++++++++++++++ 8 files changed, 612 insertions(+), 4 deletions(-) create mode 100644 scripts/tools/bundle-prettier-with-webpack-test/index.js create mode 100644 scripts/tools/bundle-prettier-with-webpack-test/package.json create mode 100644 scripts/tools/bundle-prettier-with-webpack-test/yarn.lock diff --git a/.eslintignore b/.eslintignore index 62c92fb575a9..ec4144d4ee68 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ +.tmp !/*.js /tests/format/**/*.js /tests/integration/cli/ diff --git a/.eslintrc.js b/.eslintrc.js index 3cd5adc216a7..a82be66d80a9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -167,7 +167,11 @@ module.exports = { }, }, { - files: ["**/*.mjs", "scripts/release/**/*.js"], + files: [ + "**/*.mjs", + "scripts/release/**/*.js", + "scripts/tools/bundle-prettier-with-webpack-test/**/*.js", + ], parserOptions: { sourceType: "module", }, diff --git a/.github/workflows/prod-test.yml b/.github/workflows/prod-test.yml index affdbcb3da8c..7f2c531f35b4 100644 --- a/.github/workflows/prod-test.yml +++ b/.github/workflows/prod-test.yml @@ -169,3 +169,29 @@ jobs: - name: Run CLI on Node.js v0.10.48 run: node dist/bin-prettier --version 2>&1 >/dev/null | grep "prettier requires at least version 10.13.0 of Node, please upgrade" || exit 1 + + webpack-friendly: + name: Bundle Prettier with webpack + runs-on: ubuntu-latest + needs: [build] + defaults: + run: + working-directory: scripts/tools/bundle-prettier-with-webpack-test + steps: + - name: Checkout + uses: actions/checkout@v2.4.0 + + - name: Setup Node.js + uses: actions/setup-node@v2.5.1 + + - name: Download Artifact + uses: actions/download-artifact@v2 + with: + name: dist + path: dist + + - name: Install Dependencies + run: yarn install --frozen-lockfile + + - name: Test + run: yarn test diff --git a/.gitignore b/.gitignore index 824eebe1c74a..bdbcd48b376e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,17 @@ -/.cache +# node_modules +# We have `node_modules` directory for tests, don't ignore them all /node_modules +/website/node_modules /scripts/release/node_modules +/scripts/tools/bundle-prettier-with-webpack-test/node_modules +/scripts/tools/eslint-plugin-prettier-internal-rules/node_modules + +.tmp *.log /errors /test*.* /.vscode /dist -/website/node_modules /website/build /website/i18n /website/static/playground.js @@ -22,5 +27,4 @@ package-lock.json !.yarn/versions .pnp.* .nyc_output -/scripts/tools/eslint-plugin-prettier-internal-rules/node_modules .devcontainer diff --git a/.prettierignore b/.prettierignore index 305b9916ecb2..97e6e231a3f2 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ +.tmp dist/ .cache/ coverage/ diff --git a/scripts/tools/bundle-prettier-with-webpack-test/index.js b/scripts/tools/bundle-prettier-with-webpack-test/index.js new file mode 100644 index 000000000000..a02df100f42f --- /dev/null +++ b/scripts/tools/bundle-prettier-with-webpack-test/index.js @@ -0,0 +1,71 @@ +import { fileURLToPath } from "node:url"; +import path from "node:path"; +import fs from "node:fs/promises"; +import crypto from "node:crypto"; +import webpack from "webpack"; +import { DIST_DIR } from "../../../scripts/utils/index.mjs"; + +function runWebpack(config) { + return new Promise((resolve, reject) => { + webpack(config, (error, stats) => { + if (error) { + reject(error); + return; + } + + if (stats.hasErrors()) { + const { errors } = stats.toJson(); + const error = new Error(errors[0].message); + error.errors = errors; + reject(error); + return; + } + + resolve(stats); + }); + }); +} + +const getRandomFileName = (prefix) => + prefix + "-" + crypto.randomBytes(4).toString("hex").slice(0, 4) + ".js"; + +const TEMPORARY_DIRECTORY = fileURLToPath(new URL("./.tmp", import.meta.url)); + +/* `require` in `parser-typescript.js`, #12338 */ +(async () => { + try { + await fs.mkdir(TEMPORARY_DIRECTORY); + } catch { + // No op + } + + const relativePath = path + .relative(TEMPORARY_DIRECTORY, DIST_DIR) + .replaceAll("\\", "/"); + + const PROBLEMATIC_WARNING_MESSAGE = + "Critical dependency: require function is used in a way in which dependencies cannot be statically extracted"; + const inputFile = path.join(TEMPORARY_DIRECTORY, getRandomFileName("input")); + await fs.writeFile( + inputFile, + `import "${relativePath}/parser-typescript.js"` + ); + + const stats = await runWebpack({ + mode: "production", + entry: inputFile, + output: { + path: TEMPORARY_DIRECTORY, + filename: getRandomFileName("output"), + }, + }); + const result = stats.toJson(); + const { warnings } = result; + const error = warnings.find( + ({ message }) => message === PROBLEMATIC_WARNING_MESSAGE + ); + if (error) { + console.error(error); + throw new Error("Unexpected webpack warning."); + } +})(); diff --git a/scripts/tools/bundle-prettier-with-webpack-test/package.json b/scripts/tools/bundle-prettier-with-webpack-test/package.json new file mode 100644 index 000000000000..0bf0db923d7d --- /dev/null +++ b/scripts/tools/bundle-prettier-with-webpack-test/package.json @@ -0,0 +1,12 @@ +{ + "name": "bundle-prettier-with-webpack-test", + "version": "0.0.0", + "private": "true", + "type": "module", + "devDependencies": { + "webpack": "5.70.0" + }, + "scripts": { + "test": "node ./index.js" + } +} diff --git a/scripts/tools/bundle-prettier-with-webpack-test/yarn.lock b/scripts/tools/bundle-prettier-with-webpack-test/yarn.lock new file mode 100644 index 000000000000..8363c00dbd00 --- /dev/null +++ b/scripts/tools/bundle-prettier-with-webpack-test/yarn.lock @@ -0,0 +1,489 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/eslint-scope@^3.7.3": + version "3.7.3" + resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.3.tgz#125b88504b61e3c8bc6f870882003253005c3224" + integrity sha512-PB3ldyrcnAicT35TWPs5IcwKD8S333HMaa2VVv4+wdvebJkjWuW/xESoB8IwRcog8HYVYamb1g/R31Qv5Bx03g== + dependencies: + "@types/eslint" "*" + "@types/estree" "*" + +"@types/eslint@*": + version "8.4.1" + resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.4.1.tgz#c48251553e8759db9e656de3efc846954ac32304" + integrity sha512-GE44+DNEyxxh2Kc6ro/VkIj+9ma0pO0bwv9+uHSyBrikYOHr8zYcdPvnBOp1aw8s+CjRvuSx7CyWqRrNFQ59mA== + dependencies: + "@types/estree" "*" + "@types/json-schema" "*" + +"@types/estree@*", "@types/estree@^0.0.51": + version "0.0.51" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40" + integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ== + +"@types/json-schema@*", "@types/json-schema@^7.0.8": + version "7.0.10" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.10.tgz#9b05b7896166cd00e9cbd59864853abf65d9ac23" + integrity sha512-BLO9bBq59vW3fxCpD4o0N4U+DXsvwvIcl+jofw0frQo/GrBFC+/jRZj1E7kgp6dvTyNmA4y6JCV5Id/r3mNP5A== + +"@types/node@*": + version "17.0.21" + resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.21.tgz#864b987c0c68d07b4345845c3e63b75edd143644" + integrity sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ== + +"@webassemblyjs/ast@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" + integrity sha512-ukBh14qFLjxTQNTXocdyksN5QdM28S1CxHt2rdskFyL+xFV7VremuBLVbmCePj+URalXBENx/9Lm7lnhihtCSw== + dependencies: + "@webassemblyjs/helper-numbers" "1.11.1" + "@webassemblyjs/helper-wasm-bytecode" "1.11.1" + +"@webassemblyjs/floating-point-hex-parser@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.1.tgz#f6c61a705f0fd7a6aecaa4e8198f23d9dc179e4f" + integrity sha512-iGRfyc5Bq+NnNuX8b5hwBrRjzf0ocrJPI6GWFodBFzmFnyvrQ83SHKhmilCU/8Jv67i4GJZBMhEzltxzcNagtQ== + +"@webassemblyjs/helper-api-error@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.1.tgz#1a63192d8788e5c012800ba6a7a46c705288fd16" + integrity sha512-RlhS8CBCXfRUR/cwo2ho9bkheSXG0+NwooXcc3PAILALf2QLdFyj7KGsKRbVc95hZnhnERon4kW/D3SZpp6Tcg== + +"@webassemblyjs/helper-buffer@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.1.tgz#832a900eb444884cde9a7cad467f81500f5e5ab5" + integrity sha512-gwikF65aDNeeXa8JxXa2BAk+REjSyhrNC9ZwdT0f8jc4dQQeDQ7G4m0f2QCLPJiMTTO6wfDmRmj/pW0PsUvIcA== + +"@webassemblyjs/helper-numbers@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.1.tgz#64d81da219fbbba1e3bd1bfc74f6e8c4e10a62ae" + integrity sha512-vDkbxiB8zfnPdNK9Rajcey5C0w+QJugEglN0of+kmO8l7lDb77AnlKYQF7aarZuCrv+l0UvqL+68gSDr3k9LPQ== + dependencies: + "@webassemblyjs/floating-point-hex-parser" "1.11.1" + "@webassemblyjs/helper-api-error" "1.11.1" + "@xtuc/long" "4.2.2" + +"@webassemblyjs/helper-wasm-bytecode@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.1.tgz#f328241e41e7b199d0b20c18e88429c4433295e1" + integrity sha512-PvpoOGiJwXeTrSf/qfudJhwlvDQxFgelbMqtq52WWiXC6Xgg1IREdngmPN3bs4RoO83PnL/nFrxucXj1+BX62Q== + +"@webassemblyjs/helper-wasm-section@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.1.tgz#21ee065a7b635f319e738f0dd73bfbda281c097a" + integrity sha512-10P9No29rYX1j7F3EVPX3JvGPQPae+AomuSTPiF9eBQeChHI6iqjMIwR9JmOJXwpnn/oVGDk7I5IlskuMwU/pg== + dependencies: + "@webassemblyjs/ast" "1.11.1" + "@webassemblyjs/helper-buffer" "1.11.1" + "@webassemblyjs/helper-wasm-bytecode" "1.11.1" + "@webassemblyjs/wasm-gen" "1.11.1" + +"@webassemblyjs/ieee754@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.11.1.tgz#963929e9bbd05709e7e12243a099180812992614" + integrity sha512-hJ87QIPtAMKbFq6CGTkZYJivEwZDbQUgYd3qKSadTNOhVY7p+gfP6Sr0lLRVTaG1JjFj+r3YchoqRYxNH3M0GQ== + dependencies: + "@xtuc/ieee754" "^1.2.0" + +"@webassemblyjs/leb128@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.11.1.tgz#ce814b45574e93d76bae1fb2644ab9cdd9527aa5" + integrity sha512-BJ2P0hNZ0u+Th1YZXJpzW6miwqQUGcIHT1G/sf72gLVD9DZ5AdYTqPNbHZh6K1M5VmKvFXwGSWZADz+qBWxeRw== + dependencies: + "@xtuc/long" "4.2.2" + +"@webassemblyjs/utf8@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/utf8/-/utf8-1.11.1.tgz#d1f8b764369e7c6e6bae350e854dec9a59f0a3ff" + integrity sha512-9kqcxAEdMhiwQkHpkNiorZzqpGrodQQ2IGrHHxCy+Ozng0ofyMA0lTqiLkVs1uzTRejX+/O0EOT7KxqVPuXosQ== + +"@webassemblyjs/wasm-edit@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.1.tgz#ad206ebf4bf95a058ce9880a8c092c5dec8193d6" + integrity sha512-g+RsupUC1aTHfR8CDgnsVRVZFJqdkFHpsHMfJuWQzWU3tvnLC07UqHICfP+4XyL2tnr1amvl1Sdp06TnYCmVkA== + dependencies: + "@webassemblyjs/ast" "1.11.1" + "@webassemblyjs/helper-buffer" "1.11.1" + "@webassemblyjs/helper-wasm-bytecode" "1.11.1" + "@webassemblyjs/helper-wasm-section" "1.11.1" + "@webassemblyjs/wasm-gen" "1.11.1" + "@webassemblyjs/wasm-opt" "1.11.1" + "@webassemblyjs/wasm-parser" "1.11.1" + "@webassemblyjs/wast-printer" "1.11.1" + +"@webassemblyjs/wasm-gen@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.1.tgz#86c5ea304849759b7d88c47a32f4f039ae3c8f76" + integrity sha512-F7QqKXwwNlMmsulj6+O7r4mmtAlCWfO/0HdgOxSklZfQcDu0TpLiD1mRt/zF25Bk59FIjEuGAIyn5ei4yMfLhA== + dependencies: + "@webassemblyjs/ast" "1.11.1" + "@webassemblyjs/helper-wasm-bytecode" "1.11.1" + "@webassemblyjs/ieee754" "1.11.1" + "@webassemblyjs/leb128" "1.11.1" + "@webassemblyjs/utf8" "1.11.1" + +"@webassemblyjs/wasm-opt@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.1.tgz#657b4c2202f4cf3b345f8a4c6461c8c2418985f2" + integrity sha512-VqnkNqnZlU5EB64pp1l7hdm3hmQw7Vgqa0KF/KCNO9sIpI6Fk6brDEiX+iCOYrvMuBWDws0NkTOxYEb85XQHHw== + dependencies: + "@webassemblyjs/ast" "1.11.1" + "@webassemblyjs/helper-buffer" "1.11.1" + "@webassemblyjs/wasm-gen" "1.11.1" + "@webassemblyjs/wasm-parser" "1.11.1" + +"@webassemblyjs/wasm-parser@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.1.tgz#86ca734534f417e9bd3c67c7a1c75d8be41fb199" + integrity sha512-rrBujw+dJu32gYB7/Lup6UhdkPx9S9SnobZzRVL7VcBH9Bt9bCBLEuX/YXOOtBsOZ4NQrRykKhffRWHvigQvOA== + dependencies: + "@webassemblyjs/ast" "1.11.1" + "@webassemblyjs/helper-api-error" "1.11.1" + "@webassemblyjs/helper-wasm-bytecode" "1.11.1" + "@webassemblyjs/ieee754" "1.11.1" + "@webassemblyjs/leb128" "1.11.1" + "@webassemblyjs/utf8" "1.11.1" + +"@webassemblyjs/wast-printer@1.11.1": + version "1.11.1" + resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.11.1.tgz#d0c73beda8eec5426f10ae8ef55cee5e7084c2f0" + integrity sha512-IQboUWM4eKzWW+N/jij2sRatKMh99QEelo3Eb2q0qXkvPRISAj8Qxtmw5itwqK+TTkBuUIE45AxYPToqPtL5gg== + dependencies: + "@webassemblyjs/ast" "1.11.1" + "@xtuc/long" "4.2.2" + +"@xtuc/ieee754@^1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790" + integrity sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA== + +"@xtuc/long@4.2.2": + version "4.2.2" + resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d" + integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ== + +acorn-import-assertions@^1.7.6: + version "1.8.0" + resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.8.0.tgz#ba2b5939ce62c238db6d93d81c9b111b29b855e9" + integrity sha512-m7VZ3jwz4eK6A4Vtt8Ew1/mNbP24u0FhdyfA7fSvnJR6LMdfOYnmuIrrJAgrYfYJ10F/otaHTtrtrtmHdMNzEw== + +acorn@^8.4.1, acorn@^8.5.0: + version "8.7.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf" + integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ== + +ajv-keywords@^3.5.2: + version "3.5.2" + resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d" + integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ== + +ajv@^6.12.5: + version "6.12.6" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" + integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== + dependencies: + fast-deep-equal "^3.1.1" + fast-json-stable-stringify "^2.0.0" + json-schema-traverse "^0.4.1" + uri-js "^4.2.2" + +browserslist@^4.14.5: + version "4.20.2" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.20.2.tgz#567b41508757ecd904dab4d1c646c612cd3d4f88" + integrity sha512-CQOBCqp/9pDvDbx3xfMi+86pr4KXIf2FDkTTdeuYw8OxS9t898LA1Khq57gtufFILXpfgsSx5woNgsBgvGjpsA== + dependencies: + caniuse-lite "^1.0.30001317" + electron-to-chromium "^1.4.84" + escalade "^3.1.1" + node-releases "^2.0.2" + picocolors "^1.0.0" + +buffer-from@^1.0.0: + version "1.1.2" + resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" + integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== + +caniuse-lite@^1.0.30001317: + version "1.0.30001317" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001317.tgz#0548fb28fd5bc259a70b8c1ffdbe598037666a1b" + integrity sha512-xIZLh8gBm4dqNX0gkzrBeyI86J2eCjWzYAs40q88smG844YIrN4tVQl/RhquHvKEKImWWFIVh1Lxe5n1G/N+GQ== + +chrome-trace-event@^1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz#1015eced4741e15d06664a957dbbf50d041e26ac" + integrity sha512-p3KULyQg4S7NIHixdwbGX+nFHkoBiA4YQmyWtjb8XngSKV124nJmRysgAeujbUVb15vh+RvFUfCPqU7rXk+hZg== + +commander@^2.20.0: + version "2.20.3" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" + integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== + +electron-to-chromium@^1.4.84: + version "1.4.86" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.86.tgz#90fe4a9787f48d6522957213408e08a8126b2ebc" + integrity sha512-EVTZ+igi8x63pK4bPuA95PXIs2b2Cowi3WQwI9f9qManLiZJOD1Lash1J3W4TvvcUCcIR4o/rgi9o8UicXSO+w== + +enhanced-resolve@^5.9.2: + version "5.9.2" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.9.2.tgz#0224dcd6a43389ebfb2d55efee517e5466772dd9" + integrity sha512-GIm3fQfwLJ8YZx2smuHpBKkXC1yOk+OBEmKckVyL0i/ea8mqDEykK3ld5dgH1QYPNyT/lIllxV2LULnxCHaHkA== + dependencies: + graceful-fs "^4.2.4" + tapable "^2.2.0" + +es-module-lexer@^0.9.0: + version "0.9.3" + resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-0.9.3.tgz#6f13db00cc38417137daf74366f535c8eb438f19" + integrity sha512-1HQ2M2sPtxwnvOvT1ZClHyQDiggdNjURWpY2we6aMKCQiUVxTmVs2UYPLIrD84sS+kMdUwfBSylbJPwNnBrnHQ== + +escalade@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" + integrity sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw== + +eslint-scope@5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" + integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw== + dependencies: + esrecurse "^4.3.0" + estraverse "^4.1.1" + +esrecurse@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.3.0.tgz#7ad7964d679abb28bee72cec63758b1c5d2c9921" + integrity sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag== + dependencies: + estraverse "^5.2.0" + +estraverse@^4.1.1: + version "4.3.0" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d" + integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw== + +estraverse@^5.2.0: + version "5.3.0" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.3.0.tgz#2eea5290702f26ab8fe5370370ff86c965d21123" + integrity sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA== + +events@^3.2.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400" + integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q== + +fast-deep-equal@^3.1.1: + version "3.1.3" + resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" + integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== + +fast-json-stable-stringify@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" + integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw== + +glob-to-regexp@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e" + integrity sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw== + +graceful-fs@^4.1.2, graceful-fs@^4.2.4, graceful-fs@^4.2.9: + version "4.2.9" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz#041b05df45755e587a24942279b9d113146e1c96" + integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ== + +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + +jest-worker@^27.4.5: + version "27.5.1" + resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-27.5.1.tgz#8d146f0900e8973b106b6f73cc1e9a8cb86f8db0" + integrity sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg== + dependencies: + "@types/node" "*" + merge-stream "^2.0.0" + supports-color "^8.0.0" + +json-parse-better-errors@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9" + integrity sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw== + +json-schema-traverse@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" + integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== + +loader-runner@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-4.2.0.tgz#d7022380d66d14c5fb1d496b89864ebcfd478384" + integrity sha512-92+huvxMvYlMzMt0iIOukcwYBFpkYJdpl2xsZ7LrlayO7E8SOv+JJUEK17B/dJIHAOLMfh2dZZ/Y18WgmGtYNw== + +merge-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" + integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w== + +mime-db@1.52.0: + version "1.52.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" + integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== + +mime-types@^2.1.27: + version "2.1.35" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a" + integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== + dependencies: + mime-db "1.52.0" + +neo-async@^2.6.2: + version "2.6.2" + resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" + integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== + +node-releases@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.2.tgz#7139fe71e2f4f11b47d4d2986aaf8c48699e0c01" + integrity sha512-XxYDdcQ6eKqp/YjI+tb2C5WM2LgjnZrfYg4vgQt49EK268b6gYCHsBLrK2qvJo4FmCtqmKezb0WZFK4fkrZNsg== + +picocolors@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" + integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ== + +punycode@^2.1.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" + integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== + +randombytes@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a" + integrity sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ== + dependencies: + safe-buffer "^5.1.0" + +safe-buffer@^5.1.0: + version "5.2.1" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" + integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== + +schema-utils@^3.1.0, schema-utils@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.1.1.tgz#bc74c4b6b6995c1d88f76a8b77bea7219e0c8281" + integrity sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw== + dependencies: + "@types/json-schema" "^7.0.8" + ajv "^6.12.5" + ajv-keywords "^3.5.2" + +serialize-javascript@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8" + integrity sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag== + dependencies: + randombytes "^2.1.0" + +source-map-support@~0.5.20: + version "0.5.21" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f" + integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w== + dependencies: + buffer-from "^1.0.0" + source-map "^0.6.0" + +source-map@^0.6.0, source-map@^0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" + integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== + +source-map@~0.7.2: + version "0.7.3" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383" + integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ== + +supports-color@^8.0.0: + version "8.1.1" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c" + integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q== + dependencies: + has-flag "^4.0.0" + +tapable@^2.1.1, tapable@^2.2.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0" + integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ== + +terser-webpack-plugin@^5.1.3: + version "5.3.1" + resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.1.tgz#0320dcc270ad5372c1e8993fabbd927929773e54" + integrity sha512-GvlZdT6wPQKbDNW/GDQzZFg/j4vKU96yl2q6mcUkzKOgW4gwf1Z8cZToUCrz31XHlPWH8MVb1r2tFtdDtTGJ7g== + dependencies: + jest-worker "^27.4.5" + schema-utils "^3.1.1" + serialize-javascript "^6.0.0" + source-map "^0.6.1" + terser "^5.7.2" + +terser@^5.7.2: + version "5.12.1" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.12.1.tgz#4cf2ebed1f5bceef5c83b9f60104ac4a78b49e9c" + integrity sha512-NXbs+7nisos5E+yXwAD+y7zrcTkMqb0dEJxIGtSKPdCBzopf7ni4odPul2aechpV7EXNvOudYOX2bb5tln1jbQ== + dependencies: + acorn "^8.5.0" + commander "^2.20.0" + source-map "~0.7.2" + source-map-support "~0.5.20" + +uri-js@^4.2.2: + version "4.4.1" + resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" + integrity sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg== + dependencies: + punycode "^2.1.0" + +watchpack@^2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.3.1.tgz#4200d9447b401156eeca7767ee610f8809bc9d25" + integrity sha512-x0t0JuydIo8qCNctdDrn1OzH/qDzk2+rdCOC3YzumZ42fiMqmQ7T3xQurykYMhYfHaPHTp4ZxAx2NfUo1K6QaA== + dependencies: + glob-to-regexp "^0.4.1" + graceful-fs "^4.1.2" + +webpack-sources@^3.2.3: + version "3.2.3" + resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" + integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== + +webpack@5.70.0: + version "5.70.0" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.70.0.tgz#3461e6287a72b5e6e2f4872700bc8de0d7500e6d" + integrity sha512-ZMWWy8CeuTTjCxbeaQI21xSswseF2oNOwc70QSKNePvmxE7XW36i7vpBMYZFAUHPwQiEbNGCEYIOOlyRbdGmxw== + dependencies: + "@types/eslint-scope" "^3.7.3" + "@types/estree" "^0.0.51" + "@webassemblyjs/ast" "1.11.1" + "@webassemblyjs/wasm-edit" "1.11.1" + "@webassemblyjs/wasm-parser" "1.11.1" + acorn "^8.4.1" + acorn-import-assertions "^1.7.6" + browserslist "^4.14.5" + chrome-trace-event "^1.0.2" + enhanced-resolve "^5.9.2" + es-module-lexer "^0.9.0" + eslint-scope "5.1.1" + events "^3.2.0" + glob-to-regexp "^0.4.1" + graceful-fs "^4.2.9" + json-parse-better-errors "^1.0.2" + loader-runner "^4.2.0" + mime-types "^2.1.27" + neo-async "^2.6.2" + schema-utils "^3.1.0" + tapable "^2.1.1" + terser-webpack-plugin "^5.1.3" + watchpack "^2.3.1" + webpack-sources "^3.2.3" From 23004ca4aa6a6575d26c2cef1ec0afcb38275c29 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 18 Mar 2022 12:51:30 +0800 Subject: [PATCH 02/14] Simplify test script --- .../bundle-prettier-with-webpack-test/index.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/scripts/tools/bundle-prettier-with-webpack-test/index.js b/scripts/tools/bundle-prettier-with-webpack-test/index.js index a02df100f42f..2d5a53885c58 100644 --- a/scripts/tools/bundle-prettier-with-webpack-test/index.js +++ b/scripts/tools/bundle-prettier-with-webpack-test/index.js @@ -1,6 +1,5 @@ import { fileURLToPath } from "node:url"; import path from "node:path"; -import fs from "node:fs/promises"; import crypto from "node:crypto"; import webpack from "webpack"; import { DIST_DIR } from "../../../scripts/utils/index.mjs"; @@ -33,27 +32,12 @@ const TEMPORARY_DIRECTORY = fileURLToPath(new URL("./.tmp", import.meta.url)); /* `require` in `parser-typescript.js`, #12338 */ (async () => { - try { - await fs.mkdir(TEMPORARY_DIRECTORY); - } catch { - // No op - } - - const relativePath = path - .relative(TEMPORARY_DIRECTORY, DIST_DIR) - .replaceAll("\\", "/"); - const PROBLEMATIC_WARNING_MESSAGE = "Critical dependency: require function is used in a way in which dependencies cannot be statically extracted"; - const inputFile = path.join(TEMPORARY_DIRECTORY, getRandomFileName("input")); - await fs.writeFile( - inputFile, - `import "${relativePath}/parser-typescript.js"` - ); const stats = await runWebpack({ mode: "production", - entry: inputFile, + entry: path.join(DIST_DIR, "parser-typescript.js"), output: { path: TEMPORARY_DIRECTORY, filename: getRandomFileName("output"), From ea8000b31de56ae9e7c48943b27727ecb2bc3c61 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 18 Mar 2022 14:14:30 +0800 Subject: [PATCH 03/14] Add as a weekly job --- .github/workflows/bundler-friendly.yml | 61 +++++++++++++++++++ .github/workflows/dev-package-test.yml | 6 +- .github/workflows/prod-test.yml | 26 -------- .../index.js | 58 ++++++++++++------ 4 files changed, 104 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/bundler-friendly.yml diff --git a/.github/workflows/bundler-friendly.yml b/.github/workflows/bundler-friendly.yml new file mode 100644 index 000000000000..a4faffafd7c4 --- /dev/null +++ b/.github/workflows/bundler-friendly.yml @@ -0,0 +1,61 @@ +name: Bundler_Friendly + +on: + schedule: + # “At 00:00 on Sunday.” https://crontab.guru/#0%C2%A00%C2%A0*%C2%A0*%C2%A00 + - cron: "0 0 * * 0" + pull_request: + paths: + # This workflow file + - ".github/workflows/bundler-friendly.yml" + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + cache: "yarn" + + - name: Install Dependencies + run: yarn install --frozen-lockfile + + - name: Build Package + run: yarn build + + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: dist + path: dist + + webpack: + name: Bundle Prettier with webpack + runs-on: ubuntu-latest + needs: [build] + defaults: + run: + working-directory: scripts/tools/bundle-prettier-with-webpack-test + steps: + - name: Checkout + uses: actions/checkout@v2.4.0 + + - name: Setup Node.js + uses: actions/setup-node@v2.5.1 + + - name: Download Artifact + uses: actions/download-artifact@v2 + with: + name: dist + path: dist + + - name: Install Dependencies + run: yarn install --frozen-lockfile + + - name: Test + run: yarn test diff --git a/.github/workflows/dev-package-test.yml b/.github/workflows/dev-package-test.yml index 7b4270853640..3da079dd4e4e 100644 --- a/.github/workflows/dev-package-test.yml +++ b/.github/workflows/dev-package-test.yml @@ -2,12 +2,14 @@ name: Dev_Package_Test on: schedule: - - cron: "0 0 * * 1" + # “At 00:00 on Sunday.” https://crontab.guru/#0%C2%A00%C2%A0*%C2%A0*%C2%A00 + - cron: "0 0 * * 0" pull_request: paths: - "package.json" - - ".github/workflows/dev-package-test.yml" - "yarn.lock" + # This workflow file + - ".github/workflows/dev-package-test.yml" jobs: test: diff --git a/.github/workflows/prod-test.yml b/.github/workflows/prod-test.yml index 7f2c531f35b4..affdbcb3da8c 100644 --- a/.github/workflows/prod-test.yml +++ b/.github/workflows/prod-test.yml @@ -169,29 +169,3 @@ jobs: - name: Run CLI on Node.js v0.10.48 run: node dist/bin-prettier --version 2>&1 >/dev/null | grep "prettier requires at least version 10.13.0 of Node, please upgrade" || exit 1 - - webpack-friendly: - name: Bundle Prettier with webpack - runs-on: ubuntu-latest - needs: [build] - defaults: - run: - working-directory: scripts/tools/bundle-prettier-with-webpack-test - steps: - - name: Checkout - uses: actions/checkout@v2.4.0 - - - name: Setup Node.js - uses: actions/setup-node@v2.5.1 - - - name: Download Artifact - uses: actions/download-artifact@v2 - with: - name: dist - path: dist - - - name: Install Dependencies - run: yarn install --frozen-lockfile - - - name: Test - run: yarn test diff --git a/scripts/tools/bundle-prettier-with-webpack-test/index.js b/scripts/tools/bundle-prettier-with-webpack-test/index.js index 2d5a53885c58..6b9f38e66338 100644 --- a/scripts/tools/bundle-prettier-with-webpack-test/index.js +++ b/scripts/tools/bundle-prettier-with-webpack-test/index.js @@ -1,6 +1,7 @@ import { fileURLToPath } from "node:url"; import path from "node:path"; import crypto from "node:crypto"; +import fs from "node:fs/promises"; import webpack from "webpack"; import { DIST_DIR } from "../../../scripts/utils/index.mjs"; @@ -32,24 +33,43 @@ const TEMPORARY_DIRECTORY = fileURLToPath(new URL("./.tmp", import.meta.url)); /* `require` in `parser-typescript.js`, #12338 */ (async () => { - const PROBLEMATIC_WARNING_MESSAGE = - "Critical dependency: require function is used in a way in which dependencies cannot be statically extracted"; - - const stats = await runWebpack({ - mode: "production", - entry: path.join(DIST_DIR, "parser-typescript.js"), - output: { - path: TEMPORARY_DIRECTORY, - filename: getRandomFileName("output"), - }, - }); - const result = stats.toJson(); - const { warnings } = result; - const error = warnings.find( - ({ message }) => message === PROBLEMATIC_WARNING_MESSAGE - ); - if (error) { - console.error(error); - throw new Error("Unexpected webpack warning."); + const files = await fs.readdir(DIST_DIR); + for (const file of files) { + if ( + !( + file.startsWith("parser-") || + file === "standalone.js" || + file === "doc.js" + ) + ) { + continue; + } + + console.log(`Testing ${file}: `); + + const stats = await runWebpack({ + mode: "production", + entry: path.join(DIST_DIR, file), + output: { + path: TEMPORARY_DIRECTORY, + filename: getRandomFileName(file), + }, + }); + const result = stats.toJson(); + const warnings = result.warnings.filter( + ({ message }) => + !( + message.startsWith("entrypoint size limit:") || + message.startsWith("asset size limit:") || + message.startsWith("webpack performance recommendations:") + ) + ); + + if (warnings.length > 0) { + console.log(warnings); + throw new Error("Unexpected webpack warning."); + } + + console.log("Passed."); } })(); From a48dc5dc32ec1b0efca9242a8b5ddddff35a2500 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 18 Mar 2022 14:47:34 +0800 Subject: [PATCH 04/14] Remove dynamic require --- scripts/build/config.mjs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/build/config.mjs b/scripts/build/config.mjs index 7b03ed0a467c..5c9dd53c7f51 100644 --- a/scripts/build/config.mjs +++ b/scripts/build/config.mjs @@ -92,6 +92,15 @@ const parsers = [ find: "typescriptVersionIsAtLeast[version] = semverCheck(version);", replacement: "typescriptVersionIsAtLeast[version] = true;", }, + // This cause webpack warn `Critical dependency: require function is used in a way in which dependencies cannot be statically extracted` + // #12338 + { + file: require.resolve( + "@typescript-eslint/typescript-estree/dist/create-program/shared.js" + ), + find: "moduleResolver = require(moduleResolverPath);", + replacement: "throw new Error('Dynamic require is not supported');", + }, ...Object.entries({ // `typescript/lib/typescript.js` expose extra global objects From 7e8456920ff8c79801608120624ab9a8e5c6a818 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 18 Mar 2022 15:22:42 +0800 Subject: [PATCH 05/14] Remove another `require` --- scripts/build/config.mjs | 26 ++++++++++++++++++- .../build/esbuild-plugins/replace-text.mjs | 26 +++++++++++++++---- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/scripts/build/config.mjs b/scripts/build/config.mjs index 5c9dd53c7f51..c9ec96242cf7 100644 --- a/scripts/build/config.mjs +++ b/scripts/build/config.mjs @@ -92,7 +92,7 @@ const parsers = [ find: "typescriptVersionIsAtLeast[version] = semverCheck(version);", replacement: "typescriptVersionIsAtLeast[version] = true;", }, - // This cause webpack warn `Critical dependency: require function is used in a way in which dependencies cannot be statically extracted` + // The next two replacement fixed webpack warning `Critical dependency: require function is used in a way in which dependencies cannot be statically extracted` // #12338 { file: require.resolve( @@ -101,6 +101,30 @@ const parsers = [ find: "moduleResolver = require(moduleResolverPath);", replacement: "throw new Error('Dynamic require is not supported');", }, + { + file: require.resolve("typescript"), + process(text) { + const lines = text.split("\n"); + const functionStartLine = lines.findIndex((line) => + line.includes("function tryGetNodePerformanceHooks() {") + ); + if (functionStartLine === -1) { + throw new Error("Unexpected text."); + } + const lineText = lines[functionStartLine]; + const { indentText } = lineText.match(/^(?\s+)\S/).groups; + const functionTotalLines = + lines + .slice(functionStartLine) + .findIndex((line) => line.startsWith(`${indentText}}`)) + 1; + lines.splice( + functionStartLine, + functionTotalLines, + "function tryGetNodePerformanceHooks() {}" + ); + return lines.join("\n"); + }, + }, ...Object.entries({ // `typescript/lib/typescript.js` expose extra global objects diff --git a/scripts/build/esbuild-plugins/replace-text.mjs b/scripts/build/esbuild-plugins/replace-text.mjs index a6dcf7289918..2f1b511f7612 100644 --- a/scripts/build/esbuild-plugins/replace-text.mjs +++ b/scripts/build/esbuild-plugins/replace-text.mjs @@ -1,9 +1,5 @@ import fs from "node:fs/promises"; -function replaceText(text, options) { - return text.replaceAll(options.find, options.replacement); -} - export default function esbuildPluginReplaceText({ filter = /./, replacements, @@ -12,6 +8,26 @@ export default function esbuildPluginReplaceText({ if (!replacement.file) { throw new Error("'file' option is required."); } + + if (Object.prototype.hasOwnProperty.call(replacement, "process")) { + if (typeof replacement.process !== "function") { + throw new Error("'process' option should be a function."); + } + + continue; + } + + if ( + !Object.prototype.hasOwnProperty.call(replacement, "find") || + !Object.prototype.hasOwnProperty.call(replacement, "replacement") + ) { + throw new Error( + "'process' or 'find' and 'replacement' option is required." + ); + } + + replacement.process = (text) => + text.replaceAll(replacement.find, replacement.replacement); } return { @@ -24,7 +40,7 @@ export default function esbuildPluginReplaceText({ if (replacement.file !== "*" && replacement.file !== file) { continue; } - text = replaceText(text, replacement); + text = replacement.process(text); } return { contents: text }; From 850a28d51ca51708057fdd5e0b01040002c675ef Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 18 Mar 2022 15:34:02 +0800 Subject: [PATCH 06/14] Simplify replacement with `regexp` --- scripts/build/config.mjs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/scripts/build/config.mjs b/scripts/build/config.mjs index c9ec96242cf7..b6f63fd6bc38 100644 --- a/scripts/build/config.mjs +++ b/scripts/build/config.mjs @@ -104,25 +104,10 @@ const parsers = [ { file: require.resolve("typescript"), process(text) { - const lines = text.split("\n"); - const functionStartLine = lines.findIndex((line) => - line.includes("function tryGetNodePerformanceHooks() {") - ); - if (functionStartLine === -1) { - throw new Error("Unexpected text."); - } - const lineText = lines[functionStartLine]; - const { indentText } = lineText.match(/^(?\s+)\S/).groups; - const functionTotalLines = - lines - .slice(functionStartLine) - .findIndex((line) => line.startsWith(`${indentText}}`)) + 1; - lines.splice( - functionStartLine, - functionTotalLines, + return text.replace( + /(?<=\n)(?\s+)function tryGetNodePerformanceHooks\(\) {.*?\n\k}(?=\n)/s, "function tryGetNodePerformanceHooks() {}" ); - return lines.join("\n"); }, }, From 123d7486cffa181ce429ceccb06d885870919f1b Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 18 Mar 2022 15:42:19 +0800 Subject: [PATCH 07/14] Linting --- scripts/build/esbuild-plugins/replace-text.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build/esbuild-plugins/replace-text.mjs b/scripts/build/esbuild-plugins/replace-text.mjs index 2f1b511f7612..ca9da6bd08ce 100644 --- a/scripts/build/esbuild-plugins/replace-text.mjs +++ b/scripts/build/esbuild-plugins/replace-text.mjs @@ -11,7 +11,7 @@ export default function esbuildPluginReplaceText({ if (Object.prototype.hasOwnProperty.call(replacement, "process")) { if (typeof replacement.process !== "function") { - throw new Error("'process' option should be a function."); + throw new TypeError("'process' option should be a function."); } continue; From cdbb2c547b50b72d97f65d25001b6424481e16b1 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 18 Mar 2022 15:45:14 +0800 Subject: [PATCH 08/14] Minir tweak --- .eslintrc.js | 2 +- .github/workflows/bundler-friendly.yml | 2 +- .gitignore | 2 +- scripts/build/esbuild-plugins/replace-text.mjs | 4 +--- .../index.js | 0 .../package.json | 2 +- .../yarn.lock | 0 7 files changed, 5 insertions(+), 7 deletions(-) rename scripts/tools/{bundle-prettier-with-webpack-test => bundle-test}/index.js (100%) rename scripts/tools/{bundle-prettier-with-webpack-test => bundle-test}/package.json (78%) rename scripts/tools/{bundle-prettier-with-webpack-test => bundle-test}/yarn.lock (100%) diff --git a/.eslintrc.js b/.eslintrc.js index a82be66d80a9..edcebaff7733 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -170,7 +170,7 @@ module.exports = { files: [ "**/*.mjs", "scripts/release/**/*.js", - "scripts/tools/bundle-prettier-with-webpack-test/**/*.js", + "scripts/tools/bundle-test/**/*.js", ], parserOptions: { sourceType: "module", diff --git a/.github/workflows/bundler-friendly.yml b/.github/workflows/bundler-friendly.yml index a4faffafd7c4..29eef2a3aeca 100644 --- a/.github/workflows/bundler-friendly.yml +++ b/.github/workflows/bundler-friendly.yml @@ -40,7 +40,7 @@ jobs: needs: [build] defaults: run: - working-directory: scripts/tools/bundle-prettier-with-webpack-test + working-directory: scripts/tools/bundle-test steps: - name: Checkout uses: actions/checkout@v2.4.0 diff --git a/.gitignore b/.gitignore index bdbcd48b376e..bf4cd0b74a56 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ /node_modules /website/node_modules /scripts/release/node_modules -/scripts/tools/bundle-prettier-with-webpack-test/node_modules +/scripts/tools/bundle-test/node_modules /scripts/tools/eslint-plugin-prettier-internal-rules/node_modules .tmp diff --git a/scripts/build/esbuild-plugins/replace-text.mjs b/scripts/build/esbuild-plugins/replace-text.mjs index ca9da6bd08ce..9a856c4decd6 100644 --- a/scripts/build/esbuild-plugins/replace-text.mjs +++ b/scripts/build/esbuild-plugins/replace-text.mjs @@ -21,9 +21,7 @@ export default function esbuildPluginReplaceText({ !Object.prototype.hasOwnProperty.call(replacement, "find") || !Object.prototype.hasOwnProperty.call(replacement, "replacement") ) { - throw new Error( - "'process' or 'find' and 'replacement' option is required." - ); + throw new Error("'find' and 'replacement' option is required."); } replacement.process = (text) => diff --git a/scripts/tools/bundle-prettier-with-webpack-test/index.js b/scripts/tools/bundle-test/index.js similarity index 100% rename from scripts/tools/bundle-prettier-with-webpack-test/index.js rename to scripts/tools/bundle-test/index.js diff --git a/scripts/tools/bundle-prettier-with-webpack-test/package.json b/scripts/tools/bundle-test/package.json similarity index 78% rename from scripts/tools/bundle-prettier-with-webpack-test/package.json rename to scripts/tools/bundle-test/package.json index 0bf0db923d7d..dd3ef136ac36 100644 --- a/scripts/tools/bundle-prettier-with-webpack-test/package.json +++ b/scripts/tools/bundle-test/package.json @@ -1,5 +1,5 @@ { - "name": "bundle-prettier-with-webpack-test", + "name": "@prettier/bundle-test", "version": "0.0.0", "private": "true", "type": "module", diff --git a/scripts/tools/bundle-prettier-with-webpack-test/yarn.lock b/scripts/tools/bundle-test/yarn.lock similarity index 100% rename from scripts/tools/bundle-prettier-with-webpack-test/yarn.lock rename to scripts/tools/bundle-test/yarn.lock From 0e39bcf2666e862207ff97faab6dcafb3d29cf4a Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 18 Mar 2022 16:02:58 +0800 Subject: [PATCH 09/14] Fix `standalone.js` --- scripts/build/config.mjs | 8 ++++++++ src/main/parser.js | 27 ++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/scripts/build/config.mjs b/scripts/build/config.mjs index b6f63fd6bc38..3dd803ddd600 100644 --- a/scripts/build/config.mjs +++ b/scripts/build/config.mjs @@ -1,6 +1,7 @@ import path from "node:path"; import { createRequire } from "node:module"; import createEsmUtils from "esm-utils"; +import { PROJECT_ROOT } from "../utils/index.mjs"; const { require } = createEsmUtils(import.meta); @@ -280,6 +281,13 @@ const coreBundles = [ require.resolve("./shims/chalk.cjs"), ...replaceDiffPackageEntry("lib/diff/array.js"), }, + replaceText: [ + { + file: path.join(PROJECT_ROOT, "src/main/parser.js"), + find: "return requireParser(opts.parser);", + replacement: "", + }, + ], }, { input: "bin/prettier.js", diff --git a/src/main/parser.js b/src/main/parser.js index ea2ff5b2cc97..bb1285f7dec8 100644 --- a/src/main/parser.js +++ b/src/main/parser.js @@ -50,17 +50,22 @@ function resolveParser(opts, parsers = getParsers(opts)) { ); } - try { - return { - parse: require(path.resolve(process.cwd(), opts.parser)), - astFormat: "estree", - locStart, - locEnd, - }; - } catch { - /* istanbul ignore next */ - throw new ConfigError(`Couldn't resolve parser "${opts.parser}"`); - } + // This line of code will be removed when bundling `standalone.js` + return requireParser(opts.parser); + } +} + +function requireParser(parser) { + try { + return { + parse: require(path.resolve(process.cwd(), parser)), + astFormat: "estree", + locStart, + locEnd, + }; + } catch { + /* istanbul ignore next */ + throw new ConfigError(`Couldn't resolve parser "${parser}"`); } } From d11315ef748f50e8cd965f79e59953b23ec621dc Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 18 Mar 2022 16:18:23 +0800 Subject: [PATCH 10/14] Test ESM files too --- scripts/tools/bundle-test/index.js | 35 ++++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/scripts/tools/bundle-test/index.js b/scripts/tools/bundle-test/index.js index 6b9f38e66338..c7a2df2e6d72 100644 --- a/scripts/tools/bundle-test/index.js +++ b/scripts/tools/bundle-test/index.js @@ -33,26 +33,33 @@ const TEMPORARY_DIRECTORY = fileURLToPath(new URL("./.tmp", import.meta.url)); /* `require` in `parser-typescript.js`, #12338 */ (async () => { - const files = await fs.readdir(DIST_DIR); - for (const file of files) { - if ( - !( - file.startsWith("parser-") || - file === "standalone.js" || - file === "doc.js" + const esmFilesDirectory = path.join(DIST_DIR, "esm"); + + const files = [ + (await fs.readdir(DIST_DIR)) + .filter( + (name) => + name.startsWith("parser-") || + name === "standalone.js" || + name === "doc.js" ) - ) { - continue; - } + .map((name) => ({ name, file: path.join(DIST_DIR, name) })), + (await fs.readdir(esmFilesDirectory)).map((name) => ({ + displayName: `esm/${name}`, + name, + file: path.join(esmFilesDirectory, name), + })), + ].flat(); - console.log(`Testing ${file}: `); + for (const { displayName, name, file } of files) { + console.log(`${displayName || name}: `); const stats = await runWebpack({ mode: "production", - entry: path.join(DIST_DIR, file), + entry: file, output: { path: TEMPORARY_DIRECTORY, - filename: getRandomFileName(file), + filename: getRandomFileName(name), }, }); const result = stats.toJson(); @@ -70,6 +77,6 @@ const TEMPORARY_DIRECTORY = fileURLToPath(new URL("./.tmp", import.meta.url)); throw new Error("Unexpected webpack warning."); } - console.log("Passed."); + console.log(" Passed."); } })(); From a720d143734b95c9d9cd70141207717a21944561 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 18 Mar 2022 16:25:40 +0800 Subject: [PATCH 11/14] Add changelog --- changelog_unreleased/misc/12485.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog_unreleased/misc/12485.md diff --git a/changelog_unreleased/misc/12485.md b/changelog_unreleased/misc/12485.md new file mode 100644 index 000000000000..ba690a3bb216 --- /dev/null +++ b/changelog_unreleased/misc/12485.md @@ -0,0 +1,3 @@ +#### Make artifact friendly for `webpack` (#12485 by @fisker) + +Previously, when bundling our UMD files `standalone.js`, `parser-typescript.js`, `webpack` warn about "Critical dependency: the request of a dependency is an expression", now this is fixed. From 4cbb1b50837376fbc683f051c52a1043e34f043e Mon Sep 17 00:00:00 2001 From: fisker Date: Mon, 21 Mar 2022 09:38:59 +0800 Subject: [PATCH 12/14] Simplify --- scripts/tools/bundle-test/index.js | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/scripts/tools/bundle-test/index.js b/scripts/tools/bundle-test/index.js index c7a2df2e6d72..37bb00986505 100644 --- a/scripts/tools/bundle-test/index.js +++ b/scripts/tools/bundle-test/index.js @@ -1,6 +1,5 @@ import { fileURLToPath } from "node:url"; import path from "node:path"; -import crypto from "node:crypto"; import fs from "node:fs/promises"; import webpack from "webpack"; import { DIST_DIR } from "../../../scripts/utils/index.mjs"; @@ -26,9 +25,6 @@ function runWebpack(config) { }); } -const getRandomFileName = (prefix) => - prefix + "-" + crypto.randomBytes(4).toString("hex").slice(0, 4) + ".js"; - const TEMPORARY_DIRECTORY = fileURLToPath(new URL("./.tmp", import.meta.url)); /* `require` in `parser-typescript.js`, #12338 */ @@ -59,18 +55,12 @@ const TEMPORARY_DIRECTORY = fileURLToPath(new URL("./.tmp", import.meta.url)); entry: file, output: { path: TEMPORARY_DIRECTORY, - filename: getRandomFileName(name), + filename: `${name}.[contenthash:7].js`, }, + performance: { hints: false }, }); const result = stats.toJson(); - const warnings = result.warnings.filter( - ({ message }) => - !( - message.startsWith("entrypoint size limit:") || - message.startsWith("asset size limit:") || - message.startsWith("webpack performance recommendations:") - ) - ); + const { warnings } = result; if (warnings.length > 0) { console.log(warnings); From 917cf6755bd7206516237084fc4ad5e405c7f28a Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 23 Mar 2022 10:07:31 +0800 Subject: [PATCH 13/14] Disable minimize --- scripts/tools/bundle-test/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/tools/bundle-test/index.js b/scripts/tools/bundle-test/index.js index 37bb00986505..7bac6724d10c 100644 --- a/scripts/tools/bundle-test/index.js +++ b/scripts/tools/bundle-test/index.js @@ -58,6 +58,7 @@ const TEMPORARY_DIRECTORY = fileURLToPath(new URL("./.tmp", import.meta.url)); filename: `${name}.[contenthash:7].js`, }, performance: { hints: false }, + optimization: { minimize: false }, }); const result = stats.toJson(); const { warnings } = result; From fe1d81a81b2013cf86cad772fc4ac014bf2f095d Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 23 Mar 2022 10:08:56 +0800 Subject: [PATCH 14/14] Trigger CI when test script changes --- .github/workflows/bundler-friendly.yml | 1 + .github/workflows/eslint-rules.yml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.github/workflows/bundler-friendly.yml b/.github/workflows/bundler-friendly.yml index 29eef2a3aeca..710e16fcd853 100644 --- a/.github/workflows/bundler-friendly.yml +++ b/.github/workflows/bundler-friendly.yml @@ -6,6 +6,7 @@ on: - cron: "0 0 * * 0" pull_request: paths: + - "scripts/tools/bundle-test/**" # This workflow file - ".github/workflows/bundler-friendly.yml" diff --git a/.github/workflows/eslint-rules.yml b/.github/workflows/eslint-rules.yml index 248dec720cd6..475e46651fc6 100644 --- a/.github/workflows/eslint-rules.yml +++ b/.github/workflows/eslint-rules.yml @@ -4,10 +4,12 @@ on: push: paths: - "scripts/tools/eslint-plugin-prettier-internal-rules/**" + # This workflow file - ".github/workflows/eslint-rules.yml" pull_request: paths: - "scripts/tools/eslint-plugin-prettier-internal-rules/**" + # This workflow file - ".github/workflows/eslint-rules.yml" jobs: