From cc4de21e2003705ef9b37ae66da500b313839f3d Mon Sep 17 00:00:00 2001 From: Manfred Steyer Date: Wed, 7 Aug 2024 23:27:04 +0200 Subject: [PATCH] feat(nf): add --base-href option --- libs/native-federation-core/package.json | 4 +-- .../src/lib/core/bundle-shared.ts | 28 +++++++++++-------- libs/native-federation-esbuild/package.json | 2 +- libs/native-federation-runtime/package.json | 2 +- libs/native-federation/package.json | 6 ++-- .../src/builders/build/builder.ts | 1 + .../src/builders/build/schema.d.ts | 1 + .../src/builders/build/schema.json | 3 ++ 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/libs/native-federation-core/package.json b/libs/native-federation-core/package.json index fd618f64..c6a6ccb3 100644 --- a/libs/native-federation-core/package.json +++ b/libs/native-federation-core/package.json @@ -1,11 +1,11 @@ { "name": "@softarc/native-federation", - "version": "2.0.9", + "version": "2.0.10", "type": "commonjs", "license": "MIT", "dependencies": { "json5": "^2.2.0", "npmlog": "^6.0.2", - "@softarc/native-federation-runtime": "2.0.9" + "@softarc/native-federation-runtime": "2.0.10" } } diff --git a/libs/native-federation-core/src/lib/core/bundle-shared.ts b/libs/native-federation-core/src/lib/core/bundle-shared.ts index 6d6cd5c2..ce33a931 100644 --- a/libs/native-federation-core/src/lib/core/bundle-shared.ts +++ b/libs/native-federation-core/src/lib/core/bundle-shared.ts @@ -39,18 +39,11 @@ export async function bundleShared( // ? `${encName}-${encVersion}-dev.js` // : `${encName}-${encVersion}.js`; - const hashBase = pi.version + '_' + pi.entryPoint; - const hash = crypto.createHash('sha256') - .update(hashBase) - .digest('base64') - .replace(/\//g, '_') - .replace(/\+/g, '-') - .replace(/=/g, '') - .substring(0,10); - + const hash = calcFileHash(pi); + const outName = fedOptions.dev - ? `${encName}.${hash}-dev.js` - : `${encName}.${hash}.js`; + ? `${encName}.${hash}-dev.js` + : `${encName}.${hash}.js`; return { fileName: pi.entryPoint, outName }; }); @@ -145,6 +138,19 @@ export async function bundleShared( }); } +function calcFileHash(pi: PackageInfo) { + const hashBase = pi.version + '_' + pi.entryPoint; + const hash = crypto + .createHash('sha256') + .update(hashBase) + .digest('base64') + .replace(/\//g, '_') + .replace(/\+/g, '-') + .replace(/=/g, '') + .substring(0, 10); + return hash; +} + function copyFileIfExists(cachedFile: string, fullOutputPath: string) { fs.mkdirSync(path.dirname(fullOutputPath), { recursive: true }); diff --git a/libs/native-federation-esbuild/package.json b/libs/native-federation-esbuild/package.json index 7a2010e1..cc47d77f 100644 --- a/libs/native-federation-esbuild/package.json +++ b/libs/native-federation-esbuild/package.json @@ -1,6 +1,6 @@ { "name": "@softarc/native-federation-esbuild", - "version": "2.0.9", + "version": "2.0.10", "type": "commonjs", "dependencies": { "@rollup/plugin-commonjs": "^22.0.2", diff --git a/libs/native-federation-runtime/package.json b/libs/native-federation-runtime/package.json index 439317b1..d9cf2d79 100644 --- a/libs/native-federation-runtime/package.json +++ b/libs/native-federation-runtime/package.json @@ -1,6 +1,6 @@ { "name": "@softarc/native-federation-runtime", - "version": "2.0.9", + "version": "2.0.10", "peerDependencies": {}, "dependencies": { "tslib": "^2.3.0" diff --git a/libs/native-federation/package.json b/libs/native-federation/package.json index 4b6ddc7f..84102be6 100644 --- a/libs/native-federation/package.json +++ b/libs/native-federation/package.json @@ -1,6 +1,6 @@ { "name": "@angular-architects/native-federation", - "version": "18.0.1", + "version": "18.1.0", "main": "src/index.js", "generators": "./collection.json", "builders": "./builders.json", @@ -20,8 +20,8 @@ }, "dependencies": { "@babel/core": "^7.19.0", - "@softarc/native-federation": "2.0.9", - "@softarc/native-federation-runtime": "2.0.9", + "@softarc/native-federation": "2.0.10", + "@softarc/native-federation-runtime": "2.0.10", "@types/browser-sync": "^2.29.0", "browser-sync": "^3.0.2", "esbuild": "^0.19.5", diff --git a/libs/native-federation/src/builders/build/builder.ts b/libs/native-federation/src/builders/build/builder.ts index 1b9100e0..5dbe00e5 100644 --- a/libs/native-federation/src/builders/build/builder.ts +++ b/libs/native-federation/src/builders/build/builder.ts @@ -127,6 +127,7 @@ export async function* runBuilder( const watch = !!runServer || nfOptions.watch; options.watch = watch; + options.baseHref = nfOptions.baseHref; const rebuildEvents = new RebuildHubs(); const adapter = createAngularBuildAdapter(options, context, rebuildEvents); diff --git a/libs/native-federation/src/builders/build/schema.d.ts b/libs/native-federation/src/builders/build/schema.d.ts index 1980f786..3fae81c9 100644 --- a/libs/native-federation/src/builders/build/schema.d.ts +++ b/libs/native-federation/src/builders/build/schema.d.ts @@ -11,4 +11,5 @@ export interface NfBuilderSchema extends JsonObject { watch: boolean; skipHtmlTransform: boolean; esmsInitOptions: ESMSInitOptions; + baseHref?: string; } // eslint-disable-line diff --git a/libs/native-federation/src/builders/build/schema.json b/libs/native-federation/src/builders/build/schema.json index aaaff754..811c6b21 100644 --- a/libs/native-federation/src/builders/build/schema.json +++ b/libs/native-federation/src/builders/build/schema.json @@ -43,6 +43,9 @@ "type": "boolean", "default": false }, + "baseHref": { + "type": "string" + }, "esmsInitOptions": { "type": "object", "description": "Options for esms-module-shims https://github.com/guybedford/es-module-shims?tab=readme-ov-file#init-options",