envlock-core 0.5.0 → 0.6.0
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.d.ts +3 -1
- package/dist/index.js +20 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -41,4 +41,6 @@ declare const log: {
|
|
|
41
41
|
error: (msg: string) => void;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
declare function findFreePort(preferred: number): Promise<number>;
|
|
45
|
+
|
|
46
|
+
export { ENVIRONMENTS, type Environment, type EnvlockConfig, type EnvlockOptions, type RunWithSecretsOptions, checkBinary, findFreePort, hasBinary, log, runWithSecrets, setVerbose, validateEnvFilePath, validateOnePasswordEnvId };
|
package/dist/index.js
CHANGED
|
@@ -126,9 +126,29 @@ var ENVIRONMENTS = {
|
|
|
126
126
|
staging: "staging",
|
|
127
127
|
production: "production"
|
|
128
128
|
};
|
|
129
|
+
|
|
130
|
+
// src/find-port.ts
|
|
131
|
+
import { createServer } from "net";
|
|
132
|
+
function isPortFree(port) {
|
|
133
|
+
return new Promise((resolve2) => {
|
|
134
|
+
const server = createServer();
|
|
135
|
+
server.once("error", () => resolve2(false));
|
|
136
|
+
server.once("listening", () => server.close(() => resolve2(true)));
|
|
137
|
+
server.listen(port, "127.0.0.1");
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
async function findFreePort(preferred) {
|
|
141
|
+
for (let port = preferred; port <= preferred + 10; port++) {
|
|
142
|
+
if (await isPortFree(port)) return port;
|
|
143
|
+
}
|
|
144
|
+
throw new Error(
|
|
145
|
+
`[envlock] No free port found in range ${preferred}\u2013${preferred + 10}.`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
129
148
|
export {
|
|
130
149
|
ENVIRONMENTS,
|
|
131
150
|
checkBinary,
|
|
151
|
+
findFreePort,
|
|
132
152
|
hasBinary,
|
|
133
153
|
log,
|
|
134
154
|
runWithSecrets,
|