Skip to content

Commit 1649552

Browse files
committed
fix: only extend underscore partial files
1 parent 132a466 commit 1649552

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/util/template.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@ const partialName = (s) => basename(s, extname(s)) // remove extension
1010
.replace(/^_/, '') // remove leading underscore
1111
.replace(/-([a-z])/g, (_, g) => g.toUpperCase()) // camelcase
1212

13-
const makePartials = (dir, setDefault) => {
13+
const makePartials = (dir, isBase) => {
1414
const partials = fs.readdirSync(dir).reduce((acc, f) => {
1515
const partial = fs.readFileSync(join(dir, f)).toString()
1616
const name = partialName(f)
17-
acc[name] = partial
18-
if (setDefault && f.startsWith('_')) {
17+
18+
if (isBase) {
19+
// in the default dir, everything is a partial
20+
// and also gets set with a default prefix for extending
21+
acc[name] = partial
1922
acc[partialName(`default-${name}`)] = partial
23+
} else if (f.startsWith('_')) {
24+
// otherwise only _ files get set as partials
25+
acc[name] = partial
2026
}
27+
2128
return acc
2229
}, {})
2330

test/apply/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,25 @@ t.test('content can override partials', async (t) => {
219219
},
220220
testdir: {
221221
content_dir: {
222+
'index.js': `module.exports={
223+
rootRepo:{
224+
add:{'.github/workflows/ci-release.yml': 'ci-release.yml'}
225+
}
226+
}`,
227+
'ci-release.yml': '{{> ciRelease }}\n job: 1',
222228
'_step-deps.yml': '- run: INSTALL\n',
223229
'_step-test.yml': '- run: TEST\n{{> defaultStepTest }}\n',
224230
},
225231
},
226232
})
227233
await s.apply()
228234
const ci = await s.readFile(join('.github', 'workflows', 'ci.yml'))
235+
const release = await s.readFile(join('.github', 'workflows', 'ci-release.yml'))
229236
t.ok(ci.includes('- run: INSTALL'))
230237
t.ok(ci.includes('- run: TEST'))
231238
t.notOk(ci.includes('npm i --ignore-scripts --no-audit --no-fund'))
232239
t.ok(ci.includes('npm test --ignore-scripts'))
240+
t.ok(release.includes('job: 1'))
233241
})
234242

235243
t.test('content can extend files', async (t) => {

0 commit comments

Comments
 (0)