zephyr-metro-plugin 0.0.0 → 0.1.3

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 (49) hide show
  1. package/LICENSE +39 -0
  2. package/README.md +330 -0
  3. package/TESTING.md +153 -0
  4. package/dist/README.md +330 -0
  5. package/dist/TESTING.md +153 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +12 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/lib/internal/extract-mf-remotes.d.ts +3 -0
  10. package/dist/lib/internal/extract-mf-remotes.js +22 -0
  11. package/dist/lib/internal/extract-mf-remotes.js.map +1 -0
  12. package/dist/lib/internal/extract-modules-from-exposes.d.ts +12 -0
  13. package/dist/lib/internal/extract-modules-from-exposes.js +66 -0
  14. package/dist/lib/internal/extract-modules-from-exposes.js.map +1 -0
  15. package/dist/lib/internal/get-package-dependencies.d.ts +4 -0
  16. package/dist/lib/internal/get-package-dependencies.js +9 -0
  17. package/dist/lib/internal/get-package-dependencies.js.map +1 -0
  18. package/dist/lib/internal/load-static-entries.d.ts +7 -0
  19. package/dist/lib/internal/load-static-entries.js +39 -0
  20. package/dist/lib/internal/load-static-entries.js.map +1 -0
  21. package/dist/lib/internal/metro-build-stats.d.ts +4 -0
  22. package/dist/lib/internal/metro-build-stats.js +53 -0
  23. package/dist/lib/internal/metro-build-stats.js.map +1 -0
  24. package/dist/lib/internal/metro-errors.d.ts +5 -0
  25. package/dist/lib/internal/metro-errors.js +7 -0
  26. package/dist/lib/internal/metro-errors.js.map +1 -0
  27. package/dist/lib/internal/mutate-mf-config.d.ts +10 -0
  28. package/dist/lib/internal/mutate-mf-config.js +50 -0
  29. package/dist/lib/internal/mutate-mf-config.js.map +1 -0
  30. package/dist/lib/internal/parse-shared-dependencies.d.ts +8 -0
  31. package/dist/lib/internal/parse-shared-dependencies.js +54 -0
  32. package/dist/lib/internal/parse-shared-dependencies.js.map +1 -0
  33. package/dist/lib/internal/types.d.ts +53 -0
  34. package/dist/lib/internal/types.js +3 -0
  35. package/dist/lib/internal/types.js.map +1 -0
  36. package/dist/lib/with-zephyr.d.ts +25 -0
  37. package/dist/lib/with-zephyr.js +143 -0
  38. package/dist/lib/with-zephyr.js.map +1 -0
  39. package/dist/lib/zephyr-metro-command-wrapper.d.ts +19 -0
  40. package/dist/lib/zephyr-metro-command-wrapper.js +42 -0
  41. package/dist/lib/zephyr-metro-command-wrapper.js.map +1 -0
  42. package/dist/lib/zephyr-metro-plugin.d.ts +30 -0
  43. package/dist/lib/zephyr-metro-plugin.js +162 -0
  44. package/dist/lib/zephyr-metro-plugin.js.map +1 -0
  45. package/dist/lib/zephyr-transformer.d.ts +16 -0
  46. package/dist/lib/zephyr-transformer.js +99 -0
  47. package/dist/lib/zephyr-transformer.js.map +1 -0
  48. package/dist/package.json +68 -0
  49. package/package.json +66 -10
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var _ZephyrMetroPlugin_config;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ZephyrMetroPlugin = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const zephyr_agent_1 = require("zephyr-agent");
7
+ const extract_modules_from_exposes_1 = require("./internal/extract-modules-from-exposes");
8
+ const get_package_dependencies_1 = require("./internal/get-package-dependencies");
9
+ const load_static_entries_1 = require("./internal/load-static-entries");
10
+ const metro_build_stats_1 = require("./internal/metro-build-stats");
11
+ const parse_shared_dependencies_1 = require("./internal/parse-shared-dependencies");
12
+ const extract_mf_remotes_1 = require("./internal/extract-mf-remotes");
13
+ const mutate_mf_config_1 = require("./internal/mutate-mf-config");
14
+ class ZephyrMetroPlugin {
15
+ constructor(props) {
16
+ _ZephyrMetroPlugin_config.set(this, void 0);
17
+ tslib_1.__classPrivateFieldSet(this, _ZephyrMetroPlugin_config, props, "f");
18
+ }
19
+ async beforeBuild() {
20
+ this.zephyr_engine = await zephyr_agent_1.ZephyrEngine.create({
21
+ builder: 'metro',
22
+ context: tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").context,
23
+ });
24
+ zephyr_agent_1.ze_log.config('Configuring with Zephyr... \n config: ', tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f"));
25
+ this.zephyr_engine.env.target = tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").platform;
26
+ const dependency_pairs = (0, extract_mf_remotes_1.extract_remotes_dependencies)(tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f"));
27
+ zephyr_agent_1.ze_log.config('Resolving and building towards target by zephyr_engine.env.target: ', this.zephyr_engine.env.target);
28
+ const resolved_dependency_pairs = await this.zephyr_engine.resolve_remote_dependencies(dependency_pairs);
29
+ if (tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").mfConfig) {
30
+ (0, mutate_mf_config_1.mutateMfConfig)(this.zephyr_engine, tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").mfConfig, resolved_dependency_pairs);
31
+ }
32
+ return tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").mfConfig;
33
+ }
34
+ async afterBuild() {
35
+ await this.zephyr_engine.start_new_build();
36
+ const assetsMap = await this.makeAssetsMap();
37
+ const buildStats = await this.getBuildStats(Object.values(assetsMap).filter((asset) => asset.extname === '.map' && !asset.path.includes('shared/')));
38
+ await this.zephyr_engine.upload_assets({
39
+ assetsMap,
40
+ buildStats: buildStats,
41
+ mfConfig: tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").mfConfig,
42
+ });
43
+ await this.zephyr_engine.build_finished();
44
+ }
45
+ async getConsumeMap(bundleMaps) {
46
+ const consumeMap = new Map();
47
+ bundleMaps.forEach((asset) => {
48
+ try {
49
+ const sourceMap = JSON.parse(asset['buffer'].toString());
50
+ if (sourceMap.sourcesContent && Array.isArray(sourceMap.sourcesContent)) {
51
+ // Filter out node_modules from sources and sourcesContent
52
+ const filteredSources = [];
53
+ const filteredSourcesContent = [];
54
+ // Find indices of sources that contain node_modules
55
+ if (sourceMap.sources && Array.isArray(sourceMap.sources)) {
56
+ sourceMap.sources.forEach((source, sourceIndex) => {
57
+ if (typeof source === 'string' && !source.includes('node_modules')) {
58
+ // Keep non-node_modules sources
59
+ if (sourceMap.sourcesContent[sourceIndex]) {
60
+ filteredSources.push(source);
61
+ filteredSourcesContent.push(sourceMap.sourcesContent[sourceIndex]);
62
+ }
63
+ }
64
+ });
65
+ }
66
+ // Search for ES6 import statements: import ... from 'remote/component'
67
+ const searchPattern = /import\s+(?:\{[^}]*\}|\w+)\s+from\s+['"]([^'"]+)\/([^'"]+)['"]/g;
68
+ filteredSourcesContent.forEach((content, contentIndex) => {
69
+ let match;
70
+ while ((match = searchPattern.exec(content)) !== null) {
71
+ if (match.length >= 3) {
72
+ const remoteName = match[1];
73
+ const componentName = match[2];
74
+ const fileUrl = filteredSources[contentIndex];
75
+ consumeMap.set(`${remoteName}-${componentName}`, {
76
+ consumingApplicationID: componentName,
77
+ applicationID: remoteName,
78
+ name: componentName,
79
+ usedIn: [
80
+ {
81
+ file: fileUrl.replace(tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").context, ''),
82
+ url: fileUrl.replace(tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").context, ''),
83
+ },
84
+ ],
85
+ });
86
+ zephyr_agent_1.ze_log.app('Found remote import in promise chain', {
87
+ remoteName,
88
+ componentName,
89
+ file: fileUrl.replace(tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").context, ''),
90
+ });
91
+ }
92
+ }
93
+ });
94
+ }
95
+ }
96
+ catch (error) {
97
+ zephyr_agent_1.ze_log.app('Error parsing bundle map for loadRemote calls', {
98
+ error,
99
+ chunkId: asset['path'],
100
+ });
101
+ }
102
+ });
103
+ return consumeMap;
104
+ }
105
+ async getBuildStats(bundleMaps) {
106
+ const minimal_build_stats = await (0, metro_build_stats_1.createMinimalBuildStats)(this.zephyr_engine);
107
+ const consumeMap = await this.getConsumeMap(bundleMaps);
108
+ Object.assign(minimal_build_stats, {
109
+ name: tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").mfConfig?.name || this.zephyr_engine.applicationProperties.name,
110
+ remote: tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").mfConfig?.filename || 'remoteEntry.js',
111
+ remotes: tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").mfConfig?.remotes
112
+ ? Object.keys(tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").mfConfig.remotes)
113
+ : [],
114
+ metadata: {
115
+ hasFederation: !!tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").mfConfig,
116
+ },
117
+ build_target: this.zephyr_engine.env.target,
118
+ });
119
+ // Extract shared dependencies from Module Federation config
120
+ const overrides = tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").mfConfig?.shared
121
+ ? Object.entries(tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").mfConfig.shared).map(([name, config]) => (0, parse_shared_dependencies_1.parseSharedDependencies)(name, config, this.zephyr_engine))
122
+ : [];
123
+ // Build the stats object
124
+ const buildStats = {
125
+ ...minimal_build_stats,
126
+ overrides,
127
+ modules: (0, extract_modules_from_exposes_1.extractModulesFromExposes)(tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").mfConfig, this.zephyr_engine.application_uid),
128
+ // Module Federation related data
129
+ dependencies: (0, get_package_dependencies_1.getPackageDependencies)((0, metro_build_stats_1.resolveCatalogDependencies)(this.zephyr_engine.npmProperties.dependencies)),
130
+ devDependencies: (0, get_package_dependencies_1.getPackageDependencies)((0, metro_build_stats_1.resolveCatalogDependencies)(this.zephyr_engine.npmProperties.devDependencies)),
131
+ optionalDependencies: (0, get_package_dependencies_1.getPackageDependencies)((0, metro_build_stats_1.resolveCatalogDependencies)(this.zephyr_engine.npmProperties.optionalDependencies)),
132
+ peerDependencies: (0, get_package_dependencies_1.getPackageDependencies)((0, metro_build_stats_1.resolveCatalogDependencies)(this.zephyr_engine.npmProperties.peerDependencies)),
133
+ consumes: Array.from(consumeMap.values()),
134
+ };
135
+ return buildStats;
136
+ }
137
+ async loadStaticAssets() {
138
+ const assets = await (0, load_static_entries_1.load_static_entries)({
139
+ root: tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").context,
140
+ outDir: tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").platform === 'ios' || tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").platform === 'android'
141
+ ? tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").outDir + `/${tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").platform}`
142
+ : tslib_1.__classPrivateFieldGet(this, _ZephyrMetroPlugin_config, "f").outDir,
143
+ });
144
+ return assets.reduce((acc, asset) => {
145
+ acc[asset.fileName] = asset;
146
+ return acc;
147
+ }, {});
148
+ }
149
+ async makeAssetsMap() {
150
+ const assets = await this.loadStaticAssets();
151
+ return (0, zephyr_agent_1.buildAssetsMap)(assets, this.extractBuffer, this.getAssetType);
152
+ }
153
+ extractBuffer(asset) {
154
+ return asset.source?.toString();
155
+ }
156
+ getAssetType(asset) {
157
+ return asset.type ?? 'asset';
158
+ }
159
+ }
160
+ exports.ZephyrMetroPlugin = ZephyrMetroPlugin;
161
+ _ZephyrMetroPlugin_config = new WeakMap();
162
+ //# 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,+CAAoE;AAOpE,0FAAoF;AACpF,kFAA6E;AAC7E,wEAAqE;AACrE,oEAGsC;AACtC,oFAA+E;AAE/E,sEAA6E;AAC7E,kEAA6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;gBACpE,CAAC,CAAC,+BAAA,IAAI,iCAAQ,CAAC,MAAM,GAAG,IAAI,+BAAA,IAAI,iCAAQ,CAAC,QAAQ,EAAE;gBACnD,CAAC,CAAC,+BAAA,IAAI,iCAAQ,CAAC,MAAM;SAC1B,CAAC,CAAC;QAEH,OAAO,MAAM,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;AA5MD,8CA4MC"}
@@ -0,0 +1,16 @@
1
+ import type { JsTransformOptions, JsTransformerConfig } from 'metro-transform-worker';
2
+ interface ZephyrTransformerOptions {
3
+ /** Custom manifest endpoint path */
4
+ manifestPath?: string;
5
+ /** Custom entry file patterns for more conservative targeting */
6
+ entryFiles?: string[];
7
+ }
8
+ /** Metro transformer that injects Zephyr runtime capabilities */
9
+ export declare function transform(config: JsTransformerConfig & {
10
+ zephyrTransformerOptions?: ZephyrTransformerOptions;
11
+ }, projectRoot: string, filename: string, data: Buffer, options: JsTransformOptions): Promise<{
12
+ ast: any;
13
+ code: string;
14
+ map: any;
15
+ }>;
16
+ export {};
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transform = transform;
4
+ const zephyr_agent_1 = require("zephyr-agent");
5
+ /** Default entry file patterns if none specified */
6
+ const DEFAULT_ENTRY_FILES = ['index.js', 'index.ts', 'index.tsx', 'App.js', 'App.tsx'];
7
+ /** Metro transformer that injects Zephyr runtime capabilities */
8
+ async function transform(config, projectRoot, filename, data, options) {
9
+ // Use default Metro transformer first
10
+ const upstream = require('metro-react-native-babel-transformer');
11
+ const result = await upstream.transform(config, projectRoot, filename, data, options);
12
+ // Get Zephyr transformer options from config
13
+ const zephyrOptions = config.zephyrTransformerOptions;
14
+ const entryFiles = zephyrOptions?.entryFiles || DEFAULT_ENTRY_FILES;
15
+ // Only enhance entry files - use configurable patterns for more conservative targeting
16
+ const shouldEnhance = isZephyrTargetFile(filename, result.code, entryFiles);
17
+ if (shouldEnhance) {
18
+ const manifestPath = zephyrOptions?.manifestPath || '/zephyr-manifest.json';
19
+ const enhancedCode = injectZephyrRuntime(result.code, filename, manifestPath);
20
+ return {
21
+ ...result,
22
+ code: enhancedCode,
23
+ };
24
+ }
25
+ return result;
26
+ }
27
+ /** Check if file should be enhanced with Zephyr runtime */
28
+ function isZephyrTargetFile(filename, code, entryFiles) {
29
+ // Check against configured entry file patterns
30
+ const isEntryFile = entryFiles.some((pattern) => {
31
+ // Support glob-like patterns (simple matching)
32
+ if (pattern.includes('*')) {
33
+ const regex = new RegExp(pattern.replace(/\*/g, '.*'));
34
+ return regex.test(filename);
35
+ }
36
+ return filename.endsWith(pattern) || filename.includes(`/${pattern}`);
37
+ });
38
+ if (isEntryFile) {
39
+ return true;
40
+ }
41
+ // Target files that register the app (React Native entry point detection)
42
+ if (code.includes('AppRegistry.registerComponent') ||
43
+ code.includes('AppRegistry.runApplication')) {
44
+ return true;
45
+ }
46
+ return false;
47
+ }
48
+ /** Inject Zephyr runtime plugin capabilities */
49
+ function injectZephyrRuntime(originalCode, filename, manifestPath) {
50
+ try {
51
+ // Create runtime plugin initialization code
52
+ const runtimePluginCode = generateRuntimePluginCode(manifestPath);
53
+ // Inject at the top of the file
54
+ const injectedCode = `
55
+ // === Zephyr Runtime Plugin Injection ===
56
+ ${runtimePluginCode}
57
+ // === End Zephyr Injection ===
58
+
59
+ ${originalCode}
60
+ `;
61
+ zephyr_agent_1.ze_log.misc(`Injected Zephyr runtime into: ${filename}`);
62
+ return injectedCode;
63
+ }
64
+ catch (error) {
65
+ zephyr_agent_1.ze_log.error(`Failed to inject Zephyr runtime into ${filename}: ${error}`);
66
+ return originalCode; // Return original on error
67
+ }
68
+ }
69
+ /** Generate runtime plugin initialization code */
70
+ function generateRuntimePluginCode(manifestPath) {
71
+ // Generate runtime initialization code using template strings
72
+ // This is more robust than function stringification which can break with minification
73
+ return `// Zephyr Runtime Plugin for React Native
74
+ (function() {
75
+ if (typeof global !== 'undefined' && !global.__ZEPHYR_RUNTIME_PLUGIN__) {
76
+ // Prevent multiple initializations
77
+ try {
78
+ var createZephyrRuntimePlugin = require('zephyr-xpack-internal').createZephyrRuntimePlugin;
79
+
80
+ var plugin = createZephyrRuntimePlugin({
81
+ manifestUrl: '${manifestPath}',
82
+ });
83
+
84
+ // Store globally
85
+ global.__ZEPHYR_RUNTIME_PLUGIN__ = plugin;
86
+
87
+ if (__DEV__) {
88
+ console.log('[Zephyr] Runtime plugin initialized');
89
+ }
90
+ } catch (error) {
91
+ // zephyr-xpack-internal is an optional peer dependency
92
+ if (__DEV__) {
93
+ console.warn('[Zephyr] Runtime plugin not available:', error.message);
94
+ }
95
+ }
96
+ }
97
+ })();`;
98
+ }
99
+ //# sourceMappingURL=zephyr-transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zephyr-transformer.js","sourceRoot":"","sources":["../../src/lib/zephyr-transformer.ts"],"names":[],"mappings":";;AAeA,8BAiCC;AA/CD,+CAAsC;AAUtC,oDAAoD;AACpD,MAAM,mBAAmB,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,CAAC,C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Q,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0EAA0E;IAC1E,IACE,IAAI,CAAC,QAAQ,CAAC,+BAA+B,CAAC;QAC9C,IAAI,CAAC,QAAQ,CAAC,4BAA4B,CAAC,EAC3C,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,gDAAgD;AAChD,SAAS,mBAAmB,CAC1B,YAAoB,EACpB,QAAgB,EAChB,YAAoB;IAEpB,IAAI,CAAC;QACH,4CAA4C;QAC5C,MAAM,iBAAiB,GAAG,yBAAyB,CAAC,YAAY,CAAC,CAAC;QAElE,gCAAgC;QAChC,MAAM,YAAY,GAAG;;EAEvB,iBAAiB;;;EAGjB,YAAY;CACb,CAAC;QAEE,qBAAM,CAAC,IAAI,CAAC,iCAAiC,QAAQ,EAAE,CAAC,CAAC;QACzD,OAAO,YAAY,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,qBAAM,CAAC,KAAK,CAAC,wCAAwC,QAAQ,KAAK,KAAK,EAAE,CAAC,CAAC;QAC3E,OAAO,YAAY,CAAC,CAAC,2BAA2B;IAClD,CAAC;AACH,CAAC;AAED,kDAAkD;AAClD,SAAS,yBAAyB,CAAC,YAAoB;IACrD,8DAA8D;IAC9D,sFAAsF;IACtF,OAAO;;;;;;;;wBAQe,YAAY;;;;;;;;;;;;;;;;MAgB9B,CAAC;AACP,CAAC"}
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "zephyr-metro-plugin",
3
+ "version": "0.1.3",
4
+ "description": "Metro bundler plugin for deploying React Native applications with Zephyr Cloud - OTA updates, Module Federation, and seamless deployment",
5
+ "type": "commonjs",
6
+ "license": "Apache-2.0",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "require": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "author": {
17
+ "name": "ZephyrCloudIO",
18
+ "url": "https://github.com/ZephyrCloudIO"
19
+ },
20
+ "peerDependencies": {
21
+ "metro": ">=0.70.0",
22
+ "react-native": ">=0.60.0",
23
+ "zephyr-xpack-internal": "workspace:*"
24
+ },
25
+ "peerDependenciesMeta": {
26
+ "zephyr-xpack-internal": {
27
+ "optional": true
28
+ }
29
+ },
30
+ "dependencies": {
31
+ "zephyr-agent": "workspace:*",
32
+ "zephyr-edge-contract": "workspace:*"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/ZephyrCloudIO/zephyr-packages.git",
37
+ "directory": "libs/zephyr-metro-plugin"
38
+ },
39
+ "devDependencies": {
40
+ "@rspack/core": "catalog:rspack",
41
+ "@types/find-package-json": "^1.2.6",
42
+ "@types/jest": "catalog:typescript",
43
+ "@typescript-eslint/eslint-plugin": "catalog:eslint",
44
+ "metro-config": "^0.83.3",
45
+ "metro-transform-worker": "^0.83.3",
46
+ "ts-jest": "catalog:typescript"
47
+ },
48
+ "keywords": [
49
+ "metro",
50
+ "react-native",
51
+ "zephyr",
52
+ "zephyr-cloud",
53
+ "module-federation",
54
+ "ota",
55
+ "over-the-air",
56
+ "deployment",
57
+ "bundler",
58
+ "ios",
59
+ "android",
60
+ "cross-platform",
61
+ "micro-frontends",
62
+ "plugin"
63
+ ],
64
+ "publishConfig": {
65
+ "access": "public",
66
+ "provenance": true
67
+ }
68
+ }
package/package.json CHANGED
@@ -1,12 +1,68 @@
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"
7
- },
8
- "keywords": [],
9
- "author": "Lois Z. <loisisar@outlook.com> (https://loiszhao.com/)",
10
- "license": "MIT",
11
- "description": ""
12
- }
3
+ "version": "0.1.3",
4
+ "description": "Metro bundler plugin for deploying React Native applications with Zephyr Cloud - OTA updates, Module Federation, and seamless deployment",
5
+ "type": "commonjs",
6
+ "license": "Apache-2.0",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "require": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "author": {
17
+ "name": "ZephyrCloudIO",
18
+ "url": "https://github.com/ZephyrCloudIO"
19
+ },
20
+ "peerDependencies": {
21
+ "metro": ">=0.70.0",
22
+ "react-native": ">=0.60.0",
23
+ "zephyr-xpack-internal": "0.1.3-next.1"
24
+ },
25
+ "peerDependenciesMeta": {
26
+ "zephyr-xpack-internal": {
27
+ "optional": true
28
+ }
29
+ },
30
+ "dependencies": {
31
+ "zephyr-agent": "0.1.3-next.1",
32
+ "zephyr-edge-contract": "0.1.3-next.1"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/ZephyrCloudIO/zephyr-packages.git",
37
+ "directory": "libs/zephyr-metro-plugin"
38
+ },
39
+ "devDependencies": {
40
+ "@rspack/core": "^1.5.5",
41
+ "@types/find-package-json": "^1.2.6",
42
+ "@types/jest": "29.5.14",
43
+ "@typescript-eslint/eslint-plugin": "^8.27.0",
44
+ "metro-config": "^0.83.3",
45
+ "metro-transform-worker": "^0.83.3",
46
+ "ts-jest": "^29.2.6"
47
+ },
48
+ "keywords": [
49
+ "metro",
50
+ "react-native",
51
+ "zephyr",
52
+ "zephyr-cloud",
53
+ "module-federation",
54
+ "ota",
55
+ "over-the-air",
56
+ "deployment",
57
+ "bundler",
58
+ "ios",
59
+ "android",
60
+ "cross-platform",
61
+ "micro-frontends",
62
+ "plugin"
63
+ ],
64
+ "publishConfig": {
65
+ "access": "public",
66
+ "provenance": true
67
+ }
68
+ }