Skip to content

Commit

Permalink
feat(nf): add --base-href option
Browse files Browse the repository at this point in the history
  • Loading branch information
manfredsteyer committed Aug 7, 2024
1 parent 655a658 commit cc4de21
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions libs/native-federation-core/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
28 changes: 17 additions & 11 deletions libs/native-federation-core/src/lib/core/bundle-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
});
Expand Down Expand Up @@ -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 });

Expand Down
2 changes: 1 addition & 1 deletion libs/native-federation-esbuild/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion libs/native-federation-runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@softarc/native-federation-runtime",
"version": "2.0.9",
"version": "2.0.10",
"peerDependencies": {},
"dependencies": {
"tslib": "^2.3.0"
Expand Down
6 changes: 3 additions & 3 deletions libs/native-federation/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions libs/native-federation/src/builders/build/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions libs/native-federation/src/builders/build/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface NfBuilderSchema extends JsonObject {
watch: boolean;
skipHtmlTransform: boolean;
esmsInitOptions: ESMSInitOptions;
baseHref?: string;
} // eslint-disable-line
3 changes: 3 additions & 0 deletions libs/native-federation/src/builders/build/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit cc4de21

Please sign in to comment.