@tscircuit/cli 0.1.183 → 0.1.184
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/main.js +118 -47
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -434909,7 +434909,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
|
|
|
434909
434909
|
import { execSync as execSync2 } from "node:child_process";
|
|
434910
434910
|
var import_semver2 = __toESM2(require_semver2(), 1);
|
|
434911
434911
|
// package.json
|
|
434912
|
-
var version = "0.1.
|
|
434912
|
+
var version = "0.1.183";
|
|
434913
434913
|
var package_default = {
|
|
434914
434914
|
name: "@tscircuit/cli",
|
|
434915
434915
|
version,
|
|
@@ -438460,59 +438460,128 @@ import * as path16 from "node:path";
|
|
|
438460
438460
|
// lib/shared/get-entrypoint.ts
|
|
438461
438461
|
import * as fs12 from "node:fs";
|
|
438462
438462
|
import * as path13 from "node:path";
|
|
438463
|
+
var ALLOWED_ENTRYPOINT_NAMES = Object.freeze([
|
|
438464
|
+
"index.tsx",
|
|
438465
|
+
"index.ts",
|
|
438466
|
+
"index.circuit.tsx",
|
|
438467
|
+
"main.tsx",
|
|
438468
|
+
"main.circuit.tsx"
|
|
438469
|
+
]);
|
|
438470
|
+
var MAX_SEARCH_DEPTH = 3;
|
|
438471
|
+
var MAX_RESULTS = 100;
|
|
438472
|
+
var isValidDirectory = (dirPath, projectDir) => {
|
|
438473
|
+
const resolvedDir = path13.resolve(dirPath);
|
|
438474
|
+
const resolvedProject = path13.resolve(projectDir);
|
|
438475
|
+
return resolvedDir.startsWith(resolvedProject) && !resolvedDir.includes("..");
|
|
438476
|
+
};
|
|
438477
|
+
var findEntrypointsRecursively = (dir, projectDir, maxDepth = MAX_SEARCH_DEPTH, fileNames = ALLOWED_ENTRYPOINT_NAMES) => {
|
|
438478
|
+
if (maxDepth <= 0 || !isValidDirectory(dir, projectDir)) {
|
|
438479
|
+
return [];
|
|
438480
|
+
}
|
|
438481
|
+
const results = [];
|
|
438482
|
+
try {
|
|
438483
|
+
const entries = fs12.readdirSync(dir, { withFileTypes: true });
|
|
438484
|
+
for (const entry of entries) {
|
|
438485
|
+
if (results.length >= MAX_RESULTS)
|
|
438486
|
+
break;
|
|
438487
|
+
if (entry.isFile() && fileNames.includes(entry.name)) {
|
|
438488
|
+
const filePath = path13.resolve(dir, entry.name);
|
|
438489
|
+
if (isValidDirectory(filePath, projectDir)) {
|
|
438490
|
+
results.push(filePath);
|
|
438491
|
+
}
|
|
438492
|
+
}
|
|
438493
|
+
}
|
|
438494
|
+
for (const entry of entries) {
|
|
438495
|
+
if (results.length >= MAX_RESULTS)
|
|
438496
|
+
break;
|
|
438497
|
+
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") {
|
|
438498
|
+
const subdirPath = path13.resolve(dir, entry.name);
|
|
438499
|
+
if (isValidDirectory(subdirPath, projectDir)) {
|
|
438500
|
+
results.push(...findEntrypointsRecursively(subdirPath, projectDir, maxDepth - 1, fileNames));
|
|
438501
|
+
}
|
|
438502
|
+
}
|
|
438503
|
+
}
|
|
438504
|
+
} catch {
|
|
438505
|
+
return [];
|
|
438506
|
+
}
|
|
438507
|
+
return results;
|
|
438508
|
+
};
|
|
438509
|
+
var validateProjectDir = (projectDir) => {
|
|
438510
|
+
const resolvedDir = path13.resolve(projectDir);
|
|
438511
|
+
if (!fs12.existsSync(resolvedDir)) {
|
|
438512
|
+
throw new Error(`Project directory does not exist: ${projectDir}`);
|
|
438513
|
+
}
|
|
438514
|
+
return resolvedDir;
|
|
438515
|
+
};
|
|
438516
|
+
var validateFilePath = (filePath, projectDir) => {
|
|
438517
|
+
const absolutePath = path13.resolve(projectDir, filePath);
|
|
438518
|
+
if (!absolutePath.startsWith(path13.resolve(projectDir))) {
|
|
438519
|
+
return null;
|
|
438520
|
+
}
|
|
438521
|
+
if (absolutePath.includes("..")) {
|
|
438522
|
+
return null;
|
|
438523
|
+
}
|
|
438524
|
+
return fs12.existsSync(absolutePath) ? absolutePath : null;
|
|
438525
|
+
};
|
|
438463
438526
|
var getEntrypoint = async ({
|
|
438464
438527
|
filePath,
|
|
438465
438528
|
projectDir = process.cwd(),
|
|
438466
438529
|
onSuccess = (message) => console.log(message),
|
|
438467
438530
|
onError = (message) => console.error(message)
|
|
438468
438531
|
}) => {
|
|
438469
|
-
|
|
438470
|
-
const
|
|
438471
|
-
if (
|
|
438472
|
-
|
|
438473
|
-
|
|
438532
|
+
try {
|
|
438533
|
+
const validatedProjectDir = validateProjectDir(projectDir);
|
|
438534
|
+
if (filePath) {
|
|
438535
|
+
const validatedPath = validateFilePath(filePath, validatedProjectDir);
|
|
438536
|
+
if (validatedPath) {
|
|
438537
|
+
const relativePath = path13.relative(validatedProjectDir, validatedPath);
|
|
438538
|
+
onSuccess(`Using provided file: '${relativePath}'`);
|
|
438539
|
+
return validatedPath;
|
|
438540
|
+
}
|
|
438541
|
+
onError(kleur_default.red(`File not found or invalid: '${filePath}'`));
|
|
438542
|
+
return null;
|
|
438474
438543
|
}
|
|
438475
|
-
|
|
438476
|
-
|
|
438477
|
-
|
|
438478
|
-
|
|
438479
|
-
|
|
438480
|
-
|
|
438481
|
-
|
|
438482
|
-
|
|
438483
|
-
|
|
438484
|
-
|
|
438485
|
-
|
|
438486
|
-
|
|
438487
|
-
|
|
438488
|
-
|
|
438489
|
-
|
|
438490
|
-
|
|
438491
|
-
|
|
438492
|
-
|
|
438493
|
-
|
|
438494
|
-
|
|
438495
|
-
|
|
438496
|
-
|
|
438497
|
-
|
|
438498
|
-
|
|
438499
|
-
|
|
438500
|
-
path13.resolve(
|
|
438501
|
-
|
|
438502
|
-
|
|
438503
|
-
|
|
438504
|
-
|
|
438505
|
-
|
|
438506
|
-
|
|
438507
|
-
|
|
438508
|
-
|
|
438509
|
-
break;
|
|
438544
|
+
const projectConfig = loadProjectConfig(validatedProjectDir);
|
|
438545
|
+
if (projectConfig?.mainEntrypoint && typeof projectConfig.mainEntrypoint === "string") {
|
|
438546
|
+
const validatedConfigPath = validateFilePath(projectConfig.mainEntrypoint, validatedProjectDir);
|
|
438547
|
+
if (validatedConfigPath) {
|
|
438548
|
+
const relativePath = path13.relative(validatedProjectDir, validatedConfigPath);
|
|
438549
|
+
onSuccess(`Using entrypoint from tscircuit.config.json: '${relativePath}'`);
|
|
438550
|
+
return validatedConfigPath;
|
|
438551
|
+
}
|
|
438552
|
+
}
|
|
438553
|
+
const commonLocations = [
|
|
438554
|
+
"index.tsx",
|
|
438555
|
+
"index.ts",
|
|
438556
|
+
"index.circuit.tsx",
|
|
438557
|
+
"main.tsx",
|
|
438558
|
+
"main.circuit.tsx",
|
|
438559
|
+
"lib/index.tsx",
|
|
438560
|
+
"lib/index.ts",
|
|
438561
|
+
"lib/index.circuit.tsx",
|
|
438562
|
+
"lib/main.tsx",
|
|
438563
|
+
"lib/main.circuit.tsx",
|
|
438564
|
+
"src/index.tsx",
|
|
438565
|
+
"src/index.ts",
|
|
438566
|
+
"src/index.circuit.tsx",
|
|
438567
|
+
"src/main.tsx",
|
|
438568
|
+
"src/main.circuit.tsx"
|
|
438569
|
+
].map((location) => path13.resolve(validatedProjectDir, location));
|
|
438570
|
+
const recursiveEntrypoints = findEntrypointsRecursively(validatedProjectDir, validatedProjectDir);
|
|
438571
|
+
const possibleEntrypoints = [...commonLocations, ...recursiveEntrypoints];
|
|
438572
|
+
for (const entrypoint of possibleEntrypoints) {
|
|
438573
|
+
if (fs12.existsSync(entrypoint) && isValidDirectory(entrypoint, validatedProjectDir)) {
|
|
438574
|
+
const relativePath = path13.relative(validatedProjectDir, entrypoint);
|
|
438575
|
+
onSuccess(`Detected entrypoint: '${relativePath}'`);
|
|
438576
|
+
return entrypoint;
|
|
438577
|
+
}
|
|
438510
438578
|
}
|
|
438511
|
-
}
|
|
438512
|
-
if (!detectedEntrypoint) {
|
|
438513
438579
|
onError(kleur_default.red("No entrypoint found. Run 'tsci init' to bootstrap a basic project or specify a file with 'tsci push <file>'"));
|
|
438580
|
+
return null;
|
|
438581
|
+
} catch (error) {
|
|
438582
|
+
onError(kleur_default.red(`Error detecting entrypoint: ${error instanceof Error ? error.message : "Unknown error"}`));
|
|
438583
|
+
return null;
|
|
438514
438584
|
}
|
|
438515
|
-
return detectedEntrypoint;
|
|
438516
438585
|
};
|
|
438517
438586
|
|
|
438518
438587
|
// lib/utils/get-unscoped-package-name.ts
|
|
@@ -439339,11 +439408,12 @@ class DevServer {
|
|
|
439339
439408
|
typesHandler;
|
|
439340
439409
|
constructor({
|
|
439341
439410
|
port,
|
|
439342
|
-
componentFilePath
|
|
439411
|
+
componentFilePath,
|
|
439412
|
+
projectDir
|
|
439343
439413
|
}) {
|
|
439344
439414
|
this.port = port;
|
|
439345
439415
|
this.componentFilePath = componentFilePath;
|
|
439346
|
-
this.projectDir = path18.dirname(componentFilePath);
|
|
439416
|
+
this.projectDir = projectDir ?? path18.dirname(componentFilePath);
|
|
439347
439417
|
const projectConfig = loadProjectConfig(this.projectDir);
|
|
439348
439418
|
this.ignoredFiles = projectConfig?.ignoredFiles ?? [];
|
|
439349
439419
|
this.fsKy = distribution_default.create({
|
|
@@ -439565,7 +439635,8 @@ var registerDev = (program3) => {
|
|
|
439565
439635
|
}
|
|
439566
439636
|
const server2 = new DevServer({
|
|
439567
439637
|
port,
|
|
439568
|
-
componentFilePath: absolutePath
|
|
439638
|
+
componentFilePath: absolutePath,
|
|
439639
|
+
projectDir: process.cwd()
|
|
439569
439640
|
});
|
|
439570
439641
|
await server2.start();
|
|
439571
439642
|
const timeToStart = Date.now() - startTime;
|