Bundle "Experimental CLI" (#17396)
This commit is contained in:
1 parent
59c635b939
commit
d4fd92e266
19 files changed
+303
-103
No files matched your search
@@ -33,12 +33,11 @@ jobs:
|
|||||||
- "20"
|
- "20"
|
||||||
NPM_CLIENT:
|
NPM_CLIENT:
|
||||||
- "yarn"
|
- "yarn"
|
||||||
# Disabled temporarily #13151
|
- "npm"
|
||||||
# - "npm"
|
|
||||||
- "pnpm"
|
- "pnpm"
|
||||||
env:
|
env:
|
||||||
INSTALL_PACKAGE: true
|
INSTALL_PACKAGE: true
|
||||||
NPM_CLIENT: ${{ matrix.NPM_CLIENT }}
|
PRETTIER_INSTALL_NPM_CLIENT: ${{ matrix.NPM_CLIENT }}
|
||||||
name: Test with ${{ matrix.NPM_CLIENT }}
|
name: Test with ${{ matrix.NPM_CLIENT }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
.tmp
|
.tmp
|
||||||
*.log
|
*.log
|
||||||
|
*.tgz
|
||||||
/errors
|
/errors
|
||||||
/test*.*
|
/test*.*
|
||||||
/.vscode/**/*
|
/.vscode/**/*
|
||||||
|
|||||||
+16
-4
@@ -14,11 +14,23 @@ var packageJson = require("../package.json");
|
|||||||
pleaseUpgradeNode(packageJson);
|
pleaseUpgradeNode(packageJson);
|
||||||
|
|
||||||
var dynamicImport = new Function("module", "return import(module)");
|
var dynamicImport = new Function("module", "return import(module)");
|
||||||
if (process.env.PRETTIER_EXPERIMENTAL_CLI) {
|
|
||||||
dynamicImport("@prettier/cli/bin");
|
var promise;
|
||||||
|
var index = process.argv.indexOf("--experimental-cli");
|
||||||
|
if (process.env.PRETTIER_EXPERIMENTAL_CLI || index !== -1) {
|
||||||
|
if (index !== -1) {
|
||||||
|
process.argv.splice(index, 1);
|
||||||
|
}
|
||||||
|
promise = dynamicImport("../src/experimental-cli/index.js").then(
|
||||||
|
function (cli) {
|
||||||
|
return cli.__promise;
|
||||||
|
}
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
var promise = dynamicImport("../src/cli/index.js").then(function runCli(cli) {
|
promise = dynamicImport("../src/cli/index.js").then(function runCli(cli) {
|
||||||
return cli.run();
|
return cli.run();
|
||||||
});
|
});
|
||||||
module.exports.__promise = promise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exposed for test
|
||||||
|
module.exports.__promise = promise;
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
#### Support experimental CLI (#17151 by @fisker)
|
#### Support experimental CLI (#17151, #17396 by @fisker)
|
||||||
|
|
||||||
You may already heard or used our new [performance improved CLI](https://prettier.io/blog/2023/11/30/cli-deep-dive). From prettier main, you can use it without installing unstable v4 version.
|
You may already heard or used our new [performance improved CLI](https://prettier.io/blog/2023/11/30/cli-deep-dive). From prettier main, you can use it without installing unstable v4 version.
|
||||||
|
|
||||||
1. Install `@prettier/cli` package
|
```sh
|
||||||
|
# Run CLI with `--experimental-cli`
|
||||||
|
prettier . --check --experimental-cli
|
||||||
|
|
||||||
```sh
|
# Or use environment variable `PRETTIER_EXPERIMENTAL_CLI=1`
|
||||||
yarn add prettier @prettier/cli --dev
|
PRETTIER_EXPERIMENTAL_CLI=1 prettier . --check
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Run Prettier with environment variable `PRETTIER_EXPERIMENTAL_CLI=1`
|
|
||||||
|
|
||||||
```sh
|
|
||||||
PRETTIER_EXPERIMENTAL_CLI=1 prettier . --check
|
|
||||||
```
|
|
||||||
+6
-4
@@ -10,7 +10,7 @@ const TEST_STANDALONE = Boolean(process.env.TEST_STANDALONE);
|
|||||||
const INSTALL_PACKAGE = Boolean(process.env.INSTALL_PACKAGE);
|
const INSTALL_PACKAGE = Boolean(process.env.INSTALL_PACKAGE);
|
||||||
// When debugging production test, this flag can skip installing package
|
// When debugging production test, this flag can skip installing package
|
||||||
const SKIP_PRODUCTION_INSTALL = Boolean(process.env.SKIP_PRODUCTION_INSTALL);
|
const SKIP_PRODUCTION_INSTALL = Boolean(process.env.SKIP_PRODUCTION_INSTALL);
|
||||||
const SKIP_TESTS_WITH_NEW_SYNTAX = process.versions.node.startsWith("14.");
|
const nodejsMajorVersion = Number(process.versions.node.split(".")[0]);
|
||||||
|
|
||||||
let PRETTIER_DIR = isProduction
|
let PRETTIER_DIR = isProduction
|
||||||
? path.join(PROJECT_ROOT, "dist/prettier")
|
? path.join(PROJECT_ROOT, "dist/prettier")
|
||||||
@@ -40,19 +40,21 @@ if (isProduction) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SKIP_TESTS_WITH_NEW_SYNTAX || process.versions.node.startsWith("16.")) {
|
if (nodejsMajorVersion <= 16) {
|
||||||
// Uses import attributes
|
// Uses import attributes
|
||||||
testPathIgnorePatterns.push(
|
testPathIgnorePatterns.push(
|
||||||
"<rootDir>/tests/integration/__tests__/help-options.js",
|
"<rootDir>/tests/integration/__tests__/help-options.js",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SKIP_TESTS_WITH_NEW_SYNTAX) {
|
if (nodejsMajorVersion <= 14) {
|
||||||
testPathIgnorePatterns.push(
|
testPathIgnorePatterns.push(
|
||||||
"<rootDir>/tests/integration/__tests__/plugin-parsers.js",
|
"<rootDir>/tests/integration/__tests__/plugin-parsers.js",
|
||||||
"<rootDir>/tests/integration/__tests__/normalize-doc.js",
|
"<rootDir>/tests/integration/__tests__/normalize-doc.js",
|
||||||
"<rootDir>/tests/integration/__tests__/doc-utils-clean-doc.js",
|
"<rootDir>/tests/integration/__tests__/doc-utils-clean-doc.js",
|
||||||
"<rootDir>/tests/integration/__tests__/config-invalid.js",
|
"<rootDir>/tests/integration/__tests__/config-invalid.js",
|
||||||
|
// `@prettier/cli` uses `node:stream/consumers`, not available on Node.js v14
|
||||||
|
"<rootDir>/tests/integration/__tests__/experimental-cli.js",
|
||||||
// Fails on Node.js v14
|
// Fails on Node.js v14
|
||||||
"<rootDir>/tests/dts/unit/run.js",
|
"<rootDir>/tests/dts/unit/run.js",
|
||||||
);
|
);
|
||||||
@@ -63,7 +65,7 @@ const config = {
|
|||||||
"<rootDir>/tests/config/format-test-setup.js",
|
"<rootDir>/tests/config/format-test-setup.js",
|
||||||
"<rootDir>/tests/integration/integration-test-setup.js",
|
"<rootDir>/tests/integration/integration-test-setup.js",
|
||||||
],
|
],
|
||||||
runner: "jest-light-runner/child-process",
|
runner: "jest-light-runner",
|
||||||
snapshotSerializers: [
|
snapshotSerializers: [
|
||||||
"jest-snapshot-serializer-raw",
|
"jest-snapshot-serializer-raw",
|
||||||
"jest-snapshot-serializer-ansi",
|
"jest-snapshot-serializer-ansi",
|
||||||
|
|||||||
+3
-5
@@ -7,18 +7,16 @@ export default {
|
|||||||
// We use `new Function()` to create `import()` in our `bin` file (bin/prettier.cjs)
|
// We use `new Function()` to create `import()` in our `bin` file (bin/prettier.cjs)
|
||||||
// so there is no actual use of the CLI files
|
// so there is no actual use of the CLI files
|
||||||
"src/cli/index.js",
|
"src/cli/index.js",
|
||||||
|
"src/experimental-cli/index.js",
|
||||||
],
|
],
|
||||||
project: ["src/**", "scripts/**"],
|
project: ["src/**", "scripts/**"],
|
||||||
ignore: [
|
ignore: [
|
||||||
"scripts/build/config.js",
|
"scripts/build/config.js",
|
||||||
"scripts/build/build-javascript-module.js",
|
"scripts/build/build-javascript-module.js",
|
||||||
"scripts/tools/**",
|
"scripts/tools/**",
|
||||||
|
"src/experimental-cli/**",
|
||||||
],
|
],
|
||||||
ignoreDependencies: [
|
ignoreDependencies: ["eslint-formatter-friendly", "ts-expect"],
|
||||||
"eslint-formatter-friendly",
|
|
||||||
"ts-expect",
|
|
||||||
"@prettier/cli",
|
|
||||||
],
|
|
||||||
ignoreBinaries: [
|
ignoreBinaries: [
|
||||||
"test-coverage",
|
"test-coverage",
|
||||||
"renovate-config-validator",
|
"renovate-config-validator",
|
||||||
|
|||||||
+3
-1
@@ -18,6 +18,8 @@
|
|||||||
"require": "./src/index.cjs",
|
"require": "./src/index.cjs",
|
||||||
"default": "./src/index.js"
|
"default": "./src/index.js"
|
||||||
},
|
},
|
||||||
|
"./standalone": "./src/standalone.js",
|
||||||
|
"./plugins/*": "./src/plugins/*.js",
|
||||||
"./*": "./*"
|
"./*": "./*"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -35,7 +37,7 @@
|
|||||||
"@babel/parser": "7.27.1",
|
"@babel/parser": "7.27.1",
|
||||||
"@babel/types": "7.27.1",
|
"@babel/types": "7.27.1",
|
||||||
"@glimmer/syntax": "0.94.9",
|
"@glimmer/syntax": "0.94.9",
|
||||||
"@prettier/cli": "0.7.1",
|
"@prettier/cli": "0.8.0",
|
||||||
"@prettier/html-tags": "1.0.0",
|
"@prettier/html-tags": "1.0.0",
|
||||||
"@prettier/parse-srcset": "3.1.0",
|
"@prettier/parse-srcset": "3.1.0",
|
||||||
"@typescript-eslint/typescript-estree": "8.30.1",
|
"@typescript-eslint/typescript-estree": "8.30.1",
|
||||||
|
|||||||
@@ -100,15 +100,6 @@ async function buildPackageJson({ packageConfig, file }) {
|
|||||||
prepublishOnly:
|
prepublishOnly:
|
||||||
"node -e \"assert.equal(require('.').version, require('..').version)\"",
|
"node -e \"assert.equal(require('.').version, require('..').version)\"",
|
||||||
},
|
},
|
||||||
peerDependencies: {
|
|
||||||
// Add `^` here, so we don't need release Prettier user can still update CLI
|
|
||||||
"@prettier/cli": `^${packageJson.dependencies["@prettier/cli"]}`,
|
|
||||||
},
|
|
||||||
peerDependenciesMeta: {
|
|
||||||
"@prettier/cli": {
|
|
||||||
optional: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
await writeJson(
|
await writeJson(
|
||||||
|
|||||||
+59
-3
@@ -786,11 +786,19 @@ const nodejsFiles = [
|
|||||||
replaceModule: [
|
replaceModule: [
|
||||||
{
|
{
|
||||||
module: path.join(PROJECT_ROOT, "bin/prettier.cjs"),
|
module: path.join(PROJECT_ROOT, "bin/prettier.cjs"),
|
||||||
process: (text) =>
|
process(text) {
|
||||||
text.replace("../src/cli/index.js", "../internal/legacy-cli.mjs"),
|
text = text.replace(
|
||||||
|
"../src/cli/index.js",
|
||||||
|
"../internal/legacy-cli.mjs",
|
||||||
|
);
|
||||||
|
text = text.replace(
|
||||||
|
"../src/experimental-cli/index.js",
|
||||||
|
"../internal/experimental-cli.mjs",
|
||||||
|
);
|
||||||
|
return text;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
external: ["@prettier/cli"],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: "src/cli/index.js",
|
input: "src/cli/index.js",
|
||||||
@@ -811,6 +819,54 @@ const nodejsFiles = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
...[
|
||||||
|
{
|
||||||
|
input: "src/experimental-cli/index.js",
|
||||||
|
outputBaseName: "internal/experimental-cli",
|
||||||
|
replaceModule: [
|
||||||
|
{
|
||||||
|
module: getPackageFile("@prettier/cli/dist/prettier_serial.js"),
|
||||||
|
external: "./experimental-cli-worker.mjs",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
module: getPackageFile("@prettier/cli/dist/prettier_parallel.js"),
|
||||||
|
find: 'new URL("./prettier_serial.js", import.meta.url)',
|
||||||
|
replacement:
|
||||||
|
'new URL("./experimental-cli-worker.mjs", import.meta.url)',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "src/experimental-cli/worker.js",
|
||||||
|
outputBaseName: "internal/experimental-cli-worker",
|
||||||
|
},
|
||||||
|
].map(({ input, outputBaseName, replaceModule = [] }) => ({
|
||||||
|
input,
|
||||||
|
outputBaseName,
|
||||||
|
replaceModule: [
|
||||||
|
...replaceModule,
|
||||||
|
{
|
||||||
|
module: getPackageFile("@prettier/cli/dist/constants.js"),
|
||||||
|
path: path.join(
|
||||||
|
PROJECT_ROOT,
|
||||||
|
"src/experimental-cli/constants.evaluate.js",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
...[
|
||||||
|
"package.json",
|
||||||
|
"index.mjs",
|
||||||
|
...universalFiles
|
||||||
|
.filter(
|
||||||
|
({ kind, output }) =>
|
||||||
|
kind === "javascript" && output.format === "esm",
|
||||||
|
)
|
||||||
|
.map(({ output }) => output.file),
|
||||||
|
].map((file) => ({
|
||||||
|
module: getPackageFile(`prettier/${file}`),
|
||||||
|
external: `../${file}`,
|
||||||
|
})),
|
||||||
|
],
|
||||||
|
})),
|
||||||
].flatMap((file) => {
|
].flatMap((file) => {
|
||||||
let { input, output, outputBaseName, ...buildOptions } = file;
|
let { input, output, outputBaseName, ...buildOptions } = file;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export { default as PRETTIER_VERSION } from "../main/version.evaluate.js";
|
||||||
|
export * from "@prettier/cli/dist/constants.js";
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from "@prettier/cli/bin";
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from "@prettier/cli/dist/prettier_serial.js";
|
||||||
@@ -3,6 +3,7 @@ import crypto from "node:crypto";
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
import { performance } from "node:perf_hooks";
|
||||||
import { outdent } from "outdent";
|
import { outdent } from "outdent";
|
||||||
import picocolors from "picocolors";
|
import picocolors from "picocolors";
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ const createTemporaryDirectory = () => {
|
|||||||
|
|
||||||
const allowedClients = new Set(["yarn", "npm", "pnpm"]);
|
const allowedClients = new Set(["yarn", "npm", "pnpm"]);
|
||||||
|
|
||||||
let client = process.env.NPM_CLIENT;
|
let client = process.env.PRETTIER_INSTALL_NPM_CLIENT;
|
||||||
if (!allowedClients.has(client)) {
|
if (!allowedClients.has(client)) {
|
||||||
client = "yarn";
|
client = "yarn";
|
||||||
}
|
}
|
||||||
@@ -52,6 +53,7 @@ function cleanUp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function installPrettier(packageDirectory) {
|
function installPrettier(packageDirectory) {
|
||||||
|
const start = performance.now();
|
||||||
const temporaryDirectory = createTemporaryDirectory();
|
const temporaryDirectory = createTemporaryDirectory();
|
||||||
directoriesToClean.add(temporaryDirectory);
|
directoriesToClean.add(temporaryDirectory);
|
||||||
const fileName = spawnSync("npm", ["pack"], {
|
const fileName = spawnSync("npm", ["pack"], {
|
||||||
@@ -91,9 +93,10 @@ function installPrettier(packageDirectory) {
|
|||||||
picocolors.green(
|
picocolors.green(
|
||||||
outdent`
|
outdent`
|
||||||
Prettier installed
|
Prettier installed
|
||||||
at ${picocolors.inverse(temporaryDirectory)}
|
at ${picocolors.inverse(temporaryDirectory)}
|
||||||
from ${picocolors.inverse(packageDirectory)}
|
from ${picocolors.inverse(packageDirectory)}
|
||||||
with ${picocolors.inverse(client)}.
|
with ${picocolors.inverse(client)}
|
||||||
|
in ${picocolors.inverse(`${performance.now() - start}ms`)}.
|
||||||
`,
|
`,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`experimental cli 1`] = `
|
||||||
|
{
|
||||||
|
"stdout": "foo();",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`experimental cli '--check --no-parallel' 1`] = `
|
||||||
|
{
|
||||||
|
"status": 1,
|
||||||
|
"stderr": "[warn] test-1/should-format.js
|
||||||
|
[warn] Code style issues found in 1 file. Run Prettier with --write to fix.",
|
||||||
|
"stdout": "Checking formatting...
|
||||||
|
",
|
||||||
|
"write": [],
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`experimental cli '--check' 1`] = `
|
||||||
|
{
|
||||||
|
"status": 1,
|
||||||
|
"stderr": "[warn] test-0/should-format.js
|
||||||
|
[warn] Code style issues found in 1 file. Run Prettier with --write to fix.",
|
||||||
|
"stdout": "Checking formatting...
|
||||||
|
",
|
||||||
|
"write": [],
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`experimental cli '--write --no-parallel' 1`] = `
|
||||||
|
{
|
||||||
|
"status": 0,
|
||||||
|
"stderr": "",
|
||||||
|
"stdout": "test-3/should-format.js",
|
||||||
|
"write": [],
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`experimental cli '--write' 1`] = `
|
||||||
|
{
|
||||||
|
"status": 0,
|
||||||
|
"stderr": "",
|
||||||
|
"stdout": "test-2/should-format.js",
|
||||||
|
"write": [],
|
||||||
|
}
|
||||||
|
`;
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import fs from "node:fs/promises";
|
||||||
|
import { createRequire } from "node:module";
|
||||||
|
import path from "node:path";
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
|
function runExperimentalCli(args, options) {
|
||||||
|
return runCli("cli/experimental-cli", [...args, "--no-cache"], {
|
||||||
|
...options,
|
||||||
|
env: { ...options?.env, PRETTIER_EXPERIMENTAL_CLI: 1 },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const code = 'console.log("Hello, world!");\n';
|
||||||
|
const unformatted = `
|
||||||
|
console.log(
|
||||||
|
"Hello, world!"
|
||||||
|
|
||||||
|
|
||||||
|
)
|
||||||
|
`;
|
||||||
|
|
||||||
|
describe("experimental cli", () => {
|
||||||
|
const expectedVersion =
|
||||||
|
process.env.NODE_ENV === "production" ||
|
||||||
|
(process.env.PRETTIER_INSTALLED_DIR &&
|
||||||
|
process.env.PRETTIER_INSTALL_NPM_CLIENT !== "npm")
|
||||||
|
? require(path.join(process.env.PRETTIER_DIR, "package.json")).version
|
||||||
|
: createRequire(require.resolve("@prettier/cli/package.json"))(
|
||||||
|
"prettier/package.json",
|
||||||
|
).version;
|
||||||
|
|
||||||
|
runExperimentalCli(["--version"]).test({
|
||||||
|
stderr: "",
|
||||||
|
status: 0,
|
||||||
|
write: [],
|
||||||
|
stdout: expectedVersion,
|
||||||
|
});
|
||||||
|
|
||||||
|
runExperimentalCli(["--version", "--experimental-cli"]).test({
|
||||||
|
stderr: "",
|
||||||
|
status: 0,
|
||||||
|
write: [],
|
||||||
|
stdout: expectedVersion,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Stdin format
|
||||||
|
runExperimentalCli(["--parser=meriyah"], { input: "foo( )" }).test({
|
||||||
|
stderr: "",
|
||||||
|
status: 0,
|
||||||
|
write: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const [index, args] of [
|
||||||
|
// File check
|
||||||
|
["--check"],
|
||||||
|
// File format
|
||||||
|
["--write"],
|
||||||
|
]
|
||||||
|
.flatMap((args) => [args, [...args, "--no-parallel"]])
|
||||||
|
.entries()) {
|
||||||
|
test(`'${args.join(" ")}'`, async () => {
|
||||||
|
// Since we are not able to mock file write, so we just let the CLI actually write it
|
||||||
|
const directory = new URL(
|
||||||
|
`../cli/experimental-cli/test-${index}/`,
|
||||||
|
import.meta.url,
|
||||||
|
);
|
||||||
|
const fileShouldNotFormat = new URL("./should-not-format.js", directory);
|
||||||
|
const fileShouldFormat = new URL("./should-format.js", directory);
|
||||||
|
await fs.rm(directory, { force: true, recursive: true });
|
||||||
|
await fs.mkdir(directory);
|
||||||
|
await fs.writeFile(fileShouldNotFormat, code);
|
||||||
|
await fs.writeFile(fileShouldFormat, unformatted);
|
||||||
|
|
||||||
|
const result = await runExperimentalCli([
|
||||||
|
`./test-${index}`,
|
||||||
|
...args,
|
||||||
|
"--ignore-path=do-not-ignore",
|
||||||
|
"--no-cache",
|
||||||
|
]);
|
||||||
|
|
||||||
|
{
|
||||||
|
const content = await fs.readFile(fileShouldNotFormat, "utf8");
|
||||||
|
expect(content).toBe(code);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const content = await fs.readFile(fileShouldFormat, "utf8");
|
||||||
|
expect(content).toBe(args.includes("--write") ? code : unformatted);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(result).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# dynamically created by tests
|
||||||
|
test-*
|
||||||
@@ -87,6 +87,7 @@ function runCliWorker(dir, args, options) {
|
|||||||
stdio: [options.input ? "pipe" : "ignore", "pipe", "pipe", "ipc"],
|
stdio: [options.input ? "pipe" : "ignore", "pipe", "pipe", "ipc"],
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
|
...options.env,
|
||||||
NO_COLOR: "1",
|
NO_COLOR: "1",
|
||||||
},
|
},
|
||||||
serialization: "advanced",
|
serialization: "advanced",
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ test("`printDocToString` should not manipulate docs", () => {
|
|||||||
|
|
||||||
describe("`printDocToString` has linear time complexity at most to print fill()", () => {
|
describe("`printDocToString` has linear time complexity at most to print fill()", () => {
|
||||||
const baseSize = 3_000;
|
const baseSize = 3_000;
|
||||||
const relativeMargin = 0.6;
|
const relativeMargin = 0.7;
|
||||||
const baseTime = time(makeFill(baseSize));
|
const baseTime = time(makeFill(baseSize));
|
||||||
test.each([20_000, 40_000, 60_000])("numWords=%d", (numWords) => {
|
test.each([20_000, 40_000, 60_000])("numWords=%d", (numWords) => {
|
||||||
const doc = makeFill(numWords);
|
const doc = makeFill(numWords);
|
||||||
|
|||||||
@@ -1960,39 +1960,38 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@prettier/cli@npm:0.7.1":
|
"@prettier/cli@npm:0.8.0":
|
||||||
version: 0.7.1
|
version: 0.8.0
|
||||||
resolution: "@prettier/cli@npm:0.7.1"
|
resolution: "@prettier/cli@npm:0.8.0"
|
||||||
dependencies:
|
dependencies:
|
||||||
atomically: "npm:^2.0.3"
|
atomically: "npm:^2.0.3"
|
||||||
fast-ignore: "npm:^1.1.3"
|
fast-ignore: "npm:^1.1.3"
|
||||||
find-up-json: "npm:^2.0.4"
|
find-up-json: "npm:^2.0.5"
|
||||||
function-once: "npm:^3.0.0"
|
function-once: "npm:^3.0.1"
|
||||||
import-meta-resolve: "npm:^4.1.0"
|
import-meta-resolve: "npm:^4.1.0"
|
||||||
is-binary-path: "npm:^2.1.0"
|
is-binary-path: "npm:^3.0.0"
|
||||||
js-yaml: "npm:^4.1.0"
|
js-yaml: "npm:^4.1.0"
|
||||||
json-sorted-stringify: "npm:^1.0.0"
|
json-sorted-stringify: "npm:^1.0.1"
|
||||||
json5: "npm:^2.2.3"
|
json5: "npm:^2.2.3"
|
||||||
kasi: "npm:^1.1.0"
|
kasi: "npm:^1.1.1"
|
||||||
lomemo: "npm:^1.0.0"
|
lomemo: "npm:^1.0.1"
|
||||||
pioppo: "npm:^1.2.0"
|
pioppo: "npm:^1.2.1"
|
||||||
promise-resolve-timeout: "npm:^2.0.0"
|
promise-resolve-timeout: "npm:^2.0.1"
|
||||||
smol-toml: "npm:^1.3.1"
|
smol-toml: "npm:^1.3.4"
|
||||||
specialist: "npm:^1.4.5"
|
specialist: "npm:^1.4.5"
|
||||||
tiny-editorconfig: "npm:^1.0.0"
|
tiny-editorconfig: "npm:^1.0.0"
|
||||||
tiny-jsonc: "npm:^1.0.1"
|
|
||||||
tiny-readdir: "npm:^2.7.4"
|
tiny-readdir: "npm:^2.7.4"
|
||||||
tiny-readdir-glob: "npm:^1.23.1"
|
tiny-readdir-glob: "npm:^1.23.2"
|
||||||
tiny-spinner: "npm:^2.0.4"
|
tiny-spinner: "npm:^2.0.5"
|
||||||
worktank: "npm:^2.7.3"
|
worktank: "npm:^2.7.3"
|
||||||
zeptomatch: "npm:^2.0.0"
|
zeptomatch: "npm:^2.0.1"
|
||||||
zeptomatch-escape: "npm:^1.0.0"
|
zeptomatch-escape: "npm:^1.0.1"
|
||||||
zeptomatch-is-static: "npm:^1.0.0"
|
zeptomatch-is-static: "npm:^1.0.1"
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
prettier: ^3.1.0 || ^4.0.0-alpha
|
prettier: ^3.1.0 || ^4.0.0-alpha
|
||||||
bin:
|
bin:
|
||||||
prettier-next: dist/bin.js
|
prettier-next: dist/bin.js
|
||||||
checksum: 10/ec695d454d82037a8b09bce3c1d74acae924eb226c65cf62435744279a4cedc408c463c42f54d66b2b65471ceedf216ab82f170e000066a425cae47a816c2062
|
checksum: 10/753832b6404659c19e88725d99cb650e4cadcc012f5a64fb29c02c52f68307e9c1d17e86a3677b766a19d3ce4733a09d4d3a0092edd064123abcd8e5548e0b0a
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -2631,10 +2630,10 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"binary-extensions@npm:^2.0.0":
|
"binary-extensions@npm:^3.0.0":
|
||||||
version: 2.3.0
|
version: 3.0.0
|
||||||
resolution: "binary-extensions@npm:2.3.0"
|
resolution: "binary-extensions@npm:3.0.0"
|
||||||
checksum: 10/bcad01494e8a9283abf18c1b967af65ee79b0c6a9e6fcfafebfe91dbe6e0fc7272bafb73389e198b310516ae04f7ad17d79aacf6cb4c0d5d5202a7e2e52c7d98
|
checksum: 10/2ea1a54b4f0fd466e5601247938fd3811f13de819d024401e1c01ddcba46b8168154ef27fcb6abbe62e51ee3115174e4316ee0b92352844d59279f24fb110d05
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -4373,7 +4372,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"find-up-json@npm:^2.0.4, find-up-json@npm:^2.0.5":
|
"find-up-json@npm:^2.0.5":
|
||||||
version: 2.0.5
|
version: 2.0.5
|
||||||
resolution: "find-up-json@npm:2.0.5"
|
resolution: "find-up-json@npm:2.0.5"
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -4520,7 +4519,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"function-once@npm:^3.0.0":
|
"function-once@npm:^3.0.1":
|
||||||
version: 3.0.1
|
version: 3.0.1
|
||||||
resolution: "function-once@npm:3.0.1"
|
resolution: "function-once@npm:3.0.1"
|
||||||
checksum: 10/11cc5e0fc669c01c4ec47f90b416444ee0ebfde80b43dd99011dcde46c9e16200a74cc078db646a60d4fbcb61736be729073ed2b4a46abdf2ed8d0e7e01d35e9
|
checksum: 10/11cc5e0fc669c01c4ec47f90b416444ee0ebfde80b43dd99011dcde46c9e16200a74cc078db646a60d4fbcb61736be729073ed2b4a46abdf2ed8d0e7e01d35e9
|
||||||
@@ -4983,12 +4982,12 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"is-binary-path@npm:^2.1.0":
|
"is-binary-path@npm:^3.0.0":
|
||||||
version: 2.1.0
|
version: 3.0.0
|
||||||
resolution: "is-binary-path@npm:2.1.0"
|
resolution: "is-binary-path@npm:3.0.0"
|
||||||
dependencies:
|
dependencies:
|
||||||
binary-extensions: "npm:^2.0.0"
|
binary-extensions: "npm:^3.0.0"
|
||||||
checksum: 10/078e51b4f956c2c5fd2b26bb2672c3ccf7e1faff38e0ebdba45612265f4e3d9fc3127a1fa8370bbf09eab61339203c3d3b7af5662cbf8be4030f8fac37745b0e
|
checksum: 10/3b2ff558f3f14cc90a7311638b787ed1ebb964dff5b8fb310b8e4f986d9718f9c14885c6963219186c8916a53c6fda4c7884f478c4b8293660d9493230998fa9
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -5987,7 +5986,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"json-sorted-stringify@npm:^1.0.0":
|
"json-sorted-stringify@npm:^1.0.1":
|
||||||
version: 1.0.1
|
version: 1.0.1
|
||||||
resolution: "json-sorted-stringify@npm:1.0.1"
|
resolution: "json-sorted-stringify@npm:1.0.1"
|
||||||
checksum: 10/5d23777e2d9114d9b242a1ccda1041d2639ad0db7a4178abd6937ffebf1efb18b018208b29c4ec0f78632d82c64815ec73e53d96fae63930aa7ab5c216e0ad8e
|
checksum: 10/5d23777e2d9114d9b242a1ccda1041d2639ad0db7a4178abd6937ffebf1efb18b018208b29c4ec0f78632d82c64815ec73e53d96fae63930aa7ab5c216e0ad8e
|
||||||
@@ -6010,7 +6009,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"kasi@npm:^1.1.0":
|
"kasi@npm:^1.1.1":
|
||||||
version: 1.1.1
|
version: 1.1.1
|
||||||
resolution: "kasi@npm:1.1.1"
|
resolution: "kasi@npm:1.1.1"
|
||||||
checksum: 10/6a686901db23c872c7e5965d4e044610a9b81c988106b733eebac76a49055895d3393331dffba5ed605b85cd532b2bb507133a488ce89617098523dc0df019d0
|
checksum: 10/6a686901db23c872c7e5965d4e044610a9b81c988106b733eebac76a49055895d3393331dffba5ed605b85cd532b2bb507133a488ce89617098523dc0df019d0
|
||||||
@@ -6151,7 +6150,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"lomemo@npm:^1.0.0":
|
"lomemo@npm:^1.0.1":
|
||||||
version: 1.0.1
|
version: 1.0.1
|
||||||
resolution: "lomemo@npm:1.0.1"
|
resolution: "lomemo@npm:1.0.1"
|
||||||
checksum: 10/6459218d0461eb59f2a0ba176b905bfb21c2a41879778b5f5ffcf4a955bbf71b66701b4641290181face7c455dcba486a05923722450b25ddc918a4a29e432c1
|
checksum: 10/6459218d0461eb59f2a0ba176b905bfb21c2a41879778b5f5ffcf4a955bbf71b66701b4641290181face7c455dcba486a05923722450b25ddc918a4a29e432c1
|
||||||
@@ -6834,7 +6833,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"pioppo@npm:^1.2.0":
|
"pioppo@npm:^1.2.1":
|
||||||
version: 1.2.1
|
version: 1.2.1
|
||||||
resolution: "pioppo@npm:1.2.1"
|
resolution: "pioppo@npm:1.2.1"
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -6993,7 +6992,7 @@ __metadata:
|
|||||||
"@eslint-react/eslint-plugin": "npm:1.40.4"
|
"@eslint-react/eslint-plugin": "npm:1.40.4"
|
||||||
"@eslint/js": "npm:9.24.0"
|
"@eslint/js": "npm:9.24.0"
|
||||||
"@glimmer/syntax": "npm:0.94.9"
|
"@glimmer/syntax": "npm:0.94.9"
|
||||||
"@prettier/cli": "npm:0.7.1"
|
"@prettier/cli": "npm:0.8.0"
|
||||||
"@prettier/html-tags": "npm:1.0.0"
|
"@prettier/html-tags": "npm:1.0.0"
|
||||||
"@prettier/parse-srcset": "npm:3.1.0"
|
"@prettier/parse-srcset": "npm:3.1.0"
|
||||||
"@stylistic/eslint-plugin-js": "npm:4.2.0"
|
"@stylistic/eslint-plugin-js": "npm:4.2.0"
|
||||||
@@ -7180,7 +7179,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"promise-resolve-timeout@npm:^2.0.0":
|
"promise-resolve-timeout@npm:^2.0.1":
|
||||||
version: 2.0.1
|
version: 2.0.1
|
||||||
resolution: "promise-resolve-timeout@npm:2.0.1"
|
resolution: "promise-resolve-timeout@npm:2.0.1"
|
||||||
checksum: 10/acfff518f185c209caa6d67f9a5bf540105d207752d2065b8d0d5579d49f04f5b2e374d2e64ac08f9459fc7feaabfbbbbb9ec66f342a82a9459db4e8bfd72a4e
|
checksum: 10/acfff518f185c209caa6d67f9a5bf540105d207752d2065b8d0d5579d49f04f5b2e374d2e64ac08f9459fc7feaabfbbbbb9ec66f342a82a9459db4e8bfd72a4e
|
||||||
@@ -7617,7 +7616,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"smol-toml@npm:1.3.4, smol-toml@npm:^1.3.1":
|
"smol-toml@npm:1.3.4, smol-toml@npm:^1.3.1, smol-toml@npm:^1.3.4":
|
||||||
version: 1.3.4
|
version: 1.3.4
|
||||||
resolution: "smol-toml@npm:1.3.4"
|
resolution: "smol-toml@npm:1.3.4"
|
||||||
checksum: 10/795db36448db6b353ea1171fad8b72ae2fea3b5f9aa48d2f4c79699e10bdca74d59202f6715ff738fae817bf1f80e0c38c4d3ddf8b812cac26cc6255eaa0caa2
|
checksum: 10/795db36448db6b353ea1171fad8b72ae2fea3b5f9aa48d2f4c79699e10bdca74d59202f6715ff738fae817bf1f80e0c38c4d3ddf8b812cac26cc6255eaa0caa2
|
||||||
@@ -8090,13 +8089,6 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"tiny-jsonc@npm:^1.0.1":
|
|
||||||
version: 1.0.2
|
|
||||||
resolution: "tiny-jsonc@npm:1.0.2"
|
|
||||||
checksum: 10/6eec910615606a2a940233179da74053b139e18de7cda4075689ad8f9da9cfefecb9ec86389fba9885dbe16ce9b708b5e24d847256efb7b8af324447d9d70e15
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"tiny-levenshtein@npm:^1.0.1":
|
"tiny-levenshtein@npm:^1.0.1":
|
||||||
version: 1.0.1
|
version: 1.0.1
|
||||||
resolution: "tiny-levenshtein@npm:1.0.1"
|
resolution: "tiny-levenshtein@npm:1.0.1"
|
||||||
@@ -8111,16 +8103,16 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"tiny-readdir-glob@npm:^1.23.1":
|
"tiny-readdir-glob@npm:^1.23.2":
|
||||||
version: 1.23.1
|
version: 1.23.2
|
||||||
resolution: "tiny-readdir-glob@npm:1.23.1"
|
resolution: "tiny-readdir-glob@npm:1.23.2"
|
||||||
dependencies:
|
dependencies:
|
||||||
tiny-readdir: "npm:^2.7.0"
|
tiny-readdir: "npm:^2.7.0"
|
||||||
zeptomatch: "npm:^1.2.2"
|
zeptomatch: "npm:^2.0.1"
|
||||||
zeptomatch-explode: "npm:^1.0.0"
|
zeptomatch-explode: "npm:^1.0.1"
|
||||||
zeptomatch-is-static: "npm:^1.0.0"
|
zeptomatch-is-static: "npm:^1.0.1"
|
||||||
zeptomatch-unescape: "npm:^1.0.0"
|
zeptomatch-unescape: "npm:^1.0.1"
|
||||||
checksum: 10/ada70ed76fccab497376b1c0bdc0abe4cdc588ae25914907c9d8947a24fc109c21c7c36b065596fb794eea3f3a29505c2551780c54ad526943619274cf2086ec
|
checksum: 10/ebc0cfcbb08ef8dc137eb83569410ab809d815921b3c7fe9534956a89e5e80962435b8c034d21399bb856fd95e7cbbe9d10ebaccbd1b89f26516753e12501c76
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -8133,7 +8125,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"tiny-spinner@npm:^2.0.4":
|
"tiny-spinner@npm:^2.0.5":
|
||||||
version: 2.0.5
|
version: 2.0.5
|
||||||
resolution: "tiny-spinner@npm:2.0.5"
|
resolution: "tiny-spinner@npm:2.0.5"
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -8815,35 +8807,35 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"zeptomatch-escape@npm:^1.0.0":
|
"zeptomatch-escape@npm:^1.0.1":
|
||||||
version: 1.0.1
|
version: 1.0.1
|
||||||
resolution: "zeptomatch-escape@npm:1.0.1"
|
resolution: "zeptomatch-escape@npm:1.0.1"
|
||||||
checksum: 10/d2b27a6d0abab50ea59e0f2d8526b1946db02e498dc2f5105ec060868fc8f1e745618d164ed170439ebb85678e5c06acb781c840eb36ec625c775e96472ff0ef
|
checksum: 10/d2b27a6d0abab50ea59e0f2d8526b1946db02e498dc2f5105ec060868fc8f1e745618d164ed170439ebb85678e5c06acb781c840eb36ec625c775e96472ff0ef
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"zeptomatch-explode@npm:^1.0.0":
|
"zeptomatch-explode@npm:^1.0.1":
|
||||||
version: 1.0.1
|
version: 1.0.1
|
||||||
resolution: "zeptomatch-explode@npm:1.0.1"
|
resolution: "zeptomatch-explode@npm:1.0.1"
|
||||||
checksum: 10/4424d5f58484b4e4b191f8afb17d582fbde4efcd1f25fb90a240b0f5490e7d3ab82bf0a0b6ab4e1898a918f83a9e874d611733ff0a1ddb7cf929797d870ead2c
|
checksum: 10/4424d5f58484b4e4b191f8afb17d582fbde4efcd1f25fb90a240b0f5490e7d3ab82bf0a0b6ab4e1898a918f83a9e874d611733ff0a1ddb7cf929797d870ead2c
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"zeptomatch-is-static@npm:^1.0.0":
|
"zeptomatch-is-static@npm:^1.0.1":
|
||||||
version: 1.0.1
|
version: 1.0.1
|
||||||
resolution: "zeptomatch-is-static@npm:1.0.1"
|
resolution: "zeptomatch-is-static@npm:1.0.1"
|
||||||
checksum: 10/2cc3e039034d3fa9081a2f00e50cb2932cc7d9fe061841eadef24f032ec610d32f679e28ddf6e5c50c26c567e7b6d590ded70efe1efc7d066552a0505c02d7a2
|
checksum: 10/2cc3e039034d3fa9081a2f00e50cb2932cc7d9fe061841eadef24f032ec610d32f679e28ddf6e5c50c26c567e7b6d590ded70efe1efc7d066552a0505c02d7a2
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"zeptomatch-unescape@npm:^1.0.0":
|
"zeptomatch-unescape@npm:^1.0.1":
|
||||||
version: 1.0.1
|
version: 1.0.1
|
||||||
resolution: "zeptomatch-unescape@npm:1.0.1"
|
resolution: "zeptomatch-unescape@npm:1.0.1"
|
||||||
checksum: 10/2139c86901fd58950658b0f2c618fd0ffa4b5389d8a7c3009a17d7da362d9fa4d6a79d94e7c6d969bd72e683354ee84e24c8404bb1476bba1d2b2935a500544d
|
checksum: 10/2139c86901fd58950658b0f2c618fd0ffa4b5389d8a7c3009a17d7da362d9fa4d6a79d94e7c6d969bd72e683354ee84e24c8404bb1476bba1d2b2935a500544d
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"zeptomatch@npm:^1.1.3, zeptomatch@npm:^1.2.2":
|
"zeptomatch@npm:^1.1.3":
|
||||||
version: 1.2.2
|
version: 1.2.2
|
||||||
resolution: "zeptomatch@npm:1.2.2"
|
resolution: "zeptomatch@npm:1.2.2"
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -8852,7 +8844,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"zeptomatch@npm:^2.0.0":
|
"zeptomatch@npm:^2.0.1":
|
||||||
version: 2.0.1
|
version: 2.0.1
|
||||||
resolution: "zeptomatch@npm:2.0.1"
|
resolution: "zeptomatch@npm:2.0.1"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
Reference in new issue
Block a user