zephyr-metro-plugin 0.0.0 → 0.0.56

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/LICENSE ADDED
@@ -0,0 +1,39 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ ...
13
+
14
+ END OF TERMS AND CONDITIONS
15
+
16
+ APPENDIX: How to apply the Apache License to your work.
17
+
18
+ To apply the Apache License to your work, attach the following
19
+ boilerplate notice, with the fields enclosed by brackets "[]"
20
+ replaced with your own identifying information. (Don't include
21
+ the brackets!) The text should be enclosed in the appropriate
22
+ comment syntax for the file format. We also recommend that a
23
+ file or class name and description of purpose be included on the
24
+ same line as the copyright notice for each file. The "copyright"
25
+ word should be left as is (without quotes).
26
+
27
+ Copyright [2023] [Zephyr Cloud]
28
+
29
+ Licensed under the Apache License, Version 2.0 (the "License");
30
+ you may not use this file except in compliance with the License.
31
+ You may obtain a copy of the License at
32
+
33
+ http://www.apache.org/licenses/LICENSE-2.0
34
+
35
+ Unless required by applicable law or agreed to in writing, software
36
+ distributed under the License is distributed on an "AS IS" BASIS,
37
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
+ See the License for the specific language governing permissions and
39
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # zephyr-metro-plugin
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build zephyr-metro-plugin` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test zephyr-metro-plugin` to execute the unit tests via [Jest](https://jestjs.io).
package/dist/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # zephyr-metro-plugin
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build zephyr-metro-plugin` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test zephyr-metro-plugin` to execute the unit tests via [Jest](https://jestjs.io).
@@ -0,0 +1,3 @@
1
+ export * from './lib/withZephyr';
2
+ export * from './lib/zephyr-metro-command-wrapper';
3
+ export * from './lib/zephyr-metro-plugin';
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/withZephyr"), exports);
5
+ tslib_1.__exportStar(require("./lib/zephyr-metro-command-wrapper"), exports);
6
+ tslib_1.__exportStar(require("./lib/zephyr-metro-plugin"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,6EAAmD;AACnD,oEAA0C"}
@@ -0,0 +1,2 @@
1
+ import type { ZeDependencyPair } from 'zephyr-agent';
2
+ export declare function extract_remotes_dependencies(remotes?: Record<string, string>): ZeDependencyPair[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extract_remotes_dependencies = extract_remotes_dependencies;
4
+ function extract_remotes_dependencies(remotes) {
5
+ if (!remotes)
6
+ return [];
7
+ const dependencyPairs = Object.entries(remotes).map(([name, remote]) => {
8
+ return { name, version: remote };
9
+ });
10
+ return dependencyPairs;
11
+ }
12
+ //# sourceMappingURL=extract-mf-remotes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-mf-remotes.js","sourceRoot":"","sources":["../../../src/lib/internal/extract-mf-remotes.ts"],"names":[],"mappings":";;AAEA,oEAYC;AAZD,SAAgB,4BAA4B,CAC1C,OAAgC;IAEhC,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,MAAM,eAAe,GAAuB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CACrE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE;QACjB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACnC,CAAC,CACF,CAAC;IAEF,OAAO,eAAe,CAAC;AACzB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ZephyrEngine, ZeResolvedDependency } from 'zephyr-agent';
2
+ import type { ZephyrPluginOptions } from 'zephyr-edge-contract';
3
+ export declare function mutateMfConfig(zephyr_engine: ZephyrEngine, config: Pick<ZephyrPluginOptions, 'mfConfig'>['mfConfig'], resolvedDependencyPairs: ZeResolvedDependency[] | null, delegate_module_template?: () => unknown | undefined): {
4
+ name: string;
5
+ filename: string;
6
+ exposes?: Record<string, string>;
7
+ remotes?: Record<string, string>;
8
+ shared?: Record<string, unknown>;
9
+ runtimePlugins?: string[] | undefined;
10
+ } | undefined;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mutateMfConfig = mutateMfConfig;
4
+ const zephyr_agent_1 = require("zephyr-agent");
5
+ const zephyr_xpack_internal_1 = require("zephyr-xpack-internal");
6
+ function mutateMfConfig(zephyr_engine, config, resolvedDependencyPairs, delegate_module_template = zephyr_xpack_internal_1.xpack_delegate_module_template) {
7
+ if (!resolvedDependencyPairs?.length) {
8
+ zephyr_agent_1.ze_log.mf(`No resolved dependency pairs found, skipping...`);
9
+ return;
10
+ }
11
+ const remotes = config?.remotes;
12
+ if (!remotes) {
13
+ zephyr_agent_1.ze_log.mf(`No remotes found for plugin: ${JSON.stringify(config, null, 2)}`, 'skipping...');
14
+ return;
15
+ }
16
+ Object.entries(remotes).map((remote) => {
17
+ const [remote_name, remote_version] = remote;
18
+ if (!remote_name ||
19
+ typeof remote_name !== 'string' ||
20
+ !remote_version ||
21
+ typeof remote_version !== 'string') {
22
+ zephyr_agent_1.ze_log.mf(`Invalid remote configuration: ${JSON.stringify(remote)}, skipping...`);
23
+ return;
24
+ }
25
+ const resolved_dep = resolvedDependencyPairs.find((dep) => dep.name === remote_name && dep.version === remote_version);
26
+ zephyr_agent_1.ze_log.mf(`remote_name: ${remote_name}, remote_version: ${remote_version}`);
27
+ if (!resolved_dep) {
28
+ zephyr_agent_1.ze_log.mf(`Resolved dependency pair not found for remote: ${JSON.stringify(remote, null, 2)}`, 'skipping...');
29
+ return;
30
+ }
31
+ // todo: this is a version with named export logic, we should take this into account later
32
+ const [v_app] = remote_version.includes('@')
33
+ ? remote_version.split('@')
34
+ : [remote_name];
35
+ zephyr_agent_1.ze_log.mf(`v_app: ${v_app}`);
36
+ if (v_app) {
37
+ resolved_dep.remote_entry_url = [v_app, resolved_dep.remote_entry_url].join('@');
38
+ zephyr_agent_1.ze_log.mf(`Adding version to remote entry url: ${resolved_dep.remote_entry_url}`);
39
+ }
40
+ resolved_dep.name = remote_name;
41
+ if (remotes[remote_name]) {
42
+ remotes[remote_name] = (0, zephyr_xpack_internal_1.createMfRuntimeCode)(zephyr_engine, resolved_dep, delegate_module_template);
43
+ zephyr_agent_1.ze_log.mf(`Setting runtime code for remote: ${remotes}`);
44
+ }
45
+ });
46
+ return config;
47
+ }
48
+ //# sourceMappingURL=mutate-mf-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutate-mf-config.js","sourceRoot":"","sources":["../../../src/lib/internal/mutate-mf-config.ts"],"names":[],"mappings":";;AAQA,wCAsEC;AA7ED,+CAAsC;AAEtC,iEAG+B;AAE/B,SAAgB,cAAc,CAC5B,aAA2B,EAC3B,MAAyD,EACzD,uBAAsD,EACtD,2BAAsD,sDAA8B;IAEpF,IAAI,CAAC,uBAAuB,EAAE,MAAM,EAAE,CAAC;QACrC,qBAAM,CAAC,EAAE,CAAC,iDAAiD,CAAC,CAAC;QAC7D,OAAO;IACT,CAAC;IAED,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AAE,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC;QAC7B,IAAI,KAAK,EAAE,CAAC;YACV,YAAY,CAAC,gBAAgB,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjF,qBAAM,CAAC,EAAE,CAAC,uCAAuC,YAAY,CAAC,gBAAgB,EAAE,CAAC,CAAC;QACpF,CAAC;QAED,YAAY,CAAC,IAAI,GAAG,WAAW,CAAC;QAEhC,IAAI,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YACzB,OAAO,CAAC,WAAW,CAAC,GAAG,IAAA,2CAAmB,EACxC,aAAa,EACb,YAAY,EACZ,wBAAwB,CACzB,CAAC;YACF,qBAAM,CAAC,EAAE,CAAC,oCAAoC,OAAO,EAAE,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { ZephyrPluginOptions } from 'zephyr-edge-contract';
2
+ export interface ModuleFederationConfig {
3
+ name: string;
4
+ remotes?: Record<string, string>;
5
+ shared?: Record<string, {
6
+ singleton?: boolean;
7
+ eager?: boolean;
8
+ requiredVersion?: string;
9
+ version?: string;
10
+ }>;
11
+ shareStrategy?: 'loaded-first' | 'version-first';
12
+ plugins?: string[];
13
+ }
14
+ export declare function withZephyr(context?: string, platform?: 'ios' | 'android', mode?: 'development' | 'production', outDir?: string): (config: Pick<ZephyrPluginOptions, 'mfConfig'>['mfConfig']) => Promise<Pick<ZephyrPluginOptions, 'mfConfig'>['mfConfig']>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withZephyr = withZephyr;
4
+ const zephyr_metro_plugin_1 = require("./zephyr-metro-plugin");
5
+ function withZephyr(context, platform = 'ios', mode = 'development', outDir = 'dist') {
6
+ return async function (config) {
7
+ if (!config)
8
+ return config;
9
+ const zephyrMetroPlugin = new zephyr_metro_plugin_1.ZephyrMetroPlugin({
10
+ platform,
11
+ mode,
12
+ context: context || process.cwd(),
13
+ outDir,
14
+ mfConfig: config,
15
+ });
16
+ const newConfig = await zephyrMetroPlugin.beforeBuild();
17
+ return newConfig;
18
+ };
19
+ }
20
+ //# sourceMappingURL=withZephyr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withZephyr.js","sourceRoot":"","sources":["../../src/lib/withZephyr.ts"],"names":[],"mappings":";;AAmBA,gCAuBC;AAzCD,+DAA0D;AAkB1D,SAAgB,UAAU,CACxB,OAAgB,EAChB,WAA8B,KAAK,EACnC,OAAqC,aAAa,EAClD,MAAM,GAAG,MAAM;IAIf,OAAO,KAAK,WAAW,MAAyD;QAC9E,IAAI,CAAC,MAAM;YAAE,OAAO,MAAM,CAAC;QAE3B,MAAM,iBAAiB,GAAG,IAAI,uCAAiB,CAAC;YAC9C,QAAQ;YACR,IAAI;YACJ,OAAO,EAAE,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE;YACjC,MAAM;YACN,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;QAEH,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,WAAW,EAAE,CAAC;QAExD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type MetroConfig = Record<string, unknown>;
2
+ export type MetroFederationConfig = Record<string, unknown>;
3
+ export declare function zephyrCommandWrapper(bundleFederatedRemote: (...args: any[]) => Promise<any>, loadMetroConfig: (config: MetroConfig, options: {
4
+ maxWorkers?: number;
5
+ resetCache?: boolean;
6
+ config?: string;
7
+ }) => Promise<any>, updateManifest: () => void): Promise<(...args: any[]) => Promise<any>>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zephyrCommandWrapper = zephyrCommandWrapper;
4
+ const zephyr_agent_1 = require("zephyr-agent");
5
+ const zephyr_metro_plugin_1 = require("./zephyr-metro-plugin");
6
+ async function zephyrCommandWrapper(bundleFederatedRemote, loadMetroConfig, updateManifest) {
7
+ return async (...args) => {
8
+ try {
9
+ // before build
10
+ const isDev = args[0][0]['mode'];
11
+ const platform = args[0][0]['platform'];
12
+ const context = args[1].root;
13
+ await loadMetroConfig(args[1], {
14
+ maxWorkers: args[2].maxWorkers,
15
+ resetCache: args[2].resetCache,
16
+ config: args[2].config,
17
+ });
18
+ if (!global.__METRO_FEDERATION_CONFIG) {
19
+ throw new zephyr_agent_1.ZephyrError(zephyr_agent_1.ZeErrors.ERR_MISSING_METRO_FEDERATION_CONFIG);
20
+ }
21
+ const zephyrMetroPlugin = new zephyr_metro_plugin_1.ZephyrMetroPlugin({
22
+ platform,
23
+ mode: isDev ? 'development' : 'production',
24
+ context,
25
+ outDir: 'dist',
26
+ mfConfig: global.__METRO_FEDERATION_CONFIG,
27
+ });
28
+ await zephyrMetroPlugin.beforeBuild();
29
+ updateManifest();
30
+ const res = await bundleFederatedRemote(...args);
31
+ await zephyrMetroPlugin.afterBuild();
32
+ return res;
33
+ }
34
+ catch (error) {
35
+ throw new zephyr_agent_1.ZephyrError(zephyr_agent_1.ZeErrors.ERR_UNKNOWN, {
36
+ message: JSON.stringify(error),
37
+ });
38
+ }
39
+ };
40
+ }
41
+ //# sourceMappingURL=zephyr-metro-command-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zephyr-metro-command-wrapper.js","sourceRoot":"","sources":["../../src/lib/zephyr-metro-command-wrapper.ts"],"names":[],"mappings":";;AAMA,oDAiDC;AAvDD,+CAAqD;AACrD,+DAA0D;AAKnD,KAAK,UAAU,oBAAoB,CACxC,qBAAuD,EACvD,eAGiB,EACjB,cAA0B;IAE1B,OAAO,KAAK,EAAE,GAAG,IAAW,EAAE,EAAE;QAC9B,IAAI,CAAC;YACH,eAAe;YACf,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CA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,30 @@
1
+ import type { Platform } from 'zephyr-agent';
2
+ import { ZephyrEngine } from 'zephyr-agent';
3
+ import type { ZephyrPluginOptions } from 'zephyr-edge-contract';
4
+ export interface ZephyrCommandWrapperConfig {
5
+ platform: Platform;
6
+ mode: string;
7
+ context: string;
8
+ outDir: string;
9
+ mfConfig: Pick<ZephyrPluginOptions, 'mfConfig'>['mfConfig'];
10
+ }
11
+ export declare class ZephyrMetroPlugin {
12
+ private config;
13
+ zephyr_engine: ZephyrEngine;
14
+ constructor(props: ZephyrCommandWrapperConfig);
15
+ beforeBuild(): Promise<{
16
+ name: string;
17
+ filename: string;
18
+ exposes?: Record<string, string>;
19
+ remotes?: Record<string, string>;
20
+ shared?: Record<string, unknown>;
21
+ runtimePlugins?: string[] | undefined;
22
+ } | undefined>;
23
+ afterBuild(): Promise<void>;
24
+ private getConsumeMap;
25
+ private getBuildStats;
26
+ private loadStaticAssets;
27
+ private makeAssetsMap;
28
+ private extractBuffer;
29
+ private getAssetType;
30
+ }
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZephyrMetroPlugin = void 0;
4
+ const zephyr_agent_1 = require("zephyr-agent");
5
+ const zephyr_rollx_internal_1 = require("zephyr-rollx-internal");
6
+ const extract_mf_remotes_1 = require("./internal/extract-mf-remotes");
7
+ const mutate_mf_config_1 = require("./internal/mutate-mf-config");
8
+ class ZephyrMetroPlugin {
9
+ constructor(props) {
10
+ this.config = props;
11
+ }
12
+ async beforeBuild() {
13
+ this.zephyr_engine = await zephyr_agent_1.ZephyrEngine.create({
14
+ builder: 'metro',
15
+ context: this.config.context,
16
+ });
17
+ zephyr_agent_1.ze_log.config('Configuring with Zephyr... \n config: ', this.config);
18
+ this.zephyr_engine.env.target = this.config.platform;
19
+ const dependency_pairs = (0, extract_mf_remotes_1.extract_remotes_dependencies)(this.config.mfConfig?.remotes);
20
+ zephyr_agent_1.ze_log.config('Resolving and building towards target by zephyr_engine.env.target: ', this.zephyr_engine.env.target);
21
+ const resolved_dependency_pairs = await this.zephyr_engine.resolve_remote_dependencies(dependency_pairs);
22
+ if (this.config.mfConfig) {
23
+ (0, mutate_mf_config_1.mutateMfConfig)(this.zephyr_engine, this.config.mfConfig, resolved_dependency_pairs);
24
+ }
25
+ return this.config.mfConfig;
26
+ }
27
+ async afterBuild() {
28
+ await this.zephyr_engine.start_new_build();
29
+ const assetsMap = await this.makeAssetsMap();
30
+ const buildStats = await this.getBuildStats(Object.values(assetsMap).filter((asset) => asset.extname === '.map' && !asset.path.includes('shared/')));
31
+ await this.zephyr_engine.upload_assets({
32
+ assetsMap,
33
+ buildStats,
34
+ mfConfig: this.config.mfConfig,
35
+ });
36
+ await this.zephyr_engine.build_finished();
37
+ }
38
+ async getConsumeMap(bundleMaps) {
39
+ const consumeMap = new Map();
40
+ bundleMaps.forEach((asset) => {
41
+ try {
42
+ const sourceMap = JSON.parse(asset['buffer'].toString());
43
+ if (sourceMap.sourcesContent && Array.isArray(sourceMap.sourcesContent)) {
44
+ // Filter out node_modules from sources and sourcesContent
45
+ const filteredSources = [];
46
+ const filteredSourcesContent = [];
47
+ // Find indices of sources that contain node_modules
48
+ if (sourceMap.sources && Array.isArray(sourceMap.sources)) {
49
+ sourceMap.sources.forEach((source, sourceIndex) => {
50
+ if (typeof source === 'string' && !source.includes('node_modules')) {
51
+ // Keep non-node_modules sources
52
+ if (sourceMap.sourcesContent[sourceIndex]) {
53
+ filteredSources.push(source);
54
+ filteredSourcesContent.push(sourceMap.sourcesContent[sourceIndex]);
55
+ }
56
+ }
57
+ });
58
+ }
59
+ // Search for ES6 import statements: import ... from 'remote/component'
60
+ const searchPattern = /import\s+(?:\{[^}]*\}|\w+)\s+from\s+['"]([^'"]+)\/([^'"]+)['"]/g;
61
+ filteredSourcesContent.forEach((content, contentIndex) => {
62
+ let match;
63
+ while ((match = searchPattern.exec(content)) !== null) {
64
+ if (match.length >= 3) {
65
+ const remoteName = match[1];
66
+ const componentName = match[2];
67
+ const fileUrl = filteredSources[contentIndex];
68
+ consumeMap.set(`${remoteName}-${componentName}`, {
69
+ consumingApplicationID: componentName,
70
+ applicationID: remoteName,
71
+ name: componentName,
72
+ usedIn: [
73
+ {
74
+ file: fileUrl.replace(this.config.context, ''),
75
+ url: fileUrl.replace(this.config.context, ''),
76
+ },
77
+ ],
78
+ });
79
+ zephyr_agent_1.ze_log.app('Found remote import in promise chain', {
80
+ remoteName,
81
+ componentName,
82
+ file: fileUrl.replace(this.config.context, ''),
83
+ });
84
+ }
85
+ }
86
+ });
87
+ }
88
+ }
89
+ catch (error) {
90
+ zephyr_agent_1.ze_log.app('Error parsing bundle map for loadRemote calls', {
91
+ error,
92
+ chunkId: asset['path'],
93
+ });
94
+ }
95
+ });
96
+ return consumeMap;
97
+ }
98
+ async getBuildStats(bundleMaps) {
99
+ const minimal_build_stats = await (0, zephyr_agent_1.create_minimal_build_stats)(this.zephyr_engine);
100
+ const consumeMap = await this.getConsumeMap(bundleMaps);
101
+ Object.assign(minimal_build_stats, {
102
+ name: this.config.mfConfig?.name || this.zephyr_engine.applicationProperties.name,
103
+ remote: this.config.mfConfig?.filename || 'remoteEntry.js',
104
+ remotes: this.config.mfConfig?.remotes
105
+ ? Object.keys(this.config.mfConfig.remotes)
106
+ : [],
107
+ metadata: {
108
+ hasFederation: !!this.config.mfConfig,
109
+ },
110
+ build_target: this.zephyr_engine.env.target,
111
+ });
112
+ // Extract shared dependencies from Module Federation config
113
+ const overrides = this.config.mfConfig?.shared
114
+ ? Object.entries(this.config.mfConfig.shared).map(([name, config]) => (0, zephyr_rollx_internal_1.parseSharedDependencies)(name, config, this.zephyr_engine))
115
+ : [];
116
+ // Build the stats object
117
+ const buildStats = {
118
+ ...minimal_build_stats,
119
+ overrides,
120
+ modules: (0, zephyr_rollx_internal_1.extractModulesFromExposes)(this.config.mfConfig, this.zephyr_engine.application_uid),
121
+ // Module Federation related data
122
+ dependencies: (0, zephyr_rollx_internal_1.getPackageDependencies)((0, zephyr_agent_1.resolveCatalogDependencies)(this.zephyr_engine.npmProperties.dependencies)),
123
+ devDependencies: (0, zephyr_rollx_internal_1.getPackageDependencies)((0, zephyr_agent_1.resolveCatalogDependencies)(this.zephyr_engine.npmProperties.devDependencies)),
124
+ optionalDependencies: (0, zephyr_rollx_internal_1.getPackageDependencies)((0, zephyr_agent_1.resolveCatalogDependencies)(this.zephyr_engine.npmProperties.optionalDependencies)),
125
+ peerDependencies: (0, zephyr_rollx_internal_1.getPackageDependencies)((0, zephyr_agent_1.resolveCatalogDependencies)(this.zephyr_engine.npmProperties.peerDependencies)),
126
+ consumes: Array.from(consumeMap.values()),
127
+ };
128
+ return buildStats;
129
+ }
130
+ async loadStaticAssets() {
131
+ const assets = await (0, zephyr_rollx_internal_1.load_static_entries)({
132
+ root: this.config.context,
133
+ outDir: this.config.platform === 'ios' || this.config.platform === 'android'
134
+ ? this.config.outDir + `/${this.config.platform}`
135
+ : this.config.outDir,
136
+ });
137
+ return assets.reduce((acc, asset) => {
138
+ acc[asset.fileName] = asset;
139
+ return acc;
140
+ }, {});
141
+ }
142
+ async makeAssetsMap() {
143
+ const assets = await this.loadStaticAssets();
144
+ return (0, zephyr_agent_1.buildAssetsMap)(assets, this.extractBuffer, this.getAssetType);
145
+ }
146
+ extractBuffer(asset) {
147
+ return asset.source?.toString();
148
+ }
149
+ getAssetType(asset) {
150
+ return asset.type ?? 'asset';
151
+ }
152
+ }
153
+ exports.ZephyrMetroPlugin = ZephyrMetroPlugin;
154
+ //# sourceMappingURL=zephyr-metro-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zephyr-metro-plugin.js","sourceRoot":"","sources":["../../src/lib/zephyr-metro-plugin.ts"],"names":[],"mappings":";;;AACA,+CAMsB;AAQtB,iEAK+B;AAC/B,sEAA6E;AAC7E,kEAA6D;AAU7D,MAAa,iBAAiB;IAI5B,YAAY,KAAiC;QAC3C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAA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CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YAClC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;YAC5B,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAS,CAAC,CAAC;IAChB,CAAC;IAEO,KAAK,CAAC,aAAa;QACzB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAE7C,OAAO,IAAA,6BAAc,EAAC,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACvE,CAAC;IAEO,aAAa,CAAC,KAAkB;QACtC,OAAO,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;IAClC,CAAC;IAEO,YAAY,CAAC,KAAkB;QACrC,OAAO,KAAK,CAAC,IAAI,IAAI,OAAO,CAAC;IAC/B,CAAC;CACF;AAxMD,8CAwMC"}
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "zephyr-metro-plugin",
3
+ "version": "0.0.1",
4
+ "description": "Metro plugin for Zephyr",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/ZephyrCloudIO/zephyr-packages.git",
8
+ "directory": "libs/zephyr-metro-plugin"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "author": {
12
+ "name": "ZephyrCloudIO",
13
+ "url": "https://github.com/ZephyrCloudIO"
14
+ },
15
+ "type": "commonjs",
16
+ "main": "dist/index.js",
17
+ "typings": "dist/index.d.ts",
18
+ "scripts": {
19
+ "build": "nx build zephyr-metro-plugin",
20
+ "patch-version": "pnpm version",
21
+ "test": "nx test zephyr-metro-plugin"
22
+ },
23
+ "dependencies": {
24
+ "zephyr-agent": "workspace:*",
25
+ "zephyr-xpack-internal": "workspace:*",
26
+ "zephyr-rollx-internal": "workspace:*"
27
+ },
28
+ "peerDependencies": {
29
+ "metro-config": "^0.82.4"
30
+ },
31
+ "devDependencies": {
32
+ "@rspack/core": "catalog:rspack",
33
+ "@types/find-package-json": "^1.2.6",
34
+ "@types/jest": "catalog:typescript",
35
+ "@typescript-eslint/eslint-plugin": "catalog:eslint",
36
+ "ts-jest": "catalog:typescript"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "provenance": true
41
+ },
42
+ "types": "./index.d.ts"
43
+ }
package/package.json CHANGED
@@ -1,12 +1,42 @@
1
1
  {
2
2
  "name": "zephyr-metro-plugin",
3
- "version": "0.0.0",
4
- "main": "index.js",
5
- "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1"
3
+ "version": "0.0.56",
4
+ "description": "Metro plugin for Zephyr",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/ZephyrCloudIO/zephyr-packages.git",
8
+ "directory": "libs/zephyr-metro-plugin"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "author": {
12
+ "name": "ZephyrCloudIO",
13
+ "url": "https://github.com/ZephyrCloudIO"
14
+ },
15
+ "type": "commonjs",
16
+ "main": "dist/index.js",
17
+ "typings": "dist/index.d.ts",
18
+ "dependencies": {
19
+ "zephyr-agent": "0.0.56",
20
+ "zephyr-rollx-internal": "0.0.56",
21
+ "zephyr-xpack-internal": "0.0.56"
22
+ },
23
+ "peerDependencies": {
24
+ "metro-config": "^0.82.4"
7
25
  },
8
- "keywords": [],
9
- "author": "Lois Z. <loisisar@outlook.com> (https://loiszhao.com/)",
10
- "license": "MIT",
11
- "description": ""
12
- }
26
+ "devDependencies": {
27
+ "@rspack/core": "^1.3.15",
28
+ "@types/find-package-json": "^1.2.6",
29
+ "@types/jest": "29.5.14",
30
+ "@typescript-eslint/eslint-plugin": "^8.27.0",
31
+ "ts-jest": "^29.2.6"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "provenance": true
36
+ },
37
+ "scripts": {
38
+ "build": "nx build zephyr-metro-plugin",
39
+ "patch-version": "pnpm version",
40
+ "test": "nx test zephyr-metro-plugin"
41
+ }
42
+ }