@dainprotocol/cli 1.2.26 → 1.2.30
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/__tests__/build.test.js +289 -0
- package/dist/__tests__/deploy.test.js +126 -0
- package/dist/__tests__/dev.test.js +321 -0
- package/dist/__tests__/init.test.js +290 -0
- package/dist/__tests__/integration.test.js +134 -0
- package/dist/__tests__/logs.test.js +135 -0
- package/dist/__tests__/testchat.test.js +214 -0
- package/dist/__tests__/utils.test.js +324 -0
- package/dist/commands/build.js +28 -61
- package/dist/commands/deploy.js +123 -162
- package/dist/commands/dev.js +118 -164
- package/dist/commands/init.js +2 -9
- package/dist/commands/logs.js +94 -88
- package/dist/commands/start.js +15 -4
- package/dist/commands/status.js +27 -31
- package/dist/commands/undeploy.js +29 -41
- package/dist/index.js +0 -7
- package/dist/templates/default/dain.json +1 -1
- package/dist/utils.js +112 -37
- package/package.json +12 -5
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var utils_1 = require("../utils");
|
|
7
|
+
var path_1 = __importDefault(require("path"));
|
|
8
|
+
describe('normalizeBaseUrl', function () {
|
|
9
|
+
describe('trailing slash handling', function () {
|
|
10
|
+
test('removes single trailing slash', function () {
|
|
11
|
+
expect((0, utils_1.normalizeBaseUrl)('https://example.com/')).toBe('https://example.com');
|
|
12
|
+
});
|
|
13
|
+
test('removes multiple trailing slashes', function () {
|
|
14
|
+
expect((0, utils_1.normalizeBaseUrl)('https://example.com///')).toBe('https://example.com');
|
|
15
|
+
});
|
|
16
|
+
test('handles URL without trailing slash', function () {
|
|
17
|
+
expect((0, utils_1.normalizeBaseUrl)('https://example.com')).toBe('https://example.com');
|
|
18
|
+
});
|
|
19
|
+
test('preserves path while removing trailing slash', function () {
|
|
20
|
+
expect((0, utils_1.normalizeBaseUrl)('https://example.com/api/v1/')).toBe('https://example.com/api/v1');
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe('protocol handling', function () {
|
|
24
|
+
test('handles https protocol', function () {
|
|
25
|
+
expect((0, utils_1.normalizeBaseUrl)('https://example.com')).toBe('https://example.com');
|
|
26
|
+
});
|
|
27
|
+
test('handles http protocol', function () {
|
|
28
|
+
expect((0, utils_1.normalizeBaseUrl)('http://example.com')).toBe('http://example.com');
|
|
29
|
+
});
|
|
30
|
+
test('handles wss protocol', function () {
|
|
31
|
+
expect((0, utils_1.normalizeBaseUrl)('wss://tunnel.example.com')).toBe('wss://tunnel.example.com');
|
|
32
|
+
});
|
|
33
|
+
test('handles ws protocol', function () {
|
|
34
|
+
expect((0, utils_1.normalizeBaseUrl)('ws://localhost:3000')).toBe('ws://localhost:3000');
|
|
35
|
+
});
|
|
36
|
+
test('fixes malformed triple-slash URLs', function () {
|
|
37
|
+
expect((0, utils_1.normalizeBaseUrl)('wss:///tunnel.dain-local.com')).toBe('wss://tunnel.dain-local.com');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe('edge cases', function () {
|
|
41
|
+
test('handles empty string', function () {
|
|
42
|
+
expect((0, utils_1.normalizeBaseUrl)('')).toBe('');
|
|
43
|
+
});
|
|
44
|
+
test('handles whitespace-only string', function () {
|
|
45
|
+
expect((0, utils_1.normalizeBaseUrl)(' ')).toBe('');
|
|
46
|
+
});
|
|
47
|
+
test('trims whitespace', function () {
|
|
48
|
+
expect((0, utils_1.normalizeBaseUrl)(' https://example.com ')).toBe('https://example.com');
|
|
49
|
+
});
|
|
50
|
+
test('handles localhost with port', function () {
|
|
51
|
+
expect((0, utils_1.normalizeBaseUrl)('http://localhost:3000/')).toBe('http://localhost:3000');
|
|
52
|
+
});
|
|
53
|
+
test('handles URL with query params', function () {
|
|
54
|
+
expect((0, utils_1.normalizeBaseUrl)('https://example.com/api?key=value/')).toBe('https://example.com/api?key=value');
|
|
55
|
+
});
|
|
56
|
+
test('handles invalid URL gracefully (no protocol)', function () {
|
|
57
|
+
// Falls back to string manipulation when URL parsing fails
|
|
58
|
+
expect((0, utils_1.normalizeBaseUrl)('example.com///')).toBe('example.com');
|
|
59
|
+
});
|
|
60
|
+
test('handles URL with auth credentials', function () {
|
|
61
|
+
expect((0, utils_1.normalizeBaseUrl)('https://user:pass@example.com/')).toBe('https://user:pass@example.com');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe('joinUrl', function () {
|
|
66
|
+
describe('slash normalization', function () {
|
|
67
|
+
test('joins base with trailing slash and path with leading slash', function () {
|
|
68
|
+
expect((0, utils_1.joinUrl)('https://example.com/', '/api/test')).toBe('https://example.com/api/test');
|
|
69
|
+
});
|
|
70
|
+
test('joins base without trailing slash and path with leading slash', function () {
|
|
71
|
+
expect((0, utils_1.joinUrl)('https://example.com', '/api/test')).toBe('https://example.com/api/test');
|
|
72
|
+
});
|
|
73
|
+
test('joins base with trailing slash and path without leading slash', function () {
|
|
74
|
+
expect((0, utils_1.joinUrl)('https://example.com/', 'api/test')).toBe('https://example.com/api/test');
|
|
75
|
+
});
|
|
76
|
+
test('joins base without trailing slash and path without leading slash', function () {
|
|
77
|
+
expect((0, utils_1.joinUrl)('https://example.com', 'api/test')).toBe('https://example.com/api/test');
|
|
78
|
+
});
|
|
79
|
+
test('handles multiple leading slashes in path', function () {
|
|
80
|
+
expect((0, utils_1.joinUrl)('https://example.com', '///api/test')).toBe('https://example.com/api/test');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('path handling', function () {
|
|
84
|
+
test('handles empty path', function () {
|
|
85
|
+
expect((0, utils_1.joinUrl)('https://example.com', '')).toBe('https://example.com/');
|
|
86
|
+
});
|
|
87
|
+
test('handles complex nested paths', function () {
|
|
88
|
+
expect((0, utils_1.joinUrl)('https://example.com/v1', '/users/123/profile')).toBe('https://example.com/v1/users/123/profile');
|
|
89
|
+
});
|
|
90
|
+
test('preserves query parameters in path', function () {
|
|
91
|
+
expect((0, utils_1.joinUrl)('https://example.com', '/api?foo=bar')).toBe('https://example.com/api?foo=bar');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe('parseEnvContent', function () {
|
|
96
|
+
describe('basic parsing', function () {
|
|
97
|
+
test('parses simple key=value pairs', function () {
|
|
98
|
+
var content = 'FOO=bar\nBAZ=qux';
|
|
99
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
100
|
+
expect(result).toEqual([
|
|
101
|
+
{ name: 'FOO', value: 'bar' },
|
|
102
|
+
{ name: 'BAZ', value: 'qux' },
|
|
103
|
+
]);
|
|
104
|
+
});
|
|
105
|
+
test('handles single variable', function () {
|
|
106
|
+
var result = (0, utils_1.parseEnvContent)('SINGLE=value');
|
|
107
|
+
expect(result).toEqual([{ name: 'SINGLE', value: 'value' }]);
|
|
108
|
+
});
|
|
109
|
+
test('handles empty content', function () {
|
|
110
|
+
expect((0, utils_1.parseEnvContent)('')).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('special values', function () {
|
|
114
|
+
test('preserves values with = signs (base64)', function () {
|
|
115
|
+
var content = 'JWT_SECRET=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.test==';
|
|
116
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
117
|
+
expect(result[0].value).toBe('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.test==');
|
|
118
|
+
});
|
|
119
|
+
test('preserves URLs with query params', function () {
|
|
120
|
+
var content = 'DATABASE_URL=postgresql://user:pass@host:5432/db?sslmode=require';
|
|
121
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
122
|
+
expect(result[0].value).toBe('postgresql://user:pass@host:5432/db?sslmode=require');
|
|
123
|
+
});
|
|
124
|
+
test('handles values with spaces', function () {
|
|
125
|
+
var content = 'MESSAGE=Hello World';
|
|
126
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
127
|
+
expect(result[0].value).toBe('Hello World');
|
|
128
|
+
});
|
|
129
|
+
test('handles quoted values', function () {
|
|
130
|
+
var content = 'QUOTED="hello world"';
|
|
131
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
132
|
+
expect(result[0].value).toBe('hello world');
|
|
133
|
+
});
|
|
134
|
+
test('handles single-quoted values', function () {
|
|
135
|
+
var content = "QUOTED='hello world'";
|
|
136
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
137
|
+
expect(result[0].value).toBe('hello world');
|
|
138
|
+
});
|
|
139
|
+
test('handles values with special characters (non-comment)', function () {
|
|
140
|
+
// Note: # starts a comment in dotenv, so use other special chars
|
|
141
|
+
var content = 'SPECIAL=!@$%^&*()';
|
|
142
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
143
|
+
expect(result[0].value).toBe('!@$%^&*()');
|
|
144
|
+
});
|
|
145
|
+
test('handles # in quoted values', function () {
|
|
146
|
+
// Quoted values preserve # character
|
|
147
|
+
var content = 'SPECIAL="!@#$%^&*()"';
|
|
148
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
149
|
+
expect(result[0].value).toBe('!@#$%^&*()');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
describe('comments and whitespace', function () {
|
|
153
|
+
test('ignores comment lines', function () {
|
|
154
|
+
var content = '# This is a comment\nFOO=bar\n# Another comment';
|
|
155
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
156
|
+
expect(result).toEqual([{ name: 'FOO', value: 'bar' }]);
|
|
157
|
+
});
|
|
158
|
+
test('ignores inline comments', function () {
|
|
159
|
+
var content = 'FOO=bar # this is a comment';
|
|
160
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
161
|
+
// Note: dotenv.parse treats everything after = as value
|
|
162
|
+
expect(result[0].name).toBe('FOO');
|
|
163
|
+
});
|
|
164
|
+
test('ignores empty lines', function () {
|
|
165
|
+
var content = 'FOO=bar\n\n\nBAZ=qux';
|
|
166
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
167
|
+
expect(result).toHaveLength(2);
|
|
168
|
+
});
|
|
169
|
+
test('handles Windows CRLF line endings', function () {
|
|
170
|
+
var content = 'FOO=bar\r\nBAZ=qux\r\n';
|
|
171
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
172
|
+
expect(result).toHaveLength(2);
|
|
173
|
+
expect(result[0].value).toBe('bar');
|
|
174
|
+
expect(result[1].value).toBe('qux');
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
describe('edge cases', function () {
|
|
178
|
+
test('filters out empty names', function () {
|
|
179
|
+
// This would be invalid env syntax, but we handle it gracefully
|
|
180
|
+
var content = 'VALID=value';
|
|
181
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
182
|
+
expect(result.every(function (e) { return e.name !== ''; })).toBe(true);
|
|
183
|
+
});
|
|
184
|
+
test('handles multiline values with quotes', function () {
|
|
185
|
+
var content = 'MULTI="line1\nline2"';
|
|
186
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
187
|
+
expect(result[0].value).toContain('line1');
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
describe('production scenarios', function () {
|
|
191
|
+
test('parses complex production env file', function () {
|
|
192
|
+
var _a, _b, _c;
|
|
193
|
+
var content = "# Production environment\nDATABASE_URL=postgresql://user:pass@host:5432/db?schema=public\nJWT_SECRET=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9==\nREDIS_URL=\"redis://localhost:6379\"\nAPI_KEY='sk_live_abc123=='\n\n# Feature flags\nENABLE_FEATURE=true";
|
|
194
|
+
var result = (0, utils_1.parseEnvContent)(content);
|
|
195
|
+
expect(result).toHaveLength(5);
|
|
196
|
+
expect((_a = result.find(function (e) { return e.name === 'DATABASE_URL'; })) === null || _a === void 0 ? void 0 : _a.value).toContain('postgresql://');
|
|
197
|
+
expect((_b = result.find(function (e) { return e.name === 'JWT_SECRET'; })) === null || _b === void 0 ? void 0 : _b.value).toContain('==');
|
|
198
|
+
expect((_c = result.find(function (e) { return e.name === 'REDIS_URL'; })) === null || _c === void 0 ? void 0 : _c.value).toBe('redis://localhost:6379');
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
describe('extractOrgId', function () {
|
|
203
|
+
describe('standard format: sk_agent_{agentId}_{orgId}_{secret}', function () {
|
|
204
|
+
test('extracts org ID from standard format', function () {
|
|
205
|
+
expect((0, utils_1.extractOrgId)('sk_agent_agent123_org456_secretkey')).toBe('org456');
|
|
206
|
+
});
|
|
207
|
+
test('handles org ID with numbers', function () {
|
|
208
|
+
expect((0, utils_1.extractOrgId)('sk_agent_a1_o2_s3')).toBe('o2');
|
|
209
|
+
});
|
|
210
|
+
test('handles long secret with underscores', function () {
|
|
211
|
+
expect((0, utils_1.extractOrgId)('sk_agent_myagent_myorg_secret_with_underscores')).toBe('myorg');
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
describe('org/agent format: sk_agent_org_{orgId}_agent_{agentId}_{secret}', function () {
|
|
215
|
+
test('extracts org ID from org/agent format', function () {
|
|
216
|
+
expect((0, utils_1.extractOrgId)('sk_agent_org_myorg_agent_myagent_secret')).toBe('myorg');
|
|
217
|
+
});
|
|
218
|
+
test('handles org ID with special characters', function () {
|
|
219
|
+
expect((0, utils_1.extractOrgId)('sk_agent_org_org-with-dash_agent_agent1_secret')).toBe('org-with-dash');
|
|
220
|
+
});
|
|
221
|
+
test('handles long secret in org/agent format', function () {
|
|
222
|
+
expect((0, utils_1.extractOrgId)('sk_agent_org_testorg_agent_testagent_long_secret_key')).toBe('testorg');
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
describe('invalid keys', function () {
|
|
226
|
+
test('returns empty string for undefined', function () {
|
|
227
|
+
expect((0, utils_1.extractOrgId)(undefined)).toBe('');
|
|
228
|
+
});
|
|
229
|
+
test('returns empty string for empty string', function () {
|
|
230
|
+
expect((0, utils_1.extractOrgId)('')).toBe('');
|
|
231
|
+
});
|
|
232
|
+
test('returns empty string for invalid prefix', function () {
|
|
233
|
+
expect((0, utils_1.extractOrgId)('invalid_agent_a_b_c')).toBe('');
|
|
234
|
+
});
|
|
235
|
+
test('returns empty string for too few parts', function () {
|
|
236
|
+
expect((0, utils_1.extractOrgId)('sk_agent_only_two')).toBe('');
|
|
237
|
+
});
|
|
238
|
+
test('returns empty string for malformed org format', function () {
|
|
239
|
+
expect((0, utils_1.extractOrgId)('sk_agent_org_myorg_notaagent_id_secret')).toBe('');
|
|
240
|
+
});
|
|
241
|
+
test('returns empty string when secret is missing', function () {
|
|
242
|
+
expect((0, utils_1.extractOrgId)('sk_agent_org_myorg_agent_myagent')).toBe('');
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
describe('resolveOrgId', function () {
|
|
247
|
+
var originalEnv = process.env.DAIN_ORG_ID;
|
|
248
|
+
afterEach(function () {
|
|
249
|
+
if (originalEnv !== undefined) {
|
|
250
|
+
process.env.DAIN_ORG_ID = originalEnv;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
delete process.env.DAIN_ORG_ID;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
test('prioritizes config org-id over everything', function () {
|
|
257
|
+
process.env.DAIN_ORG_ID = 'env-org';
|
|
258
|
+
var config = {
|
|
259
|
+
'main-file': 'src/index.ts',
|
|
260
|
+
'org-id': 'config-org',
|
|
261
|
+
'api-key': 'sk_agent_a_apiorg_s',
|
|
262
|
+
};
|
|
263
|
+
expect((0, utils_1.resolveOrgId)(config)).toBe('config-org');
|
|
264
|
+
});
|
|
265
|
+
test('falls back to env var when config org-id not set', function () {
|
|
266
|
+
process.env.DAIN_ORG_ID = 'env-org';
|
|
267
|
+
var config = {
|
|
268
|
+
'main-file': 'src/index.ts',
|
|
269
|
+
'api-key': 'sk_agent_a_apiorg_s',
|
|
270
|
+
};
|
|
271
|
+
expect((0, utils_1.resolveOrgId)(config)).toBe('env-org');
|
|
272
|
+
});
|
|
273
|
+
test('falls back to API key when env var not set', function () {
|
|
274
|
+
delete process.env.DAIN_ORG_ID;
|
|
275
|
+
var config = {
|
|
276
|
+
'main-file': 'src/index.ts',
|
|
277
|
+
'api-key': 'sk_agent_a_apiorg_s',
|
|
278
|
+
};
|
|
279
|
+
expect((0, utils_1.resolveOrgId)(config)).toBe('apiorg');
|
|
280
|
+
});
|
|
281
|
+
test('returns empty string when nothing available', function () {
|
|
282
|
+
delete process.env.DAIN_ORG_ID;
|
|
283
|
+
var config = {
|
|
284
|
+
'main-file': 'src/index.ts',
|
|
285
|
+
};
|
|
286
|
+
expect((0, utils_1.resolveOrgId)(config)).toBe('');
|
|
287
|
+
});
|
|
288
|
+
test('handles empty string org-id in config', function () {
|
|
289
|
+
process.env.DAIN_ORG_ID = 'env-org';
|
|
290
|
+
var config = {
|
|
291
|
+
'main-file': 'src/index.ts',
|
|
292
|
+
'org-id': '',
|
|
293
|
+
'api-key': 'sk_agent_a_apiorg_s',
|
|
294
|
+
};
|
|
295
|
+
// Empty string is falsy, so falls back to env
|
|
296
|
+
expect((0, utils_1.resolveOrgId)(config)).toBe('env-org');
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
describe('getStaticFilesPath', function () {
|
|
300
|
+
test('returns path to static directory in cwd', function () {
|
|
301
|
+
var result = (0, utils_1.getStaticFilesPath)();
|
|
302
|
+
expect(result).toBe(path_1.default.join(process.cwd(), 'static'));
|
|
303
|
+
});
|
|
304
|
+
test('is an absolute path', function () {
|
|
305
|
+
var result = (0, utils_1.getStaticFilesPath)();
|
|
306
|
+
expect(path_1.default.isAbsolute(result)).toBe(true);
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
describe('default constants', function () {
|
|
310
|
+
test('DEFAULT_TUNNEL_BASE_URL is valid WebSocket URL', function () {
|
|
311
|
+
expect(utils_1.DEFAULT_TUNNEL_BASE_URL).toMatch(/^wss?:\/\//);
|
|
312
|
+
});
|
|
313
|
+
test('DEFAULT_PLATFORM_BASE_URL is valid HTTPS URL', function () {
|
|
314
|
+
expect(utils_1.DEFAULT_PLATFORM_BASE_URL).toMatch(/^https:\/\//);
|
|
315
|
+
});
|
|
316
|
+
test('DEFAULT_API_BASE_URL is valid HTTPS URL', function () {
|
|
317
|
+
expect(utils_1.DEFAULT_API_BASE_URL).toMatch(/^https:\/\//);
|
|
318
|
+
});
|
|
319
|
+
test('default URLs do not have trailing slashes', function () {
|
|
320
|
+
expect(utils_1.DEFAULT_TUNNEL_BASE_URL.endsWith('/')).toBe(false);
|
|
321
|
+
expect(utils_1.DEFAULT_PLATFORM_BASE_URL.endsWith('/')).toBe(false);
|
|
322
|
+
expect(utils_1.DEFAULT_API_BASE_URL.endsWith('/')).toBe(false);
|
|
323
|
+
});
|
|
324
|
+
});
|
package/dist/commands/build.js
CHANGED
|
@@ -78,10 +78,6 @@ var utils_1 = require("../utils");
|
|
|
78
78
|
var ora_1 = __importDefault(require("ora"));
|
|
79
79
|
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
80
80
|
var path_1 = __importDefault(require("path"));
|
|
81
|
-
/**
|
|
82
|
-
* Finds all WASM files in node_modules that might be needed at runtime.
|
|
83
|
-
* These files are loaded via fs.readFileSync and can't be bundled by esbuild.
|
|
84
|
-
*/
|
|
85
81
|
function findWasmFiles(nodeModulesPath) {
|
|
86
82
|
return __awaiter(this, void 0, void 0, function () {
|
|
87
83
|
function scanDir(dir) {
|
|
@@ -90,39 +86,34 @@ function findWasmFiles(nodeModulesPath) {
|
|
|
90
86
|
return __generator(this, function (_b) {
|
|
91
87
|
switch (_b.label) {
|
|
92
88
|
case 0:
|
|
93
|
-
_b.trys.push([0,
|
|
89
|
+
_b.trys.push([0, 7, , 8]);
|
|
94
90
|
return [4 /*yield*/, fs_extra_1.default.readdir(dir, { withFileTypes: true })];
|
|
95
91
|
case 1:
|
|
96
92
|
entries = _b.sent();
|
|
97
93
|
_i = 0, entries_1 = entries;
|
|
98
94
|
_b.label = 2;
|
|
99
95
|
case 2:
|
|
100
|
-
if (!(_i < entries_1.length)) return [3 /*break*/,
|
|
96
|
+
if (!(_i < entries_1.length)) return [3 /*break*/, 6];
|
|
101
97
|
entry = entries_1[_i];
|
|
102
98
|
fullPath = path_1.default.join(dir, entry.name);
|
|
103
|
-
if (!entry.isDirectory()) return [3 /*break*/,
|
|
104
|
-
if (!(entry.name !== '.bin' && entry.name !== '.cache')) return [3 /*break*/, 4];
|
|
99
|
+
if (!(entry.isDirectory() && entry.name !== '.bin' && entry.name !== '.cache')) return [3 /*break*/, 4];
|
|
105
100
|
return [4 /*yield*/, scanDir(fullPath)];
|
|
106
101
|
case 3:
|
|
107
102
|
_b.sent();
|
|
108
|
-
|
|
109
|
-
case 4:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
// Only include WASM files in dist/nodejs directories (Node.js bindings)
|
|
113
|
-
if (fullPath.includes('/dist/') || fullPath.includes('/build/')) {
|
|
114
|
-
wasmFiles.push(fullPath);
|
|
115
|
-
}
|
|
103
|
+
return [3 /*break*/, 5];
|
|
104
|
+
case 4:
|
|
105
|
+
if (entry.name.endsWith('.wasm') && (fullPath.includes('/dist/') || fullPath.includes('/build/'))) {
|
|
106
|
+
wasmFiles.push(fullPath);
|
|
116
107
|
}
|
|
117
|
-
_b.label =
|
|
118
|
-
case
|
|
108
|
+
_b.label = 5;
|
|
109
|
+
case 5:
|
|
119
110
|
_i++;
|
|
120
111
|
return [3 /*break*/, 2];
|
|
121
|
-
case
|
|
122
|
-
case
|
|
112
|
+
case 6: return [3 /*break*/, 8];
|
|
113
|
+
case 7:
|
|
123
114
|
_a = _b.sent();
|
|
124
|
-
return [3 /*break*/,
|
|
125
|
-
case
|
|
115
|
+
return [3 /*break*/, 8];
|
|
116
|
+
case 8: return [2 /*return*/];
|
|
126
117
|
}
|
|
127
118
|
});
|
|
128
119
|
});
|
|
@@ -140,13 +131,9 @@ function findWasmFiles(nodeModulesPath) {
|
|
|
140
131
|
});
|
|
141
132
|
});
|
|
142
133
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Copies WASM files that are referenced in the bundle to the output directory.
|
|
145
|
-
* Scans the bundle for WASM filename references and copies matching files.
|
|
146
|
-
*/
|
|
147
134
|
function copyWasmDependencies(bundlePath, nodeModulesPath, outDir) {
|
|
148
135
|
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
-
var copiedFiles, bundleContent, wasmFiles, _i, wasmFiles_1, wasmPath, wasmName,
|
|
136
|
+
var copiedFiles, bundleContent, wasmFiles, _i, wasmFiles_1, wasmPath, wasmName, error_1;
|
|
150
137
|
return __generator(this, function (_a) {
|
|
151
138
|
switch (_a.label) {
|
|
152
139
|
case 0:
|
|
@@ -167,8 +154,7 @@ function copyWasmDependencies(bundlePath, nodeModulesPath, outDir) {
|
|
|
167
154
|
wasmPath = wasmFiles_1[_i];
|
|
168
155
|
wasmName = path_1.default.basename(wasmPath);
|
|
169
156
|
if (!bundleContent.includes(wasmName)) return [3 /*break*/, 6];
|
|
170
|
-
|
|
171
|
-
return [4 /*yield*/, fs_extra_1.default.copy(wasmPath, destPath)];
|
|
157
|
+
return [4 /*yield*/, fs_extra_1.default.copy(wasmPath, path_1.default.join(outDir, wasmName))];
|
|
172
158
|
case 5:
|
|
173
159
|
_a.sent();
|
|
174
160
|
copiedFiles.push(wasmName);
|
|
@@ -179,7 +165,6 @@ function copyWasmDependencies(bundlePath, nodeModulesPath, outDir) {
|
|
|
179
165
|
case 7: return [3 /*break*/, 9];
|
|
180
166
|
case 8:
|
|
181
167
|
error_1 = _a.sent();
|
|
182
|
-
// Non-fatal: continue without WASM files
|
|
183
168
|
console.warn('Warning: Could not process WASM dependencies:', error_1);
|
|
184
169
|
return [3 /*break*/, 9];
|
|
185
170
|
case 9: return [2 /*return*/, copiedFiles];
|
|
@@ -189,7 +174,7 @@ function copyWasmDependencies(bundlePath, nodeModulesPath, outDir) {
|
|
|
189
174
|
}
|
|
190
175
|
function build(options) {
|
|
191
176
|
return __awaiter(this, void 0, void 0, function () {
|
|
192
|
-
var spinner, config, runtime, outDir, dainDir, nodeModulesPath, buildOptions, context, targetDir, bundlePath, copiedWasm, staticDir,
|
|
177
|
+
var spinner, config, runtime, outDir, dainDir, nodeModulesPath, buildOptions, context, targetDir, bundlePath, copiedWasm, staticDir, error_2;
|
|
193
178
|
return __generator(this, function (_a) {
|
|
194
179
|
switch (_a.label) {
|
|
195
180
|
case 0:
|
|
@@ -201,11 +186,9 @@ function build(options) {
|
|
|
201
186
|
nodeModulesPath = path_1.default.join(process.cwd(), 'node_modules');
|
|
202
187
|
_a.label = 1;
|
|
203
188
|
case 1:
|
|
204
|
-
_a.trys.push([1,
|
|
205
|
-
// Ensure build directory exists
|
|
189
|
+
_a.trys.push([1, 14, , 15]);
|
|
206
190
|
return [4 /*yield*/, fs_extra_1.default.ensureDir(outDir)];
|
|
207
191
|
case 2:
|
|
208
|
-
// Ensure build directory exists
|
|
209
192
|
_a.sent();
|
|
210
193
|
buildOptions = {
|
|
211
194
|
entryPoints: [config['main-file']],
|
|
@@ -214,15 +197,9 @@ function build(options) {
|
|
|
214
197
|
outdir: outDir,
|
|
215
198
|
};
|
|
216
199
|
if (runtime === 'node') {
|
|
217
|
-
|
|
218
|
-
Object.assign(buildOptions, {
|
|
219
|
-
platform: 'node',
|
|
220
|
-
target: 'es2020',
|
|
221
|
-
minify: !options.watch,
|
|
222
|
-
});
|
|
200
|
+
Object.assign(buildOptions, { platform: 'node', target: 'es2020', minify: !options.watch });
|
|
223
201
|
}
|
|
224
202
|
else if (runtime === 'workers') {
|
|
225
|
-
// Cloudflare Workers build process
|
|
226
203
|
Object.assign(buildOptions, {
|
|
227
204
|
format: 'esm',
|
|
228
205
|
target: 'esnext',
|
|
@@ -234,10 +211,8 @@ function build(options) {
|
|
|
234
211
|
throw new Error("Unsupported runtime: ".concat(runtime));
|
|
235
212
|
}
|
|
236
213
|
if (!options.watch) return [3 /*break*/, 6];
|
|
237
|
-
// Ensure .dain directory exists for watch mode
|
|
238
214
|
return [4 /*yield*/, fs_extra_1.default.ensureDir(dainDir)];
|
|
239
215
|
case 3:
|
|
240
|
-
// Ensure .dain directory exists for watch mode
|
|
241
216
|
_a.sent();
|
|
242
217
|
return [4 /*yield*/, esbuild.context(buildOptions)];
|
|
243
218
|
case 4:
|
|
@@ -261,39 +236,31 @@ function build(options) {
|
|
|
261
236
|
return [4 /*yield*/, copyWasmDependencies(bundlePath, nodeModulesPath, targetDir)];
|
|
262
237
|
case 10:
|
|
263
238
|
copiedWasm = _a.sent();
|
|
264
|
-
if (copiedWasm.length > 0)
|
|
239
|
+
if (copiedWasm.length > 0)
|
|
265
240
|
spinner.info("WASM files copied: ".concat(copiedWasm.join(', ')));
|
|
266
|
-
}
|
|
267
241
|
_a.label = 11;
|
|
268
242
|
case 11:
|
|
269
243
|
staticDir = config['static-dir']
|
|
270
244
|
? path_1.default.join(process.cwd(), config['static-dir'])
|
|
271
245
|
: path_1.default.join(process.cwd(), 'static');
|
|
272
246
|
if (!fs_extra_1.default.existsSync(staticDir)) return [3 /*break*/, 13];
|
|
273
|
-
|
|
274
|
-
return [4 /*yield*/, fs_extra_1.default.copy(staticDir, staticOutDir)];
|
|
247
|
+
return [4 /*yield*/, fs_extra_1.default.copy(staticDir, path_1.default.join(targetDir, 'static'))];
|
|
275
248
|
case 12:
|
|
276
249
|
_a.sent();
|
|
277
|
-
spinner.info("Static files copied to ".concat(
|
|
278
|
-
|
|
250
|
+
spinner.info("Static files copied to ".concat(path_1.default.join(targetDir, 'static')));
|
|
251
|
+
_a.label = 13;
|
|
279
252
|
case 13:
|
|
280
|
-
spinner.
|
|
281
|
-
|
|
282
|
-
case 14:
|
|
283
|
-
spinner.info('Build completed successfully.');
|
|
284
|
-
spinner.info("Project built and ready for ".concat(runtime, " runtime in ").concat(targetDir, "."));
|
|
285
|
-
// Explicitly exit with success if not in watch mode
|
|
286
|
-
if (!options.watch && !options.deploy) {
|
|
253
|
+
spinner.succeed("Build complete: ".concat(runtime, " runtime in ").concat(targetDir));
|
|
254
|
+
if (!options.watch && !options.deploy)
|
|
287
255
|
process.exit(0);
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
case 15:
|
|
256
|
+
return [3 /*break*/, 15];
|
|
257
|
+
case 14:
|
|
291
258
|
error_2 = _a.sent();
|
|
292
259
|
spinner.fail('Build failed.');
|
|
293
260
|
(0, utils_1.logError)('Build process encountered an error', error_2);
|
|
294
261
|
process.exit(1);
|
|
295
|
-
return [3 /*break*/,
|
|
296
|
-
case
|
|
262
|
+
return [3 /*break*/, 15];
|
|
263
|
+
case 15: return [2 /*return*/];
|
|
297
264
|
}
|
|
298
265
|
});
|
|
299
266
|
});
|