@vercel/next 3.9.3 → 4.0.0

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.
package/dist/index.js CHANGED
@@ -44279,7 +44279,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
44279
44279
  return (mod && mod.__esModule) ? mod : { "default": mod };
44280
44280
  };
44281
44281
  Object.defineProperty(exports, "__esModule", ({ value: true }));
44282
- exports.stringifySourceMap = exports.fileToSource = exports.raw = exports.sourcemapped = void 0;
44282
+ exports.removeInlinedSourceMap = exports.stringifySourceMap = exports.fileToSource = exports.raw = exports.sourcemapped = void 0;
44283
44283
  const convert_source_map_1 = __importDefault(__webpack_require__(7101));
44284
44284
  const fs_extra_1 = __importDefault(__webpack_require__(2650));
44285
44285
  const webpack_sources_1 = __webpack_require__(5013);
@@ -44326,7 +44326,7 @@ exports.raw = raw;
44326
44326
  */
44327
44327
  async function fileToSource(content, sourceName, fullFilePath) {
44328
44328
  const sourcemap = await getSourceMap(content, fullFilePath);
44329
- const cleanContent = convert_source_map_1.default.removeComments(content);
44329
+ const cleanContent = removeInlinedSourceMap(content);
44330
44330
  return sourcemap
44331
44331
  ? new webpack_sources_1.SourceMapSource(cleanContent, sourceName, sourcemap)
44332
44332
  : new webpack_sources_1.OriginalSource(cleanContent, sourceName);
@@ -44363,6 +44363,38 @@ function stringifySourceMap(sourceMap) {
44363
44363
  return JSON.stringify(obj);
44364
44364
  }
44365
44365
  exports.stringifySourceMap = stringifySourceMap;
44366
+ // Based on https://github.com/thlorenz/convert-source-map/blob/f1ed815b4edacfa9c3c5552dd342e71a3cffbb0a/index.js#L4 (MIT license)
44367
+ // Groups: 1: media type, 2: MIME type, 3: charset, 4: encoding, 5: data.
44368
+ const SOURCE_MAP_COMMENT_REGEX = /^\s*?\/[/*][@#]\s+?sourceMappingURL=data:(((?:application|text)\/json)(?:;charset=([^;,]+?)?)?)?(?:;(base64))?,(.*?)$/gm;
44369
+ function isValidSourceMapData(encoding, data) {
44370
+ if (encoding !== 'base64') {
44371
+ // Unknown encoding. I think the comment is short (e.g. URL) if it's not
44372
+ // base64 encoded, so let's keep it to be safe.
44373
+ return false;
44374
+ }
44375
+ // Remove any spaces and "*/" of the source map comment. They should not be
44376
+ // considered as a part of the source map data.
44377
+ data = data.replace(/\s/g, '').replace(/\*\//g, '');
44378
+ // If it's an invalid base64 string, it must be a sourceMappingURL
44379
+ // inside a template literal like the follwoing.
44380
+ // https://github.com/webpack-contrib/style-loader/blob/16e401b17a39544d5c8ca47c9032f02e2b60d8f5/src/runtime/styleDomAPI.js#L35C1-L40C1
44381
+ return /^[a-zA-Z0-9+=/]+$/.test(data);
44382
+ }
44383
+ /*
44384
+ * Removes sourceMappingURL comments from a string.
44385
+ */
44386
+ function removeInlinedSourceMap(source) {
44387
+ for (const m of source.matchAll(SOURCE_MAP_COMMENT_REGEX)) {
44388
+ // Check if it's certainly a sourceMappingURL in a comment, not a part
44389
+ // of JavaScript code (e.g. template literal).
44390
+ if (!isValidSourceMapData(m[4], m[5])) {
44391
+ continue;
44392
+ }
44393
+ source = source.replace(m[0], '');
44394
+ }
44395
+ return source;
44396
+ }
44397
+ exports.removeInlinedSourceMap = removeInlinedSourceMap;
44366
44398
 
44367
44399
 
44368
44400
  /***/ }),
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.stringifySourceMap = exports.fileToSource = exports.raw = exports.sourcemapped = void 0;
6
+ exports.removeInlinedSourceMap = exports.stringifySourceMap = exports.fileToSource = exports.raw = exports.sourcemapped = void 0;
7
7
  const convert_source_map_1 = __importDefault(require("convert-source-map"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const webpack_sources_1 = require("webpack-sources");
@@ -50,7 +50,7 @@ exports.raw = raw;
50
50
  */
51
51
  async function fileToSource(content, sourceName, fullFilePath) {
52
52
  const sourcemap = await getSourceMap(content, fullFilePath);
53
- const cleanContent = convert_source_map_1.default.removeComments(content);
53
+ const cleanContent = removeInlinedSourceMap(content);
54
54
  return sourcemap
55
55
  ? new webpack_sources_1.SourceMapSource(cleanContent, sourceName, sourcemap)
56
56
  : new webpack_sources_1.OriginalSource(cleanContent, sourceName);
@@ -87,3 +87,35 @@ function stringifySourceMap(sourceMap) {
87
87
  return JSON.stringify(obj);
88
88
  }
89
89
  exports.stringifySourceMap = stringifySourceMap;
90
+ // Based on https://github.com/thlorenz/convert-source-map/blob/f1ed815b4edacfa9c3c5552dd342e71a3cffbb0a/index.js#L4 (MIT license)
91
+ // Groups: 1: media type, 2: MIME type, 3: charset, 4: encoding, 5: data.
92
+ const SOURCE_MAP_COMMENT_REGEX = /^\s*?\/[/*][@#]\s+?sourceMappingURL=data:(((?:application|text)\/json)(?:;charset=([^;,]+?)?)?)?(?:;(base64))?,(.*?)$/gm;
93
+ function isValidSourceMapData(encoding, data) {
94
+ if (encoding !== 'base64') {
95
+ // Unknown encoding. I think the comment is short (e.g. URL) if it's not
96
+ // base64 encoded, so let's keep it to be safe.
97
+ return false;
98
+ }
99
+ // Remove any spaces and "*/" of the source map comment. They should not be
100
+ // considered as a part of the source map data.
101
+ data = data.replace(/\s/g, '').replace(/\*\//g, '');
102
+ // If it's an invalid base64 string, it must be a sourceMappingURL
103
+ // inside a template literal like the follwoing.
104
+ // https://github.com/webpack-contrib/style-loader/blob/16e401b17a39544d5c8ca47c9032f02e2b60d8f5/src/runtime/styleDomAPI.js#L35C1-L40C1
105
+ return /^[a-zA-Z0-9+=/]+$/.test(data);
106
+ }
107
+ /*
108
+ * Removes sourceMappingURL comments from a string.
109
+ */
110
+ function removeInlinedSourceMap(source) {
111
+ for (const m of source.matchAll(SOURCE_MAP_COMMENT_REGEX)) {
112
+ // Check if it's certainly a sourceMappingURL in a comment, not a part
113
+ // of JavaScript code (e.g. template literal).
114
+ if (!isValidSourceMapData(m[4], m[5])) {
115
+ continue;
116
+ }
117
+ source = source.replace(m[0], '');
118
+ }
119
+ return source;
120
+ }
121
+ exports.removeInlinedSourceMap = removeInlinedSourceMap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "3.9.3",
3
+ "version": "4.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -26,9 +26,9 @@
26
26
  "@types/semver": "6.0.0",
27
27
  "@types/text-table": "0.2.1",
28
28
  "@types/webpack-sources": "3.2.0",
29
- "@vercel/build-utils": "6.8.2",
29
+ "@vercel/build-utils": "7.0.0",
30
30
  "@vercel/nft": "0.22.5",
31
- "@vercel/routing-utils": "2.2.1",
31
+ "@vercel/routing-utils": "3.0.0",
32
32
  "async-sema": "3.0.1",
33
33
  "buffer-crc32": "0.2.13",
34
34
  "bytes": "3.1.2",
@@ -40,6 +40,7 @@
40
40
  "find-up": "4.1.0",
41
41
  "fs-extra": "7.0.0",
42
42
  "get-port": "5.0.0",
43
+ "jest-junit": "16.0.0",
43
44
  "nanoid": "3.3.4",
44
45
  "ndjson": "2.0.0",
45
46
  "pretty-bytes": "5.3.0",
@@ -54,7 +55,7 @@
54
55
  "scripts": {
55
56
  "build": "node build.js",
56
57
  "build-dev": "node build.js --dev",
57
- "test": "jest --env node --verbose --bail --runInBand --testTimeout=360000",
58
+ "test": "jest --reporters=default --reporters=jest-junit --env node --verbose --bail --runInBand --testTimeout=360000",
58
59
  "test-unit": "pnpm test test/unit/",
59
60
  "test-next-local": "pnpm test test/integration/*.test.js test/integration/*.test.ts",
60
61
  "test-next-local:middleware": "pnpm test test/integration/middleware.test.ts",