apdev-js 0.2.1 → 0.2.2
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/cli.js +20 -8
- package/dist/index.cjs +25 -13
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +18 -6
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -435,7 +435,18 @@ ${path2} contains illegal characters:`);
|
|
|
435
435
|
// src/check-imports.ts
|
|
436
436
|
import { readFileSync as readFileSync2, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
|
|
437
437
|
import { join as join2, relative, sep as sep2, extname as extname2, basename } from "path";
|
|
438
|
-
|
|
438
|
+
var _ts;
|
|
439
|
+
async function loadTS() {
|
|
440
|
+
if (_ts) return _ts;
|
|
441
|
+
try {
|
|
442
|
+
_ts = (await import("typescript")).default;
|
|
443
|
+
return _ts;
|
|
444
|
+
} catch {
|
|
445
|
+
throw new Error(
|
|
446
|
+
"The 'typescript' package is required for circular import detection.\nInstall it with: npm install -g typescript\nOr locally: npm install -D typescript"
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
439
450
|
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
440
451
|
".ts",
|
|
441
452
|
".tsx",
|
|
@@ -464,7 +475,8 @@ function fileToModule(filePath, srcDir) {
|
|
|
464
475
|
}
|
|
465
476
|
return parts.join(".");
|
|
466
477
|
}
|
|
467
|
-
function extractImports(source, fileName) {
|
|
478
|
+
async function extractImports(source, fileName) {
|
|
479
|
+
const ts = await loadTS();
|
|
468
480
|
const imports = /* @__PURE__ */ new Set();
|
|
469
481
|
const sourceFile = ts.createSourceFile(
|
|
470
482
|
fileName,
|
|
@@ -539,7 +551,7 @@ function findSourceFiles(dir) {
|
|
|
539
551
|
walk(dir);
|
|
540
552
|
return results;
|
|
541
553
|
}
|
|
542
|
-
function buildDependencyGraph(srcDir, basePackage) {
|
|
554
|
+
async function buildDependencyGraph(srcDir, basePackage) {
|
|
543
555
|
const graph = /* @__PURE__ */ new Map();
|
|
544
556
|
const files = findSourceFiles(srcDir);
|
|
545
557
|
for (const file of files) {
|
|
@@ -554,7 +566,7 @@ function buildDependencyGraph(srcDir, basePackage) {
|
|
|
554
566
|
}
|
|
555
567
|
let rawImports;
|
|
556
568
|
try {
|
|
557
|
-
rawImports = extractImports(source, file);
|
|
569
|
+
rawImports = await extractImports(source, file);
|
|
558
570
|
} catch (e) {
|
|
559
571
|
console.error(`Warning: could not parse ${file}: ${e}`);
|
|
560
572
|
continue;
|
|
@@ -613,7 +625,7 @@ function findCycles(graph) {
|
|
|
613
625
|
}
|
|
614
626
|
return unique;
|
|
615
627
|
}
|
|
616
|
-
function checkCircularImports(srcDir, basePackage) {
|
|
628
|
+
async function checkCircularImports(srcDir, basePackage) {
|
|
617
629
|
let stat;
|
|
618
630
|
try {
|
|
619
631
|
stat = statSync2(srcDir);
|
|
@@ -625,7 +637,7 @@ function checkCircularImports(srcDir, basePackage) {
|
|
|
625
637
|
console.error(`Error: ${srcDir}/ is not a directory`);
|
|
626
638
|
return 1;
|
|
627
639
|
}
|
|
628
|
-
const graph = buildDependencyGraph(srcDir, basePackage);
|
|
640
|
+
const graph = await buildDependencyGraph(srcDir, basePackage);
|
|
629
641
|
console.log(`Scanned ${graph.size} modules`);
|
|
630
642
|
const cycles = findCycles(graph);
|
|
631
643
|
if (cycles.length > 0) {
|
|
@@ -705,7 +717,7 @@ function buildProgram() {
|
|
|
705
717
|
const code = checkPaths(resolved, ranges, dangerous);
|
|
706
718
|
process.exit(code);
|
|
707
719
|
});
|
|
708
|
-
program2.command("check-imports").description("Detect circular imports in a JS/TS package").option("--package <name>", "Base package name (e.g. mylib). Reads from package.json apdev config if omitted.").option("--src-dir <dir>", "Source directory containing the package (default: src)").action((opts) => {
|
|
720
|
+
program2.command("check-imports").description("Detect circular imports in a JS/TS package").option("--package <name>", "Base package name (e.g. mylib). Reads from package.json apdev config if omitted.").option("--src-dir <dir>", "Source directory containing the package (default: src)").action(async (opts) => {
|
|
709
721
|
const config = loadConfig();
|
|
710
722
|
const basePackage = opts.package ?? config["base_package"];
|
|
711
723
|
const srcDir = opts.srcDir ?? config["src_dir"] ?? "src";
|
|
@@ -715,7 +727,7 @@ function buildProgram() {
|
|
|
715
727
|
);
|
|
716
728
|
process.exit(1);
|
|
717
729
|
}
|
|
718
|
-
const code = checkCircularImports(resolve(srcDir), basePackage);
|
|
730
|
+
const code = await checkCircularImports(resolve(srcDir), basePackage);
|
|
719
731
|
process.exit(code);
|
|
720
732
|
});
|
|
721
733
|
program2.command("release").description("Interactive release automation (build, tag, GitHub release, npm publish)").option("-y, --yes", "Auto-accept all defaults (silent mode)").argument("[version]", "Version to release (auto-detected from package.json if omitted)").action((version, opts) => {
|
package/dist/index.cjs
CHANGED
|
@@ -481,7 +481,18 @@ ${path} contains illegal characters:`);
|
|
|
481
481
|
// src/check-imports.ts
|
|
482
482
|
var import_node_fs2 = require("fs");
|
|
483
483
|
var import_node_path2 = require("path");
|
|
484
|
-
var
|
|
484
|
+
var _ts;
|
|
485
|
+
async function loadTS() {
|
|
486
|
+
if (_ts) return _ts;
|
|
487
|
+
try {
|
|
488
|
+
_ts = (await import("typescript")).default;
|
|
489
|
+
return _ts;
|
|
490
|
+
} catch {
|
|
491
|
+
throw new Error(
|
|
492
|
+
"The 'typescript' package is required for circular import detection.\nInstall it with: npm install -g typescript\nOr locally: npm install -D typescript"
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
485
496
|
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
486
497
|
".ts",
|
|
487
498
|
".tsx",
|
|
@@ -510,26 +521,27 @@ function fileToModule(filePath, srcDir) {
|
|
|
510
521
|
}
|
|
511
522
|
return parts.join(".");
|
|
512
523
|
}
|
|
513
|
-
function extractImports(source, fileName) {
|
|
524
|
+
async function extractImports(source, fileName) {
|
|
525
|
+
const ts = await loadTS();
|
|
514
526
|
const imports = /* @__PURE__ */ new Set();
|
|
515
|
-
const sourceFile =
|
|
527
|
+
const sourceFile = ts.createSourceFile(
|
|
516
528
|
fileName,
|
|
517
529
|
source,
|
|
518
|
-
|
|
530
|
+
ts.ScriptTarget.Latest,
|
|
519
531
|
true,
|
|
520
|
-
fileName.endsWith(".tsx") || fileName.endsWith(".jsx") ?
|
|
532
|
+
fileName.endsWith(".tsx") || fileName.endsWith(".jsx") ? ts.ScriptKind.TSX : void 0
|
|
521
533
|
);
|
|
522
534
|
function visit(node) {
|
|
523
|
-
if (
|
|
535
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
524
536
|
imports.add(node.moduleSpecifier.text);
|
|
525
537
|
}
|
|
526
|
-
if (
|
|
538
|
+
if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
527
539
|
imports.add(node.moduleSpecifier.text);
|
|
528
540
|
}
|
|
529
|
-
if (
|
|
541
|
+
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.Identifier && node.expression.text === "require" && node.arguments.length === 1 && ts.isStringLiteral(node.arguments[0])) {
|
|
530
542
|
imports.add(node.arguments[0].text);
|
|
531
543
|
}
|
|
532
|
-
|
|
544
|
+
ts.forEachChild(node, visit);
|
|
533
545
|
}
|
|
534
546
|
visit(sourceFile);
|
|
535
547
|
return imports;
|
|
@@ -585,7 +597,7 @@ function findSourceFiles(dir) {
|
|
|
585
597
|
walk(dir);
|
|
586
598
|
return results;
|
|
587
599
|
}
|
|
588
|
-
function buildDependencyGraph(srcDir, basePackage) {
|
|
600
|
+
async function buildDependencyGraph(srcDir, basePackage) {
|
|
589
601
|
const graph = /* @__PURE__ */ new Map();
|
|
590
602
|
const files = findSourceFiles(srcDir);
|
|
591
603
|
for (const file of files) {
|
|
@@ -600,7 +612,7 @@ function buildDependencyGraph(srcDir, basePackage) {
|
|
|
600
612
|
}
|
|
601
613
|
let rawImports;
|
|
602
614
|
try {
|
|
603
|
-
rawImports = extractImports(source, file);
|
|
615
|
+
rawImports = await extractImports(source, file);
|
|
604
616
|
} catch (e) {
|
|
605
617
|
console.error(`Warning: could not parse ${file}: ${e}`);
|
|
606
618
|
continue;
|
|
@@ -659,7 +671,7 @@ function findCycles(graph) {
|
|
|
659
671
|
}
|
|
660
672
|
return unique;
|
|
661
673
|
}
|
|
662
|
-
function checkCircularImports(srcDir, basePackage) {
|
|
674
|
+
async function checkCircularImports(srcDir, basePackage) {
|
|
663
675
|
let stat;
|
|
664
676
|
try {
|
|
665
677
|
stat = (0, import_node_fs2.statSync)(srcDir);
|
|
@@ -671,7 +683,7 @@ function checkCircularImports(srcDir, basePackage) {
|
|
|
671
683
|
console.error(`Error: ${srcDir}/ is not a directory`);
|
|
672
684
|
return 1;
|
|
673
685
|
}
|
|
674
|
-
const graph = buildDependencyGraph(srcDir, basePackage);
|
|
686
|
+
const graph = await buildDependencyGraph(srcDir, basePackage);
|
|
675
687
|
console.log(`Scanned ${graph.size} modules`);
|
|
676
688
|
const cycles = findCycles(graph);
|
|
677
689
|
if (cycles.length > 0) {
|
package/dist/index.d.cts
CHANGED
|
@@ -57,11 +57,11 @@ declare function checkPaths(paths: string[], extraRanges?: [number, number][], d
|
|
|
57
57
|
/** Convert a file path to a dotted module name (relative to srcDir). */
|
|
58
58
|
declare function fileToModule(filePath: string, srcDir: string): string;
|
|
59
59
|
/** Build a module-to-module dependency graph for the given package. */
|
|
60
|
-
declare function buildDependencyGraph(srcDir: string, basePackage: string): Map<string, Set<string
|
|
60
|
+
declare function buildDependencyGraph(srcDir: string, basePackage: string): Promise<Map<string, Set<string>>>;
|
|
61
61
|
/** Find all elementary cycles in the dependency graph using DFS. */
|
|
62
62
|
declare function findCycles(graph: Map<string, Set<string>>): string[][];
|
|
63
63
|
/** Run circular import detection. Returns 0 if clean, 1 if cycles found. */
|
|
64
|
-
declare function checkCircularImports(srcDir: string, basePackage: string): number
|
|
64
|
+
declare function checkCircularImports(srcDir: string, basePackage: string): Promise<number>;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Configuration loading for apdev.
|
package/dist/index.d.ts
CHANGED
|
@@ -57,11 +57,11 @@ declare function checkPaths(paths: string[], extraRanges?: [number, number][], d
|
|
|
57
57
|
/** Convert a file path to a dotted module name (relative to srcDir). */
|
|
58
58
|
declare function fileToModule(filePath: string, srcDir: string): string;
|
|
59
59
|
/** Build a module-to-module dependency graph for the given package. */
|
|
60
|
-
declare function buildDependencyGraph(srcDir: string, basePackage: string): Map<string, Set<string
|
|
60
|
+
declare function buildDependencyGraph(srcDir: string, basePackage: string): Promise<Map<string, Set<string>>>;
|
|
61
61
|
/** Find all elementary cycles in the dependency graph using DFS. */
|
|
62
62
|
declare function findCycles(graph: Map<string, Set<string>>): string[][];
|
|
63
63
|
/** Run circular import detection. Returns 0 if clean, 1 if cycles found. */
|
|
64
|
-
declare function checkCircularImports(srcDir: string, basePackage: string): number
|
|
64
|
+
declare function checkCircularImports(srcDir: string, basePackage: string): Promise<number>;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Configuration loading for apdev.
|
package/dist/index.js
CHANGED
|
@@ -436,7 +436,18 @@ ${path2} contains illegal characters:`);
|
|
|
436
436
|
// src/check-imports.ts
|
|
437
437
|
import { readFileSync as readFileSync2, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
|
|
438
438
|
import { join as join2, relative, sep as sep2, extname as extname2, basename } from "path";
|
|
439
|
-
|
|
439
|
+
var _ts;
|
|
440
|
+
async function loadTS() {
|
|
441
|
+
if (_ts) return _ts;
|
|
442
|
+
try {
|
|
443
|
+
_ts = (await import("typescript")).default;
|
|
444
|
+
return _ts;
|
|
445
|
+
} catch {
|
|
446
|
+
throw new Error(
|
|
447
|
+
"The 'typescript' package is required for circular import detection.\nInstall it with: npm install -g typescript\nOr locally: npm install -D typescript"
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
440
451
|
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
441
452
|
".ts",
|
|
442
453
|
".tsx",
|
|
@@ -465,7 +476,8 @@ function fileToModule(filePath, srcDir) {
|
|
|
465
476
|
}
|
|
466
477
|
return parts.join(".");
|
|
467
478
|
}
|
|
468
|
-
function extractImports(source, fileName) {
|
|
479
|
+
async function extractImports(source, fileName) {
|
|
480
|
+
const ts = await loadTS();
|
|
469
481
|
const imports = /* @__PURE__ */ new Set();
|
|
470
482
|
const sourceFile = ts.createSourceFile(
|
|
471
483
|
fileName,
|
|
@@ -540,7 +552,7 @@ function findSourceFiles(dir) {
|
|
|
540
552
|
walk(dir);
|
|
541
553
|
return results;
|
|
542
554
|
}
|
|
543
|
-
function buildDependencyGraph(srcDir, basePackage) {
|
|
555
|
+
async function buildDependencyGraph(srcDir, basePackage) {
|
|
544
556
|
const graph = /* @__PURE__ */ new Map();
|
|
545
557
|
const files = findSourceFiles(srcDir);
|
|
546
558
|
for (const file of files) {
|
|
@@ -555,7 +567,7 @@ function buildDependencyGraph(srcDir, basePackage) {
|
|
|
555
567
|
}
|
|
556
568
|
let rawImports;
|
|
557
569
|
try {
|
|
558
|
-
rawImports = extractImports(source, file);
|
|
570
|
+
rawImports = await extractImports(source, file);
|
|
559
571
|
} catch (e) {
|
|
560
572
|
console.error(`Warning: could not parse ${file}: ${e}`);
|
|
561
573
|
continue;
|
|
@@ -614,7 +626,7 @@ function findCycles(graph) {
|
|
|
614
626
|
}
|
|
615
627
|
return unique;
|
|
616
628
|
}
|
|
617
|
-
function checkCircularImports(srcDir, basePackage) {
|
|
629
|
+
async function checkCircularImports(srcDir, basePackage) {
|
|
618
630
|
let stat;
|
|
619
631
|
try {
|
|
620
632
|
stat = statSync2(srcDir);
|
|
@@ -626,7 +638,7 @@ function checkCircularImports(srcDir, basePackage) {
|
|
|
626
638
|
console.error(`Error: ${srcDir}/ is not a directory`);
|
|
627
639
|
return 1;
|
|
628
640
|
}
|
|
629
|
-
const graph = buildDependencyGraph(srcDir, basePackage);
|
|
641
|
+
const graph = await buildDependencyGraph(srcDir, basePackage);
|
|
630
642
|
console.log(`Scanned ${graph.size} modules`);
|
|
631
643
|
const cycles = findCycles(graph);
|
|
632
644
|
if (cycles.length > 0) {
|
package/package.json
CHANGED