Repository: tivac/modular-css
Pull request #1021 (2025-01-08 19:48:51)

fix: dupecheck _every_ file we track
Just being cautious!

changeset-bot[bot]: ###  ⚠️  No Changeset found

Latest commit: 5016340187b71be3b7ff33397af4ab214df3a725

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. **If these changes should result in a version bump, you need to add a changeset.**

<details><summary>This PR includes no changesets</summary>

  When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

</details>

[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/tivac/modular-css/new/more-dupechecking?filename=.changeset/thirty-shrimps-grab.md&value=---%0A%22%40modular-css%2Fprocessor%22%3A%20patch%0A---%0A%0Afix%3A%20dupecheck%20_every_%20file%20we%20track%0A)


netlify[bot]: ### <span aria-hidden="true">✅</span> Deploy Preview for *m-css* ready!


|  Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 5016340187b71be3b7ff33397af4ab214df3a725 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/m-css/deploys/677ed6a69716e90008df4adf |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-1021--m-css.netlify.app](https://deploy-preview-1021--m-css.netlify.app) |
|<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br />![QR Code](https://app.netlify.com/qr-code/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1cmwiOiJodHRwczovL2RlcGxveS1wcmV2aWV3LTEwMjEtLW0tY3NzLm5ldGxpZnkuYXBwIn0.ihqr66Kastmlmfxa5vN7wqkHnaRIhINDVo1f48GjoZw)<br /><br />_Use your smartphone camera to open QR code link._</details> |
---
<!-- [m-css Preview](https://deploy-preview-1021--m-css.netlify.app) -->
_To edit notification comments on pull requests, go to your [Netlify site configuration](https://app.netlify.com/sites/m-css/configuration/notifications#deploy-webhooks)._

Patch:
diff --git a/packages/processor/processor.js b/packages/processor/processor.js
index 6b24da96..0c8bb5da 100644
--- a/packages/processor/processor.js
+++ b/packages/processor/processor.js
@@ -76,7 +76,7 @@ const DEFAULTS = {
     resolvers : [],
     rewrite   : true,
     verbose   : false,
-    
+
     exportGlobals : true,
 };
 
@@ -420,7 +420,25 @@ class Processor {
         return this._warnings;
     }
 
+    _dupeCheck(file) {
+        const check = file.toLowerCase();
+
+        // Warn about potential dupes if an ID goes past we've seen before
+        if(this._options.dupewarn) {
+            const other = this._ids.get(check);
+
+            if(other && other !== file) {
+                // eslint-disable-next-line no-console -- warning
+                console.warn(`POTENTIAL DUPLICATE FILES:\n\t${other}\n\t${file}`);
+            }
+        }
+
+        this._ids.set(check, file);
+    }
+
     _addFile(file) {
+        this._dupeCheck(file);
+
         const key = fileKey(file);
 
         if(!this._graph.hasNode(key)) {
@@ -494,7 +512,7 @@ class Processor {
 
     _addDependency({ selector, refs = [], dependency, name }) {
         const { _graph : graph } = this;
-        
+
         const dep = this._normalize(dependency);
         const fKey = this._addFile(name);
         const dKey = this._addFile(dep);
@@ -521,19 +539,7 @@ class Processor {
     // Take a file id and some text, walk it for dependencies, then
     // process and return details
     async _add(id, src) {
-        const check = id.toLowerCase();
-
-        // Warn about potential dupes if an ID goes past we've seen before
-        if(this._options.dupewarn) {
-            const other = this._ids.get(check);
-
-            if(other && other !== id) {
-                // eslint-disable-next-line no-console -- warning
-                console.warn(`POTENTIAL DUPLICATE FILES:\n\t${relative(this._options.cwd, other)}\n\t${relative(this._options.cwd, id)}`);
-            }
-        }
-
-        this._ids.set(check, id);
+        this._dupeCheck(id);
 
         this._log("_add()", id);
 


Test patch:
diff --git a/packages/processor/test/__snapshots__/options.test.js.snap b/packages/processor/test/__snapshots__/options.test.js.snap
index a3f0c485..6f4129ca 100644
--- a/packages/processor/test/__snapshots__/options.test.js.snap
+++ b/packages/processor/test/__snapshots__/options.test.js.snap
@@ -69,8 +69,8 @@ exports[`/processor.js options lifecycle options dupewarn should warn on potenti
 [
   [
     "POTENTIAL DUPLICATE FILES:
-	packages/processor/test/specimens/start.css
-	packages/processor/test/specimens/START.css",
+packages/processor/test/specimens/start.css
+packages/processor/test/specimens/START.css",
   ],
 ]
 `;
diff --git a/packages/test-utils/expect/toMatchLogspySnapshot.js b/packages/test-utils/expect/toMatchLogspySnapshot.js
index 0e33ae82..12ff749a 100644
--- a/packages/test-utils/expect/toMatchLogspySnapshot.js
+++ b/packages/test-utils/expect/toMatchLogspySnapshot.js
@@ -19,10 +19,19 @@ expect.extend({
         }
 
         const calls = spy.mock.calls.map((call) =>
-            call.map((arg) => (typeof arg === "string" && path.isAbsolute(arg) ?
-                relative([ arg ])[0] :
-                arg
-            ))
+            call.map((arg) => {
+                if(typeof arg !== "string") {
+                    return arg;
+                }
+                
+                return arg
+                    .split(/\r?\n/)
+                    .map((line) => (path.isAbsolute(line.trim()) ?
+                        relative([ line.trim() ])[0] :
+                        line)
+                    )
+                    .join("\n");
+            })
         );
 
         return snapshot.toMatchSnapshot.call(this, calls);