Skip to content

Commit 4834c6b

Browse files
committed
fix: consistent package names
1 parent e3fcb55 commit 4834c6b

3 files changed

Lines changed: 28 additions & 27 deletions

File tree

libs/native-federation-core/src/lib/core/build-for-federation.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { writeFederationInfo } from './write-federation-info';
1515
import { writeImportMap } from './write-import-map';
1616
import { logger } from '../utils/logger';
1717
import { getCachePath } from './bundle-caching';
18-
import { normalizeFilename } from '../utils/normalize';
18+
import { normalizePackageName } from '../utils/normalize';
1919
import { AbortedError } from '../utils/errors';
2020

2121
export interface BuildParams {
@@ -35,7 +35,7 @@ export async function buildForFederation(
3535
config: NormalizedFederationConfig,
3636
fedOptions: FederationOptions,
3737
externals: string[],
38-
buildParams = defaultBuildParams,
38+
buildParams = defaultBuildParams
3939
): Promise<FederationInfo> {
4040
const signal = buildParams.signal;
4141

@@ -47,33 +47,33 @@ export async function buildForFederation(
4747
config,
4848
fedOptions,
4949
externals,
50-
signal,
50+
signal
5151
);
5252
logger.measure(
5353
start,
54-
'[build artifacts] - To bundle all mappings and exposed.',
54+
'[build artifacts] - To bundle all mappings and exposed.'
5555
);
5656

5757
if (signal?.aborted)
5858
throw new AbortedError(
59-
'[buildForFederation] After exposed-and-mappings bundle',
59+
'[buildForFederation] After exposed-and-mappings bundle'
6060
);
6161
}
6262

6363
const exposedInfo = !artefactInfo
6464
? describeExposed(config, fedOptions)
6565
: artefactInfo.exposes;
6666

67-
const cacheProjectFolder = normalizeFilename(config.name);
67+
const cacheProjectFolder = normalizePackageName(config.name);
6868
if (cacheProjectFolder.length < 1) {
6969
logger.warn(
70-
"Project name in 'federation.config.js' is empty, defaulting to root cache folder.",
70+
"Project name in 'federation.config.js' is empty, defaulting to root cache folder."
7171
);
7272
}
7373

7474
const pathToCache = getCachePath(
7575
fedOptions.workspaceRoot,
76-
normalizeFilename(config.name),
76+
normalizePackageName(config.name)
7777
);
7878

7979
if (!buildParams.skipShared && sharedPackageInfoCache.length > 0) {
@@ -92,19 +92,19 @@ export async function buildForFederation(
9292
fedOptions,
9393
externals,
9494
'browser',
95-
{ pathToCache, bundleName: 'browser-shared' },
95+
{ pathToCache, bundleName: 'browser-shared' }
9696
);
9797

9898
logger.measure(
9999
start,
100-
'[build artifacts] - To bundle all shared browser externals',
100+
'[build artifacts] - To bundle all shared browser externals'
101101
);
102102

103103
sharedPackageInfoCache.push(...sharedPackageInfoBrowser);
104104

105105
if (signal?.aborted)
106106
throw new AbortedError(
107-
'[buildForFederation] After shared-browser bundle',
107+
'[buildForFederation] After shared-browser bundle'
108108
);
109109
}
110110

@@ -116,11 +116,11 @@ export async function buildForFederation(
116116
fedOptions,
117117
externals,
118118
'node',
119-
{ pathToCache, bundleName: 'node-shared' },
119+
{ pathToCache, bundleName: 'node-shared' }
120120
);
121121
logger.measure(
122122
start,
123-
'[build artifacts] - To bundle all shared node externals',
123+
'[build artifacts] - To bundle all shared node externals'
124124
);
125125
sharedPackageInfoCache.push(...sharedPackageInfoServer);
126126

@@ -136,17 +136,17 @@ export async function buildForFederation(
136136
config,
137137
fedOptions,
138138
'browser',
139-
pathToCache,
139+
pathToCache
140140
);
141141
logger.measure(
142142
start,
143-
'[build artifacts] - To bundle all separate browser externals',
143+
'[build artifacts] - To bundle all separate browser externals'
144144
);
145145
sharedPackageInfoCache.push(...separatePackageInfoBrowser);
146146

147147
if (signal?.aborted)
148148
throw new AbortedError(
149-
'[buildForFederation] After separate-browser bundle',
149+
'[buildForFederation] After separate-browser bundle'
150150
);
151151
}
152152

@@ -158,11 +158,11 @@ export async function buildForFederation(
158158
config,
159159
fedOptions,
160160
'node',
161-
pathToCache,
161+
pathToCache
162162
);
163163
logger.measure(
164164
start,
165-
'[build artifacts] - To bundle all separate node externals',
165+
'[build artifacts] - To bundle all separate node externals'
166166
);
167167
sharedPackageInfoCache.push(...separatePackageInfoServer);
168168
}
@@ -214,13 +214,13 @@ async function bundleSeparate(
214214
config: NormalizedFederationConfig,
215215
fedOptions: FederationOptions,
216216
platform: 'node' | 'browser',
217-
pathToCache: string,
217+
pathToCache: string
218218
) {
219219
const bundlePromises = Object.entries(separateBrowser).map(
220220
async ([key, shared]) => {
221221
const packageName = inferPackageFromSecondary(key);
222222
const filteredExternals = externals.filter(
223-
(e) => !e.startsWith(packageName),
223+
(e) => !e.startsWith(packageName)
224224
);
225225
return bundleShared(
226226
{ [key]: shared },
@@ -230,18 +230,18 @@ async function bundleSeparate(
230230
platform,
231231
{
232232
pathToCache,
233-
bundleName: `${platform}-${normalizeFilename(key)}`,
234-
},
233+
bundleName: `${platform}-${normalizePackageName(key)}`,
234+
}
235235
);
236-
},
236+
}
237237
);
238238

239239
const buildResults = await Promise.all(bundlePromises);
240240
return buildResults.flat();
241241
}
242242

243243
function splitShared(
244-
shared: Record<string, NormalizedSharedConfig>,
244+
shared: Record<string, NormalizedSharedConfig>
245245
): SplitSharedResult {
246246
const sharedServer: Record<string, NormalizedSharedConfig> = {};
247247
const sharedBrowser: Record<string, NormalizedSharedConfig> = {};

libs/native-federation-core/src/lib/core/remove-unused-deps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { NormalizedFederationConfig } from '../config/federation-config';
66
import { getPackageInfo, PackageInfo } from '../utils/package-info';
77
import { getExternalImports as extractExternalImports } from '../utils/get-external-imports';
88
import { MappedPath } from '../utils/mapped-paths';
9+
import { normalizePackageName } from '../utils/normalize';
910

1011
export function removeUnusedDeps(
1112
config: NormalizedFederationConfig,
@@ -116,7 +117,7 @@ function addTransientDeps(packages: Set<string>, workspaceRoot: string) {
116117
}
117118

118119
function getExternalImports(pInfo: PackageInfo, workspaceRoot: string) {
119-
const encodedPackageName = pInfo.packageName.replace(/[^A-Za-z0-9]/g, '_');
120+
const encodedPackageName = normalizePackageName(pInfo.packageName);
120121
const cacheFileName = `${encodedPackageName}-${pInfo.version}.deps.json`;
121122
const cachePath = path.join(
122123
workspaceRoot,

libs/native-federation-core/src/lib/utils/normalize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function normalize(path: string, trailingSlash?: boolean): string {
1616
return cand;
1717
}
1818

19-
export function normalizeFilename(path: string) {
20-
const sanitized = path.replace(/[^A-Za-z0-9]/g, '_');
19+
export function normalizePackageName(fileName: string) {
20+
const sanitized = fileName.replace(/[^A-Za-z0-9]/g, '_');
2121
return sanitized.startsWith('_') ? sanitized.slice(1) : sanitized;
2222
}

0 commit comments

Comments
 (0)