Skip to content

Commit

Permalink
fix import error
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiller1990 committed Feb 13, 2023
1 parent 16ca37c commit 664e159
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/scaffold-config/src/ct-detect-third-party.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ const dynamicAbsoluteImport = (filePath: string) => {
return dynamicImport(pathToFileURL(filePath).href) as Promise<any>
}

/**
* When compiling CJS -> ESM, TS can produce:
* Imported [Module: null prototype] { __esModule: true, default: { default: { type: 'cypress-ct-solid-js', ... } } }
* We just keep getting `default` property until none exists.
*/
function getDefaultExport<T extends { default?: T }> (mod: T): T {
if (mod?.default) {
return getDefaultExport(mod.default)
}

return mod?.default ?? mod
}

export async function detectThirdPartyCTFrameworks (
projectRoot: string,
): Promise<Cypress.ThirdPartyComponentFrameworkDefinition[]> {
Expand Down Expand Up @@ -81,11 +94,17 @@ export async function detectThirdPartyCTFrameworks (

debug('Resolve successful: %s', modulePath)

const m = await dynamicAbsoluteImport(modulePath).then((m) => m.default || m)
const m = await dynamicAbsoluteImport(modulePath)

debug('Imported %o', m)

const mod = getDefaultExport(m)

debug('Module is %o', mod)

debug('Import successful: %o', m)
debug('Import successful: %o', mod)

return m
return mod
} catch (e) {
debug('Ignoring %s due to error resolving: %o', e)
}
Expand Down

0 comments on commit 664e159

Please sign in to comment.