Skip to content

Commit c613429

Browse files
committed
fix: properly allow package-lock when lockfile=true
1 parent 996e0c5 commit c613429

File tree

5 files changed

+111
-3
lines changed

5 files changed

+111
-3
lines changed

lib/content/gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
!/README*
1313
!/LICENSE*
1414
!/CHANGELOG*
15-
{{#if lockfile}}
16-
package-lock.json
17-
{{/if}}
1815
{{#each ignorePaths}}
1916
{{.}}
2017
{{/each}}
18+
{{#if lockfile}}
19+
!/package-lock.json
20+
{{/if}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* IMPORTANT
2+
* This snapshot file is auto-generated, but designed for humans.
3+
* It should be checked into source control and tracked carefully.
4+
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
5+
* Make sure to inspect the output below. Do not ignore changes!
6+
*/
7+
'use strict'
8+
exports[`test/apply/lockfile.js TAP lockfile > expect resolving Promise 1`] = `
9+
.gitignore
10+
========================================
11+
# This file is automatically added by @npmcli/template-oss. Do not edit.
12+
13+
# ignore everything in the root
14+
/*
15+
16+
# keep these
17+
!/.eslintrc.local.*
18+
!**/.gitignore
19+
!/docs/
20+
!/tap-snapshots/
21+
!/test/
22+
!/map.js
23+
!/scripts/
24+
!/README*
25+
!/LICENSE*
26+
!/CHANGELOG*
27+
!/.commitlintrc.js
28+
!/.eslintrc.js
29+
!/.github/
30+
!/.gitignore
31+
!/.npmrc
32+
!/SECURITY.md
33+
!/bin/
34+
!/lib/
35+
!/package.json
36+
!/package-lock.json
37+
38+
.npmrc
39+
========================================
40+
; This file is automatically added by @npmcli/template-oss. Do not edit.
41+
42+
package-lock=true
43+
`
44+
45+
exports[`test/apply/lockfile.js TAP no lockfile by default > expect resolving Promise 1`] = `
46+
.gitignore
47+
========================================
48+
# This file is automatically added by @npmcli/template-oss. Do not edit.
49+
50+
# ignore everything in the root
51+
/*
52+
53+
# keep these
54+
!/.eslintrc.local.*
55+
!**/.gitignore
56+
!/docs/
57+
!/tap-snapshots/
58+
!/test/
59+
!/map.js
60+
!/scripts/
61+
!/README*
62+
!/LICENSE*
63+
!/CHANGELOG*
64+
!/.commitlintrc.js
65+
!/.eslintrc.js
66+
!/.github/
67+
!/.gitignore
68+
!/.npmrc
69+
!/SECURITY.md
70+
!/bin/
71+
!/lib/
72+
!/package.json
73+
74+
.npmrc
75+
========================================
76+
; This file is automatically added by @npmcli/template-oss. Do not edit.
77+
78+
package-lock=false
79+
`

tap-snapshots/test/check/gitignore.js.test.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Some problems were detected:
1313
The following files are tracked by git but matching a pattern in .gitignore:
1414
1515
ignorethis
16+
package-lock.json
1617
1718
To correct it: move files to not match one of the following patterns:
1819

test/apply/lockfile.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
const t = require('tap')
22
const setup = require('../setup.js')
33

4+
t.cleanSnapshot = setup.clean
5+
t.formatSnapshot = (obj) => setup.format.readdirSource({
6+
'.gitignore': obj['.gitignore'],
7+
'.npmrc': obj['.npmrc'],
8+
})
9+
410
t.test('lockfile', async (t) => {
511
const s = await setup(t, {
612
package: {
@@ -15,6 +21,8 @@ t.test('lockfile', async (t) => {
1521

1622
const npmrc = await s.readFile('.npmrc')
1723
t.ok(npmrc.includes('package-lock=true'))
24+
25+
await t.resolveMatchSnapshot(s.readdirSource())
1826
})
1927

2028
t.test('no lockfile by default', async (t) => {
@@ -25,4 +33,6 @@ t.test('no lockfile by default', async (t) => {
2533

2634
const npmrc = await s.readFile('.npmrc')
2735
t.ok(npmrc.includes('package-lock=false'))
36+
37+
await t.resolveMatchSnapshot(s.readdirSource())
2838
})

test/check/gitignore.js

+18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ t.test('will report tracked files in gitignore', async (t) => {
99
const s = await setup.git(t, { ok: true })
1010

1111
await s.writeFile('ignorethis', 'empty')
12+
await s.writeFile('package-lock.json', '{}')
1213

1314
await s.gca()
1415
await s.apply()
@@ -63,3 +64,20 @@ t.test('works with workspaces in separate dirs', async (t) => {
6364
await s.apply()
6465
await t.resolveMatchSnapshot(s.check())
6566
})
67+
68+
t.test('allow package-lock', async (t) => {
69+
const s = await setup.git(t, {
70+
ok: true,
71+
package: {
72+
templateOSS: {
73+
lockfile: true,
74+
},
75+
},
76+
})
77+
78+
await s.writeFile('package-lock.json', '{}')
79+
80+
await s.gca()
81+
await s.apply()
82+
t.strictSame(await s.check(), [])
83+
})

0 commit comments

Comments
 (0)