From e42ece5b1f2b881fc94ae6768945c7e23e34ea89 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Mon, 28 Jun 2021 21:09:31 -0400 Subject: [PATCH] [prettierx-rebase-branch-001] rename bin & test config items to be more consistent with prettierX 0.18.x including some updates from: - https://github.com/brodybits/prettierx/pull/549 - https://github.com/brodybits/prettierx/pull/569 - https://github.com/brodybits/prettierx/pull/603 Co-authored-by: Christopher J. Brody Co-authored-by: Adaline Valentina Simonian --- bin/{prettier.js => prettierx.js} | 0 jest.config.js | 14 +++++++++----- package.json | 2 +- scripts/build/build.mjs | 3 ++- scripts/build/config.mjs | 8 +++++--- .../{install-prettier.js => install-prettierx.js} | 0 tests/config/require-prettier.js | 5 ----- tests/config/require-prettierx.js | 6 ++++++ tests/config/require-standalone.js | 14 ++++++++++---- tests/integration/env.js | 12 +++++++----- 10 files changed, 40 insertions(+), 24 deletions(-) rename bin/{prettier.js => prettierx.js} (100%) rename scripts/{install-prettier.js => install-prettierx.js} (100%) delete mode 100644 tests/config/require-prettier.js create mode 100644 tests/config/require-prettierx.js diff --git a/bin/prettier.js b/bin/prettierx.js similarity index 100% rename from bin/prettier.js rename to bin/prettierx.js diff --git a/jest.config.js b/jest.config.js index 684a50a5e1..822c28f74b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,9 @@ "use strict"; const path = require("path"); -const installPrettier = require("./scripts/install-prettier"); + +// [prettierx] +const installPrettier = require("./scripts/install-prettierx"); const PROJECT_ROOT = __dirname; const isProduction = process.env.NODE_ENV === "production"; @@ -9,13 +11,14 @@ const ENABLE_CODE_COVERAGE = Boolean(process.env.ENABLE_CODE_COVERAGE); const TEST_STANDALONE = Boolean(process.env.TEST_STANDALONE); const INSTALL_PACKAGE = Boolean(process.env.INSTALL_PACKAGE); -let PRETTIER_DIR = isProduction +// [prettierx] +let PRETTIERX_DIR = isProduction ? path.join(PROJECT_ROOT, "dist") : PROJECT_ROOT; if (INSTALL_PACKAGE || (isProduction && !TEST_STANDALONE)) { - PRETTIER_DIR = installPrettier(PRETTIER_DIR); + PRETTIERX_DIR = installPrettier(PRETTIERX_DIR); } -process.env.PRETTIER_DIR = PRETTIER_DIR; +process.env.PRETTIERX_DIR = PRETTIERX_DIR; const testPathIgnorePatterns = []; let transform = {}; @@ -68,7 +71,8 @@ module.exports = { ], coverageReporters: ["text", "lcov"], moduleNameMapper: { - "prettier-local": "/tests/config/require-prettier.js", + // [prettierx] + "prettier-local": "/tests/config/require-prettierx.js", "prettier-standalone": "/tests/config/require-standalone.js", }, modulePathIgnorePatterns: ["/dist", "/website"], diff --git a/package.json b/package.json index b0e28c23a2..6e2d26cd2a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.1.0-dev", "prettier-version": "2.4.0", "description": "prettierx-rebase-branch-001 version branch", - "bin": "./bin/prettier.js", + "bin": "./bin/prettierx.js", "license": "MIT", "main": "./index.js", "browser": "./standalone.js", diff --git a/scripts/build/build.mjs b/scripts/build/build.mjs index c399734d22..62b6258db2 100644 --- a/scripts/build/build.mjs +++ b/scripts/build/build.mjs @@ -133,7 +133,8 @@ async function cacheFiles(cache) { async function preparePackage() { const pkg = await utils.readJson("package.json"); - pkg.bin = "./bin-prettier.js"; + // [prettierx] + pkg.bin = "./bin-prettierx.js"; pkg.engines.node = ">=10.13.0"; delete pkg.dependencies; delete pkg.devDependencies; diff --git a/scripts/build/config.mjs b/scripts/build/config.mjs index a87ed0b910..bd781037e1 100644 --- a/scripts/build/config.mjs +++ b/scripts/build/config.mjs @@ -130,13 +130,15 @@ const coreBundles = [ minify: false, }, { + // [prettierx] input: "src/standalone.js", - name: "prettier", + name: "prettierx", target: "universal", }, { - input: "bin/prettier.js", - output: "bin-prettier.js", + // [prettierx] + input: "bin/prettierx.js", + output: "bin-prettierx.js", external: ["benchmark"], }, { diff --git a/scripts/install-prettier.js b/scripts/install-prettierx.js similarity index 100% rename from scripts/install-prettier.js rename to scripts/install-prettierx.js diff --git a/tests/config/require-prettier.js b/tests/config/require-prettier.js deleted file mode 100644 index e18cf8c6ea..0000000000 --- a/tests/config/require-prettier.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict"; - -const prettier = require(process.env.PRETTIER_DIR); - -module.exports = prettier; diff --git a/tests/config/require-prettierx.js b/tests/config/require-prettierx.js new file mode 100644 index 0000000000..33a6e1f117 --- /dev/null +++ b/tests/config/require-prettierx.js @@ -0,0 +1,6 @@ +"use strict"; + +// [prettierx] +const prettier = require(process.env.PRETTIERX_DIR); + +module.exports = prettier; diff --git a/tests/config/require-standalone.js b/tests/config/require-standalone.js index a7ee4e6a55..86cbdfce04 100644 --- a/tests/config/require-standalone.js +++ b/tests/config/require-standalone.js @@ -8,7 +8,8 @@ const sandbox = vm.createContext(); const source = globby .sync(["standalone.js", "parser-*.js"], { - cwd: process.env.PRETTIER_DIR, + // [prettierx] + cwd: process.env.PRETTIERX_DIR, absolute: true, }) .map((file) => fs.readFileSync(file, "utf8")) @@ -16,7 +17,8 @@ const source = globby vm.runInContext(source, sandbox); -const allowedGlobalObjects = new Set(["prettier", "prettierPlugins"]); +// [prettierx] +const allowedGlobalObjects = new Set(["prettierx", "prettierPlugins"]); const globalObjects = Object.keys(sandbox).filter( (property) => !allowedGlobalObjects.has(property) ); @@ -38,6 +40,7 @@ if (globalObjects.length > 0) { module.exports = { formatWithCursor(input, options) { return vm.runInNewContext( + // [prettierx] ` const options = { ...$$$options, @@ -46,7 +49,7 @@ module.exports = { ...($$$options.plugins || []), ], }; - prettier.formatWithCursor($$$input, options); + prettierx.formatWithCursor($$$input, options); `, { $$$input: input, $$$options: options, ...sandbox } ); @@ -55,6 +58,7 @@ module.exports = { __debug: { parse(input, options, massage) { return vm.runInNewContext( + // [prettierx] ` const options = { ...$$$options, @@ -63,7 +67,9 @@ module.exports = { ...($$$options.plugins || []), ], }; - prettier.__debug.parse($$$input, options, ${JSON.stringify(massage)}); + prettierx.__debug.parse($$$input, options, ${JSON.stringify( + massage + )}); `, { $$$input: input, $$$options: options, ...sandbox } ); diff --git a/tests/integration/env.js b/tests/integration/env.js index 7fc8472a36..60adf2b541 100644 --- a/tests/integration/env.js +++ b/tests/integration/env.js @@ -2,18 +2,20 @@ const path = require("path"); const isProduction = process.env.NODE_ENV === "production"; -const { PRETTIER_DIR } = process.env; +// [prettierx] +const { PRETTIERX_DIR } = process.env; // [prettierx] get fork package name from package.json -const { bin, name } = require(path.join(PRETTIER_DIR, "package.json")); +const { bin, name } = require(path.join(PRETTIERX_DIR, "package.json")); const prettierCli = path.join( - PRETTIER_DIR, + PRETTIERX_DIR, // [prettierx] use fork package name from package.json typeof bin === "object" ? bin[name] : bin ); +// [prettierx] const thirdParty = isProduction - ? path.join(PRETTIER_DIR, "./third-party") - : path.join(PRETTIER_DIR, "./src/common/third-party"); + ? path.join(PRETTIERX_DIR, "./third-party") + : path.join(PRETTIERX_DIR, "./src/common/third-party"); const projectRoot = path.join(__dirname, "../..");