@risingwave/wavelet-cli 0.1.1 → 0.1.3

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 +1 @@
1
- {"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../src/config-loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD,wBAAsB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAe3E"}
1
+ {"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../src/config-loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD,wBAAsB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAY3E"}
@@ -1,13 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadConfig = loadConfig;
4
- const node_url_1 = require("node:url");
5
4
  const node_path_1 = require("node:path");
5
+ const node_child_process_1 = require("node:child_process");
6
6
  async function loadConfig(configPath) {
7
7
  const abs = (0, node_path_1.resolve)(configPath);
8
- const mod = await import((0, node_url_1.pathToFileURL)(abs).href);
9
- const config = mod.default ?? mod;
10
- if (!config.database) {
8
+ // For .ts files, use tsx to evaluate the config
9
+ if (abs.endsWith('.ts')) {
10
+ return loadTsConfig(abs);
11
+ }
12
+ // For .js/.mjs files, use dynamic import directly
13
+ const { pathToFileURL } = await import('node:url');
14
+ const mod = await import(pathToFileURL(abs).href);
15
+ return unwrapConfig(mod);
16
+ }
17
+ function loadTsConfig(absPath) {
18
+ // Use tsx to evaluate the TypeScript config and extract the result as JSON
19
+ const script = `
20
+ import('${absPath}').then(mod => {
21
+ let config = mod.default ?? mod;
22
+ if (config && typeof config === 'object' && 'default' in config) config = config.default;
23
+ process.stdout.write(JSON.stringify(config));
24
+ }).catch(err => {
25
+ process.stderr.write(err.message);
26
+ process.exit(1);
27
+ });
28
+ `;
29
+ try {
30
+ const result = (0, node_child_process_1.execSync)(`npx tsx -e "${script.replace(/"/g, '\\"')}"`, {
31
+ cwd: (0, node_path_1.resolve)(absPath, '..'),
32
+ encoding: 'utf-8',
33
+ timeout: 15000,
34
+ stdio: ['pipe', 'pipe', 'pipe'],
35
+ });
36
+ const config = JSON.parse(result);
37
+ if (!config || !config.database) {
38
+ throw new Error('Config missing database field');
39
+ }
40
+ return config;
41
+ }
42
+ catch (err) {
43
+ throw new Error(`Failed to load ${absPath}.\n` +
44
+ `Make sure tsx is installed: npm install tsx\n` +
45
+ `Error: ${err.stderr || err.message}`);
46
+ }
47
+ }
48
+ function unwrapConfig(mod) {
49
+ let config = mod.default ?? mod;
50
+ if (config && typeof config === 'object' && 'default' in config) {
51
+ config = config.default;
52
+ }
53
+ if (!config || !config.database) {
11
54
  throw new Error(`wavelet.config.ts must export a config with a 'database' field.\n` +
12
55
  `Example:\n` +
13
56
  ` import { defineConfig } from '@risingwave/wavelet'\n` +
@@ -1 +1 @@
1
- {"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../src/config-loader.ts"],"names":[],"mappings":";;AAIA,gCAeC;AAnBD,uCAAwC;AACxC,yCAAmC;AAG5B,KAAK,UAAU,UAAU,CAAC,UAAkB;IACjD,MAAM,GAAG,GAAG,IAAA,mBAAO,EAAC,UAAU,CAAC,CAAA;IAC/B,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAA,wBAAa,EAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAA;IACjD,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAA;IAEjC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,mEAAmE;YACnE,YAAY;YACZ,wDAAwD;YACxD,+DAA+D,CAChE,CAAA;IACH,CAAC;IAED,OAAO,MAAM,CA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CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,kBAAkB,OAAO,KAAK;YAC9B,+CAA+C;YAC/C,UAAU,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,CACtC,CAAA;IACH,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,GAAQ;IAC5B,IAAI,MAAM,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAA;IAC/B,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;QAChE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAA;IACzB,CAAC;IAED,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,mEAAmE;YACnE,YAAY;YACZ,wDAAwD;YACxD,+DAA+D,CAChE,CAAA;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@risingwave/wavelet-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Wavelet CLI - manage views, generate types, run dev server",
5
5
  "bin": {
6
6
  "wavelet": "./dist/index.js"
@@ -10,12 +10,12 @@
10
10
  "dev": "tsx src/index.ts"
11
11
  },
12
12
  "dependencies": {
13
- "@risingwave/wavelet": "0.1.1",
14
- "@risingwave/wavelet-server": "0.1.1",
15
- "pg": "^8.13.0"
13
+ "@risingwave/wavelet": "0.1.3",
14
+ "@risingwave/wavelet-server": "0.1.3",
15
+ "pg": "^8.13.0",
16
+ "tsx": "^4.0.0"
16
17
  },
17
18
  "devDependencies": {
18
- "tsx": "^4.0.0",
19
19
  "typescript": "^5.7.0",
20
20
  "@types/pg": "^8.11.0"
21
21
  },
@@ -1,13 +1,62 @@
1
- import { pathToFileURL } from 'node:url'
2
1
  import { resolve } from 'node:path'
2
+ import { execSync } from 'node:child_process'
3
3
  import type { WaveletConfig } from '@risingwave/wavelet'
4
4
 
5
5
  export async function loadConfig(configPath: string): Promise<WaveletConfig> {
6
6
  const abs = resolve(configPath)
7
+
8
+ // For .ts files, use tsx to evaluate the config
9
+ if (abs.endsWith('.ts')) {
10
+ return loadTsConfig(abs)
11
+ }
12
+
13
+ // For .js/.mjs files, use dynamic import directly
14
+ const { pathToFileURL } = await import('node:url')
7
15
  const mod = await import(pathToFileURL(abs).href)
8
- const config = mod.default ?? mod
16
+ return unwrapConfig(mod)
17
+ }
18
+
19
+ function loadTsConfig(absPath: string): WaveletConfig {
20
+ // Use tsx to evaluate the TypeScript config and extract the result as JSON
21
+ const script = `
22
+ import('${absPath}').then(mod => {
23
+ let config = mod.default ?? mod;
24
+ if (config && typeof config === 'object' && 'default' in config) config = config.default;
25
+ process.stdout.write(JSON.stringify(config));
26
+ }).catch(err => {
27
+ process.stderr.write(err.message);
28
+ process.exit(1);
29
+ });
30
+ `
31
+
32
+ try {
33
+ const result = execSync(`npx tsx -e "${script.replace(/"/g, '\\"')}"`, {
34
+ cwd: resolve(absPath, '..'),
35
+ encoding: 'utf-8',
36
+ timeout: 15000,
37
+ stdio: ['pipe', 'pipe', 'pipe'],
38
+ })
39
+ const config = JSON.parse(result)
40
+ if (!config || !config.database) {
41
+ throw new Error('Config missing database field')
42
+ }
43
+ return config
44
+ } catch (err: any) {
45
+ throw new Error(
46
+ `Failed to load ${absPath}.\n` +
47
+ `Make sure tsx is installed: npm install tsx\n` +
48
+ `Error: ${err.stderr || err.message}`
49
+ )
50
+ }
51
+ }
52
+
53
+ function unwrapConfig(mod: any): WaveletConfig {
54
+ let config = mod.default ?? mod
55
+ if (config && typeof config === 'object' && 'default' in config) {
56
+ config = config.default
57
+ }
9
58
 
10
- if (!config.database) {
59
+ if (!config || !config.database) {
11
60
  throw new Error(
12
61
  `wavelet.config.ts must export a config with a 'database' field.\n` +
13
62
  `Example:\n` +