Skip to content

chore: use eslint-config-webpack #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 0 additions & 70 deletions .eslintrc.js

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/cache@v4
with:
path: .eslintcache
key: lint-eslint-${{ runner.os }}-node-${{ hashFiles('**/yarn.lock', '**/.eslintrc.js') }}
key: lint-eslint-${{ runner.os }}-node-${{ hashFiles('**/yarn.lock', '**/eslint.config.mjs') }}
restore-keys: lint-eslint-
- run: yarn lint
test:
Expand Down Expand Up @@ -52,9 +52,9 @@ jobs:
architecture: ${{ steps.calculate_architecture.outputs.result }}
cache: "yarn"
- run: yarn --frozen-lockfile --ignore-engines
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x'
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'
- run: yarn --frozen-lockfile
if: matrix.node-version != '10.x' && matrix.node-version != '12.x' && matrix.node-version != '14.x'
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'
- run: yarn cover
- uses: codecov/codecov-action@v5
with:
Expand Down
16 changes: 9 additions & 7 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
"use strict";

module.exports = {
printWidth: 80,
useTabs: true,
tabWidth: 2,
trailingComma: "none",
trailingComma: "all",
arrowParens: "always",
overrides: [
{
files: "*.json",
options: {
parser: "json",
useTabs: false
}
useTabs: false,
},
},
{
files: "*.{cts,mts,ts}",
options: {
parser: "typescript"
}
}
]
parser: "typescript",
},
},
],
};
11 changes: 11 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from "eslint/config";
import config from "eslint-config-webpack";

export default defineConfig([
{
extends: [config],
rules: {
"n/prefer-node-protocol": "off",
},
},
]);
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

/** @type {import('jest').Config} */
const config = {
prettierPath: require.resolve("prettier-2"),
forceExit: true,
testMatch: ["<rootDir>/test/*.js"],
testPathIgnorePatterns: ["<rootDir>/test/helpers.js"],
transformIgnorePatterns: ["<rootDir>"],
testEnvironment: "node",
};

module.exports = config;
108 changes: 54 additions & 54 deletions lib/CachedSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const streamChunksOfRawSource = require("./helpers/streamChunksOfRawSource");
const streamChunksOfSourceMap = require("./helpers/streamChunksOfSourceMap");
const {
isDualStringBufferCachingEnabled
isDualStringBufferCachingEnabled,
} = require("./helpers/stringBufferUtils");

/** @typedef {import("./Source").HashLike} HashLike */
Expand All @@ -26,13 +26,13 @@

/**
* @typedef {object} BufferedMap
* @property {number} version
* @property {string[]} sources
* @property {string[]} names
* @property {string=} sourceRoot
* @property {(Buffer | "")[]=} sourcesContent
* @property {Buffer=} mappings
* @property {string} file
* @property {number} version version
* @property {string[]} sources sources
* @property {string[]} names name
* @property {string=} sourceRoot source root
* @property {(Buffer | "")[]=} sourcesContent sources content
* @property {Buffer=} mappings mappings
* @property {string} file file
*/

/**
Expand All @@ -41,14 +41,15 @@
*/
const mapToBufferedMap = (map) => {
if (typeof map !== "object" || !map) return map;
/** @type {BufferedMap} */
const bufferedMap = Object.assign(/** @type {BufferedMap} */ ({}), map);
const bufferedMap =
/** @type {BufferedMap} */
(/** @type {unknown} */ ({ ...map }));
if (map.mappings) {
bufferedMap.mappings = Buffer.from(map.mappings, "utf-8");
bufferedMap.mappings = Buffer.from(map.mappings, "utf8");
}
if (map.sourcesContent) {
bufferedMap.sourcesContent = map.sourcesContent.map(
(str) => str && Buffer.from(str, "utf-8")
(str) => str && Buffer.from(str, "utf8"),
);
}
return bufferedMap;
Expand All @@ -60,14 +61,15 @@
*/
const bufferedMapToMap = (bufferedMap) => {
if (typeof bufferedMap !== "object" || !bufferedMap) return bufferedMap;
/** @type {RawSourceMap} */
const map = Object.assign(/** @type {RawSourceMap} */ ({}), bufferedMap);
const map =
/** @type {RawSourceMap} */
(/** @type {unknown} */ ({ ...bufferedMap }));
if (bufferedMap.mappings) {
map.mappings = bufferedMap.mappings.toString("utf-8");
map.mappings = bufferedMap.mappings.toString("utf8");
}
if (bufferedMap.sourcesContent) {
map.sourcesContent = bufferedMap.sourcesContent.map(
(buffer) => buffer && buffer.toString("utf-8")
(buffer) => buffer && buffer.toString("utf8"),
);
}
return map;
Expand All @@ -78,15 +80,14 @@

/**
* @typedef {object} CachedData
* @property {boolean=} source
* @property {Buffer} buffer
* @property {number=} size
* @property {BufferedMaps} maps
* @property {(string | Buffer)[]=} hash
* @property {boolean=} source source
* @property {Buffer} buffer buffer
* @property {number=} size size
* @property {BufferedMaps} maps maps
* @property {(string | Buffer)[]=} hash hash
*/

class CachedSource extends Source {
// eslint-disable-next-line valid-jsdoc
/**
* @param {Source | (() => Source)} source source
* @param {CachedData=} cachedData cached data
Expand Down Expand Up @@ -117,15 +118,15 @@
/** @type {BufferedMaps} */
const bufferedMaps = new Map();
for (const pair of this._cachedMaps) {
let cacheEntry = pair[1];
const [, cacheEntry] = pair;
if (cacheEntry.bufferedMap === undefined) {
cacheEntry.bufferedMap = mapToBufferedMap(
this._getMapFromCacheEntry(cacheEntry)
this._getMapFromCacheEntry(cacheEntry),
);
}
bufferedMaps.set(pair[0], {
map: undefined,
bufferedMap: cacheEntry.bufferedMap
bufferedMap: cacheEntry.bufferedMap,
});
}
return {
Expand All @@ -140,13 +141,13 @@
this._cachedSourceType !== undefined
? this._cachedSourceType
: typeof this._cachedSource === "string"
? true
: Buffer.isBuffer(this._cachedSource)
? false
: undefined,
? true
: Buffer.isBuffer(this._cachedSource)
? false
: undefined,

Check warning on line 147 in lib/CachedSource.js

View check run for this annotation

Codecov / codecov/patch

lib/CachedSource.js#L145-L147

Added lines #L145 - L147 were not covered by tests
size: this._cachedSize,
maps: bufferedMaps,
hash: this._cachedHashUpdate
hash: this._cachedHashUpdate,
};
}

Expand Down Expand Up @@ -193,7 +194,7 @@
if (this._cachedSource !== undefined) return this._cachedSource;
if (this._cachedBuffer && this._cachedSourceType !== undefined) {
const value = this._cachedSourceType
? this._cachedBuffer.toString("utf-8")
? this._cachedBuffer.toString("utf8")
: this._cachedBuffer;
if (isDualStringBufferCachingEnabled()) {
this._cachedSource = /** @type {string} */ (value);
Expand All @@ -210,7 +211,7 @@
if (this._cachedSource !== undefined) {
const value = Buffer.isBuffer(this._cachedSource)
? this._cachedSource
: Buffer.from(this._cachedSource, "utf-8");
: Buffer.from(this._cachedSource, "utf8");
if (isDualStringBufferCachingEnabled()) {
this._cachedBuffer = value;
}
Expand All @@ -223,7 +224,7 @@
if (Buffer.isBuffer(bufferOrString)) {
return (this._cachedBuffer = bufferOrString);
}
const value = Buffer.from(bufferOrString, "utf-8");
const value = Buffer.from(bufferOrString, "utf8");
if (isDualStringBufferCachingEnabled()) {
this._cachedBuffer = value;
}
Expand Down Expand Up @@ -275,7 +276,7 @@
}
this._cachedMaps.set(key, {
map,
bufferedMap: undefined
bufferedMap: undefined,
});
return { source, map };
}
Expand All @@ -302,33 +303,32 @@
onChunk,
onSource,
onName,
!!(options && options.finalSource),
true
);
} else {
return streamChunksOfRawSource(
/** @type {string} */
(source),
onChunk,
onSource,
onName,
!!(options && options.finalSource)
Boolean(options && options.finalSource),
true,
);
}
return streamChunksOfRawSource(
/** @type {string} */
(source),
onChunk,
onSource,
onName,
Boolean(options && options.finalSource),
);
}
const { result, source, map } = streamAndGetSourceAndMap(
const sourceAndMap = streamAndGetSourceAndMap(
this.original(),
options,
onChunk,
onSource,
onName
onName,
);
this._cachedSource = source;
this._cachedSource = sourceAndMap.source;
this._cachedMaps.set(key, {
map: /** @type {RawSourceMap} */ (map),
bufferedMap: undefined
map: /** @type {RawSourceMap} */ (sourceAndMap.map),
bufferedMap: undefined,
});
return result;
return sourceAndMap.result;
}

/**
Expand All @@ -344,7 +344,7 @@
const map = this.original().map(options);
this._cachedMaps.set(key, {
map,
bufferedMap: undefined
bufferedMap: undefined,
});
return map;
}
Expand All @@ -361,7 +361,7 @@
/** @type {(string | Buffer)[]} */
const update = [];
/** @type {string | undefined} */
let currentString = undefined;
let currentString;
const tracker = {
/**
* @param {string | Buffer} item item
Expand All @@ -385,7 +385,7 @@
}
update.push(item);
}
}
},
};
this.original().updateHash(/** @type {HashLike} */ (tracker));
if (currentString !== undefined) {
Expand Down
Loading