vite-plugin-zephyr 1.3.0 → 1.4.1
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 +46 -5
- package/dist/index.mjs +0 -1
- package/dist/lib/internal/extract/extract-entrypoint.mjs +0 -1
- package/dist/lib/internal/extract/extract_mf_plugin.mjs +0 -1
- package/dist/lib/internal/extract/extract_vite_assets_map.mjs +0 -1
- package/dist/lib/internal/extract/load_public_dir.mjs +0 -1
- package/dist/lib/internal/extract/load_static_assets.mjs +0 -1
- package/dist/lib/internal/extract/load_static_entries.mjs +0 -1
- package/dist/lib/internal/extract/merge_vite_output_assets.mjs +0 -1
- package/dist/lib/internal/mf-vite-etl/ensure_runtime_plugin.mjs +0 -1
- package/dist/lib/internal/mf-vite-etl/extract-mf-vite-remotes.mjs +0 -1
- package/dist/lib/internal/mf-vite-etl/federation-metadata.mjs +0 -1
- package/dist/lib/internal/mf-vite-etl/runtime_plugin.mjs +33 -10
- package/dist/lib/internal/partial-build-scope.mjs +0 -1
- package/dist/lib/internal/types/zephyr-internal-options.mjs +1 -1
- package/dist/lib/internal/types/zephyr-output.mjs +1 -1
- package/dist/lib/internal/utils/normalize-entrypoint.mjs +0 -1
- package/dist/lib/internal/utils/normalize-vite-path.mjs +0 -1
- package/dist/lib/vite-plugin-zephyr-partial.mjs +0 -1
- package/dist/lib/vite-plugin-zephyr.js +696 -560
- package/dist/lib/vite-plugin-zephyr.mjs +245 -100
- package/package.json +2 -2
- package/dist/rslib-runtime~0.mjs +0 -21
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "node:module";
|
|
2
1
|
import { readFile } from "node:fs/promises";
|
|
3
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
4
|
import magic_string from "magic-string";
|
|
5
|
-
import { ApplicationContext, ZeErrors, ZephyrEngine, ZephyrError, assertZephyrBuildTarget, claimPartialAssetMapBatch, commitPartialAssetMapClaimBatch, createManifestContent, handleGlobalError, normalizeBasePath, rewriteEnvReadsToVirtualModule, rollbackPartialAssetMapClaimBatch, savePartialAssetMap, zeBuildAssets, zeBuildDashData, ze_log } from "zephyr-agent";
|
|
5
|
+
import { ApplicationContext, ZeErrors, ZephyrEngine, ZephyrError, assertZephyrBuildTarget, claimPartialAssetMapBatch, commitPartialAssetMapClaimBatch, createManifestContent, handleGlobalError, logFn, normalizeBasePath, rewriteEnvReadsToVirtualModule, rollbackPartialAssetMapClaimBatch, savePartialAssetMap, zeBuildAssets, zeBuildDashData, ze_log } from "zephyr-agent";
|
|
6
6
|
import { extractEntrypoint } from "./internal/extract/extract-entrypoint.mjs";
|
|
7
7
|
import { extract_mf_plugins } from "./internal/extract/extract_mf_plugin.mjs";
|
|
8
8
|
import { extract_vite_assets_map } from "./internal/extract/extract_vite_assets_map.mjs";
|
|
@@ -10,17 +10,12 @@ import { RESOLVED_ZEPHYR_MF_RUNTIME_PLUGIN_ID, ZEPHYR_MF_RUNTIME_PLUGIN_ID, ensu
|
|
|
10
10
|
import { extract_remotes_dependencies } from "./internal/mf-vite-etl/extract-mf-vite-remotes.mjs";
|
|
11
11
|
import { createViteModuleFederationPublicationMetadata, getConfigIdentities } from "./internal/mf-vite-etl/federation-metadata.mjs";
|
|
12
12
|
import { resolveVitePartialBuildScope } from "./internal/partial-build-scope.mjs";
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
|
|
13
|
+
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
14
|
+
var __rspack_import_meta_filename__ = __rspack_fileURLToPath(import.meta.url);
|
|
16
15
|
import * as __rspack_external_node_path_806ed179 from "node:path";
|
|
17
|
-
__webpack_require__.add({
|
|
18
|
-
"@module-federation/vite" (module) {
|
|
19
|
-
module.exports = __rspack_createRequire_require("@module-federation/vite");
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
16
|
const DEFAULT_LIBRARY_TYPE = 'module';
|
|
23
17
|
const VITE_ENVIRONMENT_OUTPUT_PREFIX = 'vite-environment:';
|
|
18
|
+
const runtimeRequire = createRequire(__rspack_import_meta_filename__);
|
|
24
19
|
function mergeClaimedPartialMaps(claims) {
|
|
25
20
|
const merged = {};
|
|
26
21
|
for (const claim of claims)for (const [partialKey, assetsMap] of Object.entries(claim.partialAssetMaps)){
|
|
@@ -111,6 +106,18 @@ function inferServerEntrypoint(partials, override, serverEnvironmentNames) {
|
|
|
111
106
|
];
|
|
112
107
|
return preferred.find((candidate)=>paths.includes(candidate)) ?? paths.find((candidate)=>/(^|\/)(server|index)\.(mjs|cjs|js)$/.test(candidate));
|
|
113
108
|
}
|
|
109
|
+
function hasLateOutputHook(value) {
|
|
110
|
+
if (Array.isArray(value)) return value.some(hasLateOutputHook);
|
|
111
|
+
if (!value || 'object' != typeof value) return false;
|
|
112
|
+
if ('then' in value) return true;
|
|
113
|
+
return [
|
|
114
|
+
'outputOptions',
|
|
115
|
+
'writeBundle'
|
|
116
|
+
].some((name)=>{
|
|
117
|
+
const hook = value[name];
|
|
118
|
+
return Boolean(hook && 'object' == typeof hook && 'order' in hook && 'post' === hook.order);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
114
121
|
function commonDirectory(paths) {
|
|
115
122
|
if (0 === paths.length) return;
|
|
116
123
|
const resolvedPaths = paths.map((item)=>__rspack_external_node_path_806ed179.resolve(item));
|
|
@@ -172,7 +179,7 @@ function attachViteFederationBuildStats(buildStats, federationMetadata) {
|
|
|
172
179
|
function loadModuleFederationPlugin() {
|
|
173
180
|
let moduleFederation;
|
|
174
181
|
try {
|
|
175
|
-
moduleFederation =
|
|
182
|
+
moduleFederation = runtimeRequire('@module-federation/vite');
|
|
176
183
|
} catch (error) {
|
|
177
184
|
throw new ZephyrError(ZeErrors.ERR_UNKNOWN, {
|
|
178
185
|
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}` : ''}`
|
|
@@ -207,7 +214,29 @@ function withZephyrCore(options = {}) {
|
|
|
207
214
|
let applicationContext;
|
|
208
215
|
let uploadMetadata;
|
|
209
216
|
let baseHref = '';
|
|
210
|
-
let
|
|
217
|
+
let isApplicationBuild = false;
|
|
218
|
+
let unsupportedVite6Builder = false;
|
|
219
|
+
let directOutputs = [];
|
|
220
|
+
let directBuildFailed = false;
|
|
221
|
+
let directSsr = false;
|
|
222
|
+
let expectedDirectOutputs = 1;
|
|
223
|
+
let buildManifest;
|
|
224
|
+
let hasLaterWriteHook = false;
|
|
225
|
+
let hasLaterCloseHook = false;
|
|
226
|
+
let hasLaterOutputOptionsHook = false;
|
|
227
|
+
const instantiatedEnvironments = new Set();
|
|
228
|
+
let environmentBuildStarted = false;
|
|
229
|
+
const buildAppStart = {
|
|
230
|
+
name: 'with-zephyr:build-app-start',
|
|
231
|
+
enforce: 'pre',
|
|
232
|
+
sharedDuringBuild: true,
|
|
233
|
+
buildApp: {
|
|
234
|
+
order: 'pre',
|
|
235
|
+
async handler () {
|
|
236
|
+
isApplicationBuild = true;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
211
240
|
const registerModuleFederationConfigs = (configs)=>{
|
|
212
241
|
for (const config of configs){
|
|
213
242
|
const identities = getConfigIdentities(config);
|
|
@@ -220,8 +249,67 @@ function withZephyrCore(options = {}) {
|
|
|
220
249
|
}
|
|
221
250
|
};
|
|
222
251
|
const getModuleFederationPublicationMetadata = ()=>createViteModuleFederationPublicationMetadata(mfConfigSources);
|
|
223
|
-
|
|
252
|
+
const publishDirectOutputs = async (outputs)=>{
|
|
253
|
+
const partialClaims = [];
|
|
254
|
+
const zephyrEngine = await zephyr_engine_defer;
|
|
255
|
+
try {
|
|
256
|
+
const outputRoot = commonDirectory(outputs.map((output)=>output.directory));
|
|
257
|
+
if (!outputRoot) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
258
|
+
message: 'Could not determine a shared output root for the Vite build.'
|
|
259
|
+
});
|
|
260
|
+
const serverEntries = new Set();
|
|
261
|
+
const maps = outputs.map((output)=>{
|
|
262
|
+
const prefix = preservesLockedArtifactPaths ? void 0 : __rspack_external_node_path_806ed179.relative(outputRoot, output.directory).split(__rspack_external_node_path_806ed179.sep).join('/');
|
|
263
|
+
for (const entry of output.entrypoints)serverEntries.add(prefix ? `${prefix}/${entry}` : entry);
|
|
264
|
+
return prefixAssetsMap(output.assetsMap, prefix);
|
|
265
|
+
});
|
|
266
|
+
let assetsMap = 1 === maps.length ? maps[0] : mergeAssetMaps(maps);
|
|
267
|
+
if (!isWatchMode && externalPartialScope) {
|
|
268
|
+
const batch = await claimPartialAssetMapBatch(zephyrEngine.application_uid, [
|
|
269
|
+
externalPartialScope
|
|
270
|
+
]);
|
|
271
|
+
if (!batch) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
272
|
+
message: 'Vite partialBuild was configured, but its external partial output was unavailable or already claimed.'
|
|
273
|
+
});
|
|
274
|
+
partialClaims.push(...batch.claims);
|
|
275
|
+
assetsMap = mergeAssetMaps([
|
|
276
|
+
...Object.values(mergeClaimedPartialMaps(partialClaims)),
|
|
277
|
+
assetsMap
|
|
278
|
+
]);
|
|
279
|
+
}
|
|
280
|
+
const snapshotType = options.snapshotType ?? (!preservesLockedArtifactPaths && outputs.some((output)=>output.ssr) ? 'ssr' : 'csr');
|
|
281
|
+
const finalEntrypoint = 'ssr' === snapshotType ? options.entrypoint ? normalizeEntrypoint(options.entrypoint) : 1 === serverEntries.size ? [
|
|
282
|
+
...serverEntries
|
|
283
|
+
][0] : void 0 : preservesLockedArtifactPaths ? void 0 : entrypoint;
|
|
284
|
+
if ('ssr' === snapshotType && (!finalEntrypoint || !Object.values(assetsMap).some((asset)=>asset.path === finalEntrypoint))) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
285
|
+
message: 'Could not identify an emitted Vite server entrypoint. Set withZephyr({ entrypoint }) to an emitted server chunk.'
|
|
286
|
+
});
|
|
287
|
+
if (!zephyrEngine.hasActiveBuild) await zephyrEngine.start_new_build();
|
|
288
|
+
const federationMetadata = getModuleFederationPublicationMetadata();
|
|
289
|
+
await zephyrEngine.upload_assets({
|
|
290
|
+
assetsMap,
|
|
291
|
+
buildStats: attachViteFederationBuildStats(await zeBuildDashData(zephyrEngine), federationMetadata),
|
|
292
|
+
mfConfig: federationMetadata.mfConfig,
|
|
293
|
+
mfConfigs: federationMetadata.mfConfigs,
|
|
294
|
+
hooks,
|
|
295
|
+
entrypoint: finalEntrypoint,
|
|
296
|
+
snapshotType
|
|
297
|
+
});
|
|
298
|
+
await zephyrEngine.build_finished();
|
|
299
|
+
await commitPartialAssetMapClaimBatch(zephyrEngine.application_uid, partialClaims.map(({ claimId })=>claimId));
|
|
300
|
+
} catch (error) {
|
|
301
|
+
zephyrEngine.build_failed();
|
|
302
|
+
if (partialClaims.length > 0) try {
|
|
303
|
+
await rollbackPartialAssetMapClaimBatch(zephyrEngine.application_uid, partialClaims.map(({ claimId })=>claimId));
|
|
304
|
+
} catch (rollbackError) {
|
|
305
|
+
logFn('error', ZephyrError.format(rollbackError));
|
|
306
|
+
}
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
const plugin = {
|
|
224
311
|
name: 'with-zephyr',
|
|
312
|
+
sharedDuringBuild: true,
|
|
225
313
|
enforce: 'pre',
|
|
226
314
|
config: (config)=>{
|
|
227
315
|
registerModuleFederationConfigs(extract_mf_plugins(config.plugins ?? []).map((plugin)=>plugin._options));
|
|
@@ -229,13 +317,41 @@ function withZephyrCore(options = {}) {
|
|
|
229
317
|
},
|
|
230
318
|
configResolved: async (config)=>{
|
|
231
319
|
const vite = await import("vite");
|
|
232
|
-
|
|
320
|
+
const viteMajor = Number.parseInt(vite.version.split('.')[0] ?? '0', 10);
|
|
321
|
+
if (environmentBuildStarted) {
|
|
322
|
+
instantiatedEnvironments.clear();
|
|
323
|
+
environmentBuildStarted = false;
|
|
324
|
+
}
|
|
325
|
+
const createEnvironment = config.build?.createEnvironment;
|
|
326
|
+
if (createEnvironment) config.build.createEnvironment = function(name, environmentConfig) {
|
|
327
|
+
const environment = createEnvironment.call(this, name, environmentConfig);
|
|
328
|
+
instantiatedEnvironments.add(name);
|
|
329
|
+
return environment;
|
|
330
|
+
};
|
|
331
|
+
isApplicationBuild = false;
|
|
332
|
+
directOutputs = [];
|
|
333
|
+
directBuildFailed = false;
|
|
334
|
+
buildManifest = void 0;
|
|
335
|
+
directSsr = Boolean(config.build?.ssr);
|
|
336
|
+
const configuredOutput = config.build?.rolldownOptions?.output ?? config.build?.rollupOptions?.output;
|
|
337
|
+
expectedDirectOutputs = Array.isArray(configuredOutput) ? configuredOutput.length : config.build?.lib ? config.build.lib.formats?.length ?? 2 : 1;
|
|
338
|
+
const firstBuildAppPlugin = config.getSortedPlugins?.('buildApp')[0];
|
|
339
|
+
if (viteMajor >= 7 && firstBuildAppPlugin && firstBuildAppPlugin !== buildAppStart) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
340
|
+
message: 'Place withZephyr() before other pre-ordered buildApp plugins so Zephyr can collect application output atomically.'
|
|
341
|
+
});
|
|
342
|
+
const writePlugins = config.getSortedPlugins?.('writeBundle');
|
|
343
|
+
hasLaterWriteHook = Boolean(writePlugins?.length && writePlugins.at(-1) !== plugin);
|
|
344
|
+
const closePlugins = config.getSortedPlugins?.('closeBundle');
|
|
345
|
+
hasLaterCloseHook = Boolean(closePlugins?.length && closePlugins.at(-1) !== plugin);
|
|
346
|
+
const outputOptionPlugins = config.getSortedPlugins?.('outputOptions');
|
|
347
|
+
hasLaterOutputOptionsHook = Boolean(outputOptionPlugins?.length && outputOptionPlugins.at(-1) !== plugin);
|
|
233
348
|
const root = config.root;
|
|
234
349
|
baseHref = normalizeBasePath(config.base);
|
|
235
350
|
entrypoint = normalizeEntrypoint(options.entrypoint ?? extractEntrypoint(config));
|
|
236
351
|
isWatchMode = Boolean(config.build?.watch);
|
|
237
352
|
const configuredEnvironments = config.environments ?? {};
|
|
238
353
|
environmentNames = Object.keys(configuredEnvironments);
|
|
354
|
+
unsupportedVite6Builder = 6 === viteMajor && (Boolean(config.builder) || environmentNames.length > 1);
|
|
239
355
|
environmentMetadata = new Map(Object.entries(configuredEnvironments).map(([name, environment])=>[
|
|
240
356
|
name,
|
|
241
357
|
{
|
|
@@ -346,7 +462,7 @@ function withZephyrCore(options = {}) {
|
|
|
346
462
|
try {
|
|
347
463
|
const zephyr_engine = await zephyr_engine_defer;
|
|
348
464
|
const dependencies = zephyr_engine.federated_dependencies || [];
|
|
349
|
-
const manifestContent = createManifestContent(dependencies, true);
|
|
465
|
+
const manifestContent = isApplicationBuild || isWatchMode ? createManifestContent(dependencies, true) : buildManifest ??= createManifestContent(dependencies, true);
|
|
350
466
|
this.emitFile({
|
|
351
467
|
type: 'asset',
|
|
352
468
|
fileName: 'zephyr-manifest.json',
|
|
@@ -389,102 +505,127 @@ function withZephyrCore(options = {}) {
|
|
|
389
505
|
});
|
|
390
506
|
} catch {}
|
|
391
507
|
},
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
zephyr_engine_defer
|
|
398
|
-
]);
|
|
399
|
-
zephyr_engine.buildProperties.baseHref = baseHref;
|
|
400
|
-
const environmentName = this.environment?.name;
|
|
401
|
-
const isMultiEnvironment = environmentNames.length > 1;
|
|
402
|
-
if (isWatchMode && isMultiEnvironment) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
403
|
-
message: "Vite multi-environment watch publication is not supported because environment rebuilds do not expose an atomic application generation."
|
|
404
|
-
});
|
|
405
|
-
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));
|
|
406
|
-
const resolvedEnvironmentName = environmentName ?? [
|
|
407
|
-
...environmentMetadata.entries()
|
|
408
|
-
].find(([, metadata])=>metadata.outputDir === outputDirectory)?.[0] ?? (1 === environmentNames.length ? environmentNames[0] : void 0);
|
|
409
|
-
const coordinateWithBuildApp = supportsBuildApp && !isWatchMode;
|
|
410
|
-
if (coordinateWithBuildApp && !resolvedEnvironmentName) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
411
|
-
message: `Could not associate Vite output directory "${outputDirectory}" with an environment.`
|
|
508
|
+
outputOptions: {
|
|
509
|
+
order: 'post',
|
|
510
|
+
handler (output) {
|
|
511
|
+
if (!isApplicationBuild && !isWatchMode && (hasLaterOutputOptionsHook || hasLateOutputHook(output.plugins))) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
512
|
+
message: 'Zephyr cannot verify post-ordered or asynchronous output-plugin writers. Use normal outputOptions and writeBundle ordering in synchronous output plugins.'
|
|
412
513
|
});
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
buildStart () {
|
|
518
|
+
environmentBuildStarted = true;
|
|
519
|
+
},
|
|
520
|
+
buildEnd (error) {
|
|
521
|
+
if (error) directBuildFailed = true;
|
|
522
|
+
},
|
|
523
|
+
renderError () {
|
|
524
|
+
directBuildFailed = true;
|
|
525
|
+
},
|
|
526
|
+
closeBundle: {
|
|
527
|
+
order: 'post',
|
|
528
|
+
sequential: true,
|
|
529
|
+
async handler () {
|
|
530
|
+
if (isApplicationBuild || isWatchMode || 0 === directOutputs.length) return;
|
|
531
|
+
const outputs = directOutputs;
|
|
532
|
+
directOutputs = [];
|
|
533
|
+
if (directBuildFailed || outputs.length !== expectedDirectOutputs) return;
|
|
534
|
+
try {
|
|
535
|
+
await publishDirectOutputs(outputs);
|
|
536
|
+
} catch (error) {
|
|
537
|
+
handleGlobalError(error);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
},
|
|
541
|
+
writeBundle: {
|
|
542
|
+
order: 'post',
|
|
543
|
+
sequential: true,
|
|
544
|
+
async handler (outputOptions, bundle) {
|
|
545
|
+
try {
|
|
546
|
+
const [vite_internal_options, zephyr_engine] = await Promise.all([
|
|
547
|
+
vite_internal_options_defer,
|
|
548
|
+
zephyr_engine_defer
|
|
549
|
+
]);
|
|
550
|
+
zephyr_engine.buildProperties.baseHref = baseHref;
|
|
551
|
+
const environmentName = this.environment?.name;
|
|
552
|
+
const isMultiEnvironment = environmentNames.length > 1;
|
|
553
|
+
if (!isWatchMode && unsupportedVite6Builder) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
554
|
+
message: 'Vite 6 application-builder publication requires Vite 7 or newer. Vite 6 supports only single-environment builds without a builder configuration.'
|
|
417
555
|
});
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
message: `Vite environment output "${outputDirectory}" is outside shared output root "${sharedOutputRoot}".`
|
|
556
|
+
if (isWatchMode && isMultiEnvironment) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
557
|
+
message: "Vite multi-environment watch publication is not supported because environment rebuilds do not expose an atomic application generation."
|
|
421
558
|
});
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
publicDir: isMultiEnvironment && resolvedEnvironmentName && environmentMetadata.get(resolvedEnvironmentName)?.consumer === 'server' ? void 0 : vite_internal_options.publicDir
|
|
430
|
-
};
|
|
431
|
-
let assetsMap = await extract_vite_assets_map(zephyr_engine, extractionOptions);
|
|
432
|
-
if (coordinateWithBuildApp) {
|
|
433
|
-
if (!resolvedEnvironmentName) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
434
|
-
message: `Could not associate Vite output directory "${outputDirectory}" with an environment.`
|
|
559
|
+
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));
|
|
560
|
+
const resolvedEnvironmentName = environmentName ?? [
|
|
561
|
+
...environmentMetadata.entries()
|
|
562
|
+
].find(([, metadata])=>metadata.outputDir === outputDirectory)?.[0] ?? (1 === environmentNames.length ? environmentNames[0] : void 0);
|
|
563
|
+
const coordinateWithBuildApp = isApplicationBuild && !isWatchMode;
|
|
564
|
+
if (!coordinateWithBuildApp && instantiatedEnvironments.size > 1) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
565
|
+
message: 'Use builder.buildApp() to publish multiple Vite environments atomically; individual builder.build(environment) calls cannot finalize the application.'
|
|
435
566
|
});
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
invocationId: buildInvocationId,
|
|
439
|
-
generation: buildGeneration
|
|
567
|
+
if (!coordinateWithBuildApp && !isWatchMode && (hasLaterWriteHook || hasLaterCloseHook)) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
568
|
+
message: 'Zephyr must be the last writeBundle and closeBundle hook. Use normal hook ordering for other plugins so publication cannot precede a failed build.'
|
|
440
569
|
});
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if (!isWatchMode && externalPartialScope) {
|
|
444
|
-
const batch = await claimPartialAssetMapBatch(zephyr_engine.application_uid, [
|
|
445
|
-
externalPartialScope
|
|
446
|
-
]);
|
|
447
|
-
if (!batch) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
448
|
-
message: 'Vite partialBuild was configured, but its external partial output was unavailable or already claimed.'
|
|
570
|
+
if (coordinateWithBuildApp && !resolvedEnvironmentName) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
571
|
+
message: `Could not associate Vite output directory "${outputDirectory}" with an environment.`
|
|
449
572
|
});
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
573
|
+
let assetPrefix;
|
|
574
|
+
if (coordinateWithBuildApp && isMultiEnvironment && !preservesLockedArtifactPaths) {
|
|
575
|
+
if (!sharedOutputRoot) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
576
|
+
message: 'Could not determine a shared output root for Vite environments.'
|
|
577
|
+
});
|
|
578
|
+
const relativeOutput = __rspack_external_node_path_806ed179.relative(sharedOutputRoot, outputDirectory);
|
|
579
|
+
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, {
|
|
580
|
+
message: `Vite environment output "${outputDirectory}" is outside shared output root "${sharedOutputRoot}".`
|
|
581
|
+
});
|
|
582
|
+
assetPrefix = relativeOutput ? relativeOutput.split(__rspack_external_node_path_806ed179.sep).join('/') : void 0;
|
|
583
|
+
}
|
|
584
|
+
const extractionOptions = {
|
|
585
|
+
...vite_internal_options,
|
|
586
|
+
dir: outputOptions.dir,
|
|
587
|
+
outDir: outputDirectory,
|
|
588
|
+
assets: bundle,
|
|
589
|
+
publicDir: isMultiEnvironment && resolvedEnvironmentName && environmentMetadata.get(resolvedEnvironmentName)?.consumer === 'server' ? void 0 : vite_internal_options.publicDir
|
|
590
|
+
};
|
|
591
|
+
const assetsMap = await extract_vite_assets_map(zephyr_engine, extractionOptions);
|
|
592
|
+
if (coordinateWithBuildApp) {
|
|
593
|
+
if (!resolvedEnvironmentName) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
594
|
+
message: `Could not associate Vite output directory "${outputDirectory}" with an environment.`
|
|
595
|
+
});
|
|
596
|
+
const persistedAssetsMap = preservesLockedArtifactPaths ? assetsMap : prefixAssetsMap(assetsMap, assetPrefix);
|
|
597
|
+
await savePartialAssetMap(zephyr_engine.application_uid, viteEnvironmentOutputKey(resolvedEnvironmentName, outputDirectory, outputOptions.file, outputOptions.format, persistedAssetsMap), persistedAssetsMap, {
|
|
598
|
+
invocationId: buildInvocationId,
|
|
599
|
+
generation: buildGeneration
|
|
600
|
+
});
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
const output = {
|
|
604
|
+
assetsMap,
|
|
605
|
+
directory: outputDirectory,
|
|
606
|
+
entrypoints: Object.values(bundle).flatMap((asset)=>'chunk' === asset.type && asset.isEntry ? [
|
|
607
|
+
asset.fileName
|
|
608
|
+
] : []),
|
|
609
|
+
ssr: directSsr || void 0 !== resolvedEnvironmentName && environmentMetadata.get(resolvedEnvironmentName)?.consumer === 'server'
|
|
610
|
+
};
|
|
611
|
+
if (isWatchMode) await publishDirectOutputs([
|
|
612
|
+
output
|
|
455
613
|
]);
|
|
614
|
+
else directOutputs.push(output);
|
|
615
|
+
} catch (error) {
|
|
616
|
+
directBuildFailed = true;
|
|
617
|
+
try {
|
|
618
|
+
const zephyr_engine = await zephyr_engine_defer;
|
|
619
|
+
zephyr_engine.build_failed();
|
|
620
|
+
} catch {}
|
|
621
|
+
handleGlobalError(error);
|
|
456
622
|
}
|
|
457
|
-
if (!zephyr_engine.hasActiveBuild) await zephyr_engine.start_new_build();
|
|
458
|
-
const federationMetadata = getModuleFederationPublicationMetadata();
|
|
459
|
-
await zephyr_engine.upload_assets({
|
|
460
|
-
assetsMap,
|
|
461
|
-
buildStats: attachViteFederationBuildStats(await zeBuildDashData(zephyr_engine), federationMetadata),
|
|
462
|
-
mfConfig: federationMetadata.mfConfig,
|
|
463
|
-
mfConfigs: federationMetadata.mfConfigs,
|
|
464
|
-
hooks,
|
|
465
|
-
entrypoint,
|
|
466
|
-
snapshotType: options.snapshotType ?? 'csr'
|
|
467
|
-
});
|
|
468
|
-
await zephyr_engine.build_finished();
|
|
469
|
-
await commitPartialAssetMapClaimBatch(zephyr_engine.application_uid, partialClaims.map(({ claimId })=>claimId));
|
|
470
|
-
} catch (error) {
|
|
471
|
-
try {
|
|
472
|
-
const zephyr_engine = await zephyr_engine_defer;
|
|
473
|
-
zephyr_engine.build_failed();
|
|
474
|
-
} catch {}
|
|
475
|
-
if (partialClaims.length > 0) try {
|
|
476
|
-
const zephyr_engine = await zephyr_engine_defer;
|
|
477
|
-
await rollbackPartialAssetMapClaimBatch(zephyr_engine.application_uid, partialClaims.map(({ claimId })=>claimId));
|
|
478
|
-
} catch (restoreError) {
|
|
479
|
-
handleGlobalError(restoreError);
|
|
480
|
-
}
|
|
481
|
-
handleGlobalError(error);
|
|
482
623
|
}
|
|
483
624
|
},
|
|
484
625
|
buildApp: {
|
|
485
626
|
order: 'post',
|
|
486
627
|
async handler (builder) {
|
|
487
|
-
|
|
628
|
+
isApplicationBuild = true;
|
|
488
629
|
const environments = Object.entries(builder.environments);
|
|
489
630
|
if (isWatchMode) {
|
|
490
631
|
if (environments.length > 1) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
@@ -616,13 +757,17 @@ function withZephyrCore(options = {}) {
|
|
|
616
757
|
const zephyrEngine = await zephyr_engine_defer;
|
|
617
758
|
await rollbackPartialAssetMapClaimBatch(zephyrEngine.application_uid, partialClaims.map(({ claimId })=>claimId));
|
|
618
759
|
} catch (restoreError) {
|
|
619
|
-
|
|
760
|
+
logFn('error', ZephyrError.format(restoreError));
|
|
620
761
|
}
|
|
621
762
|
handleGlobalError(error);
|
|
622
763
|
}
|
|
623
764
|
}
|
|
624
765
|
}
|
|
625
766
|
};
|
|
767
|
+
return [
|
|
768
|
+
plugin,
|
|
769
|
+
buildAppStart
|
|
770
|
+
];
|
|
626
771
|
}
|
|
627
772
|
function withZephyr(options = {}) {
|
|
628
773
|
if (void 0 !== options.target) assertZephyrBuildTarget(options.target, 'withZephyr({ target })');
|
|
@@ -633,7 +778,7 @@ function withZephyr(options = {}) {
|
|
|
633
778
|
const preservesLockedArtifactPaths = 'tap-app' === options.target;
|
|
634
779
|
for (const mfConfig of mfConfigs)plugins.push(...federation(preservesLockedArtifactPaths ? mfConfig : ensureRuntimePlugin(mfConfig)));
|
|
635
780
|
}
|
|
636
|
-
plugins.push(withZephyrCore(options));
|
|
781
|
+
plugins.push(...withZephyrCore(options));
|
|
637
782
|
return plugins;
|
|
638
783
|
}
|
|
639
784
|
export { withZephyr };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/vitejs/vite-plugin-registry/refs/heads/main/data/schema/extended-package-json.schema.json",
|
|
3
3
|
"name": "vite-plugin-zephyr",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.1",
|
|
5
5
|
"description": "Vite plugin for Zephyr",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"deploy",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"acorn": "^8.18.0",
|
|
52
52
|
"acorn-walk": "^8.3.5",
|
|
53
53
|
"magic-string": "1.2.3",
|
|
54
|
-
"zephyr-agent": "1.
|
|
54
|
+
"zephyr-agent": "1.4.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@module-federation/vite": "1.21.2",
|
package/dist/rslib-runtime~0.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
var __webpack_modules__ = {};
|
|
3
|
-
var __webpack_module_cache__ = {};
|
|
4
|
-
function __webpack_require__(moduleId) {
|
|
5
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
6
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
7
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
8
|
-
exports: {}
|
|
9
|
-
};
|
|
10
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
11
|
-
return module.exports;
|
|
12
|
-
}
|
|
13
|
-
__webpack_require__.m = __webpack_modules__;
|
|
14
|
-
(()=>{
|
|
15
|
-
__webpack_require__.add = function(modules) {
|
|
16
|
-
Object.assign(__webpack_require__.m, modules);
|
|
17
|
-
};
|
|
18
|
-
})();
|
|
19
|
-
export { __webpack_require__ };
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=rslib-runtime~0.mjs.map
|