Skip to content

Commit

Permalink
Merge branch 'main' into mdonnalley/660
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 19, 2023
2 parents 15d6556 + a068d9a commit 02a394b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
3 changes: 2 additions & 1 deletion src/config/plugin-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (!plugins || plugins.length === 0) return
Expand All @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions src/config/ts-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface PluginOptions {
root: string
tag?: string
type?: string
url?: string
}

export interface Options extends PluginOptions {
Expand Down Expand Up @@ -56,6 +57,7 @@ export interface Plugin {
* name from package.json
*/
name: string
readonly options: Options
/**
* full package.json
*
Expand Down
2 changes: 2 additions & 0 deletions test/config/config.flexible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ describe('Config with flexible taxonomy', () => {
moduleType: 'commonjs',
hasManifest: false,
isRoot: false,
options: {root: ''},
}

const pluginB: IPlugin = {
Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ describe('Config', () => {
moduleType: 'commonjs',
hasManifest: false,
isRoot: false,
options: {root: ''},
}

const pluginB: IPlugin = {
Expand All @@ -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
Expand Down

0 comments on commit 02a394b

Please sign in to comment.