Skip to content

Commit

Permalink
build(deps): upgrade to webpack 5 and remove redundant typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Austaras committed Oct 13, 2020
1 parent 9def432 commit 51b3771
Show file tree
Hide file tree
Showing 187 changed files with 626 additions and 1,593 deletions.
Binary file added .yarn-offline-mirror/@npmcli-move-file-1.0.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/@types-eslint-7.2.4.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn-offline-mirror/@types-estree-0.0.45.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/@types-json-schema-7.0.6.tgz
Binary file not shown.
Binary file not shown.
Binary file removed .yarn-offline-mirror/acorn-6.4.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/acorn-8.0.4.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/aggregate-error-3.1.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/ajv-6.12.6.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/ajv-keywords-3.5.2.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/anymatch-3.1.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/asn1.js-4.10.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/assert-1.5.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/base64-js-1.3.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/binary-extensions-2.1.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/bluebird-3.5.5.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/bn.js-4.11.8.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/braces-3.0.2.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/brorand-1.1.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/browserify-aes-1.2.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/browserify-cipher-1.0.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/browserify-des-1.0.2.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/browserify-rsa-4.0.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/browserify-sign-4.0.4.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/browserify-zlib-0.2.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/browserslist-4.14.5.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/buffer-4.9.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/buffer-xor-1.0.3.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/builtin-status-codes-3.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/cacache-12.0.2.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/cacache-15.0.5.tgz
Binary file not shown.
Binary file not shown.
Binary file removed .yarn-offline-mirror/chokidar-3.4.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/chownr-2.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/cipher-base-1.0.4.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/clean-stack-2.2.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/concat-stream-1.6.2.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/console-browserify-1.1.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/constants-browserify-1.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/copy-concurrently-1.0.5.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/create-ecdh-4.0.3.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/create-hash-1.2.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/create-hmac-1.1.7.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/crypto-browserify-3.12.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/cyclist-0.2.2.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/date-now-0.1.4.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/des.js-1.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/diffie-hellman-5.0.3.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/domain-browser-1.2.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/duplexify-3.7.1.tgz
Binary file not shown.
Binary file not shown.
Binary file removed .yarn-offline-mirror/elliptic-6.5.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/enhanced-resolve-4.3.0.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn-offline-mirror/escalade-3.1.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/eslint-scope-4.0.3.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/eslint-scope-5.1.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/esrecurse-4.3.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/estraverse-5.2.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/events-3.2.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/evp_bytestokey-1.0.3.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/figgy-pudding-3.5.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/fill-range-7.0.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/find-cache-dir-3.3.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/find-up-4.1.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/flush-write-stream-1.1.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/from2-2.3.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/fs-minipass-2.1.0.tgz
Binary file not shown.
Binary file not shown.
Binary file removed .yarn-offline-mirror/fsevents-2.1.3.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/glob-parent-5.1.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/glob-to-regexp-0.4.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/graceful-fs-4.2.4.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/hash-base-3.0.4.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/hash.js-1.1.7.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/hmac-drbg-1.0.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/https-browserify-1.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/ieee754-1.1.13.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/iferr-0.1.5.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/indent-string-4.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/inherits-2.0.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/is-binary-path-2.1.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/is-number-7.0.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/jest-worker-26.5.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/loader-runner-2.4.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/loader-runner-4.1.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/locate-path-5.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/lru-cache-5.1.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/lru-cache-6.0.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/make-dir-3.1.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/md5.js-1.3.5.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/memory-fs-0.5.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/merge-stream-2.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/miller-rabin-4.0.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/mime-db-1.44.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/mime-types-2.1.27.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn-offline-mirror/minipass-3.1.3.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/minipass-collect-1.0.2.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/minipass-flush-1.0.5.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/minipass-pipeline-1.2.4.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/minizlib-2.1.2.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/mississippi-3.0.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/mkdirp-1.0.4.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/move-concurrently-1.0.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/neo-async-2.6.2.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/node-libs-browser-2.2.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/node-releases-1.1.61.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/os-browserify-0.3.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/p-limit-2.3.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/p-limit-3.0.2.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/p-locate-4.1.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/p-map-4.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/parallel-transform-1.1.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/parse-asn1-5.1.4.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/path-browserify-0.0.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/path-exists-4.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/pbkdf2-3.0.17.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/picomatch-2.2.2.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/pkg-dir-4.2.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/process-0.11.10.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/public-encrypt-4.0.3.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/pump-2.0.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/pumpify-1.5.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/querystring-es3-0.2.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/randomfill-1.0.4.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/readdirp-3.4.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/ripemd160-2.0.2.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/run-queue-1.0.3.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/schema-utils-3.0.0.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn-offline-mirror/setimmediate-1.0.5.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/sha.js-2.4.11.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/ssri-6.0.1.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/ssri-8.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/stream-browserify-2.0.2.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/stream-each-1.2.3.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/stream-http-2.8.3.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/stream-shift-1.0.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/supports-color-7.2.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/tapable-2.0.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/tar-6.0.5.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/terser-4.1.4.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/terser-5.3.5.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/terser-webpack-plugin-1.4.4.tgz
Binary file not shown.
Binary file not shown.
Binary file removed .yarn-offline-mirror/through2-2.0.5.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/timers-browserify-2.0.11.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/to-arraybuffer-1.0.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/to-regex-range-5.0.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/tty-browserify-0.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/typedarray-0.0.6.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/util-0.10.3.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/util-0.11.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/vm-browserify-1.1.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/watchpack-1.7.4.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/watchpack-2.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/watchpack-chokidar2-2.0.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/webpack-4.44.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/webpack-5.0.0.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/webpack-sources-2.0.1.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/worker-farm-1.7.0.tgz
Binary file not shown.
Binary file removed .yarn-offline-mirror/xtend-4.0.2.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/yallist-4.0.0.tgz
Binary file not shown.
17 changes: 6 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
},
"peerDependencies": {
"core-js": "^2.6.3 || ^3.6.5",
"html-webpack-plugin": "^3.2.0 || ^4.0.0",
"html-webpack-plugin": "^4.0.0",
"terser": ">=3.12.0",
"webpack": "^4.19.0",
"webpack": "^5.0.0",
"webpack-dev-server": "^3.1.0"
},
"dependencies": {
Expand All @@ -73,9 +73,9 @@
"@babel/runtime": "^7.10.5",
"babel-loader": "^8.1.0",
"core-js": "^3.6.5",
"tapable": "^1.1.3",
"tapable": "^2.0.0",
"webpack-merge": "^5.0.9",
"webpack-sources": "^1.4.3"
"webpack-sources": "^2.0.1"
},
"devDependencies": {
"@babel/preset-react": "^7.10.4",
Expand All @@ -90,12 +90,10 @@
"@types/mocha": "^5.2.5",
"@types/node": "^12.12.53",
"@types/sinon-chai": "^3.2.4",
"@types/tapable": "^1.0.6",
"@types/webpack": "^4.41.21",
"@types/webpack-dev-middleware": "^3.7.1",
"@types/webpack-dev-server": "^3.11.0",
"@types/webpack-merge": "^4.1.5",
"@types/webpack-sources": "^1.4.1",
"@types/webpack-sources": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"acorn": "^6.0.5",
Expand Down Expand Up @@ -136,11 +134,8 @@
"ts-custom-error-shim": "^1.0.2",
"ts-node": "^8.10.2",
"typescript": "^3.9.7",
"webpack": "^4.44.0",
"webpack": "^5.0.0",
"webpack-dev-middleware": "^3.7.2",
"webpack-dev-server": "^3.11.0"
},
"resolutions": {
"@types/webpack": "^4.41.21"
}
}
8 changes: 4 additions & 4 deletions src/babel-target.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BabelLoaderTransformOptions, BabelPresetOptions } from 'babel-loader'
import * as webpack from 'webpack'
import Chunk = webpack.compilation.Chunk
import ChunkGroup = webpack.compilation.ChunkGroup
import Entrypoint = webpack.compilation.Entrypoint
import Module = webpack.compilation.Module
import Chunk = webpack.Chunk
import ChunkGroup = webpack.ChunkGroup
import Entrypoint = webpack.Entrypoint
import Module = webpack.Module

import { BabelLoaderCacheDirectoryOption } from './babel.multi.target.options'
import { BabelTargetOptions } from './babel.target.options'
Expand Down
26 changes: 10 additions & 16 deletions src/babel.multi.target.html.updater.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { AlterAssetTagsData, HtmlTag, HtmlWebpackPlugin } from 'html-webpack-plugin'
import { compilation, Compiler, Plugin } from 'webpack'
import { getHooks, HtmlTagObject } from 'html-webpack-plugin'
import { Chunk, ChunkGroup, Compilation, Compiler, Plugin } from 'webpack'

import { BabelTarget } from './babel-target'
import { getAlterAssetTags, getHeadTags, getBodyTags } from './html-webpack-plugin.polyfill'
import { PLUGIN_NAME } from './plugin.name'
import { TargetedChunkMap } from './targeted.chunk'
import Chunk = compilation.Chunk
import ChunkGroup = compilation.ChunkGroup
import Compilation = compilation.Compilation

// Works with HtmlWebpackPlugin to make sure the targeted assets are referenced correctly
// Tags for assets whose target has `esModule` set are updated with the `"type"="module"` attribute
Expand All @@ -20,15 +16,15 @@ export class BabelMultiTargetHtmlUpdater implements Plugin {

constructor(private targets: BabelTarget[]) {}

public updateScriptTags(chunkMap: TargetedChunkMap, tags: HtmlTag[]): void {
public updateScriptTags(chunkMap: TargetedChunkMap, tags: HtmlTagObject[]): void {

tags
.forEach((tag: HtmlTag) => {
.forEach((tag: HtmlTagObject) => {
if (tag.tagName !== 'script') {
return
}

const targetedChunks = chunkMap.get(tag.attributes.src)
const targetedChunks = chunkMap.get(tag.attributes.src as string)
// chunks that are added outside of an entry point (e.g. by HtmlWebpackIncludeAssetsPlugin) will not be targeted
if (!targetedChunks) {
return
Expand Down Expand Up @@ -83,7 +79,7 @@ export class BabelMultiTargetHtmlUpdater implements Plugin {
public apply(compiler: Compiler): void {

compiler.hooks.afterPlugins.tap(PLUGIN_NAME, () => {
const htmlWebpackPlugin: HtmlWebpackPlugin = compiler.options.plugins
const htmlWebpackPlugin = compiler.options.plugins
// instanceof can act wonky since we don't actually keep our own dependency on html-webpack-plugin
// should we?
.find(plugin => plugin.constructor.name === 'HtmlWebpackPlugin') as any
Expand Down Expand Up @@ -114,10 +110,8 @@ export class BabelMultiTargetHtmlUpdater implements Plugin {
return
}

const hook = getAlterAssetTags(compilation)

hook.tapPromise(`${PLUGIN_NAME} update asset tags`,
async (htmlPluginData: AlterAssetTagsData) => {
getHooks(compilation).alterAssetTagGroups.tapPromise(`${PLUGIN_NAME} update asset tags`,
async (htmlPluginData) => {
const chunkMap: TargetedChunkMap = compilation.chunkGroups.reduce((result: TargetedChunkMap, chunkGroup: ChunkGroup) => {
chunkGroup.chunks.forEach((chunk: Chunk) => {
chunk.files.forEach((file: string) => {
Expand All @@ -126,8 +120,8 @@ export class BabelMultiTargetHtmlUpdater implements Plugin {
})
return result
}, new TargetedChunkMap(compiler.options.output.publicPath))
this.updateScriptTags(chunkMap, getHeadTags(htmlPluginData))
this.updateScriptTags(chunkMap, getBodyTags(htmlPluginData))
this.updateScriptTags(chunkMap, htmlPluginData.headTags)
this.updateScriptTags(chunkMap, htmlPluginData.bodyTags)
return htmlPluginData
})

Expand Down
7 changes: 2 additions & 5 deletions src/babel.target.entry.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { compilation, Compiler, Plugin } from 'webpack'
import Compilation = compilation.Compilation
import Dependency = compilation.Dependency
import NormalModuleFactory = compilation.NormalModuleFactory
import { Compiler, Plugin, Compilation, Dependency, NormalModuleFactory } from 'webpack'

import { BabelTarget } from './babel-target'
import { BabelTargetSingleEntryDependency } from './babel.target.single.entry.dependency'
Expand All @@ -16,7 +13,7 @@ export abstract class BabelTargetEntryPlugin implements Plugin {
compiler.hooks.compilation.tap(
this.constructor.name,
(compilation: Compilation, { normalModuleFactory }: { normalModuleFactory: NormalModuleFactory }) => {
(compilation.dependencyFactories as Map<any, any>).set(
compilation.dependencyFactories.set(
BabelTargetSingleEntryDependency,
normalModuleFactory,
)
Expand Down
4 changes: 1 addition & 3 deletions src/babel.target.multi.entry.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { compilation, Compiler } from 'webpack'
import Compilation = compilation.Compilation
import NormalModuleFactory = compilation.NormalModuleFactory
import { Compilation, Compiler, NormalModuleFactory } from 'webpack'
import MultiModuleFactory = require('webpack/lib/MultiModuleFactory')
import SingleEntryDependency = require('webpack/lib/dependencies/SingleEntryDependency')

Expand Down
3 changes: 1 addition & 2 deletions src/babel.target.single.entry.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { compilation, Compiler } from 'webpack'
import Compilation = compilation.Compilation;
import { Compilation, Compiler } from 'webpack'

import { BabelTarget } from './babel-target'
import { BabelTargetEntryDependency } from './babel.target.entry.dependency'
Expand Down
16 changes: 0 additions & 16 deletions src/html-webpack-plugin.polyfill.ts

This file was deleted.

13 changes: 5 additions & 8 deletions src/named.lazy.chunks.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { compilation, Compiler, Plugin } from 'webpack'

import Chunk = compilation.Chunk;
import Compilation = compilation.Compilation;
import Origin = compilation.Origin;
import { Chunk, Compilation, Compiler, Plugin, Entrypoint } from 'webpack'

import { BabelTarget } from './babel-target'

Expand All @@ -19,11 +15,12 @@ export class NamedLazyChunksPlugin implements Plugin {
if (!group.origins) {
return
}
if (group.runtimeChunk === chunk) {
result.origins = [ group.runtimeChunk.entryModule.reasons[0].dependencies.originalName ]
if ((group as Entrypoint).runtimeChunk === chunk) {
// TODO did this actually get called?
result.origins = [ (group as Entrypoint).runtimeChunk.entryModule.reasons[0].dependencies.originalName ]
result.isEntry = true
}
group.origins.forEach((origin: Origin) => {
group.origins.forEach((origin) => {
const isLazyModule = origin.module && origin.module.options && origin.module.options.mode === 'lazy'
const isNgFactory = origin.request && origin.request.match(/\.ngfactory(?:\?babel-target=\w+)?$/)
if (!isLazyModule && !isNgFactory) {
Expand Down
22 changes: 10 additions & 12 deletions src/normalize.css.chunks.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { compilation, Compiler, Plugin } from 'webpack'

import Chunk = compilation.Chunk;
import Compilation = compilation.Compilation;
import Module = compilation.Module;
import { Chunk, Compilation, Module, Compiler, Plugin } from 'webpack'
import { STAGE_BASIC } from 'webpack/lib/OptimizationStages'

import { BabelTarget } from './babel-target'
import { PLUGIN_NAME } from './plugin.name'
Expand All @@ -27,7 +24,10 @@ export class NormalizeCssChunksPlugin implements Plugin {
return
}

compilation.hooks.optimizeChunksBasic.tap(PLUGIN_NAME, this.extractCssChunks.bind(this, compilation))
compilation.hooks.optimizeChunks.tap({
name: PLUGIN_NAME,
stage: STAGE_BASIC,
}, this.extractCssChunks.bind(this, compilation))
compilation.hooks.optimizeChunkAssets.tap(PLUGIN_NAME, this.cleanCssChunks.bind(this, compilation))

})
Expand Down Expand Up @@ -66,8 +66,7 @@ export class NormalizeCssChunksPlugin implements Plugin {
cssModules[name] = new Set<Module>()
}

chunk.modulesIterable.forEach(module => {

for (const module of chunk.modulesIterable) {
if (module.constructor.name !== 'CssModule') {
return
}
Expand All @@ -76,8 +75,7 @@ export class NormalizeCssChunksPlugin implements Plugin {

// don't duplicate modules - we should only have one per imported/required CSS/SCSS/etc file
cssModules[name].add(module)

})
}
})

if (hasUntaggedTarget) {
Expand Down Expand Up @@ -159,14 +157,14 @@ export class NormalizeCssChunksPlugin implements Plugin {
return
}

chunk.files = chunk.files.reduce((result, file) => {
chunk.files = new Set([...chunk.files].reduce((result, file) => {
if (file.endsWith('.js')) {
delete compilation.assets[file]
} else {
result.push(file)
}
return result
}, [])
}, []))
})
}

Expand Down
24 changes: 10 additions & 14 deletions src/normalize.module.ids.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { AlterAssetTagsData, HtmlTag, HtmlWebpackPlugin } from 'html-webpack-plugin'
import { Compiler, Plugin } from 'webpack'
import * as webpack from 'webpack'
import Compilation = webpack.compilation.Compilation
import Module = webpack.compilation.Module
import { HtmlTagObject, getHooks } from 'html-webpack-plugin'
import HtmlWebpackPlugin = require('html-webpack-plugin')
import { Compiler, Compilation, Module, Plugin } from 'webpack'

import { BabelTarget } from './babel-target'
import { getAlterAssetTags, getBodyTags, setBodyTags } from './html-webpack-plugin.polyfill'

export class NormalizeModuleIdsPlugin implements Plugin {

Expand Down Expand Up @@ -84,16 +81,15 @@ export class NormalizeModuleIdsPlugin implements Plugin {
return
}

const hook = getAlterAssetTags(compilation)

hook.tapPromise(this.pluginName('reorder asset tags'),
async (htmlPluginData: AlterAssetTagsData) => {
// TODO will this work?
getHooks(compilation).alterAssetTagGroups.tapPromise(this.pluginName('reorder asset tags'),
async (htmlPluginData) => {

const body = getBodyTags(htmlPluginData)
const body = htmlPluginData.bodyTags
const tags = body.slice(0)

// re-sort the tags so that es module tags are rendered first, otherwise maintaining the original order
body.sort((a: HtmlTag, b: HtmlTag) => {
body.sort((a: HtmlTagObject, b: HtmlTagObject) => {
const aIndex = tags.indexOf(a)
const bIndex = tags.indexOf(b)
if (a.tagName !== 'script' || b.tagName !== 'script' ||
Expand All @@ -110,13 +106,13 @@ export class NormalizeModuleIdsPlugin implements Plugin {
return 1
})

body.forEach((tag: HtmlTag) => {
body.forEach((tag: HtmlTagObject) => {
if (tag.tagName === 'script' && tag.attributes && tag.attributes.nomodule) {
tag.attributes.defer = true
}
})

setBodyTags(htmlPluginData, body)
htmlPluginData.bodyTags = body

return htmlPluginData

Expand Down
25 changes: 12 additions & 13 deletions src/safari-nomodule-fix/safari.nomodule.fix.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { readFileSync } from 'fs'
import { resolve } from 'path'

import { AlterAssetTagsData, HtmlTag, HtmlWebpackPlugin } from 'html-webpack-plugin'
import * as webpack from 'webpack'
import { Compiler, Plugin } from 'webpack'
import { getHooks, HtmlTagObject } from 'html-webpack-plugin'
import HtmlWebpackPlugin = require('html-webpack-plugin')
import { Compiler, Compilation, Plugin } from 'webpack'
import { RawSource } from 'webpack-sources'
import * as terser from 'terser';

import Compilation = webpack.compilation.Compilation
import * as terser from 'terser'

import { SafariNoModuleFixMode, SafariNoModuleFixInject, SafariNoModuleFixOption, SafariNoModuleFixOptionMap } from '../babel.multi.target.options'
import { PLUGIN_NAME } from '../plugin.name'
Expand All @@ -25,8 +23,7 @@ export class SafariNoModuleFixPlugin implements Plugin {
this.mode = typeof options.mode !== 'undefined' ? options.mode : true
this.inject = options.inject ? options.inject : SafariNoModuleFixInject.head
this.minify = !!options.minify
}
else {
} else {
this.mode = option as (boolean | SafariNoModuleFixMode)
this.inject = SafariNoModuleFixInject.head
this.minify = false
Expand Down Expand Up @@ -123,20 +120,22 @@ export class SafariNoModuleFixPlugin implements Plugin {
return
}

compilation.hooks.htmlWebpackPluginAlterAssetTags.tapPromise(`${PLUGIN_NAME} add safari nomodule fix tags`,
async (htmlPluginData: AlterAssetTagsData) => {
const element = this.inject === SafariNoModuleFixInject.body ? htmlPluginData.body : htmlPluginData.head
getHooks(compilation).alterAssetTagGroups.tapPromise(`${PLUGIN_NAME} add safari nomodule fix tags`,
async (htmlPluginData) => {
const element = this.inject === SafariNoModuleFixInject.body ? htmlPluginData.bodyTags : htmlPluginData.headTags
element.unshift(this.createSafariNoModuleFixTag())
return htmlPluginData
})

})
}

private createSafariNoModuleFixTag(): HtmlTag {
private createSafariNoModuleFixTag(): HtmlTagObject {

const tag: HtmlTag = {
const tag: HtmlTagObject = {
tagName: 'script',
// TODO
// @ts-ignore
closeTag: true,
attributes: {
nomodule: true,
Expand Down
6 changes: 2 additions & 4 deletions src/targeted.chunk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as webpack from 'webpack'
import Chunk = webpack.compilation.Chunk;
import ChunkGroup = webpack.compilation.ChunkGroup;
import { Chunk, ChunkGroup, PublicPath } from 'webpack'

import { BabelTarget } from './babel-target'

Expand Down Expand Up @@ -29,7 +27,7 @@ export class TargetedChunkMap {
private innerMap: { [key: string]: TargetedChunk[] } = {};
private targetedChunks: { [hash: string]: TargetedChunk } = {};

constructor(private publicPath: string) {
constructor(private publicPath: PublicPath) {
if (typeof(this.publicPath) === 'undefined') {
this.publicPath = ''
}
Expand Down
Loading

0 comments on commit 51b3771

Please sign in to comment.