From b1a3cde43763b170af0f632319ac0d49043a6ddd Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Thu, 2 Nov 2023 09:54:00 -0600 Subject: [PATCH 1/8] fix: --ignore-scripts on github installs --- package.json | 2 +- src/plugins.ts | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 16ac98b1..4d847396 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "lint": "eslint . --ext .ts", "postpublish": "yarn run clean", "posttest": "yarn lint", - "prepare": "husky install", + "postinstall": "husky install", "prepublishOnly": "yarn run build && oclif lock && oclif manifest . && oclif readme", "pretest": "yarn build && tsc -p test --noEmit", "preversion": "yarn run clean", diff --git a/src/plugins.ts b/src/plugins.ts index d400ec3a..1e39c537 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -85,28 +85,32 @@ export default class Plugins { if (name.includes(':')) { // url const url = name - await this.yarn.exec([...add, url], yarnOpts) + await this.yarn.exec([...add, '--ignore-scripts', 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) + await this.refresh({all: true, prod: true}) this.isValidPlugin(plugin) 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') { + 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(['install'], {...yarnOpts, cwd: plugin.root}) + await this.yarn.exec(['run', 'tsc'], {...yarnOpts, cwd: plugin.root}) + } catch (error) { + this.debug(error) + } } } else { // npm @@ -221,10 +225,12 @@ export default class Plugins { const pluginRoots = [...roots] if (options.all) { - const userPluginsRoots = this.config - .getPluginsList() - .filter((p) => p.type === 'user') - .map((p) => p.root) + const plugins = await this.list() + const userPluginsRoots = plugins + .filter((p) => p.type === 'user' && !p.url) + .map((p) => this.config.plugins.get(p.name)?.root) + // eslint-disable-next-line unicorn/prefer-native-coercion-functions + .filter((r): r is string => Boolean(r)) pluginRoots.push(...userPluginsRoots) } From 5ddbc904014345578281d5ff11e5295e0eeea56a Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 3 Nov 2023 10:59:58 -0600 Subject: [PATCH 2/8] fix: don't ingore scripts --- src/plugins.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/plugins.ts b/src/plugins.ts index 1e39c537..d7931f1e 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -85,7 +85,7 @@ export default class Plugins { if (name.includes(':')) { // url const url = name - await this.yarn.exec([...add, '--ignore-scripts', url], yarnOpts) + 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) @@ -106,7 +106,6 @@ export default class Plugins { // 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(['install'], {...yarnOpts, cwd: plugin.root}) await this.yarn.exec(['run', 'tsc'], {...yarnOpts, cwd: plugin.root}) } catch (error) { this.debug(error) @@ -178,7 +177,6 @@ export default class Plugins { return unfriendly } - this.debug(`expanded package name ${unfriendly} not found, using given package name ${name}`) return name } From a2a82dcfbc11600c7725a86babc79277f31331b0 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 3 Nov 2023 14:09:32 -0600 Subject: [PATCH 3/8] fix: disable husky for installs --- src/plugins.ts | 26 ++++++-------------------- src/yarn.ts | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/plugins.ts b/src/plugins.ts index d7931f1e..ffaf5b45 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -88,29 +88,17 @@ 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, + root: join(this.config.dataDir, 'node_modules', name), userPlugins: false, }) - await this.refresh({all: true, prod: true}) + await this.refresh({all: true, prod: true}, plugin.root) this.isValidPlugin(plugin) await this.add({name, type: 'user', url}) - - if (plugin.getPluginsList().find((p) => p.root === root)?.moduleType === 'module') { - 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 const range = validRange(tag) @@ -223,12 +211,10 @@ export default class Plugins { const pluginRoots = [...roots] if (options.all) { - const plugins = await this.list() - const userPluginsRoots = plugins - .filter((p) => p.type === 'user' && !p.url) - .map((p) => this.config.plugins.get(p.name)?.root) - // eslint-disable-next-line unicorn/prefer-native-coercion-functions - .filter((r): r is string => Boolean(r)) + const userPluginsRoots = this.config + .getPluginsList() + .filter((p) => p.type === 'user') + .map((p) => p.root) pluginRoots.push(...userPluginsRoots) } diff --git a/src/yarn.ts b/src/yarn.ts index 1a40a4f3..3fa50270 100644 --- a/src/yarn.ts +++ b/src/yarn.ts @@ -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() From c06fceaf7b5b9359a5a824e8e544349ab01182f8 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 6 Nov 2023 09:44:08 -0700 Subject: [PATCH 4/8] fix: only attempt tsc if tsconfig exists --- package.json | 2 +- src/plugins.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4d847396..00954d2f 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "lint": "eslint . --ext .ts", "postpublish": "yarn run clean", "posttest": "yarn lint", - "postinstall": "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", diff --git a/src/plugins.ts b/src/plugins.ts index ffaf5b45..2b1e1309 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -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) @@ -99,6 +100,20 @@ export default class Plugins { this.isValidPlugin(plugin) await this.add({name, type: 'user', url}) + + 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 const range = validRange(tag) From 25a070b7ccaf27c788f56dc7f9fc597b794d40a9 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 6 Nov 2023 09:45:52 -0700 Subject: [PATCH 5/8] chore: clean up --- src/plugins.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins.ts b/src/plugins.ts index 2b1e1309..cff6bed2 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -180,6 +180,7 @@ export default class Plugins { return unfriendly } + this.debug(`expanded package name ${unfriendly} not found, using given package name ${name}`) return name } From 204b36949c940c8417bfff6a252141e53e734618 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 6 Nov 2023 10:04:35 -0700 Subject: [PATCH 6/8] chore: update prepare script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 00954d2f..fadad3f1 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "lint": "eslint . --ext .ts", "postpublish": "yarn run clean", "posttest": "yarn lint", - "prepare": "husky install && yarn build", + "prepare": "husky install && yarn build && yarn oclif manifest", "prepublishOnly": "yarn run build && oclif lock && oclif manifest . && oclif readme", "pretest": "yarn build && tsc -p test --noEmit", "preversion": "yarn run clean", From 4159bf9e4cc4d1d2ffd748a337f15dd469766844 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 6 Nov 2023 10:14:13 -0700 Subject: [PATCH 7/8] chore: update prepare script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fadad3f1..f152eef6 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "lint": "eslint . --ext .ts", "postpublish": "yarn run clean", "posttest": "yarn lint", - "prepare": "husky install && yarn build && yarn oclif manifest", + "prepare": "husky install && yarn build && oclif manifest", "prepublishOnly": "yarn run build && oclif lock && oclif manifest . && oclif readme", "pretest": "yarn build && tsc -p test --noEmit", "preversion": "yarn run clean", From 07daa41e6aefb2e82ab38b04ec6cb614d1eea901 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 6 Nov 2023 10:22:59 -0700 Subject: [PATCH 8/8] chore: bump core --- package.json | 4 ++-- yarn.lock | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f152eef6..7c49407e 100644 --- a/package.json +++ b/package.json @@ -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", @@ -81,7 +81,7 @@ "lint": "eslint . --ext .ts", "postpublish": "yarn run clean", "posttest": "yarn lint", - "prepare": "husky install && yarn build && oclif manifest", + "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", diff --git a/yarn.lock b/yarn.lock index 31d2627e..9fb08156 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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== @@ -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" @@ -6641,6 +6673,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"