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

Pass through ResolveTypes from Webpack #97

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions src/options.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { ResolveOptions } from "webpack";

export type LogLevel = "INFO" | "WARN" | "ERROR";

export interface Options {
readonly configFile: string;
readonly extensions: ReadonlyArray<string>;
readonly extensions: ResolveOptions["extensions"];
readonly baseUrl: string | undefined;
readonly silent: boolean;
readonly logLevel: LogLevel;
readonly logInfoToStdOut: boolean;
readonly context: string | undefined;
readonly colors: boolean;
readonly mainFields: string[];
readonly mainFields: ResolveOptions["mainFields"];
}

type ValidOptions = keyof Options;
Expand Down
10 changes: 5 additions & 5 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from "path";
import * as Options from "./options";
import * as Logger from "./logger";
import * as fs from "fs";
import { ResolvePluginInstance, Resolver } from "webpack";
import { ResolveOptions, ResolvePluginInstance, Resolver } from "webpack";
import { ResolveRequest, ResolveContext } from "enhanced-resolve";

type FileSystem = Resolver["fileSystem"];
Expand Down Expand Up @@ -127,7 +127,7 @@ export class TsconfigPathsPlugin implements ResolvePluginInstance {
log: Logger.Logger;
baseUrl: string | undefined;
absoluteBaseUrl: string;
extensions: ReadonlyArray<string>;
extensions: ResolveOptions["extensions"];

matchPath: TsconfigPaths.MatchPathAsync;

Expand Down Expand Up @@ -160,7 +160,7 @@ export class TsconfigPathsPlugin implements ResolvePluginInstance {
this.matchPath = TsconfigPaths.createMatchPathAsync(
this.absoluteBaseUrl,
loadResult.paths,
options.mainFields
options.mainFields as string[] | undefined
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure we can solve this just as a typing assertion. createMatchPathAsync() does not know what to do with Array<Array<string>> so allowing to pass that may be misleading. Not sure what it means to use Array<Array<string>> as mainfields, should it just be unnested to Array<string> or does it have other meaning to webpack?

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 did figure out what it's for, at least: it's a nested main field selector.

webpack/webpack#7204 (comment)

It turns out your concern was valid; I tried adding a test to tsconfig-paths with a string[] in mainFields and it failed.

This wouldn't be a new failure, of course; it would crash just as readily now. But obviously you don't want to advertise an invalid type.

I'll see if I can get them a PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dividab/tsconfig-paths#218 - we'll see if they accept it!

Copy link
Member

Choose a reason for hiding this comment

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

Well, I maintain that package too :-). I left some comments in the tsconfig-paths issue.

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 will remove "attention to detail" from my resume, ha.

This assertion is now gone, thank you!

);
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ function createPluginCallback(
resolver: Resolver,
absoluteBaseUrl: string,
hook: Tapable,
extensions: ReadonlyArray<string>
extensions: ResolveOptions["extensions"]
): TapAsyncCallback {
const fileExistAsync = createFileExistAsync(resolver.fileSystem);
const readJsonAsync = createReadJsonAsync(resolver.fileSystem);
Expand Down Expand Up @@ -306,7 +306,7 @@ function createPluginLegacy(
resolver: LegacyResolver,
absoluteBaseUrl: string,
target: string,
extensions: ReadonlyArray<string>
extensions: ResolveOptions["extensions"]
): ResolverCallbackLegacy {
const fileExistAsync = createFileExistAsync(resolver.fileSystem);
const readJsonAsync = createReadJsonAsync(resolver.fileSystem);
Expand Down