rollipop 0.1.0-alpha.8 → 0.1.0-dev.20260118070035

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # rollipop
2
2
 
3
+ ## 0.1.0-alpha.9
4
+
5
+ ### Patch Changes
6
+
7
+ - 200e373: noop in `onHmrUpdates` when HMR is disabled
8
+ - 099598b: esm only
9
+ - 5b9fd00: update default `dev` option
10
+ - 19c5b71: add built-in constants environment variables
11
+
3
12
  ## 0.1.0-alpha.8
4
13
 
5
14
  ### Patch Changes
package/client.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ interface ImportMetaEnv {
2
+ readonly MODE: 'development' | 'production';
3
+ readonly BASE_URL?: string;
4
+ }
5
+
1
6
  interface ImportMeta {
2
7
  hot?: import('./dist').HMRContext;
3
8
  env: ImportMetaEnv;
package/dist/commands.cjs CHANGED
@@ -696,7 +696,7 @@ function getDefaultConfig(basePath, mode) {
696
696
  }
697
697
  return {
698
698
  root: basePath,
699
- mode,
699
+ mode: mode ?? "development",
700
700
  entry: "index.js",
701
701
  resolver: {
702
702
  sourceExtensions: DEFAULT_SOURCE_EXTENSIONS,
@@ -917,7 +917,6 @@ function resetCache(projectRoot) {
917
917
  //#endregion
918
918
  //#region src/utils/build-options.ts
919
919
  const DEFAULT_BUILD_OPTIONS = {
920
- dev: true,
921
920
  cache: true,
922
921
  minify: false
923
922
  };
@@ -925,7 +924,7 @@ function resolveBuildOptions(config, buildOptions) {
925
924
  if (buildOptions.outfile) buildOptions.outfile = node_path.default.resolve(config.root, buildOptions.outfile);
926
925
  if (buildOptions.sourcemap) buildOptions.sourcemap = node_path.default.resolve(config.root, buildOptions.sourcemap);
927
926
  return (0, es_toolkit.merge)(DEFAULT_BUILD_OPTIONS, {
928
- dev: config.mode === "development",
927
+ dev: buildOptions.dev ?? config.mode === "development",
929
928
  ...buildOptions
930
929
  });
931
930
  }
@@ -1390,9 +1389,9 @@ function bindReporter(config, eventSource) {
1390
1389
  return config;
1391
1390
  }
1392
1391
  function resolveHmrConfig(config) {
1393
- if (config.devMode?.hmr == null) return null;
1392
+ if (config.mode !== "development") return null;
1394
1393
  const defaultRuntimeImplements = getDefaultRuntimeImplements();
1395
- if (typeof config.devMode?.hmr === "boolean") return config.devMode.hmr ? defaultRuntimeImplements : null;
1394
+ if (typeof config.devMode.hmr === "boolean") return config.devMode.hmr ? defaultRuntimeImplements : null;
1396
1395
  const { runtimeImplement = defaultRuntimeImplements.runtimeImplement, clientImplement = defaultRuntimeImplements.clientImplement } = config.devMode.hmr;
1397
1396
  return {
1398
1397
  runtimeImplement,
@@ -1408,6 +1407,18 @@ function getDefaultRuntimeImplements() {
1408
1407
  return getDefaultRuntimeImplements.cache;
1409
1408
  }
1410
1409
 
1410
+ //#endregion
1411
+ //#region src/utils/env.ts
1412
+ function defineEnvFromObject(env) {
1413
+ return Object.fromEntries(Object.entries(env).map(([key, value]) => [`import.meta.env.${key}`, asLiteral(value)]));
1414
+ }
1415
+
1416
+ //#endregion
1417
+ //#region src/utils/server.ts
1418
+ function getBaseUrl(host, port, https) {
1419
+ return `${https ? "https" : "http"}://${host}:${port}`;
1420
+ }
1421
+
1411
1422
  //#endregion
1412
1423
  //#region src/core/env.ts
1413
1424
  function loadEnv(options) {
@@ -1618,6 +1629,7 @@ var InMemoryBundle = class {
1618
1629
  //#region src/server/bundler-pool.ts
1619
1630
  var BundlerDevEngine = class extends node_events.default {
1620
1631
  initializeHandle;
1632
+ isHmrEnabled;
1621
1633
  _id;
1622
1634
  bundle = null;
1623
1635
  buildFailedError = null;
@@ -1630,6 +1642,7 @@ var BundlerDevEngine = class extends node_events.default {
1630
1642
  this.buildOptions = buildOptions;
1631
1643
  this._id = Bundler.createId(config, buildOptions);
1632
1644
  this.initializeHandle = taskHandler();
1645
+ this.isHmrEnabled = Boolean(config.mode === "development" && config.devMode.hmr);
1633
1646
  this.initialize();
1634
1647
  }
1635
1648
  get id() {
@@ -1655,6 +1668,7 @@ var BundlerDevEngine = class extends node_events.default {
1655
1668
  host: this.options.server.host,
1656
1669
  port: this.options.server.port,
1657
1670
  onHmrUpdates: (errorOrResult) => {
1671
+ if (!this.isHmrEnabled) return;
1658
1672
  if (errorOrResult instanceof Error) {
1659
1673
  logger.error("Failed to handle HMR updates", {
1660
1674
  bundlerId: this.id,
@@ -4692,10 +4706,16 @@ function getPreset() {
4692
4706
  //#endregion
4693
4707
  //#region src/core/rolldown.ts
4694
4708
  resolveRolldownOptions.cache = /* @__PURE__ */ new Map();
4695
- async function resolveRolldownOptions(context, config, buildOptions) {
4709
+ async function resolveRolldownOptions(context, config, buildOptions, devEngineOptions) {
4696
4710
  const cachedOptions = resolveRolldownOptions.cache.get(context.id);
4697
4711
  if (cachedOptions != null) return cachedOptions;
4712
+ const isDevServerMode = config.mode === "development" && context.buildType === "serve";
4713
+ (0, es_toolkit.invariant)(isDevServerMode ? devEngineOptions != null : true, "devEngineOptions is required in dev server mode");
4698
4714
  const env = loadEnv(config);
4715
+ const builtInEnv = {
4716
+ MODE: config.mode,
4717
+ ...isDevServerMode ? { BASE_URL: getBaseUrl(devEngineOptions.host, devEngineOptions.port, devEngineOptions.https) } : null
4718
+ };
4699
4719
  const { platform, dev: dev$1, cache, minify } = buildOptions;
4700
4720
  const { sourceExtensions, assetExtensions, preferNativePlatform, ...rolldownResolve } = config.resolver;
4701
4721
  const { prelude: preludePaths, polyfills } = config.serializer;
@@ -4722,13 +4742,14 @@ async function resolveRolldownOptions(context, config, buildOptions) {
4722
4742
  global: asIdentifier(GLOBAL_IDENTIFIER),
4723
4743
  "process.env.NODE_ENV": asLiteral(nodeEnvironment(dev$1)),
4724
4744
  "process.env.DEBUG_ROLLIPOP": asLiteral(isDebugEnabled()),
4725
- ...Object.fromEntries(Object.entries(env).map(([key, value]) => [`import.meta.env.${key}`, asLiteral(value)]))
4745
+ ...defineEnvFromObject(env),
4746
+ ...defineEnvFromObject(builtInEnv)
4726
4747
  },
4727
4748
  typescript: { removeClassFieldsWithoutInitializer: true },
4728
4749
  assumptions: { setPublicClassFields: true },
4729
4750
  helpers: { mode: "Runtime" }
4730
4751
  }, rolldownTransform);
4731
- const devServerPlugins = config.mode === "development" && context.buildType === "serve" ? [reactRefreshPlugin()] : null;
4752
+ const devServerPlugins = isDevServerMode ? [reactRefreshPlugin()] : null;
4732
4753
  const { beforeTransform, afterTransform } = getPersistCachePlugins({
4733
4754
  enabled: cache,
4734
4755
  sourceExtensions,
@@ -4843,7 +4864,7 @@ var Bundler = class Bundler {
4843
4864
  const buildType = "serve";
4844
4865
  const resolvedBuildOptions = resolveBuildOptions(config, buildOptions);
4845
4866
  const context = Bundler.createContext(buildType, config, resolvedBuildOptions);
4846
- const { input = {}, output = {} } = await resolveRolldownOptions(context, config, resolvedBuildOptions);
4867
+ const { input = {}, output = {} } = await resolveRolldownOptions(context, config, resolvedBuildOptions, devEngineOptions);
4847
4868
  const devServerOptions = getOverrideOptionsForDevServer(config);
4848
4869
  const devEngine = await (0, _rollipop_rolldown_experimental.dev)((0, es_toolkit.merge)(input, devServerOptions.input), (0, es_toolkit.merge)(output, devServerOptions.output), {
4849
4870
  watch: config.watcher,
package/dist/commands.js CHANGED
@@ -646,7 +646,7 @@ function getDefaultConfig(basePath, mode) {
646
646
  }
647
647
  return {
648
648
  root: basePath,
649
- mode,
649
+ mode: mode ?? "development",
650
650
  entry: "index.js",
651
651
  resolver: {
652
652
  sourceExtensions: DEFAULT_SOURCE_EXTENSIONS,
@@ -867,7 +867,6 @@ function resetCache(projectRoot) {
867
867
  //#endregion
868
868
  //#region src/utils/build-options.ts
869
869
  const DEFAULT_BUILD_OPTIONS = {
870
- dev: true,
871
870
  cache: true,
872
871
  minify: false
873
872
  };
@@ -875,7 +874,7 @@ function resolveBuildOptions(config, buildOptions) {
875
874
  if (buildOptions.outfile) buildOptions.outfile = path.resolve(config.root, buildOptions.outfile);
876
875
  if (buildOptions.sourcemap) buildOptions.sourcemap = path.resolve(config.root, buildOptions.sourcemap);
877
876
  return merge(DEFAULT_BUILD_OPTIONS, {
878
- dev: config.mode === "development",
877
+ dev: buildOptions.dev ?? config.mode === "development",
879
878
  ...buildOptions
880
879
  });
881
880
  }
@@ -1340,9 +1339,9 @@ function bindReporter(config, eventSource) {
1340
1339
  return config;
1341
1340
  }
1342
1341
  function resolveHmrConfig(config) {
1343
- if (config.devMode?.hmr == null) return null;
1342
+ if (config.mode !== "development") return null;
1344
1343
  const defaultRuntimeImplements = getDefaultRuntimeImplements();
1345
- if (typeof config.devMode?.hmr === "boolean") return config.devMode.hmr ? defaultRuntimeImplements : null;
1344
+ if (typeof config.devMode.hmr === "boolean") return config.devMode.hmr ? defaultRuntimeImplements : null;
1346
1345
  const { runtimeImplement = defaultRuntimeImplements.runtimeImplement, clientImplement = defaultRuntimeImplements.clientImplement } = config.devMode.hmr;
1347
1346
  return {
1348
1347
  runtimeImplement,
@@ -1358,6 +1357,18 @@ function getDefaultRuntimeImplements() {
1358
1357
  return getDefaultRuntimeImplements.cache;
1359
1358
  }
1360
1359
 
1360
+ //#endregion
1361
+ //#region src/utils/env.ts
1362
+ function defineEnvFromObject(env) {
1363
+ return Object.fromEntries(Object.entries(env).map(([key, value]) => [`import.meta.env.${key}`, asLiteral(value)]));
1364
+ }
1365
+
1366
+ //#endregion
1367
+ //#region src/utils/server.ts
1368
+ function getBaseUrl(host, port, https) {
1369
+ return `${https ? "https" : "http"}://${host}:${port}`;
1370
+ }
1371
+
1361
1372
  //#endregion
1362
1373
  //#region src/core/env.ts
1363
1374
  function loadEnv(options) {
@@ -1568,6 +1579,7 @@ var InMemoryBundle = class {
1568
1579
  //#region src/server/bundler-pool.ts
1569
1580
  var BundlerDevEngine = class extends EventEmitter {
1570
1581
  initializeHandle;
1582
+ isHmrEnabled;
1571
1583
  _id;
1572
1584
  bundle = null;
1573
1585
  buildFailedError = null;
@@ -1580,6 +1592,7 @@ var BundlerDevEngine = class extends EventEmitter {
1580
1592
  this.buildOptions = buildOptions;
1581
1593
  this._id = Bundler.createId(config, buildOptions);
1582
1594
  this.initializeHandle = taskHandler();
1595
+ this.isHmrEnabled = Boolean(config.mode === "development" && config.devMode.hmr);
1583
1596
  this.initialize();
1584
1597
  }
1585
1598
  get id() {
@@ -1605,6 +1618,7 @@ var BundlerDevEngine = class extends EventEmitter {
1605
1618
  host: this.options.server.host,
1606
1619
  port: this.options.server.port,
1607
1620
  onHmrUpdates: (errorOrResult) => {
1621
+ if (!this.isHmrEnabled) return;
1608
1622
  if (errorOrResult instanceof Error) {
1609
1623
  logger.error("Failed to handle HMR updates", {
1610
1624
  bundlerId: this.id,
@@ -4642,10 +4656,16 @@ function getPreset() {
4642
4656
  //#endregion
4643
4657
  //#region src/core/rolldown.ts
4644
4658
  resolveRolldownOptions.cache = /* @__PURE__ */ new Map();
4645
- async function resolveRolldownOptions(context, config, buildOptions) {
4659
+ async function resolveRolldownOptions(context, config, buildOptions, devEngineOptions) {
4646
4660
  const cachedOptions = resolveRolldownOptions.cache.get(context.id);
4647
4661
  if (cachedOptions != null) return cachedOptions;
4662
+ const isDevServerMode = config.mode === "development" && context.buildType === "serve";
4663
+ invariant(isDevServerMode ? devEngineOptions != null : true, "devEngineOptions is required in dev server mode");
4648
4664
  const env = loadEnv(config);
4665
+ const builtInEnv = {
4666
+ MODE: config.mode,
4667
+ ...isDevServerMode ? { BASE_URL: getBaseUrl(devEngineOptions.host, devEngineOptions.port, devEngineOptions.https) } : null
4668
+ };
4649
4669
  const { platform, dev: dev$1, cache, minify } = buildOptions;
4650
4670
  const { sourceExtensions, assetExtensions, preferNativePlatform, ...rolldownResolve } = config.resolver;
4651
4671
  const { prelude: preludePaths, polyfills } = config.serializer;
@@ -4672,13 +4692,14 @@ async function resolveRolldownOptions(context, config, buildOptions) {
4672
4692
  global: asIdentifier(GLOBAL_IDENTIFIER),
4673
4693
  "process.env.NODE_ENV": asLiteral(nodeEnvironment(dev$1)),
4674
4694
  "process.env.DEBUG_ROLLIPOP": asLiteral(isDebugEnabled()),
4675
- ...Object.fromEntries(Object.entries(env).map(([key, value]) => [`import.meta.env.${key}`, asLiteral(value)]))
4695
+ ...defineEnvFromObject(env),
4696
+ ...defineEnvFromObject(builtInEnv)
4676
4697
  },
4677
4698
  typescript: { removeClassFieldsWithoutInitializer: true },
4678
4699
  assumptions: { setPublicClassFields: true },
4679
4700
  helpers: { mode: "Runtime" }
4680
4701
  }, rolldownTransform);
4681
- const devServerPlugins = config.mode === "development" && context.buildType === "serve" ? [reactRefreshPlugin()] : null;
4702
+ const devServerPlugins = isDevServerMode ? [reactRefreshPlugin()] : null;
4682
4703
  const { beforeTransform, afterTransform } = getPersistCachePlugins({
4683
4704
  enabled: cache,
4684
4705
  sourceExtensions,
@@ -4793,7 +4814,7 @@ var Bundler = class Bundler {
4793
4814
  const buildType = "serve";
4794
4815
  const resolvedBuildOptions = resolveBuildOptions(config, buildOptions);
4795
4816
  const context = Bundler.createContext(buildType, config, resolvedBuildOptions);
4796
- const { input = {}, output = {} } = await resolveRolldownOptions(context, config, resolvedBuildOptions);
4817
+ const { input = {}, output = {} } = await resolveRolldownOptions(context, config, resolvedBuildOptions, devEngineOptions);
4797
4818
  const devServerOptions = getOverrideOptionsForDevServer(config);
4798
4819
  const devEngine = await dev(merge(input, devServerOptions.input), merge(output, devServerOptions.output), {
4799
4820
  watch: config.watcher,
@@ -0,0 +1,6 @@
1
+ import { HMRClientLogLevel } from "../types/hmr";
2
+
3
+ //#region src/runtime/hmr-client.d.ts
4
+
5
+ //#endregion
6
+ export { u as default };
@@ -0,0 +1,2 @@
1
+ //#endregion
2
+ export { type c as DevRuntime };
package/dist/index.d.ts CHANGED
@@ -157,6 +157,12 @@ type DevEngineOptions = Omit<DevOptions, 'watch'> & {
157
157
  * The port to run the dev server on.
158
158
  */
159
159
  port: number;
160
+ /**
161
+ * Whether to use HTTPS.
162
+ *
163
+ * Defaults to `false`.
164
+ */
165
+ https?: boolean;
160
166
  };
161
167
  interface BundlerContext {
162
168
  id: string;
@@ -521,8 +527,9 @@ type WatcherConfig = DevWatchOptions;
521
527
  interface DevModeConfig {
522
528
  /**
523
529
  * Hot Module Replacement configurations.
530
+ * This feature is only available in `development` mode.
524
531
  *
525
- * Defaults to `true`
532
+ * Defaults to `true`.
526
533
  */
527
534
  hmr?: boolean | HmrConfig;
528
535
  }
@@ -591,7 +598,7 @@ declare function mergeConfig(baseConfig: DefaultConfig, ...overrideConfigs: Plug
591
598
  //#region src/config/defaults.d.ts
592
599
  declare function getDefaultConfig(basePath: string, mode?: Config['mode']): {
593
600
  root: string;
594
- mode: "development" | "production" | undefined;
601
+ mode: "development" | "production";
595
602
  entry: string;
596
603
  resolver: {
597
604
  sourceExtensions: string[];
@@ -635,7 +642,7 @@ declare function getDefaultConfig(basePath: string, mode?: Config['mode']): {
635
642
  globalIdentifiers: string[];
636
643
  };
637
644
  devMode: {
638
- hmr: true;
645
+ hmr: boolean | HmrConfig;
639
646
  };
640
647
  terminal: {
641
648
  status: "none" | "compat" | "progress" | undefined;
@@ -907,9 +914,34 @@ interface HMRServerError {
907
914
  description: string;
908
915
  }[];
909
916
  }
917
+ interface DevRuntimeModule {
918
+ exportsHolder: {
919
+ exports: any;
920
+ };
921
+ id: string;
922
+ exports: any;
923
+ }
924
+ interface DevRuntimeInterface {
925
+ modules: Record<string, DevRuntimeModule>;
926
+ createModuleHotContext(moduleId: string): void;
927
+ applyUpdates(boundaries: [string, string][]): void;
928
+ registerModule(id: string, exportsHolder: DevRuntimeModule['exportsHolder']): void;
929
+ loadExports(id: string): void;
930
+ }
931
+ declare class DevRuntime implements DevRuntimeInterface {
932
+ constructor(messenger: DevRuntimeMessenger);
933
+ modules: Record<string, DevRuntimeModule>;
934
+ createModuleHotContext(moduleId: string): void;
935
+ applyUpdates(boundaries: [string, string][]): void;
936
+ registerModule(id: string, exportsHolder: DevRuntimeModule['exportsHolder']): void;
937
+ loadExports(id: string): void;
938
+ }
939
+ interface DevRuntimeMessenger {
940
+ send(message: HMRClientMessage): void;
941
+ }
910
942
  declare namespace cli_d_exports {
911
943
  export { run };
912
944
  }
913
945
  declare function run(argv: string[]): void;
914
946
  //#endregion
915
- export { assets_d_exports as AssetUtils, AsyncResult, BabelTransformRule, BuildOptions, BuildType, BundleDetails, Bundler, BundlerContext, BundlerState, CodegenConfig, Config, DEFAULT_HOST, DEFAULT_PORT, DEV_SERVER_ASSET_PATH, DefaultConfig, DefineConfigContext, DevEngine, DevEngineOptions, DevModeConfig, DevServer, DevServerEvents, DynamicUserConfig, FlowConfig, FormattedError, HMRClientLogLevel, HMRClientMessage, HMRContext, HMRCustomHandler, HMRCustomMessage, HMRServerError, HMRServerMessage, HmrConfig, InteractiveCommand, InteractiveCommandContext, InteractiveModeOptions, LoadConfigOptions, LoadEnvOptions, MaybePromise, Middlewares, NullValue, type Plugin, type PluginConfig, PluginFlattenConfig, PluginOption, Polyfill, PolyfillType, PolyfillWithCode, PolyfillWithPath, ReactNativeConfig, ReportableEvent, Reporter, ResolvedConfig, ResolverConfig, RolldownConfig, SerializerConfig, ServerOptions, SwcTransformRule, TerminalConfig, TerminalReporter, TransformRule, TransformerConfig, UserConfig, 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 };
947
+ export { assets_d_exports as AssetUtils, AsyncResult, BabelTransformRule, BuildOptions, BuildType, BundleDetails, Bundler, BundlerContext, BundlerState, CodegenConfig, Config, DEFAULT_HOST, DEFAULT_PORT, DEV_SERVER_ASSET_PATH, DefaultConfig, DefineConfigContext, DevEngine, DevEngineOptions, DevModeConfig, type DevRuntime, DevRuntimeInterface, DevRuntimeMessenger, DevRuntimeModule, DevServer, DevServerEvents, DynamicUserConfig, FlowConfig, FormattedError, HMRClientLogLevel, HMRClientMessage, HMRContext, HMRCustomHandler, HMRCustomMessage, HMRServerError, HMRServerMessage, HmrConfig, InteractiveCommand, InteractiveCommandContext, InteractiveModeOptions, LoadConfigOptions, LoadEnvOptions, MaybePromise, Middlewares, NullValue, type Plugin, type PluginConfig, PluginFlattenConfig, PluginOption, Polyfill, PolyfillType, PolyfillWithCode, PolyfillWithPath, ReactNativeConfig, ReportableEvent, Reporter, ResolvedConfig, ResolverConfig, RolldownConfig, SerializerConfig, ServerOptions, SwcTransformRule, TerminalConfig, TerminalReporter, TransformRule, TransformerConfig, UserConfig, 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 };
package/dist/index.js CHANGED
@@ -190,7 +190,7 @@ function generateSourceFromAst(ast, id$1) {
190
190
 
191
191
  //#endregion
192
192
  //#region src/constants.ts
193
- const ROLLIPOP_VERSION = "0.1.0-alpha.8";
193
+ const ROLLIPOP_VERSION = "0.1.0-dev.20260118070035";
194
194
  const GLOBAL_IDENTIFIER = "__ROLLIPOP_GLOBAL__";
195
195
  /**
196
196
  * @see {@link https://github.com/facebook/metro/blob/0.81.x/docs/Configuration.md#resolvermainfields}
@@ -365,7 +365,7 @@ function getDefaultConfig(basePath, mode) {
365
365
  }
366
366
  return {
367
367
  root: basePath,
368
- mode,
368
+ mode: mode ?? "development",
369
369
  entry: "index.js",
370
370
  resolver: {
371
371
  sourceExtensions: DEFAULT_SOURCE_EXTENSIONS,
@@ -650,7 +650,6 @@ const Logo = {
650
650
  //#endregion
651
651
  //#region src/utils/build-options.ts
652
652
  const DEFAULT_BUILD_OPTIONS = {
653
- dev: true,
654
653
  cache: true,
655
654
  minify: false
656
655
  };
@@ -658,7 +657,7 @@ function resolveBuildOptions(config, buildOptions) {
658
657
  if (buildOptions.outfile) buildOptions.outfile = path.resolve(config.root, buildOptions.outfile);
659
658
  if (buildOptions.sourcemap) buildOptions.sourcemap = path.resolve(config.root, buildOptions.sourcemap);
660
659
  return merge(DEFAULT_BUILD_OPTIONS, {
661
- dev: config.mode === "development",
660
+ dev: buildOptions.dev ?? config.mode === "development",
662
661
  ...buildOptions
663
662
  });
664
663
  }
@@ -1123,9 +1122,9 @@ function bindReporter(config, eventSource) {
1123
1122
  return config;
1124
1123
  }
1125
1124
  function resolveHmrConfig(config) {
1126
- if (config.devMode?.hmr == null) return null;
1125
+ if (config.mode !== "development") return null;
1127
1126
  const defaultRuntimeImplements = getDefaultRuntimeImplements();
1128
- if (typeof config.devMode?.hmr === "boolean") return config.devMode.hmr ? defaultRuntimeImplements : null;
1127
+ if (typeof config.devMode.hmr === "boolean") return config.devMode.hmr ? defaultRuntimeImplements : null;
1129
1128
  const { runtimeImplement = defaultRuntimeImplements.runtimeImplement, clientImplement = defaultRuntimeImplements.clientImplement } = config.devMode.hmr;
1130
1129
  return {
1131
1130
  runtimeImplement,
@@ -1141,6 +1140,18 @@ function getDefaultRuntimeImplements() {
1141
1140
  return getDefaultRuntimeImplements.cache;
1142
1141
  }
1143
1142
 
1143
+ //#endregion
1144
+ //#region src/utils/env.ts
1145
+ function defineEnvFromObject(env) {
1146
+ return Object.fromEntries(Object.entries(env).map(([key, value]) => [`import.meta.env.${key}`, asLiteral(value)]));
1147
+ }
1148
+
1149
+ //#endregion
1150
+ //#region src/utils/server.ts
1151
+ function getBaseUrl(host, port, https) {
1152
+ return `${https ? "https" : "http"}://${host}:${port}`;
1153
+ }
1154
+
1144
1155
  //#endregion
1145
1156
  //#region src/core/env.ts
1146
1157
  function loadEnv(options) {
@@ -1351,6 +1362,7 @@ var InMemoryBundle = class {
1351
1362
  //#region src/server/bundler-pool.ts
1352
1363
  var BundlerDevEngine = class extends EventEmitter {
1353
1364
  initializeHandle;
1365
+ isHmrEnabled;
1354
1366
  _id;
1355
1367
  bundle = null;
1356
1368
  buildFailedError = null;
@@ -1363,6 +1375,7 @@ var BundlerDevEngine = class extends EventEmitter {
1363
1375
  this.buildOptions = buildOptions;
1364
1376
  this._id = Bundler.createId(config, buildOptions);
1365
1377
  this.initializeHandle = taskHandler();
1378
+ this.isHmrEnabled = Boolean(config.mode === "development" && config.devMode.hmr);
1366
1379
  this.initialize();
1367
1380
  }
1368
1381
  get id() {
@@ -1388,6 +1401,7 @@ var BundlerDevEngine = class extends EventEmitter {
1388
1401
  host: this.options.server.host,
1389
1402
  port: this.options.server.port,
1390
1403
  onHmrUpdates: (errorOrResult) => {
1404
+ if (!this.isHmrEnabled) return;
1391
1405
  if (errorOrResult instanceof Error) {
1392
1406
  logger$1.error("Failed to handle HMR updates", {
1393
1407
  bundlerId: this.id,
@@ -4449,10 +4463,16 @@ var plugins_exports = /* @__PURE__ */ __exportAll({
4449
4463
  //#endregion
4450
4464
  //#region src/core/rolldown.ts
4451
4465
  resolveRolldownOptions.cache = /* @__PURE__ */ new Map();
4452
- async function resolveRolldownOptions(context, config, buildOptions) {
4466
+ async function resolveRolldownOptions(context, config, buildOptions, devEngineOptions) {
4453
4467
  const cachedOptions = resolveRolldownOptions.cache.get(context.id);
4454
4468
  if (cachedOptions != null) return cachedOptions;
4469
+ const isDevServerMode = config.mode === "development" && context.buildType === "serve";
4470
+ invariant(isDevServerMode ? devEngineOptions != null : true, "devEngineOptions is required in dev server mode");
4455
4471
  const env = loadEnv(config);
4472
+ const builtInEnv = {
4473
+ MODE: config.mode,
4474
+ ...isDevServerMode ? { BASE_URL: getBaseUrl(devEngineOptions.host, devEngineOptions.port, devEngineOptions.https) } : null
4475
+ };
4456
4476
  const { platform, dev: dev$1, cache, minify } = buildOptions;
4457
4477
  const { sourceExtensions, assetExtensions, preferNativePlatform, ...rolldownResolve } = config.resolver;
4458
4478
  const { prelude: preludePaths, polyfills } = config.serializer;
@@ -4479,13 +4499,14 @@ async function resolveRolldownOptions(context, config, buildOptions) {
4479
4499
  global: asIdentifier(GLOBAL_IDENTIFIER),
4480
4500
  "process.env.NODE_ENV": asLiteral(nodeEnvironment(dev$1)),
4481
4501
  "process.env.DEBUG_ROLLIPOP": asLiteral(isDebugEnabled()),
4482
- ...Object.fromEntries(Object.entries(env).map(([key, value]) => [`import.meta.env.${key}`, asLiteral(value)]))
4502
+ ...defineEnvFromObject(env),
4503
+ ...defineEnvFromObject(builtInEnv)
4483
4504
  },
4484
4505
  typescript: { removeClassFieldsWithoutInitializer: true },
4485
4506
  assumptions: { setPublicClassFields: true },
4486
4507
  helpers: { mode: "Runtime" }
4487
4508
  }, rolldownTransform);
4488
- const devServerPlugins = config.mode === "development" && context.buildType === "serve" ? [reactRefreshPlugin()] : null;
4509
+ const devServerPlugins = isDevServerMode ? [reactRefreshPlugin()] : null;
4489
4510
  const { beforeTransform, afterTransform } = getPersistCachePlugins({
4490
4511
  enabled: cache,
4491
4512
  sourceExtensions,
@@ -4600,7 +4621,7 @@ var Bundler = class Bundler {
4600
4621
  const buildType = "serve";
4601
4622
  const resolvedBuildOptions = resolveBuildOptions(config, buildOptions);
4602
4623
  const context = Bundler.createContext(buildType, config, resolvedBuildOptions);
4603
- const { input = {}, output = {} } = await resolveRolldownOptions(context, config, resolvedBuildOptions);
4624
+ const { input = {}, output = {} } = await resolveRolldownOptions(context, config, resolvedBuildOptions, devEngineOptions);
4604
4625
  const devServerOptions = getOverrideOptionsForDevServer(config);
4605
4626
  const devEngine = await dev(merge(input, devServerOptions.input), merge(output, devServerOptions.output), {
4606
4627
  watch: config.watcher,
@@ -4678,7 +4699,7 @@ async function runServer(config, options) {
4678
4699
 
4679
4700
  //#endregion
4680
4701
  //#region package.json
4681
- var version = "0.1.0-alpha.8";
4702
+ var version = "0.1.0-dev.20260118070035";
4682
4703
 
4683
4704
  //#endregion
4684
4705
  //#region src/node/logger.ts
@@ -338,8 +338,9 @@ type WatcherConfig = DevWatchOptions;
338
338
  interface DevModeConfig {
339
339
  /**
340
340
  * Hot Module Replacement configurations.
341
+ * This feature is only available in `development` mode.
341
342
  *
342
- * Defaults to `true`
343
+ * Defaults to `true`.
343
344
  */
344
345
  hmr?: boolean | HmrConfig;
345
346
  }
@@ -406,7 +407,7 @@ type PluginFlattenConfig = Omit<Config, 'plugins'> & {
406
407
  //#region src/config/defaults.d.ts
407
408
  declare function getDefaultConfig(basePath: string, mode?: Config['mode']): {
408
409
  root: string;
409
- mode: "development" | "production" | undefined;
410
+ mode: "development" | "production";
410
411
  entry: string;
411
412
  resolver: {
412
413
  sourceExtensions: string[];
@@ -450,7 +451,7 @@ declare function getDefaultConfig(basePath: string, mode?: Config['mode']): {
450
451
  globalIdentifiers: string[];
451
452
  };
452
453
  devMode: {
453
- hmr: true;
454
+ hmr: boolean | HmrConfig;
454
455
  };
455
456
  terminal: {
456
457
  status: "none" | "compat" | "progress" | undefined;
@@ -340,8 +340,9 @@ type WatcherConfig = DevWatchOptions;
340
340
  interface DevModeConfig {
341
341
  /**
342
342
  * Hot Module Replacement configurations.
343
+ * This feature is only available in `development` mode.
343
344
  *
344
- * Defaults to `true`
345
+ * Defaults to `true`.
345
346
  */
346
347
  hmr?: boolean | HmrConfig;
347
348
  }
@@ -408,7 +409,7 @@ type PluginFlattenConfig = Omit<Config, 'plugins'> & {
408
409
  //#region src/config/defaults.d.ts
409
410
  declare function getDefaultConfig(basePath: string, mode?: Config['mode']): {
410
411
  root: string;
411
- mode: "development" | "production" | undefined;
412
+ mode: "development" | "production";
412
413
  entry: string;
413
414
  resolver: {
414
415
  sourceExtensions: string[];
@@ -452,7 +453,7 @@ declare function getDefaultConfig(basePath: string, mode?: Config['mode']): {
452
453
  globalIdentifiers: string[];
453
454
  };
454
455
  devMode: {
455
- hmr: true;
456
+ hmr: boolean | HmrConfig;
456
457
  };
457
458
  terminal: {
458
459
  status: "none" | "compat" | "progress" | undefined;
@@ -47,6 +47,31 @@ interface HMRServerError {
47
47
  description: string;
48
48
  }[];
49
49
  }
50
+ interface DevRuntimeModule {
51
+ exportsHolder: {
52
+ exports: any;
53
+ };
54
+ id: string;
55
+ exports: any;
56
+ }
57
+ interface DevRuntimeInterface {
58
+ modules: Record<string, DevRuntimeModule>;
59
+ createModuleHotContext(moduleId: string): void;
60
+ applyUpdates(boundaries: [string, string][]): void;
61
+ registerModule(id: string, exportsHolder: DevRuntimeModule['exportsHolder']): void;
62
+ loadExports(id: string): void;
63
+ }
64
+ declare class DevRuntime implements DevRuntimeInterface {
65
+ constructor(messenger: DevRuntimeMessenger);
66
+ modules: Record<string, DevRuntimeModule>;
67
+ createModuleHotContext(moduleId: string): void;
68
+ applyUpdates(boundaries: [string, string][]): void;
69
+ registerModule(id: string, exportsHolder: DevRuntimeModule['exportsHolder']): void;
70
+ loadExports(id: string): void;
71
+ }
72
+ interface DevRuntimeMessenger {
73
+ send(message: HMRClientMessage): void;
74
+ }
50
75
  //#endregion
51
76
  //#region src/runtime.d.ts
52
77
  declare global {
package/package.json CHANGED
@@ -1,18 +1,14 @@
1
1
  {
2
2
  "name": "rollipop",
3
- "version": "0.1.0-alpha.8",
3
+ "version": "0.1.0-dev.20260118070035",
4
4
  "type": "module",
5
5
  "bin": "./bin/index.js",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
6
8
  "exports": {
7
9
  ".": {
8
- "import": {
9
- "types": "./dist/index.d.ts",
10
- "default": "./dist/index.js"
11
- },
12
- "require": {
13
- "types": "./dist/index.d.cts",
14
- "default": "./dist/index.cjs"
15
- }
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
16
12
  },
17
13
  "./commands": {
18
14
  "import": {
@@ -87,8 +83,8 @@
87
83
  "@react-native-community/cli-types": "^20.1.0",
88
84
  "@react-native/babel-plugin-codegen": "^0.83.1",
89
85
  "@react-native/dev-middleware": "^0.83.1",
90
- "@rollipop/rolldown": "0.0.0-beta.1",
91
- "@rollipop/rolldown-pluginutils": "0.0.0-beta.1",
86
+ "@rollipop/rolldown": "0.0.0-beta.2",
87
+ "@rollipop/rolldown-pluginutils": "0.0.0-beta.2",
92
88
  "@svgr/core": "^8.1.0",
93
89
  "@svgr/plugin-jsx": "^8.1.0",
94
90
  "@swc/core": "^1.15.7",
@@ -128,5 +124,6 @@
128
124
  "tsdown": "0.20.0-beta.1",
129
125
  "typescript": "5.9.3",
130
126
  "vitest": "4.0.17"
131
- }
127
+ },
128
+ "stableVersion": "0.1.0-alpha.9"
132
129
  }