Skip to content

Commit a3cc928

Browse files
authored
Merge pull request #14 from jaculus-org/fix-lib-build
refactor: add validateProjectTsCfg parameter to readProjectTsconfig
2 parents 18234c3 + 016ac36 commit a3cc928

6 files changed

Lines changed: 35 additions & 8 deletions

File tree

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
npx pnpm lint
22
npx pnpm format:check
3+
npx pnpm test

packages/project/src/compiler/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ function readProjectTsconfig(
5959
system: ts.System,
6060
projectPath: string,
6161
outDir: string,
62-
logger: Logger
62+
logger: Logger,
63+
validateProjectTsCfg: boolean = true
6364
): Record<string, unknown> {
6465
const tsconfig = ts.findConfigFile("./", system.fileExists, "tsconfig.json");
6566
if (!tsconfig) {
@@ -73,7 +74,9 @@ function readProjectTsconfig(
7374
}
7475

7576
configJsonFile.config.compilerOptions ??= {};
76-
validateProjectTsconfig(configJsonFile.config.compilerOptions, outDir);
77+
if (validateProjectTsCfg) {
78+
validateProjectTsconfig(configJsonFile.config.compilerOptions, outDir);
79+
}
7780
return configJsonFile.config;
7881
}
7982

@@ -159,6 +162,7 @@ export async function compileProjectTsconfig(
159162
* @param projectPath Path to the project directory (should contain tsconfig.json)
160163
* @param logger Logger for outputting messages and diagnostics
161164
* @param noCheck If true, compiles without type checking, emitting JavaScript even if there are type errors
165+
* @param validateProjectTsCfg If true, validates the project's tsconfig.json
162166
* @param tsLibsPath Optional path to TypeScript libraries (lib.d.ts, etc.), defaults to the directory of the installed TypeScript package
163167
* @returns Promise that resolves to true if compilation succeeded
164168
*/
@@ -167,13 +171,20 @@ export async function compileProjectPath(
167171
projectPath: string,
168172
logger: Logger,
169173
noCheck: boolean = false,
174+
validateProjectTsCfg: boolean = true,
170175
tsLibsPath: string = path.dirname(
171176
fileURLToPath(import.meta.resolve?.("typescript") ?? "typescript")
172177
)
173178
): Promise<boolean> {
174179
const outDir = "build";
175180
const system = tsvfs.createSystem(fs, projectPath);
176-
const configJson = readProjectTsconfig(system, projectPath, outDir, logger);
181+
const configJson = readProjectTsconfig(
182+
system,
183+
projectPath,
184+
outDir,
185+
logger,
186+
validateProjectTsCfg
187+
);
177188

178189
return await compileProjectTsconfig(configJson, system, logger, noCheck, tsLibsPath);
179190
}

packages/project/src/registry.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ export class Registry {
7878
constructor(
7979
registryUri: string[] | undefined,
8080
public getRequest: RequestFunction,
81-
logger: Logger
81+
logger: Logger,
82+
userRegistry?: string
8283
) {
8384
this.registryUri = registryUri || DefaultRegistryUrl;
8485
this.logger = logger;
86+
if (userRegistry) {
87+
this.registryUri.unshift(userRegistry);
88+
}
8589
}
8690

8791
// return list of objects with id and description of all packages in the registry, excluding templates

packages/tools/src/commands/lib-build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { logger } from "../logger.js";
66
const cmd = new Command("List libraries from project package.json", {
77
action: async (options: Record<string, string | boolean>) => {
88
const noCheck = options["no-check"] as boolean;
9-
if (await compileProjectPath(fs, process.cwd(), logger, noCheck)) {
9+
if (await compileProjectPath(fs, process.cwd(), logger, noCheck, false)) {
1010
logger.info("Compiled successfully\n");
1111
} else {
1212
logger.error("Compilation failed\n");

packages/tools/src/commands/lib-install.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Arg, Command } from "./lib/command.js";
1+
import { Arg, Command, Opt } from "./lib/command.js";
22
import fs from "fs";
33
import { uriRequest } from "../util.js";
44
import path from "path";
@@ -8,13 +8,15 @@ import { Registry } from "@jaculus/project/registry";
88
import { logger } from "../logger.js";
99

1010
const cmd = new Command("Install Jaculus libraries base on project's package.json", {
11-
action: async (_options: Record<string, string | boolean>, args: Record<string, string>) => {
11+
action: async (options: Record<string, string | boolean>, args: Record<string, string>) => {
1212
const libraryName = args["library"] as string;
13+
const userRegistry = options["user-registry"] as string | undefined;
1314
const projectPath = process.cwd();
1415

1516
const pkg = await loadPackageJson(fs, path.join(projectPath, "package.json"));
1617
const project = new Project(fs, projectPath, logger);
17-
const registry = new Registry(pkg.jaculus?.registry, uriRequest, logger);
18+
19+
const registry = new Registry(pkg.jaculus?.registry, uriRequest, logger, userRegistry);
1820

1921
const { name, version } = splitLibraryNameVersion(libraryName);
2022
if (name && version) {
@@ -32,6 +34,14 @@ const cmd = new Command("Install Jaculus libraries base on project's package.jso
3234
{ defaultValue: "" }
3335
),
3436
],
37+
options: {
38+
"user-registry": new Opt(
39+
`Preferred registry URI. If a package exists in multiple registries, this one is used first.`,
40+
{
41+
required: false,
42+
}
43+
),
44+
},
3545
chainable: true,
3646
});
3747

test/project/compiler.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ describe("TypeScript Compiler", () => {
8787
testData.inputPath,
8888
logger,
8989
undefined,
90+
true,
9091
testData.tsLibsPath
9192
);
9293

0 commit comments

Comments
 (0)