@granite-js/mpack 0.1.6 → 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.
- package/CHANGELOG.md +18 -0
- package/dist/bundler/Bundler.d.ts +1 -1
- package/dist/bundler/Bundler.js +7 -2
- package/dist/bundler/internal/presets.d.ts +19 -0
- package/dist/bundler/internal/presets.js +103 -0
- package/dist/bundler/plugins/buildStatusPlugin/buildStatusPlugin.d.ts +2 -2
- package/dist/bundler/plugins/buildStatusPlugin/buildStatusPlugin.js +4 -5
- package/dist/bundler/plugins/dependencyAliasPlugin/aliasResolver.d.ts +1 -1
- package/dist/bundler/plugins/dependencyAliasPlugin/protocolResolver.d.ts +1 -1
- package/dist/bundler/plugins/shared/swc.d.ts +1 -1
- package/dist/bundler/plugins/transformPlugin/steps/createTransformToHermesSyntaxStep.d.ts +1 -1
- package/dist/constants/index.d.ts +2 -2
- package/dist/constants/index.js +4 -4
- package/dist/index.d.ts +3 -8
- package/dist/index.js +9 -15
- package/dist/metro/build.d.ts +17 -0
- package/dist/metro/build.js +104 -0
- package/dist/metro/getMetroConfig.d.ts +2 -9
- package/dist/metro/getMetroConfig.js +4 -6
- package/dist/metro/index.d.ts +1 -2
- package/dist/metro/index.js +20 -3
- package/dist/operations/build.d.ts +15 -0
- package/dist/operations/{runBundle.js → build.js} +51 -51
- package/dist/operations/createDebuggerMiddleware.d.ts +1 -2
- package/dist/operations/createDebuggerMiddleware.js +4 -4
- package/dist/operations/experimental/serve.d.ts +11 -0
- package/dist/operations/experimental/{runServer.js → serve.js} +21 -25
- package/dist/operations/index.d.ts +3 -3
- package/dist/operations/index.js +23 -6
- package/dist/operations/openDebugger.d.ts +1 -1
- package/dist/operations/openDebugger.js +3 -2
- package/dist/operations/serve.d.ts +10 -0
- package/dist/operations/{runServer.js → serve.js} +15 -16
- package/dist/plugins/statusPlugin.js +1 -1
- package/dist/server/DevServer.d.ts +3 -0
- package/dist/server/DevServer.js +13 -14
- package/dist/server/helpers/createBundlerForDevServer.d.ts +3 -5
- package/dist/server/helpers/createBundlerForDevServer.js +10 -37
- package/dist/server/helpers/mergeBundles.d.ts +4 -4
- package/dist/server/helpers/mergeBundles.js +10 -10
- package/dist/server/plugins/serveBundlePlugin.d.ts +2 -2
- package/dist/server/plugins/symbolicatePlugin/symbolicatePlugin.d.ts +2 -2
- package/dist/server/types.d.ts +9 -14
- package/dist/types/BundlerConfig.d.ts +1 -34
- package/dist/types/Id.d.ts +3 -0
- package/dist/{bundler/types.js → types/Id.js} +2 -2
- package/dist/types/Plugin.d.ts +2 -2
- package/dist/types/index.d.ts +1 -7
- package/dist/types/index.js +2 -14
- package/dist/utils/getId.js +1 -8
- package/dist/utils/progressBar.d.ts +1 -1
- package/dist/utils/writeBundle.d.ts +1 -1
- package/dist/vendors/metro/src/lib/ReportableEvent.d.ts +152 -0
- package/dist/vendors/metro/src/lib/TerminalReporter.d.ts +2 -2
- package/dist/vendors/metro-transform-worker/src/index.js +0 -1
- package/package.json +5 -4
- package/dist/bundler/types.d.ts +0 -17
- package/dist/metro/runBuild.d.ts +0 -12
- package/dist/metro/runBuild.js +0 -66
- package/dist/metro/runtime.d.ts +0 -3
- package/dist/metro/runtime.js +0 -56
- package/dist/metro/types.d.ts +0 -88
- package/dist/metro/types.js +0 -16
- package/dist/operations/experimental/runServer.d.ts +0 -16
- package/dist/operations/runBundle.d.ts +0 -12
- package/dist/operations/runServer.d.ts +0 -15
- package/dist/types/BuildConfig.d.ts +0 -183
- package/dist/types/BuildConfig.js +0 -16
- package/dist/types/Config.d.ts +0 -12
- package/dist/types/Config.js +0 -16
- package/dist/types/DevServerConfig.d.ts +0 -9
- package/dist/types/DevServerConfig.js +0 -16
- package/dist/types/Preset.d.ts +0 -3
- package/dist/types/Preset.js +0 -16
- package/dist/types/PresetContext.d.ts +0 -2
- package/dist/types/PresetContext.js +0 -16
- package/dist/types/ServicesConfig.d.ts +0 -2
- package/dist/types/ServicesConfig.js +0 -16
- package/dist/types/TaskConfig.d.ts +0 -16
- package/dist/types/TaskConfig.js +0 -16
- package/dist/types/schemas/buildConfigSchema.d.ts +0 -235
- package/dist/types/schemas/buildConfigSchema.js +0 -79
- package/dist/types/schemas/bundlerConfigSchema.d.ts +0 -3
- package/dist/types/schemas/bundlerConfigSchema.js +0 -51
- package/dist/types/schemas/configSchema.d.ts +0 -3
- package/dist/types/schemas/configSchema.js +0 -50
- package/dist/types/schemas/devServerConfigSchema.d.ts +0 -3
- package/dist/types/schemas/devServerConfigSchema.js +0 -43
- package/dist/types/schemas/index.d.ts +0 -6
- package/dist/types/schemas/index.js +0 -32
- package/dist/types/schemas/servicesConfigSchema.d.ts +0 -3
- package/dist/types/schemas/servicesConfigSchema.js +0 -48
- package/dist/types/schemas/taskConfigSchema.d.ts +0 -3
- package/dist/types/schemas/taskConfigSchema.js +0 -45
- package/dist/utils/loadConfig.d.ts +0 -2
- package/dist/utils/loadConfig.js +0 -37
- package/dist/utils/loadPresets.d.ts +0 -2
- package/dist/utils/loadPresets.js +0 -40
- package/dist/utils/mergeBanners.d.ts +0 -6
- package/dist/utils/mergeBanners.js +0 -35
- package/dist/utils/mergeBuildConfigs.d.ts +0 -2
- package/dist/utils/mergeBuildConfigs.js +0 -59
- package/dist/utils/mergeInject.d.ts +0 -3
- package/dist/utils/mergeInject.js +0 -30
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
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
|
+
|
|
13
|
+
## 0.1.7
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 208c053: feat: add additionalConfig reporter spec
|
|
18
|
+
- @granite-js/devtools-frontend@0.1.7
|
|
19
|
+
- @granite-js/utils@0.1.7
|
|
20
|
+
|
|
3
21
|
## 0.1.6
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/bundler/Bundler.js
CHANGED
|
@@ -40,6 +40,7 @@ var import_constants = require("../constants");
|
|
|
40
40
|
var import_logger = require("../logger");
|
|
41
41
|
var import_getId = require("../utils/getId");
|
|
42
42
|
var import_promiseHandler = require("../utils/promiseHandler");
|
|
43
|
+
var import_presets = require("./internal/presets");
|
|
43
44
|
class Bundler {
|
|
44
45
|
constructor(config) {
|
|
45
46
|
this.config = config;
|
|
@@ -48,6 +49,10 @@ class Bundler {
|
|
|
48
49
|
this.pluginDriver = new import_PluginDriver.PluginDriver(id);
|
|
49
50
|
this.config.buildConfig.entry = path.resolve(this.config.rootDir, this.config.buildConfig.entry);
|
|
50
51
|
this.config.buildConfig.outfile = path.resolve(this.config.rootDir, this.config.buildConfig.outfile);
|
|
52
|
+
this.config.buildConfig = (0, import_presets.combineWithBaseBuildConfig)(this.config, {
|
|
53
|
+
rootDir: this.config.rootDir,
|
|
54
|
+
dev: this.config.dev
|
|
55
|
+
});
|
|
51
56
|
import_logger.logger.debug("Bundler.constructor", { id, config });
|
|
52
57
|
}
|
|
53
58
|
id;
|
|
@@ -140,8 +145,8 @@ class Bundler {
|
|
|
140
145
|
(0, import_plugins.requireContextPlugin)(),
|
|
141
146
|
(0, import_plugins.transformPlugin)({
|
|
142
147
|
context: pluginContext,
|
|
143
|
-
transformSync: buildConfig.transformSync,
|
|
144
|
-
transformAsync: buildConfig.transformAsync
|
|
148
|
+
transformSync: buildConfig.transformer?.transformSync,
|
|
149
|
+
transformAsync: buildConfig.transformer?.transformAsync
|
|
145
150
|
}),
|
|
146
151
|
...esbuildOptions?.plugins ?? []
|
|
147
152
|
].filter(import_es_toolkit.isNotNil)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type BuildConfig } from '@granite-js/plugin-core';
|
|
2
|
+
import type { BundlerConfig } from '../../types';
|
|
3
|
+
export declare function getReactNativeSetupScripts({ rootDir }: {
|
|
4
|
+
rootDir: string;
|
|
5
|
+
}): string[];
|
|
6
|
+
export declare function globalVariables({ dev }: {
|
|
7
|
+
dev: boolean;
|
|
8
|
+
}): string;
|
|
9
|
+
export declare function defineGlobalVariables({ dev }: {
|
|
10
|
+
dev: boolean;
|
|
11
|
+
}): {
|
|
12
|
+
window: string;
|
|
13
|
+
__DEV__: string;
|
|
14
|
+
'process.env.NODE_ENV': string;
|
|
15
|
+
};
|
|
16
|
+
export declare function combineWithBaseBuildConfig(config: BundlerConfig, context: {
|
|
17
|
+
rootDir: string;
|
|
18
|
+
dev: boolean;
|
|
19
|
+
}): BuildConfig;
|
|
@@ -0,0 +1,103 @@
|
|
|
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 presets_exports = {};
|
|
30
|
+
__export(presets_exports, {
|
|
31
|
+
combineWithBaseBuildConfig: () => combineWithBaseBuildConfig,
|
|
32
|
+
defineGlobalVariables: () => defineGlobalVariables,
|
|
33
|
+
getReactNativeSetupScripts: () => getReactNativeSetupScripts,
|
|
34
|
+
globalVariables: () => globalVariables
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(presets_exports);
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
38
|
+
var import_plugin_core = require("@granite-js/plugin-core");
|
|
39
|
+
function getReactNativeSetupScripts({ rootDir }) {
|
|
40
|
+
const reactNativePath = import_path.default.dirname(
|
|
41
|
+
require.resolve("react-native/package.json", {
|
|
42
|
+
paths: [rootDir]
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
return [
|
|
46
|
+
...require(import_path.default.join(reactNativePath, "rn-get-polyfills"))(),
|
|
47
|
+
import_path.default.join(reactNativePath, "Libraries/Core/InitializeCore.js")
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
function globalVariables({ dev }) {
|
|
51
|
+
return [
|
|
52
|
+
"var __BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now();",
|
|
53
|
+
`var __DEV__=${JSON.stringify(dev)};`,
|
|
54
|
+
`var global=typeof globalThis!=='undefined'?globalThis:typeof global!=='undefined'?global:typeof window!=='undefined'?window:this;`
|
|
55
|
+
].join("\n");
|
|
56
|
+
}
|
|
57
|
+
function defineGlobalVariables({ dev }) {
|
|
58
|
+
return {
|
|
59
|
+
window: "global",
|
|
60
|
+
__DEV__: JSON.stringify(dev),
|
|
61
|
+
"process.env.NODE_ENV": JSON.stringify(dev ? "development" : "production")
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function combineWithBaseBuildConfig(config, context) {
|
|
65
|
+
return (0, import_plugin_core.mergeBuildConfigs)(
|
|
66
|
+
{
|
|
67
|
+
entry: config.buildConfig.entry,
|
|
68
|
+
outfile: config.buildConfig.outfile,
|
|
69
|
+
platform: config.buildConfig.platform,
|
|
70
|
+
esbuild: {
|
|
71
|
+
define: defineGlobalVariables({ dev: context.dev }),
|
|
72
|
+
prelude: getReactNativeSetupScripts({ rootDir: context.rootDir }),
|
|
73
|
+
banner: {
|
|
74
|
+
js: [
|
|
75
|
+
globalVariables({ dev: context.dev }),
|
|
76
|
+
// symbol-asynciterator polyfill (ES5)
|
|
77
|
+
`(function(){if(typeof Symbol!=="undefined"&&!Symbol.asyncIterator){Symbol.asyncIterator=Symbol.for("@@asyncIterator")}})();`
|
|
78
|
+
].join("\n")
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
babel: {
|
|
82
|
+
conditions: [
|
|
83
|
+
/**
|
|
84
|
+
* @TODO
|
|
85
|
+
* We're using a RegExp in Zod that's not supported by Hermes,
|
|
86
|
+
* so we're switching to Babel for transpilation since there's no compatible SWC config or plugin available.
|
|
87
|
+
*
|
|
88
|
+
* @see zod {@link https://github.com/colinhacks/zod/issues/2302}
|
|
89
|
+
*/
|
|
90
|
+
(_code, path2) => path2.includes("node_modules/zod")
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
config.buildConfig
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
combineWithBaseBuildConfig,
|
|
100
|
+
defineGlobalVariables,
|
|
101
|
+
getReactNativeSetupScripts,
|
|
102
|
+
globalVariables
|
|
103
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { BuildResult } from '@granite-js/plugin-core';
|
|
1
2
|
import * as esbuild from 'esbuild';
|
|
2
|
-
import {
|
|
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("
|
|
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("
|
|
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 {
|
|
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("
|
|
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,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 = "
|
|
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`
|
|
@@ -17,4 +17,4 @@ export declare const DEBUGGER_FRONTEND_PATH = "/debugger-frontend";
|
|
|
17
17
|
export declare const RESOLVER_MAIN_FIELDS: string[];
|
|
18
18
|
export declare const RESOLVER_EXPORTS_MAP_CONDITIONS: string[];
|
|
19
19
|
export declare const INTERNAL_NAMESPACE_IDENTIFIER = "__mpackInternal";
|
|
20
|
-
export declare const
|
|
20
|
+
export declare const INTERNAL_LOAD_REMOTE_IDENTIFIER = "loadRemote";
|
package/dist/constants/index.js
CHANGED
|
@@ -33,7 +33,7 @@ __export(constants_exports, {
|
|
|
33
33
|
DEBUGGER_FRONTEND_PATH: () => DEBUGGER_FRONTEND_PATH,
|
|
34
34
|
DEV_SERVER_DEFAULT_HOST: () => DEV_SERVER_DEFAULT_HOST,
|
|
35
35
|
DEV_SERVER_DEFAULT_PORT: () => DEV_SERVER_DEFAULT_PORT,
|
|
36
|
-
|
|
36
|
+
INTERNAL_LOAD_REMOTE_IDENTIFIER: () => INTERNAL_LOAD_REMOTE_IDENTIFIER,
|
|
37
37
|
INTERNAL_NAMESPACE_IDENTIFIER: () => INTERNAL_NAMESPACE_IDENTIFIER,
|
|
38
38
|
MPACK_CACHE_DIR: () => MPACK_CACHE_DIR,
|
|
39
39
|
MPACK_DATA_DIR: () => MPACK_DATA_DIR,
|
|
@@ -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 = "
|
|
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");
|
|
@@ -68,7 +68,7 @@ const DEBUGGER_FRONTEND_PATH = "/debugger-frontend";
|
|
|
68
68
|
const RESOLVER_MAIN_FIELDS = ["react-native", "browser", "main"];
|
|
69
69
|
const RESOLVER_EXPORTS_MAP_CONDITIONS = ["react-native"];
|
|
70
70
|
const INTERNAL_NAMESPACE_IDENTIFIER = "__mpackInternal";
|
|
71
|
-
const
|
|
71
|
+
const INTERNAL_LOAD_REMOTE_IDENTIFIER = "loadRemote";
|
|
72
72
|
// Annotate the CommonJS export names for ESM import in node:
|
|
73
73
|
0 && (module.exports = {
|
|
74
74
|
ASSET_EXTENSIONS,
|
|
@@ -76,7 +76,7 @@ const INTERNAL_EVALUATE_MAIN_BUNDLE_IDENTIFIER = "evaluateMainBundle";
|
|
|
76
76
|
DEBUGGER_FRONTEND_PATH,
|
|
77
77
|
DEV_SERVER_DEFAULT_HOST,
|
|
78
78
|
DEV_SERVER_DEFAULT_PORT,
|
|
79
|
-
|
|
79
|
+
INTERNAL_LOAD_REMOTE_IDENTIFIER,
|
|
80
80
|
INTERNAL_NAMESPACE_IDENTIFIER,
|
|
81
81
|
MPACK_CACHE_DIR,
|
|
82
82
|
MPACK_DATA_DIR,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
export { Bundler } from './bundler';
|
|
2
2
|
export { DevServer } from './server';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export { getMetroConfig, runBuild as metroBuild, type MetroConfig } from './metro';
|
|
3
|
+
export { BuildUtils, runServer, EXPERIMENTAL__server } from './operations';
|
|
4
|
+
export { getMetroConfig, MetroBuildUtils } from './metro';
|
|
6
5
|
export { DEV_SERVER_DEFAULT_HOST, DEV_SERVER_DEFAULT_PORT, SHARED_BUNDLE_NAME, SERVICE_BUNDLE_NAME, BUNDLE_NAME, } from './constants';
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './types/schemas';
|
|
9
|
-
export * from './types';
|
|
10
|
-
export type { AdditionalMetroConfig } from './metro/getMetroConfig';
|
|
11
|
-
export type { BuildResult } from './bundler/types';
|
|
6
|
+
export type * from './types';
|
package/dist/index.js
CHANGED
|
@@ -15,46 +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
|
-
|
|
31
|
-
loadPresets: () => import_loadPresets.loadPresets,
|
|
32
|
-
metroBuild: () => import_metro.runBuild
|
|
32
|
+
runServer: () => import_operations.runServer
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(index_exports);
|
|
35
35
|
var import_bundler = require("./bundler");
|
|
36
36
|
var import_server = require("./server");
|
|
37
|
-
var
|
|
38
|
-
var import_loadPresets = require("./utils/loadPresets");
|
|
37
|
+
var import_operations = require("./operations");
|
|
39
38
|
var import_metro = require("./metro");
|
|
40
39
|
var import_constants = require("./constants");
|
|
41
|
-
__reExport(index_exports, require("./operations"), module.exports);
|
|
42
|
-
__reExport(index_exports, require("./types/schemas"), module.exports);
|
|
43
|
-
__reExport(index_exports, require("./types"), module.exports);
|
|
44
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
45
41
|
0 && (module.exports = {
|
|
46
42
|
BUNDLE_NAME,
|
|
43
|
+
BuildUtils,
|
|
47
44
|
Bundler,
|
|
48
45
|
DEV_SERVER_DEFAULT_HOST,
|
|
49
46
|
DEV_SERVER_DEFAULT_PORT,
|
|
50
47
|
DevServer,
|
|
48
|
+
EXPERIMENTAL__server,
|
|
49
|
+
MetroBuildUtils,
|
|
51
50
|
SERVICE_BUNDLE_NAME,
|
|
52
51
|
SHARED_BUNDLE_NAME,
|
|
53
52
|
getMetroConfig,
|
|
54
|
-
|
|
55
|
-
loadPresets,
|
|
56
|
-
metroBuild,
|
|
57
|
-
...require("./operations"),
|
|
58
|
-
...require("./types/schemas"),
|
|
59
|
-
...require("./types")
|
|
53
|
+
runServer
|
|
60
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,12 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { MetroConfig } from './types';
|
|
1
|
+
import type { AdditionalMetroConfig } from '@granite-js/plugin-core';
|
|
3
2
|
export interface GetMetroConfig {
|
|
4
3
|
rootPath: string;
|
|
5
|
-
appName: string;
|
|
6
|
-
scheme: string;
|
|
7
4
|
}
|
|
8
|
-
export
|
|
9
|
-
transformSync?: (id: string, code: string) => string;
|
|
10
|
-
babelConfig?: babel.TransformOptions;
|
|
11
|
-
}
|
|
12
|
-
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
|
|
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
|
-
|
|
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: {
|
|
@@ -119,6 +116,7 @@ async function getMetroConfig({ rootPath, appName, scheme }, additionalConfig) {
|
|
|
119
116
|
server: {
|
|
120
117
|
port: import_constants.DEV_SERVER_DEFAULT_PORT
|
|
121
118
|
},
|
|
119
|
+
reporter: additionalConfig?.reporter,
|
|
122
120
|
...process.env.METRO_RESET_CACHE !== "false" ? { resetCache: true } : {}
|
|
123
121
|
});
|
|
124
122
|
}
|
package/dist/metro/index.d.ts
CHANGED
package/dist/metro/index.js
CHANGED
|
@@ -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
|
-
|
|
36
|
+
var MetroBuildUtils = __toESM(require("./build"));
|
|
20
37
|
// Annotate the CommonJS export names for ESM import in node:
|
|
21
38
|
0 && (module.exports = {
|
|
22
|
-
|
|
23
|
-
...require("./
|
|
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 {};
|