Skip to content

Commit

Permalink
fix: dont bundle the content
Browse files Browse the repository at this point in the history
  • Loading branch information
imranbarbhuiya committed Aug 27, 2023
1 parent 00f97eb commit 5ad8f06
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 148 deletions.
20 changes: 3 additions & 17 deletions src/lib/polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
/**
* `polyfillPath` and `getCachedPolyfillContent` are taken from below source with some modifications for my use case.
* https://github.com/Aslemammad/modern-node-polyfills
* @author Aslemammad
* @license MIT
*/

import { readFile } from 'node:fs/promises';
import { builtinModules } from 'node:module';
import { resolve, join } from 'node:path';

import { build } from 'esbuild';
import { loadPackageJSON, resolveModule } from 'local-pkg';
import { resolve as resolveExports } from 'resolve.exports';

Expand All @@ -20,7 +13,7 @@ async function polyfillPath(importPath: string) {

const jspmPath = resolve(
require.resolve(`@jspm/core/nodelibs/${importPath}`),
// ensure "fs/promises" is resolved properly
// ensure sub path modules are resolved properly
'../../..' + (importPath.includes('/') ? '/..' : ''),
);

Expand Down Expand Up @@ -57,14 +50,7 @@ export const getCachedPolyfillPath = (importPath: string): Promise<string> => {
export const polyfillContentAndTransform = async (importPath: string) => {
const exportFullPath = await getCachedPolyfillPath(importPath);

const content = (
await build({
write: false,
format: 'esm',
bundle: true,
entryPoints: [exportFullPath],
})
).outputFiles[0]!.text;
const content = await readFile(exportFullPath, 'utf8');

return content.replace(/eval\(/g, '(0,eval)(');
};
Expand Down
Loading

0 comments on commit 5ad8f06

Please sign in to comment.