Bundle bin and cli separately (#12306)
This commit is contained in:
1 parent
9f6c005b28
commit
5a50a0d909
8 files changed
+66
-39
No files matched your search
@@ -306,5 +306,14 @@ module.exports = {
|
||||
sourceType: "module",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["bin/prettier.js"],
|
||||
parserOptions: {
|
||||
ecmaVersion: 5,
|
||||
},
|
||||
rules: {
|
||||
"no-var": "off",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -144,3 +144,28 @@ jobs:
|
||||
env:
|
||||
NODE_ENV: production
|
||||
PRETTIER_FALLBACK_RESOLVE: true
|
||||
|
||||
cli:
|
||||
name: CLI
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.4.0
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v2.5.1
|
||||
with:
|
||||
node-version: "0.10.48"
|
||||
|
||||
- name: Download Artifact
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
|
||||
- name: Validate Node.js Version
|
||||
run: node -v | grep "v0.10.48" || exit 1
|
||||
|
||||
- name: Run CLI on Node.js v0.10.48
|
||||
run: node dist/bin-prettier --version 2>&1 >/dev/null | grep "prettier requires at least version 10.13.0 of Node, please upgrade" || exit 1
|
||||
+8
-1
@@ -2,4 +2,11 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
module.exports = require("../src/cli/index.js").run(process.argv.slice(2));
|
||||
var pleaseUpgradeNode = require("please-upgrade-node");
|
||||
var packageJson = require("../package.json");
|
||||
|
||||
pleaseUpgradeNode(packageJson);
|
||||
|
||||
var cli = require("../src/cli/index.js");
|
||||
|
||||
module.exports = cli.run(process.argv.slice(2));
|
||||
@@ -166,16 +166,18 @@ function* getEsbuildOptions(bundle, buildOptions) {
|
||||
].filter(Boolean),
|
||||
minify: shouldMinify,
|
||||
legalComments: "none",
|
||||
external: [...(bundle.external || [])],
|
||||
external: [...(bundle.external ?? [])],
|
||||
// Disable esbuild auto discover `tsconfig.json` file
|
||||
tsconfig: path.join(__dirname, "empty-tsconfig.json"),
|
||||
mainFields: ["main"],
|
||||
target: ["node10"],
|
||||
target: [...(bundle.esbuildTarget ?? ["node10"])],
|
||||
logLevel: "error",
|
||||
};
|
||||
|
||||
if (bundle.target === "universal") {
|
||||
esbuildOptions.target.push(...umdTarget);
|
||||
if (!bundle.esbuildTarget) {
|
||||
esbuildOptions.target.push(...umdTarget);
|
||||
}
|
||||
|
||||
yield {
|
||||
...esbuildOptions,
|
||||
@@ -207,7 +209,7 @@ function* getEsbuildOptions(bundle, buildOptions) {
|
||||
}
|
||||
|
||||
async function runBuild(bundle, esbuildOptions, buildOptions) {
|
||||
if (!buildOptions.babel) {
|
||||
if (!buildOptions.babel || bundle.skipBabel) {
|
||||
await esbuild.build(esbuildOptions);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ const { require } = createEsmUtils(import.meta);
|
||||
* @property {Object.<string, string>} replace - map of strings to replace when processing the bundle
|
||||
* @property {string[]} babelPlugins - babel plugins
|
||||
* @property {boolean?} minify - minify
|
||||
* @property {string[]?} esbuildTarget - ESBuild target
|
||||
* @property {boolean?} skipBabel - Skip babel transform
|
||||
|
||||
* @typedef {Object} CommonJSConfig
|
||||
* @property {string[]} ignore - paths of CJS modules to ignore
|
||||
@@ -196,6 +198,12 @@ const coreBundles = [
|
||||
{
|
||||
input: "bin/prettier.js",
|
||||
output: "bin-prettier.js",
|
||||
esbuildTarget: ["node0.10"],
|
||||
skipBabel: true,
|
||||
},
|
||||
{
|
||||
input: "src/cli/index.js",
|
||||
output: "cli.js",
|
||||
external: ["benchmark"],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -40,7 +40,16 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["index.js", "bin-prettier.js", "third-party.js"],
|
||||
files: ["bin-prettier.js"],
|
||||
parserOptions: {
|
||||
ecmaVersion: 5,
|
||||
},
|
||||
rules: {
|
||||
"compat/compat": "error",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["index.js", "bin-prettier.js", "cli.js", "third-party.js"],
|
||||
rules: {
|
||||
"no-restricted-syntax": [
|
||||
"error",
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
// eslint-disable-next-line no-restricted-modules
|
||||
const packageJson = require("../../package.json");
|
||||
require("please-upgrade-node")(packageJson);
|
||||
|
||||
// eslint-disable-next-line import/order
|
||||
const stringify = require("fast-json-stable-stringify");
|
||||
// eslint-disable-next-line no-restricted-modules
|
||||
const prettier = require("../index.js");
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
const runPrettier = require("../run-prettier.js");
|
||||
const { isProduction } = require("../env.js");
|
||||
|
||||
describe("show version with --version", () => {
|
||||
runPrettier("cli/with-shebang", ["--version"]).test({
|
||||
@@ -90,30 +89,3 @@ describe("throw error and show usage with something unexpected", () => {
|
||||
status: "non-zero",
|
||||
});
|
||||
});
|
||||
|
||||
test("node version error", async () => {
|
||||
const originalProcessVersion = process.version;
|
||||
let result;
|
||||
|
||||
Object.defineProperty(process, "version", {
|
||||
value: "v8.0.0",
|
||||
writable: false,
|
||||
});
|
||||
try {
|
||||
result = await runPrettier("cli", ["--help"]);
|
||||
} finally {
|
||||
Object.defineProperty(process, "version", {
|
||||
value: originalProcessVersion,
|
||||
writable: false,
|
||||
});
|
||||
}
|
||||
|
||||
expect(result.status).toBe(1);
|
||||
expect(result.stderr).toBe(
|
||||
`prettier requires at least version ${
|
||||
isProduction ? "10.13.0" : "12.17.0"
|
||||
} of Node, please upgrade\n`
|
||||
);
|
||||
expect(result.stdout).toBe("");
|
||||
expect(result.write).toEqual([]);
|
||||
});
|
||||
Reference in new issue
Block a user