@hypequery/cli 0.0.2 → 0.0.4
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/cli.js +1 -1
- package/dist/utils/load-api.d.ts.map +1 -1
- package/dist/utils/load-api.js +129 -24
- package/package.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -155,7 +155,7 @@ program.on('--help', function () {
|
|
|
155
155
|
console.log(' hypequery init');
|
|
156
156
|
console.log(' hypequery dev');
|
|
157
157
|
console.log(' hypequery dev --port 3000');
|
|
158
|
-
console.log(' hypequery generate --
|
|
158
|
+
console.log(' hypequery generate --output analytics/schema.ts');
|
|
159
159
|
console.log('');
|
|
160
160
|
console.log('Docs: https://hypequery.com/docs');
|
|
161
161
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-api.d.ts","sourceRoot":"","sources":["../../src/utils/load-api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"load-api.d.ts","sourceRoot":"","sources":["../../src/utils/load-api.ts"],"names":[],"mappings":"AAQA,wBAAsB,aAAa,CAAC,UAAU,EAAE,MAAM,gBAuErD"}
|
package/dist/utils/load-api.js
CHANGED
|
@@ -37,12 +37,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
import { pathToFileURL } from 'node:url';
|
|
38
38
|
import { access } from 'node:fs/promises';
|
|
39
39
|
import path from 'node:path';
|
|
40
|
-
import {
|
|
40
|
+
import { build } from 'esbuild';
|
|
41
41
|
var TYPESCRIPT_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts']);
|
|
42
|
+
var tsconfigCache = new Map();
|
|
42
43
|
export function loadApiModule(modulePath) {
|
|
43
44
|
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
-
var resolved, _a, relativePath, extension, isTypeScript,
|
|
45
|
-
var
|
|
45
|
+
var resolved, _a, relativePath, extension, isTypeScript, moduleUrl, _b, mod, error_1, relativePath, api, relativePath, availableExports;
|
|
46
|
+
var _c;
|
|
46
47
|
return __generator(this, function (_d) {
|
|
47
48
|
switch (_d.label) {
|
|
48
49
|
case 0:
|
|
@@ -64,39 +65,35 @@ export function loadApiModule(modulePath) {
|
|
|
64
65
|
case 4:
|
|
65
66
|
extension = path.extname(resolved).toLowerCase();
|
|
66
67
|
isTypeScript = TYPESCRIPT_EXTENSIONS.has(extension);
|
|
67
|
-
if (!isTypeScript) return [3 /*break*/,
|
|
68
|
-
|
|
68
|
+
if (!isTypeScript) return [3 /*break*/, 6];
|
|
69
|
+
return [4 /*yield*/, bundleTypeScriptModule(resolved)];
|
|
69
70
|
case 5:
|
|
70
|
-
_d.
|
|
71
|
-
return [
|
|
71
|
+
_b = _d.sent();
|
|
72
|
+
return [3 /*break*/, 7];
|
|
72
73
|
case 6:
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
_b = "".concat(pathToFileURL(resolved).href, "?t=").concat(Date.now());
|
|
75
|
+
_d.label = 7;
|
|
75
76
|
case 7:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"Original error: ".concat((_b = error_1 === null || error_1 === void 0 ? void 0 : error_1.message) !== null && _b !== void 0 ? _b : error_1));
|
|
77
|
+
moduleUrl = _b;
|
|
78
|
+
_d.label = 8;
|
|
79
79
|
case 8:
|
|
80
|
-
|
|
81
|
-
_d.label = 9;
|
|
82
|
-
case 9:
|
|
83
|
-
_d.trys.push([9, 11, , 12]);
|
|
80
|
+
_d.trys.push([8, 10, , 11]);
|
|
84
81
|
return [4 /*yield*/, import(moduleUrl)];
|
|
85
|
-
case
|
|
82
|
+
case 9:
|
|
86
83
|
mod = _d.sent();
|
|
87
|
-
return [3 /*break*/,
|
|
88
|
-
case
|
|
89
|
-
|
|
84
|
+
return [3 /*break*/, 11];
|
|
85
|
+
case 10:
|
|
86
|
+
error_1 = _d.sent();
|
|
90
87
|
relativePath = path.relative(process.cwd(), resolved);
|
|
91
88
|
throw new Error("Failed to load module: ".concat(relativePath, "\n\n") +
|
|
92
|
-
"Error: ".concat(
|
|
93
|
-
(
|
|
89
|
+
"Error: ".concat(error_1.message, "\n\n") +
|
|
90
|
+
(error_1.code === 'ERR_MODULE_NOT_FOUND'
|
|
94
91
|
? "This usually means:\n" +
|
|
95
92
|
" \u2022 A dependency is missing (run 'npm install')\n" +
|
|
96
93
|
" \u2022 An import path is incorrect\n"
|
|
97
94
|
: "") +
|
|
98
|
-
(
|
|
99
|
-
case
|
|
95
|
+
(error_1.stack ? "\nStack trace:\n".concat(error_1.stack, "\n") : ''));
|
|
96
|
+
case 11:
|
|
100
97
|
api = (_c = mod.api) !== null && _c !== void 0 ? _c : mod.default;
|
|
101
98
|
if (!api || typeof api.handler !== 'function') {
|
|
102
99
|
relativePath = path.relative(process.cwd(), resolved);
|
|
@@ -126,3 +123,111 @@ export function loadApiModule(modulePath) {
|
|
|
126
123
|
});
|
|
127
124
|
});
|
|
128
125
|
}
|
|
126
|
+
function bundleTypeScriptModule(entryPath) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
+
var relativePath, tsconfigPath, result, output, contents, base64, error_2;
|
|
129
|
+
var _a, _b, _c, _d;
|
|
130
|
+
return __generator(this, function (_e) {
|
|
131
|
+
switch (_e.label) {
|
|
132
|
+
case 0:
|
|
133
|
+
relativePath = path.relative(process.cwd(), entryPath);
|
|
134
|
+
return [4 /*yield*/, findNearestTsconfig(entryPath)];
|
|
135
|
+
case 1:
|
|
136
|
+
tsconfigPath = _e.sent();
|
|
137
|
+
_e.label = 2;
|
|
138
|
+
case 2:
|
|
139
|
+
_e.trys.push([2, 4, , 5]);
|
|
140
|
+
return [4 /*yield*/, build({
|
|
141
|
+
entryPoints: [entryPath],
|
|
142
|
+
bundle: true,
|
|
143
|
+
format: 'esm',
|
|
144
|
+
platform: 'node',
|
|
145
|
+
target: ['node18'],
|
|
146
|
+
sourcemap: 'inline',
|
|
147
|
+
write: false,
|
|
148
|
+
logLevel: 'silent',
|
|
149
|
+
absWorkingDir: process.cwd(),
|
|
150
|
+
packages: 'external',
|
|
151
|
+
tsconfig: tsconfigPath !== null && tsconfigPath !== void 0 ? tsconfigPath : undefined,
|
|
152
|
+
loader: {
|
|
153
|
+
'.ts': 'ts',
|
|
154
|
+
'.tsx': 'tsx',
|
|
155
|
+
'.mts': 'ts',
|
|
156
|
+
'.cts': 'ts',
|
|
157
|
+
},
|
|
158
|
+
})];
|
|
159
|
+
case 3:
|
|
160
|
+
result = _e.sent();
|
|
161
|
+
output = (_b = (_a = result.outputFiles) === null || _a === void 0 ? void 0 : _a.find(function (file) { return file.path.endsWith('.js'); })) !== null && _b !== void 0 ? _b : (_c = result.outputFiles) === null || _c === void 0 ? void 0 : _c[0];
|
|
162
|
+
if (!output) {
|
|
163
|
+
throw new Error('esbuild produced no output');
|
|
164
|
+
}
|
|
165
|
+
contents = "".concat(output.text, "\n//# sourceURL=").concat(pathToFileURL(entryPath).href);
|
|
166
|
+
base64 = Buffer.from(contents, 'utf8').toString('base64');
|
|
167
|
+
return [2 /*return*/, "data:text/javascript;base64,".concat(base64, "#ts=").concat(Date.now())];
|
|
168
|
+
case 4:
|
|
169
|
+
error_2 = _e.sent();
|
|
170
|
+
throw new Error("Failed to compile ".concat(relativePath, " with esbuild.\n") +
|
|
171
|
+
"Original error: ".concat((_d = error_2 === null || error_2 === void 0 ? void 0 : error_2.message) !== null && _d !== void 0 ? _d : error_2));
|
|
172
|
+
case 5: return [2 /*return*/];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function findNearestTsconfig(filePath) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
+
var dir, visited, _loop_1, state_1;
|
|
180
|
+
var _a;
|
|
181
|
+
return __generator(this, function (_b) {
|
|
182
|
+
switch (_b.label) {
|
|
183
|
+
case 0:
|
|
184
|
+
dir = path.dirname(filePath);
|
|
185
|
+
visited = [];
|
|
186
|
+
_loop_1 = function () {
|
|
187
|
+
var cached_1, candidate, _c, parent_1;
|
|
188
|
+
return __generator(this, function (_d) {
|
|
189
|
+
switch (_d.label) {
|
|
190
|
+
case 0:
|
|
191
|
+
if (tsconfigCache.has(dir)) {
|
|
192
|
+
cached_1 = (_a = tsconfigCache.get(dir)) !== null && _a !== void 0 ? _a : null;
|
|
193
|
+
visited.forEach(function (pathname) { return tsconfigCache.set(pathname, cached_1); });
|
|
194
|
+
return [2 /*return*/, { value: cached_1 }];
|
|
195
|
+
}
|
|
196
|
+
visited.push(dir);
|
|
197
|
+
candidate = path.join(dir, 'tsconfig.json');
|
|
198
|
+
_d.label = 1;
|
|
199
|
+
case 1:
|
|
200
|
+
_d.trys.push([1, 3, , 4]);
|
|
201
|
+
return [4 /*yield*/, access(candidate)];
|
|
202
|
+
case 2:
|
|
203
|
+
_d.sent();
|
|
204
|
+
tsconfigCache.set(dir, candidate);
|
|
205
|
+
visited.forEach(function (pathname) { return tsconfigCache.set(pathname, candidate); });
|
|
206
|
+
return [2 /*return*/, { value: candidate }];
|
|
207
|
+
case 3:
|
|
208
|
+
_c = _d.sent();
|
|
209
|
+
parent_1 = path.dirname(dir);
|
|
210
|
+
if (parent_1 === dir) {
|
|
211
|
+
visited.forEach(function (pathname) { return tsconfigCache.set(pathname, null); });
|
|
212
|
+
return [2 /*return*/, { value: null }];
|
|
213
|
+
}
|
|
214
|
+
dir = parent_1;
|
|
215
|
+
return [3 /*break*/, 4];
|
|
216
|
+
case 4: return [2 /*return*/];
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
_b.label = 1;
|
|
221
|
+
case 1:
|
|
222
|
+
if (!true) return [3 /*break*/, 3];
|
|
223
|
+
return [5 /*yield**/, _loop_1()];
|
|
224
|
+
case 2:
|
|
225
|
+
state_1 = _b.sent();
|
|
226
|
+
if (typeof state_1 === "object")
|
|
227
|
+
return [2 /*return*/, state_1.value];
|
|
228
|
+
return [3 /*break*/, 1];
|
|
229
|
+
case 3: return [2 /*return*/];
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypequery/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Command-line interface for Hypequery",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"chalk": "^5.3.0",
|
|
16
16
|
"commander": "^12.0.0",
|
|
17
17
|
"dotenv": "^16.4.7",
|
|
18
|
+
"esbuild": "^0.24.0",
|
|
18
19
|
"open": "^10.0.0",
|
|
19
20
|
"ora": "^8.0.1",
|
|
20
|
-
"prompts": "^2.4.2"
|
|
21
|
-
"tsx": "^4.19.2"
|
|
21
|
+
"prompts": "^2.4.2"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@hypequery/clickhouse": "*",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"@vitest/coverage-v8": "^2.1.6",
|
|
36
36
|
"typescript": "^5.7.3",
|
|
37
37
|
"vitest": "^2.1.6",
|
|
38
|
-
"@hypequery/
|
|
39
|
-
"@hypequery/
|
|
38
|
+
"@hypequery/serve": "0.0.3",
|
|
39
|
+
"@hypequery/clickhouse": "1.5.0"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|