@workflow/utils 4.0.1-beta.10
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/LICENSE.md +201 -0
- package/README.md +3 -0
- package/dist/check-data-dir.d.ts +36 -0
- package/dist/check-data-dir.d.ts.map +1 -0
- package/dist/check-data-dir.js +153 -0
- package/dist/check-data-dir.js.map +1 -0
- package/dist/get-port.d.ts +24 -0
- package/dist/get-port.d.ts.map +1 -0
- package/dist/get-port.js +280 -0
- package/dist/get-port.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/pluralize.d.ts +15 -0
- package/dist/pluralize.d.ts.map +1 -0
- package/dist/pluralize.js +17 -0
- package/dist/pluralize.js.map +1 -0
- package/dist/promise.d.ts +25 -0
- package/dist/promise.d.ts.map +1 -0
- package/dist/promise.js +35 -0
- package/dist/promise.js.map +1 -0
- package/dist/time.d.ts +15 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +39 -0
- package/dist/time.js.map +1 -0
- package/package.json +49 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
<http://www.apache.org/licenses/>
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Vercel Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Known paths where workflow data might be stored, relative to the project root.
|
|
3
|
+
*/
|
|
4
|
+
export declare const possibleWorkflowDataPaths: readonly [".next/workflow-data", ".workflow-data", "workflow-data"];
|
|
5
|
+
export interface WorkflowDataDirInfo {
|
|
6
|
+
/** Absolute path to the workflow data directory, if found. Absence indicates that the folder does not point to a project or folder within a valid local world. */
|
|
7
|
+
dataDir?: string;
|
|
8
|
+
/** Absolute path to the project root (parent of the workflow data folder) */
|
|
9
|
+
projectDir: string;
|
|
10
|
+
/** Short name for display: up to last two folder names of projectDir */
|
|
11
|
+
shortName: string;
|
|
12
|
+
/** Error message if the given path couldn't be accessed (doesn't exist or is not readable) */
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Extracts up to the last two folder names from a path for a short display name.
|
|
17
|
+
*
|
|
18
|
+
* Examples:
|
|
19
|
+
* - `/Users/peter/code/myproject` → `code/myproject`
|
|
20
|
+
* - `/myproject` → `myproject`
|
|
21
|
+
* - `/` → `/`
|
|
22
|
+
*/
|
|
23
|
+
export declare function getDirShortName(projectDir: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Finds the workflow data directory starting from the given path.
|
|
26
|
+
*
|
|
27
|
+
* This function handles several cases:
|
|
28
|
+
* 1. The path itself is a workflow data directory
|
|
29
|
+
* 2. The path contains one of the known workflow data directories
|
|
30
|
+
* 3. The path is somewhere inside a project with workflow data
|
|
31
|
+
*
|
|
32
|
+
* @param cwd - The directory to start searching from (can be relative, absolute, or use ~)
|
|
33
|
+
* @returns Information about the found workflow data directory, or null if not found
|
|
34
|
+
*/
|
|
35
|
+
export declare function findWorkflowDataDir(cwd: string): Promise<WorkflowDataDirInfo>;
|
|
36
|
+
//# sourceMappingURL=check-data-dir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-data-dir.d.ts","sourceRoot":"","sources":["../src/check-data-dir.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,yBAAyB,qEAI5B,CAAC;AAEX,MAAM,WAAW,mBAAmB;IAClC,kKAAkK;IAClK,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6EAA6E;IAC7E,UAAU,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC;IAClB,8FAA8F;IAC9F,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAuBD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAS1D;AAuCD;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,mBAAmB,CAAC,CAkE9B"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { access } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
4
|
+
/**
|
|
5
|
+
* Known paths where workflow data might be stored, relative to the project root.
|
|
6
|
+
*/
|
|
7
|
+
export const possibleWorkflowDataPaths = [
|
|
8
|
+
'.next/workflow-data',
|
|
9
|
+
'.workflow-data',
|
|
10
|
+
'workflow-data',
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* Expands a path that starts with ~ to use the user's home directory.
|
|
14
|
+
*/
|
|
15
|
+
function expandTilde(path) {
|
|
16
|
+
if (path.startsWith('~')) {
|
|
17
|
+
return join(homedir(), path.slice(1));
|
|
18
|
+
}
|
|
19
|
+
return path;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Normalizes a path to an absolute path.
|
|
23
|
+
*/
|
|
24
|
+
function toAbsolutePath(path, basePath) {
|
|
25
|
+
const expanded = expandTilde(path);
|
|
26
|
+
if (isAbsolute(expanded)) {
|
|
27
|
+
return resolve(expanded);
|
|
28
|
+
}
|
|
29
|
+
return resolve(basePath || process.cwd(), expanded);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Extracts up to the last two folder names from a path for a short display name.
|
|
33
|
+
*
|
|
34
|
+
* Examples:
|
|
35
|
+
* - `/Users/peter/code/myproject` → `code/myproject`
|
|
36
|
+
* - `/myproject` → `myproject`
|
|
37
|
+
* - `/` → `/`
|
|
38
|
+
*/
|
|
39
|
+
export function getDirShortName(projectDir) {
|
|
40
|
+
const parts = projectDir.split(sep).filter(Boolean);
|
|
41
|
+
if (parts.length === 0) {
|
|
42
|
+
return '/';
|
|
43
|
+
}
|
|
44
|
+
if (parts.length === 1) {
|
|
45
|
+
return parts[0];
|
|
46
|
+
}
|
|
47
|
+
return parts.slice(-2).join('/');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Checks if a directory exists.
|
|
51
|
+
*/
|
|
52
|
+
async function directoryExists(path) {
|
|
53
|
+
try {
|
|
54
|
+
await access(path);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks if the given path is itself a workflow data directory
|
|
63
|
+
* (ends with one of the possibleWorkflowDataPaths).
|
|
64
|
+
*
|
|
65
|
+
* Returns the matching suffix and the projectDir if found.
|
|
66
|
+
*/
|
|
67
|
+
function checkIfPathIsWorkflowDataDir(absolutePath) {
|
|
68
|
+
for (const suffix of possibleWorkflowDataPaths) {
|
|
69
|
+
// Handle both forward slashes and the platform's separator
|
|
70
|
+
const normalizedSuffix = suffix.split('/').join(sep);
|
|
71
|
+
if (absolutePath.endsWith(normalizedSuffix)) {
|
|
72
|
+
// Calculate how many directories up we need to go
|
|
73
|
+
const suffixParts = suffix.split('/').length;
|
|
74
|
+
let projectDir = absolutePath;
|
|
75
|
+
for (let i = 0; i < suffixParts; i++) {
|
|
76
|
+
projectDir = dirname(projectDir);
|
|
77
|
+
}
|
|
78
|
+
return { suffix, projectDir };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Finds the workflow data directory starting from the given path.
|
|
85
|
+
*
|
|
86
|
+
* This function handles several cases:
|
|
87
|
+
* 1. The path itself is a workflow data directory
|
|
88
|
+
* 2. The path contains one of the known workflow data directories
|
|
89
|
+
* 3. The path is somewhere inside a project with workflow data
|
|
90
|
+
*
|
|
91
|
+
* @param cwd - The directory to start searching from (can be relative, absolute, or use ~)
|
|
92
|
+
* @returns Information about the found workflow data directory, or null if not found
|
|
93
|
+
*/
|
|
94
|
+
export async function findWorkflowDataDir(cwd) {
|
|
95
|
+
const absoluteCwd = toAbsolutePath(cwd);
|
|
96
|
+
// Pre-check if the passed path is valid at all
|
|
97
|
+
if (!(await directoryExists(absoluteCwd))) {
|
|
98
|
+
return {
|
|
99
|
+
projectDir: absoluteCwd,
|
|
100
|
+
dataDir: undefined,
|
|
101
|
+
shortName: getDirShortName(absoluteCwd),
|
|
102
|
+
error: 'Folder does not exist',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// Case 1: Check if the path itself is already a workflow data directory
|
|
106
|
+
const isDataDir = checkIfPathIsWorkflowDataDir(absoluteCwd);
|
|
107
|
+
if (isDataDir && (await directoryExists(absoluteCwd))) {
|
|
108
|
+
return {
|
|
109
|
+
projectDir: isDataDir.projectDir,
|
|
110
|
+
dataDir: absoluteCwd,
|
|
111
|
+
shortName: getDirShortName(isDataDir.projectDir),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// Case 2: Check if cwd contains one of the workflow data directories
|
|
115
|
+
for (const path of possibleWorkflowDataPaths) {
|
|
116
|
+
const fullPath = join(absoluteCwd, path);
|
|
117
|
+
if (await directoryExists(fullPath)) {
|
|
118
|
+
return {
|
|
119
|
+
projectDir: absoluteCwd,
|
|
120
|
+
dataDir: resolve(fullPath),
|
|
121
|
+
shortName: getDirShortName(absoluteCwd),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Case 3: Walk up the directory tree to find the project root
|
|
126
|
+
let currentDir = absoluteCwd;
|
|
127
|
+
const root = resolve('/');
|
|
128
|
+
while (currentDir !== root) {
|
|
129
|
+
// Check if any workflow data path exists here
|
|
130
|
+
for (const path of possibleWorkflowDataPaths) {
|
|
131
|
+
const fullPath = join(currentDir, path);
|
|
132
|
+
if (await directoryExists(fullPath)) {
|
|
133
|
+
return {
|
|
134
|
+
projectDir: currentDir,
|
|
135
|
+
dataDir: resolve(fullPath),
|
|
136
|
+
shortName: getDirShortName(currentDir),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const parentDir = dirname(currentDir);
|
|
141
|
+
if (parentDir === currentDir) {
|
|
142
|
+
break; // Reached the filesystem root
|
|
143
|
+
}
|
|
144
|
+
currentDir = parentDir;
|
|
145
|
+
}
|
|
146
|
+
// If we get here, we didn't find a workflow data directory
|
|
147
|
+
return {
|
|
148
|
+
projectDir: absoluteCwd,
|
|
149
|
+
dataDir: undefined,
|
|
150
|
+
shortName: getDirShortName(absoluteCwd),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=check-data-dir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-data-dir.js","sourceRoot":"","sources":["../src/check-data-dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEpE;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,qBAAqB;IACrB,gBAAgB;IAChB,eAAe;CACP,CAAC;AAaX;;GAEG;AACH,SAAS,WAAW,CAAC,IAAY;IAC/B,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CA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AQ,CAAC,EAAE,CAAC;YACpC,OAAO;gBACL,UAAU,EAAE,WAAW;gBACvB,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC;gBAC1B,SAAS,EAAE,eAAe,CAAC,WAAW,CAAC;aACxC,CAAC;QACJ,CAAC;IACH,CAAC;IAED,8DAA8D;IAC9D,IAAI,UAAU,GAAG,WAAW,CAAC;IAC7B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAE1B,OAAO,UAAU,KAAK,IAAI,EAAE,CAAC;QAC3B,8CAA8C;QAC9C,KAAK,MAAM,IAAI,IAAI,yBAAyB,EAAE,CAAC;YAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YACxC,IAAI,MAAM,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACpC,OAAO;oBACL,UAAU,EAAE,UAAU;oBACtB,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC;oBAC1B,SAAS,EAAE,eAAe,CAAC,UAAU,CAAC;iBACvC,CAAC;YACJ,CAAC;QACH,CAAC;QAED,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QACtC,IAAI,SAAS,KAAK,UAAU,EAAE,CAAC;YAC7B,MAAM,CAAC,8BAA8B;QACvC,CAAC;QACD,UAAU,GAAG,SAAS,CAAC;IACzB,CAAC;IAED,2DAA2D;IAE3D,OAAO;QACL,UAAU,EAAE,WAAW;QACvB,OAAO,EAAE,SAAS;QAClB,SAAS,EAAE,eAAe,CAAC,WAAW,CAAC;KACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets all listening ports for the current process.
|
|
3
|
+
* @returns Array of port numbers the process is listening on, in deterministic order.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getAllPorts(): Promise<number[]>;
|
|
6
|
+
/**
|
|
7
|
+
* Gets the port number that the process is listening on.
|
|
8
|
+
* @returns The port number that the process is listening on, or undefined if the process is not listening on any port.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getPort(): Promise<number | undefined>;
|
|
11
|
+
export interface ProbeOptions {
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
timeout?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Gets the workflow server port by probing all listening ports.
|
|
17
|
+
* This is more reliable than getPort() when other services (like Node.js inspector)
|
|
18
|
+
* may also be listening on ports.
|
|
19
|
+
*
|
|
20
|
+
* @param options - Optional configuration for probing
|
|
21
|
+
* @returns The port number of the workflow server, or undefined if not found
|
|
22
|
+
*/
|
|
23
|
+
export declare function getWorkflowPort(options?: ProbeOptions): Promise<number | undefined>;
|
|
24
|
+
//# sourceMappingURL=get-port.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-port.d.ts","sourceRoot":"","sources":["../src/get-port.ts"],"names":[],"mappings":"AA0MA;;;GAGG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAoBrD;AAED;;;GAGG;AACH,wBAAsB,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAG3D;AAMD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAiCD;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAqC7B"}
|
package/dist/get-port.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { readdir, readFile, readlink } from 'node:fs/promises';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { execFile } from 'node:child_process';
|
|
4
|
+
const execFileAsync = promisify(execFile);
|
|
5
|
+
/**
|
|
6
|
+
* Parses a port string and returns it if valid (0-65535), otherwise undefined.
|
|
7
|
+
*/
|
|
8
|
+
function parsePort(value, radix = 10) {
|
|
9
|
+
const port = parseInt(value, radix);
|
|
10
|
+
if (!Number.isNaN(port) && port >= 0 && port <= 65535) {
|
|
11
|
+
return port;
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
// NOTE: We build /proc paths dynamically to prevent @vercel/nft from tracing them.
|
|
16
|
+
// NFT's static analysis tries to bundle any file path literal it finds (e.g., '/proc/net/tcp').
|
|
17
|
+
// Since /proc is a virtual Linux filesystem, this causes build failures in @sveltejs/adapter-vercel.
|
|
18
|
+
const join = (arr, sep) => arr.join(sep);
|
|
19
|
+
const PROC_ROOT = join(['', 'proc'], '/');
|
|
20
|
+
/**
|
|
21
|
+
* Gets ALL listening ports for the current process on Linux by reading /proc filesystem.
|
|
22
|
+
* Returns ports in order of file descriptor (deterministic ordering).
|
|
23
|
+
*/
|
|
24
|
+
async function getLinuxPorts(pid) {
|
|
25
|
+
const listenState = '0A'; // TCP LISTEN state in /proc/net/tcp
|
|
26
|
+
const tcpFiles = [`${PROC_ROOT}/net/tcp`, `${PROC_ROOT}/net/tcp6`];
|
|
27
|
+
// Step 1: Get socket inodes from /proc/<pid>/fd/ in order
|
|
28
|
+
// We preserve order to maintain deterministic behavior
|
|
29
|
+
// Use both array (for order) and Set (for O(1) lookup)
|
|
30
|
+
const socketInodes = [];
|
|
31
|
+
const socketInodesSet = new Set();
|
|
32
|
+
const fdPath = `${PROC_ROOT}/${pid}/fd`;
|
|
33
|
+
try {
|
|
34
|
+
const fds = await readdir(fdPath);
|
|
35
|
+
// Sort FDs numerically to ensure deterministic order (FDs are always numeric strings)
|
|
36
|
+
const sortedFds = fds.sort((a, b) => {
|
|
37
|
+
const numA = Number.parseInt(a, 10);
|
|
38
|
+
const numB = Number.parseInt(b, 10);
|
|
39
|
+
return numA - numB;
|
|
40
|
+
});
|
|
41
|
+
const results = await Promise.allSettled(sortedFds.map(async (fd) => {
|
|
42
|
+
const link = await readlink(`${fdPath}/${fd}`);
|
|
43
|
+
// Socket links look like: socket:[12345]
|
|
44
|
+
const match = link.match(/^socket:\[(\d+)\]$/);
|
|
45
|
+
return match?.[1] ?? null;
|
|
46
|
+
}));
|
|
47
|
+
for (const result of results) {
|
|
48
|
+
if (result.status === 'fulfilled' && result.value) {
|
|
49
|
+
socketInodes.push(result.value);
|
|
50
|
+
socketInodesSet.add(result.value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// Process might not exist or no permission
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
if (socketInodes.length === 0) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
// Step 2: Read /proc/net/tcp and /proc/net/tcp6 to find listening sockets
|
|
62
|
+
// Format: sl local_address rem_address st ... inode
|
|
63
|
+
// local_address is hex IP:port, st=0A means LISTEN
|
|
64
|
+
const inodeToPort = new Map();
|
|
65
|
+
for (const tcpFile of tcpFiles) {
|
|
66
|
+
try {
|
|
67
|
+
const content = await readFile(tcpFile, 'utf8');
|
|
68
|
+
const lines = content.split('\n').slice(1); // Skip header
|
|
69
|
+
for (const line of lines) {
|
|
70
|
+
if (!line.trim())
|
|
71
|
+
continue; // Skip empty lines
|
|
72
|
+
const parts = line.trim().split(/\s+/);
|
|
73
|
+
if (parts.length < 10)
|
|
74
|
+
continue;
|
|
75
|
+
const localAddr = parts[1]; // e.g., "00000000:0BB8" (0.0.0.0:3000)
|
|
76
|
+
const state = parts[3]; // "0A" = LISTEN
|
|
77
|
+
const inode = parts[9];
|
|
78
|
+
if (!localAddr || state !== listenState || !inode)
|
|
79
|
+
continue;
|
|
80
|
+
if (!socketInodesSet.has(inode))
|
|
81
|
+
continue;
|
|
82
|
+
// Extract port from hex format (e.g., "0BB8" -> 3000)
|
|
83
|
+
const colonIndex = localAddr.indexOf(':');
|
|
84
|
+
if (colonIndex === -1)
|
|
85
|
+
continue;
|
|
86
|
+
const portHex = localAddr.slice(colonIndex + 1);
|
|
87
|
+
if (!portHex)
|
|
88
|
+
continue;
|
|
89
|
+
const port = parsePort(portHex, 16);
|
|
90
|
+
if (port !== undefined) {
|
|
91
|
+
inodeToPort.set(inode, port);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// File might not exist (e.g., no IPv6 support) - continue to next file
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Return all ports in socket inode order (deterministic)
|
|
101
|
+
const ports = [];
|
|
102
|
+
for (const inode of socketInodes) {
|
|
103
|
+
const port = inodeToPort.get(inode);
|
|
104
|
+
if (port !== undefined) {
|
|
105
|
+
ports.push(port);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return ports;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Gets ALL listening ports for the current process on macOS using lsof.
|
|
112
|
+
* Returns ports in the order they appear in lsof output.
|
|
113
|
+
*/
|
|
114
|
+
async function getDarwinPorts(pid) {
|
|
115
|
+
try {
|
|
116
|
+
const { stdout } = await execFileAsync('lsof', [
|
|
117
|
+
'-a',
|
|
118
|
+
'-i',
|
|
119
|
+
'-P',
|
|
120
|
+
'-n',
|
|
121
|
+
'-p',
|
|
122
|
+
pid.toString(),
|
|
123
|
+
]);
|
|
124
|
+
const ports = [];
|
|
125
|
+
const lines = stdout.split('\n');
|
|
126
|
+
for (const line of lines) {
|
|
127
|
+
if (line.includes('LISTEN')) {
|
|
128
|
+
// Column 9 (0-indexed: 8) contains the address like "*:3000" or "127.0.0.1:3000"
|
|
129
|
+
const parts = line.trim().split(/\s+/);
|
|
130
|
+
const addr = parts[8];
|
|
131
|
+
if (addr) {
|
|
132
|
+
const colonIndex = addr.lastIndexOf(':');
|
|
133
|
+
if (colonIndex !== -1) {
|
|
134
|
+
const port = parsePort(addr.slice(colonIndex + 1));
|
|
135
|
+
if (port !== undefined) {
|
|
136
|
+
ports.push(port);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return ports;
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Gets ALL listening ports for the current process on Windows using netstat.
|
|
150
|
+
* Returns ports in the order they appear in netstat output.
|
|
151
|
+
*/
|
|
152
|
+
async function getWindowsPorts(pid) {
|
|
153
|
+
try {
|
|
154
|
+
const { stdout } = await execFileAsync('cmd', [
|
|
155
|
+
'/c',
|
|
156
|
+
`netstat -ano | findstr ${pid} | findstr LISTENING`,
|
|
157
|
+
]);
|
|
158
|
+
const ports = [];
|
|
159
|
+
const trimmedOutput = stdout.trim();
|
|
160
|
+
if (trimmedOutput) {
|
|
161
|
+
const lines = trimmedOutput.split('\n');
|
|
162
|
+
for (const line of lines) {
|
|
163
|
+
// Extract port from the local address column
|
|
164
|
+
// Matches both IPv4 (e.g., "127.0.0.1:3000") and IPv6 bracket notation (e.g., "[::1]:3000")
|
|
165
|
+
const match = line
|
|
166
|
+
.trim()
|
|
167
|
+
.match(/^\s*TCP\s+(?:\[[\da-f:]+\]|[\d.]+):(\d+)\s+/i);
|
|
168
|
+
if (match) {
|
|
169
|
+
const port = parsePort(match[1]);
|
|
170
|
+
if (port !== undefined) {
|
|
171
|
+
ports.push(port);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return ports;
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Gets all listening ports for the current process.
|
|
184
|
+
* @returns Array of port numbers the process is listening on, in deterministic order.
|
|
185
|
+
*/
|
|
186
|
+
export async function getAllPorts() {
|
|
187
|
+
const { pid, platform } = process;
|
|
188
|
+
try {
|
|
189
|
+
switch (platform) {
|
|
190
|
+
case 'linux':
|
|
191
|
+
return await getLinuxPorts(pid);
|
|
192
|
+
case 'darwin':
|
|
193
|
+
return await getDarwinPorts(pid);
|
|
194
|
+
case 'win32':
|
|
195
|
+
return await getWindowsPorts(pid);
|
|
196
|
+
default:
|
|
197
|
+
return [];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
if (process.env.NODE_ENV === 'development') {
|
|
202
|
+
console.debug('[getAllPorts] Detection failed:', error);
|
|
203
|
+
}
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Gets the port number that the process is listening on.
|
|
209
|
+
* @returns The port number that the process is listening on, or undefined if the process is not listening on any port.
|
|
210
|
+
*/
|
|
211
|
+
export async function getPort() {
|
|
212
|
+
const ports = await getAllPorts();
|
|
213
|
+
return ports[0];
|
|
214
|
+
}
|
|
215
|
+
// Configuration for HTTP probing
|
|
216
|
+
const PROBE_TIMEOUT_MS = 500;
|
|
217
|
+
const PROBE_ENDPOINT = '/.well-known/workflow/v1/flow?__health';
|
|
218
|
+
/**
|
|
219
|
+
* Probes a port to check if it's serving the workflow HTTP server.
|
|
220
|
+
* Uses HEAD request to minimize overhead.
|
|
221
|
+
*
|
|
222
|
+
* @returns true if the port responds with a 200 status from the health check endpoint
|
|
223
|
+
*/
|
|
224
|
+
async function probePort(port, options = {}) {
|
|
225
|
+
const { endpoint = PROBE_ENDPOINT, timeout = PROBE_TIMEOUT_MS } = options;
|
|
226
|
+
const controller = new AbortController();
|
|
227
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
228
|
+
try {
|
|
229
|
+
const response = await fetch(`http://localhost:${port}${endpoint}`, {
|
|
230
|
+
method: 'HEAD',
|
|
231
|
+
signal: controller.signal,
|
|
232
|
+
});
|
|
233
|
+
// The workflow health endpoint returns 200 for healthy
|
|
234
|
+
return response.status === 200;
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
// Connection refused, timeout, or other error
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
finally {
|
|
241
|
+
clearTimeout(timeoutId);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Gets the workflow server port by probing all listening ports.
|
|
246
|
+
* This is more reliable than getPort() when other services (like Node.js inspector)
|
|
247
|
+
* may also be listening on ports.
|
|
248
|
+
*
|
|
249
|
+
* @param options - Optional configuration for probing
|
|
250
|
+
* @returns The port number of the workflow server, or undefined if not found
|
|
251
|
+
*/
|
|
252
|
+
export async function getWorkflowPort(options) {
|
|
253
|
+
const ports = await getAllPorts();
|
|
254
|
+
if (ports.length === 0) {
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
if (ports.length === 1) {
|
|
258
|
+
// Only one port, no need to probe
|
|
259
|
+
return ports[0];
|
|
260
|
+
}
|
|
261
|
+
// Probe all ports in parallel
|
|
262
|
+
const probeResults = await Promise.all(ports.map(async (port) => ({
|
|
263
|
+
port,
|
|
264
|
+
isWorkflow: await probePort(port, options),
|
|
265
|
+
})));
|
|
266
|
+
// Return first port that responded as workflow server
|
|
267
|
+
const workflowPort = probeResults.find((r) => r.isWorkflow);
|
|
268
|
+
if (workflowPort) {
|
|
269
|
+
return workflowPort.port;
|
|
270
|
+
}
|
|
271
|
+
// Fallback to first port if probing doesn't identify workflow server
|
|
272
|
+
// This handles cases where:
|
|
273
|
+
// - Server hasn't started workflow routes yet
|
|
274
|
+
// - Network issues during probing
|
|
275
|
+
if (process.env.NODE_ENV === 'development') {
|
|
276
|
+
console.debug('[getWorkflowPort] Probing failed, falling back to first port:', ports[0]);
|
|
277
|
+
}
|
|
278
|
+
return ports[0];
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=get-port.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-port.js","sourceRoot":"","sources":["../src/get-port.ts"],"names":[],"mappings":"AAAA,OAAO,EA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AAE,CAAC;QAC3C,OAAO,CAAC,KAAK,CACX,+DAA+D,EAC/D,KAAK,CAAC,CAAC,CAAC,CACT,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAA6B,aAAa,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the singular or plural form of a word based on count.
|
|
3
|
+
*
|
|
4
|
+
* @param singular - The singular form of the word
|
|
5
|
+
* @param plural - The plural form of the word
|
|
6
|
+
* @param count - The count to determine which form to use
|
|
7
|
+
* @returns The singular form if count is 1, otherwise the plural form
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* pluralize('step', 'steps', 1) // 'step'
|
|
11
|
+
* pluralize('step', 'steps', 3) // 'steps'
|
|
12
|
+
* pluralize('retry', 'retries', 0) // 'retries'
|
|
13
|
+
*/
|
|
14
|
+
export declare function pluralize(singular: string, plural: string, count: number): string;
|
|
15
|
+
//# sourceMappingURL=pluralize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluralize.d.ts","sourceRoot":"","sources":["../src/pluralize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,MAAM,CAER"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the singular or plural form of a word based on count.
|
|
3
|
+
*
|
|
4
|
+
* @param singular - The singular form of the word
|
|
5
|
+
* @param plural - The plural form of the word
|
|
6
|
+
* @param count - The count to determine which form to use
|
|
7
|
+
* @returns The singular form if count is 1, otherwise the plural form
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* pluralize('step', 'steps', 1) // 'step'
|
|
11
|
+
* pluralize('step', 'steps', 3) // 'steps'
|
|
12
|
+
* pluralize('retry', 'retries', 0) // 'retries'
|
|
13
|
+
*/
|
|
14
|
+
export function pluralize(singular, plural, count) {
|
|
15
|
+
return count === 1 ? singular : plural;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=pluralize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluralize.js","sourceRoot":"","sources":["../src/pluralize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS,CACvB,QAAgB,EAChB,MAAc,EACd,KAAa;IAEb,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface PromiseWithResolvers<T> {
|
|
2
|
+
promise: Promise<T>;
|
|
3
|
+
resolve: (value: T) => void;
|
|
4
|
+
reject: (reason?: any) => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Polyfill for `Promise.withResolvers()`.
|
|
8
|
+
*
|
|
9
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
|
|
10
|
+
*/
|
|
11
|
+
export declare function withResolvers<T>(): PromiseWithResolvers<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a lazily-evaluated, memoized version of the provided function.
|
|
14
|
+
*
|
|
15
|
+
* The returned object exposes a `value` getter that calls `fn` only once,
|
|
16
|
+
* caches its result, and returns the cached value on subsequent accesses.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam T - The return type of the provided function.
|
|
19
|
+
* @param fn - The function to be called once and whose result will be cached.
|
|
20
|
+
* @returns An object with a `value` property that returns the memoized result of `fn`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function once<T>(fn: () => T): {
|
|
23
|
+
readonly value: T;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=promise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../src/promise.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CAChC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,KAAK,oBAAoB,CAAC,CAAC,CAAC,CAQ1D;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC;;EASlC"}
|
package/dist/promise.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polyfill for `Promise.withResolvers()`.
|
|
3
|
+
*
|
|
4
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
|
|
5
|
+
*/
|
|
6
|
+
export function withResolvers() {
|
|
7
|
+
let resolve;
|
|
8
|
+
let reject;
|
|
9
|
+
const promise = new Promise((_resolve, _reject) => {
|
|
10
|
+
resolve = _resolve;
|
|
11
|
+
reject = _reject;
|
|
12
|
+
});
|
|
13
|
+
return { promise, resolve, reject };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a lazily-evaluated, memoized version of the provided function.
|
|
17
|
+
*
|
|
18
|
+
* The returned object exposes a `value` getter that calls `fn` only once,
|
|
19
|
+
* caches its result, and returns the cached value on subsequent accesses.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam T - The return type of the provided function.
|
|
22
|
+
* @param fn - The function to be called once and whose result will be cached.
|
|
23
|
+
* @returns An object with a `value` property that returns the memoized result of `fn`.
|
|
24
|
+
*/
|
|
25
|
+
export function once(fn) {
|
|
26
|
+
const result = {
|
|
27
|
+
get value() {
|
|
28
|
+
const value = fn();
|
|
29
|
+
Object.defineProperty(result, 'value', { value });
|
|
30
|
+
return value;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=promise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise.js","sourceRoot":"","sources":["../src/promise.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,IAAI,OAA4B,CAAC;IACjC,IAAI,MAA+B,CAAC;IACpC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE;QACnD,OAAO,GAAG,QAAQ,CAAC;QACnB,MAAM,GAAG,OAAO,CAAC;IACnB,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACtC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,IAAI,CAAI,EAAW;IACjC,MAAM,MAAM,GAAG;QACb,IAAI,KAAK;YACP,MAAM,KAAK,GAAG,EAAE,EAAE,CAAC;YACnB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YAClD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/time.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StringValue } from 'ms';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a duration parameter (string, number, or Date) and returns a Date object
|
|
4
|
+
* representing when the duration should elapse.
|
|
5
|
+
*
|
|
6
|
+
* - For strings: Parses duration strings like "1s", "5m", "1h", etc. using the `ms` library
|
|
7
|
+
* - For numbers: Treats as milliseconds from now
|
|
8
|
+
* - For Date objects: Returns the date directly (handles both Date instances and date-like objects from deserialization)
|
|
9
|
+
*
|
|
10
|
+
* @param param - The duration parameter (StringValue, Date, or number of milliseconds)
|
|
11
|
+
* @returns A Date object representing when the duration should elapse
|
|
12
|
+
* @throws {Error} If the parameter is invalid or cannot be parsed
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseDurationToDate(param: StringValue | Date | number): Date;
|
|
15
|
+
//# sourceMappingURL=time.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAGtC;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CA6B5E"}
|
package/dist/time.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import ms from 'ms';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a duration parameter (string, number, or Date) and returns a Date object
|
|
4
|
+
* representing when the duration should elapse.
|
|
5
|
+
*
|
|
6
|
+
* - For strings: Parses duration strings like "1s", "5m", "1h", etc. using the `ms` library
|
|
7
|
+
* - For numbers: Treats as milliseconds from now
|
|
8
|
+
* - For Date objects: Returns the date directly (handles both Date instances and date-like objects from deserialization)
|
|
9
|
+
*
|
|
10
|
+
* @param param - The duration parameter (StringValue, Date, or number of milliseconds)
|
|
11
|
+
* @returns A Date object representing when the duration should elapse
|
|
12
|
+
* @throws {Error} If the parameter is invalid or cannot be parsed
|
|
13
|
+
*/
|
|
14
|
+
export function parseDurationToDate(param) {
|
|
15
|
+
if (typeof param === 'string') {
|
|
16
|
+
const durationMs = ms(param);
|
|
17
|
+
if (typeof durationMs !== 'number' || durationMs < 0) {
|
|
18
|
+
throw new Error(`Invalid duration: "${param}". Expected a valid duration string like "1s", "1m", "1h", etc.`);
|
|
19
|
+
}
|
|
20
|
+
return new Date(Date.now() + durationMs);
|
|
21
|
+
}
|
|
22
|
+
else if (typeof param === 'number') {
|
|
23
|
+
if (param < 0 || !Number.isFinite(param)) {
|
|
24
|
+
throw new Error(`Invalid duration: ${param}. Expected a non-negative finite number of milliseconds.`);
|
|
25
|
+
}
|
|
26
|
+
return new Date(Date.now() + param);
|
|
27
|
+
}
|
|
28
|
+
else if (param instanceof Date ||
|
|
29
|
+
(param &&
|
|
30
|
+
typeof param === 'object' &&
|
|
31
|
+
typeof param.getTime === 'function')) {
|
|
32
|
+
// Handle both Date instances and date-like objects (from deserialization)
|
|
33
|
+
return param instanceof Date ? param : new Date(param.getTime());
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw new Error(`Invalid duration parameter. Expected a duration string, number (milliseconds), or Date object.`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=time.js.map
|
package/dist/time.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB;;;;;;;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
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/vercel/workflow.git",
|
|
17
|
+
"directory": "packages/utils"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./get-port": {
|
|
25
|
+
"types": "./dist/get-port.d.ts",
|
|
26
|
+
"default": "./dist/get-port.js"
|
|
27
|
+
},
|
|
28
|
+
"./check-data-dir": {
|
|
29
|
+
"types": "./dist/check-data-dir.d.ts",
|
|
30
|
+
"default": "./dist/check-data-dir.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/ms": "2.1.0",
|
|
35
|
+
"@types/node": "22.19.0",
|
|
36
|
+
"vitest": "^3.2.4",
|
|
37
|
+
"@workflow/tsconfig": "4.0.1-beta.0"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"ms": "2.1.3"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc",
|
|
44
|
+
"dev": "tsc --watch",
|
|
45
|
+
"clean": "tsc --build --clean && rm -rf dist",
|
|
46
|
+
"test": "vitest run src",
|
|
47
|
+
"typecheck": "tsc --noEmit"
|
|
48
|
+
}
|
|
49
|
+
}
|