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

Fix TypeScript types #1132

Merged
merged 7 commits into from Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
26 changes: 14 additions & 12 deletions index.js
@@ -1,8 +1,9 @@
// @ts-check
// Import types
/* eslint-disable */
/// <reference path="./typings.d.ts" />
jantimon marked this conversation as resolved.
Show resolved Hide resolved
/* eslint-enable */
/** @typedef {import("./typings").HtmlTagObject} HtmlTagObject */
/** @typedef {import("./typings").Options} HtmlWebpackOptions */
/** @typedef {import("./typings").InternalOptions} HtmlWebpackInternalOptions */
/** @typedef {import("./typings").TemplateParameter} TemplateParameter */
/** @typedef {import("webpack/lib/Compiler.js")} WebpackCompiler */
/** @typedef {import("webpack/lib/Compilation.js")} WebpackCompilation */
'use strict';
Expand All @@ -28,14 +29,14 @@ const fsReadFileAsync = promisify(fs.readFile);

class HtmlWebpackPlugin {
/**
* @param {Partial<HtmlWebpackPluginOptions>} [options]
* @param {HtmlWebpackOptions} [options]
wingrunr21 marked this conversation as resolved.
Show resolved Hide resolved
*/
constructor (options) {
/** @type {Partial<HtmlWebpackPluginOptions>} */
/** @type {HtmlWebpackOptions} */
const userOptions = options || {};

// Default options
/** @type {HtmlWebpackPluginOptions} */
/** @type {HtmlWebpackInternalOptions} */
const defaultOptions = {
template: path.join(__dirname, 'default_index.ejs'),
templateContent: false,
Expand All @@ -56,7 +57,7 @@ class HtmlWebpackPlugin {
xhtml: false
};

/** @type {HtmlWebpackPluginOptions} */
/** @type {HtmlWebpackInternalOptions} */
this.options = Object.assign(defaultOptions, userOptions);

// Default metaOptions if no template is provided
Expand Down Expand Up @@ -112,6 +113,7 @@ class HtmlWebpackPlugin {

const minify = this.options.minify;
if (minify === true || (minify === undefined && isProductionLikeMode)) {
/** @type { import('html-minifier').Options } */
this.options.minify = {
// https://github.com/kangax/html-minifier#options-quick-reference
collapseWhitespace: true,
Expand Down Expand Up @@ -381,7 +383,7 @@ class HtmlWebpackPlugin {
/**
* This function renders the actual html by executing the template function
*
* @param {(templatePArameters) => string | Promise<string>} templateFunction
* @param {(templateParameters) => string | Promise<string>} templateFunction
* @param {{
publicPath: string,
js: Array<string>,
Expand Down Expand Up @@ -628,7 +630,7 @@ class HtmlWebpackPlugin {
*
* @param {string|false} faviconFilePath
* @param {WebpackCompilation} compilation
* @parma {string} publicPath
* @param {string} publicPath
* @returns {Promise<string|undefined>}
*/
getFaviconPublicPath (faviconFilePath, compilation, publicPath) {
Expand Down Expand Up @@ -877,7 +879,7 @@ class HtmlWebpackPlugin {
/**
* Helper to return the absolute template path with a fallback loader
* @param {string} template
* The path to the tempalate e.g. './index.html'
* The path to the template e.g. './index.html'
* @param {string} context
* The webpack base resolution path for relative paths e.g. process.cwd()
*/
Expand Down Expand Up @@ -920,8 +922,8 @@ class HtmlWebpackPlugin {
headTags: HtmlTagObject[],
bodyTags: HtmlTagObject[]
}} assetTags
* @param {HtmlWebpackPluginOptions} options
* @returns {HtmlWebpackPluginTemplateParameter}
* @param {HtmlWebpackInternalOptions} options
* @returns {TemplateParameter}
*/
function templateParametersGenerator (compilation, assets, assetTags, options) {
const xhtml = options.xhtml;
Expand Down
65 changes: 1 addition & 64 deletions lib/hooks.js
@@ -1,7 +1,5 @@
// @ts-check
/* eslint-disable */
/// <reference path="../typings.d.ts" />
/* eslint-enable */
/** @typedef {import("../typings").Hooks} HtmlWebpackPluginHooks */
'use strict';
/**
* This file provides access to all public htmlWebpackPlugin hooks
Expand All @@ -12,67 +10,6 @@

const AsyncSeriesWaterfallHook = require('tapable').AsyncSeriesWaterfallHook;

// The following typedef holds the API definition for all available hooks
wingrunr21 marked this conversation as resolved.
Show resolved Hide resolved
// to allow easier access when using ts-check or typescript inside plugins
/** @typedef {{

beforeAssetTagGeneration:
AsyncSeriesWaterfallHook<{
assets: {
publicPath: string,
js: Array<string>,
css: Array<string>,
favicon?: string | undefined,
manifest?: string | undefined
},
outputName: string,
plugin: HtmlWebpackPlugin
}>,

alterAssetTags:
AsyncSeriesWaterfallHook<{
assetTags: {
scripts: Array<HtmlTagObject>,
styles: Array<HtmlTagObject>,
meta: Array<HtmlTagObject>,
},
outputName: string,
plugin: HtmlWebpackPlugin
}>,

alterAssetTagGroups:
AsyncSeriesWaterfallHook<{
headTags: Array<HtmlTagObject | HtmlTagObject>,
bodyTags: Array<HtmlTagObject | HtmlTagObject>,
outputName: string,
plugin: HtmlWebpackPlugin
}>,

afterTemplateExecution:
AsyncSeriesWaterfallHook<{
html: string,
headTags: Array<HtmlTagObject | HtmlTagObject>,
bodyTags: Array<HtmlTagObject | HtmlTagObject>,
outputName: string,
plugin: HtmlWebpackPlugin,
}>,

beforeEmit:
AsyncSeriesWaterfallHook<{
html: string,
outputName: string,
plugin: HtmlWebpackPlugin,
}>,

afterEmit:
AsyncSeriesWaterfallHook<{
outputName: string,
plugin: HtmlWebpackPlugin
}>,

}} HtmlWebpackPluginHooks
*/

/**
* @type {WeakMap<WebpackCompilation, HtmlWebpackPluginHooks>}}
*/
Expand Down
4 changes: 1 addition & 3 deletions lib/html-tags.js
@@ -1,7 +1,5 @@
// @ts-check
/* eslint-disable */
/// <reference path="../typings.d.ts" />
/* eslint-enable */
/** @typedef {import("../typings").HtmlTagObject} HtmlTagObject */
/**
* @file
* This file provides to helper to create html as a object repesentation as
Expand Down
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -5,6 +5,7 @@
"description": "Simplifies creation of HTML files to serve your webpack bundles",
"author": "Jan Nicklas <j.nicklas@me.com> (https://github.com/jantimon)",
"main": "index.js",
"types": "typings.d.ts",
"files": [
"lib/",
"index.js",
Expand All @@ -27,9 +28,11 @@
]
},
"devDependencies": {
"@types/html-minifier": "^3.5.2",
"@types/loader-utils": "1.1.3",
"@types/node": "10.11.4",
"@types/tapable": "1.0.4",
"@types/webpack": "^4.0.0",
"appcache-webpack-plugin": "^1.4.0",
"commitizen": "3.0.2",
"css-loader": "^1.0.0",
Expand Down