@@ -19,8 +19,8 @@ function getRegistryAPIUrl(packageName: string, version: string) {
1919 return `https://registry.npmjs.org/${ packageName } /${ version } `
2020}
2121
22- async function getLatestVersion ( packageName : string ) {
23- const url = getRegistryAPIUrl ( packageName , 'latest' )
22+ async function getVersionByTag ( packageName : string , tag : string ) {
23+ const url = getRegistryAPIUrl ( packageName , tag )
2424 const response = await fetch ( url )
2525 if ( response . status === 404 ) {
2626 spinner . fail ( `Package not found: ${ packageName } ` )
@@ -42,8 +42,12 @@ function getTarballUrl(packageName: string, version: string) {
4242 return `https://registry.npmjs.org/${ packageName } /-/${ packageName } -${ version } .tgz`
4343}
4444
45- function getPackageNameForTemplate ( template : string ) {
46- return `@graphql-yoga/template-${ template } `
45+ function getPackageNameAndTagForTemplate ( template : string ) {
46+ const [ suffix , tag ] = template . split ( '@' )
47+ return {
48+ packageName : `@graphql-yoga/template-${ suffix } ` ,
49+ tag : tag ?? 'latest' ,
50+ }
4751}
4852
4953export async function createGraphQLYoga ( fullArgs : string [ ] = process . argv ) {
@@ -55,8 +59,8 @@ export async function createGraphQLYoga(fullArgs: string[] = process.argv) {
5559 values : { template = 'node-ts' } ,
5660 } = parseArgs ( { args, options, allowPositionals : true } )
5761 spinner . start ( `Fetching template ${ template } ...` )
58- const packageName = getPackageNameForTemplate ( template )
59- const version = await getLatestVersion ( packageName )
62+ const { packageName, tag } = getPackageNameAndTagForTemplate ( template )
63+ const version = await getVersionByTag ( packageName , tag )
6064 const url = getTarballUrl ( packageName , version )
6165 const response = await fetch ( url )
6266 if ( response . status === 404 ) {
0 commit comments