Skip to content

Commit 19542d3

Browse files
committed
--amend
1 parent 3779c8d commit 19542d3

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

lib/postinstall/update-package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const patchPackage = async (path, root, config) => {
4747
if (path === root && !config.applyRootModuleFiles) {
4848
// only update templateVersion if we're skipping root module files
4949
update = {
50-
templateVersion: TEMPLATE_VERSION
50+
templateVersion: TEMPLATE_VERSION,
5151
}
5252
} else {
5353
// we build a new object here so our exported set of changes is not modified

test/bin/npm-template-check.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,41 @@ t.test('with mocks', (t) => {
8181
t.strictSame(errors, [], 'errors')
8282
})
8383
})
84+
85+
t.test('workspace without root module files', async (t) => {
86+
const pkgWithWorkspaces = {
87+
'package.json': JSON.stringify({
88+
name: 'testpkg',
89+
templateOSS: {
90+
applyRootRepoFiles: false,
91+
applyWorkspaceRepoFiles: true,
92+
applyRootModuleFiles: false,
93+
94+
workspaces: ['amazinga'],
95+
},
96+
}),
97+
workspace: {
98+
a: {
99+
'package.json': JSON.stringify({
100+
name: 'amazinga',
101+
}),
102+
},
103+
},
104+
}
105+
const root = t.testdir(pkgWithWorkspaces)
106+
process.env.npm_config_local_prefix = root
107+
108+
await check({
109+
package: (path, root, config) => [{
110+
message: 'package',
111+
solution: `${path} ${root} ${config.applyRootModuleFiles}`,
112+
}],
113+
gitignore: (path, root, config) => [{
114+
message: 'gitignore',
115+
solution: `${path} ${root} ${config.applyRootRepoFiles}`,
116+
}],
117+
})
118+
119+
t.strictSame(logs, [], 'logs')
120+
t.strictSame(errors, [], 'errors')
121+
})

test/postinstall/update-package.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,38 @@ t.test('doesnt set templateVersion on own repo', async (t) => {
7676
})
7777
t.equal(JSON.parse(contents).templateVersion, undefined, 'did not get template version')
7878
})
79+
80+
t.test('only sets templateVersion on root pkg when configured', async (t) => {
81+
const pkgWithWorkspaces = {
82+
'package.json': JSON.stringify({
83+
name: 'testpkg',
84+
templateOSS: {
85+
applyRootRepoFiles: false,
86+
applyWorkspaceRepoFiles: true,
87+
applyRootModuleFiles: false,
88+
89+
workspaces: ['amazinga'],
90+
},
91+
}),
92+
workspace: {
93+
a: {
94+
'package.json': JSON.stringify({
95+
name: 'amazinga',
96+
}),
97+
},
98+
},
99+
}
100+
const root = t.testdir(pkgWithWorkspaces)
101+
await patchPackage(root, root, {
102+
applyRootRepoFiles: false,
103+
applyWorkspaceRepoFiles: true,
104+
applyRootModuleFiles: false,
105+
})
106+
107+
const contents = JSON.parse(await fs.readFile(join(root, 'package.json'), {
108+
encoding: 'utf8',
109+
}))
110+
111+
t.not(contents.templateVersion, undefined, 'should set templateVersion')
112+
t.equal(contents.author, undefined, 'should not set other fields')
113+
})

0 commit comments

Comments
 (0)