vite-plugin-zephyr 1.1.2 → 1.2.0
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/README.md +45 -1
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +44 -6
- package/dist/index.mjs +3 -0
- package/dist/lib/internal/extract/extract-entrypoint.d.mts +11 -0
- package/dist/lib/internal/extract/extract-entrypoint.d.ts +2 -1
- package/dist/lib/internal/extract/extract-entrypoint.js +53 -38
- package/dist/lib/internal/extract/extract-entrypoint.mjs +32 -0
- package/dist/lib/internal/extract/extract_mf_plugin.d.mts +10 -0
- package/dist/lib/internal/extract/extract_mf_plugin.d.ts +6 -2
- package/dist/lib/internal/extract/extract_mf_plugin.js +48 -5
- package/dist/lib/internal/extract/extract_mf_plugin.mjs +17 -0
- package/dist/lib/internal/extract/extract_vite_assets_map.d.mts +4 -0
- package/dist/lib/internal/extract/extract_vite_assets_map.d.ts +2 -1
- package/dist/lib/internal/extract/extract_vite_assets_map.js +65 -35
- package/dist/lib/internal/extract/extract_vite_assets_map.mjs +49 -0
- package/dist/lib/internal/extract/load_public_dir.d.mts +10 -0
- package/dist/lib/internal/extract/load_public_dir.d.ts +5 -2
- package/dist/lib/internal/extract/load_public_dir.js +57 -19
- package/dist/lib/internal/extract/load_public_dir.mjs +31 -0
- package/dist/lib/internal/extract/load_static_assets.d.mts +4 -0
- package/dist/lib/internal/extract/load_static_assets.d.ts +3 -2
- package/dist/lib/internal/extract/load_static_assets.js +60 -35
- package/dist/lib/internal/extract/load_static_assets.mjs +29 -0
- package/dist/lib/internal/extract/load_static_entries.d.mts +10 -0
- package/dist/lib/internal/extract/load_static_entries.d.ts +5 -2
- package/dist/lib/internal/extract/load_static_entries.js +56 -14
- package/dist/lib/internal/extract/load_static_entries.mjs +31 -0
- package/dist/lib/internal/extract/merge_vite_output_assets.d.mts +13 -0
- package/dist/lib/internal/extract/merge_vite_output_assets.d.ts +13 -0
- package/dist/lib/internal/extract/merge_vite_output_assets.js +68 -0
- package/dist/lib/internal/extract/merge_vite_output_assets.mjs +31 -0
- package/dist/lib/internal/mf-vite-etl/ensure_runtime_plugin.d.mts +31 -0
- package/dist/lib/internal/mf-vite-etl/ensure_runtime_plugin.d.ts +11 -0
- package/dist/lib/internal/mf-vite-etl/ensure_runtime_plugin.js +56 -15
- package/dist/lib/internal/mf-vite-etl/ensure_runtime_plugin.mjs +21 -0
- package/dist/lib/internal/mf-vite-etl/extract-mf-vite-remotes.d.mts +13 -0
- package/dist/lib/internal/mf-vite-etl/extract-mf-vite-remotes.d.ts +1 -0
- package/dist/lib/internal/mf-vite-etl/extract-mf-vite-remotes.js +55 -19
- package/dist/lib/internal/mf-vite-etl/extract-mf-vite-remotes.mjs +24 -0
- package/dist/lib/internal/mf-vite-etl/federation-metadata.d.mts +38 -0
- package/dist/lib/internal/mf-vite-etl/federation-metadata.d.ts +38 -0
- package/dist/lib/internal/mf-vite-etl/federation-metadata.js +154 -0
- package/dist/lib/internal/mf-vite-etl/federation-metadata.mjs +111 -0
- package/dist/lib/internal/mf-vite-etl/runtime_plugin.mjs +68 -159
- package/dist/lib/internal/partial-build-scope.d.mts +12 -0
- package/dist/lib/internal/partial-build-scope.d.ts +12 -0
- package/dist/lib/internal/partial-build-scope.js +83 -0
- package/dist/lib/internal/partial-build-scope.mjs +43 -0
- package/dist/lib/internal/types/zephyr-internal-options.d.mts +13 -0
- package/dist/lib/internal/types/zephyr-internal-options.d.ts +6 -2
- package/dist/lib/internal/types/zephyr-internal-options.js +18 -1
- package/dist/lib/internal/types/zephyr-internal-options.mjs +1 -0
- package/dist/lib/internal/types/zephyr-output.d.mts +23 -0
- package/dist/lib/internal/types/zephyr-output.d.ts +23 -0
- package/dist/lib/internal/types/zephyr-output.js +20 -0
- package/dist/lib/internal/types/zephyr-output.mjs +1 -0
- package/dist/lib/internal/utils/normalize-entrypoint.d.mts +11 -0
- package/dist/lib/internal/utils/normalize-entrypoint.d.ts +1 -0
- package/dist/lib/internal/utils/normalize-entrypoint.js +42 -24
- package/dist/lib/internal/utils/normalize-entrypoint.mjs +12 -0
- package/dist/lib/internal/utils/normalize-vite-path.d.mts +10 -0
- package/dist/lib/internal/utils/normalize-vite-path.d.ts +10 -0
- package/dist/lib/internal/utils/normalize-vite-path.js +51 -0
- package/dist/lib/internal/utils/normalize-vite-path.mjs +11 -0
- package/dist/lib/vite-plugin-zephyr-partial.d.mts +6 -0
- package/dist/lib/vite-plugin-zephyr-partial.d.ts +5 -8
- package/dist/lib/vite-plugin-zephyr-partial.js +75 -27
- package/dist/lib/vite-plugin-zephyr-partial.mjs +64 -0
- package/dist/lib/vite-plugin-zephyr.d.mts +21 -0
- package/dist/lib/vite-plugin-zephyr.d.ts +16 -3
- package/dist/lib/vite-plugin-zephyr.js +685 -239
- package/dist/lib/vite-plugin-zephyr.mjs +662 -0
- package/dist/rslib-runtime.mjs +21 -0
- package/package.json +53 -44
- package/dist/index.js.map +0 -1
- package/dist/lib/internal/extract/extract-entrypoint.js.map +0 -1
- package/dist/lib/internal/extract/extract_mf_plugin.js.map +0 -1
- package/dist/lib/internal/extract/extract_vite_assets_map.js.map +0 -1
- package/dist/lib/internal/extract/load_public_dir.js.map +0 -1
- package/dist/lib/internal/extract/load_static_assets.js.map +0 -1
- package/dist/lib/internal/extract/load_static_entries.js.map +0 -1
- package/dist/lib/internal/mf-vite-etl/ensure_runtime_plugin.js.map +0 -1
- package/dist/lib/internal/mf-vite-etl/extract-mf-vite-remotes.js.map +0 -1
- package/dist/lib/internal/types/zephyr-internal-options.js.map +0 -1
- package/dist/lib/internal/utils/normalize-entrypoint.js.map +0 -1
- package/dist/lib/vite-plugin-zephyr-partial.js.map +0 -1
- package/dist/lib/vite-plugin-zephyr.js.map +0 -1
- package/dist/package.json +0 -85
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
+
import magic_string from "magic-string";
|
|
5
|
+
import { ApplicationContext, ZeErrors, ZephyrEngine, ZephyrError, assertTapFederationPublicationMetadata, assertZephyrBuildTarget, claimPartialAssetMapBatch, commitPartialAssetMapClaimBatch, createManifestContent, handleGlobalError, normalizeBasePath, rewriteEnvReadsToVirtualModule, rollbackPartialAssetMapClaimBatch, savePartialAssetMap, usesPathAddressing, zeBuildAssets, zeBuildDashData, ze_log } from "zephyr-agent";
|
|
6
|
+
import { extractEntrypoint } from "./internal/extract/extract-entrypoint.mjs";
|
|
7
|
+
import { extract_mf_plugins } from "./internal/extract/extract_mf_plugin.mjs";
|
|
8
|
+
import { extract_vite_assets_map } from "./internal/extract/extract_vite_assets_map.mjs";
|
|
9
|
+
import { RESOLVED_ZEPHYR_MF_RUNTIME_PLUGIN_ID, ZEPHYR_MF_RUNTIME_PLUGIN_ID, ensureRuntimePlugin, getRuntimePluginPath } from "./internal/mf-vite-etl/ensure_runtime_plugin.mjs";
|
|
10
|
+
import { extract_remotes_dependencies } from "./internal/mf-vite-etl/extract-mf-vite-remotes.mjs";
|
|
11
|
+
import { createViteModuleFederationPublicationMetadata, getConfigIdentities } from "./internal/mf-vite-etl/federation-metadata.mjs";
|
|
12
|
+
import { resolveVitePartialBuildScope } from "./internal/partial-build-scope.mjs";
|
|
13
|
+
import { __webpack_require__ } from "../rslib-runtime.mjs";
|
|
14
|
+
import * as __rspack_external__module_federation_vite_fd47a9e9 from "@module-federation/vite";
|
|
15
|
+
import * as __rspack_external_node_path_806ed179 from "node:path";
|
|
16
|
+
__webpack_require__.add({
|
|
17
|
+
"@module-federation/vite" (module) {
|
|
18
|
+
module.exports = __rspack_external__module_federation_vite_fd47a9e9;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const DEFAULT_LIBRARY_TYPE = 'module';
|
|
22
|
+
const VITE_ENVIRONMENT_OUTPUT_PREFIX = 'vite-environment:';
|
|
23
|
+
function isOriginAbsoluteBase(base) {
|
|
24
|
+
return 'string' == typeof base && base.startsWith('/') && !base.startsWith('//');
|
|
25
|
+
}
|
|
26
|
+
function mergeClaimedPartialMaps(claims) {
|
|
27
|
+
const merged = {};
|
|
28
|
+
for (const claim of claims)for (const [partialKey, assetsMap] of Object.entries(claim.partialAssetMaps)){
|
|
29
|
+
if (Object.prototype.hasOwnProperty.call(merged, partialKey)) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
30
|
+
message: `Vite partial output "${partialKey}" was produced by multiple build scopes.`
|
|
31
|
+
});
|
|
32
|
+
merged[partialKey] = assetsMap;
|
|
33
|
+
}
|
|
34
|
+
return merged;
|
|
35
|
+
}
|
|
36
|
+
function mergeAssetMaps(maps) {
|
|
37
|
+
const merged = {};
|
|
38
|
+
const paths = new Map();
|
|
39
|
+
for (const assetsMap of maps)for (const [hash, asset] of Object.entries(assetsMap)){
|
|
40
|
+
const existingHash = paths.get(asset.path);
|
|
41
|
+
if (existingHash && existingHash !== hash) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
42
|
+
message: `Vite emitted conflicting partial assets for "${asset.path}".`
|
|
43
|
+
});
|
|
44
|
+
paths.set(asset.path, hash);
|
|
45
|
+
merged[hash] = asset;
|
|
46
|
+
}
|
|
47
|
+
return merged;
|
|
48
|
+
}
|
|
49
|
+
function viteEnvironmentOutputPrefix(environmentName) {
|
|
50
|
+
return `${VITE_ENVIRONMENT_OUTPUT_PREFIX}${encodeURIComponent(environmentName)}:`;
|
|
51
|
+
}
|
|
52
|
+
function viteEnvironmentOutputKey(environmentName, outputDirectory, outputFile, outputFormat, assetsMap) {
|
|
53
|
+
const destination = outputFile ? __rspack_external_node_path_806ed179.join(outputDirectory, __rspack_external_node_path_806ed179.basename(outputFile)) : outputDirectory;
|
|
54
|
+
const assets = Object.values(assetsMap).map((asset)=>[
|
|
55
|
+
asset.path.replace(/\\/g, '/'),
|
|
56
|
+
asset.hash,
|
|
57
|
+
asset.size
|
|
58
|
+
]).sort(([leftPath, leftHash], [rightPath, rightHash])=>leftPath === rightPath ? leftHash.localeCompare(rightHash) : leftPath.localeCompare(rightPath));
|
|
59
|
+
const identity = createHash('sha256').update(JSON.stringify({
|
|
60
|
+
destination: destination.replace(/\\/g, '/'),
|
|
61
|
+
format: outputFormat ?? null,
|
|
62
|
+
assets
|
|
63
|
+
})).digest('hex');
|
|
64
|
+
return `${viteEnvironmentOutputPrefix(environmentName)}${identity}`;
|
|
65
|
+
}
|
|
66
|
+
function parseViteEnvironmentOutputName(key) {
|
|
67
|
+
if (!key.startsWith(VITE_ENVIRONMENT_OUTPUT_PREFIX)) return null;
|
|
68
|
+
const outputIdentity = key.slice(VITE_ENVIRONMENT_OUTPUT_PREFIX.length);
|
|
69
|
+
const separator = outputIdentity.indexOf(':');
|
|
70
|
+
if (separator <= 0 || separator === outputIdentity.length - 1) return null;
|
|
71
|
+
try {
|
|
72
|
+
const environmentName = decodeURIComponent(outputIdentity.slice(0, separator));
|
|
73
|
+
return environmentName || null;
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function prefixAssetsMap(assetsMap, prefix) {
|
|
79
|
+
const normalized = prefix?.replace(/\\/g, '/').replace(/^\/+|\/+$/g, '');
|
|
80
|
+
if (!normalized) return assetsMap;
|
|
81
|
+
return Object.fromEntries(Object.values(assetsMap).map((asset)=>{
|
|
82
|
+
const assetPath = asset.path.replace(/\\/g, '/').replace(/^\/+/, '');
|
|
83
|
+
const prefixedPath = assetPath.startsWith(`${normalized}/`) ? assetPath : `${normalized}/${assetPath}`;
|
|
84
|
+
const prefixedAsset = zeBuildAssets({
|
|
85
|
+
filepath: prefixedPath,
|
|
86
|
+
content: asset.buffer
|
|
87
|
+
});
|
|
88
|
+
return [
|
|
89
|
+
prefixedAsset.hash,
|
|
90
|
+
prefixedAsset
|
|
91
|
+
];
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
function inferServerEntrypoint(partials, override, serverEnvironmentNames) {
|
|
95
|
+
if (override) return normalizeEntrypoint(override);
|
|
96
|
+
const allPaths = Object.values(partials).flatMap((assetsMap)=>Object.values(assetsMap).map((asset)=>asset.path));
|
|
97
|
+
const serverEnvironments = new Set(serverEnvironmentNames);
|
|
98
|
+
const serverPaths = Object.entries(partials).flatMap(([key, assetsMap])=>{
|
|
99
|
+
const environmentName = parseViteEnvironmentOutputName(key);
|
|
100
|
+
return environmentName && serverEnvironments.has(environmentName) ? Object.values(assetsMap).map((asset)=>asset.path) : [];
|
|
101
|
+
});
|
|
102
|
+
const paths = serverEnvironmentNames.length > 0 ? serverPaths : allPaths;
|
|
103
|
+
const preferred = [
|
|
104
|
+
'server/index.js',
|
|
105
|
+
'server/index.mjs',
|
|
106
|
+
'server/index.cjs',
|
|
107
|
+
'ssr/index.js',
|
|
108
|
+
'ssr/index.mjs',
|
|
109
|
+
'ssr/index.cjs',
|
|
110
|
+
'rsc/index.js',
|
|
111
|
+
'rsc/index.mjs',
|
|
112
|
+
'rsc/index.cjs'
|
|
113
|
+
];
|
|
114
|
+
return preferred.find((candidate)=>paths.includes(candidate)) ?? paths.find((candidate)=>/(^|\/)(server|index)\.(mjs|cjs|js)$/.test(candidate));
|
|
115
|
+
}
|
|
116
|
+
function commonDirectory(paths) {
|
|
117
|
+
if (0 === paths.length) return;
|
|
118
|
+
const resolvedPaths = paths.map((item)=>__rspack_external_node_path_806ed179.resolve(item));
|
|
119
|
+
let candidate = resolvedPaths[0];
|
|
120
|
+
while(candidate && !resolvedPaths.every((item)=>{
|
|
121
|
+
const relative = __rspack_external_node_path_806ed179.relative(candidate, item);
|
|
122
|
+
return !relative || !relative.startsWith(`..${__rspack_external_node_path_806ed179.sep}`) && '..' !== relative;
|
|
123
|
+
})){
|
|
124
|
+
const parent = __rspack_external_node_path_806ed179.dirname(candidate);
|
|
125
|
+
if (parent === candidate) return;
|
|
126
|
+
candidate = parent;
|
|
127
|
+
}
|
|
128
|
+
if (candidate === __rspack_external_node_path_806ed179.parse(candidate).root && resolvedPaths.length > 1) return;
|
|
129
|
+
return candidate;
|
|
130
|
+
}
|
|
131
|
+
function normalizeEntrypoint(entrypoint) {
|
|
132
|
+
const normalized = entrypoint.replace(/\\/g, '/').replace(/^\.?\/+/, '');
|
|
133
|
+
const segments = normalized.split('/').filter((segment)=>segment && '.' !== segment);
|
|
134
|
+
if (!normalized || 0 === segments.length || segments.includes('..')) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
135
|
+
message: `Vite entrypoint must be a relative path inside the snapshot: "${entrypoint}".`
|
|
136
|
+
});
|
|
137
|
+
return segments.join('/');
|
|
138
|
+
}
|
|
139
|
+
function uniqueParticipant(base, reserved) {
|
|
140
|
+
let participant = base;
|
|
141
|
+
let suffix = 1;
|
|
142
|
+
const used = new Set(reserved);
|
|
143
|
+
while(used.has(participant))participant = `${base}-${suffix++}`;
|
|
144
|
+
return participant;
|
|
145
|
+
}
|
|
146
|
+
function toModuleFederationConfigArray(mfConfig) {
|
|
147
|
+
if (!mfConfig) return [];
|
|
148
|
+
return Array.isArray(mfConfig) ? mfConfig : [
|
|
149
|
+
mfConfig
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
function attachViteFederationBuildStats(buildStats, federationMetadata) {
|
|
153
|
+
const federation = federationMetadata.federation;
|
|
154
|
+
if (!federation || 0 === federation.length) return buildStats;
|
|
155
|
+
const legacyFederation = 1 === federation.length ? federation[0] : void 0;
|
|
156
|
+
return {
|
|
157
|
+
...buildStats,
|
|
158
|
+
federation,
|
|
159
|
+
...legacyFederation ? {
|
|
160
|
+
remote: legacyFederation.remote,
|
|
161
|
+
mf_manifest: legacyFederation.mf_manifest,
|
|
162
|
+
library_type: legacyFederation.library_type,
|
|
163
|
+
exposes: legacyFederation.exposes,
|
|
164
|
+
shared: legacyFederation.shared
|
|
165
|
+
} : {
|
|
166
|
+
remote: void 0,
|
|
167
|
+
mf_manifest: void 0,
|
|
168
|
+
library_type: void 0,
|
|
169
|
+
exposes: void 0,
|
|
170
|
+
shared: void 0
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function loadModuleFederationPlugin() {
|
|
175
|
+
let moduleFederation;
|
|
176
|
+
try {
|
|
177
|
+
moduleFederation = __webpack_require__("@module-federation/vite");
|
|
178
|
+
} catch (error) {
|
|
179
|
+
throw new ZephyrError(ZeErrors.ERR_UNKNOWN, {
|
|
180
|
+
message: `vite-plugin-zephyr: @module-federation/vite is required when mfConfig is provided. Install a compatible version of @module-federation/vite to use Module Federation with withZephyr().${error instanceof Error ? ` Original error: ${error.message}` : ''}`
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if ('function' != typeof moduleFederation.federation) throw new ZephyrError(ZeErrors.ERR_UNKNOWN, {
|
|
184
|
+
message: 'vite-plugin-zephyr: failed to load @module-federation/vite federation plugin'
|
|
185
|
+
});
|
|
186
|
+
return moduleFederation.federation;
|
|
187
|
+
}
|
|
188
|
+
function withZephyrCore(options = {}) {
|
|
189
|
+
const { zephyr_engine_defer, zephyr_defer_create } = ZephyrEngine.defer_create();
|
|
190
|
+
const hooks = options.hooks;
|
|
191
|
+
const preservesLockedArtifactPaths = 'tap-app' === options.target;
|
|
192
|
+
const buildInvocationId = `vite-${randomUUID()}`;
|
|
193
|
+
const usesExternalPartialBuild = void 0 !== options.partialBuild || Boolean(process.env['ZE_BUILD_INVOCATION_ID']?.trim());
|
|
194
|
+
const externalPartialScope = usesExternalPartialBuild ? resolveVitePartialBuildScope(options.partialBuild) : void 0;
|
|
195
|
+
let resolve_vite_internal_options;
|
|
196
|
+
const vite_internal_options_defer = new Promise((resolve)=>{
|
|
197
|
+
resolve_vite_internal_options = resolve;
|
|
198
|
+
});
|
|
199
|
+
let cachedSpecifier;
|
|
200
|
+
let entrypoint;
|
|
201
|
+
const configureModuleFederationRuntime = (config)=>preservesLockedArtifactPaths ? config : ensureRuntimePlugin(config);
|
|
202
|
+
const mfConfigSources = toModuleFederationConfigArray(options.mfConfig).map(configureModuleFederationRuntime);
|
|
203
|
+
const ownedConfigIdentities = new Set(mfConfigSources.flatMap((config)=>getConfigIdentities(config)));
|
|
204
|
+
let environmentNames = [];
|
|
205
|
+
let environmentMetadata = new Map();
|
|
206
|
+
let sharedOutputRoot;
|
|
207
|
+
let isWatchMode = false;
|
|
208
|
+
let buildGeneration = 0;
|
|
209
|
+
let applicationContext;
|
|
210
|
+
let uploadMetadata;
|
|
211
|
+
let baseHref = '';
|
|
212
|
+
let supportsBuildApp = false;
|
|
213
|
+
const registerModuleFederationConfigs = (configs)=>{
|
|
214
|
+
for (const config of configs){
|
|
215
|
+
const identities = getConfigIdentities(config);
|
|
216
|
+
if (identities.some((identity)=>ownedConfigIdentities.has(identity))) continue;
|
|
217
|
+
const runtimeConfigured = configureModuleFederationRuntime(config);
|
|
218
|
+
if (!mfConfigSources.includes(runtimeConfigured)) {
|
|
219
|
+
mfConfigSources.push(runtimeConfigured);
|
|
220
|
+
for (const identity of getConfigIdentities(runtimeConfigured))ownedConfigIdentities.add(identity);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const getModuleFederationPublicationMetadata = ()=>createViteModuleFederationPublicationMetadata(mfConfigSources);
|
|
225
|
+
return {
|
|
226
|
+
name: 'with-zephyr',
|
|
227
|
+
enforce: 'pre',
|
|
228
|
+
config: (config, env)=>{
|
|
229
|
+
registerModuleFederationConfigs(extract_mf_plugins(config.plugins ?? []).map((plugin)=>plugin._options));
|
|
230
|
+
return preservesLockedArtifactPaths || 'build' !== env.command || null != config.base ? null : {
|
|
231
|
+
base: './'
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
configResolved: async (config)=>{
|
|
235
|
+
const vite = await import("vite");
|
|
236
|
+
supportsBuildApp = Number.parseInt(vite.version.split('.')[0] ?? '0', 10) >= 6;
|
|
237
|
+
const root = config.root;
|
|
238
|
+
baseHref = normalizeBasePath(config.base);
|
|
239
|
+
entrypoint = normalizeEntrypoint(options.entrypoint ?? extractEntrypoint(config));
|
|
240
|
+
isWatchMode = Boolean(config.build?.watch);
|
|
241
|
+
const configuredEnvironments = config.environments ?? {};
|
|
242
|
+
environmentNames = Object.keys(configuredEnvironments);
|
|
243
|
+
environmentMetadata = new Map(Object.entries(configuredEnvironments).map(([name, environment])=>[
|
|
244
|
+
name,
|
|
245
|
+
{
|
|
246
|
+
consumer: environment.consumer,
|
|
247
|
+
outputDir: environment.build?.outDir ? __rspack_external_node_path_806ed179.resolve(root, environment.build.outDir) : void 0
|
|
248
|
+
}
|
|
249
|
+
]));
|
|
250
|
+
const outputDirectories = [
|
|
251
|
+
...environmentMetadata.values()
|
|
252
|
+
].map(({ outputDir })=>outputDir).filter((value)=>!!value);
|
|
253
|
+
sharedOutputRoot = preservesLockedArtifactPaths || outputDirectories.length !== environmentNames.length ? void 0 : commonDirectory(outputDirectories);
|
|
254
|
+
zephyr_defer_create({
|
|
255
|
+
builder: 'vite',
|
|
256
|
+
context: root,
|
|
257
|
+
target: options.target
|
|
258
|
+
});
|
|
259
|
+
try {
|
|
260
|
+
const zephyrEngine = await zephyr_engine_defer;
|
|
261
|
+
if (usesPathAddressing(await zephyrEngine.application_configuration) && isOriginAbsoluteBase(config.base)) ze_log.init(`The resolved Vite base '${config.base}' is still origin-absolute for a path-addressed target. A later config hook may have overridden Zephyr's relative base.`);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
handleGlobalError(error);
|
|
264
|
+
}
|
|
265
|
+
resolve_vite_internal_options({
|
|
266
|
+
root,
|
|
267
|
+
outDir: config.build?.outDir,
|
|
268
|
+
publicDir: config.publicDir,
|
|
269
|
+
target: options.target
|
|
270
|
+
});
|
|
271
|
+
registerModuleFederationConfigs(extract_mf_plugins(config.plugins ?? []).map((plugin)=>plugin._options));
|
|
272
|
+
const federationMetadata = getModuleFederationPublicationMetadata();
|
|
273
|
+
const mfConfigs = federationMetadata.mfConfigs ?? [];
|
|
274
|
+
if (mfConfigs.length > 0 && !preservesLockedArtifactPaths) try {
|
|
275
|
+
const dependencyPairs = [
|
|
276
|
+
...new Map(mfConfigs.flatMap((mfConfig)=>extract_remotes_dependencies(root, mfConfig) ?? []).map((dependency)=>[
|
|
277
|
+
`${dependency.name}:${dependency.version}`,
|
|
278
|
+
dependency
|
|
279
|
+
])).values()
|
|
280
|
+
];
|
|
281
|
+
if (dependencyPairs.length > 0) {
|
|
282
|
+
const zephyr_engine = await zephyr_engine_defer;
|
|
283
|
+
await zephyr_engine.resolve_remote_dependencies(dependencyPairs, DEFAULT_LIBRARY_TYPE);
|
|
284
|
+
ze_log.remotes(`Resolved ${dependencyPairs.length} remote dependencies in configResolved`);
|
|
285
|
+
}
|
|
286
|
+
} catch (error) {
|
|
287
|
+
handleGlobalError(error);
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
const loaded = vite.loadEnv(config.mode || 'production', root, '');
|
|
291
|
+
for (const [k, v] of Object.entries(loaded))if (k.startsWith('ZE_PUBLIC_') && 'string' == typeof v && !(k in process.env)) process.env[k] = v;
|
|
292
|
+
} catch {}
|
|
293
|
+
},
|
|
294
|
+
resolveId: async (source)=>{
|
|
295
|
+
if (source === ZEPHYR_MF_RUNTIME_PLUGIN_ID) return RESOLVED_ZEPHYR_MF_RUNTIME_PLUGIN_ID;
|
|
296
|
+
try {
|
|
297
|
+
const zephyr_engine = await zephyr_engine_defer;
|
|
298
|
+
if (!cachedSpecifier) cachedSpecifier = `env:vars:${zephyr_engine.application_uid}`;
|
|
299
|
+
if (source === cachedSpecifier) {
|
|
300
|
+
if ('development' === process.env['NODE_ENV']) return '/zephyr-manifest.json';
|
|
301
|
+
return {
|
|
302
|
+
id: source,
|
|
303
|
+
external: true
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
} catch {}
|
|
307
|
+
return null;
|
|
308
|
+
},
|
|
309
|
+
load: async (id)=>{
|
|
310
|
+
if (id === RESOLVED_ZEPHYR_MF_RUNTIME_PLUGIN_ID) return readFile(getRuntimePluginPath(), 'utf8');
|
|
311
|
+
return null;
|
|
312
|
+
},
|
|
313
|
+
transform: {
|
|
314
|
+
order: 'post',
|
|
315
|
+
filter: {
|
|
316
|
+
id: /\.(mjs|cjs|js|ts|jsx|tsx)/
|
|
317
|
+
},
|
|
318
|
+
handler: async (code, id)=>{
|
|
319
|
+
if (preservesLockedArtifactPaths) return null;
|
|
320
|
+
try {
|
|
321
|
+
if (!id.includes('node_modules')) {
|
|
322
|
+
const zephyr_engine = await zephyr_engine_defer;
|
|
323
|
+
if (!cachedSpecifier) cachedSpecifier = `env:vars:${zephyr_engine.application_uid}`;
|
|
324
|
+
const res = rewriteEnvReadsToVirtualModule(String(code), cachedSpecifier);
|
|
325
|
+
if (res && 'string' == typeof res.code && res.code !== code) {
|
|
326
|
+
code = res.code;
|
|
327
|
+
return {
|
|
328
|
+
code,
|
|
329
|
+
map: new magic_string(code).generateMap({
|
|
330
|
+
hires: true
|
|
331
|
+
})
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return null;
|
|
336
|
+
} catch (error) {
|
|
337
|
+
handleGlobalError(error);
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
renderChunk: {
|
|
343
|
+
order: 'post',
|
|
344
|
+
handler (code) {
|
|
345
|
+
if (preservesLockedArtifactPaths || !cachedSpecifier) return null;
|
|
346
|
+
const importWithoutAttribute = new RegExp(`import\\s+([^\\s]+)\\s+from\\s*['"]${cachedSpecifier.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}['"]`, 'g');
|
|
347
|
+
const nextCode = code.replace(importWithoutAttribute, `import $1 from '${cachedSpecifier}' with { type: 'json' }`);
|
|
348
|
+
return nextCode === code ? null : {
|
|
349
|
+
code: nextCode,
|
|
350
|
+
map: null
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
generateBundle: async function() {
|
|
355
|
+
if (preservesLockedArtifactPaths) return;
|
|
356
|
+
try {
|
|
357
|
+
const zephyr_engine = await zephyr_engine_defer;
|
|
358
|
+
const dependencies = zephyr_engine.federated_dependencies || [];
|
|
359
|
+
const manifestContent = createManifestContent(dependencies, true);
|
|
360
|
+
this.emitFile({
|
|
361
|
+
type: 'asset',
|
|
362
|
+
fileName: 'zephyr-manifest.json',
|
|
363
|
+
source: manifestContent
|
|
364
|
+
});
|
|
365
|
+
} catch (error) {
|
|
366
|
+
handleGlobalError(error);
|
|
367
|
+
this.emitFile({
|
|
368
|
+
type: 'asset',
|
|
369
|
+
fileName: 'zephyr-manifest.json',
|
|
370
|
+
source: JSON.stringify({
|
|
371
|
+
version: '1.0.0',
|
|
372
|
+
timestamp: new Date().toISOString(),
|
|
373
|
+
dependencies: {},
|
|
374
|
+
zeVars: {}
|
|
375
|
+
}, null, 2)
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
configureServer: async (server)=>{
|
|
380
|
+
try {
|
|
381
|
+
const zephyr_engine = await zephyr_engine_defer;
|
|
382
|
+
if (!cachedSpecifier) cachedSpecifier = `env:vars:${zephyr_engine.application_uid}`;
|
|
383
|
+
server.middlewares.use((req, res, next)=>{
|
|
384
|
+
(async ()=>{
|
|
385
|
+
if (!req.url) return void next();
|
|
386
|
+
const requestUrl = req.url.split('?')[0];
|
|
387
|
+
if ('/zephyr-manifest.json' === requestUrl) try {
|
|
388
|
+
const dependencies = zephyr_engine.federated_dependencies || [];
|
|
389
|
+
const manifestContent = createManifestContent(dependencies, true);
|
|
390
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
391
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
392
|
+
res.end(manifestContent);
|
|
393
|
+
return;
|
|
394
|
+
} catch (error) {
|
|
395
|
+
handleGlobalError(error);
|
|
396
|
+
}
|
|
397
|
+
next();
|
|
398
|
+
})();
|
|
399
|
+
});
|
|
400
|
+
} catch {}
|
|
401
|
+
},
|
|
402
|
+
writeBundle: async function(outputOptions, bundle) {
|
|
403
|
+
const partialClaims = [];
|
|
404
|
+
try {
|
|
405
|
+
const [vite_internal_options, zephyr_engine] = await Promise.all([
|
|
406
|
+
vite_internal_options_defer,
|
|
407
|
+
zephyr_engine_defer
|
|
408
|
+
]);
|
|
409
|
+
zephyr_engine.buildProperties.baseHref = baseHref;
|
|
410
|
+
const environmentName = this.environment?.name;
|
|
411
|
+
const isMultiEnvironment = environmentNames.length > 1;
|
|
412
|
+
if (isWatchMode && isMultiEnvironment) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
413
|
+
message: "Vite multi-environment watch publication is not supported because environment rebuilds do not expose an atomic application generation."
|
|
414
|
+
});
|
|
415
|
+
const outputDirectory = __rspack_external_node_path_806ed179.resolve(vite_internal_options.root, outputOptions.dir ?? (outputOptions.file ? __rspack_external_node_path_806ed179.dirname(outputOptions.file) : vite_internal_options.outDir));
|
|
416
|
+
const resolvedEnvironmentName = environmentName ?? [
|
|
417
|
+
...environmentMetadata.entries()
|
|
418
|
+
].find(([, metadata])=>metadata.outputDir === outputDirectory)?.[0] ?? (1 === environmentNames.length ? environmentNames[0] : void 0);
|
|
419
|
+
const coordinateWithBuildApp = supportsBuildApp && !isWatchMode;
|
|
420
|
+
if (coordinateWithBuildApp && !resolvedEnvironmentName) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
421
|
+
message: `Could not associate Vite output directory "${outputDirectory}" with an environment.`
|
|
422
|
+
});
|
|
423
|
+
let assetPrefix;
|
|
424
|
+
if (coordinateWithBuildApp && isMultiEnvironment && !preservesLockedArtifactPaths) {
|
|
425
|
+
if (!sharedOutputRoot) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
426
|
+
message: 'Could not determine a shared output root for Vite environments.'
|
|
427
|
+
});
|
|
428
|
+
const relativeOutput = __rspack_external_node_path_806ed179.relative(sharedOutputRoot, outputDirectory);
|
|
429
|
+
if ('..' === relativeOutput || relativeOutput.startsWith(`..${__rspack_external_node_path_806ed179.sep}`) || __rspack_external_node_path_806ed179.isAbsolute(relativeOutput)) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
430
|
+
message: `Vite environment output "${outputDirectory}" is outside shared output root "${sharedOutputRoot}".`
|
|
431
|
+
});
|
|
432
|
+
assetPrefix = relativeOutput ? relativeOutput.split(__rspack_external_node_path_806ed179.sep).join('/') : void 0;
|
|
433
|
+
}
|
|
434
|
+
const extractionOptions = {
|
|
435
|
+
...vite_internal_options,
|
|
436
|
+
dir: outputOptions.dir,
|
|
437
|
+
outDir: outputDirectory,
|
|
438
|
+
assets: bundle,
|
|
439
|
+
publicDir: isMultiEnvironment && resolvedEnvironmentName && environmentMetadata.get(resolvedEnvironmentName)?.consumer === 'server' ? void 0 : vite_internal_options.publicDir
|
|
440
|
+
};
|
|
441
|
+
let assetsMap = await extract_vite_assets_map(zephyr_engine, extractionOptions);
|
|
442
|
+
if (coordinateWithBuildApp) {
|
|
443
|
+
if (!resolvedEnvironmentName) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
444
|
+
message: `Could not associate Vite output directory "${outputDirectory}" with an environment.`
|
|
445
|
+
});
|
|
446
|
+
const persistedAssetsMap = preservesLockedArtifactPaths ? assetsMap : prefixAssetsMap(assetsMap, assetPrefix);
|
|
447
|
+
await savePartialAssetMap(zephyr_engine.application_uid, viteEnvironmentOutputKey(resolvedEnvironmentName, outputDirectory, outputOptions.file, outputOptions.format, persistedAssetsMap), persistedAssetsMap, {
|
|
448
|
+
invocationId: buildInvocationId,
|
|
449
|
+
generation: buildGeneration
|
|
450
|
+
});
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (!isWatchMode && externalPartialScope) {
|
|
454
|
+
const batch = await claimPartialAssetMapBatch(zephyr_engine.application_uid, [
|
|
455
|
+
externalPartialScope
|
|
456
|
+
]);
|
|
457
|
+
if (!batch) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
458
|
+
message: 'Vite partialBuild was configured, but its external partial output was unavailable or already claimed.'
|
|
459
|
+
});
|
|
460
|
+
partialClaims.push(...batch.claims);
|
|
461
|
+
const partials = mergeClaimedPartialMaps(partialClaims);
|
|
462
|
+
assetsMap = mergeAssetMaps([
|
|
463
|
+
...Object.values(partials),
|
|
464
|
+
assetsMap
|
|
465
|
+
]);
|
|
466
|
+
}
|
|
467
|
+
if (!zephyr_engine.hasActiveBuild) await zephyr_engine.start_new_build();
|
|
468
|
+
const federationMetadata = getModuleFederationPublicationMetadata();
|
|
469
|
+
assertTapFederationPublicationMetadata({
|
|
470
|
+
target: options.target,
|
|
471
|
+
mfConfigs: federationMetadata.mfConfigs,
|
|
472
|
+
federation: federationMetadata.federation
|
|
473
|
+
});
|
|
474
|
+
await zephyr_engine.upload_assets({
|
|
475
|
+
assetsMap,
|
|
476
|
+
buildStats: attachViteFederationBuildStats(await zeBuildDashData(zephyr_engine), federationMetadata),
|
|
477
|
+
mfConfig: federationMetadata.mfConfig,
|
|
478
|
+
mfConfigs: federationMetadata.mfConfigs,
|
|
479
|
+
hooks,
|
|
480
|
+
entrypoint,
|
|
481
|
+
snapshotType: options.snapshotType ?? 'csr'
|
|
482
|
+
});
|
|
483
|
+
await zephyr_engine.build_finished();
|
|
484
|
+
await commitPartialAssetMapClaimBatch(zephyr_engine.application_uid, partialClaims.map(({ claimId })=>claimId));
|
|
485
|
+
} catch (error) {
|
|
486
|
+
try {
|
|
487
|
+
const zephyr_engine = await zephyr_engine_defer;
|
|
488
|
+
zephyr_engine.build_failed();
|
|
489
|
+
} catch {}
|
|
490
|
+
if (partialClaims.length > 0) try {
|
|
491
|
+
const zephyr_engine = await zephyr_engine_defer;
|
|
492
|
+
await rollbackPartialAssetMapClaimBatch(zephyr_engine.application_uid, partialClaims.map(({ claimId })=>claimId));
|
|
493
|
+
} catch (restoreError) {
|
|
494
|
+
handleGlobalError(restoreError);
|
|
495
|
+
}
|
|
496
|
+
handleGlobalError(error);
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
buildApp: {
|
|
500
|
+
order: 'post',
|
|
501
|
+
async handler (builder) {
|
|
502
|
+
if (!supportsBuildApp) return;
|
|
503
|
+
const environments = Object.entries(builder.environments);
|
|
504
|
+
if (isWatchMode) {
|
|
505
|
+
if (environments.length > 1) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
506
|
+
message: "Vite multi-environment watch publication is not supported because environment rebuilds do not expose an atomic application generation."
|
|
507
|
+
});
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
if (0 === environments.length) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
511
|
+
message: 'Vite exposed no build environments for Zephyr publication.'
|
|
512
|
+
});
|
|
513
|
+
let incomplete = environments.filter(([, environment])=>!environment.isBuilt).map(([name])=>name);
|
|
514
|
+
if (incomplete.length === environments.length) {
|
|
515
|
+
for (const [, environment] of environments)await builder.build(environment);
|
|
516
|
+
incomplete = environments.filter(([, environment])=>!environment.isBuilt).map(([name])=>name);
|
|
517
|
+
}
|
|
518
|
+
if (incomplete.length > 0) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
519
|
+
message: `Vite completed without these environments: ${incomplete.join(', ')}. Zephyr will not publish partial compiler output.`
|
|
520
|
+
});
|
|
521
|
+
const partialClaims = [];
|
|
522
|
+
const generation = buildGeneration++;
|
|
523
|
+
try {
|
|
524
|
+
const zephyrEngine = await zephyr_engine_defer;
|
|
525
|
+
zephyrEngine.buildProperties.baseHref = baseHref;
|
|
526
|
+
const claimScopes = [
|
|
527
|
+
{
|
|
528
|
+
invocationId: buildInvocationId,
|
|
529
|
+
generation
|
|
530
|
+
},
|
|
531
|
+
...externalPartialScope ? [
|
|
532
|
+
externalPartialScope
|
|
533
|
+
] : []
|
|
534
|
+
];
|
|
535
|
+
const batch = await claimPartialAssetMapBatch(zephyrEngine.application_uid, claimScopes);
|
|
536
|
+
if (!batch) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
537
|
+
message: externalPartialScope ? 'Vite could not atomically claim both environment and configured external partial output.' : 'Vite environment output was unavailable or already claimed.'
|
|
538
|
+
});
|
|
539
|
+
partialClaims.push(...batch.claims);
|
|
540
|
+
const claimedPartials = mergeClaimedPartialMaps(partialClaims);
|
|
541
|
+
if (0 === Object.keys(claimedPartials).length) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
542
|
+
message: 'Vite produced no environment assets for Zephyr publication.'
|
|
543
|
+
});
|
|
544
|
+
const expectedEnvironmentNames = new Set(environments.map(([name])=>name));
|
|
545
|
+
const environmentOutputCounts = new Map(environments.map(([name])=>[
|
|
546
|
+
name,
|
|
547
|
+
0
|
|
548
|
+
]));
|
|
549
|
+
const unexpectedEnvironmentOutputs = [];
|
|
550
|
+
for (const key of Object.keys(claimedPartials)){
|
|
551
|
+
if (!key.startsWith(VITE_ENVIRONMENT_OUTPUT_PREFIX)) continue;
|
|
552
|
+
const environmentName = parseViteEnvironmentOutputName(key);
|
|
553
|
+
if (!environmentName || !expectedEnvironmentNames.has(environmentName)) {
|
|
554
|
+
unexpectedEnvironmentOutputs.push(key);
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
environmentOutputCounts.set(environmentName, (environmentOutputCounts.get(environmentName) ?? 0) + 1);
|
|
558
|
+
}
|
|
559
|
+
const missingEnvironmentOutputs = environments.map(([name])=>name).filter((name)=>0 === environmentOutputCounts.get(name)).map(viteEnvironmentOutputPrefix);
|
|
560
|
+
if (missingEnvironmentOutputs.length > 0) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
561
|
+
message: `Vite did not produce Zephyr output for: ${missingEnvironmentOutputs.join(', ')}`
|
|
562
|
+
});
|
|
563
|
+
if (unexpectedEnvironmentOutputs.length > 0) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
564
|
+
message: 'Vite found stale or unexpected environment output for: ' + unexpectedEnvironmentOutputs.join(', ')
|
|
565
|
+
});
|
|
566
|
+
const serverEnvironmentNames = environments.filter(([name, environment])=>environment.config?.consumer === 'server' || environmentMetadata.get(name)?.consumer === 'server').map(([name])=>name);
|
|
567
|
+
const inferredSsr = serverEnvironmentNames.length > 0;
|
|
568
|
+
const snapshotType = options.snapshotType ?? (!preservesLockedArtifactPaths && inferredSsr ? 'ssr' : 'csr');
|
|
569
|
+
const finalEntrypoint = 'ssr' === snapshotType ? inferServerEntrypoint(claimedPartials, options.entrypoint, serverEnvironmentNames) : preservesLockedArtifactPaths ? void 0 : options.entrypoint ?? entrypoint;
|
|
570
|
+
if ('ssr' === snapshotType && !finalEntrypoint) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
571
|
+
message: 'Could not infer a Vite server entrypoint. Set withZephyr({ entrypoint }).'
|
|
572
|
+
});
|
|
573
|
+
if ('ssr' === snapshotType && finalEntrypoint && !Object.values(claimedPartials).some((assetsMap)=>Object.values(assetsMap).some((asset)=>asset.path === finalEntrypoint))) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
574
|
+
message: `Vite server entrypoint "${finalEntrypoint}" was not emitted in the coordinated snapshot.`
|
|
575
|
+
});
|
|
576
|
+
uploadMetadata = {
|
|
577
|
+
snapshotType,
|
|
578
|
+
entrypoint: finalEntrypoint
|
|
579
|
+
};
|
|
580
|
+
applicationContext ??= new ApplicationContext({
|
|
581
|
+
applicationUid: zephyrEngine.application_uid,
|
|
582
|
+
prepare: ()=>zephyrEngine.hasActiveBuild ? void 0 : zephyrEngine.start_new_build(),
|
|
583
|
+
publish: async ({ assetsMap })=>{
|
|
584
|
+
if (!uploadMetadata) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
585
|
+
message: 'Vite upload metadata was not prepared.'
|
|
586
|
+
});
|
|
587
|
+
const federationMetadata = getModuleFederationPublicationMetadata();
|
|
588
|
+
assertTapFederationPublicationMetadata({
|
|
589
|
+
target: options.target,
|
|
590
|
+
mfConfigs: federationMetadata.mfConfigs,
|
|
591
|
+
federation: federationMetadata.federation
|
|
592
|
+
});
|
|
593
|
+
await zephyrEngine.upload_assets({
|
|
594
|
+
assetsMap,
|
|
595
|
+
buildStats: attachViteFederationBuildStats(await zeBuildDashData(zephyrEngine), federationMetadata),
|
|
596
|
+
mfConfig: federationMetadata.mfConfig,
|
|
597
|
+
mfConfigs: federationMetadata.mfConfigs,
|
|
598
|
+
hooks,
|
|
599
|
+
snapshotType: uploadMetadata.snapshotType,
|
|
600
|
+
entrypoint: uploadMetadata.entrypoint
|
|
601
|
+
});
|
|
602
|
+
},
|
|
603
|
+
finish: ()=>zephyrEngine.build_finished(),
|
|
604
|
+
onFailure: ()=>zephyrEngine.build_failed()
|
|
605
|
+
});
|
|
606
|
+
const outputParticipant = uniqueParticipant('vite-output', environments.map(([name])=>name));
|
|
607
|
+
const session = applicationContext.beginBuild({
|
|
608
|
+
invocationId: `${buildInvocationId}:${generation}`,
|
|
609
|
+
generation,
|
|
610
|
+
strictAssetPaths: preservesLockedArtifactPaths,
|
|
611
|
+
participants: [
|
|
612
|
+
...environments.map(([name, environment])=>({
|
|
613
|
+
name,
|
|
614
|
+
role: environment.config?.consumer ?? environmentMetadata.get(name)?.consumer ?? name
|
|
615
|
+
})),
|
|
616
|
+
{
|
|
617
|
+
name: outputParticipant,
|
|
618
|
+
role: snapshotType
|
|
619
|
+
}
|
|
620
|
+
]
|
|
621
|
+
});
|
|
622
|
+
for (const [name] of environments)session.completeParticipant(name);
|
|
623
|
+
for (const [key, assetsMap] of Object.entries(claimedPartials))session.contribute({
|
|
624
|
+
participant: outputParticipant,
|
|
625
|
+
key,
|
|
626
|
+
assetsMap
|
|
627
|
+
});
|
|
628
|
+
session.completeParticipant(outputParticipant);
|
|
629
|
+
await session.publish();
|
|
630
|
+
await commitPartialAssetMapClaimBatch(zephyrEngine.application_uid, partialClaims.map(({ claimId })=>claimId));
|
|
631
|
+
} catch (error) {
|
|
632
|
+
try {
|
|
633
|
+
const zephyrEngine = await zephyr_engine_defer;
|
|
634
|
+
zephyrEngine.build_failed();
|
|
635
|
+
} catch {}
|
|
636
|
+
if (partialClaims.length > 0) try {
|
|
637
|
+
const zephyrEngine = await zephyr_engine_defer;
|
|
638
|
+
await rollbackPartialAssetMapClaimBatch(zephyrEngine.application_uid, partialClaims.map(({ claimId })=>claimId));
|
|
639
|
+
} catch (restoreError) {
|
|
640
|
+
handleGlobalError(restoreError);
|
|
641
|
+
}
|
|
642
|
+
handleGlobalError(error);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
function withZephyr(options = {}) {
|
|
649
|
+
if (void 0 !== options.target) assertZephyrBuildTarget(options.target, 'withZephyr({ target })');
|
|
650
|
+
const plugins = [];
|
|
651
|
+
const mfConfigs = toModuleFederationConfigArray(options.mfConfig);
|
|
652
|
+
if (mfConfigs.length > 0) {
|
|
653
|
+
const federation = loadModuleFederationPlugin();
|
|
654
|
+
const preservesLockedArtifactPaths = 'tap-app' === options.target;
|
|
655
|
+
for (const mfConfig of mfConfigs)plugins.push(...federation(preservesLockedArtifactPaths ? mfConfig : ensureRuntimePlugin(mfConfig)));
|
|
656
|
+
}
|
|
657
|
+
plugins.push(withZephyrCore(options));
|
|
658
|
+
return plugins;
|
|
659
|
+
}
|
|
660
|
+
export { withZephyr };
|
|
661
|
+
|
|
662
|
+
//# sourceMappingURL=vite-plugin-zephyr.mjs.map
|