Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
require
from UMD bundles (#12485)
- Loading branch information
Showing
13 changed files
with
699 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.tmp | ||
!/*.js | ||
/tests/format/**/*.js | ||
/tests/integration/cli/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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: | ||
- "scripts/tools/bundle-test/**" | ||
# 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-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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.tmp | ||
dist/ | ||
.cache/ | ||
coverage/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { fileURLToPath } from "node:url"; | ||
import path from "node:path"; | ||
import fs from "node:fs/promises"; | ||
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 TEMPORARY_DIRECTORY = fileURLToPath(new URL("./.tmp", import.meta.url)); | ||
|
||
/* `require` in `parser-typescript.js`, #12338 */ | ||
(async () => { | ||
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" | ||
) | ||
.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(); | ||
|
||
for (const { displayName, name, file } of files) { | ||
console.log(`${displayName || name}: `); | ||
|
||
const stats = await runWebpack({ | ||
mode: "production", | ||
entry: file, | ||
output: { | ||
path: TEMPORARY_DIRECTORY, | ||
filename: `${name}.[contenthash:7].js`, | ||
}, | ||
performance: { hints: false }, | ||
optimization: { minimize: false }, | ||
}); | ||
const result = stats.toJson(); | ||
const { warnings } = result; | ||
|
||
if (warnings.length > 0) { | ||
console.log(warnings); | ||
throw new Error("Unexpected webpack warning."); | ||
} | ||
|
||
console.log(" Passed."); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@prettier/bundle-test", | ||
"version": "0.0.0", | ||
"private": "true", | ||
"type": "module", | ||
"devDependencies": { | ||
"webpack": "5.70.0" | ||
}, | ||
"scripts": { | ||
"test": "node ./index.js" | ||
} | ||
} |
Oops, something went wrong.