Skip to content

Commit

Permalink
Merge pull request #7 from capricorn86/fix-build
Browse files Browse the repository at this point in the history
fix: [#1] Fixes problem with the build for happy-dom v14
  • Loading branch information
capricorn86 authored Apr 15, 2024
2 parents fa4b0dd + 0ed64b4 commit 6599992
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"esbuild": "^0.19.11",
"whatwg-url": "^14.0.0",
"playwright": "^1.41.1",
"happy-dom": "^13.3.1"
"happy-dom": "^14.7.1"
},
"happyLintChanged": {
"rules": [
Expand Down
16 changes: 16 additions & 0 deletions polyfills/stream/web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable */
interface UnderlyingByteSource {}
interface QueuingStrategy<R> {
__r: R | undefined;
}
interface UnderlyingSource<R> {
__r: R | undefined;
}
const ReadableStream = globalThis.ReadableStream;

export type { UnderlyingByteSource, QueuingStrategy, UnderlyingSource };
export { ReadableStream };

export default {
ReadableStream
};
38 changes: 29 additions & 9 deletions scripts/polyfill-code.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ process.on('unhandledRejection', (reason) => {

main();

const POLYFILL_MODULES = ['net', 'crypto', 'url', 'stream', 'vm', 'buffer', 'console'];
const POLYFILL_MODULES = [
'net',
'crypto',
'url',
'stream',
'stream/web',
'vm',
'buffer',
'console'
];

const POLYFILL_TRANSPILERS = [
function polyfillGlobals(_directory, _file, content) {
Expand Down Expand Up @@ -49,24 +58,35 @@ const POLYFILL_TRANSPILERS = [
''
);
},
function polyfillIncorrectHTMLElementTagNameMapExtend(_directory, file, content) {
if (!file.includes('HTMLElementTagNameMap')) {
return content;
}

return content.replace(' extends HTMLElementTagNameMap', '');
},
function polyfillModules(directory, file, content) {
const polyfillsDirectory = Path.join(directory, 'polyfills');
let newContent = content;
for (const module of POLYFILL_MODULES) {
const regexp = new RegExp(`import.+from\\s*(["']${module}["'])`);
const moduleMatch = content.match(regexp);
const regexp = new RegExp(
`import.+from\\s*(["']${module}["'])|import\\((["']${module}["'])\\)`,
'gm'
);
let match;

if (moduleMatch) {
while ((match = regexp.exec(content)) !== null) {
const modulePath = Path.relative(Path.dirname(file), polyfillsDirectory) + `/${module}.js`;
content = content.replace(
moduleMatch[0],
moduleMatch[0].replace(
moduleMatch[1],
newContent = newContent.replace(
match[0],
match[0].replace(
match[1] || match[2],
`'${modulePath.startsWith('.') ? modulePath : `./${modulePath}`}'`
)
);
}
}
return content;
return newContent;
}
];

Expand Down

0 comments on commit 6599992

Please sign in to comment.