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: migrate workbox-webpack-plugin to typescript #2882

Merged
merged 26 commits into from
Feb 18, 2022

Conversation

roikoren755
Copy link
Contributor

Prior to filing a PR, please:

  • open an issue to discuss your proposed change.
  • ensure that gulp build && gulp lint test passes locally.

R: @jeffposnick @tropicadri

Fixes #2478

Description of what's changed/fixed.
This is a work in progress.
Couldn't get tests to run locally, and there are some @ts-ignore comments littered about in places that import things from workbox-build or workbox-google-analytics that I couldn't quite figure out.

I think getting this package to use the new TS version of workbox-build would get it almost ready to merge 🤞.

Feel free to push changes, or point me in the right direction to fix things :)

@tropicadri
Copy link
Contributor

@roikoren755 Thank you for this, sorry for the late reply we've been doing some upgrading of TS lint and as you saw workbox-build migration to TS, I'll take a look at the PR and help where I can :)

@tropicadri tropicadri marked this pull request as draft September 4, 2021 16:51
@tropicadri
Copy link
Contributor

This is far from ready, but I wanted to share the updates.

  • I merged with v6 branch that has the latest eslint version, we don't use @ts-ignore when we need to disable eslint we use // eslint-disable...
  • I reused the types from workbox-build instead of creating new ones
  • I setup the build to use compile with Typescript
  • Still fixing tests.

Let me know if you have any questions, thank you for your patience with this one.

@jeffposnick
Copy link
Contributor

Thanks! I'll take a look at this soon.

Copy link
Contributor

@jeffposnick jeffposnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @tropicadri! I have a few comments to go over once you're back in the office, but generally speaking, this looks good!

package.json Outdated Show resolved Hide resolved
packages/workbox-webpack-plugin/src/inject-manifest.ts Outdated Show resolved Hide resolved
packages/workbox-webpack-plugin/src/inject-manifest.ts Outdated Show resolved Hide resolved

if (sourcemapAssetName) {
_generatedAssetNames.add(sourcemapAssetName);
const sourcemapAsset = compilation.getAsset(sourcemapAssetName);
const {source, map} = await replaceAndUpdateSourceMap({
jsFilename: config.swDest,
originalMap: JSON.parse(sourcemapAsset.source.source()),
// eslint-disable-next-line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the error here? If possible, could you use the form of the comment that disables a specific rule rather than all rules, so that it's clearer what's being worked around?

https://eslint.org/docs/user-guide/configuring/rules#using-configuration-comments

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the ones that didn't have the issue

if (condition({asset, compilation})) {
return true;
}
return condition(asset.name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is something that changed between webpack v4 and v5. I do see some v5 types that imply that conditions take a single string (and https://webpack.js.org/configuration/module/#condition sort of implies that too), but at one point I thought we needed to pass in {asset, compilation}... I am having trouble figuring out why that is, though.

But, since we aim to make this a backwards—compatible release, I feel like we need to keep the old method call here, and move to the "correct" signature of (value: string) => boolean as a breaking change in Workbox v7.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to do some "anying" to keep it the way it was before, it doesn't seem to have changed a lot: https://v4.webpack.js.org/configuration/module/#condition, I am not sure why we are passing {asset, compilation} it seems that would invoke the case where compilation receives an object and all the properties should match, but I have no idea why it is implemented this way...so we'll keep it and change in v7

@@ -159,14 +181,14 @@ function filterAssets(compilation, config) {
}

// Next, check asset-level checks via includes/excludes:
const isExcluded = checkConditions(asset, compilation, config.exclude);
const isExcluded = checkConditions(asset, config.exclude);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment—we might need to keep the old signature for backwards compatibiltiy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor

@jeffposnick jeffposnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

Thanks so much to @roikoren755 for kicking this off, and @tropicadri for finishing it up!

@jeffposnick jeffposnick merged commit 55e8144 into GoogleChrome:v6 Feb 18, 2022
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

Successfully merging this pull request may close these issues.

Migrate workbox-webpack-plugin to TypeScript
3 participants