@@ -110,29 +110,41 @@ export const createExtensions = (
110
110
'.ts' ,
111
111
'.tsx' ,
112
112
'.jsx' ,
113
-
114
- /**
115
- * Loaders for extensions .cjs, .cts, & .mts don't need to be
116
- * registered because they're explicitly specified. And unknown
117
- * extensions (incl .cjs) fallsback to using the '.js' loader:
118
- * https://github.com/nodejs/node/blob/v18.4.0/lib/internal/modules/cjs/loader.js#L430
119
- *
120
- * That said, it's actually ".js" and ".mjs" that get special treatment
121
- * rather than ".cjs" (it might as well be ".random-ext")
122
- */
123
- '.mjs' ,
124
113
] . forEach ( ( extension ) => {
114
+ const descriptor = Object . getOwnPropertyDescriptor ( extensions , extension ) ;
125
115
Object . defineProperty ( extensions , extension , {
126
116
value : transformer ,
127
117
128
118
/**
129
- * Prevent Object.keys from detecting these extensions
130
- * when CJS loader iterates over the possible extensions
131
- * https://github.com/nodejs/node/blob/v22.2.0/lib/internal/modules/cjs/loader.js#L609
119
+ * Registeration needs to be enumerable for some 3rd party libraries
120
+ * https://github.com/gulpjs/rechoir/blob/v0.8.0/index.js#L21 (used by Webpack CLI)
121
+ *
122
+ * If the extension already exists, inherit its enumerable property
123
+ * If not, only expose if it's not namespaced
132
124
*/
133
- enumerable : false ,
125
+ enumerable : descriptor ?. enumerable || ! namespace ,
134
126
} ) ;
135
127
} ) ;
136
128
129
+ /**
130
+ * Loaders for extensions .cjs, .cts, & .mts don't need to be
131
+ * registered because they're explicitly specified. And unknown
132
+ * extensions (incl .cjs) fallsback to using the '.js' loader:
133
+ * https://github.com/nodejs/node/blob/v18.4.0/lib/internal/modules/cjs/loader.js#L430
134
+ *
135
+ * That said, it's actually ".js" and ".mjs" that get special treatment
136
+ * rather than ".cjs" (it might as well be ".random-ext")
137
+ */
138
+ Object . defineProperty ( extensions , '.mjs' , {
139
+ value : transformer ,
140
+
141
+ /**
142
+ * Prevent Object.keys from detecting these extensions
143
+ * when CJS loader iterates over the possible extensions
144
+ * https://github.com/nodejs/node/blob/v22.2.0/lib/internal/modules/cjs/loader.js#L609
145
+ */
146
+ enumerable : false ,
147
+ } ) ;
148
+
137
149
return extensions ;
138
150
} ;
0 commit comments