vite-plugin-zephyr 1.2.4 → 1.4.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 +46 -5
- package/dist/index.d.ts +5 -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.d.mts +1 -2
- package/dist/lib/internal/extract/extract_mf_plugin.d.ts +2 -3
- package/dist/lib/internal/extract/extract_mf_plugin.mjs +0 -1
- package/dist/lib/internal/extract/extract_vite_assets_map.d.ts +1 -1
- package/dist/lib/internal/extract/extract_vite_assets_map.mjs +0 -1
- package/dist/lib/internal/extract/load_public_dir.d.ts +1 -1
- package/dist/lib/internal/extract/load_public_dir.mjs +0 -1
- package/dist/lib/internal/extract/load_static_assets.d.ts +2 -2
- package/dist/lib/internal/extract/load_static_assets.mjs +0 -1
- package/dist/lib/internal/extract/load_static_entries.d.ts +1 -1
- package/dist/lib/internal/extract/load_static_entries.mjs +0 -1
- package/dist/lib/internal/extract/merge_vite_output_assets.d.ts +1 -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.d.ts +1 -1
- package/dist/lib/internal/mf-vite-etl/federation-metadata.mjs +0 -1
- package/dist/lib/internal/partial-build-scope.mjs +0 -1
- package/dist/lib/internal/types/zephyr-internal-options.d.ts +1 -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.d.mts +1 -2
- package/dist/lib/vite-plugin-zephyr-partial.d.ts +2 -3
- package/dist/lib/vite-plugin-zephyr-partial.mjs +0 -1
- package/dist/lib/vite-plugin-zephyr.d.mts +1 -2
- package/dist/lib/vite-plugin-zephyr.d.ts +3 -4
- package/dist/lib/vite-plugin-zephyr.js +696 -560
- package/dist/lib/vite-plugin-zephyr.mjs +245 -99
- package/package.json +11 -11
- package/dist/rslib-runtime.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,16 +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
|
-
|
|
13
|
+
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
14
|
+
var __rspack_import_meta_filename__ = __rspack_fileURLToPath(import.meta.url);
|
|
15
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
16
|
const DEFAULT_LIBRARY_TYPE = 'module';
|
|
22
17
|
const VITE_ENVIRONMENT_OUTPUT_PREFIX = 'vite-environment:';
|
|
18
|
+
const runtimeRequire = createRequire(__rspack_import_meta_filename__);
|
|
23
19
|
function mergeClaimedPartialMaps(claims) {
|
|
24
20
|
const merged = {};
|
|
25
21
|
for (const claim of claims)for (const [partialKey, assetsMap] of Object.entries(claim.partialAssetMaps)){
|
|
@@ -110,6 +106,18 @@ function inferServerEntrypoint(partials, override, serverEnvironmentNames) {
|
|
|
110
106
|
];
|
|
111
107
|
return preferred.find((candidate)=>paths.includes(candidate)) ?? paths.find((candidate)=>/(^|\/)(server|index)\.(mjs|cjs|js)$/.test(candidate));
|
|
112
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
|
+
}
|
|
113
121
|
function commonDirectory(paths) {
|
|
114
122
|
if (0 === paths.length) return;
|
|
115
123
|
const resolvedPaths = paths.map((item)=>__rspack_external_node_path_806ed179.resolve(item));
|
|
@@ -171,7 +179,7 @@ function attachViteFederationBuildStats(buildStats, federationMetadata) {
|
|
|
171
179
|
function loadModuleFederationPlugin() {
|
|
172
180
|
let moduleFederation;
|
|
173
181
|
try {
|
|
174
|
-
moduleFederation =
|
|
182
|
+
moduleFederation = runtimeRequire('@module-federation/vite');
|
|
175
183
|
} catch (error) {
|
|
176
184
|
throw new ZephyrError(ZeErrors.ERR_UNKNOWN, {
|
|
177
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}` : ''}`
|
|
@@ -206,7 +214,29 @@ function withZephyrCore(options = {}) {
|
|
|
206
214
|
let applicationContext;
|
|
207
215
|
let uploadMetadata;
|
|
208
216
|
let baseHref = '';
|
|
209
|
-
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
|
+
};
|
|
210
240
|
const registerModuleFederationConfigs = (configs)=>{
|
|
211
241
|
for (const config of configs){
|
|
212
242
|
const identities = getConfigIdentities(config);
|
|
@@ -219,8 +249,67 @@ function withZephyrCore(options = {}) {
|
|
|
219
249
|
}
|
|
220
250
|
};
|
|
221
251
|
const getModuleFederationPublicationMetadata = ()=>createViteModuleFederationPublicationMetadata(mfConfigSources);
|
|
222
|
-
|
|
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 = {
|
|
223
311
|
name: 'with-zephyr',
|
|
312
|
+
sharedDuringBuild: true,
|
|
224
313
|
enforce: 'pre',
|
|
225
314
|
config: (config)=>{
|
|
226
315
|
registerModuleFederationConfigs(extract_mf_plugins(config.plugins ?? []).map((plugin)=>plugin._options));
|
|
@@ -228,13 +317,41 @@ function withZephyrCore(options = {}) {
|
|
|
228
317
|
},
|
|
229
318
|
configResolved: async (config)=>{
|
|
230
319
|
const vite = await import("vite");
|
|
231
|
-
|
|
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);
|
|
232
348
|
const root = config.root;
|
|
233
349
|
baseHref = normalizeBasePath(config.base);
|
|
234
350
|
entrypoint = normalizeEntrypoint(options.entrypoint ?? extractEntrypoint(config));
|
|
235
351
|
isWatchMode = Boolean(config.build?.watch);
|
|
236
352
|
const configuredEnvironments = config.environments ?? {};
|
|
237
353
|
environmentNames = Object.keys(configuredEnvironments);
|
|
354
|
+
unsupportedVite6Builder = 6 === viteMajor && (Boolean(config.builder) || environmentNames.length > 1);
|
|
238
355
|
environmentMetadata = new Map(Object.entries(configuredEnvironments).map(([name, environment])=>[
|
|
239
356
|
name,
|
|
240
357
|
{
|
|
@@ -345,7 +462,7 @@ function withZephyrCore(options = {}) {
|
|
|
345
462
|
try {
|
|
346
463
|
const zephyr_engine = await zephyr_engine_defer;
|
|
347
464
|
const dependencies = zephyr_engine.federated_dependencies || [];
|
|
348
|
-
const manifestContent = createManifestContent(dependencies, true);
|
|
465
|
+
const manifestContent = isApplicationBuild || isWatchMode ? createManifestContent(dependencies, true) : buildManifest ??= createManifestContent(dependencies, true);
|
|
349
466
|
this.emitFile({
|
|
350
467
|
type: 'asset',
|
|
351
468
|
fileName: 'zephyr-manifest.json',
|
|
@@ -388,102 +505,127 @@ function withZephyrCore(options = {}) {
|
|
|
388
505
|
});
|
|
389
506
|
} catch {}
|
|
390
507
|
},
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
zephyr_engine_defer
|
|
397
|
-
]);
|
|
398
|
-
zephyr_engine.buildProperties.baseHref = baseHref;
|
|
399
|
-
const environmentName = this.environment?.name;
|
|
400
|
-
const isMultiEnvironment = environmentNames.length > 1;
|
|
401
|
-
if (isWatchMode && isMultiEnvironment) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
402
|
-
message: "Vite multi-environment watch publication is not supported because environment rebuilds do not expose an atomic application generation."
|
|
403
|
-
});
|
|
404
|
-
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));
|
|
405
|
-
const resolvedEnvironmentName = environmentName ?? [
|
|
406
|
-
...environmentMetadata.entries()
|
|
407
|
-
].find(([, metadata])=>metadata.outputDir === outputDirectory)?.[0] ?? (1 === environmentNames.length ? environmentNames[0] : void 0);
|
|
408
|
-
const coordinateWithBuildApp = supportsBuildApp && !isWatchMode;
|
|
409
|
-
if (coordinateWithBuildApp && !resolvedEnvironmentName) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
410
|
-
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.'
|
|
411
513
|
});
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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.'
|
|
416
555
|
});
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
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."
|
|
420
558
|
});
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
publicDir: isMultiEnvironment && resolvedEnvironmentName && environmentMetadata.get(resolvedEnvironmentName)?.consumer === 'server' ? void 0 : vite_internal_options.publicDir
|
|
429
|
-
};
|
|
430
|
-
let assetsMap = await extract_vite_assets_map(zephyr_engine, extractionOptions);
|
|
431
|
-
if (coordinateWithBuildApp) {
|
|
432
|
-
if (!resolvedEnvironmentName) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
433
|
-
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.'
|
|
434
566
|
});
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
invocationId: buildInvocationId,
|
|
438
|
-
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.'
|
|
439
569
|
});
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (!isWatchMode && externalPartialScope) {
|
|
443
|
-
const batch = await claimPartialAssetMapBatch(zephyr_engine.application_uid, [
|
|
444
|
-
externalPartialScope
|
|
445
|
-
]);
|
|
446
|
-
if (!batch) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
447
|
-
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.`
|
|
448
572
|
});
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
|
454
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);
|
|
455
622
|
}
|
|
456
|
-
if (!zephyr_engine.hasActiveBuild) await zephyr_engine.start_new_build();
|
|
457
|
-
const federationMetadata = getModuleFederationPublicationMetadata();
|
|
458
|
-
await zephyr_engine.upload_assets({
|
|
459
|
-
assetsMap,
|
|
460
|
-
buildStats: attachViteFederationBuildStats(await zeBuildDashData(zephyr_engine), federationMetadata),
|
|
461
|
-
mfConfig: federationMetadata.mfConfig,
|
|
462
|
-
mfConfigs: federationMetadata.mfConfigs,
|
|
463
|
-
hooks,
|
|
464
|
-
entrypoint,
|
|
465
|
-
snapshotType: options.snapshotType ?? 'csr'
|
|
466
|
-
});
|
|
467
|
-
await zephyr_engine.build_finished();
|
|
468
|
-
await commitPartialAssetMapClaimBatch(zephyr_engine.application_uid, partialClaims.map(({ claimId })=>claimId));
|
|
469
|
-
} catch (error) {
|
|
470
|
-
try {
|
|
471
|
-
const zephyr_engine = await zephyr_engine_defer;
|
|
472
|
-
zephyr_engine.build_failed();
|
|
473
|
-
} catch {}
|
|
474
|
-
if (partialClaims.length > 0) try {
|
|
475
|
-
const zephyr_engine = await zephyr_engine_defer;
|
|
476
|
-
await rollbackPartialAssetMapClaimBatch(zephyr_engine.application_uid, partialClaims.map(({ claimId })=>claimId));
|
|
477
|
-
} catch (restoreError) {
|
|
478
|
-
handleGlobalError(restoreError);
|
|
479
|
-
}
|
|
480
|
-
handleGlobalError(error);
|
|
481
623
|
}
|
|
482
624
|
},
|
|
483
625
|
buildApp: {
|
|
484
626
|
order: 'post',
|
|
485
627
|
async handler (builder) {
|
|
486
|
-
|
|
628
|
+
isApplicationBuild = true;
|
|
487
629
|
const environments = Object.entries(builder.environments);
|
|
488
630
|
if (isWatchMode) {
|
|
489
631
|
if (environments.length > 1) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
|
|
@@ -615,13 +757,17 @@ function withZephyrCore(options = {}) {
|
|
|
615
757
|
const zephyrEngine = await zephyr_engine_defer;
|
|
616
758
|
await rollbackPartialAssetMapClaimBatch(zephyrEngine.application_uid, partialClaims.map(({ claimId })=>claimId));
|
|
617
759
|
} catch (restoreError) {
|
|
618
|
-
|
|
760
|
+
logFn('error', ZephyrError.format(restoreError));
|
|
619
761
|
}
|
|
620
762
|
handleGlobalError(error);
|
|
621
763
|
}
|
|
622
764
|
}
|
|
623
765
|
}
|
|
624
766
|
};
|
|
767
|
+
return [
|
|
768
|
+
plugin,
|
|
769
|
+
buildAppStart
|
|
770
|
+
];
|
|
625
771
|
}
|
|
626
772
|
function withZephyr(options = {}) {
|
|
627
773
|
if (void 0 !== options.target) assertZephyrBuildTarget(options.target, 'withZephyr({ target })');
|
|
@@ -632,7 +778,7 @@ function withZephyr(options = {}) {
|
|
|
632
778
|
const preservesLockedArtifactPaths = 'tap-app' === options.target;
|
|
633
779
|
for (const mfConfig of mfConfigs)plugins.push(...federation(preservesLockedArtifactPaths ? mfConfig : ensureRuntimePlugin(mfConfig)));
|
|
634
780
|
}
|
|
635
|
-
plugins.push(withZephyrCore(options));
|
|
781
|
+
plugins.push(...withZephyrCore(options));
|
|
636
782
|
return plugins;
|
|
637
783
|
}
|
|
638
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.0",
|
|
5
5
|
"description": "Vite plugin for Zephyr",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"deploy",
|
|
@@ -48,19 +48,19 @@
|
|
|
48
48
|
"provenance": true
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"acorn": "^8.
|
|
51
|
+
"acorn": "^8.18.0",
|
|
52
52
|
"acorn-walk": "^8.3.5",
|
|
53
|
-
"magic-string": "
|
|
54
|
-
"zephyr-agent": "1.
|
|
53
|
+
"magic-string": "1.2.3",
|
|
54
|
+
"zephyr-agent": "1.4.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@module-federation/vite": "1.
|
|
58
|
-
"@rslib/core": "0.
|
|
59
|
-
"@rstest/core": "0.11.
|
|
57
|
+
"@module-federation/vite": "1.21.2",
|
|
58
|
+
"@rslib/core": "1.0.0",
|
|
59
|
+
"@rstest/core": "0.11.12",
|
|
60
60
|
"@types/node": "^24.13.3",
|
|
61
|
-
"rollup": "^4.
|
|
62
|
-
"typescript": "~
|
|
63
|
-
"vite": "^8.
|
|
61
|
+
"rollup": "^4.63.1",
|
|
62
|
+
"typescript": "~7.0.0",
|
|
63
|
+
"vite": "^8.2.2"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"@module-federation/vite": "^1.13.2",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|
|
87
|
-
"build": "rslib build",
|
|
87
|
+
"build": "rslib build --lib esm && rslib build --lib cjs --no-clean",
|
|
88
88
|
"patch-version": "pnpm version",
|
|
89
89
|
"dev": "rslib build --watch",
|
|
90
90
|
"typecheck": "tsc -b",
|
package/dist/rslib-runtime.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.mjs.map
|