@softarc/native-federation
Advanced tools
+1
-1
| { | ||
| "name": "@softarc/native-federation", | ||
| "version": "4.0.0-RC7", | ||
| "version": "4.0.0-RC8", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -6,3 +6,3 @@ export * from './lib/utils/build-result-map.js'; | ||
| export type { MappedPath } from './lib/domain/utils/mapped-path.contract.js'; | ||
| export { RebuildQueue } from './lib/utils/rebuild-queue.js'; | ||
| export { RebuildQueue, type TrackResult } from './lib/utils/rebuild-queue.js'; | ||
| export { AbortedError } from './lib/utils/errors.js'; | ||
@@ -9,0 +9,0 @@ export { createBuildResultMap, lookupInResultMap, popFromResultMap, } from './lib/utils/build-result-map.js'; |
@@ -12,12 +12,6 @@ import { bundleExposedAndMappings, describeExposed, describeSharedMappings, } from './bundle-exposed-and-mappings.js'; | ||
| export async function buildForFederation(config, fedOptions, externals, signal) { | ||
| // 1. Caching | ||
| // 1. Setup | ||
| fedOptions.federationCache.cachePath = path.join(fedOptions.federationCache.cachePath, resolveProjectName(config)); | ||
| const start = process.hrtime(); | ||
| // 2. Shared mappings and exposed modules | ||
| const artifactInfo = await bundleExposedAndMappings(config, fedOptions, externals, undefined, signal); | ||
| logger.measure(start, '[build artifacts] - To bundle all mappings and exposed.'); | ||
| if (signal?.aborted) | ||
| throw new AbortedError('[buildForFederation] After exposed-and-mappings bundle'); | ||
| const exposedInfo = !artifactInfo ? describeExposed(config, fedOptions) : artifactInfo.exposes; | ||
| // 3. Externals | ||
| logger.info('Building federation artifacts'); | ||
| // 2. Externals | ||
| if (fedOptions.federationCache.externals.length > 0) { | ||
@@ -65,2 +59,9 @@ logger.info('Checksum matched, re-using cached externals.'); | ||
| } | ||
| // 2. Shared mappings and exposed modules | ||
| const start = process.hrtime(); | ||
| const artifactInfo = await bundleExposedAndMappings(config, fedOptions, externals, undefined, signal); | ||
| logger.measure(start, '[build artifacts] - To bundle all mappings and exposed.'); | ||
| if (signal?.aborted) | ||
| throw new AbortedError('[buildForFederation] After exposed-and-mappings bundle'); | ||
| const exposedInfo = !artifactInfo ? describeExposed(config, fedOptions) : artifactInfo.exposes; | ||
| const sharedMappingInfo = !artifactInfo | ||
@@ -67,0 +68,0 @@ ? describeSharedMappings(config, fedOptions) |
@@ -25,3 +25,2 @@ import fs from 'fs'; | ||
| const hash = !fedOptions.dev; | ||
| logger.info('Building federation artifacts'); | ||
| let result; | ||
@@ -28,0 +27,0 @@ try { |
@@ -8,3 +8,3 @@ export interface ExternalConfig { | ||
| platform?: 'browser' | 'node'; | ||
| build?: 'default' | 'separate'; | ||
| build?: 'default' | 'separate' | 'package'; | ||
| shareScope?: string; | ||
@@ -11,0 +11,0 @@ packageInfo?: { |
@@ -1,2 +0,2 @@ | ||
| import { NormalizedFederationConfig } from '../domain/config/federation-config.contract.js'; | ||
| import type { NormalizedFederationConfig } from '../domain/config/federation-config.contract.js'; | ||
| export declare function resolveProjectName(config: NormalizedFederationConfig): string; |
@@ -0,6 +1,19 @@ | ||
| export type TrackResult<T = never> = { | ||
| type: 'completed'; | ||
| result: { | ||
| success: boolean; | ||
| cancelled?: boolean; | ||
| }; | ||
| } | { | ||
| type: 'interrupted'; | ||
| value: T; | ||
| }; | ||
| export declare class RebuildQueue { | ||
| private activeBuilds; | ||
| private buildCounter; | ||
| enqueue(rebuildFn: (signal: AbortSignal) => Promise<void>): Promise<void>; | ||
| track<T = never>(rebuildFn: (signal: AbortSignal) => Promise<{ | ||
| success: boolean; | ||
| cancelled?: boolean; | ||
| }>, interruptPromise?: Promise<T>): Promise<TrackResult<T>>; | ||
| dispose(): void; | ||
| } |
@@ -5,17 +5,15 @@ import { logger } from './logger.js'; | ||
| buildCounter = 0; | ||
| async enqueue(rebuildFn) { | ||
| async track(rebuildFn, interruptPromise) { | ||
| const buildId = ++this.buildCounter; | ||
| const pendingCancellations = Array.from(this.activeBuilds.values()).map(buildInfo => { | ||
| buildInfo.controller.abort(); | ||
| return buildInfo.buildFinished.promise; | ||
| const pendingCancellations = Array.from(this.activeBuilds.values()).map(buildControl => { | ||
| buildControl.controller.abort(); | ||
| return buildControl.buildFinished.promise; | ||
| }); | ||
| if (pendingCancellations.length > 0) { | ||
| logger.info(`Aborting ${pendingCancellations.length} bundling task(s)..`); | ||
| } | ||
| if (pendingCancellations.length > 0) { | ||
| await Promise.all(pendingCancellations); | ||
| } | ||
| let buildFinished; | ||
| let resolveCompletion; | ||
| const completionPromise = new Promise(resolve => { | ||
| buildFinished = resolve; | ||
| resolveCompletion = resolve; | ||
| }); | ||
@@ -25,3 +23,3 @@ const control = { | ||
| buildFinished: { | ||
| resolve: buildFinished, | ||
| resolve: resolveCompletion, | ||
| promise: completionPromise, | ||
@@ -31,4 +29,25 @@ }, | ||
| this.activeBuilds.set(buildId, control); | ||
| const buildPromise = rebuildFn(control.controller.signal) | ||
| .then(result => ({ type: 'completed', result })) | ||
| .catch(error => ({ type: 'completed', result: { success: false, error } })); | ||
| let trackResult; | ||
| try { | ||
| await rebuildFn(control.controller.signal); | ||
| if (interruptPromise) { | ||
| const interruptResult = interruptPromise.then(value => ({ | ||
| type: 'interrupted', | ||
| value, | ||
| })); | ||
| const raceResult = await Promise.race([buildPromise, interruptResult]); | ||
| if (raceResult.type === 'interrupted') { | ||
| control.controller.abort(); | ||
| await buildPromise; | ||
| trackResult = raceResult; | ||
| } | ||
| else { | ||
| trackResult = raceResult; | ||
| } | ||
| } | ||
| else { | ||
| trackResult = await buildPromise; | ||
| } | ||
| } | ||
@@ -39,6 +58,7 @@ finally { | ||
| } | ||
| return trackResult; | ||
| } | ||
| dispose() { | ||
| for (const [_, buildInfo] of this.activeBuilds) { | ||
| buildInfo.controller.abort(); | ||
| for (const buildControl of this.activeBuilds.values()) { | ||
| buildControl.controller.abort(); | ||
| } | ||
@@ -45,0 +65,0 @@ this.activeBuilds.clear(); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
102994
1.19%2474
1.35%