@geekmidas/cli 0.0.9 → 0.0.10

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/README.md CHANGED
@@ -618,6 +618,39 @@ jobs:
618
618
  3. **Import errors**: Verify your environment parser and logger paths are correct
619
619
  4. **TypeScript errors**: Ensure your endpoints are properly typed
620
620
 
621
+ ### Working with Different Directories
622
+
623
+ When using the `--cwd` option to run the CLI from a different directory, TypeScript configuration (tsconfig.json) is resolved from the directory where the CLI is invoked, not from the target directory. This can cause issues with path resolution and type checking.
624
+
625
+ **Workarounds:**
626
+
627
+ 1. **Run from the target directory** (recommended):
628
+ ```bash
629
+ cd /path/to/project && gkm build
630
+ ```
631
+
632
+ 2. **Use TS_NODE_PROJECT environment variable**:
633
+ ```bash
634
+ TS_NODE_PROJECT=/path/to/project/tsconfig.json gkm build --cwd /path/to/project
635
+ ```
636
+
637
+ 3. **Create a wrapper script**:
638
+ ```bash
639
+ #!/bin/bash
640
+ # gkm-wrapper.sh
641
+ cd "$1" && shift && gkm "$@"
642
+ ```
643
+
644
+ Then use:
645
+ ```bash
646
+ ./gkm-wrapper.sh /path/to/project build --provider server
647
+ ```
648
+
649
+ 4. **Use npx with explicit tsx configuration**:
650
+ ```bash
651
+ cd /path/to/project && npx tsx --tsconfig ./tsconfig.json node_modules/.bin/gkm build
652
+ ```
653
+
621
654
  ### Debug Mode
622
655
 
623
656
  Enable verbose logging by setting the environment variable:
@@ -1,8 +1,6 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_config = require('./config-D-b45V57.cjs');
2
+ const require_config = require('./config-D8AyiwBU.cjs');
3
3
  const require_loadEndpoints = require('./loadEndpoints-CYFwuPZr.cjs');
4
- const require_tsconfig = require('./tsconfig-83amrDAp.cjs');
5
- const require_pathResolver = require('./pathResolver-B6y4yoWk.cjs');
6
4
  const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
7
5
  const path = require_chunk.__toESM(require("path"));
8
6
 
@@ -13,8 +11,6 @@ async function buildCommand(options) {
13
11
  const config = await require_config.loadConfig();
14
12
  logger.log(`Loading routes from: ${config.routes}`);
15
13
  logger.log(`Using envParser: ${config.envParser}`);
16
- const tsConfig = config.tsconfig ? require_tsconfig.loadTsConfig(config.tsconfig) : require_tsconfig.loadTsConfig();
17
- if (tsConfig) logger.log(`Using TypeScript config from: ${tsConfig.configPath}`);
18
14
  const [envParserPath, envParserName] = config.envParser.split("#");
19
15
  const envParserImportPattern = !envParserName ? "envParser" : envParserName === "envParser" ? "{ envParser }" : `{ ${envParserName} as envParser }`;
20
16
  const [loggerPath, loggerName] = config.logger.split("#");
@@ -44,7 +40,7 @@ async function buildCommand(options) {
44
40
  await (0, node_fs_promises.mkdir)(outputDir, { recursive: true });
45
41
  logger.log(`\nGenerating handlers for provider: ${provider}`);
46
42
  if (provider === "server") {
47
- const serverFile = await generateServerFile(outputDir, allEndpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern, tsConfig);
43
+ const serverFile = await generateServerFile(outputDir, allEndpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern);
48
44
  routes.push({
49
45
  path: "*",
50
46
  method: "ALL",
@@ -52,7 +48,7 @@ async function buildCommand(options) {
52
48
  });
53
49
  logger.log(`Generated server app with ${allEndpoints.length} endpoints`);
54
50
  } else for (const { file, exportName, routeInfo } of allEndpoints) {
55
- const handlerFile = await generateHandlerFile(outputDir, file, exportName, provider, routeInfo, envParserPath, envParserImportPattern, tsConfig);
51
+ const handlerFile = await generateHandlerFile(outputDir, file, exportName, provider, routeInfo, envParserPath, envParserImportPattern);
56
52
  routes.push({
57
53
  ...routeInfo,
58
54
  handler: (0, path.relative)(process.cwd(), handlerFile).replace(/\.ts$/, ".handler")
@@ -66,23 +62,23 @@ async function buildCommand(options) {
66
62
  logger.log(`Routes manifest: ${(0, path.relative)(process.cwd(), manifestPath)}`);
67
63
  }
68
64
  }
69
- async function generateServerFile(outputDir, endpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern, tsConfig) {
65
+ async function generateServerFile(outputDir, endpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern) {
70
66
  const serverFileName = "app.ts";
71
67
  const serverPath = (0, path.join)(outputDir, serverFileName);
72
68
  const importsByFile = /* @__PURE__ */ new Map();
73
69
  for (const { file, exportName } of endpoints) {
74
- const absoluteFilePath = (0, path.join)(process.cwd(), file);
75
- const importPath = require_pathResolver.resolveModuleSpecifier(serverPath, absoluteFilePath, tsConfig);
70
+ const relativePath = (0, path.relative)((0, path.dirname)(serverPath), file);
71
+ const importPath = relativePath.replace(/\.ts$/, ".js");
76
72
  if (!importsByFile.has(importPath)) importsByFile.set(importPath, []);
77
73
  importsByFile.get(importPath).push(exportName);
78
74
  }
79
- const relativeEnvParserPath = require_pathResolver.resolveModuleSpecifier(serverPath, envParserPath, tsConfig);
80
- const relativeLoggerPath = require_pathResolver.resolveModuleSpecifier(serverPath, loggerPath, tsConfig);
75
+ const relativeEnvParserPath = (0, path.relative)((0, path.dirname)(serverPath), envParserPath);
76
+ const relativeLoggerPath = (0, path.relative)((0, path.dirname)(serverPath), loggerPath);
81
77
  const imports = Array.from(importsByFile.entries()).map(([importPath, exports$1]) => `import { ${exports$1.join(", ")} } from '${importPath}';`).join("\n");
82
78
  const allExportNames = endpoints.map(({ exportName }) => exportName);
83
79
  const content = `import { HonoEndpoint } from '@geekmidas/api/hono';
84
80
  import { Endpoint } from '@geekmidas/api/server';
85
- import { HermodServiceDiscovery } from '@geekmidas/api/services';
81
+ import { ServiceDiscovery } from '@geekmidas/api/services';
86
82
  import { Hono } from 'hono';
87
83
  import ${envParserImportPattern} from '${relativeEnvParserPath}';
88
84
  import ${loggerImportPattern} from '${relativeLoggerPath}';
@@ -95,7 +91,7 @@ export function createApp(app?: Hono): Hono {
95
91
  ${allExportNames.join(",\n ")}
96
92
  ];
97
93
 
98
- const serviceDiscovery = HermodServiceDiscovery.getInstance(
94
+ const serviceDiscovery = ServiceDiscovery.getInstance(
99
95
  logger,
100
96
  envParser
101
97
  );
@@ -111,12 +107,12 @@ export default createApp;
111
107
  await (0, node_fs_promises.writeFile)(serverPath, content);
112
108
  return serverPath;
113
109
  }
114
- async function generateHandlerFile(outputDir, sourceFile, exportName, provider, _routeInfo, envParserPath, envParserImportPattern, tsConfig) {
110
+ async function generateHandlerFile(outputDir, sourceFile, exportName, provider, _routeInfo, envParserPath, envParserImportPattern) {
115
111
  const handlerFileName = `${exportName}.ts`;
116
112
  const handlerPath = (0, path.join)(outputDir, handlerFileName);
117
- const absoluteSourcePath = (0, path.join)(process.cwd(), sourceFile);
118
- const importPath = require_pathResolver.resolveModuleSpecifier(handlerPath, absoluteSourcePath, tsConfig);
119
- const relativeEnvParserPath = require_pathResolver.resolveModuleSpecifier(handlerPath, envParserPath, tsConfig);
113
+ const relativePath = (0, path.relative)((0, path.dirname)(handlerPath), sourceFile);
114
+ const importPath = relativePath.replace(/\.ts$/, ".js");
115
+ const relativeEnvParserPath = (0, path.relative)((0, path.dirname)(handlerPath), envParserPath);
120
116
  let content;
121
117
  switch (provider) {
122
118
  case "aws-apigatewayv1":
@@ -1,9 +1,7 @@
1
- import { loadConfig } from "./config-Nd751N3o.mjs";
1
+ import { loadConfig } from "./config-DV1Lwdkx.mjs";
2
2
  import { loadEndpoints } from "./loadEndpoints-BL8q2rTO.mjs";
3
- import { loadTsConfig } from "./tsconfig-BtO228Cz.mjs";
4
- import { resolveModuleSpecifier } from "./pathResolver-DaMnbf26.mjs";
5
3
  import { mkdir, writeFile } from "node:fs/promises";
6
- import { join, relative } from "path";
4
+ import { dirname, join, relative } from "path";
7
5
 
8
6
  //#region src/build.ts
9
7
  const logger = console;
@@ -12,8 +10,6 @@ async function buildCommand(options) {
12
10
  const config = await loadConfig();
13
11
  logger.log(`Loading routes from: ${config.routes}`);
14
12
  logger.log(`Using envParser: ${config.envParser}`);
15
- const tsConfig = config.tsconfig ? loadTsConfig(config.tsconfig) : loadTsConfig();
16
- if (tsConfig) logger.log(`Using TypeScript config from: ${tsConfig.configPath}`);
17
13
  const [envParserPath, envParserName] = config.envParser.split("#");
18
14
  const envParserImportPattern = !envParserName ? "envParser" : envParserName === "envParser" ? "{ envParser }" : `{ ${envParserName} as envParser }`;
19
15
  const [loggerPath, loggerName] = config.logger.split("#");
@@ -43,7 +39,7 @@ async function buildCommand(options) {
43
39
  await mkdir(outputDir, { recursive: true });
44
40
  logger.log(`\nGenerating handlers for provider: ${provider}`);
45
41
  if (provider === "server") {
46
- const serverFile = await generateServerFile(outputDir, allEndpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern, tsConfig);
42
+ const serverFile = await generateServerFile(outputDir, allEndpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern);
47
43
  routes.push({
48
44
  path: "*",
49
45
  method: "ALL",
@@ -51,7 +47,7 @@ async function buildCommand(options) {
51
47
  });
52
48
  logger.log(`Generated server app with ${allEndpoints.length} endpoints`);
53
49
  } else for (const { file, exportName, routeInfo } of allEndpoints) {
54
- const handlerFile = await generateHandlerFile(outputDir, file, exportName, provider, routeInfo, envParserPath, envParserImportPattern, tsConfig);
50
+ const handlerFile = await generateHandlerFile(outputDir, file, exportName, provider, routeInfo, envParserPath, envParserImportPattern);
55
51
  routes.push({
56
52
  ...routeInfo,
57
53
  handler: relative(process.cwd(), handlerFile).replace(/\.ts$/, ".handler")
@@ -65,23 +61,23 @@ async function buildCommand(options) {
65
61
  logger.log(`Routes manifest: ${relative(process.cwd(), manifestPath)}`);
66
62
  }
67
63
  }
68
- async function generateServerFile(outputDir, endpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern, tsConfig) {
64
+ async function generateServerFile(outputDir, endpoints, envParserPath, envParserImportPattern, loggerPath, loggerImportPattern) {
69
65
  const serverFileName = "app.ts";
70
66
  const serverPath = join(outputDir, serverFileName);
71
67
  const importsByFile = /* @__PURE__ */ new Map();
72
68
  for (const { file, exportName } of endpoints) {
73
- const absoluteFilePath = join(process.cwd(), file);
74
- const importPath = resolveModuleSpecifier(serverPath, absoluteFilePath, tsConfig);
69
+ const relativePath = relative(dirname(serverPath), file);
70
+ const importPath = relativePath.replace(/\.ts$/, ".js");
75
71
  if (!importsByFile.has(importPath)) importsByFile.set(importPath, []);
76
72
  importsByFile.get(importPath).push(exportName);
77
73
  }
78
- const relativeEnvParserPath = resolveModuleSpecifier(serverPath, envParserPath, tsConfig);
79
- const relativeLoggerPath = resolveModuleSpecifier(serverPath, loggerPath, tsConfig);
74
+ const relativeEnvParserPath = relative(dirname(serverPath), envParserPath);
75
+ const relativeLoggerPath = relative(dirname(serverPath), loggerPath);
80
76
  const imports = Array.from(importsByFile.entries()).map(([importPath, exports]) => `import { ${exports.join(", ")} } from '${importPath}';`).join("\n");
81
77
  const allExportNames = endpoints.map(({ exportName }) => exportName);
82
78
  const content = `import { HonoEndpoint } from '@geekmidas/api/hono';
83
79
  import { Endpoint } from '@geekmidas/api/server';
84
- import { HermodServiceDiscovery } from '@geekmidas/api/services';
80
+ import { ServiceDiscovery } from '@geekmidas/api/services';
85
81
  import { Hono } from 'hono';
86
82
  import ${envParserImportPattern} from '${relativeEnvParserPath}';
87
83
  import ${loggerImportPattern} from '${relativeLoggerPath}';
@@ -94,7 +90,7 @@ export function createApp(app?: Hono): Hono {
94
90
  ${allExportNames.join(",\n ")}
95
91
  ];
96
92
 
97
- const serviceDiscovery = HermodServiceDiscovery.getInstance(
93
+ const serviceDiscovery = ServiceDiscovery.getInstance(
98
94
  logger,
99
95
  envParser
100
96
  );
@@ -110,12 +106,12 @@ export default createApp;
110
106
  await writeFile(serverPath, content);
111
107
  return serverPath;
112
108
  }
113
- async function generateHandlerFile(outputDir, sourceFile, exportName, provider, _routeInfo, envParserPath, envParserImportPattern, tsConfig) {
109
+ async function generateHandlerFile(outputDir, sourceFile, exportName, provider, _routeInfo, envParserPath, envParserImportPattern) {
114
110
  const handlerFileName = `${exportName}.ts`;
115
111
  const handlerPath = join(outputDir, handlerFileName);
116
- const absoluteSourcePath = join(process.cwd(), sourceFile);
117
- const importPath = resolveModuleSpecifier(handlerPath, absoluteSourcePath, tsConfig);
118
- const relativeEnvParserPath = resolveModuleSpecifier(handlerPath, envParserPath, tsConfig);
112
+ const relativePath = relative(dirname(handlerPath), sourceFile);
113
+ const importPath = relativePath.replace(/\.ts$/, ".js");
114
+ const relativeEnvParserPath = relative(dirname(handlerPath), envParserPath);
119
115
  let content;
120
116
  switch (provider) {
121
117
  case "aws-apigatewayv1":
package/dist/build.cjs CHANGED
@@ -1,7 +1,5 @@
1
- require('./config-D-b45V57.cjs');
1
+ require('./config-D8AyiwBU.cjs');
2
2
  require('./loadEndpoints-CYFwuPZr.cjs');
3
- require('./tsconfig-83amrDAp.cjs');
4
- require('./pathResolver-B6y4yoWk.cjs');
5
- const require_build = require('./build-DGJAXiy_.cjs');
3
+ const require_build = require('./build-GTFSYaDw.cjs');
6
4
 
7
5
  exports.buildCommand = require_build.buildCommand;
package/dist/build.mjs CHANGED
@@ -1,7 +1,5 @@
1
- import "./config-Nd751N3o.mjs";
1
+ import "./config-DV1Lwdkx.mjs";
2
2
  import "./loadEndpoints-BL8q2rTO.mjs";
3
- import "./tsconfig-BtO228Cz.mjs";
4
- import "./pathResolver-DaMnbf26.mjs";
5
- import { buildCommand } from "./build-CE77jmn4.mjs";
3
+ import { buildCommand } from "./build-fWeaXigm.mjs";
6
4
 
7
5
  export { buildCommand };
@@ -1,10 +1,50 @@
1
- import { buildCommand } from "./build-CE77jmn4.mjs";
2
- import { openapiCommand } from "./openapi-UIMy3Lzi.mjs";
1
+ import { buildCommand } from "./build-fWeaXigm.mjs";
2
+ import { openapiCommand } from "./openapi-BxI6zE0N.mjs";
3
3
  import { Command } from "commander";
4
4
 
5
+ //#region package.json
6
+ var name = "@geekmidas/cli";
7
+ var version = "0.0.10";
8
+ var private$1 = false;
9
+ var type = "module";
10
+ var bin = { "gkm": "./src/index.ts" };
11
+ var exports = { ".": {
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.cjs",
14
+ "types": "./src/index.ts"
15
+ } };
16
+ var publishConfig = {
17
+ "registry": "https://registry.npmjs.org/",
18
+ "access": "public"
19
+ };
20
+ var dependencies = {
21
+ "commander": "~14.0.0",
22
+ "lodash.get": "~4.4.2",
23
+ "lodash.set": "~4.3.2",
24
+ "zod": "~3.25.67",
25
+ "fast-glob": "~3.3.3",
26
+ "@geekmidas/api": "workspace:*"
27
+ };
28
+ var devDependencies = {
29
+ "@types/lodash.get": "~4.4.9",
30
+ "@types/lodash.set": "~4.3.9"
31
+ };
32
+ var package_default = {
33
+ name,
34
+ version,
35
+ private: private$1,
36
+ type,
37
+ bin,
38
+ exports,
39
+ publishConfig,
40
+ dependencies,
41
+ devDependencies
42
+ };
43
+
44
+ //#endregion
5
45
  //#region src/cli.ts
6
46
  const program = new Command();
7
- program.name("gkm").description("GeekMidas backend framework CLI").version("0.0.2").option("--cwd <path>", "Change working directory");
47
+ program.name("gkm").description("GeekMidas backend framework CLI").version(package_default.version).option("--cwd <path>", "Change working directory");
8
48
  program.command("build").description("Build API handlers from endpoints").option("--providers <providers>", "Target providers for generated handlers (comma-separated)", "aws-apigatewayv1").action(async (options) => {
9
49
  try {
10
50
  const globalOptions = program.opts();
@@ -1,11 +1,51 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_build = require('./build-DGJAXiy_.cjs');
3
- const require_openapi = require('./openapi-C84tyelp.cjs');
2
+ const require_build = require('./build-GTFSYaDw.cjs');
3
+ const require_openapi = require('./openapi-BX7ba0w0.cjs');
4
4
  const commander = require_chunk.__toESM(require("commander"));
5
5
 
6
+ //#region package.json
7
+ var name = "@geekmidas/cli";
8
+ var version = "0.0.10";
9
+ var private$1 = false;
10
+ var type = "module";
11
+ var bin = { "gkm": "./src/index.ts" };
12
+ var exports$1 = { ".": {
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.cjs",
15
+ "types": "./src/index.ts"
16
+ } };
17
+ var publishConfig = {
18
+ "registry": "https://registry.npmjs.org/",
19
+ "access": "public"
20
+ };
21
+ var dependencies = {
22
+ "commander": "~14.0.0",
23
+ "lodash.get": "~4.4.2",
24
+ "lodash.set": "~4.3.2",
25
+ "zod": "~3.25.67",
26
+ "fast-glob": "~3.3.3",
27
+ "@geekmidas/api": "workspace:*"
28
+ };
29
+ var devDependencies = {
30
+ "@types/lodash.get": "~4.4.9",
31
+ "@types/lodash.set": "~4.3.9"
32
+ };
33
+ var package_default = {
34
+ name,
35
+ version,
36
+ private: private$1,
37
+ type,
38
+ bin,
39
+ exports: exports$1,
40
+ publishConfig,
41
+ dependencies,
42
+ devDependencies
43
+ };
44
+
45
+ //#endregion
6
46
  //#region src/cli.ts
7
47
  const program = new commander.Command();
8
- program.name("gkm").description("GeekMidas backend framework CLI").version("0.0.2").option("--cwd <path>", "Change working directory");
48
+ program.name("gkm").description("GeekMidas backend framework CLI").version(package_default.version).option("--cwd <path>", "Change working directory");
9
49
  program.command("build").description("Build API handlers from endpoints").option("--providers <providers>", "Target providers for generated handlers (comma-separated)", "aws-apigatewayv1").action(async (options) => {
10
50
  try {
11
51
  const globalOptions = program.opts();
package/dist/cli.cjs CHANGED
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env node
2
- require('./config-D-b45V57.cjs');
2
+ require('./config-D8AyiwBU.cjs');
3
3
  require('./loadEndpoints-CYFwuPZr.cjs');
4
- require('./tsconfig-83amrDAp.cjs');
5
- require('./pathResolver-B6y4yoWk.cjs');
6
- require('./build-DGJAXiy_.cjs');
7
- require('./openapi-C84tyelp.cjs');
8
- require('./cli-aXPCpkGS.cjs');
4
+ require('./build-GTFSYaDw.cjs');
5
+ require('./cli-BFQ-Dso8.cjs');
6
+ require('./openapi-BX7ba0w0.cjs');
package/dist/cli.mjs CHANGED
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import "./config-Nd751N3o.mjs";
2
+ import "./config-DV1Lwdkx.mjs";
3
3
  import "./loadEndpoints-BL8q2rTO.mjs";
4
- import "./tsconfig-BtO228Cz.mjs";
5
- import "./pathResolver-DaMnbf26.mjs";
6
- import "./build-CE77jmn4.mjs";
7
- import "./openapi-UIMy3Lzi.mjs";
8
- import "./cli-CTfdNl5c.mjs";
4
+ import "./build-fWeaXigm.mjs";
5
+ import "./cli--DOGIUC5.mjs";
6
+ import "./openapi-BxI6zE0N.mjs";
@@ -0,0 +1,23 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const path = require_chunk.__toESM(require("path"));
3
+ const fs = require_chunk.__toESM(require("fs"));
4
+
5
+ //#region src/config.ts
6
+ async function loadConfig() {
7
+ const configPath = (0, path.join)(process.cwd(), "gkm.config.json");
8
+ if (!(0, fs.existsSync)(configPath)) throw new Error("gkm.config.json not found. Please create a configuration file.");
9
+ try {
10
+ const config = await import(configPath);
11
+ return config.default || config;
12
+ } catch (error) {
13
+ throw new Error(`Failed to load gkm.config.ts: ${error.message}`);
14
+ }
15
+ }
16
+
17
+ //#endregion
18
+ Object.defineProperty(exports, 'loadConfig', {
19
+ enumerable: true,
20
+ get: function () {
21
+ return loadConfig;
22
+ }
23
+ });
@@ -0,0 +1,17 @@
1
+ import { join } from "path";
2
+ import { existsSync } from "fs";
3
+
4
+ //#region src/config.ts
5
+ async function loadConfig() {
6
+ const configPath = join(process.cwd(), "gkm.config.json");
7
+ if (!existsSync(configPath)) throw new Error("gkm.config.json not found. Please create a configuration file.");
8
+ try {
9
+ const config = await import(configPath);
10
+ return config.default || config;
11
+ } catch (error) {
12
+ throw new Error(`Failed to load gkm.config.ts: ${error.message}`);
13
+ }
14
+ }
15
+
16
+ //#endregion
17
+ export { loadConfig };
package/dist/config.cjs CHANGED
@@ -1,3 +1,3 @@
1
- const require_config = require('./config-D-b45V57.cjs');
1
+ const require_config = require('./config-D8AyiwBU.cjs');
2
2
 
3
3
  exports.loadConfig = require_config.loadConfig;
package/dist/config.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { loadConfig } from "./config-Nd751N3o.mjs";
1
+ import { loadConfig } from "./config-DV1Lwdkx.mjs";
2
2
 
3
3
  export { loadConfig };
package/dist/index.cjs CHANGED
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env -S npx tsx
2
- require('./config-D-b45V57.cjs');
2
+ require('./config-D8AyiwBU.cjs');
3
3
  require('./loadEndpoints-CYFwuPZr.cjs');
4
- require('./tsconfig-83amrDAp.cjs');
5
- require('./pathResolver-B6y4yoWk.cjs');
6
- require('./build-DGJAXiy_.cjs');
7
- require('./openapi-C84tyelp.cjs');
8
- require('./cli-aXPCpkGS.cjs');
4
+ require('./build-GTFSYaDw.cjs');
5
+ require('./cli-BFQ-Dso8.cjs');
6
+ require('./openapi-BX7ba0w0.cjs');
package/dist/index.mjs CHANGED
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env -S npx tsx
2
- import "./config-Nd751N3o.mjs";
2
+ import "./config-DV1Lwdkx.mjs";
3
3
  import "./loadEndpoints-BL8q2rTO.mjs";
4
- import "./tsconfig-BtO228Cz.mjs";
5
- import "./pathResolver-DaMnbf26.mjs";
6
- import "./build-CE77jmn4.mjs";
7
- import "./openapi-UIMy3Lzi.mjs";
8
- import "./cli-CTfdNl5c.mjs";
4
+ import "./build-fWeaXigm.mjs";
5
+ import "./cli--DOGIUC5.mjs";
6
+ import "./openapi-BxI6zE0N.mjs";
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_config = require('./config-D-b45V57.cjs');
2
+ const require_config = require('./config-D8AyiwBU.cjs');
3
3
  const require_loadEndpoints = require('./loadEndpoints-CYFwuPZr.cjs');
4
4
  const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
5
5
  const __geekmidas_api_server = require_chunk.__toESM(require("@geekmidas/api/server"));
@@ -1,4 +1,4 @@
1
- import { loadConfig } from "./config-Nd751N3o.mjs";
1
+ import { loadConfig } from "./config-DV1Lwdkx.mjs";
2
2
  import { loadEndpoints } from "./loadEndpoints-BL8q2rTO.mjs";
3
3
  import { mkdir, writeFile } from "node:fs/promises";
4
4
  import { Endpoint } from "@geekmidas/api/server";
package/dist/openapi.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env -S npx tsx
2
- require('./config-D-b45V57.cjs');
2
+ require('./config-D8AyiwBU.cjs');
3
3
  require('./loadEndpoints-CYFwuPZr.cjs');
4
- const require_openapi = require('./openapi-C84tyelp.cjs');
4
+ const require_openapi = require('./openapi-BX7ba0w0.cjs');
5
5
 
6
6
  exports.openapiCommand = require_openapi.openapiCommand;
package/dist/openapi.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env -S npx tsx
2
- import "./config-Nd751N3o.mjs";
2
+ import "./config-DV1Lwdkx.mjs";
3
3
  import "./loadEndpoints-BL8q2rTO.mjs";
4
- import { openapiCommand } from "./openapi-UIMy3Lzi.mjs";
4
+ import { openapiCommand } from "./openapi-BxI6zE0N.mjs";
5
5
 
6
6
  export { openapiCommand };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/cli",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
@@ -19,11 +19,10 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "commander": "~14.0.0",
22
- "fast-glob": "~3.3.3",
23
22
  "lodash.get": "~4.4.2",
24
23
  "lodash.set": "~4.3.2",
25
- "typescript": "~5.8.3",
26
24
  "zod": "~3.25.67",
25
+ "fast-glob": "~3.3.3",
27
26
  "@geekmidas/api": "0.0.22"
28
27
  },
29
28
  "devDependencies": {
package/src/build.ts CHANGED
@@ -2,8 +2,6 @@ import { mkdir, writeFile } from 'node:fs/promises';
2
2
  import { dirname, join, relative } from 'path';
3
3
  import { loadConfig } from './config.js';
4
4
  import { loadEndpoints } from './loadEndpoints.js';
5
- import { loadTsConfig, getOutputPath } from './tsconfig.js';
6
- import { resolveModuleSpecifier } from './helpers/pathResolver.js';
7
5
  import type {
8
6
  BuildOptions,
9
7
  Provider,
@@ -19,14 +17,6 @@ export async function buildCommand(options: BuildOptions): Promise<void> {
19
17
  logger.log(`Loading routes from: ${config.routes}`);
20
18
  logger.log(`Using envParser: ${config.envParser}`);
21
19
 
22
- // Load tsconfig if available
23
- const tsConfig = config.tsconfig
24
- ? loadTsConfig(config.tsconfig)
25
- : loadTsConfig();
26
- if (tsConfig) {
27
- logger.log(`Using TypeScript config from: ${tsConfig.configPath}`);
28
- }
29
-
30
20
  // Parse envParser configuration
31
21
  const [envParserPath, envParserName] = config.envParser.split('#');
32
22
  const envParserImportPattern = !envParserName
@@ -90,7 +80,6 @@ export async function buildCommand(options: BuildOptions): Promise<void> {
90
80
  envParserImportPattern,
91
81
  loggerPath,
92
82
  loggerImportPattern,
93
- tsConfig,
94
83
  );
95
84
 
96
85
  routes.push({
@@ -111,7 +100,6 @@ export async function buildCommand(options: BuildOptions): Promise<void> {
111
100
  routeInfo,
112
101
  envParserPath,
113
102
  envParserImportPattern,
114
- tsConfig,
115
103
  );
116
104
 
117
105
  routes.push({
@@ -152,7 +140,6 @@ async function generateServerFile(
152
140
  envParserImportPattern: string,
153
141
  loggerPath: string,
154
142
  loggerImportPattern: string,
155
- tsConfig: ReturnType<typeof loadTsConfig>,
156
143
  ): Promise<string> {
157
144
  const serverFileName = 'app.ts';
158
145
  const serverPath = join(outputDir, serverFileName);
@@ -161,13 +148,8 @@ async function generateServerFile(
161
148
  const importsByFile = new Map<string, string[]>();
162
149
 
163
150
  for (const { file, exportName } of endpoints) {
164
- const absoluteFilePath = join(process.cwd(), file);
165
- // Use path resolver to handle tsconfig paths
166
- const importPath = resolveModuleSpecifier(
167
- serverPath,
168
- absoluteFilePath,
169
- tsConfig,
170
- );
151
+ const relativePath = relative(dirname(serverPath), file);
152
+ const importPath = relativePath.replace(/\.ts$/, '.js');
171
153
 
172
154
  if (!importsByFile.has(importPath)) {
173
155
  importsByFile.set(importPath, []);
@@ -175,16 +157,8 @@ async function generateServerFile(
175
157
  importsByFile.get(importPath)!.push(exportName);
176
158
  }
177
159
 
178
- const relativeEnvParserPath = resolveModuleSpecifier(
179
- serverPath,
180
- envParserPath,
181
- tsConfig,
182
- );
183
- const relativeLoggerPath = resolveModuleSpecifier(
184
- serverPath,
185
- loggerPath,
186
- tsConfig,
187
- );
160
+ const relativeEnvParserPath = relative(dirname(serverPath), envParserPath);
161
+ const relativeLoggerPath = relative(dirname(serverPath), loggerPath);
188
162
 
189
163
  // Generate import statements
190
164
  const imports = Array.from(importsByFile.entries())
@@ -198,7 +172,7 @@ async function generateServerFile(
198
172
 
199
173
  const content = `import { HonoEndpoint } from '@geekmidas/api/hono';
200
174
  import { Endpoint } from '@geekmidas/api/server';
201
- import { HermodServiceDiscovery } from '@geekmidas/api/services';
175
+ import { ServiceDiscovery } from '@geekmidas/api/services';
202
176
  import { Hono } from 'hono';
203
177
  import ${envParserImportPattern} from '${relativeEnvParserPath}';
204
178
  import ${loggerImportPattern} from '${relativeLoggerPath}';
@@ -211,7 +185,7 @@ export function createApp(app?: Hono): Hono {
211
185
  ${allExportNames.join(',\n ')}
212
186
  ];
213
187
 
214
- const serviceDiscovery = HermodServiceDiscovery.getInstance(
188
+ const serviceDiscovery = ServiceDiscovery.getInstance(
215
189
  logger,
216
190
  envParser
217
191
  );
@@ -237,24 +211,14 @@ async function generateHandlerFile(
237
211
  _routeInfo: RouteInfo,
238
212
  envParserPath: string,
239
213
  envParserImportPattern: string,
240
- tsConfig: ReturnType<typeof loadTsConfig>,
241
214
  ): Promise<string> {
242
215
  const handlerFileName = `${exportName}.ts`;
243
216
  const handlerPath = join(outputDir, handlerFileName);
244
217
 
245
- const absoluteSourcePath = join(process.cwd(), sourceFile);
246
- // Use path resolver to handle tsconfig paths
247
- const importPath = resolveModuleSpecifier(
248
- handlerPath,
249
- absoluteSourcePath,
250
- tsConfig,
251
- );
218
+ const relativePath = relative(dirname(handlerPath), sourceFile);
219
+ const importPath = relativePath.replace(/\.ts$/, '.js');
252
220
 
253
- const relativeEnvParserPath = resolveModuleSpecifier(
254
- handlerPath,
255
- envParserPath,
256
- tsConfig,
257
- );
221
+ const relativeEnvParserPath = relative(dirname(handlerPath), envParserPath);
258
222
 
259
223
  let content: string;
260
224
 
package/src/cli.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { Command } from 'commander';
4
+ import pkg from '../package.json' assert { type: 'json' };
4
5
  import { buildCommand } from './build.js';
5
6
  import { openapiCommand } from './openapi.js';
6
7
  import type { Provider } from './types.js';
@@ -10,7 +11,7 @@ const program = new Command();
10
11
  program
11
12
  .name('gkm')
12
13
  .description('GeekMidas backend framework CLI')
13
- .version('0.0.2')
14
+ .version(pkg.version)
14
15
  .option('--cwd <path>', 'Change working directory');
15
16
 
16
17
  program
package/src/config.ts CHANGED
@@ -1,44 +1,22 @@
1
1
  import { existsSync } from 'fs';
2
- import { join, extname } from 'path';
2
+ import { join } from 'path';
3
3
  import type { GkmConfig } from './types.js';
4
4
 
5
5
  export async function loadConfig(): Promise<GkmConfig> {
6
- const cwd = process.cwd();
6
+ const configPath = join(process.cwd(), 'gkm.config.json');
7
7
 
8
- // Try to find config file with different extensions
9
- const configExtensions = ['.ts', '.js', '.json'];
10
- let configPath: string | null = null;
11
-
12
- for (const ext of configExtensions) {
13
- const path = join(cwd, `gkm.config${ext}`);
14
- if (existsSync(path)) {
15
- configPath = path;
16
- break;
17
- }
18
- }
19
-
20
- if (!configPath) {
8
+ if (!existsSync(configPath)) {
21
9
  throw new Error(
22
- 'gkm.config.{ts,js,json} not found. Please create a configuration file.',
10
+ 'gkm.config.json not found. Please create a configuration file.',
23
11
  );
24
12
  }
25
13
 
26
14
  try {
27
- const ext = extname(configPath);
28
-
29
- // For TypeScript files, ensure tsx can handle them
30
- if (ext === '.ts') {
31
- // tsx handles TypeScript files automatically
32
- const config = await import(configPath);
33
- return config.default || config;
34
- }
35
-
36
- // For JS and JSON files
37
15
  const config = await import(configPath);
38
16
  return config.default || config;
39
17
  } catch (error) {
40
18
  throw new Error(
41
- `Failed to load ${configPath}: ${(error as Error).message}`,
19
+ `Failed to load gkm.config.ts: ${(error as Error).message}`,
42
20
  );
43
21
  }
44
22
  }
package/src/types.ts CHANGED
@@ -6,7 +6,6 @@ export interface GkmConfig {
6
6
  routes: Routes;
7
7
  envParser: string;
8
8
  logger: string;
9
- tsconfig?: string; // Optional path to tsconfig.json
10
9
  }
11
10
 
12
11
  export interface BuildOptions {
@@ -1,41 +0,0 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const path = require_chunk.__toESM(require("path"));
3
- const fs = require_chunk.__toESM(require("fs"));
4
-
5
- //#region src/config.ts
6
- async function loadConfig() {
7
- const cwd = process.cwd();
8
- const configExtensions = [
9
- ".ts",
10
- ".js",
11
- ".json"
12
- ];
13
- let configPath = null;
14
- for (const ext of configExtensions) {
15
- const path$1 = (0, path.join)(cwd, `gkm.config${ext}`);
16
- if ((0, fs.existsSync)(path$1)) {
17
- configPath = path$1;
18
- break;
19
- }
20
- }
21
- if (!configPath) throw new Error("gkm.config.{ts,js,json} not found. Please create a configuration file.");
22
- try {
23
- const ext = (0, path.extname)(configPath);
24
- if (ext === ".ts") {
25
- const config$1 = await import(configPath);
26
- return config$1.default || config$1;
27
- }
28
- const config = await import(configPath);
29
- return config.default || config;
30
- } catch (error) {
31
- throw new Error(`Failed to load ${configPath}: ${error.message}`);
32
- }
33
- }
34
-
35
- //#endregion
36
- Object.defineProperty(exports, 'loadConfig', {
37
- enumerable: true,
38
- get: function () {
39
- return loadConfig;
40
- }
41
- });
@@ -1,35 +0,0 @@
1
- import { extname, join } from "path";
2
- import { existsSync } from "fs";
3
-
4
- //#region src/config.ts
5
- async function loadConfig() {
6
- const cwd = process.cwd();
7
- const configExtensions = [
8
- ".ts",
9
- ".js",
10
- ".json"
11
- ];
12
- let configPath = null;
13
- for (const ext of configExtensions) {
14
- const path = join(cwd, `gkm.config${ext}`);
15
- if (existsSync(path)) {
16
- configPath = path;
17
- break;
18
- }
19
- }
20
- if (!configPath) throw new Error("gkm.config.{ts,js,json} not found. Please create a configuration file.");
21
- try {
22
- const ext = extname(configPath);
23
- if (ext === ".ts") {
24
- const config$1 = await import(configPath);
25
- return config$1.default || config$1;
26
- }
27
- const config = await import(configPath);
28
- return config.default || config;
29
- } catch (error) {
30
- throw new Error(`Failed to load ${configPath}: ${error.message}`);
31
- }
32
- }
33
-
34
- //#endregion
35
- export { loadConfig };
@@ -1,6 +0,0 @@
1
- require('../tsconfig-83amrDAp.cjs');
2
- const require_pathResolver = require('../pathResolver-B6y4yoWk.cjs');
3
-
4
- exports.convertToJsExtension = require_pathResolver.convertToJsExtension;
5
- exports.resolveImportPath = require_pathResolver.resolveImportPath;
6
- exports.resolveModuleSpecifier = require_pathResolver.resolveModuleSpecifier;
@@ -1,4 +0,0 @@
1
- import "../tsconfig-BtO228Cz.mjs";
2
- import { convertToJsExtension, resolveImportPath, resolveModuleSpecifier } from "../pathResolver-DaMnbf26.mjs";
3
-
4
- export { convertToJsExtension, resolveImportPath, resolveModuleSpecifier };
@@ -1,47 +0,0 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_tsconfig = require('./tsconfig-83amrDAp.cjs');
3
- const path = require_chunk.__toESM(require("path"));
4
-
5
- //#region src/helpers/pathResolver.ts
6
- /**
7
- * Resolve import paths considering TypeScript path mappings
8
- */
9
- function resolveImportPath(fromFile, toFile, tsConfig) {
10
- const resolvedToFile = tsConfig ? require_tsconfig.resolvePathMapping(toFile, tsConfig) : toFile;
11
- const relativePath = (0, path.relative)((0, path.dirname)(fromFile), resolvedToFile);
12
- if (!relativePath.startsWith(".")) return `./${relativePath}`;
13
- return relativePath;
14
- }
15
- /**
16
- * Convert TypeScript file extensions to JavaScript
17
- */
18
- function convertToJsExtension(filePath) {
19
- return filePath.replace(/\.ts$/, ".js");
20
- }
21
- /**
22
- * Resolve module specifier for imports
23
- */
24
- function resolveModuleSpecifier(fromFile, toFile, tsConfig) {
25
- const importPath = resolveImportPath(fromFile, toFile, tsConfig);
26
- return convertToJsExtension(importPath);
27
- }
28
-
29
- //#endregion
30
- Object.defineProperty(exports, 'convertToJsExtension', {
31
- enumerable: true,
32
- get: function () {
33
- return convertToJsExtension;
34
- }
35
- });
36
- Object.defineProperty(exports, 'resolveImportPath', {
37
- enumerable: true,
38
- get: function () {
39
- return resolveImportPath;
40
- }
41
- });
42
- Object.defineProperty(exports, 'resolveModuleSpecifier', {
43
- enumerable: true,
44
- get: function () {
45
- return resolveModuleSpecifier;
46
- }
47
- });
@@ -1,29 +0,0 @@
1
- import { resolvePathMapping } from "./tsconfig-BtO228Cz.mjs";
2
- import { dirname, relative } from "path";
3
-
4
- //#region src/helpers/pathResolver.ts
5
- /**
6
- * Resolve import paths considering TypeScript path mappings
7
- */
8
- function resolveImportPath(fromFile, toFile, tsConfig) {
9
- const resolvedToFile = tsConfig ? resolvePathMapping(toFile, tsConfig) : toFile;
10
- const relativePath = relative(dirname(fromFile), resolvedToFile);
11
- if (!relativePath.startsWith(".")) return `./${relativePath}`;
12
- return relativePath;
13
- }
14
- /**
15
- * Convert TypeScript file extensions to JavaScript
16
- */
17
- function convertToJsExtension(filePath) {
18
- return filePath.replace(/\.ts$/, ".js");
19
- }
20
- /**
21
- * Resolve module specifier for imports
22
- */
23
- function resolveModuleSpecifier(fromFile, toFile, tsConfig) {
24
- const importPath = resolveImportPath(fromFile, toFile, tsConfig);
25
- return convertToJsExtension(importPath);
26
- }
27
-
28
- //#endregion
29
- export { convertToJsExtension, resolveImportPath, resolveModuleSpecifier };
@@ -1,94 +0,0 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const path = require_chunk.__toESM(require("path"));
3
- const fs = require_chunk.__toESM(require("fs"));
4
- const typescript = require_chunk.__toESM(require("typescript"));
5
-
6
- //#region src/tsconfig.ts
7
- /**
8
- * Find and parse the nearest tsconfig.json file
9
- */
10
- function loadTsConfig(searchPath = process.cwd()) {
11
- const configPath = typescript.default.findConfigFile(searchPath, fs.existsSync);
12
- if (!configPath) return null;
13
- const configFile = typescript.default.readConfigFile(configPath, typescript.default.sys.readFile);
14
- if (configFile.error) throw new Error(`Error reading tsconfig.json: ${typescript.default.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`);
15
- const parsedConfig = typescript.default.parseJsonConfigFileContent(configFile.config, typescript.default.sys, (0, path.dirname)(configPath));
16
- if (parsedConfig.errors.length > 0) {
17
- const errors = parsedConfig.errors.map((error) => typescript.default.flattenDiagnosticMessageText(error.messageText, "\n")).join("\n");
18
- throw new Error(`Error parsing tsconfig.json: ${errors}`);
19
- }
20
- return {
21
- configPath,
22
- config: parsedConfig,
23
- compilerOptions: parsedConfig.options
24
- };
25
- }
26
- /**
27
- * Resolve a module path using TypeScript's module resolution
28
- */
29
- function resolveModulePath(moduleName, containingFile, tsConfig) {
30
- const compilerOptions = tsConfig?.compilerOptions || {};
31
- const result = typescript.default.resolveModuleName(moduleName, containingFile, compilerOptions, typescript.default.sys);
32
- if (result.resolvedModule) return result.resolvedModule.resolvedFileName;
33
- return null;
34
- }
35
- /**
36
- * Get the output path for a TypeScript file based on tsconfig
37
- */
38
- function getOutputPath(filePath, tsConfig) {
39
- if (!tsConfig) return filePath.replace(/\.ts$/, ".js");
40
- const { compilerOptions, configPath } = tsConfig;
41
- const configDir = (0, path.dirname)(configPath);
42
- if (compilerOptions.outDir) {
43
- const rootDir = compilerOptions.rootDir || configDir;
44
- const relativePath = filePath.startsWith(rootDir) ? filePath.slice(rootDir.length) : filePath;
45
- const outputPath = (0, path.join)(compilerOptions.outDir, relativePath);
46
- return outputPath.replace(/\.ts$/, ".js");
47
- }
48
- return filePath.replace(/\.ts$/, ".js");
49
- }
50
- /**
51
- * Apply path mappings from tsconfig paths
52
- */
53
- function resolvePathMapping(importPath, tsConfig) {
54
- if (!tsConfig || !tsConfig.compilerOptions.paths) return importPath;
55
- const { paths, baseUrl } = tsConfig.compilerOptions;
56
- const configDir = (0, path.dirname)(tsConfig.configPath);
57
- const resolvedBaseUrl = baseUrl ? (0, path.resolve)(configDir, baseUrl) : configDir;
58
- for (const [pattern, replacements] of Object.entries(paths)) {
59
- const regex = new RegExp("^" + pattern.replace("*", "(.*)") + "$");
60
- const match = importPath.match(regex);
61
- if (match && replacements.length > 0) {
62
- const replacement = replacements[0];
63
- const resolvedPath = replacement.replace("*", match[1] || "");
64
- return (0, path.resolve)(resolvedBaseUrl, resolvedPath);
65
- }
66
- }
67
- return importPath;
68
- }
69
-
70
- //#endregion
71
- Object.defineProperty(exports, 'getOutputPath', {
72
- enumerable: true,
73
- get: function () {
74
- return getOutputPath;
75
- }
76
- });
77
- Object.defineProperty(exports, 'loadTsConfig', {
78
- enumerable: true,
79
- get: function () {
80
- return loadTsConfig;
81
- }
82
- });
83
- Object.defineProperty(exports, 'resolveModulePath', {
84
- enumerable: true,
85
- get: function () {
86
- return resolveModulePath;
87
- }
88
- });
89
- Object.defineProperty(exports, 'resolvePathMapping', {
90
- enumerable: true,
91
- get: function () {
92
- return resolvePathMapping;
93
- }
94
- });
@@ -1,70 +0,0 @@
1
- import { dirname, join, resolve } from "path";
2
- import { existsSync } from "fs";
3
- import ts from "typescript";
4
-
5
- //#region src/tsconfig.ts
6
- /**
7
- * Find and parse the nearest tsconfig.json file
8
- */
9
- function loadTsConfig(searchPath = process.cwd()) {
10
- const configPath = ts.findConfigFile(searchPath, existsSync);
11
- if (!configPath) return null;
12
- const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
13
- if (configFile.error) throw new Error(`Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`);
14
- const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, dirname(configPath));
15
- if (parsedConfig.errors.length > 0) {
16
- const errors = parsedConfig.errors.map((error) => ts.flattenDiagnosticMessageText(error.messageText, "\n")).join("\n");
17
- throw new Error(`Error parsing tsconfig.json: ${errors}`);
18
- }
19
- return {
20
- configPath,
21
- config: parsedConfig,
22
- compilerOptions: parsedConfig.options
23
- };
24
- }
25
- /**
26
- * Resolve a module path using TypeScript's module resolution
27
- */
28
- function resolveModulePath(moduleName, containingFile, tsConfig) {
29
- const compilerOptions = tsConfig?.compilerOptions || {};
30
- const result = ts.resolveModuleName(moduleName, containingFile, compilerOptions, ts.sys);
31
- if (result.resolvedModule) return result.resolvedModule.resolvedFileName;
32
- return null;
33
- }
34
- /**
35
- * Get the output path for a TypeScript file based on tsconfig
36
- */
37
- function getOutputPath(filePath, tsConfig) {
38
- if (!tsConfig) return filePath.replace(/\.ts$/, ".js");
39
- const { compilerOptions, configPath } = tsConfig;
40
- const configDir = dirname(configPath);
41
- if (compilerOptions.outDir) {
42
- const rootDir = compilerOptions.rootDir || configDir;
43
- const relativePath = filePath.startsWith(rootDir) ? filePath.slice(rootDir.length) : filePath;
44
- const outputPath = join(compilerOptions.outDir, relativePath);
45
- return outputPath.replace(/\.ts$/, ".js");
46
- }
47
- return filePath.replace(/\.ts$/, ".js");
48
- }
49
- /**
50
- * Apply path mappings from tsconfig paths
51
- */
52
- function resolvePathMapping(importPath, tsConfig) {
53
- if (!tsConfig || !tsConfig.compilerOptions.paths) return importPath;
54
- const { paths, baseUrl } = tsConfig.compilerOptions;
55
- const configDir = dirname(tsConfig.configPath);
56
- const resolvedBaseUrl = baseUrl ? resolve(configDir, baseUrl) : configDir;
57
- for (const [pattern, replacements] of Object.entries(paths)) {
58
- const regex = new RegExp("^" + pattern.replace("*", "(.*)") + "$");
59
- const match = importPath.match(regex);
60
- if (match && replacements.length > 0) {
61
- const replacement = replacements[0];
62
- const resolvedPath = replacement.replace("*", match[1] || "");
63
- return resolve(resolvedBaseUrl, resolvedPath);
64
- }
65
- }
66
- return importPath;
67
- }
68
-
69
- //#endregion
70
- export { getOutputPath, loadTsConfig, resolveModulePath, resolvePathMapping };
package/dist/tsconfig.cjs DELETED
@@ -1,6 +0,0 @@
1
- const require_tsconfig = require('./tsconfig-83amrDAp.cjs');
2
-
3
- exports.getOutputPath = require_tsconfig.getOutputPath;
4
- exports.loadTsConfig = require_tsconfig.loadTsConfig;
5
- exports.resolveModulePath = require_tsconfig.resolveModulePath;
6
- exports.resolvePathMapping = require_tsconfig.resolvePathMapping;
package/dist/tsconfig.mjs DELETED
@@ -1,3 +0,0 @@
1
- import { getOutputPath, loadTsConfig, resolveModulePath, resolvePathMapping } from "./tsconfig-BtO228Cz.mjs";
2
-
3
- export { getOutputPath, loadTsConfig, resolveModulePath, resolvePathMapping };
@@ -1,46 +0,0 @@
1
- import { relative, dirname } from 'path';
2
- import type { TsConfigResult } from '../tsconfig.js';
3
- import { resolvePathMapping } from '../tsconfig.js';
4
-
5
- /**
6
- * Resolve import paths considering TypeScript path mappings
7
- */
8
- export function resolveImportPath(
9
- fromFile: string,
10
- toFile: string,
11
- tsConfig?: TsConfigResult | null,
12
- ): string {
13
- // Apply path mappings if tsconfig is available
14
- const resolvedToFile = tsConfig
15
- ? resolvePathMapping(toFile, tsConfig)
16
- : toFile;
17
-
18
- // Calculate relative path
19
- const relativePath = relative(dirname(fromFile), resolvedToFile);
20
-
21
- // Ensure proper relative path format
22
- if (!relativePath.startsWith('.')) {
23
- return `./${relativePath}`;
24
- }
25
-
26
- return relativePath;
27
- }
28
-
29
- /**
30
- * Convert TypeScript file extensions to JavaScript
31
- */
32
- export function convertToJsExtension(filePath: string): string {
33
- return filePath.replace(/\.ts$/, '.js');
34
- }
35
-
36
- /**
37
- * Resolve module specifier for imports
38
- */
39
- export function resolveModuleSpecifier(
40
- fromFile: string,
41
- toFile: string,
42
- tsConfig?: TsConfigResult | null,
43
- ): string {
44
- const importPath = resolveImportPath(fromFile, toFile, tsConfig);
45
- return convertToJsExtension(importPath);
46
- }
package/src/tsconfig.ts DELETED
@@ -1,132 +0,0 @@
1
- import ts from 'typescript';
2
- import { existsSync } from 'fs';
3
- import { join, dirname, resolve } from 'path';
4
-
5
- export interface TsConfigResult {
6
- configPath: string;
7
- config: ts.ParsedCommandLine;
8
- compilerOptions: ts.CompilerOptions;
9
- }
10
-
11
- /**
12
- * Find and parse the nearest tsconfig.json file
13
- */
14
- export function loadTsConfig(
15
- searchPath: string = process.cwd(),
16
- ): TsConfigResult | null {
17
- const configPath = ts.findConfigFile(searchPath, existsSync);
18
-
19
- if (!configPath) {
20
- return null;
21
- }
22
-
23
- const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
24
-
25
- if (configFile.error) {
26
- throw new Error(
27
- `Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, '\n')}`,
28
- );
29
- }
30
-
31
- const parsedConfig = ts.parseJsonConfigFileContent(
32
- configFile.config,
33
- ts.sys,
34
- dirname(configPath),
35
- );
36
-
37
- if (parsedConfig.errors.length > 0) {
38
- const errors = parsedConfig.errors
39
- .map((error) => ts.flattenDiagnosticMessageText(error.messageText, '\n'))
40
- .join('\n');
41
- throw new Error(`Error parsing tsconfig.json: ${errors}`);
42
- }
43
-
44
- return {
45
- configPath,
46
- config: parsedConfig,
47
- compilerOptions: parsedConfig.options,
48
- };
49
- }
50
-
51
- /**
52
- * Resolve a module path using TypeScript's module resolution
53
- */
54
- export function resolveModulePath(
55
- moduleName: string,
56
- containingFile: string,
57
- tsConfig?: TsConfigResult,
58
- ): string | null {
59
- const compilerOptions = tsConfig?.compilerOptions || {};
60
-
61
- const result = ts.resolveModuleName(
62
- moduleName,
63
- containingFile,
64
- compilerOptions,
65
- ts.sys,
66
- );
67
-
68
- if (result.resolvedModule) {
69
- return result.resolvedModule.resolvedFileName;
70
- }
71
-
72
- return null;
73
- }
74
-
75
- /**
76
- * Get the output path for a TypeScript file based on tsconfig
77
- */
78
- export function getOutputPath(
79
- filePath: string,
80
- tsConfig?: TsConfigResult,
81
- ): string {
82
- if (!tsConfig) {
83
- // Default: replace .ts with .js
84
- return filePath.replace(/\.ts$/, '.js');
85
- }
86
-
87
- const { compilerOptions, configPath } = tsConfig;
88
- const configDir = dirname(configPath);
89
-
90
- // Handle outDir option
91
- if (compilerOptions.outDir) {
92
- const rootDir = compilerOptions.rootDir || configDir;
93
- const relativePath = filePath.startsWith(rootDir)
94
- ? filePath.slice(rootDir.length)
95
- : filePath;
96
-
97
- const outputPath = join(compilerOptions.outDir, relativePath);
98
- return outputPath.replace(/\.ts$/, '.js');
99
- }
100
-
101
- // Default: in-place compilation
102
- return filePath.replace(/\.ts$/, '.js');
103
- }
104
-
105
- /**
106
- * Apply path mappings from tsconfig paths
107
- */
108
- export function resolvePathMapping(
109
- importPath: string,
110
- tsConfig?: TsConfigResult,
111
- ): string {
112
- if (!tsConfig || !tsConfig.compilerOptions.paths) {
113
- return importPath;
114
- }
115
-
116
- const { paths, baseUrl } = tsConfig.compilerOptions;
117
- const configDir = dirname(tsConfig.configPath);
118
- const resolvedBaseUrl = baseUrl ? resolve(configDir, baseUrl) : configDir;
119
-
120
- for (const [pattern, replacements] of Object.entries(paths)) {
121
- const regex = new RegExp('^' + pattern.replace('*', '(.*)') + '$');
122
- const match = importPath.match(regex);
123
-
124
- if (match && replacements.length > 0) {
125
- const replacement = replacements[0];
126
- const resolvedPath = replacement.replace('*', match[1] || '');
127
- return resolve(resolvedBaseUrl, resolvedPath);
128
- }
129
- }
130
-
131
- return importPath;
132
- }