Skip to content

Commit 8d8defe

Browse files
committed
refactor: refactor release
1 parent 795aa1f commit 8d8defe

3 files changed

Lines changed: 25 additions & 28 deletions

File tree

.github/.github/workflows/publish.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/package.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,22 @@ export default class Package {
362362
this.#clearCache();
363363
}
364364

365-
async publishNpm ( latestTag, nextTag ) {
366-
if ( !this.name || this.isPrivate ) return;
365+
async publishNpm () {
366+
if ( this.isPrivate ) return result( 200 );
367+
368+
if ( !this.name ) return result( 200 );
367369

368370
this.#clearCache();
369371

370372
var res;
371373

374+
res = await this.git.getCommit();
375+
if ( !res.ok ) return res;
376+
377+
const tags = [];
378+
if ( res.data.tags.has( "latest" ) ) tags.push( "latest" );
379+
if ( res.data.tags.has( "next" ) ) tags.push( "next" );
380+
372381
// pack package
373382
res = await repeatAction( async () => {
374383
const tmpDir = new TmpDir(),
@@ -426,11 +435,13 @@ export default class Package {
426435
const pack = res.data.pack;
427436

428437
// publish npm package
429-
const addTags = [ latestTag, nextTag ].filter( tag => tag ).map( tag => `"${ tag }"` ),
430-
args = [ "npm", "publish", "--access", "public" ];
438+
// XXX
439+
const access = "public"; // "restricted"
440+
441+
const args = [ "npm", "publish", "--access", access ];
431442

432-
if ( addTags.length ) {
433-
args.push( "--tag", addTags.shift() );
443+
if ( tags.length ) {
444+
args.push( "--tag", tags.shift() );
434445
}
435446

436447
args.push( pack.path );
@@ -459,8 +470,8 @@ export default class Package {
459470
if ( !res.ok ) return res;
460471

461472
// add additional tags
462-
if ( addTags.length ) {
463-
for ( const tag of addTags ) {
473+
if ( tags.length ) {
474+
for ( const tag of tags ) {
464475
const command = shellQuote( [ "npm", "dist-tag", "add", `${ this.name }@${ this.version }`, tag ] );
465476

466477
res = await repeatAction( async () => {

lib/package/release.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,15 @@ export default class Publish {
262262
}
263263

264264
// publish root package
265-
await this.#pkg.publishNpm( this.#latestTag, this.#nextTag );
265+
res = await this.#pkg.publishNpm();
266+
if ( !res.ok ) return res;
266267

267268
// publish sub-packages
268269
for ( const pkg of subPackages ) {
269-
if ( !pkg.isPrivate ) await pkg.publishNpm( this.#latestTag, this.#nextTag );
270+
if ( pkg.isPrivate ) continue;
271+
272+
res = await pkg.publishNpm();
273+
if ( !res.ok ) return res;
270274
}
271275

272276
return result( 200 );

0 commit comments

Comments
 (0)