@utoo/pack 1.1.2 → 1.1.3
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/README.md +2 -2
- package/cjs/index.d.ts +7 -6
- package/cjs/index.js +6 -5
- package/config_schema.json +1 -1
- package/esm/index.d.ts +7 -6
- package/esm/index.js +6 -5
- package/package.json +19 -18
- package/cjs/build.d.ts +0 -3
- package/cjs/build.js +0 -82
- package/cjs/dev.d.ts +0 -43
- package/cjs/dev.js +0 -376
- package/cjs/find-root.d.ts +0 -4
- package/cjs/find-root.js +0 -75
- package/cjs/hmr.d.ts +0 -80
- package/cjs/hmr.js +0 -286
- package/cjs/loaderWorkerPool.d.ts +0 -1
- package/cjs/loaderWorkerPool.js +0 -35
- package/cjs/mkcert.d.ts +0 -7
- package/cjs/mkcert.js +0 -183
- package/cjs/project.d.ts +0 -43
- package/cjs/project.js +0 -285
- package/cjs/types.d.ts +0 -300
- package/cjs/types.js +0 -2
- package/cjs/util.d.ts +0 -19
- package/cjs/util.js +0 -155
- package/cjs/webpackCompat.d.ts +0 -7
- package/cjs/webpackCompat.js +0 -408
- package/cjs/xcodeProfile.d.ts +0 -1
- package/cjs/xcodeProfile.js +0 -16
- package/esm/build.d.ts +0 -3
- package/esm/build.js +0 -79
- package/esm/dev.d.ts +0 -43
- package/esm/dev.js +0 -360
- package/esm/find-root.d.ts +0 -4
- package/esm/find-root.js +0 -66
- package/esm/hmr.d.ts +0 -80
- package/esm/hmr.js +0 -279
- package/esm/loaderWorkerPool.d.ts +0 -1
- package/esm/loaderWorkerPool.js +0 -32
- package/esm/mkcert.d.ts +0 -7
- package/esm/mkcert.js +0 -176
- package/esm/project.d.ts +0 -43
- package/esm/project.js +0 -247
- package/esm/types.d.ts +0 -300
- package/esm/types.js +0 -1
- package/esm/util.d.ts +0 -19
- package/esm/util.js +0 -141
- package/esm/webpackCompat.d.ts +0 -7
- package/esm/webpackCompat.js +0 -401
- package/esm/xcodeProfile.d.ts +0 -1
- package/esm/xcodeProfile.js +0 -13
package/cjs/util.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ModuleBuildError = void 0;
|
|
7
|
-
exports.processIssues = processIssues;
|
|
8
|
-
exports.isWellKnownError = isWellKnownError;
|
|
9
|
-
exports.rustifyEnv = rustifyEnv;
|
|
10
|
-
exports.createDefineEnv = createDefineEnv;
|
|
11
|
-
exports.debounce = debounce;
|
|
12
|
-
exports.blockStdout = blockStdout;
|
|
13
|
-
exports.getPackPath = getPackPath;
|
|
14
|
-
const pack_shared_1 = require("@utoo/pack-shared");
|
|
15
|
-
const path_1 = __importDefault(require("path"));
|
|
16
|
-
class ModuleBuildError extends Error {
|
|
17
|
-
constructor() {
|
|
18
|
-
super(...arguments);
|
|
19
|
-
this.name = "ModuleBuildError";
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.ModuleBuildError = ModuleBuildError;
|
|
23
|
-
function processIssues(result, throwIssue, logErrors) {
|
|
24
|
-
const relevantIssues = new Set();
|
|
25
|
-
for (const issue of result.issues) {
|
|
26
|
-
if (issue.severity !== "error" &&
|
|
27
|
-
issue.severity !== "fatal" &&
|
|
28
|
-
issue.severity !== "warning")
|
|
29
|
-
continue;
|
|
30
|
-
if (issue.severity !== "warning") {
|
|
31
|
-
if (throwIssue) {
|
|
32
|
-
const formatted = (0, pack_shared_1.formatIssue)(issue);
|
|
33
|
-
relevantIssues.add(formatted);
|
|
34
|
-
}
|
|
35
|
-
// if we throw the issue it will most likely get handed and logged elsewhere
|
|
36
|
-
else if (logErrors && isWellKnownError(issue)) {
|
|
37
|
-
const formatted = (0, pack_shared_1.formatIssue)(issue);
|
|
38
|
-
console.error(formatted);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (relevantIssues.size && throwIssue) {
|
|
43
|
-
throw new ModuleBuildError([...relevantIssues].join("\n\n"));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function isWellKnownError(issue) {
|
|
47
|
-
const { title } = issue;
|
|
48
|
-
const formattedTitle = (0, pack_shared_1.renderStyledStringToErrorAnsi)(title);
|
|
49
|
-
// TODO: add more well known errors
|
|
50
|
-
if (formattedTitle.includes("Module not found") ||
|
|
51
|
-
formattedTitle.includes("Unknown module type")) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
function rustifyEnv(env) {
|
|
57
|
-
return Object.entries(env)
|
|
58
|
-
.filter(([_, value]) => value != null)
|
|
59
|
-
.map(([name, value]) => ({
|
|
60
|
-
name,
|
|
61
|
-
value,
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
function createDefineEnv(options) {
|
|
65
|
-
var _a;
|
|
66
|
-
let defineEnv = (_a = options.optionDefineEnv) !== null && _a !== void 0 ? _a : {
|
|
67
|
-
client: [],
|
|
68
|
-
edge: [],
|
|
69
|
-
nodejs: [],
|
|
70
|
-
};
|
|
71
|
-
function getDefineEnv() {
|
|
72
|
-
var _a;
|
|
73
|
-
const envs = {
|
|
74
|
-
"process.env.NODE_ENV": options.dev ? "development" : "production",
|
|
75
|
-
};
|
|
76
|
-
const userDefines = (_a = options.config.define) !== null && _a !== void 0 ? _a : {};
|
|
77
|
-
for (const key in userDefines) {
|
|
78
|
-
envs[key] = userDefines[key];
|
|
79
|
-
}
|
|
80
|
-
// serialize
|
|
81
|
-
const defineEnvStringified = {};
|
|
82
|
-
for (const key in defineEnv) {
|
|
83
|
-
const value = envs[key];
|
|
84
|
-
defineEnvStringified[key] = JSON.stringify(value);
|
|
85
|
-
}
|
|
86
|
-
return defineEnvStringified;
|
|
87
|
-
}
|
|
88
|
-
// TODO: future define envs need to extends for more compiler like server or edge.
|
|
89
|
-
for (const variant of Object.keys(defineEnv)) {
|
|
90
|
-
defineEnv[variant] = rustifyEnv(getDefineEnv());
|
|
91
|
-
}
|
|
92
|
-
return defineEnv;
|
|
93
|
-
}
|
|
94
|
-
function debounce(fn, ms, maxWait = Infinity) {
|
|
95
|
-
let timeoutId;
|
|
96
|
-
// The time the debouncing function was first called during this debounce queue.
|
|
97
|
-
let startTime = 0;
|
|
98
|
-
// The time the debouncing function was last called.
|
|
99
|
-
let lastCall = 0;
|
|
100
|
-
// The arguments and this context of the last call to the debouncing function.
|
|
101
|
-
let args, context;
|
|
102
|
-
// A helper used to that either invokes the debounced function, or
|
|
103
|
-
// reschedules the timer if a more recent call was made.
|
|
104
|
-
function run() {
|
|
105
|
-
const now = Date.now();
|
|
106
|
-
const diff = lastCall + ms - now;
|
|
107
|
-
// If the diff is non-positive, then we've waited at least `ms`
|
|
108
|
-
// milliseconds since the last call. Or if we've waited for longer than the
|
|
109
|
-
// max wait time, we must call the debounced function.
|
|
110
|
-
if (diff <= 0 || startTime + maxWait >= now) {
|
|
111
|
-
// It's important to clear the timeout id before invoking the debounced
|
|
112
|
-
// function, in case the function calls the debouncing function again.
|
|
113
|
-
timeoutId = undefined;
|
|
114
|
-
fn.apply(context, args);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
// Else, a new call was made after the original timer was scheduled. We
|
|
118
|
-
// didn't clear the timeout (doing so is very slow), so now we need to
|
|
119
|
-
// reschedule the timer for the time difference.
|
|
120
|
-
timeoutId = setTimeout(run, diff);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return function (...passedArgs) {
|
|
124
|
-
// The arguments and this context of the most recent call are saved so the
|
|
125
|
-
// debounced function can be invoked with them later.
|
|
126
|
-
args = passedArgs;
|
|
127
|
-
context = this;
|
|
128
|
-
// Instead of constantly clearing and scheduling a timer, we record the
|
|
129
|
-
// time of the last call. If a second call comes in before the timer fires,
|
|
130
|
-
// then we'll reschedule in the run function. Doing this is considerably
|
|
131
|
-
// faster.
|
|
132
|
-
lastCall = Date.now();
|
|
133
|
-
// Only schedule a new timer if we're not currently waiting.
|
|
134
|
-
if (timeoutId === undefined) {
|
|
135
|
-
startTime = lastCall;
|
|
136
|
-
timeoutId = setTimeout(run, ms);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
// ref:
|
|
141
|
-
// https://github.com/vercel/next.js/pull/51883
|
|
142
|
-
function blockStdout() {
|
|
143
|
-
// rust needs stdout to be blocking, otherwise it will throw an error (on macOS at least) when writing a lot of data (logs) to it
|
|
144
|
-
// see https://github.com/napi-rs/napi-rs/issues/1630
|
|
145
|
-
// and https://github.com/nodejs/node/blob/main/doc/api/process.md#a-note-on-process-io
|
|
146
|
-
if (process.stdout._handle != null) {
|
|
147
|
-
process.stdout._handle.setBlocking(true);
|
|
148
|
-
}
|
|
149
|
-
if (process.stderr._handle != null) {
|
|
150
|
-
process.stderr._handle.setBlocking(true);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
function getPackPath() {
|
|
154
|
-
return path_1.default.resolve(__dirname, "..");
|
|
155
|
-
}
|
package/cjs/webpackCompat.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type webpack from "webpack";
|
|
2
|
-
import { BundleOptions } from "./types";
|
|
3
|
-
export declare function readWebpackConfig(projectPath?: string, rootPath?: string): any;
|
|
4
|
-
export type WebpackConfig = Partial<Pick<webpack.Configuration, "name" | "entry" | "mode" | "module" | "resolve" | "externals" | "output" | "target" | "devtool" | "optimization" | "plugins" | "stats">> & {
|
|
5
|
-
webpackMode: true;
|
|
6
|
-
};
|
|
7
|
-
export declare function compatOptionsFromWebpack(webpackConfig: WebpackConfig, projectPath?: string, rootPath?: string): BundleOptions;
|
package/cjs/webpackCompat.js
DELETED
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.readWebpackConfig = readWebpackConfig;
|
|
7
|
-
exports.compatOptionsFromWebpack = compatOptionsFromWebpack;
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
function readWebpackConfig(projectPath, rootPath) {
|
|
10
|
-
const projectPathOutOfRoot = projectPath === undefined
|
|
11
|
-
? process.cwd()
|
|
12
|
-
: path_1.default.join(rootPath !== null && rootPath !== void 0 ? rootPath : "", projectPath);
|
|
13
|
-
const configPath = path_1.default.join(projectPathOutOfRoot, "webpack.config.js");
|
|
14
|
-
return require(configPath);
|
|
15
|
-
}
|
|
16
|
-
function compatOptionsFromWebpack(webpackConfig, projectPath, rootPath) {
|
|
17
|
-
const { entry, mode, module, resolve, externals, output, target, devtool, optimization, plugins, stats, } = webpackConfig.entry
|
|
18
|
-
? webpackConfig
|
|
19
|
-
: readWebpackConfig(projectPath, rootPath);
|
|
20
|
-
return {
|
|
21
|
-
config: {
|
|
22
|
-
entry: compatEntry(entry),
|
|
23
|
-
mode: compatMode(mode),
|
|
24
|
-
module: compatModule(module),
|
|
25
|
-
resolve: compatResolve(resolve),
|
|
26
|
-
externals: compatExternals(externals),
|
|
27
|
-
output: compatOutput(output),
|
|
28
|
-
target: compatTarget(target),
|
|
29
|
-
sourceMaps: compatSourceMaps(devtool),
|
|
30
|
-
optimization: compatOptimization(optimization),
|
|
31
|
-
define: compatFromWebpackPlugin(plugins, compatDefine),
|
|
32
|
-
provider: compatFromWebpackPlugin(plugins, compatProvider),
|
|
33
|
-
stats: compatStats(stats),
|
|
34
|
-
},
|
|
35
|
-
buildId: webpackConfig.name,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function compatMode(webpackMode) {
|
|
39
|
-
return webpackMode
|
|
40
|
-
? webpackMode === "none"
|
|
41
|
-
? "production"
|
|
42
|
-
: webpackMode
|
|
43
|
-
: "production";
|
|
44
|
-
}
|
|
45
|
-
function compatEntry(webpackEntry) {
|
|
46
|
-
const entry = [];
|
|
47
|
-
switch (typeof webpackEntry) {
|
|
48
|
-
case "string":
|
|
49
|
-
entry.push({ import: webpackEntry });
|
|
50
|
-
break;
|
|
51
|
-
case "object":
|
|
52
|
-
if (Array.isArray(webpackEntry)) {
|
|
53
|
-
webpackEntry.forEach((e) => entry.push({
|
|
54
|
-
import: e,
|
|
55
|
-
}));
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
Object.entries(webpackEntry).forEach(([k, v]) => {
|
|
59
|
-
var _a;
|
|
60
|
-
switch (typeof v) {
|
|
61
|
-
case "string":
|
|
62
|
-
entry.push({ name: k, import: v });
|
|
63
|
-
break;
|
|
64
|
-
case "object":
|
|
65
|
-
if (!Array.isArray(v)) {
|
|
66
|
-
switch (typeof v.import) {
|
|
67
|
-
case "string":
|
|
68
|
-
entry.push({
|
|
69
|
-
name: k,
|
|
70
|
-
import: v.import,
|
|
71
|
-
library: ((_a = v.library) === null || _a === void 0 ? void 0 : _a.type) === "umd"
|
|
72
|
-
? {
|
|
73
|
-
name: typeof v.library.name === "string"
|
|
74
|
-
? v.library.name
|
|
75
|
-
: undefined,
|
|
76
|
-
export: typeof v.library.export === "string"
|
|
77
|
-
? [v.library.export]
|
|
78
|
-
: v.library.export,
|
|
79
|
-
}
|
|
80
|
-
: undefined,
|
|
81
|
-
});
|
|
82
|
-
break;
|
|
83
|
-
default:
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
if (v.length === 0) {
|
|
89
|
-
throw "entry value items is empty";
|
|
90
|
-
}
|
|
91
|
-
else if (v.length === 1) {
|
|
92
|
-
entry.push({ name: k, import: v[0] });
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
throw "multi entry items for one entry not supported yet";
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
break;
|
|
99
|
-
default:
|
|
100
|
-
throw "non string and non object entry path not supported yet";
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
break;
|
|
105
|
-
case "function":
|
|
106
|
-
throw "functional entry not supported yet";
|
|
107
|
-
default:
|
|
108
|
-
throw "entry config not compatible now";
|
|
109
|
-
}
|
|
110
|
-
return entry;
|
|
111
|
-
}
|
|
112
|
-
function compatFromWebpackPlugin(webpackPlugins, picker) {
|
|
113
|
-
const plugin = webpackPlugins === null || webpackPlugins === void 0 ? void 0 : webpackPlugins.find((p) => p && typeof p === "object" && p.constructor.name === picker.pluginName);
|
|
114
|
-
return picker(plugin);
|
|
115
|
-
}
|
|
116
|
-
compatDefine.pluginName = "DefinePlugin";
|
|
117
|
-
function compatDefine(maybeWebpackPluginInstance) {
|
|
118
|
-
const definitions = maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
|
|
119
|
-
if (!definitions || typeof definitions !== "object") {
|
|
120
|
-
return definitions;
|
|
121
|
-
}
|
|
122
|
-
const processedDefinitions = {};
|
|
123
|
-
for (const [key, value] of Object.entries(definitions)) {
|
|
124
|
-
if (typeof value === "object" && value !== null) {
|
|
125
|
-
processedDefinitions[key] = JSON.stringify(value);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
processedDefinitions[key] = value;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return processedDefinitions;
|
|
132
|
-
}
|
|
133
|
-
compatProvider.pluginName = "ProvidePlugin";
|
|
134
|
-
function compatProvider(maybeWebpackPluginInstance) {
|
|
135
|
-
const definitions = maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
|
|
136
|
-
if (!definitions || typeof definitions !== "object") {
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
const provider = {};
|
|
140
|
-
for (const [key, value] of Object.entries(definitions)) {
|
|
141
|
-
if (typeof value === "string") {
|
|
142
|
-
// Simple module import: { $: 'jquery' }
|
|
143
|
-
provider[key] = value;
|
|
144
|
-
}
|
|
145
|
-
else if (Array.isArray(value)) {
|
|
146
|
-
if (value.length === 1) {
|
|
147
|
-
// e.g. { process: ['process/browser'] } for default import
|
|
148
|
-
provider[key] = value[0];
|
|
149
|
-
}
|
|
150
|
-
else if (value.length >= 2) {
|
|
151
|
-
// Named export import: { Buffer: ['buffer', 'Buffer'] }
|
|
152
|
-
provider[key] = [value[0], value[1]];
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return Object.keys(provider).length > 0 ? provider : undefined;
|
|
157
|
-
}
|
|
158
|
-
function compatExternals(webpackExternals) {
|
|
159
|
-
if (!webpackExternals) {
|
|
160
|
-
return undefined;
|
|
161
|
-
}
|
|
162
|
-
let externals = {};
|
|
163
|
-
switch (typeof webpackExternals) {
|
|
164
|
-
case "string": {
|
|
165
|
-
// Single string external: "lodash" -> { "lodash": "lodash" }
|
|
166
|
-
externals[webpackExternals] = webpackExternals;
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
case "object": {
|
|
170
|
-
if (Array.isArray(webpackExternals)) {
|
|
171
|
-
// Array of externals: ["lodash", "react"] -> { "lodash": "lodash", "react": "react" }
|
|
172
|
-
externals = webpackExternals.reduce((acc, external) => {
|
|
173
|
-
if (typeof external === "string") {
|
|
174
|
-
acc[external] = external;
|
|
175
|
-
}
|
|
176
|
-
else if (typeof external === "object" && external !== null) {
|
|
177
|
-
Object.assign(acc, compatExternals(external));
|
|
178
|
-
}
|
|
179
|
-
return acc;
|
|
180
|
-
}, {});
|
|
181
|
-
}
|
|
182
|
-
else if (webpackExternals instanceof RegExp) {
|
|
183
|
-
throw "regex external not supported yet";
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
if ("byLayer" in webpackExternals) {
|
|
187
|
-
throw "by layer external item not supported yet";
|
|
188
|
-
}
|
|
189
|
-
Object.entries(webpackExternals).forEach(([key, value]) => {
|
|
190
|
-
if (typeof value === "string") {
|
|
191
|
-
// Check if it's a script type with shorthand syntax: "global@https://example.com/script.js"
|
|
192
|
-
if (value.includes("@") &&
|
|
193
|
-
(value.startsWith("script ") || value.includes("://"))) {
|
|
194
|
-
const match = value.match(/^(?:script\s+)?(.+?)@(.+)$/);
|
|
195
|
-
if (match) {
|
|
196
|
-
const [, globalName, scriptUrl] = match;
|
|
197
|
-
// Use utoo-pack string format: "script globalName@url"
|
|
198
|
-
externals[key] = `script ${globalName}@${scriptUrl}`;
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
externals[key] = value;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
// Simple string mapping: { "react": "React" }
|
|
206
|
-
externals[key] = value;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
else if (Array.isArray(value)) {
|
|
210
|
-
// Array format handling
|
|
211
|
-
if (value.length >= 2) {
|
|
212
|
-
const [first, second] = value;
|
|
213
|
-
// Check if it's a script type array: ["https://example.com/script.js", "GlobalName"]
|
|
214
|
-
if (typeof first === "string" &&
|
|
215
|
-
first.includes("://") &&
|
|
216
|
-
typeof second === "string") {
|
|
217
|
-
// Use utoo-pack object format for script
|
|
218
|
-
externals[key] = {
|
|
219
|
-
root: second,
|
|
220
|
-
type: "script",
|
|
221
|
-
script: first,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
else if (typeof first === "string" &&
|
|
225
|
-
typeof second === "string") {
|
|
226
|
-
// Handle type prefix formats
|
|
227
|
-
if (first.startsWith("commonjs")) {
|
|
228
|
-
externals[key] = `commonjs ${second}`;
|
|
229
|
-
}
|
|
230
|
-
else if (first === "module") {
|
|
231
|
-
externals[key] = `esm ${second}`;
|
|
232
|
-
}
|
|
233
|
-
else if (first === "var" ||
|
|
234
|
-
first === "global" ||
|
|
235
|
-
first === "window") {
|
|
236
|
-
externals[key] = second;
|
|
237
|
-
}
|
|
238
|
-
else if (first === "script") {
|
|
239
|
-
// Script type without URL in array format - treat as regular script prefix
|
|
240
|
-
externals[key] = `script ${second}`;
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
externals[key] = `${first} ${second}`;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
externals[key] = value[0] || key;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
externals[key] = value[0] || key;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
else if (typeof value === "object" && value !== null) {
|
|
255
|
-
// Object format: handle complex configurations
|
|
256
|
-
if ("root" in value || "commonjs" in value || "amd" in value) {
|
|
257
|
-
// Standard webpack externals object format
|
|
258
|
-
if (value.commonjs) {
|
|
259
|
-
externals[key] = `commonjs ${value.commonjs}`;
|
|
260
|
-
}
|
|
261
|
-
else if (value.root) {
|
|
262
|
-
externals[key] = value.root;
|
|
263
|
-
}
|
|
264
|
-
else if (value.amd) {
|
|
265
|
-
externals[key] = value.amd;
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
externals[key] = key;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
// Treat as utoo-pack specific configuration (might already be in correct format)
|
|
273
|
-
externals[key] = value;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
// Fallback to key name
|
|
278
|
-
externals[key] = key;
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
case "function": {
|
|
285
|
-
throw "functional external not supported yet";
|
|
286
|
-
}
|
|
287
|
-
default:
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
return externals;
|
|
291
|
-
}
|
|
292
|
-
function compatModule(webpackModule) {
|
|
293
|
-
if (!Array.isArray(webpackModule === null || webpackModule === void 0 ? void 0 : webpackModule.rules)) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const moduleRules = {
|
|
297
|
-
rules: webpackModule.rules.reduce((acc, cur) => {
|
|
298
|
-
var _a, _b;
|
|
299
|
-
switch (typeof cur) {
|
|
300
|
-
case "object":
|
|
301
|
-
if (cur) {
|
|
302
|
-
let condition = (_b = (_a = cur.test) === null || _a === void 0 ? void 0 : _a.toString().match(/(\.\w+)/)) === null || _b === void 0 ? void 0 : _b[1];
|
|
303
|
-
if (condition) {
|
|
304
|
-
Object.assign(acc, {
|
|
305
|
-
["*" + condition]: {
|
|
306
|
-
loaders: typeof cur.use === "string"
|
|
307
|
-
? [cur.use]
|
|
308
|
-
: typeof (cur === null || cur === void 0 ? void 0 : cur.use) === "object"
|
|
309
|
-
? Array.isArray(cur.use)
|
|
310
|
-
? cur.use.map((use) => typeof use === "string"
|
|
311
|
-
? { loader: use, options: {} }
|
|
312
|
-
: {
|
|
313
|
-
loader: use.loader,
|
|
314
|
-
options: use.options || {},
|
|
315
|
-
})
|
|
316
|
-
: [
|
|
317
|
-
{
|
|
318
|
-
loader: cur.loader,
|
|
319
|
-
options: cur.options || {},
|
|
320
|
-
},
|
|
321
|
-
]
|
|
322
|
-
: [],
|
|
323
|
-
as: "*.js",
|
|
324
|
-
},
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
break;
|
|
329
|
-
default:
|
|
330
|
-
break;
|
|
331
|
-
}
|
|
332
|
-
return acc;
|
|
333
|
-
}, {}),
|
|
334
|
-
};
|
|
335
|
-
return moduleRules;
|
|
336
|
-
}
|
|
337
|
-
function compatResolve(webpackResolve) {
|
|
338
|
-
if (!webpackResolve) {
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
const { alias, extensions } = webpackResolve;
|
|
342
|
-
return {
|
|
343
|
-
alias: alias
|
|
344
|
-
? Array.isArray(alias)
|
|
345
|
-
? alias.reduce((acc, cur) => Object.assign(acc, { [cur.name]: cur.alias }), {})
|
|
346
|
-
: Object.entries(alias).reduce((acc, [k, v]) => {
|
|
347
|
-
if (typeof v === "string") {
|
|
348
|
-
// Handle alias keys ending with $ by removing the $
|
|
349
|
-
const aliasKey = k.endsWith("$") ? k.slice(0, -1) : k;
|
|
350
|
-
Object.assign(acc, { [aliasKey]: v });
|
|
351
|
-
}
|
|
352
|
-
else {
|
|
353
|
-
throw "non string alias value not supported yet";
|
|
354
|
-
}
|
|
355
|
-
return acc;
|
|
356
|
-
}, {})
|
|
357
|
-
: undefined,
|
|
358
|
-
extensions,
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
function compatOutput(webpackOutput) {
|
|
362
|
-
if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename) && typeof webpackOutput.filename !== "string") {
|
|
363
|
-
throw "non string output filename not supported yet";
|
|
364
|
-
}
|
|
365
|
-
if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename) &&
|
|
366
|
-
typeof webpackOutput.chunkFilename !== "string") {
|
|
367
|
-
throw "non string output chunkFilename not supported yet";
|
|
368
|
-
}
|
|
369
|
-
if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.publicPath) &&
|
|
370
|
-
typeof webpackOutput.publicPath !== "string") {
|
|
371
|
-
throw "non string output publicPath not supported yet";
|
|
372
|
-
}
|
|
373
|
-
return {
|
|
374
|
-
path: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.path,
|
|
375
|
-
filename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename,
|
|
376
|
-
chunkFilename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename,
|
|
377
|
-
clean: !!(webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.clean),
|
|
378
|
-
publicPath: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.publicPath,
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
function compatTarget(webpackTarget) {
|
|
382
|
-
return webpackTarget
|
|
383
|
-
? Array.isArray(webpackTarget)
|
|
384
|
-
? webpackTarget.join(" ")
|
|
385
|
-
: webpackTarget
|
|
386
|
-
: undefined;
|
|
387
|
-
}
|
|
388
|
-
function compatSourceMaps(webpackSourceMaps) {
|
|
389
|
-
return !!webpackSourceMaps;
|
|
390
|
-
}
|
|
391
|
-
function compatOptimization(webpackOptimization) {
|
|
392
|
-
if (!webpackOptimization) {
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
const { moduleIds, minimize, concatenateModules } = webpackOptimization;
|
|
396
|
-
return {
|
|
397
|
-
moduleIds: moduleIds === "named"
|
|
398
|
-
? "named"
|
|
399
|
-
: moduleIds === "deterministic"
|
|
400
|
-
? "deterministic"
|
|
401
|
-
: undefined,
|
|
402
|
-
minify: minimize,
|
|
403
|
-
concatenateModules,
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
function compatStats(webpackStats) {
|
|
407
|
-
return !!webpackStats;
|
|
408
|
-
}
|
package/cjs/xcodeProfile.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function xcodeProfilingReady(): Promise<void>;
|
package/cjs/xcodeProfile.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.xcodeProfilingReady = xcodeProfilingReady;
|
|
4
|
-
async function xcodeProfilingReady() {
|
|
5
|
-
await new Promise((resolve) => {
|
|
6
|
-
const readline = require("readline");
|
|
7
|
-
const rl = readline.createInterface({
|
|
8
|
-
input: process.stdin,
|
|
9
|
-
output: process.stdout,
|
|
10
|
-
});
|
|
11
|
-
rl.question(`Xcode profile enabled. Current process ${process.title} (${process.pid}) . Press Enter to continue...\n`, () => {
|
|
12
|
-
rl.close();
|
|
13
|
-
resolve();
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
}
|
package/esm/build.d.ts
DELETED
package/esm/build.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { handleIssues } from "@utoo/pack-shared";
|
|
2
|
-
import { spawn } from "child_process";
|
|
3
|
-
import { existsSync } from "fs";
|
|
4
|
-
import { nanoid } from "nanoid";
|
|
5
|
-
import { join } from "path";
|
|
6
|
-
import { findRootDir } from "./find-root";
|
|
7
|
-
import { projectFactory } from "./project";
|
|
8
|
-
import { blockStdout, createDefineEnv, getPackPath } from "./util";
|
|
9
|
-
import { compatOptionsFromWebpack } from "./webpackCompat";
|
|
10
|
-
import { xcodeProfilingReady } from "./xcodeProfile";
|
|
11
|
-
export function build(options, projectPath, rootPath) {
|
|
12
|
-
const bundleOptions = options.webpackMode
|
|
13
|
-
? compatOptionsFromWebpack(options, projectPath, rootPath)
|
|
14
|
-
: options;
|
|
15
|
-
if (!rootPath) {
|
|
16
|
-
// help user to find the rootDir automatically.
|
|
17
|
-
rootPath = findRootDir(projectPath || process.cwd());
|
|
18
|
-
}
|
|
19
|
-
return buildInternal(bundleOptions, projectPath, rootPath);
|
|
20
|
-
}
|
|
21
|
-
async function buildInternal(bundleOptions, projectPath, rootPath) {
|
|
22
|
-
var _a, _b, _c, _d;
|
|
23
|
-
blockStdout();
|
|
24
|
-
if (process.env.XCODE_PROFILE) {
|
|
25
|
-
await xcodeProfilingReady();
|
|
26
|
-
}
|
|
27
|
-
const createProject = projectFactory();
|
|
28
|
-
const project = await createProject({
|
|
29
|
-
processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
|
|
30
|
-
defineEnv: createDefineEnv({
|
|
31
|
-
config: bundleOptions.config,
|
|
32
|
-
dev: (_b = bundleOptions.dev) !== null && _b !== void 0 ? _b : false,
|
|
33
|
-
optionDefineEnv: bundleOptions.defineEnv,
|
|
34
|
-
}),
|
|
35
|
-
watch: {
|
|
36
|
-
enable: false,
|
|
37
|
-
},
|
|
38
|
-
dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
|
|
39
|
-
buildId: bundleOptions.buildId || nanoid(),
|
|
40
|
-
config: {
|
|
41
|
-
...bundleOptions.config,
|
|
42
|
-
stats: Boolean(process.env.ANALYZE) || bundleOptions.config.stats,
|
|
43
|
-
},
|
|
44
|
-
projectPath: projectPath || process.cwd(),
|
|
45
|
-
rootPath: rootPath || projectPath || process.cwd(),
|
|
46
|
-
packPath: getPackPath(),
|
|
47
|
-
}, {
|
|
48
|
-
persistentCaching: false,
|
|
49
|
-
});
|
|
50
|
-
const entrypoints = await project.writeAllEntrypointsToDisk();
|
|
51
|
-
handleIssues(entrypoints.issues);
|
|
52
|
-
if (process.env.ANALYZE) {
|
|
53
|
-
await analyzeBundle(((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || "dist");
|
|
54
|
-
}
|
|
55
|
-
await project.shutdown();
|
|
56
|
-
// TODO: Maybe run tasks in worker is a better way, see
|
|
57
|
-
// https://github.com/vercel/next.js/blob/512d8283054407ab92b2583ecce3b253c3be7b85/packages/next/src/lib/worker.ts
|
|
58
|
-
}
|
|
59
|
-
async function analyzeBundle(outputPath) {
|
|
60
|
-
const statsPath = join(outputPath, "stats.json");
|
|
61
|
-
if (!existsSync(statsPath)) {
|
|
62
|
-
console.warn(`Stats file not found at ${statsPath}. Make sure to enable stats in your configuration.`);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
return new Promise((resolve, reject) => {
|
|
66
|
-
const analyzer = spawn("npx", ["webpack-bundle-analyzer", statsPath], {
|
|
67
|
-
stdio: "inherit",
|
|
68
|
-
shell: true,
|
|
69
|
-
});
|
|
70
|
-
analyzer.on("error", (error) => {
|
|
71
|
-
reject(new Error(`Failed to start bundle analyzer: ${error.message}`));
|
|
72
|
-
});
|
|
73
|
-
analyzer.on("close", () => {
|
|
74
|
-
// The analyzer process has finished, so we can resolve the promise
|
|
75
|
-
// to allow the build process to exit gracefully.
|
|
76
|
-
resolve();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|