Skip to content

Commit

Permalink
refactor: replace bundle-require with jiti
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkx committed Feb 16, 2024
1 parent b5e75c4 commit c8dfb98
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
3 changes: 0 additions & 3 deletions packages/modernjs-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
"prepack": "pnpm build",
"lint:type": "tsc --noEmit"
},
"dependencies": {
"bundle-require": "^4.0.2"
},
"devDependencies": {
"@modern-js/app-tools": "^2.46.1",
"@modern-js/utils": "^2.46.1",
Expand Down
4 changes: 1 addition & 3 deletions packages/modernjs-plugin/src/plugins/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export const manifestPlugin = (options: ManifestOptions): RsbuildPlugin => {
const outputPath = path.join(distPath, 'manifest.json');

async function generateManifest() {
const {
mod: { default: manifest },
} = await evalFile<{ default: unknown }>(sourcePath);
const manifest = await evalFile<unknown>(sourcePath);
const content = isDev() ? JSON.stringify(manifest, null, 2) : JSON.stringify(manifest);
await fs.writeFile(outputPath, content);
}
Expand Down
7 changes: 4 additions & 3 deletions packages/modernjs-plugin/src/utils/require.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { bundleRequire } from 'bundle-require';
// @ts-ignore ts source check
import createJITI from '@rsbuild/shared/jiti';

export async function evalFile<T>(filepath: string) {
return await bundleRequire<T>({ filepath });
export async function evalFile<T>(filepath: string): Promise<T> {
return await createJITI(__filename, { requireCache: false, interopDefault: true })(filepath);
}
30 changes: 26 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c8dfb98

Please sign in to comment.