Migrated version.evaluate.cjs to ES Module (#17347)
This commit is contained in:
1 parent
c992b0bc1b
commit
4b2db262b7
7 files changed
+17
-17
No files matched your search
+7
-1
@@ -40,9 +40,15 @@ if (isProduction) {
|
||||
);
|
||||
}
|
||||
|
||||
if (SKIP_TESTS_WITH_NEW_SYNTAX) {
|
||||
if (SKIP_TESTS_WITH_NEW_SYNTAX || process.versions.node.startsWith("16.")) {
|
||||
// Uses import attributes
|
||||
testPathIgnorePatterns.push(
|
||||
"<rootDir>/tests/integration/__tests__/help-options.js",
|
||||
);
|
||||
}
|
||||
|
||||
if (SKIP_TESTS_WITH_NEW_SYNTAX) {
|
||||
testPathIgnorePatterns.push(
|
||||
"<rootDir>/tests/integration/__tests__/plugin-parsers.js",
|
||||
"<rootDir>/tests/integration/__tests__/normalize-doc.js",
|
||||
"<rootDir>/tests/integration/__tests__/doc-utils-clean-doc.js",
|
||||
|
||||
@@ -6,14 +6,11 @@ export default function esbuildPluginEvaluate() {
|
||||
return {
|
||||
name: "evaluate",
|
||||
setup(build) {
|
||||
const { format } = build.initialOptions;
|
||||
|
||||
build.onLoad(
|
||||
{ filter: /\.evaluate\.c?js$/, namespace: "file" },
|
||||
{ filter: /\.evaluate\.[cm]?js$/, namespace: "file" },
|
||||
async ({ path }) => {
|
||||
const module = await import(url.pathToFileURL(path));
|
||||
const text = Object.entries(module)
|
||||
.filter(([specifier]) => specifier !== "module.exports")
|
||||
.map(([specifier, value]) => {
|
||||
const code =
|
||||
value instanceof RegExp
|
||||
@@ -21,18 +18,14 @@ export default function esbuildPluginEvaluate() {
|
||||
: serialize(value, { space: 2 });
|
||||
|
||||
if (specifier === "default") {
|
||||
return format === "cjs"
|
||||
? `module.exports = ${code};`
|
||||
: `export default ${code};`;
|
||||
return `export default ${code};`;
|
||||
}
|
||||
|
||||
if (!isValidIdentifier(specifier)) {
|
||||
throw new Error(`${specifier} is not a valid specifier`);
|
||||
}
|
||||
|
||||
return format === "cjs"
|
||||
? `exports.${specifier} = ${code};`
|
||||
: `export const ${specifier} = ${code};`;
|
||||
return `export const ${specifier} = ${code};`;
|
||||
})
|
||||
.join("\n");
|
||||
return { contents: text };
|
||||
|
||||
+2
-1
@@ -41,6 +41,7 @@ prettier.__debug = debugApis;
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
prettier.util = require("./utils/public.js");
|
||||
prettier.doc = require("./document/public.js");
|
||||
prettier.version = require("./main/version.evaluate.js").default;
|
||||
} else {
|
||||
Object.defineProperties(prettier, {
|
||||
util: {
|
||||
@@ -70,7 +71,7 @@ if (process.env.NODE_ENV === "production") {
|
||||
},
|
||||
},
|
||||
});
|
||||
prettier.version = require("../package.json").version;
|
||||
}
|
||||
prettier.version = require("./main/version.evaluate.cjs");
|
||||
|
||||
module.exports = prettier;
|
||||
+1
-1
@@ -140,5 +140,5 @@ export {
|
||||
resolveConfigFile,
|
||||
};
|
||||
export * as doc from "./document/public.js";
|
||||
export { default as version } from "./main/version.evaluate.cjs";
|
||||
export { default as version } from "./main/version.evaluate.js";
|
||||
export * as util from "./utils/public.js";
|
||||
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = require("../../package.json").version;
|
||||
@@ -0,0 +1,3 @@
|
||||
import packageJson from "../../package.json" with { type: "json" };
|
||||
|
||||
export default packageJson.version;
|
||||
+1
-1
@@ -52,5 +52,5 @@ export {
|
||||
getSupportInfo,
|
||||
};
|
||||
export * as doc from "./document/public.js";
|
||||
export { default as version } from "./main/version.evaluate.cjs";
|
||||
export { default as version } from "./main/version.evaluate.js";
|
||||
export * as util from "./utils/public.js";
|
||||
Reference in new issue
Block a user