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)