@utoo/pack-shared 1.4.1 → 1.4.2-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/config.d.ts +11 -1
- package/cjs/webpackCompat.d.ts +2 -0
- package/cjs/webpackCompat.js +23 -13
- package/esm/config.d.ts +11 -1
- package/esm/webpackCompat.d.ts +2 -0
- package/esm/webpackCompat.js +23 -13
- package/package.json +1 -1
package/cjs/config.d.ts
CHANGED
|
@@ -21,6 +21,15 @@ export type RustifiedEnv = {
|
|
|
21
21
|
export type JSONValue = string | number | boolean | JSONValue[] | {
|
|
22
22
|
[k: string]: JSONValue;
|
|
23
23
|
};
|
|
24
|
+
export interface MdxTransformOptions {
|
|
25
|
+
development?: boolean;
|
|
26
|
+
jsx?: boolean;
|
|
27
|
+
jsxRuntime?: string;
|
|
28
|
+
jsxImportSource?: string;
|
|
29
|
+
providerImportSource?: string;
|
|
30
|
+
mdxType?: "commonmark" | "gfm";
|
|
31
|
+
}
|
|
32
|
+
export type MdxOptions = boolean | MdxTransformOptions;
|
|
24
33
|
export type TurbopackLoaderOptions = Record<string, JSONValue>;
|
|
25
34
|
export type TurbopackLoaderItem = string | {
|
|
26
35
|
loader: string;
|
|
@@ -106,7 +115,7 @@ export interface ResolveOptions {
|
|
|
106
115
|
alias?: Record<string, string | string[] | Record<string, string | string[]>>;
|
|
107
116
|
extensions?: string[];
|
|
108
117
|
}
|
|
109
|
-
export type ExternalType = "script" | "commonjs" | "esm" | "global";
|
|
118
|
+
export type ExternalType = "script" | "commonjs" | "esm" | "global" | "promise";
|
|
110
119
|
export interface ExternalAdvanced {
|
|
111
120
|
root: string;
|
|
112
121
|
type?: ExternalType;
|
|
@@ -241,6 +250,7 @@ export interface ConfigComplete {
|
|
|
241
250
|
pluginRuntimeStrategy?: "workerThreads" | "childProcesses";
|
|
242
251
|
persistentCaching?: boolean;
|
|
243
252
|
nodePolyfill?: boolean;
|
|
253
|
+
mdx?: MdxOptions;
|
|
244
254
|
devServer?: DevServerConfig;
|
|
245
255
|
server?: {
|
|
246
256
|
/** Entry point for the server runtime (e.g. "src/server.ts") */
|
package/cjs/webpackCompat.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export type WebpackEntry = string | string[] | Record<string, string | {
|
|
|
70
70
|
};
|
|
71
71
|
} | string[]>;
|
|
72
72
|
export type WebpackExternals = string | RegExp | Record<string, string | string[] | object> | (string | RegExp | Record<string, string | string[] | object>)[];
|
|
73
|
+
export type WebpackExternalsType = "promise";
|
|
73
74
|
export type WebpackTarget = string | string[];
|
|
74
75
|
export type WebpackDevTool = string | boolean;
|
|
75
76
|
export type WebpackStats = string | boolean | object;
|
|
@@ -82,6 +83,7 @@ export interface WebpackConfig {
|
|
|
82
83
|
module?: WebpackModule;
|
|
83
84
|
resolve?: WebpackResolve;
|
|
84
85
|
externals?: WebpackExternals;
|
|
86
|
+
externalsType?: WebpackExternalsType;
|
|
85
87
|
output?: WebpackOutput;
|
|
86
88
|
target?: WebpackTarget;
|
|
87
89
|
devtool?: WebpackDevTool;
|
package/cjs/webpackCompat.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.compatOptionsFromWebpack = compatOptionsFromWebpack;
|
|
4
4
|
function compatOptionsFromWebpack(webpackConfig) {
|
|
5
|
-
const { entry, mode, module, resolve, externals, output, target, devtool, optimization, plugins, stats, } = webpackConfig;
|
|
5
|
+
const { entry, mode, module, resolve, externals, externalsType, output, target, devtool, optimization, plugins, stats, } = webpackConfig;
|
|
6
6
|
const html = compatFromWebpackPlugin(plugins, compatHtml);
|
|
7
7
|
const copy = compatFromWebpackPlugin(plugins, compatCopy);
|
|
8
8
|
const outputCompat = compatOutput(output);
|
|
@@ -18,7 +18,7 @@ function compatOptionsFromWebpack(webpackConfig) {
|
|
|
18
18
|
mode: compatMode(mode),
|
|
19
19
|
module: compatModule(module),
|
|
20
20
|
resolve: compatResolve(resolve),
|
|
21
|
-
externals: compatExternals(externals),
|
|
21
|
+
externals: compatExternals(externals, externalsType),
|
|
22
22
|
output: outputCompat,
|
|
23
23
|
target: compatTarget(target),
|
|
24
24
|
sourceMaps: compatSourceMaps(devtool),
|
|
@@ -183,7 +183,7 @@ function compatProvider(maybeWebpackPluginInstance) {
|
|
|
183
183
|
}
|
|
184
184
|
return Object.keys(provider).length > 0 ? provider : undefined;
|
|
185
185
|
}
|
|
186
|
-
function compatExternals(webpackExternals) {
|
|
186
|
+
function compatExternals(webpackExternals, externalsType) {
|
|
187
187
|
if (!webpackExternals) {
|
|
188
188
|
return undefined;
|
|
189
189
|
}
|
|
@@ -191,7 +191,7 @@ function compatExternals(webpackExternals) {
|
|
|
191
191
|
switch (typeof webpackExternals) {
|
|
192
192
|
case "string": {
|
|
193
193
|
// Single string external: "lodash" -> { "lodash": "lodash" }
|
|
194
|
-
externals[webpackExternals] = webpackExternals;
|
|
194
|
+
externals[webpackExternals] = compatExternalValue(webpackExternals, externalsType);
|
|
195
195
|
break;
|
|
196
196
|
}
|
|
197
197
|
case "object": {
|
|
@@ -199,10 +199,10 @@ function compatExternals(webpackExternals) {
|
|
|
199
199
|
// Array of externals: ["lodash", "react"] -> { "lodash": "lodash", "react": "react" }
|
|
200
200
|
externals = webpackExternals.reduce((acc, external) => {
|
|
201
201
|
if (typeof external === "string") {
|
|
202
|
-
acc[external] = external;
|
|
202
|
+
acc[external] = compatExternalValue(external, externalsType);
|
|
203
203
|
}
|
|
204
204
|
else if (typeof external === "object" && external !== null) {
|
|
205
|
-
Object.assign(acc, compatExternals(external));
|
|
205
|
+
Object.assign(acc, compatExternals(external, externalsType));
|
|
206
206
|
}
|
|
207
207
|
return acc;
|
|
208
208
|
}, {});
|
|
@@ -231,7 +231,7 @@ function compatExternals(webpackExternals) {
|
|
|
231
231
|
}
|
|
232
232
|
else {
|
|
233
233
|
// Simple string mapping: { "react": "React" }
|
|
234
|
-
externals[key] = value;
|
|
234
|
+
externals[key] = compatExternalValue(value, externalsType);
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
else if (Array.isArray(value)) {
|
|
@@ -258,6 +258,9 @@ function compatExternals(webpackExternals) {
|
|
|
258
258
|
else if (first === "module") {
|
|
259
259
|
externals[key] = `esm ${second}`;
|
|
260
260
|
}
|
|
261
|
+
else if (first === "promise") {
|
|
262
|
+
externals[key] = `promise ${second}`;
|
|
263
|
+
}
|
|
261
264
|
else if (first === "var" ||
|
|
262
265
|
first === "global" ||
|
|
263
266
|
first === "window") {
|
|
@@ -272,11 +275,11 @@ function compatExternals(webpackExternals) {
|
|
|
272
275
|
}
|
|
273
276
|
}
|
|
274
277
|
else {
|
|
275
|
-
externals[key] = value[0] || key;
|
|
278
|
+
externals[key] = compatExternalValue(value[0] || key, externalsType);
|
|
276
279
|
}
|
|
277
280
|
}
|
|
278
281
|
else {
|
|
279
|
-
externals[key] = value[0] || key;
|
|
282
|
+
externals[key] = compatExternalValue(value[0] || key, externalsType);
|
|
280
283
|
}
|
|
281
284
|
}
|
|
282
285
|
else if (typeof value === "object" && value !== null) {
|
|
@@ -288,13 +291,13 @@ function compatExternals(webpackExternals) {
|
|
|
288
291
|
externals[key] = `commonjs ${val.commonjs}`;
|
|
289
292
|
}
|
|
290
293
|
else if (val.root) {
|
|
291
|
-
externals[key] = val.root;
|
|
294
|
+
externals[key] = compatExternalValue(val.root, externalsType);
|
|
292
295
|
}
|
|
293
296
|
else if (val.amd) {
|
|
294
|
-
externals[key] = val.amd;
|
|
297
|
+
externals[key] = compatExternalValue(val.amd, externalsType);
|
|
295
298
|
}
|
|
296
299
|
else {
|
|
297
|
-
externals[key] = key;
|
|
300
|
+
externals[key] = compatExternalValue(key, externalsType);
|
|
298
301
|
}
|
|
299
302
|
}
|
|
300
303
|
else {
|
|
@@ -304,7 +307,7 @@ function compatExternals(webpackExternals) {
|
|
|
304
307
|
}
|
|
305
308
|
else {
|
|
306
309
|
// Fallback to key name
|
|
307
|
-
externals[key] = key;
|
|
310
|
+
externals[key] = compatExternalValue(key, externalsType);
|
|
308
311
|
}
|
|
309
312
|
});
|
|
310
313
|
}
|
|
@@ -318,6 +321,13 @@ function compatExternals(webpackExternals) {
|
|
|
318
321
|
}
|
|
319
322
|
return externals;
|
|
320
323
|
}
|
|
324
|
+
function compatExternalValue(value, externalsType) {
|
|
325
|
+
if (externalsType === "promise" &&
|
|
326
|
+
!value.match(/^(commonjs|esm|script|promise)\s/)) {
|
|
327
|
+
return `promise ${value}`;
|
|
328
|
+
}
|
|
329
|
+
return value;
|
|
330
|
+
}
|
|
321
331
|
function compatModule(webpackModule) {
|
|
322
332
|
if (!Array.isArray(webpackModule === null || webpackModule === void 0 ? void 0 : webpackModule.rules)) {
|
|
323
333
|
return;
|
package/esm/config.d.ts
CHANGED
|
@@ -21,6 +21,15 @@ export type RustifiedEnv = {
|
|
|
21
21
|
export type JSONValue = string | number | boolean | JSONValue[] | {
|
|
22
22
|
[k: string]: JSONValue;
|
|
23
23
|
};
|
|
24
|
+
export interface MdxTransformOptions {
|
|
25
|
+
development?: boolean;
|
|
26
|
+
jsx?: boolean;
|
|
27
|
+
jsxRuntime?: string;
|
|
28
|
+
jsxImportSource?: string;
|
|
29
|
+
providerImportSource?: string;
|
|
30
|
+
mdxType?: "commonmark" | "gfm";
|
|
31
|
+
}
|
|
32
|
+
export type MdxOptions = boolean | MdxTransformOptions;
|
|
24
33
|
export type TurbopackLoaderOptions = Record<string, JSONValue>;
|
|
25
34
|
export type TurbopackLoaderItem = string | {
|
|
26
35
|
loader: string;
|
|
@@ -106,7 +115,7 @@ export interface ResolveOptions {
|
|
|
106
115
|
alias?: Record<string, string | string[] | Record<string, string | string[]>>;
|
|
107
116
|
extensions?: string[];
|
|
108
117
|
}
|
|
109
|
-
export type ExternalType = "script" | "commonjs" | "esm" | "global";
|
|
118
|
+
export type ExternalType = "script" | "commonjs" | "esm" | "global" | "promise";
|
|
110
119
|
export interface ExternalAdvanced {
|
|
111
120
|
root: string;
|
|
112
121
|
type?: ExternalType;
|
|
@@ -241,6 +250,7 @@ export interface ConfigComplete {
|
|
|
241
250
|
pluginRuntimeStrategy?: "workerThreads" | "childProcesses";
|
|
242
251
|
persistentCaching?: boolean;
|
|
243
252
|
nodePolyfill?: boolean;
|
|
253
|
+
mdx?: MdxOptions;
|
|
244
254
|
devServer?: DevServerConfig;
|
|
245
255
|
server?: {
|
|
246
256
|
/** Entry point for the server runtime (e.g. "src/server.ts") */
|
package/esm/webpackCompat.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export type WebpackEntry = string | string[] | Record<string, string | {
|
|
|
70
70
|
};
|
|
71
71
|
} | string[]>;
|
|
72
72
|
export type WebpackExternals = string | RegExp | Record<string, string | string[] | object> | (string | RegExp | Record<string, string | string[] | object>)[];
|
|
73
|
+
export type WebpackExternalsType = "promise";
|
|
73
74
|
export type WebpackTarget = string | string[];
|
|
74
75
|
export type WebpackDevTool = string | boolean;
|
|
75
76
|
export type WebpackStats = string | boolean | object;
|
|
@@ -82,6 +83,7 @@ export interface WebpackConfig {
|
|
|
82
83
|
module?: WebpackModule;
|
|
83
84
|
resolve?: WebpackResolve;
|
|
84
85
|
externals?: WebpackExternals;
|
|
86
|
+
externalsType?: WebpackExternalsType;
|
|
85
87
|
output?: WebpackOutput;
|
|
86
88
|
target?: WebpackTarget;
|
|
87
89
|
devtool?: WebpackDevTool;
|
package/esm/webpackCompat.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function compatOptionsFromWebpack(webpackConfig) {
|
|
2
|
-
const { entry, mode, module, resolve, externals, output, target, devtool, optimization, plugins, stats, } = webpackConfig;
|
|
2
|
+
const { entry, mode, module, resolve, externals, externalsType, output, target, devtool, optimization, plugins, stats, } = webpackConfig;
|
|
3
3
|
const html = compatFromWebpackPlugin(plugins, compatHtml);
|
|
4
4
|
const copy = compatFromWebpackPlugin(plugins, compatCopy);
|
|
5
5
|
const outputCompat = compatOutput(output);
|
|
@@ -15,7 +15,7 @@ export function compatOptionsFromWebpack(webpackConfig) {
|
|
|
15
15
|
mode: compatMode(mode),
|
|
16
16
|
module: compatModule(module),
|
|
17
17
|
resolve: compatResolve(resolve),
|
|
18
|
-
externals: compatExternals(externals),
|
|
18
|
+
externals: compatExternals(externals, externalsType),
|
|
19
19
|
output: outputCompat,
|
|
20
20
|
target: compatTarget(target),
|
|
21
21
|
sourceMaps: compatSourceMaps(devtool),
|
|
@@ -180,7 +180,7 @@ function compatProvider(maybeWebpackPluginInstance) {
|
|
|
180
180
|
}
|
|
181
181
|
return Object.keys(provider).length > 0 ? provider : undefined;
|
|
182
182
|
}
|
|
183
|
-
function compatExternals(webpackExternals) {
|
|
183
|
+
function compatExternals(webpackExternals, externalsType) {
|
|
184
184
|
if (!webpackExternals) {
|
|
185
185
|
return undefined;
|
|
186
186
|
}
|
|
@@ -188,7 +188,7 @@ function compatExternals(webpackExternals) {
|
|
|
188
188
|
switch (typeof webpackExternals) {
|
|
189
189
|
case "string": {
|
|
190
190
|
// Single string external: "lodash" -> { "lodash": "lodash" }
|
|
191
|
-
externals[webpackExternals] = webpackExternals;
|
|
191
|
+
externals[webpackExternals] = compatExternalValue(webpackExternals, externalsType);
|
|
192
192
|
break;
|
|
193
193
|
}
|
|
194
194
|
case "object": {
|
|
@@ -196,10 +196,10 @@ function compatExternals(webpackExternals) {
|
|
|
196
196
|
// Array of externals: ["lodash", "react"] -> { "lodash": "lodash", "react": "react" }
|
|
197
197
|
externals = webpackExternals.reduce((acc, external) => {
|
|
198
198
|
if (typeof external === "string") {
|
|
199
|
-
acc[external] = external;
|
|
199
|
+
acc[external] = compatExternalValue(external, externalsType);
|
|
200
200
|
}
|
|
201
201
|
else if (typeof external === "object" && external !== null) {
|
|
202
|
-
Object.assign(acc, compatExternals(external));
|
|
202
|
+
Object.assign(acc, compatExternals(external, externalsType));
|
|
203
203
|
}
|
|
204
204
|
return acc;
|
|
205
205
|
}, {});
|
|
@@ -228,7 +228,7 @@ function compatExternals(webpackExternals) {
|
|
|
228
228
|
}
|
|
229
229
|
else {
|
|
230
230
|
// Simple string mapping: { "react": "React" }
|
|
231
|
-
externals[key] = value;
|
|
231
|
+
externals[key] = compatExternalValue(value, externalsType);
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
else if (Array.isArray(value)) {
|
|
@@ -255,6 +255,9 @@ function compatExternals(webpackExternals) {
|
|
|
255
255
|
else if (first === "module") {
|
|
256
256
|
externals[key] = `esm ${second}`;
|
|
257
257
|
}
|
|
258
|
+
else if (first === "promise") {
|
|
259
|
+
externals[key] = `promise ${second}`;
|
|
260
|
+
}
|
|
258
261
|
else if (first === "var" ||
|
|
259
262
|
first === "global" ||
|
|
260
263
|
first === "window") {
|
|
@@ -269,11 +272,11 @@ function compatExternals(webpackExternals) {
|
|
|
269
272
|
}
|
|
270
273
|
}
|
|
271
274
|
else {
|
|
272
|
-
externals[key] = value[0] || key;
|
|
275
|
+
externals[key] = compatExternalValue(value[0] || key, externalsType);
|
|
273
276
|
}
|
|
274
277
|
}
|
|
275
278
|
else {
|
|
276
|
-
externals[key] = value[0] || key;
|
|
279
|
+
externals[key] = compatExternalValue(value[0] || key, externalsType);
|
|
277
280
|
}
|
|
278
281
|
}
|
|
279
282
|
else if (typeof value === "object" && value !== null) {
|
|
@@ -285,13 +288,13 @@ function compatExternals(webpackExternals) {
|
|
|
285
288
|
externals[key] = `commonjs ${val.commonjs}`;
|
|
286
289
|
}
|
|
287
290
|
else if (val.root) {
|
|
288
|
-
externals[key] = val.root;
|
|
291
|
+
externals[key] = compatExternalValue(val.root, externalsType);
|
|
289
292
|
}
|
|
290
293
|
else if (val.amd) {
|
|
291
|
-
externals[key] = val.amd;
|
|
294
|
+
externals[key] = compatExternalValue(val.amd, externalsType);
|
|
292
295
|
}
|
|
293
296
|
else {
|
|
294
|
-
externals[key] = key;
|
|
297
|
+
externals[key] = compatExternalValue(key, externalsType);
|
|
295
298
|
}
|
|
296
299
|
}
|
|
297
300
|
else {
|
|
@@ -301,7 +304,7 @@ function compatExternals(webpackExternals) {
|
|
|
301
304
|
}
|
|
302
305
|
else {
|
|
303
306
|
// Fallback to key name
|
|
304
|
-
externals[key] = key;
|
|
307
|
+
externals[key] = compatExternalValue(key, externalsType);
|
|
305
308
|
}
|
|
306
309
|
});
|
|
307
310
|
}
|
|
@@ -315,6 +318,13 @@ function compatExternals(webpackExternals) {
|
|
|
315
318
|
}
|
|
316
319
|
return externals;
|
|
317
320
|
}
|
|
321
|
+
function compatExternalValue(value, externalsType) {
|
|
322
|
+
if (externalsType === "promise" &&
|
|
323
|
+
!value.match(/^(commonjs|esm|script|promise)\s/)) {
|
|
324
|
+
return `promise ${value}`;
|
|
325
|
+
}
|
|
326
|
+
return value;
|
|
327
|
+
}
|
|
318
328
|
function compatModule(webpackModule) {
|
|
319
329
|
if (!Array.isArray(webpackModule === null || webpackModule === void 0 ? void 0 : webpackModule.rules)) {
|
|
320
330
|
return;
|