Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GoogleChrome/workbox
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.2.3
Choose a base ref
...
head repository: GoogleChrome/workbox
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.2.4
Choose a head ref
  • 2 commits
  • 62 files changed
  • 1 contributor

Commits on Aug 11, 2021

  1. Override more function validation (#2911)

    * Override more fn validation
    
    * Opt-out of linting
    jeffposnick authored Aug 11, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    74f01e3 View commit details
  2. v6.2.4

    jeffposnick committed Aug 11, 2021
    Copy the full SHA
    0074b20 View commit details
Showing with 183 additions and 151 deletions.
  1. +9 −0 gulp-tasks/build-node-packages.js
  2. +1 −1 lerna.json
  3. +1 −1 packages/workbox-background-sync/package-lock.json
  4. +2 −2 packages/workbox-background-sync/package.json
  5. +1 −1 packages/workbox-background-sync/src/_version.ts
  6. +1 −1 packages/workbox-broadcast-update/package-lock.json
  7. +2 −2 packages/workbox-broadcast-update/package.json
  8. +1 −1 packages/workbox-broadcast-update/src/_version.ts
  9. +1 −1 packages/workbox-build/package-lock.json
  10. +16 −16 packages/workbox-build/package.json
  11. +1 −1 packages/workbox-build/src/cdn-details.json
  12. +1 −0 packages/workbox-build/src/lib/errors.ts
  13. +57 −7 packages/workbox-build/src/lib/validate-options.ts
  14. +2 −9 packages/workbox-build/src/schema/GenerateSWOptions.json
  15. +2 −9 packages/workbox-build/src/schema/GetManifestOptions.json
  16. +2 −9 packages/workbox-build/src/schema/InjectManifestOptions.json
  17. +2 −9 packages/workbox-build/src/schema/WebpackGenerateSWOptions.json
  18. +2 −9 packages/workbox-build/src/schema/WebpackInjectManifestOptions.json
  19. +1 −1 packages/workbox-cacheable-response/package-lock.json
  20. +2 −2 packages/workbox-cacheable-response/package.json
  21. +1 −1 packages/workbox-cacheable-response/src/_version.ts
  22. +1 −1 packages/workbox-cli/package-lock.json
  23. +2 −2 packages/workbox-cli/package.json
  24. +1 −1 packages/workbox-core/package-lock.json
  25. +1 −1 packages/workbox-core/package.json
  26. +1 −1 packages/workbox-core/src/_version.ts
  27. +1 −1 packages/workbox-expiration/package-lock.json
  28. +2 −2 packages/workbox-expiration/package.json
  29. +1 −1 packages/workbox-expiration/src/_version.ts
  30. +1 −1 packages/workbox-google-analytics/package-lock.json
  31. +5 −5 packages/workbox-google-analytics/package.json
  32. +1 −1 packages/workbox-google-analytics/src/_version.ts
  33. +1 −1 packages/workbox-navigation-preload/package-lock.json
  34. +2 −2 packages/workbox-navigation-preload/package.json
  35. +1 −1 packages/workbox-navigation-preload/src/_version.ts
  36. +1 −1 packages/workbox-precaching/package-lock.json
  37. +4 −4 packages/workbox-precaching/package.json
  38. +1 −1 packages/workbox-precaching/src/_version.ts
  39. +1 −1 packages/workbox-range-requests/package-lock.json
  40. +2 −2 packages/workbox-range-requests/package.json
  41. +1 −1 packages/workbox-range-requests/src/_version.ts
  42. +1 −1 packages/workbox-recipes/package-lock.json
  43. +7 −7 packages/workbox-recipes/package.json
  44. +1 −1 packages/workbox-recipes/src/_version.ts
  45. +1 −1 packages/workbox-routing/package-lock.json
  46. +2 −2 packages/workbox-routing/package.json
  47. +1 −1 packages/workbox-routing/src/_version.ts
  48. +1 −1 packages/workbox-strategies/package-lock.json
  49. +2 −2 packages/workbox-strategies/package.json
  50. +1 −1 packages/workbox-strategies/src/_version.ts
  51. +1 −1 packages/workbox-streams/package-lock.json
  52. +3 −3 packages/workbox-streams/package.json
  53. +1 −1 packages/workbox-streams/src/_version.ts
  54. +1 −1 packages/workbox-sw/_version.mjs
  55. +1 −1 packages/workbox-sw/package-lock.json
  56. +1 −1 packages/workbox-sw/package.json
  57. +1 −1 packages/workbox-webpack-plugin/package-lock.json
  58. +2 −2 packages/workbox-webpack-plugin/package.json
  59. +1 −1 packages/workbox-window/package-lock.json
  60. +2 −2 packages/workbox-window/package.json
  61. +1 −1 packages/workbox-window/src/_version.ts
  62. +12 −5 test/workbox-build/node/generate-sw.js
9 changes: 9 additions & 0 deletions gulp-tasks/build-node-packages.js
Original file line number Diff line number Diff line change
@@ -71,10 +71,19 @@ async function generateWorkboxBuildJSONSchema(packagePath) {
schema.properties.include.items = {};
}

// See https://github.com/GoogleChrome/workbox/issues/2910
if (schema.definitions.OnSyncCallback) {
schema.definitions.OnSyncCallback = {};
}

if (schema.definitions.RouteMatchCallback) {
schema.definitions.RouteMatchCallback = {};
}

if (schema.definitions.RouteHandlerCallback) {
schema.definitions.RouteHandlerCallback = {};
}

// See https://github.com/GoogleChrome/workbox/issues/2901
if (schema.definitions.WorkboxPlugin) {
for (const plugin of Object.keys(
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -3,5 +3,5 @@
"packages": [
"packages/*"
],
"version": "6.2.3"
"version": "6.2.4"
}
2 changes: 1 addition & 1 deletion packages/workbox-background-sync/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/workbox-background-sync/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workbox-background-sync",
"version": "6.2.3",
"version": "6.2.4",
"license": "MIT",
"author": "Google's Web DevRel Team",
"description": "Queues failed requests and uses the Background Sync API to replay them when the network is available",
@@ -25,6 +25,6 @@
"types": "index.d.ts",
"dependencies": {
"idb": "^6.0.0",
"workbox-core": "6.2.3"
"workbox-core": "6.2.4"
}
}
2 changes: 1 addition & 1 deletion packages/workbox-background-sync/src/_version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// @ts-ignore
try{self['workbox:background-sync:6.2.3']&&_()}catch(e){}
try{self['workbox:background-sync:6.2.4']&&_()}catch(e){}
2 changes: 1 addition & 1 deletion packages/workbox-broadcast-update/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/workbox-broadcast-update/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workbox-broadcast-update",
"version": "6.2.3",
"version": "6.2.4",
"license": "MIT",
"author": "Google's Web DevRel Team",
"description": "A service worker helper library that uses the Broadcast Channel API to announce when a cached response has updated",
@@ -22,6 +22,6 @@
"module": "index.mjs",
"types": "index.d.ts",
"dependencies": {
"workbox-core": "6.2.3"
"workbox-core": "6.2.4"
}
}
2 changes: 1 addition & 1 deletion packages/workbox-broadcast-update/src/_version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// @ts-ignore
try{self['workbox:broadcast-update:6.2.3']&&_()}catch(e){}
try{self['workbox:broadcast-update:6.2.4']&&_()}catch(e){}
2 changes: 1 addition & 1 deletion packages/workbox-build/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions packages/workbox-build/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workbox-build",
"version": "6.2.3",
"version": "6.2.4",
"description": "A module that integrates into your build process, helping you generate a manifest of local files that workbox-sw should precache.",
"keywords": [
"workbox",
@@ -43,21 +43,21 @@
"strip-comments": "^2.0.1",
"tempy": "^0.6.0",
"upath": "^1.2.0",
"workbox-background-sync": "6.2.3",
"workbox-broadcast-update": "6.2.3",
"workbox-cacheable-response": "6.2.3",
"workbox-core": "6.2.3",
"workbox-expiration": "6.2.3",
"workbox-google-analytics": "6.2.3",
"workbox-navigation-preload": "6.2.3",
"workbox-precaching": "6.2.3",
"workbox-range-requests": "6.2.3",
"workbox-recipes": "6.2.3",
"workbox-routing": "6.2.3",
"workbox-strategies": "6.2.3",
"workbox-streams": "6.2.3",
"workbox-sw": "6.2.3",
"workbox-window": "6.2.3"
"workbox-background-sync": "6.2.4",
"workbox-broadcast-update": "6.2.4",
"workbox-cacheable-response": "6.2.4",
"workbox-core": "6.2.4",
"workbox-expiration": "6.2.4",
"workbox-google-analytics": "6.2.4",
"workbox-navigation-preload": "6.2.4",
"workbox-precaching": "6.2.4",
"workbox-range-requests": "6.2.4",
"workbox-recipes": "6.2.4",
"workbox-routing": "6.2.4",
"workbox-strategies": "6.2.4",
"workbox-streams": "6.2.4",
"workbox-sw": "6.2.4",
"workbox-window": "6.2.4"
},
"main": "build/index.js",
"workbox": {
2 changes: 1 addition & 1 deletion packages/workbox-build/src/cdn-details.json
Original file line number Diff line number Diff line change
@@ -2,5 +2,5 @@
"origin": "https://storage.googleapis.com",
"bucketName": "workbox-cdn",
"releasesDir": "releases",
"latestVersion": "6.2.3"
"latestVersion": "6.2.4"
}
1 change: 1 addition & 0 deletions packages/workbox-build/src/lib/errors.ts
Original file line number Diff line number Diff line change
@@ -120,4 +120,5 @@ export const errors = {
configure a custom cacheName.`,
'manifest-transforms': ol`When using manifestTransforms, you must provide
an array of functions.`,
'invalid-handler-string': ol`The handler name provided is not valid: `,
};
64 changes: 57 additions & 7 deletions packages/workbox-build/src/lib/validate-options.ts
Original file line number Diff line number Diff line change
@@ -40,7 +40,12 @@ export class WorkboxConfigError extends Error {
}
}

function validate<T>(input: unknown, methodName: MethodNames): T {
// Some methods need to do follow-up validation using the JSON schema,
// so return both the validated options and then schema.
function validate<T>(
input: unknown,
methodName: MethodNames,
): [T, JSONSchemaType<T>] {
// Don't mutate input: https://github.com/GoogleChrome/workbox/issues/2158
const inputCopy = Object.assign({}, input);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
@@ -49,7 +54,7 @@ function validate<T>(input: unknown, methodName: MethodNames): T {
if (validate(inputCopy)) {
// All methods support manifestTransforms, so validate it here.
ensureValidManifestTransforms(inputCopy);
return inputCopy;
return [inputCopy, jsonSchema];
}

const betterErrors = betterAjvErrors({
@@ -126,23 +131,65 @@ function ensureValidRuntimeCachingOrGlobDirectory(
}
}

// This is... messy, because we can't rely on the built-in ajv validation for
// runtimeCaching.handler, as it needs to accept {} (i.e. any) due to
// https://github.com/GoogleChrome/workbox/pull/2899
// So we need to perform validation when a string (not a function) is used.
function ensureValidStringHandler(
options: GenerateSWOptions | WebpackGenerateSWOptions,
jsonSchema: JSONSchemaType<GenerateSWOptions | WebpackGenerateSWOptions>,
): void {
let validHandlers: Array<string> = [];
/* eslint-disable */
for (const handler of jsonSchema.definitions?.RuntimeCaching?.properties
?.handler?.anyOf || []) {
if ('enum' in handler) {
validHandlers = handler.enum;
break;
}
}
/* eslint-enable */

for (const runtimeCaching of options.runtimeCaching || []) {
if (
typeof runtimeCaching.handler === 'string' &&
!validHandlers.includes(runtimeCaching.handler)
) {
throw new WorkboxConfigError(
errors['invalid-handler-string'] + runtimeCaching.handler,
);
}
}
}

export function validateGenerateSWOptions(input: unknown): GenerateSWOptions {
const validatedOptions = validate<GenerateSWOptions>(input, 'GenerateSW');
const [validatedOptions, jsonSchema] = validate<GenerateSWOptions>(
input,
'GenerateSW',
);
ensureValidNavigationPreloadConfig(validatedOptions);
ensureValidCacheExpiration(validatedOptions);
ensureValidRuntimeCachingOrGlobDirectory(validatedOptions);
ensureValidStringHandler(validatedOptions, jsonSchema);

return validatedOptions;
}

export function validateGetManifestOptions(input: unknown): GetManifestOptions {
return validate<GetManifestOptions>(input, 'GetManifest');
const [validatedOptions] = validate<GetManifestOptions>(input, 'GetManifest');

return validatedOptions;
}

export function validateInjectManifestOptions(
input: unknown,
): InjectManifestOptions {
return validate<InjectManifestOptions>(input, 'InjectManifest');
const [validatedOptions] = validate<InjectManifestOptions>(
input,
'InjectManifest',
);

return validatedOptions;
}

// The default `exclude: [/\.map$/, /^manifest.*\.js$/]` value can't be
@@ -157,13 +204,14 @@ export function validateWebpackGenerateSWOptions(
},
input,
);
const validatedOptions = validate<WebpackGenerateSWOptions>(
const [validatedOptions, jsonSchema] = validate<WebpackGenerateSWOptions>(
inputWithExcludeDefault,
'WebpackGenerateSW',
);

ensureValidNavigationPreloadConfig(validatedOptions);
ensureValidCacheExpiration(validatedOptions);
ensureValidStringHandler(validatedOptions, jsonSchema);

return validatedOptions;
}
@@ -178,8 +226,10 @@ export function validateWebpackInjectManifestOptions(
},
input,
);
return validate<WebpackInjectManifestOptions>(
const [validatedOptions] = validate<WebpackInjectManifestOptions>(
inputWithExcludeDefault,
'WebpackInjectManifest',
);

return validatedOptions;
}
11 changes: 2 additions & 9 deletions packages/workbox-build/src/schema/GenerateSWOptions.json
Original file line number Diff line number Diff line change
@@ -407,11 +407,7 @@
"urlPattern"
]
},
"RouteHandlerCallback": {
"description": "The \"handler\" callback is invoked whenever a `Router` matches a URL/Request\nto a `Route` via its `RouteMatchCallback`. This handler callback should\nreturn a `Promise` that resolves with a `Response`.\n\nIf a non-empty array or object is returned by the `RouteMatchCallback` it\nwill be passed in as this handler's `options.params` argument.",
"type": "object",
"additionalProperties": false
},
"RouteHandlerCallback": {},
"RouteHandlerObject": {
"description": "An object with a `handle` method of type `RouteHandlerCallback`.\n\nA `Route` object can be created with either an `RouteHandlerCallback`\nfunction or this `RouteHandler` object. The benefit of the `RouteHandler`\nis it can be extended (as is done by the `workbox-strategies` package).",
"type": "object",
@@ -437,10 +433,7 @@
},
"additionalProperties": false
},
"OnSyncCallback": {
"type": "object",
"additionalProperties": false
},
"OnSyncCallback": {},
"BroadcastCacheUpdateOptions": {
"type": "object",
"properties": {
11 changes: 2 additions & 9 deletions packages/workbox-build/src/schema/GetManifestOptions.json
Original file line number Diff line number Diff line change
@@ -299,11 +299,7 @@
"urlPattern"
]
},
"RouteHandlerCallback": {
"description": "The \"handler\" callback is invoked whenever a `Router` matches a URL/Request\nto a `Route` via its `RouteMatchCallback`. This handler callback should\nreturn a `Promise` that resolves with a `Response`.\n\nIf a non-empty array or object is returned by the `RouteMatchCallback` it\nwill be passed in as this handler's `options.params` argument.",
"type": "object",
"additionalProperties": false
},
"RouteHandlerCallback": {},
"RouteHandlerObject": {
"description": "An object with a `handle` method of type `RouteHandlerCallback`.\n\nA `Route` object can be created with either an `RouteHandlerCallback`\nfunction or this `RouteHandler` object. The benefit of the `RouteHandler`\nis it can be extended (as is done by the `workbox-strategies` package).",
"type": "object",
@@ -329,10 +325,7 @@
},
"additionalProperties": false
},
"OnSyncCallback": {
"type": "object",
"additionalProperties": false
},
"OnSyncCallback": {},
"BroadcastCacheUpdateOptions": {
"type": "object",
"properties": {
11 changes: 2 additions & 9 deletions packages/workbox-build/src/schema/InjectManifestOptions.json
Original file line number Diff line number Diff line change
@@ -311,11 +311,7 @@
"urlPattern"
]
},
"RouteHandlerCallback": {
"description": "The \"handler\" callback is invoked whenever a `Router` matches a URL/Request\nto a `Route` via its `RouteMatchCallback`. This handler callback should\nreturn a `Promise` that resolves with a `Response`.\n\nIf a non-empty array or object is returned by the `RouteMatchCallback` it\nwill be passed in as this handler's `options.params` argument.",
"type": "object",
"additionalProperties": false
},
"RouteHandlerCallback": {},
"RouteHandlerObject": {
"description": "An object with a `handle` method of type `RouteHandlerCallback`.\n\nA `Route` object can be created with either an `RouteHandlerCallback`\nfunction or this `RouteHandler` object. The benefit of the `RouteHandler`\nis it can be extended (as is done by the `workbox-strategies` package).",
"type": "object",
@@ -341,10 +337,7 @@
},
"additionalProperties": false
},
"OnSyncCallback": {
"type": "object",
"additionalProperties": false
},
"OnSyncCallback": {},
"BroadcastCacheUpdateOptions": {
"type": "object",
"properties": {
11 changes: 2 additions & 9 deletions packages/workbox-build/src/schema/WebpackGenerateSWOptions.json
Original file line number Diff line number Diff line change
@@ -386,11 +386,7 @@
"urlPattern"
]
},
"RouteHandlerCallback": {
"description": "The \"handler\" callback is invoked whenever a `Router` matches a URL/Request\nto a `Route` via its `RouteMatchCallback`. This handler callback should\nreturn a `Promise` that resolves with a `Response`.\n\nIf a non-empty array or object is returned by the `RouteMatchCallback` it\nwill be passed in as this handler's `options.params` argument.",
"type": "object",
"additionalProperties": false
},
"RouteHandlerCallback": {},
"RouteHandlerObject": {
"description": "An object with a `handle` method of type `RouteHandlerCallback`.\n\nA `Route` object can be created with either an `RouteHandlerCallback`\nfunction or this `RouteHandler` object. The benefit of the `RouteHandler`\nis it can be extended (as is done by the `workbox-strategies` package).",
"type": "object",
@@ -416,10 +412,7 @@
},
"additionalProperties": false
},
"OnSyncCallback": {
"type": "object",
"additionalProperties": false
},
"OnSyncCallback": {},
"BroadcastCacheUpdateOptions": {
"type": "object",
"properties": {
Original file line number Diff line number Diff line change
@@ -298,11 +298,7 @@
"urlPattern"
]
},
"RouteHandlerCallback": {
"description": "The \"handler\" callback is invoked whenever a `Router` matches a URL/Request\nto a `Route` via its `RouteMatchCallback`. This handler callback should\nreturn a `Promise` that resolves with a `Response`.\n\nIf a non-empty array or object is returned by the `RouteMatchCallback` it\nwill be passed in as this handler's `options.params` argument.",
"type": "object",
"additionalProperties": false
},
"RouteHandlerCallback": {},
"RouteHandlerObject": {
"description": "An object with a `handle` method of type `RouteHandlerCallback`.\n\nA `Route` object can be created with either an `RouteHandlerCallback`\nfunction or this `RouteHandler` object. The benefit of the `RouteHandler`\nis it can be extended (as is done by the `workbox-strategies` package).",
"type": "object",
@@ -328,10 +324,7 @@
},
"additionalProperties": false
},
"OnSyncCallback": {
"type": "object",
"additionalProperties": false
},
"OnSyncCallback": {},
"BroadcastCacheUpdateOptions": {
"type": "object",
"properties": {
Loading