rollipop 1.0.0-alpha.21 → 1.0.0-alpha.23
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/CHANGELOG.md +19 -0
- package/dist/{chunk-DEq-mXcV.js → _virtual/_rolldown/runtime.js} +1 -1
- package/dist/commands.d.ts +2 -4
- package/dist/commands.js +10 -3957
- package/dist/common/code.js +21 -0
- package/dist/common/constants.js +5 -0
- package/dist/common/env.js +33 -0
- package/dist/common/logger.d.ts +34 -0
- package/dist/common/logger.js +82 -0
- package/dist/common/logo.js +54 -0
- package/dist/common/progress-bar.js +167 -0
- package/dist/common/transformer.js +13 -0
- package/dist/common/types.d.ts +10 -0
- package/dist/config/compose-override.js +18 -0
- package/dist/config/defaults.d.ts +74 -0
- package/dist/config/defaults.js +74 -0
- package/dist/config/define-config.d.ts +13 -0
- package/dist/config/define-config.js +6 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.js +5 -0
- package/dist/config/load-config.d.ts +19 -0
- package/dist/config/load-config.js +73 -0
- package/dist/config/merge-config.d.ts +12 -0
- package/dist/config/merge-config.js +20 -0
- package/dist/config/types.d.ts +452 -0
- package/dist/constants.d.ts +35 -0
- package/dist/constants.js +146 -0
- package/dist/core/assets.d.ts +91 -0
- package/dist/core/assets.js +244 -0
- package/dist/core/bundler.d.ts +15 -0
- package/dist/core/bundler.js +80 -0
- package/dist/core/env.d.ts +11 -0
- package/dist/core/env.js +36 -0
- package/dist/core/fs/data.js +9 -0
- package/dist/core/fs/storage.d.ts +15 -0
- package/dist/core/fs/storage.js +31 -0
- package/dist/core/plugins/babel-plugin.d.ts +22 -0
- package/dist/core/plugins/babel-plugin.js +74 -0
- package/dist/core/plugins/context.d.ts +10 -0
- package/dist/core/plugins/context.js +24 -0
- package/dist/core/plugins/dev-server-plugin.d.ts +13 -0
- package/dist/core/plugins/dev-server-plugin.js +27 -0
- package/dist/core/plugins/index.d.ts +13 -0
- package/dist/core/plugins/index.js +18 -0
- package/dist/core/plugins/prelude-plugin.d.ts +10 -0
- package/dist/core/plugins/prelude-plugin.js +23 -0
- package/dist/core/plugins/react-native-plugin.d.ts +36 -0
- package/dist/core/plugins/react-native-plugin.js +81 -0
- package/dist/core/plugins/reporter-plugin.d.ts +11 -0
- package/dist/core/plugins/reporter-plugin.js +87 -0
- package/dist/core/plugins/shared/filters.js +5 -0
- package/dist/core/plugins/swc-plugin.d.ts +26 -0
- package/dist/core/plugins/swc-plugin.js +108 -0
- package/dist/core/plugins/types.d.ts +18 -0
- package/dist/core/plugins/utils/source.js +10 -0
- package/dist/core/plugins/utils/transform-utils.js +56 -0
- package/dist/core/rolldown.js +313 -0
- package/dist/core/settings.js +19 -0
- package/dist/core/types.d.ts +83 -0
- package/dist/filter.d.ts +1 -0
- package/dist/filter.js +2 -0
- package/dist/hmr-runtime.iife.js +5 -5
- package/dist/index.d.ts +24 -1221
- package/dist/index.js +19 -4029
- package/dist/internal/react-native.js +24 -0
- package/dist/logger.js +5 -0
- package/dist/node/cli-utils.d.ts +10 -0
- package/dist/node/cli-utils.js +28 -0
- package/dist/node/cli.d.ts +6 -0
- package/dist/node/cli.js +23 -0
- package/dist/node/commands/agent/action.js +91 -0
- package/dist/node/commands/agent/command.js +10 -0
- package/dist/node/commands/agent/index.js +2 -0
- package/dist/node/commands/bundle/action.js +33 -0
- package/dist/node/commands/bundle/command.js +96 -0
- package/dist/node/commands/bundle/index.js +2 -0
- package/dist/node/commands/start/action.js +37 -0
- package/dist/node/commands/start/command.js +93 -0
- package/dist/node/commands/start/debugger.js +79 -0
- package/dist/node/commands/start/index.js +2 -0
- package/dist/node/commands/start/setup-interactive-mode.d.ts +20 -0
- package/dist/node/commands/start/setup-interactive-mode.js +107 -0
- package/dist/node/constants.js +4 -0
- package/dist/node/logger.js +5 -0
- package/dist/node/types.d.ts +23 -0
- package/dist/node/utils.js +23 -0
- package/dist/package.js +4 -0
- package/dist/runtime.js +1 -1
- package/dist/server/bundle.d.ts +12 -0
- package/dist/server/bundle.js +55 -0
- package/dist/server/bundler-pool.d.ts +51 -0
- package/dist/server/bundler-pool.js +197 -0
- package/dist/server/common/schema.js +19 -0
- package/dist/server/constants.d.ts +6 -0
- package/dist/server/constants.js +6 -0
- package/dist/server/create-dev-server.d.ts +6 -0
- package/dist/server/create-dev-server.js +185 -0
- package/dist/server/error.js +9 -0
- package/dist/server/events/event-bus.d.ts +12 -0
- package/dist/server/events/event-bus.js +16 -0
- package/dist/server/events/types.d.ts +37 -0
- package/dist/server/events/types.js +6 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +3 -0
- package/dist/server/logger.js +33 -0
- package/dist/server/mcp/context.js +14 -0
- package/dist/server/mcp/server.js +86 -0
- package/dist/server/mcp/tools/app-log-diagnostics.js +37 -0
- package/dist/server/mcp/tools/build-diagnostics.js +97 -0
- package/dist/server/mcp/tools/build-info.js +33 -0
- package/dist/server/mcp/tools/device-diagnostics.js +52 -0
- package/dist/server/mcp/tools/index.js +277 -0
- package/dist/server/middlewares/request-logger.js +15 -0
- package/dist/server/middlewares/serve-assets.js +49 -0
- package/dist/server/middlewares/serve-bundle.js +72 -0
- package/dist/server/middlewares/sse.js +34 -0
- package/dist/server/middlewares/symbolicate.js +71 -0
- package/dist/server/sse/adapter.js +74 -0
- package/dist/server/sse/event-bus.js +26 -0
- package/dist/server/symbolicate.js +93 -0
- package/dist/server/types.d.ts +125 -0
- package/dist/server/wss/hmr-server.js +209 -0
- package/dist/server/wss/server.d.ts +9 -0
- package/dist/server/wss/server.js +70 -0
- package/dist/{runtime.d.cts → types/hmr.d.ts} +1 -12
- package/dist/types.d.ts +78 -0
- package/dist/utils/babel.js +11 -0
- package/dist/utils/build-options.js +17 -0
- package/dist/utils/bundle.js +6 -0
- package/dist/utils/config.d.ts +5 -0
- package/dist/utils/config.js +32 -0
- package/dist/utils/dev-server.js +51 -0
- package/dist/utils/env.js +7 -0
- package/dist/utils/errors.js +9 -0
- package/dist/utils/hash.js +8 -0
- package/dist/utils/id.js +28 -0
- package/dist/utils/node-resolve.js +42 -0
- package/dist/utils/promise.js +15 -0
- package/dist/utils/reporters.js +120 -0
- package/dist/utils/reset-cache.d.ts +8 -0
- package/dist/utils/reset-cache.js +25 -0
- package/dist/utils/response.js +91 -0
- package/dist/utils/run-build.d.ts +8 -0
- package/dist/utils/run-build.js +7 -0
- package/dist/utils/run-server.d.ts +6 -0
- package/dist/utils/run-server.js +20 -0
- package/dist/utils/runtime-target.js +9 -0
- package/dist/utils/serialize.js +10 -0
- package/dist/utils/server.js +6 -0
- package/dist/utils/storage.js +6 -0
- package/dist/utils/string.js +6 -0
- package/dist/utils/swc.js +10 -0
- package/dist/utils/terminal.js +86 -0
- package/dist/utils/url.js +23 -0
- package/package.json +56 -68
- package/dist/commands.cjs +0 -4008
- package/dist/commands.d.cts +0 -5
- package/dist/pluginutils.d.ts +0 -1
- package/dist/pluginutils.js +0 -2
- package/dist/runtime.cjs +0 -34
- /package/dist/{chunk-DXpK5_cz.js → chunk-DJV587Yu.js} +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { logger } from "../server/logger.js";
|
|
2
|
+
import http from "node:http";
|
|
3
|
+
//#region src/utils/dev-server.ts
|
|
4
|
+
async function assertDevServerStatus(options) {
|
|
5
|
+
const { devServerUrl, projectRoot, port } = options;
|
|
6
|
+
const status = await getDevServerStatus(devServerUrl, projectRoot);
|
|
7
|
+
let shouldExit = false;
|
|
8
|
+
switch (status) {
|
|
9
|
+
case 1:
|
|
10
|
+
logger.warn(`A dev server is already running for this project on port ${port}. Exiting.`);
|
|
11
|
+
shouldExit = true;
|
|
12
|
+
break;
|
|
13
|
+
case 2:
|
|
14
|
+
logger.error(`Another process is running on port ${port}. Please terminate this process and try again, or use another port with "--port".`);
|
|
15
|
+
shouldExit = true;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
if (shouldExit) process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
async function getDevServerStatus(devServerUrl, projectRoot) {
|
|
21
|
+
const { hostname, port } = new URL(devServerUrl);
|
|
22
|
+
try {
|
|
23
|
+
if (!await isPortOccupied(hostname, port)) return 0;
|
|
24
|
+
const statusResponse = await fetch(`${devServerUrl}/status`);
|
|
25
|
+
return await statusResponse.text() === "packager-status:running" && statusResponse.headers.get("X-React-Native-Project-Root") === projectRoot ? 1 : 2;
|
|
26
|
+
} catch {
|
|
27
|
+
return 3;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function isPortOccupied(host, port) {
|
|
31
|
+
let result = false;
|
|
32
|
+
const server = http.createServer();
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
server.once("error", (error) => {
|
|
35
|
+
server.close();
|
|
36
|
+
if (error.code === "EADDRINUSE") result = true;
|
|
37
|
+
else reject(error);
|
|
38
|
+
});
|
|
39
|
+
server.once("listening", () => {
|
|
40
|
+
result = false;
|
|
41
|
+
server.close();
|
|
42
|
+
});
|
|
43
|
+
server.once("close", () => resolve(result));
|
|
44
|
+
server.listen({
|
|
45
|
+
host,
|
|
46
|
+
port
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { assertDevServerStatus };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { asLiteral } from "../common/code.js";
|
|
2
|
+
//#region src/utils/env.ts
|
|
3
|
+
function defineEnvFromObject(env) {
|
|
4
|
+
return Object.fromEntries(Object.entries(env).map(([key, value]) => [`import.meta.env.${key}`, asLiteral(value)]));
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { defineEnvFromObject };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import stripAnsi from "strip-ansi";
|
|
2
|
+
//#region src/utils/errors.ts
|
|
3
|
+
function normalizeRolldownError(error) {
|
|
4
|
+
const normalizedError = new Error(stripAnsi(error.message));
|
|
5
|
+
normalizedError.stack = error.stack;
|
|
6
|
+
return normalizedError;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { normalizeRolldownError };
|
package/dist/utils/id.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ROLLIPOP_VERSION } from "../constants.js";
|
|
2
|
+
import { md5 } from "./hash.js";
|
|
3
|
+
import { serialize } from "./serialize.js";
|
|
4
|
+
import { pick } from "es-toolkit";
|
|
5
|
+
//#region src/utils/id.ts
|
|
6
|
+
function createId(config, buildOptions) {
|
|
7
|
+
return md5(serialize([
|
|
8
|
+
ROLLIPOP_VERSION,
|
|
9
|
+
filterTransformAffectedOptions(buildOptions),
|
|
10
|
+
filterTransformAffectedConfig(config)
|
|
11
|
+
]));
|
|
12
|
+
}
|
|
13
|
+
function filterTransformAffectedOptions(buildOptions) {
|
|
14
|
+
return pick(buildOptions, ["platform", "dev"]);
|
|
15
|
+
}
|
|
16
|
+
function filterTransformAffectedConfig(config) {
|
|
17
|
+
const { transformer, serializer, reactNative, devMode, plugins = [] } = config;
|
|
18
|
+
return [
|
|
19
|
+
transformer,
|
|
20
|
+
serializer.polyfills,
|
|
21
|
+
serializer.prelude,
|
|
22
|
+
reactNative.assetRegistryPath,
|
|
23
|
+
devMode,
|
|
24
|
+
plugins.map((plugin, index) => `${plugin.name}#${index}`)
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { createId };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { __require } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/utils/node-resolve.ts
|
|
5
|
+
function resolveFrom(basePath, lookupPath) {
|
|
6
|
+
if (path.isAbsolute(lookupPath)) return lookupPath;
|
|
7
|
+
return __require.resolve(lookupPath, { paths: [basePath] });
|
|
8
|
+
}
|
|
9
|
+
function resolvePackagePath(basePath, packageName) {
|
|
10
|
+
let packagePath = null;
|
|
11
|
+
try {
|
|
12
|
+
packagePath = resolvePackagePathWithNodeRequire(basePath, packageName, "package.json");
|
|
13
|
+
if (packagePath) return packagePath;
|
|
14
|
+
} catch {}
|
|
15
|
+
try {
|
|
16
|
+
packagePath = resolvePackagePathWithNodeRequire(basePath, packageName);
|
|
17
|
+
if (packagePath) return packagePath;
|
|
18
|
+
} catch {}
|
|
19
|
+
throw new Error(`Failed to resolve package path for '${packageName}'`);
|
|
20
|
+
}
|
|
21
|
+
function resolvePackageJson(basePath, packageName) {
|
|
22
|
+
try {
|
|
23
|
+
const packagePath = resolvePackagePath(basePath, packageName);
|
|
24
|
+
const packageJsonPath = path.join(packagePath, "package.json");
|
|
25
|
+
const rawPackageJson = fs.readFileSync(packageJsonPath, "utf-8");
|
|
26
|
+
return JSON.parse(rawPackageJson);
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function resolvePackagePathWithNodeRequire(basePath, packageName, subpath) {
|
|
32
|
+
const resolvedPath = __require.resolve(subpath ? `${packageName}/${subpath}` : packageName, { paths: [basePath] });
|
|
33
|
+
const root = path.parse(resolvedPath).root;
|
|
34
|
+
let currentPath = path.dirname(resolvedPath);
|
|
35
|
+
while (currentPath !== root) {
|
|
36
|
+
if (fs.existsSync(path.join(currentPath, "package.json"))) return currentPath;
|
|
37
|
+
currentPath = path.dirname(currentPath);
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { resolveFrom, resolvePackageJson, resolvePackagePath };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/utils/promise.ts
|
|
2
|
+
function taskHandler() {
|
|
3
|
+
let resolver;
|
|
4
|
+
let rejector;
|
|
5
|
+
return {
|
|
6
|
+
task: new Promise((resolve, reject) => {
|
|
7
|
+
resolver = resolve;
|
|
8
|
+
rejector = reject;
|
|
9
|
+
}),
|
|
10
|
+
resolve: () => resolver?.(void 0),
|
|
11
|
+
reject: (reason) => rejector?.(reason)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { taskHandler };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Logger } from "../common/logger.js";
|
|
2
|
+
import { ProgressBarRenderManager } from "../common/progress-bar.js";
|
|
3
|
+
import { logger } from "../logger.js";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
//#region src/utils/reporters.ts
|
|
7
|
+
function mergeReporters(reporters) {
|
|
8
|
+
return { update(event) {
|
|
9
|
+
reporters.forEach((reporter) => reporter.update(event));
|
|
10
|
+
} };
|
|
11
|
+
}
|
|
12
|
+
var ClientLogReporter = class {
|
|
13
|
+
logger = new Logger("app");
|
|
14
|
+
update(event) {
|
|
15
|
+
if (event.type === "client_log") {
|
|
16
|
+
if (event.level === "group" || event.level === "groupCollapsed") {
|
|
17
|
+
this.logger.info(...event.data);
|
|
18
|
+
return;
|
|
19
|
+
} else if (event.level === "groupEnd") return;
|
|
20
|
+
this.logger[event.level](...event.data);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var ProgressBarStatusReporter = class {
|
|
25
|
+
root;
|
|
26
|
+
renderManager = ProgressBarRenderManager.getInstance();
|
|
27
|
+
progressBar;
|
|
28
|
+
flags = 0;
|
|
29
|
+
progressVisible = false;
|
|
30
|
+
lastBuildTotalModules;
|
|
31
|
+
hmrUpdateCount = 0;
|
|
32
|
+
constructor(root, id, label, initialTotalModules) {
|
|
33
|
+
this.root = root;
|
|
34
|
+
this.lastBuildTotalModules = initialTotalModules;
|
|
35
|
+
this.progressBar = this.renderManager.register(id, {
|
|
36
|
+
label,
|
|
37
|
+
total: initialTotalModules
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
renderProgress(id, totalModules, transformedModules) {
|
|
41
|
+
const isHmrProgress = (this.flags & 1) === 0 && (this.flags & 2) !== 0;
|
|
42
|
+
if (isHmrProgress) this.progressBar.setCurrent(0).setTotal(0).start();
|
|
43
|
+
const shouldStartProgress = !this.progressVisible;
|
|
44
|
+
if (shouldStartProgress) this.progressVisible = true;
|
|
45
|
+
if (totalModules != null) this.progressBar.setTotal(totalModules);
|
|
46
|
+
const displayId = this.getDisplayPath(id);
|
|
47
|
+
this.progressBar.setCurrent(transformedModules).setModuleId(displayId);
|
|
48
|
+
if (shouldStartProgress) this.renderManager.start();
|
|
49
|
+
else this.renderManager.render();
|
|
50
|
+
if (isHmrProgress) {
|
|
51
|
+
this.flags = 0;
|
|
52
|
+
this.hmrUpdateCount++;
|
|
53
|
+
this.progressBar.completeHmr(displayId, this.hmrUpdateCount);
|
|
54
|
+
this.renderManager.release();
|
|
55
|
+
this.progressVisible = false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
getCompletedBuildCurrent(event) {
|
|
59
|
+
const processedModules = event.transformedModules + event.cacheHitModules;
|
|
60
|
+
return processedModules === 0 && event.totalModules > 0 ? event.totalModules : processedModules;
|
|
61
|
+
}
|
|
62
|
+
getDisplayPath(id) {
|
|
63
|
+
const relativePath = path.relative(this.root, id);
|
|
64
|
+
if (relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath)) return relativePath;
|
|
65
|
+
return id;
|
|
66
|
+
}
|
|
67
|
+
update(event) {
|
|
68
|
+
switch (event.type) {
|
|
69
|
+
case "bundle_build_started":
|
|
70
|
+
this.progressBar.setCurrent(0).setTotal(this.lastBuildTotalModules);
|
|
71
|
+
this.flags |= 1;
|
|
72
|
+
this.progressBar.start();
|
|
73
|
+
if ((this.flags & 2) !== 0) {
|
|
74
|
+
this.progressVisible = true;
|
|
75
|
+
this.renderManager.start();
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
case "bundle_build_failed":
|
|
79
|
+
this.flags = 0;
|
|
80
|
+
this.progressBar.complete(0, true);
|
|
81
|
+
this.renderManager.release();
|
|
82
|
+
this.progressVisible = false;
|
|
83
|
+
break;
|
|
84
|
+
case "bundle_build_done":
|
|
85
|
+
this.flags = 0;
|
|
86
|
+
this.lastBuildTotalModules = event.totalModules;
|
|
87
|
+
this.progressBar.setCurrent(this.getCompletedBuildCurrent(event)).setTotal(event.totalModules).complete(event.duration, false);
|
|
88
|
+
this.renderManager.release();
|
|
89
|
+
this.progressVisible = false;
|
|
90
|
+
break;
|
|
91
|
+
case "transform":
|
|
92
|
+
const { id, totalModules, transformedModules } = event;
|
|
93
|
+
this.renderProgress(id, totalModules, transformedModules);
|
|
94
|
+
break;
|
|
95
|
+
case "watch_change":
|
|
96
|
+
this.flags |= 2;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
var CompatStatusReporter = class {
|
|
102
|
+
update(event) {
|
|
103
|
+
switch (event.type) {
|
|
104
|
+
case "bundle_build_started":
|
|
105
|
+
logger.info("Build started...");
|
|
106
|
+
break;
|
|
107
|
+
case "bundle_build_failed":
|
|
108
|
+
logger.error(`Build failed`);
|
|
109
|
+
break;
|
|
110
|
+
case "bundle_build_done":
|
|
111
|
+
const { duration, totalModules } = event;
|
|
112
|
+
const time = chalk.blue(`${duration.toFixed(2)}ms`);
|
|
113
|
+
const modules = chalk.blue(`(${totalModules} modules)`);
|
|
114
|
+
logger.info(`Build completed in ${time} ${modules}`);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
//#endregion
|
|
120
|
+
export { ClientLogReporter, CompatStatusReporter, ProgressBarStatusReporter, mergeReporters };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/utils/reset-cache.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Remove the entire build cache directory for the given project root.
|
|
4
|
+
* Backs the `reset_cache` MCP tool and the `--reset-cache` CLI flag.
|
|
5
|
+
*/
|
|
6
|
+
declare function resetCache(projectRoot: string): void;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { resetCache };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getSharedDataPath } from "../core/fs/data.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/utils/reset-cache.ts
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the build cache directory for the given project root. The cache
|
|
7
|
+
* itself is owned by rolldown's native implementation; we keep the path
|
|
8
|
+
* here only because `resetCache` — and any tooling that wants to inspect
|
|
9
|
+
* the on-disk layout — needs to know where to look.
|
|
10
|
+
*/
|
|
11
|
+
function getCacheDirectory(projectRoot) {
|
|
12
|
+
return path.join(getSharedDataPath(projectRoot), "cache");
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Remove the entire build cache directory for the given project root.
|
|
16
|
+
* Backs the `reset_cache` MCP tool and the `--reset-cache` CLI flag.
|
|
17
|
+
*/
|
|
18
|
+
function resetCache(projectRoot) {
|
|
19
|
+
fs.rmSync(getCacheDirectory(projectRoot), {
|
|
20
|
+
recursive: true,
|
|
21
|
+
force: true
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { resetCache };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//#region src/utils/response.ts
|
|
2
|
+
var BundleResponse = class BundleResponse {
|
|
3
|
+
reply;
|
|
4
|
+
static CRLF = "\r\n";
|
|
5
|
+
static THROTTLE_DELAY = 10;
|
|
6
|
+
done = 0;
|
|
7
|
+
total = 0;
|
|
8
|
+
boundary;
|
|
9
|
+
throttleTimer = null;
|
|
10
|
+
constructor(reply) {
|
|
11
|
+
this.reply = reply;
|
|
12
|
+
const boundary = performance.now().toString();
|
|
13
|
+
this.boundary = boundary;
|
|
14
|
+
this.reply.raw.writeHead(200, { "Content-Type": `multipart/mixed; boundary="${boundary}"` });
|
|
15
|
+
}
|
|
16
|
+
writeChunk(data, headers, end = false) {
|
|
17
|
+
if (this.reply.raw.writableEnded) return;
|
|
18
|
+
const CRLF = BundleResponse.CRLF;
|
|
19
|
+
this.reply.raw.write(`${CRLF}--${this.boundary}${CRLF}`);
|
|
20
|
+
this.reply.raw.write(Object.entries(headers).map(([key, value]) => `${key}: ${value}`).join(CRLF) + CRLF + CRLF);
|
|
21
|
+
if (data) this.reply.raw.write(data);
|
|
22
|
+
if (end) {
|
|
23
|
+
this.reply.raw.write(`${CRLF}--${this.boundary}--${CRLF}`);
|
|
24
|
+
this.reply.raw.end();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Sample
|
|
29
|
+
*
|
|
30
|
+
* ```
|
|
31
|
+
* --boundary
|
|
32
|
+
*
|
|
33
|
+
* Content-Type: application/json
|
|
34
|
+
*
|
|
35
|
+
* {"done":10,"total":100}
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
writeBundleState(done, total) {
|
|
39
|
+
const previousProgress = this.done / this.total;
|
|
40
|
+
const currentProgress = done / total;
|
|
41
|
+
this.done = done;
|
|
42
|
+
this.total = total;
|
|
43
|
+
if (total < 10 || this.throttleTimer != null || previousProgress >= currentProgress) return;
|
|
44
|
+
this.writeChunk(JSON.stringify({
|
|
45
|
+
done,
|
|
46
|
+
total
|
|
47
|
+
}), { "Content-Type": "application/json" });
|
|
48
|
+
this.throttleTimer = setTimeout(() => {
|
|
49
|
+
this.throttleTimer = null;
|
|
50
|
+
}, BundleResponse.THROTTLE_DELAY);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Sample
|
|
54
|
+
*
|
|
55
|
+
* ```
|
|
56
|
+
* --boundary
|
|
57
|
+
*
|
|
58
|
+
* X-Metro-Files-Changed-Count: 0
|
|
59
|
+
* Content-Type: application/json
|
|
60
|
+
* Content-Length: 100
|
|
61
|
+
* Last-Modified: Thu, 10 Aug 2023 12:00:00 GMT
|
|
62
|
+
*
|
|
63
|
+
* <bundle result>
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
endWithBundle(bundle) {
|
|
67
|
+
this.writeChunk(JSON.stringify({
|
|
68
|
+
done: this.total,
|
|
69
|
+
total: this.total
|
|
70
|
+
}), { "Content-Type": "application/json" });
|
|
71
|
+
this.writeChunk(bundle, {
|
|
72
|
+
"X-Metro-Files-Changed-Count": String(0),
|
|
73
|
+
"Content-Type": "application/javascript; charset=UTF-8",
|
|
74
|
+
"Content-Length": String(Buffer.byteLength(bundle)),
|
|
75
|
+
"Last-Modified": (/* @__PURE__ */ new Date()).toUTCString()
|
|
76
|
+
}, true);
|
|
77
|
+
}
|
|
78
|
+
endWithError(error) {
|
|
79
|
+
const errorData = JSON.stringify({
|
|
80
|
+
type: error?.name ?? "InternalError",
|
|
81
|
+
message: error?.message ?? "internal error",
|
|
82
|
+
errors: []
|
|
83
|
+
});
|
|
84
|
+
this.writeChunk(errorData, {
|
|
85
|
+
"Content-Type": "application/json",
|
|
86
|
+
"X-Http-Status": "500"
|
|
87
|
+
}, true);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
//#endregion
|
|
91
|
+
export { BundleResponse };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BuildOptions } from "../core/types.js";
|
|
2
|
+
import { ResolvedConfig } from "../config/defaults.js";
|
|
3
|
+
import * as rolldown from "@rollipop/rolldown";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/run-build.d.ts
|
|
6
|
+
declare function runBuild(config: ResolvedConfig, options: BuildOptions): Promise<rolldown.OutputChunk>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { runBuild };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DevServer, ServerOptions } from "../server/types.js";
|
|
2
|
+
import { ResolvedConfig } from "../config/defaults.js";
|
|
3
|
+
//#region src/utils/run-server.d.ts
|
|
4
|
+
declare function runServer(config: ResolvedConfig, options: ServerOptions): Promise<DevServer>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { runServer };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { logger } from "../server/logger.js";
|
|
2
|
+
import { DEFAULT_HOST, DEFAULT_PORT } from "../server/constants.js";
|
|
3
|
+
import { createDevServer } from "../server/create-dev-server.js";
|
|
4
|
+
import "../server/index.js";
|
|
5
|
+
//#region src/utils/run-server.ts
|
|
6
|
+
async function runServer(config, options) {
|
|
7
|
+
const { port = DEFAULT_PORT, host = DEFAULT_HOST, https = false } = options;
|
|
8
|
+
const devServer = await createDevServer(config, options);
|
|
9
|
+
await devServer.instance.listen({
|
|
10
|
+
port,
|
|
11
|
+
host
|
|
12
|
+
});
|
|
13
|
+
if (options.mcp === true) {
|
|
14
|
+
const protocol = https ? "https" : "http";
|
|
15
|
+
logger.info(`MCP server listening at ${protocol}://${host}:${port}/mcp`);
|
|
16
|
+
}
|
|
17
|
+
return devServer;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { runServer };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/utils/serialize.ts
|
|
2
|
+
function serialize(value) {
|
|
3
|
+
return JSON.stringify(value, (_, value) => {
|
|
4
|
+
if (typeof value === "function") return value.toString();
|
|
5
|
+
if (value instanceof RegExp) return value.toString();
|
|
6
|
+
return value;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { serialize };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { mergeWith } from "es-toolkit";
|
|
2
|
+
//#region src/utils/swc.ts
|
|
3
|
+
function mergeSwcOptions(options) {
|
|
4
|
+
return options.reduce((acc, options) => mergeWith(acc, options, merge$1), {});
|
|
5
|
+
}
|
|
6
|
+
function merge$1(target, source, key) {
|
|
7
|
+
if (key === "plugins") return [...target ?? [], ...source ?? []];
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { mergeSwcOptions };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import wrapAnsi from "wrap-ansi";
|
|
2
|
+
//#region src/utils/terminal.ts
|
|
3
|
+
/**
|
|
4
|
+
* Based on https://github.com/sindresorhus/log-update/blob/master/index.js
|
|
5
|
+
* Based on https://github.com/unjs/webpackbar
|
|
6
|
+
*/
|
|
7
|
+
function eraseLines(count) {
|
|
8
|
+
let clear = "";
|
|
9
|
+
for (let i = 0; i < count; i++) clear += `\u001B[2K` + (i < count - 1 ? `\u001B[1A` : "");
|
|
10
|
+
if (count) clear += `\u001B[G`;
|
|
11
|
+
return clear;
|
|
12
|
+
}
|
|
13
|
+
function ellipsisLeft(value, maxLength) {
|
|
14
|
+
if (value.length <= maxLength - 3) return value;
|
|
15
|
+
return `...${value.slice(value.length - maxLength - 1)}`;
|
|
16
|
+
}
|
|
17
|
+
const originalWrite = Symbol("original-write");
|
|
18
|
+
var StreamManager = class {
|
|
19
|
+
prevLineCount;
|
|
20
|
+
listening;
|
|
21
|
+
extraLines;
|
|
22
|
+
_streams;
|
|
23
|
+
constructor() {
|
|
24
|
+
this.prevLineCount = 0;
|
|
25
|
+
this.listening = false;
|
|
26
|
+
this.extraLines = "";
|
|
27
|
+
this._onData = this._onData.bind(this);
|
|
28
|
+
this._streams = [process.stdout, process.stderr];
|
|
29
|
+
}
|
|
30
|
+
render(lines) {
|
|
31
|
+
this.listen();
|
|
32
|
+
const wrappedLines = wrapAnsi(lines, this.columns, {
|
|
33
|
+
trim: false,
|
|
34
|
+
hard: true,
|
|
35
|
+
wordWrap: false
|
|
36
|
+
});
|
|
37
|
+
const data = eraseLines(this.prevLineCount) + wrappedLines + "\n" + this.extraLines;
|
|
38
|
+
this.write(data);
|
|
39
|
+
const _lines = data.split("\n");
|
|
40
|
+
this.prevLineCount = _lines.length;
|
|
41
|
+
}
|
|
42
|
+
get columns() {
|
|
43
|
+
return (process.stderr.columns || 80) - 2;
|
|
44
|
+
}
|
|
45
|
+
write(data) {
|
|
46
|
+
const stream = process.stderr;
|
|
47
|
+
if (stream.write[originalWrite]) stream.write[originalWrite].call(stream, data, "utf8");
|
|
48
|
+
else stream.write(data, "utf8");
|
|
49
|
+
}
|
|
50
|
+
clear() {
|
|
51
|
+
this.done();
|
|
52
|
+
this.write(eraseLines(this.prevLineCount));
|
|
53
|
+
}
|
|
54
|
+
done() {
|
|
55
|
+
this.stopListen();
|
|
56
|
+
this.prevLineCount = 0;
|
|
57
|
+
this.extraLines = "";
|
|
58
|
+
}
|
|
59
|
+
_onData(data) {
|
|
60
|
+
const lines = String(data).split("\n").length - 1;
|
|
61
|
+
if (lines > 0) {
|
|
62
|
+
this.prevLineCount += lines;
|
|
63
|
+
this.extraLines += data;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
listen() {
|
|
67
|
+
if (this.listening) return;
|
|
68
|
+
for (const stream of this._streams) {
|
|
69
|
+
if (stream.write[originalWrite]) continue;
|
|
70
|
+
const write = (data, ...args) => {
|
|
71
|
+
if (!stream.write[originalWrite]) return stream.write(data, ...args);
|
|
72
|
+
this._onData(data);
|
|
73
|
+
return stream.write[originalWrite].call(stream, data, ...args);
|
|
74
|
+
};
|
|
75
|
+
write[originalWrite] = stream.write;
|
|
76
|
+
stream.write = write;
|
|
77
|
+
}
|
|
78
|
+
this.listening = true;
|
|
79
|
+
}
|
|
80
|
+
stopListen() {
|
|
81
|
+
for (const stream of this._streams) if (stream.write[originalWrite]) stream.write = stream.write[originalWrite];
|
|
82
|
+
this.listening = false;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
//#endregion
|
|
86
|
+
export { StreamManager, ellipsisLeft };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/utils/url.ts
|
|
2
|
+
function parseUrl(value) {
|
|
3
|
+
if (value.startsWith("/")) {
|
|
4
|
+
const [pathname, query] = value.split("?");
|
|
5
|
+
return {
|
|
6
|
+
pathname,
|
|
7
|
+
query: query ? toQueryObject(new URLSearchParams(query)) : {}
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const url = new URL(value);
|
|
11
|
+
return {
|
|
12
|
+
pathname: url.pathname,
|
|
13
|
+
query: toQueryObject(url.searchParams)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function toQueryObject(searchParams) {
|
|
17
|
+
return searchParams.entries().reduce((acc, [key, value]) => ({
|
|
18
|
+
...acc,
|
|
19
|
+
[key]: value
|
|
20
|
+
}), {});
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { parseUrl };
|