@utoo/pack 0.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +9 -0
- package/cjs/binding.d.ts +222 -0
- package/cjs/binding.js +341 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +75 -0
- package/cjs/magicIdentifier.d.ts +2 -0
- package/cjs/magicIdentifier.js +89 -0
- package/cjs/project.d.ts +43 -0
- package/cjs/project.js +290 -0
- package/cjs/types.d.ts +261 -0
- package/cjs/types.js +2 -0
- package/cjs/util.d.ts +10 -0
- package/cjs/util.js +139 -0
- package/cjs/xcodeProfile.d.ts +1 -0
- package/cjs/xcodeProfile.js +16 -0
- package/esm/binding.d.ts +222 -0
- package/esm/binding.js +341 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +69 -0
- package/esm/magicIdentifier.d.ts +2 -0
- package/esm/magicIdentifier.js +85 -0
- package/esm/project.d.ts +43 -0
- package/esm/project.js +252 -0
- package/esm/types.d.ts +261 -0
- package/esm/types.js +1 -0
- package/esm/util.d.ts +10 -0
- package/esm/util.js +130 -0
- package/esm/xcodeProfile.d.ts +1 -0
- package/esm/xcodeProfile.js +13 -0
- package/global.d.ts +10 -0
- package/package.json +75 -0
package/esm/binding.js
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
/* prettier-ignore */
|
|
5
|
+
/* auto-generated by NAPI-RS */
|
|
6
|
+
const { existsSync, readFileSync } = require('fs');
|
|
7
|
+
const { join } = require('path');
|
|
8
|
+
const { platform, arch } = process;
|
|
9
|
+
let nativeBinding = null;
|
|
10
|
+
let localFileExisted = false;
|
|
11
|
+
let loadError = null;
|
|
12
|
+
function isMusl() {
|
|
13
|
+
// For Node 10
|
|
14
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
15
|
+
try {
|
|
16
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim();
|
|
17
|
+
return readFileSync(lddPath, 'utf8').includes('musl');
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const { glibcVersionRuntime } = process.report.getReport().header;
|
|
25
|
+
return !glibcVersionRuntime;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
switch (platform) {
|
|
29
|
+
case 'android':
|
|
30
|
+
switch (arch) {
|
|
31
|
+
case 'arm64':
|
|
32
|
+
localFileExisted = existsSync(join(__dirname, 'pack.android-arm64.node'));
|
|
33
|
+
try {
|
|
34
|
+
if (localFileExisted) {
|
|
35
|
+
nativeBinding = require('./pack.android-arm64.node');
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
nativeBinding = require('@utoo/pack-android-arm64');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
loadError = e;
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case 'arm':
|
|
46
|
+
localFileExisted = existsSync(join(__dirname, 'pack.android-arm-eabi.node'));
|
|
47
|
+
try {
|
|
48
|
+
if (localFileExisted) {
|
|
49
|
+
nativeBinding = require('./pack.android-arm-eabi.node');
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
nativeBinding = require('@utoo/pack-android-arm-eabi');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
loadError = e;
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
throw new Error(`Unsupported architecture on Android ${arch}`);
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
case 'win32':
|
|
64
|
+
switch (arch) {
|
|
65
|
+
case 'x64':
|
|
66
|
+
localFileExisted = existsSync(join(__dirname, 'pack.win32-x64-msvc.node'));
|
|
67
|
+
try {
|
|
68
|
+
if (localFileExisted) {
|
|
69
|
+
nativeBinding = require('./pack.win32-x64-msvc.node');
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
nativeBinding = require('@utoo/pack-win32-x64-msvc');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
loadError = e;
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case 'ia32':
|
|
80
|
+
localFileExisted = existsSync(join(__dirname, 'pack.win32-ia32-msvc.node'));
|
|
81
|
+
try {
|
|
82
|
+
if (localFileExisted) {
|
|
83
|
+
nativeBinding = require('./pack.win32-ia32-msvc.node');
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
nativeBinding = require('@utoo/pack-win32-ia32-msvc');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
loadError = e;
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
case 'arm64':
|
|
94
|
+
localFileExisted = existsSync(join(__dirname, 'pack.win32-arm64-msvc.node'));
|
|
95
|
+
try {
|
|
96
|
+
if (localFileExisted) {
|
|
97
|
+
nativeBinding = require('./pack.win32-arm64-msvc.node');
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
nativeBinding = require('@utoo/pack-win32-arm64-msvc');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
loadError = e;
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
default:
|
|
108
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`);
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
case 'darwin':
|
|
112
|
+
localFileExisted = existsSync(join(__dirname, 'pack.darwin-universal.node'));
|
|
113
|
+
try {
|
|
114
|
+
if (localFileExisted) {
|
|
115
|
+
nativeBinding = require('./pack.darwin-universal.node');
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
nativeBinding = require('@utoo/pack-darwin-universal');
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
catch (_a) { }
|
|
123
|
+
switch (arch) {
|
|
124
|
+
case 'x64':
|
|
125
|
+
localFileExisted = existsSync(join(__dirname, 'pack.darwin-x64.node'));
|
|
126
|
+
try {
|
|
127
|
+
if (localFileExisted) {
|
|
128
|
+
nativeBinding = require('./pack.darwin-x64.node');
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
nativeBinding = require('@utoo/pack-darwin-x64');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
loadError = e;
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
case 'arm64':
|
|
139
|
+
localFileExisted = existsSync(join(__dirname, 'pack.darwin-arm64.node'));
|
|
140
|
+
try {
|
|
141
|
+
if (localFileExisted) {
|
|
142
|
+
nativeBinding = require('./pack.darwin-arm64.node');
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
nativeBinding = require('@utoo/pack-darwin-arm64');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
loadError = e;
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`);
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
case 'freebsd':
|
|
157
|
+
if (arch !== 'x64') {
|
|
158
|
+
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
|
|
159
|
+
}
|
|
160
|
+
localFileExisted = existsSync(join(__dirname, 'pack.freebsd-x64.node'));
|
|
161
|
+
try {
|
|
162
|
+
if (localFileExisted) {
|
|
163
|
+
nativeBinding = require('./pack.freebsd-x64.node');
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
nativeBinding = require('@utoo/pack-freebsd-x64');
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
loadError = e;
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
case 'linux':
|
|
174
|
+
switch (arch) {
|
|
175
|
+
case 'x64':
|
|
176
|
+
if (isMusl()) {
|
|
177
|
+
localFileExisted = existsSync(join(__dirname, 'pack.linux-x64-musl.node'));
|
|
178
|
+
try {
|
|
179
|
+
if (localFileExisted) {
|
|
180
|
+
nativeBinding = require('./pack.linux-x64-musl.node');
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
nativeBinding = require('@utoo/pack-linux-x64-musl');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
loadError = e;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
localFileExisted = existsSync(join(__dirname, 'pack.linux-x64-gnu.node'));
|
|
192
|
+
try {
|
|
193
|
+
if (localFileExisted) {
|
|
194
|
+
nativeBinding = require('./pack.linux-x64-gnu.node');
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
nativeBinding = require('@utoo/pack-linux-x64-gnu');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
loadError = e;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
case 'arm64':
|
|
206
|
+
if (isMusl()) {
|
|
207
|
+
localFileExisted = existsSync(join(__dirname, 'pack.linux-arm64-musl.node'));
|
|
208
|
+
try {
|
|
209
|
+
if (localFileExisted) {
|
|
210
|
+
nativeBinding = require('./pack.linux-arm64-musl.node');
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
nativeBinding = require('@utoo/pack-linux-arm64-musl');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
loadError = e;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
localFileExisted = existsSync(join(__dirname, 'pack.linux-arm64-gnu.node'));
|
|
222
|
+
try {
|
|
223
|
+
if (localFileExisted) {
|
|
224
|
+
nativeBinding = require('./pack.linux-arm64-gnu.node');
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
nativeBinding = require('@utoo/pack-linux-arm64-gnu');
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch (e) {
|
|
231
|
+
loadError = e;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
break;
|
|
235
|
+
case 'arm':
|
|
236
|
+
if (isMusl()) {
|
|
237
|
+
localFileExisted = existsSync(join(__dirname, 'pack.linux-arm-musleabihf.node'));
|
|
238
|
+
try {
|
|
239
|
+
if (localFileExisted) {
|
|
240
|
+
nativeBinding = require('./pack.linux-arm-musleabihf.node');
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
nativeBinding = require('@utoo/pack-linux-arm-musleabihf');
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
catch (e) {
|
|
247
|
+
loadError = e;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
localFileExisted = existsSync(join(__dirname, 'pack.linux-arm-gnueabihf.node'));
|
|
252
|
+
try {
|
|
253
|
+
if (localFileExisted) {
|
|
254
|
+
nativeBinding = require('./pack.linux-arm-gnueabihf.node');
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
nativeBinding = require('@utoo/pack-linux-arm-gnueabihf');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
loadError = e;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
break;
|
|
265
|
+
case 'riscv64':
|
|
266
|
+
if (isMusl()) {
|
|
267
|
+
localFileExisted = existsSync(join(__dirname, 'pack.linux-riscv64-musl.node'));
|
|
268
|
+
try {
|
|
269
|
+
if (localFileExisted) {
|
|
270
|
+
nativeBinding = require('./pack.linux-riscv64-musl.node');
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
nativeBinding = require('@utoo/pack-linux-riscv64-musl');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
catch (e) {
|
|
277
|
+
loadError = e;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
localFileExisted = existsSync(join(__dirname, 'pack.linux-riscv64-gnu.node'));
|
|
282
|
+
try {
|
|
283
|
+
if (localFileExisted) {
|
|
284
|
+
nativeBinding = require('./pack.linux-riscv64-gnu.node');
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
nativeBinding = require('@utoo/pack-linux-riscv64-gnu');
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
catch (e) {
|
|
291
|
+
loadError = e;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
break;
|
|
295
|
+
case 's390x':
|
|
296
|
+
localFileExisted = existsSync(join(__dirname, 'pack.linux-s390x-gnu.node'));
|
|
297
|
+
try {
|
|
298
|
+
if (localFileExisted) {
|
|
299
|
+
nativeBinding = require('./pack.linux-s390x-gnu.node');
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
nativeBinding = require('@utoo/pack-linux-s390x-gnu');
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
catch (e) {
|
|
306
|
+
loadError = e;
|
|
307
|
+
}
|
|
308
|
+
break;
|
|
309
|
+
default:
|
|
310
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`);
|
|
311
|
+
}
|
|
312
|
+
break;
|
|
313
|
+
default:
|
|
314
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
|
|
315
|
+
}
|
|
316
|
+
if (!nativeBinding) {
|
|
317
|
+
if (loadError) {
|
|
318
|
+
throw loadError;
|
|
319
|
+
}
|
|
320
|
+
throw new Error(`Failed to load native binding`);
|
|
321
|
+
}
|
|
322
|
+
const { endpointWriteToDisk, endpointServerChangedSubscribe, endpointClientChangedSubscribe, projectNew, projectUpdate, projectOnExit, projectShutdown, projectWriteAllEntrypointsToDisk, projectEntrypointsSubscribe, projectHmrEvents, projectHmrIdentifiersSubscribe, projectUpdateInfoSubscribe, projectTraceSource, projectGetSourceForAsset, projectGetSourceMap, projectGetSourceMapSync, rootTaskDispose, initCustomTraceSubscriber, teardownTraceSubscriber } = nativeBinding;
|
|
323
|
+
module.exports.endpointWriteToDisk = endpointWriteToDisk;
|
|
324
|
+
module.exports.endpointServerChangedSubscribe = endpointServerChangedSubscribe;
|
|
325
|
+
module.exports.endpointClientChangedSubscribe = endpointClientChangedSubscribe;
|
|
326
|
+
module.exports.projectNew = projectNew;
|
|
327
|
+
module.exports.projectUpdate = projectUpdate;
|
|
328
|
+
module.exports.projectOnExit = projectOnExit;
|
|
329
|
+
module.exports.projectShutdown = projectShutdown;
|
|
330
|
+
module.exports.projectWriteAllEntrypointsToDisk = projectWriteAllEntrypointsToDisk;
|
|
331
|
+
module.exports.projectEntrypointsSubscribe = projectEntrypointsSubscribe;
|
|
332
|
+
module.exports.projectHmrEvents = projectHmrEvents;
|
|
333
|
+
module.exports.projectHmrIdentifiersSubscribe = projectHmrIdentifiersSubscribe;
|
|
334
|
+
module.exports.projectUpdateInfoSubscribe = projectUpdateInfoSubscribe;
|
|
335
|
+
module.exports.projectTraceSource = projectTraceSource;
|
|
336
|
+
module.exports.projectGetSourceForAsset = projectGetSourceForAsset;
|
|
337
|
+
module.exports.projectGetSourceMap = projectGetSourceMap;
|
|
338
|
+
module.exports.projectGetSourceMapSync = projectGetSourceMapSync;
|
|
339
|
+
module.exports.rootTaskDispose = rootTaskDispose;
|
|
340
|
+
module.exports.initCustomTraceSubscriber = initCustomTraceSubscriber;
|
|
341
|
+
module.exports.teardownTraceSubscriber = teardownTraceSubscriber;
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function build(dir?: string): Promise<void>;
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { nanoid } from "nanoid";
|
|
2
|
+
import { projectFactory } from "./project";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { formatIssue, isRelevantWarning } from "./util";
|
|
6
|
+
import { xcodeProfilingReady } from "./xcodeProfile";
|
|
7
|
+
// ref:
|
|
8
|
+
// https://github.com/vercel/next.js/pull/51883
|
|
9
|
+
function blockStdout() {
|
|
10
|
+
// 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
|
|
11
|
+
// see https://github.com/napi-rs/napi-rs/issues/1630
|
|
12
|
+
// and https://github.com/nodejs/node/blob/main/doc/api/process.md#a-note-on-process-io
|
|
13
|
+
if (process.stdout._handle != null) {
|
|
14
|
+
process.stdout._handle.setBlocking(true);
|
|
15
|
+
}
|
|
16
|
+
if (process.stderr._handle != null) {
|
|
17
|
+
process.stderr._handle.setBlocking(true);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export async function build(dir) {
|
|
21
|
+
var _a, _b, _c, _d;
|
|
22
|
+
blockStdout();
|
|
23
|
+
if (process.env.XCODE_PROFILE) {
|
|
24
|
+
await xcodeProfilingReady();
|
|
25
|
+
}
|
|
26
|
+
const cwd = dir || process.cwd();
|
|
27
|
+
const projectOptions = JSON.parse(fs.readFileSync(path.join(cwd, "project_options.json"), {
|
|
28
|
+
encoding: "utf-8",
|
|
29
|
+
}));
|
|
30
|
+
const createProject = projectFactory();
|
|
31
|
+
const project = await createProject({
|
|
32
|
+
processEnv: (_a = projectOptions.processEnv) !== null && _a !== void 0 ? _a : {},
|
|
33
|
+
processDefineEnv: (_b = projectOptions.processDefineEnv) !== null && _b !== void 0 ? _b : {
|
|
34
|
+
client: [],
|
|
35
|
+
nodejs: [],
|
|
36
|
+
edge: [],
|
|
37
|
+
},
|
|
38
|
+
watch: (_c = projectOptions.watch) !== null && _c !== void 0 ? _c : {
|
|
39
|
+
enable: false,
|
|
40
|
+
},
|
|
41
|
+
dev: (_d = projectOptions.dev) !== null && _d !== void 0 ? _d : false,
|
|
42
|
+
buildId: nanoid(),
|
|
43
|
+
config: projectOptions.config,
|
|
44
|
+
rootPath: path.resolve(cwd, projectOptions.rootPath),
|
|
45
|
+
projectPath: path.resolve(cwd, projectOptions.projectPath),
|
|
46
|
+
}, {
|
|
47
|
+
persistentCaching: false,
|
|
48
|
+
});
|
|
49
|
+
const entrypoints = await project.writeAllEntrypointsToDisk();
|
|
50
|
+
const topLevelErrors = [];
|
|
51
|
+
const topLevelWarnings = [];
|
|
52
|
+
for (const issue of entrypoints.issues) {
|
|
53
|
+
if (issue.severity === "error" || issue.severity === "fatal") {
|
|
54
|
+
topLevelErrors.push(formatIssue(issue));
|
|
55
|
+
}
|
|
56
|
+
else if (isRelevantWarning(issue)) {
|
|
57
|
+
topLevelWarnings.push(formatIssue(issue));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (topLevelWarnings.length > 0) {
|
|
61
|
+
console.warn(`Turbopack build encountered ${topLevelWarnings.length} warnings:\n${topLevelWarnings.join("\n")}`);
|
|
62
|
+
}
|
|
63
|
+
if (topLevelErrors.length > 0) {
|
|
64
|
+
throw new Error(`Turbopack build failed with ${topLevelErrors.length} errors:\n${topLevelErrors.join("\n")}`);
|
|
65
|
+
}
|
|
66
|
+
await project.shutdown();
|
|
67
|
+
// TODO: Maybe run tasks in worker is a better way, see
|
|
68
|
+
// https://github.com/vercel/next.js/blob/512d8283054407ab92b2583ecce3b253c3be7b85/packages/next/src/lib/worker.ts
|
|
69
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
function decodeHex(hexStr) {
|
|
2
|
+
if (hexStr.trim() === "") {
|
|
3
|
+
throw new Error("can't decode empty hex");
|
|
4
|
+
}
|
|
5
|
+
const num = parseInt(hexStr, 16);
|
|
6
|
+
if (isNaN(num)) {
|
|
7
|
+
throw new Error(`invalid hex: \`${hexStr}\``);
|
|
8
|
+
}
|
|
9
|
+
return String.fromCodePoint(num);
|
|
10
|
+
}
|
|
11
|
+
const DECODE_REGEX = /^__TURBOPACK__([a-zA-Z0-9_$]+)__$/;
|
|
12
|
+
export function decodeMagicIdentifier(identifier) {
|
|
13
|
+
const matches = identifier.match(DECODE_REGEX);
|
|
14
|
+
if (!matches) {
|
|
15
|
+
return identifier;
|
|
16
|
+
}
|
|
17
|
+
const inner = matches[1];
|
|
18
|
+
let output = "";
|
|
19
|
+
let mode = 0 /* Mode.Text */;
|
|
20
|
+
let buffer = "";
|
|
21
|
+
for (let i = 0; i < inner.length; i++) {
|
|
22
|
+
const char = inner[i];
|
|
23
|
+
if (mode === 0 /* Mode.Text */) {
|
|
24
|
+
if (char === "_") {
|
|
25
|
+
mode = 1 /* Mode.Underscore */;
|
|
26
|
+
}
|
|
27
|
+
else if (char === "$") {
|
|
28
|
+
mode = 2 /* Mode.Hex */;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
output += char;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (mode === 1 /* Mode.Underscore */) {
|
|
35
|
+
if (char === "_") {
|
|
36
|
+
output += " ";
|
|
37
|
+
mode = 0 /* Mode.Text */;
|
|
38
|
+
}
|
|
39
|
+
else if (char === "$") {
|
|
40
|
+
output += "_";
|
|
41
|
+
mode = 2 /* Mode.Hex */;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
output += char;
|
|
45
|
+
mode = 0 /* Mode.Text */;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else if (mode === 2 /* Mode.Hex */) {
|
|
49
|
+
if (buffer.length === 2) {
|
|
50
|
+
output += decodeHex(buffer);
|
|
51
|
+
buffer = "";
|
|
52
|
+
}
|
|
53
|
+
if (char === "_") {
|
|
54
|
+
if (buffer !== "") {
|
|
55
|
+
throw new Error(`invalid hex: \`${buffer}\``);
|
|
56
|
+
}
|
|
57
|
+
mode = 3 /* Mode.LongHex */;
|
|
58
|
+
}
|
|
59
|
+
else if (char === "$") {
|
|
60
|
+
if (buffer !== "") {
|
|
61
|
+
throw new Error(`invalid hex: \`${buffer}\``);
|
|
62
|
+
}
|
|
63
|
+
mode = 0 /* Mode.Text */;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
buffer += char;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (mode === 3 /* Mode.LongHex */) {
|
|
70
|
+
if (char === "_") {
|
|
71
|
+
throw new Error(`invalid hex: \`${buffer + char}\``);
|
|
72
|
+
}
|
|
73
|
+
else if (char === "$") {
|
|
74
|
+
output += decodeHex(buffer);
|
|
75
|
+
buffer = "";
|
|
76
|
+
mode = 0 /* Mode.Text */;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
buffer += char;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return output;
|
|
84
|
+
}
|
|
85
|
+
export const MAGIC_IDENTIFIER_REGEX = /__TURBOPACK__[a-zA-Z0-9_$]+__/g;
|
package/esm/project.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as binding from "./binding";
|
|
2
|
+
import type { NapiWrittenEndpoint, StackFrame } 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: 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<binding.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<binding.NapiUpdateMessage>>;
|
|
41
|
+
shutdown(): Promise<void>;
|
|
42
|
+
onExit(): Promise<void>;
|
|
43
|
+
}>;
|