@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.cts CHANGED
@@ -1,6 +1,9 @@
1
1
  import * as rolldown_experimental0 from "rolldown/experimental";
2
2
  import { DevOptions, DevWatchOptions, TransformOptions } from "rolldown/experimental";
3
3
  import * as rolldown from "rolldown";
4
+ import { RollupLogWithString } from "rolldown";
5
+ import { FastifyInstance } from "fastify";
6
+ import * as ws from "ws";
4
7
  import { FileStorage } from "@rollipop/common";
5
8
 
6
9
  //#region rolldown:runtime
@@ -37,34 +40,307 @@ type MetroCompatibleClientLogEvent = {
37
40
  data: any[];
38
41
  };
39
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
40
245
  //#region src/config/types.d.ts
41
246
  interface Config {
247
+ /**
248
+ * Defaults to current working directory.
249
+ */
42
250
  root?: string;
251
+ /**
252
+ * Defaults to: `index.js`
253
+ */
43
254
  entry?: string;
255
+ /**
256
+ * Resolver configuration.
257
+ */
44
258
  resolver?: ResolverConfig;
259
+ /**
260
+ * Transformer configuration.
261
+ */
45
262
  transformer?: TransformerConfig;
263
+ /**
264
+ * Serializer configuration.
265
+ */
46
266
  serializer?: SerializerConfig;
267
+ /**
268
+ * Watcher configuration.
269
+ */
47
270
  watcher?: WatcherConfig;
271
+ /**
272
+ * React Native specific configuration.
273
+ */
48
274
  reactNative?: ReactNativeConfig;
275
+ /**
276
+ * Terminal configuration.
277
+ */
49
278
  terminal?: TerminalConfig;
279
+ /**
280
+ * Reporter configuration.
281
+ */
50
282
  reporter?: Reporter;
51
- 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
+ */
52
292
  dangerously_overrideRolldownOptions?: RolldownConfig | ((config: RolldownConfig) => RolldownConfig) | ((config: RolldownConfig) => Promise<RolldownConfig>);
53
293
  }
54
294
  type ResolverConfig = Omit<NonNullable<rolldown.InputOptions['resolve']>, 'extensions'> & {
295
+ /**
296
+ * Defaults to: `['ts', 'tsx', 'js', 'jsx', 'mjs', 'cjs', 'json']`
297
+ */
55
298
  sourceExtensions?: string[];
299
+ /**
300
+ * Defaults to: `['bmp', 'gif', 'jpg', 'jpeg', 'png', 'webp', 'avif', 'ico', 'icns', 'icxl', 'webp']`
301
+ */
56
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
+ */
57
312
  preferNativePlatform?: boolean;
58
313
  };
59
- 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
+ */
60
320
  svg?: boolean;
321
+ /**
322
+ * Flow specific configuration.
323
+ */
61
324
  flow?: FlowConfig;
62
325
  };
63
326
  interface FlowConfig {
327
+ /**
328
+ * Filter for Flow transformation pipeline.
329
+ */
64
330
  filter?: rolldown.HookFilter;
65
331
  }
66
332
  interface SerializerConfig {
333
+ /**
334
+ * Paths to prelude files.
335
+ *
336
+ * Prelude files are imported in the top of the entry module.
337
+ */
67
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
+ */
68
344
  polyfills?: Polyfill[];
69
345
  }
70
346
  type Polyfill = string | PolyfillWithCode | PolyfillWithPath;
@@ -79,13 +355,29 @@ type PolyfillWithPath = {
79
355
  type PolyfillType = 'plain' | 'iife';
80
356
  type WatcherConfig = DevWatchOptions;
81
357
  interface ReactNativeConfig {
358
+ /**
359
+ * Codegen specific configuration.
360
+ */
82
361
  codegen?: CodegenConfig;
362
+ /**
363
+ * Path to asset registry file.
364
+ *
365
+ * Defaults to: `react-native/Libraries/Image/AssetRegistry.js`
366
+ */
83
367
  assetRegistryPath?: string;
84
368
  }
85
369
  interface CodegenConfig {
370
+ /**
371
+ * Filter for codegen transformation pipeline.
372
+ */
86
373
  filter?: rolldown.HookFilter;
87
374
  }
88
375
  interface TerminalConfig {
376
+ /**
377
+ * Status of the terminal.
378
+ *
379
+ * Defaults to: `process.stderr.isTTY ? 'progress' : 'compat'`
380
+ */
89
381
  status?: 'compat' | 'progress';
90
382
  }
91
383
  interface RolldownConfig {
@@ -93,17 +385,8 @@ interface RolldownConfig {
93
385
  output?: rolldown.OutputOptions;
94
386
  }
95
387
  //#endregion
96
- //#region src/config/define-config.d.ts
97
- interface DefineConfigContext {
98
- command?: string;
99
- defaultConfig: DefaultConfig;
100
- }
101
- type UserConfig = Config | DynamicConfig;
102
- type DynamicConfig = ((context: DefineConfigContext) => Config) | ((context: DefineConfigContext) => Promise<Config>);
103
- declare function defineConfig(userConfig: UserConfig): UserConfig;
104
- //#endregion
105
388
  //#region src/config/defaults.d.ts
106
- declare function getDefaultConfig(basePath: string, context: Omit<DefineConfigContext, 'defaultConfig'>): {
389
+ declare function getDefaultConfig(basePath: string): {
107
390
  root: string;
108
391
  entry: string;
109
392
  resolver: {
@@ -124,10 +407,10 @@ declare function getDefaultConfig(basePath: string, context: Omit<DefineConfigCo
124
407
  };
125
408
  serializer: {
126
409
  prelude: string[];
127
- polyfills: (string | {
410
+ polyfills: {
128
411
  type: "iife";
129
412
  code: string;
130
- })[];
413
+ }[];
131
414
  };
132
415
  watcher: {
133
416
  skipWrite: true;
@@ -150,45 +433,6 @@ declare function getDefaultConfig(basePath: string, context: Omit<DefineConfigCo
150
433
  type DefaultConfig = ReturnType<typeof getDefaultConfig>;
151
434
  type ResolvedConfig = Config & DefaultConfig;
152
435
  //#endregion
153
- //#region src/core/cache/cache.d.ts
154
- interface Cache<Key$1, Input, Output = Input> {
155
- get(key: Key$1): Output | null | undefined;
156
- set(key: Key$1, value: Input): void;
157
- clear(): void;
158
- }
159
- //#endregion
160
- //#region src/core/cache/file-system-cache.d.ts
161
- type Key = string;
162
- declare class FileSystemCache implements Cache<Key, string> {
163
- private readonly cacheDirectory;
164
- constructor(cacheDirectory: string);
165
- private ensureCacheDirectory;
166
- get(key: Key): string | undefined;
167
- set(key: Key, value: string): void;
168
- clear(): void;
169
- }
170
- //#endregion
171
- //#region src/core/types.d.ts
172
- interface BuildOptions {
173
- platform: string;
174
- dev?: boolean;
175
- minify?: boolean;
176
- cache?: boolean;
177
- outfile?: string;
178
- assetsDir?: string;
179
- }
180
- type DevEngineOptions = DevOptions & {
181
- host: string;
182
- port: number;
183
- };
184
- interface BundlerContext {
185
- id: string;
186
- cache: FileSystemCache;
187
- storage: FileStorage;
188
- mode: BuildMode;
189
- }
190
- type BuildMode = 'build' | 'serve';
191
- //#endregion
192
436
  //#region src/core/bundler.d.ts
193
437
  declare class Bundler {
194
438
  private readonly config;
@@ -199,17 +443,6 @@ declare class Bundler {
199
443
  build(buildOptions: BuildOptions): Promise<rolldown.OutputChunk>;
200
444
  }
201
445
  //#endregion
202
- //#region src/config/load-config.d.ts
203
- interface LoadConfigOptions {
204
- cwd?: string;
205
- configFile?: string;
206
- context?: Omit<DefineConfigContext, 'defaultConfig'>;
207
- }
208
- declare function loadConfig(options?: LoadConfigOptions): Promise<ResolvedConfig>;
209
- //#endregion
210
- //#region src/config/merge-config.d.ts
211
- declare function mergeConfig(baseConfig: DefaultConfig, overrideConfig: Config): ResolvedConfig;
212
- //#endregion
213
446
  //#region src/core/plugins/react-native-plugin.d.ts
214
447
  interface ReactNativePluginOptions {
215
448
  platform: string;
@@ -228,7 +461,7 @@ interface ReactRefreshPluginOptions {
228
461
  include?: RegExp | string;
229
462
  exclude?: RegExp | string;
230
463
  }
231
- declare function reactRefreshPlugin(options?: ReactRefreshPluginOptions): rolldown.Plugin;
464
+ declare function reactRefreshPlugin(options?: ReactRefreshPluginOptions): rolldown.Plugin[];
232
465
  interface ApplyRefreshWrapperOptions {
233
466
  id: string;
234
467
  hasRefresh: boolean;
@@ -402,6 +635,11 @@ type HMRServerMessage = {
402
635
  type: 'hmr:error';
403
636
  payload: HMRServerError;
404
637
  };
638
+ type HMRCustomServerMessage = {
639
+ type: string;
640
+ payload: unknown;
641
+ };
642
+ type HMRCustomHandler = (message: HMRCustomServerMessage) => void;
405
643
  interface HMRServerError {
406
644
  type: string;
407
645
  message: string;
@@ -416,4 +654,4 @@ declare class TerminalReporter implements Reporter {
416
654
  update(event: ReportableEvent): void;
417
655
  }
418
656
  //#endregion
419
- 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 };