xatriumcss 1.0.14 → 1.0.15

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +43 -40
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xatriumcss",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Ultra-fast utility-first CSS framework",
5
5
  "main": "./src/index.js",
6
6
  "files": [
package/src/cli.js CHANGED
@@ -12,10 +12,10 @@ function parseArgs(argv) {
12
12
  '--output': null,
13
13
  '--watch': false
14
14
  };
15
-
15
+
16
16
  for (let i = 0; i < argv.length; i++) {
17
17
  const arg = argv[i];
18
-
18
+
19
19
  if (arg === '--watch' || arg === '-w') {
20
20
  args['--watch'] = true;
21
21
  } else if (arg === '--input' || arg === '-i') {
@@ -24,7 +24,7 @@ function parseArgs(argv) {
24
24
  args['--output'] = argv[++i];
25
25
  }
26
26
  }
27
-
27
+
28
28
  return args;
29
29
  }
30
30
 
@@ -44,12 +44,12 @@ config.output = path.resolve(projectRoot, config.output);
44
44
 
45
45
  function build() {
46
46
  const startTime = process.hrtime.bigint();
47
-
47
+
48
48
  console.log('šŸ” Checking for @import "xatriumcss"...');
49
-
49
+
50
50
  // Check if input CSS has the import
51
51
  const hasImport = hasXatriumImport(config.input);
52
-
52
+
53
53
  if (!hasImport) {
54
54
  console.log('āš ļø No @import "xatriumcss" found - writing empty CSS');
55
55
  const outputDir = path.dirname(config.output);
@@ -57,24 +57,24 @@ function build() {
57
57
  fs.mkdirSync(outputDir, { recursive: true });
58
58
  }
59
59
  fs.writeFileSync(config.output, '', 'utf-8');
60
-
60
+
61
61
  const endTime = process.hrtime.bigint();
62
62
  const duration = endTime - startTime;
63
63
  console.log(`āœ… Done in ${formatTime(duration)}`);
64
64
  return;
65
65
  }
66
-
66
+
67
67
  runParser(config);
68
-
68
+
69
69
  const endTime = process.hrtime.bigint();
70
70
  const duration = endTime - startTime;
71
-
71
+
72
72
  console.log(`āœ… Done in ${formatTime(duration)}`);
73
73
  }
74
74
 
75
75
  function formatTime(nanoseconds) {
76
76
  const ms = Number(nanoseconds) / 1_000_000;
77
-
77
+
78
78
  if (ms < 1000) return `${Math.round(ms)}ms`;
79
79
  return `${(ms / 1000).toFixed(2)}s`;
80
80
  }
@@ -89,116 +89,119 @@ function formatTime(nanoseconds) {
89
89
  process.exit(1);
90
90
  }
91
91
 
92
+ // Watch mode
92
93
  // Watch mode
93
94
  if (args['--watch']) {
94
95
  console.log('\nšŸ‘€ Watch mode enabled\n');
95
96
  console.log('\nšŸ‘€ Watching for changes...\n');
96
-
97
+
97
98
  const changedFiles = new Set();
98
99
  let rebuildTimer = null;
99
- let isBuilding = false;
100
-
100
+ let isBuilding = false; // ← ADD THIS FLAG
101
+
101
102
  function scheduleRebuild() {
102
- if (rebuildTimer || isBuilding) return;
103
+ if (rebuildTimer || isBuilding) return; // ← Check if building
103
104
 
104
105
  rebuildTimer = setTimeout(() => {
105
106
  const files = Array.from(changedFiles);
106
107
  changedFiles.clear();
107
108
  rebuildTimer = null;
108
109
 
109
- isBuilding = true;
110
+ isBuilding = true; // ← Set flag
110
111
  try {
111
112
  build();
112
113
  } catch (error) {
113
114
  console.error('āŒ Build error:', error.message);
114
115
  } finally {
115
- isBuilding = false;
116
+ isBuilding = false; // ← Clear flag
116
117
  }
117
- }, 10);
118
+ }, 100); // ← Increase to 100ms
118
119
  }
119
-
120
+
120
121
  // Get directories to watch
121
122
  const watchDirs = new Set();
122
123
  const contentPatterns = Array.isArray(config.content) ? config.content : [config.content];
123
-
124
+
125
+ // Normalize output path for comparison
126
+ const normalizedOutput = path.normalize(config.output).toLowerCase();
127
+
124
128
  for (const pattern of contentPatterns) {
125
129
  const baseDir = pattern.split('**')[0].replace(/\*/g, '');
126
130
  const resolvedDir = path.resolve(projectRoot, baseDir || '.');
127
-
131
+
128
132
  if (fs.existsSync(resolvedDir)) {
129
133
  watchDirs.add(resolvedDir);
130
134
  }
131
135
  }
132
-
136
+
133
137
  // IMPORTANT: Watch the input CSS directory
134
138
  const inputDir = path.dirname(config.input);
135
139
  if (fs.existsSync(inputDir)) {
136
140
  watchDirs.add(inputDir);
137
141
  }
138
-
142
+
143
+ console.log('šŸ‘ļø Watching directories:', Array.from(watchDirs));
144
+
139
145
  // Subscribe to file changes
140
146
  const subscriptions = [];
141
-
147
+
142
148
  for (const dir of watchDirs) {
143
149
  const subscription = await watcher.subscribe(dir, (err, events) => {
144
150
  if (err) {
145
151
  console.error('āŒ Watcher error:', err);
146
152
  return;
147
153
  }
148
-
154
+
149
155
  for (const event of events) {
150
156
  if (event.type === 'delete') continue;
151
157
 
152
158
  // Normalize paths for comparison
153
159
  const normalizedPath = path.normalize(event.path).toLowerCase();
154
-
160
+
155
161
  // CRITICAL: Ignore output file to prevent infinite loop
156
162
  if (normalizedPath === normalizedOutput) {
163
+ console.log('🚫 Ignoring output file change');
157
164
  continue;
158
165
  }
159
-
166
+
160
167
  // Also ignore the entire output directory
161
168
  if (normalizedPath.startsWith(path.dirname(normalizedOutput).toLowerCase())) {
162
169
  const isOutputDir = path.dirname(normalizedPath) === path.dirname(normalizedOutput).toLowerCase();
163
170
  if (isOutputDir) {
171
+ console.log('🚫 Ignoring output directory change');
164
172
  continue;
165
173
  }
166
174
  }
167
175
 
168
- // CRITICAL: Ignore output file to prevent infinite loop
169
- if (path.resolve(event.path) === path.resolve(config.output)) {
170
- continue;
171
- }
172
-
173
176
  const ext = path.extname(event.path);
174
- const isInputFile = path.resolve(event.path) === path.resolve(config.input);
175
-
177
+ const isInputFile = path.normalize(event.path).toLowerCase() === path.normalize(config.input).toLowerCase();
178
+
176
179
  // Watch input CSS and content files
177
180
  if (isInputFile || ['.html', '.jsx', '.js', '.ts', '.tsx', '.vue', '.css'].includes(ext)) {
178
181
  changedFiles.add(event.path);
179
182
  console.log('šŸ“ Changed:', path.relative(projectRoot, event.path));
180
183
  }
181
184
  }
182
-
185
+
183
186
  if (changedFiles.size > 0) {
184
187
  scheduleRebuild();
185
188
  }
186
189
  });
187
-
190
+
188
191
  subscriptions.push(subscription);
189
192
  }
190
-
193
+
191
194
  // Cleanup on exit
192
195
  process.on('SIGINT', async () => {
193
196
  console.log('\n\nšŸ‘‹ Shutting down...');
194
-
197
+
195
198
  for (const sub of subscriptions) {
196
199
  await sub.unsubscribe();
197
200
  }
198
-
201
+
199
202
  process.exit(0);
200
203
  });
201
-
204
+
202
205
  process.stdin.resume();
203
206
  }
204
207
  })();