Skip to content

Commit 6af577c

Browse files
chore: use eslint-config-webpack (#170)
1 parent 4588be9 commit 6af577c

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

+4649
-2800
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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1+
"use strict";
2+
13
module.exports = {
24
printWidth: 80,
35
useTabs: true,
46
tabWidth: 2,
5-
trailingComma: "none",
7+
trailingComma: "all",
68
arrowParens: "always",
79
overrides: [
810
{
911
files: "*.json",
1012
options: {
1113
parser: "json",
12-
useTabs: false
13-
}
14+
useTabs: false,
15+
},
1416
},
1517
{
1618
files: "*.{cts,mts,ts}",
1719
options: {
18-
parser: "typescript"
19-
}
20-
}
21-
]
20+
parser: "typescript",
21+
},
22+
},
23+
],
2224
};

eslint.config.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from "eslint/config";
2+
import config from "eslint-config-webpack";
3+
4+
export default defineConfig([
5+
{
6+
extends: [config],
7+
rules: {
8+
"n/prefer-node-protocol": "off",
9+
},
10+
},
11+
]);

jest.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
/** @type {import('jest').Config} */
4+
const config = {
5+
prettierPath: require.resolve("prettier-2"),
6+
forceExit: true,
7+
testMatch: ["<rootDir>/test/*.js"],
8+
testPathIgnorePatterns: ["<rootDir>/test/helpers.js"],
9+
transformIgnorePatterns: ["<rootDir>"],
10+
testEnvironment: "node",
11+
};
12+
13+
module.exports = config;

lib/CachedSource.js

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const streamAndGetSourceAndMap = require("./helpers/streamAndGetSourceAndMap");
1010
const streamChunksOfRawSource = require("./helpers/streamChunksOfRawSource");
1111
const streamChunksOfSourceMap = require("./helpers/streamChunksOfSourceMap");
1212
const {
13-
isDualStringBufferCachingEnabled
13+
isDualStringBufferCachingEnabled,
1414
} = require("./helpers/stringBufferUtils");
1515

1616
/** @typedef {import("./Source").HashLike} HashLike */
@@ -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,15 +118,15 @@ 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(
123-
this._getMapFromCacheEntry(cacheEntry)
124+
this._getMapFromCacheEntry(cacheEntry),
124125
);
125126
}
126127
bufferedMaps.set(pair[0], {
127128
map: undefined,
128-
bufferedMap: cacheEntry.bufferedMap
129+
bufferedMap: cacheEntry.bufferedMap,
129130
});
130131
}
131132
return {
@@ -140,13 +141,13 @@ 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,
149-
hash: this._cachedHashUpdate
150+
hash: this._cachedHashUpdate,
150151
};
151152
}
152153

@@ -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
}
@@ -275,7 +276,7 @@ class CachedSource extends Source {
275276
}
276277
this._cachedMaps.set(key, {
277278
map,
278-
bufferedMap: undefined
279+
bufferedMap: undefined,
279280
});
280281
return { source, map };
281282
}
@@ -302,33 +303,32 @@ class CachedSource extends Source {
302303
onChunk,
303304
onSource,
304305
onName,
305-
!!(options && options.finalSource),
306-
true
307-
);
308-
} else {
309-
return streamChunksOfRawSource(
310-
/** @type {string} */
311-
(source),
312-
onChunk,
313-
onSource,
314-
onName,
315-
!!(options && options.finalSource)
306+
Boolean(options && options.finalSource),
307+
true,
316308
);
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,
324-
onName
324+
onName,
325325
);
326-
this._cachedSource = source;
326+
this._cachedSource = sourceAndMap.source;
327327
this._cachedMaps.set(key, {
328-
map: /** @type {RawSourceMap} */ (map),
329-
bufferedMap: undefined
328+
map: /** @type {RawSourceMap} */ (sourceAndMap.map),
329+
bufferedMap: undefined,
330330
});
331-
return result;
331+
return sourceAndMap.result;
332332
}
333333

334334
/**
@@ -344,7 +344,7 @@ class CachedSource extends Source {
344344
const map = this.original().map(options);
345345
this._cachedMaps.set(key, {
346346
map,
347-
bufferedMap: undefined
347+
bufferedMap: undefined,
348348
});
349349
return map;
350350
}
@@ -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
@@ -385,7 +385,7 @@ class CachedSource extends Source {
385385
}
386386
update.push(item);
387387
}
388-
}
388+
},
389389
};
390390
this.original().updateHash(/** @type {HashLike} */ (tracker));
391391
if (currentString !== undefined) {

0 commit comments

Comments
 (0)