Skip to content

Commit

Permalink
fix: dont cache yarn bin on class
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 23, 2023
1 parent f68c98c commit e803fe1
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import makeDebug from 'debug'
import {fork} from 'node:child_process'
import {createRequire} from 'node:module'
import {join} from 'node:path'
import {fileURLToPath} from 'node:url'
import NpmRunPath from 'npm-run-path'

import {WarningsCache} from './util.js'
Expand All @@ -20,16 +19,15 @@ type YarnExecOptions = {
}

export default class Yarn {
private bin: string
private config: Interfaces.Config

constructor({config}: {config: Interfaces.Config}) {
this.config = config
this.bin = require.resolve('yarn/bin/yarn.js', {paths: [fileURLToPath(import.meta.url), config.root]})
debug('yarn binary path', this.bin)
}

async exec(args: string[] = [], opts: YarnExecOptions): Promise<void> {
const bin = require.resolve('yarn/bin/yarn.js')
debug('yarn binary path', bin)
const {cwd, silent, verbose} = opts
if (args[0] !== 'run') {
// https://classic.yarnpkg.com/lang/en/docs/cli/#toc-concurrency-and-mutex
Expand Down Expand Up @@ -68,12 +66,12 @@ export default class Yarn {
}

if (verbose) {
process.stderr.write(`${cwd}: ${this.bin} ${args.join(' ')}`)
process.stderr.write(`${cwd}: ${bin} ${args.join(' ')}`)
}

debug(`${cwd}: ${this.bin} ${args.join(' ')}`)
debug(`${cwd}: ${bin} ${args.join(' ')}`)
try {
await this.fork(this.bin, args, options)
await this.fork(bin, args, options)
debug('yarn done')
} catch (error: unknown) {
const {message} = error as Error & {message: string}
Expand Down

0 comments on commit e803fe1

Please sign in to comment.