@utoo/pack 0.0.1-alpha.15 → 0.0.1-alpha.17
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/binding.d.ts +11 -15
- package/cjs/build.d.ts +3 -1
- package/cjs/build.js +18 -11
- package/cjs/dev.d.ts +3 -1
- package/cjs/dev.js +9 -2
- package/cjs/hmr.js +3 -3
- package/cjs/index.d.ts +14 -2
- package/cjs/index.js +4 -2
- package/cjs/project.d.ts +1 -1
- package/cjs/project.js +0 -2
- package/cjs/types.d.ts +7 -7
- package/cjs/webpackCompat.d.ts +6 -0
- package/cjs/webpackCompat.js +341 -0
- package/esm/binding.d.ts +11 -15
- package/esm/build.d.ts +3 -1
- package/esm/build.js +18 -11
- package/esm/dev.d.ts +3 -1
- package/esm/dev.js +9 -2
- package/esm/hmr.js +3 -3
- package/esm/index.d.ts +14 -2
- package/esm/index.js +6 -2
- package/esm/project.d.ts +1 -1
- package/esm/project.js +0 -2
- package/esm/types.d.ts +7 -7
- package/esm/webpackCompat.d.ts +6 -0
- package/esm/webpackCompat.js +338 -0
- package/package.json +11 -9
package/cjs/binding.d.ts
CHANGED
|
@@ -9,12 +9,6 @@ export declare class ExternalObject<T> {
|
|
|
9
9
|
[K: symbol]: T
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
export interface TransformOutput {
|
|
13
|
-
code: string
|
|
14
|
-
map?: string
|
|
15
|
-
output?: string
|
|
16
|
-
diagnostics: Array<string>
|
|
17
|
-
}
|
|
18
12
|
export interface NapiEndpointConfig {
|
|
19
13
|
|
|
20
14
|
}
|
|
@@ -63,7 +57,7 @@ export interface NapiProjectOptions {
|
|
|
63
57
|
* A map of environment variables which should get injected at compile
|
|
64
58
|
* time.
|
|
65
59
|
*/
|
|
66
|
-
|
|
60
|
+
defineEnv: NapiDefineEnv
|
|
67
61
|
/** The mode in which Next.js is running. */
|
|
68
62
|
dev: boolean
|
|
69
63
|
/** The build id. */
|
|
@@ -88,7 +82,7 @@ export interface NapiPartialProjectOptions {
|
|
|
88
82
|
* A map of environment variables which should get injected at compile
|
|
89
83
|
* time.
|
|
90
84
|
*/
|
|
91
|
-
|
|
85
|
+
defineEnv?: NapiDefineEnv
|
|
92
86
|
/** The mode in which Next.js is running. */
|
|
93
87
|
dev?: boolean
|
|
94
88
|
/** The build id. */
|
|
@@ -136,7 +130,7 @@ export interface NapiEntrypoints {
|
|
|
136
130
|
}
|
|
137
131
|
export declare function projectWriteAllEntrypointsToDisk(project: { __napiType: "Project" }): Promise<TurbopackResult>
|
|
138
132
|
export declare function projectEntrypointsSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
|
139
|
-
export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier:
|
|
133
|
+
export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: RcStr, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
|
140
134
|
export interface HmrIdentifiers {
|
|
141
135
|
identifiers: Array<string>
|
|
142
136
|
}
|
|
@@ -166,16 +160,18 @@ export declare function projectUpdateInfoSubscribe(project: { __napiType: "Proje
|
|
|
166
160
|
export interface StackFrame {
|
|
167
161
|
isServer: boolean
|
|
168
162
|
isInternal?: boolean
|
|
169
|
-
originalFile?:
|
|
170
|
-
file:
|
|
163
|
+
originalFile?: RcStr
|
|
164
|
+
file: RcStr
|
|
165
|
+
/** 1-indexed, unlike source map tokens */
|
|
171
166
|
line?: number
|
|
167
|
+
/** 1-indexed, unlike source map tokens */
|
|
172
168
|
column?: number
|
|
173
|
-
methodName?:
|
|
169
|
+
methodName?: RcStr
|
|
174
170
|
}
|
|
175
171
|
export declare function projectTraceSource(project: { __napiType: "Project" }, frame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>
|
|
176
172
|
export declare function projectGetSourceForAsset(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
|
|
177
|
-
export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath:
|
|
178
|
-
export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath:
|
|
173
|
+
export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: RcStr): Promise<string | null>
|
|
174
|
+
export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: RcStr): string | null
|
|
179
175
|
export declare function rootTaskDispose(rootTask: { __napiType: "RootTask" }): void
|
|
180
176
|
export interface NapiIssue {
|
|
181
177
|
severity: string
|
|
@@ -186,7 +182,7 @@ export interface NapiIssue {
|
|
|
186
182
|
detail?: any
|
|
187
183
|
source?: NapiIssueSource
|
|
188
184
|
documentationLink: string
|
|
189
|
-
|
|
185
|
+
importTraces: any
|
|
190
186
|
}
|
|
191
187
|
export interface NapiIssueSource {
|
|
192
188
|
source: NapiSource
|
package/cjs/build.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { BundleOptions } from "./types";
|
|
2
|
-
|
|
2
|
+
import { WebpackConfig } from "./webpackCompat";
|
|
3
|
+
export declare function build(bundleOptions: BundleOptions, projectPath?: string, rootPath?: string): Promise<void>;
|
|
4
|
+
export declare function build(webpackConfig: WebpackConfig, projectPath?: string, rootPath?: string): Promise<void>;
|
package/cjs/build.js
CHANGED
|
@@ -4,27 +4,34 @@ exports.build = build;
|
|
|
4
4
|
const nanoid_1 = require("nanoid");
|
|
5
5
|
const project_1 = require("./project");
|
|
6
6
|
const util_1 = require("./util");
|
|
7
|
+
const webpackCompat_1 = require("./webpackCompat");
|
|
7
8
|
const xcodeProfile_1 = require("./xcodeProfile");
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
function build(options, projectPath, rootPath) {
|
|
10
|
+
const bundleOptions = options.compatMode
|
|
11
|
+
? (0, webpackCompat_1.compatOptionsFromWebpack)(options)
|
|
12
|
+
: options;
|
|
13
|
+
return buildInternal(bundleOptions, projectPath, rootPath);
|
|
14
|
+
}
|
|
15
|
+
async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
16
|
+
var _a, _b, _c;
|
|
10
17
|
(0, util_1.blockStdout)();
|
|
11
18
|
if (process.env.XCODE_PROFILE) {
|
|
12
19
|
await (0, xcodeProfile_1.xcodeProfilingReady)();
|
|
13
20
|
}
|
|
14
21
|
const createProject = (0, project_1.projectFactory)();
|
|
15
22
|
const project = await createProject({
|
|
16
|
-
processEnv: (_a =
|
|
17
|
-
|
|
18
|
-
config:
|
|
19
|
-
dev: (_b =
|
|
20
|
-
optionDefineEnv:
|
|
23
|
+
processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
|
|
24
|
+
defineEnv: (0, util_1.createDefineEnv)({
|
|
25
|
+
config: bundleOptions.config,
|
|
26
|
+
dev: (_b = bundleOptions.dev) !== null && _b !== void 0 ? _b : false,
|
|
27
|
+
optionDefineEnv: bundleOptions.defineEnv,
|
|
21
28
|
}),
|
|
22
|
-
watch:
|
|
29
|
+
watch: {
|
|
23
30
|
enable: false,
|
|
24
31
|
},
|
|
25
|
-
dev: (
|
|
26
|
-
buildId: (0, nanoid_1.nanoid)(),
|
|
27
|
-
config:
|
|
32
|
+
dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
|
|
33
|
+
buildId: bundleOptions.buildId || (0, nanoid_1.nanoid)(),
|
|
34
|
+
config: bundleOptions.config,
|
|
28
35
|
projectPath: projectPath || process.cwd(),
|
|
29
36
|
rootPath: rootPath || projectPath || process.cwd(),
|
|
30
37
|
}, {
|
package/cjs/dev.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import { IncomingMessage, ServerResponse } from "http";
|
|
|
2
2
|
import send from "send";
|
|
3
3
|
import { Duplex, Writable } from "stream";
|
|
4
4
|
import { BundleOptions } from "./types";
|
|
5
|
-
|
|
5
|
+
import { WebpackConfig } from "./webpackCompat";
|
|
6
|
+
export declare function serve(bundleOptions: BundleOptions, projectPath?: string, rootPath?: string, serverOptions?: StartServerOptions): Promise<void>;
|
|
7
|
+
export declare function serve(webpackConfig: WebpackConfig, projectPath?: string, rootPath?: string, serverOptions?: StartServerOptions): Promise<void>;
|
|
6
8
|
export interface SelfSignedCertificate {
|
|
7
9
|
key: string;
|
|
8
10
|
cert: string;
|
package/cjs/dev.js
CHANGED
|
@@ -22,8 +22,15 @@ const url_1 = __importDefault(require("url"));
|
|
|
22
22
|
const hmr_1 = require("./hmr");
|
|
23
23
|
const mkcert_1 = require("./mkcert");
|
|
24
24
|
const util_1 = require("./util");
|
|
25
|
+
const webpackCompat_1 = require("./webpackCompat");
|
|
25
26
|
const xcodeProfile_1 = require("./xcodeProfile");
|
|
26
|
-
|
|
27
|
+
function serve(options, projectPath, rootPath, serverOptions) {
|
|
28
|
+
const bundleOptions = options.compatMode
|
|
29
|
+
? (0, webpackCompat_1.compatOptionsFromWebpack)(options)
|
|
30
|
+
: options;
|
|
31
|
+
return serveInternal(bundleOptions, projectPath, rootPath, serverOptions);
|
|
32
|
+
}
|
|
33
|
+
async function serveInternal(options, projectPath, rootPath, serverOptions) {
|
|
27
34
|
(0, util_1.blockStdout)();
|
|
28
35
|
if (process.env.XCODE_PROFILE) {
|
|
29
36
|
await (0, xcodeProfile_1.xcodeProfilingReady)();
|
|
@@ -35,7 +42,7 @@ async function serve(options, projectPath, rootPath, serverOptions) {
|
|
|
35
42
|
selfSignedCertificate: (serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.https)
|
|
36
43
|
? await (0, mkcert_1.createSelfSignedCertificate)((serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.hostname) || "localhost")
|
|
37
44
|
: undefined,
|
|
38
|
-
}, options, projectPath, rootPath);
|
|
45
|
+
}, options, projectPath || process.cwd(), rootPath);
|
|
39
46
|
}
|
|
40
47
|
async function startServer(serverOptions, bundleOptions, projectPath, rootPath) {
|
|
41
48
|
let { port, hostname, selfSignedCertificate } = serverOptions;
|
package/cjs/hmr.js
CHANGED
|
@@ -17,16 +17,16 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
|
17
17
|
const createProject = (0, project_1.projectFactory)();
|
|
18
18
|
const project = await createProject({
|
|
19
19
|
processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
|
|
20
|
-
|
|
20
|
+
defineEnv: (0, util_1.createDefineEnv)({
|
|
21
21
|
config: bundleOptions.config,
|
|
22
22
|
dev: true,
|
|
23
|
-
optionDefineEnv: bundleOptions.
|
|
23
|
+
optionDefineEnv: bundleOptions.defineEnv,
|
|
24
24
|
}),
|
|
25
25
|
watch: {
|
|
26
26
|
enable: true,
|
|
27
27
|
},
|
|
28
28
|
dev: true,
|
|
29
|
-
buildId: (0, nanoid_1.nanoid)(),
|
|
29
|
+
buildId: bundleOptions.buildId || (0, nanoid_1.nanoid)(),
|
|
30
30
|
config: {
|
|
31
31
|
...bundleOptions.config,
|
|
32
32
|
mode: "development",
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { build } from "./build";
|
|
2
|
+
import { serve } from "./dev";
|
|
3
|
+
import * as webpackCompat from "./webpackCompat";
|
|
4
|
+
export { build };
|
|
5
|
+
export { serve };
|
|
6
|
+
declare const utoopack: {
|
|
7
|
+
build: typeof build;
|
|
8
|
+
serve: typeof serve;
|
|
9
|
+
};
|
|
10
|
+
export default utoopack;
|
|
11
|
+
export type WebpackConfig = webpackCompat.WebpackConfig;
|
|
12
|
+
declare namespace utoopack {
|
|
13
|
+
type WebpackConfig = webpackCompat.WebpackConfig;
|
|
14
|
+
}
|
package/cjs/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serve = exports.build = void 0;
|
|
4
|
-
|
|
4
|
+
const build_1 = require("./build");
|
|
5
5
|
Object.defineProperty(exports, "build", { enumerable: true, get: function () { return build_1.build; } });
|
|
6
|
-
|
|
6
|
+
const dev_1 = require("./dev");
|
|
7
7
|
Object.defineProperty(exports, "serve", { enumerable: true, get: function () { return dev_1.serve; } });
|
|
8
|
+
const utoopack = { build: build_1.build, serve: dev_1.serve };
|
|
9
|
+
exports.default = utoopack;
|
package/cjs/project.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare class TurbopackInternalError extends Error {
|
|
|
5
5
|
name: string;
|
|
6
6
|
constructor(cause: Error);
|
|
7
7
|
}
|
|
8
|
-
export declare function projectFactory(): (options: ProjectOptions
|
|
8
|
+
export declare function projectFactory(): (options: Required<ProjectOptions>, turboEngineOptions: binding.NapiTurboEngineOptions) => Promise<{
|
|
9
9
|
readonly _nativeProject: {
|
|
10
10
|
__napiType: "Project";
|
|
11
11
|
};
|
package/cjs/project.js
CHANGED
|
@@ -35,7 +35,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.TurbopackInternalError = void 0;
|
|
37
37
|
exports.projectFactory = projectFactory;
|
|
38
|
-
const nanoid_1 = require("nanoid");
|
|
39
38
|
const util_1 = require("util");
|
|
40
39
|
const binding = __importStar(require("./binding"));
|
|
41
40
|
const util_2 = require("./util");
|
|
@@ -91,7 +90,6 @@ function ensureLoadersHaveSerializableOptions(turbopackRules) {
|
|
|
91
90
|
async function serializeConfig(config) {
|
|
92
91
|
var _a, _b;
|
|
93
92
|
let configSerializable = { ...config };
|
|
94
|
-
configSerializable.generateBuildId = () => (0, nanoid_1.nanoid)();
|
|
95
93
|
if ((_a = configSerializable.module) === null || _a === void 0 ? void 0 : _a.rules) {
|
|
96
94
|
ensureLoadersHaveSerializableOptions(configSerializable.module.rules);
|
|
97
95
|
}
|
package/cjs/types.d.ts
CHANGED
|
@@ -65,7 +65,6 @@ export interface DefineEnv {
|
|
|
65
65
|
}
|
|
66
66
|
export interface ExperimentalConfig {
|
|
67
67
|
}
|
|
68
|
-
export type TurbopackRuleConfigItemOrShortcut = TurbopackRuleConfigItem;
|
|
69
68
|
export type TurbopackRuleConfigItem = TurbopackRuleConfigItemOptions | {
|
|
70
69
|
[condition: string]: TurbopackRuleConfigItem;
|
|
71
70
|
} | false;
|
|
@@ -81,7 +80,7 @@ export type TurbopackRuleConfigItemOptions = {
|
|
|
81
80
|
as?: string;
|
|
82
81
|
};
|
|
83
82
|
export interface ModuleOptions {
|
|
84
|
-
rules?: Record<string,
|
|
83
|
+
rules?: Record<string, TurbopackRuleConfigItem>;
|
|
85
84
|
}
|
|
86
85
|
export interface ResolveOptions {
|
|
87
86
|
alias?: Record<string, string | string[] | Record<string, string | string[]>>;
|
|
@@ -152,6 +151,7 @@ export interface ConfigComplete {
|
|
|
152
151
|
images?: {
|
|
153
152
|
inlineLimit?: number;
|
|
154
153
|
};
|
|
154
|
+
stats?: boolean;
|
|
155
155
|
experimental?: ExperimentalConfig;
|
|
156
156
|
persistentCaching?: boolean;
|
|
157
157
|
cacheHandler?: string;
|
|
@@ -205,23 +205,23 @@ export interface ProjectOptions {
|
|
|
205
205
|
/**
|
|
206
206
|
* A map of environment variables to use when compiling code.
|
|
207
207
|
*/
|
|
208
|
-
processEnv
|
|
209
|
-
|
|
208
|
+
processEnv?: Record<string, string>;
|
|
209
|
+
defineEnv?: DefineEnv;
|
|
210
210
|
/**
|
|
211
211
|
* Whether to watch the filesystem for file changes.
|
|
212
212
|
*/
|
|
213
|
-
watch
|
|
213
|
+
watch?: {
|
|
214
214
|
enable: boolean;
|
|
215
215
|
pollIntervalMs?: number;
|
|
216
216
|
};
|
|
217
217
|
/**
|
|
218
218
|
* The mode of utoo-pack.
|
|
219
219
|
*/
|
|
220
|
-
dev
|
|
220
|
+
dev?: boolean;
|
|
221
221
|
/**
|
|
222
222
|
* The build id.
|
|
223
223
|
*/
|
|
224
|
-
buildId
|
|
224
|
+
buildId?: string;
|
|
225
225
|
}
|
|
226
226
|
export type BundleOptions = Omit<ProjectOptions, "rootPath" | "projectPath">;
|
|
227
227
|
export interface Project {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type webpack from "webpack";
|
|
2
|
+
import { BundleOptions } from "./types";
|
|
3
|
+
export type WebpackConfig = Pick<webpack.Configuration, "name" | "entry" | "mode" | "module" | "resolve" | "externals" | "output" | "target" | "devtool" | "optimization" | "plugins" | "stats"> & {
|
|
4
|
+
compatMode: true;
|
|
5
|
+
};
|
|
6
|
+
export declare function compatOptionsFromWebpack(webpackConfig: WebpackConfig): BundleOptions;
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compatOptionsFromWebpack = compatOptionsFromWebpack;
|
|
4
|
+
function compatOptionsFromWebpack(webpackConfig) {
|
|
5
|
+
const { entry, mode, module, resolve, externals, output, target, devtool, optimization, plugins, stats, } = webpackConfig;
|
|
6
|
+
return {
|
|
7
|
+
config: {
|
|
8
|
+
entry: compatEntry(entry),
|
|
9
|
+
mode: compatMode(mode),
|
|
10
|
+
module: compatModule(module),
|
|
11
|
+
resolve: compatResolve(resolve),
|
|
12
|
+
externals: compatExternals(externals),
|
|
13
|
+
output: compatOutput(output),
|
|
14
|
+
target: compatTarget(target),
|
|
15
|
+
sourceMaps: compatSourceMaps(devtool),
|
|
16
|
+
optimization: compatOptimization(optimization),
|
|
17
|
+
define: compatFromWebpackPlugin(plugins, compatDefine),
|
|
18
|
+
stats: compatStats(stats),
|
|
19
|
+
},
|
|
20
|
+
buildId: webpackConfig.name,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function compatMode(webpackMode) {
|
|
24
|
+
return webpackMode
|
|
25
|
+
? webpackMode === "none"
|
|
26
|
+
? "production"
|
|
27
|
+
: webpackMode
|
|
28
|
+
: "production";
|
|
29
|
+
}
|
|
30
|
+
function compatEntry(webpackEntry) {
|
|
31
|
+
const entry = [];
|
|
32
|
+
switch (typeof webpackEntry) {
|
|
33
|
+
case "string":
|
|
34
|
+
entry.push({ import: webpackEntry });
|
|
35
|
+
break;
|
|
36
|
+
case "object":
|
|
37
|
+
if (Array.isArray(webpackEntry)) {
|
|
38
|
+
webpackEntry.forEach((e) => entry.push({
|
|
39
|
+
import: e,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
Object.entries(webpackEntry).forEach(([k, v]) => {
|
|
44
|
+
var _a;
|
|
45
|
+
switch (typeof v) {
|
|
46
|
+
case "string":
|
|
47
|
+
entry.push({ name: k, import: v });
|
|
48
|
+
break;
|
|
49
|
+
case "object":
|
|
50
|
+
if (!Array.isArray(v)) {
|
|
51
|
+
switch (typeof v.import) {
|
|
52
|
+
case "string":
|
|
53
|
+
entry.push({
|
|
54
|
+
name: k,
|
|
55
|
+
import: v.import,
|
|
56
|
+
library: ((_a = v.library) === null || _a === void 0 ? void 0 : _a.type) === "umd"
|
|
57
|
+
? {
|
|
58
|
+
name: typeof v.library.name === "string"
|
|
59
|
+
? v.library.name
|
|
60
|
+
: undefined,
|
|
61
|
+
export: typeof v.library.export === "string"
|
|
62
|
+
? [v.library.export]
|
|
63
|
+
: v.library.export,
|
|
64
|
+
}
|
|
65
|
+
: undefined,
|
|
66
|
+
});
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw "multi entry items for one entry not supported yet";
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
throw "non string and non object entry path not supported yet";
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
case "function":
|
|
83
|
+
throw "functional entry not supported yet";
|
|
84
|
+
default:
|
|
85
|
+
throw "entry config not compatible now";
|
|
86
|
+
}
|
|
87
|
+
return entry;
|
|
88
|
+
}
|
|
89
|
+
function compatFromWebpackPlugin(webpackPlugins, picker) {
|
|
90
|
+
const plugin = webpackPlugins === null || webpackPlugins === void 0 ? void 0 : webpackPlugins.find((p) => p && typeof p === "object" && p.constructor.name === picker.pluginName);
|
|
91
|
+
return picker(plugin);
|
|
92
|
+
}
|
|
93
|
+
compatDefine.pluginName = "DefinePlugin";
|
|
94
|
+
function compatDefine(maybeWebpackPluginInstance) {
|
|
95
|
+
return maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
|
|
96
|
+
}
|
|
97
|
+
function compatExternals(webpackExternals) {
|
|
98
|
+
if (!webpackExternals) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
let externals = {};
|
|
102
|
+
switch (typeof webpackExternals) {
|
|
103
|
+
case "string": {
|
|
104
|
+
// Single string external: "lodash" -> { "lodash": "lodash" }
|
|
105
|
+
externals[webpackExternals] = webpackExternals;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case "object": {
|
|
109
|
+
if (Array.isArray(webpackExternals)) {
|
|
110
|
+
// Array of externals: ["lodash", "react"] -> { "lodash": "lodash", "react": "react" }
|
|
111
|
+
externals = webpackExternals.reduce((acc, external) => {
|
|
112
|
+
if (typeof external === "string") {
|
|
113
|
+
acc[external] = external;
|
|
114
|
+
}
|
|
115
|
+
else if (typeof external === "object" && external !== null) {
|
|
116
|
+
Object.assign(acc, compatExternals(external));
|
|
117
|
+
}
|
|
118
|
+
return acc;
|
|
119
|
+
}, {});
|
|
120
|
+
}
|
|
121
|
+
else if (webpackExternals instanceof RegExp) {
|
|
122
|
+
throw "regex external not supported yet";
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
if ("byLayer" in webpackExternals) {
|
|
126
|
+
throw "by layer external item not supported yet";
|
|
127
|
+
}
|
|
128
|
+
Object.entries(webpackExternals).forEach(([key, value]) => {
|
|
129
|
+
if (typeof value === "string") {
|
|
130
|
+
// Check if it's a script type with shorthand syntax: "global@https://example.com/script.js"
|
|
131
|
+
if (value.includes("@") &&
|
|
132
|
+
(value.startsWith("script ") || value.includes("://"))) {
|
|
133
|
+
const match = value.match(/^(?:script\s+)?(.+?)@(.+)$/);
|
|
134
|
+
if (match) {
|
|
135
|
+
const [, globalName, scriptUrl] = match;
|
|
136
|
+
// Use utoo-pack string format: "script globalName@url"
|
|
137
|
+
externals[key] = `script ${globalName}@${scriptUrl}`;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
externals[key] = value;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// Simple string mapping: { "react": "React" }
|
|
145
|
+
externals[key] = value;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (Array.isArray(value)) {
|
|
149
|
+
// Array format handling
|
|
150
|
+
if (value.length >= 2) {
|
|
151
|
+
const [first, second] = value;
|
|
152
|
+
// Check if it's a script type array: ["https://example.com/script.js", "GlobalName"]
|
|
153
|
+
if (typeof first === "string" &&
|
|
154
|
+
first.includes("://") &&
|
|
155
|
+
typeof second === "string") {
|
|
156
|
+
// Use utoo-pack object format for script
|
|
157
|
+
externals[key] = {
|
|
158
|
+
root: second,
|
|
159
|
+
type: "script",
|
|
160
|
+
script: first,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
else if (typeof first === "string" &&
|
|
164
|
+
typeof second === "string") {
|
|
165
|
+
// Handle type prefix formats
|
|
166
|
+
if (first.startsWith("commonjs")) {
|
|
167
|
+
externals[key] = `commonjs ${second}`;
|
|
168
|
+
}
|
|
169
|
+
else if (first === "module") {
|
|
170
|
+
externals[key] = `esm ${second}`;
|
|
171
|
+
}
|
|
172
|
+
else if (first === "var" ||
|
|
173
|
+
first === "global" ||
|
|
174
|
+
first === "window") {
|
|
175
|
+
externals[key] = second;
|
|
176
|
+
}
|
|
177
|
+
else if (first === "script") {
|
|
178
|
+
// Script type without URL in array format - treat as regular script prefix
|
|
179
|
+
externals[key] = `script ${second}`;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
externals[key] = `${first} ${second}`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
externals[key] = value[0] || key;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
externals[key] = value[0] || key;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else if (typeof value === "object" && value !== null) {
|
|
194
|
+
// Object format: handle complex configurations
|
|
195
|
+
if ("root" in value || "commonjs" in value || "amd" in value) {
|
|
196
|
+
// Standard webpack externals object format
|
|
197
|
+
if (value.commonjs) {
|
|
198
|
+
externals[key] = `commonjs ${value.commonjs}`;
|
|
199
|
+
}
|
|
200
|
+
else if (value.root) {
|
|
201
|
+
externals[key] = value.root;
|
|
202
|
+
}
|
|
203
|
+
else if (value.amd) {
|
|
204
|
+
externals[key] = value.amd;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
externals[key] = key;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
// Treat as utoo-pack specific configuration (might already be in correct format)
|
|
212
|
+
externals[key] = value;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
// Fallback to key name
|
|
217
|
+
externals[key] = key;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case "function": {
|
|
224
|
+
throw "functional external not supported yet";
|
|
225
|
+
}
|
|
226
|
+
default:
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
return externals;
|
|
230
|
+
}
|
|
231
|
+
function compatModule(webpackModule) {
|
|
232
|
+
if (!Array.isArray(webpackModule === null || webpackModule === void 0 ? void 0 : webpackModule.rules)) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const moduleRules = {
|
|
236
|
+
rules: webpackModule.rules.reduce((acc, cur) => {
|
|
237
|
+
var _a, _b;
|
|
238
|
+
switch (typeof cur) {
|
|
239
|
+
case "object":
|
|
240
|
+
if (cur) {
|
|
241
|
+
let condition = (_b = (_a = cur.test) === null || _a === void 0 ? void 0 : _a.toString().match(/(\.\w+)/)) === null || _b === void 0 ? void 0 : _b[1];
|
|
242
|
+
if (condition) {
|
|
243
|
+
Object.assign(acc, {
|
|
244
|
+
["*" + condition]: {
|
|
245
|
+
loaders: typeof cur.use === "string"
|
|
246
|
+
? [cur.use]
|
|
247
|
+
: typeof (cur === null || cur === void 0 ? void 0 : cur.use) === "object"
|
|
248
|
+
? Array.isArray(cur.use)
|
|
249
|
+
? cur.use.map((use) => typeof use === "string"
|
|
250
|
+
? { loader: use, options: {} }
|
|
251
|
+
: {
|
|
252
|
+
loader: use.loader,
|
|
253
|
+
options: use.options || {},
|
|
254
|
+
})
|
|
255
|
+
: [
|
|
256
|
+
{
|
|
257
|
+
loader: cur.loader,
|
|
258
|
+
options: cur.options || {},
|
|
259
|
+
},
|
|
260
|
+
]
|
|
261
|
+
: [],
|
|
262
|
+
as: "*.js",
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
break;
|
|
268
|
+
default:
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
return acc;
|
|
272
|
+
}, {}),
|
|
273
|
+
};
|
|
274
|
+
return moduleRules;
|
|
275
|
+
}
|
|
276
|
+
function compatResolve(webpackResolve) {
|
|
277
|
+
if (!webpackResolve) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const { alias, extensions } = webpackResolve;
|
|
281
|
+
return {
|
|
282
|
+
alias: alias
|
|
283
|
+
? Array.isArray(alias)
|
|
284
|
+
? alias.reduce((acc, cur) => Object.assign(acc, { [cur.name]: cur.alias }), {})
|
|
285
|
+
: Object.entries(alias).reduce((acc, [k, v]) => {
|
|
286
|
+
if (typeof v === "string") {
|
|
287
|
+
Object.assign(acc, { [k]: v });
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
throw "non string alias value not supported yet";
|
|
291
|
+
}
|
|
292
|
+
return acc;
|
|
293
|
+
}, {})
|
|
294
|
+
: undefined,
|
|
295
|
+
extensions,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function compatOutput(webpackOutput) {
|
|
299
|
+
if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename) && typeof webpackOutput.filename !== "string") {
|
|
300
|
+
throw "non string output filename not supported yet";
|
|
301
|
+
}
|
|
302
|
+
if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename) &&
|
|
303
|
+
typeof webpackOutput.chunkFilename !== "string") {
|
|
304
|
+
throw "non string output chunkFilename not supported yet";
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
path: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.path,
|
|
308
|
+
filename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename,
|
|
309
|
+
chunkFilename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename,
|
|
310
|
+
clean: !!(webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.clean),
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function compatTarget(webpackTarget) {
|
|
314
|
+
return webpackTarget
|
|
315
|
+
? Array.isArray(webpackTarget)
|
|
316
|
+
? webpackTarget.join(" ")
|
|
317
|
+
: webpackTarget
|
|
318
|
+
: undefined;
|
|
319
|
+
}
|
|
320
|
+
function compatSourceMaps(webpackSourceMaps) {
|
|
321
|
+
return !!webpackSourceMaps;
|
|
322
|
+
}
|
|
323
|
+
function compatOptimization(webpackOptimization) {
|
|
324
|
+
if (!webpackOptimization) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const { moduleIds, minimize,
|
|
328
|
+
// TODO: concatenateModules to be supported, need to upgrade to next.js@15.4
|
|
329
|
+
} = webpackOptimization;
|
|
330
|
+
return {
|
|
331
|
+
moduleIds: moduleIds === "named"
|
|
332
|
+
? "named"
|
|
333
|
+
: moduleIds === "deterministic"
|
|
334
|
+
? "deterministic"
|
|
335
|
+
: undefined,
|
|
336
|
+
minify: minimize,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
function compatStats(webpackStats) {
|
|
340
|
+
return !!webpackStats;
|
|
341
|
+
}
|