Skip to content

Commit

Permalink
fix: dont write release please file for private workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Mar 29, 2022
1 parent a1e3c57 commit 15c19c1
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const getConfig = async ({
pkgName: pkg.name,
pkgNameFs: pkg.name.replace(/\//g, '-').replace(/@/g, ''),
pkgRelPath: pkgRelPath,
pkgPrivate: !!pkg.private,
// booleans to control application of updates
isForce,
isDogFood,
Expand Down
5 changes: 4 additions & 1 deletion lib/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const rootModule = {
// Changes for each workspace but applied to the root of the repo
const workspaceRepo = {
add: {
'.github/workflows/release-please-{{pkgNameFs}}.yml': 'release-please.yml',
'.github/workflows/release-please-{{pkgNameFs}}.yml': {
file: 'release-please.yml',
filter: (o) => !o.pkg.private,
},
'.github/workflows/ci-{{pkgNameFs}}.yml': 'ci.yml',
},
}
Expand Down
4 changes: 4 additions & 0 deletions lib/content/pkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"preversion": "npm test",
{{#if pkgPrivate}}
"postversion": "git push origin --follow-tags",
{{else}}
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
{{/if}}
"snap": "tap",
"test": "tap",
"posttest": "npm run lint",
Expand Down
19 changes: 16 additions & 3 deletions lib/util/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ const fullTarget = (dir, file, options) => join(dir, template(file, options))

// given an obj of files, return the full target/source paths and associated parser
const getParsers = (dir, files, options) => Object.entries(files).map(([t, s]) => {
let { file, parser: fileParser } = typeof s === 'string' ? { file: s } : s
const target = fullTarget(dir, t, options)
let {
file,
parser: fileParser,
filter,
} = typeof s === 'string' ? { file: s } : s

file = join(options.config.sourceDir, file)
const target = fullTarget(dir, t, options)

if (typeof filter === 'function' && !filter(options)) {
return null
}

if (fileParser) {
// allow files to extend base parsers or create new ones
return new (fileParser(Parser.Parsers))(target, file, options)
}

return new (Parser(file))(target, file, options)
})

Expand All @@ -32,7 +43,9 @@ const rmEach = async (dir, files, options, fn) => {
const parseEach = async (dir, files, options, fn) => {
const res = []
for (const parser of getParsers(dir, files, options)) {
res.push(await fn(parser))
if (parser) {
res.push(await fn(parser))
}
}
return res.filter(Boolean)
}
Expand Down
29 changes: 29 additions & 0 deletions test/apply/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const t = require('tap')
const fs = require('fs')
const { join } = require('path')
const setup = require('../setup.js')

t.cleanSnapshot = setup.clean
Expand Down Expand Up @@ -71,3 +73,30 @@ t.test('workspaces', async (t) => {
await s.apply()
await t.resolveMatchSnapshot(s.readdir())
})

t.test('private workspace', async (t) => {
const s = await setup(t, {
package: {},
workspaces: {
a: { private: true },
b: {},
},
})
await s.apply()

const pkg = await s.readJson(join('workspaces', 'b', 'package.json'))
const privatePkg = await s.readJson(join('workspaces', 'a', 'package.json'))

t.ok(pkg.scripts.prepublishOnly)
t.ok(pkg.scripts.postversion)

t.notOk(privatePkg.scripts.prepublishOnly)
t.ok(privatePkg.scripts.postversion)

t.equal(pkg.scripts.prepublishOnly, privatePkg.scripts.postversion)

const rp = s.join('.github', 'workflows')
t.ok(fs.existsSync(join(rp, 'release-please.yml')))
t.ok(fs.existsSync(join(rp, 'release-please-b.yml')))
t.notOk(fs.existsSync(join(rp, 'release-please-a.yml')))
})

0 comments on commit 15c19c1

Please sign in to comment.