Skip to content

Commit

Permalink
chore: fix lint and types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jun 11, 2024
1 parent 7acd348 commit 1954237
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 68 deletions.
7 changes: 6 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ module.exports = [
"no-inner-declarations": "error",
"no-loop-func": "off",
"n/no-missing-require": ["error", { allowModules: ["webpack"] }],
"n/no-unsupported-features/node-builtins": [
"error",
{
ignores: ["zlib.createBrotliCompress", "zlib.createBrotliDecompress"]
}
],
"jsdoc/check-alignment": "off",
"jsdoc/tag-lines": "off",
// TODO enable me
Expand Down Expand Up @@ -182,7 +188,6 @@ module.exports = [
"n/no-unsupported-features/node-builtins": [
"error",
{
version: ">=10.13.0",
allowExperimental: true
}
]
Expand Down
4 changes: 2 additions & 2 deletions lib/ConcatenationScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ class ConcatenationScope {
const asiSafeFlag = asiSafe
? "_asiSafe1"
: asiSafe === false
? "_asiSafe0"
: "";
? "_asiSafe0"
: "";
const exportData = ids
? Buffer.from(JSON.stringify(ids), "utf-8").toString("hex")
: "ns";
Expand Down
8 changes: 4 additions & 4 deletions lib/ContextModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ class ContextModule extends Module {
this.context
? [this.context]
: typeof this.options.resource === "string"
? [this.options.resource]
: /** @type {string[]} */ (this.options.resource),
? [this.options.resource]
: /** @type {string[]} */ (this.options.resource),
null,
SNAPSHOT_OPTIONS,
(err, snapshot) => {
Expand Down Expand Up @@ -992,8 +992,8 @@ module.exports = webpackAsyncContext;`;
const requestPrefix = hasNoChunk
? "Promise.resolve()"
: hasMultipleOrNoChunks
? `Promise.all(ids.slice(${chunksStartPosition}).map(${RuntimeGlobals.ensureChunk}))`
: `${RuntimeGlobals.ensureChunk}(ids[${chunksStartPosition}])`;
? `Promise.all(ids.slice(${chunksStartPosition}).map(${RuntimeGlobals.ensureChunk}))`
: `${RuntimeGlobals.ensureChunk}(ids[${chunksStartPosition}])`;
const returnModuleObject = this.getReturnModuleObjectSource(
fakeMap,
true,
Expand Down
2 changes: 1 addition & 1 deletion lib/EvalDevToolModulePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class EvalDevToolModulePlugin {
compilation.outputOptions.trustedTypes
? `${RuntimeGlobals.createScript}(${JSON.stringify(
content + footer
)})`
)})`
: JSON.stringify(content + footer)
});`
);
Expand Down
12 changes: 6 additions & 6 deletions lib/ExternalModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const getSourceForImportExternal = (
? `, { assert: ${JSON.stringify(
dependencyMeta.attributes,
importAssertionReplacer
)} }`
)} }`
: `, { with: ${JSON.stringify(dependencyMeta.attributes)} }`
: "";
if (!Array.isArray(moduleAndSpecifiers)) {
Expand Down Expand Up @@ -244,7 +244,7 @@ class ModuleExternalInitFragment extends InitFragment {
? ` assert ${JSON.stringify(
dependencyMeta.attributes,
importAssertionReplacer
)}`
)}`
: ` with ${JSON.stringify(dependencyMeta.attributes)}`
: ""
};\n`,
Expand Down Expand Up @@ -360,10 +360,10 @@ const getSourceForModuleExternal = (
? `var x = ${runtimeTemplate.basicFunction(
"y",
`var x = {}; ${RuntimeGlobals.definePropertyGetters}(x, y); return x`
)} \nvar y = ${runtimeTemplate.returningFunction(
)} \nvar y = ${runtimeTemplate.returningFunction(
runtimeTemplate.returningFunction("x"),
"x"
)}`
)}`
: undefined,
runtimeRequirements: moduleRemapping
? RUNTIME_REQUIREMENTS_FOR_MODULE
Expand Down Expand Up @@ -443,7 +443,7 @@ const getSourceForAmdOrUmdExternal = (
externalVariable,
Array.isArray(request) ? request.join(".") : request,
runtimeTemplate
)
)
: undefined,
expression: externalVariable
};
Expand Down Expand Up @@ -703,7 +703,7 @@ class ExternalModule extends Module {
/** @type {string} */
(runtimeTemplate.outputOptions.importMetaName),
runtimeTemplate.supportNodePrefixForCoreModules()
)
)
: getSourceForCommonJsExternal(request);
case "amd":
case "amd-require":
Expand Down
2 changes: 1 addition & 1 deletion lib/FileSystemInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3389,7 +3389,7 @@ class FileSystemInfo {
: {
...timestamp,
...hash
};
};
this._contextTshs.set(path, result);
callback(null, result);
};
Expand Down
6 changes: 3 additions & 3 deletions lib/HotModuleReplacementPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ class HotModuleReplacementPlugin {
: compilation.codeGenerationResults.getHash(
module,
chunk.runtime
);
);
if (records.chunkModuleHashes[key] !== hash) {
updatedModules.add(module, chunk);
}
Expand Down Expand Up @@ -629,7 +629,7 @@ class HotModuleReplacementPlugin {
: compilation.codeGenerationResults.getHash(
module,
newRuntime
);
);
if (hash !== oldHash) {
if (module.type === WEBPACK_MODULE_TYPE_RUNTIME) {
newRuntimeModules = newRuntimeModules || [];
Expand Down Expand Up @@ -798,7 +798,7 @@ To fix this, make sure to include [runtime] in the output.hotUpdateMainFilename
Array.from(removedModules, m =>
chunkGraph.getModuleId(m)
)
)
)
};

const source = new RawSource(JSON.stringify(hotUpdateMainJson));
Expand Down
2 changes: 1 addition & 1 deletion lib/ModuleFilenameHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ ModuleFilenameHelpers.createFilename = (
? options
: {
moduleFilenameTemplate: options
})
})
};

let absoluteResourcePath;
Expand Down
26 changes: 13 additions & 13 deletions lib/NormalModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ const contextifySourceMap = (context, sourceMap, associatedObjectForCache) => {
const mapper = !sourceRoot
? source => source
: sourceRoot.endsWith("/")
? source =>
source.startsWith("/")
? `${sourceRoot.slice(0, -1)}${source}`
: `${sourceRoot}${source}`
: source =>
source.startsWith("/")
? `${sourceRoot}${source}`
: `${sourceRoot}/${source}`;
? source =>
source.startsWith("/")
? `${sourceRoot.slice(0, -1)}${source}`
: `${sourceRoot}${source}`
: source =>
source.startsWith("/")
? `${sourceRoot}${source}`
: `${sourceRoot}/${source}`;
const newSources = sourceMap.sources.map(source =>
contextifySourceUrl(context, mapper(source), associatedObjectForCache)
);
Expand Down Expand Up @@ -859,7 +859,7 @@ class NormalModule extends Module {
currentLoader
? compilation.runtimeTemplate.requestShortener.shorten(
currentLoader.loader
)
)
: "unknown"
}) didn't return a Buffer or String`
);
Expand Down Expand Up @@ -1156,10 +1156,10 @@ class NormalModule extends Module {
if (absolute !== dep && ABSOLUTE_PATH_REGEX.test(absolute)) {
(depWithoutGlob !== dep
? /** @type {NonNullable<KnownBuildInfo["contextDependencies"]>} */
(
(
/** @type {BuildInfo} */ (this.buildInfo)
.contextDependencies
)
)
: deps
).add(absolute);
}
Expand Down Expand Up @@ -1352,7 +1352,7 @@ class NormalModule extends Module {
const source = this.error
? new RawSource(
"throw new Error(" + JSON.stringify(this.error.message) + ");"
)
)
: /** @type {Generator} */ (this.generator).generate(this, {
dependencyTemplates,
runtimeTemplate,
Expand All @@ -1364,7 +1364,7 @@ class NormalModule extends Module {
codeGenerationResults,
getData,
type
});
});

if (source) {
sources.set(type, new CachedSource(source));
Expand Down
18 changes: 9 additions & 9 deletions lib/NormalModuleFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ class NormalModuleFactory extends ModuleFactory {
noPreAutoLoaders || noPrePostAutoLoaders
? 2
: noAutoLoaders
? 1
: 0
? 1
: 0
)
.split(/!+/);
unresolvedResource = /** @type {string} */ (rawElements.pop());
Expand Down Expand Up @@ -763,7 +763,7 @@ class NormalModuleFactory extends ModuleFactory {
resolveOptions || EMPTY_RESOLVE_OPTIONS,
"dependencyType",
dependencyType
)
)
: resolveOptions
);
this.resolveResource(
Expand Down Expand Up @@ -1178,12 +1178,12 @@ If changing the source code is not an option there is also a resolve options cal
const type = /\.mjs$/i.test(parsedResult.path)
? "module"
: /\.cjs$/i.test(parsedResult.path)
? "commonjs"
: /** @type {ResolveRequest} */
(resolveRequest).descriptionFileData === undefined
? undefined
: /** @type {ResolveRequest} */
(resolveRequest).descriptionFileData.type;
? "commonjs"
: /** @type {ResolveRequest} */
(resolveRequest).descriptionFileData === undefined
? undefined
: /** @type {ResolveRequest} */
(resolveRequest).descriptionFileData.type;
const resolved = {
loader: parsedResult.path,
type,
Expand Down
9 changes: 2 additions & 7 deletions lib/schemes/HttpUriPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
const EventEmitter = require("events");
const { extname, basename } = require("path");
const { URL } = require("url");
const {
createGunzip,
// eslint-disable-next-line n/no-unsupported-features/node-builtins
createBrotliDecompress,
createInflate
} = require("zlib");
const { createGunzip, createBrotliDecompress, createInflate } = require("zlib");
const NormalModule = require("../NormalModule");
const createSchemaValidation = require("../util/create-schema-validation");
const createHash = require("../util/createHash");
Expand Down Expand Up @@ -205,7 +200,7 @@ class Lockfile {
: {
resolved: key,
...entry
}
}
);
}
return lockfile;
Expand Down
10 changes: 4 additions & 6 deletions lib/serialization/FileMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
const { constants } = require("buffer");
const { pipeline } = require("stream");
const {
// eslint-disable-next-line n/no-unsupported-features/node-builtins
createBrotliCompress,
// eslint-disable-next-line n/no-unsupported-features/node-builtins
createBrotliDecompress,
createGzip,
createGunzip,
Expand Down Expand Up @@ -62,23 +60,23 @@ const DECOMPRESSION_CHUNK_SIZE = 100 * 1024 * 1024;
const writeUInt64LE = Buffer.prototype.writeBigUInt64LE
? (buf, value, offset) => {
buf.writeBigUInt64LE(BigInt(value), offset);
}
}
: (buf, value, offset) => {
const low = value % 0x100000000;
const high = (value - low) / 0x100000000;
buf.writeUInt32LE(low, offset);
buf.writeUInt32LE(high, offset + 4);
};
};

const readUInt64LE = Buffer.prototype.readBigUInt64LE
? (buf, offset) => {
return Number(buf.readBigUInt64LE(offset));
}
}
: (buf, offset) => {
const low = buf.readUInt32LE(offset);
const high = buf.readUInt32LE(offset + 4);
return high * 0x100000000 + low;
};
};

/**
* @typedef {object} SerializeResult
Expand Down
Loading

0 comments on commit 1954237

Please sign in to comment.