@utoo/pack 1.1.3 → 1.1.4
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/commands/build.d.ts +3 -0
- package/cjs/commands/build.js +165 -0
- package/cjs/commands/dev.d.ts +44 -0
- package/cjs/commands/dev.js +387 -0
- package/cjs/config/readWebpackConfig.d.ts +1 -0
- package/cjs/config/readWebpackConfig.js +14 -0
- package/cjs/config/types.d.ts +1 -0
- package/cjs/config/types.js +17 -0
- package/cjs/config/webpackCompat.d.ts +2 -0
- package/cjs/config/webpackCompat.js +7 -0
- package/cjs/core/hmr.d.ts +80 -0
- package/cjs/core/hmr.js +341 -0
- package/cjs/core/loaderWorkerPool.d.ts +1 -0
- package/cjs/core/loaderWorkerPool.js +35 -0
- package/cjs/core/project.d.ts +43 -0
- package/cjs/core/project.js +291 -0
- package/cjs/core/types.d.ts +94 -0
- package/cjs/core/types.js +2 -0
- package/cjs/plugins/HtmlPlugin.d.ts +9 -0
- package/cjs/plugins/HtmlPlugin.js +116 -0
- package/cjs/utils/common.d.ts +3 -0
- package/cjs/utils/common.js +32 -0
- package/cjs/utils/find-root.d.ts +4 -0
- package/cjs/utils/find-root.js +75 -0
- package/cjs/utils/html-entry.d.ts +2 -0
- package/cjs/utils/html-entry.js +47 -0
- package/cjs/utils/mkcert.d.ts +7 -0
- package/cjs/utils/mkcert.js +183 -0
- package/cjs/utils/print-server-info.d.ts +1 -0
- package/cjs/utils/print-server-info.js +50 -0
- package/cjs/utils/xcodeProfile.d.ts +1 -0
- package/cjs/utils/xcodeProfile.js +16 -0
- package/esm/commands/build.d.ts +3 -0
- package/esm/commands/build.js +129 -0
- package/esm/commands/dev.d.ts +44 -0
- package/esm/commands/dev.js +371 -0
- package/esm/config/readWebpackConfig.d.ts +1 -0
- package/esm/config/readWebpackConfig.js +8 -0
- package/esm/config/types.d.ts +1 -0
- package/esm/config/types.js +1 -0
- package/esm/config/webpackCompat.d.ts +2 -0
- package/esm/config/webpackCompat.js +2 -0
- package/esm/core/hmr.d.ts +80 -0
- package/esm/core/hmr.js +334 -0
- package/esm/core/loaderWorkerPool.d.ts +1 -0
- package/esm/core/loaderWorkerPool.js +32 -0
- package/esm/core/project.d.ts +43 -0
- package/esm/core/project.js +253 -0
- package/esm/core/types.d.ts +94 -0
- package/esm/core/types.js +1 -0
- package/esm/plugins/HtmlPlugin.d.ts +9 -0
- package/esm/plugins/HtmlPlugin.js +109 -0
- package/esm/utils/common.d.ts +3 -0
- package/esm/utils/common.js +18 -0
- package/esm/utils/find-root.d.ts +4 -0
- package/esm/utils/find-root.js +66 -0
- package/esm/utils/html-entry.d.ts +2 -0
- package/esm/utils/html-entry.js +41 -0
- package/esm/utils/mkcert.d.ts +7 -0
- package/esm/utils/mkcert.js +176 -0
- package/esm/utils/print-server-info.d.ts +1 -0
- package/esm/utils/print-server-info.js +44 -0
- package/esm/utils/xcodeProfile.d.ts +1 -0
- package/esm/utils/xcodeProfile.js +13 -0
- package/package.json +12 -14
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.TurbopackInternalError = void 0;
|
|
37
|
+
exports.projectFactory = projectFactory;
|
|
38
|
+
const util_1 = require("util");
|
|
39
|
+
const binding = __importStar(require("../binding"));
|
|
40
|
+
const common_1 = require("../utils/common");
|
|
41
|
+
const loaderWorkerPool_1 = require("./loaderWorkerPool");
|
|
42
|
+
class TurbopackInternalError extends Error {
|
|
43
|
+
constructor(cause) {
|
|
44
|
+
super(cause.message);
|
|
45
|
+
this.name = "TurbopackInternalError";
|
|
46
|
+
this.stack = cause.stack;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.TurbopackInternalError = TurbopackInternalError;
|
|
50
|
+
async function withErrorCause(fn) {
|
|
51
|
+
try {
|
|
52
|
+
return await fn();
|
|
53
|
+
}
|
|
54
|
+
catch (nativeError) {
|
|
55
|
+
throw new TurbopackInternalError(nativeError);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function ensureLoadersHaveSerializableOptions(turbopackRules) {
|
|
59
|
+
for (const [glob, rule] of Object.entries(turbopackRules)) {
|
|
60
|
+
if (Array.isArray(rule)) {
|
|
61
|
+
checkLoaderItems(rule, glob);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
checkConfigItem(rule, glob);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function checkConfigItem(rule, glob) {
|
|
68
|
+
if (!rule)
|
|
69
|
+
return;
|
|
70
|
+
if ("loaders" in rule) {
|
|
71
|
+
checkLoaderItems(rule.loaders, glob);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
for (const key in rule) {
|
|
75
|
+
const inner = rule[key];
|
|
76
|
+
if (typeof inner === "object" && inner) {
|
|
77
|
+
checkConfigItem(inner, glob);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function checkLoaderItems(loaderItems, glob) {
|
|
83
|
+
for (const loaderItem of loaderItems) {
|
|
84
|
+
if (typeof loaderItem !== "string" &&
|
|
85
|
+
!(0, util_1.isDeepStrictEqual)(loaderItem, JSON.parse(JSON.stringify(loaderItem)))) {
|
|
86
|
+
throw new Error(`loader ${loaderItem.loader} for match "${glob}" does not have serializable options. Ensure that options passed are plain JavaScript objects and values.`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async function serializeConfig(config) {
|
|
92
|
+
var _a;
|
|
93
|
+
const configSerializable = { ...config };
|
|
94
|
+
if (configSerializable.entry) {
|
|
95
|
+
configSerializable.entry = configSerializable.entry.map((entry) => {
|
|
96
|
+
const { html, ...rest } = entry;
|
|
97
|
+
return rest;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
if ((_a = configSerializable.module) === null || _a === void 0 ? void 0 : _a.rules) {
|
|
101
|
+
ensureLoadersHaveSerializableOptions(configSerializable.module.rules);
|
|
102
|
+
}
|
|
103
|
+
if (configSerializable.optimization) {
|
|
104
|
+
configSerializable.optimization = { ...configSerializable.optimization };
|
|
105
|
+
const { modularizeImports } = configSerializable.optimization;
|
|
106
|
+
if (modularizeImports) {
|
|
107
|
+
configSerializable.optimization.modularizeImports = Object.fromEntries(Object.entries(modularizeImports).map(([mod, config]) => [
|
|
108
|
+
mod,
|
|
109
|
+
{
|
|
110
|
+
...config,
|
|
111
|
+
transform: typeof config.transform === "string"
|
|
112
|
+
? config.transform
|
|
113
|
+
: Object.entries(config.transform).map(([key, value]) => [
|
|
114
|
+
key,
|
|
115
|
+
value,
|
|
116
|
+
]),
|
|
117
|
+
},
|
|
118
|
+
]));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return JSON.stringify(configSerializable, null, 2);
|
|
122
|
+
}
|
|
123
|
+
async function rustifyPartialProjectOptions(options) {
|
|
124
|
+
return {
|
|
125
|
+
...options,
|
|
126
|
+
config: options.config && (await serializeConfig(options.config)),
|
|
127
|
+
processEnv: options.processEnv && (0, common_1.rustifyEnv)(options.processEnv),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
async function rustifyProjectOptions(options) {
|
|
131
|
+
var _a;
|
|
132
|
+
return {
|
|
133
|
+
...options,
|
|
134
|
+
config: await serializeConfig(options.config),
|
|
135
|
+
processEnv: (0, common_1.rustifyEnv)((_a = options.processEnv) !== null && _a !== void 0 ? _a : {}),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function projectFactory() {
|
|
139
|
+
const cancel = new (class Cancel extends Error {
|
|
140
|
+
})();
|
|
141
|
+
function subscribe(useBuffer, nativeFunction) {
|
|
142
|
+
// A buffer of produced items. This will only contain values if the
|
|
143
|
+
// consumer is slower than the producer.
|
|
144
|
+
let buffer = [];
|
|
145
|
+
// A deferred value waiting for the next produced item. This will only
|
|
146
|
+
// exist if the consumer is faster than the producer.
|
|
147
|
+
let waiting;
|
|
148
|
+
let canceled = false;
|
|
149
|
+
// The native function will call this every time it emits a new result. We
|
|
150
|
+
// either need to notify a waiting consumer, or buffer the new result until
|
|
151
|
+
// the consumer catches up.
|
|
152
|
+
function emitResult(err, value) {
|
|
153
|
+
if (waiting) {
|
|
154
|
+
let { resolve, reject } = waiting;
|
|
155
|
+
waiting = undefined;
|
|
156
|
+
if (err)
|
|
157
|
+
reject(err);
|
|
158
|
+
else
|
|
159
|
+
resolve(value);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
const item = { err, value };
|
|
163
|
+
if (useBuffer)
|
|
164
|
+
buffer.push(item);
|
|
165
|
+
else
|
|
166
|
+
buffer[0] = item;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function* createIterator() {
|
|
170
|
+
const task = await withErrorCause(() => nativeFunction(emitResult));
|
|
171
|
+
try {
|
|
172
|
+
while (!canceled) {
|
|
173
|
+
if (buffer.length > 0) {
|
|
174
|
+
const item = buffer.shift();
|
|
175
|
+
if (item.err)
|
|
176
|
+
throw item.err;
|
|
177
|
+
yield item.value;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
// eslint-disable-next-line no-loop-func
|
|
181
|
+
yield new Promise((resolve, reject) => {
|
|
182
|
+
waiting = { resolve, reject };
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
catch (e) {
|
|
188
|
+
if (e === cancel)
|
|
189
|
+
return;
|
|
190
|
+
if (e instanceof Error) {
|
|
191
|
+
throw new TurbopackInternalError(e);
|
|
192
|
+
}
|
|
193
|
+
throw e;
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
if (task) {
|
|
197
|
+
binding.rootTaskDispose(task);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const iterator = createIterator();
|
|
202
|
+
iterator.return = async () => {
|
|
203
|
+
canceled = true;
|
|
204
|
+
if (waiting)
|
|
205
|
+
waiting.reject(cancel);
|
|
206
|
+
return { value: undefined, done: true };
|
|
207
|
+
};
|
|
208
|
+
return iterator;
|
|
209
|
+
}
|
|
210
|
+
class ProjectImpl {
|
|
211
|
+
constructor(nativeProject) {
|
|
212
|
+
this._nativeProject = nativeProject;
|
|
213
|
+
if (typeof binding.registerWorkerScheduler === "function") {
|
|
214
|
+
(0, loaderWorkerPool_1.runLoaderWorkerPool)(binding, require.resolve("@utoo/pack/cjs/binding.js"));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
async update(options) {
|
|
218
|
+
await withErrorCause(async () => binding.projectUpdate(this._nativeProject, await rustifyPartialProjectOptions(options)));
|
|
219
|
+
}
|
|
220
|
+
async writeAllEntrypointsToDisk() {
|
|
221
|
+
return await withErrorCause(async () => {
|
|
222
|
+
const napiEndpoints = (await binding.projectWriteAllEntrypointsToDisk(this._nativeProject));
|
|
223
|
+
return napiEntrypointsToRawEntrypoints(napiEndpoints);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
entrypointsSubscribe() {
|
|
227
|
+
const subscription = subscribe(false, async (callback) => binding.projectEntrypointsSubscribe(this._nativeProject, callback));
|
|
228
|
+
return (async function* () {
|
|
229
|
+
for await (const entrypoints of subscription) {
|
|
230
|
+
yield napiEntrypointsToRawEntrypoints(entrypoints);
|
|
231
|
+
}
|
|
232
|
+
})();
|
|
233
|
+
}
|
|
234
|
+
hmrEvents(identifier) {
|
|
235
|
+
return subscribe(true, async (callback) => binding.projectHmrEvents(this._nativeProject, identifier, callback));
|
|
236
|
+
}
|
|
237
|
+
hmrIdentifiersSubscribe() {
|
|
238
|
+
return subscribe(false, async (callback) => binding.projectHmrIdentifiersSubscribe(this._nativeProject, callback));
|
|
239
|
+
}
|
|
240
|
+
traceSource(stackFrame, currentDirectoryFileUrl) {
|
|
241
|
+
return binding.projectTraceSource(this._nativeProject, stackFrame, currentDirectoryFileUrl);
|
|
242
|
+
}
|
|
243
|
+
getSourceForAsset(filePath) {
|
|
244
|
+
return binding.projectGetSourceForAsset(this._nativeProject, filePath);
|
|
245
|
+
}
|
|
246
|
+
getSourceMap(filePath) {
|
|
247
|
+
return binding.projectGetSourceMap(this._nativeProject, filePath);
|
|
248
|
+
}
|
|
249
|
+
getSourceMapSync(filePath) {
|
|
250
|
+
return binding.projectGetSourceMapSync(this._nativeProject, filePath);
|
|
251
|
+
}
|
|
252
|
+
updateInfoSubscribe(aggregationMs) {
|
|
253
|
+
return subscribe(true, async (callback) => binding.projectUpdateInfoSubscribe(this._nativeProject, aggregationMs, callback));
|
|
254
|
+
}
|
|
255
|
+
shutdown() {
|
|
256
|
+
return binding.projectShutdown(this._nativeProject);
|
|
257
|
+
}
|
|
258
|
+
onExit() {
|
|
259
|
+
return binding.projectOnExit(this._nativeProject);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
class EndpointImpl {
|
|
263
|
+
constructor(nativeEndpoint) {
|
|
264
|
+
this._nativeEndpoint = nativeEndpoint;
|
|
265
|
+
}
|
|
266
|
+
async writeToDisk() {
|
|
267
|
+
return await withErrorCause(() => binding.endpointWriteToDisk(this._nativeEndpoint));
|
|
268
|
+
}
|
|
269
|
+
async clientChanged() {
|
|
270
|
+
const clientSubscription = subscribe(false, async (callback) => binding.endpointClientChangedSubscribe(await this._nativeEndpoint, callback));
|
|
271
|
+
await clientSubscription.next();
|
|
272
|
+
return clientSubscription;
|
|
273
|
+
}
|
|
274
|
+
async serverChanged(includeIssues) {
|
|
275
|
+
const serverSubscription = subscribe(false, async (callback) => binding.endpointServerChangedSubscribe(await this._nativeEndpoint, includeIssues, callback));
|
|
276
|
+
await serverSubscription.next();
|
|
277
|
+
return serverSubscription;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function napiEntrypointsToRawEntrypoints(entrypoints) {
|
|
281
|
+
return {
|
|
282
|
+
apps: (entrypoints.apps || []).map((e) => new EndpointImpl(e)),
|
|
283
|
+
libraries: (entrypoints.libraries || []).map((e) => new EndpointImpl(e)),
|
|
284
|
+
issues: entrypoints.issues,
|
|
285
|
+
diagnostics: entrypoints.diagnostics,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
return async function createProject(options, turboEngineOptions) {
|
|
289
|
+
return new ProjectImpl(await binding.projectNew(await rustifyProjectOptions(options), turboEngineOptions || {}));
|
|
290
|
+
};
|
|
291
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { HmrIdentifiers, NapiDiagnostic, NapiIssue, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "../binding";
|
|
2
|
+
import { BundleOptions } from "../config/types";
|
|
3
|
+
declare global {
|
|
4
|
+
export type TurbopackResult<T = {}> = T & {
|
|
5
|
+
issues: NapiIssue[];
|
|
6
|
+
diagnostics: NapiDiagnostic[];
|
|
7
|
+
};
|
|
8
|
+
export type RefCell = {
|
|
9
|
+
readonly __tag: unique symbol;
|
|
10
|
+
};
|
|
11
|
+
export type ExternalEndpoint = {
|
|
12
|
+
readonly __tag: unique symbol;
|
|
13
|
+
};
|
|
14
|
+
export type RcStr = string;
|
|
15
|
+
}
|
|
16
|
+
export interface BaseUpdate {
|
|
17
|
+
resource: {
|
|
18
|
+
headers: unknown;
|
|
19
|
+
path: string;
|
|
20
|
+
};
|
|
21
|
+
diagnostics: unknown[];
|
|
22
|
+
issues: NapiIssue[];
|
|
23
|
+
}
|
|
24
|
+
export interface IssuesUpdate extends BaseUpdate {
|
|
25
|
+
type: "issues";
|
|
26
|
+
}
|
|
27
|
+
export interface EcmascriptMergedUpdate {
|
|
28
|
+
type: "EcmascriptMergedUpdate";
|
|
29
|
+
chunks: {
|
|
30
|
+
[moduleName: string]: {
|
|
31
|
+
type: "partial";
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
entries: {
|
|
35
|
+
[moduleName: string]: {
|
|
36
|
+
code: string;
|
|
37
|
+
map: string;
|
|
38
|
+
url: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface PartialUpdate extends BaseUpdate {
|
|
43
|
+
type: "partial";
|
|
44
|
+
instruction: {
|
|
45
|
+
type: "ChunkListUpdate";
|
|
46
|
+
merged: EcmascriptMergedUpdate[] | undefined;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export type Update = IssuesUpdate | PartialUpdate;
|
|
50
|
+
export interface ProjectOptions extends BundleOptions {
|
|
51
|
+
/**
|
|
52
|
+
* A root path from which all files must be nested under. Trying to access
|
|
53
|
+
* a file outside this root will fail. Think of this as a chroot.
|
|
54
|
+
*/
|
|
55
|
+
rootPath: string;
|
|
56
|
+
/**
|
|
57
|
+
* A path inside the root_path which contains the app/pages directories.
|
|
58
|
+
*/
|
|
59
|
+
projectPath: string;
|
|
60
|
+
}
|
|
61
|
+
export { BundleOptions };
|
|
62
|
+
export interface Project {
|
|
63
|
+
update(options: Partial<ProjectOptions>): Promise<void>;
|
|
64
|
+
entrypointsSubscribe(): AsyncIterableIterator<TurbopackResult<RawEntrypoints>>;
|
|
65
|
+
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
|
|
66
|
+
hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
|
|
67
|
+
getSourceForAsset(filePath: string): Promise<string | null>;
|
|
68
|
+
getSourceMap(filePath: string): Promise<string | null>;
|
|
69
|
+
getSourceMapSync(filePath: string): string | null;
|
|
70
|
+
traceSource(stackFrame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>;
|
|
71
|
+
updateInfoSubscribe(aggregationMs: number): AsyncIterableIterator<TurbopackResult<NapiUpdateMessage>>;
|
|
72
|
+
shutdown(): Promise<void>;
|
|
73
|
+
onExit(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
export interface RawEntrypoints {
|
|
76
|
+
apps?: Endpoint[];
|
|
77
|
+
libraries?: Endpoint[];
|
|
78
|
+
}
|
|
79
|
+
export interface Endpoint {
|
|
80
|
+
/** Write files for the endpoint to disk. */
|
|
81
|
+
writeToDisk(): Promise<TurbopackResult<NapiWrittenEndpoint>>;
|
|
82
|
+
/**
|
|
83
|
+
* Listen to client-side changes to the endpoint.
|
|
84
|
+
* After clientChanged() has been awaited it will listen to changes.
|
|
85
|
+
* The async iterator will yield for each change.
|
|
86
|
+
*/
|
|
87
|
+
clientChanged(): Promise<AsyncIterableIterator<TurbopackResult>>;
|
|
88
|
+
/**
|
|
89
|
+
* Listen to server-side changes to the endpoint.
|
|
90
|
+
* After serverChanged() has been awaited it will listen to changes.
|
|
91
|
+
* The async iterator will yield for each change.
|
|
92
|
+
*/
|
|
93
|
+
serverChanged(includeIssues: boolean): Promise<AsyncIterableIterator<TurbopackResult>>;
|
|
94
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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.HtmlPlugin = void 0;
|
|
7
|
+
const domparser_rs_1 = require("domparser-rs");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
class HtmlPlugin {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
async generate(outputDir, assets, globalPublicPath) {
|
|
15
|
+
const templatePath = this.config.template
|
|
16
|
+
? path_1.default.resolve(process.cwd(), this.config.template)
|
|
17
|
+
: undefined;
|
|
18
|
+
const publicPath = globalPublicPath || "";
|
|
19
|
+
let htmlContent = "";
|
|
20
|
+
if (this.config.templateContent) {
|
|
21
|
+
htmlContent = this.config.templateContent;
|
|
22
|
+
}
|
|
23
|
+
else if (templatePath && fs_1.default.existsSync(templatePath)) {
|
|
24
|
+
htmlContent = fs_1.default.readFileSync(templatePath, "utf-8");
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
htmlContent = `<!DOCTYPE html>
|
|
28
|
+
<html>
|
|
29
|
+
<head>
|
|
30
|
+
<meta charset="utf-8">
|
|
31
|
+
<title>${this.config.title || "Utoo App"}</title>
|
|
32
|
+
</head>
|
|
33
|
+
<body>
|
|
34
|
+
<div id="root"></div>
|
|
35
|
+
</body>
|
|
36
|
+
</html>`;
|
|
37
|
+
}
|
|
38
|
+
const parser = new domparser_rs_1.DOMParser();
|
|
39
|
+
const doc = parser.parseFromString(htmlContent, "text/html");
|
|
40
|
+
if (this.config.title) {
|
|
41
|
+
const title = doc.querySelector("title");
|
|
42
|
+
if (title) {
|
|
43
|
+
title.textContent = this.config.title;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const head = doc.querySelector("head");
|
|
47
|
+
if (head) {
|
|
48
|
+
const titleNode = doc.createElement("title");
|
|
49
|
+
titleNode.textContent = this.config.title;
|
|
50
|
+
head.appendChild(titleNode);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Inject meta
|
|
55
|
+
if (this.config.meta) {
|
|
56
|
+
const head = doc.querySelector("head");
|
|
57
|
+
if (head) {
|
|
58
|
+
Object.entries(this.config.meta).forEach(([name, value]) => {
|
|
59
|
+
const meta = doc.createElement("meta");
|
|
60
|
+
if (typeof value === "string") {
|
|
61
|
+
meta.setAttribute("name", name);
|
|
62
|
+
meta.setAttribute("content", value);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
Object.entries(value).forEach(([k, v]) => {
|
|
66
|
+
meta.setAttribute(k, v);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
head.appendChild(meta);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const head = doc.querySelector("head");
|
|
74
|
+
const body = doc.querySelector("body");
|
|
75
|
+
// Inject CSS
|
|
76
|
+
assets.css.forEach((cssFile) => {
|
|
77
|
+
const link = doc.createElement("link");
|
|
78
|
+
link.setAttribute("rel", "stylesheet");
|
|
79
|
+
link.setAttribute("href", publicPath
|
|
80
|
+
? publicPath.endsWith("/")
|
|
81
|
+
? publicPath + cssFile
|
|
82
|
+
: publicPath + "/" + cssFile
|
|
83
|
+
: cssFile);
|
|
84
|
+
if (head)
|
|
85
|
+
head.appendChild(link);
|
|
86
|
+
});
|
|
87
|
+
// Inject JS
|
|
88
|
+
assets.js.forEach((jsFile) => {
|
|
89
|
+
const script = doc.createElement("script");
|
|
90
|
+
script.setAttribute("src", publicPath
|
|
91
|
+
? publicPath.endsWith("/")
|
|
92
|
+
? publicPath + jsFile
|
|
93
|
+
: publicPath + "/" + jsFile
|
|
94
|
+
: jsFile);
|
|
95
|
+
if (this.config.scriptLoading === "defer") {
|
|
96
|
+
script.setAttribute("defer", "");
|
|
97
|
+
}
|
|
98
|
+
else if (this.config.scriptLoading === "module") {
|
|
99
|
+
script.setAttribute("type", "module");
|
|
100
|
+
}
|
|
101
|
+
if (this.config.inject === "head" && head) {
|
|
102
|
+
head.appendChild(script);
|
|
103
|
+
}
|
|
104
|
+
else if (body) {
|
|
105
|
+
body.appendChild(script);
|
|
106
|
+
}
|
|
107
|
+
else if (head) {
|
|
108
|
+
head.appendChild(script); // Fallback
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const finalHtml = doc.outerHTML;
|
|
112
|
+
const filename = this.config.filename || "index.html";
|
|
113
|
+
fs_1.default.writeFileSync(path_1.default.join(outputDir, filename), finalHtml);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.HtmlPlugin = HtmlPlugin;
|
|
@@ -0,0 +1,32 @@
|
|
|
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.rustifyEnv = exports.processIssues = exports.ModuleBuildError = exports.isWellKnownError = exports.debounce = exports.createDefineEnv = void 0;
|
|
7
|
+
exports.blockStdout = blockStdout;
|
|
8
|
+
exports.getPackPath = getPackPath;
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
var pack_shared_1 = require("@utoo/pack-shared");
|
|
11
|
+
Object.defineProperty(exports, "createDefineEnv", { enumerable: true, get: function () { return pack_shared_1.createDefineEnv; } });
|
|
12
|
+
Object.defineProperty(exports, "debounce", { enumerable: true, get: function () { return pack_shared_1.debounce; } });
|
|
13
|
+
Object.defineProperty(exports, "isWellKnownError", { enumerable: true, get: function () { return pack_shared_1.isWellKnownError; } });
|
|
14
|
+
Object.defineProperty(exports, "ModuleBuildError", { enumerable: true, get: function () { return pack_shared_1.ModuleBuildError; } });
|
|
15
|
+
Object.defineProperty(exports, "processIssues", { enumerable: true, get: function () { return pack_shared_1.processIssues; } });
|
|
16
|
+
Object.defineProperty(exports, "rustifyEnv", { enumerable: true, get: function () { return pack_shared_1.rustifyEnv; } });
|
|
17
|
+
// ref:
|
|
18
|
+
// https://github.com/vercel/next.js/pull/51883
|
|
19
|
+
function blockStdout() {
|
|
20
|
+
// 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
|
|
21
|
+
// see https://github.com/napi-rs/napi-rs/issues/1630
|
|
22
|
+
// and https://github.com/nodejs/node/blob/main/doc/api/process.md#a-note-on-process-io
|
|
23
|
+
if (process.stdout._handle != null) {
|
|
24
|
+
process.stdout._handle.setBlocking(true);
|
|
25
|
+
}
|
|
26
|
+
if (process.stderr._handle != null) {
|
|
27
|
+
process.stderr._handle.setBlocking(true);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function getPackPath() {
|
|
31
|
+
return path_1.default.resolve(__dirname, "..");
|
|
32
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function findRootLockFile(cwd: string): string | undefined;
|
|
2
|
+
export declare function findPackageJson(cwd: string): string | undefined;
|
|
3
|
+
export declare function findWorkspacesRoot(cwd: string): string;
|
|
4
|
+
export declare function findRootDir(cwd: string): string;
|
|
@@ -0,0 +1,75 @@
|
|
|
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.findRootLockFile = findRootLockFile;
|
|
7
|
+
exports.findPackageJson = findPackageJson;
|
|
8
|
+
exports.findWorkspacesRoot = findWorkspacesRoot;
|
|
9
|
+
exports.findRootDir = findRootDir;
|
|
10
|
+
const find_up_1 = __importDefault(require("find-up"));
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
function findRootLockFile(cwd) {
|
|
14
|
+
return find_up_1.default.sync([
|
|
15
|
+
"pnpm-lock.yaml",
|
|
16
|
+
"package-lock.json",
|
|
17
|
+
"yarn.lock",
|
|
18
|
+
"bun.lock",
|
|
19
|
+
"bun.lockb",
|
|
20
|
+
], {
|
|
21
|
+
cwd,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
// compatible with tnpm
|
|
25
|
+
function findPackageJson(cwd) {
|
|
26
|
+
return find_up_1.default.sync(["package.json"], {
|
|
27
|
+
cwd,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function isWorkspaceRoot(pkgPath) {
|
|
31
|
+
const pkgJson = (0, fs_1.readFileSync)(pkgPath, "utf-8");
|
|
32
|
+
const pkgJsonContent = JSON.parse(pkgJson);
|
|
33
|
+
return Boolean(pkgJsonContent.workspaces);
|
|
34
|
+
}
|
|
35
|
+
// refer from: https://github.com/umijs/mako/blob/next/crates/pm/src/helper/workspace.rs#L153
|
|
36
|
+
// TODO: 这块逻辑后续跟 utoo-pkg 使用一套方法
|
|
37
|
+
function findWorkspacesRoot(cwd) {
|
|
38
|
+
const pkgJson = findPackageJson(cwd);
|
|
39
|
+
if (!pkgJson)
|
|
40
|
+
return cwd;
|
|
41
|
+
const pkgJsonFiles = [pkgJson];
|
|
42
|
+
while (true) {
|
|
43
|
+
const lastPkgJson = pkgJsonFiles[pkgJsonFiles.length - 1];
|
|
44
|
+
const currentDir = (0, path_1.dirname)(lastPkgJson);
|
|
45
|
+
const parentDir = (0, path_1.dirname)(currentDir);
|
|
46
|
+
if (parentDir === currentDir)
|
|
47
|
+
break;
|
|
48
|
+
if (isWorkspaceRoot(lastPkgJson))
|
|
49
|
+
break;
|
|
50
|
+
const newPkgJson = findPackageJson(parentDir);
|
|
51
|
+
if (!newPkgJson)
|
|
52
|
+
break;
|
|
53
|
+
pkgJsonFiles.push(newPkgJson);
|
|
54
|
+
}
|
|
55
|
+
return (0, path_1.dirname)(pkgJsonFiles[pkgJsonFiles.length - 1]);
|
|
56
|
+
}
|
|
57
|
+
function findRootDir(cwd) {
|
|
58
|
+
const lockFile = findRootLockFile(cwd);
|
|
59
|
+
if (!lockFile)
|
|
60
|
+
return findWorkspacesRoot(cwd);
|
|
61
|
+
const lockFiles = [lockFile];
|
|
62
|
+
while (true) {
|
|
63
|
+
const lastLockFile = lockFiles[lockFiles.length - 1];
|
|
64
|
+
const currentDir = (0, path_1.dirname)(lastLockFile);
|
|
65
|
+
const parentDir = (0, path_1.dirname)(currentDir);
|
|
66
|
+
// dirname('/')==='/' so if we happen to reach the FS root (as might happen in a container we need to quit to avoid looping forever
|
|
67
|
+
if (parentDir === currentDir)
|
|
68
|
+
break;
|
|
69
|
+
const newLockFile = findRootLockFile(parentDir);
|
|
70
|
+
if (!newLockFile)
|
|
71
|
+
break;
|
|
72
|
+
lockFiles.push(newLockFile);
|
|
73
|
+
}
|
|
74
|
+
return (0, path_1.dirname)(lockFiles[lockFiles.length - 1]);
|
|
75
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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.processHtmlEntry = processHtmlEntry;
|
|
7
|
+
const domparser_rs_1 = require("domparser-rs");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
function processHtmlEntry(config, projectPath) {
|
|
11
|
+
if (!config.entry)
|
|
12
|
+
return;
|
|
13
|
+
const newEntries = [];
|
|
14
|
+
config.entry = config.entry.filter((entry) => {
|
|
15
|
+
if (entry.import.endsWith(".html")) {
|
|
16
|
+
const htmlPath = path_1.default.resolve(projectPath, entry.import);
|
|
17
|
+
if (fs_1.default.existsSync(htmlPath)) {
|
|
18
|
+
const content = fs_1.default.readFileSync(htmlPath, "utf-8");
|
|
19
|
+
const parser = new domparser_rs_1.DOMParser();
|
|
20
|
+
const doc = parser.parseFromString(content, "text/html");
|
|
21
|
+
const scripts = doc.querySelectorAll("script");
|
|
22
|
+
scripts.forEach((script) => {
|
|
23
|
+
const src = script.getAttribute("src");
|
|
24
|
+
if (src && !src.startsWith("http") && !src.startsWith("//")) {
|
|
25
|
+
const scriptPath = path_1.default.join(path_1.default.dirname(entry.import), src);
|
|
26
|
+
newEntries.push({
|
|
27
|
+
import: scriptPath,
|
|
28
|
+
html: {
|
|
29
|
+
template: entry.import,
|
|
30
|
+
templateContent: doc.outerHTML,
|
|
31
|
+
filename: path_1.default.basename(entry.import),
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
// Remove the script tag from the DOM
|
|
35
|
+
if (script.parentNode) {
|
|
36
|
+
script.parentNode.removeChild(script);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
});
|
|
45
|
+
// Add new script entries
|
|
46
|
+
config.entry.push(...newEntries);
|
|
47
|
+
}
|