msw 2.2.4 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -122,6 +122,9 @@ function isNodeProcess() {
122
122
  return false;
123
123
  }
124
124
 
125
+ // src/browser/setupWorker/start/createStartHandler.ts
126
+ var import_devUtils7 = require("../core/utils/internal/devUtils.js");
127
+
125
128
  // node_modules/.pnpm/@open-draft+until@2.1.0/node_modules/@open-draft/until/lib/index.mjs
126
129
  var until = async (promise) => {
127
130
  try {
@@ -134,9 +137,6 @@ var until = async (promise) => {
134
137
  }
135
138
  };
136
139
 
137
- // src/browser/setupWorker/start/createStartHandler.ts
138
- var import_devUtils6 = require("../core/utils/internal/devUtils.js");
139
-
140
140
  // src/browser/setupWorker/start/utils/getWorkerInstance.ts
141
141
  var import_devUtils = require("../core/utils/internal/devUtils.js");
142
142
 
@@ -379,18 +379,22 @@ This exception has been gracefully handled as a 500 response, however, it's stro
379
379
  };
380
380
  };
381
381
 
382
- // src/browser/utils/requestIntegrityCheck.ts
383
- async function requestIntegrityCheck(context, serviceWorker) {
382
+ // src/browser/utils/checkWorkerIntegrity.ts
383
+ var import_devUtils5 = require("../core/utils/internal/devUtils.js");
384
+ async function checkWorkerIntegrity(context) {
384
385
  context.workerChannel.send("INTEGRITY_CHECK_REQUEST");
385
- const { payload: actualChecksum } = await context.events.once(
386
- "INTEGRITY_CHECK_RESPONSE"
387
- );
388
- if (actualChecksum !== "223d191a56023cd36aa88c802961b911") {
389
- throw new Error(
390
- `Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"223d191a56023cd36aa88c802961b911"}).`
386
+ const { payload } = await context.events.once("INTEGRITY_CHECK_RESPONSE");
387
+ if (payload.checksum !== "5db7e6e8385dc04e017ac4823e0e9b29") {
388
+ import_devUtils5.devUtils.warn(
389
+ `The currently registered Service Worker has been generated by a different version of MSW (${payload.packageVersion}) and may not be fully compatible with the installed version.
390
+
391
+ It's recommended you update your worker script by running this command:
392
+
393
+ \u2022 npx msw init <PUBLIC_DIR>
394
+
395
+ You can also automate this process and make the worker script update automatically upon the library installations. Read more: https://mswjs.io/docs/cli/init.`
391
396
  );
392
397
  }
393
- return serviceWorker;
394
398
  }
395
399
 
396
400
  // node_modules/.pnpm/@mswjs+interceptors@0.25.16/node_modules/@mswjs/interceptors/lib/browser/chunk-UJZOJSMP.mjs
@@ -1083,10 +1087,10 @@ function createResponseListener(context) {
1083
1087
  }
1084
1088
 
1085
1089
  // src/browser/setupWorker/start/utils/validateWorkerScope.ts
1086
- var import_devUtils5 = require("../core/utils/internal/devUtils.js");
1090
+ var import_devUtils6 = require("../core/utils/internal/devUtils.js");
1087
1091
  function validateWorkerScope(registration, options) {
1088
1092
  if (!options?.quiet && !location.href.startsWith(registration.scope)) {
1089
- import_devUtils5.devUtils.warn(
1093
+ import_devUtils6.devUtils.warn(
1090
1094
  `Cannot intercept requests on this page because it's outside of the worker's scope ("${registration.scope}"). If you wish to mock API requests on this page, you must resolve this scope issue.
1091
1095
 
1092
1096
  - (Recommended) Register the worker at the root level ("/") of your application.
@@ -1112,14 +1116,14 @@ var createStartHandler = (context) => {
1112
1116
  );
1113
1117
  const [worker, registration] = instance;
1114
1118
  if (!worker) {
1115
- const missingWorkerMessage = customOptions?.findWorker ? import_devUtils6.devUtils.formatMessage(
1119
+ const missingWorkerMessage = customOptions?.findWorker ? import_devUtils7.devUtils.formatMessage(
1116
1120
  `Failed to locate the Service Worker registration using a custom "findWorker" predicate.
1117
1121
 
1118
1122
  Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
1119
1123
  More details: https://mswjs.io/docs/api/setup-worker/start#findworker
1120
1124
  `,
1121
1125
  options.serviceWorker.url
1122
- ) : import_devUtils6.devUtils.formatMessage(
1126
+ ) : import_devUtils7.devUtils.formatMessage(
1123
1127
  `Failed to locate the Service Worker registration.
1124
1128
 
1125
1129
  This most likely means that the worker script URL "%s" cannot resolve against the actual public hostname (%s). This may happen if your application runs behind a proxy, or has a dynamic hostname.
@@ -1138,19 +1142,12 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
1138
1142
  }
1139
1143
  window.clearInterval(context.keepAliveInterval);
1140
1144
  });
1141
- const integrityCheckResult = await until(
1142
- () => requestIntegrityCheck(context, worker)
1143
- );
1144
- if (integrityCheckResult.error) {
1145
- import_devUtils6.devUtils.error(`Detected outdated Service Worker: ${integrityCheckResult.error.message}
1146
-
1147
- The mocking is still enabled, but it's highly recommended that you update your Service Worker by running:
1148
-
1149
- $ npx msw init <PUBLIC_DIR>
1150
-
1151
- This is necessary to ensure that the Service Worker is in sync with the library to guarantee its stability.
1152
- If this message still persists after updating, please report an issue: https://github.com/open-draft/msw/issues `);
1153
- }
1145
+ await checkWorkerIntegrity(context).catch((error2) => {
1146
+ import_devUtils7.devUtils.error(
1147
+ "Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues), including the original error below."
1148
+ );
1149
+ console.error(error2);
1150
+ });
1154
1151
  context.keepAliveInterval = window.setInterval(
1155
1152
  () => context.workerChannel.send("KEEPALIVE_REQUEST"),
1156
1153
  5e3
@@ -1181,16 +1178,16 @@ If this message still persists after updating, please report an issue: https://g
1181
1178
  };
1182
1179
 
1183
1180
  // src/browser/setupWorker/stop/createStop.ts
1184
- var import_devUtils8 = require("../core/utils/internal/devUtils.js");
1181
+ var import_devUtils9 = require("../core/utils/internal/devUtils.js");
1185
1182
 
1186
1183
  // src/browser/setupWorker/stop/utils/printStopMessage.ts
1187
- var import_devUtils7 = require("../core/utils/internal/devUtils.js");
1184
+ var import_devUtils8 = require("../core/utils/internal/devUtils.js");
1188
1185
  function printStopMessage(args = {}) {
1189
1186
  if (args.quiet) {
1190
1187
  return;
1191
1188
  }
1192
1189
  console.log(
1193
- `%c${import_devUtils7.devUtils.formatMessage("Mocking disabled.")}`,
1190
+ `%c${import_devUtils8.devUtils.formatMessage("Mocking disabled.")}`,
1194
1191
  "color:orangered;font-weight:bold;"
1195
1192
  );
1196
1193
  }
@@ -1199,7 +1196,7 @@ function printStopMessage(args = {}) {
1199
1196
  var createStop = (context) => {
1200
1197
  return function stop() {
1201
1198
  if (!context.isMockingEnabled) {
1202
- import_devUtils8.devUtils.warn(
1199
+ import_devUtils9.devUtils.warn(
1203
1200
  'Found a redundant "worker.stop()" call. Note that stopping the worker while mocking already stopped has no effect. Consider removing this "worker.stop()" call.'
1204
1201
  );
1205
1202
  return;
@@ -2290,7 +2287,7 @@ function createFallbackStop(context) {
2290
2287
  }
2291
2288
 
2292
2289
  // src/browser/setupWorker/setupWorker.ts
2293
- var import_devUtils9 = require("../core/utils/internal/devUtils.js");
2290
+ var import_devUtils10 = require("../core/utils/internal/devUtils.js");
2294
2291
  var import_SetupApi = require("../core/SetupApi.js");
2295
2292
  var import_mergeRight2 = require("../core/utils/internal/mergeRight.js");
2296
2293
 
@@ -2318,7 +2315,7 @@ var SetupWorkerApi = class extends import_SetupApi.SetupApi {
2318
2315
  super(...handlers);
2319
2316
  invariant(
2320
2317
  !isNodeProcess(),
2321
- import_devUtils9.devUtils.formatMessage(
2318
+ import_devUtils10.devUtils.formatMessage(
2322
2319
  "Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead."
2323
2320
  )
2324
2321
  );
@@ -2416,7 +2413,7 @@ var SetupWorkerApi = class extends import_SetupApi.SetupApi {
2416
2413
  }
2417
2414
  async start(options = {}) {
2418
2415
  if (options.waitUntilReady === true) {
2419
- import_devUtils9.devUtils.warn(
2416
+ import_devUtils10.devUtils.warn(
2420
2417
  'The "waitUntilReady" option has been deprecated. Please remove it from this "worker.start()" call. Follow the recommended Browser integration (https://mswjs.io/docs/integrations/browser) to eliminate any race conditions between the Service Worker registration and any requests made by your application on initial render.'
2421
2418
  );
2422
2419
  }