@lowdefy/node-utils 0.0.0-experimental-20260720072521 → 0.0.0-experimental-20260720135014
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
|
@@ -14,13 +14,9 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import cleanDirectory from './cleanDirectory.js';
|
|
16
16
|
import copyFileOrDirectory from './copyFileOrDirectory.js';
|
|
17
|
-
import findAvailablePort from './findAvailablePort.js';
|
|
18
17
|
import getFileExtension, { getFileSubExtension } from './getFileExtension.js';
|
|
19
18
|
import getSecretsFromEnv from './getSecretsFromEnv.js';
|
|
20
|
-
import installIfPackageJsonChanged from './installIfPackageJsonChanged.js';
|
|
21
|
-
import isPortAvailable from './isPortAvailable.js';
|
|
22
19
|
import spawnProcess from './spawnProcess.js';
|
|
23
20
|
import readFile from './readFile.js';
|
|
24
21
|
import writeFile from './writeFile.js';
|
|
25
|
-
|
|
26
|
-
export { cleanDirectory, copyFileOrDirectory, findAvailablePort, getFileExtension, getFileSubExtension, getSecretsFromEnv, installIfPackageJsonChanged, isPortAvailable, spawnProcess, readFile, writeFile, writeFileIfChanged };
|
|
22
|
+
export { cleanDirectory, copyFileOrDirectory, getFileExtension, getFileSubExtension, getSecretsFromEnv, spawnProcess, readFile, writeFile };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/node-utils",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-20260720135014",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"dist/*"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@lowdefy/errors": "0.0.0-experimental-
|
|
38
|
-
"@lowdefy/helpers": "0.0.0-experimental-
|
|
39
|
-
"fs-extra": "11.
|
|
37
|
+
"@lowdefy/errors": "0.0.0-experimental-20260720135014",
|
|
38
|
+
"@lowdefy/helpers": "0.0.0-experimental-20260720135014",
|
|
39
|
+
"fs-extra": "11.1.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@swc/cli": "0.8.
|
|
43
|
-
"@swc/core": "1.15.
|
|
42
|
+
"@swc/cli": "0.8.0",
|
|
43
|
+
"@swc/core": "1.15.18",
|
|
44
44
|
"@swc/jest": "0.2.39",
|
|
45
45
|
"copyfiles": "2.4.1",
|
|
46
46
|
"jest": "28.1.3"
|
|
@@ -1,27 +0,0 @@
|
|
|
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 isPortAvailable from './isPortAvailable.js';
|
|
16
|
-
async function findAvailablePort({ port, maxAttempts = 100 }) {
|
|
17
|
-
const startPort = Number(port);
|
|
18
|
-
for(let candidate = startPort; candidate < startPort + maxAttempts; candidate += 1){
|
|
19
|
-
if (await isPortAvailable({
|
|
20
|
-
port: candidate
|
|
21
|
-
})) {
|
|
22
|
-
return candidate;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
throw new Error(`[Server Error] No available port found in range ${startPort}-${startPort + maxAttempts - 1}.`);
|
|
26
|
-
}
|
|
27
|
-
export default findAvailablePort;
|
|
@@ -1,43 +0,0 @@
|
|
|
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;
|
package/dist/isPortAvailable.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
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 net from 'net';
|
|
16
|
-
// libuv sets SO_REUSEADDR on listening sockets, so on macOS a wildcard bind
|
|
17
|
-
// succeeds while another process holds a specific loopback address (and vice
|
|
18
|
-
// versa) — only an exact address match fails with EADDRINUSE. A single
|
|
19
|
-
// anonymous bind therefore reports ports busy on 127.0.0.1 (how Vite binds
|
|
20
|
-
// `localhost`) as available. Probe the wildcard and both loopback addresses
|
|
21
|
-
// so each common binding pattern is detected by its exact match.
|
|
22
|
-
const HOSTS = [
|
|
23
|
-
undefined,
|
|
24
|
-
'127.0.0.1',
|
|
25
|
-
'::1'
|
|
26
|
-
];
|
|
27
|
-
function checkHost({ port, host }) {
|
|
28
|
-
return new Promise((resolve, reject)=>{
|
|
29
|
-
const server = net.createServer();
|
|
30
|
-
server.on('error', (error)=>{
|
|
31
|
-
if (error.code === 'EADDRINUSE') {
|
|
32
|
-
resolve(false);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
// Host has no IPv6 loopback — nothing can occupy that address.
|
|
36
|
-
if ([
|
|
37
|
-
'EADDRNOTAVAIL',
|
|
38
|
-
'EAFNOSUPPORT',
|
|
39
|
-
'EINVAL'
|
|
40
|
-
].includes(error.code)) {
|
|
41
|
-
resolve(true);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
reject(error);
|
|
45
|
-
});
|
|
46
|
-
server.listen(port, host, ()=>{
|
|
47
|
-
server.close(()=>resolve(true));
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
async function isPortAvailable({ port }) {
|
|
52
|
-
for (const host of HOSTS){
|
|
53
|
-
if (!await checkHost({
|
|
54
|
-
port,
|
|
55
|
-
host
|
|
56
|
-
})) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
export default isPortAvailable;
|
|
@@ -1,27 +0,0 @@
|
|
|
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;
|