Skip to content

Commit 0de1c83

Browse files
authored
fix: no collect node internal utils (#2787)
1 parent bc245f2 commit 0de1c83

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

.changeset/little-snakes-fail.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@module-federation/third-party-dts-extractor': patch
3+
'@module-federation/dts-plugin': patch
4+
---
5+
6+
fix: do not collect node internal utils

packages/dts-plugin/tests/setup.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
import { rmSync } from 'fs';
21
import path from 'path';
2+
import { rmSync } from 'fs';
33

4-
const TEMP_TS_CONFIG_DIR = path.resolve(__dirname, 'node_modules/.federation');
4+
const TEMP_TS_CONFIG_DIR = path.resolve(
5+
__dirname,
6+
'../node_modules/.federation',
7+
);
58
try {
69
rmSync(TEMP_TS_CONFIG_DIR, { recursive: true });
710
} catch (err) {
811
// noop
912
}
13+
const TEMP_DIST = path.resolve(__dirname, '../dist-test');
14+
try {
15+
rmSync(TEMP_DIST, { recursive: true });
16+
} catch (err) {
17+
// noop
18+
}

packages/dts-plugin/vite.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="vitest" />
22
import { defineConfig } from 'vite';
3-
import path from 'path';
3+
import './tests/setup';
44

55
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
66

@@ -20,6 +20,5 @@ export default defineConfig({
2020
],
2121
reporters: ['default'],
2222
testTimeout: 60000,
23-
setupFiles: [path.resolve(__dirname, './tests/setup.ts')],
2423
},
2524
});

packages/third-party-dts-extractor/src/ThirdPartyExtractor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { getTypedName } from './utils';
66

77
const ignoredPkgs = ['typescript'];
88

9+
// require.resolve('path')==='path'
10+
const isNodeUtils = (pkgJsonPath: string, importPath: string) => {
11+
return pkgJsonPath === importPath;
12+
};
913
class ThirdPartyExtractor {
1014
pkgs: Record<string, string>;
1115
pattern: RegExp;
@@ -41,6 +45,9 @@ class ThirdPartyExtractor {
4145
const pkgJsonPath = findPkg.sync(
4246
require.resolve(importPath, { paths: [this.context] }),
4347
) as string;
48+
if (isNodeUtils(pkgJsonPath, importPath)) {
49+
return;
50+
}
4451
const dir = path.dirname(pkgJsonPath);
4552
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8')) as Record<
4653
string,

0 commit comments

Comments
 (0)