-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: fall back to global npm and yarn if not found #871
Changes from 4 commits
4f84a52
96f22e7
bafa6c1
2ebbe35
d508801
78881da
0f151dc
827256b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
import {Interfaces, ux} from '@oclif/core' | ||
import {Errors, Interfaces, ux} from '@oclif/core' | ||
import makeDebug from 'debug' | ||
import {createRequire} from 'node:module' | ||
import {fileURLToPath} from 'node:url' | ||
|
||
import {ExecOptions, Output, fork} from './fork.js' | ||
import {LogLevel} from './log-level.js' | ||
import {ExecOptions, Output, spawn} from './spawn.js' | ||
|
||
const require = createRequire(import.meta.url) | ||
const debug = makeDebug('@oclif/plugin-plugins:yarn') | ||
|
||
export class Yarn { | ||
private bin: string | undefined | ||
private config: Interfaces.Config | ||
private logLevel: LogLevel | ||
|
||
|
@@ -31,7 +32,7 @@ export class Yarn { | |
|
||
debug(`${options.cwd}: ${bin} ${args.join(' ')}`) | ||
try { | ||
const output = await fork(bin, args, options) | ||
const output = await spawn(bin, args, options) | ||
debug('yarn done') | ||
return output | ||
} catch (error: unknown) { | ||
|
@@ -45,6 +46,18 @@ export class Yarn { | |
} | ||
|
||
private async findYarn(): Promise<string> { | ||
return require.resolve('yarn/bin/yarn.js', {paths: [this.config.root, fileURLToPath(import.meta.url)]}) | ||
if (this.bin) return this.bin | ||
try { | ||
this.bin = require.resolve('yarn/bin/yarn.js', {paths: [this.config.root, fileURLToPath(import.meta.url)]}) | ||
} catch { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the different resolve logic for yarn? When I remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just pulled the logic in exactly as it was in the last major: https://github.com/oclif/plugin-plugins/blob/4.3.10/src/yarn.ts#L30 I can replicate the same logic that we use for npm... but I'm wondering if it's worth it if we one day hope to remove the "install dependencies after linking" logic altogether. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's fine since we'd like to get rid of this. I don't really see an issue with this, I was just curious if it was deliberate. |
||
const {default: which} = await import('which') | ||
this.bin = await which('yarn') | ||
} | ||
|
||
if (!this.bin) { | ||
throw new Errors.CLIError('yarn not found') | ||
} | ||
|
||
return this.bin | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1994,6 +1994,11 @@ | |
resolved "https://registry.npmjs.org/@types/validate-npm-package-name/-/validate-npm-package-name-4.0.2.tgz" | ||
integrity sha512-lrpDziQipxCEeK5kWxvljWYhUvOiB2A9izZd9B2AFarYAkqZshb4lPbRs7zKEic6eGtH8V/2qJW+dPp9OtF6bw== | ||
|
||
"@types/which@^3.0.3": | ||
version "3.0.3" | ||
resolved "https://registry.yarnpkg.com/@types/which/-/which-3.0.3.tgz#41142ed5a4743128f1bc0b69c46890f0453ddb89" | ||
integrity sha512-2C1+XoY0huExTbs8MQv1DuS5FS86+SEjdM9F/+GS61gg5Hqbtj8ZiDSx8MfWcyei907fIPbfPGCOrNUTnVHY1g== | ||
|
||
"@types/wrap-ansi@^3.0.0": | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz#18b97a972f94f60a679fd5c796d96421b9abb9fd" | ||
|
@@ -6417,16 +6422,7 @@ [email protected]: | |
resolved "https://registry.npmjs.org/string-argv/-/string-argv-0.3.2.tgz" | ||
integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q== | ||
|
||
"string-width-cjs@npm:string-width@^4.2.0": | ||
version "4.2.3" | ||
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" | ||
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== | ||
dependencies: | ||
emoji-regex "^8.0.0" | ||
is-fullwidth-code-point "^3.0.0" | ||
strip-ansi "^6.0.1" | ||
|
||
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: | ||
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: | ||
version "4.2.3" | ||
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" | ||
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== | ||
|
@@ -6487,14 +6483,7 @@ string_decoder@^1.1.1: | |
dependencies: | ||
safe-buffer "~5.2.0" | ||
|
||
"strip-ansi-cjs@npm:strip-ansi@^6.0.1": | ||
version "6.0.1" | ||
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" | ||
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== | ||
dependencies: | ||
ansi-regex "^5.0.1" | ||
|
||
strip-ansi@^6.0.0, strip-ansi@^6.0.1: | ||
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: | ||
version "6.0.1" | ||
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" | ||
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== | ||
|
@@ -6917,7 +6906,7 @@ which@^2.0.1: | |
|
||
which@^4.0.0: | ||
version "4.0.0" | ||
resolved "https://registry.npmjs.org/which/-/which-4.0.0.tgz" | ||
resolved "https://registry.yarnpkg.com/which/-/which-4.0.0.tgz#cd60b5e74503a3fbcfbf6cd6b4138a8bae644c1a" | ||
integrity sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg== | ||
dependencies: | ||
isexe "^3.1.1" | ||
|
@@ -6946,7 +6935,7 @@ [email protected]: | |
resolved "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz" | ||
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw== | ||
|
||
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": | ||
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: | ||
version "7.0.0" | ||
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz" | ||
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== | ||
|
@@ -6964,15 +6953,6 @@ wrap-ansi@^6.2.0: | |
string-width "^4.1.0" | ||
strip-ansi "^6.0.0" | ||
|
||
wrap-ansi@^7.0.0: | ||
version "7.0.0" | ||
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz" | ||
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== | ||
dependencies: | ||
ansi-styles "^4.0.0" | ||
string-width "^4.1.0" | ||
strip-ansi "^6.0.0" | ||
|
||
wrap-ansi@^8.1.0: | ||
version "8.1.0" | ||
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's clever