diff --git a/.github/workflows/dev-package-test.yml b/.github/workflows/dev-package-test.yml index b60bd2c7f9..27b3ae34e3 100644 --- a/.github/workflows/dev-package-test.yml +++ b/.github/workflows/dev-package-test.yml @@ -22,8 +22,6 @@ jobs: NPM_CLIENT: - "yarn" - "npm" - # [prettierx] skip on pnpm for now (...) - SKIP_NPM_CLIENT_TEST: - "pnpm" env: INSTALL_PACKAGE: true diff --git a/scripts/install-prettier.js b/scripts/install-prettier.js index 5932be8343..f6db9a3cae 100644 --- a/scripts/install-prettier.js +++ b/scripts/install-prettier.js @@ -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; @@ -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); };