Skip to content

Commit

Permalink
fix: filter import errors and close TypeStrong#653
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland Groza committed Oct 8, 2018
1 parent 5490e9d commit 79d9c91
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
formatErrors,
getAndCacheOutputJSFileName,
getAndCacheProjectReference,
noImportError,
validateSourceMapOncePerProject
} from './utils';

Expand Down Expand Up @@ -475,7 +476,7 @@ function getTranspilationEmit(
loaderContext.context
);

loaderContext._module.errors.push(...errors);
loaderContext._module.errors.push(...errors.filter(noImportError));
}

return { outputText, sourceMapText };
Expand Down
7 changes: 4 additions & 3 deletions src/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
ensureProgram,
formatErrors,
isUsingProjectReferences,
makeError
makeError,
noImportError
} from './utils';
import { makeWatchRun } from './watch-run';

Expand Down Expand Up @@ -111,7 +112,7 @@ function successfulTypeScriptInstance(
loader.context
);

loader._module.errors.push(...errors);
loader._module.errors.push(...errors.filter(noImportError));

return {
error: makeError(
Expand Down Expand Up @@ -176,7 +177,7 @@ function successfulTypeScriptInstance(
loader.context
);

loader._module.errors.push(...errors);
loader._module.errors.push(...errors.filter(noImportError));
}

instances[loaderOptions.instance] = {
Expand Down
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ export function isUsingProjectReferences(instance: TSInstance) {
return false;
}

export function noImportError(error: WebpackError) {
const { message } = error;
const v3 = /export '.*'( \(reexported as '.*'\))? was not found in/;
const v4 = /Attempted import error: '.*' is not exported from '.*'\./;
return v3.test(message) || v4.test(message);
}

/**
* Gets the project reference for a file from the cache if it exists,
* or gets it from TypeScript and caches it otherwise.
Expand Down

0 comments on commit 79d9c91

Please sign in to comment.