@depup/webpack-sources 3.3.4-depup.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/LICENSE +21 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/lib/CachedSource.js +419 -0
- package/lib/CompatSource.js +109 -0
- package/lib/ConcatSource.js +398 -0
- package/lib/OriginalSource.js +202 -0
- package/lib/PrefixSource.js +162 -0
- package/lib/RawSource.js +140 -0
- package/lib/ReplaceSource.js +557 -0
- package/lib/SizeOnlySource.js +71 -0
- package/lib/Source.js +89 -0
- package/lib/SourceMapSource.js +367 -0
- package/lib/helpers/createMappingsSerializer.js +225 -0
- package/lib/helpers/getFromStreamChunks.js +159 -0
- package/lib/helpers/getGeneratedSourceInfo.js +44 -0
- package/lib/helpers/getName.js +21 -0
- package/lib/helpers/getSource.js +24 -0
- package/lib/helpers/readMappings.js +120 -0
- package/lib/helpers/splitIntoLines.js +33 -0
- package/lib/helpers/splitIntoPotentialTokens.js +53 -0
- package/lib/helpers/streamAndGetSourceAndMap.js +123 -0
- package/lib/helpers/streamChunks.js +62 -0
- package/lib/helpers/streamChunksOfCombinedSourceMap.js +366 -0
- package/lib/helpers/streamChunksOfRawSource.js +54 -0
- package/lib/helpers/streamChunksOfSourceMap.js +499 -0
- package/lib/helpers/stringBufferUtils.js +117 -0
- package/lib/index.js +120 -0
- package/package.json +71 -0
- package/types.d.ts +461 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 JS Foundation and other contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @depup/webpack-sources
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [webpack-sources](https://www.npmjs.com/package/webpack-sources)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/webpack-sources
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [webpack-sources](https://www.npmjs.com/package/webpack-sources) @ 3.3.4 |
|
|
17
|
+
| Processed | 2026-03-17 |
|
|
18
|
+
| Smoke test | passed |
|
|
19
|
+
| Deps updated | 0 |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/webpack-sources
|
|
24
|
+
|
|
25
|
+
License inherited from the original package.
|
package/changes.json
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const Source = require("./Source");
|
|
9
|
+
const streamAndGetSourceAndMap = require("./helpers/streamAndGetSourceAndMap");
|
|
10
|
+
const streamChunksOfRawSource = require("./helpers/streamChunksOfRawSource");
|
|
11
|
+
const streamChunksOfSourceMap = require("./helpers/streamChunksOfSourceMap");
|
|
12
|
+
const {
|
|
13
|
+
isDualStringBufferCachingEnabled,
|
|
14
|
+
} = require("./helpers/stringBufferUtils");
|
|
15
|
+
|
|
16
|
+
/** @typedef {import("./Source").HashLike} HashLike */
|
|
17
|
+
/** @typedef {import("./Source").MapOptions} MapOptions */
|
|
18
|
+
/** @typedef {import("./Source").RawSourceMap} RawSourceMap */
|
|
19
|
+
/** @typedef {import("./Source").SourceAndMap} SourceAndMap */
|
|
20
|
+
/** @typedef {import("./Source").SourceValue} SourceValue */
|
|
21
|
+
/** @typedef {import("./helpers/getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */
|
|
22
|
+
/** @typedef {import("./helpers/streamChunks").OnChunk} OnChunk */
|
|
23
|
+
/** @typedef {import("./helpers/streamChunks").OnName} OnName */
|
|
24
|
+
/** @typedef {import("./helpers/streamChunks").OnSource} OnSource */
|
|
25
|
+
/** @typedef {import("./helpers/streamChunks").Options} Options */
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {object} BufferedMap
|
|
29
|
+
* @property {number} version version
|
|
30
|
+
* @property {string[]} sources sources
|
|
31
|
+
* @property {string[]} names name
|
|
32
|
+
* @property {string=} sourceRoot source root
|
|
33
|
+
* @property {(Buffer | "")[]=} sourcesContent sources content
|
|
34
|
+
* @property {Buffer=} mappings mappings
|
|
35
|
+
* @property {string} file file
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {null | RawSourceMap} map map
|
|
40
|
+
* @returns {null | BufferedMap} buffered map
|
|
41
|
+
*/
|
|
42
|
+
const mapToBufferedMap = (map) => {
|
|
43
|
+
if (typeof map !== "object" || !map) return map;
|
|
44
|
+
const bufferedMap =
|
|
45
|
+
/** @type {BufferedMap} */
|
|
46
|
+
(/** @type {unknown} */ ({ ...map }));
|
|
47
|
+
if (map.mappings) {
|
|
48
|
+
bufferedMap.mappings = Buffer.from(map.mappings, "utf8");
|
|
49
|
+
}
|
|
50
|
+
if (map.sourcesContent) {
|
|
51
|
+
bufferedMap.sourcesContent = map.sourcesContent.map(
|
|
52
|
+
(str) => str && Buffer.from(str, "utf8"),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return bufferedMap;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {null | BufferedMap} bufferedMap buffered map
|
|
60
|
+
* @returns {null | RawSourceMap} map
|
|
61
|
+
*/
|
|
62
|
+
const bufferedMapToMap = (bufferedMap) => {
|
|
63
|
+
if (typeof bufferedMap !== "object" || !bufferedMap) return bufferedMap;
|
|
64
|
+
const map =
|
|
65
|
+
/** @type {RawSourceMap} */
|
|
66
|
+
(/** @type {unknown} */ ({ ...bufferedMap }));
|
|
67
|
+
if (bufferedMap.mappings) {
|
|
68
|
+
map.mappings = bufferedMap.mappings.toString("utf8");
|
|
69
|
+
}
|
|
70
|
+
if (bufferedMap.sourcesContent) {
|
|
71
|
+
map.sourcesContent = bufferedMap.sourcesContent.map(
|
|
72
|
+
(buffer) => buffer && buffer.toString("utf8"),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return map;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** @typedef {{ map?: null | RawSourceMap, bufferedMap?: null | BufferedMap }} BufferEntry */
|
|
79
|
+
/** @typedef {Map<string, BufferEntry>} BufferedMaps */
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @typedef {object} CachedData
|
|
83
|
+
* @property {boolean=} source source
|
|
84
|
+
* @property {Buffer} buffer buffer
|
|
85
|
+
* @property {number=} size size
|
|
86
|
+
* @property {BufferedMaps} maps maps
|
|
87
|
+
* @property {(string | Buffer)[]=} hash hash
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
class CachedSource extends Source {
|
|
91
|
+
/**
|
|
92
|
+
* @param {Source | (() => Source)} source source
|
|
93
|
+
* @param {CachedData=} cachedData cached data
|
|
94
|
+
*/
|
|
95
|
+
constructor(source, cachedData) {
|
|
96
|
+
super();
|
|
97
|
+
/**
|
|
98
|
+
* @private
|
|
99
|
+
* @type {Source | (() => Source)}
|
|
100
|
+
*/
|
|
101
|
+
this._source = source;
|
|
102
|
+
/**
|
|
103
|
+
* @private
|
|
104
|
+
* @type {boolean | undefined}
|
|
105
|
+
*/
|
|
106
|
+
this._cachedSourceType = cachedData ? cachedData.source : undefined;
|
|
107
|
+
/**
|
|
108
|
+
* @private
|
|
109
|
+
* @type {undefined | string}
|
|
110
|
+
*/
|
|
111
|
+
this._cachedSource = undefined;
|
|
112
|
+
/**
|
|
113
|
+
* @private
|
|
114
|
+
* @type {Buffer | undefined}
|
|
115
|
+
*/
|
|
116
|
+
this._cachedBuffer = cachedData ? cachedData.buffer : undefined;
|
|
117
|
+
/**
|
|
118
|
+
* @private
|
|
119
|
+
* @type {number | undefined}
|
|
120
|
+
*/
|
|
121
|
+
this._cachedSize = cachedData ? cachedData.size : undefined;
|
|
122
|
+
/**
|
|
123
|
+
* @private
|
|
124
|
+
* @type {BufferedMaps}
|
|
125
|
+
*/
|
|
126
|
+
this._cachedMaps = cachedData ? cachedData.maps : new Map();
|
|
127
|
+
/**
|
|
128
|
+
* @private
|
|
129
|
+
* @type {(string | Buffer)[] | undefined}
|
|
130
|
+
*/
|
|
131
|
+
this._cachedHashUpdate = cachedData ? cachedData.hash : undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @returns {CachedData} cached data
|
|
136
|
+
*/
|
|
137
|
+
getCachedData() {
|
|
138
|
+
/** @type {BufferedMaps} */
|
|
139
|
+
const bufferedMaps = new Map();
|
|
140
|
+
for (const pair of this._cachedMaps) {
|
|
141
|
+
const [, cacheEntry] = pair;
|
|
142
|
+
if (cacheEntry.bufferedMap === undefined) {
|
|
143
|
+
cacheEntry.bufferedMap = mapToBufferedMap(
|
|
144
|
+
this._getMapFromCacheEntry(cacheEntry),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
bufferedMaps.set(pair[0], {
|
|
148
|
+
map: undefined,
|
|
149
|
+
bufferedMap: cacheEntry.bufferedMap,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
// We don't want to cache strings
|
|
154
|
+
// So if we have a caches sources
|
|
155
|
+
// create a buffer from it and only store
|
|
156
|
+
// if it was a Buffer or string
|
|
157
|
+
buffer: this._cachedSource
|
|
158
|
+
? this.buffer()
|
|
159
|
+
: /** @type {Buffer} */ (this._cachedBuffer),
|
|
160
|
+
source:
|
|
161
|
+
this._cachedSourceType !== undefined
|
|
162
|
+
? this._cachedSourceType
|
|
163
|
+
: typeof this._cachedSource === "string"
|
|
164
|
+
? true
|
|
165
|
+
: Buffer.isBuffer(this._cachedSource)
|
|
166
|
+
? false
|
|
167
|
+
: undefined,
|
|
168
|
+
size: this._cachedSize,
|
|
169
|
+
maps: bufferedMaps,
|
|
170
|
+
hash: this._cachedHashUpdate,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
originalLazy() {
|
|
175
|
+
return this._source;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
original() {
|
|
179
|
+
if (typeof this._source === "function") this._source = this._source();
|
|
180
|
+
return this._source;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @returns {SourceValue} source
|
|
185
|
+
*/
|
|
186
|
+
source() {
|
|
187
|
+
const source = this._getCachedSource();
|
|
188
|
+
if (source !== undefined) return source;
|
|
189
|
+
return (this._cachedSource =
|
|
190
|
+
/** @type {string} */
|
|
191
|
+
(this.original().source()));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @private
|
|
196
|
+
* @param {BufferEntry} cacheEntry cache entry
|
|
197
|
+
* @returns {null | RawSourceMap} raw source map
|
|
198
|
+
*/
|
|
199
|
+
_getMapFromCacheEntry(cacheEntry) {
|
|
200
|
+
if (cacheEntry.map !== undefined) {
|
|
201
|
+
return cacheEntry.map;
|
|
202
|
+
} else if (cacheEntry.bufferedMap !== undefined) {
|
|
203
|
+
return (cacheEntry.map = bufferedMapToMap(cacheEntry.bufferedMap));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @private
|
|
211
|
+
* @returns {undefined | string} cached source
|
|
212
|
+
*/
|
|
213
|
+
_getCachedSource() {
|
|
214
|
+
if (this._cachedSource !== undefined) return this._cachedSource;
|
|
215
|
+
if (this._cachedBuffer && this._cachedSourceType !== undefined) {
|
|
216
|
+
const value = this._cachedSourceType
|
|
217
|
+
? this._cachedBuffer.toString("utf8")
|
|
218
|
+
: this._cachedBuffer;
|
|
219
|
+
if (isDualStringBufferCachingEnabled()) {
|
|
220
|
+
this._cachedSource = /** @type {string} */ (value);
|
|
221
|
+
}
|
|
222
|
+
return /** @type {string} */ (value);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @returns {Buffer} buffer
|
|
228
|
+
*/
|
|
229
|
+
buffer() {
|
|
230
|
+
if (this._cachedBuffer !== undefined) return this._cachedBuffer;
|
|
231
|
+
if (this._cachedSource !== undefined) {
|
|
232
|
+
const value = Buffer.isBuffer(this._cachedSource)
|
|
233
|
+
? this._cachedSource
|
|
234
|
+
: Buffer.from(this._cachedSource, "utf8");
|
|
235
|
+
if (isDualStringBufferCachingEnabled()) {
|
|
236
|
+
this._cachedBuffer = value;
|
|
237
|
+
}
|
|
238
|
+
return value;
|
|
239
|
+
}
|
|
240
|
+
if (typeof this.original().buffer === "function") {
|
|
241
|
+
return (this._cachedBuffer = this.original().buffer());
|
|
242
|
+
}
|
|
243
|
+
const bufferOrString = this.source();
|
|
244
|
+
if (Buffer.isBuffer(bufferOrString)) {
|
|
245
|
+
return (this._cachedBuffer = bufferOrString);
|
|
246
|
+
}
|
|
247
|
+
const value = Buffer.from(bufferOrString, "utf8");
|
|
248
|
+
if (isDualStringBufferCachingEnabled()) {
|
|
249
|
+
this._cachedBuffer = value;
|
|
250
|
+
}
|
|
251
|
+
return value;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @returns {number} size
|
|
256
|
+
*/
|
|
257
|
+
size() {
|
|
258
|
+
if (this._cachedSize !== undefined) return this._cachedSize;
|
|
259
|
+
if (this._cachedBuffer !== undefined) {
|
|
260
|
+
return (this._cachedSize = this._cachedBuffer.length);
|
|
261
|
+
}
|
|
262
|
+
const source = this._getCachedSource();
|
|
263
|
+
if (source !== undefined) {
|
|
264
|
+
return (this._cachedSize = Buffer.byteLength(source));
|
|
265
|
+
}
|
|
266
|
+
return (this._cachedSize = this.original().size());
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @param {MapOptions=} options map options
|
|
271
|
+
* @returns {SourceAndMap} source and map
|
|
272
|
+
*/
|
|
273
|
+
sourceAndMap(options) {
|
|
274
|
+
const key = options ? JSON.stringify(options) : "{}";
|
|
275
|
+
const cacheEntry = this._cachedMaps.get(key);
|
|
276
|
+
// Look for a cached map
|
|
277
|
+
if (cacheEntry !== undefined) {
|
|
278
|
+
// We have a cached map in some representation
|
|
279
|
+
const map = this._getMapFromCacheEntry(cacheEntry);
|
|
280
|
+
|
|
281
|
+
// Either get the cached source or compute it
|
|
282
|
+
return { source: this.source(), map };
|
|
283
|
+
}
|
|
284
|
+
// Look for a cached source
|
|
285
|
+
let source = this._getCachedSource();
|
|
286
|
+
// Compute the map
|
|
287
|
+
let map;
|
|
288
|
+
if (source !== undefined) {
|
|
289
|
+
map = this.original().map(options);
|
|
290
|
+
} else {
|
|
291
|
+
// Compute the source and map together.
|
|
292
|
+
const sourceAndMap = this.original().sourceAndMap(options);
|
|
293
|
+
source = /** @type {string} */ (sourceAndMap.source);
|
|
294
|
+
map = sourceAndMap.map;
|
|
295
|
+
this._cachedSource = source;
|
|
296
|
+
}
|
|
297
|
+
this._cachedMaps.set(key, {
|
|
298
|
+
map,
|
|
299
|
+
bufferedMap: undefined,
|
|
300
|
+
});
|
|
301
|
+
return { source, map };
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* @param {Options} options options
|
|
306
|
+
* @param {OnChunk} onChunk called for each chunk of code
|
|
307
|
+
* @param {OnSource} onSource called for each source
|
|
308
|
+
* @param {OnName} onName called for each name
|
|
309
|
+
* @returns {GeneratedSourceInfo} generated source info
|
|
310
|
+
*/
|
|
311
|
+
streamChunks(options, onChunk, onSource, onName) {
|
|
312
|
+
const key = options ? JSON.stringify(options) : "{}";
|
|
313
|
+
if (
|
|
314
|
+
this._cachedMaps.has(key) &&
|
|
315
|
+
(this._cachedBuffer !== undefined || this._cachedSource !== undefined)
|
|
316
|
+
) {
|
|
317
|
+
const { source, map } = this.sourceAndMap(options);
|
|
318
|
+
if (map) {
|
|
319
|
+
return streamChunksOfSourceMap(
|
|
320
|
+
/** @type {string} */
|
|
321
|
+
(source),
|
|
322
|
+
map,
|
|
323
|
+
onChunk,
|
|
324
|
+
onSource,
|
|
325
|
+
onName,
|
|
326
|
+
Boolean(options && options.finalSource),
|
|
327
|
+
true,
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
return streamChunksOfRawSource(
|
|
331
|
+
/** @type {string} */
|
|
332
|
+
(source),
|
|
333
|
+
onChunk,
|
|
334
|
+
onSource,
|
|
335
|
+
onName,
|
|
336
|
+
Boolean(options && options.finalSource),
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
const sourceAndMap = streamAndGetSourceAndMap(
|
|
340
|
+
this.original(),
|
|
341
|
+
options,
|
|
342
|
+
onChunk,
|
|
343
|
+
onSource,
|
|
344
|
+
onName,
|
|
345
|
+
);
|
|
346
|
+
this._cachedSource = sourceAndMap.source;
|
|
347
|
+
this._cachedMaps.set(key, {
|
|
348
|
+
map: /** @type {RawSourceMap} */ (sourceAndMap.map),
|
|
349
|
+
bufferedMap: undefined,
|
|
350
|
+
});
|
|
351
|
+
return sourceAndMap.result;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* @param {MapOptions=} options map options
|
|
356
|
+
* @returns {RawSourceMap | null} map
|
|
357
|
+
*/
|
|
358
|
+
map(options) {
|
|
359
|
+
const key = options ? JSON.stringify(options) : "{}";
|
|
360
|
+
const cacheEntry = this._cachedMaps.get(key);
|
|
361
|
+
if (cacheEntry !== undefined) {
|
|
362
|
+
return this._getMapFromCacheEntry(cacheEntry);
|
|
363
|
+
}
|
|
364
|
+
const map = this.original().map(options);
|
|
365
|
+
this._cachedMaps.set(key, {
|
|
366
|
+
map,
|
|
367
|
+
bufferedMap: undefined,
|
|
368
|
+
});
|
|
369
|
+
return map;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* @param {HashLike} hash hash
|
|
374
|
+
* @returns {void}
|
|
375
|
+
*/
|
|
376
|
+
updateHash(hash) {
|
|
377
|
+
if (this._cachedHashUpdate !== undefined) {
|
|
378
|
+
for (const item of this._cachedHashUpdate) hash.update(item);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
/** @type {(string | Buffer)[]} */
|
|
382
|
+
const update = [];
|
|
383
|
+
/** @type {string | undefined} */
|
|
384
|
+
let currentString;
|
|
385
|
+
const tracker = {
|
|
386
|
+
/**
|
|
387
|
+
* @param {string | Buffer} item item
|
|
388
|
+
* @returns {void}
|
|
389
|
+
*/
|
|
390
|
+
update: (item) => {
|
|
391
|
+
if (typeof item === "string" && item.length < 10240) {
|
|
392
|
+
if (currentString === undefined) {
|
|
393
|
+
currentString = item;
|
|
394
|
+
} else {
|
|
395
|
+
currentString += item;
|
|
396
|
+
if (currentString.length > 102400) {
|
|
397
|
+
update.push(Buffer.from(currentString));
|
|
398
|
+
currentString = undefined;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
if (currentString !== undefined) {
|
|
403
|
+
update.push(Buffer.from(currentString));
|
|
404
|
+
currentString = undefined;
|
|
405
|
+
}
|
|
406
|
+
update.push(item);
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
this.original().updateHash(/** @type {HashLike} */ (tracker));
|
|
411
|
+
if (currentString !== undefined) {
|
|
412
|
+
update.push(Buffer.from(currentString));
|
|
413
|
+
}
|
|
414
|
+
for (const item of update) hash.update(item);
|
|
415
|
+
this._cachedHashUpdate = update;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
module.exports = CachedSource;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const Source = require("./Source");
|
|
9
|
+
|
|
10
|
+
/** @typedef {import("./Source").HashLike} HashLike */
|
|
11
|
+
/** @typedef {import("./Source").MapOptions} MapOptions */
|
|
12
|
+
/** @typedef {import("./Source").RawSourceMap} RawSourceMap */
|
|
13
|
+
/** @typedef {import("./Source").SourceAndMap} SourceAndMap */
|
|
14
|
+
/** @typedef {import("./Source").SourceValue} SourceValue */
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {object} SourceLike
|
|
18
|
+
* @property {() => SourceValue} source source
|
|
19
|
+
* @property {(() => Buffer)=} buffer buffer
|
|
20
|
+
* @property {(() => number)=} size size
|
|
21
|
+
* @property {((options?: MapOptions) => RawSourceMap | null)=} map map
|
|
22
|
+
* @property {((options?: MapOptions) => SourceAndMap)=} sourceAndMap source and map
|
|
23
|
+
* @property {((hash: HashLike) => void)=} updateHash hash updater
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
class CompatSource extends Source {
|
|
27
|
+
/**
|
|
28
|
+
* @param {SourceLike} sourceLike source like
|
|
29
|
+
* @returns {Source} source
|
|
30
|
+
*/
|
|
31
|
+
static from(sourceLike) {
|
|
32
|
+
return sourceLike instanceof Source
|
|
33
|
+
? sourceLike
|
|
34
|
+
: new CompatSource(sourceLike);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {SourceLike} sourceLike source like
|
|
39
|
+
*/
|
|
40
|
+
constructor(sourceLike) {
|
|
41
|
+
super();
|
|
42
|
+
/**
|
|
43
|
+
* @private
|
|
44
|
+
* @type {SourceLike}
|
|
45
|
+
*/
|
|
46
|
+
this._sourceLike = sourceLike;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @returns {SourceValue} source
|
|
51
|
+
*/
|
|
52
|
+
source() {
|
|
53
|
+
return this._sourceLike.source();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
buffer() {
|
|
57
|
+
if (typeof this._sourceLike.buffer === "function") {
|
|
58
|
+
return this._sourceLike.buffer();
|
|
59
|
+
}
|
|
60
|
+
return super.buffer();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
size() {
|
|
64
|
+
if (typeof this._sourceLike.size === "function") {
|
|
65
|
+
return this._sourceLike.size();
|
|
66
|
+
}
|
|
67
|
+
return super.size();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {MapOptions=} options map options
|
|
72
|
+
* @returns {RawSourceMap | null} map
|
|
73
|
+
*/
|
|
74
|
+
map(options) {
|
|
75
|
+
if (typeof this._sourceLike.map === "function") {
|
|
76
|
+
return this._sourceLike.map(options);
|
|
77
|
+
}
|
|
78
|
+
return super.map(options);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {MapOptions=} options map options
|
|
83
|
+
* @returns {SourceAndMap} source and map
|
|
84
|
+
*/
|
|
85
|
+
sourceAndMap(options) {
|
|
86
|
+
if (typeof this._sourceLike.sourceAndMap === "function") {
|
|
87
|
+
return this._sourceLike.sourceAndMap(options);
|
|
88
|
+
}
|
|
89
|
+
return super.sourceAndMap(options);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @param {HashLike} hash hash
|
|
94
|
+
* @returns {void}
|
|
95
|
+
*/
|
|
96
|
+
updateHash(hash) {
|
|
97
|
+
if (typeof this._sourceLike.updateHash === "function") {
|
|
98
|
+
return this._sourceLike.updateHash(hash);
|
|
99
|
+
}
|
|
100
|
+
if (typeof this._sourceLike.map === "function") {
|
|
101
|
+
throw new Error(
|
|
102
|
+
"A Source-like object with a 'map' method must also provide an 'updateHash' method",
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
hash.update(this.buffer());
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
module.exports = CompatSource;
|