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

feat: add LoaderContext to types #13164

Merged
merged 32 commits into from May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
586d013
feat: LoaderContext type
johnnyreilly Apr 16, 2021
a2f8808
apply @sokra's feedback and include runtime type
johnnyreilly Apr 19, 2021
df44d7d
attempt @sokras suggestion
johnnyreilly Apr 20, 2021
79da320
non generics
johnnyreilly Apr 20, 2021
39042a2
Update lib/index.js
johnnyreilly Apr 20, 2021
b967f36
Update declarations/LoaderContext.d.ts
johnnyreilly Apr 20, 2021
5ef8aca
Update declarations/LoaderContext.d.ts
johnnyreilly Apr 20, 2021
3d45e2b
Update declarations/LoaderContext.d.ts
johnnyreilly Apr 20, 2021
1578fd4
schema
johnnyreilly Apr 20, 2021
25c80ea
Merge branch 'master' of https://github.com/johnnyreilly/webpack
johnnyreilly Apr 20, 2021
a679319
bring in suggested types
johnnyreilly Apr 20, 2021
111e95c
Update declarations/LoaderContext.d.ts
johnnyreilly Apr 20, 2021
35eef1e
Update declarations/LoaderContext.d.ts
johnnyreilly Apr 20, 2021
3898b38
Update declarations/LoaderContext.d.ts
johnnyreilly Apr 20, 2021
481832d
Update declarations/LoaderContext.d.ts
johnnyreilly Apr 20, 2021
57e49bc
Update declarations/LoaderContext.d.ts
johnnyreilly Apr 20, 2021
8703248
Update declarations/LoaderContext.d.ts
johnnyreilly Apr 20, 2021
40a5eb1
tried generic workarouuund
johnnyreilly Apr 20, 2021
8cd30eb
revert generic approach
johnnyreilly Apr 20, 2021
ee03137
change import
johnnyreilly Apr 20, 2021
cf1a1fe
fixup some types
sokra Apr 22, 2021
984308a
generate types with yarn special-lint-fix
johnnyreilly Apr 22, 2021
e42915c
clean up types
sokra Apr 22, 2021
7cc4078
fix some internal types
sokra Apr 22, 2021
ea53a23
improve LoaderContext declaration
sokra Apr 22, 2021
4e70b37
test typings and fix type problems in loaders in the test suite
sokra Apr 22, 2021
b71e0ce
Merge branch 'master' into johnnyreilly/master
sokra Apr 22, 2021
5b21dd2
fix import problem
sokra Apr 22, 2021
77f625a
upgrade tooling and update types.d.ts
sokra May 7, 2021
87c0d1c
Merge branch 'master' into johnnyreilly/master
sokra May 7, 2021
b6693fe
getOptions returns OptionsType
sokra May 7, 2021
442a1eb
rename validate function to avoid conflict
sokra May 7, 2021
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
28 changes: 27 additions & 1 deletion lib/NormalModule.js
Expand Up @@ -44,8 +44,11 @@ const memoize = require("./util/memoize");

/** @typedef {import("source-map").RawSourceMap} SourceMap */
/** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("../declarations/WebpackOptions").Loader} Loader */
johnnyreilly marked this conversation as resolved.
Show resolved Hide resolved
/** @typedef {import("../declarations/WebpackOptions").Mode} Mode */
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
/** @typedef {import("./ChunkGraph")} ChunkGraph */
/** @typedef {import("./Compiler")} Compiler */
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
/** @typedef {import("./Generator")} Generator */
Expand All @@ -61,6 +64,7 @@ const memoize = require("./util/memoize");
/** @typedef {import("./RequestShortener")} RequestShortener */
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
/** @typedef {import("./logging/Logger").Logger} WebpackLogger */
/** @typedef {import("./util/Hash")} Hash */
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
Expand All @@ -79,6 +83,28 @@ const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:\\|\\\\|\/)/;
* @property {string?} type
*/

/**
* @typedef {Object} LoaderContextBase
johnnyreilly marked this conversation as resolved.
Show resolved Hide resolved
* @property {(schema: any) => any} getOptions
* @property {(warning: any) => void} emitWarning
* @property {(error: any) => void} emitError
* @property {(context: any, request: any, callback: any) => void} resolve
* @property {(options: any) => (context: any, request: any, callback: any) => Promise<any>} getResolve
* @property {(name: any, content: any, sourceMap: any, assetInfo: any) => void} emitFile
* @property {(dep: any) => void} addBuildDependency
* @property {{ absolutify: (context: any, request: any) => string; contextify: (context: any, request: any) => string; }} utils
* @property {string} rootContext
* @property {boolean} webpack
* @property {boolean} sourceMap
* @property {Mode} mode
* @property {any} _module
johnnyreilly marked this conversation as resolved.
Show resolved Hide resolved
* @property {Compilation} _compilation
* @property {Compiler} _compiler
* @property {InputFileSystem} fs
*/

/** @typedef {LoaderContextBase & Loader} LoaderContext */

/**
* @param {string} context absolute context path
* @param {string} source a source path
Expand Down Expand Up @@ -421,7 +447,7 @@ class NormalModule extends Module {
* @param {WebpackOptions} options webpack options
* @param {Compilation} compilation the compilation
* @param {InputFileSystem} fs file system from reading
* @returns {any} loader context
* @returns {LoaderContext} loader context
*/
createLoaderContext(resolver, options, compilation, fs) {
const { requestShortener } = compilation.runtimeTemplate;
Expand Down
29 changes: 28 additions & 1 deletion types.d.ts
Expand Up @@ -5740,6 +5740,32 @@ declare class LoadScriptRuntimeModule extends HelperRuntimeModule {
declare interface Loader {
[index: string]: any;
}
type LoaderContext = LoaderContextBase & Loader;
declare interface LoaderContextBase {
getOptions: (schema?: any) => any;
emitWarning: (warning?: any) => void;
emitError: (error?: any) => void;
resolve: (context?: any, request?: any, callback?: any) => void;
getResolve: (
options?: any
) => (context?: any, request?: any, callback?: any) => Promise<any>;
emitFile: (
name?: any,
content?: any,
sourceMap?: any,
assetInfo?: any
) => void;
addBuildDependency: (dep?: any) => void;
utils: {
absolutify: (context?: any, request?: any) => string;
contextify: (context?: any, request?: any) => string;
};
rootContext: string;
webpack: boolean;
sourceMap: boolean;
mode: Mode;
fs: InputFileSystem;
}
declare interface LoaderItem {
loader: string;
options: any;
Expand Down Expand Up @@ -5924,6 +5950,7 @@ declare interface MinChunkSizePluginOptions {
*/
minChunkSize: number;
}
type Mode = "development" | "production" | "none";
declare class Module extends DependenciesBlock {
constructor(type: string, context?: string, layer?: string);
type: string;
Expand Down Expand Up @@ -6847,7 +6874,7 @@ declare class NormalModule extends Module {
options: WebpackOptionsNormalized,
compilation: Compilation,
fs: InputFileSystem
): any;
): LoaderContext;
getCurrentLoader(loaderContext?: any, index?: any): null | LoaderItem;
createSource(
context: string,
Expand Down