Skip to content

Commit bd187c7

Browse files
committed
feat: Use oclif template config for manifest URLs
Debatable whether this is a feature or a fix, since it used to work, but it's been such a long time since it did that it's effectively totally new.
1 parent e586190 commit bd187c7

2 files changed

Lines changed: 89 additions & 15 deletions

File tree

src/update.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,14 @@ const setChannel = async (channel: string, dataDir: string): Promise<void> =>
375375
writeFile(join(dataDir, 'channel'), channel, 'utf8')
376376

377377
const fetchChannelManifest = async (channel: string, config: Config): Promise<Interfaces.S3Manifest> => {
378-
const s3Key = s3ChannelManifestKey(channel, config)
378+
const hasCustomTemplates = Boolean(config.pjson.oclif?.update?.s3?.templates)
379+
const s3Key = hasCustomTemplates
380+
? config.s3Key('manifest', {
381+
arch: config.arch,
382+
channel,
383+
platform: determinePlatform(config),
384+
})
385+
: s3ChannelManifestKey(channel, config)
379386
try {
380387
return await fetchManifest(s3Key, config)
381388
} catch (error: unknown) {

test/update.test.ts

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,8 @@ describe('update plugin', () => {
7474

7575
it('should not update - already on same version', async () => {
7676
clientRoot = await setupClientRoot({config}, '2.0.0')
77-
const platformRegex = new RegExp(`tarballs\\/example-cli\\/${config.platform}-${config.arch}`)
78-
const manifestRegex = new RegExp(`channels\\/stable\\/example-cli-${config.platform}-${config.arch}-buildmanifest`)
77+
const manifestRegex = new RegExp(`tarballs\\/example-cli\\/${config.platform}-${config.arch}`)
7978
nock(/oclif-staging.s3.amazonaws.com/)
80-
.get(platformRegex)
81-
.reply(200, {version: '2.0.0'})
8279
.get(manifestRegex)
8380
.reply(200, {version: '2.0.0'})
8481

@@ -90,8 +87,7 @@ describe('update plugin', () => {
9087

9188
it('should update to channel', async () => {
9289
clientRoot = await setupClientRoot({config})
93-
const platformRegex = new RegExp(`tarballs\\/example-cli\\/${config.platform}-${config.arch}`)
94-
const manifestRegex = new RegExp(`channels\\/stable\\/example-cli-${config.platform}-${config.arch}-buildmanifest`)
90+
const manifestRegex = new RegExp(`tarballs\\/example-cli\\/${config.platform}-${config.arch}`)
9591
const tarballRegex = new RegExp(
9692
`tarballs\\/example-cli\\/example-cli-v2.0.1\\/example-cli-v2.0.1-${config.platform}-${config.arch}gz`,
9793
)
@@ -104,8 +100,6 @@ describe('update plugin', () => {
104100
const gzContents = zlib.gzipSync(' ')
105101

106102
nock(/oclif-staging.s3.amazonaws.com/)
107-
.get(platformRegex)
108-
.reply(200, {version: '2.0.1'})
109103
.get(manifestRegex)
110104
.reply(200, {version: '2.0.1'})
111105
.get(tarballRegex)
@@ -267,8 +261,6 @@ describe('update plugin', () => {
267261

268262
it('should update from local file', async () => {
269263
clientRoot = await setupClientRoot({config})
270-
const platformRegex = new RegExp(`tarballs\\/example-cli\\/${config.platform}-${config.arch}`)
271-
const manifestRegex = new RegExp(`channels\\/stable\\/example-cli-${config.platform}-${config.arch}-buildmanifest`)
272264
const tarballRegex = new RegExp(
273265
`tarballs\\/example-cli\\/example-cli-v2.0.0\\/example-cli-v2.0.1-${config.platform}-${config.arch}gz`,
274266
)
@@ -282,10 +274,6 @@ describe('update plugin', () => {
282274
const gzContents = zlib.gzipSync(' ')
283275

284276
nock(/oclif-staging.s3.amazonaws.com/)
285-
.get(platformRegex)
286-
.reply(200, {version: '2.0.1'})
287-
.get(manifestRegex)
288-
.reply(200, {version: '2.0.1'})
289277
.get(tarballRegex)
290278
.reply(200, gzContents, {
291279
'Content-Encoding': 'gzip',
@@ -298,4 +286,83 @@ describe('update plugin', () => {
298286
const stdout = stripAnsi(collector.stdout.join(' '))
299287
expect(stdout).to.matches(/Updating to a specific version will not update the channel/)
300288
})
289+
290+
describe('custom S3 templates', () => {
291+
it('should use config.s3Key() for manifest URL when custom templates are configured', async () => {
292+
clientRoot = await setupClientRoot({config}, '2.0.0')
293+
// The example config has custom S3 templates with target.manifest:
294+
// "tarballs/<%- bin %>/<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- platform %>-<%- arch %>"
295+
// For channel=stable, this produces: tarballs/example-cli/{platform}-{arch}
296+
const customManifestRegex = new RegExp(`tarballs\\/example-cli\\/${config.platform}-${config.arch}$`)
297+
// Verify the hardcoded format is NOT used
298+
const hardcodedManifestRegex = new RegExp(
299+
`channels\\/stable\\/example-cli-${config.platform}-${config.arch}-buildmanifest`,
300+
)
301+
const interceptedPaths: string[] = []
302+
303+
nock(/oclif-staging.s3.amazonaws.com/)
304+
.get(customManifestRegex)
305+
.reply(function () {
306+
interceptedPaths.push(this.req.path)
307+
return [200, {version: '2.0.0'}]
308+
})
309+
310+
updater = initUpdater(config)
311+
await updater.runUpdate({autoUpdate: false})
312+
313+
expect(interceptedPaths).to.have.lengthOf(1)
314+
expect(interceptedPaths[0]).to.match(customManifestRegex)
315+
expect(interceptedPaths[0]).to.not.match(hardcodedManifestRegex)
316+
})
317+
318+
it('should use hardcoded manifest key when no custom templates are configured', async () => {
319+
// Remove custom templates from the config
320+
const originalTemplates = config.pjson.oclif.update!.s3!.templates
321+
delete (config.pjson.oclif.update!.s3 as Record<string, unknown>).templates
322+
323+
clientRoot = await setupClientRoot({config}, '2.0.0')
324+
const hardcodedManifestRegex = new RegExp(
325+
`channels\\/stable\\/example-cli-${config.platform}-${config.arch}-buildmanifest`,
326+
)
327+
const interceptedPaths: string[] = []
328+
329+
nock(/oclif-staging.s3.amazonaws.com/)
330+
.get(hardcodedManifestRegex)
331+
.reply(function () {
332+
interceptedPaths.push(this.req.path)
333+
return [200, {version: '2.0.0'}]
334+
})
335+
336+
updater = initUpdater(config)
337+
await updater.runUpdate({autoUpdate: false})
338+
339+
expect(interceptedPaths).to.have.lengthOf(1)
340+
expect(interceptedPaths[0]).to.match(hardcodedManifestRegex)
341+
342+
// Restore templates
343+
config.pjson.oclif.update!.s3!.templates = originalTemplates
344+
})
345+
346+
it('should use custom template manifest URL for non-stable channels', async () => {
347+
clientRoot = await setupClientRoot({config}, '2.0.0')
348+
// For channel=beta, the template produces: tarballs/example-cli/channels/beta/{platform}-{arch}
349+
const betaManifestRegex = new RegExp(
350+
`tarballs\\/example-cli\\/channels\\/beta\\/${config.platform}-${config.arch}`,
351+
)
352+
const interceptedPaths: string[] = []
353+
354+
nock(/oclif-staging.s3.amazonaws.com/)
355+
.get(betaManifestRegex)
356+
.reply(function () {
357+
interceptedPaths.push(this.req.path)
358+
return [200, {version: '2.0.0'}]
359+
})
360+
361+
updater = initUpdater(config)
362+
await updater.runUpdate({autoUpdate: false, channel: 'beta'})
363+
364+
expect(interceptedPaths).to.have.lengthOf(1)
365+
expect(interceptedPaths[0]).to.match(betaManifestRegex)
366+
})
367+
})
301368
})

0 commit comments

Comments
 (0)