@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/cjs/util.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModuleBuildError = void 0;
|
|
4
|
+
exports.processIssues = processIssues;
|
|
5
|
+
exports.isWellKnownError = isWellKnownError;
|
|
6
|
+
exports.formatIssue = formatIssue;
|
|
7
|
+
exports.renderStyledStringToErrorAnsi = renderStyledStringToErrorAnsi;
|
|
8
|
+
exports.isRelevantWarning = isRelevantWarning;
|
|
9
|
+
const picocolors_1 = require("picocolors");
|
|
10
|
+
const code_frame_1 = require("@babel/code-frame");
|
|
11
|
+
const magicIdentifier_1 = require("./magicIdentifier");
|
|
12
|
+
class ModuleBuildError extends Error {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.name = "ModuleBuildError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ModuleBuildError = ModuleBuildError;
|
|
19
|
+
function processIssues(result, throwIssue, logErrors) {
|
|
20
|
+
const relevantIssues = new Set();
|
|
21
|
+
for (const issue of result.issues) {
|
|
22
|
+
if (issue.severity !== "error" &&
|
|
23
|
+
issue.severity !== "fatal" &&
|
|
24
|
+
issue.severity !== "warning")
|
|
25
|
+
continue;
|
|
26
|
+
if (issue.severity !== "warning") {
|
|
27
|
+
if (throwIssue) {
|
|
28
|
+
const formatted = formatIssue(issue);
|
|
29
|
+
relevantIssues.add(formatted);
|
|
30
|
+
}
|
|
31
|
+
// if we throw the issue it will most likely get handed and logged elsewhere
|
|
32
|
+
else if (logErrors && isWellKnownError(issue)) {
|
|
33
|
+
const formatted = formatIssue(issue);
|
|
34
|
+
console.error(formatted);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (relevantIssues.size && throwIssue) {
|
|
39
|
+
throw new ModuleBuildError([...relevantIssues].join("\n\n"));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function isWellKnownError(issue) {
|
|
43
|
+
const { title } = issue;
|
|
44
|
+
const formattedTitle = renderStyledStringToErrorAnsi(title);
|
|
45
|
+
// TODO: add more well known errors
|
|
46
|
+
if (formattedTitle.includes("Module not found") ||
|
|
47
|
+
formattedTitle.includes("Unknown module type")) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
function formatIssue(issue) {
|
|
53
|
+
const { filePath, title, description, source } = issue;
|
|
54
|
+
let { documentationLink } = issue;
|
|
55
|
+
let formattedTitle = renderStyledStringToErrorAnsi(title).replace(/\n/g, "\n ");
|
|
56
|
+
let formattedFilePath = filePath
|
|
57
|
+
.replace("[project]/", "./")
|
|
58
|
+
.replaceAll("/./", "/")
|
|
59
|
+
.replace("\\\\?\\", "");
|
|
60
|
+
let message = "";
|
|
61
|
+
if (source && source.range) {
|
|
62
|
+
const { start } = source.range;
|
|
63
|
+
message = `${formattedFilePath}:${start.line + 1}:${start.column + 1}\n${formattedTitle}`;
|
|
64
|
+
}
|
|
65
|
+
else if (formattedFilePath) {
|
|
66
|
+
message = `${formattedFilePath}\n${formattedTitle}`;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
message = formattedTitle;
|
|
70
|
+
}
|
|
71
|
+
message += "\n";
|
|
72
|
+
if ((source === null || source === void 0 ? void 0 : source.range) && source.source.content) {
|
|
73
|
+
const { start, end } = source.range;
|
|
74
|
+
message +=
|
|
75
|
+
(0, code_frame_1.codeFrameColumns)(source.source.content, {
|
|
76
|
+
start: {
|
|
77
|
+
line: start.line + 1,
|
|
78
|
+
column: start.column + 1,
|
|
79
|
+
},
|
|
80
|
+
end: {
|
|
81
|
+
line: end.line + 1,
|
|
82
|
+
column: end.column + 1,
|
|
83
|
+
},
|
|
84
|
+
}, { forceColor: true }).trim() + "\n\n";
|
|
85
|
+
}
|
|
86
|
+
if (description) {
|
|
87
|
+
message += renderStyledStringToErrorAnsi(description) + "\n\n";
|
|
88
|
+
}
|
|
89
|
+
// TODO: make it possible to enable this for debugging, but not in tests.
|
|
90
|
+
// if (detail) {
|
|
91
|
+
// message += renderStyledStringToErrorAnsi(detail) + '\n\n'
|
|
92
|
+
// }
|
|
93
|
+
// TODO: Include a trace from the issue.
|
|
94
|
+
if (documentationLink) {
|
|
95
|
+
message += documentationLink + "\n\n";
|
|
96
|
+
}
|
|
97
|
+
return message;
|
|
98
|
+
}
|
|
99
|
+
function renderStyledStringToErrorAnsi(string) {
|
|
100
|
+
function decodeMagicIdentifiers(str) {
|
|
101
|
+
return str.replaceAll(magicIdentifier_1.MAGIC_IDENTIFIER_REGEX, (ident) => {
|
|
102
|
+
try {
|
|
103
|
+
return (0, picocolors_1.magenta)(`{${(0, magicIdentifier_1.decodeMagicIdentifier)(ident)}}`);
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
return (0, picocolors_1.magenta)(`{${ident} (decoding failed: ${e})}`);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
switch (string.type) {
|
|
111
|
+
case "text":
|
|
112
|
+
return decodeMagicIdentifiers(string.value);
|
|
113
|
+
case "strong":
|
|
114
|
+
return (0, picocolors_1.bold)((0, picocolors_1.red)(decodeMagicIdentifiers(string.value)));
|
|
115
|
+
case "code":
|
|
116
|
+
return (0, picocolors_1.green)(decodeMagicIdentifiers(string.value));
|
|
117
|
+
case "line":
|
|
118
|
+
return string.value.map(renderStyledStringToErrorAnsi).join("");
|
|
119
|
+
case "stack":
|
|
120
|
+
return string.value.map(renderStyledStringToErrorAnsi).join("\n");
|
|
121
|
+
default:
|
|
122
|
+
throw new Error("Unknown StyledString type", string);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function isRelevantWarning(issue) {
|
|
126
|
+
return issue.severity === "warning" && !isNodeModulesIssue(issue);
|
|
127
|
+
}
|
|
128
|
+
function isNodeModulesIssue(issue) {
|
|
129
|
+
if (issue.severity === "warning" && issue.stage === "config") {
|
|
130
|
+
// Override for the externalize issue
|
|
131
|
+
// `Package foo (serverExternalPackages or default list) can't be external`
|
|
132
|
+
if (renderStyledStringToErrorAnsi(issue.title).includes("can't be external")) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return (issue.severity === "warning" &&
|
|
137
|
+
(issue.filePath.match(/^(?:.*[\\/])?node_modules(?:[\\/].*)?$/) !== null ||
|
|
138
|
+
issue.filePath.includes("@utoo/pack")));
|
|
139
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function xcodeProfilingReady(): Promise<void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
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/binding.d.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
export declare class ExternalObject<T> {
|
|
7
|
+
readonly '': {
|
|
8
|
+
readonly '': unique symbol
|
|
9
|
+
[K: symbol]: T
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export interface TransformOutput {
|
|
13
|
+
code: string
|
|
14
|
+
map?: string
|
|
15
|
+
output?: string
|
|
16
|
+
diagnostics: Array<string>
|
|
17
|
+
}
|
|
18
|
+
export interface NapiEndpointConfig {
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
export interface NapiServerPath {
|
|
22
|
+
path: string
|
|
23
|
+
contentHash: string
|
|
24
|
+
}
|
|
25
|
+
export interface NapiWrittenEndpoint {
|
|
26
|
+
type: string
|
|
27
|
+
entryPath?: string
|
|
28
|
+
clientPaths: Array<string>
|
|
29
|
+
serverPaths: Array<NapiServerPath>
|
|
30
|
+
config: NapiEndpointConfig
|
|
31
|
+
}
|
|
32
|
+
export declare function endpointWriteToDisk(endpoint: { __napiType: "Endpoint" }): Promise<TurbopackResult>
|
|
33
|
+
export declare function endpointServerChangedSubscribe(endpoint: { __napiType: "Endpoint" }, issues: boolean, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
|
34
|
+
export declare function endpointClientChangedSubscribe(endpoint: { __napiType: "Endpoint" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
|
35
|
+
export interface NapiEnvVar {
|
|
36
|
+
name: string
|
|
37
|
+
value: string
|
|
38
|
+
}
|
|
39
|
+
export interface NapiWatchOptions {
|
|
40
|
+
/** Whether to watch the filesystem for file changes. */
|
|
41
|
+
enable: boolean
|
|
42
|
+
/**
|
|
43
|
+
* Enable polling at a certain interval if the native file watching doesn't work (e.g.
|
|
44
|
+
* docker).
|
|
45
|
+
*/
|
|
46
|
+
pollIntervalMs?: number
|
|
47
|
+
}
|
|
48
|
+
export interface NapiProjectOptions {
|
|
49
|
+
/**
|
|
50
|
+
* A root path from which all files must be nested under. Trying to access
|
|
51
|
+
* a file outside this root will fail. Think of this as a chroot.
|
|
52
|
+
*/
|
|
53
|
+
rootPath: string
|
|
54
|
+
/** A path inside the root_path which contains the app/pages directories. */
|
|
55
|
+
projectPath: string
|
|
56
|
+
/** Filesystem watcher options. */
|
|
57
|
+
watch: NapiWatchOptions
|
|
58
|
+
/** The contents of config.js, serialized to JSON. */
|
|
59
|
+
config: string
|
|
60
|
+
/** A map of environment variables to use when compiling code. */
|
|
61
|
+
processEnv: Array<NapiEnvVar>
|
|
62
|
+
/**
|
|
63
|
+
* A map of environment variables which should get injected at compile
|
|
64
|
+
* time.
|
|
65
|
+
*/
|
|
66
|
+
processDefineEnv: NapiDefineEnv
|
|
67
|
+
/** The mode in which Next.js is running. */
|
|
68
|
+
dev: boolean
|
|
69
|
+
/** The build id. */
|
|
70
|
+
buildId: string
|
|
71
|
+
}
|
|
72
|
+
/** [NapiProjectOptions] with all fields optional. */
|
|
73
|
+
export interface NapiPartialProjectOptions {
|
|
74
|
+
/**
|
|
75
|
+
* A root path from which all files must be nested under. Trying to access
|
|
76
|
+
* a file outside this root will fail. Think of this as a chroot.
|
|
77
|
+
*/
|
|
78
|
+
rootPath?: string
|
|
79
|
+
/** A path inside the root_path which contains the app/pages directories. */
|
|
80
|
+
projectPath?: string
|
|
81
|
+
/** Filesystem watcher options. */
|
|
82
|
+
watch?: NapiWatchOptions
|
|
83
|
+
/** The contents of config.js, serialized to JSON. */
|
|
84
|
+
config?: string
|
|
85
|
+
/** A map of environment variables to use when compiling code. */
|
|
86
|
+
processEnv?: Array<NapiEnvVar>
|
|
87
|
+
/**
|
|
88
|
+
* A map of environment variables which should get injected at compile
|
|
89
|
+
* time.
|
|
90
|
+
*/
|
|
91
|
+
processDefineEnv?: NapiDefineEnv
|
|
92
|
+
/** The mode in which Next.js is running. */
|
|
93
|
+
dev?: boolean
|
|
94
|
+
/** The build id. */
|
|
95
|
+
buildId?: string
|
|
96
|
+
/**
|
|
97
|
+
* When the code is minified, this opts out of the default mangling of
|
|
98
|
+
* local names for variables, functions etc., which can be useful for
|
|
99
|
+
* debugging/profiling purposes.
|
|
100
|
+
*/
|
|
101
|
+
noMangling?: boolean
|
|
102
|
+
}
|
|
103
|
+
export interface NapiDefineEnv {
|
|
104
|
+
client: Array<NapiEnvVar>
|
|
105
|
+
edge: Array<NapiEnvVar>
|
|
106
|
+
nodejs: Array<NapiEnvVar>
|
|
107
|
+
}
|
|
108
|
+
export interface NapiTurboEngineOptions {
|
|
109
|
+
/** Use the new backend with persistent caching enabled. */
|
|
110
|
+
persistentCaching?: boolean
|
|
111
|
+
/** An upper bound of memory that turbopack will attempt to stay under. */
|
|
112
|
+
memoryLimit?: number
|
|
113
|
+
/** Track dependencies between tasks. If false, any change during build will error. */
|
|
114
|
+
dependencyTracking?: boolean
|
|
115
|
+
}
|
|
116
|
+
export declare function projectNew(options: NapiProjectOptions, turboEngineOptions: NapiTurboEngineOptions): Promise<{ __napiType: "Project" }>
|
|
117
|
+
export declare function projectUpdate(project: { __napiType: "Project" }, options: NapiPartialProjectOptions): Promise<void>
|
|
118
|
+
/**
|
|
119
|
+
* Runs exit handlers for the project registered using the [`ExitHandler`] API.
|
|
120
|
+
*
|
|
121
|
+
* This is called by `project_shutdown`, so if you're calling that API, you shouldn't call this
|
|
122
|
+
* one.
|
|
123
|
+
*/
|
|
124
|
+
export declare function projectOnExit(project: { __napiType: "Project" }): Promise<void>
|
|
125
|
+
/**
|
|
126
|
+
* Runs `project_on_exit`, and then waits for turbo_tasks to gracefully shut down.
|
|
127
|
+
*
|
|
128
|
+
* This is used in builds where it's important that we completely persist turbo-tasks to disk, but
|
|
129
|
+
* it's skipped in the development server (`project_on_exit` is used instead with a short timeout),
|
|
130
|
+
* where we prioritize fast exit and user responsiveness over all else.
|
|
131
|
+
*/
|
|
132
|
+
export declare function projectShutdown(project: { __napiType: "Project" }): Promise<void>
|
|
133
|
+
export interface NapiEntrypoints {
|
|
134
|
+
apps?: Array<ExternalObject<ExternalEndpoint>>
|
|
135
|
+
libraries?: Array<ExternalObject<ExternalEndpoint>>
|
|
136
|
+
}
|
|
137
|
+
export declare function projectWriteAllEntrypointsToDisk(project: { __napiType: "Project" }): Promise<TurbopackResult>
|
|
138
|
+
export declare function projectEntrypointsSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
|
139
|
+
export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: string, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
|
140
|
+
export interface HmrIdentifiers {
|
|
141
|
+
identifiers: Array<string>
|
|
142
|
+
}
|
|
143
|
+
export declare function projectHmrIdentifiersSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
|
|
144
|
+
export interface NapiUpdateMessage {
|
|
145
|
+
updateType: string
|
|
146
|
+
value?: NapiUpdateInfo
|
|
147
|
+
}
|
|
148
|
+
export interface NapiUpdateInfo {
|
|
149
|
+
duration: number
|
|
150
|
+
tasks: number
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Subscribes to lifecycle events of the compilation.
|
|
154
|
+
*
|
|
155
|
+
* Emits an [UpdateMessage::Start] event when any computation starts.
|
|
156
|
+
* Emits an [UpdateMessage::End] event when there was no computation for the
|
|
157
|
+
* specified time (`aggregation_ms`). The [UpdateMessage::End] event contains
|
|
158
|
+
* information about the computations that happened since the
|
|
159
|
+
* [UpdateMessage::Start] event. It contains the duration of the computation
|
|
160
|
+
* (excluding the idle time that was spend waiting for `aggregation_ms`), and
|
|
161
|
+
* the number of tasks that were executed.
|
|
162
|
+
*
|
|
163
|
+
* The signature of the `func` is `(update_message: UpdateMessage) => void`.
|
|
164
|
+
*/
|
|
165
|
+
export declare function projectUpdateInfoSubscribe(project: { __napiType: "Project" }, aggregationMs: number, func: (...args: any[]) => any): void
|
|
166
|
+
export interface StackFrame {
|
|
167
|
+
isServer: boolean
|
|
168
|
+
isInternal?: boolean
|
|
169
|
+
originalFile?: string
|
|
170
|
+
file: string
|
|
171
|
+
line?: number
|
|
172
|
+
column?: number
|
|
173
|
+
methodName?: string
|
|
174
|
+
}
|
|
175
|
+
export declare function projectTraceSource(project: { __napiType: "Project" }, frame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>
|
|
176
|
+
export declare function projectGetSourceForAsset(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
|
|
177
|
+
export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
|
|
178
|
+
export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: string): string | null
|
|
179
|
+
export declare function rootTaskDispose(rootTask: { __napiType: "RootTask" }): void
|
|
180
|
+
export interface NapiIssue {
|
|
181
|
+
severity: string
|
|
182
|
+
stage: string
|
|
183
|
+
filePath: string
|
|
184
|
+
title: any
|
|
185
|
+
description?: any
|
|
186
|
+
detail?: any
|
|
187
|
+
source?: NapiIssueSource
|
|
188
|
+
documentationLink: string
|
|
189
|
+
subIssues: Array<NapiIssue>
|
|
190
|
+
}
|
|
191
|
+
export interface NapiIssueSource {
|
|
192
|
+
source: NapiSource
|
|
193
|
+
range?: NapiIssueSourceRange
|
|
194
|
+
}
|
|
195
|
+
export interface NapiIssueSourceRange {
|
|
196
|
+
start: NapiSourcePos
|
|
197
|
+
end: NapiSourcePos
|
|
198
|
+
}
|
|
199
|
+
export interface NapiSource {
|
|
200
|
+
ident: string
|
|
201
|
+
content?: string
|
|
202
|
+
}
|
|
203
|
+
export interface NapiSourcePos {
|
|
204
|
+
line: number
|
|
205
|
+
column: number
|
|
206
|
+
}
|
|
207
|
+
export interface NapiDiagnostic {
|
|
208
|
+
category: string
|
|
209
|
+
name: string
|
|
210
|
+
payload: Record<string, string>
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Initialize tracing subscriber to emit traces. This configures subscribers
|
|
214
|
+
* for Trace Event Format <https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview>.
|
|
215
|
+
*/
|
|
216
|
+
export declare function initCustomTraceSubscriber(traceOutFilePath?: string | undefined | null): ExternalObject<RefCell>
|
|
217
|
+
/**
|
|
218
|
+
* Teardown currently running tracing subscriber to flush out remaining traces.
|
|
219
|
+
* This should be called when parent node.js process exits, otherwise generated
|
|
220
|
+
* trace may drop traces in the buffer.
|
|
221
|
+
*/
|
|
222
|
+
export declare function teardownTraceSubscriber(guardExternal: ExternalObject<RefCell>): void
|