@vercel/next 4.0.6 → 4.0.7

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.
@@ -1,121 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.removeInlinedSourceMap = exports.stringifySourceMap = exports.fileToSource = exports.raw = exports.sourcemapped = void 0;
7
- const convert_source_map_1 = __importDefault(require("convert-source-map"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const webpack_sources_1 = require("webpack-sources");
10
- /**
11
- * A template literal tag that preserves existing source maps, if any. This
12
- * allows to compose multiple sources and preserve the source maps, so we can
13
- * resolve the correct line numbers in the stack traces later on.
14
- *
15
- * @param strings The string literals.
16
- * @param sources All the sources that may optionally have source maps. Use
17
- * `raw` to pass a string that should be inserted raw (with no source map
18
- * attached).
19
- */
20
- function sourcemapped(strings, ...sources) {
21
- const concat = new webpack_sources_1.ConcatSource();
22
- for (let i = 0; i < Math.max(strings.length, sources.length); i++) {
23
- const string = strings[i];
24
- const source = sources[i];
25
- if (string)
26
- concat.add(raw(string));
27
- if (source)
28
- concat.add(source);
29
- }
30
- return concat;
31
- }
32
- exports.sourcemapped = sourcemapped;
33
- /**
34
- * A helper to create a Source from a string with no source map.
35
- * This allows to obfuscate the source code from the user and print `[native code]`
36
- * when resolving the stack trace.
37
- */
38
- function raw(value) {
39
- return new webpack_sources_1.OriginalSource(value, '[native code]');
40
- }
41
- exports.raw = raw;
42
- /**
43
- * Takes a file with contents and tries to extract its source maps it will
44
- * first try to use a `${fullFilePath}.map` file if it exists. Then, it will
45
- * try to use the inline source map comment.
46
- *
47
- * @param content The file contents.
48
- * @param sourceName the name of the source.
49
- * @param fullFilePath The full path to the file.
50
- */
51
- async function fileToSource(content, sourceName, fullFilePath) {
52
- const sourcemap = await getSourceMap(content, fullFilePath);
53
- const cleanContent = removeInlinedSourceMap(content);
54
- return sourcemap
55
- ? new webpack_sources_1.SourceMapSource(cleanContent, sourceName, sourcemap)
56
- : new webpack_sources_1.OriginalSource(cleanContent, sourceName);
57
- }
58
- exports.fileToSource = fileToSource;
59
- /**
60
- * Finds a source map for a given content and file path. First it will try to
61
- * use a `${fullFilePath}.map` file if it exists. Then, it will try to use
62
- * the inline source map comment.
63
- */
64
- async function getSourceMap(content, fullFilePath) {
65
- try {
66
- if (fullFilePath && (await fs_extra_1.default.pathExists(`${fullFilePath}.map`))) {
67
- const mapJson = await fs_extra_1.default.readFile(`${fullFilePath}.map`, 'utf8');
68
- return convert_source_map_1.default.fromJSON(mapJson).toObject();
69
- }
70
- return convert_source_map_1.default.fromComment(content).toObject();
71
- }
72
- catch {
73
- return null;
74
- }
75
- }
76
- /**
77
- * Stringifies a source map, removing unnecessary data:
78
- * * `sourcesContent` is not needed to trace back frames.
79
- */
80
- function stringifySourceMap(sourceMap) {
81
- if (!sourceMap)
82
- return;
83
- const obj = typeof sourceMap === 'object'
84
- ? { ...sourceMap }
85
- : convert_source_map_1.default.fromJSON(sourceMap).toObject();
86
- delete obj.sourcesContent;
87
- return JSON.stringify(obj);
88
- }
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;