Skip to content

Commit ea554a2

Browse files
chore: use eslint-config-webpack
1 parent 9d63cbc commit ea554a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4326
-2474
lines changed

.eslintrc.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/cache@v4
2424
with:
2525
path: .eslintcache
26-
key: lint-eslint-${{ runner.os }}-node-${{ hashFiles('**/yarn.lock', '**/.eslintrc.js') }}
26+
key: lint-eslint-${{ runner.os }}-node-${{ hashFiles('**/yarn.lock', '**/eslint.config.mjs') }}
2727
restore-keys: lint-eslint-
2828
- run: yarn lint
2929
test:
@@ -52,9 +52,9 @@ jobs:
5252
architecture: ${{ steps.calculate_architecture.outputs.result }}
5353
cache: "yarn"
5454
- run: yarn --frozen-lockfile --ignore-engines
55-
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x'
55+
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x' || matrix.node-version == '18.x'
5656
- run: yarn --frozen-lockfile
57-
if: matrix.node-version != '10.x' && matrix.node-version != '12.x' && matrix.node-version != '14.x'
57+
if: matrix.node-version != '10.x' && matrix.node-version != '12.x' && matrix.node-version != '14.x' && matrix.node-version != '16.x' && matrix.node-version != '18.x'
5858
- run: yarn cover
5959
- uses: codecov/codecov-action@v5
6060
with:

.prettierrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use strict";
2+
13
module.exports = {
24
printWidth: 80,
35
useTabs: true,

eslint.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// eslint-disable-next-line import/no-unresolved
2+
import { defineConfig } from "eslint/config";
3+
import config from "eslint-config-webpack";
4+
5+
export default defineConfig([
6+
{
7+
extends: [config]
8+
}
9+
]);

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
/** @type {import('jest').Config} */
4+
const config = {
5+
prettierPath: require.resolve("prettier-2")
6+
};
7+
8+
module.exports = config;

lib/CachedSource.js

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ const {
2626

2727
/**
2828
* @typedef {object} BufferedMap
29-
* @property {number} version
30-
* @property {string[]} sources
31-
* @property {string[]} names
32-
* @property {string=} sourceRoot
33-
* @property {(Buffer | "")[]=} sourcesContent
34-
* @property {Buffer=} mappings
35-
* @property {string} file
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
3636
*/
3737

3838
/**
@@ -41,14 +41,15 @@ const {
4141
*/
4242
const mapToBufferedMap = (map) => {
4343
if (typeof map !== "object" || !map) return map;
44-
/** @type {BufferedMap} */
45-
const bufferedMap = Object.assign(/** @type {BufferedMap} */ ({}), map);
44+
const bufferedMap =
45+
/** @type {BufferedMap} */
46+
(/** @type {unknown} */ ({ ...map }));
4647
if (map.mappings) {
47-
bufferedMap.mappings = Buffer.from(map.mappings, "utf-8");
48+
bufferedMap.mappings = Buffer.from(map.mappings, "utf8");
4849
}
4950
if (map.sourcesContent) {
5051
bufferedMap.sourcesContent = map.sourcesContent.map(
51-
(str) => str && Buffer.from(str, "utf-8")
52+
(str) => str && Buffer.from(str, "utf8")
5253
);
5354
}
5455
return bufferedMap;
@@ -60,14 +61,15 @@ const mapToBufferedMap = (map) => {
6061
*/
6162
const bufferedMapToMap = (bufferedMap) => {
6263
if (typeof bufferedMap !== "object" || !bufferedMap) return bufferedMap;
63-
/** @type {RawSourceMap} */
64-
const map = Object.assign(/** @type {RawSourceMap} */ ({}), bufferedMap);
64+
const map =
65+
/** @type {RawSourceMap} */
66+
(/** @type {unknown} */ ({ ...bufferedMap }));
6567
if (bufferedMap.mappings) {
66-
map.mappings = bufferedMap.mappings.toString("utf-8");
68+
map.mappings = bufferedMap.mappings.toString("utf8");
6769
}
6870
if (bufferedMap.sourcesContent) {
6971
map.sourcesContent = bufferedMap.sourcesContent.map(
70-
(buffer) => buffer && buffer.toString("utf-8")
72+
(buffer) => buffer && buffer.toString("utf8")
7173
);
7274
}
7375
return map;
@@ -78,15 +80,14 @@ const bufferedMapToMap = (bufferedMap) => {
7880

7981
/**
8082
* @typedef {object} CachedData
81-
* @property {boolean=} source
82-
* @property {Buffer} buffer
83-
* @property {number=} size
84-
* @property {BufferedMaps} maps
85-
* @property {(string | Buffer)[]=} hash
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
8688
*/
8789

8890
class CachedSource extends Source {
89-
// eslint-disable-next-line valid-jsdoc
9091
/**
9192
* @param {Source | (() => Source)} source source
9293
* @param {CachedData=} cachedData cached data
@@ -117,7 +118,7 @@ class CachedSource extends Source {
117118
/** @type {BufferedMaps} */
118119
const bufferedMaps = new Map();
119120
for (const pair of this._cachedMaps) {
120-
let cacheEntry = pair[1];
121+
const [, cacheEntry] = pair;
121122
if (cacheEntry.bufferedMap === undefined) {
122123
cacheEntry.bufferedMap = mapToBufferedMap(
123124
this._getMapFromCacheEntry(cacheEntry)
@@ -140,10 +141,10 @@ class CachedSource extends Source {
140141
this._cachedSourceType !== undefined
141142
? this._cachedSourceType
142143
: typeof this._cachedSource === "string"
143-
? true
144-
: Buffer.isBuffer(this._cachedSource)
145-
? false
146-
: undefined,
144+
? true
145+
: Buffer.isBuffer(this._cachedSource)
146+
? false
147+
: undefined,
147148
size: this._cachedSize,
148149
maps: bufferedMaps,
149150
hash: this._cachedHashUpdate
@@ -193,7 +194,7 @@ class CachedSource extends Source {
193194
if (this._cachedSource !== undefined) return this._cachedSource;
194195
if (this._cachedBuffer && this._cachedSourceType !== undefined) {
195196
const value = this._cachedSourceType
196-
? this._cachedBuffer.toString("utf-8")
197+
? this._cachedBuffer.toString("utf8")
197198
: this._cachedBuffer;
198199
if (isDualStringBufferCachingEnabled()) {
199200
this._cachedSource = /** @type {string} */ (value);
@@ -210,7 +211,7 @@ class CachedSource extends Source {
210211
if (this._cachedSource !== undefined) {
211212
const value = Buffer.isBuffer(this._cachedSource)
212213
? this._cachedSource
213-
: Buffer.from(this._cachedSource, "utf-8");
214+
: Buffer.from(this._cachedSource, "utf8");
214215
if (isDualStringBufferCachingEnabled()) {
215216
this._cachedBuffer = value;
216217
}
@@ -223,7 +224,7 @@ class CachedSource extends Source {
223224
if (Buffer.isBuffer(bufferOrString)) {
224225
return (this._cachedBuffer = bufferOrString);
225226
}
226-
const value = Buffer.from(bufferOrString, "utf-8");
227+
const value = Buffer.from(bufferOrString, "utf8");
227228
if (isDualStringBufferCachingEnabled()) {
228229
this._cachedBuffer = value;
229230
}
@@ -302,33 +303,32 @@ class CachedSource extends Source {
302303
onChunk,
303304
onSource,
304305
onName,
305-
!!(options && options.finalSource),
306+
Boolean(options && options.finalSource),
306307
true
307308
);
308-
} else {
309-
return streamChunksOfRawSource(
310-
/** @type {string} */
311-
(source),
312-
onChunk,
313-
onSource,
314-
onName,
315-
!!(options && options.finalSource)
316-
);
317309
}
310+
return streamChunksOfRawSource(
311+
/** @type {string} */
312+
(source),
313+
onChunk,
314+
onSource,
315+
onName,
316+
Boolean(options && options.finalSource)
317+
);
318318
}
319-
const { result, source, map } = streamAndGetSourceAndMap(
319+
const sourceAndMap = streamAndGetSourceAndMap(
320320
this.original(),
321321
options,
322322
onChunk,
323323
onSource,
324324
onName
325325
);
326-
this._cachedSource = source;
326+
this._cachedSource = sourceAndMap.source;
327327
this._cachedMaps.set(key, {
328-
map: /** @type {RawSourceMap} */ (map),
328+
map: /** @type {RawSourceMap} */ (sourceAndMap.map),
329329
bufferedMap: undefined
330330
});
331-
return result;
331+
return sourceAndMap.result;
332332
}
333333

334334
/**
@@ -361,7 +361,7 @@ class CachedSource extends Source {
361361
/** @type {(string | Buffer)[]} */
362362
const update = [];
363363
/** @type {string | undefined} */
364-
let currentString = undefined;
364+
let currentString;
365365
const tracker = {
366366
/**
367367
* @param {string | Buffer} item item

lib/CompatSource.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ const Source = require("./Source");
1515

1616
/**
1717
* @typedef {object} SourceLike
18-
* @property {() => SourceValue} source
19-
* @property {(() => Buffer)=} buffer
20-
* @property {(() => number)=} size
21-
* @property {((options?: MapOptions) => RawSourceMap | null)=} map
22-
* @property {((options?: MapOptions) => SourceAndMap)=} sourceAndMap
23-
* @property {((hash: HashLike) => void)=} updateHash
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
2424
*/
2525

2626
class CompatSource extends Source {

0 commit comments

Comments
 (0)