Skip to content

Commit

Permalink
feat(nf): update for angular 19 + ssr/hydration
Browse files Browse the repository at this point in the history
  • Loading branch information
manfredsteyer committed Dec 20, 2024
1 parent f2ad1f1 commit dbb6162
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 19 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.12",
"version": "2.0.13",
"type": "commonjs",
"license": "MIT",
"dependencies": {
"json5": "^2.2.0",
"npmlog": "^6.0.2",
"@softarc/native-federation-runtime": "2.0.12"
"@softarc/native-federation-runtime": "2.0.13"
}
}
3 changes: 3 additions & 0 deletions libs/native-federation-core/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { DEFAULT_SKIP_LIST } from './lib/core/default-skip-list';

export { NormalizedFederationConfig } from './lib/config/federation-config';
export { FederationOptions } from './lib/core/federation-options';
export { setBuildAdapter } from './lib/core/build-adapter';
Expand Down Expand Up @@ -29,3 +31,4 @@ export {
export { logger, setLogLevel } from './lib/utils/logger';
export { hashFile } from './lib/utils/hash-file';
export * from './lib/utils/build-result-map';

40 changes: 33 additions & 7 deletions libs/native-federation-core/src/lib/config/share-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DEFAULT_SKIP_LIST,
isInSkipList,
PREPARED_DEFAULT_SKIP_LIST,
PreparedSkipList,
prepareSkipList,
SkipList,
} from '../core/default-skip-list';
Expand Down Expand Up @@ -321,7 +322,7 @@ export function shareAll(
}
}

return module.exports.share(share, projectPath);
return module.exports.share(share, projectPath, skip);
}

function inferProjectPath(projectPath: string) {
Expand Down Expand Up @@ -351,7 +352,8 @@ type TransientDependency = {

function findTransientDeps(
packageNames: string[],
projectRoot: string
projectRoot: string,
preparedSkipList: PreparedSkipList
): TransientDependency[] {
const discovered = new Set<string>();
const result: TransientDependency[] = [];
Expand All @@ -363,7 +365,13 @@ function findTransientDeps(
packageName,
'package.json'
);
_findTransientDeps(packagePath, projectRoot, discovered, result);
_findTransientDeps(
packagePath,
projectRoot,
preparedSkipList,
discovered,
result
);
}

return result;
Expand All @@ -372,6 +380,7 @@ function findTransientDeps(
function _findTransientDeps(
packagePath: string,
projectRoot: string,
preparedSkipList: PreparedSkipList,
discovered: Set<string>,
result: TransientDependency[]
) {
Expand All @@ -391,30 +400,47 @@ function _findTransientDeps(
);
const depPath = path.dirname(depPackageJson);

if (!discovered.has(depPackageJson)) {
if (
!discovered.has(depPackageJson) &&
!isInSkipList(dep, preparedSkipList) &&
fs.existsSync(depPackageJson)
) {
discovered.add(depPackageJson);
const version = packageJson.dependencies[dep];
result.push({
packageName: dep,
requiredVersion: version,
packagePath: depPath,
});
_findTransientDeps(depPackageJson, projectRoot, discovered, result);
_findTransientDeps(
depPackageJson,
projectRoot,
preparedSkipList,
discovered,
result
);
}
}
}

export function share(
configuredShareObjects: Config,
projectPath = ''
projectPath = '',
skipList = DEFAULT_SKIP_LIST
): Config {
projectPath = inferProjectPath(projectPath);
const packagePath = findPackageJson(projectPath);

const sharedPackageNames = Object.keys(configuredShareObjects);
const packageDirectory = path.dirname(packagePath);

const transientDeps = findTransientDeps(sharedPackageNames, packageDirectory);
const preparedSkipList = prepareSkipList(skipList);

const transientDeps = findTransientDeps(
sharedPackageNames,
packageDirectory,
preparedSkipList
);

const transientShareObject = transientDeps.reduce(
(acc, curr) => ({
Expand Down
6 changes: 3 additions & 3 deletions libs/native-federation-core/src/lib/core/default-skip-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export const DEFAULT_SKIP_LIST: SkipList = [
'@angular/localize/tools',
(pkg) => pkg.startsWith('@angular/common/locales'),
(pkg) => pkg.startsWith('rxjs/internal'),
'@angular/platform-server',
'@angular/platform-server/init',
'@angular/ssr',
// '@angular/platform-server',
// '@angular/platform-server/init',
// '@angular/ssr',
'express',
/\/schematics(\/|$)/,
/^@nx\/angular/,
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.12",
"version": "2.0.13",
"type": "commonjs",
"dependencies": {
"@rollup/plugin-commonjs": "^22.0.2",
Expand Down
2 changes: 1 addition & 1 deletion libs/native-federation-node/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@softarc/native-federation-node",
"version": "2.0.12"
"version": "2.0.13"
}
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.12",
"version": "2.0.13",
"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.2.5",
"version": "18.2.6",
"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.12",
"@softarc/native-federation-runtime": "2.0.12",
"@softarc/native-federation": "2.0.13",
"@softarc/native-federation-runtime": "2.0.13",
"@types/browser-sync": "^2.29.0",
"@chialab/esbuild-plugin-commonjs": "^0.18.0",
"browser-sync": "^3.0.2",
Expand Down
1 change: 1 addition & 0 deletions libs/native-federation/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export {
findRootTsConfigJson,
share,
shareAll,
DEFAULT_SKIP_LIST
} from '@softarc/native-federation/build';
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async function runEsbuild(
'object-rest-spread': false,
},
splitting: kind === 'mapping-or-exposed',
platform: 'browser',
platform: 'node',
format: 'esm',
target: ['esnext'],
logLimit: kind === 'shared-package' ? 1 : 0,
Expand Down

0 comments on commit dbb6162

Please sign in to comment.