deslop-js 0.9.7 → 0.9.8
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/entries-worker.mjs +242 -223
- package/dist/index.cjs +785 -808
- package/dist/index.d.cts +3 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +788 -810
- package/dist/{parse-C6-m3QMJ.mjs → parse-C6Iu3cJw.mjs} +175 -176
- package/dist/parse-worker.mjs +1 -1
- package/package.json +1 -1
package/dist/entries-worker.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { a as OUTPUT_DIRECTORIES, c as SCRIPT_EXTENSIONLESS_FILE_PATTERN, d as STANDALONE_PROJECT_LOCKFILES, i as MONOREPO_ROOT_MARKERS, l as SCRIPT_FILE_PATTERN, o as RESOLVER_EXTENSIONS, r as LOCKFILE_MARKERS, s as SCRIPT_CONFIG_FILE_PATTERN, t as extractReactRouterRouteModuleEntries, u as SOURCE_EXTENSIONS$3 } from "./parse-
|
|
1
|
+
import { a as OUTPUT_DIRECTORIES, c as SCRIPT_EXTENSIONLESS_FILE_PATTERN, d as STANDALONE_PROJECT_LOCKFILES, i as MONOREPO_ROOT_MARKERS, l as SCRIPT_FILE_PATTERN, o as RESOLVER_EXTENSIONS, r as LOCKFILE_MARKERS, s as SCRIPT_CONFIG_FILE_PATTERN, t as extractReactRouterRouteModuleEntries, u as SOURCE_EXTENSIONS$3 } from "./parse-C6Iu3cJw.mjs";
|
|
2
2
|
import { parentPort } from "node:worker_threads";
|
|
3
3
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
4
4
|
import fg from "fast-glob";
|
|
5
5
|
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
|
-
import { readFile } from "node:fs/promises";
|
|
7
6
|
import ts from "typescript";
|
|
8
7
|
import "oxc-resolver";
|
|
8
|
+
import { readFile } from "node:fs/promises";
|
|
9
9
|
|
|
10
10
|
//#region src/collect/workspaces.ts
|
|
11
11
|
const resolveWorkspaces = (rootDir) => {
|
|
@@ -1306,6 +1306,246 @@ const extractSiblingWorkspaceImportEntries = (absoluteRoot) => {
|
|
|
1306
1306
|
return [...new Set(importedEntries)];
|
|
1307
1307
|
};
|
|
1308
1308
|
|
|
1309
|
+
//#endregion
|
|
1310
|
+
//#region src/collect/package-json-entries.ts
|
|
1311
|
+
const DEFAULT_INDEX_PATTERNS = [
|
|
1312
|
+
"src/index.ts",
|
|
1313
|
+
"src/index.tsx",
|
|
1314
|
+
"src/index.js",
|
|
1315
|
+
"src/index.jsx",
|
|
1316
|
+
"src/main.ts",
|
|
1317
|
+
"src/main.tsx",
|
|
1318
|
+
"src/main.js",
|
|
1319
|
+
"src/main.jsx",
|
|
1320
|
+
"index.ts",
|
|
1321
|
+
"index.tsx",
|
|
1322
|
+
"index.js",
|
|
1323
|
+
"index.jsx",
|
|
1324
|
+
"main.ts",
|
|
1325
|
+
"main.tsx",
|
|
1326
|
+
"main.js",
|
|
1327
|
+
"main.jsx"
|
|
1328
|
+
];
|
|
1329
|
+
const SOURCE_EXTENSIONS = [
|
|
1330
|
+
".ts",
|
|
1331
|
+
".tsx",
|
|
1332
|
+
".mts",
|
|
1333
|
+
".cts"
|
|
1334
|
+
];
|
|
1335
|
+
const COMMON_SOURCE_DIRECTORIES = [
|
|
1336
|
+
"src",
|
|
1337
|
+
"lib",
|
|
1338
|
+
"main",
|
|
1339
|
+
"app",
|
|
1340
|
+
"source"
|
|
1341
|
+
];
|
|
1342
|
+
const BUILD_OUTPUT_DIRECTORY_PATTERN = /^(?:\.\/)?(?:dist(?:-[a-z]+)?|build|out|esm|cjs)\/(?:(?:esm|cjs|es|lib|commonjs|module)\/)?/;
|
|
1343
|
+
const IMPORTABLE_EXTENSION_SET = new Set([
|
|
1344
|
+
".ts",
|
|
1345
|
+
".tsx",
|
|
1346
|
+
".js",
|
|
1347
|
+
".jsx",
|
|
1348
|
+
".mts",
|
|
1349
|
+
".mjs",
|
|
1350
|
+
".cts",
|
|
1351
|
+
".cjs",
|
|
1352
|
+
".css",
|
|
1353
|
+
".scss",
|
|
1354
|
+
".less",
|
|
1355
|
+
".sass"
|
|
1356
|
+
]);
|
|
1357
|
+
const PACKAGE_ENTRY_FIELDS = [
|
|
1358
|
+
"main",
|
|
1359
|
+
"module",
|
|
1360
|
+
"browser",
|
|
1361
|
+
"types",
|
|
1362
|
+
"typings",
|
|
1363
|
+
"style",
|
|
1364
|
+
"source"
|
|
1365
|
+
];
|
|
1366
|
+
const findDefaultIndexEntry = (directory) => {
|
|
1367
|
+
for (const pattern of DEFAULT_INDEX_PATTERNS) {
|
|
1368
|
+
const candidatePath = resolve(directory, pattern);
|
|
1369
|
+
if (existsSync(candidatePath)) return candidatePath;
|
|
1370
|
+
}
|
|
1371
|
+
};
|
|
1372
|
+
const findSourceFileWithKnownExtension = (pathWithoutExtension) => {
|
|
1373
|
+
for (const sourceExtension of SOURCE_EXTENSIONS) {
|
|
1374
|
+
const candidatePath = pathWithoutExtension + sourceExtension;
|
|
1375
|
+
if (existsSync(candidatePath)) return candidatePath;
|
|
1376
|
+
}
|
|
1377
|
+
};
|
|
1378
|
+
const findSourceFile = (baseDirectory, relativePath, shouldResolveDirectoryIndex = true) => {
|
|
1379
|
+
const pathWithoutExtension = join(baseDirectory, relativePath).replace(/\.[cm]?js(x?)$/, "");
|
|
1380
|
+
const sourceFile = findSourceFileWithKnownExtension(pathWithoutExtension);
|
|
1381
|
+
if (sourceFile) return sourceFile;
|
|
1382
|
+
const fallbackPath = shouldResolveDirectoryIndex ? join(pathWithoutExtension, "index.ts") : join(baseDirectory, relativePath);
|
|
1383
|
+
return existsSync(fallbackPath) ? fallbackPath : void 0;
|
|
1384
|
+
};
|
|
1385
|
+
const findSourceFileStrict = (baseDirectory, relativePath) => findSourceFile(baseDirectory, relativePath, false);
|
|
1386
|
+
const readTypeScriptBuildDirectories = (rootDirectory) => {
|
|
1387
|
+
const tsconfigPath = join(rootDirectory, "tsconfig.json");
|
|
1388
|
+
if (!existsSync(tsconfigPath)) return void 0;
|
|
1389
|
+
const tsconfigContent = readFileSync(tsconfigPath, "utf-8").replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
1390
|
+
const tsconfig = JSON.parse(tsconfigContent);
|
|
1391
|
+
const outDirectory = tsconfig?.compilerOptions?.outDir;
|
|
1392
|
+
if (!outDirectory) return void 0;
|
|
1393
|
+
const configuredRootDirectory = tsconfig?.compilerOptions?.rootDir;
|
|
1394
|
+
return {
|
|
1395
|
+
absoluteOutDirectory: resolve(rootDirectory, outDirectory),
|
|
1396
|
+
sourceRoot: configuredRootDirectory ? resolve(rootDirectory, configuredRootDirectory) : rootDirectory,
|
|
1397
|
+
shouldSearchCommonSourceDirectories: !configuredRootDirectory
|
|
1398
|
+
};
|
|
1399
|
+
};
|
|
1400
|
+
const findRelativeBuildPath = (absoluteOutDirectory, builtAbsolutePath) => {
|
|
1401
|
+
const relativeToBuild = relative(absoluteOutDirectory, builtAbsolutePath);
|
|
1402
|
+
if (relativeToBuild.length === 0 || relativeToBuild === ".." || relativeToBuild.startsWith(`..${sep}`) || isAbsolute(relativeToBuild)) return;
|
|
1403
|
+
return relativeToBuild;
|
|
1404
|
+
};
|
|
1405
|
+
const findSourcePathForBuildOutput = (buildDirectories, relativeBuildPath, rootDirectory) => {
|
|
1406
|
+
const sourceFileMatch = findSourceFile(buildDirectories.sourceRoot, relativeBuildPath);
|
|
1407
|
+
if (sourceFileMatch) return sourceFileMatch;
|
|
1408
|
+
const directCandidate = join(buildDirectories.sourceRoot, relativeBuildPath);
|
|
1409
|
+
if (existsSync(directCandidate)) return directCandidate;
|
|
1410
|
+
if (!buildDirectories.shouldSearchCommonSourceDirectories) return void 0;
|
|
1411
|
+
for (const sourceDirectory of COMMON_SOURCE_DIRECTORIES) {
|
|
1412
|
+
const candidate = findSourceFile(resolve(rootDirectory, sourceDirectory), relativeBuildPath);
|
|
1413
|
+
if (candidate) return candidate;
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
const resolveBuiltPathToSource = (builtAbsolutePath, rootDirectory) => {
|
|
1417
|
+
if (existsSync(builtAbsolutePath)) return void 0;
|
|
1418
|
+
try {
|
|
1419
|
+
const buildDirectories = readTypeScriptBuildDirectories(rootDirectory);
|
|
1420
|
+
if (!buildDirectories) return void 0;
|
|
1421
|
+
const relativeBuildPath = findRelativeBuildPath(buildDirectories.absoluteOutDirectory, builtAbsolutePath);
|
|
1422
|
+
if (!relativeBuildPath) return void 0;
|
|
1423
|
+
return findSourcePathForBuildOutput(buildDirectories, relativeBuildPath, rootDirectory);
|
|
1424
|
+
} catch {}
|
|
1425
|
+
};
|
|
1426
|
+
const resolveEntryPathViaHeuristic = (entryPath, rootDirectory) => {
|
|
1427
|
+
const buildDirectoryMatch = entryPath.match(BUILD_OUTPUT_DIRECTORY_PATTERN);
|
|
1428
|
+
if (!buildDirectoryMatch) return void 0;
|
|
1429
|
+
const relativeToBuildDirectory = entryPath.slice(buildDirectoryMatch[0].length);
|
|
1430
|
+
for (const sourceDirectory of COMMON_SOURCE_DIRECTORIES) {
|
|
1431
|
+
const sourceBaseDirectory = resolve(rootDirectory, sourceDirectory);
|
|
1432
|
+
if (!existsSync(sourceBaseDirectory)) continue;
|
|
1433
|
+
const sourceFileMatch = findSourceFileStrict(sourceBaseDirectory, relativeToBuildDirectory);
|
|
1434
|
+
if (sourceFileMatch) return sourceFileMatch;
|
|
1435
|
+
}
|
|
1436
|
+
};
|
|
1437
|
+
const resolveEntryPath = (entryPath, rootDirectory) => {
|
|
1438
|
+
const absolutePath = resolve(rootDirectory, entryPath);
|
|
1439
|
+
const normalizedEntry = entryPath.replace(/^\.\//, "");
|
|
1440
|
+
if (BUILD_OUTPUT_DIRECTORY_PATTERN.test(normalizedEntry)) {
|
|
1441
|
+
const sourcePath = resolveBuiltPathToSource(absolutePath, rootDirectory);
|
|
1442
|
+
if (sourcePath) return sourcePath;
|
|
1443
|
+
const heuristicMatch = resolveEntryPathViaHeuristic(normalizedEntry, rootDirectory);
|
|
1444
|
+
if (heuristicMatch) return heuristicMatch;
|
|
1445
|
+
}
|
|
1446
|
+
if (existsSync(absolutePath)) return absolutePath;
|
|
1447
|
+
return resolveBuiltPathToSource(absolutePath, rootDirectory) ?? findSourceFile(rootDirectory, normalizedEntry) ?? resolveEntryPathViaHeuristic(normalizedEntry, rootDirectory) ?? absolutePath;
|
|
1448
|
+
};
|
|
1449
|
+
const collectExportPaths = (exportValue, rootDirectory, entries) => {
|
|
1450
|
+
if (typeof exportValue === "string") {
|
|
1451
|
+
if (exportValue.includes("*")) {
|
|
1452
|
+
const normalizedPattern = exportValue.startsWith("./") ? exportValue.slice(2) : exportValue;
|
|
1453
|
+
entries.push(...findImportableFiles(normalizedPattern, rootDirectory, ["**/node_modules/**"]));
|
|
1454
|
+
} else entries.push(resolveEntryPath(exportValue, rootDirectory));
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
if (!exportValue || typeof exportValue !== "object") return;
|
|
1458
|
+
for (const nestedExportValue of Object.values(exportValue)) collectExportPaths(nestedExportValue, rootDirectory, entries);
|
|
1459
|
+
};
|
|
1460
|
+
const isImportableSourceFile = (filePath) => IMPORTABLE_EXTENSION_SET.has(filePath.slice(filePath.lastIndexOf(".")));
|
|
1461
|
+
const findImportableFiles = (pattern, rootDirectory, ignoredPatterns) => fg.sync(pattern, {
|
|
1462
|
+
cwd: rootDirectory,
|
|
1463
|
+
absolute: true,
|
|
1464
|
+
onlyFiles: true,
|
|
1465
|
+
ignore: ignoredPatterns
|
|
1466
|
+
}).filter(isImportableSourceFile);
|
|
1467
|
+
const expandSideEffectGlobToSourcePatterns = (pattern) => {
|
|
1468
|
+
const patterns = new Set([pattern]);
|
|
1469
|
+
if (pattern.endsWith(".js")) {
|
|
1470
|
+
patterns.add(pattern.replace(/\.js$/, ".ts"));
|
|
1471
|
+
patterns.add(pattern.replace(/\.js$/, ".tsx"));
|
|
1472
|
+
}
|
|
1473
|
+
if (pattern.includes("/lib/") || pattern.startsWith("lib/")) patterns.add(pattern.replace(/\blib\b/g, "src"));
|
|
1474
|
+
if (pattern.includes("/esm/") || pattern.startsWith("esm/")) patterns.add(pattern.replace(/\besm\b/g, "src"));
|
|
1475
|
+
return [...patterns];
|
|
1476
|
+
};
|
|
1477
|
+
const collectFieldEntries = (packageJson, rootDirectory, entries) => {
|
|
1478
|
+
for (const field of PACKAGE_ENTRY_FIELDS) {
|
|
1479
|
+
const entryPath = packageJson[field];
|
|
1480
|
+
if (typeof entryPath === "string") entries.push(resolveEntryPath(entryPath, rootDirectory));
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
const resolveExportEntry = (exportEntry, rootDirectory) => {
|
|
1484
|
+
const resolvedExportEntry = resolveEntryWithExtensions(exportEntry) ?? resolveEntryPathWithExtensions(exportEntry, rootDirectory) ?? resolveSourcePath(exportEntry, rootDirectory);
|
|
1485
|
+
if (resolvedExportEntry && existsSync(resolvedExportEntry)) return resolvedExportEntry;
|
|
1486
|
+
const typescriptReactEntry = exportEntry.endsWith(".ts") ? exportEntry.replace(/\.ts$/, ".tsx") : void 0;
|
|
1487
|
+
if (typescriptReactEntry && existsSync(typescriptReactEntry)) return typescriptReactEntry;
|
|
1488
|
+
return existsSync(exportEntry) ? exportEntry : resolveEntryPath(exportEntry, rootDirectory);
|
|
1489
|
+
};
|
|
1490
|
+
const collectPackageExportEntries = (exportValue, rootDirectory, entries) => {
|
|
1491
|
+
if (!exportValue) return;
|
|
1492
|
+
const exportEntries = [];
|
|
1493
|
+
collectExportPaths(exportValue, rootDirectory, exportEntries);
|
|
1494
|
+
for (const exportEntry of exportEntries) entries.push(resolveExportEntry(exportEntry, rootDirectory));
|
|
1495
|
+
};
|
|
1496
|
+
const collectPackageBinEntries = (binValue, rootDirectory, entries) => {
|
|
1497
|
+
if (typeof binValue === "string") {
|
|
1498
|
+
entries.push(resolveEntryPath(binValue, rootDirectory));
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
if (!binValue || typeof binValue !== "object") return;
|
|
1502
|
+
for (const binPath of Object.values(binValue)) if (typeof binPath === "string") entries.push(resolveEntryPath(binPath, rootDirectory));
|
|
1503
|
+
};
|
|
1504
|
+
const collectSideEffectEntries = (sideEffectValue, rootDirectory, entries) => {
|
|
1505
|
+
if (!Array.isArray(sideEffectValue)) return;
|
|
1506
|
+
for (const sideEffectPattern of sideEffectValue) {
|
|
1507
|
+
if (typeof sideEffectPattern !== "string") continue;
|
|
1508
|
+
for (const sourcePattern of expandSideEffectGlobToSourcePatterns(sideEffectPattern)) entries.push(...findImportableFiles(sourcePattern, rootDirectory, [
|
|
1509
|
+
"**/node_modules/**",
|
|
1510
|
+
"**/dist/**",
|
|
1511
|
+
"**/build/**"
|
|
1512
|
+
]));
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
const collectBuildEntries = (buildValue, rootDirectory, entries) => {
|
|
1516
|
+
if (typeof buildValue !== "object" || buildValue === null) return;
|
|
1517
|
+
const buildFileEntries = Reflect.get(buildValue, "files");
|
|
1518
|
+
if (!Array.isArray(buildFileEntries)) return;
|
|
1519
|
+
for (const buildFileEntry of buildFileEntries) {
|
|
1520
|
+
if (typeof buildFileEntry !== "string" || buildFileEntry.includes("*")) continue;
|
|
1521
|
+
const resolvedBuildFile = resolveEntryPathWithExtensions(buildFileEntry, rootDirectory);
|
|
1522
|
+
if (resolvedBuildFile && existsSync(resolvedBuildFile)) entries.push(resolvedBuildFile);
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
const collectJestEntries = (jestValue, rootDirectory, entries) => {
|
|
1526
|
+
if (!jestValue || typeof jestValue !== "object") return;
|
|
1527
|
+
const jestConfigContent = JSON.stringify(jestValue);
|
|
1528
|
+
for (const jestRootDirectoryMatch of jestConfigContent.matchAll(/<rootDir>\/([^"\\]+)/g)) {
|
|
1529
|
+
const resolvedJestFile = resolveEntryPathWithExtensions(jestRootDirectoryMatch[1], rootDirectory);
|
|
1530
|
+
if (resolvedJestFile && existsSync(resolvedJestFile)) entries.push(resolvedJestFile);
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
const extractPackageJsonEntries = async (packageJsonPath) => {
|
|
1534
|
+
const entries = [];
|
|
1535
|
+
try {
|
|
1536
|
+
const content = await readFile(packageJsonPath, "utf-8");
|
|
1537
|
+
const packageJson = JSON.parse(content);
|
|
1538
|
+
const rootDirectory = packageJsonPath.replace(/\/package\.json$/, "");
|
|
1539
|
+
collectFieldEntries(packageJson, rootDirectory, entries);
|
|
1540
|
+
collectPackageExportEntries(packageJson.exports, rootDirectory, entries);
|
|
1541
|
+
collectPackageBinEntries(packageJson.bin, rootDirectory, entries);
|
|
1542
|
+
collectSideEffectEntries(packageJson.sideEffects, rootDirectory, entries);
|
|
1543
|
+
collectBuildEntries(packageJson.build, rootDirectory, entries);
|
|
1544
|
+
collectJestEntries(packageJson.jest, rootDirectory, entries);
|
|
1545
|
+
} catch {}
|
|
1546
|
+
return entries;
|
|
1547
|
+
};
|
|
1548
|
+
|
|
1309
1549
|
//#endregion
|
|
1310
1550
|
//#region src/collect/entries.ts
|
|
1311
1551
|
const resolveEntries = async (config) => {
|
|
@@ -1418,203 +1658,6 @@ const resolveEntries = async (config) => {
|
|
|
1418
1658
|
alwaysUsedFiles: [...new Set([...toolingDiscovery.alwaysUsedFiles, ...testRunnerDiscovery.alwaysUsedFiles].map(toPosixPath))]
|
|
1419
1659
|
};
|
|
1420
1660
|
};
|
|
1421
|
-
const DEFAULT_INDEX_PATTERNS = [
|
|
1422
|
-
"src/index.ts",
|
|
1423
|
-
"src/index.tsx",
|
|
1424
|
-
"src/index.js",
|
|
1425
|
-
"src/index.jsx",
|
|
1426
|
-
"src/main.ts",
|
|
1427
|
-
"src/main.tsx",
|
|
1428
|
-
"src/main.js",
|
|
1429
|
-
"src/main.jsx",
|
|
1430
|
-
"index.ts",
|
|
1431
|
-
"index.tsx",
|
|
1432
|
-
"index.js",
|
|
1433
|
-
"index.jsx",
|
|
1434
|
-
"main.ts",
|
|
1435
|
-
"main.tsx",
|
|
1436
|
-
"main.js",
|
|
1437
|
-
"main.jsx"
|
|
1438
|
-
];
|
|
1439
|
-
const findDefaultIndexEntry = (directory) => {
|
|
1440
|
-
for (const pattern of DEFAULT_INDEX_PATTERNS) {
|
|
1441
|
-
const candidatePath = resolve(directory, pattern);
|
|
1442
|
-
if (existsSync(candidatePath)) return candidatePath;
|
|
1443
|
-
}
|
|
1444
|
-
};
|
|
1445
|
-
const SOURCE_EXTENSIONS = [
|
|
1446
|
-
".ts",
|
|
1447
|
-
".tsx",
|
|
1448
|
-
".mts",
|
|
1449
|
-
".cts"
|
|
1450
|
-
];
|
|
1451
|
-
const COMMON_SOURCE_DIRECTORIES = [
|
|
1452
|
-
"src",
|
|
1453
|
-
"lib",
|
|
1454
|
-
"main",
|
|
1455
|
-
"app",
|
|
1456
|
-
"source"
|
|
1457
|
-
];
|
|
1458
|
-
const BUILD_OUTPUT_DIRECTORY_PATTERN = /^(?:\.\/)?(?:dist(?:-[a-z]+)?|build|out|esm|cjs)\/(?:(?:esm|cjs|es|lib|commonjs|module)\/)?/;
|
|
1459
|
-
const findSourceFile = (baseDir, relativePath) => {
|
|
1460
|
-
const pathWithoutExtension = join(baseDir, relativePath).replace(/\.[cm]?js(x?)$/, "");
|
|
1461
|
-
for (const sourceExtension of SOURCE_EXTENSIONS) {
|
|
1462
|
-
const candidatePath = pathWithoutExtension + sourceExtension;
|
|
1463
|
-
if (existsSync(candidatePath)) return candidatePath;
|
|
1464
|
-
}
|
|
1465
|
-
const indexCandidate = join(pathWithoutExtension, "index.ts");
|
|
1466
|
-
if (existsSync(indexCandidate)) return indexCandidate;
|
|
1467
|
-
};
|
|
1468
|
-
const findSourceFileStrict = (baseDir, relativePath) => {
|
|
1469
|
-
const pathWithoutExtension = join(baseDir, relativePath).replace(/\.[cm]?js(x?)$/, "");
|
|
1470
|
-
for (const sourceExtension of SOURCE_EXTENSIONS) {
|
|
1471
|
-
const candidatePath = pathWithoutExtension + sourceExtension;
|
|
1472
|
-
if (existsSync(candidatePath)) return candidatePath;
|
|
1473
|
-
}
|
|
1474
|
-
const exactPath = join(baseDir, relativePath);
|
|
1475
|
-
if (existsSync(exactPath)) return exactPath;
|
|
1476
|
-
};
|
|
1477
|
-
const resolveBuiltPathToSource = (builtAbsolutePath, rootDir) => {
|
|
1478
|
-
if (existsSync(builtAbsolutePath)) return void 0;
|
|
1479
|
-
try {
|
|
1480
|
-
const tsconfigPath = join(rootDir, "tsconfig.json");
|
|
1481
|
-
if (!existsSync(tsconfigPath)) return void 0;
|
|
1482
|
-
const tsconfigContent = readFileSync(tsconfigPath, "utf-8").replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
1483
|
-
const tsconfig = JSON.parse(tsconfigContent);
|
|
1484
|
-
const outDir = tsconfig?.compilerOptions?.outDir;
|
|
1485
|
-
if (!outDir) return void 0;
|
|
1486
|
-
const absoluteOutDir = resolve(rootDir, outDir);
|
|
1487
|
-
const relativeToBuild = builtAbsolutePath.startsWith(absoluteOutDir) ? builtAbsolutePath.slice(absoluteOutDir.length) : void 0;
|
|
1488
|
-
if (!relativeToBuild) return void 0;
|
|
1489
|
-
const rootDirOption = tsconfig?.compilerOptions?.rootDir;
|
|
1490
|
-
const sourceRoot = rootDirOption ? resolve(rootDir, rootDirOption) : rootDir;
|
|
1491
|
-
const sourceFileMatch = findSourceFile(sourceRoot, relativeToBuild);
|
|
1492
|
-
if (sourceFileMatch) return sourceFileMatch;
|
|
1493
|
-
const directCandidate = join(sourceRoot, relativeToBuild);
|
|
1494
|
-
if (existsSync(directCandidate)) return directCandidate;
|
|
1495
|
-
if (!rootDirOption) for (const sourceDir of COMMON_SOURCE_DIRECTORIES) {
|
|
1496
|
-
const candidate = findSourceFile(resolve(rootDir, sourceDir), relativeToBuild);
|
|
1497
|
-
if (candidate) return candidate;
|
|
1498
|
-
}
|
|
1499
|
-
} catch {}
|
|
1500
|
-
};
|
|
1501
|
-
const resolveEntryPathViaHeuristic = (entryPath, rootDir) => {
|
|
1502
|
-
if (!BUILD_OUTPUT_DIRECTORY_PATTERN.test(entryPath)) return void 0;
|
|
1503
|
-
const buildDirMatch = entryPath.match(BUILD_OUTPUT_DIRECTORY_PATTERN);
|
|
1504
|
-
if (!buildDirMatch) return void 0;
|
|
1505
|
-
const relativeToBuildDir = entryPath.slice(buildDirMatch[0].length);
|
|
1506
|
-
for (const sourceDir of COMMON_SOURCE_DIRECTORIES) {
|
|
1507
|
-
const sourceBaseDir = resolve(rootDir, sourceDir);
|
|
1508
|
-
if (!existsSync(sourceBaseDir)) continue;
|
|
1509
|
-
const sourceFileMatch = findSourceFileStrict(sourceBaseDir, relativeToBuildDir);
|
|
1510
|
-
if (sourceFileMatch) return sourceFileMatch;
|
|
1511
|
-
}
|
|
1512
|
-
};
|
|
1513
|
-
const resolveEntryPath = (entryPath, rootDir) => {
|
|
1514
|
-
const absolutePath = resolve(rootDir, entryPath);
|
|
1515
|
-
const normalizedEntry = entryPath.replace(/^\.\//, "");
|
|
1516
|
-
if (BUILD_OUTPUT_DIRECTORY_PATTERN.test(normalizedEntry)) {
|
|
1517
|
-
const sourcePath = resolveBuiltPathToSource(absolutePath, rootDir);
|
|
1518
|
-
if (sourcePath) return sourcePath;
|
|
1519
|
-
const heuristicMatch = resolveEntryPathViaHeuristic(normalizedEntry, rootDir);
|
|
1520
|
-
if (heuristicMatch) return heuristicMatch;
|
|
1521
|
-
}
|
|
1522
|
-
if (existsSync(absolutePath)) return absolutePath;
|
|
1523
|
-
const sourcePath = resolveBuiltPathToSource(absolutePath, rootDir);
|
|
1524
|
-
if (sourcePath) return sourcePath;
|
|
1525
|
-
const directSourceMatch = findSourceFile(rootDir, normalizedEntry);
|
|
1526
|
-
if (directSourceMatch) return directSourceMatch;
|
|
1527
|
-
const heuristicMatch = resolveEntryPathViaHeuristic(normalizedEntry, rootDir);
|
|
1528
|
-
if (heuristicMatch) return heuristicMatch;
|
|
1529
|
-
return absolutePath;
|
|
1530
|
-
};
|
|
1531
|
-
const extractPackageJsonEntries = async (packageJsonPath) => {
|
|
1532
|
-
const entries = [];
|
|
1533
|
-
try {
|
|
1534
|
-
const content = await readFile(packageJsonPath, "utf-8");
|
|
1535
|
-
const packageJson = JSON.parse(content);
|
|
1536
|
-
const rootDir = packageJsonPath.replace(/\/package\.json$/, "");
|
|
1537
|
-
for (const field of [
|
|
1538
|
-
"main",
|
|
1539
|
-
"module",
|
|
1540
|
-
"browser",
|
|
1541
|
-
"types",
|
|
1542
|
-
"typings",
|
|
1543
|
-
"style",
|
|
1544
|
-
"source"
|
|
1545
|
-
]) if (typeof packageJson[field] === "string") entries.push(resolveEntryPath(packageJson[field], rootDir));
|
|
1546
|
-
if (packageJson.exports) {
|
|
1547
|
-
const exportEntries = [];
|
|
1548
|
-
collectExportPaths(packageJson.exports, rootDir, exportEntries);
|
|
1549
|
-
for (const exportEntry of exportEntries) {
|
|
1550
|
-
const resolvedExportEntry = resolveEntryWithExtensions(exportEntry) ?? resolveEntryPathWithExtensions(exportEntry, rootDir) ?? resolveSourcePath(exportEntry, rootDir);
|
|
1551
|
-
if (resolvedExportEntry && existsSync(resolvedExportEntry)) {
|
|
1552
|
-
entries.push(resolvedExportEntry);
|
|
1553
|
-
continue;
|
|
1554
|
-
}
|
|
1555
|
-
if (exportEntry.endsWith(".ts")) {
|
|
1556
|
-
const tsxFallback = exportEntry.replace(/\.ts$/, ".tsx");
|
|
1557
|
-
if (existsSync(tsxFallback)) {
|
|
1558
|
-
entries.push(tsxFallback);
|
|
1559
|
-
continue;
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
if (existsSync(exportEntry)) entries.push(exportEntry);
|
|
1563
|
-
else entries.push(resolveEntryPath(exportEntry, rootDir));
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
if (packageJson.bin) {
|
|
1567
|
-
if (typeof packageJson.bin === "string") entries.push(resolveEntryPath(packageJson.bin, rootDir));
|
|
1568
|
-
else if (typeof packageJson.bin === "object") {
|
|
1569
|
-
for (const binPath of Object.values(packageJson.bin)) if (typeof binPath === "string") entries.push(resolveEntryPath(binPath, rootDir));
|
|
1570
|
-
}
|
|
1571
|
-
}
|
|
1572
|
-
if (Array.isArray(packageJson.sideEffects)) for (const sideEffectPattern of packageJson.sideEffects) {
|
|
1573
|
-
if (typeof sideEffectPattern !== "string") continue;
|
|
1574
|
-
const sourcePatterns = expandSideEffectGlobToSourcePatterns(sideEffectPattern);
|
|
1575
|
-
for (const sourcePattern of sourcePatterns) {
|
|
1576
|
-
const matchedSideEffectFiles = fg.sync(sourcePattern, {
|
|
1577
|
-
cwd: rootDir,
|
|
1578
|
-
absolute: true,
|
|
1579
|
-
onlyFiles: true,
|
|
1580
|
-
ignore: [
|
|
1581
|
-
"**/node_modules/**",
|
|
1582
|
-
"**/dist/**",
|
|
1583
|
-
"**/build/**"
|
|
1584
|
-
]
|
|
1585
|
-
});
|
|
1586
|
-
for (const matchedSideEffectFile of matchedSideEffectFiles) if (isImportableSourceFile(matchedSideEffectFile)) entries.push(matchedSideEffectFile);
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1589
|
-
if (packageJson.build && typeof packageJson.build === "object") {
|
|
1590
|
-
const buildConfig = packageJson.build;
|
|
1591
|
-
if (Array.isArray(buildConfig.files)) for (const buildFileEntry of buildConfig.files) {
|
|
1592
|
-
if (typeof buildFileEntry !== "string") continue;
|
|
1593
|
-
if (buildFileEntry.includes("*")) continue;
|
|
1594
|
-
const resolvedBuildFile = resolveEntryWithExtensions(resolve(rootDir, buildFileEntry)) ?? resolveEntryPathWithExtensions(buildFileEntry, rootDir);
|
|
1595
|
-
if (resolvedBuildFile && existsSync(resolvedBuildFile)) entries.push(resolvedBuildFile);
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
if (packageJson.jest && typeof packageJson.jest === "object") {
|
|
1599
|
-
const jestRootDirMatches = JSON.stringify(packageJson.jest).matchAll(/<rootDir>\/([^"\\]+)/g);
|
|
1600
|
-
for (const jestRootDirMatch of jestRootDirMatches) {
|
|
1601
|
-
const resolvedJestFile = resolveEntryPathWithExtensions(jestRootDirMatch[1], rootDir);
|
|
1602
|
-
if (resolvedJestFile && existsSync(resolvedJestFile)) entries.push(resolvedJestFile);
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
|
-
} catch {}
|
|
1606
|
-
return entries;
|
|
1607
|
-
};
|
|
1608
|
-
const expandSideEffectGlobToSourcePatterns = (pattern) => {
|
|
1609
|
-
const patterns = new Set([pattern]);
|
|
1610
|
-
if (pattern.endsWith(".js")) {
|
|
1611
|
-
patterns.add(pattern.replace(/\.js$/, ".ts"));
|
|
1612
|
-
patterns.add(pattern.replace(/\.js$/, ".tsx"));
|
|
1613
|
-
}
|
|
1614
|
-
if (pattern.includes("/lib/") || pattern.startsWith("lib/")) patterns.add(pattern.replace(/\blib\b/g, "src"));
|
|
1615
|
-
if (pattern.includes("/esm/") || pattern.startsWith("esm/")) patterns.add(pattern.replace(/\besm\b/g, "src"));
|
|
1616
|
-
return [...patterns];
|
|
1617
|
-
};
|
|
1618
1661
|
const SHELL_OPERATORS_PATTERN = /\s*(?:&&|\|\||[;&|])\s*/;
|
|
1619
1662
|
const SCRIPT_MULTIPLEXERS = new Set([
|
|
1620
1663
|
"concurrently",
|
|
@@ -2575,30 +2618,6 @@ const extractTestSetupFiles = (directory) => {
|
|
|
2575
2618
|
} catch {}
|
|
2576
2619
|
return entries;
|
|
2577
2620
|
};
|
|
2578
|
-
const IMPORTABLE_EXTENSION_SET = new Set(SOURCE_EXTENSIONS$3.map((extension) => `.${extension}`));
|
|
2579
|
-
const isImportableSourceFile = (filePath) => IMPORTABLE_EXTENSION_SET.has(filePath.slice(filePath.lastIndexOf(".")));
|
|
2580
|
-
const expandWildcardExportPattern = (pattern, rootDir) => {
|
|
2581
|
-
const normalized = pattern.startsWith("./") ? pattern.slice(2) : pattern;
|
|
2582
|
-
return fg.sync(normalized, {
|
|
2583
|
-
cwd: rootDir,
|
|
2584
|
-
absolute: true,
|
|
2585
|
-
onlyFiles: true,
|
|
2586
|
-
ignore: ["**/node_modules/**"]
|
|
2587
|
-
}).filter(isImportableSourceFile);
|
|
2588
|
-
};
|
|
2589
|
-
const collectExportPaths = (exportValue, rootDir, entries) => {
|
|
2590
|
-
if (typeof exportValue === "string") {
|
|
2591
|
-
if (exportValue.includes("*")) {
|
|
2592
|
-
const expandedFiles = expandWildcardExportPattern(exportValue, rootDir);
|
|
2593
|
-
entries.push(...expandedFiles);
|
|
2594
|
-
return;
|
|
2595
|
-
}
|
|
2596
|
-
entries.push(resolveEntryPath(exportValue, rootDir));
|
|
2597
|
-
return;
|
|
2598
|
-
}
|
|
2599
|
-
if (typeof exportValue !== "object" || exportValue === null) return;
|
|
2600
|
-
for (const [, nestedValue] of Object.entries(exportValue)) collectExportPaths(nestedValue, rootDir, entries);
|
|
2601
|
-
};
|
|
2602
2621
|
const TEST_FRAMEWORK_PATTERNS = [
|
|
2603
2622
|
{
|
|
2604
2623
|
enablers: [
|