@openpkg-ts/sdk 0.38.0 → 0.39.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/index.d.ts +1 -1
- package/dist/index.js +103 -61
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1551,7 +1551,7 @@ interface ProgramResult {
|
|
|
1551
1551
|
/** Resolved project references (workspace packages) */
|
|
1552
1552
|
projectReferences?: ts7.ResolvedProjectReference[];
|
|
1553
1553
|
}
|
|
1554
|
-
declare function createProgram(
|
|
1554
|
+
declare function createProgram(options: ProgramOptions): ProgramResult;
|
|
1555
1555
|
import * as TS from "typescript";
|
|
1556
1556
|
/**
|
|
1557
1557
|
* A schema adapter can detect and extract output types from a specific
|
package/dist/index.js
CHANGED
|
@@ -1298,6 +1298,7 @@ function filterSpec(spec, criteria) {
|
|
|
1298
1298
|
import ts11 from "typescript";
|
|
1299
1299
|
|
|
1300
1300
|
// src/ast/utils.ts
|
|
1301
|
+
import * as path2 from "node:path";
|
|
1301
1302
|
import ts from "typescript";
|
|
1302
1303
|
function parseExamplesFromTags(tags) {
|
|
1303
1304
|
const examples = [];
|
|
@@ -1442,8 +1443,10 @@ function getJSDocComment(node, symbol, checker) {
|
|
|
1442
1443
|
}
|
|
1443
1444
|
function getSourceLocation(node, sourceFile) {
|
|
1444
1445
|
const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
1446
|
+
const relative2 = path2.relative(process.cwd(), sourceFile.fileName);
|
|
1447
|
+
const file = relative2.startsWith("..") ? sourceFile.fileName : relative2;
|
|
1445
1448
|
return {
|
|
1446
|
-
file
|
|
1449
|
+
file,
|
|
1447
1450
|
line: line + 1
|
|
1448
1451
|
};
|
|
1449
1452
|
}
|
|
@@ -1614,7 +1617,7 @@ function getExportKind(declaration, type) {
|
|
|
1614
1617
|
|
|
1615
1618
|
// src/compiler/program.ts
|
|
1616
1619
|
import * as fs3 from "node:fs";
|
|
1617
|
-
import * as
|
|
1620
|
+
import * as path3 from "node:path";
|
|
1618
1621
|
import ts2 from "typescript";
|
|
1619
1622
|
function isJsFile(file) {
|
|
1620
1623
|
return /\.(js|mjs|cjs|jsx)$/.test(file);
|
|
@@ -1635,21 +1638,37 @@ var DEFAULT_COMPILER_OPTIONS = {
|
|
|
1635
1638
|
declaration: true,
|
|
1636
1639
|
moduleResolution: ts2.ModuleResolutionKind.NodeJs
|
|
1637
1640
|
};
|
|
1641
|
+
function resolveWorkspaceEntry(pkgDir) {
|
|
1642
|
+
const candidates = [
|
|
1643
|
+
path3.join(pkgDir, "src", "index.ts"),
|
|
1644
|
+
path3.join(pkgDir, "src", "index.tsx"),
|
|
1645
|
+
path3.join(pkgDir, "index.ts")
|
|
1646
|
+
];
|
|
1647
|
+
try {
|
|
1648
|
+
const pkg = JSON.parse(fs3.readFileSync(path3.join(pkgDir, "package.json"), "utf-8"));
|
|
1649
|
+
for (const field of [pkg.types, pkg.typings]) {
|
|
1650
|
+
if (typeof field === "string") {
|
|
1651
|
+
candidates.push(path3.resolve(pkgDir, field));
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
} catch {}
|
|
1655
|
+
return candidates.find((c) => fs3.existsSync(c));
|
|
1656
|
+
}
|
|
1638
1657
|
function resolveProjectReferences(configPath, parsedConfig) {
|
|
1639
1658
|
const additionalFiles = [];
|
|
1640
1659
|
if (!parsedConfig.projectReferences?.length) {
|
|
1641
1660
|
return additionalFiles;
|
|
1642
1661
|
}
|
|
1643
|
-
const configDir =
|
|
1662
|
+
const configDir = path3.dirname(configPath);
|
|
1644
1663
|
for (const ref of parsedConfig.projectReferences) {
|
|
1645
|
-
const refPath =
|
|
1646
|
-
const refConfigPath = fs3.existsSync(
|
|
1664
|
+
const refPath = path3.resolve(configDir, ref.path);
|
|
1665
|
+
const refConfigPath = fs3.existsSync(path3.join(refPath, "tsconfig.json")) ? path3.join(refPath, "tsconfig.json") : refPath;
|
|
1647
1666
|
if (!fs3.existsSync(refConfigPath))
|
|
1648
1667
|
continue;
|
|
1649
1668
|
const refConfigFile = ts2.readConfigFile(refConfigPath, ts2.sys.readFile);
|
|
1650
1669
|
if (refConfigFile.error)
|
|
1651
1670
|
continue;
|
|
1652
|
-
const refParsed = ts2.parseJsonConfigFileContent(refConfigFile.config, ts2.sys,
|
|
1671
|
+
const refParsed = ts2.parseJsonConfigFileContent(refConfigFile.config, ts2.sys, path3.dirname(refConfigPath));
|
|
1653
1672
|
additionalFiles.push(...refParsed.fileNames);
|
|
1654
1673
|
}
|
|
1655
1674
|
return additionalFiles;
|
|
@@ -1682,7 +1701,7 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1682
1701
|
let rootDir;
|
|
1683
1702
|
let workspaceGlobs = [];
|
|
1684
1703
|
for (let i = 0;i < 10; i++) {
|
|
1685
|
-
const pnpmPath =
|
|
1704
|
+
const pnpmPath = path3.join(currentDir, "pnpm-workspace.yaml");
|
|
1686
1705
|
if (fs3.existsSync(pnpmPath)) {
|
|
1687
1706
|
try {
|
|
1688
1707
|
const yamlContent = fs3.readFileSync(pnpmPath, "utf-8");
|
|
@@ -1693,7 +1712,7 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1693
1712
|
}
|
|
1694
1713
|
} catch {}
|
|
1695
1714
|
}
|
|
1696
|
-
const pkgPath =
|
|
1715
|
+
const pkgPath = path3.join(currentDir, "package.json");
|
|
1697
1716
|
if (fs3.existsSync(pkgPath)) {
|
|
1698
1717
|
try {
|
|
1699
1718
|
const pkg = JSON.parse(fs3.readFileSync(pkgPath, "utf-8"));
|
|
@@ -1704,7 +1723,7 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1704
1723
|
}
|
|
1705
1724
|
} catch {}
|
|
1706
1725
|
}
|
|
1707
|
-
const parent =
|
|
1726
|
+
const parent = path3.dirname(currentDir);
|
|
1708
1727
|
if (parent === currentDir)
|
|
1709
1728
|
break;
|
|
1710
1729
|
currentDir = parent;
|
|
@@ -1713,33 +1732,31 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1713
1732
|
return;
|
|
1714
1733
|
const packages = new Map;
|
|
1715
1734
|
for (const glob of workspaceGlobs) {
|
|
1716
|
-
const globDir =
|
|
1735
|
+
const globDir = path3.join(rootDir, glob.replace(/\/\*$/, ""));
|
|
1717
1736
|
if (!fs3.existsSync(globDir) || !fs3.statSync(globDir).isDirectory())
|
|
1718
1737
|
continue;
|
|
1719
1738
|
const entries = fs3.readdirSync(globDir, { withFileTypes: true });
|
|
1720
1739
|
for (const entry of entries) {
|
|
1721
1740
|
if (!entry.isDirectory())
|
|
1722
1741
|
continue;
|
|
1723
|
-
const pkgDir =
|
|
1724
|
-
const pkgJsonPath =
|
|
1742
|
+
const pkgDir = path3.join(globDir, entry.name);
|
|
1743
|
+
const pkgJsonPath = path3.join(pkgDir, "package.json");
|
|
1725
1744
|
if (!fs3.existsSync(pkgJsonPath))
|
|
1726
1745
|
continue;
|
|
1727
1746
|
try {
|
|
1728
1747
|
const pkg = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf-8"));
|
|
1729
1748
|
if (pkg.name) {
|
|
1730
|
-
|
|
1731
|
-
packages.set(pkg.name, srcDir);
|
|
1749
|
+
packages.set(pkg.name, pkgDir);
|
|
1732
1750
|
}
|
|
1733
1751
|
} catch {}
|
|
1734
1752
|
}
|
|
1735
1753
|
}
|
|
1736
1754
|
return packages.size > 0 ? { packages, rootDir } : undefined;
|
|
1737
1755
|
}
|
|
1738
|
-
function createProgram({
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
}) {
|
|
1756
|
+
function createProgram(options) {
|
|
1757
|
+
const { content } = options;
|
|
1758
|
+
const entryFile = path3.resolve(options.entryFile);
|
|
1759
|
+
const baseDir = path3.resolve(options.baseDir ?? path3.dirname(entryFile));
|
|
1743
1760
|
let configPath = ts2.findConfigFile(baseDir, ts2.sys.fileExists, "tsconfig.json");
|
|
1744
1761
|
if (!configPath) {
|
|
1745
1762
|
configPath = ts2.findConfigFile(baseDir, ts2.sys.fileExists, "jsconfig.json");
|
|
@@ -1748,7 +1765,7 @@ function createProgram({
|
|
|
1748
1765
|
let additionalRootFiles = [];
|
|
1749
1766
|
if (configPath) {
|
|
1750
1767
|
const configFile = ts2.readConfigFile(configPath, ts2.sys.readFile);
|
|
1751
|
-
const parsedConfig = ts2.parseJsonConfigFileContent(configFile.config, ts2.sys,
|
|
1768
|
+
const parsedConfig = ts2.parseJsonConfigFileContent(configFile.config, ts2.sys, path3.dirname(configPath));
|
|
1752
1769
|
compilerOptions = { ...compilerOptions, ...parsedConfig.options };
|
|
1753
1770
|
additionalRootFiles = resolveProjectReferences(configPath, parsedConfig);
|
|
1754
1771
|
const sourceFiles = parsedConfig.fileNames.filter((f) => !f.includes(".test.") && !f.includes(".spec.") && !f.includes("/dist/") && !f.includes("/node_modules/"));
|
|
@@ -1772,20 +1789,20 @@ function createProgram({
|
|
|
1772
1789
|
let inMemorySource;
|
|
1773
1790
|
if (workspaceMap) {
|
|
1774
1791
|
const originalResolveModuleNames = compilerHost.resolveModuleNames?.bind(compilerHost);
|
|
1775
|
-
compilerHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference,
|
|
1792
|
+
compilerHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, options2) => {
|
|
1776
1793
|
return moduleNames.map((moduleName) => {
|
|
1777
|
-
const
|
|
1778
|
-
if (
|
|
1779
|
-
const
|
|
1780
|
-
if (
|
|
1781
|
-
return { resolvedFileName:
|
|
1794
|
+
const pkgDir = workspaceMap.packages.get(moduleName);
|
|
1795
|
+
if (pkgDir) {
|
|
1796
|
+
const entryPath = resolveWorkspaceEntry(pkgDir);
|
|
1797
|
+
if (entryPath) {
|
|
1798
|
+
return { resolvedFileName: entryPath, isExternalLibraryImport: false };
|
|
1782
1799
|
}
|
|
1783
1800
|
}
|
|
1784
1801
|
if (originalResolveModuleNames) {
|
|
1785
|
-
const result = originalResolveModuleNames([moduleName], containingFile, _reusedNames, redirectedReference,
|
|
1802
|
+
const result = originalResolveModuleNames([moduleName], containingFile, _reusedNames, redirectedReference, options2);
|
|
1786
1803
|
return result[0];
|
|
1787
1804
|
}
|
|
1788
|
-
const resolved = ts2.resolveModuleName(moduleName, containingFile,
|
|
1805
|
+
const resolved = ts2.resolveModuleName(moduleName, containingFile, options2, compilerHost);
|
|
1789
1806
|
return resolved.resolvedModule;
|
|
1790
1807
|
});
|
|
1791
1808
|
};
|
|
@@ -1893,6 +1910,18 @@ var BUILTIN_GENERICS = new Set([
|
|
|
1893
1910
|
"InstanceType",
|
|
1894
1911
|
"Awaited"
|
|
1895
1912
|
]);
|
|
1913
|
+
var RESOLVED_UTILITY_TYPES = new Set([
|
|
1914
|
+
"Partial",
|
|
1915
|
+
"Required",
|
|
1916
|
+
"Readonly",
|
|
1917
|
+
"Pick",
|
|
1918
|
+
"Omit",
|
|
1919
|
+
"Record",
|
|
1920
|
+
"Exclude",
|
|
1921
|
+
"Extract",
|
|
1922
|
+
"NonNullable",
|
|
1923
|
+
"Awaited"
|
|
1924
|
+
]);
|
|
1896
1925
|
var BUILTIN_TYPES = new Set([
|
|
1897
1926
|
"Date",
|
|
1898
1927
|
"RegExp",
|
|
@@ -2318,6 +2347,13 @@ function buildSchemaInternal(type, checker, ctx) {
|
|
|
2318
2347
|
if (BUILTIN_TYPES.has(name)) {
|
|
2319
2348
|
return { $ref: `#/types/${name}` };
|
|
2320
2349
|
}
|
|
2350
|
+
if (RESOLVED_UTILITY_TYPES.has(name) && type.flags & ts3.TypeFlags.Object) {
|
|
2351
|
+
const props = type.getProperties();
|
|
2352
|
+
const hasIndex = checker.getIndexInfosOfType(type).length > 0;
|
|
2353
|
+
if (props.length > 0 || hasIndex) {
|
|
2354
|
+
return buildObjectSchema(props, checker, ctx, type);
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2321
2357
|
if (isBuiltinGeneric(name) || !name.startsWith("__")) {
|
|
2322
2358
|
const packageOrigin = getTypeOrigin(type, checker);
|
|
2323
2359
|
if (ctx) {
|
|
@@ -2432,7 +2468,11 @@ function buildObjectSchema(properties, checker, ctx, originalType) {
|
|
|
2432
2468
|
properties: props,
|
|
2433
2469
|
...required.length > 0 ? { required } : {}
|
|
2434
2470
|
};
|
|
2435
|
-
|
|
2471
|
+
const stringIndex = originalType ? checker.getIndexInfosOfType(originalType).find((i) => i.keyType.flags & ts3.TypeFlags.String) : undefined;
|
|
2472
|
+
if (stringIndex) {
|
|
2473
|
+
schema.additionalProperties = buildSchema(stringIndex.type, checker, ctx);
|
|
2474
|
+
}
|
|
2475
|
+
if (Object.keys(props).length === 0 && originalType && !stringIndex) {
|
|
2436
2476
|
setSchemaExtension(schema, "x-ts-type", checker.typeToString(originalType));
|
|
2437
2477
|
}
|
|
2438
2478
|
return schema;
|
|
@@ -2947,7 +2987,8 @@ class TypeRegistry {
|
|
|
2947
2987
|
}
|
|
2948
2988
|
buildObjectSchemaFromProperties(type, checker, ctx) {
|
|
2949
2989
|
const properties = type.getProperties();
|
|
2950
|
-
|
|
2990
|
+
const stringIndex = checker.getIndexInfosOfType(type).find((i) => i.keyType.flags & ts5.TypeFlags.String);
|
|
2991
|
+
if (properties.length === 0 && !stringIndex) {
|
|
2951
2992
|
return { type: checker.typeToString(type) };
|
|
2952
2993
|
}
|
|
2953
2994
|
const props = {};
|
|
@@ -2980,7 +3021,8 @@ class TypeRegistry {
|
|
|
2980
3021
|
return {
|
|
2981
3022
|
type: "object",
|
|
2982
3023
|
properties: props,
|
|
2983
|
-
...required.length > 0 ? { required } : {}
|
|
3024
|
+
...required.length > 0 ? { required } : {},
|
|
3025
|
+
...stringIndex ? { additionalProperties: buildSchema(stringIndex.type, checker, ctx) } : {}
|
|
2984
3026
|
};
|
|
2985
3027
|
}
|
|
2986
3028
|
}
|
|
@@ -4628,7 +4670,7 @@ function detectExternalPackage(symbol, checker) {
|
|
|
4628
4670
|
return;
|
|
4629
4671
|
}
|
|
4630
4672
|
// src/primitives/list.ts
|
|
4631
|
-
import * as
|
|
4673
|
+
import * as path4 from "node:path";
|
|
4632
4674
|
import ts12 from "typescript";
|
|
4633
4675
|
async function listExports(options) {
|
|
4634
4676
|
const { entryFile, baseDir, content } = options;
|
|
@@ -4689,7 +4731,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
|
|
|
4689
4731
|
return {
|
|
4690
4732
|
name,
|
|
4691
4733
|
kind: "namespace",
|
|
4692
|
-
file:
|
|
4734
|
+
file: path4.relative(path4.dirname(entryFile), declaration.fileName),
|
|
4693
4735
|
line: 1,
|
|
4694
4736
|
reexport: true
|
|
4695
4737
|
};
|
|
@@ -4703,7 +4745,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
|
|
|
4703
4745
|
return {
|
|
4704
4746
|
name,
|
|
4705
4747
|
kind,
|
|
4706
|
-
file:
|
|
4748
|
+
file: path4.relative(path4.dirname(entryFile), sourceFile.fileName),
|
|
4707
4749
|
line: line + 1,
|
|
4708
4750
|
...description ? { description } : {},
|
|
4709
4751
|
...deprecated ? { deprecated: true } : {},
|
|
@@ -4725,7 +4767,7 @@ function getDescriptionPreview(symbol, checker) {
|
|
|
4725
4767
|
}
|
|
4726
4768
|
// src/builder/spec-builder.ts
|
|
4727
4769
|
import * as fs6 from "node:fs";
|
|
4728
|
-
import * as
|
|
4770
|
+
import * as path8 from "node:path";
|
|
4729
4771
|
import { SCHEMA_URL, SCHEMA_VERSION } from "@openpkg-ts/spec";
|
|
4730
4772
|
import ts16 from "typescript";
|
|
4731
4773
|
|
|
@@ -4763,7 +4805,7 @@ function resolveExportTarget2(symbol, checker) {
|
|
|
4763
4805
|
import { spawn, spawnSync } from "node:child_process";
|
|
4764
4806
|
import * as fs4 from "node:fs";
|
|
4765
4807
|
import * as os from "node:os";
|
|
4766
|
-
import * as
|
|
4808
|
+
import * as path5 from "node:path";
|
|
4767
4809
|
var MAX_BUFFER_SIZE = 10 * 1024 * 1024;
|
|
4768
4810
|
function isStandardJSONSchema(obj) {
|
|
4769
4811
|
if (typeof obj !== "object" || obj === null)
|
|
@@ -5022,7 +5064,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5022
5064
|
return result;
|
|
5023
5065
|
}
|
|
5024
5066
|
const tempDir = os.tmpdir();
|
|
5025
|
-
const workerPath =
|
|
5067
|
+
const workerPath = path5.join(tempDir, `openpkg-extract-worker-${Date.now()}.ts`);
|
|
5026
5068
|
try {
|
|
5027
5069
|
fs4.writeFileSync(workerPath, TS_WORKER_SCRIPT);
|
|
5028
5070
|
const optionsJson = JSON.stringify({ target, libraryOptions });
|
|
@@ -5031,7 +5073,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5031
5073
|
const child = spawn(runtime.cmd, args, {
|
|
5032
5074
|
timeout,
|
|
5033
5075
|
stdio: ["ignore", "pipe", "pipe"],
|
|
5034
|
-
cwd:
|
|
5076
|
+
cwd: path5.dirname(tsFilePath)
|
|
5035
5077
|
});
|
|
5036
5078
|
let stdout = "";
|
|
5037
5079
|
let stderr = "";
|
|
@@ -5132,7 +5174,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5132
5174
|
}
|
|
5133
5175
|
}
|
|
5134
5176
|
function readTsconfigOutDir(baseDir) {
|
|
5135
|
-
const tsconfigPath =
|
|
5177
|
+
const tsconfigPath = path5.join(baseDir, "tsconfig.json");
|
|
5136
5178
|
try {
|
|
5137
5179
|
if (!fs4.existsSync(tsconfigPath)) {
|
|
5138
5180
|
return null;
|
|
@@ -5147,7 +5189,7 @@ function readTsconfigOutDir(baseDir) {
|
|
|
5147
5189
|
return null;
|
|
5148
5190
|
}
|
|
5149
5191
|
function resolveCompiledPath(tsPath, baseDir) {
|
|
5150
|
-
const relativePath =
|
|
5192
|
+
const relativePath = path5.relative(baseDir, tsPath);
|
|
5151
5193
|
const withoutExt = relativePath.replace(/\.tsx?$/, "");
|
|
5152
5194
|
const srcPrefix = withoutExt.replace(/^src\//, "");
|
|
5153
5195
|
const tsconfigOutDir = readTsconfigOutDir(baseDir);
|
|
@@ -5155,7 +5197,7 @@ function resolveCompiledPath(tsPath, baseDir) {
|
|
|
5155
5197
|
const candidates = [];
|
|
5156
5198
|
if (tsconfigOutDir) {
|
|
5157
5199
|
for (const ext of extensions) {
|
|
5158
|
-
candidates.push(
|
|
5200
|
+
candidates.push(path5.join(baseDir, tsconfigOutDir, `${srcPrefix}${ext}`));
|
|
5159
5201
|
}
|
|
5160
5202
|
}
|
|
5161
5203
|
const commonOutDirs = ["dist", "build", "lib", "out"];
|
|
@@ -5163,17 +5205,17 @@ function resolveCompiledPath(tsPath, baseDir) {
|
|
|
5163
5205
|
if (outDir === tsconfigOutDir)
|
|
5164
5206
|
continue;
|
|
5165
5207
|
for (const ext of extensions) {
|
|
5166
|
-
candidates.push(
|
|
5208
|
+
candidates.push(path5.join(baseDir, outDir, `${srcPrefix}${ext}`));
|
|
5167
5209
|
}
|
|
5168
5210
|
}
|
|
5169
5211
|
for (const ext of extensions) {
|
|
5170
|
-
candidates.push(
|
|
5212
|
+
candidates.push(path5.join(baseDir, `${withoutExt}${ext}`));
|
|
5171
5213
|
}
|
|
5172
5214
|
const workspaceMatch = baseDir.match(/^(.+\/packages\/[^/]+)$/);
|
|
5173
5215
|
if (workspaceMatch) {
|
|
5174
5216
|
const pkgRoot = workspaceMatch[1];
|
|
5175
5217
|
for (const ext of extensions) {
|
|
5176
|
-
candidates.push(
|
|
5218
|
+
candidates.push(path5.join(pkgRoot, "dist", `${srcPrefix}${ext}`));
|
|
5177
5219
|
}
|
|
5178
5220
|
}
|
|
5179
5221
|
for (const candidate of candidates) {
|
|
@@ -5307,7 +5349,7 @@ async function extractStandardSchemasFromProject(entryFile, baseDir, options = {
|
|
|
5307
5349
|
|
|
5308
5350
|
// src/builder/external-resolver.ts
|
|
5309
5351
|
import * as fs5 from "node:fs";
|
|
5310
|
-
import * as
|
|
5352
|
+
import * as path6 from "node:path";
|
|
5311
5353
|
import picomatch from "picomatch";
|
|
5312
5354
|
import ts14 from "typescript";
|
|
5313
5355
|
function matchesExternalPattern(packageName, include, exclude) {
|
|
@@ -5341,11 +5383,11 @@ function findPackageJson(resolvedPath, packageName) {
|
|
|
5341
5383
|
const isScoped = packageName.startsWith("@");
|
|
5342
5384
|
const packageParts = isScoped ? packageName.split("/").slice(0, 2) : [packageName.split("/")[0]];
|
|
5343
5385
|
const packageDir = packageParts.join("/");
|
|
5344
|
-
let dir =
|
|
5386
|
+
let dir = path6.dirname(resolvedPath);
|
|
5345
5387
|
const maxDepth = 10;
|
|
5346
5388
|
for (let i = 0;i < maxDepth; i++) {
|
|
5347
5389
|
if (dir.endsWith(`node_modules/${packageDir}`)) {
|
|
5348
|
-
const pkgPath =
|
|
5390
|
+
const pkgPath = path6.join(dir, "package.json");
|
|
5349
5391
|
if (fs5.existsSync(pkgPath)) {
|
|
5350
5392
|
try {
|
|
5351
5393
|
return JSON.parse(fs5.readFileSync(pkgPath, "utf-8"));
|
|
@@ -5354,7 +5396,7 @@ function findPackageJson(resolvedPath, packageName) {
|
|
|
5354
5396
|
}
|
|
5355
5397
|
}
|
|
5356
5398
|
}
|
|
5357
|
-
const parent =
|
|
5399
|
+
const parent = path6.dirname(dir);
|
|
5358
5400
|
if (parent === dir)
|
|
5359
5401
|
break;
|
|
5360
5402
|
dir = parent;
|
|
@@ -5598,7 +5640,7 @@ function hasInternalTag(typeName, program, sourceFile) {
|
|
|
5598
5640
|
}
|
|
5599
5641
|
|
|
5600
5642
|
// src/builder/verification.ts
|
|
5601
|
-
import * as
|
|
5643
|
+
import * as path7 from "node:path";
|
|
5602
5644
|
var BUILTIN_TYPES2 = new Set([
|
|
5603
5645
|
"Array",
|
|
5604
5646
|
"ArrayBuffer",
|
|
@@ -5687,8 +5729,8 @@ function isExternalType2(definedIn, baseDir) {
|
|
|
5687
5729
|
return true;
|
|
5688
5730
|
if (definedIn.includes("node_modules"))
|
|
5689
5731
|
return true;
|
|
5690
|
-
const normalizedDefined =
|
|
5691
|
-
const normalizedBase =
|
|
5732
|
+
const normalizedDefined = path7.resolve(definedIn);
|
|
5733
|
+
const normalizedBase = path7.resolve(baseDir);
|
|
5692
5734
|
return !normalizedDefined.startsWith(normalizedBase);
|
|
5693
5735
|
}
|
|
5694
5736
|
function shouldSkipDanglingRef(name) {
|
|
@@ -6027,7 +6069,7 @@ async function extract(options) {
|
|
|
6027
6069
|
}
|
|
6028
6070
|
}
|
|
6029
6071
|
const types = ctx.typeRegistry.getAll();
|
|
6030
|
-
const projectBaseDir = baseDir ??
|
|
6072
|
+
const projectBaseDir = baseDir ?? path8.dirname(entryFile);
|
|
6031
6073
|
const definedTypes = new Set(types.map((t) => t.id));
|
|
6032
6074
|
const forgottenExports = collectForgottenExports(exports, types, program, sourceFile, exportedIds, projectBaseDir, definedTypes);
|
|
6033
6075
|
for (const forgotten of forgottenExports) {
|
|
@@ -6060,7 +6102,7 @@ async function extract(options) {
|
|
|
6060
6102
|
}
|
|
6061
6103
|
let runtimeMetadata;
|
|
6062
6104
|
if (options.schemaExtraction === "hybrid") {
|
|
6063
|
-
const projectBaseDir2 = baseDir ||
|
|
6105
|
+
const projectBaseDir2 = baseDir || path8.dirname(entryFile);
|
|
6064
6106
|
const runtimeResult = await extractStandardSchemasFromProject(entryFile, projectBaseDir2, {
|
|
6065
6107
|
target: options.schemaTarget || "draft-2020-12",
|
|
6066
6108
|
timeout: 15000
|
|
@@ -6349,7 +6391,7 @@ function createEmptySpec(entryFile, includeSchema, isDtsSource) {
|
|
|
6349
6391
|
return {
|
|
6350
6392
|
...includeSchema ? { $schema: SCHEMA_URL } : {},
|
|
6351
6393
|
openpkg: SCHEMA_VERSION,
|
|
6352
|
-
meta: { name:
|
|
6394
|
+
meta: { name: path8.basename(entryFile, path8.extname(entryFile)) },
|
|
6353
6395
|
exports: [],
|
|
6354
6396
|
generation: {
|
|
6355
6397
|
generator: "@openpkg-ts/sdk",
|
|
@@ -6365,7 +6407,7 @@ function findTypeInProgram(name, checker, program, sourceFile, symFlags) {
|
|
|
6365
6407
|
const localSym = checker.resolveName(name, sourceFile, symFlags, false);
|
|
6366
6408
|
if (localSym)
|
|
6367
6409
|
return checker.getDeclaredTypeOfSymbol(localSym);
|
|
6368
|
-
const entryDir =
|
|
6410
|
+
const entryDir = path8.dirname(sourceFile.fileName);
|
|
6369
6411
|
for (const sf of program.getSourceFiles()) {
|
|
6370
6412
|
const fn = sf.fileName;
|
|
6371
6413
|
if (fn.includes("/typescript/lib/lib.") || fn.includes("\\typescript\\lib\\lib."))
|
|
@@ -6381,22 +6423,22 @@ function findTypeInProgram(name, checker, program, sourceFile, symFlags) {
|
|
|
6381
6423
|
return;
|
|
6382
6424
|
}
|
|
6383
6425
|
async function getPackageMeta(entryFile, baseDir) {
|
|
6384
|
-
let dir = baseDir ??
|
|
6385
|
-
while (dir !==
|
|
6386
|
-
const pkgPath =
|
|
6426
|
+
let dir = baseDir ?? path8.dirname(entryFile);
|
|
6427
|
+
while (dir !== path8.dirname(dir)) {
|
|
6428
|
+
const pkgPath = path8.join(dir, "package.json");
|
|
6387
6429
|
try {
|
|
6388
6430
|
if (fs6.existsSync(pkgPath)) {
|
|
6389
6431
|
const pkg = JSON.parse(fs6.readFileSync(pkgPath, "utf-8"));
|
|
6390
6432
|
return {
|
|
6391
|
-
name: pkg.name ??
|
|
6433
|
+
name: pkg.name ?? path8.basename(dir),
|
|
6392
6434
|
version: pkg.version,
|
|
6393
6435
|
description: pkg.description
|
|
6394
6436
|
};
|
|
6395
6437
|
}
|
|
6396
6438
|
} catch {}
|
|
6397
|
-
dir =
|
|
6439
|
+
dir = path8.dirname(dir);
|
|
6398
6440
|
}
|
|
6399
|
-
return { name:
|
|
6441
|
+
return { name: path8.basename(baseDir ?? path8.dirname(entryFile)) };
|
|
6400
6442
|
}
|
|
6401
6443
|
|
|
6402
6444
|
// src/primitives/spec.ts
|