@hypequery/cli 0.0.1 → 0.0.2

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.
@@ -1,14 +1,3 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -45,23 +34,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
35
  }
47
36
  };
48
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
- if (ar || !(i in from)) {
51
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
- ar[i] = from[i];
53
- }
54
- }
55
- return to.concat(ar || Array.prototype.slice.call(from));
56
- };
57
37
  import { pathToFileURL } from 'node:url';
58
- import { spawn } from 'node:child_process';
59
38
  import { access } from 'node:fs/promises';
60
39
  import path from 'node:path';
40
+ import { ensureTypeScriptRuntime } from './ensure-ts-runtime.js';
41
+ var TYPESCRIPT_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts']);
61
42
  export function loadApiModule(modulePath) {
62
43
  return __awaiter(this, void 0, void 0, function () {
63
- var resolved, _a, relativePath, isTypeScript, _b, child, moduleUrl, mod, error_1, relativePath, api, relativePath, availableExports;
64
- var _c;
44
+ var resolved, _a, relativePath, extension, isTypeScript, error_1, moduleUrl, mod, error_2, relativePath, api, relativePath, availableExports;
45
+ var _b, _c;
65
46
  return __generator(this, function (_d) {
66
47
  switch (_d.label) {
67
48
  case 0:
@@ -81,57 +62,41 @@ export function loadApiModule(modulePath) {
81
62
  "You can specify a different file with:\n" +
82
63
  " hypequery dev path/to/your/queries.ts");
83
64
  case 4:
84
- isTypeScript = resolved.endsWith('.ts') || resolved.endsWith('.mts') || resolved.endsWith('.cts');
85
- if (!(isTypeScript && !process.env.TSX_LOADED)) return [3 /*break*/, 9];
65
+ extension = path.extname(resolved).toLowerCase();
66
+ isTypeScript = TYPESCRIPT_EXTENSIONS.has(extension);
67
+ if (!isTypeScript) return [3 /*break*/, 8];
86
68
  _d.label = 5;
87
69
  case 5:
88
70
  _d.trys.push([5, 7, , 8]);
89
- // @ts-ignore - tsx module might not have types
90
- return [4 /*yield*/, import('tsx/esm')];
71
+ return [4 /*yield*/, ensureTypeScriptRuntime()];
91
72
  case 6:
92
- // @ts-ignore - tsx module might not have types
93
73
  _d.sent();
94
74
  return [3 /*break*/, 8];
95
75
  case 7:
96
- _b = _d.sent();
97
- throw new Error("To run TypeScript files directly, install tsx:\n npm install -D tsx\n\nOr compile your TypeScript first and use the .js file instead.");
76
+ error_1 = _d.sent();
77
+ throw new Error("Failed to load TypeScript support. This should never happen because the CLI bundles tsx.\n" +
78
+ "Original error: ".concat((_b = error_1 === null || error_1 === void 0 ? void 0 : error_1.message) !== null && _b !== void 0 ? _b : error_1));
98
79
  case 8:
99
- // Re-exec the current command with tsx
100
- console.error('\n⚠️ TypeScript detected. Restarting with tsx...\n');
101
- child = spawn('npx', __spreadArray(['tsx'], process.argv.slice(1), true), {
102
- stdio: 'inherit',
103
- env: __assign(__assign({}, process.env), { TSX_LOADED: 'true' }),
104
- });
105
- child.on('exit', function (code) {
106
- process.exit(code || 0);
107
- });
108
- child.on('error', function (error) {
109
- console.error('Failed to restart with tsx:', error);
110
- process.exit(1);
111
- });
112
- // Return a never-resolving promise since we're exiting
113
- return [2 /*return*/, new Promise(function () { })];
114
- case 9:
115
80
  moduleUrl = "".concat(pathToFileURL(resolved).href, "?t=").concat(Date.now());
116
- _d.label = 10;
117
- case 10:
118
- _d.trys.push([10, 12, , 13]);
81
+ _d.label = 9;
82
+ case 9:
83
+ _d.trys.push([9, 11, , 12]);
119
84
  return [4 /*yield*/, import(moduleUrl)];
120
- case 11:
85
+ case 10:
121
86
  mod = _d.sent();
122
- return [3 /*break*/, 13];
123
- case 12:
124
- error_1 = _d.sent();
87
+ return [3 /*break*/, 12];
88
+ case 11:
89
+ error_2 = _d.sent();
125
90
  relativePath = path.relative(process.cwd(), resolved);
126
91
  throw new Error("Failed to load module: ".concat(relativePath, "\n\n") +
127
- "Error: ".concat(error_1.message, "\n\n") +
128
- (error_1.code === 'ERR_MODULE_NOT_FOUND'
92
+ "Error: ".concat(error_2.message, "\n\n") +
93
+ (error_2.code === 'ERR_MODULE_NOT_FOUND'
129
94
  ? "This usually means:\n" +
130
95
  " \u2022 A dependency is missing (run 'npm install')\n" +
131
96
  " \u2022 An import path is incorrect\n"
132
97
  : "") +
133
- (error_1.stack ? "\nStack trace:\n".concat(error_1.stack, "\n") : ''));
134
- case 13:
98
+ (error_2.stack ? "\nStack trace:\n".concat(error_2.stack, "\n") : ''));
99
+ case 12:
135
100
  api = (_c = mod.api) !== null && _c !== void 0 ? _c : mod.default;
136
101
  if (!api || typeof api.handler !== 'function') {
137
102
  relativePath = path.relative(process.cwd(), resolved);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypequery/cli",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Command-line interface for Hypequery",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -11,30 +11,28 @@
11
11
  "dist"
12
12
  ],
13
13
  "dependencies": {
14
+ "@clickhouse/client": "^1.16.0",
14
15
  "chalk": "^5.3.0",
15
16
  "commander": "^12.0.0",
17
+ "dotenv": "^16.4.7",
16
18
  "open": "^10.0.0",
17
19
  "ora": "^8.0.1",
18
- "prompts": "^2.4.2"
20
+ "prompts": "^2.4.2",
21
+ "tsx": "^4.19.2"
19
22
  },
20
23
  "peerDependencies": {
21
24
  "@hypequery/clickhouse": "*",
22
- "@hypequery/serve": "*",
23
- "tsx": "^4.0.0"
25
+ "@hypequery/serve": "*"
24
26
  },
25
27
  "peerDependenciesMeta": {
26
28
  "@hypequery/clickhouse": {
27
29
  "optional": true
28
- },
29
- "tsx": {
30
- "optional": true
31
30
  }
32
31
  },
33
32
  "devDependencies": {
34
33
  "@types/node": "^20.11.30",
35
34
  "@types/prompts": "^2.4.9",
36
35
  "@vitest/coverage-v8": "^2.1.6",
37
- "tsx": "^4.19.2",
38
36
  "typescript": "^5.7.3",
39
37
  "vitest": "^2.1.6",
40
38
  "@hypequery/clickhouse": "1.4.1",