@dainprotocol/cli 1.2.19 → 1.2.24

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.
@@ -68,9 +68,118 @@ var utils_1 = require("../utils");
68
68
  var ora_1 = __importDefault(require("ora"));
69
69
  var fs_extra_1 = __importDefault(require("fs-extra"));
70
70
  var path_1 = __importDefault(require("path"));
71
+ /**
72
+ * Finds all WASM files in node_modules that might be needed at runtime.
73
+ * These files are loaded via fs.readFileSync and can't be bundled by esbuild.
74
+ */
75
+ function findWasmFiles(nodeModulesPath) {
76
+ return __awaiter(this, void 0, void 0, function () {
77
+ function scanDir(dir) {
78
+ return __awaiter(this, void 0, void 0, function () {
79
+ var entries, _i, entries_1, entry, fullPath, _a;
80
+ return __generator(this, function (_b) {
81
+ switch (_b.label) {
82
+ case 0:
83
+ _b.trys.push([0, 8, , 9]);
84
+ return [4 /*yield*/, fs_extra_1.default.readdir(dir, { withFileTypes: true })];
85
+ case 1:
86
+ entries = _b.sent();
87
+ _i = 0, entries_1 = entries;
88
+ _b.label = 2;
89
+ case 2:
90
+ if (!(_i < entries_1.length)) return [3 /*break*/, 7];
91
+ entry = entries_1[_i];
92
+ fullPath = path_1.default.join(dir, entry.name);
93
+ if (!entry.isDirectory()) return [3 /*break*/, 5];
94
+ if (!(entry.name !== '.bin' && entry.name !== '.cache')) return [3 /*break*/, 4];
95
+ return [4 /*yield*/, scanDir(fullPath)];
96
+ case 3:
97
+ _b.sent();
98
+ _b.label = 4;
99
+ case 4: return [3 /*break*/, 6];
100
+ case 5:
101
+ if (entry.name.endsWith('.wasm')) {
102
+ // Only include WASM files in dist/nodejs directories (Node.js bindings)
103
+ if (fullPath.includes('/dist/') || fullPath.includes('/build/')) {
104
+ wasmFiles.push(fullPath);
105
+ }
106
+ }
107
+ _b.label = 6;
108
+ case 6:
109
+ _i++;
110
+ return [3 /*break*/, 2];
111
+ case 7: return [3 /*break*/, 9];
112
+ case 8:
113
+ _a = _b.sent();
114
+ return [3 /*break*/, 9];
115
+ case 9: return [2 /*return*/];
116
+ }
117
+ });
118
+ });
119
+ }
120
+ var wasmFiles;
121
+ return __generator(this, function (_a) {
122
+ switch (_a.label) {
123
+ case 0:
124
+ wasmFiles = [];
125
+ return [4 /*yield*/, scanDir(nodeModulesPath)];
126
+ case 1:
127
+ _a.sent();
128
+ return [2 /*return*/, wasmFiles];
129
+ }
130
+ });
131
+ });
132
+ }
133
+ /**
134
+ * Copies WASM files that are referenced in the bundle to the output directory.
135
+ * Scans the bundle for WASM filename references and copies matching files.
136
+ */
137
+ function copyWasmDependencies(bundlePath, nodeModulesPath, outDir) {
138
+ return __awaiter(this, void 0, void 0, function () {
139
+ var copiedFiles, bundleContent, wasmFiles, _i, wasmFiles_1, wasmPath, wasmName, destPath, error_1;
140
+ return __generator(this, function (_a) {
141
+ switch (_a.label) {
142
+ case 0:
143
+ copiedFiles = [];
144
+ _a.label = 1;
145
+ case 1:
146
+ _a.trys.push([1, 8, , 9]);
147
+ return [4 /*yield*/, fs_extra_1.default.readFile(bundlePath, 'utf-8')];
148
+ case 2:
149
+ bundleContent = _a.sent();
150
+ return [4 /*yield*/, findWasmFiles(nodeModulesPath)];
151
+ case 3:
152
+ wasmFiles = _a.sent();
153
+ _i = 0, wasmFiles_1 = wasmFiles;
154
+ _a.label = 4;
155
+ case 4:
156
+ if (!(_i < wasmFiles_1.length)) return [3 /*break*/, 7];
157
+ wasmPath = wasmFiles_1[_i];
158
+ wasmName = path_1.default.basename(wasmPath);
159
+ if (!bundleContent.includes(wasmName)) return [3 /*break*/, 6];
160
+ destPath = path_1.default.join(outDir, wasmName);
161
+ return [4 /*yield*/, fs_extra_1.default.copy(wasmPath, destPath)];
162
+ case 5:
163
+ _a.sent();
164
+ copiedFiles.push(wasmName);
165
+ _a.label = 6;
166
+ case 6:
167
+ _i++;
168
+ return [3 /*break*/, 4];
169
+ case 7: return [3 /*break*/, 9];
170
+ case 8:
171
+ error_1 = _a.sent();
172
+ // Non-fatal: continue without WASM files
173
+ console.warn('Warning: Could not process WASM dependencies:', error_1);
174
+ return [3 /*break*/, 9];
175
+ case 9: return [2 /*return*/, copiedFiles];
176
+ }
177
+ });
178
+ });
179
+ }
71
180
  function build(options) {
72
181
  return __awaiter(this, void 0, void 0, function () {
73
- var spinner, config, runtime, outDir, dainDir, buildOptions, context, staticDir, staticOutDir, error_1;
182
+ var spinner, config, runtime, outDir, dainDir, nodeModulesPath, buildOptions, context, targetDir, bundlePath, copiedWasm, staticDir, staticOutDir, error_2;
74
183
  return __generator(this, function (_a) {
75
184
  switch (_a.label) {
76
185
  case 0:
@@ -79,9 +188,10 @@ function build(options) {
79
188
  runtime = options.runtime || config.runtime || 'node';
80
189
  outDir = path_1.default.join(process.cwd(), config['out-dir'] || 'build');
81
190
  dainDir = path_1.default.join(process.cwd(), '.dain');
191
+ nodeModulesPath = path_1.default.join(process.cwd(), 'node_modules');
82
192
  _a.label = 1;
83
193
  case 1:
84
- _a.trys.push([1, 12, , 13]);
194
+ _a.trys.push([1, 15, , 16]);
85
195
  // Ensure build directory exists
86
196
  return [4 /*yield*/, fs_extra_1.default.ensureDir(outDir)];
87
197
  case 2:
@@ -132,34 +242,48 @@ function build(options) {
132
242
  _a.sent();
133
243
  _a.label = 8;
134
244
  case 8:
245
+ targetDir = options.watch ? dainDir : outDir;
246
+ if (!(runtime === 'node')) return [3 /*break*/, 11];
247
+ bundlePath = path_1.default.join(targetDir, 'index.js');
248
+ return [4 /*yield*/, fs_extra_1.default.pathExists(bundlePath)];
249
+ case 9:
250
+ if (!_a.sent()) return [3 /*break*/, 11];
251
+ return [4 /*yield*/, copyWasmDependencies(bundlePath, nodeModulesPath, targetDir)];
252
+ case 10:
253
+ copiedWasm = _a.sent();
254
+ if (copiedWasm.length > 0) {
255
+ spinner.info("WASM files copied: ".concat(copiedWasm.join(', ')));
256
+ }
257
+ _a.label = 11;
258
+ case 11:
135
259
  staticDir = config['static-dir']
136
260
  ? path_1.default.join(process.cwd(), config['static-dir'])
137
261
  : path_1.default.join(process.cwd(), 'static');
138
- if (!fs_extra_1.default.existsSync(staticDir)) return [3 /*break*/, 10];
139
- staticOutDir = path_1.default.join(options.watch ? dainDir : outDir, 'static');
262
+ if (!fs_extra_1.default.existsSync(staticDir)) return [3 /*break*/, 13];
263
+ staticOutDir = path_1.default.join(targetDir, 'static');
140
264
  return [4 /*yield*/, fs_extra_1.default.copy(staticDir, staticOutDir)];
141
- case 9:
265
+ case 12:
142
266
  _a.sent();
143
267
  spinner.info("Static files copied to ".concat(staticOutDir));
144
- return [3 /*break*/, 11];
145
- case 10:
268
+ return [3 /*break*/, 14];
269
+ case 13:
146
270
  spinner.info('No static directory found. Skipping static file copy.');
147
- _a.label = 11;
148
- case 11:
271
+ _a.label = 14;
272
+ case 14:
149
273
  spinner.info('Build completed successfully.');
150
- spinner.info("Project built and ready for ".concat(runtime, " runtime in ").concat(options.watch ? dainDir : outDir, "."));
274
+ spinner.info("Project built and ready for ".concat(runtime, " runtime in ").concat(targetDir, "."));
151
275
  // Explicitly exit with success if not in watch mode
152
276
  if (!options.watch && !options.deploy) {
153
277
  process.exit(0);
154
278
  }
155
- return [3 /*break*/, 13];
156
- case 12:
157
- error_1 = _a.sent();
279
+ return [3 /*break*/, 16];
280
+ case 15:
281
+ error_2 = _a.sent();
158
282
  spinner.fail('Build failed.');
159
- (0, utils_1.logError)('Build process encountered an error', error_1);
283
+ (0, utils_1.logError)('Build process encountered an error', error_2);
160
284
  process.exit(1);
161
- return [3 /*break*/, 13];
162
- case 13: return [2 /*return*/];
285
+ return [3 /*break*/, 16];
286
+ case 16: return [2 /*return*/];
163
287
  }
164
288
  });
165
289
  });
package/dist/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/cli",
3
- "version": "1.2.19",
3
+ "version": "1.2.24",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -10,18 +10,14 @@
10
10
  "bin": {
11
11
  "dain": "./dist/index.js"
12
12
  },
13
- "scripts": {
14
- "build": "tsc && cp -r templates dist/",
15
- "prepublishOnly": "pnpm run build"
16
- },
17
13
  "files": [
18
14
  "dist",
19
15
  "README.md"
20
16
  ],
21
17
  "dependencies": {
22
18
  "@ai-sdk/anthropic": "^0.0.50",
23
- "@dainprotocol/service-sdk": "^2.0.60",
24
- "@dainprotocol/tunnel": "^1.1.25",
19
+ "@dainprotocol/service-sdk": "^2.0.75",
20
+ "@dainprotocol/tunnel": "^1.1.29",
25
21
  "@types/fs-extra": "^11.0.4",
26
22
  "@types/localtunnel": "^2.0.4",
27
23
  "ai": "^3.3.41",
@@ -41,5 +37,8 @@
41
37
  "@types/node": "^22.5.4",
42
38
  "ts-node": "^10.9.2",
43
39
  "typescript": "^5.5.4"
40
+ },
41
+ "scripts": {
42
+ "build": "tsc && cp -r templates dist/"
44
43
  }
45
- }
44
+ }