diff --git a/.changeset/little-snakes-fail.md b/.changeset/little-snakes-fail.md new file mode 100644 index 00000000000..3869729dcba --- /dev/null +++ b/.changeset/little-snakes-fail.md @@ -0,0 +1,6 @@ +--- +'@module-federation/third-party-dts-extractor': patch +'@module-federation/dts-plugin': patch +--- + +fix: do not collect node internal utils diff --git a/packages/dts-plugin/tests/setup.ts b/packages/dts-plugin/tests/setup.ts index c13e5bb7671..de4a0b39f83 100644 --- a/packages/dts-plugin/tests/setup.ts +++ b/packages/dts-plugin/tests/setup.ts @@ -1,9 +1,18 @@ -import { rmSync } from 'fs'; import path from 'path'; +import { rmSync } from 'fs'; -const TEMP_TS_CONFIG_DIR = path.resolve(__dirname, 'node_modules/.federation'); +const TEMP_TS_CONFIG_DIR = path.resolve( + __dirname, + '../node_modules/.federation', +); try { rmSync(TEMP_TS_CONFIG_DIR, { recursive: true }); } catch (err) { // noop } +const TEMP_DIST = path.resolve(__dirname, '../dist-test'); +try { + rmSync(TEMP_DIST, { recursive: true }); +} catch (err) { + // noop +} diff --git a/packages/dts-plugin/vite.config.ts b/packages/dts-plugin/vite.config.ts index a48e17283b3..43b343965ef 100644 --- a/packages/dts-plugin/vite.config.ts +++ b/packages/dts-plugin/vite.config.ts @@ -1,6 +1,6 @@ /// import { defineConfig } from 'vite'; -import path from 'path'; +import './tests/setup'; import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; @@ -20,6 +20,5 @@ export default defineConfig({ ], reporters: ['default'], testTimeout: 60000, - setupFiles: [path.resolve(__dirname, './tests/setup.ts')], }, }); diff --git a/packages/third-party-dts-extractor/src/ThirdPartyExtractor.ts b/packages/third-party-dts-extractor/src/ThirdPartyExtractor.ts index 4b2b7fbcf24..309e4d875db 100644 --- a/packages/third-party-dts-extractor/src/ThirdPartyExtractor.ts +++ b/packages/third-party-dts-extractor/src/ThirdPartyExtractor.ts @@ -6,6 +6,10 @@ import { getTypedName } from './utils'; const ignoredPkgs = ['typescript']; +// require.resolve('path')==='path' +const isNodeUtils = (pkgJsonPath: string, importPath: string) => { + return pkgJsonPath === importPath; +}; class ThirdPartyExtractor { pkgs: Record; pattern: RegExp; @@ -41,6 +45,9 @@ class ThirdPartyExtractor { const pkgJsonPath = findPkg.sync( require.resolve(importPath, { paths: [this.context] }), ) as string; + if (isNodeUtils(pkgJsonPath, importPath)) { + return; + } const dir = path.dirname(pkgJsonPath); const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8')) as Record< string,