Skip to content

Commit

Permalink
--amend
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzy committed Dec 9, 2021
1 parent 3779c8d commit 19542d3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/postinstall/update-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const patchPackage = async (path, root, config) => {
if (path === root && !config.applyRootModuleFiles) {
// only update templateVersion if we're skipping root module files
update = {
templateVersion: TEMPLATE_VERSION
templateVersion: TEMPLATE_VERSION,
}
} else {
// we build a new object here so our exported set of changes is not modified
Expand Down
38 changes: 38 additions & 0 deletions test/bin/npm-template-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,41 @@ t.test('with mocks', (t) => {
t.strictSame(errors, [], 'errors')
})
})

t.test('workspace without root module files', async (t) => {
const pkgWithWorkspaces = {
'package.json': JSON.stringify({
name: 'testpkg',
templateOSS: {
applyRootRepoFiles: false,
applyWorkspaceRepoFiles: true,
applyRootModuleFiles: false,

workspaces: ['amazinga'],
},
}),
workspace: {
a: {
'package.json': JSON.stringify({
name: 'amazinga',
}),
},
},
}
const root = t.testdir(pkgWithWorkspaces)
process.env.npm_config_local_prefix = root

await check({
package: (path, root, config) => [{
message: 'package',
solution: `${path} ${root} ${config.applyRootModuleFiles}`,
}],
gitignore: (path, root, config) => [{
message: 'gitignore',
solution: `${path} ${root} ${config.applyRootRepoFiles}`,
}],
})

t.strictSame(logs, [], 'logs')
t.strictSame(errors, [], 'errors')
})
35 changes: 35 additions & 0 deletions test/postinstall/update-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,38 @@ t.test('doesnt set templateVersion on own repo', async (t) => {
})
t.equal(JSON.parse(contents).templateVersion, undefined, 'did not get template version')
})

t.test('only sets templateVersion on root pkg when configured', async (t) => {
const pkgWithWorkspaces = {
'package.json': JSON.stringify({
name: 'testpkg',
templateOSS: {
applyRootRepoFiles: false,
applyWorkspaceRepoFiles: true,
applyRootModuleFiles: false,

workspaces: ['amazinga'],
},
}),
workspace: {
a: {
'package.json': JSON.stringify({
name: 'amazinga',
}),
},
},
}
const root = t.testdir(pkgWithWorkspaces)
await patchPackage(root, root, {
applyRootRepoFiles: false,
applyWorkspaceRepoFiles: true,
applyRootModuleFiles: false,
})

const contents = JSON.parse(await fs.readFile(join(root, 'package.json'), {
encoding: 'utf8',
}))

t.not(contents.templateVersion, undefined, 'should set templateVersion')
t.equal(contents.author, undefined, 'should not set other fields')
})

0 comments on commit 19542d3

Please sign in to comment.