@module-federation/third-party-dts-extractor 2.6.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @module-federation/third-party-dts-extractor
2
2
 
3
+ ## 2.8.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 6ee67dc: Reduce installed and bundled size by replacing general-purpose cache, path, version, package lookup, scheduling, fetch, and error fallback dependencies with focused built-in utilities.
8
+
9
+ ## 2.7.0
10
+
11
+ ### Patch Changes
12
+
13
+ - 2add9ef: chore(third-party-dts-extractor): replace `resolve` with `exsolve` (0 transitive deps, ~100KB smaller) for the single `package.json` lookup.
14
+ - a5f123a: chore: replace `find-pkg` with `empathic` (per [e18e replacements](https://e18e.dev/docs/replacements/find-pkg.html)). Removes unused `find-pkg` dependency from `@module-federation/manifest`.
15
+ - 8ec950c: Bump runtime dependencies: echarts 6.1.0 (devtools), hono 4.12.26 and @hono/node-server 1.19.13 (treeshake-server), lodash-es 4.18.1 (rspress-plugin), handlebars 4.7.9 (create-module-federation), resolve 1.22.12 (third-party-dts-extractor).
16
+
3
17
  ## 2.6.0
4
18
 
5
19
  ## 2.5.1
@@ -16,5 +16,4 @@ declare class ThirdPartyExtractor {
16
16
  collectPkgs(str: string): void;
17
17
  copyDts(): Promise<void>;
18
18
  }
19
-
20
19
  export { ThirdPartyExtractor };
package/dist/index.d.ts CHANGED
@@ -1,20 +1 @@
1
- type ThirdPartyExtractorOptions = {
2
- destDir: string;
3
- context?: string;
4
- exclude?: Array<string | RegExp>;
5
- };
6
- declare class ThirdPartyExtractor {
7
- pkgs: Record<string, string>;
8
- pattern: RegExp;
9
- context: string;
10
- destDir: string;
11
- exclude: Array<string | RegExp>;
12
- constructor({ destDir, context, exclude, }: ThirdPartyExtractorOptions);
13
- addPkgs(pkgName: string, dirName: string): void;
14
- inferPkgDir(importPath: string): string | void;
15
- collectTypeImports(str: string): string[];
16
- collectPkgs(str: string): void;
17
- copyDts(): Promise<void>;
18
- }
19
-
20
- export { ThirdPartyExtractor };
1
+ export { ThirdPartyExtractor } from './ThirdPartyExtractor';
package/dist/index.js CHANGED
@@ -7,11 +7,9 @@
7
7
  });
8
8
 
9
9
  // src/ThirdPartyExtractor.ts
10
- var _findpkg = require('find-pkg'); var _findpkg2 = _interopRequireDefault(_findpkg);
11
10
  var _promises = require('fs/promises');
12
11
  var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
13
12
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
14
- var _resolve = require('resolve'); var _resolve2 = _interopRequireDefault(_resolve);
15
13
 
16
14
  // src/utils.ts
17
15
 
@@ -19,11 +17,11 @@ var _resolve = require('resolve'); var _resolve2 = _interopRequireDefault(_resol
19
17
  function getTypedName(name) {
20
18
  return `@types/${name.replace(/^@/, "").replace("/", "__")}`;
21
19
  }
22
- function getPackageRootDir(packageName) {
20
+ function getPackageRootDir(packageName, context = process.cwd()) {
23
21
  if (!packageName) {
24
22
  throw new Error("No package name provided.");
25
23
  }
26
- const entryFile = __require.resolve(packageName);
24
+ const entryFile = __require.resolve(packageName, { paths: [context] });
27
25
  const entryDir = _path2.default.dirname(entryFile);
28
26
  let fallbackPackageJsonPath = _path2.default.join(
29
27
  entryDir,
@@ -63,6 +61,31 @@ function getPackageRootDir(packageName) {
63
61
  `Could not find a matching package.json for "${packageName}" and no fallback was found.`
64
62
  );
65
63
  }
64
+ function resolvePackageJson(packageName, context) {
65
+ try {
66
+ return __require.resolve(`${packageName}/package.json`, {
67
+ paths: [context]
68
+ });
69
+ } catch (e) {
70
+ let currentPath = _path2.default.resolve(context);
71
+ while (true) {
72
+ const candidate = _path2.default.join(
73
+ currentPath,
74
+ "node_modules",
75
+ packageName,
76
+ "package.json"
77
+ );
78
+ if (_fs2.default.existsSync(candidate)) {
79
+ return candidate;
80
+ }
81
+ const parentPath = _path2.default.dirname(currentPath);
82
+ if (parentPath === currentPath) {
83
+ throw new Error(`Could not resolve package.json for "${packageName}".`);
84
+ }
85
+ currentPath = parentPath;
86
+ }
87
+ }
88
+ }
66
89
 
67
90
  // src/ThirdPartyExtractor.ts
68
91
  var ignoredPkgs = ["typescript"];
@@ -113,7 +136,7 @@ var ThirdPartyExtractor = class {
113
136
  if (isNodeUtils(importEntry, importPath)) {
114
137
  return;
115
138
  }
116
- const packageDir = getPackageRootDir(importPath);
139
+ const packageDir = getPackageRootDir(importPath, this.context);
117
140
  const pkgJsonPath = _path2.default.join(packageDir, "package.json");
118
141
  const dir = _path2.default.dirname(pkgJsonPath);
119
142
  const pkg = JSON.parse(_fs.readFileSync.call(void 0, pkgJsonPath, "utf-8"));
@@ -130,11 +153,7 @@ var ThirdPartyExtractor = class {
130
153
  return dir;
131
154
  } else {
132
155
  const typedPkgName = getTypedName(pkg.name);
133
- const typedPkgJsonPath = _findpkg2.default.sync(
134
- _resolve2.default.sync(`${typedPkgName}/package.json`, {
135
- basedir: this.context
136
- })
137
- );
156
+ const typedPkgJsonPath = resolvePackageJson(typedPkgName, this.context);
138
157
  const typedDir = _path2.default.dirname(typedPkgJsonPath);
139
158
  _fs.readFileSync.call(void 0, typedPkgJsonPath, "utf-8");
140
159
  this.addPkgs(typedPkgName, typedDir);
package/dist/index.mjs CHANGED
@@ -7,11 +7,9 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
7
7
  });
8
8
 
9
9
  // src/ThirdPartyExtractor.ts
10
- import findPkg from "find-pkg";
11
10
  import { copyFile, lstat, mkdir, readdir } from "fs/promises";
12
11
  import { existsSync, readFileSync } from "fs";
13
12
  import path2 from "path";
14
- import resolve from "resolve";
15
13
 
16
14
  // src/utils.ts
17
15
  import path from "path";
@@ -19,11 +17,11 @@ import fs from "fs";
19
17
  function getTypedName(name) {
20
18
  return `@types/${name.replace(/^@/, "").replace("/", "__")}`;
21
19
  }
22
- function getPackageRootDir(packageName) {
20
+ function getPackageRootDir(packageName, context = process.cwd()) {
23
21
  if (!packageName) {
24
22
  throw new Error("No package name provided.");
25
23
  }
26
- const entryFile = __require.resolve(packageName);
24
+ const entryFile = __require.resolve(packageName, { paths: [context] });
27
25
  const entryDir = path.dirname(entryFile);
28
26
  let fallbackPackageJsonPath = path.join(
29
27
  entryDir,
@@ -63,6 +61,31 @@ function getPackageRootDir(packageName) {
63
61
  `Could not find a matching package.json for "${packageName}" and no fallback was found.`
64
62
  );
65
63
  }
64
+ function resolvePackageJson(packageName, context) {
65
+ try {
66
+ return __require.resolve(`${packageName}/package.json`, {
67
+ paths: [context]
68
+ });
69
+ } catch (e) {
70
+ let currentPath = path.resolve(context);
71
+ while (true) {
72
+ const candidate = path.join(
73
+ currentPath,
74
+ "node_modules",
75
+ packageName,
76
+ "package.json"
77
+ );
78
+ if (fs.existsSync(candidate)) {
79
+ return candidate;
80
+ }
81
+ const parentPath = path.dirname(currentPath);
82
+ if (parentPath === currentPath) {
83
+ throw new Error(`Could not resolve package.json for "${packageName}".`);
84
+ }
85
+ currentPath = parentPath;
86
+ }
87
+ }
88
+ }
66
89
 
67
90
  // src/ThirdPartyExtractor.ts
68
91
  var ignoredPkgs = ["typescript"];
@@ -113,7 +136,7 @@ var ThirdPartyExtractor = class {
113
136
  if (isNodeUtils(importEntry, importPath)) {
114
137
  return;
115
138
  }
116
- const packageDir = getPackageRootDir(importPath);
139
+ const packageDir = getPackageRootDir(importPath, this.context);
117
140
  const pkgJsonPath = path2.join(packageDir, "package.json");
118
141
  const dir = path2.dirname(pkgJsonPath);
119
142
  const pkg = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
@@ -130,11 +153,7 @@ var ThirdPartyExtractor = class {
130
153
  return dir;
131
154
  } else {
132
155
  const typedPkgName = getTypedName(pkg.name);
133
- const typedPkgJsonPath = findPkg.sync(
134
- resolve.sync(`${typedPkgName}/package.json`, {
135
- basedir: this.context
136
- })
137
- );
156
+ const typedPkgJsonPath = resolvePackageJson(typedPkgName, this.context);
138
157
  const typedDir = path2.dirname(typedPkgJsonPath);
139
158
  readFileSync(typedPkgJsonPath, "utf-8");
140
159
  this.addPkgs(typedPkgName, typedDir);
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/third-party-dts-extractor",
3
- "version": "2.6.0",
3
+ "version": "2.8.0",
4
4
  "files": [
5
5
  "dist/",
6
6
  "README.md"
@@ -31,21 +31,18 @@
31
31
  "types": "./dist/index.d.ts",
32
32
  "author": "hanric <hanric.zhang@gmail.com>",
33
33
  "license": "MIT",
34
- "dependencies": {
35
- "find-pkg": "2.0.0",
36
- "resolve": "1.22.8"
37
- },
38
34
  "devDependencies": {
35
+ "@rstest/core": "^0.10.6",
39
36
  "@types/node": "^20.19.5",
40
37
  "@types/react": "^18.3.11",
41
- "vitest": "1.6.0",
42
38
  "react": "^18",
39
+ "typescript": "7.0.2",
43
40
  "tsup": "7.3.0"
44
41
  },
45
42
  "scripts": {
46
- "build": "tsup --config tsup.config.ts --outDir dist && cp package.json dist && cp *.md dist",
43
+ "build": "tsup --config tsup.config.ts --outDir dist && tsc -p tsconfig.lib.json && cp package.json dist && cp *.md dist",
47
44
  "lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\"",
48
- "test": "pnpm exec vitest run --passWithNoTests --config vite.config.mts",
45
+ "test": "pnpm exec rstest --passWithNoTests",
49
46
  "pre-release": "pnpm run test && pnpm run build"
50
47
  }
51
48
  }
@@ -0,0 +1,14 @@
1
+ declare function getTypedName(name: string): string;
2
+ /**
3
+ * Locates the directory of the package.json for the given packageName.
4
+ * 1. Resolves the entry file via require.resolve().
5
+ * 2. Looks for package.json in that same directory (fallback).
6
+ * 3. Climb upward until the folder name matches localName
7
+ * (the part after a scope slash, e.g. "@scope/sdk" => "sdk").
8
+ * 4. If that folder's package.json has "name" === packageName, return that directory.
9
+ * 5. Otherwise, return the fallback directory (if it contains a package.json).
10
+ * 6. If all else fails, throw an error.
11
+ */
12
+ declare function getPackageRootDir(packageName: string | undefined, context?: string): string;
13
+ declare function resolvePackageJson(packageName: string, context: string): string;
14
+ export { getTypedName, getPackageRootDir, resolvePackageJson };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/third-party-dts-extractor",
3
- "version": "2.6.0",
3
+ "version": "2.8.0",
4
4
  "files": [
5
5
  "dist/",
6
6
  "README.md"
@@ -31,21 +31,18 @@
31
31
  "types": "./dist/index.d.ts",
32
32
  "author": "hanric <hanric.zhang@gmail.com>",
33
33
  "license": "MIT",
34
- "dependencies": {
35
- "find-pkg": "2.0.0",
36
- "resolve": "1.22.8"
37
- },
38
34
  "devDependencies": {
35
+ "@rstest/core": "^0.10.6",
39
36
  "@types/node": "^20.19.5",
40
37
  "@types/react": "^18.3.11",
41
- "vitest": "1.6.0",
42
38
  "react": "^18",
39
+ "typescript": "7.0.2",
43
40
  "tsup": "7.3.0"
44
41
  },
45
42
  "scripts": {
46
- "build": "tsup --config tsup.config.ts --outDir dist && cp package.json dist && cp *.md dist",
43
+ "build": "tsup --config tsup.config.ts --outDir dist && tsc -p tsconfig.lib.json && cp package.json dist && cp *.md dist",
47
44
  "lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\"",
48
- "test": "pnpm exec vitest run --passWithNoTests --config vite.config.mts",
45
+ "test": "pnpm exec rstest --passWithNoTests",
49
46
  "pre-release": "pnpm run test && pnpm run build"
50
47
  }
51
48
  }