Skip to content

Commit

Permalink
prettierx ci: restore dev-package-test with pnpm
Browse files Browse the repository at this point in the history
(in prettierx-rebase-branch-001 version branch)

support pnpm test with some script improvements

(dev package test with pnpm)

refactor scripts/install-prettier.js with optional dep support

based on changes proposed in:

- #603

Co-authored-by: Adaline Valentina Simonian <[email protected]>
Co-authored-by: Christopher J. Brody <[email protected]>
  • Loading branch information
Christopher J. Brody and adalinesimonian committed Jun 28, 2021
1 parent f6ed67f commit abaec89
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/dev-package-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ jobs:
NPM_CLIENT:
- "yarn"
- "npm"
# [prettierx] skip on pnpm for now (...)
SKIP_NPM_CLIENT_TEST:
- "pnpm"
env:
INSTALL_PACKAGE: true
Expand Down
38 changes: 19 additions & 19 deletions scripts/install-prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const path = require("path");
const shell = require("shelljs");
const tempy = require("tempy");

// [prettierx] package name & peer dependencies:
const { name, devDependencies } = require("../package.json");

// [prettierx] peer dependency versions:
const flowParserVersion = devDependencies["flow-parser"];
const typescriptVersion = devDependencies.typescript;
// [prettierx]: optional dep support & fork package name from package.json
const {
devDependencies,
peerDependenciesMeta,
name,
} = require("../package.json");

shell.config.fatal = true;

Expand All @@ -22,32 +22,32 @@ module.exports = (packageDir) => {
const tarPath = path.join(tmpDir, file);

shell.exec(`${client} init -y`, { cwd: tmpDir, silent: true });

// [prettierx]: typescript/flow-parser optional dep support
const args = [
`"${tarPath}"`,
...Object.entries(peerDependenciesMeta)
.filter(([, meta]) => meta.optional)
.map(([dep]) => `${dep}@${devDependencies[dep]}`),
].join(" ");

let installCommand = "";
switch (client) {
case "npm":
// [prettierx] peer dependencies via npm:
shell.exec(`npm i flow-parser@${flowParserVersion}`, { cwd: tmpDir });
shell.exec(`npm i typescript@${typescriptVersion}`, { cwd: tmpDir });
// npm fails when engine requirement only with `--engine-strict`
installCommand = `npm install "${tarPath}" --engine-strict`;
installCommand = `npm install ${args} --engine-strict`;
break;
case "pnpm":
// [prettierx] skip peer dependencies via pnpm for now (...)
// shell.exec(`pnpm add flow-parser@${flowParserVersion}`, { cwd: tmpDir });
// shell.exec(`pnpm add typescript@${typescriptVersion}`, { cwd: tmpDir });
// Note: current pnpm can't work with `--engine-strict` and engineStrict setting in `.npmrc`
installCommand = `pnpm add "${tarPath}"`;
installCommand = `pnpm add ${args}`;
break;
default:
// [prettierx] peer dependencies via Yarn:
shell.exec(`yarn add flow-parser@${flowParserVersion}`, { cwd: tmpDir });
shell.exec(`yarn add typescript@${typescriptVersion}`, { cwd: tmpDir });
// yarn fails when engine requirement not compatible by default
installCommand = `yarn add "${tarPath}"`;
installCommand = `yarn add ${args}`;
}

shell.exec(installCommand, { cwd: tmpDir });

// [prettierx] use package name:
// [prettierx] use fork package name:
return path.join(tmpDir, "node_modules", name);
};

0 comments on commit abaec89

Please sign in to comment.