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) }