Fix map not updating when using watch files

This commit is contained in:
g45t345rt 2021-03-31 14:48:29 -04:00
parent 81d1e9ea77
commit d798528ba6
3 changed files with 29 additions and 13 deletions

13
dist/index.esm.js vendored
View File

@ -19,10 +19,15 @@ const postCSSPlugin = ({
generateScopedName: "[name]__[local]___[hash:base64:5]", generateScopedName: "[name]__[local]___[hash:base64:5]",
...typeof modules !== "boolean" ? modules : {}, ...typeof modules !== "boolean" ? modules : {},
getJSON(filepath, json, outpath) { getJSON(filepath, json, outpath) {
modulesMap.push({ const mapIndex = modulesMap.findIndex((m) => m.path === filepath);
path: filepath, if (mapIndex !== -1) {
map: json modulesMap[mapIndex].map = json;
}); } else {
modulesMap.push({
path: filepath,
map: json
});
}
if (typeof modules !== "boolean" && typeof modules.getJSON === "function") if (typeof modules !== "boolean" && typeof modules.getJSON === "function")
return modules.getJSON(filepath, json, outpath); return modules.getJSON(filepath, json, outpath);
} }

13
dist/index.js vendored
View File

@ -45,10 +45,15 @@ const postCSSPlugin = ({
generateScopedName: "[name]__[local]___[hash:base64:5]", generateScopedName: "[name]__[local]___[hash:base64:5]",
...typeof modules !== "boolean" ? modules : {}, ...typeof modules !== "boolean" ? modules : {},
getJSON(filepath, json, outpath) { getJSON(filepath, json, outpath) {
modulesMap.push({ const mapIndex = modulesMap.findIndex((m) => m.path === filepath);
path: filepath, if (mapIndex !== -1) {
map: json modulesMap[mapIndex].map = json;
}); } else {
modulesMap.push({
path: filepath,
map: json
});
}
if (typeof modules !== "boolean" && typeof modules.getJSON === "function") if (typeof modules !== "boolean" && typeof modules.getJSON === "function")
return modules.getJSON(filepath, json, outpath); return modules.getJSON(filepath, json, outpath);
} }

View File

@ -43,10 +43,16 @@ const postCSSPlugin = ({
generateScopedName: "[name]__[local]___[hash:base64:5]", generateScopedName: "[name]__[local]___[hash:base64:5]",
...(typeof modules !== "boolean" ? modules : {}), ...(typeof modules !== "boolean" ? modules : {}),
getJSON(filepath, json, outpath) { getJSON(filepath, json, outpath) {
modulesMap.push({ // Make sure to replace json map instead of pushing new map everytime with edit file on watch
path: filepath, const mapIndex = modulesMap.findIndex((m) => m.path === filepath);
map: json if (mapIndex !== -1) {
}); modulesMap[mapIndex].map = json;
} else {
modulesMap.push({
path: filepath,
map: json
});
}
if ( if (
typeof modules !== "boolean" && typeof modules !== "boolean" &&
@ -62,7 +68,7 @@ const postCSSPlugin = ({
// Namespace is empty when using CSS as an entrypoint // Namespace is empty when using CSS as an entrypoint
if (args.namespace !== "file" && args.namespace !== "") return; if (args.namespace !== "file" && args.namespace !== "") return;
// Resolve files also from node_modules (ex: npm normalize.css) // Resolve files from node_modules (ex: npm install normalize.css)
let sourceFullPath = resolveFile(args.path); let sourceFullPath = resolveFile(args.path);
if (!sourceFullPath) if (!sourceFullPath)
sourceFullPath = path.resolve(args.resolveDir, args.path); sourceFullPath = path.resolve(args.resolveDir, args.path);