rollipop 1.0.0-alpha.23 → 1.0.0-alpha.24

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 (48) hide show
  1. package/dist/common/code.js +9 -5
  2. package/dist/common/progress-bar.js +1 -1
  3. package/dist/config/defaults.d.ts +5 -8
  4. package/dist/config/index.d.ts +1 -1
  5. package/dist/config/types.d.ts +6 -3
  6. package/dist/constants.d.ts +3 -2
  7. package/dist/constants.js +7 -6
  8. package/dist/core/bundler.d.ts +2 -1
  9. package/dist/core/bundler.js +1 -1
  10. package/dist/core/fs/data.js +7 -2
  11. package/dist/core/fs/storage.js +2 -2
  12. package/dist/core/plugins/entry-plugin.d.ts +10 -0
  13. package/dist/core/plugins/entry-plugin.js +28 -0
  14. package/dist/core/plugins/index.d.ts +2 -2
  15. package/dist/core/plugins/index.js +2 -2
  16. package/dist/core/rolldown.js +69 -27
  17. package/dist/hmr-runtime.iife.js +8 -8
  18. package/dist/index.d.ts +2 -2
  19. package/dist/internal/react-native.js +6 -5
  20. package/dist/node/cli-utils.js +12 -2
  21. package/dist/node/cli.js +4 -2
  22. package/dist/node/commands/agent/action.js +10 -0
  23. package/dist/node/commands/bundle/action.js +2 -1
  24. package/dist/node/commands/skills/action.js +49 -0
  25. package/dist/node/commands/skills/command.js +16 -0
  26. package/dist/node/types.d.ts +6 -0
  27. package/dist/node/utils.js +2 -2
  28. package/dist/package.js +1 -1
  29. package/dist/runtime.js +2 -2
  30. package/dist/server/bundler-pool.d.ts +3 -1
  31. package/dist/server/bundler-pool.js +28 -4
  32. package/dist/server/mcp/server.js +1 -1
  33. package/dist/utils/build-options.d.ts +16 -0
  34. package/dist/utils/id.js +13 -3
  35. package/dist/utils/storage.js +4 -1
  36. package/dist/utils/transform.js +28 -0
  37. package/package.json +8 -6
  38. package/skills/build.md +31 -0
  39. package/skills/configuration.md +31 -0
  40. package/skills/core.md +31 -0
  41. package/skills/debugging.md +34 -0
  42. package/skills/dev-server.md +35 -0
  43. package/skills/migration.md +31 -0
  44. package/skills/plugins.md +37 -0
  45. package/skills/troubleshooting.md +36 -0
  46. package/CHANGELOG.md +0 -204
  47. package/dist/core/plugins/prelude-plugin.d.ts +0 -10
  48. package/dist/core/plugins/prelude-plugin.js +0 -23
@@ -1,21 +1,25 @@
1
- import { GLOBAL_IDENTIFIER } from "../constants.js";
2
1
  import { indent } from "../utils/string.js";
3
2
  import dedent from "dedent";
4
3
  //#region src/common/code.ts
4
+ const GLOBAL_OBJECT_EXPRESSION = [
5
+ `typeof globalThis !== 'undefined' ? globalThis`,
6
+ ` : typeof global !== 'undefined' ? global`,
7
+ ` : typeof window !== 'undefined' ? window`,
8
+ " : this"
9
+ ].join("");
5
10
  function asLiteral(value) {
6
11
  return JSON.stringify(value);
7
12
  }
8
13
  function nodeEnvironment(dev) {
9
14
  return dev ? "development" : "production";
10
15
  }
11
- function iife(body, path = "<unknown>") {
16
+ function iife(body) {
12
17
  const bodyPlaceholder = "__BODY__";
13
18
  return dedent`
14
- // ${path}
15
19
  (function (global) {
16
20
  ${bodyPlaceholder}
17
- })(${GLOBAL_IDENTIFIER});
18
- `.replace(bodyPlaceholder, indent(body, 1));
21
+ })(${GLOBAL_OBJECT_EXPRESSION});
22
+ `.replace(bodyPlaceholder, indent(body, 1, " ")).trim();
19
23
  }
20
24
  //#endregion
21
25
  export { asLiteral, iife, nodeEnvironment };
@@ -15,7 +15,7 @@ const runningRenderer = { render(state, context) {
15
15
  const bg = chalk.white(BLOCK_CHAR);
16
16
  const fg = chalk.cyan(BLOCK_CHAR);
17
17
  const bar = range(BAR_LENGTH).map((n) => n < width ? fg : bg).join("");
18
- const progressLabel = unknownTotal ? chalk.gray("(calculating...)") : `(${progress.toFixed(2)}%)`;
18
+ const progressLabel = unknownTotal ? "" : `(${progress.toFixed(2)}%)`;
19
19
  const moduleCountLabel = unknownTotal ? `${current} modules` : `${current}/${total} modules`;
20
20
  return `${[
21
21
  chalk.cyan("●"),
@@ -1,5 +1,5 @@
1
1
  import { Reporter } from "../types.js";
2
- import { Config, DevModeConfig, OptimizationConfig, ReactNativeConfig } from "./types.js";
2
+ import { Config, DevModeConfig, OptimizationConfig, Polyfill, ReactNativeConfig } from "./types.js";
3
3
  import { PluginFlattenConfig } from "./merge-config.js";
4
4
 
5
5
  //#region src/config/defaults.d.ts
@@ -26,10 +26,7 @@ declare function getDefaultConfig(projectRoot: string, mode?: Config['mode']): P
26
26
  };
27
27
  serializer: {
28
28
  prelude: string[];
29
- polyfills: {
30
- type: "iife";
31
- code: string;
32
- }[];
29
+ polyfills: Polyfill[];
33
30
  };
34
31
  watcher: {
35
32
  skipWrite: true;
@@ -61,9 +58,9 @@ declare function getDefaultConfig(projectRoot: string, mode?: Config['mode']): P
61
58
  status: "none" | "compat" | "progress" | undefined;
62
59
  };
63
60
  envDir: string;
64
- envFile: string;
65
- envPrefix: string;
66
- runtimeTarget: "hermes-v1";
61
+ envFile: NonNullable<Config["envFile"]>;
62
+ envPrefix: NonNullable<Config["envPrefix"]>;
63
+ runtimeTarget: NonNullable<Config["runtimeTarget"]>;
67
64
  experimental: {
68
65
  nativeTransformPipeline: boolean;
69
66
  };
@@ -1,4 +1,4 @@
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";
1
+ import { BabelTransformConfig, CodegenConfig, Config, DevModeConfig, ExperimentalConfig, FlowConfig, HmrConfig, OptimizationConfig, PluginOption, Polyfill, PolyfillOptions, PolyfillType, PolyfillWithCode, PolyfillWithPath, ReactNativeConfig, ResolverConfig, RolldownConfig, RollipopReactNativeFlowConfig, RollipopReactNativeWorkletsConfig, SerializerConfig, SwcTransformConfig, TerminalConfig, TransformRule, TransformerConfig, WatcherConfig } from "./types.js";
2
2
  import { PluginFlattenConfig, mergeConfig } from "./merge-config.js";
3
3
  import { DefaultConfig, ResolvedConfig, getDefaultConfig } from "./defaults.js";
4
4
  import { DefineConfigContext, DynamicUserConfig, UserConfig, defineConfig } from "./define-config.js";
@@ -327,14 +327,17 @@ interface SerializerConfig {
327
327
  shimMissingExports?: rolldown.InputOptions['shimMissingExports'];
328
328
  }
329
329
  type Polyfill = string | PolyfillWithCode | PolyfillWithPath;
330
+ type PolyfillOptions = {
331
+ withTransform?: boolean;
332
+ };
330
333
  type PolyfillWithCode = {
331
334
  type: PolyfillType;
332
335
  code: string;
333
- };
336
+ } & PolyfillOptions;
334
337
  type PolyfillWithPath = {
335
338
  type: PolyfillType;
336
339
  path: string;
337
- };
340
+ } & PolyfillOptions;
338
341
  type PolyfillType = 'plain' | 'iife';
339
342
  type OptimizationConfig = rolldown.OptimizationOptions & {
340
343
  /**
@@ -449,4 +452,4 @@ interface RolldownConfig {
449
452
  output?: rolldown.OutputOptions;
450
453
  }
451
454
  //#endregion
452
- export { BabelTransformConfig, CodegenConfig, Config, DevModeConfig, ExperimentalConfig, FlowConfig, HmrConfig, OptimizationConfig, PluginOption, Polyfill, PolyfillType, PolyfillWithCode, PolyfillWithPath, ReactNativeConfig, ResolverConfig, RolldownConfig, type RollipopReactNativeFlowConfig, type RollipopReactNativeWorkletsConfig, SerializerConfig, SwcTransformConfig, TerminalConfig, TransformRule, TransformerConfig, WatcherConfig };
455
+ export { BabelTransformConfig, CodegenConfig, Config, DevModeConfig, ExperimentalConfig, FlowConfig, HmrConfig, OptimizationConfig, PluginOption, Polyfill, PolyfillOptions, PolyfillType, PolyfillWithCode, PolyfillWithPath, ReactNativeConfig, ResolverConfig, RolldownConfig, type RollipopReactNativeFlowConfig, type RollipopReactNativeWorkletsConfig, SerializerConfig, SwcTransformConfig, TerminalConfig, TransformRule, TransformerConfig, WatcherConfig };
@@ -1,5 +1,5 @@
1
1
  declare namespace constants_d_exports {
2
- export { DEFAULT_ASSET_EXTENSIONS, DEFAULT_ASSET_REGISTRY_PATH, DEFAULT_ENV_FILE, DEFAULT_ENV_PREFIX, DEFAULT_HMR_CLIENT_PATH, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_REACT_NATIVE_GLOBAL_IDENTIFIERS, DEFAULT_RESOLVER_ALIAS_FIELDS, DEFAULT_RESOLVER_CONDITION_NAMES, DEFAULT_RESOLVER_MAIN_FIELDS, DEFAULT_RUNTIME_TARGET, DEFAULT_SOURCE_EXTENSIONS, GLOBAL_IDENTIFIER, IMAGE_EXTENSIONS, ROLLIPOP_VERSION };
2
+ export { DEFAULT_ASSET_EXTENSIONS, DEFAULT_ASSET_REGISTRY_PATH, DEFAULT_ENV_FILE, DEFAULT_ENV_PREFIX, DEFAULT_HMR_CLIENT_PATH, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_REACT_NATIVE_GLOBAL_IDENTIFIERS, DEFAULT_RESOLVER_ALIAS_FIELDS, DEFAULT_RESOLVER_CONDITION_NAMES, DEFAULT_RESOLVER_MAIN_FIELDS, DEFAULT_RUNTIME_TARGET, DEFAULT_SOURCE_EXTENSIONS, IMAGE_EXTENSIONS, ROLLIPOP_VERSION, ROLLIPOP_VIRTUAL_ENTRY_ID, ROLLIPOP_VIRTUAL_PREFIX };
3
3
  }
4
4
  /**
5
5
  * @see `vite.config.ts`
@@ -8,7 +8,8 @@ declare global {
8
8
  var __ROLLIPOP_VERSION__: string;
9
9
  }
10
10
  declare const ROLLIPOP_VERSION: string;
11
- declare const GLOBAL_IDENTIFIER = "global";
11
+ declare const ROLLIPOP_VIRTUAL_PREFIX = "\0rollipop/";
12
+ declare const ROLLIPOP_VIRTUAL_ENTRY_ID = "\0rollipop/entry";
12
13
  /**
13
14
  * @see {@link https://github.com/facebook/metro/blob/0.81.x/docs/Configuration.md#resolvermainfields}
14
15
  */
package/dist/constants.js CHANGED
@@ -13,12 +13,14 @@ var constants_exports = /* @__PURE__ */ __exportAll({
13
13
  DEFAULT_RESOLVER_MAIN_FIELDS: () => DEFAULT_RESOLVER_MAIN_FIELDS,
14
14
  DEFAULT_RUNTIME_TARGET: () => DEFAULT_RUNTIME_TARGET,
15
15
  DEFAULT_SOURCE_EXTENSIONS: () => DEFAULT_SOURCE_EXTENSIONS,
16
- GLOBAL_IDENTIFIER: () => GLOBAL_IDENTIFIER,
17
16
  IMAGE_EXTENSIONS: () => IMAGE_EXTENSIONS,
18
- ROLLIPOP_VERSION: () => ROLLIPOP_VERSION
17
+ ROLLIPOP_VERSION: () => ROLLIPOP_VERSION,
18
+ ROLLIPOP_VIRTUAL_ENTRY_ID: () => ROLLIPOP_VIRTUAL_ENTRY_ID,
19
+ ROLLIPOP_VIRTUAL_PREFIX: () => ROLLIPOP_VIRTUAL_PREFIX
19
20
  });
20
- const ROLLIPOP_VERSION = "1.0.0-alpha.23";
21
- const GLOBAL_IDENTIFIER = "global";
21
+ const ROLLIPOP_VERSION = "1.0.0-alpha.24";
22
+ const ROLLIPOP_VIRTUAL_PREFIX = "\0rollipop/";
23
+ const ROLLIPOP_VIRTUAL_ENTRY_ID = `${ROLLIPOP_VIRTUAL_PREFIX}entry`;
22
24
  /**
23
25
  * @see {@link https://github.com/facebook/metro/blob/0.81.x/docs/Configuration.md#resolvermainfields}
24
26
  */
@@ -85,7 +87,6 @@ const DEFAULT_ASSET_EXTENSIONS = [
85
87
  const DEFAULT_ASSET_REGISTRY_PATH = "react-native/Libraries/Image/AssetRegistry.js";
86
88
  const DEFAULT_HMR_CLIENT_PATH = "react-native/Libraries/Utilities/HMRClient.js";
87
89
  const DEFAULT_REACT_NATIVE_GLOBAL_IDENTIFIERS = [
88
- GLOBAL_IDENTIFIER,
89
90
  "Promise",
90
91
  "regeneratorRuntime",
91
92
  "XMLHttpRequest",
@@ -143,4 +144,4 @@ const DEFAULT_ENV_PREFIX = "ROLLIPOP_";
143
144
  const DEFAULT_ENV_FILE = ".env";
144
145
  const DEFAULT_RUNTIME_TARGET = "hermes-v1";
145
146
  //#endregion
146
- export { 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, GLOBAL_IDENTIFIER, IMAGE_EXTENSIONS, ROLLIPOP_VERSION, constants_exports };
147
+ export { 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, IMAGE_EXTENSIONS, ROLLIPOP_VERSION, ROLLIPOP_VIRTUAL_ENTRY_ID, ROLLIPOP_VIRTUAL_PREFIX, constants_exports };
@@ -1,4 +1,5 @@
1
1
  import { BuildOptions, DevEngine, DevEngineOptions } from "./types.js";
2
+ import { ResolvedBuildOptions } from "../utils/build-options.js";
2
3
  import { ResolvedConfig } from "../config/defaults.js";
3
4
  import * as rolldown from "@rollipop/rolldown";
4
5
 
@@ -6,7 +7,7 @@ import * as rolldown from "@rollipop/rolldown";
6
7
  declare class Bundler {
7
8
  private readonly config;
8
9
  static devEngine(config: ResolvedConfig, buildOptions: Omit<BuildOptions, 'dev' | 'outfile'>, devEngineOptions: DevEngineOptions): Promise<DevEngine>;
9
- static createId(config: ResolvedConfig, buildOptions: BuildOptions): string;
10
+ static createId(config: ResolvedConfig, buildOptions: ResolvedBuildOptions): string;
10
11
  private static createContext;
11
12
  constructor(config: ResolvedConfig);
12
13
  build(buildOptions: BuildOptions): Promise<rolldown.OutputChunk>;
@@ -29,7 +29,7 @@ var Bundler = class Bundler {
29
29
  return devEngine;
30
30
  }
31
31
  static createId(config, buildOptions) {
32
- return createId(config, buildOptions);
32
+ return createId(config, resolveBuildOptions(config, buildOptions));
33
33
  }
34
34
  static createContext(buildType, config, buildOptions) {
35
35
  return {
@@ -1,9 +1,14 @@
1
1
  import { SHARED_DATA_PATH } from "../../common/constants.js";
2
- import "node:fs";
2
+ import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  //#region src/core/fs/data.ts
5
5
  function getSharedDataPath(basePath) {
6
6
  return path.join(basePath, SHARED_DATA_PATH);
7
7
  }
8
+ function ensureSharedDataPath(basePath) {
9
+ const sharedDataPath = getSharedDataPath(basePath);
10
+ if (!fs.existsSync(sharedDataPath)) fs.mkdirSync(sharedDataPath, { recursive: true });
11
+ return sharedDataPath;
12
+ }
8
13
  //#endregion
9
- export { getSharedDataPath };
14
+ export { ensureSharedDataPath, getSharedDataPath };
@@ -1,4 +1,4 @@
1
- import { getSharedDataPath } from "./data.js";
1
+ import { ensureSharedDataPath } from "./data.js";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { merge } from "es-toolkit";
@@ -15,7 +15,7 @@ var FileStorage = class FileStorage {
15
15
  }
16
16
  constructor(basePath) {
17
17
  this.basePath = basePath;
18
- this.dataFilePath = path.join(getSharedDataPath(basePath), "rollipop.json");
18
+ this.dataFilePath = path.join(ensureSharedDataPath(basePath), "rollipop.json");
19
19
  if (fs.existsSync(this.dataFilePath)) this.data = JSON.parse(fs.readFileSync(this.dataFilePath, "utf-8"));
20
20
  else this.data = DEFAULT_DATA;
21
21
  }
@@ -0,0 +1,10 @@
1
+ import * as rolldown from "@rollipop/rolldown";
2
+
3
+ //#region src/core/plugins/entry-plugin.d.ts
4
+ interface EntryPluginOptions {
5
+ entryPath: string;
6
+ preludePaths?: string[];
7
+ }
8
+ declare function entryPlugin(options: EntryPluginOptions): rolldown.Plugin;
9
+ //#endregion
10
+ export { EntryPluginOptions, entryPlugin };
@@ -0,0 +1,28 @@
1
+ import { ROLLIPOP_VIRTUAL_ENTRY_ID } from "../../constants.js";
2
+ import { exactRegex, id, include } from "@rollipop/rolldown/filter";
3
+ //#region src/core/plugins/entry-plugin.ts
4
+ const VIRTUAL_ENTRY_FILTER = [include(id(exactRegex(ROLLIPOP_VIRTUAL_ENTRY_ID)))];
5
+ function entryPlugin(options) {
6
+ const { entryPath, preludePaths = [] } = options;
7
+ const importStatements = [...preludePaths, entryPath].map((modulePath) => `import ${JSON.stringify(modulePath)};`).join("\n");
8
+ return {
9
+ name: "rollipop:entry",
10
+ resolveId: {
11
+ filter: VIRTUAL_ENTRY_FILTER,
12
+ handler() {
13
+ return ROLLIPOP_VIRTUAL_ENTRY_ID;
14
+ }
15
+ },
16
+ load: {
17
+ filter: VIRTUAL_ENTRY_FILTER,
18
+ handler() {
19
+ return {
20
+ code: importStatements,
21
+ moduleType: "js"
22
+ };
23
+ }
24
+ }
25
+ };
26
+ }
27
+ //#endregion
28
+ export { entryPlugin };
@@ -1,5 +1,5 @@
1
1
  import { ReactNativePluginOptions, reactNativePlugin } from "./react-native-plugin.js";
2
- import { PreludePluginOptions, preludePlugin } from "./prelude-plugin.js";
2
+ import { EntryPluginOptions, entryPlugin } from "./entry-plugin.js";
3
3
  import { BabelPluginOptions, babelPlugin } from "./babel-plugin.js";
4
4
  import { SwcPluginOptions, swcPlugin } from "./swc-plugin.js";
5
5
  import { ReporterPluginOptions, reporterPlugin } from "./reporter-plugin.js";
@@ -7,7 +7,7 @@ import { DevServerPluginOptions, devServerPlugin } from "./dev-server-plugin.js"
7
7
 
8
8
  //#region src/core/plugins/index.d.ts
9
9
  declare namespace index_d_exports {
10
- export { BabelPluginOptions, DevServerPluginOptions, PreludePluginOptions, ReactNativePluginOptions, ReporterPluginOptions, SwcPluginOptions, babelPlugin as babel, devServerPlugin as devServer, preludePlugin as prelude, reactNativePlugin as reactNative, reporterPlugin as reporter, swcPlugin as swc };
10
+ export { BabelPluginOptions, DevServerPluginOptions, EntryPluginOptions, ReactNativePluginOptions, ReporterPluginOptions, SwcPluginOptions, babelPlugin as babel, devServerPlugin as devServer, entryPlugin as entry, reactNativePlugin as reactNative, reporterPlugin as reporter, swcPlugin as swc };
11
11
  }
12
12
  //#endregion
13
13
  export { index_d_exports };
@@ -1,6 +1,6 @@
1
1
  import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
2
2
  import { reactNativePlugin } from "./react-native-plugin.js";
3
- import { preludePlugin } from "./prelude-plugin.js";
3
+ import { entryPlugin } from "./entry-plugin.js";
4
4
  import { babelPlugin } from "./babel-plugin.js";
5
5
  import { swcPlugin } from "./swc-plugin.js";
6
6
  import { reporterPlugin } from "./reporter-plugin.js";
@@ -9,7 +9,7 @@ import { devServerPlugin } from "./dev-server-plugin.js";
9
9
  var plugins_exports = /* @__PURE__ */ __exportAll({
10
10
  babel: () => babelPlugin,
11
11
  devServer: () => devServerPlugin,
12
- prelude: () => preludePlugin,
12
+ entry: () => entryPlugin,
13
13
  reactNative: () => reactNativePlugin,
14
14
  reporter: () => reporterPlugin,
15
15
  swc: () => swcPlugin
@@ -1,19 +1,22 @@
1
1
  import { isDebugEnabled } from "../common/env.js";
2
+ import { ROLLIPOP_VIRTUAL_ENTRY_ID } from "../constants.js";
3
+ import { asLiteral, iife, nodeEnvironment } from "../common/code.js";
2
4
  import { getGlobalVariables } from "../internal/react-native.js";
3
5
  import { resolveFrom, resolvePackageJson } from "../utils/node-resolve.js";
4
6
  import { CompatStatusReporter, ProgressBarStatusReporter, mergeReporters } from "../utils/reporters.js";
5
7
  import { printPluginLog } from "./plugins/context.js";
6
8
  import { applyOverrideRolldownOptions } from "../config/compose-override.js";
7
- import { asLiteral, iife, nodeEnvironment } from "../common/code.js";
9
+ import { createVirtualModuleId, escapeVirtualModuleId } from "../utils/id.js";
8
10
  import { resolveHmrConfig } from "../utils/config.js";
9
11
  import { defineEnvFromObject } from "../utils/env.js";
10
12
  import { resolveRuntimeTarget } from "../utils/runtime-target.js";
11
13
  import { getBaseUrl } from "../utils/server.js";
12
- import { getBuildTotalModules } from "../utils/storage.js";
14
+ import { getBuildTotalModules, setBuildTotalModules } from "../utils/storage.js";
15
+ import { transformWithRollipop } from "../utils/transform.js";
13
16
  import { loadEnv } from "./env.js";
14
17
  import { withTransformBoundary } from "./plugins/utils/transform-utils.js";
15
18
  import { reactNativePlugin } from "./plugins/react-native-plugin.js";
16
- import { preludePlugin } from "./plugins/prelude-plugin.js";
19
+ import { entryPlugin } from "./plugins/entry-plugin.js";
17
20
  import { babelPlugin } from "./plugins/babel-plugin.js";
18
21
  import { swcPlugin } from "./plugins/swc-plugin.js";
19
22
  import { reporterPlugin } from "./plugins/reporter-plugin.js";
@@ -37,7 +40,7 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
37
40
  const hmrConfig = resolveHmrConfig(config);
38
41
  const hmrEnabled = hmrConfig != null;
39
42
  const { sourceExtensions, assetExtensions, preferNativePlatform, external: rolldownExternal, ...rolldownResolve } = config.resolver;
40
- const { polyfills, banner: rolldownBanner, footer: rolldownFooter, postBanner: rolldownPostBanner, postFooter: rolldownPostFooter, intro: rolldownIntro, outro: rolldownOutro, shimMissingExports: rolldownShimMissingExports } = config.serializer;
43
+ const { banner: rolldownBanner, footer: rolldownFooter, postBanner: rolldownPostBanner, postFooter: rolldownPostFooter, intro: rolldownIntro, outro: rolldownOutro, shimMissingExports: rolldownShimMissingExports } = config.serializer;
41
44
  const { flow: _flow, babel: _babel, swc: _swc, ...rolldownTransform } = config.transformer;
42
45
  const { treeshake: rolldownTreeshake, minify: rolldownMinify, lazyBarrel: rolldownLazyBarrel, ...rolldownOptimization } = config.optimization;
43
46
  const { globalIdentifiers: rolldownGlobalIdentifiers } = config.reactNative;
@@ -60,13 +63,13 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
60
63
  __DEV__: asLiteral(dev),
61
64
  "process.env.NODE_ENV": asLiteral(nodeEnvironment(dev)),
62
65
  "process.env.DEBUG_ROLLIPOP": asLiteral(isDebugEnabled()),
63
- ...hmrEnabled ? null : { "import.meta.hot": "{}" },
66
+ ...hmrEnabled ? null : { "import.meta.hot": "undefined" },
64
67
  ...defineEnvFromObject(env),
65
68
  ...defineEnvFromObject(builtInEnv)
66
69
  },
67
70
  helpers: { mode: "Runtime" }
68
71
  }, rolldownTransform);
69
- const preludePluginOptions = resolvePreludePluginOptions(config);
72
+ const entryPluginOptions = resolveEntryPluginOptions(config);
70
73
  const reactNativePluginOptions = await resolveReactNativePluginOptions(config, context, buildOptions);
71
74
  const babelPluginOptions = resolveBabelPluginOptions(config, context);
72
75
  const swcPluginOptions = resolveSwcPluginOptions(config, context);
@@ -75,7 +78,7 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
75
78
  const finalOptions = await applyDangerouslyOverrideOptionsFinalizer(config, {
76
79
  platform: "neutral",
77
80
  cwd: config.root,
78
- input: config.entry,
81
+ input: ROLLIPOP_VIRTUAL_ENTRY_ID,
79
82
  tsconfig: config.tsconfig,
80
83
  resolve: mergedResolveOptions,
81
84
  transform: mergedTransformOptions,
@@ -88,7 +91,7 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
88
91
  ...isDevServerMode ? { devMode: hmrConfig ? { implement: hmrConfig.runtimeImplement } : false } : null
89
92
  },
90
93
  plugins: withTransformBoundary(context, [
91
- preludePlugin(preludePluginOptions),
94
+ entryPlugin(entryPluginOptions),
92
95
  reactNativePlugin(reactNativePluginOptions),
93
96
  babelPlugin(babelPluginOptions),
94
97
  swcPlugin(swcPluginOptions),
@@ -111,17 +114,17 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
111
114
  level,
112
115
  log: diagnostic
113
116
  });
114
- else if (isPluginLog(log)) config.reporter?.update({
115
- type: "build_log",
116
- level,
117
- log: diagnostic
118
- });
119
- if (log.code?.startsWith("PLUGIN_")) printPluginLog(level, log, log.plugin);
120
- else defaultHandler(level, log);
117
+ else if (isPluginLog(log)) {
118
+ config.reporter?.update({
119
+ type: "build_log",
120
+ level,
121
+ log: diagnostic
122
+ });
123
+ printPluginLog(level, log, log.plugin);
124
+ } else defaultHandler(level, log);
121
125
  },
122
126
  id: context.id
123
127
  }, {
124
- format: "esm",
125
128
  file: buildOptions.outfile,
126
129
  banner: rolldownBanner,
127
130
  footer: rolldownFooter,
@@ -131,7 +134,7 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
131
134
  intro: async (chunk) => {
132
135
  return [
133
136
  ...getGlobalVariables(dev, context.buildType),
134
- ...loadPolyfills(polyfills),
137
+ ...loadPolyfills(config),
135
138
  typeof rolldownIntro === "function" ? await rolldownIntro(chunk) : rolldownIntro
136
139
  ].filter(isNotNil).join("\n");
137
140
  },
@@ -142,7 +145,6 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
142
145
  sourcemapIgnoreList: rolldownSourcemapIgnoreList,
143
146
  sourcemapPathTransform: rolldownSourcemapPathTransform ?? createProjectRootSourcemapPathTransform(config.root),
144
147
  codeSplitting: false,
145
- strictExecutionOrder: true,
146
148
  globalIdentifiers: rolldownGlobalIdentifiers,
147
149
  persistentCache: cache
148
150
  });
@@ -150,10 +152,10 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
150
152
  return finalOptions;
151
153
  }
152
154
  resolveRolldownOptions.cache = /* @__PURE__ */ new Map();
153
- function resolvePreludePluginOptions(config) {
155
+ function resolveEntryPluginOptions(config) {
154
156
  return {
155
157
  entryPath: config.entry,
156
- modulePaths: config.serializer.prelude
158
+ preludePaths: config.serializer.prelude
157
159
  };
158
160
  }
159
161
  async function resolveReactNativePluginOptions(config, context, buildOptions) {
@@ -217,11 +219,21 @@ function resolveDevServerPluginOptions(config, hmrConfig) {
217
219
  }
218
220
  function resolveReporterPluginOptions(config, context, buildOptions) {
219
221
  const statusReporter = createStatusReporter(config, context, buildOptions);
222
+ const buildTotalModulesReporter = createBuildTotalModulesReporter(context);
220
223
  return {
221
224
  initialTotalModules: getBuildTotalModules(context.storage, context.id),
222
- reporter: mergeReporters([statusReporter, config.reporter].filter(isNotNil))
225
+ reporter: mergeReporters([
226
+ buildTotalModulesReporter,
227
+ statusReporter,
228
+ config.reporter
229
+ ].filter(isNotNil))
223
230
  };
224
231
  }
232
+ function createBuildTotalModulesReporter(context) {
233
+ return { update(event) {
234
+ if (event.type === "bundle_build_done") setBuildTotalModules(context.storage, context.id, event.totalModules);
235
+ } };
236
+ }
225
237
  function createStatusReporter(config, context, buildOptions) {
226
238
  switch (config.terminal.status) {
227
239
  case "compat": return new CompatStatusReporter();
@@ -248,12 +260,21 @@ function createProjectRootSourcemapPathTransform(projectRoot) {
248
260
  return path.relative(projectRoot, absolute);
249
261
  };
250
262
  }
251
- function loadPolyfills(polyfills) {
252
- return polyfills.map((polyfill) => {
263
+ function loadPolyfills(config) {
264
+ return config.serializer.polyfills.map((polyfill, index) => {
253
265
  if (typeof polyfill === "string") return fs.readFileSync(polyfill, "utf-8");
254
266
  const path = "path" in polyfill ? polyfill.path : void 0;
255
267
  const content = "code" in polyfill ? polyfill.code : fs.readFileSync(polyfill.path, "utf-8");
256
- return polyfill.type === "iife" ? iife(content, path) : content;
268
+ const id = createVirtualModuleId("polyfill", {
269
+ index: index.toString(),
270
+ path: path ?? ""
271
+ });
272
+ const code = polyfill.withTransform ? transformWithRollipop(id, content, config).code : content;
273
+ return [
274
+ `//#region ${escapeVirtualModuleId(id)}`,
275
+ polyfill.type === "iife" ? iife(code) : code,
276
+ "//#endregion"
277
+ ].join("\n");
257
278
  });
258
279
  }
259
280
  async function applyDangerouslyOverrideOptionsFinalizer(config, inputOptions, outputOptions) {
@@ -285,14 +306,35 @@ function toBuildDiagnosticLog(log) {
285
306
  }
286
307
  function getOverrideOptions() {
287
308
  return {
288
- input: { experimental: { nativeMagicString: true } },
289
- output: {}
309
+ input: {
310
+ optimization: {
311
+ /**
312
+ * Must disable `inlineConst` option with the rollipop's custom module format.
313
+ *
314
+ * ```js
315
+ * __rollipop_define__(function (global, module, __rollipop_exports__, __rollipop_require__) {
316
+ * __rollipop_require__.r(__rollipop_exports__);
317
+ * __rollipop_require__.d(__rollipop_exports__, { default: () => __default });
318
+ * var __default = 'value'; // <-- This must be a preserved as exported value. NOT inlined.
319
+ * }, 1234);
320
+ * ```
321
+ */
322
+ inlineConst: false },
323
+ experimental: { nativeMagicString: true }
324
+ },
325
+ output: { format: "rollipop" }
290
326
  };
291
327
  }
292
328
  function getOverrideOptionsForDevServer(buildOptions) {
293
329
  const overrideOptions = getOverrideOptions();
294
330
  const input = {
295
- transform: { jsx: { development: true } },
331
+ transform: { jsx: {
332
+ development: buildOptions.dev,
333
+ /**
334
+ * @see `rollipopReactRefreshWrapperPlugin`
335
+ */
336
+ refresh: false
337
+ } },
296
338
  experimental: { incrementalBuild: true },
297
339
  treeshake: false
298
340
  };
@@ -125,7 +125,7 @@
125
125
  return e && typeof Symbol !== "undefined" && e.constructor === Symbol ? "symbol" : typeof e;
126
126
  }
127
127
  function isReactRefreshBoundary(n) {
128
- if (global.__ReactRefresh.isLikelyComponentType(n)) return true;
128
+ if (globalThis.__ReactRefresh.isLikelyComponentType(n)) return true;
129
129
  if (n === void 0 || n === null || (typeof n === "undefined" ? "undefined" : e(n)) !== "object") return false;
130
130
  var r = false;
131
131
  var t = true;
@@ -133,7 +133,7 @@
133
133
  r = true;
134
134
  if (o === "__esModule") continue;
135
135
  var f = n[o];
136
- if (!global.__ReactRefresh.isLikelyComponentType(f)) t = false;
136
+ if (!globalThis.__ReactRefresh.isLikelyComponentType(f)) t = false;
137
137
  }
138
138
  return r && t;
139
139
  }
@@ -141,7 +141,7 @@
141
141
  function enqueueUpdate() {
142
142
  if (n) return;
143
143
  n = setTimeout(function() {
144
- global.__ReactRefresh.performReactRefresh();
144
+ globalThis.__ReactRefresh.performReactRefresh();
145
145
  n = null;
146
146
  }, 50);
147
147
  }
@@ -283,7 +283,7 @@
283
283
  {
284
284
  key: "refresh",
285
285
  get: function e() {
286
- return global.__ReactRefresh;
286
+ return globalThis.__ReactRefresh;
287
287
  }
288
288
  },
289
289
  {
@@ -535,7 +535,7 @@
535
535
  var o, i;
536
536
  debug("[HMR]: Custom HMR message received: ".concat(n.type));
537
537
  r.socketHolder.emit(n.type, n.payload);
538
- (o = (i = global).__ROLLIPOP_CUSTOM_HMR_HANDLER__) === null || o === void 0 || o.call(i, e, n);
538
+ (o = (i = globalThis).__ROLLIPOP_CUSTOM_HMR_HANDLER__) === null || o === void 0 || o.call(i, e, n);
539
539
  return;
540
540
  }
541
541
  switch (n.type) {
@@ -553,7 +553,7 @@
553
553
  key: "evaluate",
554
554
  value: function evaluate(code, sourceURL) {
555
555
  debug("[HMR]: Evaluating code\n".concat(code));
556
- if (global.globalEvalWithSourceUrl) global.globalEvalWithSourceUrl(code, sourceURL);
556
+ if (globalThis.globalEvalWithSourceUrl) globalThis.globalEvalWithSourceUrl(code, sourceURL);
557
557
  else eval(code);
558
558
  }
559
559
  },
@@ -562,7 +562,7 @@
562
562
  value: function e() {
563
563
  debug("[HMR]: Reloading");
564
564
  var e = "DevSettings";
565
- (global.__turboModuleProxy ? global.__turboModuleProxy(e) : global.nativeModuleProxy[e]).reload();
565
+ (globalThis.__turboModuleProxy ? globalThis.__turboModuleProxy(e) : globalThis.nativeModuleProxy[e]).reload();
566
566
  }
567
567
  }
568
568
  ]);
@@ -580,6 +580,6 @@
580
580
  if ("type" in e && typeof e.type === "string" && e.type.startsWith("hmr:")) return false;
581
581
  return true;
582
582
  }
583
- (___rolldown_runtime__ = (_globalThis = global).__rolldown_runtime__) !== null && ___rolldown_runtime__ !== void 0 || (_globalThis.__rolldown_runtime__ = new ReactNativeDevRuntime());
583
+ (___rolldown_runtime__ = (_globalThis = globalThis).__rolldown_runtime__) !== null && ___rolldown_runtime__ !== void 0 || (_globalThis.__rolldown_runtime__ = new ReactNativeDevRuntime());
584
584
  //#endregion
585
585
  })();
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import { DEFAULT_HOST, DEFAULT_PORT, DEV_SERVER_ASSET_PATH } from "./server/cons
6
6
  import { Plugin, PluginConfig } from "./core/plugins/types.js";
7
7
  import { InteractiveCommand, InteractiveCommandContext, InteractiveModeOptions, setupInteractiveMode } from "./node/commands/start/setup-interactive-mode.js";
8
8
  import { createCommand, createReactNativeCliCommand } from "./node/cli-utils.js";
9
- 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 "./config/types.js";
9
+ import { BabelTransformConfig, CodegenConfig, Config, DevModeConfig, ExperimentalConfig, FlowConfig, HmrConfig, OptimizationConfig, PluginOption, Polyfill, PolyfillOptions, PolyfillType, PolyfillWithCode, PolyfillWithPath, ReactNativeConfig, ResolverConfig, RolldownConfig, RollipopReactNativeFlowConfig, RollipopReactNativeWorkletsConfig, SerializerConfig, SwcTransformConfig, TerminalConfig, TransformRule, TransformerConfig, WatcherConfig } from "./config/types.js";
10
10
  import { PluginFlattenConfig, mergeConfig } from "./config/merge-config.js";
11
11
  import { DefaultConfig, ResolvedConfig, getDefaultConfig } from "./config/defaults.js";
12
12
  import { DefineConfigContext, DynamicUserConfig, UserConfig, defineConfig } from "./config/define-config.js";
@@ -23,4 +23,4 @@ import { DevRuntime, DevRuntimeInterface, DevRuntimeMessenger, DevRuntimeModule,
23
23
  import { cli_d_exports } from "./node/cli.js";
24
24
  import * as rolldown from "@rollipop/rolldown";
25
25
  import * as rolldownExperimental from "@rollipop/rolldown/experimental";
26
- export { assets_d_exports as AssetUtils, type AsyncResult, type BabelTransformConfig, type BuildDiagnosticLog, type BuildOptions, type BuildType, type BundleDetails, Bundler, type BundlerContext, type BundlerState, type CodegenConfig, type Config, constants_d_exports as Constants, DEFAULT_HOST, DEFAULT_PORT, DEV_SERVER_ASSET_PATH, type DeepRequired, DefaultConfig, DefineConfigContext, type DevEngine, type DevEngineOptions, type DevModeConfig, type DevRuntime, type DevRuntimeInterface, type DevRuntimeMessenger, type DevRuntimeModule, type DevServer, type DevServerContext, type DevServerEvents, DynamicUserConfig, type ExperimentalConfig, type FastifyInstance, type FlowConfig, type FormattedError, type HMRClientLogLevel, type HMRClientMessage, type HMRContext, type HMRCustomHandler, type HMRCustomMessage, type HMRServerError, type HMRServerMessage, type HmrConfig, InteractiveCommand, InteractiveCommandContext, InteractiveModeOptions, LoadConfigOptions, LoadEnvOptions, type MaybePromise, type MetroCompatibleClientLogEvent, type Middlewares, type NullValue, type OptimizationConfig, type PackageJson, type Plugin, type PluginConfig, PluginFlattenConfig, type PluginOption, type Polyfill, type PolyfillType, type PolyfillWithCode, type PolyfillWithPath, type ReactNativeConfig, type ReportableEvent, type Reporter, ResolvedConfig, type ResolverConfig, type RolldownConfig, type RollipopReactNativeFlowConfig, type RollipopReactNativeWorkletsConfig, type SerializerConfig, type ServerOptions, type SwcTransformConfig, type TerminalConfig, type TransformRule, type TransformerConfig, UserConfig, type WatcherConfig, cli_d_exports as cli, createCommand, createDevServer, createReactNativeCliCommand, defineConfig, flattenPluginOption, getDefaultConfig, invokeConfigResolved, loadConfig, loadEnv, mergeConfig, index_d_exports as plugins, resetCache, resolvePluginConfig, rolldown, rolldownExperimental, runBuild, runServer, setupInteractiveMode };
26
+ export { assets_d_exports as AssetUtils, type AsyncResult, type BabelTransformConfig, type BuildDiagnosticLog, type BuildOptions, type BuildType, type BundleDetails, Bundler, type BundlerContext, type BundlerState, type CodegenConfig, type Config, constants_d_exports as Constants, DEFAULT_HOST, DEFAULT_PORT, DEV_SERVER_ASSET_PATH, type DeepRequired, DefaultConfig, DefineConfigContext, type DevEngine, type DevEngineOptions, type DevModeConfig, type DevRuntime, type DevRuntimeInterface, type DevRuntimeMessenger, type DevRuntimeModule, type DevServer, type DevServerContext, type DevServerEvents, DynamicUserConfig, type ExperimentalConfig, type FastifyInstance, type FlowConfig, type FormattedError, type HMRClientLogLevel, type HMRClientMessage, type HMRContext, type HMRCustomHandler, type HMRCustomMessage, type HMRServerError, type HMRServerMessage, type HmrConfig, InteractiveCommand, InteractiveCommandContext, InteractiveModeOptions, LoadConfigOptions, LoadEnvOptions, type MaybePromise, type MetroCompatibleClientLogEvent, type Middlewares, type NullValue, type OptimizationConfig, type PackageJson, type Plugin, type PluginConfig, PluginFlattenConfig, type PluginOption, type Polyfill, type PolyfillOptions, type PolyfillType, type PolyfillWithCode, type PolyfillWithPath, type ReactNativeConfig, type ReportableEvent, type Reporter, ResolvedConfig, type ResolverConfig, type RolldownConfig, type RollipopReactNativeFlowConfig, type RollipopReactNativeWorkletsConfig, type SerializerConfig, type ServerOptions, type SwcTransformConfig, type TerminalConfig, type TransformRule, type TransformerConfig, UserConfig, type WatcherConfig, cli_d_exports as cli, createCommand, createDevServer, createReactNativeCliCommand, defineConfig, flattenPluginOption, getDefaultConfig, invokeConfigResolved, loadConfig, loadEnv, mergeConfig, index_d_exports as plugins, resetCache, resolvePluginConfig, rolldown, rolldownExperimental, runBuild, runServer, setupInteractiveMode };
@@ -1,5 +1,5 @@
1
1
  import { __require } from "../_virtual/_rolldown/runtime.js";
2
- import { GLOBAL_IDENTIFIER } from "../constants.js";
2
+ import { asLiteral } from "../common/code.js";
3
3
  import path from "node:path";
4
4
  import { isNotNil } from "es-toolkit";
5
5
  //#region src/internal/react-native.ts
@@ -12,10 +12,11 @@ function getPolyfillScriptPaths(reactNativePath) {
12
12
  function getGlobalVariables(dev, buildType) {
13
13
  const isDevServerMode = dev && buildType === "serve";
14
14
  return [
15
- `var __BUNDLE_START_TIME__=globalThis.nativePerformanceNow?nativePerformanceNow():Date.now();`,
16
- `var __DEV__=${dev};`,
17
- `var ${GLOBAL_IDENTIFIER}=typeof globalThis!=='undefined'?globalThis:typeof global !== 'undefined'?global:typeof window!=='undefined'?window:this;`,
18
- `var process=globalThis.process||{};process.env=process.env||{};process.env.NODE_ENV=process.env.NODE_ENV||"${dev ? "development" : "production"}";`,
15
+ `var __BUNDLE_START_TIME__ = globalThis.nativePerformanceNow ? nativePerformanceNow() : Date.now();`,
16
+ `var __DEV__ = ${asLiteral(dev)};`,
17
+ `var process = globalThis.process || {};`,
18
+ "process.env = process.env || {};",
19
+ `process.env.NODE_ENV = process.env.NODE_ENV || ${asLiteral(dev ? "development" : "production")};`,
19
20
  isDevServerMode ? `var $RefreshReg$ = () => {};` : null,
20
21
  isDevServerMode ? `var $RefreshSig$ = () => (v) => v;` : null
21
22
  ].filter(isNotNil);