Skip to content

fix(skip-list): fixed the handling and passing of the skip list #902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .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 Expand Up @@ -46,6 +47,5 @@ migrations.json
# Angular
.angular

.nx
.cursor/rules/nx-rules.mdc
.github/instructions/nx.instructions.md
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
39 changes: 24 additions & 15 deletions libs/native-federation-core/src/lib/config/share-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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 +25,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 +109,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 @@ -136,27 +136,29 @@ function _findSecondaries(
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 +178,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 +241,7 @@ function readConfiguredSecondaries(
continue;
}

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

Expand Down Expand Up @@ -350,10 +359,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 +569,8 @@ export function share(
includeSecondaries,
libPath,
key,
shareObject
shareObject,
preparedSkipList
);
if (secondaries) {
addSecondaries(secondaries, result);
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
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.1",
"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-node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"module": "ES2020",
"target": "ES2020",
"allowJs": true
"allowJs": true,
},
"files": [],
"include": [],
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.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function getRemoteNameByOptions(options: LoadRemoteModuleOptions) {
remoteName = getRemoteNameByBaseUrl(baseUrl);
} else {
throw new Error(
'unexpcted arguments: Please pass remoteName or remoteEntry'
'unexpected arguments: Please pass remoteName or remoteEntry'
);
}

Expand Down
4 changes: 2 additions & 2 deletions libs/native-federation/src/builders/build/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export async function* runBuilder(
const fedOptions: FederationOptions = {
workspaceRoot: context.workspaceRoot,
outputPath: browserOutputPath,
federationConfig: infereConfigPath(options.tsConfig),
federationConfig: inferConfigPath(options.tsConfig),
tsConfig: options.tsConfig,
verbose: options.verbose,
watch: false, // options.watch,
Expand Down Expand Up @@ -454,7 +454,7 @@ function getLocaleFilter(
return localize;
}

function infereConfigPath(tsConfig: string): string {
function inferConfigPath(tsConfig: string): string {
const relProjectPath = path.dirname(tsConfig);
const relConfigPath = path.join(relProjectPath, 'federation.config.js');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function updateWorkspaceConfig(

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
2 changes: 1 addition & 1 deletion libs/native-federation/src/schematics/init/schematic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function updateWorkspaceConfig(

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
2 changes: 1 addition & 1 deletion libs/native-federation/src/schematics/remove/schematic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function updateWorkspaceConfig(

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
Loading
Loading