diff --git a/src/config/config.ts b/src/config/config.ts index a3fcef2b7..78df047bd 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -528,7 +528,17 @@ export class Config implements IConfig { } catch (error: any) { final.failures.push({error: error as Error, plugin: p}) debug(error) - if (!captureErrors && error.oclif?.exit !== undefined) throw error + // Do not throw the error if + // captureErrors is set to true + // error.oclif.exit is undefined or 0 + // error.code is MODULE_NOT_FOUND + if ( + !captureErrors && + error.oclif?.exit !== undefined && + error.oclif?.exit !== 0 && + error.code !== 'MODULE_NOT_FOUND' + ) + throw error } marker?.addDetails({ diff --git a/src/config/plugin-loader.ts b/src/config/plugin-loader.ts index 0fcc8a130..ea466387d 100644 --- a/src/config/plugin-loader.ts +++ b/src/config/plugin-loader.ts @@ -94,7 +94,7 @@ export default class PluginLoader { private async loadPlugins( root: string, type: string, - plugins: ({name?: string; root?: string; tag?: string} | string)[], + plugins: ({name?: string; root?: string; tag?: string; url?: string} | string)[], parent?: Plugin.Plugin, ): Promise { if (!plugins || plugins.length === 0) return @@ -112,6 +112,7 @@ export default class PluginLoader { if (typeof plugin !== 'string') { opts.tag = plugin.tag || opts.tag opts.root = plugin.root || opts.root + opts.url = plugin.url } if (parent) { diff --git a/src/config/ts-node.ts b/src/config/ts-node.ts index 7a0328350..b24ce1d72 100644 --- a/src/config/ts-node.ts +++ b/src/config/ts-node.ts @@ -201,7 +201,7 @@ function determinePath(root: string, orig: string): string { export function tsPath(root: string, orig: string, plugin: Plugin): string export function tsPath(root: string, orig: string | undefined, plugin?: Plugin): string | undefined export function tsPath(root: string, orig: string | undefined, plugin?: Plugin): string | undefined { - const rootPlugin = Cache.getInstance().get('rootPlugin') + const rootPlugin = plugin?.options.isRoot ? plugin : Cache.getInstance().get('rootPlugin') if (!orig) return orig orig = orig.startsWith(root) ? orig : join(root, orig) @@ -223,10 +223,16 @@ export function tsPath(root: string, orig: string | undefined, plugin?: Plugin): memoizedWarn( `${plugin?.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`, ) + + if (plugin?.options.url) + memoizedWarn( + `${plugin?.name} is an ESM module installed from github and cannot be auto-transpiled. Existing compiled source will be used instead.`, + ) return orig } - if (settings.tsnodeEnabled === undefined && isProduction && plugin?.type !== 'link') { + // Do not skip ts-node registration if the plugin is linked or installed from github + if (settings.tsnodeEnabled === undefined && isProduction && plugin?.type !== 'link' && !plugin?.options.url) { debug(`Skipping ts-node registration for ${root} because NODE_ENV is NOT "test" or "development"`) return orig } diff --git a/src/interfaces/plugin.ts b/src/interfaces/plugin.ts index d374e0fd9..7eac9cfad 100644 --- a/src/interfaces/plugin.ts +++ b/src/interfaces/plugin.ts @@ -14,6 +14,7 @@ export interface PluginOptions { root: string tag?: string type?: string + url?: string } export interface Options extends PluginOptions { @@ -56,6 +57,7 @@ export interface Plugin { * name from package.json */ name: string + readonly options: Options /** * full package.json * diff --git a/test/config/config.flexible.test.ts b/test/config/config.flexible.test.ts index 2d95ea68a..b68162c2c 100644 --- a/test/config/config.flexible.test.ts +++ b/test/config/config.flexible.test.ts @@ -104,6 +104,7 @@ describe('Config with flexible taxonomy', () => { moduleType: 'commonjs', hasManifest: false, isRoot: false, + options: {root: ''}, } const pluginB: IPlugin = { @@ -125,6 +126,7 @@ describe('Config with flexible taxonomy', () => { moduleType: 'commonjs', hasManifest: false, isRoot: false, + options: {root: ''}, } const plugins = new Map().set(pluginA.name, pluginA).set(pluginB.name, pluginB) diff --git a/test/config/config.test.ts b/test/config/config.test.ts index 82f014a5e..1fd875216 100644 --- a/test/config/config.test.ts +++ b/test/config/config.test.ts @@ -293,6 +293,7 @@ describe('Config', () => { moduleType: 'commonjs', hasManifest: false, isRoot: false, + options: {root: ''}, } const pluginB: IPlugin = { @@ -314,6 +315,7 @@ describe('Config', () => { moduleType: 'commonjs', hasManifest: false, isRoot: false, + options: {root: ''}, } const plugins = new Map().set(pluginA.name, pluginA).set(pluginB.name, pluginB) let test = fancy