Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ node_modules
*.launch
.settings/
*.sublime-workspace
.tool-versions

# IDE - VSCode
.vscode/*
Expand Down
2 changes: 1 addition & 1 deletion libs/mf/rspack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './src/rspack';
export {
DEFAULT_SECONARIES_SKIP_LIST,
DEFAULT_SECONDARIES_SKIP_LIST,
DEFAULT_SKIP_LIST,
SharedMappings,
findRootTsConfigJson,
Expand Down
6 changes: 3 additions & 3 deletions libs/mf/src/schematics/init-webpack/schematic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function nxBuildersAvailable(tree: Tree): boolean {
return true;
}

function infereNxBuilderNames(tree: Tree): { dev: string; prod: string } {
function inferNxBuilderNames(tree: Tree): { dev: string; prod: string } {
const dep = getPackageJsonDependency(tree, '@nx/angular');

const useDevServer =
Expand Down Expand Up @@ -334,7 +334,7 @@ export default function config(options: MfSchematicSchema): Rule {
options.nxBuilders = nxBuildersAvailable(tree); // tree.exists('nx.json');
}

const nxBuilderNames = infereNxBuilderNames(tree);
const nxBuilderNames = inferNxBuilderNames(tree);

if (options.nxBuilders) {
console.log('Using Nx builders!');
Expand All @@ -354,7 +354,7 @@ export default function config(options: MfSchematicSchema): Rule {

if (!projectConfig?.architect?.build || !projectConfig?.architect?.serve) {
throw new Error(
`The project doen't have a build or serve target in angular.json!`
`The project doesn't have a build or serve target in angular.json!`
);
}

Expand Down
8 changes: 4 additions & 4 deletions libs/mf/src/utils/share-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const DEFAULT_SKIP_LIST = [
'zone.js',
];

export const DEFAULT_SECONARIES_SKIP_LIST = [
export const DEFAULT_SECONDARIES_SKIP_LIST = [
'@angular/router/upgrade',
'@angular/common/upgrade',
];
Expand Down Expand Up @@ -135,7 +135,7 @@ function getSecondaries(
packagePath: string,
key: string,
shareObject: SharedConfig,
exclude = [...DEFAULT_SECONARIES_SKIP_LIST]
exclude = [...DEFAULT_SECONDARIES_SKIP_LIST]
): Record<string, SharedConfig> {
if (typeof includeSecondaries === 'object') {
if (Array.isArray(includeSecondaries.skip)) {
Expand Down Expand Up @@ -217,7 +217,7 @@ function readConfiguredSecondaries(

export function shareAll(
config: CustomSharedConfig = {},
skip: string[] = [...DEFAULT_SKIP_LIST, ...DEFAULT_SECONARIES_SKIP_LIST],
skip: string[] = [...DEFAULT_SKIP_LIST, ...DEFAULT_SECONDARIES_SKIP_LIST],
packageJsonPath = ''
): Config {
if (!packageJsonPath) {
Expand Down Expand Up @@ -247,7 +247,7 @@ export function setInferVersion(infer: boolean): void {
export function share(
shareObjects: Config,
packageJsonPath = '',
skip: string[] = DEFAULT_SECONARIES_SKIP_LIST
skip: string[] = DEFAULT_SECONDARIES_SKIP_LIST
): Config {
if (!packageJsonPath) {
packageJsonPath = cwd();
Expand Down
4 changes: 2 additions & 2 deletions libs/mf/src/utils/with-mf-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
DEFAULT_SECONARIES_SKIP_LIST,
DEFAULT_SECONDARIES_SKIP_LIST,
DEFAULT_SKIP_LIST,
findRootTsConfigJson,
shareAll,
Expand All @@ -15,7 +15,7 @@ export function withModuleFederationPlugin(config: unknown) {

const skip = [
...DEFAULT_SKIP_LIST,
...DEFAULT_SECONARIES_SKIP_LIST,
...DEFAULT_SECONDARIES_SKIP_LIST,
...(config['skip'] || []),
];

Expand Down
42 changes: 25 additions & 17 deletions libs/native-federation-core/src/lib/config/share-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { SharedConfig } from './federation-config';
import {
DEFAULT_SKIP_LIST,
isInSkipList,
PREPARED_DEFAULT_SKIP_LIST,
PreparedSkipList,
prepareSkipList,
SkipList,
Expand All @@ -17,7 +16,6 @@ import {
} from '../utils/package-info';
import { getConfigContext } from './configuration-context';
import { logger } from '../utils/logger';
import { resolveGlobSync } from '../utils/resolve-glob';

import {
KeyValuePair,
Expand All @@ -26,7 +24,7 @@ import {

let inferVersion = false;

export const DEFAULT_SECONARIES_SKIP_LIST = [
export const DEFAULT_SECONDARIES_SKIP_LIST = [
'@angular/router/upgrade',
'@angular/common/upgrade',
];
Expand Down Expand Up @@ -110,7 +108,8 @@ function _findSecondaries(
libPath: string,
excludes: string[],
shareObject: SharedConfig,
acc: Record<string, SharedConfig>
acc: Record<string, SharedConfig>,
preparedSkipList: PreparedSkipList
): void {
const files = fs.readdirSync(libPath);

Expand All @@ -129,34 +128,36 @@ function _findSecondaries(
continue;
}

if (isInSkipList(secondaryLibName, PREPARED_DEFAULT_SKIP_LIST)) {
if (isInSkipList(secondaryLibName, preparedSkipList)) {
continue;
}

acc[secondaryLibName] = { ...shareObject };
}

_findSecondaries(s, excludes, shareObject, acc);
_findSecondaries(s, excludes, shareObject, acc, preparedSkipList);
}
}

function findSecondaries(
libPath: string,
excludes: string[],
shareObject: SharedConfig
shareObject: SharedConfig,
preparedSkipList: PreparedSkipList
): Record<string, SharedConfig> {
const acc = {} as Record<string, SharedConfig>;
_findSecondaries(libPath, excludes, shareObject, acc);
_findSecondaries(libPath, excludes, shareObject, acc, preparedSkipList);
return acc;
}

function getSecondaries(
includeSecondaries: IncludeSecondariesOptions,
libPath: string,
key: string,
shareObject: SharedConfig
shareObject: SharedConfig,
preparedSkipList: PreparedSkipList
): Record<string, SharedConfig> | null {
let exclude = [...DEFAULT_SECONARIES_SKIP_LIST];
let exclude = [...DEFAULT_SECONDARIES_SKIP_LIST];

if (typeof includeSecondaries === 'object') {
if (Array.isArray(includeSecondaries.skip)) {
Expand All @@ -176,22 +177,29 @@ function getSecondaries(
key,
libPath,
exclude,
shareObject
shareObject,
preparedSkipList
);
if (configured) {
return configured;
}

// Fallback: Search folders
const secondaries = findSecondaries(libPath, exclude, shareObject);
const secondaries = findSecondaries(
libPath,
exclude,
shareObject,
preparedSkipList
);
return secondaries;
}

function readConfiguredSecondaries(
parent: string,
libPath: string,
exclude: string[],
shareObject: SharedConfig
shareObject: SharedConfig,
preparedSkipList: PreparedSkipList
): Record<string, SharedConfig> | null {
const libPackageJson = path.join(libPath, 'package.json');

Expand Down Expand Up @@ -232,7 +240,7 @@ function readConfiguredSecondaries(
continue;
}

if (isInSkipList(secondaryName, PREPARED_DEFAULT_SKIP_LIST)) {
if (isInSkipList(secondaryName, preparedSkipList)) {
continue;
}

Expand Down Expand Up @@ -350,10 +358,9 @@ export function shareAll(

const versionMaps = getVersionMaps(projectPath, projectPath);
const share: Record<string, unknown> = {};
const preparedSkipList = prepareSkipList(skip);

for (const versions of versionMaps) {
const preparedSkipList = prepareSkipList(skip);

for (const key in versions) {
if (isInSkipList(key, preparedSkipList)) {
continue;
Expand Down Expand Up @@ -561,7 +568,8 @@ export function share(
includeSecondaries,
libPath,
key,
shareObject
shareObject,
preparedSkipList
);
if (secondaries) {
addSecondaries(secondaries, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function buildForFederation(
let artefactInfo: ArtefactInfo | undefined;

if (!buildParams.skipMappingsAndExposed) {
let start = process.hrtime();
const start = process.hrtime();
artefactInfo = await bundleExposedAndMappings(
config,
fedOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export async function bundleExposedAndMappings(
dev: !fedOptions.dev
? undefined
: {
entryPoint: normalize(path.normalize(item.fileName)),
},
entryPoint: normalize(path.normalize(item.fileName)),
},
});
}

Expand All @@ -90,10 +90,10 @@ export async function bundleExposedAndMappings(
dev: !fedOptions.dev
? undefined
: {
entryPoint: normalize(
path.join(fedOptions.workspaceRoot, item.fileName)
),
},
entryPoint: normalize(
path.join(fedOptions.workspaceRoot, item.fileName)
),
},
});
}

Expand All @@ -117,8 +117,8 @@ export function describeExposed(
dev: !options.dev
? undefined
: {
entryPoint: localPath,
},
entryPoint: localPath,
},
});
}

Expand All @@ -142,8 +142,8 @@ export function describeSharedMappings(
dev: !fedOptions.dev
? undefined
: {
entryPoint: normalize(path.normalize(m.path)),
},
entryPoint: normalize(path.normalize(m.path)),
},
});
}

Expand Down
4 changes: 2 additions & 2 deletions libs/native-federation-core/src/lib/core/bundle-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function bundleShared(

fs.mkdirSync(cachePath, { recursive: true });

const inferedPackageInfos = Object.keys(sharedBundles)
const inferredPackageInfos = Object.keys(sharedBundles)
.filter((packageName) => !sharedBundles[packageName].packageInfo)
.map((packageName) => getPackageInfo(packageName, folder))
.filter((pi) => !!pi) as PackageInfo[];
Expand All @@ -49,7 +49,7 @@ export async function bundleShared(
...sharedBundles[packageName].packageInfo,
})) as PackageInfo[];

const packageInfos = [...inferedPackageInfos, ...configuredPackageInfos];
const packageInfos = [...inferredPackageInfos, ...configuredPackageInfos];

const configState =
'BUNDLER_CHUNKS' + // TODO: Replace this with lib version
Expand Down
2 changes: 0 additions & 2 deletions libs/native-federation-core/src/lib/core/default-skip-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export const DEFAULT_SKIP_LIST: SkipList = [
// (pkg) => pkg.startsWith('@angular/common/locales'),
];

export const PREPARED_DEFAULT_SKIP_LIST = prepareSkipList(DEFAULT_SKIP_LIST);

export type PreparedSkipList = {
strings: Set<string>;
functions: SkipFn[];
Expand Down
4 changes: 2 additions & 2 deletions libs/native-federation-esbuild/src/lib/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function createEsBuildAdapter(config: EsBuildAdapterConfig) {

for (const entryPoint of entryPoints) {
const isPkg = entryPoint.fileName.includes('node_modules');
const pkgName = isPkg ? inferePkgName(entryPoint.fileName) : '';
const pkgName = isPkg ? inferPkgName(entryPoint.fileName) : '';
const tmpFolder = `node_modules/.tmp/${pkgName}`;

if (isPkg) {
Expand Down Expand Up @@ -170,7 +170,7 @@ async function prepareNodePackage(
});
}

function inferePkgName(entryPoint: string) {
function inferPkgName(entryPoint: string) {
return entryPoint
.replace(/.*?node_modules/g, '')
.replace(/[^A-Za-z0-9.]/g, '_');
Expand Down
6 changes: 5 additions & 1 deletion libs/native-federation-node/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"name": "@softarc/native-federation-node",
"version": "3.3.6",
"license": "MIT"
"license": "MIT",
"dependencies": {
"@softarc/native-federation-runtime": "^3.3.1",
"tslib": "^2.8.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function resolveAndComposeImportMap(parsed) {
let sortedAndNormalizedImports = {};

// Step 4
if (parsed.hasOwnProperty('imports')) {
if (Object.prototype.hasOwnProperty.call(parsed, 'imports')) {
// Step 4.1
if (!isPlainObject(parsed.imports)) {
throw Error(`Invalid import map - "imports" property must be an object`);
Expand All @@ -106,7 +106,7 @@ export function resolveAndComposeImportMap(parsed) {
let sortedAndNormalizedScopes = {};

// Step 6
if (parsed.hasOwnProperty('scopes')) {
if (Object.prototype.hasOwnProperty.call(parsed, 'scopes')) {
// Step 6.1
if (!isPlainObject(parsed.scopes)) {
throw Error(`Invalid import map - "scopes" property must be an object`);
Expand Down Expand Up @@ -250,15 +250,15 @@ export async function load(url, context, defaultLoad) {
const source = await res.text();
return {
shortCircuit: true,
format: 'module',
format: 'module',
source,
};
}

if (!url.startsWith('node:')) {
context.format = 'module';
}

return defaultLoad(url, context, defaultLoad);
}

Expand Down
2 changes: 1 addition & 1 deletion libs/native-federation-runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test native-federation-runtime3` to execute the unit tests.
Run `nx test native-federation-runtime` to execute the unit tests.
Loading