Project Init

This commit is contained in:
Muluhabt
2026-05-29 15:23:46 +03:00
commit 2fbc557aac
67387 changed files with 6063341 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024-present zhanghang(2heal1)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1 @@
# @module-federation/third-party-dts-extractor

View File

@@ -0,0 +1,305 @@
# @module-federation/third-party-dts-extractor
## 2.5.0
## 2.4.0
## 2.3.3
## 2.3.2
## 2.3.1
## 2.3.0
## 2.2.3
## 2.2.2
## 2.2.1
## 2.2.0
## 2.1.0
## 2.0.1
## 2.0.0
## 0.24.1
## 0.24.0
## 0.23.0
## 0.22.1
## 0.22.0
## 0.21.6
## 0.21.5
## 0.21.4
## 0.21.3
## 0.21.2
## 0.21.1
## 0.21.0
## 0.20.0
## 0.19.1
## 0.19.0
## 0.18.4
## 0.18.3
## 0.18.2
## 0.18.1
## 0.18.0
## 0.17.1
### Patch Changes
- a7cf276: chore: upgrade NX to 21.2.3, Storybook to 9.0.9, and TypeScript to 5.8.3
- Upgraded NX from 21.0.3 to 21.2.3 with workspace configuration updates
- Migrated Storybook from 8.3.5 to 9.0.9 with updated configurations and automigrations
- Upgraded TypeScript from 5.7.3 to 5.8.3 with compatibility fixes
- Fixed package exports and type declaration paths across all packages
- Resolved module resolution issues and TypeScript compatibility problems
- Updated build configurations and dependencies to support latest versions
- d31a326: refactor: sink React packages from root to individual packages
- Removed React dependencies from root package.json and moved them to packages that actually need them
- Fixed rsbuild-plugin configuration to match workspace patterns
- Updated tests to handle platform-specific files
- This change improves dependency management by ensuring packages only have the dependencies they actually use
## 0.17.0
## 0.16.0
## 0.15.0
## 0.14.3
## 0.14.2
## 0.14.1
## 0.14.0
## 0.13.1
### Patch Changes
- 723d0f8: fix(third-party-dts-extractor): correctly sets the source of the package types
## 0.13.0
### Patch Changes
- 38f324f: Disable live bindings on cjs builds of the runtime packages
## 0.12.0
### Patch Changes
- ef96c4d: feat(dts-plugin): support exclude extract specify third party dts
## 0.11.4
## 0.11.3
## 0.11.2
## 0.11.1
## 0.11.0
## 0.10.0
## 0.9.1
## 0.9.0
## 0.8.12
## 0.8.11
## 0.8.10
## 0.8.9
## 0.8.8
## 0.8.7
## 0.8.6
## 0.8.5
## 0.8.4
## 0.8.3
## 0.8.2
## 0.8.1
## 0.8.0
## 0.7.7
## 0.7.6
## 0.7.5
## 0.7.4
## 0.7.3
## 0.7.2
## 0.7.1
## 0.7.0
## 0.6.16
## 0.6.15
## 0.6.14
## 0.6.13
## 0.6.12
## 0.6.11
## 0.6.10
## 0.6.9
## 0.6.8
## 0.6.7
## 0.6.6
## 0.6.5
## 0.6.4
## 0.6.3
## 0.6.2
## 0.6.1
## 0.6.0
## 0.5.2
## 0.5.1
## 0.5.0
## 0.4.0
## 0.3.5
## 0.3.4
## 0.3.3
## 0.3.2
### Patch Changes
- 0de1c83: fix: do not collect node internal utils
## 0.3.1
## 0.3.0
## 0.2.8
## 0.2.7
### Patch Changes
- b00ef13: fix(dts-plugin): support compile vue@3 dts
## 0.2.6
## 0.2.5
## 0.2.4
## 0.2.3
## 0.2.2
## 0.2.1
## 0.2.0
## 0.1.21
## 0.1.20
### Patch Changes
- 685c607: feat: support dynamic remote type hints
## 0.1.19
## 0.1.18
## 0.1.17
## 0.1.16
## 0.1.15
## 0.1.14
## 0.1.13
### Patch Changes
- 677958c: fix: tsup configuration
## 0.1.12
## 0.1.11
## 0.1.10
## 0.1.9
## 0.1.8
## 0.1.7
## 0.1.6
### Patch Changes
- 72c7b80: chore: fix release tag
## 0.0.18
### Patch Changes
- c8c0ad2: feat: enhance type capability

View File

@@ -0,0 +1 @@
# @module-federation/third-party-dts-extractor

View File

@@ -0,0 +1,20 @@
type ThirdPartyExtractorOptions = {
destDir: string;
context?: string;
exclude?: Array<string | RegExp>;
};
declare class ThirdPartyExtractor {
pkgs: Record<string, string>;
pattern: RegExp;
context: string;
destDir: string;
exclude: Array<string | RegExp>;
constructor({ destDir, context, exclude, }: ThirdPartyExtractorOptions);
addPkgs(pkgName: string, dirName: string): void;
inferPkgDir(importPath: string): string | void;
collectTypeImports(str: string): string[];
collectPkgs(str: string): void;
copyDts(): Promise<void>;
}
export { ThirdPartyExtractor };

View File

@@ -0,0 +1,20 @@
type ThirdPartyExtractorOptions = {
destDir: string;
context?: string;
exclude?: Array<string | RegExp>;
};
declare class ThirdPartyExtractor {
pkgs: Record<string, string>;
pattern: RegExp;
context: string;
destDir: string;
exclude: Array<string | RegExp>;
constructor({ destDir, context, exclude, }: ThirdPartyExtractorOptions);
addPkgs(pkgName: string, dirName: string): void;
inferPkgDir(importPath: string): string | void;
collectTypeImports(str: string): string[];
collectPkgs(str: string): void;
copyDts(): Promise<void>;
}
export { ThirdPartyExtractor };

View File

@@ -0,0 +1,204 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined")
return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
// src/ThirdPartyExtractor.ts
var _findpkg = require('find-pkg'); var _findpkg2 = _interopRequireDefault(_findpkg);
var _promises = require('fs/promises');
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
var _resolve = require('resolve'); var _resolve2 = _interopRequireDefault(_resolve);
// src/utils.ts
function getTypedName(name) {
return `@types/${name.replace(/^@/, "").replace("/", "__")}`;
}
function getPackageRootDir(packageName) {
if (!packageName) {
throw new Error("No package name provided.");
}
const entryFile = __require.resolve(packageName);
const entryDir = _path2.default.dirname(entryFile);
let fallbackPackageJsonPath = _path2.default.join(
entryDir,
"package.json"
);
if (!_fs2.default.existsSync(fallbackPackageJsonPath)) {
fallbackPackageJsonPath = null;
}
const match = packageName.match(/^@[^/]+\/(.+)$/);
const localName = match ? match[1] : packageName;
let currentDir = entryDir;
while (_path2.default.basename(currentDir) !== localName && // Keep going if names differ
_path2.default.dirname(currentDir) !== currentDir) {
try {
currentDir = _path2.default.dirname(currentDir);
} catch (err) {
if (err.code === "EACCES") {
continue;
} else {
throw err;
}
}
}
if (_path2.default.basename(currentDir) === localName) {
const candidate = _path2.default.join(currentDir, "package.json");
if (_fs2.default.existsSync(candidate)) {
const pkgContent = JSON.parse(_fs2.default.readFileSync(candidate, "utf8"));
if (pkgContent.name === packageName) {
return currentDir;
}
}
}
if (fallbackPackageJsonPath) {
return entryDir;
}
throw new Error(
`Could not find a matching package.json for "${packageName}" and no fallback was found.`
);
}
// src/ThirdPartyExtractor.ts
var ignoredPkgs = ["typescript"];
var isNodeUtils = (pkgJsonPath, importPath) => {
return pkgJsonPath === importPath;
};
var ThirdPartyExtractor = class {
constructor({
destDir,
context = process.cwd(),
exclude = []
}) {
this.destDir = destDir;
this.context = context;
this.pkgs = {};
this.pattern = /(from|import\()\s*['"]([^'"]+)['"]/g;
this.exclude = exclude;
}
addPkgs(pkgName, dirName) {
if (ignoredPkgs.includes(pkgName)) {
return;
}
if (this.exclude.some((pattern) => {
if (typeof pattern === "string") {
return new RegExp(pattern).test(pkgName);
} else {
return pattern.test(pkgName);
}
})) {
return;
}
this.pkgs[pkgName] = dirName;
}
inferPkgDir(importPath) {
if (this.pkgs[importPath]) {
return;
}
if (_path2.default.isAbsolute(importPath)) {
return;
}
if (importPath.startsWith(".")) {
return;
}
try {
const importEntry = __require.resolve(importPath, {
paths: [this.context]
});
if (isNodeUtils(importEntry, importPath)) {
return;
}
const packageDir = getPackageRootDir(importPath);
const pkgJsonPath = _path2.default.join(packageDir, "package.json");
const dir = _path2.default.dirname(pkgJsonPath);
const pkg = JSON.parse(_fs.readFileSync.call(void 0, pkgJsonPath, "utf-8"));
const types = pkg.types || pkg.typings;
if (dir === this.context) {
return;
}
if (types) {
const typesDir = _path2.default.dirname(_path2.default.resolve(dir, types));
this.addPkgs(pkg.name, typesDir);
return typesDir;
} else if (_fs.existsSync.call(void 0, _path2.default.resolve(dir, "index.d.ts"))) {
this.addPkgs(pkg.name, dir);
return dir;
} else {
const typedPkgName = getTypedName(pkg.name);
const typedPkgJsonPath = _findpkg2.default.sync(
_resolve2.default.sync(`${typedPkgName}/package.json`, {
basedir: this.context
})
);
const typedDir = _path2.default.dirname(typedPkgJsonPath);
_fs.readFileSync.call(void 0, typedPkgJsonPath, "utf-8");
this.addPkgs(typedPkgName, typedDir);
return typedDir;
}
} catch (_err) {
return;
}
}
collectTypeImports(str) {
const { pattern } = this;
let match;
const imports = /* @__PURE__ */ new Set();
while ((match = pattern.exec(str)) !== null) {
imports.add(match[2]);
}
return [...imports];
}
collectPkgs(str) {
const imports = this.collectTypeImports(str);
imports.forEach((importPath) => {
this.inferPkgDir(importPath);
});
}
async copyDts() {
if (!Object.keys(this.pkgs).length) {
return;
}
const ensureDir = async (dir) => _promises.mkdir.call(void 0, dir, { recursive: true });
const copyFiles = async (srcDir, destDir) => {
if (srcDir.startsWith(".")) {
return;
}
const files = await _promises.readdir.call(void 0, srcDir);
await Promise.all(
files.map(async (file) => {
const fullPath = _path2.default.join(srcDir, file);
if (["node_modules", "bin"].includes(file)) {
return;
}
const stats = await _promises.lstat.call(void 0, fullPath);
if (stats.isDirectory()) {
const destFullPath = _path2.default.join(destDir, file);
await ensureDir(destFullPath);
await copyFiles(fullPath, destFullPath);
} else {
if (fullPath.endsWith(".d.ts") || fullPath.endsWith("package.json")) {
await _promises.copyFile.call(void 0, fullPath, _path2.default.join(destDir, file));
}
}
})
);
};
await ensureDir(this.destDir);
await Promise.all(
Object.keys(this.pkgs).map(async (pkgName) => {
const pkgDir = this.pkgs[pkgName];
const destDir = _path2.default.resolve(this.destDir, pkgName);
await ensureDir(destDir);
await copyFiles(pkgDir, destDir);
})
);
}
};
exports.ThirdPartyExtractor = ThirdPartyExtractor;

View File

@@ -0,0 +1,204 @@
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined")
return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
// src/ThirdPartyExtractor.ts
import findPkg from "find-pkg";
import { copyFile, lstat, mkdir, readdir } from "fs/promises";
import { existsSync, readFileSync } from "fs";
import path2 from "path";
import resolve from "resolve";
// src/utils.ts
import path from "path";
import fs from "fs";
function getTypedName(name) {
return `@types/${name.replace(/^@/, "").replace("/", "__")}`;
}
function getPackageRootDir(packageName) {
if (!packageName) {
throw new Error("No package name provided.");
}
const entryFile = __require.resolve(packageName);
const entryDir = path.dirname(entryFile);
let fallbackPackageJsonPath = path.join(
entryDir,
"package.json"
);
if (!fs.existsSync(fallbackPackageJsonPath)) {
fallbackPackageJsonPath = null;
}
const match = packageName.match(/^@[^/]+\/(.+)$/);
const localName = match ? match[1] : packageName;
let currentDir = entryDir;
while (path.basename(currentDir) !== localName && // Keep going if names differ
path.dirname(currentDir) !== currentDir) {
try {
currentDir = path.dirname(currentDir);
} catch (err) {
if (err.code === "EACCES") {
continue;
} else {
throw err;
}
}
}
if (path.basename(currentDir) === localName) {
const candidate = path.join(currentDir, "package.json");
if (fs.existsSync(candidate)) {
const pkgContent = JSON.parse(fs.readFileSync(candidate, "utf8"));
if (pkgContent.name === packageName) {
return currentDir;
}
}
}
if (fallbackPackageJsonPath) {
return entryDir;
}
throw new Error(
`Could not find a matching package.json for "${packageName}" and no fallback was found.`
);
}
// src/ThirdPartyExtractor.ts
var ignoredPkgs = ["typescript"];
var isNodeUtils = (pkgJsonPath, importPath) => {
return pkgJsonPath === importPath;
};
var ThirdPartyExtractor = class {
constructor({
destDir,
context = process.cwd(),
exclude = []
}) {
this.destDir = destDir;
this.context = context;
this.pkgs = {};
this.pattern = /(from|import\()\s*['"]([^'"]+)['"]/g;
this.exclude = exclude;
}
addPkgs(pkgName, dirName) {
if (ignoredPkgs.includes(pkgName)) {
return;
}
if (this.exclude.some((pattern) => {
if (typeof pattern === "string") {
return new RegExp(pattern).test(pkgName);
} else {
return pattern.test(pkgName);
}
})) {
return;
}
this.pkgs[pkgName] = dirName;
}
inferPkgDir(importPath) {
if (this.pkgs[importPath]) {
return;
}
if (path2.isAbsolute(importPath)) {
return;
}
if (importPath.startsWith(".")) {
return;
}
try {
const importEntry = __require.resolve(importPath, {
paths: [this.context]
});
if (isNodeUtils(importEntry, importPath)) {
return;
}
const packageDir = getPackageRootDir(importPath);
const pkgJsonPath = path2.join(packageDir, "package.json");
const dir = path2.dirname(pkgJsonPath);
const pkg = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
const types = pkg.types || pkg.typings;
if (dir === this.context) {
return;
}
if (types) {
const typesDir = path2.dirname(path2.resolve(dir, types));
this.addPkgs(pkg.name, typesDir);
return typesDir;
} else if (existsSync(path2.resolve(dir, "index.d.ts"))) {
this.addPkgs(pkg.name, dir);
return dir;
} else {
const typedPkgName = getTypedName(pkg.name);
const typedPkgJsonPath = findPkg.sync(
resolve.sync(`${typedPkgName}/package.json`, {
basedir: this.context
})
);
const typedDir = path2.dirname(typedPkgJsonPath);
readFileSync(typedPkgJsonPath, "utf-8");
this.addPkgs(typedPkgName, typedDir);
return typedDir;
}
} catch (_err) {
return;
}
}
collectTypeImports(str) {
const { pattern } = this;
let match;
const imports = /* @__PURE__ */ new Set();
while ((match = pattern.exec(str)) !== null) {
imports.add(match[2]);
}
return [...imports];
}
collectPkgs(str) {
const imports = this.collectTypeImports(str);
imports.forEach((importPath) => {
this.inferPkgDir(importPath);
});
}
async copyDts() {
if (!Object.keys(this.pkgs).length) {
return;
}
const ensureDir = async (dir) => mkdir(dir, { recursive: true });
const copyFiles = async (srcDir, destDir) => {
if (srcDir.startsWith(".")) {
return;
}
const files = await readdir(srcDir);
await Promise.all(
files.map(async (file) => {
const fullPath = path2.join(srcDir, file);
if (["node_modules", "bin"].includes(file)) {
return;
}
const stats = await lstat(fullPath);
if (stats.isDirectory()) {
const destFullPath = path2.join(destDir, file);
await ensureDir(destFullPath);
await copyFiles(fullPath, destFullPath);
} else {
if (fullPath.endsWith(".d.ts") || fullPath.endsWith("package.json")) {
await copyFile(fullPath, path2.join(destDir, file));
}
}
})
);
};
await ensureDir(this.destDir);
await Promise.all(
Object.keys(this.pkgs).map(async (pkgName) => {
const pkgDir = this.pkgs[pkgName];
const destDir = path2.resolve(this.destDir, pkgName);
await ensureDir(destDir);
await copyFiles(pkgDir, destDir);
})
);
}
};
export {
ThirdPartyExtractor
};

View File

@@ -0,0 +1,51 @@
{
"name": "@module-federation/third-party-dts-extractor",
"version": "2.5.0",
"files": [
"dist/",
"README.md"
],
"repository": {
"type": "git",
"url": "git+https://github.com/module-federation/core.git",
"directory": "packages/third-party-dts-extractor"
},
"publishConfig": {
"access": "public"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
},
"typesVersions": {
"*": {
".": [
"./dist/index.d.ts"
]
}
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"author": "hanric <hanric.zhang@gmail.com>",
"license": "MIT",
"dependencies": {
"find-pkg": "2.0.0",
"resolve": "1.22.8"
},
"devDependencies": {
"@types/node": "^20.19.5",
"@types/react": "^18.3.11",
"vitest": "1.6.0",
"react": "^18",
"tsup": "7.3.0"
},
"scripts": {
"build": "tsup --config tsup.config.ts --outDir dist && cp package.json dist && cp *.md dist",
"lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\"",
"test": "pnpm exec vitest run --passWithNoTests --config vite.config.mts",
"pre-release": "pnpm run test && pnpm run build"
}
}

View File

@@ -0,0 +1,51 @@
{
"name": "@module-federation/third-party-dts-extractor",
"version": "2.5.0",
"files": [
"dist/",
"README.md"
],
"repository": {
"type": "git",
"url": "git+https://github.com/module-federation/core.git",
"directory": "packages/third-party-dts-extractor"
},
"publishConfig": {
"access": "public"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
},
"typesVersions": {
"*": {
".": [
"./dist/index.d.ts"
]
}
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"author": "hanric <hanric.zhang@gmail.com>",
"license": "MIT",
"dependencies": {
"find-pkg": "2.0.0",
"resolve": "1.22.8"
},
"devDependencies": {
"@types/node": "^20.19.5",
"@types/react": "^18.3.11",
"vitest": "1.6.0",
"react": "^18",
"tsup": "7.3.0"
},
"scripts": {
"build": "tsup --config tsup.config.ts --outDir dist && cp package.json dist && cp *.md dist",
"lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\"",
"test": "pnpm exec vitest run --passWithNoTests --config vite.config.mts",
"pre-release": "pnpm run test && pnpm run build"
}
}