From 2caed3db66f678e49db09a72456cf072604826a8 Mon Sep 17 00:00:00 2001 From: Kara Brightwell Date: Thu, 9 Jan 2025 11:05:26 +0000 Subject: [PATCH] fix: actually support CJS in importEntryPoint --- core/cli/src/plugin/entry-point.ts | 39 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/core/cli/src/plugin/entry-point.ts b/core/cli/src/plugin/entry-point.ts index 97f620824..2adea5e95 100644 --- a/core/cli/src/plugin/entry-point.ts +++ b/core/cli/src/plugin/entry-point.ts @@ -4,6 +4,7 @@ import type { Base } from '@dotcom-tool-kit/base' import type { EntryPoint } from '@dotcom-tool-kit/plugin' import { Validated, invalid } from '@dotcom-tool-kit/validated' import { isPlainObject } from 'lodash' +import { __importDefault } from 'tslib' import { indentReasons } from '../messages' const isPlainObjectGuard = (value: unknown): value is Record => isPlainObject(value) @@ -36,25 +37,23 @@ export async function importEntryPoint(pluginModule.default) - .mapError((reasons) => [ - `the ${type.name.toLowerCase()} ${s.hook(name)} is not a compatible instance of ${s.code( - type.name - )}:\n - ${reasons.join('\n - ')}` - ]) - } else { - return invalid([ - `entrypoint ${s.filepath(entryPoint.modulePath)} in plugin ${s.plugin( - entryPoint.plugin.id - )} does not have a ${s.code('default')} export` - ]) + if (isPlainObjectGuard(pluginModule)) { + const defaultExport = __importDefault(pluginModule).default + + if (typeof defaultExport === 'function') { + return type + .isCompatible(defaultExport) + .mapError((reasons) => [ + `the ${type.name.toLowerCase()} ${s.hook( + defaultExport.name + )} is not a compatible instance of ${s.code(type.name)}:\n - ${reasons.join('\n - ')}` + ]) + } } + + return invalid([ + `entrypoint ${s.filepath(entryPoint.modulePath)} in plugin ${s.plugin( + entryPoint.plugin.id + )} does not export a class as its ${s.code('default')} export or ${s.code('module.exports')}` + ]) }