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.
Files changed (161) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/{chunk-DEq-mXcV.js → _virtual/_rolldown/runtime.js} +1 -1
  3. package/dist/commands.d.ts +2 -4
  4. package/dist/commands.js +10 -3957
  5. package/dist/common/code.js +21 -0
  6. package/dist/common/constants.js +5 -0
  7. package/dist/common/env.js +33 -0
  8. package/dist/common/logger.d.ts +34 -0
  9. package/dist/common/logger.js +82 -0
  10. package/dist/common/logo.js +54 -0
  11. package/dist/common/progress-bar.js +167 -0
  12. package/dist/common/transformer.js +13 -0
  13. package/dist/common/types.d.ts +10 -0
  14. package/dist/config/compose-override.js +18 -0
  15. package/dist/config/defaults.d.ts +74 -0
  16. package/dist/config/defaults.js +74 -0
  17. package/dist/config/define-config.d.ts +13 -0
  18. package/dist/config/define-config.js +6 -0
  19. package/dist/config/index.d.ts +5 -0
  20. package/dist/config/index.js +5 -0
  21. package/dist/config/load-config.d.ts +19 -0
  22. package/dist/config/load-config.js +73 -0
  23. package/dist/config/merge-config.d.ts +12 -0
  24. package/dist/config/merge-config.js +20 -0
  25. package/dist/config/types.d.ts +452 -0
  26. package/dist/constants.d.ts +35 -0
  27. package/dist/constants.js +146 -0
  28. package/dist/core/assets.d.ts +91 -0
  29. package/dist/core/assets.js +244 -0
  30. package/dist/core/bundler.d.ts +15 -0
  31. package/dist/core/bundler.js +80 -0
  32. package/dist/core/env.d.ts +11 -0
  33. package/dist/core/env.js +36 -0
  34. package/dist/core/fs/data.js +9 -0
  35. package/dist/core/fs/storage.d.ts +15 -0
  36. package/dist/core/fs/storage.js +31 -0
  37. package/dist/core/plugins/babel-plugin.d.ts +22 -0
  38. package/dist/core/plugins/babel-plugin.js +74 -0
  39. package/dist/core/plugins/context.d.ts +10 -0
  40. package/dist/core/plugins/context.js +24 -0
  41. package/dist/core/plugins/dev-server-plugin.d.ts +13 -0
  42. package/dist/core/plugins/dev-server-plugin.js +27 -0
  43. package/dist/core/plugins/index.d.ts +13 -0
  44. package/dist/core/plugins/index.js +18 -0
  45. package/dist/core/plugins/prelude-plugin.d.ts +10 -0
  46. package/dist/core/plugins/prelude-plugin.js +23 -0
  47. package/dist/core/plugins/react-native-plugin.d.ts +36 -0
  48. package/dist/core/plugins/react-native-plugin.js +81 -0
  49. package/dist/core/plugins/reporter-plugin.d.ts +11 -0
  50. package/dist/core/plugins/reporter-plugin.js +87 -0
  51. package/dist/core/plugins/shared/filters.js +5 -0
  52. package/dist/core/plugins/swc-plugin.d.ts +26 -0
  53. package/dist/core/plugins/swc-plugin.js +108 -0
  54. package/dist/core/plugins/types.d.ts +18 -0
  55. package/dist/core/plugins/utils/source.js +10 -0
  56. package/dist/core/plugins/utils/transform-utils.js +56 -0
  57. package/dist/core/rolldown.js +313 -0
  58. package/dist/core/settings.js +19 -0
  59. package/dist/core/types.d.ts +83 -0
  60. package/dist/filter.d.ts +1 -0
  61. package/dist/filter.js +2 -0
  62. package/dist/hmr-runtime.iife.js +5 -5
  63. package/dist/index.d.ts +24 -1221
  64. package/dist/index.js +19 -4029
  65. package/dist/internal/react-native.js +24 -0
  66. package/dist/logger.js +5 -0
  67. package/dist/node/cli-utils.d.ts +10 -0
  68. package/dist/node/cli-utils.js +28 -0
  69. package/dist/node/cli.d.ts +6 -0
  70. package/dist/node/cli.js +23 -0
  71. package/dist/node/commands/agent/action.js +91 -0
  72. package/dist/node/commands/agent/command.js +10 -0
  73. package/dist/node/commands/agent/index.js +2 -0
  74. package/dist/node/commands/bundle/action.js +33 -0
  75. package/dist/node/commands/bundle/command.js +96 -0
  76. package/dist/node/commands/bundle/index.js +2 -0
  77. package/dist/node/commands/start/action.js +37 -0
  78. package/dist/node/commands/start/command.js +93 -0
  79. package/dist/node/commands/start/debugger.js +79 -0
  80. package/dist/node/commands/start/index.js +2 -0
  81. package/dist/node/commands/start/setup-interactive-mode.d.ts +20 -0
  82. package/dist/node/commands/start/setup-interactive-mode.js +107 -0
  83. package/dist/node/constants.js +4 -0
  84. package/dist/node/logger.js +5 -0
  85. package/dist/node/types.d.ts +23 -0
  86. package/dist/node/utils.js +23 -0
  87. package/dist/package.js +4 -0
  88. package/dist/runtime.js +1 -1
  89. package/dist/server/bundle.d.ts +12 -0
  90. package/dist/server/bundle.js +55 -0
  91. package/dist/server/bundler-pool.d.ts +51 -0
  92. package/dist/server/bundler-pool.js +197 -0
  93. package/dist/server/common/schema.js +19 -0
  94. package/dist/server/constants.d.ts +6 -0
  95. package/dist/server/constants.js +6 -0
  96. package/dist/server/create-dev-server.d.ts +6 -0
  97. package/dist/server/create-dev-server.js +185 -0
  98. package/dist/server/error.js +9 -0
  99. package/dist/server/events/event-bus.d.ts +12 -0
  100. package/dist/server/events/event-bus.js +16 -0
  101. package/dist/server/events/types.d.ts +37 -0
  102. package/dist/server/events/types.js +6 -0
  103. package/dist/server/index.d.ts +3 -0
  104. package/dist/server/index.js +3 -0
  105. package/dist/server/logger.js +33 -0
  106. package/dist/server/mcp/context.js +14 -0
  107. package/dist/server/mcp/server.js +86 -0
  108. package/dist/server/mcp/tools/app-log-diagnostics.js +37 -0
  109. package/dist/server/mcp/tools/build-diagnostics.js +97 -0
  110. package/dist/server/mcp/tools/build-info.js +33 -0
  111. package/dist/server/mcp/tools/device-diagnostics.js +52 -0
  112. package/dist/server/mcp/tools/index.js +277 -0
  113. package/dist/server/middlewares/request-logger.js +15 -0
  114. package/dist/server/middlewares/serve-assets.js +49 -0
  115. package/dist/server/middlewares/serve-bundle.js +72 -0
  116. package/dist/server/middlewares/sse.js +34 -0
  117. package/dist/server/middlewares/symbolicate.js +71 -0
  118. package/dist/server/sse/adapter.js +74 -0
  119. package/dist/server/sse/event-bus.js +26 -0
  120. package/dist/server/symbolicate.js +93 -0
  121. package/dist/server/types.d.ts +125 -0
  122. package/dist/server/wss/hmr-server.js +209 -0
  123. package/dist/server/wss/server.d.ts +9 -0
  124. package/dist/server/wss/server.js +70 -0
  125. package/dist/{runtime.d.cts → types/hmr.d.ts} +1 -12
  126. package/dist/types.d.ts +78 -0
  127. package/dist/utils/babel.js +11 -0
  128. package/dist/utils/build-options.js +17 -0
  129. package/dist/utils/bundle.js +6 -0
  130. package/dist/utils/config.d.ts +5 -0
  131. package/dist/utils/config.js +32 -0
  132. package/dist/utils/dev-server.js +51 -0
  133. package/dist/utils/env.js +7 -0
  134. package/dist/utils/errors.js +9 -0
  135. package/dist/utils/hash.js +8 -0
  136. package/dist/utils/id.js +28 -0
  137. package/dist/utils/node-resolve.js +42 -0
  138. package/dist/utils/promise.js +15 -0
  139. package/dist/utils/reporters.js +120 -0
  140. package/dist/utils/reset-cache.d.ts +8 -0
  141. package/dist/utils/reset-cache.js +25 -0
  142. package/dist/utils/response.js +91 -0
  143. package/dist/utils/run-build.d.ts +8 -0
  144. package/dist/utils/run-build.js +7 -0
  145. package/dist/utils/run-server.d.ts +6 -0
  146. package/dist/utils/run-server.js +20 -0
  147. package/dist/utils/runtime-target.js +9 -0
  148. package/dist/utils/serialize.js +10 -0
  149. package/dist/utils/server.js +6 -0
  150. package/dist/utils/storage.js +6 -0
  151. package/dist/utils/string.js +6 -0
  152. package/dist/utils/swc.js +10 -0
  153. package/dist/utils/terminal.js +86 -0
  154. package/dist/utils/url.js +23 -0
  155. package/package.json +56 -68
  156. package/dist/commands.cjs +0 -4008
  157. package/dist/commands.d.cts +0 -5
  158. package/dist/pluginutils.d.ts +0 -1
  159. package/dist/pluginutils.js +0 -2
  160. package/dist/runtime.cjs +0 -34
  161. /package/dist/{chunk-DXpK5_cz.js → chunk-DJV587Yu.js} +0 -0
@@ -0,0 +1,21 @@
1
+ import { GLOBAL_IDENTIFIER } from "../constants.js";
2
+ import { indent } from "../utils/string.js";
3
+ import dedent from "dedent";
4
+ //#region src/common/code.ts
5
+ function asLiteral(value) {
6
+ return JSON.stringify(value);
7
+ }
8
+ function nodeEnvironment(dev) {
9
+ return dev ? "development" : "production";
10
+ }
11
+ function iife(body, path = "<unknown>") {
12
+ const bodyPlaceholder = "__BODY__";
13
+ return dedent`
14
+ // ${path}
15
+ (function (global) {
16
+ ${bodyPlaceholder}
17
+ })(${GLOBAL_IDENTIFIER});
18
+ `.replace(bodyPlaceholder, indent(body, 1));
19
+ }
20
+ //#endregion
21
+ export { asLiteral, iife, nodeEnvironment };
@@ -0,0 +1,5 @@
1
+ //#region src/common/constants.ts
2
+ const DEBUG_KEY = "rollipop";
3
+ const SHARED_DATA_PATH = ".rollipop";
4
+ //#endregion
5
+ export { DEBUG_KEY, SHARED_DATA_PATH };
@@ -0,0 +1,33 @@
1
+ import "./constants.js";
2
+ //#region src/common/env.ts
3
+ const TRUTHY_VALUES = [
4
+ "yes",
5
+ "on",
6
+ "true",
7
+ "enabled"
8
+ ];
9
+ const FALSY_VALUES = [
10
+ "no",
11
+ "off",
12
+ "false",
13
+ "disabled"
14
+ ];
15
+ function parseDebugKeys() {
16
+ return Object.keys(process.env).filter((key) => /^debug_/i.test(key)).reduce((acc, key) => {
17
+ const prop = key.slice(6).toLowerCase().replace(/_([a-z])/g, (_, key) => key.toUpperCase());
18
+ let value = process.env[key];
19
+ const lowerCase = typeof value === "string" ? value.toLowerCase() : value.toString();
20
+ if (TRUTHY_VALUES.includes(lowerCase)) value = true;
21
+ else if (FALSY_VALUES.includes(lowerCase)) value = false;
22
+ else value = Boolean(Number(value));
23
+ acc[prop] = value;
24
+ return acc;
25
+ }, {});
26
+ }
27
+ let debugKeys = null;
28
+ function isDebugEnabled() {
29
+ if (debugKeys == null) debugKeys = parseDebugKeys();
30
+ return debugKeys["rollipop"] ?? false;
31
+ }
32
+ //#endregion
33
+ export { isDebugEnabled };
@@ -0,0 +1,34 @@
1
+ import { ChalkInstance } from "chalk";
2
+
3
+ //#region src/common/logger.d.ts
4
+ declare class Logger {
5
+ private readonly scope?;
6
+ private static blocked;
7
+ private static queuedMessages;
8
+ static Colors: {
9
+ trace: ChalkInstance;
10
+ debug: ChalkInstance;
11
+ log: ChalkInstance;
12
+ info: ChalkInstance;
13
+ warn: ChalkInstance;
14
+ error: ChalkInstance;
15
+ };
16
+ private format;
17
+ private debugEnabled;
18
+ static block(): void;
19
+ static unblock(flush?: boolean): void;
20
+ constructor(scope?: string | undefined);
21
+ getFormat(): string;
22
+ setFormat(format: string): void;
23
+ private getTimestamp;
24
+ private print;
25
+ trace(...args: unknown[]): void;
26
+ debug(...args: unknown[]): void;
27
+ log(...args: unknown[]): void;
28
+ info(...args: unknown[]): void;
29
+ warn(...args: unknown[]): void;
30
+ error(...args: unknown[]): void;
31
+ child(scope: string): Logger;
32
+ }
33
+ //#endregion
34
+ export { Logger };
@@ -0,0 +1,82 @@
1
+ import { isDebugEnabled } from "./env.js";
2
+ import { invariant } from "es-toolkit";
3
+ import chalk from "chalk";
4
+ import dayjs from "dayjs";
5
+ //#region src/common/logger.ts
6
+ var Logger = class Logger {
7
+ scope;
8
+ static blocked = false;
9
+ static queuedMessages = [];
10
+ static Colors = {
11
+ trace: chalk.gray,
12
+ debug: chalk.blue,
13
+ log: chalk.green,
14
+ info: chalk.cyan,
15
+ warn: chalk.yellow,
16
+ error: chalk.red
17
+ };
18
+ format = "HH:mm:ss.SSS";
19
+ debugEnabled;
20
+ static block() {
21
+ this.blocked = true;
22
+ }
23
+ static unblock(flush = true) {
24
+ this.blocked = false;
25
+ if (flush) for (const args of Logger.queuedMessages) console.log(...args);
26
+ Logger.queuedMessages.length = 0;
27
+ }
28
+ constructor(scope) {
29
+ this.scope = scope;
30
+ this.debugEnabled = isDebugEnabled();
31
+ }
32
+ getFormat() {
33
+ return this.format;
34
+ }
35
+ setFormat(format) {
36
+ this.format = format;
37
+ }
38
+ getTimestamp() {
39
+ return dayjs().format(this.getFormat());
40
+ }
41
+ print(logLevel, ...args) {
42
+ const timestamp = chalk.gray(this.getTimestamp());
43
+ const level = Logger.Colors[logLevel](logLevel);
44
+ if (this.scope) args = [
45
+ timestamp,
46
+ level,
47
+ chalk.magenta(this.scope),
48
+ ...args
49
+ ];
50
+ else args = [
51
+ timestamp,
52
+ level,
53
+ ...args
54
+ ];
55
+ if (Logger.blocked) Logger.queuedMessages.push(args);
56
+ else console.log(...args);
57
+ }
58
+ trace(...args) {
59
+ this.debugEnabled && this.print("trace", ...args);
60
+ }
61
+ debug(...args) {
62
+ this.debugEnabled && this.print("debug", ...args);
63
+ }
64
+ log(...args) {
65
+ this.print("log", ...args);
66
+ }
67
+ info(...args) {
68
+ this.print("info", ...args);
69
+ }
70
+ warn(...args) {
71
+ this.print("warn", ...args);
72
+ }
73
+ error(...args) {
74
+ this.print("error", ...args);
75
+ }
76
+ child(scope) {
77
+ invariant(this.scope, "Logger must have a scope to create a child logger");
78
+ return new Logger(`${this.scope}:${scope}`);
79
+ }
80
+ };
81
+ //#endregion
82
+ export { Logger };
@@ -0,0 +1,54 @@
1
+ import chalk from "chalk";
2
+ import gradient from "gradient-string";
3
+ //#region src/common/logo.ts
4
+ const CANDY = `
5
+ _....._
6
+ .' _..._ '.
7
+ / /\` __ \`\\ \\
8
+ ; ; /\` \\ | ;
9
+ | | | (_/ ; |
10
+ ; ; \\_ _.' .;
11
+ \\ '. \`\` _.'/
12
+ '._\`"'"\`_.'`;
13
+ const STICK = `
14
+ / /\`\`
15
+ / /
16
+ /__/`;
17
+ const DESCRIPTIONS = [
18
+ "Rollipop",
19
+ "Modern build toolkit for React Native",
20
+ "Powered by Rolldown"
21
+ ];
22
+ const PRIMARY_COLOR = "#42A5F5";
23
+ const BASE_GRADIENT_COLORS = [PRIMARY_COLOR, "#BBDEFB"];
24
+ const PADDING = 20;
25
+ function printLogo() {
26
+ let maxLogoWidth = 0;
27
+ const padding = " ".repeat(PADDING);
28
+ const gradientColors = [...BASE_GRADIENT_COLORS];
29
+ const styledCandy = CANDY.split("\n").map((line) => {
30
+ maxLogoWidth = Math.max(line.length, maxLogoWidth);
31
+ return gradient(gradientColors.reverse())(line);
32
+ }).join("\n") + STICK;
33
+ console.log(styledCandy.split("\n").map((line) => padding + line).join("\n"));
34
+ console.log("");
35
+ DESCRIPTIONS.forEach((description, index) => {
36
+ const descriptionHalfLength = description.length / 2;
37
+ const logoHalfWidth = maxLogoWidth / 2;
38
+ const padding = " ".repeat(PADDING - descriptionHalfLength + logoHalfWidth);
39
+ if (index === 0) console.log(padding + chalk.bold.hex(PRIMARY_COLOR)(description));
40
+ else console.log(padding + description);
41
+ });
42
+ console.log("");
43
+ }
44
+ let _printed = false;
45
+ const Logo = {
46
+ print: printLogo,
47
+ printOnce: () => {
48
+ if (_printed) return;
49
+ _printed = true;
50
+ printLogo();
51
+ }
52
+ };
53
+ //#endregion
54
+ export { Logo };
@@ -0,0 +1,167 @@
1
+ import { StreamManager, ellipsisLeft } from "../utils/terminal.js";
2
+ import { range, throttle } from "es-toolkit";
3
+ import chalk from "chalk";
4
+ //#region src/common/progress-bar.ts
5
+ const BAR_LENGTH = 25;
6
+ const BLOCK_CHAR = "█";
7
+ const idleRenderer = { render(_state, context) {
8
+ return ` ${chalk.gray("Waiting...")} ${chalk.gray(context.label)}\n`;
9
+ } };
10
+ const runningRenderer = { render(state, context) {
11
+ const { label, current, total, columns } = context;
12
+ const unknownTotal = total === 0;
13
+ const progress = unknownTotal ? 0 : current / total * 100;
14
+ const width = unknownTotal ? 0 : progress * (BAR_LENGTH / 100);
15
+ const bg = chalk.white(BLOCK_CHAR);
16
+ const fg = chalk.cyan(BLOCK_CHAR);
17
+ const bar = range(BAR_LENGTH).map((n) => n < width ? fg : bg).join("");
18
+ const progressLabel = unknownTotal ? chalk.gray("(calculating...)") : `(${progress.toFixed(2)}%)`;
19
+ const moduleCountLabel = unknownTotal ? `${current} modules` : `${current}/${total} modules`;
20
+ return `${[
21
+ chalk.cyan("●"),
22
+ bar,
23
+ progressLabel,
24
+ chalk.gray(moduleCountLabel),
25
+ chalk.gray(label)
26
+ ].join(" ")}\n${state.moduleId ? " " + chalk.grey(ellipsisLeft(state.moduleId, columns - 10)) : ""}`;
27
+ } };
28
+ const completedRenderer = { render(state, context) {
29
+ if (state.hasErrors) return `${chalk.red("✘")} Build failed ${chalk.gray(context.label)}`;
30
+ else {
31
+ const icon = chalk.green("✔");
32
+ const durationInSeconds = (state.duration / 1e3).toFixed(2);
33
+ return `${`${icon} Build completed ${chalk.gray(context.label)}`}\n${chalk.grey(` Built in ${durationInSeconds}s (${context.current}/${context.total} modules)`)}`;
34
+ }
35
+ } };
36
+ const hmrCompletedRenderer = { render(state, context) {
37
+ const icon = chalk.green("✔");
38
+ const count = chalk.yellow(`(x${state.count})`);
39
+ const moduleId = chalk.gray(ellipsisLeft(state.moduleId, context.columns - 4));
40
+ return `${icon} HMR Updated ${chalk.gray(context.label)} ${count}\n ${moduleId}`;
41
+ } };
42
+ var ProgressBarRenderer = class {
43
+ renderers = {
44
+ idle: idleRenderer,
45
+ running: runningRenderer,
46
+ completed: completedRenderer,
47
+ "hmr-completed": hmrCompletedRenderer
48
+ };
49
+ render(state, context) {
50
+ return this.renderers[state.type].render(state, context);
51
+ }
52
+ };
53
+ var ProgressBar = class {
54
+ columns = (process.stderr.columns || 80) - 2;
55
+ renderer;
56
+ label;
57
+ state = { type: "idle" };
58
+ current = 0;
59
+ total;
60
+ stale = false;
61
+ constructor(options) {
62
+ this.total = options.total;
63
+ this.label = options.label;
64
+ this.renderer = options.renderer ?? new ProgressBarRenderer();
65
+ }
66
+ get done() {
67
+ return this.state.type === "completed" || this.state.type === "hmr-completed";
68
+ }
69
+ setCurrent(current) {
70
+ this.current = current;
71
+ this.stale = true;
72
+ return this;
73
+ }
74
+ setTotal(total) {
75
+ this.total = total;
76
+ this.stale = true;
77
+ return this;
78
+ }
79
+ start() {
80
+ this.state = { type: "running" };
81
+ this.stale = true;
82
+ return this;
83
+ }
84
+ setModuleId(moduleId) {
85
+ if (this.state.type !== "running") return this;
86
+ this.state = {
87
+ type: "running",
88
+ moduleId
89
+ };
90
+ this.stale = true;
91
+ return this;
92
+ }
93
+ complete(duration, hasErrors = false) {
94
+ this.state = {
95
+ type: "completed",
96
+ duration,
97
+ hasErrors
98
+ };
99
+ this.stale = true;
100
+ return this;
101
+ }
102
+ completeHmr(moduleId, count) {
103
+ this.state = {
104
+ type: "hmr-completed",
105
+ count,
106
+ moduleId
107
+ };
108
+ this.stale = true;
109
+ return this;
110
+ }
111
+ render() {
112
+ this.stale = false;
113
+ const context = {
114
+ label: this.label,
115
+ current: this.current,
116
+ total: this.total,
117
+ columns: this.columns
118
+ };
119
+ return this.renderer.render(this.state, context);
120
+ }
121
+ };
122
+ var ProgressBarRenderManager = class ProgressBarRenderManager {
123
+ static instance = null;
124
+ streamManager = new StreamManager();
125
+ progressBars = /* @__PURE__ */ new Map();
126
+ throttledRender;
127
+ static getInstance() {
128
+ if (!ProgressBarRenderManager.instance) ProgressBarRenderManager.instance = new ProgressBarRenderManager();
129
+ return ProgressBarRenderManager.instance;
130
+ }
131
+ constructor() {
132
+ this.throttledRender = throttle(this._render.bind(this), 50);
133
+ }
134
+ _render() {
135
+ const renderedLines = Array.from(this.progressBars.values().filter((progressBar) => progressBar.stale).map((progressBar) => progressBar.render()));
136
+ if (renderedLines.length > 0) this.streamManager.render(renderedLines.join("\n\n"));
137
+ }
138
+ register(key, options) {
139
+ const progressBar = this.progressBars.get(key);
140
+ if (progressBar == null) {
141
+ const newProgressBar = new ProgressBar(options);
142
+ this.progressBars.set(key, newProgressBar);
143
+ return newProgressBar;
144
+ }
145
+ return progressBar;
146
+ }
147
+ start() {
148
+ console.log();
149
+ this.streamManager.listen();
150
+ this._render();
151
+ }
152
+ render() {
153
+ this.throttledRender();
154
+ }
155
+ release() {
156
+ if (this.progressBars.values().every((progressBar) => progressBar.done)) {
157
+ this._render();
158
+ this.streamManager.done();
159
+ console.log();
160
+ }
161
+ }
162
+ clear() {
163
+ this.streamManager.clear();
164
+ }
165
+ };
166
+ //#endregion
167
+ export { ProgressBarRenderManager };
@@ -0,0 +1,13 @@
1
+ import transform from "fast-flow-transform";
2
+ //#region src/common/transformer.ts
3
+ async function stripFlowTypes(id, code) {
4
+ return await transform({
5
+ filename: id,
6
+ source: code,
7
+ sourcemap: true,
8
+ dialect: "flow",
9
+ format: "pretty"
10
+ });
11
+ }
12
+ //#endregion
13
+ export { stripFlowTypes };
@@ -0,0 +1,10 @@
1
+ //#region src/common/types.d.ts
2
+ interface FileStorageData {
3
+ build: {
4
+ [buildHash: string]: {
5
+ totalModules: number;
6
+ };
7
+ };
8
+ }
9
+ //#endregion
10
+ export { FileStorageData };
@@ -0,0 +1,18 @@
1
+ import { merge } from "es-toolkit";
2
+ //#region src/config/compose-override.ts
3
+ async function applyOverrideRolldownOptions(override, rolldownOptions) {
4
+ if (typeof override === "function") return await override(rolldownOptions);
5
+ return {
6
+ input: merge(rolldownOptions.input ?? {}, override.input ?? {}),
7
+ output: merge(rolldownOptions.output ?? {}, override.output ?? {})
8
+ };
9
+ }
10
+ function composeOverrideRolldownOptions(target, source) {
11
+ if (source == null) return target;
12
+ if (target == null) return source;
13
+ return async (rolldownOptions) => {
14
+ return await applyOverrideRolldownOptions(source, await applyOverrideRolldownOptions(target, rolldownOptions));
15
+ };
16
+ }
17
+ //#endregion
18
+ export { applyOverrideRolldownOptions, composeOverrideRolldownOptions };
@@ -0,0 +1,74 @@
1
+ import { Reporter } from "../types.js";
2
+ import { Config, DevModeConfig, OptimizationConfig, ReactNativeConfig } from "./types.js";
3
+ import { PluginFlattenConfig } from "./merge-config.js";
4
+
5
+ //#region src/config/defaults.d.ts
6
+ declare function getDefaultConfig(projectRoot: string, mode?: Config['mode']): Promise<{
7
+ root: string;
8
+ mode: "development" | "production";
9
+ entry: string;
10
+ resolver: {
11
+ sourceExtensions: string[];
12
+ assetExtensions: string[];
13
+ mainFields: string[];
14
+ aliasFields: string[][];
15
+ conditionNames: string[];
16
+ preferNativePlatform: true;
17
+ symlinks: true;
18
+ };
19
+ transformer: {
20
+ flow: {
21
+ filter: {
22
+ id: RegExp;
23
+ code: RegExp;
24
+ };
25
+ };
26
+ };
27
+ serializer: {
28
+ prelude: string[];
29
+ polyfills: {
30
+ type: "iife";
31
+ code: string;
32
+ }[];
33
+ };
34
+ watcher: {
35
+ skipWrite: true;
36
+ useDebounce: true;
37
+ debounceDuration: number;
38
+ };
39
+ optimization: {
40
+ treeshake: NonNullable<OptimizationConfig["treeshake"]>;
41
+ };
42
+ reactNative: {
43
+ reactNativePath: string;
44
+ codegen: {
45
+ /**
46
+ * @see {@link https://github.com/facebook/react-native/blob/v0.83.1/packages/react-native-babel-preset/src/configs/main.js#L78}
47
+ */
48
+ filter: {
49
+ code: RegExp;
50
+ };
51
+ };
52
+ assetRegistryPath: NonNullable<NonNullable<ReactNativeConfig>["assetRegistryPath"]>;
53
+ hmrClientPath: NonNullable<NonNullable<ReactNativeConfig>["hmrClientPath"]>;
54
+ globalIdentifiers: string[];
55
+ };
56
+ devMode: {
57
+ hmr: NonNullable<DevModeConfig["hmr"]>;
58
+ };
59
+ reporter: Reporter;
60
+ terminal: {
61
+ status: "none" | "compat" | "progress" | undefined;
62
+ };
63
+ envDir: string;
64
+ envFile: string;
65
+ envPrefix: string;
66
+ runtimeTarget: "hermes-v1";
67
+ experimental: {
68
+ nativeTransformPipeline: boolean;
69
+ };
70
+ }>;
71
+ type DefaultConfig = Awaited<ReturnType<typeof getDefaultConfig>>;
72
+ type ResolvedConfig = DefaultConfig & PluginFlattenConfig;
73
+ //#endregion
74
+ export { DefaultConfig, ResolvedConfig, getDefaultConfig };
@@ -0,0 +1,74 @@
1
+ import { isDebugEnabled } from "../common/env.js";
2
+ import { stripFlowTypes } from "../common/transformer.js";
3
+ import { DEFAULT_ASSET_EXTENSIONS, DEFAULT_ASSET_REGISTRY_PATH, DEFAULT_ENV_FILE, DEFAULT_ENV_PREFIX, DEFAULT_HMR_CLIENT_PATH, DEFAULT_REACT_NATIVE_GLOBAL_IDENTIFIERS, DEFAULT_RESOLVER_ALIAS_FIELDS, DEFAULT_RESOLVER_CONDITION_NAMES, DEFAULT_RESOLVER_MAIN_FIELDS, DEFAULT_RUNTIME_TARGET, DEFAULT_SOURCE_EXTENSIONS } from "../constants.js";
4
+ import { getInitializeCorePath, getPolyfillScriptPaths } from "../internal/react-native.js";
5
+ import { resolvePackagePath } from "../utils/node-resolve.js";
6
+ import { ClientLogReporter } from "../utils/reporters.js";
7
+ import fs from "node:fs";
8
+ //#region src/config/defaults.ts
9
+ async function getDefaultConfig(projectRoot, mode) {
10
+ let reactNativePath;
11
+ try {
12
+ reactNativePath = process.env.ROLLIPOP_REACT_NATIVE_PATH ?? resolvePackagePath(projectRoot, "react-native");
13
+ } catch {
14
+ throw new Error(`Could not resolve 'react-native' package path. Please check your project path.`);
15
+ }
16
+ return {
17
+ root: projectRoot,
18
+ mode: mode ?? "development",
19
+ entry: "index.js",
20
+ resolver: {
21
+ sourceExtensions: DEFAULT_SOURCE_EXTENSIONS,
22
+ assetExtensions: DEFAULT_ASSET_EXTENSIONS,
23
+ mainFields: DEFAULT_RESOLVER_MAIN_FIELDS,
24
+ aliasFields: DEFAULT_RESOLVER_ALIAS_FIELDS,
25
+ conditionNames: DEFAULT_RESOLVER_CONDITION_NAMES,
26
+ preferNativePlatform: true,
27
+ symlinks: true
28
+ },
29
+ transformer: { flow: { filter: {
30
+ id: /\.jsx?$/,
31
+ code: /@flow/
32
+ } } },
33
+ serializer: {
34
+ prelude: [getInitializeCorePath(projectRoot)],
35
+ polyfills: await Promise.all(getPolyfillScriptPaths(reactNativePath).map(async (path) => {
36
+ return {
37
+ type: "iife",
38
+ code: (await stripFlowTypes(path, fs.readFileSync(path, "utf-8"))).code
39
+ };
40
+ }))
41
+ },
42
+ watcher: {
43
+ skipWrite: true,
44
+ useDebounce: true,
45
+ debounceDuration: 50
46
+ },
47
+ optimization: { treeshake: true },
48
+ reactNative: {
49
+ reactNativePath,
50
+ codegen: {
51
+ /**
52
+ * @see {@link https://github.com/facebook/react-native/blob/v0.83.1/packages/react-native-babel-preset/src/configs/main.js#L78}
53
+ */
54
+ filter: { code: /\bcodegenNativeComponent</ } },
55
+ assetRegistryPath: DEFAULT_ASSET_REGISTRY_PATH,
56
+ hmrClientPath: DEFAULT_HMR_CLIENT_PATH,
57
+ globalIdentifiers: DEFAULT_REACT_NATIVE_GLOBAL_IDENTIFIERS
58
+ },
59
+ devMode: { hmr: true },
60
+ reporter: new ClientLogReporter(),
61
+ terminal: { status: (() => {
62
+ if (isDebugEnabled()) return "compat";
63
+ if (process.stderr.isTTY) return "progress";
64
+ return "compat";
65
+ })() },
66
+ envDir: projectRoot,
67
+ envFile: DEFAULT_ENV_FILE,
68
+ envPrefix: DEFAULT_ENV_PREFIX,
69
+ runtimeTarget: DEFAULT_RUNTIME_TARGET,
70
+ experimental: { nativeTransformPipeline: false }
71
+ };
72
+ }
73
+ //#endregion
74
+ export { getDefaultConfig };
@@ -0,0 +1,13 @@
1
+ import { Config } from "./types.js";
2
+ import { DefaultConfig } from "./defaults.js";
3
+
4
+ //#region src/config/define-config.d.ts
5
+ interface DefineConfigContext {
6
+ command?: string;
7
+ defaultConfig: DefaultConfig;
8
+ }
9
+ type UserConfig = Config | DynamicUserConfig;
10
+ type DynamicUserConfig = ((context: DefineConfigContext) => Config) | ((context: DefineConfigContext) => Promise<Config>);
11
+ declare function defineConfig(userConfig: UserConfig): UserConfig;
12
+ //#endregion
13
+ export { DefineConfigContext, DynamicUserConfig, UserConfig, defineConfig };
@@ -0,0 +1,6 @@
1
+ //#region src/config/define-config.ts
2
+ function defineConfig(userConfig) {
3
+ return userConfig;
4
+ }
5
+ //#endregion
6
+ export { defineConfig };
@@ -0,0 +1,5 @@
1
+ import { BabelTransformConfig, CodegenConfig, Config, DevModeConfig, ExperimentalConfig, FlowConfig, HmrConfig, OptimizationConfig, PluginOption, Polyfill, PolyfillType, PolyfillWithCode, PolyfillWithPath, ReactNativeConfig, ResolverConfig, RolldownConfig, RollipopReactNativeFlowConfig, RollipopReactNativeWorkletsConfig, SerializerConfig, SwcTransformConfig, TerminalConfig, TransformRule, TransformerConfig, WatcherConfig } from "./types.js";
2
+ import { PluginFlattenConfig, mergeConfig } from "./merge-config.js";
3
+ import { DefaultConfig, ResolvedConfig, getDefaultConfig } from "./defaults.js";
4
+ import { DefineConfigContext, DynamicUserConfig, UserConfig, defineConfig } from "./define-config.js";
5
+ import { LoadConfigOptions, flattenPluginOption, invokeConfigResolved, loadConfig, resolvePluginConfig } from "./load-config.js";
@@ -0,0 +1,5 @@
1
+ import "./defaults.js";
2
+ import "./define-config.js";
3
+ import "./merge-config.js";
4
+ import "./load-config.js";
5
+ export {};
@@ -0,0 +1,19 @@
1
+ import { Plugin, PluginConfig, ResolvedPluginConfig } from "../core/plugins/types.js";
2
+ import { Config, PluginOption } from "./types.js";
3
+ import { ResolvedConfig } from "./defaults.js";
4
+ import { DefineConfigContext } from "./define-config.js";
5
+
6
+ //#region src/config/load-config.d.ts
7
+ interface LoadConfigOptions {
8
+ cwd?: string;
9
+ configFile?: string;
10
+ mode?: Config['mode'];
11
+ context?: Omit<DefineConfigContext, 'defaultConfig'>;
12
+ }
13
+ declare function loadConfig(options?: LoadConfigOptions): Promise<ResolvedConfig>;
14
+ declare function flattenPluginOption(pluginOption: PluginOption): Promise<Plugin[]>;
15
+ declare function resolvePluginConfig(baseConfig: ResolvedConfig, plugins: Plugin[]): Promise<ResolvedPluginConfig>;
16
+ declare function resolvePluginConfig(baseConfig: Config, plugins: Plugin[]): Promise<PluginConfig>;
17
+ declare function invokeConfigResolved(config: ResolvedConfig, plugins: Plugin[]): Promise<void>;
18
+ //#endregion
19
+ export { LoadConfigOptions, flattenPluginOption, invokeConfigResolved, loadConfig, resolvePluginConfig };