Major refactor (#18381)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-12-01 07:25:25 +08:00
1 parent 45a738c7c0
commit e240f15e75
350 files changed
+1374 -1283

No files matched your search

+2 -1
View File
@@ -7,7 +7,8 @@ const groupSize = Number(groupSizeString);
const { format } = await import(`./${version}/dist/index.mjs`);
const sourceText = readFileSync(
process.env.PRETTIER_PERF_FILENAME || "../../src/language-js/utils/index.js",
process.env.PRETTIER_PERF_FILENAME ||
"../../src/language-js/utilities/index.js",
"utf8",
);
+1 -1
View File
@@ -14,7 +14,7 @@ import {
WEBSITE_DIR,
writeFile,
writeJson,
} from "./utils/index.js";
} from "./utilities/index.js";
const runYarn = (command, args, options) =>
spawn("yarn", [command, ...args], { stdio: "inherit", ...options });
+1 -1
View File
@@ -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 { PROJECT_ROOT } from "../utils/index.js";
import { PROJECT_ROOT } from "../utilities/index.js";
const separator = `\n${"-".repeat(40)}\n\n`;
+2 -2
View File
@@ -6,7 +6,7 @@ import createEsmUtils from "esm-utils";
import {
PRODUCTION_MINIMAL_NODE_JS_VERSION,
PROJECT_ROOT,
} from "../utils/index.js";
} from "../utilities/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";
@@ -17,7 +17,7 @@ import esbuildPluginThrowWarnings from "./esbuild-plugins/throw-warnings.js";
import esbuildPluginUmd from "./esbuild-plugins/umd.js";
import esbuildPluginVisualizer from "./esbuild-plugins/visualizer.js";
import transform from "./transform/index.js";
import { getPackageFile } from "./utils.js";
import { getPackageFile } from "./utilities.js";
const {
readJsonSync,
+1 -1
View File
@@ -4,7 +4,7 @@ import {
PROJECT_ROOT,
readJson,
writeJson,
} from "../utils/index.js";
} from "../utilities/index.js";
const keysToKeep = [
"name",
+1 -1
View File
@@ -3,7 +3,7 @@ import path from "node:path";
import url from "node:url";
import { isValidIdentifier } from "@babel/types";
import { outdent } from "outdent";
import { PROJECT_ROOT, writeFile } from "../utils/index.js";
import { PROJECT_ROOT, writeFile } from "../utilities/index.js";
async function typesFileBuilder({ packageConfig, file }) {
/**
+1 -1
View File
@@ -7,7 +7,7 @@ import createEsmUtils from "esm-utils";
import styleText from "node-style-text";
import prettyBytes from "pretty-bytes";
import prettyMilliseconds from "pretty-ms";
import { DIST_DIR } from "../utils/index.js";
import { DIST_DIR } from "../utilities/index.js";
import packageConfigs from "./config.js";
import parseArguments from "./parse-arguments.js";
+2 -2
View File
@@ -3,7 +3,7 @@ import path from "node:path";
import url from "node:url";
import createEsmUtils from "esm-utils";
import { outdent } from "outdent";
import { copyFile, DIST_DIR, PROJECT_ROOT } from "../utils/index.js";
import { copyFile, DIST_DIR, PROJECT_ROOT } from "../utilities/index.js";
import buildDependenciesLicense from "./build-dependencies-license.js";
import buildJavascriptModule from "./build-javascript-module.js";
import buildOxcWasmParser from "./build-oxc-wasm-parser.js";
@@ -15,7 +15,7 @@ import {
import buildTypes from "./build-types.js";
import esmifyTypescriptEslint from "./esmify-typescript-eslint.js";
import modifyTypescriptModule from "./modify-typescript-module.js";
import { getPackageFile } from "./utils.js";
import { getPackageFile } from "./utilities.js";
const {
require,
+1 -1
View File
@@ -2,7 +2,7 @@
import * as path from "node:path";
import { outdent } from "outdent";
import { PROJECT_ROOT, writeFile } from "../utils/index.js";
import { PROJECT_ROOT, writeFile } from "../utilities/index.js";
function esmifyTypescriptEslint(text) {
/*
+1 -1
View File
@@ -2,7 +2,7 @@ import path from "node:path";
import escapeStringRegexp from "escape-string-regexp";
import MagicString from "magic-string";
import { outdent } from "outdent";
import { PROJECT_ROOT, writeFile } from "../utils/index.js";
import { PROJECT_ROOT, writeFile } from "../utilities/index.js";
import UNUSED_SPECIFIERS from "./typescript-unused-specifiers.js";
function* getModules(text) {
+1 -1
View File
@@ -1,6 +1,6 @@
import path from "node:path";
import { parseArgs } from "node:util";
import { DIST_DIR } from "../utils/index.js";
import { DIST_DIR } from "../utilities/index.js";
const isUnique = (array) => new Set(array).size === array.length;
+1 -1
View File
@@ -3,7 +3,7 @@ import generate from "@babel/generator";
import { parse } from "@babel/parser";
import { traverseFast as traverse } from "@babel/types";
import { outdent } from "outdent";
import { PROJECT_ROOT, SOURCE_DIR } from "../../utils/index.js";
import { PROJECT_ROOT, SOURCE_DIR } from "../../utilities/index.js";
import * as transforms from "./transforms/index.js";
const packageTransforms = new Map([
@@ -1,7 +1,7 @@
import path from "node:path";
import { pathToFileURL } from "node:url";
import makeSynchronized from "make-synchronized";
import { SOURCE_DIR } from "../../../utils/index.js";
import { SOURCE_DIR } from "../../../utilities/index.js";
const PUBLIC_MODULE_URL = pathToFileURL(
path.join(SOURCE_DIR, "document/public.js"),
@@ -1,5 +1,5 @@
import path from "node:path";
import { SOURCE_DIR } from "../../../utils/index.js";
import { SOURCE_DIR } from "../../../utilities/index.js";
import getPublicDocFunctionality from "./get-public-doc-functionality.js";
import {
createIdentifier,
@@ -3,7 +3,7 @@ import path from "node:path";
import url from "node:url";
import { resolve } from "import-meta-resolve";
import { isUrl, toUrl } from "url-or-path";
import { PROJECT_ROOT } from "../utils/index.js";
import { PROJECT_ROOT } from "../utilities/index.js";
const NODE_MODULES_PATH = path.join(PROJECT_ROOT, "node_modules");
+1 -1
View File
@@ -3,7 +3,7 @@ import fs from "node:fs/promises";
import path from "node:path";
import eslintPluginCompat from "eslint-plugin-compat";
import buildConfig from "./build/config.js";
import { DIST_DIR } from "./utils/index.js";
import { DIST_DIR } from "./utilities/index.js";
const { browserslist: targets } = JSON.parse(
await fs.readFile(new URL("../package.json", import.meta.url)),
+1 -1
View File
@@ -10,7 +10,7 @@ import {
getEntries,
printEntries,
replaceVersions,
} from "./utils/changelog.js";
} from "./utilities/changelog.js";
const { previousVersion, newVersion } = parseArguments();
+1 -1
View File
@@ -12,7 +12,7 @@ import {
getEntries,
printEntries,
replaceVersions,
} from "./utils/changelog.js";
} from "./utilities/changelog.js";
const { __dirname, require } = createEsmUtils(import.meta);
const blogDir = path.join(__dirname, "../website/blog");
+1 -1
View File
@@ -4,7 +4,7 @@
import fs from "node:fs/promises";
import path from "node:path";
import { PROJECT_ROOT } from "./utils/index.js";
import { PROJECT_ROOT } from "./utilities/index.js";
const FORMAT_TEST_DIRECTORY = path.join(PROJECT_ROOT, "tests/format/");
const TEST_SCRIPT_FILE_NAME = "format.test.js";
+1 -1
View File
@@ -12,7 +12,7 @@
import fs from "node:fs/promises";
import enquirer from "enquirer";
import openEditor from "open-editor";
import { CHANGELOG_CATEGORIES } from "./utils/changelog-categories.js";
import { CHANGELOG_CATEGORIES } from "./utilities/changelog-categories.js";
const prNumberPrompt = new enquirer.NumberPrompt({
message: "Input your Pull Request number:",
+1 -1
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import { generateSchema } from "./utils/generate-schema.js";
import { generateSchema } from "./utilities/generate-schema.js";
console.log(await generateSchema());
+1 -1
View File
@@ -6,7 +6,7 @@ import indexToPosition from "index-to-position";
import { outdent } from "outdent";
import remarkParse from "remark-parse";
import unified from "unified";
import { CHANGELOG_CATEGORIES } from "./utils/changelog-categories.js";
import { CHANGELOG_CATEGORIES } from "./utilities/changelog-categories.js";
const CHANGELOG_DIR = "changelog_unreleased";
const TEMPLATE_FILE = "TEMPLATE.md";
+1 -1
View File
@@ -1,4 +1,4 @@
// TODO: Implement this in `utils.js` when jest.importActual is landed.
// TODO: Implement this in `utilities.js` when jest.importActual is landed.
export default function getFormattedDate() {
const date = new Date();
const isoStr = date.toISOString();
+1 -1
View File
@@ -1,7 +1,7 @@
import semver from "semver";
import parseArguments from "./parse-arguments.js";
import * as steps from "./steps/index.js";
import { logPromise, readJson } from "./utils.js";
import { logPromise, readJson } from "./utilities.js";
const params = parseArguments();
const {
+7 -1
View File
@@ -1,6 +1,12 @@
import fs from "node:fs";
import semver from "semver";
import { logPromise, readJson, runGit, runYarn, writeJson } from "../utils.js";
import {
logPromise,
readJson,
runGit,
runYarn,
writeJson,
} from "../utilities.js";
async function format() {
await runYarn(["fix:prettier"]);
+1 -1
View File
@@ -1,4 +1,4 @@
import { runGit } from "../utils.js";
import { runGit } from "../utilities.js";
export default async function checkGitStatus({ next }) {
const { stdout: status } = await runGit(["status", "--porcelain"]);
+1 -1
View File
@@ -1,7 +1,7 @@
import fs from "node:fs/promises";
import { fileURLToPath } from "node:url";
import fastGlob from "fast-glob";
import { runGit } from "../utils.js";
import { runGit } from "../utilities.js";
export default async function cleanChangelog({ repo }) {
const changelogUnreleasedDir = fileURLToPath(
+1 -1
View File
@@ -1,5 +1,5 @@
import styleText from "node-style-text";
import { logPromise, readJson, runYarn } from "../utils.js";
import { logPromise, readJson, runYarn } from "../utilities.js";
export default async function generateBundles({ dry, version, manual }) {
if (!manual) {
@@ -1,5 +1,5 @@
import fs from "node:fs/promises";
import { runGit, runYarn } from "../utils.js";
import { runGit, runYarn } from "../utilities.js";
const PROJECT_ROOT = new URL("../../../", import.meta.url);
+1 -1
View File
@@ -1,4 +1,4 @@
import { runYarn } from "../utils.js";
import { runYarn } from "../utilities.js";
const lintFiles = () => runYarn("lint");
+1 -1
View File
@@ -1,6 +1,6 @@
import styleText from "node-style-text";
import semver from "semver";
import { runGit, waitForEnter } from "../utils.js";
import { runGit, waitForEnter } from "../utilities.js";
export default async function mergeBlogPost({
dry,
+2 -2
View File
@@ -1,6 +1,6 @@
import styleText from "node-style-text";
import outdent from "outdent";
import { fetchText, logPromise, writeFile } from "../utils.js";
import { fetchText, logPromise, writeFile } from "../utilities.js";
const SCHEMA_REPO = "SchemaStore/schemastore";
const SCHEMA_PATH = "src/schemas/json/prettierrc.json";
@@ -10,7 +10,7 @@ const EDIT_URL = `https://github.com/${SCHEMA_REPO}/edit/master/${SCHEMA_PATH}`;
// Any optional or manual step can be warned in this script.
async function checkSchema() {
const { generateSchema } = await import("../../utils/generate-schema.js");
const { generateSchema } = await import("../../utilities/generate-schema.js");
const schema = await generateSchema();
const remoteSchema = await logPromise(
"Checking current schema in SchemaStore",
+1 -1
View File
@@ -1,6 +1,6 @@
import enquirer from "enquirer";
import spawn from "nano-spawn";
import { waitForEnter } from "../utils.js";
import { waitForEnter } from "../utilities.js";
export default async function publishToNpm({ dry }) {
console.log(`Ready to publish to NPM${dry ? "(--dry-run)" : ""}`);
+1 -1
View File
@@ -1,4 +1,4 @@
import { runGit } from "../utils.js";
import { runGit } from "../utilities.js";
export default async function pushToGit({ version, repo }) {
await runGit(["commit", "-am", `Release ${version}`]);
@@ -5,7 +5,7 @@ import {
getBlogPostInfo,
getChangelogContent,
waitForEnter,
} from "../utils.js";
} from "../utilities.js";
const RELEASE_URL_BASE = "https://github.com/prettier/prettier/releases/new?";
export function getReleaseUrl(version, previousVersion) {
+1 -1
View File
@@ -8,7 +8,7 @@ import {
logPromise,
runYarn,
waitForEnter,
} from "../utils.js";
} from "../utilities.js";
function writeChangelog(params) {
const changelog = fs.readFileSync("CHANGELOG.md", "utf8");
@@ -1,5 +1,5 @@
import styleText from "node-style-text";
import { fetchText, logPromise, processFile, runGit } from "../utils.js";
import { fetchText, logPromise, processFile, runGit } from "../utilities.js";
async function getNpmDependentsCount() {
const npmPage = await logPromise(
+1 -1
View File
@@ -1,4 +1,4 @@
import { processFile, readJson, runYarn, writeJson } from "../utils.js";
import { processFile, readJson, runYarn, writeJson } from "../utilities.js";
export default async function updateVersion({ version, next }) {
const pkg = await readJson("package.json");
@@ -1,6 +1,6 @@
import styleText from "node-style-text";
import outdent from "outdent";
import { logPromise, waitForEnter } from "../utils.js";
import { logPromise, waitForEnter } from "../utilities.js";
export async function isVersionReleased(version) {
const response = await fetch("https://registry.npmjs.org/prettier/");
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.