Skip to content

Commit

Permalink
fix(builder): add --access public when publishing public packages, al…
Browse files Browse the repository at this point in the history
…low ignoring errors in spawned processes
  • Loading branch information
Daniel Schaffer committed Jun 9, 2019
1 parent 31fa0fd commit 9db2b45
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions builder/src/builder-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface Package {
peerDependencies?: DependencyMap
devDependencies?: DependencyMap
license?: any
private?: boolean
}

export const BUILDER_PROJECT_DEFAULTS: BuilderProjectOptions = {
Expand Down
7 changes: 5 additions & 2 deletions builder/src/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class Publisher {
if (registry) {
infoArgs.push('--registry', registry)
}
let packageInfo = await this.util.spawn('npm', infoArgs)
let packageInfo = await this.util.spawn('npm', infoArgs, undefined, true)
if (packageInfo) {
this.logger.warn(`${publishTarget}: skipping publish, already exists`, packageInfo.trim())
return packageInfo
Expand All @@ -102,14 +102,17 @@ export class Publisher {
if (registry) {
infoArgs.push('--registry', registry)
}
if (!packageInfo && !info.packageConfig.private) {
publishArgs.push('--access', 'public')
}
await this.util.spawn('npm', publishArgs, {
cwd: info.outPath,
})
this.logger.debug(`${publishTarget}: publish complete`)

while(!packageInfo) {
this.logger.debug(`${publishTarget}: waiting for package to become available...`)
packageInfo = await this.util.spawn('npm', infoArgs)
packageInfo = await this.util.spawn('npm', infoArgs, undefined, true)
}
this.logger.debug(`${publishTarget}: done.`)
}
Expand Down
13 changes: 11 additions & 2 deletions builder/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Util {
})
}

public spawn(command: string, args?: string[], options?: SpawnOptions): Promise<string> {
public spawn(command: string, args?: string[], options?: SpawnOptions, ignoreErrors: boolean = false): Promise<string> {
return new Promise<string>((resolve, reject) => {
options = Object.assign(options || {}, {
env: process.env,
Expand All @@ -57,7 +57,16 @@ export class Util {
let error: string = ''
cmd.stdout.on('data', chunk => output += chunk)
cmd.stderr.on('data', chunk => error += chunk)
cmd.on('close', code => code === 0 ? resolve(output) : reject(new Error(output + error)))
cmd.on('close', code => {
if (code === 0 || ignoreErrors) {
if (error) {
this.logger.debug('Ignored error:', error)
}
resolve(error ? undefined : output)
} else {
reject(new Error(output + error))
}
})
})
}

Expand Down

0 comments on commit 9db2b45

Please sign in to comment.