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

Migrate workbox-build to TypeScript #2867

Merged
merged 82 commits into from
Jun 17, 2021
Merged

Migrate workbox-build to TypeScript #2867

merged 82 commits into from
Jun 17, 2021

Conversation

jeffposnick
Copy link
Contributor

R: @tropicadri

Fixes #2806, fixes #2477

There's obviously a lot going on in this PR. Sorry!

At a high level, this migrates workbox-build to TypeScript. (Following this PR, only workbox-webpack-plugin and workbox-sw are written in JavaScript.)

The goal was to preserve functionality during this migration, and not require a major semver bump. The biggest change under the hood is swapping out @hapi/joi option validation for a two-part system that generates JSON schema based on our TypeScript definitions at build time, and then uses https://ajv.js.org/ to validate at runtime against that schema. @hapi/joi is a bit more sophisticated in terms of complex runtime validation (e.g. ensuring that if one option is set, another option needs to also be set, making options mutually exclusive, etc.) so some of those relationships needed to be expressed at runtime via custom functions, meaning that the generated JSON schema are not 100% the source of truth.

Many of the test changes across all the packages reflect the fact that validation now throws slightly different errors due to the above mentioned change.

There are other small changes sprinkled throughout this PR as well, based on things that I found necessary while working with the additional TypeScript code. Please flag anything that looks amiss!

Copy link
Collaborator

@tropicadri tropicadri left a comment

Choose a reason for hiding this comment

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

There are several linting errors and I added a couple of suggestions.

packages/workbox-build/src/lib/get-file-details.ts Outdated Show resolved Hide resolved
test/workbox-build/node/generate-sw.js Outdated Show resolved Hide resolved
packages/workbox-build/src/lib/cdn-utils.ts Outdated Show resolved Hide resolved
packages/workbox-build/src/lib/validate-options.ts Outdated Show resolved Hide resolved
@jeffposnick
Copy link
Contributor Author

Thanks! Regarding the linting errors, I'm not going to be able to resolve the three instances of Parsing error: Cannot read property 'map' of undefined in this PR. As per https://stackoverflow.com/a/64626605/385997, we're going to have to upgrade our TypeScript eslint dependencies to resolve them, and that's a larger effort being done in the other PR that you're working on.

The other errors should be resolved now, though.

jeffposnick and others added 8 commits June 16, 2021 10:28
Co-authored-by: Adriana Jara <32825533+tropicadri@users.noreply.github.com>
Co-authored-by: Adriana Jara <32825533+tropicadri@users.noreply.github.com>
…nsform.ts

Co-authored-by: Adriana Jara <32825533+tropicadri@users.noreply.github.com>
…nsform.ts

Co-authored-by: Adriana Jara <32825533+tropicadri@users.noreply.github.com>
Co-authored-by: Adriana Jara <32825533+tropicadri@users.noreply.github.com>
Co-authored-by: Adriana Jara <32825533+tropicadri@users.noreply.github.com>
Co-authored-by: Adriana Jara <32825533+tropicadri@users.noreply.github.com>
Co-authored-by: Adriana Jara <32825533+tropicadri@users.noreply.github.com>
Copy link
Collaborator

@tropicadri tropicadri left a comment

Choose a reason for hiding this comment

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

Sorry there was a typo in one of my previous suggestions, I added the fix.

Ack on the map undefined issue.

LGTM

…nsform.ts

Co-authored-by: Adriana Jara <32825533+tropicadri@users.noreply.github.com>
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.

[workbox-build] Uses old deprecated @hapi/joi Migrate workbox-build to TypeScript
2 participants