2021-05-15 20:09:52 +08:00
|
|
|
import path from "node:path";
|
2023-02-03 11:10:00 +08:00
|
|
|
import url from "node:url";
|
2023-02-23 22:15:18 +09:00
|
|
|
import fs from "node:fs";
|
2022-01-28 18:27:27 +08:00
|
|
|
import { createRequire } from "node:module";
|
2022-01-09 01:15:04 +08:00
|
|
|
import createEsmUtils from "esm-utils";
|
2023-02-23 22:15:18 +09:00
|
|
|
import {
|
|
|
|
|
PROJECT_ROOT,
|
|
|
|
|
DIST_DIR,
|
|
|
|
|
copyFile,
|
|
|
|
|
writeFile,
|
|
|
|
|
} from "../utils/index.mjs";
|
2022-09-25 11:50:59 +08:00
|
|
|
import buildJavascriptModule from "./build-javascript-module.js";
|
|
|
|
|
import buildPackageJson from "./build-package-json.js";
|
|
|
|
|
import buildLicense from "./build-license.js";
|
2022-09-06 20:38:50 +08:00
|
|
|
import modifyTypescriptModule from "./modify-typescript-module.mjs";
|
2023-03-01 15:34:30 +08:00
|
|
|
import { getPackageFile } from "./utils.js";
|
2022-01-09 01:15:04 +08:00
|
|
|
|
2023-02-03 11:10:00 +08:00
|
|
|
const {
|
|
|
|
|
require,
|
|
|
|
|
dirname,
|
|
|
|
|
resolve: importMetaResolve,
|
|
|
|
|
} = createEsmUtils(import.meta);
|
|
|
|
|
const resolveEsmModulePath = async (specifier) =>
|
|
|
|
|
url.fileURLToPath(await importMetaResolve(specifier));
|
2023-02-23 22:15:18 +09:00
|
|
|
const copyFileBuilder = ({ file }) =>
|
|
|
|
|
copyFile(
|
|
|
|
|
path.join(PROJECT_ROOT, file.input),
|
|
|
|
|
path.join(DIST_DIR, file.output.file)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
async function typesFileBuilder({ file }) {
|
|
|
|
|
/**
|
|
|
|
|
* @typedef {{ from: string, to: string }} ImportPathReplacement
|
|
|
|
|
* @typedef {{ [input: string]: Array<ImportPathReplacement> }} ReplacementMap
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** @type {Array<ImportPathReplacement>} */
|
|
|
|
|
const jsParsersImportReplacement = [
|
|
|
|
|
{ from: "../../index.js", to: "../index.js" },
|
|
|
|
|
];
|
|
|
|
|
/** @type {ReplacementMap} */
|
|
|
|
|
const pathReplacementMap = {
|
2023-03-07 08:54:11 +08:00
|
|
|
"src/index.d.ts": [{ from: "./document/public.js", to: "./doc.js" }],
|
2023-02-23 22:15:18 +09:00
|
|
|
"src/language-js/parse/acorn-and-espree.d.ts": jsParsersImportReplacement,
|
|
|
|
|
"src/language-js/parse/angular.d.ts": jsParsersImportReplacement,
|
|
|
|
|
"src/language-js/parse/babel.d.ts": jsParsersImportReplacement,
|
|
|
|
|
"src/language-js/parse/flow.d.ts": jsParsersImportReplacement,
|
|
|
|
|
"src/language-js/parse/meriyah.d.ts": jsParsersImportReplacement,
|
|
|
|
|
"src/language-js/parse/typescript.d.ts": jsParsersImportReplacement,
|
|
|
|
|
};
|
|
|
|
|
const replacements = pathReplacementMap[file.input] ?? [];
|
|
|
|
|
let data = await fs.promises.readFile(file.input, "utf8");
|
|
|
|
|
for (const { from, to } of replacements) {
|
|
|
|
|
data = data.replaceAll(
|
|
|
|
|
new RegExp(` from "${from}";`, "g"),
|
|
|
|
|
` from "${to}";`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
await writeFile(path.join(DIST_DIR, file.output.file), data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getTypesFileConfig({ input: jsFileInput, outputBaseName }) {
|
|
|
|
|
const input = jsFileInput.replace(/\.[cm]?js$/, ".d.ts");
|
|
|
|
|
if (!fs.existsSync(path.join(PROJECT_ROOT, input))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
input,
|
|
|
|
|
output: {
|
|
|
|
|
file: outputBaseName + ".d.ts",
|
|
|
|
|
},
|
|
|
|
|
kind: "types",
|
|
|
|
|
build: typesFileBuilder,
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-05-24 15:30:45 -03:00
|
|
|
|
|
|
|
|
/**
|
2022-09-25 11:50:59 +08:00
|
|
|
* @typedef {Object} BuildOptions
|
|
|
|
|
* @property {object[]?} replaceModule - Module replacements
|
|
|
|
|
* @property {string[]?} target - ESBuild targets
|
|
|
|
|
* @property {string[]?} external - array of paths that should not be included in the final bundle
|
|
|
|
|
* @property {boolean?} minify - disable code minification
|
|
|
|
|
*
|
|
|
|
|
* @typedef {Object} Output
|
2023-02-23 22:15:18 +09:00
|
|
|
* @property {"esm" | "umd" | "cjs" | "text" | "json"} format - File format
|
2022-09-25 11:50:59 +08:00
|
|
|
* @property {string} file - path of the output file in the `dist/` folder
|
|
|
|
|
* @property {string?} umdVariableName - name for the UMD file (for plugins, it'll be `prettierPlugins.${name}`)
|
|
|
|
|
*
|
|
|
|
|
* @typedef {Object} File
|
2023-02-23 22:15:18 +09:00
|
|
|
* @property {string} input - input of the file
|
2022-09-25 11:50:59 +08:00
|
|
|
* @property {Output} output - output of the file
|
2023-02-23 22:15:18 +09:00
|
|
|
* @property {"javascript" | "types" | "meta"} kind - file kind
|
2022-09-25 11:50:59 +08:00
|
|
|
* @property {function} build - file generate function
|
2023-02-23 22:15:18 +09:00
|
|
|
* @property {"node" | "universal"} platform - ESBuild platform
|
2022-09-25 11:50:59 +08:00
|
|
|
* @property {BuildOptions} buildOptions - ESBuild options
|
|
|
|
|
* @property {boolean?} isPlugin - file is a plugin
|
2018-05-24 15:30:45 -03:00
|
|
|
*/
|
|
|
|
|
|
2022-03-15 12:36:13 +08:00
|
|
|
/*
|
|
|
|
|
`diff` use deprecated folder mapping "./" in the "exports" field,
|
2023-03-01 15:34:30 +08:00
|
|
|
so we can't `import("diff/lib/diff/array.js")` directly.
|
2022-03-16 10:24:22 +08:00
|
|
|
To reduce the bundle size, replace the entry with smaller files.
|
2022-03-15 12:36:13 +08:00
|
|
|
|
2023-03-01 15:34:30 +08:00
|
|
|
We can switch to deep import once https://github.com/kpdecker/jsdiff/pull/351 get merged
|
2022-03-15 12:36:13 +08:00
|
|
|
*/
|
|
|
|
|
const replaceDiffPackageEntry = (file) => ({
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile("diff/lib/index.mjs"),
|
|
|
|
|
path: getPackageFile(`diff/${file}`),
|
2022-03-15 12:36:13 +08:00
|
|
|
});
|
|
|
|
|
|
2022-09-25 11:50:59 +08:00
|
|
|
const extensions = {
|
|
|
|
|
esm: ".mjs",
|
|
|
|
|
umd: ".js",
|
|
|
|
|
cjs: ".cjs",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const pluginFiles = [
|
2023-02-16 15:02:41 +08:00
|
|
|
{
|
|
|
|
|
input: "src/language-js/parse/babel.js",
|
|
|
|
|
replaceModule: [
|
|
|
|
|
{
|
|
|
|
|
// We don't use value of JSXText
|
|
|
|
|
module: require.resolve("@babel/parser"),
|
|
|
|
|
process: (text) =>
|
|
|
|
|
text.replaceAll(
|
|
|
|
|
"const entity = entities[desc];",
|
|
|
|
|
"const entity = undefined"
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2022-12-05 10:11:01 +08:00
|
|
|
{
|
|
|
|
|
input: "src/language-js/parse/flow.js",
|
|
|
|
|
replaceModule: [
|
|
|
|
|
{
|
|
|
|
|
module: require.resolve("flow-parser"),
|
|
|
|
|
process: (text) =>
|
|
|
|
|
text
|
|
|
|
|
.replaceAll('require("fs")', "{}")
|
|
|
|
|
.replaceAll('require("constants")', "{}"),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2018-05-24 15:30:45 -03:00
|
|
|
{
|
2021-07-15 09:53:34 +08:00
|
|
|
input: "src/language-js/parse/typescript.js",
|
2022-03-20 14:04:30 +08:00
|
|
|
replaceModule: [
|
2022-03-23 10:21:02 +08:00
|
|
|
{
|
|
|
|
|
module: require.resolve("typescript"),
|
2022-09-06 20:38:50 +08:00
|
|
|
process: modifyTypescriptModule,
|
2022-03-23 10:21:02 +08:00
|
|
|
},
|
2022-10-16 13:36:22 +08:00
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile(
|
2022-10-16 13:36:22 +08:00
|
|
|
"@typescript-eslint/typescript-estree/dist/parser.js"
|
|
|
|
|
),
|
|
|
|
|
process(text) {
|
|
|
|
|
text = text
|
|
|
|
|
.replace('require("./create-program/createDefaultProgram")', "{}")
|
|
|
|
|
.replace('require("./create-program/createIsolatedProgram")', "{}")
|
|
|
|
|
.replace('require("./create-program/createProjectProgram")', "{}")
|
2022-11-06 21:46:46 +08:00
|
|
|
.replace('require("./create-program/useProvidedPrograms")', "{}");
|
|
|
|
|
return text;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile(
|
2022-11-06 21:46:46 +08:00
|
|
|
"@typescript-eslint/typescript-estree/dist/parseSettings/createParseSettings.js"
|
|
|
|
|
),
|
|
|
|
|
process(text) {
|
|
|
|
|
return text
|
2023-02-12 20:09:37 +08:00
|
|
|
.replace('require("./resolveProjectList")', "{}")
|
2022-10-16 13:36:22 +08:00
|
|
|
.replace(
|
2022-11-06 21:46:46 +08:00
|
|
|
'require("../create-program/shared")',
|
2022-10-16 13:36:22 +08:00
|
|
|
"{ensureAbsolutePath: path => path}"
|
|
|
|
|
)
|
|
|
|
|
.replace(
|
|
|
|
|
"process.cwd()",
|
|
|
|
|
JSON.stringify("/prettier-security-dirname-placeholder")
|
|
|
|
|
)
|
|
|
|
|
.replace(
|
2022-11-06 21:46:46 +08:00
|
|
|
"parseSettings.projects = ",
|
|
|
|
|
"parseSettings.projects = [] || "
|
|
|
|
|
);
|
2022-10-16 13:36:22 +08:00
|
|
|
},
|
|
|
|
|
},
|
2022-11-06 21:46:46 +08:00
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile(
|
2022-11-06 21:46:46 +08:00
|
|
|
"@typescript-eslint/typescript-estree/dist/parseSettings/inferSingleRun.js"
|
|
|
|
|
),
|
|
|
|
|
text: "exports.inferSingleRun = () => false;",
|
|
|
|
|
},
|
2023-02-19 11:15:06 +08:00
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile(
|
2023-02-19 11:15:06 +08:00
|
|
|
"@typescript-eslint/typescript-estree/dist/parseSettings/ExpiringCache.js"
|
|
|
|
|
),
|
|
|
|
|
text: "exports.ExpiringCache = class {};",
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile(
|
2023-02-19 11:15:06 +08:00
|
|
|
"@typescript-eslint/typescript-estree/dist/parseSettings/getProjectConfigFiles.js"
|
|
|
|
|
),
|
|
|
|
|
text: "exports.resolveProjectList = () => [];",
|
|
|
|
|
},
|
2022-11-06 21:46:46 +08:00
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile(
|
2022-11-06 21:46:46 +08:00
|
|
|
"@typescript-eslint/typescript-estree/dist/parseSettings/warnAboutTSVersion.js"
|
|
|
|
|
),
|
|
|
|
|
text: "exports.warnAboutTSVersion = () => {};",
|
|
|
|
|
},
|
2022-10-16 13:36:22 +08:00
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile(
|
2022-10-16 13:36:22 +08:00
|
|
|
"@typescript-eslint/typescript-estree/dist/create-program/getScriptKind.js"
|
|
|
|
|
),
|
|
|
|
|
process: (text) =>
|
|
|
|
|
text.replace(
|
|
|
|
|
'require("path")',
|
|
|
|
|
"{extname: file => file.split('.').pop()}"
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile(
|
2022-10-16 13:36:22 +08:00
|
|
|
"@typescript-eslint/typescript-estree/dist/version-check.js"
|
|
|
|
|
),
|
2022-11-06 21:46:46 +08:00
|
|
|
text: "exports.typescriptVersionIsAtLeast = new Proxy({}, {get: () => true})",
|
2022-10-16 13:36:22 +08:00
|
|
|
},
|
2022-10-23 11:19:57 +08:00
|
|
|
// Only needed if `range`/`loc` in parse options is `false`
|
|
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile(
|
2022-10-23 11:19:57 +08:00
|
|
|
"@typescript-eslint/typescript-estree/dist/ast-converter.js"
|
|
|
|
|
),
|
|
|
|
|
process: (text) => text.replace('require("./simple-traverse")', "{}"),
|
|
|
|
|
},
|
2022-03-20 14:04:30 +08:00
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile("debug/src/browser.js"),
|
2022-03-25 16:37:34 +08:00
|
|
|
path: path.join(dirname, "./shims/debug.js"),
|
2022-03-20 14:04:30 +08:00
|
|
|
},
|
2022-03-14 20:02:02 +08:00
|
|
|
],
|
2018-05-24 15:30:45 -03:00
|
|
|
},
|
2020-10-13 09:14:02 +08:00
|
|
|
{
|
2022-01-28 15:25:30 +08:00
|
|
|
input: "src/language-js/parse/acorn-and-espree.js",
|
2022-10-06 15:20:19 +08:00
|
|
|
umdPropertyName: "acornAndEspree",
|
2022-03-20 14:04:30 +08:00
|
|
|
replaceModule: [
|
2022-03-14 20:02:02 +08:00
|
|
|
{
|
2022-03-20 14:04:30 +08:00
|
|
|
module: require.resolve("espree"),
|
2023-02-16 15:02:41 +08:00
|
|
|
process: (text) =>
|
|
|
|
|
text
|
|
|
|
|
.replaceAll(
|
|
|
|
|
/exports\.(?:Syntax|VisitorKeys|latestEcmaVersion|supportedEcmaVersions|tokenize|version) = .*?;/g,
|
|
|
|
|
""
|
|
|
|
|
)
|
|
|
|
|
.replaceAll(
|
|
|
|
|
/const (Syntax|VisitorKeys|latestEcmaVersion|supportedEcmaVersions) = /g,
|
|
|
|
|
"const $1 = undefined && "
|
|
|
|
|
)
|
|
|
|
|
.replace("require('eslint-visitor-keys')", "{}"),
|
2022-03-14 20:02:02 +08:00
|
|
|
},
|
|
|
|
|
{
|
2023-02-16 15:02:41 +08:00
|
|
|
// We don't use value of JSXText
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile("acorn-jsx/xhtml.js"),
|
2023-02-16 15:02:41 +08:00
|
|
|
text: "module.exports = {};",
|
2022-03-14 20:02:02 +08:00
|
|
|
},
|
|
|
|
|
],
|
2020-10-13 09:14:02 +08:00
|
|
|
},
|
2023-02-03 11:10:00 +08:00
|
|
|
{
|
|
|
|
|
input: "src/language-js/parse/meriyah.js",
|
|
|
|
|
replaceModule: [
|
|
|
|
|
{
|
|
|
|
|
// We don't use value of JSXText
|
|
|
|
|
module: await resolveEsmModulePath("meriyah"),
|
|
|
|
|
find: "parser.tokenValue = decodeHTMLStrict(raw);",
|
|
|
|
|
replacement: "parser.tokenValue = raw;",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2018-11-04 23:03:07 +08:00
|
|
|
{
|
2021-07-15 09:53:34 +08:00
|
|
|
input: "src/language-js/parse/angular.js",
|
2022-10-11 11:26:30 +08:00
|
|
|
replaceModule: [
|
|
|
|
|
// We only use a small set of `@angular/compiler` from `esm2020/src/expression_parser/`
|
|
|
|
|
// Those files can't be imported, they also not directly runnable, because `.mjs` extension is missing
|
|
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile("@angular/compiler/fesm2020/compiler.mjs"),
|
2022-10-11 11:26:30 +08:00
|
|
|
text: /* indent */ `
|
|
|
|
|
export * from '../esm2020/src/expression_parser/ast.mjs';
|
|
|
|
|
export {Lexer} from '../esm2020/src/expression_parser/lexer.mjs';
|
|
|
|
|
export {Parser} from '../esm2020/src/expression_parser/parser.mjs';
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
...[
|
|
|
|
|
"expression_parser/lexer.mjs",
|
|
|
|
|
"expression_parser/parser.mjs",
|
|
|
|
|
"ml_parser/interpolation_config.mjs",
|
|
|
|
|
].map((file) => ({
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile(`@angular/compiler/esm2020/src/${file}`),
|
2022-10-11 11:26:30 +08:00
|
|
|
process: (text) =>
|
|
|
|
|
text.replaceAll(/(?<=import .*? from )'(.{1,2}\/.*)'/g, "'$1.mjs'"),
|
|
|
|
|
})),
|
|
|
|
|
],
|
2018-11-04 23:03:07 +08:00
|
|
|
},
|
2018-05-24 15:30:45 -03:00
|
|
|
{
|
|
|
|
|
input: "src/language-css/parser-postcss.js",
|
2022-03-20 14:04:30 +08:00
|
|
|
replaceModule: [
|
2022-03-20 21:56:09 +08:00
|
|
|
// The following two replacements prevent load `source-map` module
|
|
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile("postcss/lib/previous-map.js"),
|
2022-03-20 21:56:09 +08:00
|
|
|
text: "module.exports = class {};",
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile("postcss/lib/map-generator.js"),
|
2022-03-20 21:56:09 +08:00
|
|
|
text: "module.exports = class { generate() {} };",
|
|
|
|
|
},
|
2023-03-01 15:34:30 +08:00
|
|
|
{
|
|
|
|
|
module: getPackageFile("postcss/lib/input.js"),
|
|
|
|
|
process: (text) =>
|
|
|
|
|
text.replace("require('url')", "{}").replace("require('path')", "{}"),
|
|
|
|
|
},
|
|
|
|
|
// `postcss-values-parser` uses constructor.name, it will be changed by bundler
|
|
|
|
|
// https://github.com/shellscape/postcss-values-parser/blob/c00f858ab8c86ce9f06fdb702e8f26376f467248/lib/parser.js#L499
|
|
|
|
|
{
|
|
|
|
|
module: getPackageFile("postcss-values-parser/lib/parser.js"),
|
|
|
|
|
find: "node.constructor.name === 'Word'",
|
|
|
|
|
replacement: "node.type === 'word'",
|
|
|
|
|
},
|
2022-10-29 16:28:20 +08:00
|
|
|
// Prevent `node:util`, `node:utl`, and `node:path` shim
|
|
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile("postcss-values-parser/lib/tokenize.js"),
|
2022-10-29 16:28:20 +08:00
|
|
|
process: (text) =>
|
|
|
|
|
text
|
|
|
|
|
.replace("require('util')", "{}")
|
|
|
|
|
.replace(
|
|
|
|
|
"let message = util.format('Unclosed %s at line: %d, column: %d, token: %d', what, line, pos - offset, pos);",
|
|
|
|
|
"let message = `Unclosed ${what} at line: ${line}, column: ${pos - offset}, token: ${pos}`;"
|
|
|
|
|
)
|
|
|
|
|
.replace(
|
|
|
|
|
"let message = util.format('Syntax error at line: %d, column: %d, token: %d', line, pos - offset, pos);",
|
|
|
|
|
"let message = `Syntax error at line: ${line}, column: ${pos - offset}, token: ${pos}`;"
|
|
|
|
|
),
|
|
|
|
|
},
|
2022-03-14 20:02:02 +08:00
|
|
|
],
|
2018-05-24 15:30:45 -03:00
|
|
|
},
|
2022-09-25 11:50:59 +08:00
|
|
|
"src/language-graphql/parser-graphql.js",
|
2018-05-24 15:30:45 -03:00
|
|
|
{
|
2020-01-29 17:45:57 +08:00
|
|
|
input: "src/language-markdown/parser-markdown.js",
|
2022-03-20 14:04:30 +08:00
|
|
|
replaceModule: [
|
|
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile("parse-entities/decode-entity.browser.js"),
|
|
|
|
|
path: getPackageFile("parse-entities/decode-entity.js"),
|
2022-03-20 14:04:30 +08:00
|
|
|
},
|
|
|
|
|
],
|
2018-05-24 15:30:45 -03:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input: "src/language-handlebars/parser-glimmer.js",
|
2022-08-10 19:32:44 +08:00
|
|
|
replaceModule: [
|
|
|
|
|
// See comment in `src/language-handlebars/parser-glimmer.js` file
|
|
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile(
|
2022-08-10 19:32:44 +08:00
|
|
|
"@glimmer/syntax/dist/commonjs/es2017/lib/parser/tokenizer-event-handlers.js"
|
|
|
|
|
),
|
2023-03-01 15:34:30 +08:00
|
|
|
path: getPackageFile(
|
2022-08-10 19:32:44 +08:00
|
|
|
"@glimmer/syntax/dist/modules/es2017/lib/parser/tokenizer-event-handlers.js"
|
|
|
|
|
),
|
|
|
|
|
},
|
2022-10-22 23:35:19 +08:00
|
|
|
// This passed to plugins, our plugin don't need access to the options
|
|
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile(
|
2022-10-22 23:35:19 +08:00
|
|
|
"@glimmer/syntax/dist/modules/es2017/lib/parser/tokenizer-event-handlers.js"
|
|
|
|
|
),
|
|
|
|
|
process: (text) =>
|
|
|
|
|
text.replace(/\nconst syntax = \{.*?\n\};/su, "\nconst syntax = {};"),
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-03-01 15:34:30 +08:00
|
|
|
module: getPackageFile("@handlebars/parser/dist/esm/index.js"),
|
|
|
|
|
path: getPackageFile("@handlebars/parser/dist/esm/parse.js"),
|
2022-10-22 23:35:19 +08:00
|
|
|
},
|
2022-08-10 19:32:44 +08:00
|
|
|
],
|
2018-05-24 15:30:45 -03:00
|
|
|
},
|
2022-09-25 11:50:59 +08:00
|
|
|
"src/language-html/parser-html.js",
|
|
|
|
|
"src/language-yaml/parser-yaml.js",
|
|
|
|
|
].map((file) => {
|
|
|
|
|
if (typeof file === "string") {
|
|
|
|
|
file = { input: file };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let { input, umdPropertyName, outputBaseName, ...buildOptions } = file;
|
|
|
|
|
|
|
|
|
|
outputBaseName ??= input.match(
|
|
|
|
|
/(?:parser-|parse\/)(?<outputBaseName>.*?)\.js$/
|
|
|
|
|
).groups.outputBaseName;
|
2022-10-06 15:20:19 +08:00
|
|
|
|
2022-09-25 11:50:59 +08:00
|
|
|
const umdVariableName = `prettierPlugins.${
|
|
|
|
|
umdPropertyName ?? outputBaseName
|
|
|
|
|
}`;
|
2021-07-15 09:53:34 +08:00
|
|
|
|
|
|
|
|
return {
|
2022-09-25 11:50:59 +08:00
|
|
|
input,
|
2022-10-06 15:20:19 +08:00
|
|
|
outputBaseName: `plugins/${outputBaseName}`,
|
2022-09-25 11:50:59 +08:00
|
|
|
umdVariableName,
|
|
|
|
|
buildOptions,
|
|
|
|
|
isPlugin: true,
|
2021-07-15 09:53:34 +08:00
|
|
|
};
|
|
|
|
|
});
|
2018-05-24 15:30:45 -03:00
|
|
|
|
2022-09-25 11:50:59 +08:00
|
|
|
const nonPluginUniversalFiles = [
|
|
|
|
|
{
|
2023-03-07 08:54:11 +08:00
|
|
|
input: "src/document/public.js",
|
2022-09-25 11:50:59 +08:00
|
|
|
outputBaseName: "doc",
|
|
|
|
|
umdVariableName: "doc",
|
|
|
|
|
minify: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input: "src/standalone.js",
|
|
|
|
|
umdVariableName: "prettier",
|
|
|
|
|
replaceModule: [
|
|
|
|
|
{
|
|
|
|
|
module: require.resolve("@babel/highlight"),
|
|
|
|
|
path: path.join(dirname, "./shims/babel-highlight.js"),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
module: createRequire(require.resolve("vnopts")).resolve("chalk"),
|
|
|
|
|
path: path.join(dirname, "./shims/chalk.js"),
|
|
|
|
|
},
|
|
|
|
|
replaceDiffPackageEntry("lib/diff/array.js"),
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
].map((file) => {
|
|
|
|
|
const {
|
|
|
|
|
input,
|
|
|
|
|
outputBaseName = path.basename(input, ".js"),
|
|
|
|
|
umdVariableName,
|
|
|
|
|
...buildOptions
|
|
|
|
|
} = file;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
input,
|
|
|
|
|
outputBaseName,
|
|
|
|
|
umdVariableName,
|
|
|
|
|
buildOptions,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const universalFiles = [...nonPluginUniversalFiles, ...pluginFiles].flatMap(
|
|
|
|
|
(file) => {
|
|
|
|
|
let { input, outputBaseName, umdVariableName, buildOptions, isPlugin } =
|
|
|
|
|
file;
|
|
|
|
|
|
|
|
|
|
outputBaseName ??= path.basename(input);
|
|
|
|
|
|
|
|
|
|
return [
|
2023-02-23 22:15:18 +09:00
|
|
|
...[
|
|
|
|
|
{
|
|
|
|
|
format: "esm",
|
|
|
|
|
file: `${outputBaseName}${extensions.esm}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: "umd",
|
|
|
|
|
file: `${outputBaseName}${extensions.umd}`,
|
|
|
|
|
umdVariableName,
|
|
|
|
|
},
|
|
|
|
|
].map((output) => ({
|
|
|
|
|
input,
|
|
|
|
|
output,
|
|
|
|
|
platform: "universal",
|
|
|
|
|
buildOptions,
|
|
|
|
|
isPlugin,
|
|
|
|
|
build: buildJavascriptModule,
|
|
|
|
|
kind: "javascript",
|
|
|
|
|
})),
|
|
|
|
|
getTypesFileConfig({ input, outputBaseName }),
|
|
|
|
|
];
|
2022-09-25 11:50:59 +08:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const nodejsFiles = [
|
2018-05-24 15:30:45 -03:00
|
|
|
{
|
2021-05-27 08:54:42 +08:00
|
|
|
input: "src/index.js",
|
2022-03-20 14:04:30 +08:00
|
|
|
replaceModule: [
|
2022-03-14 20:02:02 +08:00
|
|
|
{
|
2022-03-20 14:04:30 +08:00
|
|
|
module: require.resolve("@iarna/toml/lib/toml-parser.js"),
|
2022-03-14 20:02:02 +08:00
|
|
|
find: "const utilInspect = eval(\"require('util').inspect\")",
|
|
|
|
|
replacement: "const utilInspect = require('util').inspect",
|
|
|
|
|
},
|
2022-03-21 10:37:57 +08:00
|
|
|
// `editorconfig` use a older version of `semver` and only uses `semver.gte`
|
|
|
|
|
{
|
|
|
|
|
module: require.resolve("editorconfig"),
|
|
|
|
|
find: 'var semver = __importStar(require("semver"));',
|
|
|
|
|
replacement: `
|
|
|
|
|
var semver = {
|
|
|
|
|
gte: require(${JSON.stringify(
|
|
|
|
|
require.resolve("semver/functions/gte")
|
|
|
|
|
)})
|
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
},
|
2022-05-10 15:42:11 +08:00
|
|
|
{
|
|
|
|
|
module: require.resolve("n-readlines"),
|
|
|
|
|
find: "const readBuffer = new Buffer(this.options.readChunk);",
|
|
|
|
|
replacement: "const readBuffer = Buffer.alloc(this.options.readChunk);",
|
|
|
|
|
},
|
2022-03-20 14:04:30 +08:00
|
|
|
replaceDiffPackageEntry("lib/diff/array.js"),
|
2022-03-14 20:02:02 +08:00
|
|
|
],
|
2018-05-24 15:30:45 -03:00
|
|
|
},
|
2022-09-23 09:46:18 +08:00
|
|
|
{
|
|
|
|
|
input: "src/index.cjs",
|
|
|
|
|
},
|
2018-05-24 15:30:45 -03:00
|
|
|
{
|
2022-04-03 00:04:45 +08:00
|
|
|
input: "bin/prettier.cjs",
|
2022-10-06 15:20:19 +08:00
|
|
|
outputBaseName: "bin/prettier",
|
2022-09-25 11:50:59 +08:00
|
|
|
target: ["node0.10"],
|
2022-08-11 14:08:08 +08:00
|
|
|
replaceModule: [
|
|
|
|
|
{
|
|
|
|
|
module: path.join(PROJECT_ROOT, "bin/prettier.cjs"),
|
2022-10-06 15:20:19 +08:00
|
|
|
process: (text) =>
|
|
|
|
|
text.replace('"../src/cli/index.js"', '"../internal/cli.mjs"'),
|
2022-08-11 14:08:08 +08:00
|
|
|
},
|
|
|
|
|
],
|
2022-03-13 22:47:02 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input: "src/cli/index.js",
|
2022-10-06 15:20:19 +08:00
|
|
|
outputBaseName: "internal/cli",
|
2021-05-27 08:54:42 +08:00
|
|
|
external: ["benchmark"],
|
2022-03-20 14:04:30 +08:00
|
|
|
replaceModule: [replaceDiffPackageEntry("lib/patch/create.js")],
|
2018-05-24 15:30:45 -03:00
|
|
|
},
|
|
|
|
|
{
|
2022-07-12 10:20:11 +08:00
|
|
|
input: "src/common/third-party.js",
|
2022-10-06 15:20:19 +08:00
|
|
|
outputBaseName: "internal/third-party",
|
2022-03-20 14:04:30 +08:00
|
|
|
replaceModule: [
|
2020-01-10 09:21:44 +08:00
|
|
|
// cosmiconfig@6 -> import-fresh can't find parentModule, since module is bundled
|
2022-03-20 14:04:30 +08:00
|
|
|
{
|
|
|
|
|
module: require.resolve("parent-module"),
|
2022-03-25 16:37:34 +08:00
|
|
|
path: path.join(dirname, "./shims/parent-module.cjs"),
|
2022-03-20 14:04:30 +08:00
|
|
|
},
|
|
|
|
|
],
|
2018-05-24 15:30:45 -03:00
|
|
|
},
|
2023-02-23 22:15:18 +09:00
|
|
|
].flatMap((file) => {
|
2022-09-25 11:50:59 +08:00
|
|
|
let { input, output, outputBaseName, ...buildOptions } = file;
|
2021-05-27 08:54:42 +08:00
|
|
|
|
2022-09-25 11:50:59 +08:00
|
|
|
const format = input.endsWith(".cjs") ? "cjs" : "esm";
|
2022-10-06 15:20:19 +08:00
|
|
|
outputBaseName ??= path.basename(input, path.extname(input));
|
2022-09-25 11:50:59 +08:00
|
|
|
|
2023-02-23 22:15:18 +09:00
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
input,
|
|
|
|
|
output: {
|
|
|
|
|
format,
|
|
|
|
|
file: `${outputBaseName}${extensions[format]}`,
|
|
|
|
|
},
|
|
|
|
|
platform: "node",
|
|
|
|
|
buildOptions,
|
|
|
|
|
build: buildJavascriptModule,
|
|
|
|
|
kind: "javascript",
|
2022-09-25 11:50:59 +08:00
|
|
|
},
|
2023-02-23 22:15:18 +09:00
|
|
|
getTypesFileConfig({ input, outputBaseName }),
|
|
|
|
|
];
|
2022-09-25 11:50:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const metaFiles = [
|
|
|
|
|
{
|
|
|
|
|
input: "package.json",
|
|
|
|
|
output: {
|
|
|
|
|
format: "json",
|
|
|
|
|
},
|
|
|
|
|
build: buildPackageJson,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-02-23 22:15:18 +09:00
|
|
|
input: "README.md",
|
|
|
|
|
build: copyFileBuilder,
|
2022-09-25 11:50:59 +08:00
|
|
|
},
|
|
|
|
|
{
|
2023-02-23 22:15:18 +09:00
|
|
|
input: "LICENSE",
|
2022-09-25 11:50:59 +08:00
|
|
|
build: buildLicense,
|
|
|
|
|
},
|
2023-02-23 22:15:18 +09:00
|
|
|
].map((file) => ({
|
|
|
|
|
...file,
|
|
|
|
|
output: { file: file.input, ...file.output },
|
|
|
|
|
kind: "meta",
|
|
|
|
|
}));
|
2022-09-25 11:50:59 +08:00
|
|
|
|
|
|
|
|
/** @type {Files[]} */
|
2023-02-23 22:15:18 +09:00
|
|
|
const files = [...nodejsFiles, ...universalFiles, ...metaFiles].filter(Boolean);
|
2022-09-25 11:50:59 +08:00
|
|
|
export default files;
|