Skip to content

Commit 26958c6

Browse files
authored
Remove the isSWEnv dev assertion (#2453)
1 parent 257b5c4 commit 26958c6

File tree

6 files changed

+0
-68
lines changed

6 files changed

+0
-68
lines changed

packages/workbox-core/src/_private/assert.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@
99
import {WorkboxError, WorkboxErrorDetails} from '../_private/WorkboxError.js';
1010
import '../_version.js';
1111

12-
13-
/*
14-
* This method returns true if the current context is a service worker.
15-
*/
16-
const isSWEnv = (moduleName: string) => {
17-
if (!('ServiceWorkerGlobalScope' in self)) {
18-
throw new WorkboxError('not-in-sw', {moduleName});
19-
}
20-
};
21-
2212
/*
2313
* This method throws if the supplied value is not an array.
2414
* The destructed values are required to produce a meaningful error for users.
@@ -101,7 +91,6 @@ const finalAssertExports = process.env.NODE_ENV === 'production' ? null : {
10191
isArray,
10292
isInstance,
10393
isOneOf,
104-
isSWEnv,
10594
isType,
10695
isArrayOfClass,
10796
};

packages/workbox-core/src/models/messages/messages.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ export const messages: MessageMap = {
2727
`${JSON.stringify(value)}.`;
2828
},
2929

30-
'not-in-sw': ({moduleName}) => {
31-
if (!moduleName) {
32-
throw new Error(`Unexpected input to 'not-in-sw' error.`);
33-
}
34-
return `The '${moduleName}' must be used in a service worker.`;
35-
},
36-
3730
'not-an-array': ({moduleName, className, funcName, paramName}) => {
3831
if (!moduleName || !className || !funcName || !paramName) {
3932
throw new Error(`Unexpected input to 'not-an-array' error.`);

packages/workbox-precaching/src/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
https://opensource.org/licenses/MIT.
77
*/
88

9-
import {assert} from 'workbox-core/_private/assert.js';
10-
119
import {addPlugins} from './addPlugins.js';
1210
import {addRoute} from './addRoute.js';
1311
import {cleanupOutdatedCaches} from './cleanupOutdatedCaches.js';
@@ -21,10 +19,6 @@ import {PrecacheController} from './PrecacheController.js';
2119

2220
import './_version.js';
2321

24-
if (process.env.NODE_ENV !== 'production') {
25-
assert!.isSWEnv('workbox-precaching');
26-
}
27-
2822
/**
2923
* Most consumers of this module will want to use the
3024
* [precacheAndRoute()]{@link module:workbox-precaching.precacheAndRoute}

test/workbox-core/sw/_private/test-assert.mjs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,6 @@ describe(`assert`, function() {
1616
}
1717
});
1818

19-
describe(`isSWEnv`, function() {
20-
let sandbox;
21-
before(function() {
22-
sandbox = sinon.createSandbox();
23-
});
24-
25-
afterEach(function() {
26-
sandbox.restore();
27-
});
28-
29-
it(`should throw if ServiceWorkerGlobalScope is not defined`, async function() {
30-
if (process.env.NODE_ENV === 'production') this.skip();
31-
32-
const originalServiceWorkerGlobalScope = self.ServiceWorkerGlobalScope;
33-
delete self.ServiceWorkerGlobalScope;
34-
35-
await expectError(() => assert.isSWEnv('example-module'), 'not-in-sw');
36-
37-
self.ServiceWorkerGlobalScope = originalServiceWorkerGlobalScope;
38-
});
39-
40-
it(`should return false if self is not an instance of ServiceWorkerGlobalScope`, function() {
41-
if (process.env.NODE_ENV === 'production') this.skip();
42-
43-
sandbox.stub(self, 'self').value({});
44-
45-
return expectError(() => assert.isSWEnv('example-module'), 'not-in-sw');
46-
});
47-
48-
it(`should not throw if self is an instance of ServiceWorkerGlobalScope`, function() {
49-
if (process.env.NODE_ENV === 'production') this.skip();
50-
51-
assert.isSWEnv('example-module');
52-
});
53-
});
54-
5519
describe(`isArray`, function() {
5620
it(`shouldn't throw when given an array`, function() {
5721
if (process.env.NODE_ENV === 'production') this.skip();

test/workbox-precaching/static/addToCacheList.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ <h3>precache.addToCacheList()</h3>
77
<button class="js-index-unrevisioned">Add Unrevisioned Assets</button>
88

99
<script src="../../../../packages/workbox-core/build/browser/workbox-core.dev.js"></script>
10-
<script>
11-
// Make precaching think it's in the SW.
12-
workbox.core.default.assert.isSWEnv = () => {}
13-
</script>
1410
<script src="../../../../packages/workbox-precaching/build/browser/workbox-precaching.dev.js"></script>
1511
<script>
1612
const precacheController = new workbox.precaching.PrecacheController();

test/workbox-precaching/static/precache.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ <h3>precache.install() &amp; precache.activate()</h3>
1414
};
1515
</script>
1616
<script src="../../../../packages/workbox-core/build/browser/workbox-core.dev.js"></script>
17-
<script>
18-
// Make precaching think it's in the SW.
19-
workbox.core.default.assert.isSWEnv = () => {}
20-
</script>
2117
<script src="../../../../packages/workbox-precaching/build/browser/workbox-precaching.dev.js"></script>
2218

2319
<script>

0 commit comments

Comments
 (0)