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

fix(js): mimic the behavior of tsc compilation for runTypeCheck #9240

Merged
merged 2 commits into from Mar 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions e2e/js/src/js.test.ts
Expand Up @@ -51,7 +51,9 @@ describe('js e2e', () => {
`dist/libs/${lib}/README.md`,
`dist/libs/${lib}/package.json`,
`dist/libs/${lib}/src/index.js`,
`dist/libs/${lib}/src/lib/${lib}.js`
`dist/libs/${lib}/src/lib/${lib}.js`,
`dist/libs/${lib}/src/index.d.ts`,
`dist/libs/${lib}/src/lib/${lib}.d.ts`
);

updateJson(`libs/${lib}/project.json`, (json) => {
Expand Down Expand Up @@ -108,7 +110,9 @@ describe('js e2e', () => {
checkFilesExist(
`dist/libs/${parentLib}/package.json`,
`dist/libs/${parentLib}/src/index.js`,
`dist/libs/${parentLib}/src/lib/${parentLib}.js`
`dist/libs/${parentLib}/src/lib/${parentLib}.js`,
`dist/libs/${parentLib}/src/index.d.ts`,
`dist/libs/${parentLib}/src/lib/${parentLib}.d.ts`
);

const tsconfig = readJson(`tsconfig.base.json`);
Expand All @@ -120,6 +124,7 @@ describe('js e2e', () => {
updateFile(`libs/${parentLib}/src/index.ts`, () => {
return `
import { ${lib} } from '@${scope}/${lib}'
export * from './lib/${parentLib}';
`;
});

Expand Down Expand Up @@ -172,7 +177,9 @@ describe('js e2e', () => {
checkFilesExist(
`dist/libs/${lib}/package.json`,
`dist/libs/${lib}/src/index.js`,
`dist/libs/${lib}/src/lib/${lib}.js`
`dist/libs/${lib}/src/lib/${lib}.js`,
`dist/libs/${lib}/src/index.d.ts`,
`dist/libs/${lib}/src/lib/${lib}.d.ts`
);

const parentLib = uniq('parentlib');
Expand All @@ -192,7 +199,9 @@ describe('js e2e', () => {
checkFilesExist(
`dist/libs/${parentLib}/package.json`,
`dist/libs/${parentLib}/src/index.js`,
`dist/libs/${parentLib}/src/lib/${parentLib}.js`
`dist/libs/${parentLib}/src/lib/${parentLib}.js`,
`dist/libs/${parentLib}/src/index.d.ts`,
`dist/libs/${parentLib}/src/lib/${parentLib}.d.ts`
);

const tsconfig = readJson(`tsconfig.base.json`);
Expand All @@ -203,7 +212,8 @@ describe('js e2e', () => {

updateFile(`libs/${parentLib}/src/index.ts`, () => {
return `
import { ${lib} } from '@${scope}/${lib}'
import { ${lib} } from '@${scope}/${lib}';
export * from './lib/${parentLib}';
`;
});

Expand Down
3 changes: 2 additions & 1 deletion packages/js/src/utils/swc/compile-swc.ts
Expand Up @@ -20,8 +20,9 @@ function getTypeCheckOptions(normalizedOptions: NormalizedSwcExecutorOptions) {
const typeCheckOptions: TypeCheckOptions = {
mode: 'emitDeclarationOnly',
tsConfigPath: tsConfig,
outDir: outputPath.replace(`/${projectRoot}`, ''),
outDir: outputPath,
workspaceRoot: root,
rootDir: projectRoot,
};

if (watch) {
Expand Down
5 changes: 4 additions & 1 deletion packages/js/src/utils/typescript/run-type-check.ts
Expand Up @@ -19,6 +19,7 @@ interface BaseTypeCheckOptions {
tsConfigPath: string;
cacheDir?: string;
incremental?: boolean;
rootDir?: string;
}

type Mode = NoEmitMode | EmitDeclarationOnlyMode;
Expand Down Expand Up @@ -116,7 +117,8 @@ export async function runTypeCheck(

async function setupTypeScript(options: TypeCheckOptions) {
const ts = await import('typescript');
const { workspaceRoot, tsConfigPath, cacheDir, incremental } = options;
const { workspaceRoot, tsConfigPath, cacheDir, incremental, rootDir } =
options;
const config = readTsConfig(tsConfigPath);
if (config.errors.length) {
throw new Error(`Invalid config file: ${config.errors}`);
Expand All @@ -132,6 +134,7 @@ async function setupTypeScript(options: TypeCheckOptions) {
skipLibCheck: true,
...emitOptions,
incremental,
rootDir: rootDir || config.options.rootDir,
};

return { ts, workspaceRoot, cacheDir, config, compilerOptions };
Expand Down