11import type esbuild from "esbuild" ;
2+ import path from "path" ;
23import type { Program } from "../../programs/base" ;
34import { createNodePolyfillMap } from "./create-node-polyfill-map" ;
45
56export const POLYFILL_IMPORT_NS = "react-gnome-polyfills" ;
67
78const NodePolyfills = createNodePolyfillMap ( [
89 {
9- matcher : / ^ ( f s ) | ( n o d e : f s ) $ / ,
10+ matcher : / ^ ( f s | n o d e : f s ) $ / ,
1011 configFlag : ( c ) => ! ! c . polyfills ?. node ?. fs ,
1112 filename : "fs.mjs" ,
1213 } ,
1314 {
14- matcher : / ^ ( f s \/ p r o m i s e s ) | ( n o d e : f s \/ p r o m i s e s ) $ / ,
15+ matcher : / ^ ( f s \/ p r o m i s e s | n o d e : f s \/ p r o m i s e s ) $ / ,
1516 configFlag : ( c ) => ! ! c . polyfills ?. node ?. fs ,
1617 filename : "fs-promises.mjs" ,
1718 } ,
1819 {
19- matcher : / ^ ( p a t h ) | ( n o d e : p a t h ) $ / ,
20+ matcher : / ^ ( p a t h | n o d e : p a t h ) $ / ,
2021 configFlag : ( c ) => ! ! c . polyfills ?. node ?. path ,
2122 filename : "path.mjs" ,
2223 } ,
2324 {
24- matcher : / ^ ( q u e r y s t r i n g ) | ( n o d e : q u e r y s t r i n g ) $ / ,
25+ matcher : / ^ ( q u e r y s t r i n g | n o d e : q u e r y s t r i n g ) $ / ,
2526 configFlag : ( c ) => ! ! c . polyfills ?. node ?. querystring ,
2627 filename : "querystring.mjs" ,
2728 } ,
2829 {
29- matcher : / ^ ( o s ) | ( n o d e : o s ) $ / ,
30+ matcher : / ^ ( o s | n o d e : o s ) $ / ,
3031 configFlag : ( c ) => ! ! c . polyfills ?. node ?. os ,
3132 filename : "node-os.mjs" ,
3233 } ,
@@ -44,34 +45,13 @@ export const importPolyfillsPlugin = (program: Program) => {
4445 build . onResolve ( { filter : / .* / } , ( arg ) => {
4546 if ( customPoly . importName === arg . path ) {
4647 return {
47- path : customPoly . filepath ,
48- namespace : POLYFILL_IMPORT_NS ,
48+ path : path . join ( program . cwd , customPoly . filepath ) ,
4949 } ;
5050 }
5151 } ) ;
5252 }
5353 }
5454 }
55-
56- if ( program . config . customPolyfills ) {
57- build . onLoad (
58- {
59- filter : / .* / ,
60- namespace : POLYFILL_IMPORT_NS ,
61- } ,
62- ( args ) => {
63- return {
64- contents : /* js */ `
65- import * as _mod from "${ args . path } ";
66- const _default = _mod.default ?? _mod;
67- export default _default;
68- export * from "${ args . path } ";
69- ` . trim ( ) ,
70- resolveDir : program . cwd ,
71- } ;
72- } ,
73- ) ;
74- }
7555 } ,
7656 } ;
7757} ;
0 commit comments