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

Implement Webpack 5.0 Typings (when available) #69

Open
Brian-McBride opened this issue Mar 15, 2021 · 0 comments
Open

Implement Webpack 5.0 Typings (when available) #69

Brian-McBride opened this issue Mar 15, 2021 · 0 comments

Comments

@Brian-McBride
Copy link
Contributor

Just creating a ticket here to remember.

Possible Issue with createPluginCallback

Problem: Callback typing is currently string when webpack 5 is now expecting null | ResolveRequest

The getHook() method on the resolver returns:

AsyncSeriesBailHook<
    [ResolveRequest, ResolveContext],
    null | ResolveRequest
>

When we call tapAsync, the cast function looks roughly like this:

tapAsync(
    options: string | Tap & IfSet<AdditionalOptions>,
    fn: (ResolveRequest, ResolveContext, InnerCallback<Error, null | ResolveRequest>) => void
): void;

Currently, the function createPluginCallback has cast a callback with this:

(err?: Error, result?: string): void;

Current status

It seems to be working fine currently.

Future Needs

It seems that to write proper plugins, there will need to have some way of getting to ResolveRequest and ResolveContext types.

ResolveRequest

These types are a match from the module enhanced-resolve and might just be auto-generating.

type ResolveRequest = BaseResolveRequest & Partial<ParsedIdentifier>;
declare interface BaseResolveRequest {
	path: string | false;
	descriptionFilePath?: string;
	descriptionFileRoot?: string;
	descriptionFileData?: object;
	relativePath?: string;
	ignoreSymlinks?: boolean;
	fullySpecified?: boolean;
}
declare interface ParsedIdentifier {
	request: string;
	query: string;
	fragment: string;
	directory: boolean;
	module: boolean;
	file: boolean;
	internal: boolean;
}

It is probably worth refactoring the createPluginCallback to return the ResolveRequest object.
Only path looks required. Would the current returned string easily convert to { path: currentString } ?

Next steps

When the ResolvePluginInstance type is exported from webpack. This should result in this line:

export class TsconfigPathsPlugin implements ResolverPlugin {}

The Resolver type should be imported from webpack and replace the current Resolver interface.

Legacy support should just be done via NPM versions. If someone wants to fall back to Webpack 4 or earlier, they can grab an earlier release?

If there is a desire for legacy support, renaming most of the current types with a Legacy prefix would keep the namespace clear.

There is another type that will be needed. The FileSystem from webpack. I'm looking to add it to a PR. But it is accessible via type FileSystem = Request["fileSystem"]. Annoying, but accessible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant