Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
612 additions
and
4 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
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,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."); | ||
} | ||
})(); |
12 changes: 12 additions & 0 deletions
12
scripts/tools/bundle-prettier-with-webpack-test/package.json
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": "bundle-prettier-with-webpack-test", | ||
"version": "0.0.0", | ||
"private": "true", | ||
"type": "module", | ||
"devDependencies": { | ||
"webpack": "5.70.0" | ||
}, | ||
"scripts": { | ||
"test": "node ./index.js" | ||
} | ||
} |
Oops, something went wrong.