Skip to content

Commit

Permalink
fix(js): mimic the behavior of tsc compilation for runTypeCheck (#9240)
Browse files Browse the repository at this point in the history
* fix(js): mimic the behavior of tsc compilation for runTypeCheck

ISSUES CLOSED: #9203

* chore(js): add check for type defs files in e2e

Co-authored-by: Chau Tran <ctran@Chaus-MacBook-Pro.local>
  • Loading branch information
2 people authored and FrozenPandaz committed Mar 21, 2022
1 parent ddb10e1 commit d778340
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
20 changes: 15 additions & 5 deletions e2e/js/src/js.test.ts
Expand Up @@ -48,7 +48,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 @@ -105,7 +107,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 @@ -117,6 +121,7 @@ describe('js e2e', () => {
updateFile(`libs/${parentLib}/src/index.ts`, () => {
return `
import { ${lib} } from '@${scope}/${lib}'
export * from './lib/${parentLib}';
`;
});

Expand Down Expand Up @@ -144,7 +149,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 @@ -164,7 +171,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 @@ -175,7 +184,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

0 comments on commit d778340

Please sign in to comment.