From aeb0162f68358f5783f63868a0c7c79d327f87fe Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Sat, 9 Apr 2022 14:38:34 -0700 Subject: [PATCH 1/7] fix: use ops+robot as git user for all ci --- .github/workflows/audit.yml | 4 +- .github/workflows/ci.yml | 8 +-- .github/workflows/codeql-analysis.yml | 4 +- .github/workflows/post-dependabot.yml | 4 +- .github/workflows/pull-request.yml | 4 +- lib/content/setup-git.yml | 4 +- .../test/apply/full-content.js.test.cjs | 72 +++++++++---------- tap-snapshots/test/check/diffs.js.test.cjs | 6 +- 8 files changed, 53 insertions(+), 53 deletions(-) diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 03dcd937..7f48d351 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -15,8 +15,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c04f4181..287a8696 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,8 +22,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x @@ -59,8 +59,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 56cd7b9c..0067fc1b 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -34,8 +34,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: diff --git a/.github/workflows/post-dependabot.yml b/.github/workflows/post-dependabot.yml index 0372a7a9..4dd83131 100644 --- a/.github/workflows/post-dependabot.yml +++ b/.github/workflows/post-dependabot.yml @@ -16,8 +16,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 93a5c3c9..bf86a7da 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -20,8 +20,8 @@ jobs: fetch-depth: 0 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x diff --git a/lib/content/setup-git.yml b/lib/content/setup-git.yml index 4ecd4697..8c148e97 100644 --- a/lib/content/setup-git.yml +++ b/lib/content/setup-git.yml @@ -7,5 +7,5 @@ {{/if}} - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" diff --git a/tap-snapshots/test/apply/full-content.js.test.cjs b/tap-snapshots/test/apply/full-content.js.test.cjs index 97ff50bc..5eb207e2 100644 --- a/tap-snapshots/test/apply/full-content.js.test.cjs +++ b/tap-snapshots/test/apply/full-content.js.test.cjs @@ -145,8 +145,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x @@ -182,8 +182,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x @@ -219,8 +219,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: \${{ matrix.node-version }} @@ -283,8 +283,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: @@ -312,8 +312,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x @@ -362,8 +362,8 @@ jobs: fetch-depth: 0 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x @@ -623,8 +623,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x @@ -664,8 +664,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x @@ -701,8 +701,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: \${{ matrix.node-version }} @@ -757,8 +757,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x @@ -794,8 +794,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: \${{ matrix.node-version }} @@ -846,8 +846,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x @@ -883,8 +883,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: \${{ matrix.node-version }} @@ -947,8 +947,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: @@ -976,8 +976,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x @@ -1026,8 +1026,8 @@ jobs: fetch-depth: 0 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x @@ -1085,8 +1085,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x @@ -1148,8 +1148,8 @@ jobs: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x diff --git a/tap-snapshots/test/check/diffs.js.test.cjs b/tap-snapshots/test/check/diffs.js.test.cjs index 83abafbc..d834a2d8 100644 --- a/tap-snapshots/test/check/diffs.js.test.cjs +++ b/tap-snapshots/test/check/diffs.js.test.cjs @@ -311,7 +311,7 @@ The repo file ci.yml needs to be updated: .github/workflows/ci.yml ======================================== @@ -63,4 +63,24 @@ - git config --global user.name "npm cli ops bot" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: \${{ matrix.node-version }} @@ -365,8 +365,8 @@ The repo file audit.yml needs to be updated: - uses: actions/checkout@v3 - name: Setup git user run: | - git config --global user.email "ops+npm-cli@npmjs.com" - git config --global user.name "npm cli ops bot" + git config --global user.email "npm team" + git config --global user.name "ops+robot@npmjs.com" - uses: actions/setup-node@v3 with: node-version: 16.x From c808c4ffd8ed7d1c198736a815df15e9a68ebb9c Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Fri, 15 Apr 2022 11:56:27 -0700 Subject: [PATCH 2/7] fix: lockfile setting adds lockfile to allowed gitignore --- lib/content/gitignore | 3 +++ test/apply/lockfile.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/apply/lockfile.js diff --git a/lib/content/gitignore b/lib/content/gitignore index f1cbf0fe..39fbb90d 100644 --- a/lib/content/gitignore +++ b/lib/content/gitignore @@ -12,6 +12,9 @@ !/README* !/LICENSE* !/CHANGELOG* +{{#if lockfile}} +package-lock.json +{{/if}} {{#each ignorePaths}} {{.}} {{/each}} diff --git a/test/apply/lockfile.js b/test/apply/lockfile.js new file mode 100644 index 00000000..3ffeba99 --- /dev/null +++ b/test/apply/lockfile.js @@ -0,0 +1,28 @@ +const t = require('tap') +const setup = require('../setup.js') + +t.test('lockfile', async (t) => { + const s = await setup(t, { + package: { + templateOSS: { + lockfile: true, + }, + }, + }) + await s.apply() + const gitignore = await s.readFile('.gitignore') + t.ok(gitignore.includes('package-lock.json')) + + const npmrc = await s.readFile('.npmrc') + t.ok(npmrc.includes('package-lock=true')) +}) + +t.test('no lockfile by default', async (t) => { + const s = await setup(t) + await s.apply() + const gitignore = await s.readFile('.gitignore') + t.ok(!gitignore.includes('package-lock.json')) + + const npmrc = await s.readFile('.npmrc') + t.ok(npmrc.includes('package-lock=false')) +}) From 2f7dcfa8c8f00677ad24ad15dd059556f1dfa1e8 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Fri, 15 Apr 2022 11:44:11 -0700 Subject: [PATCH 3/7] fix: dont create release please for private root pkg --- lib/content/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/content/index.js b/lib/content/index.js index dcd26b4f..5977dff1 100644 --- a/lib/content/index.js +++ b/lib/content/index.js @@ -13,7 +13,10 @@ const rootRepo = { '.github/workflows/codeql-analysis.yml': 'codeql-analysis.yml', '.github/workflows/post-dependabot.yml': 'post-dependabot.yml', '.github/workflows/pull-request.yml': 'pull-request.yml', - '.github/workflows/release-please.yml': 'release-please.yml', + '.github/workflows/release-please.yml': { + file: 'release-please.yml', + filter: (o) => !o.pkg.private, + }, }, } From 32f7f7c3df80b40a7536182e72b883d77ba46e64 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 13 Apr 2022 20:41:43 -0700 Subject: [PATCH 4/7] feat: allow option to set npm bin in package.json --- lib/config.js | 20 ++++++-- lib/content/index.js | 1 + lib/content/pkg.json | 8 ++-- test/apply/npm-bin.js | 104 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 test/apply/npm-bin.js diff --git a/lib/config.js b/lib/config.js index 338c7949..2c18e604 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,4 +1,4 @@ -const { relative, dirname, posix, win32 } = require('path') +const { relative, dirname, join, posix, win32 } = require('path') const log = require('proc-log') const { uniq, defaults } = require('lodash') const parseCIVersions = require('./util/parse-ci-versions.js') @@ -50,13 +50,14 @@ const getConfig = async ({ workspaceRepo, workspaceModule, version, - ...pkgContent + ...pkgConfig // this includes config merged in from root }, }) => { const isRoot = root === path const isLatest = version === LATEST_VERSION const isDogFood = pkg.name === NAME const isForce = process.argv.includes('--force') + const rawPkgConfig = getPkgConfig(pkg) // this is written to ci yml files so it needs to always use posix const pkgRelPath = makePosix(relative(root, path)) @@ -128,12 +129,25 @@ const getConfig = async ({ // merge the rest of base and pkg content to make the // full content object - const content = { ...baseContent, ...pkgContent } + const content = { ...baseContent, ...pkgConfig } // set some defaults on content that can be overwritten unlike // derived values which are calculated from other config const contentDefaults = {} + if (content.npmBin && content.npmBin !== baseContent.npmBin) { + // make it relative to each workspace if they did not set the config themselves + if (!rawPkgConfig.npmBin) { + content.npmBin = makePosix(join(relative(path, root), content.npmBin)) + } + // a bit of a hack but allow custom node paths or no node path at all + // checks if the first thing has node somewhere in it and if it doesnt + // puts a system node in front of the script + const execPaths = content.npmBin.split(' ')[0].split(posix.sep) + if (execPaths.every(p => p !== 'node')) { + content.npmBin = `node ${content.npmBin}` + } + } if (Array.isArray(content.ciVersions)) { const parsed = parseCIVersions(content.ciVersions) contentDefaults.engines = parsed.engines diff --git a/lib/content/index.js b/lib/content/index.js index 5977dff1..e76fac65 100644 --- a/lib/content/index.js +++ b/lib/content/index.js @@ -73,6 +73,7 @@ module.exports = { distPaths: ['bin/', 'lib/'], ciVersions: ['12.13.0', '12.x', '14.15.0', '14.x', '16.0.0', '16.x'], lockfile: false, + npmBin: 'npm', unwantedPackages: [ 'eslint', 'eslint-plugin-node', diff --git a/lib/content/pkg.json b/lib/content/pkg.json index 06ac6e8f..ce0d9571 100644 --- a/lib/content/pkg.json +++ b/lib/content/pkg.json @@ -5,17 +5,17 @@ "lint": "eslint \"**/*.js\"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", - "lintfix": "npm run lint -- --fix", - "preversion": "npm test", + "lintfix": "{{npmBin}} run lint -- --fix", + "preversion": "{{npmBin}} test", {{#if pkgPrivate}} "postversion": "git push origin --follow-tags", {{else}} - "postversion": "npm publish", + "postversion": "{{npmBin}} publish", "prepublishOnly": "git push origin --follow-tags", {{/if}} "snap": "tap", "test": "tap", - "posttest": "npm run lint", + "posttest": "{{npmBin}} run lint", "template-copy": {{{del}}}, "lint:fix": {{{del}}} }, diff --git a/test/apply/npm-bin.js b/test/apply/npm-bin.js new file mode 100644 index 00000000..33854cb3 --- /dev/null +++ b/test/apply/npm-bin.js @@ -0,0 +1,104 @@ +const t = require('tap') +const { join } = require('path') +const setup = require('../setup.js') + +t.test('custom node', async (t) => { + const s = await setup(t, { + ok: true, + package: { + templateOSS: { + npmBin: 'node /path/to/npm', + }, + }, + }) + await s.apply() + const { scripts } = await s.readJson('package.json') + t.equal(scripts.posttest, 'node /path/to/npm run lint') +}) + +t.test('custom node', async (t) => { + const s = await setup(t, { + ok: true, + package: { + templateOSS: { + npmBin: 'node /path/to/npm', + }, + }, + }) + await s.apply() + const { scripts } = await s.readJson('package.json') + t.equal(scripts.posttest, 'node /path/to/npm run lint') +}) + +t.test('relative npm bin with workspaces', async (t) => { + const s = await setup(t, { + ok: true, + package: { + templateOSS: { + npmBin: 'cli.js', + }, + }, + workspaces: { a: '@name/aaaa', b: 'bbb' }, + }) + await s.apply() + const { scripts } = await s.readJson('package.json') + const { scripts: scriptsA } = await s.readJson(join(s.workspaces.a, 'package.json')) + const { scripts: scriptsB } = await s.readJson(join(s.workspaces.b, 'package.json')) + t.equal(scripts.posttest, 'node cli.js run lint') + t.equal(scriptsA.posttest, 'node ../../cli.js run lint') + t.equal(scriptsB.posttest, 'node ../../cli.js run lint') +}) + +t.test('npm bin workspaces only with root config', async (t) => { + const s = await setup(t, { + ok: true, + package: { + templateOSS: { + rootRepo: false, + rootModule: false, + npmBin: './cli.js', + }, + }, + workspaces: { a: '@name/aaaa', b: 'bbb' }, + }) + await s.apply() + const { scripts } = await s.readJson('package.json') + const { scripts: scriptsA } = await s.readJson(join(s.workspaces.a, 'package.json')) + const { scripts: scriptsB } = await s.readJson(join(s.workspaces.b, 'package.json')) + t.equal(scripts, undefined) + t.equal(scriptsA.posttest, 'node ../../cli.js run lint') + t.equal(scriptsB.posttest, 'node ../../cli.js run lint') +}) + +t.test('separate workspace configs', async (t) => { + const s = await setup(t, { + ok: true, + package: { + templateOSS: { + rootRepo: false, + rootModule: false, + }, + }, + workspaces: { + a: { + name: 'a', + templateOSS: { + npmBin: 'bin_a.js', + }, + }, + b: { + name: 'b', + templateOSS: { + npmBin: 'bin_b.js', + }, + }, + }, + }) + await s.apply() + const { scripts } = await s.readJson('package.json') + const { scripts: scriptsA } = await s.readJson(join(s.workspaces.a, 'package.json')) + const { scripts: scriptsB } = await s.readJson(join(s.workspaces.b, 'package.json')) + t.equal(scripts, undefined) + t.equal(scriptsA.posttest, 'node bin_a.js run lint') + t.equal(scriptsB.posttest, 'node bin_b.js run lint') +}) From 996e0c5029fe8d519daee29b3241033400debac2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 15 Apr 2022 22:10:00 +0000 Subject: [PATCH 5/7] chore(main): release 3.4.0 --- CHANGELOG.md | 14 ++++++++++++++ package.json | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d662b55f..6e478e07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [3.4.0](https://github.com/npm/template-oss/compare/v3.3.2...v3.4.0) (2022-04-15) + + +### Features + +* allow option to set npm bin in package.json ([32f7f7c](https://github.com/npm/template-oss/commit/32f7f7c3df80b40a7536182e72b883d77ba46e64)) + + +### Bug Fixes + +* dont create release please for private root pkg ([2f7dcfa](https://github.com/npm/template-oss/commit/2f7dcfa8c8f00677ad24ad15dd059556f1dfa1e8)) +* lockfile setting adds lockfile to allowed gitignore ([c808c4f](https://github.com/npm/template-oss/commit/c808c4ffd8ed7d1c198736a815df15e9a68ebb9c)) +* use ops+robot as git user for all ci ([aeb0162](https://github.com/npm/template-oss/commit/aeb0162f68358f5783f63868a0c7c79d327f87fe)) + ### [3.3.2](https://github.com/npm/template-oss/compare/v3.3.1...v3.3.2) (2022-04-06) diff --git a/package.json b/package.json index 09e42b0f..6a338bfc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/template-oss", - "version": "3.3.2", + "version": "3.4.0", "description": "templated files used in npm CLI team oss projects", "main": "lib/content/index.js", "bin": { From c613429d2b46d94561aa20a8d39ca969a30f4391 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Fri, 15 Apr 2022 15:33:21 -0700 Subject: [PATCH 6/7] fix: properly allow package-lock when lockfile=true --- lib/content/gitignore | 6 +- tap-snapshots/test/apply/lockfile.js.test.cjs | 79 +++++++++++++++++++ .../test/check/gitignore.js.test.cjs | 1 + test/apply/lockfile.js | 10 +++ test/check/gitignore.js | 18 +++++ 5 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 tap-snapshots/test/apply/lockfile.js.test.cjs diff --git a/lib/content/gitignore b/lib/content/gitignore index 39fbb90d..01684a6e 100644 --- a/lib/content/gitignore +++ b/lib/content/gitignore @@ -12,9 +12,9 @@ !/README* !/LICENSE* !/CHANGELOG* -{{#if lockfile}} -package-lock.json -{{/if}} {{#each ignorePaths}} {{.}} {{/each}} +{{#if lockfile}} +!/package-lock.json +{{/if}} diff --git a/tap-snapshots/test/apply/lockfile.js.test.cjs b/tap-snapshots/test/apply/lockfile.js.test.cjs new file mode 100644 index 00000000..d9316652 --- /dev/null +++ b/tap-snapshots/test/apply/lockfile.js.test.cjs @@ -0,0 +1,79 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/apply/lockfile.js TAP lockfile > expect resolving Promise 1`] = ` +.gitignore +======================================== +# This file is automatically added by @npmcli/template-oss. Do not edit. + +# ignore everything in the root +/* + +# keep these +!/.eslintrc.local.* +!**/.gitignore +!/docs/ +!/tap-snapshots/ +!/test/ +!/map.js +!/scripts/ +!/README* +!/LICENSE* +!/CHANGELOG* +!/.commitlintrc.js +!/.eslintrc.js +!/.github/ +!/.gitignore +!/.npmrc +!/SECURITY.md +!/bin/ +!/lib/ +!/package.json +!/package-lock.json + +.npmrc +======================================== +; This file is automatically added by @npmcli/template-oss. Do not edit. + +package-lock=true +` + +exports[`test/apply/lockfile.js TAP no lockfile by default > expect resolving Promise 1`] = ` +.gitignore +======================================== +# This file is automatically added by @npmcli/template-oss. Do not edit. + +# ignore everything in the root +/* + +# keep these +!/.eslintrc.local.* +!**/.gitignore +!/docs/ +!/tap-snapshots/ +!/test/ +!/map.js +!/scripts/ +!/README* +!/LICENSE* +!/CHANGELOG* +!/.commitlintrc.js +!/.eslintrc.js +!/.github/ +!/.gitignore +!/.npmrc +!/SECURITY.md +!/bin/ +!/lib/ +!/package.json + +.npmrc +======================================== +; This file is automatically added by @npmcli/template-oss. Do not edit. + +package-lock=false +` diff --git a/tap-snapshots/test/check/gitignore.js.test.cjs b/tap-snapshots/test/check/gitignore.js.test.cjs index 89e415f5..4cbbbf2c 100644 --- a/tap-snapshots/test/check/gitignore.js.test.cjs +++ b/tap-snapshots/test/check/gitignore.js.test.cjs @@ -13,6 +13,7 @@ Some problems were detected: The following files are tracked by git but matching a pattern in .gitignore: ignorethis + package-lock.json To correct it: move files to not match one of the following patterns: diff --git a/test/apply/lockfile.js b/test/apply/lockfile.js index 3ffeba99..53cb800c 100644 --- a/test/apply/lockfile.js +++ b/test/apply/lockfile.js @@ -1,6 +1,12 @@ const t = require('tap') const setup = require('../setup.js') +t.cleanSnapshot = setup.clean +t.formatSnapshot = (obj) => setup.format.readdirSource({ + '.gitignore': obj['.gitignore'], + '.npmrc': obj['.npmrc'], +}) + t.test('lockfile', async (t) => { const s = await setup(t, { package: { @@ -15,6 +21,8 @@ t.test('lockfile', async (t) => { const npmrc = await s.readFile('.npmrc') t.ok(npmrc.includes('package-lock=true')) + + await t.resolveMatchSnapshot(s.readdirSource()) }) t.test('no lockfile by default', async (t) => { @@ -25,4 +33,6 @@ t.test('no lockfile by default', async (t) => { const npmrc = await s.readFile('.npmrc') t.ok(npmrc.includes('package-lock=false')) + + await t.resolveMatchSnapshot(s.readdirSource()) }) diff --git a/test/check/gitignore.js b/test/check/gitignore.js index bd5f249d..113be47a 100644 --- a/test/check/gitignore.js +++ b/test/check/gitignore.js @@ -9,6 +9,7 @@ t.test('will report tracked files in gitignore', async (t) => { const s = await setup.git(t, { ok: true }) await s.writeFile('ignorethis', 'empty') + await s.writeFile('package-lock.json', '{}') await s.gca() await s.apply() @@ -63,3 +64,20 @@ t.test('works with workspaces in separate dirs', async (t) => { await s.apply() await t.resolveMatchSnapshot(s.check()) }) + +t.test('allow package-lock', async (t) => { + const s = await setup.git(t, { + ok: true, + package: { + templateOSS: { + lockfile: true, + }, + }, + }) + + await s.writeFile('package-lock.json', '{}') + + await s.gca() + await s.apply() + t.strictSame(await s.check(), []) +}) From 124406e9cad0e54b053e95ea15f260dabb85be10 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 15 Apr 2022 22:33:52 +0000 Subject: [PATCH 7/7] chore(main): release 3.4.1 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e478e07..a6d7c65e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### [3.4.1](https://github.com/npm/template-oss/compare/v3.4.0...v3.4.1) (2022-04-15) + + +### Bug Fixes + +* properly allow package-lock when lockfile=true ([c613429](https://github.com/npm/template-oss/commit/c613429d2b46d94561aa20a8d39ca969a30f4391)) + ## [3.4.0](https://github.com/npm/template-oss/compare/v3.3.2...v3.4.0) (2022-04-15) diff --git a/package.json b/package.json index 6a338bfc..99dab9ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/template-oss", - "version": "3.4.0", + "version": "3.4.1", "description": "templated files used in npm CLI team oss projects", "main": "lib/content/index.js", "bin": {