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

rangeRequests option in runtimeCaching #2871

Merged
merged 3 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 gulp-tasks/build-node-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function generateWorkboxBuildJSONSchema(packagePath) {
schema.definitions.RouteMatchCallback.typeof = 'function';
}
await fse.writeJSON(upath.join(packagePath, 'src', 'schema',
`${optionType}.json`), schema);
`${optionType}.json`), schema, {spaces: 2});
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/workbox-build/src/_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ import './_version.mjs';
* property to use when creating the
* [`PrecacheFallbackPlugin`]{@link module:workbox-precaching.PrecacheFallbackPlugin}.
*
* @property {boolean} [options.rangeRequests] Set to `true` to add the
* [`RangeRequestsPlugin`]{@link module:workbox-range-requests.RangeRequestsPlugin}
* for the strategy being configured.
*
* @property {Object} [options.matchOptions] The `matchOptions` property value
* to use when constructing one of the
* [Workbox strategy classes]{@link module:workbox-strategies}.
Expand Down
9 changes: 9 additions & 0 deletions packages/workbox-build/src/lib/runtime-caching-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ function getOptionsString(moduleRegistry: ModuleRegistry, options: RuntimeCachin
break;
}

case 'rangeRequests': {
const plugin = moduleRegistry.use(
'workbox-range-requests', 'RangeRequestsPlugin');

// There are no configuration options for the constructor.
plugins.push(`new ${plugin}()`);
break;
}

default: {
throw new Error(errors['bad-runtime-caching-config'] + optionName);
}
Expand Down
871 changes: 870 additions & 1 deletion packages/workbox-build/src/schema/GenerateSWOptions.json

Large diffs are not rendered by default.

763 changes: 762 additions & 1 deletion packages/workbox-build/src/schema/GetManifestOptions.json

Large diffs are not rendered by default.

775 changes: 774 additions & 1 deletion packages/workbox-build/src/schema/InjectManifestOptions.json

Large diffs are not rendered by default.

874 changes: 873 additions & 1 deletion packages/workbox-build/src/schema/WebpackGenerateSWOptions.json

Large diffs are not rendered by default.

786 changes: 785 additions & 1 deletion packages/workbox-build/src/schema/WebpackInjectManifestOptions.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/workbox-build/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface RuntimeCaching {
precacheFallback?: {
fallbackURL: string;
};
rangeRequests?: boolean;
fetchOptions?: RequestInit;
matchOptions?: CacheQueryOptions;
};
Expand Down
7 changes: 7 additions & 0 deletions test/workbox-build/node/lib/runtime-caching-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function validate(runtimeCachingOptions, convertedOptions) {
workbox_background_sync_BackgroundSyncPlugin: sinon.spy(),
workbox_broadcast_update_BroadcastUpdatePlugin: sinon.spy(),
workbox_precaching_PrecacheFallbackPlugin: sinon.spy(),
workbox_range_requests_RangeRequestsPlugin: sinon.spy(),
workbox_routing_registerRoute: sinon.spy(),
workbox_strategies_CacheFirst: sinon.spy(),
workbox_strategies_CacheOnly: sinon.spy(),
Expand Down Expand Up @@ -102,6 +103,10 @@ function validate(runtimeCachingOptions, convertedOptions) {
expect(globalScope.workbox_precaching_PrecacheFallbackPlugin.calledWith(options.precacheFallback)).to.be.true;
}

if (options.rangeRequests) {
expect(globalScope.workbox_range_requests_RangeRequestsPlugin.calledWith()).to.be.true;
}

if (options.backgroundSync) {
if ('options' in options.backgroundSync) {
expect(
Expand Down Expand Up @@ -190,6 +195,7 @@ describe(`[workbox-build] src/lib/utils/runtime-caching-converter.js`, function(
precacheFallback: {
fallbackURL: '/test1',
},
rangeRequests: false,
fetchOptions: {
headers: {
'Custom': 'Header',
Expand Down Expand Up @@ -218,6 +224,7 @@ describe(`[workbox-build] src/lib/utils/runtime-caching-converter.js`, function(
maxRetentionTime: 123,
},
},
rangeRequests: true,
precacheFallback: {
fallbackURL: '/test2',
},
Expand Down