Skip to content

Commit 15c19c1

Browse files
committed
fix: dont write release please file for private workspace
1 parent a1e3c57 commit 15c19c1

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

lib/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const getConfig = async ({
112112
pkgName: pkg.name,
113113
pkgNameFs: pkg.name.replace(/\//g, '-').replace(/@/g, ''),
114114
pkgRelPath: pkgRelPath,
115+
pkgPrivate: !!pkg.private,
115116
// booleans to control application of updates
116117
isForce,
117118
isDogFood,

lib/content/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ const rootModule = {
3838
// Changes for each workspace but applied to the root of the repo
3939
const workspaceRepo = {
4040
add: {
41-
'.github/workflows/release-please-{{pkgNameFs}}.yml': 'release-please.yml',
41+
'.github/workflows/release-please-{{pkgNameFs}}.yml': {
42+
file: 'release-please.yml',
43+
filter: (o) => !o.pkg.private,
44+
},
4245
'.github/workflows/ci-{{pkgNameFs}}.yml': 'ci.yml',
4346
},
4447
}

lib/content/pkg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
"template-oss-apply": "template-oss-apply --force",
88
"lintfix": "npm run lint -- --fix",
99
"preversion": "npm test",
10+
{{#if pkgPrivate}}
11+
"postversion": "git push origin --follow-tags",
12+
{{else}}
1013
"postversion": "npm publish",
1114
"prepublishOnly": "git push origin --follow-tags",
15+
{{/if}}
1216
"snap": "tap",
1317
"test": "tap",
1418
"posttest": "npm run lint",

lib/util/files.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@ const fullTarget = (dir, file, options) => join(dir, template(file, options))
99

1010
// given an obj of files, return the full target/source paths and associated parser
1111
const getParsers = (dir, files, options) => Object.entries(files).map(([t, s]) => {
12-
let { file, parser: fileParser } = typeof s === 'string' ? { file: s } : s
13-
const target = fullTarget(dir, t, options)
12+
let {
13+
file,
14+
parser: fileParser,
15+
filter,
16+
} = typeof s === 'string' ? { file: s } : s
17+
1418
file = join(options.config.sourceDir, file)
19+
const target = fullTarget(dir, t, options)
20+
21+
if (typeof filter === 'function' && !filter(options)) {
22+
return null
23+
}
24+
1525
if (fileParser) {
1626
// allow files to extend base parsers or create new ones
1727
return new (fileParser(Parser.Parsers))(target, file, options)
1828
}
29+
1930
return new (Parser(file))(target, file, options)
2031
})
2132

@@ -32,7 +43,9 @@ const rmEach = async (dir, files, options, fn) => {
3243
const parseEach = async (dir, files, options, fn) => {
3344
const res = []
3445
for (const parser of getParsers(dir, files, options)) {
35-
res.push(await fn(parser))
46+
if (parser) {
47+
res.push(await fn(parser))
48+
}
3649
}
3750
return res.filter(Boolean)
3851
}

test/apply/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const t = require('tap')
2+
const fs = require('fs')
3+
const { join } = require('path')
24
const setup = require('../setup.js')
35

46
t.cleanSnapshot = setup.clean
@@ -71,3 +73,30 @@ t.test('workspaces', async (t) => {
7173
await s.apply()
7274
await t.resolveMatchSnapshot(s.readdir())
7375
})
76+
77+
t.test('private workspace', async (t) => {
78+
const s = await setup(t, {
79+
package: {},
80+
workspaces: {
81+
a: { private: true },
82+
b: {},
83+
},
84+
})
85+
await s.apply()
86+
87+
const pkg = await s.readJson(join('workspaces', 'b', 'package.json'))
88+
const privatePkg = await s.readJson(join('workspaces', 'a', 'package.json'))
89+
90+
t.ok(pkg.scripts.prepublishOnly)
91+
t.ok(pkg.scripts.postversion)
92+
93+
t.notOk(privatePkg.scripts.prepublishOnly)
94+
t.ok(privatePkg.scripts.postversion)
95+
96+
t.equal(pkg.scripts.prepublishOnly, privatePkg.scripts.postversion)
97+
98+
const rp = s.join('.github', 'workflows')
99+
t.ok(fs.existsSync(join(rp, 'release-please.yml')))
100+
t.ok(fs.existsSync(join(rp, 'release-please-b.yml')))
101+
t.notOk(fs.existsSync(join(rp, 'release-please-a.yml')))
102+
})

0 commit comments

Comments
 (0)