11#! /usr/bin/env node
22const { execSync } = require ( "child_process" ) ;
33const { writeFileSync, readFileSync } = require ( "fs" ) ;
4- const { join } = require ( "path" ) ;
4+ const { join, basename } = require ( "path" ) ;
55
6- const [ , packageFromRef , versionFromRef ] = / ^ r e f s \/ t a g s \/ ( .+ ) \@ ( [ ^ \@ ] + ) $ / . exec ( process . env . GITHUB_REF ?? "" ) ?? [ ] ;
6+ const [ , packageFromRef , versionFromRef ] = / ^ r e f s \/ t a g s \/ ( .+ ) - v ( \d * \. \d ( \. \d ) ? ( - . + ) ? ) $ / . exec ( process . env . GITHUB_REF ?? "" ) ?? [ ] ;
77const ref = process . env . GITHUB_SHA ?? "HEAD" ;
88const shortSHA = execSync ( `git rev-parse --short ${ ref } ` ) . toString ( ) . trim ( ) ;
99
1010const lernaList = JSON . parse ( execSync ( `lerna list --json ${ packageFromRef ? '' : '--since' } ` ) . toString ( ) ) ;
11- if ( packageFromRef && ! lernaList . find ( it => it . name === packageFromRef ) ) {
11+ if ( packageFromRef && ! lernaList . find ( it => basename ( it . location ) === packageFromRef ) ) {
1212 throw `Lerna didn't find ${ packageFromRef } in this workspace` ;
1313}
1414
@@ -24,13 +24,13 @@ wombatDressingRoomTokens.forEach((token, pkg) => {
2424
2525for ( const lerna of lernaList ) {
2626 if ( lerna . private ) continue ;
27- if ( packageFromRef && packageFromRef !== lerna . name ) continue ;
27+ if ( packageFromRef && packageFromRef !== basename ( lerna . location ) ) continue ;
2828 if ( versionFromRef && versionFromRef . split ( '-' ) [ 0 ] !== lerna . version ) {
2929 throw `Cowardly refusing to publish ${ lerna . name } @${ versionFromRef } from ${ lerna . version } , version needs to be bumped in source.` ;
3030 }
3131 const version = versionFromRef || `${ lerna . version } -canary.${ shortSHA } ` ;
3232 const cwd = lerna . location ;
33- const tag = packageFromRef ? ( version . includes ( '-' ) ? 'next' : 'latest' ) : 'canary' ;
33+ const tag = versionFromRef ? ( version . includes ( '-' ) ? 'next' : 'latest' ) : 'canary' ;
3434 const packageJsonPath = join ( lerna . location , 'package.json' ) ;
3535 const packageJson = JSON . parse ( readFileSync ( packageJsonPath ) . toString ( ) ) ;
3636 packageJson . version = version ;
0 commit comments