-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): use bundle-require instead of jiti (no hackfix, but also n…
…o CJS configs)
- Loading branch information
1 parent
cea97cf
commit 028c592
Showing
6 changed files
with
39 additions
and
137 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,9 @@ | ||
import { TransformOptions } from '@babel/core'; | ||
import jiti from 'jiti'; | ||
import { dirname, join, relative } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { babelPluginLighthouseHackfix } from './babel-plugin-lighthouse-hackfix'; | ||
import { bundleRequire } from 'bundle-require'; | ||
|
||
export async function cli(configPath: string) { | ||
const path = resolveImportPath(configPath); | ||
const data = await loadModule(path); | ||
console.log('Loaded config:', data); | ||
return data; | ||
} | ||
|
||
function resolveImportPath(path: string) { | ||
const absolutePath = join(process.cwd(), path); | ||
const modulePath = fileURLToPath(new URL(import.meta.url)); | ||
const relativePath = relative(dirname(modulePath), absolutePath); | ||
if (!relativePath.startsWith('.')) { | ||
return `./${relativePath}`; | ||
} | ||
return relativePath; | ||
} | ||
|
||
async function loadModule(path: string) { | ||
if (/\.[cm]?ts$/.test(path)) { | ||
const babelOptions: TransformOptions = { | ||
plugins: [babelPluginLighthouseHackfix], | ||
}; | ||
const jitiLoader = jiti(fileURLToPath(new URL(import.meta.url)), { | ||
interopDefault: true, | ||
transformOptions: { | ||
babel: babelOptions, | ||
}, | ||
}); | ||
return jitiLoader(path); | ||
} | ||
|
||
const module = await import(path); | ||
return module.default ?? module; | ||
const { mod } = await bundleRequire({ | ||
filepath: configPath, | ||
format: 'esm', | ||
}); | ||
return mod.default || mod; | ||
} |
This file was deleted.
Oops, something went wrong.