New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove require
from UMD bundles
#12485
Merged
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
76d9ecc
Test Issue 12338
fisker 23004ca
Simplify test script
fisker ea8000b
Add as a weekly job
fisker a48dc5d
Remove dynamic require
fisker 7e84569
Remove another `require`
fisker 850a28d
Simplify replacement with `regexp`
fisker 123d748
Linting
fisker cdbb2c5
Minir tweak
fisker 0e39bcf
Fix `standalone.js`
fisker d11315e
Test ESM files too
fisker a720d14
Add changelog
fisker f41a77d
Merge branch 'main' into issue-12338
fisker 4cbb1b5
Simplify
fisker 917cf67
Disable minimize
fisker fe1d81a
Trigger CI when test script changes
fisker File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,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-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
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
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,82 @@ | ||
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"; | ||
|
||
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 () => { | ||
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: getRandomFileName(name), | ||
}, | ||
}); | ||
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."); | ||
} | ||
})(); |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexander-akait Do you know how to prevent webpack write file to disk?