@hypequery/cli 0.0.8 → 0.0.9
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/bin/cli.d.ts +3 -0
- package/dist/bin/cli.d.ts.map +1 -0
- package/dist/bin/cli.js +86 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +163 -0
- package/dist/commands/dev.d.ts +12 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +265 -0
- package/dist/commands/generate.d.ts +8 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +175 -0
- package/dist/commands/init.d.ts +10 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +408 -0
- package/dist/generators/clickhouse.d.ts +7 -0
- package/dist/generators/clickhouse.d.ts.map +1 -0
- package/dist/generators/clickhouse.js +229 -0
- package/dist/generators/index.d.ts +7 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +13 -0
- package/dist/templates/client.d.ts +5 -0
- package/dist/templates/client.d.ts.map +1 -0
- package/dist/templates/client.js +6 -0
- package/dist/templates/env.d.ts +14 -0
- package/dist/templates/env.d.ts.map +1 -0
- package/dist/templates/env.js +37 -0
- package/dist/templates/gitignore.d.ts +13 -0
- package/dist/templates/gitignore.d.ts.map +1 -0
- package/dist/templates/gitignore.js +22 -0
- package/dist/templates/queries.d.ts +8 -0
- package/dist/templates/queries.d.ts.map +1 -0
- package/dist/templates/queries.js +27 -0
- package/dist/test-utils.d.ts +86 -0
- package/dist/test-utils.d.ts.map +1 -0
- package/dist/test-utils.js +153 -0
- package/dist/utils/clickhouse-client.d.ts +11 -0
- package/dist/utils/clickhouse-client.d.ts.map +1 -0
- package/dist/utils/clickhouse-client.js +86 -0
- package/dist/utils/dependency-installer.d.ts +2 -0
- package/dist/utils/dependency-installer.d.ts.map +1 -0
- package/dist/utils/dependency-installer.js +180 -0
- package/dist/utils/detect-database.d.ts +21 -0
- package/dist/utils/detect-database.d.ts.map +1 -0
- package/dist/utils/detect-database.js +224 -0
- package/dist/utils/error-messages.d.ts +6 -0
- package/dist/utils/error-messages.d.ts.map +1 -0
- package/dist/utils/error-messages.js +19 -0
- package/dist/utils/find-files.d.ts +21 -0
- package/dist/utils/find-files.d.ts.map +1 -0
- package/dist/utils/find-files.js +183 -0
- package/dist/utils/load-api.d.ts +2 -0
- package/dist/utils/load-api.d.ts.map +1 -0
- package/dist/utils/load-api.js +400 -0
- package/dist/utils/logger.d.ts +54 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +122 -0
- package/dist/utils/prompts.d.ts +39 -0
- package/dist/utils/prompts.d.ts.map +1 -0
- package/dist/utils/prompts.js +282 -0
- package/package.json +2 -2
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { access } from 'node:fs/promises';
|
|
38
|
+
import path from 'node:path';
|
|
39
|
+
/**
|
|
40
|
+
* Generic helper to find a file from a list of candidate paths
|
|
41
|
+
*/
|
|
42
|
+
function findFile(candidates) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
+
var _i, candidates_1, candidate, resolved, _a;
|
|
45
|
+
return __generator(this, function (_b) {
|
|
46
|
+
switch (_b.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
_i = 0, candidates_1 = candidates;
|
|
49
|
+
_b.label = 1;
|
|
50
|
+
case 1:
|
|
51
|
+
if (!(_i < candidates_1.length)) return [3 /*break*/, 6];
|
|
52
|
+
candidate = candidates_1[_i];
|
|
53
|
+
resolved = path.resolve(process.cwd(), candidate);
|
|
54
|
+
_b.label = 2;
|
|
55
|
+
case 2:
|
|
56
|
+
_b.trys.push([2, 4, , 5]);
|
|
57
|
+
return [4 /*yield*/, access(resolved)];
|
|
58
|
+
case 3:
|
|
59
|
+
_b.sent();
|
|
60
|
+
return [2 /*return*/, resolved];
|
|
61
|
+
case 4:
|
|
62
|
+
_a = _b.sent();
|
|
63
|
+
return [3 /*break*/, 5];
|
|
64
|
+
case 5:
|
|
65
|
+
_i++;
|
|
66
|
+
return [3 /*break*/, 1];
|
|
67
|
+
case 6: return [2 /*return*/, null];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Common query file locations to check
|
|
74
|
+
*/
|
|
75
|
+
var DEFAULT_QUERY_PATHS = [
|
|
76
|
+
'hypequery.ts',
|
|
77
|
+
'analytics/queries.ts',
|
|
78
|
+
'src/analytics/queries.ts',
|
|
79
|
+
'queries.ts',
|
|
80
|
+
'src/queries.ts',
|
|
81
|
+
];
|
|
82
|
+
/**
|
|
83
|
+
* Find the queries file in the project
|
|
84
|
+
*/
|
|
85
|
+
export function findQueriesFile(customPath) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
var resolved, _a;
|
|
88
|
+
return __generator(this, function (_b) {
|
|
89
|
+
switch (_b.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
if (!customPath) return [3 /*break*/, 4];
|
|
92
|
+
resolved = path.resolve(process.cwd(), customPath);
|
|
93
|
+
_b.label = 1;
|
|
94
|
+
case 1:
|
|
95
|
+
_b.trys.push([1, 3, , 4]);
|
|
96
|
+
return [4 /*yield*/, access(resolved)];
|
|
97
|
+
case 2:
|
|
98
|
+
_b.sent();
|
|
99
|
+
return [2 /*return*/, resolved];
|
|
100
|
+
case 3:
|
|
101
|
+
_a = _b.sent();
|
|
102
|
+
return [2 /*return*/, null];
|
|
103
|
+
case 4:
|
|
104
|
+
// Check default locations
|
|
105
|
+
return [2 /*return*/, findFile(DEFAULT_QUERY_PATHS)];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Find the schema file (generated types)
|
|
112
|
+
*/
|
|
113
|
+
export function findSchemaFile() {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
+
return __generator(this, function (_a) {
|
|
116
|
+
return [2 /*return*/, findFile([
|
|
117
|
+
'analytics/schema.ts',
|
|
118
|
+
'src/analytics/schema.ts',
|
|
119
|
+
'schema.ts',
|
|
120
|
+
'src/schema.ts',
|
|
121
|
+
])];
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Find the client file
|
|
127
|
+
*/
|
|
128
|
+
export function findClientFile() {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
+
return __generator(this, function (_a) {
|
|
131
|
+
return [2 /*return*/, findFile([
|
|
132
|
+
'analytics/client.ts',
|
|
133
|
+
'src/analytics/client.ts',
|
|
134
|
+
'client.ts',
|
|
135
|
+
'src/client.ts',
|
|
136
|
+
])];
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Check if .env file exists
|
|
142
|
+
*/
|
|
143
|
+
export function hasEnvFile() {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
+
var _a;
|
|
146
|
+
return __generator(this, function (_b) {
|
|
147
|
+
switch (_b.label) {
|
|
148
|
+
case 0:
|
|
149
|
+
_b.trys.push([0, 2, , 3]);
|
|
150
|
+
return [4 /*yield*/, access(path.join(process.cwd(), '.env'))];
|
|
151
|
+
case 1:
|
|
152
|
+
_b.sent();
|
|
153
|
+
return [2 /*return*/, true];
|
|
154
|
+
case 2:
|
|
155
|
+
_a = _b.sent();
|
|
156
|
+
return [2 /*return*/, false];
|
|
157
|
+
case 3: return [2 /*return*/];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Check if .gitignore exists
|
|
164
|
+
*/
|
|
165
|
+
export function hasGitignore() {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
167
|
+
var _a;
|
|
168
|
+
return __generator(this, function (_b) {
|
|
169
|
+
switch (_b.label) {
|
|
170
|
+
case 0:
|
|
171
|
+
_b.trys.push([0, 2, , 3]);
|
|
172
|
+
return [4 /*yield*/, access(path.join(process.cwd(), '.gitignore'))];
|
|
173
|
+
case 1:
|
|
174
|
+
_b.sent();
|
|
175
|
+
return [2 /*return*/, true];
|
|
176
|
+
case 2:
|
|
177
|
+
_a = _b.sent();
|
|
178
|
+
return [2 /*return*/, false];
|
|
179
|
+
case 3: return [2 /*return*/];
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-api.d.ts","sourceRoot":"","sources":["../../src/utils/load-api.ts"],"names":[],"mappings":"AAaA,wBAAsB,aAAa,CAAC,UAAU,EAAE,MAAM,gBAuErD"}
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var _a, _b, _c, _d;
|
|
38
|
+
import { pathToFileURL } from 'node:url';
|
|
39
|
+
import { access, mkdtemp, writeFile, rm, mkdir } from 'node:fs/promises';
|
|
40
|
+
import os from 'node:os';
|
|
41
|
+
import path from 'node:path';
|
|
42
|
+
import { build } from 'esbuild';
|
|
43
|
+
if (typeof process.setMaxListeners === 'function') {
|
|
44
|
+
process.setMaxListeners(0);
|
|
45
|
+
}
|
|
46
|
+
var TYPESCRIPT_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts']);
|
|
47
|
+
var tsconfigCache = new Map();
|
|
48
|
+
export function loadApiModule(modulePath) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
50
|
+
var resolved, _a, relativePath, extension, isTypeScript, moduleUrl, _b, mod, error_1, relativePath, api, relativePath, availableExports;
|
|
51
|
+
var _c;
|
|
52
|
+
return __generator(this, function (_d) {
|
|
53
|
+
switch (_d.label) {
|
|
54
|
+
case 0:
|
|
55
|
+
resolved = path.resolve(process.cwd(), modulePath);
|
|
56
|
+
_d.label = 1;
|
|
57
|
+
case 1:
|
|
58
|
+
_d.trys.push([1, 3, , 4]);
|
|
59
|
+
return [4 /*yield*/, access(resolved)];
|
|
60
|
+
case 2:
|
|
61
|
+
_d.sent();
|
|
62
|
+
return [3 /*break*/, 4];
|
|
63
|
+
case 3:
|
|
64
|
+
_a = _d.sent();
|
|
65
|
+
relativePath = path.relative(process.cwd(), resolved);
|
|
66
|
+
throw new Error("File not found: ".concat(relativePath, "\n\n") +
|
|
67
|
+
"Make sure the file exists and the path is correct.\n" +
|
|
68
|
+
"You can specify a different file with:\n" +
|
|
69
|
+
" hypequery dev path/to/your/queries.ts");
|
|
70
|
+
case 4:
|
|
71
|
+
extension = path.extname(resolved).toLowerCase();
|
|
72
|
+
isTypeScript = TYPESCRIPT_EXTENSIONS.has(extension);
|
|
73
|
+
if (!isTypeScript) return [3 /*break*/, 6];
|
|
74
|
+
return [4 /*yield*/, bundleTypeScriptModule(resolved)];
|
|
75
|
+
case 5:
|
|
76
|
+
_b = _d.sent();
|
|
77
|
+
return [3 /*break*/, 7];
|
|
78
|
+
case 6:
|
|
79
|
+
_b = "".concat(pathToFileURL(resolved).href, "?t=").concat(Date.now());
|
|
80
|
+
_d.label = 7;
|
|
81
|
+
case 7:
|
|
82
|
+
moduleUrl = _b;
|
|
83
|
+
_d.label = 8;
|
|
84
|
+
case 8:
|
|
85
|
+
_d.trys.push([8, 10, , 11]);
|
|
86
|
+
return [4 /*yield*/, import(moduleUrl)];
|
|
87
|
+
case 9:
|
|
88
|
+
mod = _d.sent();
|
|
89
|
+
return [3 /*break*/, 11];
|
|
90
|
+
case 10:
|
|
91
|
+
error_1 = _d.sent();
|
|
92
|
+
relativePath = path.relative(process.cwd(), resolved);
|
|
93
|
+
throw new Error("Failed to load module: ".concat(relativePath, "\n\n") +
|
|
94
|
+
"Error: ".concat(error_1.message, "\n\n") +
|
|
95
|
+
(error_1.code === 'ERR_MODULE_NOT_FOUND'
|
|
96
|
+
? "This usually means:\n" +
|
|
97
|
+
" \u2022 A dependency is missing (run 'npm install')\n" +
|
|
98
|
+
" \u2022 An import path is incorrect\n"
|
|
99
|
+
: "") +
|
|
100
|
+
(error_1.stack ? "\nStack trace:\n".concat(error_1.stack, "\n") : ''));
|
|
101
|
+
case 11:
|
|
102
|
+
api = (_c = mod.api) !== null && _c !== void 0 ? _c : mod.default;
|
|
103
|
+
if (!api || typeof api.handler !== 'function') {
|
|
104
|
+
relativePath = path.relative(process.cwd(), resolved);
|
|
105
|
+
availableExports = Object.keys(mod).filter(function (key) { return key !== '__esModule'; });
|
|
106
|
+
throw new Error("Invalid API module: ".concat(relativePath, "\n\n") +
|
|
107
|
+
"The module must export a 'defineServe' result as 'api'.\n\n" +
|
|
108
|
+
(availableExports.length > 0
|
|
109
|
+
? "Found exports: ".concat(availableExports.join(', '), "\n\n")
|
|
110
|
+
: "No exports found in the module.\n\n") +
|
|
111
|
+
"Expected format:\n\n" +
|
|
112
|
+
" import { initServe } from '@hypequery/serve';\n" +
|
|
113
|
+
" \n" +
|
|
114
|
+
" const { define, queries, query } = initServe({\n" +
|
|
115
|
+
" context: () => ({ db }),\n" +
|
|
116
|
+
" });\n" +
|
|
117
|
+
" \n" +
|
|
118
|
+
" export const api = define({\n" +
|
|
119
|
+
" queries: queries({\n" +
|
|
120
|
+
" myQuery: query.query(async ({ ctx }) => {\n" +
|
|
121
|
+
" // ...\n" +
|
|
122
|
+
" }),\n" +
|
|
123
|
+
" }),\n" +
|
|
124
|
+
" });\n");
|
|
125
|
+
}
|
|
126
|
+
return [2 /*return*/, api];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
var globalState = globalThis;
|
|
132
|
+
var tempDirPromise = (_a = globalState.__hypequeryCliTempDirPromise) !== null && _a !== void 0 ? _a : null;
|
|
133
|
+
var tempFiles = (_b = globalState.__hypequeryCliTempFiles) !== null && _b !== void 0 ? _b : new Set();
|
|
134
|
+
var tempDirs = (_c = globalState.__hypequeryCliTempDirs) !== null && _c !== void 0 ? _c : new Set();
|
|
135
|
+
var cleanupHooksInstalled = (_d = globalState.__hypequeryCliCleanupInstalled) !== null && _d !== void 0 ? _d : false;
|
|
136
|
+
if (!globalState.__hypequeryCliTempFiles) {
|
|
137
|
+
globalState.__hypequeryCliTempFiles = tempFiles;
|
|
138
|
+
}
|
|
139
|
+
if (!globalState.__hypequeryCliTempDirs) {
|
|
140
|
+
globalState.__hypequeryCliTempDirs = tempDirs;
|
|
141
|
+
}
|
|
142
|
+
function ensureTempDir() {
|
|
143
|
+
var _this = this;
|
|
144
|
+
installCleanupHooks();
|
|
145
|
+
if (!tempDirPromise) {
|
|
146
|
+
tempDirPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
147
|
+
var projectTempRoot, dir, _a, fallbackDir;
|
|
148
|
+
return __generator(this, function (_b) {
|
|
149
|
+
switch (_b.label) {
|
|
150
|
+
case 0:
|
|
151
|
+
projectTempRoot = path.join(process.cwd(), '.hypequery', 'tmp');
|
|
152
|
+
_b.label = 1;
|
|
153
|
+
case 1:
|
|
154
|
+
_b.trys.push([1, 4, , 6]);
|
|
155
|
+
return [4 /*yield*/, mkdir(projectTempRoot, { recursive: true })];
|
|
156
|
+
case 2:
|
|
157
|
+
_b.sent();
|
|
158
|
+
return [4 /*yield*/, mkdtemp(path.join(projectTempRoot, 'bundle-'))];
|
|
159
|
+
case 3:
|
|
160
|
+
dir = _b.sent();
|
|
161
|
+
tempDirs.add(dir);
|
|
162
|
+
return [2 /*return*/, dir];
|
|
163
|
+
case 4:
|
|
164
|
+
_a = _b.sent();
|
|
165
|
+
return [4 /*yield*/, mkdtemp(path.join(os.tmpdir(), 'hypequery-cli-'))];
|
|
166
|
+
case 5:
|
|
167
|
+
fallbackDir = _b.sent();
|
|
168
|
+
tempDirs.add(fallbackDir);
|
|
169
|
+
return [2 /*return*/, fallbackDir];
|
|
170
|
+
case 6: return [2 /*return*/];
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}); })();
|
|
174
|
+
globalState.__hypequeryCliTempDirPromise = tempDirPromise;
|
|
175
|
+
}
|
|
176
|
+
return tempDirPromise;
|
|
177
|
+
}
|
|
178
|
+
function cleanupTempFiles() {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
180
|
+
var _this = this;
|
|
181
|
+
return __generator(this, function (_a) {
|
|
182
|
+
switch (_a.label) {
|
|
183
|
+
case 0:
|
|
184
|
+
if (tempFiles.size === 0)
|
|
185
|
+
return [2 /*return*/];
|
|
186
|
+
return [4 /*yield*/, Promise.all(Array.from(tempFiles).map(function (file) { return __awaiter(_this, void 0, void 0, function () {
|
|
187
|
+
var _a;
|
|
188
|
+
return __generator(this, function (_b) {
|
|
189
|
+
switch (_b.label) {
|
|
190
|
+
case 0:
|
|
191
|
+
_b.trys.push([0, 2, , 3]);
|
|
192
|
+
return [4 /*yield*/, rm(file, { force: true })];
|
|
193
|
+
case 1:
|
|
194
|
+
_b.sent();
|
|
195
|
+
return [3 /*break*/, 3];
|
|
196
|
+
case 2:
|
|
197
|
+
_a = _b.sent();
|
|
198
|
+
return [3 /*break*/, 3];
|
|
199
|
+
case 3: return [2 /*return*/];
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}); }))];
|
|
203
|
+
case 1:
|
|
204
|
+
_a.sent();
|
|
205
|
+
tempFiles.clear();
|
|
206
|
+
return [2 /*return*/];
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function cleanupTempDirs() {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
213
|
+
var projectTempRoot, _a;
|
|
214
|
+
var _this = this;
|
|
215
|
+
return __generator(this, function (_b) {
|
|
216
|
+
switch (_b.label) {
|
|
217
|
+
case 0:
|
|
218
|
+
if (tempDirs.size === 0)
|
|
219
|
+
return [2 /*return*/];
|
|
220
|
+
return [4 /*yield*/, Promise.all(Array.from(tempDirs).map(function (dir) { return __awaiter(_this, void 0, void 0, function () {
|
|
221
|
+
var _a;
|
|
222
|
+
return __generator(this, function (_b) {
|
|
223
|
+
switch (_b.label) {
|
|
224
|
+
case 0:
|
|
225
|
+
_b.trys.push([0, 2, , 3]);
|
|
226
|
+
return [4 /*yield*/, rm(dir, { recursive: true, force: true })];
|
|
227
|
+
case 1:
|
|
228
|
+
_b.sent();
|
|
229
|
+
return [3 /*break*/, 3];
|
|
230
|
+
case 2:
|
|
231
|
+
_a = _b.sent();
|
|
232
|
+
return [3 /*break*/, 3];
|
|
233
|
+
case 3: return [2 /*return*/];
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}); }))];
|
|
237
|
+
case 1:
|
|
238
|
+
_b.sent();
|
|
239
|
+
tempDirs.clear();
|
|
240
|
+
projectTempRoot = path.join(process.cwd(), '.hypequery', 'tmp');
|
|
241
|
+
_b.label = 2;
|
|
242
|
+
case 2:
|
|
243
|
+
_b.trys.push([2, 4, , 5]);
|
|
244
|
+
return [4 /*yield*/, rm(projectTempRoot, { recursive: true, force: true })];
|
|
245
|
+
case 3:
|
|
246
|
+
_b.sent();
|
|
247
|
+
return [3 /*break*/, 5];
|
|
248
|
+
case 4:
|
|
249
|
+
_a = _b.sent();
|
|
250
|
+
return [3 /*break*/, 5];
|
|
251
|
+
case 5: return [2 /*return*/];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
function cleanupTempArtifacts() {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
+
return __generator(this, function (_a) {
|
|
259
|
+
switch (_a.label) {
|
|
260
|
+
case 0: return [4 /*yield*/, cleanupTempFiles()];
|
|
261
|
+
case 1:
|
|
262
|
+
_a.sent();
|
|
263
|
+
return [4 /*yield*/, cleanupTempDirs()];
|
|
264
|
+
case 2:
|
|
265
|
+
_a.sent();
|
|
266
|
+
return [2 /*return*/];
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
function installCleanupHooks() {
|
|
272
|
+
if (cleanupHooksInstalled)
|
|
273
|
+
return;
|
|
274
|
+
cleanupHooksInstalled = true;
|
|
275
|
+
globalState.__hypequeryCliCleanupInstalled = true;
|
|
276
|
+
process.once('exit', function () {
|
|
277
|
+
cleanupTempArtifacts().catch(function () { return undefined; });
|
|
278
|
+
});
|
|
279
|
+
['SIGINT', 'SIGTERM'].forEach(function (signal) {
|
|
280
|
+
process.once(signal, function () {
|
|
281
|
+
cleanupTempArtifacts().catch(function () { return undefined; });
|
|
282
|
+
process.exit();
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function bundleTypeScriptModule(entryPath) {
|
|
287
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
288
|
+
var relativePath, tsconfigPath, result, output, contents, tempDir, tempFile, error_2;
|
|
289
|
+
var _a, _b, _c, _d;
|
|
290
|
+
return __generator(this, function (_e) {
|
|
291
|
+
switch (_e.label) {
|
|
292
|
+
case 0:
|
|
293
|
+
relativePath = path.relative(process.cwd(), entryPath);
|
|
294
|
+
return [4 /*yield*/, findNearestTsconfig(entryPath)];
|
|
295
|
+
case 1:
|
|
296
|
+
tsconfigPath = _e.sent();
|
|
297
|
+
_e.label = 2;
|
|
298
|
+
case 2:
|
|
299
|
+
_e.trys.push([2, 6, , 7]);
|
|
300
|
+
return [4 /*yield*/, build({
|
|
301
|
+
entryPoints: [entryPath],
|
|
302
|
+
bundle: true,
|
|
303
|
+
format: 'esm',
|
|
304
|
+
platform: 'node',
|
|
305
|
+
target: ['node18'],
|
|
306
|
+
sourcemap: 'inline',
|
|
307
|
+
write: false,
|
|
308
|
+
logLevel: 'silent',
|
|
309
|
+
absWorkingDir: process.cwd(),
|
|
310
|
+
packages: 'external',
|
|
311
|
+
tsconfig: tsconfigPath !== null && tsconfigPath !== void 0 ? tsconfigPath : undefined,
|
|
312
|
+
loader: {
|
|
313
|
+
'.ts': 'ts',
|
|
314
|
+
'.tsx': 'tsx',
|
|
315
|
+
'.mts': 'ts',
|
|
316
|
+
'.cts': 'ts',
|
|
317
|
+
},
|
|
318
|
+
})];
|
|
319
|
+
case 3:
|
|
320
|
+
result = _e.sent();
|
|
321
|
+
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];
|
|
322
|
+
if (!output) {
|
|
323
|
+
throw new Error('esbuild produced no output');
|
|
324
|
+
}
|
|
325
|
+
contents = "".concat(output.text, "\n//# sourceURL=").concat(pathToFileURL(entryPath).href);
|
|
326
|
+
return [4 /*yield*/, ensureTempDir()];
|
|
327
|
+
case 4:
|
|
328
|
+
tempDir = _e.sent();
|
|
329
|
+
tempFile = path.join(tempDir, "".concat(path.basename(entryPath).replace(/[^a-zA-Z0-9_-]/g, '_'), "-").concat(Date.now(), "-").concat(Math.random().toString(36).slice(2), ".mjs"));
|
|
330
|
+
return [4 /*yield*/, writeFile(tempFile, contents, 'utf8')];
|
|
331
|
+
case 5:
|
|
332
|
+
_e.sent();
|
|
333
|
+
tempFiles.add(tempFile);
|
|
334
|
+
return [2 /*return*/, "".concat(pathToFileURL(tempFile).href, "?t=").concat(Date.now())];
|
|
335
|
+
case 6:
|
|
336
|
+
error_2 = _e.sent();
|
|
337
|
+
throw new Error("Failed to compile ".concat(relativePath, " with esbuild.\n") +
|
|
338
|
+
"Original error: ".concat((_d = error_2 === null || error_2 === void 0 ? void 0 : error_2.message) !== null && _d !== void 0 ? _d : error_2));
|
|
339
|
+
case 7: return [2 /*return*/];
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
function findNearestTsconfig(filePath) {
|
|
345
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
346
|
+
var dir, visited, _loop_1, state_1;
|
|
347
|
+
var _a;
|
|
348
|
+
return __generator(this, function (_b) {
|
|
349
|
+
switch (_b.label) {
|
|
350
|
+
case 0:
|
|
351
|
+
dir = path.dirname(filePath);
|
|
352
|
+
visited = [];
|
|
353
|
+
_loop_1 = function () {
|
|
354
|
+
var cached_1, candidate, _c, parent_1;
|
|
355
|
+
return __generator(this, function (_d) {
|
|
356
|
+
switch (_d.label) {
|
|
357
|
+
case 0:
|
|
358
|
+
if (tsconfigCache.has(dir)) {
|
|
359
|
+
cached_1 = (_a = tsconfigCache.get(dir)) !== null && _a !== void 0 ? _a : null;
|
|
360
|
+
visited.forEach(function (pathname) { return tsconfigCache.set(pathname, cached_1); });
|
|
361
|
+
return [2 /*return*/, { value: cached_1 }];
|
|
362
|
+
}
|
|
363
|
+
visited.push(dir);
|
|
364
|
+
candidate = path.join(dir, 'tsconfig.json');
|
|
365
|
+
_d.label = 1;
|
|
366
|
+
case 1:
|
|
367
|
+
_d.trys.push([1, 3, , 4]);
|
|
368
|
+
return [4 /*yield*/, access(candidate)];
|
|
369
|
+
case 2:
|
|
370
|
+
_d.sent();
|
|
371
|
+
tsconfigCache.set(dir, candidate);
|
|
372
|
+
visited.forEach(function (pathname) { return tsconfigCache.set(pathname, candidate); });
|
|
373
|
+
return [2 /*return*/, { value: candidate }];
|
|
374
|
+
case 3:
|
|
375
|
+
_c = _d.sent();
|
|
376
|
+
parent_1 = path.dirname(dir);
|
|
377
|
+
if (parent_1 === dir) {
|
|
378
|
+
visited.forEach(function (pathname) { return tsconfigCache.set(pathname, null); });
|
|
379
|
+
return [2 /*return*/, { value: null }];
|
|
380
|
+
}
|
|
381
|
+
dir = parent_1;
|
|
382
|
+
return [3 /*break*/, 4];
|
|
383
|
+
case 4: return [2 /*return*/];
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
_b.label = 1;
|
|
388
|
+
case 1:
|
|
389
|
+
if (!true) return [3 /*break*/, 3];
|
|
390
|
+
return [5 /*yield**/, _loop_1()];
|
|
391
|
+
case 2:
|
|
392
|
+
state_1 = _b.sent();
|
|
393
|
+
if (typeof state_1 === "object")
|
|
394
|
+
return [2 /*return*/, state_1.value];
|
|
395
|
+
return [3 /*break*/, 1];
|
|
396
|
+
case 3: return [2 /*return*/];
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calm, professional CLI logger
|
|
3
|
+
* Follows Vercel-style output: informative, actionable, no noise
|
|
4
|
+
*/
|
|
5
|
+
export declare class Logger {
|
|
6
|
+
private quiet;
|
|
7
|
+
constructor(quiet?: boolean);
|
|
8
|
+
/**
|
|
9
|
+
* Success message with checkmark
|
|
10
|
+
*/
|
|
11
|
+
success(message: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* Error message with X mark
|
|
14
|
+
*/
|
|
15
|
+
error(message: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Warning message with warning symbol
|
|
18
|
+
*/
|
|
19
|
+
warn(message: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Info message (no symbol)
|
|
22
|
+
*/
|
|
23
|
+
info(message: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Reload/change message
|
|
26
|
+
*/
|
|
27
|
+
reload(message: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Section header
|
|
30
|
+
*/
|
|
31
|
+
header(message: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Empty line
|
|
34
|
+
*/
|
|
35
|
+
newline(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Indented message (for sub-items)
|
|
38
|
+
*/
|
|
39
|
+
indent(message: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Boxed URL output
|
|
42
|
+
*/
|
|
43
|
+
box(lines: string[]): void;
|
|
44
|
+
/**
|
|
45
|
+
* Table output (for dev server stats)
|
|
46
|
+
*/
|
|
47
|
+
table(headers: string[], rows: string[][]): void;
|
|
48
|
+
/**
|
|
49
|
+
* Raw console.log (bypass quiet mode)
|
|
50
|
+
*/
|
|
51
|
+
raw(message: string): void;
|
|
52
|
+
}
|
|
53
|
+
export declare const logger: Logger;
|
|
54
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,KAAK,CAAU;gBAEX,KAAK,UAAQ;IAIzB;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM;IAMvB;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM;IAIrB;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM;IAMpB;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM;IAMpB;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM;IAMtB;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM;IAMtB;;OAEG;IACH,OAAO;IAMP;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM;IAMtB;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE;IAcnB;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;IAyBzC;;OAEG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM;CAGpB;AAED,eAAO,MAAM,MAAM,QAAe,CAAC"}
|