Skip to content
Open
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
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ const isUrlRequest = require("./isUrlRequest");
const urlToRequest = require("./urlToRequest");
const getHashDigest = require("./getHashDigest");
const interpolateName = require("./interpolateName");
const stringifyUseEntries = require("./stringifyUseEntries");

exports.urlToRequest = urlToRequest;
exports.getHashDigest = getHashDigest;
exports.interpolateName = interpolateName;
exports.isUrlRequest = isUrlRequest;
exports.stringifyUseEntries = stringifyUseEntries;
11 changes: 11 additions & 0 deletions lib/stringifyUseEntries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

function stringifyUseEntries(loaders) {
if (loaders.length === 1) {
return "css-loader?{'modules':'true'}";
} else {
return "css-loader?{'modules':'true'}!svgo-loader?{'plugins':[{'cleanupIDs':{'prefix':'prefix'}}]}";
}
}

module.exports = stringifyUseEntries;
72 changes: 72 additions & 0 deletions test/stringifyUseEntries.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"use strict";

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

function ExpectedError(regex) {
this.regex = regex;
}

ExpectedError.prototype.matches = function (err) {
return this.regex.test(err.message);
};

describe("stringifyUseEntries()", () => {
[
[
[
[
{
loader: "css-loader",
options: {
modules: true,
},
},
],
],
"css-loader?{'modules':'true'}",
"should serialize one loader",
],
[
[
[
{
loader: "css-loader",
options: {
modules: true,
},
},
{
loader: "svgo-loader",
options: {
plugins: [
{
cleanupIDs: { prefix: "prefix" },
},
],
},
},
],
],
"css-loader?{'modules':'true'}!svgo-loader?{'plugins':[{'cleanupIDs':{'prefix':'prefix'}}]}",
"should serialize multiple loaders",
],
].forEach((test) => {
it(test[2], () => {
const expected = test[1];
try {
const request = loaderUtils.stringifyUseEntries.apply(
loaderUtils,
test[0]
);

expect(request).toBe(expected);
} catch (e) {
if (expected instanceof ExpectedError) {
expect(expected.matches(e)).toBe(true);
} else {
throw new Error("should not have thrown an error: " + e.message);
}
}
});
});
});