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

Enable enhanced-resolve for a Small Amount of Cases #1509

Closed
wants to merge 5 commits into from
Closed
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
36 changes: 29 additions & 7 deletions src/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
import type * as webpack from 'webpack';

import { create as _create } from 'enhanced-resolve';
import { create } from 'enhanced-resolve';

export function makeResolver(
_options: webpack.WebpackOptionsNormalized
options: webpack.WebpackOptionsNormalized
): ResolveSync {
/* Currently, `enhanced-resolve` does not work properly alongside `ts-loader`.
* This feature is disabled until a proper worflow has been worked out. */
return (_context, _path, _moduleName?): string | false => {
throw new Error();
};
const resolveOptions = options.resolve;
const resolver = create.sync(resolveOptions);

if ('alias' in resolveOptions || 'fallback' in resolveOptions) {
const neutralOptions = Object.assign({}, resolveOptions);
delete neutralOptions.alias;
delete neutralOptions.fallback;
const neutralResolver = create.sync(neutralOptions);

return (context, path, moduleName?): string | false => {
const result = resolver(context, path, moduleName);

try {
const neutralResult = neutralResolver(context, path, moduleName);

if (result !== neutralResult) {
return result;
} else {
return false;
}
} catch {
return result;
}
};
} else {
return () => false;
}
}

export type ResolveSync = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
asset bundle.js 2.6 KiB [emitted] (name: main)
./app.ts 120 bytes [built] [code generated] [2 errors]
./app.ts 120 bytes [built] [code generated] [1 error]
./common/components/myComponent.ts 46 bytes [built] [code generated]

ERROR in app.ts
./app.ts 1:29-53
[tsl] ERROR in app.ts(1,30)
 TS2307: Cannot find module 'components/myComponent' or its corresponding type declarations.
ts-loader-default_609318b4f68865d3

ERROR in app.ts
./app.ts 2:30-55
[tsl] ERROR in app.ts(2,31)
 TS2307: Cannot find module 'components/myComponent2' or its corresponding type declarations.
ts-loader-default_609318b4f68865d3

webpack compiled with 2 errors
webpack compiled with 1 error
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
asset bundle.js 2.6 KiB [emitted] (name: main)
cached modules 120 bytes [cached] 1 module
./app.ts 120 bytes [built] [code generated] [1 error]
./common/components/myComponent.ts 45 bytes [built] [code generated]

ERROR in app.ts
./app.ts 1:29-53
[tsl] ERROR in app.ts(1,30)
 TS2307: Cannot find module 'components/myComponent' or its corresponding type declarations.
ts-loader-default_609318b4f68865d3

ERROR in app.ts
./app.ts 2:30-55
[tsl] ERROR in app.ts(2,31)
 TS2307: Cannot find module 'components/myComponent2' or its corresponding type declarations.
ts-loader-default_609318b4f68865d3

webpack compiled with 2 errors
webpack compiled with 1 error
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
asset bundle.js 2.6 KiB [emitted] (name: main)
./app.ts 120 bytes [built] [code generated] [2 errors]
./app.ts 120 bytes [built] [code generated] [1 error]
./common/components/myComponent.ts 46 bytes [built] [code generated]

ERROR in app.ts
./app.ts 1:29-53
Does not compute.... code: 2307,severity: error,content: Cannot find module 'components/myComponent' or its corresponding type declarations.,file: app.ts,line: 1,character: 30,context: .test/errorFormatter
ts-loader-default_85b0565984bbe8dd

ERROR in app.ts
./app.ts 2:30-55
Does not compute.... code: 2307,severity: error,content: Cannot find module 'components/myComponent2' or its corresponding type declarations.,file: app.ts,line: 2,character: 31,context: .test/errorFormatter
ts-loader-default_85b0565984bbe8dd

webpack compiled with 2 errors
webpack compiled with 1 error
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
asset bundle.js 2.59 KiB [emitted] (name: main)
./app.ts 101 bytes [built] [code generated] [1 error]
./app.ts 101 bytes [built] [code generated]
./fake.ts 165 bytes [built] [code generated]

ERROR in app.ts
./app.ts 1:29-34
[tsl] ERROR in app.ts(1,30)
 TS2307: Cannot find module 'api' or its corresponding type declarations.
ts-loader-default_609318b4f68865d3

webpack compiled with 1 error
webpack compiled successfully