Skip to content

Commit

Permalink
fix: properly allow package-lock when lockfile=true
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Apr 15, 2022
1 parent 996e0c5 commit c613429
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/content/gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
!/README*
!/LICENSE*
!/CHANGELOG*
{{#if lockfile}}
package-lock.json
{{/if}}
{{#each ignorePaths}}
{{.}}
{{/each}}
{{#if lockfile}}
!/package-lock.json
{{/if}}
79 changes: 79 additions & 0 deletions tap-snapshots/test/apply/lockfile.js.test.cjs
Original file line number Diff line number Diff line change
@@ -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
`
1 change: 1 addition & 0 deletions tap-snapshots/test/check/gitignore.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions test/apply/lockfile.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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) => {
Expand All @@ -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())
})
18 changes: 18 additions & 0 deletions test/check/gitignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(), [])
})

0 comments on commit c613429

Please sign in to comment.