Skip to content

Commit

Permalink
R CompilerOptions#project to tsConfig
Browse files Browse the repository at this point in the history
fixes #53
  • Loading branch information
jwloka committed Jan 25, 2025
1 parent 4d6ff4a commit 3895f8e
Show file tree
Hide file tree
Showing 22 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion packages/compiler/src/CompilerArguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CompilerOptions } from "@quatico/websmith-core";
* Licensed under the MIT License. See LICENSE in the project root for license information.
* ---------------------------------------------------------------------------------------------
*/
export interface CompilerArguments extends Partial<Omit<CompilerOptions, "tsconfig" | "reporter" | "project" | "additionalArguments" | "targets">> {
export interface CompilerArguments extends Partial<Omit<CompilerOptions, "cliArgs" | "reporter" | "tsConfig" | "additionalArguments" | "targets">> {
targets?: string;
files?: string[];
project?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/src/command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("addCompileCommand", () => {
outDir: "/lib",
sourceMap: false,
};
expect(actual.project).toEqual(compilerOptions);
expect(actual.tsConfig).toEqual(compilerOptions);

expect({ wildcardDirectories: {}, ...actual.cliArgs }).toEqual({
options: compilerOptions,
Expand Down Expand Up @@ -116,7 +116,7 @@ describe("addCompileCommand", () => {

addCompileCommand(new Command(), target).parse(["--project", "expected/tsconfig.json"], { from: "user" });

expect(target.getOptions().project.configFilePath).toEqual(expect.stringContaining("/expected/tsconfig.json"));
expect(target.getOptions().tsConfig.configFilePath).toEqual(expect.stringContaining("/expected/tsconfig.json"));
});

it("should yield sourceMap option w/ --sourceMap cli argument", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/src/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("createOptions", () => {
},
});

const actual = createOptions({ project: "./expected/tsconfig.json" }, new NoReporter(), target).project;
const actual = createOptions({ project: "./expected/tsconfig.json" }, new NoReporter(), target).tsConfig;

expect(actual).toEqual({
configFilePath: "/expected/tsconfig.json",
Expand Down Expand Up @@ -109,7 +109,7 @@ describe("createOptions", () => {
addons: ["one", "two"],
addonsDir: "/expected",
},
project: {
tsConfig: {
configFilePath: "/tsconfig.json",
outDir: "/lib",
},
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const createOptions = (args: CompilerArguments, reporter = new NoReporter
// TODO: Do we need lib files, or is injecting them into the system sufficient?
// files?: Record<string, string>;
cliArgs: tsConfig,
project: tsConfig.options,
tsConfig: tsConfig.options,
reporter,
sourceMap: args.sourceMap ?? DEFAULTS.sourceMap,
targets: resolveTargets(targets, compilationConfig, reporter),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/compiler/Compiler.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("end-2-end compile", () => {

const actual = new Compiler(
compileOptions(target, {
project: { outDir: "./bin" },
tsConfig: { outDir: "./bin" },
}),
target
).compile();
Expand Down
50 changes: 25 additions & 25 deletions packages/core/src/compiler/Compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe("getSystem", () => {
describe("setOptions", () => {
it("replaces compiler options", () => {
const expected = {
project: {
tsConfig: {
react: 1,
},
} as unknown as CompilerOptions;
Expand All @@ -78,7 +78,7 @@ describe("setOptions", () => {
}).getSourceFile("src/target.ts");

new CompilerTestClass(
compileOptions(target, { project: { outDir: "/expected" }, cliArgs: { fileNames: [entry!.fileName] } }),
compileOptions(target, { tsConfig: { outDir: "/expected" }, cliArgs: { fileNames: [entry!.fileName] } }),
target
).watch();

Expand Down Expand Up @@ -183,7 +183,7 @@ describe("compile", () => {
sourceMap: false,
transpileOnly: false,
watch: false,
project: {
tsConfig: {
module: ts.ModuleKind.ESNext,
target: ts.ScriptTarget.Latest,
configFilePath: "./tsconfig.json",
Expand Down Expand Up @@ -212,7 +212,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("src/target.ts");
const target = compileOptions(fileSystem, {
project: { declaration: true },
tsConfig: { declaration: true },
cliArgs: { fileNames: [entry!.fileName] },
});

Expand All @@ -235,7 +235,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("src/target.ts");
const target = compileOptions(fileSystem, {
project: { declaration: true },
tsConfig: { declaration: true },
cliArgs: { fileNames: [entry!.fileName] },
});

Expand All @@ -258,7 +258,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("src/target.ts");
const target = compileOptions(fileSystem, {
project: { declaration: false, sourceMap: false },
tsConfig: { declaration: false, sourceMap: false },
cliArgs: { fileNames: [entry!.fileName] },
transpileOnly: true,
});
Expand All @@ -279,7 +279,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("src/target.ts");
const target = compileOptions(fileSystem, {
project: { declaration: true, declarationMap: false, sourceMap: false },
tsConfig: { declaration: true, declarationMap: false, sourceMap: false },
cliArgs: { fileNames: [entry!.fileName] },
sourceMap: true,
transpileOnly: true,
Expand All @@ -301,7 +301,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("src/target.ts");
const target = compileOptions(fileSystem, {
project: { declaration: true, declarationMap: true, sourceMap: false },
tsConfig: { declaration: true, declarationMap: true, sourceMap: false },
cliArgs: { fileNames: [entry!.fileName] },
sourceMap: true,
transpileOnly: true,
Expand All @@ -323,7 +323,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("src/target.ts");
const target = compileOptions(fileSystem, {
project: { declaration: false, declarationMap: false, sourceMap: true },
tsConfig: { declaration: false, declarationMap: false, sourceMap: true },
cliArgs: { fileNames: [entry!.fileName] },
sourceMap: true,
transpileOnly: true,
Expand All @@ -348,7 +348,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("src/target.ts");
const target = compileOptions(fileSystem, {
project: { declaration: false, sourceMap: false },
tsConfig: { declaration: false, sourceMap: false },
cliArgs: { fileNames: [entry!.fileName] },
});

Expand All @@ -368,7 +368,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("src/target.ts");
const target = compileOptions(fileSystem, {
project: { declaration: true, declarationMap: false, sourceMap: false },
tsConfig: { declaration: true, declarationMap: false, sourceMap: false },
cliArgs: { fileNames: [entry!.fileName] },
sourceMap: true,
});
Expand All @@ -393,7 +393,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("src/target.ts");
const target = compileOptions(fileSystem, {
project: { declaration: true, declarationMap: true, sourceMap: false },
tsConfig: { declaration: true, declarationMap: true, sourceMap: false },
cliArgs: { fileNames: [entry!.fileName] },
sourceMap: true,
});
Expand Down Expand Up @@ -421,7 +421,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("src/target.ts");
const target = compileOptions(fileSystem, {
project: { declaration: false, declarationMap: false, sourceMap: true },
tsConfig: { declaration: false, declarationMap: false, sourceMap: true },
cliArgs: { fileNames: [entry!.fileName] },
sourceMap: true,
});
Expand All @@ -445,7 +445,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("src/target.ts");
const target = compileOptions(fileSystem, {
project: { declaration: false, declarationMap: false, sourceMap: false },
tsConfig: { declaration: false, declarationMap: false, sourceMap: false },
cliArgs: { fileNames: [entry!.fileName] },
sourceMap: true,
transpileOnly: true,
Expand All @@ -467,7 +467,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("src/target.ts");
const target = compileOptions(fileSystem, {
project: { declaration: false, declarationMap: false, sourceMap: false },
tsConfig: { declaration: false, declarationMap: false, sourceMap: false },
cliArgs: { fileNames: [entry!.fileName] },
sourceMap: true,
});
Expand All @@ -486,7 +486,7 @@ describe("emitSourceFile", () => {
"src/config.json": `{"name":"test"}`,
}).getSourceFile("src/config.json");
const target = compileOptions(fileSystem, {
project: {
tsConfig: {
declaration: false,
declarationMap: false,
sourceMap: false,
Expand All @@ -509,7 +509,7 @@ describe("emitSourceFile", () => {
"src/config.json": `{"name":"test"}`,
}).getSourceFile("src/config.json");
const target = compileOptions(fileSystem, {
project: {
tsConfig: {
declaration: false,
declarationMap: false,
sourceMap: false,
Expand Down Expand Up @@ -538,7 +538,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("types/style.d.ts");
const target = compileOptions(fileSystem, {
project: {
tsConfig: {
declaration: false,
declarationMap: false,
sourceMap: false,
Expand Down Expand Up @@ -567,7 +567,7 @@ describe("emitSourceFile", () => {
`,
}).getSourceFile("types/style.d.ts");
const target = compileOptions(fileSystem, {
project: {
tsConfig: {
declaration: false,
declarationMap: false,
sourceMap: false,
Expand Down Expand Up @@ -675,7 +675,7 @@ describe("watch", () => {
configFilePath: "/fake/websmith.config.json",
targets: { "*": { writeFile: true } },
},
project: { declaration: true, outDir: "/build" },
tsConfig: { declaration: true, outDir: "/build" },
cliArgs: { fileNames: [entry!.fileName] },
watch: true,
});
Expand Down Expand Up @@ -707,7 +707,7 @@ describe("watch", () => {
configFilePath: "/fake/websmith.config.json",
targets: { "*": { writeFile: true, options: { outDir: "/build" } } },
},
project: { declaration: true },
tsConfig: { declaration: true },
cliArgs: { options: { outDir: "/build" }, fileNames: [entry!.fileName] },
watch: true,
});
Expand Down Expand Up @@ -742,7 +742,7 @@ describe("watch", () => {
target2: { writeFile: true, options: { outDir: "/target2", declaration: false } },
},
},
project: { declaration: true },
tsConfig: { declaration: true },
targets: ["target1", "target2"],
cliArgs: { options: { outDir: "/build" }, fileNames: [entry!.fileName] },
watch: true,
Expand Down Expand Up @@ -786,7 +786,7 @@ describe("watch", () => {
},
},
},
project: { declaration: true },
tsConfig: { declaration: true },
targets: ["target1", "target2"],
cliArgs: { options: { outDir: "/build" }, fileNames: [entry!.fileName] },
transpileOnly: true,
Expand Down Expand Up @@ -837,7 +837,7 @@ describe("watch", () => {
target1: { writeFile: true, options: { outDir: "/target1" } },
},
},
project: { declaration: true },
tsConfig: { declaration: true },
targets: ["target1"],
cliArgs: {
options: { outDir: "/build" },
Expand Down Expand Up @@ -889,7 +889,7 @@ describe("watch", () => {
target1: { writeFile: true, options: { outDir: "/target1" } },
},
},
project: { declaration: true },
tsConfig: { declaration: true },
targets: ["target1"],
cliArgs: { options: { outDir: "/build" }, fileNames: [entry!.fileName] },
watch: true,
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/compiler/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ export class Compiler {
target?: string,
registerDependencyCallback?: (filePath: string) => void
): CompilationContext {
const { buildDir, config, configFile, project, cliArgs, watch } = compileOptions;
const { buildDir, config, configFile, tsConfig, cliArgs, watch } = compileOptions;
const { options = {}, config: targetConfig } = getTargetConfig(target, config);
return new CompilationContext({
buildDir,
project: { ...project, ...options },
tsConfig: { ...tsConfig, ...options },
projectDir: dirname(configFile ?? cliArgs.raw?.configFilePath ?? this.system.getCurrentDirectory()),
system: this.system,
program: ts.createProgram({ rootNames: this.getRootFiles(), options: project, host: createCompileHost(project) }),
cliArgs: { ...cliArgs, options: { ...project, ...options } },
program: ts.createProgram({ rootNames: this.getRootFiles(), options: tsConfig, host: createCompileHost(tsConfig) }),
cliArgs: { ...cliArgs, options: { ...tsConfig, ...options } },
rootFiles: this.getRootFiles(),
reporter: this.reporter,
...(!!targetConfig && { config: targetConfig }),
Expand Down Expand Up @@ -344,7 +344,7 @@ export class Compiler {

private transpileJson({ ctx, fileName, content }: CompilationFragment) {
// JSON are only output by TypoScript if an outDir is provided, otherwise they are ignored.
if (this.options.project.outDir !== undefined) {
if (this.options.tsConfig.outDir !== undefined) {
const fileNames = ts.getOutputFileNames(ctx.getConfig(), fileName, !this.system.useCaseSensitiveFileNames);
return { outputFiles: [{ name: fileNames[0], text: content, writeByteOrderMark: false }], emitSkipped: false };
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/compiler/CompilerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface CompilerOptions {
configFile?: string;
debug?: boolean;
cliArgs: ts.ParsedCommandLine;
project: ts.CompilerOptions;
tsConfig: ts.CompilerOptions;
reporter: Reporter;
sourceMap?: boolean;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ beforeEach(() => {
testProgram = ts.createProgram({ options: {}, rootNames: [] });
testObj = new CompilationContextTestClass({
buildDir: "",
project: {},
tsConfig: {},
projectDir: testSystem.getCurrentDirectory(),
reporter: new ReporterMock(testSystem),
rootFiles: [],
Expand Down Expand Up @@ -182,7 +182,7 @@ describe("resolvePath", () => {
beforeEach(() => {
testObj = new CompilationContextTestClass({
buildDir: "",
project: {},
tsConfig: {},
projectDir: "/expected",
reporter: new ReporterMock(testSystem),
rootFiles: [],
Expand Down Expand Up @@ -271,7 +271,7 @@ describe("addAssetDependency", () => {
const target = jest.fn();
testObj = new CompilationContextTestClass({
buildDir: "",
project: {},
tsConfig: {},
projectDir: testSystem.getCurrentDirectory(),
reporter: new ReporterMock(testSystem),
rootFiles: [],
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/compiler/compilation/CompilationContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type CompilationContextOptions = {
buildDir: string;
config?: unknown;
program: ts.Program;
project: ts.CompilerOptions;
tsConfig: ts.CompilerOptions;
projectDir: string;
reporter: Reporter;
rootFiles: string[];
Expand Down Expand Up @@ -50,7 +50,7 @@ export class CompilationContext implements AddonContext {
private assetCodeDependency: Map<string, string[]> = new Map();

constructor(options: CompilationContextOptions) {
const { buildDir, config, program, project, projectDir, rootFiles, system, target, cliArgs, watchCallback, registerDependencyCallback } =
const { buildDir, config, program, tsConfig, projectDir, rootFiles, system, target, cliArgs, watchCallback, registerDependencyCallback } =
options;
this.buildDir = buildDir;
this.rootFiles = rootFiles;
Expand All @@ -61,7 +61,7 @@ export class CompilationContext implements AddonContext {
this.generators = [];
this.languageHost = this.createLanguageServiceHost({
system,
options: project,
options: tsConfig,
target,
});
this.cache = new FileCache(system);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/compile-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export const compileOptions = (
transpileOnly: false,
watch: false,
...overrides,
project: {
tsConfig: {
module: ts.ModuleKind.ESNext,
target: ts.ScriptTarget.Latest,
configFilePath: "./tsconfig.json",
...overrides?.project,
...overrides?.tsConfig,
},
targets: overrides?.targets ?? ["*"],
cliArgs: {
Expand Down
Loading

0 comments on commit 3895f8e

Please sign in to comment.