Bundle package into dist/prettier/ (#15825)
This commit is contained in:
1 parent
004e1e0028
commit
377b231a5d
16 files changed
+82
-54
No files matched your search
@@ -152,7 +152,7 @@ jobs:
|
||||
run: node -v | grep "v0.10.48" || exit 1
|
||||
|
||||
- name: Run CLI on Node.js v0.10.48
|
||||
run: node dist/bin/prettier.cjs --version 2>&1 >/dev/null | grep "prettier requires at least version 14 of Node, please upgrade" || exit 1
|
||||
run: node dist/prettier/bin/prettier.cjs --version 2>&1 >/dev/null | grep "prettier requires at least version 14 of Node, please upgrade" || exit 1
|
||||
|
||||
preview:
|
||||
if: github.event_name == 'pull_request' && github.repository == 'prettier/prettier'
|
||||
@@ -178,4 +178,4 @@ jobs:
|
||||
- name: Release
|
||||
run: |
|
||||
npx pkg-pr-new publish --compact
|
||||
working-directory: dist
|
||||
working-directory: dist/prettier
|
||||
+1
-1
@@ -13,7 +13,7 @@ const SKIP_PRODUCTION_INSTALL = Boolean(process.env.SKIP_PRODUCTION_INSTALL);
|
||||
const SKIP_TESTS_WITH_NEW_SYNTAX = process.versions.node.startsWith("14.");
|
||||
|
||||
let PRETTIER_DIR = isProduction
|
||||
? path.join(PROJECT_ROOT, "dist")
|
||||
? path.join(PROJECT_ROOT, "dist/prettier")
|
||||
: PROJECT_ROOT;
|
||||
let PRETTIER_INSTALLED_DIR = "";
|
||||
if (
|
||||
|
||||
+3
-3
@@ -162,9 +162,9 @@
|
||||
"test:dev-package": "cross-env INSTALL_PACKAGE=1 yarn test",
|
||||
"test:dist": "cross-env NODE_ENV=production yarn test",
|
||||
"test:dist-standalone": "cross-env TEST_STANDALONE=1 yarn test:dist",
|
||||
"test:dist-lint": "eslint dist --config=./scripts/bundle-eslint-config.js --quiet",
|
||||
"perf": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin/prettier.cjs",
|
||||
"perf:inspect": "yarn && yarn build && cross-env NODE_ENV=production node --inspect-brk ./dist/bin/prettier.cjs",
|
||||
"test:dist-lint": "eslint dist/prettier --config=./scripts/bundle-eslint-config.js --quiet --format friendly",
|
||||
"perf": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/prettier/bin/prettier.cjs",
|
||||
"perf:inspect": "yarn && yarn build && cross-env NODE_ENV=production node --inspect-brk ./dist/prettier/bin/prettier.cjs",
|
||||
"perf:benchmark": "yarn perf --debug-benchmark",
|
||||
"perf:compare": "./scripts/benchmark/compare.sh",
|
||||
"lint": "run-p --continue-on-error \"lint:*\"",
|
||||
|
||||
@@ -20,7 +20,7 @@ const runYarn = (command, args, options) =>
|
||||
spawn("yarn", [command, ...args], { stdio: "inherit", ...options });
|
||||
const IS_PULL_REQUEST = process.env.PULL_REQUEST === "true";
|
||||
const PRETTIER_DIR = IS_PULL_REQUEST
|
||||
? DIST_DIR
|
||||
? path.join(DIST_DIR, "prettier")
|
||||
: url.fileURLToPath(new URL("../node_modules/prettier", import.meta.url));
|
||||
const PLAYGROUND_PRETTIER_DIR = path.join(WEBSITE_DIR, "static/lib");
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { outdent } from "outdent";
|
||||
import rollupPluginLicense from "rollup-plugin-license";
|
||||
import { DIST_DIR, PROJECT_ROOT } from "../utils/index.js";
|
||||
import { PROJECT_ROOT } from "../utils/index.js";
|
||||
|
||||
const separator = `\n${"-".repeat(40)}\n\n`;
|
||||
|
||||
@@ -120,7 +120,14 @@ function getLicenseText(dependencies) {
|
||||
return [head, content].join("\n\n");
|
||||
}
|
||||
|
||||
async function buildDependenciesLicense({ file, files, results, cliOptions }) {
|
||||
async function buildDependenciesLicense({
|
||||
packageConfig,
|
||||
file,
|
||||
results,
|
||||
cliOptions,
|
||||
}) {
|
||||
const { distDirectory, files } = packageConfig;
|
||||
|
||||
const fileName = file.output.file;
|
||||
|
||||
if (files.at(-1) !== file) {
|
||||
@@ -144,7 +151,7 @@ async function buildDependenciesLicense({ file, files, results, cliOptions }) {
|
||||
|
||||
const text = getLicenseText(dependencies);
|
||||
|
||||
await fs.writeFile(path.join(DIST_DIR, fileName), text);
|
||||
await fs.writeFile(path.join(distDirectory, fileName), text);
|
||||
}
|
||||
|
||||
export default buildDependenciesLicense;
|
||||
@@ -4,7 +4,7 @@ import browserslistToEsbuild from "browserslist-to-esbuild";
|
||||
import esbuild from "esbuild";
|
||||
import { nodeModulesPolyfillPlugin as esbuildPluginNodeModulePolyfills } from "esbuild-plugins-node-modules-polyfill";
|
||||
import createEsmUtils from "esm-utils";
|
||||
import { DIST_DIR, PROJECT_ROOT } from "../utils/index.js";
|
||||
import { PROJECT_ROOT } from "../utils/index.js";
|
||||
import esbuildPluginAddDefaultExport from "./esbuild-plugins/add-default-export.js";
|
||||
import esbuildPluginEvaluate from "./esbuild-plugins/evaluate.js";
|
||||
import esbuildPluginPrimitiveDefine from "./esbuild-plugins/primitive-define.js";
|
||||
@@ -35,7 +35,9 @@ const getRelativePath = (from, to) => {
|
||||
return relativePath;
|
||||
};
|
||||
|
||||
function getEsbuildOptions({ file, files, cliOptions }) {
|
||||
function getEsbuildOptions({ packageConfig, file, cliOptions }) {
|
||||
const { distDirectory, files } = packageConfig;
|
||||
|
||||
// Save dependencies to file
|
||||
file.dependencies = [];
|
||||
|
||||
@@ -232,7 +234,7 @@ function getEsbuildOptions({ file, files, cliOptions }) {
|
||||
target: [...(buildOptions.target ?? ["node14"])],
|
||||
logLevel: "error",
|
||||
format: file.output.format,
|
||||
outfile: path.join(DIST_DIR, cliOptions.saveAs ?? file.output.file),
|
||||
outfile: path.join(distDirectory, cliOptions.saveAs ?? file.output.file),
|
||||
// https://esbuild.github.io/api/#main-fields
|
||||
mainFields: file.platform === "node" ? ["module", "main"] : undefined,
|
||||
supported: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import path from "node:path";
|
||||
import { DIST_DIR, PROJECT_ROOT, readJson, writeJson } from "../utils/index.js";
|
||||
import { PROJECT_ROOT, readJson, writeJson } from "../utils/index.js";
|
||||
|
||||
const keysToKeep = [
|
||||
"name",
|
||||
@@ -20,7 +20,8 @@ const keysToKeep = [
|
||||
"preferUnplugged",
|
||||
];
|
||||
|
||||
async function buildPackageJson({ file, files }) {
|
||||
async function buildPackageJson({ packageConfig, file }) {
|
||||
const { distDirectory, files } = packageConfig;
|
||||
const packageJson = await readJson(path.join(PROJECT_ROOT, file.input));
|
||||
|
||||
const bin = files.find(
|
||||
@@ -102,7 +103,7 @@ async function buildPackageJson({ file, files }) {
|
||||
};
|
||||
|
||||
await writeJson(
|
||||
path.join(DIST_DIR, file.output.file),
|
||||
path.join(distDirectory, file.output.file),
|
||||
Object.assign(pick(packageJson, keysToKeep), overrides),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ import path from "node:path";
|
||||
import url from "node:url";
|
||||
import { isValidIdentifier } from "@babel/types";
|
||||
import { outdent } from "outdent";
|
||||
import { DIST_DIR, PROJECT_ROOT, writeFile } from "../utils/index.js";
|
||||
import { PROJECT_ROOT, writeFile } from "../utils/index.js";
|
||||
|
||||
async function typesFileBuilder({ file }) {
|
||||
async function typesFileBuilder({ packageConfig, file }) {
|
||||
/**
|
||||
* @typedef {{ from: string, to: string }} ImportPathReplacement
|
||||
* @typedef {{ [input: string]: Array<ImportPathReplacement> }} ReplacementMap
|
||||
@@ -20,14 +20,17 @@ async function typesFileBuilder({ file }) {
|
||||
for (const { from, to } of replacements) {
|
||||
text = text.replaceAll(` from "${from}";`, ` from "${to}";`);
|
||||
}
|
||||
await writeFile(path.join(DIST_DIR, file.output.file), text);
|
||||
await writeFile(
|
||||
path.join(packageConfig.distDirectory, file.output.file),
|
||||
text,
|
||||
);
|
||||
}
|
||||
|
||||
function toPropertyKey(name) {
|
||||
return isValidIdentifier(name) ? name : JSON.stringify(name);
|
||||
}
|
||||
|
||||
async function buildPluginTypes({ file: { input, output } }) {
|
||||
async function buildPluginTypes({ packageConfig, file: { input, output } }) {
|
||||
const pluginModule = await import(
|
||||
url.pathToFileURL(path.join(PROJECT_ROOT, input))
|
||||
);
|
||||
@@ -52,7 +55,10 @@ async function buildPluginTypes({ file: { input, output } }) {
|
||||
};
|
||||
`;
|
||||
|
||||
await writeFile(path.join(DIST_DIR, output.file), `${code}\n`);
|
||||
await writeFile(
|
||||
path.join(packageConfig.distDirectory, output.file),
|
||||
`${code}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
function buildTypes(options) {
|
||||
|
||||
+13
-7
@@ -7,7 +7,7 @@ import createEsmUtils from "esm-utils";
|
||||
import styleText from "node-style-text";
|
||||
import prettyBytes from "pretty-bytes";
|
||||
import { DIST_DIR } from "../utils/index.js";
|
||||
import files from "./config.js";
|
||||
import packageConfig from "./config.js";
|
||||
import parseArguments from "./parse-arguments.js";
|
||||
|
||||
const { require } = createEsmUtils(import.meta);
|
||||
@@ -44,7 +44,8 @@ const clear = () => {
|
||||
readline.cursorTo(process.stdout, 0, null);
|
||||
};
|
||||
|
||||
async function buildFile({ file, files, cliOptions, results }) {
|
||||
async function buildFile({ packageConfig, file, cliOptions, results }) {
|
||||
const { distDirectory } = packageConfig;
|
||||
let displayName = file.output.file;
|
||||
if (
|
||||
(file.platform === "universal" && file.output.format !== "esm") ||
|
||||
@@ -69,7 +70,7 @@ async function buildFile({ file, files, cliOptions, results }) {
|
||||
|
||||
let result;
|
||||
try {
|
||||
result = await file.build({ file, files, cliOptions, results });
|
||||
result = await file.build({ packageConfig, file, cliOptions, results });
|
||||
} catch (error) {
|
||||
console.log(status.FAIL + "\n");
|
||||
console.error(error);
|
||||
@@ -87,7 +88,7 @@ async function buildFile({ file, files, cliOptions, results }) {
|
||||
|
||||
const sizeMessages = [];
|
||||
if (cliOptions.printSize) {
|
||||
const { size } = await fs.stat(path.join(DIST_DIR, outputFile));
|
||||
const { size } = await fs.stat(path.join(distDirectory, outputFile));
|
||||
sizeMessages.push(prettyBytes(size));
|
||||
}
|
||||
|
||||
@@ -103,7 +104,7 @@ async function buildFile({ file, files, cliOptions, results }) {
|
||||
}
|
||||
|
||||
if (stableSize) {
|
||||
const { size } = await fs.stat(path.join(DIST_DIR, outputFile));
|
||||
const { size } = await fs.stat(path.join(distDirectory, outputFile));
|
||||
const sizeDiff = size - stableSize;
|
||||
const message = styleText[sizeDiff > 0 ? "yellow" : "green"](
|
||||
prettyBytes(sizeDiff),
|
||||
@@ -151,8 +152,13 @@ async function run() {
|
||||
console.log(styleText.inverse(" Building packages "));
|
||||
|
||||
const results = [];
|
||||
for (const file of files) {
|
||||
const result = await buildFile({ file, files, cliOptions, results });
|
||||
for (const file of packageConfig.files) {
|
||||
const result = await buildFile({
|
||||
packageConfig,
|
||||
file,
|
||||
cliOptions,
|
||||
results,
|
||||
});
|
||||
results.push(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@ const {
|
||||
} = createEsmUtils(import.meta);
|
||||
const resolveEsmModulePath = (specifier) =>
|
||||
url.fileURLToPath(importMetaResolve(specifier));
|
||||
const copyFileBuilder = ({ file }) =>
|
||||
const copyFileBuilder = ({ packageConfig, file }) =>
|
||||
copyFile(
|
||||
path.join(PROJECT_ROOT, file.input),
|
||||
path.join(DIST_DIR, file.output.file),
|
||||
path.join(packageConfig.distDirectory, file.output.file),
|
||||
);
|
||||
|
||||
function getTypesFileConfig({ input: jsFileInput, outputBaseName, isPlugin }) {
|
||||
@@ -38,7 +38,7 @@ function getTypesFileConfig({ input: jsFileInput, outputBaseName, isPlugin }) {
|
||||
return {
|
||||
input,
|
||||
output: {
|
||||
file: outputBaseName + ".d.ts",
|
||||
file: `${outputBaseName}.d.ts`,
|
||||
},
|
||||
kind: "types",
|
||||
isPlugin,
|
||||
@@ -867,4 +867,8 @@ const metaFiles = [
|
||||
|
||||
/** @type {Files[]} */
|
||||
const files = [...nodejsFiles, ...universalFiles, ...metaFiles].filter(Boolean);
|
||||
export default files;
|
||||
export default {
|
||||
packageName: "prettier",
|
||||
distDirectory: path.join(DIST_DIR, "prettier"),
|
||||
files,
|
||||
};
|
||||
@@ -39,7 +39,9 @@ function parseArguments() {
|
||||
);
|
||||
}
|
||||
|
||||
if (!path.join(DIST_DIR, result.saveAs).startsWith(DIST_DIR)) {
|
||||
// TODO: Support package name
|
||||
const distDirectory = path.join(DIST_DIR, "prettier");
|
||||
if (!path.join(distDirectory, result.saveAs).startsWith(distDirectory)) {
|
||||
throw new Error("'--save-as' can only relative path");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ export default async function generateBundles({ dry, version, manual }) {
|
||||
runYarn(["build", "--clean", "--print-size", "--compare-size"]),
|
||||
);
|
||||
|
||||
const builtPkg = await readJson("dist/package.json");
|
||||
const builtPkg = await readJson("dist/prettier/package.json");
|
||||
if (!dry && builtPkg.version !== version) {
|
||||
throw new Error(
|
||||
`Expected ${version} in dist/package.json but found ${builtPkg.version}`,
|
||||
`Expected ${version} in dist/prettier/package.json but found ${builtPkg.version}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export default async function publishToNpm({ dry }) {
|
||||
args.push("--otp", otp);
|
||||
}
|
||||
|
||||
await spawn("npm", args, { cwd: "./dist" });
|
||||
await spawn("npm", args, { cwd: "./dist/prettier" });
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,8 +2,7 @@ import { createRequire } from "node:module";
|
||||
import path from "node:path";
|
||||
import url from "node:url";
|
||||
import webpack from "webpack";
|
||||
import files from "../../build/config.js";
|
||||
import { DIST_DIR } from "../../utils/index.js";
|
||||
import packageConfig from "../../build/config.js";
|
||||
|
||||
function runWebpack(config) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -30,6 +29,7 @@ const TEMPORARY_DIRECTORY = url.fileURLToPath(
|
||||
new URL("./.tmp", import.meta.url),
|
||||
);
|
||||
|
||||
const { distDirectory, files } = packageConfig;
|
||||
/* `require` in `parser-typescript.js`, #12338 */
|
||||
for (const file of files) {
|
||||
if (file.platform !== "universal") {
|
||||
@@ -39,7 +39,7 @@ for (const file of files) {
|
||||
|
||||
const stats = await runWebpack({
|
||||
mode: "production",
|
||||
entry: path.join(DIST_DIR, file.output.file),
|
||||
entry: path.join(distDirectory, file.output.file),
|
||||
output: {
|
||||
path: TEMPORARY_DIRECTORY,
|
||||
filename: `${file.output.file}.[contenthash:7].${
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import * as prettier from "../../../../dist/index.js";
|
||||
import * as prettier from "../../../../dist/prettier/index.js";
|
||||
|
||||
import * as prettierPluginEstree from "../../../../dist/plugins/estree.js";
|
||||
import * as prettierPluginBabel from "../../../../dist/plugins/babel.js";
|
||||
import * as prettierPluginFlow from "../../../../dist/plugins/flow.js";
|
||||
import * as prettierPluginTypeScript from "../../../../dist/plugins/typescript.js";
|
||||
import * as prettierPluginAcorn from "../../../../dist/plugins/acorn.js";
|
||||
import * as prettierPluginMeriyah from "../../../../dist/plugins/meriyah.js";
|
||||
import * as prettierPluginAngular from "../../../../dist/plugins/angular.js";
|
||||
import * as prettierPluginPostcss from "../../../../dist/plugins/postcss.js";
|
||||
import * as prettierPluginGraphql from "../../../../dist/plugins/graphql.js";
|
||||
import * as prettierPluginMarkdown from "../../../../dist/plugins/markdown.js";
|
||||
import * as prettierPluginGlimmer from "../../../../dist/plugins/glimmer.js";
|
||||
import * as prettierPluginHtml from "../../../../dist/plugins/html.js";
|
||||
import * as prettierPluginYaml from "../../../../dist/plugins/yaml.js";
|
||||
import * as prettierPluginEstree from "../../../../dist/prettier/plugins/estree.js";
|
||||
import * as prettierPluginBabel from "../../../../dist/prettier/plugins/babel.js";
|
||||
import * as prettierPluginFlow from "../../../../dist/prettier/plugins/flow.js";
|
||||
import * as prettierPluginTypeScript from "../../../../dist/prettier/plugins/typescript.js";
|
||||
import * as prettierPluginAcorn from "../../../../dist/prettier/plugins/acorn.js";
|
||||
import * as prettierPluginMeriyah from "../../../../dist/prettier/plugins/meriyah.js";
|
||||
import * as prettierPluginAngular from "../../../../dist/prettier/plugins/angular.js";
|
||||
import * as prettierPluginPostcss from "../../../../dist/prettier/plugins/postcss.js";
|
||||
import * as prettierPluginGraphql from "../../../../dist/prettier/plugins/graphql.js";
|
||||
import * as prettierPluginMarkdown from "../../../../dist/prettier/plugins/markdown.js";
|
||||
import * as prettierPluginGlimmer from "../../../../dist/prettier/plugins/glimmer.js";
|
||||
import * as prettierPluginHtml from "../../../../dist/prettier/plugins/html.js";
|
||||
import * as prettierPluginYaml from "../../../../dist/prettier/plugins/yaml.js";
|
||||
|
||||
const options: prettier.ParserOptions = {
|
||||
filepath: "/home/mark/prettier/bin/prettier.js",
|
||||
|
||||
@@ -11,7 +11,7 @@ import { projectRoot } from "../env.js";
|
||||
const { require, importModule } = createEsmUtils(import.meta);
|
||||
|
||||
const parserNames = coreOptions.parser.choices.map(({ value }) => value);
|
||||
const distDirectory = path.join(projectRoot, "dist");
|
||||
const distDirectory = path.join(projectRoot, "dist/prettier");
|
||||
|
||||
// Files including U+FFEE can't load in Chrome Extension
|
||||
// `prettier-chrome-extension` https://github.com/prettier/prettier-chrome-extension
|
||||
|
||||
Reference in new issue
Block a user