Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
npx pnpm lint
npx pnpm format:check
npx pnpm test
17 changes: 14 additions & 3 deletions packages/project/src/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ function readProjectTsconfig(
system: ts.System,
projectPath: string,
outDir: string,
logger: Logger
logger: Logger,
validateProjectTsCfg: boolean = true
): Record<string, unknown> {
const tsconfig = ts.findConfigFile("./", system.fileExists, "tsconfig.json");
if (!tsconfig) {
Expand All @@ -73,7 +74,9 @@ function readProjectTsconfig(
}

configJsonFile.config.compilerOptions ??= {};
validateProjectTsconfig(configJsonFile.config.compilerOptions, outDir);
if (validateProjectTsCfg) {
validateProjectTsconfig(configJsonFile.config.compilerOptions, outDir);
}
return configJsonFile.config;
}

Expand Down Expand Up @@ -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
*/
Expand All @@ -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<boolean> {
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);
}
6 changes: 5 additions & 1 deletion packages/project/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/commands/lib-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { logger } from "../logger.js";
const cmd = new Command("List libraries from project package.json", {
action: async (options: Record<string, string | boolean>) => {
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");
Expand Down
16 changes: 13 additions & 3 deletions packages/tools/src/commands/lib-install.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<string, string | boolean>, args: Record<string, string>) => {
action: async (options: Record<string, string | boolean>, args: Record<string, string>) => {
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) {
Expand All @@ -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,
});

Expand Down
1 change: 1 addition & 0 deletions test/project/compiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe("TypeScript Compiler", () => {
testData.inputPath,
logger,
undefined,
true,
testData.tsLibsPath
);

Expand Down
Loading