@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/esm/hmr.js
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import { nanoid } from "nanoid";
|
|
2
|
-
import ws from "ws";
|
|
3
|
-
import { projectFactory } from "./project";
|
|
4
|
-
import { createDefineEnv, debounce, getPackPath, processIssues } from "./util";
|
|
5
|
-
const wsServer = new ws.Server({ noServer: true });
|
|
6
|
-
const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random());
|
|
7
|
-
export const FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
|
|
8
|
-
export async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
9
|
-
var _a;
|
|
10
|
-
const createProject = projectFactory();
|
|
11
|
-
const project = await createProject({
|
|
12
|
-
processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
|
|
13
|
-
defineEnv: createDefineEnv({
|
|
14
|
-
config: bundleOptions.config,
|
|
15
|
-
dev: true,
|
|
16
|
-
optionDefineEnv: bundleOptions.defineEnv,
|
|
17
|
-
}),
|
|
18
|
-
watch: {
|
|
19
|
-
enable: true,
|
|
20
|
-
},
|
|
21
|
-
dev: true,
|
|
22
|
-
buildId: bundleOptions.buildId || nanoid(),
|
|
23
|
-
config: {
|
|
24
|
-
...bundleOptions.config,
|
|
25
|
-
mode: "development",
|
|
26
|
-
optimization: {
|
|
27
|
-
...bundleOptions.config.optimization,
|
|
28
|
-
minify: false,
|
|
29
|
-
moduleIds: "named",
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
projectPath: projectPath || process.cwd(),
|
|
33
|
-
rootPath: rootPath || projectPath || process.cwd(),
|
|
34
|
-
packPath: getPackPath(),
|
|
35
|
-
}, {
|
|
36
|
-
persistentCaching: true,
|
|
37
|
-
});
|
|
38
|
-
const entrypointsSubscription = project.entrypointsSubscribe();
|
|
39
|
-
let currentEntriesHandlingResolve;
|
|
40
|
-
let currentEntriesHandling = new Promise((resolve) => (currentEntriesHandlingResolve = resolve));
|
|
41
|
-
let hmrEventHappened = false;
|
|
42
|
-
let hmrHash = 0;
|
|
43
|
-
const clients = new Set();
|
|
44
|
-
const clientStates = new WeakMap();
|
|
45
|
-
function sendToClient(client, payload) {
|
|
46
|
-
client.send(JSON.stringify(payload));
|
|
47
|
-
}
|
|
48
|
-
function sendEnqueuedMessages() {
|
|
49
|
-
for (const client of clients) {
|
|
50
|
-
const state = clientStates.get(client);
|
|
51
|
-
if (!state) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
for (const payload of state.hmrPayloads.values()) {
|
|
55
|
-
sendToClient(client, payload);
|
|
56
|
-
}
|
|
57
|
-
state.hmrPayloads.clear();
|
|
58
|
-
if (state.turbopackUpdates.length > 0) {
|
|
59
|
-
sendToClient(client, {
|
|
60
|
-
action: "turbopack-message" /* HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE */,
|
|
61
|
-
data: state.turbopackUpdates,
|
|
62
|
-
});
|
|
63
|
-
state.turbopackUpdates.length = 0;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const sendEnqueuedMessagesDebounce = debounce(sendEnqueuedMessages, 2);
|
|
68
|
-
function sendTurbopackMessage(payload) {
|
|
69
|
-
var _a;
|
|
70
|
-
payload.diagnostics = [];
|
|
71
|
-
payload.issues = [];
|
|
72
|
-
for (const client of clients) {
|
|
73
|
-
(_a = clientStates.get(client)) === null || _a === void 0 ? void 0 : _a.turbopackUpdates.push(payload);
|
|
74
|
-
}
|
|
75
|
-
hmrEventHappened = true;
|
|
76
|
-
sendEnqueuedMessagesDebounce();
|
|
77
|
-
}
|
|
78
|
-
async function subscribeToHmrEvents(client, id) {
|
|
79
|
-
const state = clientStates.get(client);
|
|
80
|
-
if (!state || state.subscriptions.has(id)) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const subscription = project.hmrEvents(id);
|
|
84
|
-
state.subscriptions.set(id, subscription);
|
|
85
|
-
// The subscription will always emit once, which is the initial
|
|
86
|
-
// computation. This is not a change, so swallow it.
|
|
87
|
-
try {
|
|
88
|
-
await subscription.next();
|
|
89
|
-
for await (const data of subscription) {
|
|
90
|
-
processIssues(data, true, true);
|
|
91
|
-
if (data.type !== "issues") {
|
|
92
|
-
sendTurbopackMessage(data);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
catch (e) {
|
|
97
|
-
// The client might be using an HMR session from a previous server, tell them
|
|
98
|
-
// to fully reload the page to resolve the issue. We can't use
|
|
99
|
-
// `hotReloader.send` since that would force every connected client to
|
|
100
|
-
// reload, only this client is out of date.
|
|
101
|
-
const reloadAction = {
|
|
102
|
-
action: "reload" /* HMR_ACTIONS_SENT_TO_BROWSER.RELOAD */,
|
|
103
|
-
data: `error in HMR event subscription for ${id}: ${e}`,
|
|
104
|
-
};
|
|
105
|
-
sendToClient(client, reloadAction);
|
|
106
|
-
client.close();
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function unsubscribeFromHmrEvents(client, id) {
|
|
111
|
-
const state = clientStates.get(client);
|
|
112
|
-
if (!state) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const subscription = state.subscriptions.get(id);
|
|
116
|
-
subscription === null || subscription === void 0 ? void 0 : subscription.return();
|
|
117
|
-
}
|
|
118
|
-
async function handleEntrypointsSubscription() {
|
|
119
|
-
for await (const entrypoints of entrypointsSubscription) {
|
|
120
|
-
if (!currentEntriesHandlingResolve) {
|
|
121
|
-
currentEntriesHandling = new Promise(
|
|
122
|
-
// eslint-disable-next-line no-loop-func
|
|
123
|
-
(resolve) => (currentEntriesHandlingResolve = resolve));
|
|
124
|
-
}
|
|
125
|
-
await Promise.all(entrypoints.apps.map((l) => l.writeToDisk().then((res) => processIssues(res, true, true))));
|
|
126
|
-
currentEntriesHandlingResolve();
|
|
127
|
-
currentEntriesHandlingResolve = undefined;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const hotReloader = {
|
|
131
|
-
turbopackProject: project,
|
|
132
|
-
serverStats: null,
|
|
133
|
-
onHMR(req, socket, head, onUpgrade) {
|
|
134
|
-
wsServer.handleUpgrade(req, socket, head, (client) => {
|
|
135
|
-
onUpgrade === null || onUpgrade === void 0 ? void 0 : onUpgrade(client);
|
|
136
|
-
const subscriptions = new Map();
|
|
137
|
-
clients.add(client);
|
|
138
|
-
clientStates.set(client, {
|
|
139
|
-
hmrPayloads: new Map(),
|
|
140
|
-
turbopackUpdates: [],
|
|
141
|
-
subscriptions,
|
|
142
|
-
});
|
|
143
|
-
client.on("close", () => {
|
|
144
|
-
var _a;
|
|
145
|
-
// Remove active subscriptions
|
|
146
|
-
for (const subscription of subscriptions.values()) {
|
|
147
|
-
(_a = subscription.return) === null || _a === void 0 ? void 0 : _a.call(subscription);
|
|
148
|
-
}
|
|
149
|
-
clientStates.delete(client);
|
|
150
|
-
clients.delete(client);
|
|
151
|
-
});
|
|
152
|
-
client.addEventListener("message", ({ data }) => {
|
|
153
|
-
const parsedData = JSON.parse(typeof data !== "string" ? data.toString() : data);
|
|
154
|
-
// messages
|
|
155
|
-
switch (parsedData.event) {
|
|
156
|
-
case "client-error": // { errorCount, clientId }
|
|
157
|
-
case "client-warning": // { warningCount, clientId }
|
|
158
|
-
case "client-success": // { clientId }
|
|
159
|
-
case "client-full-reload": // { stackTrace, hadRuntimeError }
|
|
160
|
-
const { hadRuntimeError, dependencyChain } = parsedData;
|
|
161
|
-
if (hadRuntimeError) {
|
|
162
|
-
console.warn(FAST_REFRESH_RUNTIME_RELOAD);
|
|
163
|
-
}
|
|
164
|
-
if (Array.isArray(dependencyChain) &&
|
|
165
|
-
typeof dependencyChain[0] === "string") {
|
|
166
|
-
const cleanedModulePath = dependencyChain[0]
|
|
167
|
-
.replace(/^\[project\]/, ".")
|
|
168
|
-
.replace(/ \[.*\] \(.*\)$/, "");
|
|
169
|
-
console.warn(`Fast Refresh had to perform a full reload when ${cleanedModulePath} changed.`);
|
|
170
|
-
}
|
|
171
|
-
break;
|
|
172
|
-
default:
|
|
173
|
-
// Might be a Turbopack message...
|
|
174
|
-
if (!parsedData.type) {
|
|
175
|
-
throw new Error(`unrecognized HMR message "${data}"`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
// Turbopack messages
|
|
179
|
-
switch (parsedData.type) {
|
|
180
|
-
case "turbopack-subscribe":
|
|
181
|
-
subscribeToHmrEvents(client, parsedData.path);
|
|
182
|
-
break;
|
|
183
|
-
case "turbopack-unsubscribe":
|
|
184
|
-
unsubscribeFromHmrEvents(client, parsedData.path);
|
|
185
|
-
break;
|
|
186
|
-
default:
|
|
187
|
-
if (!parsedData.event) {
|
|
188
|
-
throw new Error(`unrecognized Turbopack HMR message "${data}"`);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
const turbopackConnected = {
|
|
193
|
-
action: "turbopack-connected" /* HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED */,
|
|
194
|
-
data: { sessionId },
|
|
195
|
-
};
|
|
196
|
-
sendToClient(client, turbopackConnected);
|
|
197
|
-
const errors = [];
|
|
198
|
-
(async function () {
|
|
199
|
-
const sync = {
|
|
200
|
-
action: "sync" /* HMR_ACTIONS_SENT_TO_BROWSER.SYNC */,
|
|
201
|
-
errors,
|
|
202
|
-
warnings: [],
|
|
203
|
-
hash: "",
|
|
204
|
-
};
|
|
205
|
-
sendToClient(client, sync);
|
|
206
|
-
})();
|
|
207
|
-
});
|
|
208
|
-
},
|
|
209
|
-
send(action) {
|
|
210
|
-
const payload = JSON.stringify(action);
|
|
211
|
-
for (const client of clients) {
|
|
212
|
-
client.send(payload);
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
setHmrServerError(_error) {
|
|
216
|
-
// Not implemented yet.
|
|
217
|
-
},
|
|
218
|
-
clearHmrServerError() {
|
|
219
|
-
// Not implemented yet.
|
|
220
|
-
},
|
|
221
|
-
async start() { },
|
|
222
|
-
async buildFallbackError() {
|
|
223
|
-
// Not implemented yet.
|
|
224
|
-
},
|
|
225
|
-
close() {
|
|
226
|
-
for (const wsClient of clients) {
|
|
227
|
-
// it's okay to not cleanly close these websocket connections, this is dev
|
|
228
|
-
wsClient.terminate();
|
|
229
|
-
}
|
|
230
|
-
clients.clear();
|
|
231
|
-
},
|
|
232
|
-
};
|
|
233
|
-
handleEntrypointsSubscription().catch((err) => {
|
|
234
|
-
console.error(err);
|
|
235
|
-
process.exit(1);
|
|
236
|
-
});
|
|
237
|
-
// Write empty manifests
|
|
238
|
-
await currentEntriesHandling;
|
|
239
|
-
async function handleProjectUpdates() {
|
|
240
|
-
for await (const updateMessage of project.updateInfoSubscribe(30)) {
|
|
241
|
-
switch (updateMessage.updateType) {
|
|
242
|
-
case "start": {
|
|
243
|
-
hotReloader.send({ action: "building" /* HMR_ACTIONS_SENT_TO_BROWSER.BUILDING */ });
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
case "end": {
|
|
247
|
-
sendEnqueuedMessages();
|
|
248
|
-
const errors = new Map();
|
|
249
|
-
for (const client of clients) {
|
|
250
|
-
const state = clientStates.get(client);
|
|
251
|
-
if (!state) {
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
const clientErrors = new Map(errors);
|
|
255
|
-
sendToClient(client, {
|
|
256
|
-
action: "built" /* HMR_ACTIONS_SENT_TO_BROWSER.BUILT */,
|
|
257
|
-
hash: String(++hmrHash),
|
|
258
|
-
errors: [...clientErrors.values()],
|
|
259
|
-
warnings: [],
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
if (hmrEventHappened) {
|
|
263
|
-
const time = updateMessage.value.duration;
|
|
264
|
-
const timeMessage = time > 2000 ? `${Math.round(time / 100) / 10}s` : `${time}ms`;
|
|
265
|
-
console.log(`Compiled in ${timeMessage}`);
|
|
266
|
-
hmrEventHappened = false;
|
|
267
|
-
}
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
default:
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
handleProjectUpdates().catch((err) => {
|
|
275
|
-
console.error(err);
|
|
276
|
-
process.exit(1);
|
|
277
|
-
});
|
|
278
|
-
return hotReloader;
|
|
279
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function runLoaderWorkerPool(binding: typeof import("./binding"), bindingPath: string): Promise<void>;
|
package/esm/loaderWorkerPool.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Worker } from "worker_threads";
|
|
2
|
-
const loaderWorkers = {};
|
|
3
|
-
function getPoolId(cwd, filename) {
|
|
4
|
-
return `${cwd}:${filename}`;
|
|
5
|
-
}
|
|
6
|
-
let workerSchedulerRegistered = false;
|
|
7
|
-
export async function runLoaderWorkerPool(binding, bindingPath) {
|
|
8
|
-
if (workerSchedulerRegistered) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
binding.registerWorkerScheduler((creation) => {
|
|
12
|
-
const { options: { filename, cwd }, } = creation;
|
|
13
|
-
let poolId = getPoolId(cwd, filename);
|
|
14
|
-
const worker = new Worker(filename, {
|
|
15
|
-
workerData: {
|
|
16
|
-
bindingPath,
|
|
17
|
-
cwd,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
worker.unref();
|
|
21
|
-
const workers = loaderWorkers[poolId] || (loaderWorkers[poolId] = new Map());
|
|
22
|
-
workers.set(worker.threadId, worker);
|
|
23
|
-
}, (termination) => {
|
|
24
|
-
var _a;
|
|
25
|
-
const { options: { filename, cwd }, workerId, } = termination;
|
|
26
|
-
let poolId = getPoolId(cwd, filename);
|
|
27
|
-
const workers = loaderWorkers[poolId];
|
|
28
|
-
(_a = workers.get(workerId)) === null || _a === void 0 ? void 0 : _a.terminate();
|
|
29
|
-
workers.delete(workerId);
|
|
30
|
-
});
|
|
31
|
-
workerSchedulerRegistered = true;
|
|
32
|
-
}
|
package/esm/mkcert.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export interface SelfSignedCertificate {
|
|
2
|
-
key: string;
|
|
3
|
-
cert: string;
|
|
4
|
-
rootCA?: string;
|
|
5
|
-
}
|
|
6
|
-
export declare function createSelfSignedCertificate(host?: string, certDir?: string): Promise<SelfSignedCertificate | undefined>;
|
|
7
|
-
export declare function getCacheDirectory(fileDirectory: string, envPath?: string): string;
|
package/esm/mkcert.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { execSync } from "node:child_process";
|
|
2
|
-
import { createPrivateKey, X509Certificate } from "node:crypto";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import os from "os";
|
|
6
|
-
const { WritableStream } = require("node:stream/web");
|
|
7
|
-
const MKCERT_VERSION = "v1.4.4";
|
|
8
|
-
function getBinaryName() {
|
|
9
|
-
const platform = process.platform;
|
|
10
|
-
const arch = process.arch === "x64" ? "amd64" : process.arch;
|
|
11
|
-
if (platform === "win32") {
|
|
12
|
-
return `mkcert-${MKCERT_VERSION}-windows-${arch}.exe`;
|
|
13
|
-
}
|
|
14
|
-
if (platform === "darwin") {
|
|
15
|
-
return `mkcert-${MKCERT_VERSION}-darwin-${arch}`;
|
|
16
|
-
}
|
|
17
|
-
if (platform === "linux") {
|
|
18
|
-
return `mkcert-${MKCERT_VERSION}-linux-${arch}`;
|
|
19
|
-
}
|
|
20
|
-
throw new Error(`Unsupported platform: ${platform}`);
|
|
21
|
-
}
|
|
22
|
-
async function downloadBinary() {
|
|
23
|
-
try {
|
|
24
|
-
const binaryName = getBinaryName();
|
|
25
|
-
const cacheDirectory = getCacheDirectory("mkcert");
|
|
26
|
-
const binaryPath = path.join(cacheDirectory, binaryName);
|
|
27
|
-
if (fs.existsSync(binaryPath)) {
|
|
28
|
-
return binaryPath;
|
|
29
|
-
}
|
|
30
|
-
const downloadUrl = `https://github.com/FiloSottile/mkcert/releases/download/${MKCERT_VERSION}/${binaryName}`;
|
|
31
|
-
await fs.promises.mkdir(cacheDirectory, { recursive: true });
|
|
32
|
-
console.log(`Downloading mkcert package...`);
|
|
33
|
-
const response = await fetch(downloadUrl);
|
|
34
|
-
if (!response.ok || !response.body) {
|
|
35
|
-
throw new Error(`request failed with status ${response.status}`);
|
|
36
|
-
}
|
|
37
|
-
console.log(`Download response was successful, writing to disk`);
|
|
38
|
-
const binaryWriteStream = fs.createWriteStream(binaryPath);
|
|
39
|
-
await response.body.pipeTo(new WritableStream({
|
|
40
|
-
write(chunk) {
|
|
41
|
-
return new Promise((resolve, reject) => {
|
|
42
|
-
binaryWriteStream.write(chunk, (error) => {
|
|
43
|
-
if (error) {
|
|
44
|
-
reject(error);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
resolve();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
},
|
|
51
|
-
close() {
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
binaryWriteStream.close((error) => {
|
|
54
|
-
if (error) {
|
|
55
|
-
reject(error);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
resolve();
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
}));
|
|
63
|
-
await fs.promises.chmod(binaryPath, 0o755);
|
|
64
|
-
return binaryPath;
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
console.error("Error downloading mkcert:", err);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
export async function createSelfSignedCertificate(host, certDir = "certificates") {
|
|
71
|
-
try {
|
|
72
|
-
const binaryPath = await downloadBinary();
|
|
73
|
-
if (!binaryPath)
|
|
74
|
-
throw new Error("missing mkcert binary");
|
|
75
|
-
const resolvedCertDir = path.resolve(process.cwd(), `./${certDir}`);
|
|
76
|
-
await fs.promises.mkdir(resolvedCertDir, {
|
|
77
|
-
recursive: true,
|
|
78
|
-
});
|
|
79
|
-
const keyPath = path.resolve(resolvedCertDir, "localhost-key.pem");
|
|
80
|
-
const certPath = path.resolve(resolvedCertDir, "localhost.pem");
|
|
81
|
-
if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
|
|
82
|
-
const cert = new X509Certificate(fs.readFileSync(certPath));
|
|
83
|
-
const key = fs.readFileSync(keyPath);
|
|
84
|
-
if (cert.checkHost(host !== null && host !== void 0 ? host : "localhost") &&
|
|
85
|
-
cert.checkPrivateKey(createPrivateKey(key))) {
|
|
86
|
-
console.log("Using already generated self signed certificate");
|
|
87
|
-
const caLocation = execSync(`"${binaryPath}" -CAROOT`)
|
|
88
|
-
.toString()
|
|
89
|
-
.trim();
|
|
90
|
-
return {
|
|
91
|
-
key: keyPath,
|
|
92
|
-
cert: certPath,
|
|
93
|
-
rootCA: `${caLocation}/rootCA.pem`,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
console.log("Attempting to generate self signed certificate. This may prompt for your password");
|
|
98
|
-
const defaultHosts = ["localhost", "127.0.0.1", "::1"];
|
|
99
|
-
const hosts = host && !defaultHosts.includes(host)
|
|
100
|
-
? [...defaultHosts, host]
|
|
101
|
-
: defaultHosts;
|
|
102
|
-
execSync(`"${binaryPath}" -install -key-file "${keyPath}" -cert-file "${certPath}" ${hosts.join(" ")}`, { stdio: "ignore" });
|
|
103
|
-
const caLocation = execSync(`"${binaryPath}" -CAROOT`).toString().trim();
|
|
104
|
-
if (!fs.existsSync(keyPath) || !fs.existsSync(certPath)) {
|
|
105
|
-
throw new Error("Certificate files not found");
|
|
106
|
-
}
|
|
107
|
-
console.log(`CA Root certificate created in ${caLocation}`);
|
|
108
|
-
console.log(`Certificates created in ${resolvedCertDir}`);
|
|
109
|
-
const gitignorePath = path.resolve(process.cwd(), "./.gitignore");
|
|
110
|
-
if (fs.existsSync(gitignorePath)) {
|
|
111
|
-
const gitignore = await fs.promises.readFile(gitignorePath, "utf8");
|
|
112
|
-
if (!gitignore.includes(certDir)) {
|
|
113
|
-
console.log("Adding certificates to .gitignore");
|
|
114
|
-
await fs.promises.appendFile(gitignorePath, `\n${certDir}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
key: keyPath,
|
|
119
|
-
cert: certPath,
|
|
120
|
-
rootCA: `${caLocation}/rootCA.pem`,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
catch (err) {
|
|
124
|
-
console.error("Failed to generate self-signed certificate. Falling back to http.", err);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// get platform specific cache directory adapted from playwright's handling
|
|
128
|
-
// https://github.com/microsoft/playwright/blob/7d924470d397975a74a19184c136b3573a974e13/packages/playwright-core/src/utils/registry.ts#L141
|
|
129
|
-
export function getCacheDirectory(fileDirectory, envPath) {
|
|
130
|
-
let result;
|
|
131
|
-
if (envPath) {
|
|
132
|
-
result = envPath;
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
let systemCacheDirectory;
|
|
136
|
-
if (process.platform === "linux") {
|
|
137
|
-
systemCacheDirectory =
|
|
138
|
-
process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache");
|
|
139
|
-
}
|
|
140
|
-
else if (process.platform === "darwin") {
|
|
141
|
-
systemCacheDirectory = path.join(os.homedir(), "Library", "Caches");
|
|
142
|
-
}
|
|
143
|
-
else if (process.platform === "win32") {
|
|
144
|
-
systemCacheDirectory =
|
|
145
|
-
process.env.LOCALAPPDATA || path.join(os.homedir(), "AppData", "Local");
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
/// Attempt to use generic tmp location for un-handled platform
|
|
149
|
-
if (!systemCacheDirectory) {
|
|
150
|
-
for (const dir of [
|
|
151
|
-
path.join(os.homedir(), ".cache"),
|
|
152
|
-
path.join(os.tmpdir()),
|
|
153
|
-
]) {
|
|
154
|
-
if (fs.existsSync(dir)) {
|
|
155
|
-
systemCacheDirectory = dir;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (!systemCacheDirectory) {
|
|
161
|
-
console.error(new Error("Unsupported platform: " + process.platform));
|
|
162
|
-
process.exit(0);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
result = path.join(systemCacheDirectory, fileDirectory);
|
|
166
|
-
}
|
|
167
|
-
if (!path.isAbsolute(result)) {
|
|
168
|
-
// It is important to resolve to the absolute path:
|
|
169
|
-
// - for unzipping to work correctly;
|
|
170
|
-
// - so that registry directory matches between installation and execution.
|
|
171
|
-
// INIT_CWD points to the root of `npm/yarn install` and is probably what
|
|
172
|
-
// the user meant when typing the relative path.
|
|
173
|
-
result = path.resolve(process.env["INIT_CWD"] || process.cwd(), result);
|
|
174
|
-
}
|
|
175
|
-
return result;
|
|
176
|
-
}
|
package/esm/project.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { HmrIdentifiers, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "./binding";
|
|
2
|
-
import * as binding from "./binding";
|
|
3
|
-
import { ProjectOptions, RawEntrypoints, Update } from "./types";
|
|
4
|
-
export declare class TurbopackInternalError extends Error {
|
|
5
|
-
name: string;
|
|
6
|
-
constructor(cause: Error);
|
|
7
|
-
}
|
|
8
|
-
export declare function projectFactory(): (options: Required<ProjectOptions>, turboEngineOptions: binding.NapiTurboEngineOptions) => Promise<{
|
|
9
|
-
readonly _nativeProject: {
|
|
10
|
-
__napiType: "Project";
|
|
11
|
-
};
|
|
12
|
-
update(options: Partial<ProjectOptions>): Promise<void>;
|
|
13
|
-
writeAllEntrypointsToDisk(): Promise<TurbopackResult<RawEntrypoints>>;
|
|
14
|
-
entrypointsSubscribe(): AsyncGenerator<{
|
|
15
|
-
apps: {
|
|
16
|
-
readonly _nativeEndpoint: {
|
|
17
|
-
__napiType: "Endpoint";
|
|
18
|
-
};
|
|
19
|
-
writeToDisk(): Promise<TurbopackResult<NapiWrittenEndpoint>>;
|
|
20
|
-
clientChanged(): Promise<AsyncIterableIterator<TurbopackResult<{}>>>;
|
|
21
|
-
serverChanged(includeIssues: boolean): Promise<AsyncIterableIterator<TurbopackResult<{}>>>;
|
|
22
|
-
}[];
|
|
23
|
-
libraries: {
|
|
24
|
-
readonly _nativeEndpoint: {
|
|
25
|
-
__napiType: "Endpoint";
|
|
26
|
-
};
|
|
27
|
-
writeToDisk(): Promise<TurbopackResult<NapiWrittenEndpoint>>;
|
|
28
|
-
clientChanged(): Promise<AsyncIterableIterator<TurbopackResult<{}>>>;
|
|
29
|
-
serverChanged(includeIssues: boolean): Promise<AsyncIterableIterator<TurbopackResult<{}>>>;
|
|
30
|
-
}[];
|
|
31
|
-
issues: binding.NapiIssue[];
|
|
32
|
-
diagnostics: binding.NapiDiagnostic[];
|
|
33
|
-
}, void, unknown>;
|
|
34
|
-
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
|
|
35
|
-
hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
|
|
36
|
-
traceSource(stackFrame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>;
|
|
37
|
-
getSourceForAsset(filePath: string): Promise<string | null>;
|
|
38
|
-
getSourceMap(filePath: string): Promise<string | null>;
|
|
39
|
-
getSourceMapSync(filePath: string): string | null;
|
|
40
|
-
updateInfoSubscribe(aggregationMs: number): AsyncIterableIterator<TurbopackResult<NapiUpdateMessage>>;
|
|
41
|
-
shutdown(): Promise<void>;
|
|
42
|
-
onExit(): Promise<void>;
|
|
43
|
-
}>;
|