Skip to content

Commit

Permalink
chore(gatsby): migrate gatsby-webpack-stats-extractor to TypeScript (#…
Browse files Browse the repository at this point in the history
…22404)

* migrate gatsby-webpack-stats-extractor to TypeScript

* update @types/webpack

* fix typecheck

Co-authored-by: Blaine Kasten <blainekasten@gmail.com>
  • Loading branch information
sasurau4 and blainekasten authored May 12, 2020
1 parent 7a720f4 commit cddffd8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/semver": "^7.1.0",
"@types/signal-exit": "^3.0.0",
"@types/stack-trace": "^0.0.29",
"@types/webpack": "^4.41.7",
"@types/webpack": "^4.41.8",
"@types/webpack-merge": "^4.1.5",
"@typescript-eslint/eslint-plugin": "^2.24.0",
"@typescript-eslint/parser": "^2.24.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
const fs = require(`fs-extra`)
const path = require(`path`)
import fs from "fs-extra"
import path from "path"
import { Compiler } from "webpack"

class GatsbyWebpackStatsExtractor {
constructor(options) {
export class GatsbyWebpackStatsExtractor {
private plugin: { name: string }
constructor() {
this.plugin = { name: `GatsbyWebpackStatsExtractor` }
this.options = options || {}
}
apply(compiler) {
apply(compiler: Compiler): void {
compiler.hooks.done.tapAsync(this.plugin.name, (stats, done) => {
let assets = {}
let assetsMap = {}
for (let chunkGroup of stats.compilation.chunkGroups) {
const assets = {}
const assetsMap = {}
for (const chunkGroup of stats.compilation.chunkGroups) {
if (chunkGroup.name) {
let files = []
for (let chunk of chunkGroup.chunks) {
const files: string[] = []
for (const chunk of chunkGroup.chunks) {
files.push(...chunk.files)
}
assets[chunkGroup.name] = files.filter(f => f.slice(-4) !== `.map`)
Expand Down Expand Up @@ -44,5 +45,3 @@ class GatsbyWebpackStatsExtractor {
})
}
}

module.exports = GatsbyWebpackStatsExtractor
6 changes: 3 additions & 3 deletions packages/gatsby/src/utils/webpack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin"
import isWsl from "is-wsl"
import { getBrowsersList } from "./browserslist"

import GatsbyWebpackStatsExtractor from "./gatsby-webpack-stats-extractor"
import { GatsbyWebpackStatsExtractor } from "./gatsby-webpack-stats-extractor"
import { GatsbyWebpackEslintGraphqlSchemaReload } from "./gatsby-webpack-eslint-graphql-schema-reload-plugin"

import { builtinPlugins } from "./webpack-plugins"
Expand Down Expand Up @@ -639,8 +639,8 @@ export const createWebpackUtils = (

plugins.moment = (): Plugin => plugins.ignore(/^\.\/locale$/, /moment$/)

plugins.extractStats = (options: any): GatsbyWebpackStatsExtractor =>
new GatsbyWebpackStatsExtractor(options)
plugins.extractStats = (): GatsbyWebpackStatsExtractor =>
new GatsbyWebpackStatsExtractor()

plugins.eslintGraphqlSchemaReload = (): GatsbyWebpackEslintGraphqlSchemaReload =>
new GatsbyWebpackEslintGraphqlSchemaReload()
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4351,10 +4351,10 @@
"@types/webpack-sources" "*"
source-map "^0.6.0"

"@types/webpack@^4.41.7":
version "4.41.7"
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.7.tgz#22be27dbd4362b01c3954ca9b021dbc9328d9511"
integrity sha512-OQG9viYwO0V1NaNV7d0n79V+n6mjOV30CwgFPIfTzwmk8DHbt+C4f2aBGdCYbo3yFyYD6sjXfqqOjwkl1j+ulA==
"@types/webpack@^4.41.8":
version "4.41.8"
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.8.tgz#d2244f5f612ee30230a5c8c4ae678bce90d27277"
integrity sha512-mh4litLHTlDG84TGCFv1pZldndI34vkrW9Mks++Zx4KET7DRMoCXUvLbTISiuF4++fMgNnhV9cc1nCXJQyBYbQ==
dependencies:
"@types/anymatch" "*"
"@types/node" "*"
Expand Down

0 comments on commit cddffd8

Please sign in to comment.