Skip to content

Commit

Permalink
fix: HUSKY=0 on github installs (#702)
Browse files Browse the repository at this point in the history
* fix: --ignore-scripts on github installs

* fix: don't ingore scripts

* fix: disable husky for installs

* fix: only attempt tsc if tsconfig exists

* chore: clean up

* chore: update prepare script

* chore: update prepare script

* chore: bump core
  • Loading branch information
mdonnalley authored Nov 6, 2023
1 parent ff042d5 commit 69129c9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Salesforce",
"bugs": "https://github.com/oclif/plugin-plugins/issues",
"dependencies": {
"@oclif/core": "^3.7.1",
"@oclif/core": "^3.10.2",
"chalk": "^5.3.0",
"debug": "^4.3.4",
"npm": "9.8.1",
Expand Down Expand Up @@ -81,7 +81,7 @@
"lint": "eslint . --ext .ts",
"postpublish": "yarn run clean",
"posttest": "yarn lint",
"prepare": "husky install",
"prepare": "husky install && yarn build",
"prepublishOnly": "yarn run build && oclif lock && oclif manifest . && oclif readme",
"pretest": "yarn build && tsc -p test --noEmit",
"preversion": "yarn run clean",
Expand Down
22 changes: 14 additions & 8 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ export default class Plugins {
await this.yarn.exec([...add, url], yarnOpts)
const {dependencies} = await this.pjson()
name = Object.entries(dependencies ?? {}).find(([, u]) => u === url)![0]
const root = join(this.config.dataDir, 'node_modules', name)
plugin = await Config.load({
devPlugins: false,
name,
root: join(this.config.dataDir, 'node_modules', name),
root,
userPlugins: false,
})
await this.refresh({all: true, prod: true}, plugin.root)
Expand All @@ -100,13 +101,18 @@ export default class Plugins {

await this.add({name, type: 'user', url})

try {
// CJS plugins can be auto-transpiled at runtime but ESM plugins
// cannot. To support ESM plugins we need to compile them after
// installing them.
await this.yarn.exec(['run', 'tsc'], {...yarnOpts, cwd: plugin.root})
} catch (error) {
this.debug(error)
if (
plugin.getPluginsList().find((p) => p.root === root)?.moduleType === 'module' &&
(await fileExists(join(plugin.root, 'tsconfig.json')))
) {
try {
// CJS plugins can be auto-transpiled at runtime but ESM plugins
// cannot. To support ESM plugins we need to compile them after
// installing them.
await this.yarn.exec(['run', 'tsc'], {...yarnOpts, cwd: plugin.root})
} catch (error) {
this.debug(error)
}
}
} else {
// npm
Expand Down
15 changes: 12 additions & 3 deletions src/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,18 @@ export default class Yarn {
const cache = YarnMessagesCache.getInstance()

return new Promise((resolve, reject) => {
// YARN_IGNORE_PATH=1 prevents yarn from resolving to the globally configured yarn binary.
// In other words, it ensures that it resolves to the yarn binary that is available in the node_modules directory.
const forked = fork(modulePath, args, {...options, env: {...process.env, YARN_IGNORE_PATH: '1'}})
const forked = fork(modulePath, args, {
...options,
env: {
...process.env,
// Disable husky hooks because a plugin might be trying to install them, which will
// break the install since the install location isn't a .git directory.
HUSKY: '0',
// YARN_IGNORE_PATH=1 prevents yarn from resolving to the globally configured yarn binary.
// In other words, it ensures that it resolves to the yarn binary that is available in the node_modules directory.
YARN_IGNORE_PATH: '1',
},
})
forked.stderr?.on('data', (d: Buffer) => {
if (!options.silent) {
const str = d.toString()
Expand Down
39 changes: 38 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@
wordwrap "^1.0.0"
wrap-ansi "^7.0.0"

"@oclif/core@^3.0.4", "@oclif/core@^3.2.1", "@oclif/core@^3.3.1", "@oclif/core@^3.7.1":
"@oclif/core@^3.0.4", "@oclif/core@^3.2.1", "@oclif/core@^3.3.1":
version "3.9.1"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-3.9.1.tgz#056cf2e5b0962eac371a31d12963b188ca314716"
integrity sha512-ZVz2TY8f0cA2HHIWdIAYOjpKynEyF481cKs1J6olDViLZ4OJonuLgGWUFs9luaadBcYtRoVuM3Ox1cdSqeUWFw==
Expand Down Expand Up @@ -682,6 +682,38 @@
wordwrap "^1.0.0"
wrap-ansi "^7.0.0"

"@oclif/core@^3.10.2":
version "3.10.2"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-3.10.2.tgz#bed039f3b39208c6d4042ddd3e02fb237d78bf6d"
integrity sha512-tpOhDXPKLMavFsjrWpF1sTdyvOgcSlWBP+puO60XYnDk4+c1ghK7Pr7AA83VIyyUqUSBaxKjUJcZJJHGYfXuIA==
dependencies:
ansi-escapes "^4.3.2"
ansi-styles "^4.3.0"
cardinal "^2.1.1"
chalk "^4.1.2"
clean-stack "^3.0.1"
cli-progress "^3.12.0"
debug "^4.3.4"
ejs "^3.1.9"
get-package-type "^0.1.0"
globby "^11.1.0"
hyperlinker "^1.0.0"
indent-string "^4.0.0"
is-wsl "^2.2.0"
js-yaml "^3.14.1"
natural-orderby "^2.0.3"
object-treeify "^1.1.33"
password-prompt "^1.1.2"
slice-ansi "^4.0.0"
string-width "^4.2.3"
strip-ansi "^6.0.1"
supports-color "^8.1.1"
supports-hyperlinks "^2.2.0"
tsconfck "^3.0.0"
widest-line "^3.1.0"
wordwrap "^1.0.0"
wrap-ansi "^7.0.0"

"@oclif/plugin-help@^5.2.14":
version "5.2.20"
resolved "https://registry.yarnpkg.com/@oclif/plugin-help/-/plugin-help-5.2.20.tgz#4035a0ac231f95fb8e334da342175e3ca00f6abc"
Expand Down Expand Up @@ -6655,6 +6687,11 @@ ts-node@^10.8.1, ts-node@^10.9.1:
v8-compile-cache-lib "^3.0.1"
yn "3.1.1"

tsconfck@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/tsconfck/-/tsconfck-3.0.0.tgz#b469f1ced12973bbec3209a55ed8de3bb04223c9"
integrity sha512-w3wnsIrJNi7avf4Zb0VjOoodoO0woEqGgZGQm+LHH9przdUI+XDKsWAXwxHA1DaRTjeuZNcregSzr7RaA8zG9A==

tsconfig-paths@^3.14.2:
version "3.14.2"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz#6e32f1f79412decd261f92d633a9dc1cfa99f088"
Expand Down

0 comments on commit 69129c9

Please sign in to comment.