@utoo/pack 0.0.1-alpha.2 → 0.0.1-alpha.21
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 +11 -9
- package/cjs/build.d.ts +4 -2
- package/cjs/build.js +18 -11
- package/cjs/dev.d.ts +44 -0
- package/cjs/dev.js +362 -0
- package/cjs/{hotReloader.d.ts → hmr.d.ts} +4 -11
- package/cjs/{hotReloader.js → hmr.js} +14 -61
- package/cjs/index.d.ts +13 -14
- package/cjs/index.js +6 -4
- package/cjs/mkcert.d.ts +7 -0
- package/cjs/mkcert.js +183 -0
- package/cjs/project.d.ts +4 -4
- package/cjs/project.js +0 -2
- package/cjs/types.d.ts +22 -9
- package/cjs/util.d.ts +1 -1
- package/cjs/util.js +1 -1
- package/cjs/webpackCompat.d.ts +6 -0
- package/cjs/webpackCompat.js +341 -0
- package/config_schema.json +30 -2
- package/esm/binding.d.ts +11 -9
- package/esm/build.d.ts +4 -2
- package/esm/build.js +18 -11
- package/esm/dev.d.ts +44 -0
- package/esm/dev.js +346 -0
- package/esm/{hotReloader.d.ts → hmr.d.ts} +4 -11
- package/esm/{hotReloader.js → hmr.js} +14 -60
- package/esm/index.d.ts +13 -14
- package/esm/index.js +6 -2
- package/esm/mkcert.d.ts +7 -0
- package/esm/mkcert.js +176 -0
- package/esm/project.d.ts +4 -4
- package/esm/project.js +0 -2
- package/esm/types.d.ts +22 -9
- package/esm/util.d.ts +1 -1
- package/esm/util.js +1 -1
- package/esm/webpackCompat.d.ts +6 -0
- package/esm/webpackCompat.js +338 -0
- package/package.json +17 -11
- package/cjs/sourceMap.d.ts +0 -21
- package/cjs/sourceMap.js +0 -2
- package/cjs/watch.d.ts +0 -2
- package/cjs/watch.js +0 -14
- package/esm/sourceMap.d.ts +0 -21
- package/esm/sourceMap.js +0 -1
- package/esm/watch.d.ts +0 -2
- package/esm/watch.js +0 -11
|
@@ -4,76 +4,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.FAST_REFRESH_RUNTIME_RELOAD = void 0;
|
|
7
|
-
exports.setBundlerFindSourceMapImplementation = setBundlerFindSourceMapImplementation;
|
|
8
7
|
exports.createHotReloader = createHotReloader;
|
|
8
|
+
const nanoid_1 = require("nanoid");
|
|
9
9
|
const ws_1 = __importDefault(require("ws"));
|
|
10
|
-
const path_1 = require("path");
|
|
11
|
-
const url_1 = require("url");
|
|
12
10
|
const project_1 = require("./project");
|
|
13
11
|
const util_1 = require("./util");
|
|
14
|
-
const nanoid_1 = require("nanoid");
|
|
15
12
|
const wsServer = new ws_1.default.Server({ noServer: true });
|
|
16
13
|
const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random());
|
|
17
|
-
/**
|
|
18
|
-
* Replaces turbopack:///[project] with the specified project in the `source` field.
|
|
19
|
-
*/
|
|
20
|
-
function rewriteTurbopackSources(projectRoot, sourceMap) {
|
|
21
|
-
if ("sections" in sourceMap) {
|
|
22
|
-
for (const section of sourceMap.sections) {
|
|
23
|
-
rewriteTurbopackSources(projectRoot, section.map);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
for (let i = 0; i < sourceMap.sources.length; i++) {
|
|
28
|
-
sourceMap.sources[i] = (0, url_1.pathToFileURL)((0, path_1.join)(projectRoot, sourceMap.sources[i].replace(/turbopack:\/\/\/\[project\]/, ""))).toString();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function getSourceMapFromTurbopack(project, projectRoot, sourceURL) {
|
|
33
|
-
let sourceMapJson = null;
|
|
34
|
-
try {
|
|
35
|
-
sourceMapJson = project.getSourceMapSync(sourceURL);
|
|
36
|
-
}
|
|
37
|
-
catch (err) { }
|
|
38
|
-
if (sourceMapJson === null) {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const payload = JSON.parse(sourceMapJson);
|
|
43
|
-
// The sourcemap from Turbopack is not yet written to disk so its `sources`
|
|
44
|
-
// are not absolute paths yet. We need to rewrite them to be absolute paths.
|
|
45
|
-
rewriteTurbopackSources(projectRoot, payload);
|
|
46
|
-
return payload;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
// Find a source map using the bundler's API.
|
|
50
|
-
// This is only a fallback for when Node.js fails to due to bugs e.g. https://github.com/nodejs/node/issues/52102
|
|
51
|
-
// TODO: Remove once all supported Node.js versions are fixed.
|
|
52
|
-
// TODO(veil): Set from Webpack as well
|
|
53
|
-
let bundlerFindSourceMapPayload = () => undefined;
|
|
54
|
-
function setBundlerFindSourceMapImplementation(findSourceMapImplementation) {
|
|
55
|
-
bundlerFindSourceMapPayload = findSourceMapImplementation;
|
|
56
|
-
}
|
|
57
14
|
exports.FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
|
|
58
|
-
async function createHotReloader(
|
|
59
|
-
var _a
|
|
15
|
+
async function createHotReloader(bundleOptions, projectPath, rootPath) {
|
|
16
|
+
var _a;
|
|
60
17
|
const createProject = (0, project_1.projectFactory)();
|
|
61
18
|
const project = await createProject({
|
|
62
|
-
processEnv: (_a =
|
|
63
|
-
|
|
64
|
-
config:
|
|
19
|
+
processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
|
|
20
|
+
defineEnv: (0, util_1.createDefineEnv)({
|
|
21
|
+
config: bundleOptions.config,
|
|
65
22
|
dev: true,
|
|
66
|
-
optionDefineEnv:
|
|
23
|
+
optionDefineEnv: bundleOptions.defineEnv,
|
|
67
24
|
}),
|
|
68
|
-
watch:
|
|
69
|
-
enable:
|
|
25
|
+
watch: {
|
|
26
|
+
enable: true,
|
|
70
27
|
},
|
|
71
28
|
dev: true,
|
|
72
|
-
buildId: (0, nanoid_1.nanoid)(),
|
|
29
|
+
buildId: bundleOptions.buildId || (0, nanoid_1.nanoid)(),
|
|
73
30
|
config: {
|
|
74
|
-
...
|
|
31
|
+
...bundleOptions.config,
|
|
32
|
+
mode: "development",
|
|
75
33
|
optimization: {
|
|
76
|
-
...
|
|
34
|
+
...bundleOptions.config.optimization,
|
|
77
35
|
minify: false,
|
|
78
36
|
moduleIds: "named",
|
|
79
37
|
},
|
|
@@ -83,7 +41,6 @@ async function createHotReloader(projectOptions, projectPath, rootPath) {
|
|
|
83
41
|
}, {
|
|
84
42
|
persistentCaching: true,
|
|
85
43
|
});
|
|
86
|
-
setBundlerFindSourceMapImplementation(getSourceMapFromTurbopack.bind(null, project, projectOptions.projectPath));
|
|
87
44
|
const entrypointsSubscription = project.entrypointsSubscribe();
|
|
88
45
|
let currentEntriesHandlingResolve;
|
|
89
46
|
let currentEntriesHandling = new Promise((resolve) => (currentEntriesHandlingResolve = resolve));
|
|
@@ -116,9 +73,6 @@ async function createHotReloader(projectOptions, projectPath, rootPath) {
|
|
|
116
73
|
const sendEnqueuedMessagesDebounce = (0, util_1.debounce)(sendEnqueuedMessages, 2);
|
|
117
74
|
function sendTurbopackMessage(payload) {
|
|
118
75
|
var _a;
|
|
119
|
-
// TODO(PACK-2049): For some reason we end up emitting hundreds of issues messages on bigger apps,
|
|
120
|
-
// a lot of which are duplicates.
|
|
121
|
-
// They are currently not handled on the client at all, so might as well not send them for now.
|
|
122
76
|
payload.diagnostics = [];
|
|
123
77
|
payload.issues = [];
|
|
124
78
|
for (const client of clients) {
|
|
@@ -182,10 +136,9 @@ async function createHotReloader(projectOptions, projectPath, rootPath) {
|
|
|
182
136
|
const hotReloader = {
|
|
183
137
|
turbopackProject: project,
|
|
184
138
|
serverStats: null,
|
|
185
|
-
// TODO: Figure out if socket type can match the HotReloaderInterface
|
|
186
139
|
onHMR(req, socket, head, onUpgrade) {
|
|
187
140
|
wsServer.handleUpgrade(req, socket, head, (client) => {
|
|
188
|
-
onUpgrade(client);
|
|
141
|
+
onUpgrade === null || onUpgrade === void 0 ? void 0 : onUpgrade(client);
|
|
189
142
|
const subscriptions = new Map();
|
|
190
143
|
clients.add(client);
|
|
191
144
|
clientStates.set(client, {
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
1
|
+
import { build } from "./build";
|
|
2
|
+
import { serve } from "./dev";
|
|
3
|
+
import * as webpackCompat from "./webpackCompat";
|
|
4
|
+
export { build };
|
|
5
|
+
export { serve };
|
|
6
|
+
declare const utoopack: {
|
|
7
|
+
build: typeof build;
|
|
8
|
+
serve: typeof serve;
|
|
9
|
+
};
|
|
10
|
+
export default utoopack;
|
|
11
|
+
export type WebpackConfig = webpackCompat.WebpackConfig;
|
|
12
|
+
declare namespace utoopack {
|
|
13
|
+
type WebpackConfig = webpackCompat.WebpackConfig;
|
|
15
14
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.serve = exports.build = void 0;
|
|
4
|
+
const build_1 = require("./build");
|
|
5
5
|
Object.defineProperty(exports, "build", { enumerable: true, get: function () { return build_1.build; } });
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "
|
|
6
|
+
const dev_1 = require("./dev");
|
|
7
|
+
Object.defineProperty(exports, "serve", { enumerable: true, get: function () { return dev_1.serve; } });
|
|
8
|
+
const utoopack = { build: build_1.build, serve: dev_1.serve };
|
|
9
|
+
exports.default = utoopack;
|
package/cjs/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/cjs/mkcert.js
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createSelfSignedCertificate = createSelfSignedCertificate;
|
|
7
|
+
exports.getCacheDirectory = getCacheDirectory;
|
|
8
|
+
const node_child_process_1 = require("node:child_process");
|
|
9
|
+
const node_crypto_1 = require("node:crypto");
|
|
10
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
+
const os_1 = __importDefault(require("os"));
|
|
13
|
+
const { WritableStream } = require("node:stream/web");
|
|
14
|
+
const MKCERT_VERSION = "v1.4.4";
|
|
15
|
+
function getBinaryName() {
|
|
16
|
+
const platform = process.platform;
|
|
17
|
+
const arch = process.arch === "x64" ? "amd64" : process.arch;
|
|
18
|
+
if (platform === "win32") {
|
|
19
|
+
return `mkcert-${MKCERT_VERSION}-windows-${arch}.exe`;
|
|
20
|
+
}
|
|
21
|
+
if (platform === "darwin") {
|
|
22
|
+
return `mkcert-${MKCERT_VERSION}-darwin-${arch}`;
|
|
23
|
+
}
|
|
24
|
+
if (platform === "linux") {
|
|
25
|
+
return `mkcert-${MKCERT_VERSION}-linux-${arch}`;
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Unsupported platform: ${platform}`);
|
|
28
|
+
}
|
|
29
|
+
async function downloadBinary() {
|
|
30
|
+
try {
|
|
31
|
+
const binaryName = getBinaryName();
|
|
32
|
+
const cacheDirectory = getCacheDirectory("mkcert");
|
|
33
|
+
const binaryPath = node_path_1.default.join(cacheDirectory, binaryName);
|
|
34
|
+
if (node_fs_1.default.existsSync(binaryPath)) {
|
|
35
|
+
return binaryPath;
|
|
36
|
+
}
|
|
37
|
+
const downloadUrl = `https://github.com/FiloSottile/mkcert/releases/download/${MKCERT_VERSION}/${binaryName}`;
|
|
38
|
+
await node_fs_1.default.promises.mkdir(cacheDirectory, { recursive: true });
|
|
39
|
+
console.log(`Downloading mkcert package...`);
|
|
40
|
+
const response = await fetch(downloadUrl);
|
|
41
|
+
if (!response.ok || !response.body) {
|
|
42
|
+
throw new Error(`request failed with status ${response.status}`);
|
|
43
|
+
}
|
|
44
|
+
console.log(`Download response was successful, writing to disk`);
|
|
45
|
+
const binaryWriteStream = node_fs_1.default.createWriteStream(binaryPath);
|
|
46
|
+
await response.body.pipeTo(new WritableStream({
|
|
47
|
+
write(chunk) {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
binaryWriteStream.write(chunk, (error) => {
|
|
50
|
+
if (error) {
|
|
51
|
+
reject(error);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
resolve();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
close() {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
binaryWriteStream.close((error) => {
|
|
61
|
+
if (error) {
|
|
62
|
+
reject(error);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
resolve();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
}));
|
|
70
|
+
await node_fs_1.default.promises.chmod(binaryPath, 0o755);
|
|
71
|
+
return binaryPath;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
console.error("Error downloading mkcert:", err);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function createSelfSignedCertificate(host, certDir = "certificates") {
|
|
78
|
+
try {
|
|
79
|
+
const binaryPath = await downloadBinary();
|
|
80
|
+
if (!binaryPath)
|
|
81
|
+
throw new Error("missing mkcert binary");
|
|
82
|
+
const resolvedCertDir = node_path_1.default.resolve(process.cwd(), `./${certDir}`);
|
|
83
|
+
await node_fs_1.default.promises.mkdir(resolvedCertDir, {
|
|
84
|
+
recursive: true,
|
|
85
|
+
});
|
|
86
|
+
const keyPath = node_path_1.default.resolve(resolvedCertDir, "localhost-key.pem");
|
|
87
|
+
const certPath = node_path_1.default.resolve(resolvedCertDir, "localhost.pem");
|
|
88
|
+
if (node_fs_1.default.existsSync(keyPath) && node_fs_1.default.existsSync(certPath)) {
|
|
89
|
+
const cert = new node_crypto_1.X509Certificate(node_fs_1.default.readFileSync(certPath));
|
|
90
|
+
const key = node_fs_1.default.readFileSync(keyPath);
|
|
91
|
+
if (cert.checkHost(host !== null && host !== void 0 ? host : "localhost") &&
|
|
92
|
+
cert.checkPrivateKey((0, node_crypto_1.createPrivateKey)(key))) {
|
|
93
|
+
console.log("Using already generated self signed certificate");
|
|
94
|
+
const caLocation = (0, node_child_process_1.execSync)(`"${binaryPath}" -CAROOT`)
|
|
95
|
+
.toString()
|
|
96
|
+
.trim();
|
|
97
|
+
return {
|
|
98
|
+
key: keyPath,
|
|
99
|
+
cert: certPath,
|
|
100
|
+
rootCA: `${caLocation}/rootCA.pem`,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
console.log("Attempting to generate self signed certificate. This may prompt for your password");
|
|
105
|
+
const defaultHosts = ["localhost", "127.0.0.1", "::1"];
|
|
106
|
+
const hosts = host && !defaultHosts.includes(host)
|
|
107
|
+
? [...defaultHosts, host]
|
|
108
|
+
: defaultHosts;
|
|
109
|
+
(0, node_child_process_1.execSync)(`"${binaryPath}" -install -key-file "${keyPath}" -cert-file "${certPath}" ${hosts.join(" ")}`, { stdio: "ignore" });
|
|
110
|
+
const caLocation = (0, node_child_process_1.execSync)(`"${binaryPath}" -CAROOT`).toString().trim();
|
|
111
|
+
if (!node_fs_1.default.existsSync(keyPath) || !node_fs_1.default.existsSync(certPath)) {
|
|
112
|
+
throw new Error("Certificate files not found");
|
|
113
|
+
}
|
|
114
|
+
console.log(`CA Root certificate created in ${caLocation}`);
|
|
115
|
+
console.log(`Certificates created in ${resolvedCertDir}`);
|
|
116
|
+
const gitignorePath = node_path_1.default.resolve(process.cwd(), "./.gitignore");
|
|
117
|
+
if (node_fs_1.default.existsSync(gitignorePath)) {
|
|
118
|
+
const gitignore = await node_fs_1.default.promises.readFile(gitignorePath, "utf8");
|
|
119
|
+
if (!gitignore.includes(certDir)) {
|
|
120
|
+
console.log("Adding certificates to .gitignore");
|
|
121
|
+
await node_fs_1.default.promises.appendFile(gitignorePath, `\n${certDir}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
key: keyPath,
|
|
126
|
+
cert: certPath,
|
|
127
|
+
rootCA: `${caLocation}/rootCA.pem`,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
console.error("Failed to generate self-signed certificate. Falling back to http.", err);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// get platform specific cache directory adapted from playwright's handling
|
|
135
|
+
// https://github.com/microsoft/playwright/blob/7d924470d397975a74a19184c136b3573a974e13/packages/playwright-core/src/utils/registry.ts#L141
|
|
136
|
+
function getCacheDirectory(fileDirectory, envPath) {
|
|
137
|
+
let result;
|
|
138
|
+
if (envPath) {
|
|
139
|
+
result = envPath;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
let systemCacheDirectory;
|
|
143
|
+
if (process.platform === "linux") {
|
|
144
|
+
systemCacheDirectory =
|
|
145
|
+
process.env.XDG_CACHE_HOME || node_path_1.default.join(os_1.default.homedir(), ".cache");
|
|
146
|
+
}
|
|
147
|
+
else if (process.platform === "darwin") {
|
|
148
|
+
systemCacheDirectory = node_path_1.default.join(os_1.default.homedir(), "Library", "Caches");
|
|
149
|
+
}
|
|
150
|
+
else if (process.platform === "win32") {
|
|
151
|
+
systemCacheDirectory =
|
|
152
|
+
process.env.LOCALAPPDATA || node_path_1.default.join(os_1.default.homedir(), "AppData", "Local");
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
/// Attempt to use generic tmp location for un-handled platform
|
|
156
|
+
if (!systemCacheDirectory) {
|
|
157
|
+
for (const dir of [
|
|
158
|
+
node_path_1.default.join(os_1.default.homedir(), ".cache"),
|
|
159
|
+
node_path_1.default.join(os_1.default.tmpdir()),
|
|
160
|
+
]) {
|
|
161
|
+
if (node_fs_1.default.existsSync(dir)) {
|
|
162
|
+
systemCacheDirectory = dir;
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (!systemCacheDirectory) {
|
|
168
|
+
console.error(new Error("Unsupported platform: " + process.platform));
|
|
169
|
+
process.exit(0);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
result = node_path_1.default.join(systemCacheDirectory, fileDirectory);
|
|
173
|
+
}
|
|
174
|
+
if (!node_path_1.default.isAbsolute(result)) {
|
|
175
|
+
// It is important to resolve to the absolute path:
|
|
176
|
+
// - for unzipping to work correctly;
|
|
177
|
+
// - so that registry directory matches between installation and execution.
|
|
178
|
+
// INIT_CWD points to the root of `npm/yarn install` and is probably what
|
|
179
|
+
// the user meant when typing the relative path.
|
|
180
|
+
result = node_path_1.default.resolve(process.env["INIT_CWD"] || process.cwd(), result);
|
|
181
|
+
}
|
|
182
|
+
return result;
|
|
183
|
+
}
|
package/cjs/project.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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;
|
|
6
6
|
constructor(cause: Error);
|
|
7
7
|
}
|
|
8
|
-
export declare function projectFactory(): (options: ProjectOptions
|
|
8
|
+
export declare function projectFactory(): (options: Required<ProjectOptions>, turboEngineOptions: binding.NapiTurboEngineOptions) => Promise<{
|
|
9
9
|
readonly _nativeProject: {
|
|
10
10
|
__napiType: "Project";
|
|
11
11
|
};
|
|
@@ -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/cjs/project.js
CHANGED
|
@@ -37,7 +37,6 @@ exports.TurbopackInternalError = void 0;
|
|
|
37
37
|
exports.projectFactory = projectFactory;
|
|
38
38
|
const util_1 = require("util");
|
|
39
39
|
const binding = __importStar(require("./binding"));
|
|
40
|
-
const nanoid_1 = require("nanoid");
|
|
41
40
|
const util_2 = require("./util");
|
|
42
41
|
class TurbopackInternalError extends Error {
|
|
43
42
|
constructor(cause) {
|
|
@@ -91,7 +90,6 @@ function ensureLoadersHaveSerializableOptions(turbopackRules) {
|
|
|
91
90
|
async function serializeConfig(config) {
|
|
92
91
|
var _a, _b;
|
|
93
92
|
let configSerializable = { ...config };
|
|
94
|
-
configSerializable.generateBuildId = () => (0, nanoid_1.nanoid)();
|
|
95
93
|
if ((_a = configSerializable.module) === null || _a === void 0 ? void 0 : _a.rules) {
|
|
96
94
|
ensureLoadersHaveSerializableOptions(configSerializable.module.rules);
|
|
97
95
|
}
|
package/cjs/types.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
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
|
+
export type RcStr = string;
|
|
14
|
+
}
|
|
2
15
|
export interface BaseUpdate {
|
|
3
16
|
resource: {
|
|
4
17
|
headers: unknown;
|
|
@@ -53,7 +66,6 @@ export interface DefineEnv {
|
|
|
53
66
|
}
|
|
54
67
|
export interface ExperimentalConfig {
|
|
55
68
|
}
|
|
56
|
-
export type TurbopackRuleConfigItemOrShortcut = TurbopackRuleConfigItem;
|
|
57
69
|
export type TurbopackRuleConfigItem = TurbopackRuleConfigItemOptions | {
|
|
58
70
|
[condition: string]: TurbopackRuleConfigItem;
|
|
59
71
|
} | false;
|
|
@@ -69,7 +81,7 @@ export type TurbopackRuleConfigItemOptions = {
|
|
|
69
81
|
as?: string;
|
|
70
82
|
};
|
|
71
83
|
export interface ModuleOptions {
|
|
72
|
-
rules?: Record<string,
|
|
84
|
+
rules?: Record<string, TurbopackRuleConfigItem>;
|
|
73
85
|
}
|
|
74
86
|
export interface ResolveOptions {
|
|
75
87
|
alias?: Record<string, string | string[] | Record<string, string | string[]>>;
|
|
@@ -140,6 +152,7 @@ export interface ConfigComplete {
|
|
|
140
152
|
images?: {
|
|
141
153
|
inlineLimit?: number;
|
|
142
154
|
};
|
|
155
|
+
stats?: boolean;
|
|
143
156
|
experimental?: ExperimentalConfig;
|
|
144
157
|
persistentCaching?: boolean;
|
|
145
158
|
cacheHandler?: string;
|
|
@@ -193,25 +206,25 @@ export interface ProjectOptions {
|
|
|
193
206
|
/**
|
|
194
207
|
* A map of environment variables to use when compiling code.
|
|
195
208
|
*/
|
|
196
|
-
processEnv
|
|
197
|
-
|
|
209
|
+
processEnv?: Record<string, string>;
|
|
210
|
+
defineEnv?: DefineEnv;
|
|
198
211
|
/**
|
|
199
212
|
* Whether to watch the filesystem for file changes.
|
|
200
213
|
*/
|
|
201
|
-
watch
|
|
214
|
+
watch?: {
|
|
202
215
|
enable: boolean;
|
|
203
216
|
pollIntervalMs?: number;
|
|
204
217
|
};
|
|
205
218
|
/**
|
|
206
219
|
* The mode of utoo-pack.
|
|
207
220
|
*/
|
|
208
|
-
dev
|
|
221
|
+
dev?: boolean;
|
|
209
222
|
/**
|
|
210
223
|
* The build id.
|
|
211
224
|
*/
|
|
212
|
-
buildId
|
|
225
|
+
buildId?: string;
|
|
213
226
|
}
|
|
214
|
-
export type
|
|
227
|
+
export type BundleOptions = Omit<ProjectOptions, "rootPath" | "projectPath">;
|
|
215
228
|
export interface Project {
|
|
216
229
|
update(options: Partial<ProjectOptions>): Promise<void>;
|
|
217
230
|
entrypointsSubscribe(): AsyncIterableIterator<TurbopackResult<RawEntrypoints>>;
|
package/cjs/util.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NapiIssue } from "./binding";
|
|
2
|
-
import {
|
|
2
|
+
import { ConfigComplete, DefineEnv, RustifiedEnv, StyledString } from "./types";
|
|
3
3
|
export declare class ModuleBuildError extends Error {
|
|
4
4
|
name: string;
|
|
5
5
|
}
|
package/cjs/util.js
CHANGED
|
@@ -10,8 +10,8 @@ exports.rustifyEnv = rustifyEnv;
|
|
|
10
10
|
exports.createDefineEnv = createDefineEnv;
|
|
11
11
|
exports.debounce = debounce;
|
|
12
12
|
exports.blockStdout = blockStdout;
|
|
13
|
-
const picocolors_1 = require("picocolors");
|
|
14
13
|
const code_frame_1 = require("@babel/code-frame");
|
|
14
|
+
const picocolors_1 = require("picocolors");
|
|
15
15
|
const magicIdentifier_1 = require("./magicIdentifier");
|
|
16
16
|
class ModuleBuildError extends Error {
|
|
17
17
|
constructor() {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type webpack from "webpack";
|
|
2
|
+
import { BundleOptions } from "./types";
|
|
3
|
+
export type WebpackConfig = Pick<webpack.Configuration, "name" | "entry" | "mode" | "module" | "resolve" | "externals" | "output" | "target" | "devtool" | "optimization" | "plugins" | "stats"> & {
|
|
4
|
+
compatMode: true;
|
|
5
|
+
};
|
|
6
|
+
export declare function compatOptionsFromWebpack(webpackConfig: WebpackConfig): BundleOptions;
|