@vocab/core 1.0.2 → 1.0.3

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
  # @vocab/core
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`78e874f`](https://github.com/seek-oss/vocab/commit/78e874f720ca34d771072c09fe55b57ff3158e02) [#71](https://github.com/seek-oss/vocab/pull/71) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Only write compiled runtime files to disk if they have been changed
8
+
3
9
  ## 1.0.2
4
10
 
5
11
  ### Patch Changes
@@ -508,7 +508,7 @@ async function generateRuntime(loadedTranslation) {
508
508
  });
509
509
  const outputFilePath = getTSFileFromDevLanguageFile(filePath);
510
510
  trace(`Writing translation types to ${outputFilePath}`);
511
- await fs.promises.writeFile(outputFilePath, declaration);
511
+ await writeIfChanged(outputFilePath, declaration);
512
512
  }
513
513
  function watch(config) {
514
514
  const cwd = config.projectRoot || process.cwd();
@@ -584,6 +584,24 @@ async function compile({
584
584
  }
585
585
  }
586
586
 
587
+ async function writeIfChanged(filepath, contents) {
588
+ let hasChanged = true;
589
+
590
+ try {
591
+ const existingContents = await fs.promises.readFile(filepath, {
592
+ encoding: 'utf-8'
593
+ });
594
+ hasChanged = existingContents !== contents;
595
+ } catch (e) {// ignore error, likely a file doesn't exist error so we want to write anyway
596
+ }
597
+
598
+ if (hasChanged) {
599
+ await fs.promises.writeFile(filepath, contents, {
600
+ encoding: 'utf-8'
601
+ });
602
+ }
603
+ }
604
+
587
605
  /* eslint-disable no-console */
588
606
  function findMissingKeys(loadedTranslation, devLanguageName, altLangauges) {
589
607
  const devLanguage = loadedTranslation.languages[devLanguageName];
@@ -508,7 +508,7 @@ async function generateRuntime(loadedTranslation) {
508
508
  });
509
509
  const outputFilePath = getTSFileFromDevLanguageFile(filePath);
510
510
  trace(`Writing translation types to ${outputFilePath}`);
511
- await fs.promises.writeFile(outputFilePath, declaration);
511
+ await writeIfChanged(outputFilePath, declaration);
512
512
  }
513
513
  function watch(config) {
514
514
  const cwd = config.projectRoot || process.cwd();
@@ -584,6 +584,24 @@ async function compile({
584
584
  }
585
585
  }
586
586
 
587
+ async function writeIfChanged(filepath, contents) {
588
+ let hasChanged = true;
589
+
590
+ try {
591
+ const existingContents = await fs.promises.readFile(filepath, {
592
+ encoding: 'utf-8'
593
+ });
594
+ hasChanged = existingContents !== contents;
595
+ } catch (e) {// ignore error, likely a file doesn't exist error so we want to write anyway
596
+ }
597
+
598
+ if (hasChanged) {
599
+ await fs.promises.writeFile(filepath, contents, {
600
+ encoding: 'utf-8'
601
+ });
602
+ }
603
+ }
604
+
587
605
  /* eslint-disable no-console */
588
606
  function findMissingKeys(loadedTranslation, devLanguageName, altLangauges) {
589
607
  const devLanguage = loadedTranslation.languages[devLanguageName];
@@ -1,4 +1,4 @@
1
- import { promises, existsSync } from 'fs';
1
+ import { existsSync, promises } from 'fs';
2
2
  import path from 'path';
3
3
  import { parse, isSelectElement, isTagElement, isArgumentElement, isNumberElement, isPluralElement, isDateElement, isTimeElement } from '@formatjs/icu-messageformat-parser';
4
4
  import prettier from 'prettier';
@@ -493,7 +493,7 @@ async function generateRuntime(loadedTranslation) {
493
493
  });
494
494
  const outputFilePath = getTSFileFromDevLanguageFile(filePath);
495
495
  trace(`Writing translation types to ${outputFilePath}`);
496
- await promises.writeFile(outputFilePath, declaration);
496
+ await writeIfChanged(outputFilePath, declaration);
497
497
  }
498
498
  function watch(config) {
499
499
  const cwd = config.projectRoot || process.cwd();
@@ -569,6 +569,24 @@ async function compile({
569
569
  }
570
570
  }
571
571
 
572
+ async function writeIfChanged(filepath, contents) {
573
+ let hasChanged = true;
574
+
575
+ try {
576
+ const existingContents = await promises.readFile(filepath, {
577
+ encoding: 'utf-8'
578
+ });
579
+ hasChanged = existingContents !== contents;
580
+ } catch (e) {// ignore error, likely a file doesn't exist error so we want to write anyway
581
+ }
582
+
583
+ if (hasChanged) {
584
+ await promises.writeFile(filepath, contents, {
585
+ encoding: 'utf-8'
586
+ });
587
+ }
588
+ }
589
+
572
590
  /* eslint-disable no-console */
573
591
  function findMissingKeys(loadedTranslation, devLanguageName, altLangauges) {
574
592
  const devLanguage = loadedTranslation.languages[devLanguageName];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocab/core",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "main": "dist/vocab-core.cjs.js",
5
5
  "module": "dist/vocab-core.esm.js",
6
6
  "author": "SEEK",
package/src/compile.ts CHANGED
@@ -219,7 +219,7 @@ export async function generateRuntime(loadedTranslation: LoadedTranslation) {
219
219
  });
220
220
  const outputFilePath = getTSFileFromDevLanguageFile(filePath);
221
221
  trace(`Writing translation types to ${outputFilePath}`);
222
- await fs.writeFile(outputFilePath, declaration);
222
+ await writeIfChanged(outputFilePath, declaration);
223
223
  }
224
224
 
225
225
  export function watch(config: UserConfig) {
@@ -311,3 +311,19 @@ export async function compile(
311
311
  return watch(config);
312
312
  }
313
313
  }
314
+
315
+ async function writeIfChanged(filepath: string, contents: string) {
316
+ let hasChanged = true;
317
+
318
+ try {
319
+ const existingContents = await fs.readFile(filepath, { encoding: 'utf-8' });
320
+
321
+ hasChanged = existingContents !== contents;
322
+ } catch (e) {
323
+ // ignore error, likely a file doesn't exist error so we want to write anyway
324
+ }
325
+
326
+ if (hasChanged) {
327
+ await fs.writeFile(filepath, contents, { encoding: 'utf-8' });
328
+ }
329
+ }