@utoo/pack 0.0.1-alpha.1 → 0.0.1-alpha.12
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/binding.d.ts +153 -100
- package/cjs/build.d.ts +2 -0
- package/cjs/build.js +53 -0
- package/cjs/dev.d.ts +42 -0
- package/cjs/dev.js +355 -0
- package/cjs/hmr.d.ts +80 -0
- package/cjs/hmr.js +285 -0
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +5 -73
- package/cjs/mkcert.d.ts +7 -0
- package/cjs/mkcert.js +183 -0
- package/cjs/project.d.ts +3 -3
- package/cjs/project.js +4 -11
- package/cjs/types.d.ts +16 -2
- package/cjs/util.d.ts +12 -1
- package/cjs/util.js +102 -1
- package/config_schema.json +710 -0
- package/esm/binding.d.ts +153 -100
- package/esm/build.d.ts +2 -0
- package/esm/build.js +50 -0
- package/esm/dev.d.ts +42 -0
- package/esm/dev.js +339 -0
- package/esm/hmr.d.ts +80 -0
- package/esm/hmr.js +278 -0
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -69
- package/esm/mkcert.d.ts +7 -0
- package/esm/mkcert.js +176 -0
- package/esm/project.d.ts +3 -3
- package/esm/project.js +2 -9
- package/esm/types.d.ts +16 -2
- package/esm/util.d.ts +12 -1
- package/esm/util.js +98 -1
- package/package.json +38 -23
- package/bin/cli.js +0 -9
- package/global.d.ts +0 -10
package/esm/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { build } from "./build";
|
|
2
|
+
export { serve } from "./dev";
|
package/esm/index.js
CHANGED
|
@@ -1,69 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
}
|
|
1
|
+
export { build } from "./build";
|
|
2
|
+
export { serve } from "./dev";
|
package/esm/mkcert.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
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
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { HmrIdentifiers, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "./binding";
|
|
1
2
|
import * as binding from "./binding";
|
|
2
|
-
import type { NapiWrittenEndpoint, StackFrame } from "./binding";
|
|
3
3
|
import { ProjectOptions, RawEntrypoints, Update } from "./types";
|
|
4
4
|
export declare class TurbopackInternalError extends Error {
|
|
5
5
|
name: string;
|
|
@@ -32,12 +32,12 @@ export declare function projectFactory(): (options: ProjectOptions, turboEngineO
|
|
|
32
32
|
diagnostics: binding.NapiDiagnostic[];
|
|
33
33
|
}, void, unknown>;
|
|
34
34
|
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
|
|
35
|
-
hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<
|
|
35
|
+
hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
|
|
36
36
|
traceSource(stackFrame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>;
|
|
37
37
|
getSourceForAsset(filePath: string): Promise<string | null>;
|
|
38
38
|
getSourceMap(filePath: string): Promise<string | null>;
|
|
39
39
|
getSourceMapSync(filePath: string): string | null;
|
|
40
|
-
updateInfoSubscribe(aggregationMs: number): AsyncIterableIterator<TurbopackResult<
|
|
40
|
+
updateInfoSubscribe(aggregationMs: number): AsyncIterableIterator<TurbopackResult<NapiUpdateMessage>>;
|
|
41
41
|
shutdown(): Promise<void>;
|
|
42
42
|
onExit(): Promise<void>;
|
|
43
43
|
}>;
|
package/esm/project.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { nanoid } from "nanoid";
|
|
1
2
|
import { isDeepStrictEqual } from "util";
|
|
2
3
|
import * as binding from "./binding";
|
|
3
|
-
import {
|
|
4
|
+
import { rustifyEnv } from "./util";
|
|
4
5
|
export class TurbopackInternalError extends Error {
|
|
5
6
|
constructor(cause) {
|
|
6
7
|
super(cause.message);
|
|
@@ -76,14 +77,6 @@ async function serializeConfig(config) {
|
|
|
76
77
|
}
|
|
77
78
|
return JSON.stringify(configSerializable, null, 2);
|
|
78
79
|
}
|
|
79
|
-
function rustifyEnv(env) {
|
|
80
|
-
return Object.entries(env)
|
|
81
|
-
.filter(([_, value]) => value != null)
|
|
82
|
-
.map(([name, value]) => ({
|
|
83
|
-
name,
|
|
84
|
-
value,
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
80
|
async function rustifyPartialProjectOptions(options) {
|
|
88
81
|
return {
|
|
89
82
|
...options,
|
package/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import { HmrIdentifiers, NapiIssue, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "./binding";
|
|
1
|
+
import { HmrIdentifiers, NapiDiagnostic, NapiIssue, NapiUpdateMessage, NapiWrittenEndpoint, StackFrame } from "./binding";
|
|
2
|
+
declare global {
|
|
3
|
+
export type TurbopackResult<T = {}> = T & {
|
|
4
|
+
issues: NapiIssue[];
|
|
5
|
+
diagnostics: NapiDiagnostic[];
|
|
6
|
+
};
|
|
7
|
+
export type RefCell = {
|
|
8
|
+
readonly __tag: unique symbol;
|
|
9
|
+
};
|
|
10
|
+
export type ExternalEndpoint = {
|
|
11
|
+
readonly __tag: unique symbol;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
2
14
|
export interface BaseUpdate {
|
|
3
15
|
resource: {
|
|
4
16
|
headers: unknown;
|
|
@@ -93,6 +105,7 @@ export interface ConfigComplete {
|
|
|
93
105
|
type?: "standalone" | "export";
|
|
94
106
|
filename?: string;
|
|
95
107
|
chunkFilename?: string;
|
|
108
|
+
clean?: boolean;
|
|
96
109
|
};
|
|
97
110
|
target?: string;
|
|
98
111
|
sourceMaps?: boolean;
|
|
@@ -202,7 +215,7 @@ export interface ProjectOptions {
|
|
|
202
215
|
pollIntervalMs?: number;
|
|
203
216
|
};
|
|
204
217
|
/**
|
|
205
|
-
* The mode
|
|
218
|
+
* The mode of utoo-pack.
|
|
206
219
|
*/
|
|
207
220
|
dev: boolean;
|
|
208
221
|
/**
|
|
@@ -210,6 +223,7 @@ export interface ProjectOptions {
|
|
|
210
223
|
*/
|
|
211
224
|
buildId: string;
|
|
212
225
|
}
|
|
226
|
+
export type BundleOptions = Omit<ProjectOptions, "rootPath" | "projectPath">;
|
|
213
227
|
export interface Project {
|
|
214
228
|
update(options: Partial<ProjectOptions>): Promise<void>;
|
|
215
229
|
entrypointsSubscribe(): AsyncIterableIterator<TurbopackResult<RawEntrypoints>>;
|
package/esm/util.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NapiIssue } from "./binding";
|
|
2
|
-
import { StyledString } from "./types";
|
|
2
|
+
import { ConfigComplete, DefineEnv, RustifiedEnv, StyledString } from "./types";
|
|
3
3
|
export declare class ModuleBuildError extends Error {
|
|
4
4
|
name: string;
|
|
5
5
|
}
|
|
@@ -8,3 +8,14 @@ export declare function isWellKnownError(issue: NapiIssue): boolean;
|
|
|
8
8
|
export declare function formatIssue(issue: NapiIssue): string;
|
|
9
9
|
export declare function renderStyledStringToErrorAnsi(string: StyledString): string;
|
|
10
10
|
export declare function isRelevantWarning(issue: NapiIssue): boolean;
|
|
11
|
+
export declare function rustifyEnv(env: Record<string, string>): RustifiedEnv;
|
|
12
|
+
interface DefineEnvOptions {
|
|
13
|
+
config: ConfigComplete;
|
|
14
|
+
dev: boolean;
|
|
15
|
+
optionDefineEnv?: DefineEnv;
|
|
16
|
+
}
|
|
17
|
+
export declare function createDefineEnv(options: DefineEnvOptions): DefineEnv;
|
|
18
|
+
type AnyFunc<T> = (this: T, ...args: any) => any;
|
|
19
|
+
export declare function debounce<T, F extends AnyFunc<T>>(fn: F, ms: number, maxWait?: number): (this: T, ...passedArgs: Parameters<F>) => void;
|
|
20
|
+
export declare function blockStdout(): void;
|
|
21
|
+
export {};
|
package/esm/util.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { bold, green, magenta, red } from "picocolors";
|
|
2
1
|
import { codeFrameColumns } from "@babel/code-frame";
|
|
2
|
+
import { bold, green, magenta, red } from "picocolors";
|
|
3
3
|
import { decodeMagicIdentifier, MAGIC_IDENTIFIER_REGEX, } from "./magicIdentifier";
|
|
4
4
|
export class ModuleBuildError extends Error {
|
|
5
5
|
constructor() {
|
|
@@ -128,3 +128,100 @@ function isNodeModulesIssue(issue) {
|
|
|
128
128
|
(issue.filePath.match(/^(?:.*[\\/])?node_modules(?:[\\/].*)?$/) !== null ||
|
|
129
129
|
issue.filePath.includes("@utoo/pack")));
|
|
130
130
|
}
|
|
131
|
+
export function rustifyEnv(env) {
|
|
132
|
+
return Object.entries(env)
|
|
133
|
+
.filter(([_, value]) => value != null)
|
|
134
|
+
.map(([name, value]) => ({
|
|
135
|
+
name,
|
|
136
|
+
value,
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
export function createDefineEnv(options) {
|
|
140
|
+
var _a;
|
|
141
|
+
let defineEnv = (_a = options.optionDefineEnv) !== null && _a !== void 0 ? _a : {
|
|
142
|
+
client: [],
|
|
143
|
+
edge: [],
|
|
144
|
+
nodejs: [],
|
|
145
|
+
};
|
|
146
|
+
function getDefineEnv() {
|
|
147
|
+
var _a;
|
|
148
|
+
const envs = {
|
|
149
|
+
"process.env.NODE_ENV": options.dev ? "development" : "production",
|
|
150
|
+
};
|
|
151
|
+
const userDefines = (_a = options.config.define) !== null && _a !== void 0 ? _a : {};
|
|
152
|
+
for (const key in userDefines) {
|
|
153
|
+
envs[key] = userDefines[key];
|
|
154
|
+
}
|
|
155
|
+
// serialize
|
|
156
|
+
const defineEnvStringified = {};
|
|
157
|
+
for (const key in defineEnv) {
|
|
158
|
+
const value = envs[key];
|
|
159
|
+
defineEnvStringified[key] = JSON.stringify(value);
|
|
160
|
+
}
|
|
161
|
+
return defineEnvStringified;
|
|
162
|
+
}
|
|
163
|
+
// TODO: future define envs need to extends for more compiler like server or edge.
|
|
164
|
+
for (const variant of Object.keys(defineEnv)) {
|
|
165
|
+
defineEnv[variant] = rustifyEnv(getDefineEnv());
|
|
166
|
+
}
|
|
167
|
+
return defineEnv;
|
|
168
|
+
}
|
|
169
|
+
export function debounce(fn, ms, maxWait = Infinity) {
|
|
170
|
+
let timeoutId;
|
|
171
|
+
// The time the debouncing function was first called during this debounce queue.
|
|
172
|
+
let startTime = 0;
|
|
173
|
+
// The time the debouncing function was last called.
|
|
174
|
+
let lastCall = 0;
|
|
175
|
+
// The arguments and this context of the last call to the debouncing function.
|
|
176
|
+
let args, context;
|
|
177
|
+
// A helper used to that either invokes the debounced function, or
|
|
178
|
+
// reschedules the timer if a more recent call was made.
|
|
179
|
+
function run() {
|
|
180
|
+
const now = Date.now();
|
|
181
|
+
const diff = lastCall + ms - now;
|
|
182
|
+
// If the diff is non-positive, then we've waited at least `ms`
|
|
183
|
+
// milliseconds since the last call. Or if we've waited for longer than the
|
|
184
|
+
// max wait time, we must call the debounced function.
|
|
185
|
+
if (diff <= 0 || startTime + maxWait >= now) {
|
|
186
|
+
// It's important to clear the timeout id before invoking the debounced
|
|
187
|
+
// function, in case the function calls the debouncing function again.
|
|
188
|
+
timeoutId = undefined;
|
|
189
|
+
fn.apply(context, args);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
// Else, a new call was made after the original timer was scheduled. We
|
|
193
|
+
// didn't clear the timeout (doing so is very slow), so now we need to
|
|
194
|
+
// reschedule the timer for the time difference.
|
|
195
|
+
timeoutId = setTimeout(run, diff);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return function (...passedArgs) {
|
|
199
|
+
// The arguments and this context of the most recent call are saved so the
|
|
200
|
+
// debounced function can be invoked with them later.
|
|
201
|
+
args = passedArgs;
|
|
202
|
+
context = this;
|
|
203
|
+
// Instead of constantly clearing and scheduling a timer, we record the
|
|
204
|
+
// time of the last call. If a second call comes in before the timer fires,
|
|
205
|
+
// then we'll reschedule in the run function. Doing this is considerably
|
|
206
|
+
// faster.
|
|
207
|
+
lastCall = Date.now();
|
|
208
|
+
// Only schedule a new timer if we're not currently waiting.
|
|
209
|
+
if (timeoutId === undefined) {
|
|
210
|
+
startTime = lastCall;
|
|
211
|
+
timeoutId = setTimeout(run, ms);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
// ref:
|
|
216
|
+
// https://github.com/vercel/next.js/pull/51883
|
|
217
|
+
export function blockStdout() {
|
|
218
|
+
// 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
|
|
219
|
+
// see https://github.com/napi-rs/napi-rs/issues/1630
|
|
220
|
+
// and https://github.com/nodejs/node/blob/main/doc/api/process.md#a-note-on-process-io
|
|
221
|
+
if (process.stdout._handle != null) {
|
|
222
|
+
process.stdout._handle.setBlocking(true);
|
|
223
|
+
}
|
|
224
|
+
if (process.stderr._handle != null) {
|
|
225
|
+
process.stderr._handle.setBlocking(true);
|
|
226
|
+
}
|
|
227
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/pack",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.12",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./esm/index.js",
|
|
9
|
+
"require": "./cjs/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./cjs/*": "./cjs/*",
|
|
12
|
+
"./esm/*": "./esm/*",
|
|
13
|
+
"./config_schema.json": "./config_schema.json",
|
|
14
|
+
"./package.json": "./package.json"
|
|
8
15
|
},
|
|
9
16
|
"files": [
|
|
10
17
|
"./cjs/*.js",
|
|
11
18
|
"./cjs/*.d.ts",
|
|
12
19
|
"./esm/*.js",
|
|
13
20
|
"./esm/*.d.ts",
|
|
14
|
-
"./
|
|
15
|
-
"./global.d.ts"
|
|
21
|
+
"./config_schema.json"
|
|
16
22
|
],
|
|
17
23
|
"napi": {
|
|
18
24
|
"name": "pack",
|
|
@@ -31,23 +37,32 @@
|
|
|
31
37
|
},
|
|
32
38
|
"license": "MIT",
|
|
33
39
|
"dependencies": {
|
|
34
|
-
"
|
|
35
|
-
"picocolors": "^1.1.1",
|
|
40
|
+
"react-refresh": "^0.12.0",
|
|
36
41
|
"@babel/code-frame": "7.22.5",
|
|
37
42
|
"@utoo/loader-runner": "^1.0.0",
|
|
38
43
|
"@utoo/style-loader": "^1.0.0",
|
|
44
|
+
"less": "^4.0.0",
|
|
45
|
+
"less-loader": "^12.0.0",
|
|
46
|
+
"nanoid": "^3.3.11",
|
|
47
|
+
"picocolors": "^1.1.1",
|
|
39
48
|
"postcss": "8.4.31",
|
|
49
|
+
"resolve-url-loader": "^5.0.0",
|
|
40
50
|
"sass": "1.54.0",
|
|
41
|
-
"less": "^4.0.0",
|
|
42
51
|
"sass-loader": "^13.2.0",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
52
|
+
"ws": "^8.18.1",
|
|
53
|
+
"send": "0.17.1"
|
|
45
54
|
},
|
|
46
55
|
"devDependencies": {
|
|
47
56
|
"@napi-rs/cli": "^2.18.0",
|
|
48
|
-
"@
|
|
57
|
+
"@swc/helpers": "^0.5.15",
|
|
49
58
|
"@types/babel__code-frame": "7.0.2",
|
|
50
|
-
"
|
|
59
|
+
"@types/node": "^20.3.0",
|
|
60
|
+
"styled-jsx": "^5.1.6",
|
|
61
|
+
"typescript": "^5.8.3",
|
|
62
|
+
"@types/ws": "^8.18.1",
|
|
63
|
+
"@types/webpack": "^5.28.5",
|
|
64
|
+
"@types/send": "0.14.4",
|
|
65
|
+
"@types/mime-types": "3.0.1"
|
|
51
66
|
},
|
|
52
67
|
"engines": {
|
|
53
68
|
"node": ">= 10"
|
|
@@ -55,21 +70,21 @@
|
|
|
55
70
|
"scripts": {
|
|
56
71
|
"build:cjs": "rm -rf cjs && tsc -p ./tsconfig.json --module commonjs --outDir cjs && cp src/*.d.ts cjs/",
|
|
57
72
|
"build:esm": "rm -rf esm && tsc -p ./tsconfig.json --module esnext --outDir esm && cp src/*.d.ts esm/",
|
|
58
|
-
"build:local": "npm run build:binding && npm run build:cjs && cp src/*.node cjs/",
|
|
73
|
+
"build:local": "npm run build:binding:local && npm run build:cjs && npm run build:esm && cp src/*.node cjs/ && cp src/*.node esm/",
|
|
59
74
|
"artifacts": "napi artifacts --dir ./src --dist npm",
|
|
60
|
-
"build:binding": "napi build src --platform --release -p pack-napi --cargo-cwd ../../ --cargo-name pack_napi --features plugin --js binding.js --dts binding.d.ts
|
|
61
|
-
"build:binding:
|
|
62
|
-
"prepublishOnly": "npm run build:esm && npm run build:cjs && napi prepublish -t npm",
|
|
75
|
+
"build:binding": "napi build src --platform --release -p pack-napi --cargo-cwd ../../ --cargo-name pack_napi --features plugin --js binding.js --dts binding.d.ts",
|
|
76
|
+
"build:binding:local": "napi build src --platform --profile release-local -p pack-napi --cargo-cwd ../../ --cargo-name pack_napi --features plugin --js binding.js --dts binding.d.ts",
|
|
77
|
+
"prepublishOnly": "npm run build:esm && npm run build:cjs && napi prepublish -t npm --skip-gh-release",
|
|
63
78
|
"version": "napi version"
|
|
64
79
|
},
|
|
65
80
|
"repository": "git@github.com:umijs/mako.git",
|
|
66
81
|
"optionalDependencies": {
|
|
67
|
-
"@utoo/pack-darwin-arm64": "0.0.1-alpha.
|
|
68
|
-
"@utoo/pack-darwin-x64": "0.0.1-alpha.
|
|
69
|
-
"@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.
|
|
70
|
-
"@utoo/pack-linux-arm64-musl": "0.0.1-alpha.
|
|
71
|
-
"@utoo/pack-linux-x64-gnu": "0.0.1-alpha.
|
|
72
|
-
"@utoo/pack-linux-x64-musl": "0.0.1-alpha.
|
|
73
|
-
"@utoo/pack-win32-x64-msvc": "0.0.1-alpha.
|
|
82
|
+
"@utoo/pack-darwin-arm64": "0.0.1-alpha.12",
|
|
83
|
+
"@utoo/pack-darwin-x64": "0.0.1-alpha.12",
|
|
84
|
+
"@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.12",
|
|
85
|
+
"@utoo/pack-linux-arm64-musl": "0.0.1-alpha.12",
|
|
86
|
+
"@utoo/pack-linux-x64-gnu": "0.0.1-alpha.12",
|
|
87
|
+
"@utoo/pack-linux-x64-musl": "0.0.1-alpha.12",
|
|
88
|
+
"@utoo/pack-win32-x64-msvc": "0.0.1-alpha.12"
|
|
74
89
|
}
|
|
75
90
|
}
|
package/bin/cli.js
DELETED
package/global.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { NapiDiagnostic, NapiIssue } from "./src/binding";
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
export type TurbopackResult<T = {}> = T & {
|
|
5
|
-
issues: NapiIssue[];
|
|
6
|
-
diagnostics: NapiDiagnostic[];
|
|
7
|
-
};
|
|
8
|
-
export type RefCell = { readonly __tag: unique symbol };
|
|
9
|
-
export type ExternalEndpoint = { readonly __tag: unique symbol };
|
|
10
|
-
}
|