Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
chore: run prettier on new files
  • Loading branch information
stephenkao committed Apr 8, 2024
commit cd3b7ae25a5d8216a20e5b99bcd41a94789243a0
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1473,12 +1473,12 @@ module.exports = {
// synchronously write a .json mapping file in the same directory as the resource
const exportsJson = exports.reduce(
(acc, { name, value }) => ({ ...acc, [name]: value }),
{}
{},
);

const outputPath = path.resolve(
path.dirname(resourcePath),
`${path.basename(resourcePath)}.json`
`${path.basename(resourcePath)}.json`,
);

const fs = require("fs");
Expand All @@ -1503,12 +1503,12 @@ module.exports = {
getJSON: async ({ resourcePath, exports }) => {
const exportsJson = exports.reduce(
(acc, { name, value }) => ({ ...acc, [name]: value }),
{}
{},
);

const outputPath = path.resolve(
path.dirname(resourcePath),
`${path.basename(resourcePath)}.json`
`${path.basename(resourcePath)}.json`,
);

const fsp = require("fs/promises");
Expand Down Expand Up @@ -1548,15 +1548,15 @@ function addReplacements(resourcePath, imports, exportsJson, replacements) {
importReplacementsMap[resourcePath] = replacements.reduce(
(acc, { replacementName, importName, localName }) => {
const replacementImportUrl = imports.find(
(importData) => importData.importName === importName
(importData) => importData.importName === importName,
).url;
const relativePathRe = /.*!(.*)"/;
const [, relativePath] = replacementImportUrl.match(relativePathRe);
const importPath = path.resolve(path.dirname(resourcePath), relativePath);
const identifier = generateIdentifier(importPath, localName);
return { ...acc, [replacementName]: `___REPLACEMENT${identifier}___` };
},
{}
{},
);

// iterate through the raw exports and add stand-in variables
Expand All @@ -1572,7 +1572,7 @@ function addReplacements(resourcePath, imports, exportsJson, replacements) {
CSS_LOADER_REPLACEMENT_REGEX,
(_, replacementName) => {
return importReplacementsMap[resourcePath][replacementName];
}
},
);
} else {
// otherwise, no class names need replacements so we can add them to
Expand All @@ -1598,7 +1598,7 @@ function replaceReplacements(classNames) {
const canonicalValue = replaceReplacements(replacementsMap[identifier]);
canonicalValuesMap[identifier] = canonicalValue;
return canonicalValue;
}
},
);

return adjustedClassNames;
Expand All @@ -1615,7 +1615,7 @@ module.exports = {
getJSON: ({ resourcePath, imports, exports, replacements }) => {
const exportsJson = exports.reduce(
(acc, { name, value }) => ({ ...acc, [name]: value }),
{}
{},
);

if (replacements.length > 0) {
Expand All @@ -1625,7 +1625,7 @@ module.exports = {
resourcePath,
imports,
exportsJson,
replacements
replacements,
);
} else {
// no replacements present --> add to canonicalValuesMap verbatim
Expand All @@ -1649,7 +1649,7 @@ module.exports = {
apply(compiler) {
compiler.hooks.done.tap("CssModulesJsonPlugin", () => {
for (const [identifier, classNames] of Object.entries(
replacementsMap
replacementsMap,
)) {
const adjustedClassNames = replaceReplacements(classNames);
replacementsMap[identifier] = adjustedClassNames;
Expand All @@ -1662,7 +1662,7 @@ module.exports = {
fs.writeFileSync(
"./output.css.json",
JSON.stringify(allExportsJson, null, 2),
"utf8"
"utf8",
);
});
},
Expand Down
4 changes: 2 additions & 2 deletions test/modules-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2621,10 +2621,10 @@ describe('"modules" option', () => {
expect(args).toMatchSnapshot("args");

expect(
getModuleSource("./modules/getJSON/source.css", stats)
getModuleSource("./modules/getJSON/source.css", stats),
).toMatchSnapshot("module");
expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot(
"result"
"result",
);
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
Expand Down