Skip to content

Commit ae03fba

Browse files
committed
feat(nf): allow to version repo-internal libs (mapped paths)
1 parent 37b7bf2 commit ae03fba

File tree

14 files changed

+102
-33
lines changed

14 files changed

+102
-33
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "@softarc/native-federation",
3-
"version": "2.0.20",
3+
"version": "2.0.22",
44
"type": "commonjs",
55
"license": "MIT",
66
"dependencies": {
77
"json5": "^2.2.0",
88
"npmlog": "^6.0.2",
9-
"@softarc/native-federation-runtime": "2.0.20"
9+
"@softarc/native-federation-runtime": "2.0.22"
1010
}
1111
}

libs/native-federation-core/src/lib/config/federation-config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export interface FederationConfig {
2424
sharedMappings?: Array<string>;
2525
skip?: SkipList;
2626
externals?: string[];
27+
features?: {
28+
mappingVersion?: boolean;
29+
}
2730
}
2831

2932
export interface NormalizedSharedConfig {
@@ -48,4 +51,7 @@ export interface NormalizedFederationConfig {
4851
sharedMappings: Array<MappedPath>;
4952
skip: PreparedSkipList;
5053
externals: string[];
54+
features: {
55+
mappingVersion: boolean;
56+
}
5157
}

libs/native-federation-core/src/lib/config/with-native-federation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export function withNativeFederation(
2525
sharedMappings: normalizeSharedMappings(config, skip),
2626
skip,
2727
externals: config.externals ?? [],
28+
features: {
29+
mappingVersion: config.features?.mappingVersion ?? false,
30+
},
2831
};
2932
}
3033

libs/native-federation-core/src/lib/core/bundle-exposed-and-mappings.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import path from 'path';
2+
import fs from 'fs';
3+
24
import { NormalizedFederationConfig } from '../config/federation-config';
35
import { FederationOptions } from './federation-options';
46
import { bundle } from '../utils/build-utils';
@@ -61,7 +63,7 @@ export async function bundleExposedAndMappings(
6163
requiredVersion: '',
6264
singleton: true,
6365
strictVersion: false,
64-
version: '',
66+
version: config.features.mappingVersion ? getMappingVersion(item.fileName) : '',
6567
dev: !fedOptions.dev
6668
? undefined
6769
: {
@@ -127,7 +129,7 @@ export function describeSharedMappings(
127129
requiredVersion: '',
128130
singleton: true,
129131
strictVersion: false,
130-
version: '',
132+
version: config.features.mappingVersion ? getMappingVersion(m.path) : '',
131133
dev: !fedOptions.dev
132134
? undefined
133135
: {
@@ -138,3 +140,16 @@ export function describeSharedMappings(
138140

139141
return result;
140142
}
143+
144+
function getMappingVersion(fileName: string): string {
145+
const entryFileDir = path.dirname(fileName);
146+
const cand1 = path.join(entryFileDir, 'package.json');
147+
const cand2 = path.join(path.dirname(entryFileDir), 'package.json');
148+
149+
const packageJsonPath = [cand1, cand2].find((cand) => fs.existsSync(cand));
150+
if (packageJsonPath) {
151+
const json = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
152+
return json.version ?? '';
153+
}
154+
return '';
155+
}

libs/native-federation-core/src/lib/core/bundle-shared.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as path from 'path';
22
import * as fs from 'fs';
3-
import { NormalizedFederationConfig, NormalizedSharedConfig } from '../config/federation-config';
3+
import {
4+
NormalizedFederationConfig,
5+
NormalizedSharedConfig,
6+
} from '../config/federation-config';
47
import { bundle } from '../utils/build-utils';
58
import { getPackageInfo, PackageInfo } from '../utils/package-info';
69
import { SharedInfo } from '@softarc/native-federation-runtime';
@@ -9,6 +12,7 @@ import { copySrcMapIfExists } from '../utils/copy-src-map-if-exists';
912
import { logger } from '../utils/logger';
1013
import { normalize } from '../utils/normalize';
1114
import crypto from 'crypto';
15+
import { DEFAULT_EXTERNAL_LIST } from './default-external-list';
1216

1317
export async function bundleShared(
1418
sharedBundles: Record<string, NormalizedSharedConfig>,
@@ -83,11 +87,16 @@ export async function bundleShared(
8387
);
8488
}
8589

90+
const additionalExternals = platform === 'browser' ? DEFAULT_EXTERNAL_LIST : [];
91+
8692
try {
8793
await bundle({
8894
entryPoints,
8995
tsConfigPath: fedOptions.tsConfig,
90-
external: externals,
96+
external: [
97+
...additionalExternals,
98+
...externals
99+
],
91100
outdir: cachePath,
92101
mappedPaths: config.sharedMappings,
93102
dev: fedOptions.dev,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const NODE_PACKAGES = [
2+
'assert',
3+
'buffer',
4+
'child_process',
5+
'cluster',
6+
'crypto',
7+
'dgram',
8+
'dns',
9+
'events',
10+
'fs',
11+
'http',
12+
'https',
13+
'module',
14+
'net',
15+
'os',
16+
'path',
17+
'querystring',
18+
'readline',
19+
'stream',
20+
'timers',
21+
'tls',
22+
'tty',
23+
'url',
24+
'util',
25+
'v8',
26+
'vm',
27+
'zlib',
28+
];
29+
30+
export const DEFAULT_EXTERNAL_LIST = NODE_PACKAGES.flatMap(p => ([p, 'node:' + p]));

libs/native-federation-esbuild/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@softarc/native-federation-esbuild",
3-
"version": "2.0.20",
3+
"version": "2.0.22",
44
"type": "commonjs",
55
"dependencies": {
66
"@rollup/plugin-commonjs": "^22.0.2",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"name": "@softarc/native-federation-node",
3-
"version": "2.0.20"
3+
"version": "2.0.22"
44
}

libs/native-federation-runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@softarc/native-federation-runtime",
3-
"version": "2.0.20",
3+
"version": "2.0.22",
44
"dependencies": {
55
"tslib": "^2.3.0"
66
},

libs/native-federation/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-architects/native-federation",
3-
"version": "19.0.8",
3+
"version": "19.0.10",
44
"main": "src/index.js",
55
"generators": "./collection.json",
66
"builders": "./builders.json",
@@ -20,8 +20,8 @@
2020
},
2121
"dependencies": {
2222
"@babel/core": "^7.19.0",
23-
"@softarc/native-federation": "2.0.20",
24-
"@softarc/native-federation-runtime": "2.0.20",
23+
"@softarc/native-federation": "2.0.22",
24+
"@softarc/native-federation-runtime": "2.0.22",
2525
"@types/browser-sync": "^2.29.0",
2626
"@chialab/esbuild-plugin-commonjs": "^0.18.0",
2727
"browser-sync": "^3.0.2",

0 commit comments

Comments
 (0)