Skip to content

Commit

Permalink
chore!: minimum supported Node.js version is 18.12.0 (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jan 15, 2024
1 parent ac7068f commit 7fcab17
Show file tree
Hide file tree
Showing 11 changed files with 7,313 additions and 15,970 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Expand Up @@ -60,7 +60,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [18.x, 20.x, 21.x]
webpack-version: [latest]

runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion babel.config.js
Expand Up @@ -10,7 +10,7 @@ module.exports = (api) => {
"@babel/preset-env",
{
targets: {
node: "14.15.0",
node: "18.12.0",
},
},
],
Expand Down
23,176 changes: 7,258 additions & 15,918 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Expand Up @@ -13,7 +13,7 @@
},
"main": "dist/cjs.js",
"engines": {
"node": ">= 14.15.0"
"node": ">= 18.12.0"
},
"scripts": {
"start": "npm run build -- -w",
Expand Down Expand Up @@ -48,26 +48,26 @@
"source-map-js": "^1.0.2"
},
"devDependencies": {
"@babel/cli": "^7.23.0",
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.7",
"@babel/preset-env": "^7.23.7",
"@commitlint/cli": "^17.7.2",
"@commitlint/config-conventional": "^16.2.4",
"@babel/preset-env": "^7.23.8",
"@commitlint/cli": "^18.4.4",
"@commitlint/config-conventional": "^18.4.4",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^29.7.0",
"cross-env": "^7.0.3",
"cspell": "^6.31.3",
"del": "^6.0.0",
"del-cli": "^4.0.1",
"cspell": "^8.3.2",
"del": "^7.1.0",
"del-cli": "^5.1.0",
"eslint": "^8.50.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.28.1",
"husky": "^8.0.3",
"jest": "^29.7.0",
"lint-staged": "^13.3.0",
"memfs": "^3.5.3",
"lint-staged": "^15.2.0",
"memfs": "^4.6.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"prettier": "^3.2.2",
"standard-version": "^9.5.0",
"webpack": "^5.88.2"
},
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Expand Up @@ -54,7 +54,7 @@ export default async function loader(input, inputMap) {
({ sourceURL, sourceContent } = await fetchFromURL(
this,
this.context,
sourceMappingURL
sourceMappingURL,
));
} catch (error) {
this.emitWarning(error);
Expand All @@ -75,8 +75,8 @@ export default async function loader(input, inputMap) {
} catch (parseError) {
this.emitWarning(
new Error(
`Failed to parse source map from '${sourceMappingURL}': ${parseError}`
)
`Failed to parse source map from '${sourceMappingURL}': ${parseError}`,
),
);

callback(null, input, inputMap);
Expand Down Expand Up @@ -117,7 +117,7 @@ export default async function loader(input, inputMap) {
context,
source,
map.sourceRoot,
skipReading
skipReading,
));
} catch (error) {
errored = true;
Expand All @@ -133,7 +133,7 @@ export default async function loader(input, inputMap) {

// Return original value of `source` when error happens
return { sourceURL: errored ? source : sourceURL, sourceContent };
})
}),
);

const newMap = { ...map };
Expand Down
6 changes: 3 additions & 3 deletions src/parse-data-url.js
Expand Up @@ -85,7 +85,7 @@ function percentDecodeBytes(input) {
} else {
output[outputIndex] = parseInt(
String.fromCodePoint(input[i + 1], input[i + 2]),
16
16,
);
i += 2;
}
Expand Down Expand Up @@ -249,7 +249,7 @@ export default function parseDataUrl(stringInput) {

// Can't use /i regexp flag because it isn't restricted to ASCII.
const mimeTypeBase64MatchResult = /(.*); *[Bb][Aa][Ss][Ee]64$/.exec(
mediaType
mediaType,
);

if (mimeTypeBase64MatchResult) {
Expand Down Expand Up @@ -362,7 +362,7 @@ export default function parseDataUrl(stringInput) {
if (inputMediaType[positionMediaType] === '"') {
[parameterValue, positionMediaType] = collectAnHTTPQuotedString(
inputMediaType,
positionMediaType
positionMediaType,
);

while (
Expand Down
22 changes: 11 additions & 11 deletions src/utils.js
Expand Up @@ -25,7 +25,7 @@ const sourceMappingURLRegex = RegExp(
innerRegex.source +
")" +
")" +
"\\s*"
"\\s*",
);
/* eslint-enable prefer-template */

Expand Down Expand Up @@ -145,7 +145,7 @@ async function fetchFromFilesystem(loaderContext, sourceURL) {
});
} catch (error) {
throw new Error(
`Failed to parse source map from '${sourceURL}' file: ${error}`
`Failed to parse source map from '${sourceURL}' file: ${error}`,
);
}

Expand All @@ -155,15 +155,15 @@ async function fetchFromFilesystem(loaderContext, sourceURL) {
async function fetchPathsFromFilesystem(
loaderContext,
possibleRequests,
errorsAccumulator = ""
errorsAccumulator = "",
) {
let result;

try {
result = await fetchFromFilesystem(
loaderContext,
possibleRequests[0],
errorsAccumulator
errorsAccumulator,
);
} catch (error) {
// eslint-disable-next-line no-param-reassign
Expand All @@ -180,7 +180,7 @@ async function fetchPathsFromFilesystem(
return fetchPathsFromFilesystem(
loaderContext,
tailPossibleRequests,
errorsAccumulator
errorsAccumulator,
);
}

Expand All @@ -196,7 +196,7 @@ async function fetchFromURL(
context,
url,
sourceRoot,
skipReading = false
skipReading = false,
) {
// 1. It's an absolute url and it is not `windows` path like `C:\dir\file`
if (isURL(url)) {
Expand All @@ -221,21 +221,21 @@ async function fetchFromURL(
const sourceURL = path.normalize(pathFromURL);
const { data: sourceContent } = await fetchFromFilesystem(
loaderContext,
sourceURL
sourceURL,
);

return { sourceURL, sourceContent };
}

throw new Error(
`Failed to parse source map: '${url}' URL is not supported`
`Failed to parse source map: '${url}' URL is not supported`,
);
}

// 2. It's a scheme-relative
if (/^\/\//.test(url)) {
throw new Error(
`Failed to parse source map: '${url}' URL is not supported`
`Failed to parse source map: '${url}' URL is not supported`,
);
}

Expand All @@ -250,13 +250,13 @@ async function fetchFromURL(

if (url.startsWith("/")) {
possibleRequests.push(
getAbsolutePath(context, sourceURL.slice(1), sourceRoot)
getAbsolutePath(context, sourceURL.slice(1), sourceRoot),
);
}

const result = await fetchPathsFromFilesystem(
loaderContext,
possibleRequests
possibleRequests,
);

sourceURL = result.path;
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/execute.js
Expand Up @@ -8,7 +8,7 @@ export default (code) => {
const module = new Module(resource, parentModule);
// eslint-disable-next-line no-underscore-dangle
module.paths = Module._nodeModulePaths(
path.resolve(__dirname, "../fixtures")
path.resolve(__dirname, "../fixtures"),
);
module.filename = resource;

Expand Down
2 changes: 1 addition & 1 deletion test/helpers/getCodeFromBundle.js
Expand Up @@ -22,7 +22,7 @@ function getCodeFromBundle(stats, compiler, asset) {
`${code};\nmodule.exports = sourceMapLoaderExport;`,
{
module: {},
}
},
);

// eslint-disable-next-line no-underscore-dangle
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/getCompiler.js
Expand Up @@ -7,7 +7,7 @@ export default (
fixture,
loaderOptions = {},
config = {},
skipTestLoader = false
skipTestLoader = false,
) => {
const loaders = [
{
Expand Down
35 changes: 19 additions & 16 deletions test/loader.test.js
Expand Up @@ -172,7 +172,7 @@ describe("source-map-loader", () => {
// Create the entryPointFile file
const entryFileContent = `// Some content \r\n // # sourceMappingURL=file://${sourceMapPath.replace(
/\\/g,
"/"
"/",
)}`;
fs.writeFileSync(entryFileAbsolutePath, entryFileContent);

Expand Down Expand Up @@ -267,13 +267,16 @@ describe("source-map-loader", () => {
expect(codeFromBundle.map).toBeUndefined();
expect(codeFromBundle.code).toMatchSnapshot("code");

if (process.version.startsWith("v20")) {
if (
process.version.startsWith("v20") ||
process.version.startsWith("v21")
) {
expect(getWarnings(stats)[0]).toContain(
`SyntaxError: Unexpected non-whitespace character after JSON at position 102`
`SyntaxError: Unexpected non-whitespace character after JSON at position 102`,
);
} else {
expect(getWarnings(stats)[0]).toContain(
`SyntaxError: Unexpected string in JSON at position 102`
`SyntaxError: Unexpected string in JSON at position 102`,
);
}
expect(getErrors(stats)).toMatchSnapshot("errors");
Expand Down Expand Up @@ -332,7 +335,7 @@ describe("source-map-loader", () => {
const rootRelativeSourcePath = path.join(sourceRoot, sourceFilename);
const sourceMapPath = path.join(
sourceRoot,
"absolute-sourceRoot-source-map.map"
"absolute-sourceRoot-source-map.map",
);

// Create the sourcemap file
Expand Down Expand Up @@ -368,12 +371,12 @@ describe("source-map-loader", () => {
__dirname,
"fixtures",
"data",
sourceFilename
sourceFilename,
);
const sourceMapPath = path.join(
__dirname,
"fixtures",
"relative-sourceRoot-source-map.map"
"relative-sourceRoot-source-map.map",
);

const testId = "relative-sourceRoot-source-map.js";
Expand All @@ -398,7 +401,7 @@ describe("source-map-loader", () => {
const currentDirPath = path.join(
__dirname,
"fixtures",
"indexed-sourcemap"
"indexed-sourcemap",
);

const testId = path.join(currentDirPath, "file.js");
Expand Down Expand Up @@ -426,7 +429,7 @@ describe("source-map-loader", () => {
const currentDirPath = path.join(
__dirname,
"fixtures",
"indexed-sourcemap"
"indexed-sourcemap",
);

const testId = path.join(currentDirPath, "file2.js");
Expand Down Expand Up @@ -454,7 +457,7 @@ describe("source-map-loader", () => {
const currentDirPath = path.join(
__dirname,
"fixtures",
"indexed-sourcemap"
"indexed-sourcemap",
);

const testId = path.join(currentDirPath, "file.js");
Expand All @@ -472,8 +475,8 @@ describe("source-map-loader", () => {
path.normalize(
source
.replace(/webpack:\/\/sourceMapLoaderExport\//, "")
.replace("..", "")
)
.replace("..", ""),
),
);

expect(new Set(normalizedSources)).toEqual(new Set(dependencies));
Expand All @@ -497,7 +500,7 @@ describe("source-map-loader", () => {
const entryFileAbsolutePath = path.join(sourceRoot, javaScriptFilename);
const sourceMapPath = path.join(
sourceRoot,
"map-without-sourceroot.js.map"
"map-without-sourceroot.js.map",
);

// Create the sourcemap file
Expand Down Expand Up @@ -653,7 +656,7 @@ describe("source-map-loader", () => {
const codeFromBundle = getCodeFromBundle(stats, compiler);

expect(
stats.toString({ warningsFilter: /Failed to parse source map/ })
stats.toString({ warningsFilter: /Failed to parse source map/ }),
).not.toContain("Failed to parse source map");
expect(codeFromBundle.map).toBeUndefined();
expect(codeFromBundle.code).toMatchSnapshot("code");
Expand All @@ -667,7 +670,7 @@ describe("source-map-loader", () => {
const sourceFilename = "server-relative-url-path.js";
const sourceMapPath = path.join(
sourceRoot,
"server-relative-url-path.js.map"
"server-relative-url-path.js.map",
);

// Create the sourcemap file
Expand Down Expand Up @@ -715,7 +718,7 @@ describe("source-map-loader", () => {
path.resolve(
__dirname,
"fixtures",
"data/relative-sourceRoot-source-map.txt"
"data/relative-sourceRoot-source-map.txt",
),
];
const notInDependencies = ["", "data:invalid;A;a", "./data/not-found.txt"];
Expand Down

0 comments on commit 7fcab17

Please sign in to comment.