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
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
f2009fe
WIP
jeffposnick Dec 23, 2020
56c29b0
Finished getManifest
jeffposnick Dec 23, 2020
e1f6105
GenerateSW migrated
jeffposnick Dec 23, 2020
5a27e31
Getting there
jeffposnick Dec 23, 2020
e6ad7b3
WIP
jeffposnick Dec 23, 2020
b774e0d
Runtime caching TS
jeffposnick Dec 24, 2020
f1bc1a8
More WIP
jeffposnick Jan 16, 2021
85b6aff
More WIP
jeffposnick Jan 16, 2021
65e69c6
Validation, type fixes
jeffposnick Jan 16, 2021
c40c873
Builds!
jeffposnick Jan 16, 2021
1e946bf
No default exports
jeffposnick Jan 17, 2021
1c2df4f
null support in optional strings
jeffposnick Feb 10, 2021
3f52fbc
Merge remote-tracking branch 'origin/v6' into wb-build-ts
jeffposnick Apr 27, 2021
aa9e454
Accept string or buffer again
jeffposnick Apr 30, 2021
d672134
Fix JSDocs
jeffposnick May 5, 2021
63d1be2
Merge remote-tracking branch 'origin/v6' into wb-build-ts
jeffposnick May 23, 2021
7c9c646
CanIUse update
jeffposnick May 23, 2021
b2e0f19
test/additional-manifest-entries-transform
jeffposnick May 23, 2021
06bb97d
lib/bundle
jeffposnick May 23, 2021
0f6c05a
cdnUtils test
jeffposnick Jun 4, 2021
464f0c3
Switched to esModuleInterop
jeffposnick Jun 4, 2021
e5ab8b0
Still WIP
jeffposnick Jun 4, 2021
a49d5cd
get-file-size migration
jeffposnick Jun 7, 2021
b9427d2
get-string-details test migration
jeffposnick Jun 7, 2021
f364a00
A few more
jeffposnick Jun 7, 2021
705e832
populateSWTemplate changes
jeffposnick Jun 7, 2021
1337286
A few more
jeffposnick Jun 8, 2021
6ba9a82
validate options
jeffposnick Jun 8, 2021
3ccfdde
Update ts-auto-guard
jeffposnick Jun 8, 2021
9184df0
Fix dependency-check
jeffposnick Jun 8, 2021
728ca6d
Swapped the exports
jeffposnick Jun 8, 2021
82fbb94
JSON Schema + ajv
jeffposnick Jun 9, 2021
cd28f02
TS 4.1.5
jeffposnick Jun 9, 2021
d258ac1
Getting closer to validation
jeffposnick Jun 9, 2021
0069bba
Some default logic
jeffposnick Jun 9, 2021
2f80549
Switched default quotes
jeffposnick Jun 9, 2021
ed52775
Cleanup optional types
jeffposnick Jun 9, 2021
a8a161c
Figuring out errors
jeffposnick Jun 9, 2021
759b196
Refactor
jeffposnick Jun 9, 2021
cdabfc8
Update validate-options test
jeffposnick Jun 9, 2021
69b9e66
Started integration test migration
jeffposnick Jun 9, 2021
4749d24
Remove joi schema
jeffposnick Jun 9, 2021
48559c8
Fixed some swDest logic
jeffposnick Jun 9, 2021
fae8a0e
Closer to webpack tests working
jeffposnick Jun 9, 2021
f3a4e8b
Fix transformManifest usage
jeffposnick Jun 9, 2021
53aa9a8
Use a copy of the exclude array
jeffposnick Jun 10, 2021
acfbefe
More include/exclude fun
jeffposnick Jun 10, 2021
afdae9f
swDest default fix
jeffposnick Jun 10, 2021
38ac1e6
Function support?
jeffposnick Jun 10, 2021
649985f
modifyURLPrefix workaround
jeffposnick Jun 10, 2021
6a79eb1
Fix an import
jeffposnick Jun 10, 2021
1f780ac
Improve error messages
jeffposnick Jun 10, 2021
311b1d6
Fix test string
jeffposnick Jun 10, 2021
4475aec
New validation unit test
jeffposnick Jun 10, 2021
ad68acc
getManifest working
jeffposnick Jun 10, 2021
19c207a
Working through generateSW
jeffposnick Jun 10, 2021
7d895fc
Function massaging
jeffposnick Jun 14, 2021
fb4aa3e
Cleanup of exclude/include
jeffposnick Jun 14, 2021
a856e6b
Fix a few more gSW tests
jeffposnick Jun 14, 2021
3945e8b
RouteMatchCallback function
jeffposnick Jun 14, 2021
aed3f6a
Expiration w/cacheName check
jeffposnick Jun 14, 2021
a534b13
Optional globDirectory
jeffposnick Jun 14, 2021
dfafd9e
InjectManifest tests
jeffposnick Jun 14, 2021
d50d4db
Test cleanup
jeffposnick Jun 14, 2021
25cfa2f
Fix a test
jeffposnick Jun 14, 2021
0cca507
Fix a config modification
jeffposnick Jun 14, 2021
935ca5e
v5 injectmanifest test
jeffposnick Jun 14, 2021
781e92d
esModuleInterop support
jeffposnick Jun 14, 2021
a7ef09d
Fixes for proxied build
jeffposnick Jun 15, 2021
d812352
Final tweaks
jeffposnick Jun 15, 2021
3ec8ddc
Linting
jeffposnick Jun 16, 2021
a9eee0f
Automated linting fixes
jeffposnick Jun 16, 2021
6a71bb2
Tweak linting rules
jeffposnick Jun 16, 2021
76bc659
Update packages/workbox-build/src/lib/get-file-details.ts
jeffposnick Jun 16, 2021
14cc0ad
Update test/workbox-build/node/generate-sw.js
jeffposnick Jun 16, 2021
8816a4d
Update packages/workbox-build/src/lib/additional-manifest-entries-tra…
jeffposnick Jun 16, 2021
207bb4f
Update packages/workbox-build/src/lib/additional-manifest-entries-tra…
jeffposnick Jun 16, 2021
19a3ff3
Update packages/workbox-build/src/lib/cdn-utils.ts
jeffposnick Jun 16, 2021
4e363bd
Update packages/workbox-build/src/lib/get-file-manifest-entries.ts
jeffposnick Jun 16, 2021
c066941
Update packages/workbox-build/src/lib/stringify-without-comments.ts
jeffposnick Jun 16, 2021
4caaaeb
Update packages/workbox-build/src/lib/validate-options.ts
jeffposnick Jun 16, 2021
4af8d17
Update packages/workbox-build/src/lib/additional-manifest-entries-tra…
jeffposnick Jun 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ firebase-debug.log
# Generated TypeScript files and build data
tsconfig.tsbuildinfo
packages/workbox-*/**/*.d.ts
!packages/workbox-cli/src/index.d.ts
!packages/workbox-*/src/**/*.d.ts
packages/workbox-*/**/*.js
!packages/workbox-build/**/*.js
!packages/workbox-webpack-plugin/**/*.js
Expand Down
54 changes: 54 additions & 0 deletions gulp-tasks/build-node-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

const {parallel} = require('gulp');
const execa = require('execa');
const fse = require('fs-extra');
const TJS = require('typescript-json-schema');
const upath = require('upath');

const constants = require('./utils/constants');
Expand All @@ -28,7 +30,59 @@ async function buildNodePackage(packagePath) {
], {preferLocal: true});
}

async function generateWorkboxBuildJSONSchema(packagePath) {
const program = TJS.programFromConfig(upath.join(packagePath,
'tsconfig.json'));
const generator = TJS.buildGenerator(program, {
noExtraProps: true,
required: true,
});
const optionTypes = [
'GenerateSWOptions',
'GetManifestOptions',
'InjectManifestOptions',
'WebpackGenerateSWOptions',
'WebpackInjectManifestOptions',
];
for (const optionType of optionTypes) {
const schema = generator.getSchemaForSymbol(optionType);
// Ideally, we'd set typeOfKeyword so that functions could be represented.
// Instead, we need to hardcode a few overrides to deal with functions.
// See https://github.com/YousefED/typescript-json-schema/issues/424
if (schema.properties.manifestTransforms) {
schema.properties.manifestTransforms.items = {typeof: 'function'};
}
if (schema.properties.exclude) {
schema.properties.exclude.items.anyOf = [
{'$ref': '#/definitions/RegExp'},
{type: 'string'},
{typeof: 'function'},
];
}
if (schema.properties.include) {
schema.properties.include.items.anyOf = [
{'$ref': '#/definitions/RegExp'},
{type: 'string'},
{typeof: 'function'},
];
}
if (schema.definitions.RouteMatchCallback) {
delete schema.definitions.RouteMatchCallback.type;
delete schema.definitions.RouteMatchCallback.additionalProperties;
schema.definitions.RouteMatchCallback.typeof = 'function';
}
await fse.writeJSON(upath.join(packagePath, 'src', 'schema',
`${optionType}.json`), schema);
}
}

async function buildNodeTSPackage(packagePath) {
// Hardcode special logic for workbox-build, as it's the only package
// that requires JSON schema generation.
if (packagePath.endsWith('workbox-build')) {
await generateWorkboxBuildJSONSchema(packagePath);
}

await execa('tsc', ['-b', packagePath], {preferLocal: true});
}

Expand Down
12 changes: 7 additions & 5 deletions gulp-tasks/build-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ async function cleanPackage(packagePath) {
if (await fse.pathExists(upath.join(packagePath, 'src', 'index.ts'))) {
// Store the list of deleted files, so we can delete directories after.
const deletedPaths = await del([
upath.join(packagePath, '**/*.+(js|mjs|d.ts)'),
`${packagePath}/**/*.+(js|mjs|d.ts)`,
// Don't delete files in node_modules.
'!**/node_modules', '!**/node_modules/**/*',
'!**/node_modules/**/*',
// Don't delete anything under src.
`!${packagePath}/src/**/*`,
]);

// Any directories in `deletedPaths` that are top-level directories to the
Expand Down Expand Up @@ -57,12 +59,12 @@ module.exports = {
build_packages_clean: cleanSequence(),
build_packages: series(
cleanSequence(),
// This needs to be a series, not in parallel, so that there isn't a
// race condition with the terser nameCache.
series(build_sw_packages, build_window_packages),
parallel(
build_node_packages,
build_node_ts_packages,
// This needs to be a series, not in parallel, so that there isn't a
// race condition with the terser nameCache.
series(build_sw_packages, build_window_packages),
),
),
};
6 changes: 3 additions & 3 deletions gulp-tasks/utils/versioned-cdn-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
https://opensource.org/licenses/MIT.
*/

const {getCDNOrigin} = require(
'../../packages/workbox-build/src/lib/cdn-utils');
const cdn = require('../../packages/workbox-build/src/cdn-details.json');
const lernaPkg = require('../../lerna.json');

module.exports = () => `${getCDNOrigin()}/${lernaPkg.version}`;
module.exports = () => `${cdn.origin}/${cdn.bucketName}/${cdn.releasesDir}` +
`/${lernaPkg.version}`;
2 changes: 1 addition & 1 deletion infra/testing/webpack-build-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

function joinMessages(errorsOrWarnings) {
if ('message' in errorsOrWarnings[0]) {
if (errorsOrWarnings[0].message) {
return errorsOrWarnings.map((item) => item.message).join('\n');
} else {
return errorsOrWarnings.join('\n');
Expand Down
Loading