vite-plugin-zephyr 0.0.0-canary.4 → 0.0.0-canary.5
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/dist/lib/internal/mf-vite-etl/load_resolved_remotes.js +1 -2
- package/dist/lib/internal/mf-vite-etl/load_resolved_remotes.js.map +1 -1
- package/dist/lib/internal/mf-vite-etl/runtime_plugin.js +1 -12
- package/dist/lib/internal/mf-vite-etl/runtime_plugin.js.map +1 -1
- package/dist/lib/internal/mf-vite-etl/runtime_plugins_parser.js +3 -6
- package/dist/lib/internal/mf-vite-etl/runtime_plugins_parser.js.map +1 -1
- package/dist/lib/vite-plugin-zephyr.d.ts +1 -1
- package/dist/lib/vite-plugin-zephyr.js +13 -276
- package/dist/lib/vite-plugin-zephyr.js.map +1 -1
- package/dist/package.json +1 -2
- package/package.json +2 -3
|
@@ -8,9 +8,8 @@ function load_resolved_remotes(resolved_remotes, code) {
|
|
|
8
8
|
const startTime = Date.now();
|
|
9
9
|
try {
|
|
10
10
|
const runtimePluginsExtraction = (0, runtime_plugins_parser_1.parseRuntimePlugin)(code);
|
|
11
|
-
if (!runtimePluginsExtraction)
|
|
11
|
+
if (!runtimePluginsExtraction)
|
|
12
12
|
return code;
|
|
13
|
-
}
|
|
14
13
|
const { pluginsArray, startIndex, endIndex } = runtimePluginsExtraction;
|
|
15
14
|
// Add Zephyr plugin to the array
|
|
16
15
|
// We need to add a Zephyr plugin to the end of the array
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load_resolved_remotes.js","sourceRoot":"","sources":["../../../../src/lib/internal/mf-vite-etl/load_resolved_remotes.ts"],"names":[],"mappings":";;AAKA,
|
|
1
|
+
{"version":3,"file":"load_resolved_remotes.js","sourceRoot":"","sources":["../../../../src/lib/internal/mf-vite-etl/load_resolved_remotes.ts"],"names":[],"mappings":";;AAKA,sDAsCC;AA1CD,+CAAsC;AACtC,qDAAyD;AACzD,qEAA8D;AAE9D,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ePlugin = {
|
|
7
7
|
name: 'zephyr-runtime-remote-resolver',
|
|
8
8
|
beforeInit: (args) => {
|
|
9
|
-
console.log('🚀 ZEPHYR RUNTIME PLUGIN: beforeInit called!');
|
|
10
|
-
console.log('🚀 ZEPHYR RUNTIME PLUGIN: args.userOptions.remotes:', args.userOptions.remotes);
|
|
11
9
|
const resolvedRemoteMap = JSON.parse('__REMOTE_MAP__');
|
|
12
|
-
console.log('🚀 ZEPHYR RUNTIME PLUGIN: resolvedRemoteMap:', resolvedRemoteMap);
|
|
13
10
|
const _windows = typeof window !== 'undefined' ? window : globalThis;
|
|
14
|
-
console.log('🚀 ZEPHYR RUNTIME PLUGIN: _windows:', _windows);
|
|
15
11
|
args.userOptions.remotes.forEach((remote) => {
|
|
16
|
-
console.log('🚀 ZEPHYR RUNTIME PLUGIN: Processing remote:', remote.name, 'original remote:', remote);
|
|
17
12
|
const resolvedRemote = resolvedRemoteMap[remote.name];
|
|
18
|
-
if (!resolvedRemote)
|
|
19
|
-
console.log('🚀 ZEPHYR RUNTIME PLUGIN: No resolved remote found for:', remote.name);
|
|
13
|
+
if (!resolvedRemote)
|
|
20
14
|
return;
|
|
21
|
-
}
|
|
22
15
|
const sessionEdgeURL = _windows.sessionStorage.getItem(resolvedRemote.application_uid);
|
|
23
|
-
console.log('🚀 ZEPHYR RUNTIME PLUGIN: sessionEdgeURL for', remote.name, ':', sessionEdgeURL);
|
|
24
16
|
const urlOverwrite = sessionEdgeURL !== null && sessionEdgeURL !== void 0 ? sessionEdgeURL : resolvedRemote.remote_entry_url;
|
|
25
|
-
console.log('🚀 ZEPHYR RUNTIME PLUGIN: urlOverwrite for', remote.name, ':', urlOverwrite);
|
|
26
17
|
// @ts-expect-error overwriting entry if needed
|
|
27
18
|
remote.entry = urlOverwrite;
|
|
28
|
-
console.log('🚀 ZEPHYR RUNTIME PLUGIN: Updated remote for', remote.name, 'to:', remote);
|
|
29
19
|
});
|
|
30
|
-
console.log('🚀 ZEPHYR RUNTIME PLUGIN: Final args.userOptions.remotes:', args.userOptions.remotes);
|
|
31
20
|
return args;
|
|
32
21
|
},
|
|
33
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime_plugin.js","sourceRoot":"","sources":["../../../../src/lib/internal/mf-vite-etl/runtime_plugin.ts"],"names":[],"mappings":";;AAGA,
|
|
1
|
+
{"version":3,"file":"runtime_plugin.js","sourceRoot":"","sources":["../../../../src/lib/internal/mf-vite-etl/runtime_plugin.ts"],"names":[],"mappings":";;AAGA,sDA+BC;AA/BD,SAAgB,qBAAqB,CAAC,gBAAwC;IAC5E,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAClC,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CACxD,CAAC;IAEF,MAAM,aAAa,GAA4B;QAC7C,IAAI,EAAE,gCAAgC;QACtC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE;YACnB,MAAM,iBAAiB,GACrB,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;YAC/B,MAAM,QAAQ,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC;YACrE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;gBAC1C,MAAM,cAAc,GAAG,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACtD,IAAI,CAAC,cAAc;oBAAE,OAAO;gBAC5B,MAAM,cAAc,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CACpD,cAAc,CAAC,eAAe,CAC/B,CAAC;gBAEF,MAAM,YAAY,GAAG,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,cAAc,CAAC,gBAAgB,CAAC;gBAEvE,+CAA+C;gBAC/C,MAAM,CAAC,KAAK,GAAG,YAAY,CAAC;YAC9B,CAAC,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;IAEF,OAAO,gBAAgB,CAAC,aAAa,CAAC,CAAC,OAAO,CAC5C,gBAAgB,EAChB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,GAA4B;IACpD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACvD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;YAChC,OAAO,GAAG,GAAG,KAAK,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;QACvC,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACvD,OAAO,GAAG,GAAG,KAAK,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9C,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,GAAG,GAAG,MAAM,KAAK,GAAG,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,GAAG,KAAK,KAAK,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACrC,CAAC"}
|
|
@@ -14,14 +14,11 @@ function parseRuntimePlugin(code) {
|
|
|
14
14
|
ranges: true,
|
|
15
15
|
});
|
|
16
16
|
let pluginsArrayNode;
|
|
17
|
-
// Find the plugins array in the runtimeInit call
|
|
17
|
+
// Find the plugins array in the runtimeInit call
|
|
18
18
|
acorn_walk_1.default.simple(ast, {
|
|
19
19
|
CallExpression(node) {
|
|
20
|
-
var _a, _b
|
|
21
|
-
|
|
22
|
-
const isRuntimeInit = ((_a = node.callee) === null || _a === void 0 ? void 0 : _a.name) === 'runtimeInit';
|
|
23
|
-
const isMinifiedInit = ((_c = (_b = node.callee) === null || _b === void 0 ? void 0 : _b.object) === null || _c === void 0 ? void 0 : _c.name) === 'p' && ((_e = (_d = node.callee) === null || _d === void 0 ? void 0 : _d.property) === null || _e === void 0 ? void 0 : _e.name) === 'init';
|
|
24
|
-
if ((isRuntimeInit || isMinifiedInit) && ((_f = node.arguments) === null || _f === void 0 ? void 0 : _f.length) > 0) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
if (((_a = node.callee) === null || _a === void 0 ? void 0 : _a.name) === 'runtimeInit' && ((_b = node.arguments) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
25
22
|
const initArg = node.arguments[0];
|
|
26
23
|
if (initArg.type === 'ObjectExpression') {
|
|
27
24
|
for (const prop of initArg.properties) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime_plugins_parser.js","sourceRoot":"","sources":["../../../../src/lib/internal/mf-vite-etl/runtime_plugins_parser.ts"],"names":[],"mappings":";;AAUA,
|
|
1
|
+
{"version":3,"file":"runtime_plugins_parser.js","sourceRoot":"","sources":["../../../../src/lib/internal/mf-vite-etl/runtime_plugins_parser.ts"],"names":[],"mappings":";;AAUA,gDAgDC;;AA1DD,0DAA0B;AAC1B,oEAA8B;AAC9B,+CAAsC;AAQtC,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,6BAA6B;IAC7B,MAAM,GAAG,GAAG,eAAK,CAAC,KAAK,CAAC,IAAI,EAAE;QAC5B,WAAW,EAAE,QAAQ;QACrB,UAAU,EAAE,QAAQ;QACpB,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,IAAI;KACb,CAAC,CAAC;IAEH,IAAI,gBAAwC,CAAC;IAE7C,iDAAiD;IACjD,oBAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACf,cAAc,CAAC,IAAS;;YACtB,IAAI,CAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,IAAI,MAAK,aAAa,IAAI,CAAA,MAAA,IAAI,CAAC,SAAS,0CAAE,MAAM,IAAG,CAAC,EAAE,CAAC;gBACtE,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;gBAElC,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;oBACxC,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;wBACtC,IACE,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,YAAY;4BAC9B,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS;4BAC3B,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,iBAAiB,EACrC,CAAC;4BACD,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC;4BAC9B,MAAM;wBACR,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IAEH,IACE,CAAC,gBAAgB;QACjB,CAAC,CAAC,OAAO,IAAI,gBAAgB,CAAC;QAC9B,CAAC,CAAC,KAAK,IAAI,gBAAgB,CAAC,EAC5B,CAAC;QACD,qBAAM,CAAC,EAAE,CAAC,8CAA8C,CAAC,CAAC;QAC1D,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,4BAA4B;IAC5B,MAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC;IAC1C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CAAC;IACtC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAEtD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { federation } from '@module-federation/vite';
|
|
2
|
-
import {
|
|
2
|
+
import type { Plugin } from 'vite';
|
|
3
3
|
export type ModuleFederationOptions = Parameters<typeof federation>[0];
|
|
4
4
|
interface VitePluginZephyrOptions {
|
|
5
5
|
mfConfig?: ModuleFederationOptions;
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withZephyr = withZephyr;
|
|
4
4
|
const vite_1 = require("@module-federation/vite");
|
|
5
|
-
const vite_2 = require("vite");
|
|
6
5
|
const zephyr_agent_1 = require("zephyr-agent");
|
|
7
|
-
const zephyr_environment_variables_1 = require("zephyr-environment-variables");
|
|
8
6
|
const extract_mf_plugin_1 = require("./internal/extract/extract_mf_plugin");
|
|
9
7
|
const extract_vite_assets_map_1 = require("./internal/extract/extract_vite_assets_map");
|
|
10
8
|
const extract_mf_vite_remotes_1 = require("./internal/mf-vite-etl/extract-mf-vite-remotes");
|
|
@@ -27,16 +25,15 @@ function zephyrPlugin() {
|
|
|
27
25
|
let root;
|
|
28
26
|
let baseHref = '/';
|
|
29
27
|
let mfPlugin;
|
|
30
|
-
let cachedSpecifier;
|
|
31
28
|
return {
|
|
32
29
|
name: 'with-zephyr',
|
|
33
|
-
|
|
34
|
-
enforce: 'pre',
|
|
30
|
+
enforce: 'post',
|
|
35
31
|
configResolved: async (config) => {
|
|
36
32
|
var _a, _b;
|
|
37
33
|
root = config.root;
|
|
38
34
|
baseHref = config.base || '/';
|
|
39
|
-
|
|
35
|
+
if (config.command === 'serve')
|
|
36
|
+
return;
|
|
40
37
|
zephyr_defer_create({
|
|
41
38
|
builder: 'vite',
|
|
42
39
|
context: config.root,
|
|
@@ -47,129 +44,19 @@ function zephyrPlugin() {
|
|
|
47
44
|
publicDir: config.publicDir,
|
|
48
45
|
});
|
|
49
46
|
mfPlugin = (0, extract_mf_plugin_1.extract_mf_plugin)((_b = config.plugins) !== null && _b !== void 0 ? _b : []);
|
|
50
|
-
// Load .env files into process.env so ZE_PUBLIC_* are available to the agent
|
|
51
|
-
try {
|
|
52
|
-
const loaded = (0, vite_2.loadEnv)(config.mode || 'production', root, '');
|
|
53
|
-
for (const [k, v] of Object.entries(loaded)) {
|
|
54
|
-
if (k.startsWith('ZE_PUBLIC_') && typeof v === 'string') {
|
|
55
|
-
if (!(k in process.env))
|
|
56
|
-
process.env[k] = v;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch (_c) {
|
|
61
|
-
// ignore if loadEnv unavailable
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
// config: (config) => {
|
|
65
|
-
// // Configure Vite to handle JSON imports with import assertions
|
|
66
|
-
// config.build = config.build || {};
|
|
67
|
-
// config.build.rollupOptions = config.build.rollupOptions || {};
|
|
68
|
-
// // Ensure JSON files are treated as external when imported with import assertions
|
|
69
|
-
// const existingExternal = config.build.rollupOptions.external;
|
|
70
|
-
// if (typeof existingExternal === 'function') {
|
|
71
|
-
// const originalExternal = existingExternal;
|
|
72
|
-
// config.build.rollupOptions.external = (
|
|
73
|
-
// id: string,
|
|
74
|
-
// importer: string | undefined,
|
|
75
|
-
// isResolved: boolean
|
|
76
|
-
// ) => {
|
|
77
|
-
// if (id.endsWith('.json') && id.includes('zephyr-manifest')) {
|
|
78
|
-
// return true;
|
|
79
|
-
// }
|
|
80
|
-
// return originalExternal(id, importer, isResolved);
|
|
81
|
-
// };
|
|
82
|
-
// } else {
|
|
83
|
-
// // Convert to function to handle JSON files
|
|
84
|
-
// const externals = Array.isArray(existingExternal)
|
|
85
|
-
// ? existingExternal
|
|
86
|
-
// : existingExternal
|
|
87
|
-
// ? [existingExternal]
|
|
88
|
-
// : [];
|
|
89
|
-
// config.build.rollupOptions.external = (
|
|
90
|
-
// id: string,
|
|
91
|
-
// importer: string | undefined,
|
|
92
|
-
// isResolved: boolean
|
|
93
|
-
// ) => {
|
|
94
|
-
// if (id.endsWith('.json') && id.includes('zephyr-manifest')) {
|
|
95
|
-
// return true;
|
|
96
|
-
// }
|
|
97
|
-
// // Check against existing externals
|
|
98
|
-
// return externals.some((external) => {
|
|
99
|
-
// if (typeof external === 'string') return id === external;
|
|
100
|
-
// if (external instanceof RegExp) return external.test(id);
|
|
101
|
-
// return false;
|
|
102
|
-
// });
|
|
103
|
-
// };
|
|
104
|
-
// }
|
|
105
|
-
// return config;
|
|
106
|
-
// },
|
|
107
|
-
resolveId: async (source) => {
|
|
108
|
-
try {
|
|
109
|
-
const zephyr_engine = await zephyr_engine_defer;
|
|
110
|
-
if (!cachedSpecifier) {
|
|
111
|
-
const appName = zephyr_engine.applicationProperties.name;
|
|
112
|
-
cachedSpecifier = `env:vars:${appName}`;
|
|
113
|
-
}
|
|
114
|
-
if (source === cachedSpecifier) {
|
|
115
|
-
// In dev mode, use a virtual module; in build mode, mark as external
|
|
116
|
-
if (process.env['NODE_ENV'] === 'development') {
|
|
117
|
-
const appName = zephyr_engine.applicationProperties.name;
|
|
118
|
-
return { id: `\0virtual:zephyr-env-${appName}` };
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
// Mark this as external so it gets resolved by the import map at runtime
|
|
122
|
-
return { id: source, external: true };
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
catch (_a) {
|
|
127
|
-
// ignore
|
|
128
|
-
}
|
|
129
|
-
return null;
|
|
130
47
|
},
|
|
131
|
-
// load: async (id) => {
|
|
132
|
-
// // Handle virtual module in dev mode
|
|
133
|
-
// if (id.startsWith('\0virtual:zephyr-env-')) {
|
|
134
|
-
// try {
|
|
135
|
-
// const zephyr_engine = await zephyr_engine_defer;
|
|
136
|
-
// const dependencies = zephyr_engine.federated_dependencies || [];
|
|
137
|
-
// const manifestContent = createManifestContent(dependencies, true);
|
|
138
|
-
// return `export default ${manifestContent};`;
|
|
139
|
-
// } catch (error) {
|
|
140
|
-
// logFn('error', `Failed to load virtual module: ${ZephyrError.format(error)}`);
|
|
141
|
-
// return 'export default {};';
|
|
142
|
-
// }
|
|
143
|
-
// }
|
|
144
|
-
// return null;
|
|
145
|
-
// },
|
|
146
48
|
transform: async (code, id) => {
|
|
147
49
|
try {
|
|
148
|
-
if (id.includes('virtual:mf-REMOTE_ENTRY_ID')
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const result = (0, load_resolved_remotes_1.load_resolved_remotes)(resolved_remotes, code);
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
161
|
-
if (/\.(mjs|cjs|js|ts|jsx|tsx)$/.test(id) && !id.includes('node_modules')) {
|
|
162
|
-
const zephyr_engine = await zephyr_engine_defer;
|
|
163
|
-
if (!cachedSpecifier) {
|
|
164
|
-
const appName = zephyr_engine.applicationProperties.name;
|
|
165
|
-
cachedSpecifier = `env:vars:${appName}`;
|
|
166
|
-
}
|
|
167
|
-
const res = (0, zephyr_environment_variables_1.rewriteEnvReadsToVirtualModule)(String(code), cachedSpecifier);
|
|
168
|
-
if (res && typeof res.code === 'string' && res.code !== code) {
|
|
169
|
-
code = res.code;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return code;
|
|
50
|
+
if (!id.includes('virtual:mf-REMOTE_ENTRY_ID') || !mfPlugin)
|
|
51
|
+
return code;
|
|
52
|
+
const dependencyPairs = (0, extract_mf_vite_remotes_1.extract_remotes_dependencies)(root, mfPlugin._options);
|
|
53
|
+
if (!dependencyPairs)
|
|
54
|
+
return code;
|
|
55
|
+
const zephyr_engine = await zephyr_engine_defer;
|
|
56
|
+
const resolved_remotes = await zephyr_engine.resolve_remote_dependencies(dependencyPairs);
|
|
57
|
+
if (!resolved_remotes)
|
|
58
|
+
return code;
|
|
59
|
+
return (0, load_resolved_remotes_1.load_resolved_remotes)(resolved_remotes, code);
|
|
173
60
|
}
|
|
174
61
|
catch (error) {
|
|
175
62
|
(0, zephyr_agent_1.logFn)('error', zephyr_agent_1.ZephyrError.format(error));
|
|
@@ -177,156 +64,6 @@ function zephyrPlugin() {
|
|
|
177
64
|
return code;
|
|
178
65
|
}
|
|
179
66
|
},
|
|
180
|
-
generateBundle: async function (options, bundle) {
|
|
181
|
-
// Process remoteEntry.js to inject runtime plugin
|
|
182
|
-
if (mfPlugin) {
|
|
183
|
-
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
184
|
-
if (fileName === 'remoteEntry.js' &&
|
|
185
|
-
chunk &&
|
|
186
|
-
typeof chunk === 'object' &&
|
|
187
|
-
'type' in chunk &&
|
|
188
|
-
chunk.type === 'chunk' &&
|
|
189
|
-
'code' in chunk) {
|
|
190
|
-
try {
|
|
191
|
-
const dependencyPairs = (0, extract_mf_vite_remotes_1.extract_remotes_dependencies)(root, mfPlugin._options);
|
|
192
|
-
if (!dependencyPairs) {
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
const zephyr_engine = await zephyr_engine_defer;
|
|
196
|
-
const resolved_remotes = await zephyr_engine.resolve_remote_dependencies(dependencyPairs);
|
|
197
|
-
if (!resolved_remotes) {
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
const result = (0, load_resolved_remotes_1.load_resolved_remotes)(resolved_remotes, chunk.code);
|
|
201
|
-
chunk.code = result;
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
(0, zephyr_agent_1.logFn)('error', zephyr_agent_1.ZephyrError.format(error));
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
// Ensure import assertions are preserved in the final bundle
|
|
210
|
-
if (cachedSpecifier) {
|
|
211
|
-
for (const [, chunk] of Object.entries(bundle)) {
|
|
212
|
-
if (chunk &&
|
|
213
|
-
typeof chunk === 'object' &&
|
|
214
|
-
'type' in chunk &&
|
|
215
|
-
chunk.type === 'chunk' &&
|
|
216
|
-
'code' in chunk) {
|
|
217
|
-
// Replace imports without assertions with imports that have assertions
|
|
218
|
-
const importWithoutAssertion = new RegExp(`import\\s+([^\\s]+)\\s+from\\s*['"]${cachedSpecifier.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}['"]`, 'g');
|
|
219
|
-
if (chunk.code.match(importWithoutAssertion)) {
|
|
220
|
-
chunk.code = chunk.code.replace(importWithoutAssertion, `import $1 from '${cachedSpecifier}' with { type: 'json' }`);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
// Generate the zephyr manifest
|
|
226
|
-
try {
|
|
227
|
-
const zephyr_engine = await zephyr_engine_defer;
|
|
228
|
-
const dependencies = zephyr_engine.federated_dependencies || [];
|
|
229
|
-
const manifestContent = (0, zephyr_agent_1.createManifestContent)(dependencies, true);
|
|
230
|
-
this.emitFile({
|
|
231
|
-
type: 'asset',
|
|
232
|
-
fileName: 'zephyr-manifest.json',
|
|
233
|
-
source: manifestContent,
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
catch (error) {
|
|
237
|
-
(0, zephyr_agent_1.logFn)('error', zephyr_agent_1.ZephyrError.format(error));
|
|
238
|
-
// Fallback to empty manifest if there's an error
|
|
239
|
-
this.emitFile({
|
|
240
|
-
type: 'asset',
|
|
241
|
-
fileName: 'zephyr-manifest.json',
|
|
242
|
-
source: JSON.stringify({
|
|
243
|
-
version: '1.0.0',
|
|
244
|
-
timestamp: new Date().toISOString(),
|
|
245
|
-
dependencies: {},
|
|
246
|
-
zeVars: {},
|
|
247
|
-
}, null, 2),
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
// For dev server mode - serve env module and upload when server starts
|
|
252
|
-
configureServer: async (server) => {
|
|
253
|
-
// Add route to serve zephyr-manifest.json with correct MIME type
|
|
254
|
-
server.middlewares.use((req, res, next) => {
|
|
255
|
-
if (req.url === '/zephyr-manifest.json') {
|
|
256
|
-
void (async () => {
|
|
257
|
-
try {
|
|
258
|
-
const zephyr_engine = await zephyr_engine_defer;
|
|
259
|
-
const dependencies = zephyr_engine.federated_dependencies || [];
|
|
260
|
-
// Use the same function as other plugins to ensure consistency
|
|
261
|
-
const manifestContent = (0, zephyr_agent_1.createManifestContent)(dependencies, true);
|
|
262
|
-
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
263
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
264
|
-
res.end(manifestContent);
|
|
265
|
-
}
|
|
266
|
-
catch (_a) {
|
|
267
|
-
// Fallback to empty manifest if there's an error
|
|
268
|
-
const fallbackManifest = JSON.stringify({
|
|
269
|
-
version: '1.0.0',
|
|
270
|
-
timestamp: new Date().toISOString(),
|
|
271
|
-
dependencies: {},
|
|
272
|
-
zeVars: {},
|
|
273
|
-
}, null, 2);
|
|
274
|
-
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
275
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
276
|
-
res.end(fallbackManifest);
|
|
277
|
-
}
|
|
278
|
-
})();
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
next();
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
// Upload dev build
|
|
285
|
-
try {
|
|
286
|
-
const [vite_internal_options, zephyr_engine] = await Promise.all([
|
|
287
|
-
vite_internal_options_defer,
|
|
288
|
-
zephyr_engine_defer,
|
|
289
|
-
]);
|
|
290
|
-
zephyr_engine.buildProperties.baseHref = baseHref;
|
|
291
|
-
await zephyr_engine.start_new_build();
|
|
292
|
-
const assetsMap = await (0, extract_vite_assets_map_1.extract_vite_assets_map)(zephyr_engine, vite_internal_options);
|
|
293
|
-
await zephyr_engine.upload_assets({
|
|
294
|
-
assetsMap,
|
|
295
|
-
buildStats: await (0, zephyr_agent_1.zeBuildDashData)(zephyr_engine),
|
|
296
|
-
});
|
|
297
|
-
await zephyr_engine.build_finished();
|
|
298
|
-
}
|
|
299
|
-
catch (error) {
|
|
300
|
-
(0, zephyr_agent_1.logFn)('error', zephyr_agent_1.ZephyrError.format(error));
|
|
301
|
-
}
|
|
302
|
-
},
|
|
303
|
-
// Inject import map into HTML
|
|
304
|
-
transformIndexHtml: async (html) => {
|
|
305
|
-
var _a;
|
|
306
|
-
try {
|
|
307
|
-
const zephyr_engine = await zephyr_engine_defer;
|
|
308
|
-
const appName = zephyr_engine.applicationProperties.name;
|
|
309
|
-
// Convert federated dependencies to remotes format
|
|
310
|
-
const remotes = ((_a = zephyr_engine.federated_dependencies) === null || _a === void 0 ? void 0 : _a.map((dep) => ({
|
|
311
|
-
name: dep.name,
|
|
312
|
-
remote_entry_url: dep.default_url,
|
|
313
|
-
}))) || [];
|
|
314
|
-
// Use the same import map creation as Rspack plugin
|
|
315
|
-
const importMap = (0, zephyr_agent_1.buildEnvImportMap)(appName, remotes);
|
|
316
|
-
const importMapScript = `<script type="importmap">${JSON.stringify({ imports: importMap }, null, 2)}</script>`;
|
|
317
|
-
// Check if import map already exists
|
|
318
|
-
if (!html.includes('type="importmap"')) {
|
|
319
|
-
// Inject import map before closing head tag
|
|
320
|
-
html = html.replace('</head>', ` ${importMapScript}\n</head>`);
|
|
321
|
-
}
|
|
322
|
-
return html;
|
|
323
|
-
}
|
|
324
|
-
catch (error) {
|
|
325
|
-
(0, zephyr_agent_1.logFn)('error', `Failed to inject import map: ${zephyr_agent_1.ZephyrError.format(error)}`);
|
|
326
|
-
return html;
|
|
327
|
-
}
|
|
328
|
-
},
|
|
329
|
-
// For production builds
|
|
330
67
|
closeBundle: async () => {
|
|
331
68
|
try {
|
|
332
69
|
const [vite_internal_options, zephyr_engine] = await Promise.all([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-zephyr.js","sourceRoot":"","sources":["../../src/lib/vite-plugin-zephyr.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"vite-plugin-zephyr.js","sourceRoot":"","sources":["../../src/lib/vite-plugin-zephyr.ts"],"names":[],"mappings":";;AAeA,gCAQC;AAvBD,kDAAqD;AAErD,+CAAiF;AACjF,4EAAyE;AACzE,wFAAqF;AACrF,4FAA8F;AAC9F,wFAAqF;AASrF,SAAgB,UAAU,CAAC,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AM,aAAa,CAAC,aAAa,CAAC;oBAChC,SAAS;oBACT,UAAU,EAAE,MAAM,IAAA,8BAAe,EAAC,aAAa,CAAC;iBACjD,CAAC,CAAC;gBACH,MAAM,aAAa,CAAC,cAAc,EAAE,CAAC;YACvC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAA,oBAAK,EAAC,OAAO,EAAE,0BAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/package.json
CHANGED
|
@@ -28,8 +28,7 @@
|
|
|
28
28
|
"json5": "2.2.3",
|
|
29
29
|
"rollup": "catalog:rollup4",
|
|
30
30
|
"vite": "catalog:vite6",
|
|
31
|
-
"zephyr-agent": "workspace:*"
|
|
32
|
-
"zephyr-environment-variables": "workspace:*"
|
|
31
|
+
"zephyr-agent": "workspace:*"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
34
|
"@types/is-ci": "catalog:typescript",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-zephyr",
|
|
3
|
-
"version": "0.0.0-canary.
|
|
3
|
+
"version": "0.0.0-canary.5",
|
|
4
4
|
"description": "Vite plugin for Zephyr",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
"json5": "2.2.3",
|
|
25
25
|
"rollup": "^4.36.0",
|
|
26
26
|
"vite": "^6.2.7",
|
|
27
|
-
"zephyr-agent": "0.0.0-canary.
|
|
28
|
-
"zephyr-environment-variables": "0.0.0"
|
|
27
|
+
"zephyr-agent": "0.0.0-canary.5"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
30
|
"@types/is-ci": "3.0.4",
|