diff --git a/.eslintrc.js b/.eslintrc.js index 11ee4479..0c65d1f5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,6 +11,7 @@ const localConfigs = readdir(__dirname) module.exports = { root: true, ignorePatterns: [ + 'tap-testdir*/', 'workspace/test-workspace/**', ], extends: [ diff --git a/.eslintrc.local.json b/.eslintrc.local.json deleted file mode 100644 index a3e78e7e..00000000 --- a/.eslintrc.local.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "ignorePatterns": [ - "lib/content/*", - "!lib/content/index.js" - ] -} diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 36f007e8..908ae169 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -30,48 +30,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: ${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index 6169a73c..47af73ef 100644 --- a/.github/workflows/ci-release.yml +++ b/.github/workflows/ci-release.yml @@ -85,48 +85,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: ${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -161,12 +146,9 @@ jobs: os: windows-latest shell: cmd node-version: - - 14.17.0 - - 14.x - - 16.13.0 - - 16.x - - 18.0.0 + - 18.17.0 - 18.x + - 20.5.0 - 20.x runs-on: ${{ matrix.platform.os }} defaults: @@ -235,7 +217,9 @@ jobs: - name: Update Windows npm if: | matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') ) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz @@ -245,34 +229,33 @@ jobs: cd .. rmdir /s /q package - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: ${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v diff --git a/.github/workflows/ci-test-workspace.yml b/.github/workflows/ci-test-workspace.yml index 2f7d6684..10789010 100644 --- a/.github/workflows/ci-test-workspace.yml +++ b/.github/workflows/ci-test-workspace.yml @@ -38,48 +38,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: ${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -107,12 +92,9 @@ jobs: os: windows-latest shell: cmd node-version: - - 14.17.0 - - 14.x - - 16.13.0 - - 16.x - - 18.0.0 + - 18.17.0 - 18.x + - 20.5.0 - 20.x runs-on: ${{ matrix.platform.os }} defaults: @@ -136,7 +118,9 @@ jobs: - name: Update Windows npm if: | matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') ) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz @@ -146,34 +130,33 @@ jobs: cd .. rmdir /s /q package - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: ${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec4a5c1f..61f6c92a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,48 +38,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: ${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -107,12 +92,9 @@ jobs: os: windows-latest shell: cmd node-version: - - 14.17.0 - - 14.x - - 16.13.0 - - 16.x - - 18.0.0 + - 18.17.0 - 18.x + - 20.5.0 - 20.x runs-on: ${{ matrix.platform.os }} defaults: @@ -136,7 +118,9 @@ jobs: - name: Update Windows npm if: | matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') ) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz @@ -146,34 +130,33 @@ jobs: cd .. rmdir /s /q package - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: ${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v diff --git a/.github/workflows/post-dependabot.yml b/.github/workflows/post-dependabot.yml index c144660e..9a4b7611 100644 --- a/.github/workflows/post-dependabot.yml +++ b/.github/workflows/post-dependabot.yml @@ -31,48 +31,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: ${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 63a6169f..3418d4c4 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -34,48 +34,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: ${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 160a2e2e..ca20ccba 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,48 +47,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: ${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -204,48 +189,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: ${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v diff --git a/.gitignore b/.gitignore index 135c3883..e0bd2dd9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ # ignore everything in the root /* +# transient test directories +tap-testdir*/ # keep these !**/.gitignore @@ -27,6 +29,7 @@ !/SECURITY.md !/tap-snapshots/ !/test/ +!/tsconfig.json !/workspace/ /workspace/* !/workspace/test-workspace/ diff --git a/.release-please-manifest.json b/.release-please-manifest.json index bdabf696..fd68703c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.19.0" + ".": "4.20.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e431451..98c1367e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,36 @@ # Changelog +## [4.20.0](https://github.com/npm/template-oss/compare/v4.19.0...v4.20.0) (2023-11-15) + +### Features + +* [`17ea62d`](https://github.com/npm/template-oss/commit/17ea62ddae905344c50458e10a204cf13cb56aaf) [#371](https://github.com/npm/template-oss/pull/371) add typescript and esm support (@lukekarrys) +* [`ea0e866`](https://github.com/npm/template-oss/commit/ea0e8661e0a9759fed1a4044cb1f5905dad1942c) [#373](https://github.com/npm/template-oss/pull/373) update engines (#373) (@lukekarrys) + +### Bug Fixes + +* [`74331b4`](https://github.com/npm/template-oss/commit/74331b4a815fb83c69ee57c05d299c1a647b46c0) [#371](https://github.com/npm/template-oss/pull/371) remove tap 16 specific config when using tap 18 (@lukekarrys) +* [`3fca74f`](https://github.com/npm/template-oss/commit/3fca74f484b683ec204350d491a4eb201e882b85) [#371](https://github.com/npm/template-oss/pull/371) always lint all js-ish extensions (@lukekarrys) +* [`37e9e0e`](https://github.com/npm/template-oss/commit/37e9e0ed8eb5a0ff49531d5b9cb2105f81004358) [#371](https://github.com/npm/template-oss/pull/371) use npx semver to better determine latest npm (@lukekarrys) +* [`3e1792c`](https://github.com/npm/template-oss/commit/3e1792c441752d52bb3b446698dc6a0850b3b4de) [#362](https://github.com/npm/template-oss/pull/362) add suffix to template files (#362) (@rotu) +* [`ebb48ec`](https://github.com/npm/template-oss/commit/ebb48ecbf3dfffb6e21634528723267018f324af) [#368](https://github.com/npm/template-oss/pull/368) add PR approval to auto publish flow (#368) (@wraithgar) +* [`f065bcb`](https://github.com/npm/template-oss/commit/f065bcb147e8a8104848e594363540e1b056b548) [#366](https://github.com/npm/template-oss/pull/366) prefer upstream over origin when getting remote (@lukekarrys) +* [`29bf19d`](https://github.com/npm/template-oss/commit/29bf19d5b809b573185753321f5e498155c55f5b) [#364](https://github.com/npm/template-oss/pull/364) Ignore transient tap test directories (#364) (@wraithgar) + +### Documentation + +* [`2a8d79e`](https://github.com/npm/template-oss/commit/2a8d79ef33c939af4ee909dd7c851ce96db16d93) [#372](https://github.com/npm/template-oss/pull/372) add note about semver and breaking changes (#372) (@lukekarrys) + +### Dependencies + +* [`ec65582`](https://github.com/npm/template-oss/commit/ec65582767348658bb8a6f9040099ff704c03d1d) [#375](https://github.com/npm/template-oss/pull/375) bump @commitlint/config-conventional from 17.8.1 to 18.1.0 +* [`c8420a6`](https://github.com/npm/template-oss/commit/c8420a6755609eba54886e6af5a123c57f2002eb) [#374](https://github.com/npm/template-oss/pull/374) bump @commitlint/cli from 17.8.1 to 18.2.0 +* [`f2521ed`](https://github.com/npm/template-oss/commit/f2521edc63fd6bd313fdc3fdac8e3a3c0bd70af9) [#370](https://github.com/npm/template-oss/pull/370) bump @npmcli/arborist from 6.5.0 to 7.2.1 +* [`8c20554`](https://github.com/npm/template-oss/commit/8c2055457c112e616a0529bfb5baa296d3bdecc9) [#346](https://github.com/npm/template-oss/pull/346) bump @npmcli/git from 4.1.0 to 5.0.3 +* [`f25926a`](https://github.com/npm/template-oss/commit/f25926ab282975ea371700c6e8d17d454ab93777) [#343](https://github.com/npm/template-oss/pull/343) bump @npmcli/package-json from 4.0.1 to 5.0.0 +* [`af30dbe`](https://github.com/npm/template-oss/commit/af30dbe3bbf4f410f31473f3df89b5893c01be62) [#357](https://github.com/npm/template-oss/pull/357) bump hosted-git-info from 6.1.1 to 7.0.1 +* [`0b59cd6`](https://github.com/npm/template-oss/commit/0b59cd6bc32a48f69a7a46b6a7e9c28a106fcffe) [#349](https://github.com/npm/template-oss/pull/349) bump npm-package-arg from 10.1.0 to 11.0.1 + ## [4.19.0](https://github.com/npm/template-oss/compare/v4.18.1...v4.19.0) (2023-09-15) ### Features diff --git a/README.md b/README.md index 1a423510..b4405581 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,11 @@ This module bundles the npm CLI team's basics for package development into a single devDependency. -**CAUTION: THESE CHANGES WILL OVERWRITE ANY LOCAL FILES AND SETTINGS** +> [!WARNING] +> THESE CHANGES WILL OVERWRITE LOCAL FILES AND SETTINGS + +> [!IMPORTANT] +> This package does not follow semantic versioning for its API. This package is designed to be installed with `--save-exact` and therefore will make breaking API changes outside of major versions, including `engines` narrowing. Major versions are reserved for breaking changes to files written to a repo by this package. ### Configuration @@ -60,21 +64,21 @@ any of the same settings in the root. ### Content All the templated content for this repo lives in -[`lib/content/`](./lib/content/). The `index.js`[./lib/content/index.js] file +[`lib/content/`](./lib/content/). The [`index.js`](./lib/content/index.js) file controls how and where this content is written. Content files can be overwritten or merged with the existing target file. -Currently mergining is only supported for `package.json` files. +Merging is only supported for some types of files (ini, yaml, json, package.json) Each content file goes through the following pipeline: 1. It is read from its source location -1. It is are templated using Handlebars with the variables from each packages's - config (with some derived values generated in [`config.js`](./lib/config.js) -1. It is parsed based on its file extension in +2. It is compiled using [Handlebars](https://handlebarsjs.com/) with the variables from each packages's + config (with some derived values generated in [`config.js`](./lib/config.js)) +3. It is parsed based on its file extension in [`parser.js`](./lib/util/parser.js) -1. Additional logic is applied by the parser -1. It is written to its target location +4. Additional logic is applied by the parser +5. It is written to its target location ### Usage @@ -82,7 +86,7 @@ This package provides two bin scripts: #### `template-oss-check` -This will check if any of the applied files different from the target content, +This will check if any of the applied files differ from the target content, or if any of the other associated checks fail. The diffs of each file or check will be reported with instructions on how to fix it. @@ -92,7 +96,7 @@ This will write all source files to their target locations in the cwd. It will do nothing if `package.json#templateOSS.version` is the same as the version being run. This can be overridden by `--force`. -This is the script that is run on `postinsall`. +This is the script that is run on `postinstall`. ### Extending @@ -100,7 +104,7 @@ This is the script that is run on `postinsall`. This directory is where all the logic for applying files lives. It should be possible to add new files without modifying anything in this directory. To add a -file, add the templated file to `lib/content/$FILENAME` and add entry for it in +file, add the templated file to `lib/content/$FILENAME` and an entry for it in `lib/content/index.js` depending on where and when it should be written (root vs workspace, repo vs module, add vs remove, etc). diff --git a/bin/release-manager.js b/bin/release-manager.js index b56695af..0a7fcca3 100755 --- a/bin/release-manager.js +++ b/bin/release-manager.js @@ -50,6 +50,12 @@ const MANUAL_PUBLISH_STEPS = ` ` const AUTO_PUBLISH_STEPS = ` +1. Approve this PR + + \`\`\`sh + gh pr review -R {NWO} --approve + \`\`\` + 1. Merge release PR :rotating_light: Merging this will auto publish :rotating_light: \`\`\`sh diff --git a/lib/config.js b/lib/config.js index e7e41c8b..789cb5c2 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,18 +1,22 @@ -const { relative, dirname, join, extname, posix, win32 } = require('path') -const { defaults, pick, omit, uniq, isPlainObject } = require('lodash') +const { relative, dirname, join, extname } = require('path') +const { defaults, defaultsDeep, pick, omit, uniq, isPlainObject } = require('lodash') +const semver = require('semver') const ciVersions = require('./util/ci-versions.js') const parseDependabot = require('./util/dependabot.js') const git = require('./util/git.js') const gitignore = require('./util/gitignore.js') const { mergeWithCustomizers, customizers } = require('./util/merge.js') const { FILE_KEYS, parseConfig: parseFiles, getAddedFiles, mergeFiles } = require('./util/files.js') +const template = require('./util/template.js') +const getCmdPath = require('./util/get-cmd-path.js') +const importOrRequire = require('./util/import-or-require.js') +const { makePosix, deglob, posixDir, posixGlob } = require('./util/path.js') +const { name: NAME, version: LATEST_VERSION } = require('../package.json') const CONFIG_KEY = 'templateOSS' -const getPkgConfig = (pkg) => pkg[CONFIG_KEY] || {} - -const { name: NAME, version: LATEST_VERSION } = require('../package.json') const MERGE_KEYS = [...FILE_KEYS, 'defaultContent', 'content'] const DEFAULT_CONTENT = require.resolve(NAME) +const getPkgConfig = (pkg) => pkg[CONFIG_KEY] || {} const merge = mergeWithCustomizers( customizers.mergeArrays('branches', 'distPaths', 'allowPaths', 'ignorePaths'), @@ -23,43 +27,6 @@ const merge = mergeWithCustomizers( } ) -const makePosix = (v) => v.split(win32.sep).join(posix.sep) -const deglob = (v) => makePosix(v).replace(/[/*]+$/, '') -const posixDir = (v) => `${v === '.' ? '' : deglob(v).replace(/\/$/, '')}${posix.sep}` -const posixGlob = (str) => `${posixDir(str)}**` - -const getCmdPath = (key, { pkgConfig, rootConfig, isRoot, pkg, rootPkg }) => { - const result = (local, isRelative) => { - let root = local - const isLocal = local.startsWith('.') || local.startsWith('/') - - if (isLocal) { - if (isRelative) { - // Make a path relative from a workspace to the root if we are in a workspace - local = makePosix(join(relative(pkg.path, rootPkg.path), local)) - } - local = `node ${local}` - root = `node ${root}` - } - - return { - isLocal, - local, - root, - } - } - - if (pkgConfig[key]) { - return result(pkgConfig[key]) - } - - if (rootConfig[key]) { - return result(rootConfig[key], !isRoot) - } - - return result(key) -} - const mergeConfigs = (...configs) => { const mergedConfig = merge(...configs.map(c => pick(c, MERGE_KEYS))) return defaults(mergedConfig, { @@ -72,37 +39,33 @@ const mergeConfigs = (...configs) => { }) } -const readContentPath = (path) => { +const readContentPath = async (path) => { if (!path) { return {} } - let content = {} const index = extname(path) === '.js' ? path : join(path, 'index.js') const dir = dirname(index) - - try { - content = require(index) - } catch { - // its ok if this fails since the content dir - // might only be to provide other files. the - // index.js is optional - } + const content = await importOrRequire(index) return { content, dir } } -const getConfig = (path, rawConfig) => { - const config = omit(readContentPath(path).content, FILE_KEYS) +const getConfig = async (path, rawConfig) => { + const { content } = await readContentPath(path) + const config = omit(content, FILE_KEYS) return merge(config, rawConfig ? omit(rawConfig, FILE_KEYS) : {}) } -const getFiles = (path, rawConfig) => { - const { content, dir } = readContentPath(path) +const getFiles = async (path, rawConfig, templateSettings) => { + const { content, dir } = await readContentPath(path) if (!dir) { return [] } - return [parseFiles(pick(content, FILE_KEYS), dir, pick(rawConfig, FILE_KEYS)), dir] + return [ + parseFiles(pick(content, FILE_KEYS), dir, pick(rawConfig, FILE_KEYS), templateSettings), + dir, + ] } const getFullConfig = async ({ @@ -127,39 +90,15 @@ const getFullConfig = async ({ // These config items are merged betweent the root and child workspaces and only come from // the package.json because they can be used to read configs from other the content directories const mergedConfig = mergeConfigs(rootPkg.config, pkg.config) - - const defaultConfig = getConfig(DEFAULT_CONTENT) - const [defaultFiles, defaultDir] = getFiles(DEFAULT_CONTENT, mergedConfig) + const defaultConfig = await getConfig(DEFAULT_CONTENT) const useDefault = mergedConfig.defaultContent && defaultConfig - const rootConfig = getConfig(rootPkg.config.content, rootPkg.config) - const [rootFiles, rootDir] = getFiles(rootPkg.config.content, mergedConfig) + const rootConfig = await getConfig(rootPkg.config.content, rootPkg.config) // The content config only gets set from the package we are in, it doesn't inherit // anything from the root const rootPkgConfig = merge(useDefault, rootConfig) - const pkgConfig = merge(useDefault, getConfig(pkg.config.content, pkg.config)) - const [pkgFiles, pkgDir] = getFiles(mergedConfig.content, mergedConfig) - - // Files get merged in from the default content (that template-oss provides) as well - // as any content paths provided from the root or the workspace - const fileDirs = uniq([useDefault && defaultDir, rootDir, pkgDir].filter(Boolean)) - const files = mergeFiles(useDefault && defaultFiles, rootFiles, pkgFiles) - const repoFiles = isRoot ? files.rootRepo : files.workspaceRepo - const moduleFiles = isRoot ? files.rootModule : files.workspaceModule - - const allowRootDirs = [ - // Allways allow module files in root or workspaces - ...getAddedFiles(moduleFiles), - ...isRoot ? [ - // in the root allow all repo files - ...getAddedFiles(repoFiles), - // and allow all workspace repo level files in the root - ...pkgs - .filter(p => p.path !== rootPkg.path && p.config.workspaceRepo !== false) - .flatMap(() => getAddedFiles(files.workspaceRepo)), - ] : [], - ] + const pkgConfig = merge(useDefault, await getConfig(pkg.config.content, pkg.config)) const npmPath = getCmdPath('npm', { pkgConfig, rootConfig, isRoot, pkg, rootPkg }) const npxPath = getCmdPath('npx', { pkgConfig, rootConfig, isRoot, pkg, rootPkg }) @@ -185,6 +124,8 @@ const getFullConfig = async ({ ? pkgConfig.releaseBranch.replace(/\*/g, pkgConfig.backport) : defaultBranch + const esm = pkg.pkgJson?.type === 'module' || !!pkgConfig.typescript || !!pkgConfig.esm + // all derived keys const derived = { isRoot, @@ -209,18 +150,11 @@ const getFullConfig = async ({ releaseBranch, publishTag, dependabot: parseDependabot(pkgConfig, defaultConfig, gitBranches.branches), - // repo + // paths repoDir: rootPkg.path, - repoFiles, - applyRepo: !!repoFiles, - // module moduleDir: pkg.path, - moduleFiles, - applyModule: !!moduleFiles, - // package pkgName: pkg.pkgJson.name, pkgNameFs: pkg.pkgJson.name.replace(/\//g, '-').replace(/@/g, ''), - // paths pkgPath, pkgDir: posixDir(pkgPath), pkgGlob: posixGlob(pkgPath), @@ -228,6 +162,12 @@ const getFullConfig = async ({ allFlags: isMono ? '-ws -iwr --if-present' : '', workspacePaths, workspaceGlobs: workspacePaths.map(posixGlob), + // type + esm, + cjsExt: esm ? 'cjs' : 'js', + deleteJsExt: esm ? 'js' : 'cjs', + // tap + tap18: semver.coerce(pkg.pkgJson?.devDependencies?.tap)?.major === 18, // booleans to control application of updates isForce, isDogFood, @@ -243,20 +183,6 @@ const getFullConfig = async ({ lockfile: rootPkgConfig.lockfile, // ci versions / engines ciVersions: ciVersions.get(pkg.pkgJson.engines?.node, pkgConfig), - // gitignore - ignorePaths: [ - ...gitignore.sort([ - ...gitignore.allowRootDir(allowRootDirs), - ...isRoot && pkgConfig.lockfile ? ['!/package-lock.json'] : [], - ...(pkgConfig.allowPaths || []).map((p) => `!${p}`), - ...(pkgConfig.ignorePaths || []), - ]), - // these cant be sorted since they rely on order - // to allow a previously ignored directoy - ...isRoot - ? gitignore.allowDir(wsPkgs.map((p) => makePosix(relative(rootPkg.path, p.path)))) - : [], - ], // needs update if we are dogfooding this repo, with force argv, or its // behind the current version needsUpdate: isForce || isDogFood || !isLatest, @@ -264,15 +190,22 @@ const getFullConfig = async ({ __NAME__: NAME, __CONFIG_KEY__: CONFIG_KEY, __VERSION__: LATEST_VERSION, - __PARTIAL_DIRS__: fileDirs, } - if (!pkgConfig.eslint) { - derived.ignorePaths = derived.ignorePaths.filter(p => !p.includes('eslint')) - if (Array.isArray(pkgConfig.requiredPackages?.devDependencies)) { - pkgConfig.requiredPackages.devDependencies = - pkgConfig.requiredPackages.devDependencies.filter(p => !p.includes('eslint')) - } + if (!pkgConfig.eslint && Array.isArray(pkgConfig.requiredPackages?.devDependencies)) { + pkgConfig.requiredPackages.devDependencies = + pkgConfig.requiredPackages.devDependencies.filter(p => !p.includes('eslint')) + } + + if (pkgConfig.typescript) { + defaultsDeep(pkgConfig, { allowPaths: [], requiredPackages: { devDependencies: [] } }) + pkgConfig.distPaths = null + pkgConfig.allowPaths.push('/src/') + pkgConfig.requiredPackages.devDependencies.push( + 'typescript', + 'tshy', + '@typescript-eslint/parser' + ) } const gitUrl = await git.getUrl(rootPkg.path) @@ -284,10 +217,55 @@ const getFullConfig = async ({ } } - return { - ...pkgConfig, - ...derived, - } + const fullConfig = { ...pkgConfig, ...derived } + + // files, come at the end since file names can be based on config + const [defaultFiles, defaultDir] = await getFiles(DEFAULT_CONTENT, mergedConfig, fullConfig) + const [rootFiles, rootDir] = await getFiles(rootPkg.config.content, mergedConfig, fullConfig) + const [pkgFiles, pkgDir] = await getFiles(mergedConfig.content, mergedConfig, fullConfig) + + // Files get merged in from the default content (that template-oss provides) as well + // as any content paths provided from the root or the workspace + const fileDirs = uniq([useDefault && defaultDir, rootDir, pkgDir].filter(Boolean)) + const files = mergeFiles(useDefault && defaultFiles, rootFiles, pkgFiles) + const repoFiles = isRoot ? files.rootRepo : files.workspaceRepo + const moduleFiles = isRoot ? files.rootModule : files.workspaceModule + + Object.assign(fullConfig, { + repoFiles, + moduleFiles, + applyRepo: !!repoFiles, + applyModule: !!moduleFiles, + __PARTIAL_DIRS__: fileDirs, + // gitignore, these use the full config so need to come at the very end + ignorePaths: [ + ...gitignore.sort([ + ...gitignore.allowRootDir([ + // Allways allow module files in root or workspaces + ...getAddedFiles(moduleFiles).map(s => template(s, fullConfig)), + ...isRoot ? [ + // in the root allow all repo files + ...getAddedFiles(repoFiles).map(s => template(s, fullConfig)), + // and allow all workspace repo level files in the root + ...pkgs + .filter(p => p.path !== rootPkg.path && p.config.workspaceRepo !== false) + .flatMap(() => getAddedFiles(files.workspaceRepo)), + ] : [], + ]), + ...isRoot && pkgConfig.lockfile ? ['!/package-lock.json'] : [], + ...(pkgConfig.allowPaths || []).map((p) => `!${p}`), + ...(pkgConfig.distPaths || []).map((p) => `!/${p}`), + ...(pkgConfig.ignorePaths || []), + ]), + // these cant be sorted since they rely on order + // to allow a previously ignored directoy + ...isRoot + ? gitignore.allowDir(wsPkgs.map((p) => makePosix(relative(rootPkg.path, p.path)))) + : [], + ].filter(p => !pkgConfig.eslint ? !p.includes('eslint') : true), + }) + + return fullConfig } module.exports = getFullConfig diff --git a/lib/content/CODEOWNERS b/lib/content/CODEOWNERS.hbs similarity index 100% rename from lib/content/CODEOWNERS rename to lib/content/CODEOWNERS.hbs diff --git a/lib/content/CODE_OF_CONDUCT.md b/lib/content/CODE_OF_CONDUCT-md.hbs similarity index 100% rename from lib/content/CODE_OF_CONDUCT.md rename to lib/content/CODE_OF_CONDUCT-md.hbs diff --git a/lib/content/CONTRIBUTING.md b/lib/content/CONTRIBUTING-md.hbs similarity index 100% rename from lib/content/CONTRIBUTING.md rename to lib/content/CONTRIBUTING-md.hbs diff --git a/lib/content/LICENSE.md b/lib/content/LICENSE-md.hbs similarity index 100% rename from lib/content/LICENSE.md rename to lib/content/LICENSE-md.hbs diff --git a/lib/content/SECURITY.md b/lib/content/SECURITY-md.hbs similarity index 100% rename from lib/content/SECURITY.md rename to lib/content/SECURITY-md.hbs diff --git a/lib/content/_job-matrix.yml b/lib/content/_job-matrix-yml.hbs similarity index 93% rename from lib/content/_job-matrix.yml rename to lib/content/_job-matrix-yml.hbs index 8d77a5c2..5ad768b0 100644 --- a/lib/content/_job-matrix.yml +++ b/lib/content/_job-matrix-yml.hbs @@ -26,4 +26,4 @@ defaults: run: shell: $\{{ matrix.platform.shell }} steps: - {{> stepsSetup jobIsMatrix=true }} + {{> stepsSetupYml jobIsMatrix=true }} diff --git a/lib/content/_job-release-integration.yml b/lib/content/_job-release-integration-yml.hbs similarity index 97% rename from lib/content/_job-release-integration.yml rename to lib/content/_job-release-integration-yml.hbs index 136ca0a1..2cd8787f 100644 --- a/lib/content/_job-release-integration.yml +++ b/lib/content/_job-release-integration-yml.hbs @@ -29,7 +29,7 @@ defaults: run: shell: bash steps: - {{> stepNode lockfile=false }} + {{> stepNodeYml lockfile=false }} - name: View in Registry run: | EXIT_CODE=0 diff --git a/lib/content/_job.yml b/lib/content/_job-yml.hbs similarity index 87% rename from lib/content/_job.yml rename to lib/content/_job-yml.hbs index 48c6100a..4dab1885 100644 --- a/lib/content/_job.yml +++ b/lib/content/_job-yml.hbs @@ -5,4 +5,4 @@ defaults: run: shell: bash steps: - {{> stepsSetup }} + {{> stepsSetupYml }} diff --git a/lib/content/_on-ci.yml b/lib/content/_on-ci-yml.hbs similarity index 100% rename from lib/content/_on-ci.yml rename to lib/content/_on-ci-yml.hbs diff --git a/lib/content/_step-audit.yml b/lib/content/_step-audit-yml.hbs similarity index 100% rename from lib/content/_step-audit.yml rename to lib/content/_step-audit-yml.hbs diff --git a/lib/content/_step-checks.yml b/lib/content/_step-checks-yml.hbs similarity index 100% rename from lib/content/_step-checks.yml rename to lib/content/_step-checks-yml.hbs diff --git a/lib/content/_step-deps.yml b/lib/content/_step-deps-yml.hbs similarity index 100% rename from lib/content/_step-deps.yml rename to lib/content/_step-deps-yml.hbs diff --git a/lib/content/_step-git.yml b/lib/content/_step-git-yml.hbs similarity index 100% rename from lib/content/_step-git.yml rename to lib/content/_step-git-yml.hbs diff --git a/lib/content/_step-lint.yml b/lib/content/_step-lint-yml.hbs similarity index 100% rename from lib/content/_step-lint.yml rename to lib/content/_step-lint-yml.hbs diff --git a/lib/content/_step-node-yml.hbs b/lib/content/_step-node-yml.hbs new file mode 100644 index 00000000..0458fd95 --- /dev/null +++ b/lib/content/_step-node-yml.hbs @@ -0,0 +1,60 @@ +- name: Setup Node + uses: actions/setup-node@v3 + id: node + with: + node-version: {{#if jobIsMatrix}}$\{{ matrix.node-version }}{{else}}{{ last ciVersions }}{{/if}} + check-latest: contains({{#if jobIsMatrix}}matrix.node-version{{else}}'{{ last ciVersions }}'{{/if}}, '.x') + {{#if lockfile}} + cache: npm + {{/if}} + +{{#if updateNpm}} +{{#if jobIsMatrix}} +# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows +- name: Update Windows npm + if: | + matrix.platform.os == 'windows-latest' && ( + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') + ) + run: | + curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz + tar xf npm-7.5.4.tgz + cd package + node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz + cd .. + rmdir /s /q package +{{/if}} + +- name: Install Latest npm + shell: bash + env: + NODE_VERSION: $\{{ steps.node.outputs.node-version }} + run: | + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") + + echo "node@$NODE_VERSION" + + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH + +- name: npm Version + run: npm -v +{{/if}} diff --git a/lib/content/_step-node.yml b/lib/content/_step-node.yml deleted file mode 100644 index 4b4bf455..00000000 --- a/lib/content/_step-node.yml +++ /dev/null @@ -1,57 +0,0 @@ -- name: Setup Node - uses: actions/setup-node@v3 - id: node - with: - node-version: {{#if jobIsMatrix}}$\{{ matrix.node-version }}{{else}}{{ last ciVersions }}{{/if}} - check-latest: contains({{#if jobIsMatrix}}matrix.node-version{{else}}'{{ last ciVersions }}'{{/if}}, '.x') - {{#if lockfile}} - cache: npm - {{/if}} - -{{#if updateNpm}} -# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows -- name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz - cd .. - rmdir /s /q package - -# Start on Node 10 because we dont test on anything lower -- name: Install npm@7 on Node 10 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" - -- name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" - -- name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" - -- name: Install npm@latest on Node - if: $\{{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest - -- name: npm Version - run: npm -v -{{/if}} diff --git a/lib/content/_step-test.yml b/lib/content/_step-test-yml.hbs similarity index 100% rename from lib/content/_step-test.yml rename to lib/content/_step-test-yml.hbs diff --git a/lib/content/_steps-setup-yml.hbs b/lib/content/_steps-setup-yml.hbs new file mode 100644 index 00000000..962f2885 --- /dev/null +++ b/lib/content/_steps-setup-yml.hbs @@ -0,0 +1,6 @@ +{{~#if jobCheck}}{{> stepChecksYml }}{{/if}} +{{~#unless jobSkipSetup}} +{{> stepGitYml }} +{{> stepNodeYml }} +{{> stepDepsYml }} +{{/unless}} diff --git a/lib/content/_steps-setup.yml b/lib/content/_steps-setup.yml deleted file mode 100644 index e17d5f3d..00000000 --- a/lib/content/_steps-setup.yml +++ /dev/null @@ -1,6 +0,0 @@ -{{~#if jobCheck}}{{> stepChecks }}{{/if}} -{{~#unless jobSkipSetup}} -{{> stepGit }} -{{> stepNode }} -{{> stepDeps }} -{{/unless}} diff --git a/lib/content/audit.yml b/lib/content/audit-yml.hbs similarity index 61% rename from lib/content/audit.yml rename to lib/content/audit-yml.hbs index 77ef4b89..07794faa 100644 --- a/lib/content/audit.yml +++ b/lib/content/audit-yml.hbs @@ -8,5 +8,5 @@ on: jobs: audit: - {{> job jobName="Audit Dependencies" jobDepFlags="--package-lock" }} - {{> stepAudit }} + {{> jobYml jobName="Audit Dependencies" jobDepFlags="--package-lock" }} + {{> stepAuditYml }} diff --git a/lib/content/bug.yml b/lib/content/bug-yml.hbs similarity index 100% rename from lib/content/bug.yml rename to lib/content/bug-yml.hbs diff --git a/lib/content/ci-release.yml b/lib/content/ci-release-yml.hbs similarity index 73% rename from lib/content/ci-release.yml rename to lib/content/ci-release-yml.hbs index 73bb97b8..6253ffe9 100644 --- a/lib/content/ci-release.yml +++ b/lib/content/ci-release-yml.hbs @@ -19,19 +19,19 @@ on: jobs: lint-all: - {{> job + {{> jobYml jobName="Lint All" jobCheck=(obj sha="inputs.check-sha") jobCheckout=(obj ref="${{ inputs.ref }}") }} - {{> stepLint jobRunFlags=allFlags }} - {{> stepChecks jobCheck=true }} + {{> stepLintYml jobRunFlags=allFlags }} + {{> stepChecksYml jobCheck=true }} test-all: - {{> jobMatrix + {{> jobMatrixYml jobName="Test All" jobCheck=(obj sha="inputs.check-sha") jobCheckout=(obj ref="${{ inputs.ref }}") }} - {{> stepTest jobRunFlags=allFlags }} - {{> stepChecks jobCheck=true }} + {{> stepTestYml jobRunFlags=allFlags }} + {{> stepChecksYml jobCheck=true }} diff --git a/lib/content/ci-yml.hbs b/lib/content/ci-yml.hbs new file mode 100644 index 00000000..ebb6d917 --- /dev/null +++ b/lib/content/ci-yml.hbs @@ -0,0 +1,13 @@ +name: CI {{~#if isWorkspace}} - {{ pkgName }}{{/if}} + +on: + {{> onCiYml }} + +jobs: + lint: + {{> jobYml jobName="Lint" }} + {{> stepLintYml jobRunFlags=pkgFlags }} + + test: + {{> jobMatrixYml jobName="Test" }} + {{> stepTestYml jobRunFlags=pkgFlags }} diff --git a/lib/content/ci.yml b/lib/content/ci.yml deleted file mode 100644 index 0226d0c3..00000000 --- a/lib/content/ci.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: CI {{~#if isWorkspace}} - {{ pkgName }}{{/if}} - -on: - {{> onCi }} - -jobs: - lint: - {{> job jobName="Lint" }} - {{> stepLint jobRunFlags=pkgFlags }} - - test: - {{> jobMatrix jobName="Test" }} - {{> stepTest jobRunFlags=pkgFlags }} diff --git a/lib/content/codeql-analysis.yml b/lib/content/codeql-analysis-yml.hbs similarity index 96% rename from lib/content/codeql-analysis.yml rename to lib/content/codeql-analysis-yml.hbs index 4903a0be..78415d3f 100644 --- a/lib/content/codeql-analysis.yml +++ b/lib/content/codeql-analysis-yml.hbs @@ -24,7 +24,7 @@ jobs: contents: read security-events: write steps: - {{> stepGit }} + {{> stepGitYml }} - name: Initialize CodeQL uses: github/codeql-action/init@v2 with: diff --git a/lib/content/commitlintrc.js b/lib/content/commitlintrc-js.hbs similarity index 100% rename from lib/content/commitlintrc.js rename to lib/content/commitlintrc-js.hbs diff --git a/lib/content/config.yml b/lib/content/config-yml.hbs similarity index 100% rename from lib/content/config.yml rename to lib/content/config-yml.hbs diff --git a/lib/content/dependabot.yml b/lib/content/dependabot-yml.hbs similarity index 100% rename from lib/content/dependabot.yml rename to lib/content/dependabot-yml.hbs diff --git a/lib/content/eslintrc.js b/lib/content/eslintrc-js.hbs similarity index 64% rename from lib/content/eslintrc.js rename to lib/content/eslintrc-js.hbs index 8ee511c7..bb38c366 100644 --- a/lib/content/eslintrc.js +++ b/lib/content/eslintrc-js.hbs @@ -8,12 +8,22 @@ const localConfigs = readdir(__dirname) module.exports = { root: true, - {{#if workspaceGlobs}} ignorePatterns: [ + 'tap-testdir*/', {{#each workspaceGlobs}} '{{ . }}', {{/each}} + {{#if typescript}} + 'dist/', + {{/if}} ], + {{#if typescript}} + parser: '@typescript-eslint/parser', + settings: { + 'import/resolver': { + typescript: {}, + }, + }, {{/if}} extends: [ '@npmcli', diff --git a/lib/content/gitignore b/lib/content/gitignore.hbs similarity index 67% rename from lib/content/gitignore rename to lib/content/gitignore.hbs index d9d4b23e..21074e32 100644 --- a/lib/content/gitignore +++ b/lib/content/gitignore.hbs @@ -1,5 +1,7 @@ # ignore everything in the root /* +# transient test directories +tap-testdir*/ # keep these {{#each ignorePaths}} diff --git a/lib/content/index.js b/lib/content/index.js index 19c8117f..5dda526f 100644 --- a/lib/content/index.js +++ b/lib/content/index.js @@ -5,46 +5,47 @@ const isPublic = (p) => p.config.isPublic const sharedRootAdd = (name) => ({ // release '.github/workflows/release.yml': { - file: 'release.yml', + file: 'release-yml.hbs', filter: isPublic, }, '.github/workflows/ci-release.yml': { - file: 'ci-release.yml', + file: 'ci-release-yml.hbs', filter: isPublic, }, '.release-please-manifest.json': { - file: 'release-please-manifest.json', + file: 'release-please-manifest-json.hbs', filter: isPublic, - parser: (p) => class extends p.JsonMerge { - comment = null - }, + parser: (p) => p.JsonMergeNoComment, }, 'release-please-config.json': { - file: 'release-please-config.json', + file: 'release-please-config-json.hbs', filter: isPublic, - parser: (p) => class extends p.JsonMerge { - comment = null - }, + parser: (p) => p.JsonMergeNoComment, + }, + 'tsconfig.json': { + file: 'tsconfig-json.hbs', + filter: (p) => p.config.typescript, + parser: (p) => p.JsonMergeNoComment, }, // this lint commits which is only necessary for releases '.github/workflows/pull-request.yml': { - file: 'pull-request.yml', + file: 'pull-request-yml.hbs', filter: isPublic, }, // ci - '.github/matchers/tap.json': 'tap.json', - [`.github/workflows/ci${name ? `-${name}` : ''}.yml`]: 'ci.yml', + '.github/matchers/tap.json': 'tap-json.hbs', + [`.github/workflows/ci${name ? `-${name}` : ''}.yml`]: 'ci-yml.hbs', // dependabot '.github/dependabot.yml': { - file: 'dependabot.yml', + file: 'dependabot-yml.hbs', filter: (p) => p.config.dependabot, }, '.github/workflows/post-dependabot.yml': { - file: 'post-dependabot.yml', + file: 'post-dependabot-yml.hbs', filter: (p) => p.config.dependabot, }, '.github/settings.yml': { - file: 'settings.yml', + file: 'settings-yml.hbs', filter: (p) => !p.config.isReleaseBranch, }, }) @@ -61,15 +62,16 @@ const sharedRootRm = () => ({ // Changes applied to the root of the repo const rootRepo = { add: { - '.commitlintrc.js': 'commitlintrc.js', - '.github/ISSUE_TEMPLATE/bug.yml': 'bug.yml', - '.github/ISSUE_TEMPLATE/config.yml': 'config.yml', - '.github/CODEOWNERS': 'CODEOWNERS', - '.github/workflows/audit.yml': 'audit.yml', - '.github/workflows/codeql-analysis.yml': 'codeql-analysis.yml', + '.commitlintrc.{{ cjsExt }}': 'commitlintrc-js.hbs', + '.github/ISSUE_TEMPLATE/bug.yml': 'bug-yml.hbs', + '.github/ISSUE_TEMPLATE/config.yml': 'config-yml.hbs', + '.github/CODEOWNERS': 'CODEOWNERS.hbs', + '.github/workflows/audit.yml': 'audit-yml.hbs', + '.github/workflows/codeql-analysis.yml': 'codeql-analysis-yml.hbs', ...sharedRootAdd(), }, rm: { + '.commitlintrc.{{ deleteJsExt }}': true, '.github/workflows/release-test.yml': true, '.github/workflows/release-please.yml': true, ...sharedRootRm(), @@ -83,19 +85,19 @@ const rootRepo = { // dir. so we might want to combine these const rootModule = { add: { - '.eslintrc.js': { - file: 'eslintrc.js', + '.eslintrc.{{ cjsExt }}': { + file: 'eslintrc-js.hbs', filter: (p) => p.config.eslint, }, - '.gitignore': 'gitignore', - '.npmrc': 'npmrc', - 'SECURITY.md': 'SECURITY.md', - 'CODE_OF_CONDUCT.md': 'CODE_OF_CONDUCT.md', - 'CONTRIBUTING.md': 'CONTRIBUTING.md', - 'package.json': 'pkg.json', + '.gitignore': 'gitignore.hbs', + '.npmrc': 'npmrc.hbs', + 'SECURITY.md': 'SECURITY-md.hbs', + 'CODE_OF_CONDUCT.md': 'CODE_OF_CONDUCT-md.hbs', + 'CONTRIBUTING.md': 'CONTRIBUTING-md.hbs', + 'package.json': 'package-json.hbs', }, rm: [ - '.eslintrc.!(js|local.*)', + '.eslintrc.!({{ cjsExt }}|local.*)', ], } @@ -114,16 +116,16 @@ const workspaceRepo = { // Changes for each workspace but applied to the relative workspace dir const workspaceModule = { add: { - '.eslintrc.js': { - file: 'eslintrc.js', + '.eslintrc.{{ cjsExt }}': { + file: 'eslintrc-js.hbs', filter: (p) => p.config.eslint, }, - '.gitignore': 'gitignore', - 'package.json': 'pkg.json', + '.gitignore': 'gitignore.hbs', + 'package.json': 'package-json.hbs', }, rm: [ '.npmrc', - '.eslintrc.!(js|local.*)', + '.eslintrc.!({{ cjsExt }}|local.*)', 'SECURITY.md', ], } @@ -144,8 +146,6 @@ module.exports = { 'lib/', ], allowPaths: [ - '/bin/', - '/lib/', '/.eslintrc.local.*', '**/.gitignore', '/docs/', @@ -157,13 +157,17 @@ module.exports = { '/LICENSE*', '/CHANGELOG*', ], - ignorePaths: [], + ignorePaths: [ + /* to be provided by consuming package */ + ], ciVersions: {}, latestCiVersion: 20, lockfile: false, codeowner: '@npm/cli-team', eslint: true, publish: false, + typescript: false, + esm: false, updateNpm: true, dependabot: 'increase-if-necessary', unwantedPackages: [ diff --git a/lib/content/npmrc b/lib/content/npmrc.hbs similarity index 100% rename from lib/content/npmrc rename to lib/content/npmrc.hbs diff --git a/lib/content/pkg.json b/lib/content/package-json.hbs similarity index 75% rename from lib/content/pkg.json rename to lib/content/package-json.hbs index 59d33551..bba7ebdf 100644 --- a/lib/content/pkg.json +++ b/lib/content/package-json.hbs @@ -1,8 +1,9 @@ { "author": "GitHub Inc.", - "files": {{{ json distPaths }}}, + "files": {{#if typescript}}{{{ del }}}{{else}}{{{ json distPaths }}}{{/if}}, + "type": {{#if esm}}"module"{{else}}{{{ del }}}{{/if}}, "scripts": { - "lint": "{{#if eslint}}eslint \"**/*.js\"{{else}}echo linting disabled{{/if}}", + "lint": "{{#if eslint}}eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"{{else}}echo linting disabled{{/if}}", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "{{ localNpmPath }} run lint -- --fix", @@ -13,6 +14,9 @@ "test-all": "{{ localNpmPath }} run test {{ allFlags }}", "lint-all": "{{ localNpmPath }} run lint {{ allFlags }}", {{/if}} + {{#if typescript}} + "prepare": "tshy", + {{/if}} "template-copy": {{{ del }}}, "lint:fix": {{{ del }}}, "preversion": {{{ del }}}, @@ -30,13 +34,13 @@ {{#if workspacePaths}} "test-ignore": "^({{ join workspacePaths "|" }})/", {{/if}} - "nyc-arg": [ + "nyc-arg": {{#if tap18}}{{{ del }}}{{else}}[ {{#each workspaceGlobs}} "--exclude", "{{ . }}", {{/each}} "--exclude", "tap-snapshots/**" - ] + ]{{/if}} } } diff --git a/lib/content/post-dependabot.yml b/lib/content/post-dependabot-yml.hbs similarity index 99% rename from lib/content/post-dependabot.yml rename to lib/content/post-dependabot-yml.hbs index fe7526c4..46cfdc58 100644 --- a/lib/content/post-dependabot.yml +++ b/lib/content/post-dependabot-yml.hbs @@ -8,7 +8,7 @@ permissions: jobs: template-oss: - {{> job + {{> jobYml jobName="template-oss" jobIf="github.actor == 'dependabot[bot]'" jobCheckout=(obj ref="${{ github.event.pull_request.head.ref }}") diff --git a/lib/content/pull-request.yml b/lib/content/pull-request-yml.hbs similarity index 89% rename from lib/content/pull-request.yml rename to lib/content/pull-request-yml.hbs index 3c523b71..a4db6afe 100644 --- a/lib/content/pull-request.yml +++ b/lib/content/pull-request-yml.hbs @@ -10,7 +10,7 @@ on: jobs: commitlint: - {{> job jobName="Lint Commits" jobCheckout=(obj fetch-depth=0) }} + {{> jobYml jobName="Lint Commits" jobCheckout=(obj fetch-depth=0) }} - name: Run Commitlint on Commits id: commit continue-on-error: true diff --git a/lib/content/release-please-config.json b/lib/content/release-please-config-json.hbs similarity index 100% rename from lib/content/release-please-config.json rename to lib/content/release-please-config-json.hbs diff --git a/lib/content/release-please-manifest.json b/lib/content/release-please-manifest-json.hbs similarity index 100% rename from lib/content/release-please-manifest.json rename to lib/content/release-please-manifest-json.hbs diff --git a/lib/content/release.yml b/lib/content/release-yml.hbs similarity index 90% rename from lib/content/release.yml rename to lib/content/release-yml.hbs index 976e1e90..43e7acbc 100644 --- a/lib/content/release.yml +++ b/lib/content/release-yml.hbs @@ -27,7 +27,7 @@ jobs: pr-number: $\{{ steps.release.outputs.pr-number }} comment-id: $\{{ steps.pr-comment.outputs.result }} check-id: $\{{ steps.check.outputs.check_id }} - {{> job jobName="Release" }} + {{> jobYml jobName="Release" }} - name: Release Please id: release env: @@ -66,14 +66,14 @@ jobs: } return commentId - {{> stepChecks jobCheck=(obj name="Release" sha="steps.release.outputs.pr-sha") }} + {{> stepChecksYml jobCheck=(obj name="Release" sha="steps.release.outputs.pr-sha") }} update: needs: release outputs: sha: $\{{ steps.commit.outputs.sha }} check-id: $\{{ steps.check.outputs.check_id }} - {{> job + {{> jobYml jobName="Update - Release" jobIf="needs.release.outputs.pr" jobCheckout=(obj ref="${{ needs.release.outputs.branch }}" fetch-depth=0) @@ -94,8 +94,8 @@ jobs: git commit --all --amend --no-edit || true git push --force-with-lease echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - {{> stepChecks jobName="Update - Release" jobCheck=(obj sha="steps.commit.outputs.sha" name="Release" )}} - {{> stepChecks jobCheck=(obj id="needs.release.outputs.check-id" )}} + {{> stepChecksYml jobName="Update - Release" jobCheck=(obj sha="steps.commit.outputs.sha" name="Release" )}} + {{> stepChecksYml jobCheck=(obj id="needs.release.outputs.check-id" )}} ci: name: CI - Release @@ -108,7 +108,7 @@ jobs: post-ci: needs: [release, update, ci] - {{> job jobName="Post CI - Release" jobIf="needs.release.outputs.pr && always()" jobSkipSetup=true }} + {{> jobYml jobName="Post CI - Release" jobIf="needs.release.outputs.pr && always()" jobSkipSetup=true }} - name: Get Needs Result id: needs-result run: | @@ -121,11 +121,11 @@ jobs: result="success" fi echo "result=$result" >> $GITHUB_OUTPUT - {{> stepChecks jobCheck=(obj id="needs.update.outputs.check-id" status="steps.needs-result.outputs.result") }} + {{> stepChecksYml jobCheck=(obj id="needs.update.outputs.check-id" status="steps.needs-result.outputs.result") }} post-release: needs: release - {{> job jobName="Post Release - Release" jobIf="needs.release.outputs.releases" jobSkipSetup=true }} + {{> jobYml jobName="Post Release - Release" jobIf="needs.release.outputs.releases" jobSkipSetup=true }} - name: Create Release PR Comment uses: actions/github-script@v6 env: @@ -163,11 +163,11 @@ jobs: needs: release name: Release Integration if: needs.release.outputs.release - {{> jobReleaseIntegration }} + {{> jobReleaseIntegrationYml }} post-release-integration: needs: [release, release-integration] - {{> job jobName="Post Release Integration - Release" jobIf="needs.release.outputs.release && always()" jobSkipSetup=true }} + {{> jobYml jobName="Post Release Integration - Release" jobIf="needs.release.outputs.release && always()" jobSkipSetup=true }} - name: Get Needs Result id: needs-result run: | diff --git a/lib/content/settings.yml b/lib/content/settings-yml.hbs similarity index 100% rename from lib/content/settings.yml rename to lib/content/settings-yml.hbs diff --git a/lib/content/tap.json b/lib/content/tap-json.hbs similarity index 100% rename from lib/content/tap.json rename to lib/content/tap-json.hbs diff --git a/lib/content/tsconfig-json.hbs b/lib/content/tsconfig-json.hbs new file mode 100644 index 00000000..42776f85 --- /dev/null +++ b/lib/content/tsconfig-json.hbs @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "jsx": "react", + "declaration": true, + "declarationMap": true, + "inlineSources": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "moduleResolution": "nodenext", + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "target": "es2022", + "module": "nodenext" + } +} diff --git a/lib/util/files.js b/lib/util/files.js index 3b2b5723..713c01e0 100644 --- a/lib/util/files.js +++ b/lib/util/files.js @@ -1,5 +1,5 @@ const { join } = require('path') -const { defaultsDeep, omit } = require('lodash') +const { defaultsDeep, omit, isPlainObject } = require('lodash') const deepMapValues = require('just-deep-map-values') const { glob } = require('glob') const { mergeWithCustomizers, customizers } = require('./merge.js') @@ -12,6 +12,11 @@ const FILE_KEYS = ['rootRepo', 'rootModule', 'workspaceRepo', 'workspaceModule'] const globify = pattern => pattern.split('\\').join('/') +const deepMapKeys = (obj, fn) => Object.entries(obj).reduce((acc, [key, value]) => { + acc[fn(key)] = isPlainObject(value) ? deepMapKeys(value, fn) : value + return acc +}, {}) + const mergeFiles = mergeWithCustomizers((value, srcValue, key, target, source, stack) => { // This will merge all files except if the src file has overwrite:false. Then // the files will be turned into an array so they can be applied on top of @@ -35,7 +40,7 @@ const fileEntries = (dir, files, options, { allowMultipleSources = true } = {}) continue } - // target paths need to be joinsed with dir and templated + // target paths need to be joined with dir and templated const target = join(dir, template(key, options)) if (Array.isArray(source)) { @@ -66,7 +71,7 @@ const getParsers = (dir, files, options, parseOptions) => { const clean = typeof shouldClean === 'function' ? shouldClean(options) : false if (parser) { - // allow files to extend base parsers or create new ones + // allow files to extend base parsers or create new ones return new (parser(Parser.Parsers))(target, file, options, { clean }) } @@ -105,23 +110,27 @@ const parseEach = async (dir, files, options, parseOptions, fn) => { return res.filter(Boolean) } -const parseConfig = (files, dir, overrides) => { - const normalizeFiles = (v) => deepMapValues(v, (value, key) => { - if (key === RM_KEY && Array.isArray(value)) { - return value.reduce((acc, k) => { - acc[k] = true - return acc - }, {}) - } - if (typeof value === 'string') { - const file = join(dir, value) - return key === 'file' ? file : { file } - } - if (value === true && FILE_KEYS.includes(key)) { - return {} - } - return value - }) +const parseConfig = (files, dir, overrides, templateSettings) => { + const normalizeFiles = (v) => { + v = deepMapKeys(v, (s) => template(s, templateSettings)) + return deepMapValues(v, (value, key) => { + if (key === RM_KEY && Array.isArray(value)) { + return value.reduce((acc, k) => { + // template files nows since they need to be normalized before merging + acc[template(k, templateSettings)] = true + return acc + }, {}) + } + if (typeof value === 'string') { + const file = join(dir, value) + return key === 'file' ? file : { file } + } + if (value === true && FILE_KEYS.includes(key)) { + return {} + } + return value + }) + } const merged = mergeFiles(normalizeFiles(files), normalizeFiles(overrides)) const withDefaults = defaultsDeep(merged, FILE_KEYS.reduce((acc, k) => { diff --git a/lib/util/get-cmd-path.js b/lib/util/get-cmd-path.js new file mode 100644 index 00000000..0c311044 --- /dev/null +++ b/lib/util/get-cmd-path.js @@ -0,0 +1,36 @@ +const { join, relative } = require('path') +const { makePosix } = require('./path.js') + +const getCmdPath = (key, { pkgConfig, rootConfig, isRoot, pkg, rootPkg }) => { + const result = (local, isRelative) => { + let root = local + const isLocal = local.startsWith('.') || local.startsWith('/') + + if (isLocal) { + if (isRelative) { + // Make a path relative from a workspace to the root if we are in a workspace + local = makePosix(join(relative(pkg.path, rootPkg.path), local)) + } + local = `node ${local}` + root = `node ${root}` + } + + return { + isLocal, + local, + root, + } + } + + if (pkgConfig[key]) { + return result(pkgConfig[key]) + } + + if (rootConfig[key]) { + return result(rootConfig[key], !isRoot) + } + + return result(key) +} + +module.exports = getCmdPath diff --git a/lib/util/git.js b/lib/util/git.js index 1b35f660..c28760db 100644 --- a/lib/util/git.js +++ b/lib/util/git.js @@ -19,9 +19,9 @@ const tryGit = async (path, ...args) => { // parse a repo from a git origin into a format // for a package.json#repository object -const getUrl = async (path) => { +const getRemoteUrl = async (path, remote) => { try { - const urlStr = await tryGit(path, 'remote', 'get-url', 'origin') + const urlStr = await tryGit(path, 'remote', 'get-url', remote) const { domain, user, project } = hgi.fromUrl(urlStr) const url = new URL(`https://${domain}`) url.pathname = `/${user}/${project}.git` @@ -31,6 +31,10 @@ const getUrl = async (path) => { } } +const getUrl = async (path) => { + return (await getRemoteUrl(path, 'upstream')) ?? (await getRemoteUrl(path, 'origin')) +} + const getBranches = async (path, branchPatterns) => { let matchingBranches = new Set() let matchingPatterns = new Set() diff --git a/lib/util/import-or-require.js b/lib/util/import-or-require.js new file mode 100644 index 00000000..8fc7ef97 --- /dev/null +++ b/lib/util/import-or-require.js @@ -0,0 +1,29 @@ +// This fixes weird behavior I was seeing where calls to require(path) would +// fail the first time and then fetch via dynamic import which is correct, but +// then subsequent requires for the same path would return an empty object. Not +// sure if a bug or I'm doing something wrong but since the require/imports here +// are short lived, it is safe to create our own cache and use that. +const { pathToFileURL } = require('url') + +const importOrRequireCache = new Map() + +const importOrRequire = async (path) => { + if (importOrRequireCache.has(path)) { + return importOrRequireCache.get(path) + } + let content = {} + try { + content = require(path) + } catch { + try { + content = await import(pathToFileURL(path)).then(r => r.default) + } catch { + // its ok if this fails since the content dir might only be to provide + // other files. the index.js is optional + } + } + importOrRequireCache.set(path, content) + return content +} + +module.exports = importOrRequire diff --git a/lib/util/parser.js b/lib/util/parser.js index 3ca63e9e..27f498b7 100644 --- a/lib/util/parser.js +++ b/lib/util/parser.js @@ -173,7 +173,7 @@ class Gitignore extends Base { } class Js extends Base { - static types = ['*.js'] + static types = ['*.js', '*.cjs'] comment = (c) => `/* ${c} */` } @@ -306,6 +306,10 @@ class JsonMerge extends Json { merge = (t, s) => merge(t, s) } +class JsonMergeNoComment extends JsonMerge { + comment = null +} + class PackageJson extends JsonMerge { static types = ['package.json'] @@ -346,6 +350,7 @@ const Parsers = { YmlMerge, Json, JsonMerge, + JsonMergeNoComment, PackageJson, } diff --git a/lib/util/path.js b/lib/util/path.js new file mode 100644 index 00000000..e0582f59 --- /dev/null +++ b/lib/util/path.js @@ -0,0 +1,13 @@ +const { posix, win32 } = require('path') + +const makePosix = (v) => v.split(win32.sep).join(posix.sep) +const deglob = (v) => makePosix(v).replace(/[/*]+$/, '') +const posixDir = (v) => `${v === '.' ? '' : deglob(v).replace(/\/$/, '')}${posix.sep}` +const posixGlob = (str) => `${posixDir(str)}**` + +module.exports = { + makePosix, + deglob, + posixDir, + posixGlob, +} diff --git a/lib/util/template.js b/lib/util/template.js index 1eb67ed7..d035b3db 100644 --- a/lib/util/template.js +++ b/lib/util/template.js @@ -31,7 +31,7 @@ const makePartials = (dir, isBase) => { Handlebars.registerPartial(partials) } -const setupHandlebars = (baseDir, ...otherDirs) => { +const setupHandlebars = (dirs) => { Handlebars.registerHelper('obj', ({ hash }) => Object.fromEntries(safeValues(hash))) Handlebars.registerHelper('join', (arr, sep) => arr.join(typeof sep === 'string' ? sep : ', ')) Handlebars.registerHelper('pluck', (arr, key) => arr.map(a => a[key])) @@ -40,14 +40,17 @@ const setupHandlebars = (baseDir, ...otherDirs) => { Handlebars.registerHelper('json', (c) => JSON.stringify(c)) Handlebars.registerHelper('del', () => JSON.stringify(DELETE)) - makePartials(baseDir, true) - for (const dir of otherDirs) { - makePartials(dir) + if (Array.isArray(dirs)) { + const [baseDir, ...otherDirs] = dirs + makePartials(baseDir, true) + for (const dir of otherDirs) { + makePartials(dir) + } } } -const template = (str, { config, ...options }) => { - setupHandlebars(...config.__PARTIAL_DIRS__) +const template = (str, { config = {}, ...options }) => { + setupHandlebars(config.__PARTIAL_DIRS__) const t = Handlebars.compile(str, { strict: true }) diff --git a/package.json b/package.json index e1a6bdeb..7ada91a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/template-oss", - "version": "4.19.0", + "version": "4.20.0", "description": "templated files used in npm CLI team oss projects", "main": "lib/content/index.js", "bin": { @@ -10,7 +10,7 @@ "template-oss-release-manager": "bin/release-manager.js" }, "scripts": { - "lint": "eslint \"**/*.js\"", + "lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"", "lintfix": "npm run lint -- --fix", "posttest": "npm run lint", "snap": "tap", @@ -33,25 +33,25 @@ "license": "ISC", "dependencies": { "@actions/core": "^1.9.1", - "@commitlint/cli": "^17.1.1", - "@commitlint/config-conventional": "^17.1.0", + "@commitlint/cli": "^18.2.0", + "@commitlint/config-conventional": "^18.1.0", "@isaacs/string-locale-compare": "^1.1.0", - "@npmcli/arborist": "^6.0.0", - "@npmcli/git": "^4.0.0", + "@npmcli/arborist": "^7.2.1", + "@npmcli/git": "^5.0.3", "@npmcli/map-workspaces": "^3.0.0", - "@npmcli/package-json": "^4.0.0", + "@npmcli/package-json": "^5.0.0", "@octokit/rest": "^19.0.4", "diff": "^5.0.0", "glob": "^10.1.0", "handlebars": "^4.7.7", - "hosted-git-info": "^6.0.0", + "hosted-git-info": "^7.0.1", "ini": "^4.0.0", "json-parse-even-better-errors": "^3.0.0", "just-deep-map-values": "^1.1.1", "just-diff": "^6.0.0", "lodash": "^4.17.21", "minimatch": "^9.0.2", - "npm-package-arg": "^10.0.0", + "npm-package-arg": "^11.0.1", "proc-log": "^3.0.0", "release-please": "npm:@npmcli/release-please@^14.2.6", "semver": "^7.3.5", @@ -81,7 +81,7 @@ "publish": true }, "engines": { - "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + "node": "^18.17.0 || >=20.5.0" }, "workspaces": [ "workspace/test-workspace" diff --git a/tap-snapshots/test/apply/source-snapshots.js.test.cjs b/tap-snapshots/test/apply/source-snapshots.js.test.cjs index ec1bf3d9..901b2f94 100644 --- a/tap-snapshots/test/apply/source-snapshots.js.test.cjs +++ b/tap-snapshots/test/apply/source-snapshots.js.test.cjs @@ -33,6 +33,9 @@ const localConfigs = readdir(__dirname) module.exports = { root: true, + ignorePatterns: [ + 'tap-testdir*/', + ], extends: [ '@npmcli', ...localConfigs, @@ -255,48 +258,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -396,48 +384,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -540,7 +513,9 @@ jobs: - name: Update Windows npm if: | matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') ) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz @@ -550,34 +525,33 @@ jobs: cd .. rmdir /s /q package - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -635,48 +609,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -727,7 +686,9 @@ jobs: - name: Update Windows npm if: | matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') ) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz @@ -737,34 +698,33 @@ jobs: cd .. rmdir /s /q package - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -853,48 +813,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -1024,48 +969,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -1136,48 +1066,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -1293,48 +1208,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -1503,48 +1403,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -1638,6 +1523,8 @@ jobs: # ignore everything in the root /* +# transient test directories +tap-testdir*/ # keep these !**/.gitignore @@ -1663,6 +1550,7 @@ jobs: !/SECURITY.md !/tap-snapshots/ !/test/ +!/tsconfig.json .npmrc ======================================== @@ -1745,7 +1633,7 @@ package.json "name": "testpkg", "version": "1.0.0", "scripts": { - "lint": "eslint /"**/*.js/"", + "lint": "eslint /"**/*.{js,cjs,ts,mjs,jsx,tsx}/"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", @@ -1873,6 +1761,7 @@ const localConfigs = readdir(__dirname) module.exports = { root: true, ignorePatterns: [ + 'tap-testdir*/', 'workspaces/a/**', 'workspaces/b/**', ], @@ -2098,48 +1987,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -2194,48 +2068,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -2286,7 +2145,9 @@ jobs: - name: Update Windows npm if: | matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') ) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz @@ -2296,34 +2157,33 @@ jobs: cd .. rmdir /s /q package - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -2378,48 +2238,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -2470,7 +2315,9 @@ jobs: - name: Update Windows npm if: | matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') ) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz @@ -2480,34 +2327,33 @@ jobs: cd .. rmdir /s /q package - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -2607,48 +2453,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -2751,7 +2582,9 @@ jobs: - name: Update Windows npm if: | matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') ) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz @@ -2761,34 +2594,33 @@ jobs: cd .. rmdir /s /q package - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -2852,48 +2684,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -2944,7 +2761,9 @@ jobs: - name: Update Windows npm if: | matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') ) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz @@ -2954,34 +2773,33 @@ jobs: cd .. rmdir /s /q package - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -3070,48 +2888,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -3241,48 +3044,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -3353,48 +3141,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -3510,48 +3283,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -3720,48 +3478,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -3855,6 +3598,8 @@ jobs: # ignore everything in the root /* +# transient test directories +tap-testdir*/ # keep these !**/.gitignore @@ -3880,6 +3625,7 @@ jobs: !/SECURITY.md !/tap-snapshots/ !/test/ +!/tsconfig.json !/workspaces/ /workspaces/* !/workspaces/a/ @@ -3972,7 +3718,7 @@ package.json "workspaces/b" ], "scripts": { - "lint": "eslint /"**/*.js/"", + "lint": "eslint /"**/*.{js,cjs,ts,mjs,jsx,tsx}/"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", @@ -4078,6 +3824,9 @@ const localConfigs = readdir(__dirname) module.exports = { root: true, + ignorePatterns: [ + 'tap-testdir*/', + ], extends: [ '@npmcli', ...localConfigs, @@ -4090,6 +3839,8 @@ workspaces/a/.gitignore # ignore everything in the root /* +# transient test directories +tap-testdir*/ # keep these !**/.gitignore @@ -4114,7 +3865,7 @@ workspaces/a/package.json "name": "a", "version": "1.0.0", "scripts": { - "lint": "eslint /"**/*.js/"", + "lint": "eslint /"**/*.{js,cjs,ts,mjs,jsx,tsx}/"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", @@ -4153,6 +3904,9 @@ const localConfigs = readdir(__dirname) module.exports = { root: true, + ignorePatterns: [ + 'tap-testdir*/', + ], extends: [ '@npmcli', ...localConfigs, @@ -4165,6 +3919,8 @@ workspaces/b/.gitignore # ignore everything in the root /* +# transient test directories +tap-testdir*/ # keep these !**/.gitignore @@ -4189,7 +3945,7 @@ workspaces/b/package.json "name": "b", "version": "1.0.0", "scripts": { - "lint": "eslint /"**/*.js/"", + "lint": "eslint /"**/*.{js,cjs,ts,mjs,jsx,tsx}/"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", @@ -4373,48 +4129,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -4465,7 +4206,9 @@ jobs: - name: Update Windows npm if: | matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') ) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz @@ -4475,34 +4218,33 @@ jobs: cd .. rmdir /s /q package - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -4557,48 +4299,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -4649,7 +4376,9 @@ jobs: - name: Update Windows npm if: | matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') ) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz @@ -4659,34 +4388,33 @@ jobs: cd .. rmdir /s /q package - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -4786,48 +4514,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -4930,7 +4643,9 @@ jobs: - name: Update Windows npm if: | matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') + startsWith(steps.node.outputs.node-version, 'v10.') || + startsWith(steps.node.outputs.node-version, 'v12.') || + startsWith(steps.node.outputs.node-version, 'v14.') ) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz @@ -4940,34 +4655,33 @@ jobs: cd .. rmdir /s /q package - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -5020,48 +4734,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -5191,48 +4890,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -5303,48 +4987,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -5460,48 +5129,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -5670,48 +5324,33 @@ jobs: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -5877,6 +5516,9 @@ const localConfigs = readdir(__dirname) module.exports = { root: true, + ignorePatterns: [ + 'tap-testdir*/', + ], extends: [ '@npmcli', ...localConfigs, @@ -5889,6 +5531,8 @@ workspaces/a/.gitignore # ignore everything in the root /* +# transient test directories +tap-testdir*/ # keep these !**/.gitignore @@ -5913,7 +5557,7 @@ workspaces/a/package.json "name": "a", "version": "1.0.0", "scripts": { - "lint": "eslint /"**/*.js/"", + "lint": "eslint /"**/*.{js,cjs,ts,mjs,jsx,tsx}/"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", @@ -5952,6 +5596,9 @@ const localConfigs = readdir(__dirname) module.exports = { root: true, + ignorePatterns: [ + 'tap-testdir*/', + ], extends: [ '@npmcli', ...localConfigs, @@ -5964,6 +5611,8 @@ workspaces/b/.gitignore # ignore everything in the root /* +# transient test directories +tap-testdir*/ # keep these !**/.gitignore @@ -5988,7 +5637,7 @@ workspaces/b/package.json "name": "b", "version": "1.0.0", "scripts": { - "lint": "eslint /"**/*.js/"", + "lint": "eslint /"**/*.{js,cjs,ts,mjs,jsx,tsx}/"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", diff --git a/tap-snapshots/test/check/diff-snapshots.js.test.cjs b/tap-snapshots/test/check/diff-snapshots.js.test.cjs index d6574da4..c37c69c5 100644 --- a/tap-snapshots/test/check/diff-snapshots.js.test.cjs +++ b/tap-snapshots/test/check/diff-snapshots.js.test.cjs @@ -99,23 +99,23 @@ The repo file audit.yml needs to be updated: [@npmcli/template-oss ERROR] There was an erroring getting the target file [@npmcli/template-oss ERROR] Error: {{ROOT}}/test/check/tap-testdir-diff-snapshots-update-and-remove-errors/.github/workflows/audit.yml - YAMLParseError: Implicit keys need to be on a single line at line 84, column 1: + YAMLParseError: Implicit keys need to be on a single line at line 69, column 1: run: npm audit --audit-level=none >>>>I HOPE THIS IS NOT VALID YAML<<<<<<<<<<< ^ - YAMLParseError: Block scalar header includes extra characters: >>>>I at line 84, column 2: + YAMLParseError: Block scalar header includes extra characters: >>>>I at line 69, column 2: >>>>I HOPE THIS IS NOT VALID YAML<<<<<<<<<<< ^ - YAMLParseError: Not a YAML token: HOPE THIS IS NOT VALID YAML<<<<<<<<<<< at line 84, column 7: + YAMLParseError: Not a YAML token: HOPE THIS IS NOT VALID YAML<<<<<<<<<<< at line 69, column 7: >>>>I HOPE THIS IS NOT VALID YAML<<<<<<<<<<< ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - YAMLParseError: Implicit map keys need to be followed by map values at line 84, column 1: + YAMLParseError: Implicit map keys need to be followed by map values at line 69, column 1: run: npm audit --audit-level=none >>>>I HOPE THIS IS NOT VALID YAML<<<<<<<<<<< @@ -156,48 +156,33 @@ The repo file audit.yml needs to be updated: node-version: 20.x check-latest: contains('20.x', '.x') - # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows - - name: Update Windows npm - if: | - matrix.platform.os == 'windows-latest' && ( - startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.') - ) - run: | - curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz - tar xf npm-7.5.4.tgz - cd package - node lib/npm.js install --no-fund --no-audit -g ../npm-7.5.4.tgz - cd .. - rmdir /s /q package - - # Start on Node 10 because we dont test on anything lower - - name: Install npm@7 on Node 10 + - name: Install Latest npm shell: bash - if: startsWith(steps.node.outputs.node-version, 'v10.') - id: npm-7 + env: + NODE_VERSION: \${{ steps.node.outputs.node-version }} run: | - npm i --prefer-online --no-fund --no-audit -g npm@7 - echo "updated=true" >> "$GITHUB_OUTPUT" + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") - - name: Install npm@8 on Node 12 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v12.') - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + echo "node@$NODE_VERSION" - - name: Install npm@9 on Node 14/16/18.0 - shell: bash - if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - id: npm-9 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@9 - echo "updated=true" >> "$GITHUB_OUTPUT" + for SPEC in \${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi - - name: Install npm@latest on Node - if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - run: npm i --prefer-online --no-fund --no-audit -g npm@latest + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH - name: npm Version run: npm -v @@ -217,23 +202,22 @@ The repo file ci.yml needs to be updated: .github/workflows/ci.yml ======================================== - @@ -159,4 +159,25 @@ - id: npm-8 - run: | - npm i --prefer-online --no-fund --no-audit -g npm@8 - echo "updated=true" >> "$GITHUB_OUTPUT" + @@ -146,4 +146,24 @@ + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + + echo "Found compatible version: npm@$MATCH" + + break + + fi + + done + - + - name: Install npm@9 on Node 14/16/18.0 - + shell: bash - + if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.') - + id: npm-9 - + run: | - + npm i --prefer-online --no-fund --no-audit -g npm@9 - + echo "updated=true" >> "$GITHUB_OUTPUT" + + if [ -z $MATCH ]; then + + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + + exit 1 + + fi + - + - name: Install npm@latest on Node - + if: \${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }} - + run: npm i --prefer-online --no-fund --no-audit -g npm@latest + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH + + - name: npm Version + run: npm -v diff --git a/tap-snapshots/test/check/snapshots.js.test.cjs b/tap-snapshots/test/check/snapshots.js.test.cjs index 0c2c6c71..245c3bcd 100644 --- a/tap-snapshots/test/check/snapshots.js.test.cjs +++ b/tap-snapshots/test/check/snapshots.js.test.cjs @@ -73,7 +73,7 @@ The module file package.json needs to be updated: "lib/" ] "scripts" is missing, expected { - "lint": "eslint /"**/*.js/"", + "lint": "eslint /"**/*.{js,cjs,ts,mjs,jsx,tsx}/"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", @@ -120,6 +120,7 @@ The following files are tracked by git but matching a pattern in .gitignore: To correct it: move files to not match one of the following patterns: /* + tap-testdir*/ !**/.gitignore !/.commitlintrc.js !/.eslintrc.js @@ -143,6 +144,7 @@ To correct it: move files to not match one of the following patterns: !/SECURITY.md !/tap-snapshots/ !/test/ + !/tsconfig.json ------------------------------------------------------------------- ` @@ -159,6 +161,7 @@ The following files are tracked by git but matching a pattern in .gitignore: To correct it: move files to not match one of the following patterns: /* + tap-testdir*/ !**/.gitignore !/.commitlintrc.js !/.eslintrc.js @@ -182,6 +185,7 @@ To correct it: move files to not match one of the following patterns: !/SECURITY.md !/tap-snapshots/ !/test/ + !/tsconfig.json !/workspaces/ /workspaces/* !/workspaces/a/ @@ -196,6 +200,7 @@ The following files are tracked by git but matching a pattern in workspaces/a/.g To correct it: move files to not match one of the following patterns: /* + tap-testdir*/ !**/.gitignore !/.eslintrc.js !/.eslintrc.local.* @@ -221,6 +226,7 @@ The following files are tracked by git but matching a pattern in workspaces/b/.g To correct it: move files to not match one of the following patterns: /* + tap-testdir*/ !**/.gitignore !/.eslintrc.js !/.eslintrc.local.* @@ -321,7 +327,7 @@ The module file package.json needs to be updated: "lib/" ] "scripts" is missing, expected { - "lint": "eslint /"**/*.js/"", + "lint": "eslint /"**/*.{js,cjs,ts,mjs,jsx,tsx}/"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", @@ -397,7 +403,7 @@ The module file package.json needs to be updated: "lib/" ] "scripts" is missing, expected { - "lint": "eslint /"**/*.js/"", + "lint": "eslint /"**/*.{js,cjs,ts,mjs,jsx,tsx}/"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", @@ -466,7 +472,7 @@ The module file package.json needs to be updated: "lib/" ] "scripts" is missing, expected { - "lint": "eslint /"**/*.js/"", + "lint": "eslint /"**/*.{js,cjs,ts,mjs,jsx,tsx}/"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", diff --git a/test/apply/allow-paths.js b/test/apply/allow-paths.js index 2cf93fd1..fd272d68 100644 --- a/test/apply/allow-paths.js +++ b/test/apply/allow-paths.js @@ -34,8 +34,8 @@ t.test('works with custom content', async (t) => { }, testdir: { content_dir: { - 'paths.json': '{{{json allowPaths}}}', - 'index.js': 'module.exports={rootRepo:{add:{"paths.json":"paths.json"}}}', + 'paths-json.hbs': '{{{json allowPaths}}}', + 'index.js': 'module.exports={rootRepo:{add:{"paths.json":"paths-json.hbs"}}}', }, }, }) diff --git a/test/apply/esm.js b/test/apply/esm.js new file mode 100644 index 00000000..3afc80ca --- /dev/null +++ b/test/apply/esm.js @@ -0,0 +1,23 @@ +const t = require('tap') +const setup = require('../setup.js') + +t.test('basic', async (t) => { + const s = await setup(t, { + package: { + type: 'module', + templateOSS: { + content: 'content_dir', + }, + }, + testdir: { + content_dir: { + 'file.js': 'var x = 1;', + 'index.js': 'export default { rootRepo:{add:{"file.js":"file.js"}} }', + }, + }, + }) + await s.apply() + + const file = await s.readFile('file.js') + t.match(file, 'var x = 1;') +}) diff --git a/test/apply/index.js b/test/apply/index.js index a26ea1bf..3be5f2a5 100644 --- a/test/apply/index.js +++ b/test/apply/index.js @@ -1,5 +1,4 @@ const t = require('tap') -const fs = require('fs') const { join } = require('path') const setup = require('../setup.js') @@ -21,10 +20,10 @@ t.test('turn off root files', async (t) => { }, }) await s.apply() - t.notOk(fs.existsSync(s.join('.commitlintrc.js'))) - t.notOk(fs.existsSync(s.join('.eslintrc.js'))) - t.ok(fs.existsSync(s.join('.github', 'workflows', 'release-test.yml'))) - t.ok(fs.existsSync(s.join('.eslintrc.yml'))) + t.notOk(await s.exists('.commitlintrc.js')) + t.notOk(await s.exists('.eslintrc.js')) + t.ok(await s.exists('.github', 'workflows', 'release-test.yml')) + t.ok(await s.exists('.eslintrc.yml')) }) t.test('turn off root rm only', async (t) => { @@ -49,10 +48,10 @@ t.test('turn off root rm only', async (t) => { }, }) await s.apply() - t.ok(fs.existsSync(s.join('.commitlintrc.js'))) - t.ok(fs.existsSync(s.join('.eslintrc.js'))) - t.ok(fs.existsSync(s.join('.github', 'workflows', 'release-test.yml'))) - t.ok(fs.existsSync(s.join('.eslintrc.yml'))) + t.ok(await s.exists('.commitlintrc.js')) + t.ok(await s.exists('.eslintrc.js')) + t.ok(await s.exists('.github', 'workflows', 'release-test.yml')) + t.ok(await s.exists('.eslintrc.yml')) }) t.test('turn off root add only', async (t) => { @@ -77,10 +76,10 @@ t.test('turn off root add only', async (t) => { }, }) await s.apply() - t.notOk(fs.existsSync(s.join('.commitlintrc.js'))) - t.notOk(fs.existsSync(s.join('.eslintrc.js'))) - t.notOk(fs.existsSync(s.join('.github', 'workflows', 'release-test.yml'))) - t.notOk(fs.existsSync(s.join('.eslintrc.yml'))) + t.notOk(await s.exists('.commitlintrc.js')) + t.notOk(await s.exists('.eslintrc.js')) + t.notOk(await s.exists('.github', 'workflows', 'release-test.yml')) + t.notOk(await s.exists('.eslintrc.yml')) }) t.test('turn off specific files', async (t) => { @@ -115,10 +114,10 @@ t.test('turn off specific files', async (t) => { }, }) await s.apply() - t.notOk(fs.existsSync(s.join('.commitlintrc.js'))) - t.notOk(fs.existsSync(s.join('.eslintrc.js'))) - t.ok(fs.existsSync(s.join('.github', 'workflows', 'release-test.yml'))) - t.ok(fs.existsSync(s.join('.eslintrc.yml'))) + t.notOk(await s.exists('.commitlintrc.js')) + t.notOk(await s.exists('.eslintrc.js')) + t.ok(await s.exists('.github', 'workflows', 'release-test.yml')) + t.ok(await s.exists('.eslintrc.yml')) }) t.test('root can set workspace files', async (t) => { @@ -143,8 +142,8 @@ t.test('root can set workspace files', async (t) => { }, }) await s.apply() - t.notOk(fs.existsSync(s.join(s.workspaces.a, '.eslintrc.js'))) - t.ok(fs.existsSync(s.join(s.workspaces.a, '.npmrc'))) + t.notOk(await s.exists(s.workspaces.a, '.eslintrc.js')) + t.ok(await s.exists(s.workspaces.a, '.npmrc')) }) t.test('workspace config can override root', async (t) => { @@ -161,7 +160,7 @@ t.test('workspace config can override root', async (t) => { a: { templateOSS: { workspaceModule: { - add: { '.eslintrc.js': 'eslintrc.js' }, + add: { '.eslintrc.js': 'eslintrc-js.hbs' }, rm: { '.npmrc': true }, }, }, @@ -176,8 +175,8 @@ t.test('workspace config can override root', async (t) => { }, }) await s.apply() - t.ok(fs.existsSync(s.join(s.workspaces.a, '.eslintrc.js'))) - t.notOk(fs.existsSync(s.join(s.workspaces.a, '.npmrc'))) + t.ok(await s.exists(s.workspaces.a, '.eslintrc.js')) + t.notOk(await s.exists(s.workspaces.a, '.npmrc')) }) t.test('workspaces can override content', async (t) => { @@ -199,15 +198,15 @@ t.test('workspaces can override content', async (t) => { testdir: { content_dir: { 'index.js': 'module.exports={}' }, content_dir2: { - 'x.js': 'exists', - 'index.js': 'module.exports={workspaceRepo:{add:{"x.js":"x.js"}}}', + 'x-js.hbs': 'exists', + 'index.js': 'module.exports={workspaceRepo:{add:{"x.js":"x-js.hbs"}}}', }, }, }) await s.apply() - t.notOk(fs.existsSync(s.join('.eslintrc.js'))) - t.ok(fs.existsSync(s.join(s.workspaces.a, '.eslintrc.js'))) - t.ok(fs.existsSync(s.join('x.js'))) + t.notOk(await s.exists('.eslintrc.js')) + t.ok(await s.exists(s.workspaces.a, '.eslintrc.js')) + t.ok(await s.exists('x.js')) }) t.test('content can override partials', async (t) => { @@ -221,12 +220,12 @@ t.test('content can override partials', async (t) => { content_dir: { 'index.js': `module.exports={ rootRepo:{ - add:{'.github/workflows/ci-release.yml': 'ci-release.yml'} + add:{'.github/workflows/ci-release.yml': 'ci-release-yml.hbs'} } }`, - 'ci-release.yml': '{{> ciRelease }}\n job: 1', - '_step-deps.yml': '- run: INSTALL\n', - '_step-test.yml': '- run: TEST\n{{> defaultStepTest }}\n', + 'ci-release-yml.hbs': '{{> ciReleaseYml }}\n job: 1', + '_step-deps-yml.hbs': '- run: INSTALL\n', + '_step-test-yml.hbs': '- run: TEST\n{{> defaultStepTestYml }}\n', }, }, }) @@ -250,8 +249,8 @@ t.test('content can extend files', async (t) => { testdir: { content_dir: { // eslint-disable-next-line max-len - 'index.js': 'module.exports={rootRepo:{add:{".github/workflows/release.yml": "release.yml"}}}', - 'release.yml': '{{> ciRelease}}\n smoke-publish:\n runs-on: ubuntu-latest', + 'index.js': 'module.exports={rootRepo:{add:{".github/workflows/release.yml": "release-yml.hbs"}}}', + 'release-yml.hbs': '{{> ciReleaseYml}}\n smoke-publish:\n runs-on: ubuntu-latest', }, }, }) @@ -339,8 +338,7 @@ t.test('private workspace', async (t) => { t.ok(rpConfig.packages['workspaces/b']) t.notOk(rpConfig.packages['workspaces/a']) - const rp = s.join('.github', 'workflows') - t.ok(fs.existsSync(join(rp, 'release.yml'))) - t.notOk(fs.existsSync(join(rp, 'release-please-b.yml'))) - t.notOk(fs.existsSync(join(rp, 'release-please-a.yml'))) + t.ok(await s.exists('.github', 'workflows', 'release.yml')) + t.notOk(await s.exists('.github', 'workflows', 'release-please-b.yml')) + t.notOk(await s.exists('.github', 'workflows', 'release-please-a.yml')) }) diff --git a/test/apply/release-config.js b/test/apply/release-config.js index 94e6b75b..270f6d32 100644 --- a/test/apply/release-config.js +++ b/test/apply/release-config.js @@ -1,5 +1,4 @@ const t = require('tap') -const { existsSync } = require('fs') const setup = require('../setup.js') t.test('root only', async (t) => { @@ -19,7 +18,7 @@ t.test('root only', async (t) => { await s.apply() const releaseConfig = await s.readJson('release-please-config.json').catch(() => ({})) - const pr = existsSync(s.join('.github', 'workflows', 'pull-request.yml')) + const pr = await s.exists('.github', 'workflows', 'pull-request.yml') t.strictSame(releaseConfig.plugins, expected.plugins ? ['node-workspace'] : undefined) t.equal(pr, expected.pr) diff --git a/test/apply/tap.js b/test/apply/tap.js new file mode 100644 index 00000000..2a204877 --- /dev/null +++ b/test/apply/tap.js @@ -0,0 +1,37 @@ +const t = require('tap') +const setup = require('../setup.js') + +t.test('tap@18', async (t) => { + const s = await setup(t, { + ok: true, + package: { + devDependencies: { + tap: '^18', + }, + }, + }) + + await s.apply() + const pkg = await s.readJson('package.json') + t.strictSame(pkg.tap, {}) +}) + +t.test('tap@16', async (t) => { + const s = await setup(t, { + ok: true, + package: { + devDependencies: { + tap: '^16', + }, + }, + }) + + await s.apply() + const pkg = await s.readJson('package.json') + t.strictSame(pkg.tap, { + 'nyc-arg': [ + '--exclude', + 'tap-snapshots/**', + ], + }) +}) diff --git a/test/apply/typescript.js b/test/apply/typescript.js new file mode 100644 index 00000000..63aae412 --- /dev/null +++ b/test/apply/typescript.js @@ -0,0 +1,57 @@ +const t = require('tap') +const setup = require('../setup.js') + +t.test('basic', async (t) => { + const s = await setup(t, { + ok: true, + package: { + templateOSS: { + typescript: true, + }, + }, + testdir: { + '.eslintrc.js': 'delete this', + '.commitlintrc.js': 'delete this', + }, + }) + + t.ok(await s.exists('.eslintrc.js')) + t.ok(await s.exists('.commitlintrc.js')) + + await s.apply() + const checks = await s.check() + const pkg = await s.readJson('package.json') + const eslint = await s.readFile('.eslintrc.cjs') + + t.strictSame(checks[0].body, ['typescript', 'tshy', '@typescript-eslint/parser']) + t.equal(pkg.scripts.prepare, 'tshy') + t.equal(pkg.type, 'module') + t.match(eslint, 'dist/') + t.match(eslint, '@typescript-eslint/parser') + t.notOk(await s.exists('.eslintrc.js')) + t.notOk(await s.exists('.commitlintrc.js')) + t.ok(await s.exists('.commitlintrc.cjs')) +}) + +t.test('no default content', async (t) => { + const s = await setup(t, { + ok: true, + package: { + templateOSS: { + typescript: true, + defaultContent: false, + content: 'content_dir', + }, + }, + testdir: { + content_dir: { + 'file.js': 'var x = 1;', + 'index.js': 'module.exports={rootModule:{add:{"file.js":"file.js"}}}', + }, + }, + }) + await s.apply() + const checks = await s.check() + + t.strictSame(checks[0].body, ['typescript', 'tshy', '@typescript-eslint/parser']) +}) diff --git a/test/setup.js b/test/setup.js index 32c817de..33305b6f 100644 --- a/test/setup.js +++ b/test/setup.js @@ -94,6 +94,7 @@ const setupRoot = async (t, root, mocks) => { readdir, readJson: async (f) => JSON.parse(await rootFs.readFile(f)), writeJson: (p, d) => rootFs.writeFile(p, JSON.stringify(d, null, 2)), + exists: (...p) => fs.access(rootPath(...p)).then(() => true).catch(() => false), join: rootPath, apply: () => apply(root), check: () => check(root), @@ -106,7 +107,7 @@ const setup = async (t, { workspaces = {}, testdir = {}, mocks = {}, - ok, + ok = false, } = {}) => { const wsLookup = {} const pkg = merge( diff --git a/workspace/test-workspace/.eslintrc.js b/workspace/test-workspace/.eslintrc.js index 5db9f815..f21d26ec 100644 --- a/workspace/test-workspace/.eslintrc.js +++ b/workspace/test-workspace/.eslintrc.js @@ -10,6 +10,9 @@ const localConfigs = readdir(__dirname) module.exports = { root: true, + ignorePatterns: [ + 'tap-testdir*/', + ], extends: [ '@npmcli', ...localConfigs, diff --git a/workspace/test-workspace/.gitignore b/workspace/test-workspace/.gitignore index 79af2bfc..a96d056a 100644 --- a/workspace/test-workspace/.gitignore +++ b/workspace/test-workspace/.gitignore @@ -2,6 +2,8 @@ # ignore everything in the root /* +# transient test directories +tap-testdir*/ # keep these !**/.gitignore diff --git a/workspace/test-workspace/package.json b/workspace/test-workspace/package.json index 148cf346..4f304a50 100644 --- a/workspace/test-workspace/package.json +++ b/workspace/test-workspace/package.json @@ -6,7 +6,7 @@ "private": true, "scripts": { "test": "tap", - "lint": "eslint \"**/*.js\"", + "lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", @@ -35,7 +35,7 @@ "lib/" ], "engines": { - "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + "node": "^18.17.0 || >=20.5.0" }, "templateOSS": { "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten."