Skip to content

Commit

Permalink
fix dynamic requires using .default for es module interop
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLarkInn committed Dec 23, 2022
1 parent abceae4 commit fd6ceac
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/getHashDigest.ts
Expand Up @@ -71,20 +71,20 @@ export default function getHashDigest(buffer: Buffer, algorithm: string | "xxhas

if (algorithm === "xxhash64") {
if (createXXHash64 === undefined) {
createXXHash64 = require("./hash/xxhash64");
createXXHash64 = require("./hash/xxhash64").default;

if (BatchedHash === undefined) {
BatchedHash = require("./hash/BatchedHash");
BatchedHash = require("./hash/BatchedHash").default;
}
}

hash = new BatchedHash(createXXHash64() as unknown as Hash);
} else if (algorithm === "md4") {
if (createMd4 === undefined) {
createMd4 = require("./hash/md4");
createMd4 = require("./hash/md4").default;

if (BatchedHash === undefined) {
BatchedHash = require("./hash/BatchedHash");
BatchedHash = require("./hash/BatchedHash").default;
}
}

Expand All @@ -94,7 +94,7 @@ export default function getHashDigest(buffer: Buffer, algorithm: string | "xxhas
crypto = require("crypto");

if (BulkUpdateDecorator === undefined) {
BulkUpdateDecorator = require("./hash/BulkUpdateDecorator");
BulkUpdateDecorator = require("./hash/BulkUpdateDecorator").default;
}
}

Expand All @@ -104,7 +104,7 @@ export default function getHashDigest(buffer: Buffer, algorithm: string | "xxhas
crypto = require("crypto");

if (BulkUpdateDecorator === undefined) {
BulkUpdateDecorator = require("./hash/BulkUpdateDecorator");
BulkUpdateDecorator = require("./hash/BulkUpdateDecorator").default;
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/interpolateName.ts
Expand Up @@ -104,7 +104,9 @@ export default function interpolateName(loaderContext: LoaderContext<{}>, name:
}

if (
// @ts-ignore
// @ts-ignore LoaderContext doesn't even have options defined on it?
// If we chagned this to be `loaderContext.getOptions()` it would still not have
// the customInterpolateName function defined on it.
typeof loaderContext.options === "object" &&
// @ts-ignore
typeof loaderContext.options.customInterpolateName === "function"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -33,7 +33,7 @@
"typescript": "^4.9.4",
"webpack": "^5.64.4"
},
"main": "lib/index.js",
"main": "dist/index.js",
"files": [
"lib"
]
Expand Down
2 changes: 1 addition & 1 deletion test/getHashDigest.test.js
@@ -1,6 +1,6 @@
"use strict";

const loaderUtils = require("../dist");
const loaderUtils = require("../");

describe("getHashDigest()", () => {
[
Expand Down
2 changes: 1 addition & 1 deletion test/interpolateName.test.js
@@ -1,6 +1,6 @@
"use strict";

const loaderUtils = require("../dist");
const loaderUtils = require("../");

describe("interpolateName()", () => {
function run(tests) {
Expand Down
2 changes: 1 addition & 1 deletion test/isUrlRequest.test.js
@@ -1,6 +1,6 @@
"use strict";

const loaderUtils = require("../dist");
const loaderUtils = require("../");

function ExpectedError(regex) {
this.regex = regex;
Expand Down
2 changes: 1 addition & 1 deletion test/urlToRequest.test.js
@@ -1,6 +1,6 @@
"use strict";

const loaderUtils = require("../dist");
const loaderUtils = require("../");

function ExpectedError(regex) {
this.regex = regex;
Expand Down

0 comments on commit fd6ceac

Please sign in to comment.