Skip to content

Commit

Permalink
feat: allow adding latest to other ci versions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Jul 5, 2023
1 parent b83a19a commit 6e02268
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@ const getFullConfig = async ({

if (pkgConfig.ciVersions) {
let versions = pkgConfig.ciVersions
if (versions === 'latest') {
const defaultVersions = [rootPkgConfig, defaultConfig].find(c => Array.isArray(c.ciVersions))
versions = defaultVersions.ciVersions.slice(-1)
if (versions === 'latest' || (Array.isArray(versions) && versions.includes('latest'))) {
const { ciVersions } = [isWorkspace ? rootPkgConfig : {}, defaultConfig]
.find(c => Array.isArray(c.ciVersions))
const defaultLatest = ciVersions[ciVersions.length - 1]
versions = [].concat(versions).map(v => v === 'latest' ? defaultLatest : v)
}

const { targets, engines } = parseCIVersions(versions)
Expand Down
20 changes: 20 additions & 0 deletions test/apply/engines.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ t.test('can set engines and ci separately', async (t) => {
t.notOk(ci.includes('- 12'))
})

t.test('can set ci to latest plus other versions', async (t) => {
const s = await setup(t, {
package: {
templateOSS: {
ciVersions: ['6', '8', 'latest'],
engines: '*',
},
},
})
await s.apply()

const pkg = await s.readJson('package.json')
const ci = await s.readFile(join('.github', 'workflows', 'ci.yml'))

t.equal(pkg.engines.node, '*')
t.ok(ci.includes('- 6'))
t.ok(ci.includes('- 8'))
t.ok(ci.includes('- 18.x'))
})

t.test('latest ci versions', async (t) => {
const s = await setup(t, {
package: {
Expand Down

0 comments on commit 6e02268

Please sign in to comment.