@module-federation/third-party-dts-extractor 0.13.0 → 0.13.1

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,11 @@
1
1
  # @module-federation/third-party-dts-extractor
2
2
 
3
+ ## 0.13.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 723d0f8: fix(third-party-dts-extractor): correctly sets the source of the package types
8
+
3
9
  ## 0.13.0
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -13,9 +13,55 @@ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
13
13
  var _resolve = require('resolve'); var _resolve2 = _interopRequireDefault(_resolve);
14
14
 
15
15
  // packages/third-party-dts-extractor/src/utils.ts
16
+
17
+ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
16
18
  function getTypedName(name) {
17
19
  return `@types/${name.replace(/^@/, "").replace("/", "__")}`;
18
20
  }
21
+ function getPackageRootDir(packageName) {
22
+ if (!packageName) {
23
+ throw new Error("No package name provided.");
24
+ }
25
+ const entryFile = __require.resolve(packageName);
26
+ const entryDir = _path2.default.dirname(entryFile);
27
+ let fallbackPackageJsonPath = _path2.default.join(
28
+ entryDir,
29
+ "package.json"
30
+ );
31
+ if (!_fs2.default.existsSync(fallbackPackageJsonPath)) {
32
+ fallbackPackageJsonPath = null;
33
+ }
34
+ const match = packageName.match(/^@[^/]+\/(.+)$/);
35
+ const localName = match ? match[1] : packageName;
36
+ let currentDir = entryDir;
37
+ while (_path2.default.basename(currentDir) !== localName && // Keep going if names differ
38
+ _path2.default.dirname(currentDir) !== currentDir) {
39
+ try {
40
+ currentDir = _path2.default.dirname(currentDir);
41
+ } catch (err) {
42
+ if (err.code === "EACCES") {
43
+ continue;
44
+ } else {
45
+ throw err;
46
+ }
47
+ }
48
+ }
49
+ if (_path2.default.basename(currentDir) === localName) {
50
+ const candidate = _path2.default.join(currentDir, "package.json");
51
+ if (_fs2.default.existsSync(candidate)) {
52
+ const pkgContent = JSON.parse(_fs2.default.readFileSync(candidate, "utf8"));
53
+ if (pkgContent.name === packageName) {
54
+ return currentDir;
55
+ }
56
+ }
57
+ }
58
+ if (fallbackPackageJsonPath) {
59
+ return entryDir;
60
+ }
61
+ throw new Error(
62
+ `Could not find a matching package.json for "${packageName}" and no fallback was found.`
63
+ );
64
+ }
19
65
 
20
66
  // packages/third-party-dts-extractor/src/ThirdPartyExtractor.ts
21
67
  var ignoredPkgs = ["typescript"];
@@ -66,7 +112,8 @@ var ThirdPartyExtractor = class {
66
112
  if (isNodeUtils(importEntry, importPath)) {
67
113
  return;
68
114
  }
69
- const pkgJsonPath = _findpkg2.default.sync(importEntry);
115
+ const packageDir = getPackageRootDir(importPath);
116
+ const pkgJsonPath = _path2.default.join(packageDir, "package.json");
70
117
  const dir = _path2.default.dirname(pkgJsonPath);
71
118
  const pkg = JSON.parse(_fsextra2.default.readFileSync(pkgJsonPath, "utf-8"));
72
119
  const types = pkg.types || pkg.typings;
@@ -74,8 +121,9 @@ var ThirdPartyExtractor = class {
74
121
  return;
75
122
  }
76
123
  if (types) {
77
- this.addPkgs(pkg.name, dir);
78
- return dir;
124
+ const typesDir = _path2.default.dirname(_path2.default.resolve(dir, types));
125
+ this.addPkgs(pkg.name, typesDir);
126
+ return typesDir;
79
127
  } else if (_fsextra2.default.existsSync(_path2.default.resolve(dir, "index.d.ts"))) {
80
128
  this.addPkgs(pkg.name, dir);
81
129
  return dir;
package/dist/index.mjs CHANGED
@@ -8,14 +8,60 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
8
8
 
9
9
  // packages/third-party-dts-extractor/src/ThirdPartyExtractor.ts
10
10
  import findPkg from "find-pkg";
11
- import fs from "fs-extra";
12
- import path from "path";
11
+ import fs2 from "fs-extra";
12
+ import path2 from "path";
13
13
  import resolve from "resolve";
14
14
 
15
15
  // packages/third-party-dts-extractor/src/utils.ts
16
+ import path from "node:path";
17
+ import fs from "node:fs";
16
18
  function getTypedName(name) {
17
19
  return `@types/${name.replace(/^@/, "").replace("/", "__")}`;
18
20
  }
21
+ function getPackageRootDir(packageName) {
22
+ if (!packageName) {
23
+ throw new Error("No package name provided.");
24
+ }
25
+ const entryFile = __require.resolve(packageName);
26
+ const entryDir = path.dirname(entryFile);
27
+ let fallbackPackageJsonPath = path.join(
28
+ entryDir,
29
+ "package.json"
30
+ );
31
+ if (!fs.existsSync(fallbackPackageJsonPath)) {
32
+ fallbackPackageJsonPath = null;
33
+ }
34
+ const match = packageName.match(/^@[^/]+\/(.+)$/);
35
+ const localName = match ? match[1] : packageName;
36
+ let currentDir = entryDir;
37
+ while (path.basename(currentDir) !== localName && // Keep going if names differ
38
+ path.dirname(currentDir) !== currentDir) {
39
+ try {
40
+ currentDir = path.dirname(currentDir);
41
+ } catch (err) {
42
+ if (err.code === "EACCES") {
43
+ continue;
44
+ } else {
45
+ throw err;
46
+ }
47
+ }
48
+ }
49
+ if (path.basename(currentDir) === localName) {
50
+ const candidate = path.join(currentDir, "package.json");
51
+ if (fs.existsSync(candidate)) {
52
+ const pkgContent = JSON.parse(fs.readFileSync(candidate, "utf8"));
53
+ if (pkgContent.name === packageName) {
54
+ return currentDir;
55
+ }
56
+ }
57
+ }
58
+ if (fallbackPackageJsonPath) {
59
+ return entryDir;
60
+ }
61
+ throw new Error(
62
+ `Could not find a matching package.json for "${packageName}" and no fallback was found.`
63
+ );
64
+ }
19
65
 
20
66
  // packages/third-party-dts-extractor/src/ThirdPartyExtractor.ts
21
67
  var ignoredPkgs = ["typescript"];
@@ -53,7 +99,7 @@ var ThirdPartyExtractor = class {
53
99
  if (this.pkgs[importPath]) {
54
100
  return;
55
101
  }
56
- if (path.isAbsolute(importPath)) {
102
+ if (path2.isAbsolute(importPath)) {
57
103
  return;
58
104
  }
59
105
  if (importPath.startsWith(".")) {
@@ -66,17 +112,19 @@ var ThirdPartyExtractor = class {
66
112
  if (isNodeUtils(importEntry, importPath)) {
67
113
  return;
68
114
  }
69
- const pkgJsonPath = findPkg.sync(importEntry);
70
- const dir = path.dirname(pkgJsonPath);
71
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
115
+ const packageDir = getPackageRootDir(importPath);
116
+ const pkgJsonPath = path2.join(packageDir, "package.json");
117
+ const dir = path2.dirname(pkgJsonPath);
118
+ const pkg = JSON.parse(fs2.readFileSync(pkgJsonPath, "utf-8"));
72
119
  const types = pkg.types || pkg.typings;
73
120
  if (dir === this.context) {
74
121
  return;
75
122
  }
76
123
  if (types) {
77
- this.addPkgs(pkg.name, dir);
78
- return dir;
79
- } else if (fs.existsSync(path.resolve(dir, "index.d.ts"))) {
124
+ const typesDir = path2.dirname(path2.resolve(dir, types));
125
+ this.addPkgs(pkg.name, typesDir);
126
+ return typesDir;
127
+ } else if (fs2.existsSync(path2.resolve(dir, "index.d.ts"))) {
80
128
  this.addPkgs(pkg.name, dir);
81
129
  return dir;
82
130
  } else {
@@ -86,8 +134,8 @@ var ThirdPartyExtractor = class {
86
134
  basedir: this.context
87
135
  })
88
136
  );
89
- const typedDir = path.dirname(typedPkgJsonPath);
90
- fs.readFileSync(typedPkgJsonPath, "utf-8");
137
+ const typedDir = path2.dirname(typedPkgJsonPath);
138
+ fs2.readFileSync(typedPkgJsonPath, "utf-8");
91
139
  this.addPkgs(typedPkgName, typedDir);
92
140
  return typedDir;
93
141
  }
@@ -116,7 +164,7 @@ var ThirdPartyExtractor = class {
116
164
  }
117
165
  const ensureDir = async (dir) => {
118
166
  try {
119
- await fs.mkdir(dir, { recursive: true });
167
+ await fs2.mkdir(dir, { recursive: true });
120
168
  } catch (err) {
121
169
  if (err.code !== "EEXIST")
122
170
  throw err;
@@ -126,21 +174,21 @@ var ThirdPartyExtractor = class {
126
174
  if (srcDir.startsWith(".")) {
127
175
  return;
128
176
  }
129
- const files = await fs.readdir(srcDir);
177
+ const files = await fs2.readdir(srcDir);
130
178
  await Promise.all(
131
179
  files.map(async (file) => {
132
- const fullPath = path.join(srcDir, file);
180
+ const fullPath = path2.join(srcDir, file);
133
181
  if (["node_modules", "bin"].includes(file)) {
134
182
  return;
135
183
  }
136
- const stats = await fs.lstat(fullPath);
184
+ const stats = await fs2.lstat(fullPath);
137
185
  if (stats.isDirectory()) {
138
- const destFullPath = path.join(destDir, file);
186
+ const destFullPath = path2.join(destDir, file);
139
187
  await ensureDir(destFullPath);
140
188
  await copyFiles(fullPath, destFullPath);
141
189
  } else {
142
190
  if (fullPath.endsWith(".d.ts") || fullPath.endsWith("package.json")) {
143
- await fs.copyFile(fullPath, path.join(destDir, file));
191
+ await fs2.copyFile(fullPath, path2.join(destDir, file));
144
192
  }
145
193
  }
146
194
  })
@@ -150,7 +198,7 @@ var ThirdPartyExtractor = class {
150
198
  await Promise.all(
151
199
  Object.keys(this.pkgs).map(async (pkgName) => {
152
200
  const pkgDir = this.pkgs[pkgName];
153
- const destDir = path.resolve(this.destDir, pkgName);
201
+ const destDir = path2.resolve(this.destDir, pkgName);
154
202
  await ensureDir(destDir);
155
203
  await copyFiles(pkgDir, destDir);
156
204
  })
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/third-party-dts-extractor",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "files": [
5
5
  "dist/",
6
6
  "README.md"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/third-party-dts-extractor",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "files": [
5
5
  "dist/",
6
6
  "README.md"