Skip to content

Commit

Permalink
[prettierx-update-branch-0010] rename bin & test config items
Browse files Browse the repository at this point in the history
to be more consistent with prettierX 0.18.x

including some updates from:

- #549
- #569

Co-authored-by: Christopher J. Brody <[email protected]>
Co-authored-by: Adaline Valentina Simonian <[email protected]>
  • Loading branch information
brodycj and adalinesimonian committed Jun 17, 2021
1 parent 0d065fe commit ec3378a
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 25 deletions.
File renamed without changes.
14 changes: 9 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
"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";
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 = {};
Expand Down Expand Up @@ -68,7 +71,8 @@ module.exports = {
],
coverageReporters: ["text", "lcov"],
moduleNameMapper: {
"prettier-local": "<rootDir>/tests/config/require-prettier.js",
// [prettierx]
"prettier-local": "<rootDir>/tests/config/require-prettierx.js",
"prettier-standalone": "<rootDir>/tests/config/require-standalone.js",
},
modulePathIgnorePatterns: ["<rootDir>/dist", "<rootDir>/website"],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "prettierx-update-branch-0010",
"version": "0.1.0-dev",
"description": "prettierx-update-branch-0010 version branch",
"bin": "./bin/prettier.js",
"bin": "./bin/prettierx.js",
"author": "James Long",
"license": "MIT",
"main": "./index.js",
Expand Down
3 changes: 2 additions & 1 deletion scripts/build/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions scripts/build/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
},
{
Expand Down
File renamed without changes.
5 changes: 0 additions & 5 deletions tests/config/require-prettier.js

This file was deleted.

6 changes: 6 additions & 0 deletions tests/config/require-prettierx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";

// [prettierx]
const prettier = require(process.env.PRETTIERX_DIR);

module.exports = prettier;
14 changes: 10 additions & 4 deletions tests/config/require-standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ 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"))
.join(";");

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)
);
Expand All @@ -38,6 +40,7 @@ if (globalObjects.length > 0) {
module.exports = {
formatWithCursor(input, options) {
return vm.runInNewContext(
// [prettierx]
`
const options = {
...$$$options,
Expand All @@ -46,7 +49,7 @@ module.exports = {
...($$$options.plugins || []),
],
};
prettier.formatWithCursor($$$input, options);
prettierx.formatWithCursor($$$input, options);
`,
{ $$$input: input, $$$options: options, ...sandbox }
);
Expand All @@ -55,6 +58,7 @@ module.exports = {
__debug: {
parse(input, options, massage) {
return vm.runInNewContext(
// [prettierx]
`
const options = {
...$$$options,
Expand All @@ -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 }
);
Expand Down
13 changes: 7 additions & 6 deletions tests/integration/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

const path = require("path");
const isProduction = process.env.NODE_ENV === "production";
const { PRETTIER_DIR } = process.env;
// [prettierx] get fork package name from package.json
const { bin, name } = require(path.join(PRETTIER_DIR, "package.json"));
// [prettierx]
const { PRETTIERX_DIR } = process.env;
const { bin } = 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, "../..");

Expand Down

0 comments on commit ec3378a

Please sign in to comment.