From 305fea8a59a6d1693ac3195810e2d73b99aa7c36 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 23 Apr 2020 10:37:09 +0800 Subject: [PATCH] Codebase install test (#6373) --- .github/workflows/dev-package-test.yml | 44 ++++++++++++++++++++++++++ cspell.json | 2 ++ jest.config.js | 2 +- package.json | 8 +++++ scripts/install-prettier.js | 30 ++++++++++++++---- tests_config/require_prettier.js | 3 +- 6 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/dev-package-test.yml diff --git a/.github/workflows/dev-package-test.yml b/.github/workflows/dev-package-test.yml new file mode 100644 index 000000000..374da648e --- /dev/null +++ b/.github/workflows/dev-package-test.yml @@ -0,0 +1,44 @@ +name: Dev_Package_Test + +on: + schedule: + - cron: "0 0 * * 1" + +jobs: + test: + strategy: + fail-fast: false + matrix: + os: + - "ubuntu-latest" + node: + - "10" + NPM_CLIENT: + - "yarn" + - "npm" + - "pnpm" + env: + INSTALL_PACKAGE: true + NPM_CLIENT: ${{ matrix.NPM_CLIENT }} + name: Test with ${{ matrix.NPM_CLIENT }} + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + + - name: Install Dependencies + run: yarn install --frozen-lockfile + + - name: Install Client Package + if: matrix.NPM_CLIENT == 'pnpm' + run: npm install --global ${{ matrix.NPM_CLIENT }} + + - name: Run Tests + run: yarn test:dev-package --maxWorkers=2 diff --git a/cspell.json b/cspell.json index a66454b25..bc2291979 100644 --- a/cspell.json +++ b/cspell.json @@ -234,6 +234,7 @@ "noreferrer", "normalise", "normalised", + "npmrc", "nullability", "nullish", "Nuno", @@ -255,6 +256,7 @@ "pcss", "Pierzchała", "Pieter", + "pnpm", "postprocess", "postprocessor", "precache", diff --git a/jest.config.js b/jest.config.js index 91ae0e3ee..fdcd4bf86 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,7 +3,7 @@ const installPrettier = require("./scripts/install-prettier"); const ENABLE_CODE_COVERAGE = !!process.env.ENABLE_CODE_COVERAGE; -if (process.env.NODE_ENV === "production") { +if (process.env.NODE_ENV === "production" || process.env.INSTALL_PACKAGE) { process.env.PRETTIER_DIR = installPrettier(); } diff --git a/package.json b/package.json index fb47b7f82..092e7d7e2 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,13 @@ "engines": { "node": ">=10.13.0" }, + "files": [ + "index.js", + "standalone.js", + "package.json", + "src", + "bin" + ], "dependencies": { "@angular/compiler": "9.0.5", "@babel/code-frame": "7.8.3", @@ -116,6 +123,7 @@ "prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1", "prepare-release": "yarn && yarn build && yarn test:dist", "test": "jest", + "test:dev-package": "cross-env INSTALL_PACKAGE=1 jest", "test:dist": "cross-env NODE_ENV=production jest", "test:dist-standalone": "cross-env NODE_ENV=production TEST_STANDALONE=1 jest tests/", "test:integration": "jest tests_integration", diff --git a/scripts/install-prettier.js b/scripts/install-prettier.js index 449c5f451..ddd565f1f 100644 --- a/scripts/install-prettier.js +++ b/scripts/install-prettier.js @@ -7,17 +7,33 @@ const tempy = require("tempy"); shell.config.fatal = true; const rootDir = path.join(__dirname, ".."); -const distDir = path.join(rootDir, "dist"); +const client = process.env.NPM_CLIENT || "yarn"; +const packageDir = + process.env.NODE_ENV === "production" ? path.join(rootDir, "dist") : rootDir; module.exports = () => { - const file = shell.exec("npm pack", { cwd: distDir }).stdout.trim(); - const tarPath = path.join(distDir, file); const tmpDir = tempy.directory(); + const file = shell.exec("npm pack", { cwd: packageDir }).stdout.trim(); + shell.mv(path.join(packageDir, file), tmpDir); + const tarPath = path.join(tmpDir, file); - shell.config.silent = true; - shell.exec("npm init -y", { cwd: tmpDir }); - shell.exec(`npm install "${tarPath}"`, { cwd: tmpDir }); - shell.config.silent = false; + shell.exec(`${client} init -y`, { cwd: tmpDir, silent: true }); + let installCommand = ""; + switch (client) { + case "npm": + // npm fails when engine requirement only with `--engine-strict` + installCommand = `npm install "${tarPath}" --engine-strict`; + break; + case "pnpm": + // Note: current pnpm can't work with `--engine-strict` and engineStrict setting in `.npmrc` + installCommand = `pnpm add "${tarPath}"`; + break; + default: + // yarn fails when engine requirement not compatible by default + installCommand = `yarn add "${tarPath}"`; + } + + shell.exec(installCommand, { cwd: tmpDir }); return path.join(tmpDir, "node_modules/prettier"); }; diff --git a/tests_config/require_prettier.js b/tests_config/require_prettier.js index 3d0429992..7a1cfaf9b 100644 --- a/tests_config/require_prettier.js +++ b/tests_config/require_prettier.js @@ -1,7 +1,6 @@ "use strict"; -const isProduction = process.env.NODE_ENV === "production"; -const prettierRootDir = isProduction ? process.env.PRETTIER_DIR : "../"; +const prettierRootDir = process.env.PRETTIER_DIR || "../"; const prettier = require(prettierRootDir);