From 1acc1770dc44a629d49902ca3891ad298768170b Mon Sep 17 00:00:00 2001 From: SteveVanOpstal Date: Fri, 7 Jun 2024 08:53:05 +0200 Subject: [PATCH 1/3] feat(core): resolve wildcard mappings --- .../src/lib/config/with-native-federation.ts | 4 -- .../src/lib/utils/mapped-paths.ts | 36 +++++++++- package-lock.json | 66 +++++++++---------- package.json | 3 + 4 files changed, 69 insertions(+), 40 deletions(-) diff --git a/libs/native-federation-core/src/lib/config/with-native-federation.ts b/libs/native-federation-core/src/lib/config/with-native-federation.ts index 200baa8b..6b6438b6 100644 --- a/libs/native-federation-core/src/lib/config/with-native-federation.ts +++ b/libs/native-federation-core/src/lib/config/with-native-federation.ts @@ -85,9 +85,5 @@ function normalizeSharedMappings( (p) => !isInSkipList(p.key, skip) && !p.key.includes('*') ); - if (paths.find((p) => p.key.includes('*'))) { - logger.warn('Sharing mapped paths with wildcards (*) not supported'); - } - return result; } diff --git a/libs/native-federation-core/src/lib/utils/mapped-paths.ts b/libs/native-federation-core/src/lib/utils/mapped-paths.ts index ae5f554a..4a0a52bf 100644 --- a/libs/native-federation-core/src/lib/utils/mapped-paths.ts +++ b/libs/native-federation-core/src/lib/utils/mapped-paths.ts @@ -1,6 +1,8 @@ import * as path from 'path'; import * as fs from 'fs'; import * as JSON5 from 'json5'; +import * as glob from 'fast-glob'; +import * as mm from 'micromatch'; export interface MappedPath { key: string; @@ -39,8 +41,7 @@ export function getMappedPaths({ fs.readFileSync(rootTsConfigPath, { encoding: 'utf-8' }) ); - const mappings = tsConfig?.compilerOptions?.paths; - + const mappings = resolveWildcardsToPaths(tsConfig?.compilerOptions?.paths); if (!mappings) { return result; } @@ -58,3 +59,34 @@ export function getMappedPaths({ return result; } + +function resolveWildcardsToPaths(paths: { [key: string]: string[] }): { + [key: string]: string[]; +} { + let results = {}; + for (const key in paths) { + const path = paths[key][0]; + if (path.includes('*')) { + const entries = glob.sync(path, { unique: true }); + + for (const entry of entries) { + if (!entry.includes('index.ts') && !entry.includes('index.js')) { + continue; + } + + const capturedPath = mm.capture(path, entry); + if (!capturedPath) { + continue; + } + + results = { + ...results, + [key.replace('*', capturedPath[0])]: [entry], + }; + } + } else { + results = { ...results, [key]: [path] }; + } + } + return results; +} diff --git a/package-lock.json b/package-lock.json index 1e89c893..efdba8e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,10 @@ "@angular/platform-browser-dynamic": "17.1.2", "@angular/router": "17.1.2", "@module-federation/vite": "^0.2.6", + "@types/micromatch": "^4.0.7", "es-module-shims": "^1.5.12", + "fast-glob": "^3.3.2", + "micromatch": "^4.0.7", "rxjs": "^7.0.0", "tslib": "^2.0.0", "zone.js": "0.14.2" @@ -4955,7 +4958,6 @@ "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", - "dev": true, "dependencies": { "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" @@ -4968,7 +4970,6 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", - "dev": true, "engines": { "node": ">= 8" } @@ -4977,7 +4978,6 @@ "version": "1.2.8", "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", - "dev": true, "dependencies": { "@nodelib/fs.scandir": "2.1.5", "fastq": "^1.6.0" @@ -7597,6 +7597,11 @@ "@types/node": "*" } }, + "node_modules/@types/braces": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@types/braces/-/braces-3.0.4.tgz", + "integrity": "sha512-0WR3b8eaISjEW7RpZnclONaLFDf7buaowRHdqLp4vLj54AsSAYWfh3DRbfiYJY9XDxMgx1B4sE1Afw2PGpuHOA==" + }, "node_modules/@types/browser-sync": { "version": "2.29.0", "resolved": "https://registry.npmjs.org/@types/browser-sync/-/browser-sync-2.29.0.tgz", @@ -7609,6 +7614,15 @@ "chokidar": "^3.0.0" } }, + "node_modules/@types/browser-sync/node_modules/@types/micromatch": { + "version": "2.3.35", + "resolved": "https://registry.npmjs.org/@types/micromatch/-/micromatch-2.3.35.tgz", + "integrity": "sha512-J749bHo/Zu56w0G0NI/IGHLQPiSsjx//0zJhfEVAN95K/xM5C8ZDmhkXtU3qns0sBOao7HuQzr8XV1/2o5LbXA==", + "dev": true, + "dependencies": { + "@types/parse-glob": "*" + } + }, "node_modules/@types/cacheable-request": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.3.tgz", @@ -7823,12 +7837,11 @@ "dev": true }, "node_modules/@types/micromatch": { - "version": "2.3.35", - "resolved": "https://registry.npmjs.org/@types/micromatch/-/micromatch-2.3.35.tgz", - "integrity": "sha512-J749bHo/Zu56w0G0NI/IGHLQPiSsjx//0zJhfEVAN95K/xM5C8ZDmhkXtU3qns0sBOao7HuQzr8XV1/2o5LbXA==", - "dev": true, + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/@types/micromatch/-/micromatch-4.0.7.tgz", + "integrity": "sha512-C/FMQ8HJAZhTsDpl4wDKZdMeeW5USjgzOczUwTGbRc1ZopPgOhIEnxY2ZgUrsuyy4DwK1JVOJZKFakv3TbCKiA==", "dependencies": { - "@types/parse-glob": "*" + "@types/braces": "*" } }, "node_modules/@types/mime": { @@ -10315,12 +10328,11 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "dev": true, + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -14181,7 +14193,6 @@ "version": "3.3.2", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", - "dev": true, "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", @@ -14224,7 +14235,6 @@ "version": "1.17.1", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", "integrity": "sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==", - "dev": true, "dependencies": { "reusify": "^1.0.4" } @@ -14363,10 +14373,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -14961,7 +14970,6 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, "dependencies": { "is-glob": "^4.0.1" }, @@ -15959,7 +15967,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -15985,7 +15992,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "dev": true, "dependencies": { "is-extglob": "^2.1.1" }, @@ -16034,7 +16040,6 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true, "engines": { "node": ">=0.12.0" } @@ -19080,7 +19085,6 @@ "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", - "dev": true, "engines": { "node": ">= 8" } @@ -19095,12 +19099,11 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", - "dev": true, + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", + "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==", "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -19111,7 +19114,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, "engines": { "node": ">=8.6" }, @@ -22537,7 +22539,6 @@ "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", - "dev": true, "funding": [ { "type": "github", @@ -23027,7 +23028,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", - "dev": true, "engines": { "iojs": ">=1.0.0", "node": ">=0.10.0" @@ -23116,7 +23116,6 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", - "dev": true, "funding": [ { "type": "github", @@ -24794,7 +24793,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, "dependencies": { "is-number": "^7.0.0" }, diff --git a/package.json b/package.json index 8b152a18..f97a5a4e 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,10 @@ "@angular/platform-browser-dynamic": "17.1.2", "@angular/router": "17.1.2", "@module-federation/vite": "^0.2.6", + "@types/micromatch": "^4.0.7", "es-module-shims": "^1.5.12", + "fast-glob": "^3.3.2", + "micromatch": "^4.0.7", "rxjs": "^7.0.0", "tslib": "^2.0.0", "zone.js": "0.14.2" From fdac4630f76f1bfb602b34f4119bd120b31162a7 Mon Sep 17 00:00:00 2001 From: SteveVanOpstal Date: Fri, 7 Jun 2024 09:09:37 +0200 Subject: [PATCH 2/3] chore: move @types/micromatch to devDependencies --- package-lock.json | 6 ++++-- package.json | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index efdba8e1..1cd4edf2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,6 @@ "@angular/platform-browser-dynamic": "17.1.2", "@angular/router": "17.1.2", "@module-federation/vite": "^0.2.6", - "@types/micromatch": "^4.0.7", "es-module-shims": "^1.5.12", "fast-glob": "^3.3.2", "micromatch": "^4.0.7", @@ -59,6 +58,7 @@ "@types/browser-sync": "^2.29.0", "@types/cross-spawn": "^6.0.2", "@types/jest": "29.5.11", + "@types/micromatch": "^4.0.7", "@types/node": "^18.16.9", "@types/npmlog": "^4.1.4", "@typescript-eslint/eslint-plugin": "6.21.0", @@ -7600,7 +7600,8 @@ "node_modules/@types/braces": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/@types/braces/-/braces-3.0.4.tgz", - "integrity": "sha512-0WR3b8eaISjEW7RpZnclONaLFDf7buaowRHdqLp4vLj54AsSAYWfh3DRbfiYJY9XDxMgx1B4sE1Afw2PGpuHOA==" + "integrity": "sha512-0WR3b8eaISjEW7RpZnclONaLFDf7buaowRHdqLp4vLj54AsSAYWfh3DRbfiYJY9XDxMgx1B4sE1Afw2PGpuHOA==", + "dev": true }, "node_modules/@types/browser-sync": { "version": "2.29.0", @@ -7840,6 +7841,7 @@ "version": "4.0.7", "resolved": "https://registry.npmjs.org/@types/micromatch/-/micromatch-4.0.7.tgz", "integrity": "sha512-C/FMQ8HJAZhTsDpl4wDKZdMeeW5USjgzOczUwTGbRc1ZopPgOhIEnxY2ZgUrsuyy4DwK1JVOJZKFakv3TbCKiA==", + "dev": true, "dependencies": { "@types/braces": "*" } diff --git a/package.json b/package.json index f97a5a4e..ec5c7046 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "@angular/platform-browser-dynamic": "17.1.2", "@angular/router": "17.1.2", "@module-federation/vite": "^0.2.6", - "@types/micromatch": "^4.0.7", "es-module-shims": "^1.5.12", "fast-glob": "^3.3.2", "micromatch": "^4.0.7", @@ -85,6 +84,7 @@ "@types/browser-sync": "^2.29.0", "@types/cross-spawn": "^6.0.2", "@types/jest": "29.5.11", + "@types/micromatch": "^4.0.7", "@types/node": "^18.16.9", "@types/npmlog": "^4.1.4", "@typescript-eslint/eslint-plugin": "6.21.0", From bd15052b603b93680e8b73bac51de8298e34ce97 Mon Sep 17 00:00:00 2001 From: SteveVanOpstal Date: Fri, 7 Jun 2024 09:11:12 +0200 Subject: [PATCH 3/3] chore(core): add fast-glob and micromatch dependencies to core --- libs/native-federation-core/package.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/native-federation-core/package.json b/libs/native-federation-core/package.json index d2c8e795..39869ff0 100644 --- a/libs/native-federation-core/package.json +++ b/libs/native-federation-core/package.json @@ -5,6 +5,11 @@ "dependencies": { "json5": "^2.2.0", "npmlog": "^6.0.2", - "@softarc/native-federation-runtime": "2.0.9" + "@softarc/native-federation-runtime": "2.0.9", + "fast-glob": "^3.3.2", + "micromatch": "^4.0.7" + }, + "devDependencies": { + "@types/micromatch": "^4.0.7" } }