Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jsii): configure outDir and rootDir for tsc #593

Merged
merged 6 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/jsii/lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class Compiler implements Emitter {

const prog = ts.createProgram({
rootNames: this.rootFiles.concat(_pathOfLibraries(this.compilerHost)),
options: COMPILER_OPTIONS,
options: {...COMPILER_OPTIONS, outDir: this.options.projectInfo.tscOutDir, rootDir: this.options.projectInfo.tscRootDir},
// Make the references absolute for the compiler
projectReferences: tsconf.references && tsconf.references.map(ref => ({ path: path.resolve(ref.path) })),
host: this.compilerHost
Expand All @@ -118,7 +118,12 @@ export class Compiler implements Emitter {
const projectRoot = this.options.projectInfo.projectRoot;
const host = ts.createWatchCompilerHost(
this.configPath,
{ ...COMPILER_OPTIONS, noEmitOnError: false },
{
...COMPILER_OPTIONS,
noEmitOnError: false,
outDir: this.options.projectInfo.tscOutDir,
rootDir: this.options.projectInfo.tscRootDir,
},
{ ...ts.sys, getCurrentDirectory() { return projectRoot; } }
);
if (!host.getDefaultLibLocation) {
Expand Down Expand Up @@ -188,10 +193,12 @@ export class Compiler implements Emitter {
lib: COMPILER_OPTIONS.lib && COMPILER_OPTIONS.lib.map(name => name.slice(4, name.length - 5)),
// Those int-enums, we need to output the names instead
module: COMPILER_OPTIONS.module && ts.ModuleKind[COMPILER_OPTIONS.module],
outDir: this.options.projectInfo.tscOutDir,
rootDir: this.options.projectInfo.tscRootDir,
target: COMPILER_OPTIONS.target && ts.ScriptTarget[COMPILER_OPTIONS.target],
jsx: COMPILER_OPTIONS.jsx && Case.snake(ts.JsxEmit[COMPILER_OPTIONS.jsx]),
},
include: ["**/*.ts"],
include: [this.options.projectInfo.tscRootDir ? `${this.options.projectInfo.tscRootDir}/**/*.ts` : "**/*.ts"],
exclude: ["node_modules"].concat(this.options.projectInfo.excludeTypescript),
// Change the references a little. We write 'originalpath' to the
// file under the 'path' key, which is the same as what the
Expand Down
4 changes: 4 additions & 0 deletions packages/jsii/lib/project-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface ProjectInfo {
readonly contributors?: ReadonlyArray<spec.Person>;
readonly excludeTypescript: string[];
readonly projectReferences?: boolean;
readonly tscOutDir?: string;
readonly tscRootDir?: string;
}

export async function loadProjectInfo(projectRoot: string, { fixPeerDependencies }: { fixPeerDependencies: boolean }): Promise<ProjectInfo> {
Expand Down Expand Up @@ -138,6 +140,8 @@ export async function loadProjectInfo(projectRoot: string, { fixPeerDependencies

excludeTypescript: (pkg.jsii && pkg.jsii.excludeTypescript) || [],
projectReferences: pkg.jsii && pkg.jsii.projectReferences,
tscOutDir: pkg.jsii && pkg.jsii.tscoutdir,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not call it tscOutDir in the jsii config as well?

(thinking aloud) does this make sense in package.json or should they be command-line arguments? I guess we're mirroring the tsconfig.json here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I named it according to the outdir variable but I am happy to rename it. I think this is something I want to configure for my project. I don't think there is much difference in configuring it inside the jsii block or in the scripts section ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd like to have options that'll land in tsconfig.json modeled in a separate namespace altogether:

/// package.json
{
  // ...
  "jsii": {
    // ...
    "tsc": {
      "outDir": "dist",
      "rootDir": "lib",
    },
    // ...
  },
  // ...
}

Then, I'd use the exact same name that is in tsconfig's compilerOptions block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great. I will update this.

tscRootDir: pkg.jsii && pkg.jsii.tscrootdir,
};
}

Expand Down
4 changes: 3 additions & 1 deletion packages/jsii/test/test.negatives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ function _makeProjectInfo(types: string): ProjectInfo {
transitiveDependencies: [],
bundleDependencies: {},
targets: {},
excludeTypescript: []
excludeTypescript: [],
tscOutDir: undefined,
tscRootDir: undefined,
};
}