diff --git a/.husky/pre-commit b/.husky/pre-commit index 46d9e90..b9b7350 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,2 +1,3 @@ npx pnpm lint npx pnpm format:check +npx pnpm test diff --git a/packages/project/src/compiler/index.ts b/packages/project/src/compiler/index.ts index d110096..8079ea5 100644 --- a/packages/project/src/compiler/index.ts +++ b/packages/project/src/compiler/index.ts @@ -59,7 +59,8 @@ function readProjectTsconfig( system: ts.System, projectPath: string, outDir: string, - logger: Logger + logger: Logger, + validateProjectTsCfg: boolean = true ): Record { const tsconfig = ts.findConfigFile("./", system.fileExists, "tsconfig.json"); if (!tsconfig) { @@ -73,7 +74,9 @@ function readProjectTsconfig( } configJsonFile.config.compilerOptions ??= {}; - validateProjectTsconfig(configJsonFile.config.compilerOptions, outDir); + if (validateProjectTsCfg) { + validateProjectTsconfig(configJsonFile.config.compilerOptions, outDir); + } return configJsonFile.config; } @@ -159,6 +162,7 @@ export async function compileProjectTsconfig( * @param projectPath Path to the project directory (should contain tsconfig.json) * @param logger Logger for outputting messages and diagnostics * @param noCheck If true, compiles without type checking, emitting JavaScript even if there are type errors + * @param validateProjectTsCfg If true, validates the project's tsconfig.json * @param tsLibsPath Optional path to TypeScript libraries (lib.d.ts, etc.), defaults to the directory of the installed TypeScript package * @returns Promise that resolves to true if compilation succeeded */ @@ -167,13 +171,20 @@ export async function compileProjectPath( projectPath: string, logger: Logger, noCheck: boolean = false, + validateProjectTsCfg: boolean = true, tsLibsPath: string = path.dirname( fileURLToPath(import.meta.resolve?.("typescript") ?? "typescript") ) ): Promise { const outDir = "build"; const system = tsvfs.createSystem(fs, projectPath); - const configJson = readProjectTsconfig(system, projectPath, outDir, logger); + const configJson = readProjectTsconfig( + system, + projectPath, + outDir, + logger, + validateProjectTsCfg + ); return await compileProjectTsconfig(configJson, system, logger, noCheck, tsLibsPath); } diff --git a/packages/project/src/registry.ts b/packages/project/src/registry.ts index 7467ba5..d5c0d32 100644 --- a/packages/project/src/registry.ts +++ b/packages/project/src/registry.ts @@ -78,10 +78,14 @@ export class Registry { constructor( registryUri: string[] | undefined, public getRequest: RequestFunction, - logger: Logger + logger: Logger, + userRegistry?: string ) { this.registryUri = registryUri || DefaultRegistryUrl; this.logger = logger; + if (userRegistry) { + this.registryUri.unshift(userRegistry); + } } // return list of objects with id and description of all packages in the registry, excluding templates diff --git a/packages/tools/src/commands/lib-build.ts b/packages/tools/src/commands/lib-build.ts index cdd3707..2a86a28 100644 --- a/packages/tools/src/commands/lib-build.ts +++ b/packages/tools/src/commands/lib-build.ts @@ -6,7 +6,7 @@ import { logger } from "../logger.js"; const cmd = new Command("List libraries from project package.json", { action: async (options: Record) => { const noCheck = options["no-check"] as boolean; - if (await compileProjectPath(fs, process.cwd(), logger, noCheck)) { + if (await compileProjectPath(fs, process.cwd(), logger, noCheck, false)) { logger.info("Compiled successfully\n"); } else { logger.error("Compilation failed\n"); diff --git a/packages/tools/src/commands/lib-install.ts b/packages/tools/src/commands/lib-install.ts index 5e355d8..1dc8909 100644 --- a/packages/tools/src/commands/lib-install.ts +++ b/packages/tools/src/commands/lib-install.ts @@ -1,4 +1,4 @@ -import { Arg, Command } from "./lib/command.js"; +import { Arg, Command, Opt } from "./lib/command.js"; import fs from "fs"; import { uriRequest } from "../util.js"; import path from "path"; @@ -8,13 +8,15 @@ import { Registry } from "@jaculus/project/registry"; import { logger } from "../logger.js"; const cmd = new Command("Install Jaculus libraries base on project's package.json", { - action: async (_options: Record, args: Record) => { + action: async (options: Record, args: Record) => { const libraryName = args["library"] as string; + const userRegistry = options["user-registry"] as string | undefined; const projectPath = process.cwd(); const pkg = await loadPackageJson(fs, path.join(projectPath, "package.json")); const project = new Project(fs, projectPath, logger); - const registry = new Registry(pkg.jaculus?.registry, uriRequest, logger); + + const registry = new Registry(pkg.jaculus?.registry, uriRequest, logger, userRegistry); const { name, version } = splitLibraryNameVersion(libraryName); if (name && version) { @@ -32,6 +34,14 @@ const cmd = new Command("Install Jaculus libraries base on project's package.jso { defaultValue: "" } ), ], + options: { + "user-registry": new Opt( + `Preferred registry URI. If a package exists in multiple registries, this one is used first.`, + { + required: false, + } + ), + }, chainable: true, }); diff --git a/test/project/compiler.test.ts b/test/project/compiler.test.ts index d3f65cf..f980380 100644 --- a/test/project/compiler.test.ts +++ b/test/project/compiler.test.ts @@ -87,6 +87,7 @@ describe("TypeScript Compiler", () => { testData.inputPath, logger, undefined, + true, testData.tsLibsPath );