@lowdefy/node-utils 0.0.0-experimental-20260610091556 → 0.0.0-experimental-20260611102401

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/dist/index.js CHANGED
@@ -16,7 +16,9 @@
16
16
  import copyFileOrDirectory from './copyFileOrDirectory.js';
17
17
  import getFileExtension, { getFileSubExtension } from './getFileExtension.js';
18
18
  import getSecretsFromEnv from './getSecretsFromEnv.js';
19
+ import installIfPackageJsonChanged from './installIfPackageJsonChanged.js';
19
20
  import spawnProcess from './spawnProcess.js';
20
21
  import readFile from './readFile.js';
21
22
  import writeFile from './writeFile.js';
22
- export { cleanDirectory, copyFileOrDirectory, getFileExtension, getFileSubExtension, getSecretsFromEnv, spawnProcess, readFile, writeFile };
23
+ import writeFileIfChanged from './writeFileIfChanged.js';
24
+ export { cleanDirectory, copyFileOrDirectory, getFileExtension, getFileSubExtension, getSecretsFromEnv, installIfPackageJsonChanged, spawnProcess, readFile, writeFile, writeFileIfChanged };
@@ -0,0 +1,43 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import crypto from 'crypto';
16
+ import path from 'path';
17
+ import { type } from '@lowdefy/helpers';
18
+ import readFile from './readFile.js';
19
+ import writeFile from './writeFile.js';
20
+ async function installIfPackageJsonChanged({ directory, install }) {
21
+ if (!type.isString(directory)) {
22
+ throw new Error(`installIfPackageJsonChanged requires a directory string. Received ${JSON.stringify(directory)}.`);
23
+ }
24
+ if (!type.isFunction(install)) {
25
+ throw new Error('installIfPackageJsonChanged requires an install function.');
26
+ }
27
+ const packageJsonContent = await readFile(path.join(directory, 'package.json'));
28
+ if (packageJsonContent === null) {
29
+ throw new Error(`Could not read package.json in ${directory}.`);
30
+ }
31
+ const hash = crypto.createHash('sha1').update(packageJsonContent).digest('base64');
32
+ // Stored inside node_modules so deleting node_modules also clears the hash,
33
+ // forcing the next run to install.
34
+ const hashPath = path.join(directory, 'node_modules', '.lowdefy-install-hash');
35
+ const previousHash = await readFile(hashPath);
36
+ if (previousHash === hash) {
37
+ return false;
38
+ }
39
+ await install();
40
+ await writeFile(hashPath, hash);
41
+ return true;
42
+ }
43
+ export default installIfPackageJsonChanged;
@@ -0,0 +1,27 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import readFile from './readFile.js';
16
+ import writeFile from './writeFile.js';
17
+ // Skipping byte-identical writes keeps file mtimes stable so watchers (Vite
18
+ // module graph, chokidar) do not react to rebuilds that changed nothing.
19
+ async function writeFileIfChanged(filePath, content) {
20
+ const existing = await readFile(filePath);
21
+ if (existing === content) {
22
+ return false;
23
+ }
24
+ await writeFile(filePath, content);
25
+ return true;
26
+ }
27
+ export default writeFileIfChanged;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/node-utils",
3
- "version": "0.0.0-experimental-20260610091556",
3
+ "version": "0.0.0-experimental-20260611102401",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -34,8 +34,8 @@
34
34
  "dist/*"
35
35
  ],
36
36
  "dependencies": {
37
- "@lowdefy/errors": "0.0.0-experimental-20260610091556",
38
- "@lowdefy/helpers": "0.0.0-experimental-20260610091556",
37
+ "@lowdefy/errors": "0.0.0-experimental-20260611102401",
38
+ "@lowdefy/helpers": "0.0.0-experimental-20260611102401",
39
39
  "fs-extra": "11.1.1"
40
40
  },
41
41
  "devDependencies": {