css-module-sync 0.1.34 → 1.0.1

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,18 +1,10 @@
1
1
  {
2
2
  "name": "css-module-sync",
3
- "version": "0.1.34",
3
+ "version": "1.0.1",
4
4
  "description": "Auto sync css module classes with react components",
5
5
  "author": "Max Matinpalo",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
- "homepage": "https://github.com/max-matinpalo/css-module-sync#readme",
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/max-matinpalo/css-module-sync.git"
12
- },
13
- "bugs": {
14
- "url": "https://github.com/max-matinpalo/css-module-sync/issues"
15
- },
16
8
  "bin": {
17
9
  "css-sync": "./src/css_sync.js"
18
10
  }
@@ -1,4 +1,4 @@
1
- const BLOCK_MIN_DECLS = 7;
1
+ const BLOCK_MIN_DECLS = 5;
2
2
 
3
3
  /**
4
4
  * css_formatter.js
package/src/css_sync.js CHANGED
@@ -109,23 +109,32 @@ async function format_css_only(css_path) {
109
109
  }
110
110
 
111
111
  async function sync_file(tsx_path) {
112
+ let tsx;
113
+ try { tsx = await fs.readFile(tsx_path, "utf-8"); } catch { return; }
114
+
115
+ const used_ordered = extract_classes(tsx);
116
+ const dir = path.dirname(tsx_path);
117
+ const name = path.basename(tsx_path, path.extname(tsx_path));
118
+ const module_path = path.join(dir, `${name}.module.css`);
119
+ const css_exists = existsSync(module_path);
120
+
121
+ if (FLAGS.gen && used_ordered.length === 0 && !css_exists) return;
122
+
112
123
  const css_path = await resolve_css_path(tsx_path);
113
124
  if (!css_path) return;
114
- let tsx, css;
115
- try {
116
- [tsx, css] = await Promise.all([fs.readFile(tsx_path, "utf-8"), fs.readFile(css_path, "utf-8")]);
117
- } catch (e) { return; }
118
- if (FLAGS.gen) {
125
+
126
+ let css;
127
+ try { css = await fs.readFile(css_path, "utf-8"); } catch { return; }
128
+
129
+ if (FLAGS.gen && used_ordered.length > 0) {
119
130
  const target = `import styles from "./${path.basename(css_path)}";`;
120
- let found = false;
121
- const next = tsx.replace(/^import\s+styles\s+from\s+["'].+["'];?\n?/gm, (m) => {
122
- if (m.includes(`./${path.basename(css_path)}`)) { found = true; return m; }
123
- return "";
124
- });
125
- const final = found ? next : `${target}\n${next}`;
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)}`;
126
135
  if (final !== tsx) await fs.writeFile(tsx_path, tsx = final);
127
136
  }
128
- const used_ordered = extract_classes(tsx);
137
+
129
138
  let root;
130
139
  try { root = parse(css); } catch { return; }
131
140
  const class_to_idxs = new Map();
@@ -39,38 +39,41 @@
39
39
  "height",
40
40
  "min-height",
41
41
  "max-height",
42
- "aspect-ratio",
43
42
  "margin...",
44
43
  "padding...",
45
- "border..."
44
+ "border...",
45
+ "aspect-ratio"
46
46
  ]
47
47
  },
48
48
  {
49
- "category": "COLOR",
49
+ "category": "SCROLL",
50
+ "keywords": [
51
+ "overflow...",
52
+ "scroll...",
53
+ "scrollbar...",
54
+ "overscroll-behavior...",
55
+ "-webkit-overflow-scrolling"
56
+ ]
57
+ },
58
+ {
59
+ "category": "VISUALS",
50
60
  "keywords": [
51
61
  "color",
52
62
  "background...",
53
63
  "opacity",
54
- "box-shadow"
64
+ "box-shadow",
65
+ "backdrop-filter",
66
+ "-webkit-backdrop-filter"
55
67
  ]
56
68
  },
57
69
  {
58
70
  "category": "TYPO",
59
71
  "keywords": [
60
- "font",
61
- "font-family",
62
- "font-size",
63
- "font-weight",
64
- "font-style",
65
72
  "font...",
66
- "font-stretch",
67
73
  "line-height",
74
+ "text...",
68
75
  "letter-spacing",
69
76
  "word-spacing",
70
- "text-align",
71
- "text-transform",
72
- "text-decoration....",
73
- "text-underline-offset",
74
77
  "white-space"
75
78
  ]
76
79
  },