@rollipop/core 0.1.0-alpha.0 → 0.1.0-alpha.2

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/dist/index.d.ts CHANGED
@@ -1,7 +1,12 @@
1
- import { FileStorage } from "@rollipop/common";
1
+ import { FileStorage, Logger } from "@rollipop/common";
2
2
  import * as rolldown from "rolldown";
3
+ import { RollupLogWithString } from "rolldown";
3
4
  import * as rolldown_experimental0 from "rolldown/experimental";
4
5
  import { DevOptions, DevWatchOptions, TransformOptions } from "rolldown/experimental";
6
+ import { FastifyInstance } from "fastify";
7
+ import EventEmitter from "node:events";
8
+ import * as ws from "ws";
9
+ import "@fastify/middie";
5
10
 
6
11
  //#region src/types.d.ts
7
12
  interface Reporter {
@@ -35,34 +40,307 @@ type MetroCompatibleClientLogEvent = {
35
40
  data: any[];
36
41
  };
37
42
  //#endregion
43
+ //#region src/config/define-config.d.ts
44
+ interface DefineConfigContext {
45
+ command?: string;
46
+ defaultConfig: DefaultConfig;
47
+ }
48
+ type UserConfig = Config | DynamicConfig;
49
+ type DynamicConfig = ((context: DefineConfigContext) => Config) | ((context: DefineConfigContext) => Promise<Config>);
50
+ declare function defineConfig(userConfig: UserConfig): UserConfig;
51
+ //#endregion
52
+ //#region src/config/load-config.d.ts
53
+ interface LoadConfigOptions {
54
+ cwd?: string;
55
+ configFile?: string;
56
+ context?: Omit<DefineConfigContext, 'defaultConfig'>;
57
+ }
58
+ declare function loadConfig(options?: LoadConfigOptions): Promise<ResolvedConfig>;
59
+ declare function resolvePluginConfig(baseConfig: Config, plugins: Plugin[]): Promise<Config>;
60
+ declare function invokeConfigResolved(config: ResolvedConfig, plugins: Plugin[]): Promise<void>;
61
+ //#endregion
62
+ //#region src/config/merge-config.d.ts
63
+ declare function mergeConfig(baseConfig: Config, ...overrideConfigs: Config[]): Config;
64
+ declare function mergeConfig(baseConfig: DefaultConfig, ...overrideConfigs: Config[]): ResolvedConfig;
65
+ //#endregion
66
+ //#region src/server/wss/server.d.ts
67
+ type BufferLike = Parameters<ws.WebSocket['send']>[0];
68
+ type WebSocketClient = ws.WebSocket & {
69
+ id: number;
70
+ };
71
+ //#endregion
72
+ //#region src/server/types.d.ts
73
+ interface ServerOptions {
74
+ port?: number;
75
+ host?: string;
76
+ https?: boolean;
77
+ key?: string;
78
+ cert?: string;
79
+ onDeviceConnected?: (client: WebSocketClient) => void;
80
+ onDeviceMessage?: (client: WebSocketClient, data: ws.RawData) => void;
81
+ onDeviceConnectionError?: (client: WebSocketClient, error: Error) => void;
82
+ onDeviceDisconnected?: (client: WebSocketClient) => void;
83
+ }
84
+ interface Middlewares {
85
+ /**
86
+ * Register a middleware to the Fastify instance.
87
+ *
88
+ * **NOTE**: This is a wrapper of `instance.use`.
89
+ */
90
+ use: FastifyInstance['use'];
91
+ }
92
+ interface DevServer {
93
+ /**
94
+ * Resolved Rollipop config.
95
+ */
96
+ config: ResolvedConfig;
97
+ /**
98
+ * The Fastify instance.
99
+ */
100
+ instance: FastifyInstance;
101
+ /**
102
+ * `express` and `connect` style middleware registration API.
103
+ */
104
+ middlewares: Middlewares;
105
+ /**
106
+ * The message websocket server API.
107
+ */
108
+ message: ws.Server & {
109
+ /**
110
+ * Broadcast a message to all connected devices.
111
+ */
112
+ broadcast: (method: string, params?: Record<string, any>) => void;
113
+ };
114
+ /**
115
+ * The events websocket server API.
116
+ */
117
+ events: ws.Server & {
118
+ /**
119
+ * Report an event to the reporter.
120
+ */
121
+ reportEvent: (event: {
122
+ type: string;
123
+ [key: string]: unknown;
124
+ }) => void;
125
+ };
126
+ /**
127
+ * HMR websocket server API
128
+ */
129
+ hot: ws.Server & {
130
+ send: (client: ws.WebSocket, data: BufferLike) => void;
131
+ sendAll: (data: BufferLike) => void;
132
+ };
133
+ }
134
+ interface BundleDetails {
135
+ bundleType: string;
136
+ dev: boolean;
137
+ entryFile: string;
138
+ minify: boolean;
139
+ platform?: string;
140
+ }
141
+ interface FormattedError {
142
+ type: string;
143
+ message: string;
144
+ errors: {
145
+ description: string;
146
+ }[];
147
+ }
148
+ //#endregion
149
+ //#region src/server/create-dev-server.d.ts
150
+ declare function createDevServer(config: ResolvedConfig, options?: ServerOptions): Promise<DevServer>;
151
+ //#endregion
152
+ //#region src/server/constants.d.ts
153
+ declare const DEFAULT_PORT = 8081;
154
+ declare const DEFAULT_HOST = "localhost";
155
+ //#endregion
156
+ //#region src/core/cache/cache.d.ts
157
+ interface Cache<Key$1, Input, Output = Input> {
158
+ get(key: Key$1): Output | null | undefined;
159
+ set(key: Key$1, value: Input): void;
160
+ clear(): void;
161
+ }
162
+ //#endregion
163
+ //#region src/core/cache/file-system-cache.d.ts
164
+ type Key = string;
165
+ declare class FileSystemCache implements Cache<Key, string> {
166
+ private readonly cacheDirectory;
167
+ constructor(cacheDirectory: string);
168
+ private ensureCacheDirectory;
169
+ get(key: Key): string | undefined;
170
+ set(key: Key, value: string): void;
171
+ clear(): void;
172
+ }
173
+ //#endregion
174
+ //#region src/core/types.d.ts
175
+ interface BuildOptions {
176
+ /**
177
+ * The platform to build for.
178
+ */
179
+ platform: string;
180
+ /**
181
+ * Whether to build in development mode.
182
+ *
183
+ * Defaults to `true`.
184
+ */
185
+ dev?: boolean;
186
+ /**
187
+ * Whether to minify the bundle.
188
+ *
189
+ * Defaults to `false`.
190
+ */
191
+ minify?: boolean;
192
+ /**
193
+ * Enable or disable the cache.
194
+ *
195
+ * Defaults to `true`.
196
+ */
197
+ cache?: boolean;
198
+ /**
199
+ * The output file.
200
+ */
201
+ outfile?: string;
202
+ /**
203
+ * The sourcemap file.
204
+ */
205
+ sourcemap?: string;
206
+ /**
207
+ * The assets directory.
208
+ */
209
+ assetsDir?: string;
210
+ }
211
+ type DevEngineOptions = DevOptions & {
212
+ /**
213
+ * The host to run the dev server on.
214
+ */
215
+ host: string;
216
+ /**
217
+ * The port to run the dev server on.
218
+ */
219
+ port: number;
220
+ };
221
+ interface BundlerContext {
222
+ id: string;
223
+ cache: FileSystemCache;
224
+ storage: FileStorage;
225
+ mode: BuildMode;
226
+ }
227
+ type BuildMode = 'build' | 'serve';
228
+ type AsyncResult<T> = T | Promise<T>;
229
+ //#endregion
230
+ //#region src/core/plugins/context.d.ts
231
+ interface PluginContext {
232
+ debug: (log: RollupLogWithString) => void;
233
+ info: (log: RollupLogWithString) => void;
234
+ warn: (log: RollupLogWithString) => void;
235
+ }
236
+ //#endregion
237
+ //#region src/core/plugins/types.d.ts
238
+ type PluginConfig = Omit<Config, 'plugins' | 'dangerously_overrideRolldownOptions'>;
239
+ type Plugin = rolldown.Plugin & {
240
+ config?: PluginConfig | ((this: PluginContext, config: PluginConfig) => AsyncResult<PluginConfig | null | void>);
241
+ configResolved?: (this: PluginContext, config: ResolvedConfig) => AsyncResult<void>;
242
+ configureServer?: (this: PluginContext, server: DevServer) => AsyncResult<void | (() => AsyncResult<void>)>;
243
+ };
244
+ //#endregion
38
245
  //#region src/config/types.d.ts
39
246
  interface Config {
247
+ /**
248
+ * Defaults to current working directory.
249
+ */
40
250
  root?: string;
251
+ /**
252
+ * Defaults to: `index.js`
253
+ */
41
254
  entry?: string;
255
+ /**
256
+ * Resolver configuration.
257
+ */
42
258
  resolver?: ResolverConfig;
259
+ /**
260
+ * Transformer configuration.
261
+ */
43
262
  transformer?: TransformerConfig;
263
+ /**
264
+ * Serializer configuration.
265
+ */
44
266
  serializer?: SerializerConfig;
267
+ /**
268
+ * Watcher configuration.
269
+ */
45
270
  watcher?: WatcherConfig;
271
+ /**
272
+ * React Native specific configuration.
273
+ */
46
274
  reactNative?: ReactNativeConfig;
275
+ /**
276
+ * Terminal configuration.
277
+ */
47
278
  terminal?: TerminalConfig;
279
+ /**
280
+ * Reporter configuration.
281
+ */
48
282
  reporter?: Reporter;
49
- plugins?: rolldown.Plugin[];
283
+ /**
284
+ * Plugins.
285
+ */
286
+ plugins?: Plugin[];
287
+ /**
288
+ * Rollipop provides default options for Rolldown, but you can override them by this option.
289
+ *
290
+ * **DANGEROUS**: This option is dangerous because it can break the build.
291
+ */
50
292
  dangerously_overrideRolldownOptions?: RolldownConfig | ((config: RolldownConfig) => RolldownConfig) | ((config: RolldownConfig) => Promise<RolldownConfig>);
51
293
  }
52
294
  type ResolverConfig = Omit<NonNullable<rolldown.InputOptions['resolve']>, 'extensions'> & {
295
+ /**
296
+ * Defaults to: `['ts', 'tsx', 'js', 'jsx', 'mjs', 'cjs', 'json']`
297
+ */
53
298
  sourceExtensions?: string[];
299
+ /**
300
+ * Defaults to: `['bmp', 'gif', 'jpg', 'jpeg', 'png', 'webp', 'avif', 'ico', 'icns', 'icxl', 'webp']`
301
+ */
54
302
  assetExtensions?: string[];
303
+ /**
304
+ * If `true`, resolver will resolve `native` suffixed files.
305
+ *
306
+ * e.g.
307
+ * - **true**: `index.android` -> `index.native` -> `index`
308
+ * - **false**: `index.android` -> `index`
309
+ *
310
+ * Defaults to: `true`
311
+ */
55
312
  preferNativePlatform?: boolean;
56
313
  };
57
- type TransformerConfig = Omit<TransformOptions, 'plugins'> & {
314
+ type TransformerConfig = Omit<TransformOptions, 'cwd' | 'plugins'> & {
315
+ /**
316
+ * Transform SVG assets files to React components using `@svgr/core`.
317
+ *
318
+ * Defaults to: `true`
319
+ */
58
320
  svg?: boolean;
321
+ /**
322
+ * Flow specific configuration.
323
+ */
59
324
  flow?: FlowConfig;
60
325
  };
61
326
  interface FlowConfig {
327
+ /**
328
+ * Filter for Flow transformation pipeline.
329
+ */
62
330
  filter?: rolldown.HookFilter;
63
331
  }
64
332
  interface SerializerConfig {
333
+ /**
334
+ * Paths to prelude files.
335
+ *
336
+ * Prelude files are imported in the top of the entry module.
337
+ */
65
338
  prelude?: string[];
339
+ /**
340
+ * Polyfills to include in the output bundle.
341
+ *
342
+ * Polyfills are injected in the top of the output bundle.
343
+ */
66
344
  polyfills?: Polyfill[];
67
345
  }
68
346
  type Polyfill = string | PolyfillWithCode | PolyfillWithPath;
@@ -77,13 +355,29 @@ type PolyfillWithPath = {
77
355
  type PolyfillType = 'plain' | 'iife';
78
356
  type WatcherConfig = DevWatchOptions;
79
357
  interface ReactNativeConfig {
358
+ /**
359
+ * Codegen specific configuration.
360
+ */
80
361
  codegen?: CodegenConfig;
362
+ /**
363
+ * Path to asset registry file.
364
+ *
365
+ * Defaults to: `react-native/Libraries/Image/AssetRegistry.js`
366
+ */
81
367
  assetRegistryPath?: string;
82
368
  }
83
369
  interface CodegenConfig {
370
+ /**
371
+ * Filter for codegen transformation pipeline.
372
+ */
84
373
  filter?: rolldown.HookFilter;
85
374
  }
86
375
  interface TerminalConfig {
376
+ /**
377
+ * Status of the terminal.
378
+ *
379
+ * Defaults to: `process.stderr.isTTY ? 'progress' : 'compat'`
380
+ */
87
381
  status?: 'compat' | 'progress';
88
382
  }
89
383
  interface RolldownConfig {
@@ -91,17 +385,8 @@ interface RolldownConfig {
91
385
  output?: rolldown.OutputOptions;
92
386
  }
93
387
  //#endregion
94
- //#region src/config/define-config.d.ts
95
- interface DefineConfigContext {
96
- command?: string;
97
- defaultConfig: DefaultConfig;
98
- }
99
- type UserConfig = Config | DynamicConfig;
100
- type DynamicConfig = ((context: DefineConfigContext) => Config) | ((context: DefineConfigContext) => Promise<Config>);
101
- declare function defineConfig(userConfig: UserConfig): UserConfig;
102
- //#endregion
103
388
  //#region src/config/defaults.d.ts
104
- declare function getDefaultConfig(basePath: string, context: Omit<DefineConfigContext, 'defaultConfig'>): {
389
+ declare function getDefaultConfig(basePath: string): {
105
390
  root: string;
106
391
  entry: string;
107
392
  resolver: {
@@ -122,10 +407,10 @@ declare function getDefaultConfig(basePath: string, context: Omit<DefineConfigCo
122
407
  };
123
408
  serializer: {
124
409
  prelude: string[];
125
- polyfills: (string | {
410
+ polyfills: {
126
411
  type: "iife";
127
412
  code: string;
128
- })[];
413
+ }[];
129
414
  };
130
415
  watcher: {
131
416
  skipWrite: true;
@@ -148,45 +433,6 @@ declare function getDefaultConfig(basePath: string, context: Omit<DefineConfigCo
148
433
  type DefaultConfig = ReturnType<typeof getDefaultConfig>;
149
434
  type ResolvedConfig = Config & DefaultConfig;
150
435
  //#endregion
151
- //#region src/core/cache/cache.d.ts
152
- interface Cache<Key$1, Input, Output = Input> {
153
- get(key: Key$1): Output | null | undefined;
154
- set(key: Key$1, value: Input): void;
155
- clear(): void;
156
- }
157
- //#endregion
158
- //#region src/core/cache/file-system-cache.d.ts
159
- type Key = string;
160
- declare class FileSystemCache implements Cache<Key, string> {
161
- private readonly cacheDirectory;
162
- constructor(cacheDirectory: string);
163
- private ensureCacheDirectory;
164
- get(key: Key): string | undefined;
165
- set(key: Key, value: string): void;
166
- clear(): void;
167
- }
168
- //#endregion
169
- //#region src/core/types.d.ts
170
- interface BuildOptions {
171
- platform: string;
172
- dev?: boolean;
173
- minify?: boolean;
174
- cache?: boolean;
175
- outfile?: string;
176
- assetsDir?: string;
177
- }
178
- type DevEngineOptions = DevOptions & {
179
- host: string;
180
- port: number;
181
- };
182
- interface BundlerContext {
183
- id: string;
184
- cache: FileSystemCache;
185
- storage: FileStorage;
186
- mode: BuildMode;
187
- }
188
- type BuildMode = 'build' | 'serve';
189
- //#endregion
190
436
  //#region src/core/bundler.d.ts
191
437
  declare class Bundler {
192
438
  private readonly config;
@@ -197,17 +443,6 @@ declare class Bundler {
197
443
  build(buildOptions: BuildOptions): Promise<rolldown.OutputChunk>;
198
444
  }
199
445
  //#endregion
200
- //#region src/config/load-config.d.ts
201
- interface LoadConfigOptions {
202
- cwd?: string;
203
- configFile?: string;
204
- context?: Omit<DefineConfigContext, 'defaultConfig'>;
205
- }
206
- declare function loadConfig(options?: LoadConfigOptions): Promise<ResolvedConfig>;
207
- //#endregion
208
- //#region src/config/merge-config.d.ts
209
- declare function mergeConfig(baseConfig: DefaultConfig, overrideConfig: Config): ResolvedConfig;
210
- //#endregion
211
446
  //#region src/core/plugins/react-native-plugin.d.ts
212
447
  interface ReactNativePluginOptions {
213
448
  platform: string;
@@ -226,7 +461,7 @@ interface ReactRefreshPluginOptions {
226
461
  include?: RegExp | string;
227
462
  exclude?: RegExp | string;
228
463
  }
229
- declare function reactRefreshPlugin(options?: ReactRefreshPluginOptions): rolldown.Plugin;
464
+ declare function reactRefreshPlugin(options?: ReactRefreshPluginOptions): rolldown.Plugin[];
230
465
  interface ApplyRefreshWrapperOptions {
231
466
  id: string;
232
467
  hasRefresh: boolean;
@@ -400,6 +635,11 @@ type HMRServerMessage = {
400
635
  type: 'hmr:error';
401
636
  payload: HMRServerError;
402
637
  };
638
+ type HMRCustomServerMessage = {
639
+ type: string;
640
+ payload: unknown;
641
+ };
642
+ type HMRCustomHandler = (message: HMRCustomServerMessage) => void;
403
643
  interface HMRServerError {
404
644
  type: string;
405
645
  message: string;
@@ -414,4 +654,4 @@ declare class TerminalReporter implements Reporter {
414
654
  update(event: ReportableEvent): void;
415
655
  }
416
656
  //#endregion
417
- export { assets_d_exports as AssetUtils, BuildMode, BuildOptions, Bundler, BundlerContext, CodegenConfig, Config, DefaultConfig, TerminalReporter as DefaultReporter, DefineConfigContext, DevEngineOptions, DynamicConfig, FlowConfig, HMRClientLogLevel, HMRClientMessage, HMRServerError, HMRServerMessage, LoadConfigOptions, PluginUtils, Polyfill, PolyfillType, PolyfillWithCode, PolyfillWithPath, ReactNativeConfig, ReportableEvent, Reporter, ResolvedConfig, ResolverConfig, RolldownConfig, SerializerConfig, TerminalConfig, TransformerConfig, UserConfig, WatcherConfig, defineConfig, getDefaultConfig, loadConfig, mergeConfig, index_d_exports as plugins, rolldown, rolldown_experimental0 as rolldownExperimental };
657
+ export { assets_d_exports as AssetUtils, AsyncResult, BuildMode, BuildOptions, BundleDetails, Bundler, BundlerContext, CodegenConfig, Config, DEFAULT_HOST, DEFAULT_PORT, DefaultConfig, TerminalReporter as DefaultReporter, DefineConfigContext, DevEngineOptions, DevServer, DynamicConfig, FlowConfig, FormattedError, HMRClientLogLevel, HMRClientMessage, HMRCustomHandler, HMRCustomServerMessage, HMRServerError, HMRServerMessage, LoadConfigOptions, Middlewares, type Plugin, type PluginConfig, PluginUtils, Polyfill, PolyfillType, PolyfillWithCode, PolyfillWithPath, ReactNativeConfig, ReportableEvent, Reporter, ResolvedConfig, ResolverConfig, RolldownConfig, SerializerConfig, ServerOptions, TerminalConfig, TransformerConfig, UserConfig, WatcherConfig, createDevServer, defineConfig, getDefaultConfig, invokeConfigResolved, loadConfig, mergeConfig, index_d_exports as plugins, resolvePluginConfig, rolldown, rolldown_experimental0 as rolldownExperimental };