css-module-sync 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-module-sync",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Auto sync css module classes with react components",
5
5
  "author": "Max Matinpalo",
6
6
  "type": "module",
package/src/css_sync.js CHANGED
@@ -128,11 +128,13 @@ async function sync_file(tsx_path) {
128
128
 
129
129
  if (FLAGS.gen && used_ordered.length > 0) {
130
130
  const target = `import styles from "./${path.basename(css_path)}";`;
131
- const next = tsx.replace(/^import\s+styles\s+from\s+["'][^"']+["'];?\s*\n?/gm, "");
132
- const m = next.match(/^(\s*(?:(?:\/\*.*?\*\/)\s*|\/\/.*\s*)*)(["']use client["'];?\s*\n)?/s);
133
- const i = m ? m[0].length : 0;
134
- const final = `${next.slice(0, i)}${target}\n${next.slice(i)}`;
135
- if (final !== tsx) await fs.writeFile(tsx_path, tsx = final);
131
+ if (!tsx.includes(target)) {
132
+ const next = tsx.replace(/^import\s+styles\s+from\s+["'][^"']+["'];?\s*\n?/gm, "");
133
+ const m = next.match(/^(\s*(?:(?:\/\*.*?\*\/)\s*|\/\/.*\s*)*)(["']use client["'];?\s*\n)?/s);
134
+ const i = m ? m[0].length : 0;
135
+ const final = `${next.slice(0, i)}${target}\n${next.slice(i)}`;
136
+ if (final !== tsx) await fs.writeFile(tsx_path, tsx = final);
137
+ }
136
138
  }
137
139
 
138
140
  let root;
@@ -263,7 +265,7 @@ async function main() {
263
265
  console.warn(`[RENAME] Multiple orphan .module.css in ${dir}; skipping:\n` +
264
266
  orphans.map(p => `- ${path.basename(p)}`).join("\n"));
265
267
  }
266
- }, 50); // Decreased timeout to run before sync_file
268
+ }, 50);
267
269
  }
268
270
  }
269
271
 
@@ -273,7 +275,7 @@ async function main() {
273
275
  debouncers.delete(full_path);
274
276
  if (is_tsx) sync_file(full_path).catch(() => { });
275
277
  else if (FLAGS.sort) format_css_only(full_path).catch(() => { });
276
- }, 150)); // Increased timeout to run after rename
278
+ }, 150));
277
279
  });
278
280
  }
279
281
  }
package/README.md DELETED
@@ -1,22 +0,0 @@
1
-
2
- # css-module-sync
3
- Auto sync css module classes with react components.
4
-
5
-
6
- ### Install
7
- ```bash
8
- npm install css-module-sync
9
- ```
10
-
11
- ### Usage
12
- ```bash
13
- npx css-sync
14
- ```
15
-
16
- ### Options
17
-
18
- | Option | Description |
19
- |---------|----------------------------------------------------------|
20
- | --watch | Watches components all time and keeps styles in sync |
21
- | --dir | Directory to watch (default is `src`) |
22
- | --gen | Auto generates `.module.css` files for `.jsx` / `.tsx` files. Filename must start with uppercase letter and contain no spaces |