@granite-js/mpack 0.1.7 → 0.1.8

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 (91) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/bundler/Bundler.d.ts +1 -1
  3. package/dist/bundler/Bundler.js +2 -2
  4. package/dist/bundler/internal/presets.d.ts +2 -1
  5. package/dist/bundler/internal/presets.js +2 -4
  6. package/dist/bundler/plugins/buildStatusPlugin/buildStatusPlugin.d.ts +2 -2
  7. package/dist/bundler/plugins/buildStatusPlugin/buildStatusPlugin.js +4 -5
  8. package/dist/bundler/plugins/dependencyAliasPlugin/aliasResolver.d.ts +1 -1
  9. package/dist/bundler/plugins/dependencyAliasPlugin/protocolResolver.d.ts +1 -1
  10. package/dist/bundler/plugins/shared/swc.d.ts +1 -1
  11. package/dist/bundler/plugins/transformPlugin/steps/createTransformToHermesSyntaxStep.d.ts +1 -1
  12. package/dist/constants/index.d.ts +1 -1
  13. package/dist/constants/index.js +1 -1
  14. package/dist/index.d.ts +3 -6
  15. package/dist/index.js +9 -9
  16. package/dist/metro/build.d.ts +17 -0
  17. package/dist/metro/build.js +104 -0
  18. package/dist/metro/getMetroConfig.d.ts +2 -13
  19. package/dist/metro/getMetroConfig.js +3 -6
  20. package/dist/metro/index.d.ts +1 -2
  21. package/dist/metro/index.js +20 -3
  22. package/dist/operations/build.d.ts +15 -0
  23. package/dist/operations/{runBundle.js → build.js} +51 -37
  24. package/dist/operations/createDebuggerMiddleware.d.ts +1 -2
  25. package/dist/operations/createDebuggerMiddleware.js +4 -4
  26. package/dist/operations/experimental/serve.d.ts +11 -0
  27. package/dist/operations/experimental/{runServer.js → serve.js} +21 -22
  28. package/dist/operations/index.d.ts +3 -3
  29. package/dist/operations/index.js +23 -6
  30. package/dist/operations/openDebugger.d.ts +1 -1
  31. package/dist/operations/openDebugger.js +3 -2
  32. package/dist/operations/serve.d.ts +10 -0
  33. package/dist/operations/{runServer.js → serve.js} +11 -13
  34. package/dist/plugins/statusPlugin.js +1 -1
  35. package/dist/server/DevServer.js +8 -9
  36. package/dist/server/helpers/createBundlerForDevServer.d.ts +3 -5
  37. package/dist/server/helpers/createBundlerForDevServer.js +7 -20
  38. package/dist/server/helpers/mergeBundles.d.ts +1 -1
  39. package/dist/server/plugins/serveBundlePlugin.d.ts +2 -2
  40. package/dist/server/plugins/symbolicatePlugin/symbolicatePlugin.d.ts +2 -2
  41. package/dist/server/types.d.ts +9 -13
  42. package/dist/types/BundlerConfig.d.ts +1 -34
  43. package/dist/types/Id.d.ts +3 -0
  44. package/dist/{bundler/types.js → types/Id.js} +2 -2
  45. package/dist/types/Plugin.d.ts +2 -2
  46. package/dist/types/index.d.ts +1 -5
  47. package/dist/types/index.js +2 -10
  48. package/dist/utils/getId.js +1 -8
  49. package/dist/utils/progressBar.d.ts +1 -1
  50. package/dist/utils/writeBundle.d.ts +1 -1
  51. package/package.json +5 -4
  52. package/dist/bundler/types.d.ts +0 -17
  53. package/dist/metro/runBuild.d.ts +0 -12
  54. package/dist/metro/runBuild.js +0 -66
  55. package/dist/metro/runtime.d.ts +0 -3
  56. package/dist/metro/runtime.js +0 -54
  57. package/dist/metro/types.d.ts +0 -92
  58. package/dist/metro/types.js +0 -16
  59. package/dist/operations/experimental/runServer.d.ts +0 -15
  60. package/dist/operations/runBundle.d.ts +0 -12
  61. package/dist/operations/runServer.d.ts +0 -15
  62. package/dist/types/BuildConfig.d.ts +0 -183
  63. package/dist/types/BuildConfig.js +0 -16
  64. package/dist/types/Config.d.ts +0 -12
  65. package/dist/types/Config.js +0 -16
  66. package/dist/types/DevServerConfig.d.ts +0 -4
  67. package/dist/types/DevServerConfig.js +0 -16
  68. package/dist/types/ServicesConfig.d.ts +0 -2
  69. package/dist/types/ServicesConfig.js +0 -16
  70. package/dist/types/TaskConfig.d.ts +0 -11
  71. package/dist/types/TaskConfig.js +0 -16
  72. package/dist/types/schemas/buildConfigSchema.d.ts +0 -198
  73. package/dist/types/schemas/buildConfigSchema.js +0 -70
  74. package/dist/types/schemas/bundlerConfigSchema.d.ts +0 -3
  75. package/dist/types/schemas/bundlerConfigSchema.js +0 -51
  76. package/dist/types/schemas/configSchema.d.ts +0 -3
  77. package/dist/types/schemas/configSchema.js +0 -50
  78. package/dist/types/schemas/devServerConfigSchema.d.ts +0 -3
  79. package/dist/types/schemas/devServerConfigSchema.js +0 -42
  80. package/dist/types/schemas/index.d.ts +0 -6
  81. package/dist/types/schemas/index.js +0 -32
  82. package/dist/types/schemas/servicesConfigSchema.d.ts +0 -3
  83. package/dist/types/schemas/servicesConfigSchema.js +0 -48
  84. package/dist/types/schemas/taskConfigSchema.d.ts +0 -3
  85. package/dist/types/schemas/taskConfigSchema.js +0 -44
  86. package/dist/utils/mergeBanners.d.ts +0 -6
  87. package/dist/utils/mergeBanners.js +0 -35
  88. package/dist/utils/mergeBuildConfigs.d.ts +0 -2
  89. package/dist/utils/mergeBuildConfigs.js +0 -59
  90. package/dist/utils/mergeInject.d.ts +0 -3
  91. package/dist/utils/mergeInject.js +0 -30
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @granite-js/mpack
2
2
 
3
+ ## 0.1.8
4
+
5
+ ### Patch Changes
6
+
7
+ - b69366c: improve config structure
8
+ - Updated dependencies [b69366c]
9
+ - @granite-js/plugin-core@0.1.8
10
+ - @granite-js/devtools-frontend@0.1.8
11
+ - @granite-js/utils@0.1.8
12
+
3
13
  ## 0.1.7
4
14
 
5
15
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import type { BuildResult } from './types';
1
+ import type { BuildResult } from '@granite-js/plugin-core';
2
2
  import { BundlerConfig, INTERNAL__Id } from '../types';
3
3
  import { Plugin } from '../types/Plugin';
4
4
  export declare class Bundler {
@@ -145,8 +145,8 @@ class Bundler {
145
145
  (0, import_plugins.requireContextPlugin)(),
146
146
  (0, import_plugins.transformPlugin)({
147
147
  context: pluginContext,
148
- transformSync: buildConfig.transformSync,
149
- transformAsync: buildConfig.transformAsync
148
+ transformSync: buildConfig.transformer?.transformSync,
149
+ transformAsync: buildConfig.transformer?.transformAsync
150
150
  }),
151
151
  ...esbuildOptions?.plugins ?? []
152
152
  ].filter(import_es_toolkit.isNotNil)
@@ -1,4 +1,5 @@
1
- import { BuildConfig, BundlerConfig } from '../../types';
1
+ import { type BuildConfig } from '@granite-js/plugin-core';
2
+ import type { BundlerConfig } from '../../types';
2
3
  export declare function getReactNativeSetupScripts({ rootDir }: {
3
4
  rootDir: string;
4
5
  }): string[];
@@ -35,7 +35,7 @@ __export(presets_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(presets_exports);
37
37
  var import_path = __toESM(require("path"));
38
- var import_mergeBuildConfigs = require("../../utils/mergeBuildConfigs");
38
+ var import_plugin_core = require("@granite-js/plugin-core");
39
39
  function getReactNativeSetupScripts({ rootDir }) {
40
40
  const reactNativePath = import_path.default.dirname(
41
41
  require.resolve("react-native/package.json", {
@@ -62,7 +62,7 @@ function defineGlobalVariables({ dev }) {
62
62
  };
63
63
  }
64
64
  function combineWithBaseBuildConfig(config, context) {
65
- return (0, import_mergeBuildConfigs.mergeBuildConfigs)(
65
+ return (0, import_plugin_core.mergeBuildConfigs)(
66
66
  {
67
67
  entry: config.buildConfig.entry,
68
68
  outfile: config.buildConfig.outfile,
@@ -73,8 +73,6 @@ function combineWithBaseBuildConfig(config, context) {
73
73
  banner: {
74
74
  js: [
75
75
  globalVariables({ dev: context.dev }),
76
- "global.__granite = global.__granite || {};",
77
- `global.__granite.app = { name: ${JSON.stringify(config.appName)}, scheme: ${JSON.stringify(config.scheme)} };`,
78
76
  // symbol-asynciterator polyfill (ES5)
79
77
  `(function(){if(typeof Symbol!=="undefined"&&!Symbol.asyncIterator){Symbol.asyncIterator=Symbol.for("@@asyncIterator")}})();`
80
78
  ].join("\n")
@@ -1,6 +1,6 @@
1
+ import type { BuildResult } from '@granite-js/plugin-core';
1
2
  import * as esbuild from 'esbuild';
2
- import { BuildResult } from '../../types';
3
- import { PluginOptions } from '../types';
3
+ import type { PluginOptions } from '../types';
4
4
  export interface BuildStatusPluginOptions {
5
5
  onPrepare: () => void | Promise<void>;
6
6
  onStart: () => void | Promise<void>;
@@ -31,11 +31,11 @@ function buildStatusPlugin({ context, ...hooks }) {
31
31
  let buildStartedAt = 0;
32
32
  let moduleCount = 0;
33
33
  build.onStart(async () => {
34
- import_logger.logger.debug("\uBE4C\uB4DC \uC900\uBE44 \uC911", { id: context.id });
34
+ import_logger.logger.debug("Preparing build", { id: context.id });
35
35
  await hooks.onPrepare();
36
36
  moduleCount = 0;
37
37
  buildStartedAt = performance.now();
38
- import_logger.logger.debug("\uBE4C\uB4DC \uC2DC\uC791", { id: context.id, buildStartedAt });
38
+ import_logger.logger.debug("Build started", { id: context.id, buildStartedAt });
39
39
  await hooks.onStart();
40
40
  });
41
41
  build.onLoad({ filter: /.*/ }, async () => {
@@ -44,13 +44,12 @@ function buildStatusPlugin({ context, ...hooks }) {
44
44
  });
45
45
  build.onEnd(async (result) => {
46
46
  const endAt = performance.now();
47
- const { tag, buildConfig } = context.config;
47
+ const { buildConfig } = context.config;
48
48
  const { outfile, sourcemapOutfile, platform, extra } = buildConfig;
49
49
  const { source, sourcemap } = (0, import_getBundleOutputs.getBundleOutputs)(outfile, result);
50
50
  const duration = endAt - buildStartedAt;
51
51
  if (source && sourcemap) {
52
52
  Object.defineProperties(result, {
53
- tag: { value: tag, enumerable: true },
54
53
  bundle: { value: { source, sourcemap }, enumerable: true },
55
54
  outfile: { value: outfile, enumerable: true },
56
55
  sourcemapOutfile: { value: sourcemapOutfile ?? (0, import_getSourcemapName.getSourcemapName)(outfile), enumerable: true },
@@ -60,7 +59,7 @@ function buildStatusPlugin({ context, ...hooks }) {
60
59
  duration: { value: duration, enumerable: true },
61
60
  size: { value: source.contents.byteLength, enumerable: true }
62
61
  });
63
- import_logger.logger.debug("\uBE4C\uB4DC \uC644\uB8CC", { id: context.id, tag });
62
+ import_logger.logger.debug("Build completed", { id: context.id });
64
63
  await hooks.onEnd(result);
65
64
  } else {
66
65
  throw new Error("invalid bundle result");
@@ -1,3 +1,3 @@
1
+ import type { AliasConfig } from '@granite-js/plugin-core';
1
2
  import type { PluginBuild } from 'esbuild';
2
- import type { AliasConfig } from '../../../types';
3
3
  export declare function setupAliasResolver(build: PluginBuild, rootDir: string, aliasConfig: AliasConfig[]): void;
@@ -1,3 +1,3 @@
1
+ import type { ProtocolConfig } from '@granite-js/plugin-core';
1
2
  import type { PluginBuild } from 'esbuild';
2
- import type { ProtocolConfig } from '../../../types';
3
3
  export declare function setupProtocolResolver(build: PluginBuild, protocolConfig: ProtocolConfig): void;
@@ -1,5 +1,5 @@
1
+ import type { AliasConfig } from '@granite-js/plugin-core';
1
2
  import type { JscConfig } from '@swc/core';
2
- import type { AliasConfig } from '../../../types';
3
3
  /**
4
4
  * `@swc/helpers`를 사용하여 번들 크기를 최적화 하기 위한 구성입니다.
5
5
  *
@@ -1,5 +1,5 @@
1
+ import type { BuildConfig } from '@granite-js/plugin-core';
1
2
  import { AsyncTransformStep } from '../../../../transformer/TransformPipeline';
2
- import { BuildConfig } from '../../../../types';
3
3
  interface TransformToHermesSyntaxStepConfig {
4
4
  dev: boolean;
5
5
  additionalSwcOptions?: BuildConfig['swc'];
@@ -5,7 +5,7 @@ export declare const MPACK_DATA_DIR: string;
5
5
  export declare const MPACK_CACHE_DIR: string;
6
6
  export declare const SOURCE_EXTENSIONS: readonly [".tsx", ".ts", ".jsx", ".js", ".json"];
7
7
  export declare const ASSET_EXTENSIONS: readonly [".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg"];
8
- export declare const DEV_SERVER_DEFAULT_HOST = "localhost";
8
+ export declare const DEV_SERVER_DEFAULT_HOST = "0.0.0.0";
9
9
  export declare const DEV_SERVER_DEFAULT_PORT = 8081;
10
10
  /**
11
11
  * 제거 필요: `SHARED_BUNDLE_NAME`, `SERVICE_BUNDLE_NAME` -> `BUNDLE_NAME`
@@ -59,7 +59,7 @@ const MPACK_DATA_DIR = path.join(TEMP_DIR, "data");
59
59
  const MPACK_CACHE_DIR = path.join(TEMP_DIR, "cache");
60
60
  const SOURCE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".json"];
61
61
  const ASSET_EXTENSIONS = [".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg"];
62
- const DEV_SERVER_DEFAULT_HOST = "localhost";
62
+ const DEV_SERVER_DEFAULT_HOST = "0.0.0.0";
63
63
  const DEV_SERVER_DEFAULT_PORT = 8081;
64
64
  const SHARED_BUNDLE_NAME = (0, import_getBundleName.getBundleName)("index");
65
65
  const SERVICE_BUNDLE_NAME = (0, import_getBundleName.getBundleName)("service");
package/dist/index.d.ts CHANGED
@@ -1,9 +1,6 @@
1
1
  export { Bundler } from './bundler';
2
2
  export { DevServer } from './server';
3
- export { getMetroConfig, runBuild as metroBuild, type MetroConfig } from './metro';
3
+ export { BuildUtils, runServer, EXPERIMENTAL__server } from './operations';
4
+ export { getMetroConfig, MetroBuildUtils } from './metro';
4
5
  export { DEV_SERVER_DEFAULT_HOST, DEV_SERVER_DEFAULT_PORT, SHARED_BUNDLE_NAME, SERVICE_BUNDLE_NAME, BUNDLE_NAME, } from './constants';
5
- export * from './operations';
6
- export * from './types/schemas';
7
- export * from './types';
8
- export type { AdditionalMetroConfig } from './metro/getMetroConfig';
9
- export type { BuildResult } from './bundler/types';
6
+ export type * from './types';
package/dist/index.js CHANGED
@@ -15,40 +15,40 @@ var __copyProps = (to, from, except, desc) => {
15
15
  }
16
16
  return to;
17
17
  };
18
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
19
  var index_exports = {};
21
20
  __export(index_exports, {
22
21
  BUNDLE_NAME: () => import_constants.BUNDLE_NAME,
22
+ BuildUtils: () => import_operations.BuildUtils,
23
23
  Bundler: () => import_bundler.Bundler,
24
24
  DEV_SERVER_DEFAULT_HOST: () => import_constants.DEV_SERVER_DEFAULT_HOST,
25
25
  DEV_SERVER_DEFAULT_PORT: () => import_constants.DEV_SERVER_DEFAULT_PORT,
26
26
  DevServer: () => import_server.DevServer,
27
+ EXPERIMENTAL__server: () => import_operations.EXPERIMENTAL__server,
28
+ MetroBuildUtils: () => import_metro.MetroBuildUtils,
27
29
  SERVICE_BUNDLE_NAME: () => import_constants.SERVICE_BUNDLE_NAME,
28
30
  SHARED_BUNDLE_NAME: () => import_constants.SHARED_BUNDLE_NAME,
29
31
  getMetroConfig: () => import_metro.getMetroConfig,
30
- metroBuild: () => import_metro.runBuild
32
+ runServer: () => import_operations.runServer
31
33
  });
32
34
  module.exports = __toCommonJS(index_exports);
33
35
  var import_bundler = require("./bundler");
34
36
  var import_server = require("./server");
37
+ var import_operations = require("./operations");
35
38
  var import_metro = require("./metro");
36
39
  var import_constants = require("./constants");
37
- __reExport(index_exports, require("./operations"), module.exports);
38
- __reExport(index_exports, require("./types/schemas"), module.exports);
39
- __reExport(index_exports, require("./types"), module.exports);
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  BUNDLE_NAME,
43
+ BuildUtils,
43
44
  Bundler,
44
45
  DEV_SERVER_DEFAULT_HOST,
45
46
  DEV_SERVER_DEFAULT_PORT,
46
47
  DevServer,
48
+ EXPERIMENTAL__server,
49
+ MetroBuildUtils,
47
50
  SERVICE_BUNDLE_NAME,
48
51
  SHARED_BUNDLE_NAME,
49
52
  getMetroConfig,
50
- metroBuild,
51
- ...require("./operations"),
52
- ...require("./types/schemas"),
53
- ...require("./types")
53
+ runServer
54
54
  });
@@ -0,0 +1,17 @@
1
+ import { BuildResult, type CompleteGraniteConfig } from '@granite-js/plugin-core';
2
+ interface CommonMetroBuildOptions {
3
+ outfile?: string;
4
+ dev?: boolean;
5
+ minify?: boolean;
6
+ platform: 'ios' | 'android';
7
+ }
8
+ export interface MetroBuildOptions extends CommonMetroBuildOptions {
9
+ config: CompleteGraniteConfig;
10
+ }
11
+ export interface MetroBuildAllOptions {
12
+ config: CompleteGraniteConfig;
13
+ concurrency?: number;
14
+ }
15
+ export declare function build({ config, ...options }: MetroBuildOptions): Promise<BuildResult>;
16
+ export declare function buildAll(optionsList: CommonMetroBuildOptions[], { config, concurrency }: MetroBuildAllOptions): Promise<BuildResult[]>;
17
+ export {};
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var build_exports = {};
30
+ __export(build_exports, {
31
+ build: () => build,
32
+ buildAll: () => buildAll
33
+ });
34
+ module.exports = __toCommonJS(build_exports);
35
+ var import_path = __toESM(require("path"));
36
+ var import_plugin_core = require("@granite-js/plugin-core");
37
+ var import_es_toolkit = require("es-toolkit");
38
+ var import_getMetroConfig = require("./getMetroConfig");
39
+ var import_src = __toESM(require("../vendors/metro/src"));
40
+ async function build({ config, ...options }) {
41
+ const driver = (0, import_plugin_core.createPluginHooksDriver)(config);
42
+ await driver.build.pre();
43
+ const buildResult = await buildImpl(config, options);
44
+ await driver.build.post({
45
+ buildResults: [buildResult]
46
+ });
47
+ return buildResult;
48
+ }
49
+ async function buildAll(optionsList, { config, concurrency = 2 }) {
50
+ const buildResults = [];
51
+ const semaphore = new import_es_toolkit.Semaphore(Math.min(concurrency, optionsList.length));
52
+ const driver = (0, import_plugin_core.createPluginHooksDriver)(config);
53
+ await driver.build.pre();
54
+ for (const options of optionsList) {
55
+ await semaphore.acquire();
56
+ try {
57
+ const buildResult = await buildImpl(config, options);
58
+ buildResults.push(buildResult);
59
+ } catch {
60
+ semaphore.release();
61
+ }
62
+ }
63
+ await driver.build.post({ buildResults });
64
+ return buildResults;
65
+ }
66
+ async function buildImpl(config, { platform, outfile = `bundle.${platform}.js`, minify = false, dev = true }) {
67
+ const metroConfig = await (0, import_getMetroConfig.getMetroConfig)({ rootPath: config.cwd }, config.metro);
68
+ const out = import_path.default.join(config.outdir, outfile);
69
+ await import_src.default.runBuild(metroConfig, {
70
+ entry: config.entryFile,
71
+ out,
72
+ platform,
73
+ minify,
74
+ dev
75
+ });
76
+ return buildResultShim(config, { outfile, platform, minify, dev });
77
+ }
78
+ function buildResultShim(config, options) {
79
+ const unsupportedField = new Proxy({}, {
80
+ get: (_, key) => {
81
+ throw new Error(`Unsupported field: ${key.toString()}`);
82
+ }
83
+ });
84
+ return {
85
+ platform: options.platform,
86
+ bundle: unsupportedField,
87
+ outfile: import_path.default.join(config.outdir, options.outfile),
88
+ outputFiles: [{ path: options.outfile, contents: new Uint8Array(), hash: "", text: "" }],
89
+ sourcemapOutfile: "",
90
+ warnings: [],
91
+ errors: [],
92
+ extra: unsupportedField,
93
+ mangleCache: unsupportedField,
94
+ metafile: unsupportedField,
95
+ size: 0,
96
+ duration: 0,
97
+ totalModuleCount: 0
98
+ };
99
+ }
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ build,
103
+ buildAll
104
+ });
@@ -1,16 +1,5 @@
1
- import type * as babel from '@babel/core';
2
- import type { MetroConfig } from './types';
3
- import type { ReportableEvent } from '../vendors/metro/src/lib/ReportableEvent';
1
+ import type { AdditionalMetroConfig } from '@granite-js/plugin-core';
4
2
  export interface GetMetroConfig {
5
3
  rootPath: string;
6
- appName: string;
7
- scheme: string;
8
4
  }
9
- export interface AdditionalMetroConfig extends MetroConfig {
10
- transformSync?: (id: string, code: string) => string;
11
- babelConfig?: babel.TransformOptions;
12
- reporter?: {
13
- update: (event: ReportableEvent) => void;
14
- };
15
- }
16
- export declare function getMetroConfig({ rootPath, appName, scheme }: GetMetroConfig, additionalConfig?: AdditionalMetroConfig): Promise<any>;
5
+ export declare function getMetroConfig({ rootPath }: GetMetroConfig, additionalConfig?: AdditionalMetroConfig): Promise<any>;
@@ -35,7 +35,6 @@ var import_path = __toESM(require("path"));
35
35
  var import_utils = require("@granite-js/utils");
36
36
  var import_enhancedResolver = require("./enhancedResolver");
37
37
  var import_getMonorepoRoot = require("./getMonorepoRoot");
38
- var import_runtime = require("./runtime");
39
38
  var import_constants = require("../constants");
40
39
  var import_defaults = require("../vendors/metro-config/src/defaults");
41
40
  var import_exclusionList = __toESM(require("../vendors/metro-config/src/defaults/exclusionList"));
@@ -59,12 +58,11 @@ const INTERNAL_CALLSITES_REGEX = new RegExp(
59
58
  "^\\[native code\\]$"
60
59
  ].join("|")
61
60
  );
62
- async function getMetroConfig({ rootPath, appName, scheme }, additionalConfig) {
61
+ async function getMetroConfig({ rootPath }, additionalConfig) {
63
62
  const defaultConfig = (0, import_defaults.getDefaultValues)(rootPath);
64
63
  const reactNativePath = import_path.default.dirname(resolveFromRoot("react-native/package.json", rootPath));
65
64
  const resolvedRootPath = await (0, import_getMonorepoRoot.getMonorepoRoot)(rootPath);
66
65
  const packageRootPath = await (0, import_utils.getPackageRoot)();
67
- const { path: envFilePath } = await (0, import_runtime.writeEnvScript)(packageRootPath, appName, scheme);
68
66
  return (0, import_loadConfig.mergeConfig)(defaultConfig, {
69
67
  watchFolders: [resolvedRootPath, packageRootPath],
70
68
  transformerPath: resolveVendors("metro-transform-worker/src"),
@@ -105,9 +103,8 @@ async function getMetroConfig({ rootPath, appName, scheme }, additionalConfig) {
105
103
  serializer: {
106
104
  getModulesRunBeforeMainModule: () => [resolveFromRoot("react-native/Libraries/Core/InitializeCore", rootPath)],
107
105
  getPolyfills: () => [
108
- envFilePath,
109
- ...additionalConfig?.serializer?.getPolyfills?.() ?? [],
110
- ...require(import_path.default.join(reactNativePath, "rn-get-polyfills"))()
106
+ ...require(import_path.default.join(reactNativePath, "rn-get-polyfills"))(),
107
+ ...additionalConfig?.serializer?.getPolyfills?.() ?? []
111
108
  ]
112
109
  },
113
110
  symbolicator: {
@@ -1,3 +1,2 @@
1
1
  export * from './getMetroConfig';
2
- export * from './runBuild';
3
- export type { MetroConfig } from './types';
2
+ export * as MetroBuildUtils from './build';
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
6
12
  var __copyProps = (to, from, except, desc) => {
7
13
  if (from && typeof from === "object" || typeof from === "function") {
8
14
  for (let key of __getOwnPropNames(from))
@@ -12,13 +18,24 @@ var __copyProps = (to, from, except, desc) => {
12
18
  return to;
13
19
  };
14
20
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
15
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
30
  var metro_exports = {};
31
+ __export(metro_exports, {
32
+ MetroBuildUtils: () => MetroBuildUtils
33
+ });
17
34
  module.exports = __toCommonJS(metro_exports);
18
35
  __reExport(metro_exports, require("./getMetroConfig"), module.exports);
19
- __reExport(metro_exports, require("./runBuild"), module.exports);
36
+ var MetroBuildUtils = __toESM(require("./build"));
20
37
  // Annotate the CommonJS export names for ESM import in node:
21
38
  0 && (module.exports = {
22
- ...require("./getMetroConfig"),
23
- ...require("./runBuild")
39
+ MetroBuildUtils,
40
+ ...require("./getMetroConfig")
24
41
  });
@@ -0,0 +1,15 @@
1
+ import { type BuildConfig, type BuildResult, type CompleteGraniteConfig } from '@granite-js/plugin-core';
2
+ import type { BundlerConfig, PluginFactory } from '../types';
3
+ type CommonBuildOptions = Omit<BundlerConfig, 'rootDir' | 'buildConfig'> & Pick<BuildConfig, 'platform' | 'outfile'>;
4
+ export interface BuildOptions extends CommonBuildOptions {
5
+ config: CompleteGraniteConfig;
6
+ plugins?: PluginFactory[];
7
+ }
8
+ export interface BuildAllOptions {
9
+ config: CompleteGraniteConfig;
10
+ concurrency?: number;
11
+ plugins?: PluginFactory[];
12
+ }
13
+ export declare function build({ config, plugins, ...options }: BuildOptions): Promise<BuildResult>;
14
+ export declare function buildAll(optionsList: CommonBuildOptions[], { config, plugins, concurrency }: BuildAllOptions): Promise<BuildResult[]>;
15
+ export {};
@@ -26,58 +26,72 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var runBundle_exports = {};
30
- __export(runBundle_exports, {
31
- runBundle: () => runBundle
29
+ var build_exports = {};
30
+ __export(build_exports, {
31
+ build: () => build,
32
+ buildAll: () => buildAll
32
33
  });
33
- module.exports = __toCommonJS(runBundle_exports);
34
+ module.exports = __toCommonJS(build_exports);
34
35
  var fs = __toESM(require("fs/promises"));
35
36
  var path = __toESM(require("path"));
36
- var import_semaphore = require("@shopify/semaphore");
37
+ var import_plugin_core = require("@granite-js/plugin-core");
37
38
  var import_es_toolkit = require("es-toolkit");
38
39
  var import_bundler = require("../bundler");
39
40
  var import_performance = require("../performance");
40
41
  var import_writeBundle = require("../utils/writeBundle");
41
- async function runBundle(options) {
42
- const config = options.config;
43
- const semaphore = new import_semaphore.Semaphore(config.concurrency ?? 4);
44
- const buildResults = await Promise.all(
45
- config.tasks.map(async ({ tag, build }) => {
46
- if (typeof options.tag === "string" && tag !== options.tag) {
47
- return;
48
- }
49
- const bundler = new import_bundler.Bundler({
50
- tag,
51
- buildConfig: build,
52
- appName: config.appName,
53
- scheme: config.scheme,
54
- services: config.services,
55
- dev: options.dev,
56
- metafile: options.metafile,
57
- rootDir: options.rootDir,
58
- cache: options.cache
59
- });
60
- if (options.plugins) {
61
- options.plugins.forEach((fn) => bundler.addPlugin(fn()));
62
- }
63
- const permit = await semaphore.acquire();
42
+ async function build({ config, plugins = [], ...options }) {
43
+ const driver = (0, import_plugin_core.createPluginHooksDriver)(config);
44
+ await driver.build.pre();
45
+ const buildResult = await buildImpl(config, plugins, options);
46
+ await driver.build.post({ buildResults: [buildResult] });
47
+ return buildResult;
48
+ }
49
+ async function buildAll(optionsList, { config, plugins = [], concurrency = 2 }) {
50
+ const buildResults = [];
51
+ const semaphore = new import_es_toolkit.Semaphore(Math.min(concurrency, optionsList.length));
52
+ const driver = (0, import_plugin_core.createPluginHooksDriver)(config);
53
+ await driver.build.pre();
54
+ await Promise.all(
55
+ optionsList.map(async (options) => {
56
+ await semaphore.acquire();
64
57
  try {
65
- const result = await bundler.build();
66
- await (0, import_writeBundle.writeBundle)(result.outfile, result.bundle);
67
- return result;
68
- } finally {
69
- await permit.release();
58
+ const buildResult = await buildImpl(config, plugins, options);
59
+ buildResults.push(buildResult);
60
+ } catch {
61
+ semaphore.release();
70
62
  }
71
63
  })
72
- ).then((results) => results.filter(import_es_toolkit.isNotNil));
64
+ );
65
+ await driver.build.post({ buildResults });
66
+ return buildResults;
67
+ }
68
+ async function buildImpl(config, plugins, { platform, outfile = `bundle.${platform}.js`, cache = true, dev = true, metafile = false }) {
69
+ const resolvedOutfile = path.join(config.outdir, outfile);
70
+ const bundler = new import_bundler.Bundler({
71
+ rootDir: config.cwd,
72
+ cache,
73
+ dev,
74
+ metafile,
75
+ buildConfig: {
76
+ platform,
77
+ outfile: resolvedOutfile,
78
+ ...config.build
79
+ }
80
+ });
81
+ for (const plugin of plugins) {
82
+ bundler.addPlugin(plugin());
83
+ }
84
+ const buildResult = await bundler.build();
85
+ await (0, import_writeBundle.writeBundle)(buildResult.outfile, buildResult.bundle);
73
86
  const performanceSummary = import_performance.Performance.getSummary();
74
87
  if (performanceSummary != null) {
75
88
  (0, import_performance.printSummary)(performanceSummary);
76
- await fs.writeFile(path.join(options.rootDir, "perf.json"), JSON.stringify(performanceSummary, null, 2), "utf-8");
89
+ await fs.writeFile(path.join(config.cwd, "perf.json"), JSON.stringify(performanceSummary, null, 2), "utf-8");
77
90
  }
78
- return buildResults;
91
+ return buildResult;
79
92
  }
80
93
  // Annotate the CommonJS export names for ESM import in node:
81
94
  0 && (module.exports = {
82
- runBundle
95
+ build,
96
+ buildAll
83
97
  });
@@ -1,10 +1,9 @@
1
1
  import connect from 'connect';
2
2
  interface DebuggerMiddlewareConfig {
3
- host?: string;
4
3
  port: number;
5
4
  broadcastMessage: (method: string, params?: Record<string, unknown>) => void;
6
5
  }
7
- export declare function createDebuggerMiddleware({ host, port, broadcastMessage }: DebuggerMiddlewareConfig): {
6
+ export declare function createDebuggerMiddleware({ port, broadcastMessage }: DebuggerMiddlewareConfig): {
8
7
  middleware: connect.Server;
9
8
  enableStdinWatchMode: () => void;
10
9
  };
@@ -45,7 +45,7 @@ var import_vendors = require("../vendors");
45
45
  const debug = (0, import_debug.default)("cli:start");
46
46
  const { InspectorProxy } = (0, import_vendors.getModule)("metro-inspector-proxy");
47
47
  const chromeInstanceMap = /* @__PURE__ */ new Map();
48
- function createDebuggerMiddleware({ host, port, broadcastMessage }) {
48
+ function createDebuggerMiddleware({ port, broadcastMessage }) {
49
49
  const middleware = (0, import_connect.default)().use(`/${import_constants.DEBUGGER_FRONTEND_PATH}`, (0, import_serve_static.default)(import_path.default.resolve(import_devtools_frontend.default)));
50
50
  function enableStdinWatchMode() {
51
51
  if (!process.stdout.isTTY || process.stdin.setRawMode == null) {
@@ -80,14 +80,14 @@ function createDebuggerMiddleware({ host, port, broadcastMessage }) {
80
80
  broadcastMessage("devMenu");
81
81
  break;
82
82
  case "j":
83
- openReactNativeDebugger(host, port);
83
+ openReactNativeDebugger(port);
84
84
  break;
85
85
  }
86
86
  });
87
87
  }
88
88
  return { middleware, enableStdinWatchMode };
89
89
  }
90
- async function openReactNativeDebugger(host = "localhost", port) {
90
+ async function openReactNativeDebugger(port) {
91
91
  const connectedDevices = Array.from(InspectorProxy.devices.entries());
92
92
  let targetDevice;
93
93
  for (const [id, device] of connectedDevices) {
@@ -113,7 +113,7 @@ async function openReactNativeDebugger(host = "localhost", port) {
113
113
  }
114
114
  console.log(`Opening debugger for '${targetDevice.name}'...`);
115
115
  chromeInstanceMap.get(targetDevice.id)?.kill();
116
- (0, import_openDebugger.openDebugger)(host, port, targetDevice.id.toString()).then((chrome) => {
116
+ (0, import_openDebugger.openDebugger)(port, targetDevice.id.toString()).then((chrome) => {
117
117
  chromeInstanceMap.set(targetDevice.id, chrome);
118
118
  }).catch((error) => {
119
119
  if (error.message.includes("ECONNREFUSED")) {
@@ -0,0 +1,11 @@
1
+ import { CompleteGraniteConfig } from '@granite-js/plugin-core';
2
+ interface RunServerArgs {
3
+ config: CompleteGraniteConfig;
4
+ host?: string;
5
+ port?: number;
6
+ onServerReady?: () => Promise<void> | void;
7
+ }
8
+ export declare function EXPERIMENTAL__server({ config, host, port, onServerReady, }: RunServerArgs): Promise<{
9
+ cleanup: () => Promise<void>;
10
+ }>;
11
+ export {};