@rollipop/core 0.0.0 → 0.1.0-alpha.0
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 +12 -0
- package/README.md +1 -1
- package/dist/chunk-BYW8Mqxw.js +21 -0
- package/dist/hmr-client.cjs +212 -0
- package/dist/hmr-runtime.js +158 -0
- package/dist/hmr-shims.js +10 -0
- package/dist/index.cjs +1700 -0
- package/dist/index.d.cts +419 -0
- package/dist/index.d.ts +417 -0
- package/dist/index.js +1619 -0
- package/package.json +78 -2
- package/.editorconfig +0 -10
- package/.gitattributes +0 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { FileStorage } from "@rollipop/common";
|
|
2
|
+
import * as rolldown from "rolldown";
|
|
3
|
+
import * as rolldown_experimental0 from "rolldown/experimental";
|
|
4
|
+
import { DevOptions, DevWatchOptions, TransformOptions } from "rolldown/experimental";
|
|
5
|
+
|
|
6
|
+
//#region src/types.d.ts
|
|
7
|
+
interface Reporter {
|
|
8
|
+
update(event: ReportableEvent): void;
|
|
9
|
+
}
|
|
10
|
+
type ReportableEvent = {
|
|
11
|
+
type: 'bundle_build_started';
|
|
12
|
+
} | {
|
|
13
|
+
type: 'bundle_build_done';
|
|
14
|
+
} | {
|
|
15
|
+
type: 'bundle_build_failed';
|
|
16
|
+
error: Error;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'transform';
|
|
19
|
+
id: string;
|
|
20
|
+
totalModules: number | undefined;
|
|
21
|
+
transformedModules: number;
|
|
22
|
+
} | {
|
|
23
|
+
type: 'watch_change';
|
|
24
|
+
id: string;
|
|
25
|
+
} | MetroCompatibleClientLogEvent;
|
|
26
|
+
type MetroCompatibleClientLogEvent = {
|
|
27
|
+
type: 'client_log';
|
|
28
|
+
level: 'trace' | 'info' | 'warn' | 'log' | 'group' | 'groupCollapsed' | 'groupEnd' | 'debug'
|
|
29
|
+
/**
|
|
30
|
+
* In react-native, ReportableEvent['level'] does not defined `error` type.
|
|
31
|
+
* But, Flipper supports the `error` type.
|
|
32
|
+
*
|
|
33
|
+
* @see https://github.com/facebook/flipper/blob/v0.273.0/desktop/flipper-common/src/server-types.tsx#L74
|
|
34
|
+
*/ | 'error';
|
|
35
|
+
data: any[];
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/config/types.d.ts
|
|
39
|
+
interface Config {
|
|
40
|
+
root?: string;
|
|
41
|
+
entry?: string;
|
|
42
|
+
resolver?: ResolverConfig;
|
|
43
|
+
transformer?: TransformerConfig;
|
|
44
|
+
serializer?: SerializerConfig;
|
|
45
|
+
watcher?: WatcherConfig;
|
|
46
|
+
reactNative?: ReactNativeConfig;
|
|
47
|
+
terminal?: TerminalConfig;
|
|
48
|
+
reporter?: Reporter;
|
|
49
|
+
plugins?: rolldown.Plugin[];
|
|
50
|
+
dangerously_overrideRolldownOptions?: RolldownConfig | ((config: RolldownConfig) => RolldownConfig) | ((config: RolldownConfig) => Promise<RolldownConfig>);
|
|
51
|
+
}
|
|
52
|
+
type ResolverConfig = Omit<NonNullable<rolldown.InputOptions['resolve']>, 'extensions'> & {
|
|
53
|
+
sourceExtensions?: string[];
|
|
54
|
+
assetExtensions?: string[];
|
|
55
|
+
preferNativePlatform?: boolean;
|
|
56
|
+
};
|
|
57
|
+
type TransformerConfig = Omit<TransformOptions, 'plugins'> & {
|
|
58
|
+
svg?: boolean;
|
|
59
|
+
flow?: FlowConfig;
|
|
60
|
+
};
|
|
61
|
+
interface FlowConfig {
|
|
62
|
+
filter?: rolldown.HookFilter;
|
|
63
|
+
}
|
|
64
|
+
interface SerializerConfig {
|
|
65
|
+
prelude?: string[];
|
|
66
|
+
polyfills?: Polyfill[];
|
|
67
|
+
}
|
|
68
|
+
type Polyfill = string | PolyfillWithCode | PolyfillWithPath;
|
|
69
|
+
type PolyfillWithCode = {
|
|
70
|
+
type: PolyfillType;
|
|
71
|
+
code: string;
|
|
72
|
+
};
|
|
73
|
+
type PolyfillWithPath = {
|
|
74
|
+
type: PolyfillType;
|
|
75
|
+
path: string;
|
|
76
|
+
};
|
|
77
|
+
type PolyfillType = 'plain' | 'iife';
|
|
78
|
+
type WatcherConfig = DevWatchOptions;
|
|
79
|
+
interface ReactNativeConfig {
|
|
80
|
+
codegen?: CodegenConfig;
|
|
81
|
+
assetRegistryPath?: string;
|
|
82
|
+
}
|
|
83
|
+
interface CodegenConfig {
|
|
84
|
+
filter?: rolldown.HookFilter;
|
|
85
|
+
}
|
|
86
|
+
interface TerminalConfig {
|
|
87
|
+
status?: 'compat' | 'progress';
|
|
88
|
+
}
|
|
89
|
+
interface RolldownConfig {
|
|
90
|
+
input?: rolldown.InputOptions;
|
|
91
|
+
output?: rolldown.OutputOptions;
|
|
92
|
+
}
|
|
93
|
+
//#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
|
+
//#region src/config/defaults.d.ts
|
|
104
|
+
declare function getDefaultConfig(basePath: string, context: Omit<DefineConfigContext, 'defaultConfig'>): {
|
|
105
|
+
root: string;
|
|
106
|
+
entry: string;
|
|
107
|
+
resolver: {
|
|
108
|
+
sourceExtensions: string[];
|
|
109
|
+
assetExtensions: string[];
|
|
110
|
+
mainFields: string[];
|
|
111
|
+
conditionNames: string[];
|
|
112
|
+
preferNativePlatform: true;
|
|
113
|
+
};
|
|
114
|
+
transformer: {
|
|
115
|
+
svg: true;
|
|
116
|
+
flow: {
|
|
117
|
+
filter: {
|
|
118
|
+
id: RegExp;
|
|
119
|
+
code: RegExp;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
serializer: {
|
|
124
|
+
prelude: string[];
|
|
125
|
+
polyfills: (string | {
|
|
126
|
+
type: "iife";
|
|
127
|
+
code: string;
|
|
128
|
+
})[];
|
|
129
|
+
};
|
|
130
|
+
watcher: {
|
|
131
|
+
skipWrite: true;
|
|
132
|
+
useDebounce: true;
|
|
133
|
+
debounceDuration: number;
|
|
134
|
+
};
|
|
135
|
+
reactNative: {
|
|
136
|
+
codegen: {
|
|
137
|
+
filter: {
|
|
138
|
+
code: RegExp;
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
assetRegistryPath: string;
|
|
142
|
+
};
|
|
143
|
+
terminal: {
|
|
144
|
+
status: "progress" | "compat";
|
|
145
|
+
};
|
|
146
|
+
reporter: Reporter;
|
|
147
|
+
};
|
|
148
|
+
type DefaultConfig = ReturnType<typeof getDefaultConfig>;
|
|
149
|
+
type ResolvedConfig = Config & DefaultConfig;
|
|
150
|
+
//#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
|
+
//#region src/core/bundler.d.ts
|
|
191
|
+
declare class Bundler {
|
|
192
|
+
private readonly config;
|
|
193
|
+
static devEngine(config: ResolvedConfig, buildOptions: Omit<BuildOptions, 'dev' | 'outfile'>, devEngineOptions: DevEngineOptions): Promise<rolldown_experimental0.DevEngine>;
|
|
194
|
+
static createId(config: ResolvedConfig, buildOptions: BuildOptions): string;
|
|
195
|
+
private static createContext;
|
|
196
|
+
constructor(config: ResolvedConfig);
|
|
197
|
+
build(buildOptions: BuildOptions): Promise<rolldown.OutputChunk>;
|
|
198
|
+
}
|
|
199
|
+
//#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
|
+
//#region src/core/plugins/react-native-plugin.d.ts
|
|
212
|
+
interface ReactNativePluginOptions {
|
|
213
|
+
platform: string;
|
|
214
|
+
dev: boolean;
|
|
215
|
+
mode: BuildMode;
|
|
216
|
+
flowFilter: rolldown.HookFilter;
|
|
217
|
+
codegenFilter: rolldown.HookFilter;
|
|
218
|
+
assetsDir?: string;
|
|
219
|
+
assetExtensions: string[];
|
|
220
|
+
assetRegistryPath: string;
|
|
221
|
+
}
|
|
222
|
+
declare function reactNativePlugin(config: ResolvedConfig, options: ReactNativePluginOptions): rolldown.Plugin[];
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/core/plugins/react-refresh-plugin.d.ts
|
|
225
|
+
interface ReactRefreshPluginOptions {
|
|
226
|
+
include?: RegExp | string;
|
|
227
|
+
exclude?: RegExp | string;
|
|
228
|
+
}
|
|
229
|
+
declare function reactRefreshPlugin(options?: ReactRefreshPluginOptions): rolldown.Plugin;
|
|
230
|
+
interface ApplyRefreshWrapperOptions {
|
|
231
|
+
id: string;
|
|
232
|
+
hasRefresh: boolean;
|
|
233
|
+
onlyReactComponent: boolean;
|
|
234
|
+
}
|
|
235
|
+
declare function applyRefreshWrapper(s: rolldown.BindingMagicString, options: ApplyRefreshWrapperOptions): void;
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/core/plugins/prelude-plugin.d.ts
|
|
238
|
+
interface PreludePluginOptions {
|
|
239
|
+
modulePaths: string[];
|
|
240
|
+
}
|
|
241
|
+
declare function preludePlugin(options: PreludePluginOptions): rolldown.Plugin;
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region src/core/plugins/status-plugin.d.ts
|
|
244
|
+
interface StatusPluginOptions {
|
|
245
|
+
initialTotalModules?: number;
|
|
246
|
+
onStart?: () => void;
|
|
247
|
+
onEnd?: (result: StatusPluginEndResult) => void;
|
|
248
|
+
onResolve?: (id: string) => void;
|
|
249
|
+
onTransform?: (result: StatusPluginTransformResult) => void;
|
|
250
|
+
onWatchChange?: (id: string) => void;
|
|
251
|
+
}
|
|
252
|
+
interface StatusPluginTransformResult {
|
|
253
|
+
id: string;
|
|
254
|
+
totalModules: number | undefined;
|
|
255
|
+
transformedModules: number;
|
|
256
|
+
}
|
|
257
|
+
interface StatusPluginEndResult {
|
|
258
|
+
totalModules: number;
|
|
259
|
+
duration: number;
|
|
260
|
+
error: Error | undefined;
|
|
261
|
+
}
|
|
262
|
+
declare function statusPlugin(options?: StatusPluginOptions): rolldown.Plugin;
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/core/plugins/json-plugin.d.ts
|
|
265
|
+
declare function jsonPlugin(): rolldown.Plugin;
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/core/plugins/svg-plugin.d.ts
|
|
268
|
+
interface SvgPluginOptions {
|
|
269
|
+
enabled: boolean;
|
|
270
|
+
}
|
|
271
|
+
declare function svgPlugin(options: SvgPluginOptions): rolldown.Plugin;
|
|
272
|
+
declare namespace index_d_exports {
|
|
273
|
+
export { PreludePluginOptions, ReactNativePluginOptions, ReactRefreshPluginOptions, StatusPluginEndResult, StatusPluginOptions, StatusPluginTransformResult, SvgPluginOptions, applyRefreshWrapper, jsonPlugin as json, preludePlugin as prelude, reactNativePlugin as reactNative, reactRefreshPlugin as reactRefresh, statusPlugin as status, svgPlugin as svg };
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/core/plugins/utils/index.d.ts
|
|
277
|
+
/**
|
|
278
|
+
* Enhance a plugin to cache the result. (transform hook only)
|
|
279
|
+
*/
|
|
280
|
+
declare function cacheable(plugin: rolldown.Plugin): rolldown.Plugin<any>;
|
|
281
|
+
declare const PluginUtils: Readonly<{
|
|
282
|
+
cacheable: typeof cacheable;
|
|
283
|
+
}>;
|
|
284
|
+
declare namespace assets_d_exports {
|
|
285
|
+
export { AssetContext, AssetData, AssetDataFiltered, AssetDataWithoutFiles, AssetInfo, AssetScale, copyAssetsToDestination, getAssetPriority, getSuffixedPath, platformSuffixPattern, resolveAssetPath, resolveScaledAssets, stripSuffix };
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* **NOTE**: Type definitions are ported from `metro` implementation.
|
|
289
|
+
*
|
|
290
|
+
* @see https://github.com/facebook/metro/blob/0.81.x/packages/metro/src/Assets.js
|
|
291
|
+
*/
|
|
292
|
+
interface AssetContext {
|
|
293
|
+
platform: string;
|
|
294
|
+
preferNativePlatform: boolean;
|
|
295
|
+
}
|
|
296
|
+
interface AssetInfo {
|
|
297
|
+
files: string[];
|
|
298
|
+
hash: string;
|
|
299
|
+
name: string;
|
|
300
|
+
scales: number[];
|
|
301
|
+
type: string;
|
|
302
|
+
}
|
|
303
|
+
interface AssetDataWithoutFiles {
|
|
304
|
+
__packager_asset: boolean;
|
|
305
|
+
fileSystemLocation: string;
|
|
306
|
+
hash: string;
|
|
307
|
+
httpServerLocation: string;
|
|
308
|
+
name: string;
|
|
309
|
+
scales: AssetScale[];
|
|
310
|
+
type: string;
|
|
311
|
+
width?: number;
|
|
312
|
+
height?: number;
|
|
313
|
+
}
|
|
314
|
+
interface AssetDataFiltered {
|
|
315
|
+
__packager_asset: boolean;
|
|
316
|
+
hash: string;
|
|
317
|
+
httpServerLocation: string;
|
|
318
|
+
name: string;
|
|
319
|
+
scales: AssetScale[];
|
|
320
|
+
type: string;
|
|
321
|
+
width?: number;
|
|
322
|
+
height?: number;
|
|
323
|
+
}
|
|
324
|
+
interface AssetData extends AssetDataWithoutFiles {
|
|
325
|
+
id: string;
|
|
326
|
+
files: string[];
|
|
327
|
+
}
|
|
328
|
+
type AssetScale = 0.75 | 1 | 1.5 | 2 | 3;
|
|
329
|
+
interface ResolveScaledAssetsOptions {
|
|
330
|
+
projectRoot: string;
|
|
331
|
+
assetPath: string;
|
|
332
|
+
platform: string;
|
|
333
|
+
preferNativePlatform: boolean;
|
|
334
|
+
}
|
|
335
|
+
declare function resolveScaledAssets(options: ResolveScaledAssetsOptions): Promise<AssetData>;
|
|
336
|
+
declare function platformSuffixPattern(context: AssetContext): string;
|
|
337
|
+
declare function stripSuffix(assetPath: string, context: AssetContext): string;
|
|
338
|
+
declare function getAssetPriority(assetPath: string, context: AssetContext): 0 | 3 | 2 | 1;
|
|
339
|
+
interface GetSuffixedPathOptions {
|
|
340
|
+
scale?: AssetScale;
|
|
341
|
+
platform?: string;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* add suffix to asset path
|
|
345
|
+
*
|
|
346
|
+
* ```js
|
|
347
|
+
* // assetPath input
|
|
348
|
+
* '/path/to/assets/image.png'
|
|
349
|
+
*
|
|
350
|
+
* // `platform` suffixed
|
|
351
|
+
* '/path/to/assets/image.android.png'
|
|
352
|
+
*
|
|
353
|
+
* // `scale` suffixed
|
|
354
|
+
* '/path/to/assets/image@1x.png'
|
|
355
|
+
*
|
|
356
|
+
* // both `platform` and `scale` suffixed
|
|
357
|
+
* '/path/to/assets/image@1x.android.png'
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
360
|
+
declare function getSuffixedPath(assetPath: string, context: AssetContext, options: GetSuffixedPathOptions): string;
|
|
361
|
+
declare function resolveAssetPath(assetPath: string, context: AssetContext, scale: AssetScale): string;
|
|
362
|
+
interface CopyAssetsToDestinationOptions {
|
|
363
|
+
assets: AssetData[];
|
|
364
|
+
assetsDir: string;
|
|
365
|
+
platform: string;
|
|
366
|
+
preferNativePlatform: boolean;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* @see https://github.com/facebook/react-native/blob/0.83-stable/packages/community-cli-plugin/src/commands/bundle/assetPathUtils.js
|
|
370
|
+
*/
|
|
371
|
+
declare function copyAssetsToDestination(options: CopyAssetsToDestinationOptions): Promise<undefined>;
|
|
372
|
+
//#endregion
|
|
373
|
+
//#region src/types/hmr.d.ts
|
|
374
|
+
type HMRClientLogLevel = 'trace' | 'info' | 'warn' | 'error' | 'log' | 'group' | 'groupCollapsed' | 'groupEnd' | 'debug';
|
|
375
|
+
type HMRClientMessage = {
|
|
376
|
+
type: 'hmr:connected';
|
|
377
|
+
bundleEntry: string;
|
|
378
|
+
platform: string;
|
|
379
|
+
} | {
|
|
380
|
+
type: 'hmr:module-registered';
|
|
381
|
+
modules: string[];
|
|
382
|
+
} | {
|
|
383
|
+
type: 'hmr:log';
|
|
384
|
+
level: HMRClientLogLevel;
|
|
385
|
+
data: any[];
|
|
386
|
+
} | {
|
|
387
|
+
type: 'hmr:invalidate';
|
|
388
|
+
moduleId: string;
|
|
389
|
+
};
|
|
390
|
+
type HMRServerMessage = {
|
|
391
|
+
type: 'hmr:update-start';
|
|
392
|
+
} | {
|
|
393
|
+
type: 'hmr:update-done';
|
|
394
|
+
} | {
|
|
395
|
+
type: 'hmr:update';
|
|
396
|
+
code: string;
|
|
397
|
+
} | {
|
|
398
|
+
type: 'hmr:reload';
|
|
399
|
+
} | {
|
|
400
|
+
type: 'hmr:error';
|
|
401
|
+
payload: HMRServerError;
|
|
402
|
+
};
|
|
403
|
+
interface HMRServerError {
|
|
404
|
+
type: string;
|
|
405
|
+
message: string;
|
|
406
|
+
errors: {
|
|
407
|
+
description: string;
|
|
408
|
+
}[];
|
|
409
|
+
}
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region src/reporter.d.ts
|
|
412
|
+
declare class TerminalReporter implements Reporter {
|
|
413
|
+
private logger;
|
|
414
|
+
update(event: ReportableEvent): void;
|
|
415
|
+
}
|
|
416
|
+
//#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 };
|