@pikku/cli 0.9.11 → 0.9.12

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @pikku/cli
2
2
 
3
+ ## 0.9.12
4
+
5
+ ### Patch Changes
6
+
7
+ - eb8ed09: feat: only write files if the content changed / file doesn't exist, this stops triggering restarts for development
8
+
3
9
  ## 0.9.11
4
10
 
5
11
  ### Patch Changes
package/dist/src/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { relative, dirname, resolve } from 'path';
2
- import { mkdir, writeFile } from 'fs/promises';
2
+ import { mkdir, readFile, writeFile } from 'fs/promises';
3
3
  import chalk from 'chalk';
4
4
  import { fileURLToPath } from 'url';
5
5
  import { readFileSync } from 'fs';
@@ -165,10 +165,21 @@ export const writeFileInDir = async (logger, path, content, { ignoreModifyCommen
165
165
  else {
166
166
  content = `${ignoreModifyComment ? '' : DO_NOT_MODIFY_COMMENT}${content}`;
167
167
  }
168
- await mkdir(dirname(path), { recursive: true });
169
- await writeFile(path, content, 'utf-8');
170
- if (logWrite) {
171
- logger.success(`✓ File written to ${path}`);
168
+ // Try to read existing file content
169
+ let existingContent;
170
+ try {
171
+ existingContent = await readFile(path, 'utf-8');
172
+ }
173
+ catch (error) {
174
+ // File doesn't exist, so we need to write it
175
+ }
176
+ // Only write if content has changed or file doesn't exist
177
+ if (existingContent !== content) {
178
+ await mkdir(dirname(path), { recursive: true });
179
+ await writeFile(path, content, 'utf-8');
180
+ if (logWrite) {
181
+ logger.success(`✓ File written to ${path}`);
182
+ }
172
183
  }
173
184
  };
174
185
  export const logCommandInfoAndTime = async (logger, commandStart, commandEnd, [skipCondition, skipMessage = 'none found'], callback) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/cli",
3
- "version": "0.9.11",
3
+ "version": "0.9.12",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "bin": {
package/src/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { relative, dirname, resolve } from 'path'
2
2
  import { PathToNameAndType, InspectorState, TypesMap } from '@pikku/inspector'
3
- import { mkdir, writeFile } from 'fs/promises'
3
+ import { mkdir, readFile, writeFile } from 'fs/promises'
4
4
  import chalk from 'chalk'
5
5
  import { fileURLToPath } from 'url'
6
6
  import { readFileSync } from 'fs'
@@ -301,11 +301,22 @@ export const writeFileInDir = async (
301
301
  content = `${ignoreModifyComment ? '' : DO_NOT_MODIFY_COMMENT}${content}`
302
302
  }
303
303
 
304
- await mkdir(dirname(path), { recursive: true })
305
- await writeFile(path, content, 'utf-8')
304
+ // Try to read existing file content
305
+ let existingContent: string | undefined
306
+ try {
307
+ existingContent = await readFile(path, 'utf-8')
308
+ } catch (error) {
309
+ // File doesn't exist, so we need to write it
310
+ }
311
+
312
+ // Only write if content has changed or file doesn't exist
313
+ if (existingContent !== content) {
314
+ await mkdir(dirname(path), { recursive: true })
315
+ await writeFile(path, content, 'utf-8')
306
316
 
307
- if (logWrite) {
308
- logger.success(`✓ File written to ${path}`)
317
+ if (logWrite) {
318
+ logger.success(`✓ File written to ${path}`)
319
+ }
309
320
  }
310
321
  }
311
322