shiftapi 0.0.16 → 0.0.18

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.
@@ -83,7 +83,20 @@ export const client = createClient({
83
83
  export { createClient };
84
84
  `;
85
85
  }
86
- function nextClientJsTemplate(port, baseUrl) {
86
+ function nextClientJsTemplate(port, baseUrl, devApiPrefix) {
87
+ if (!devApiPrefix) {
88
+ return `// Auto-generated by @shiftapi/next. Do not edit.
89
+ import createClient from "openapi-fetch";
90
+
91
+ const baseUrl =
92
+ process.env.NEXT_PUBLIC_SHIFTAPI_BASE_URL || ${JSON.stringify(baseUrl)};
93
+
94
+ /** Pre-configured, fully-typed API client. */
95
+ export const client = createClient({ baseUrl });
96
+
97
+ export { createClient };
98
+ `;
99
+ }
87
100
  const devServerUrl = `http://localhost:${port}`;
88
101
  return `// Auto-generated by @shiftapi/next. Do not edit.
89
102
  import createClient from "openapi-fetch";
@@ -91,7 +104,7 @@ import createClient from "openapi-fetch";
91
104
  const baseUrl =
92
105
  process.env.NEXT_PUBLIC_SHIFTAPI_BASE_URL ||
93
106
  (typeof window !== "undefined"
94
- ? ${JSON.stringify("/__shiftapi")}
107
+ ? ${JSON.stringify(devApiPrefix)}
95
108
  : ${JSON.stringify(devServerUrl)});
96
109
 
97
110
  /** Pre-configured, fully-typed API client. */
@@ -150,7 +163,7 @@ function writeGeneratedFiles(typesRoot, generatedDts, baseUrl, options) {
150
163
  ) + "\n"
151
164
  );
152
165
  }
153
- function patchTsConfig(tsconfigDir, typesRoot) {
166
+ function patchTsConfigPaths(tsconfigDir, typesRoot) {
154
167
  const tsconfigPath = resolve(tsconfigDir, "tsconfig.json");
155
168
  if (!existsSync(tsconfigPath)) return;
156
169
  const raw = readFileSync2(tsconfigPath, "utf-8");
@@ -163,14 +176,19 @@ function patchTsConfig(tsconfigDir, typesRoot) {
163
176
  );
164
177
  return;
165
178
  }
166
- const rel = relative(tsconfigDir, resolve(typesRoot, ".shiftapi", "tsconfig.json"));
167
- const extendsPath = rel.startsWith("..") ? rel : `./${rel}`;
168
- if (tsconfig?.extends === extendsPath) return;
169
- tsconfig.extends = extendsPath;
179
+ const dtsRel = relative(tsconfigDir, resolve(typesRoot, ".shiftapi", "client.d.ts"));
180
+ const dtsPath = dtsRel.startsWith("..") ? dtsRel : `./${dtsRel}`;
181
+ tsconfig.compilerOptions = tsconfig.compilerOptions || {};
182
+ tsconfig.compilerOptions.paths = tsconfig.compilerOptions.paths || {};
183
+ const existing = tsconfig.compilerOptions.paths[MODULE_ID];
184
+ if (Array.isArray(existing) && existing.length === 1 && existing[0] === dtsPath) {
185
+ return;
186
+ }
187
+ tsconfig.compilerOptions.paths[MODULE_ID] = [dtsPath];
170
188
  const detectedIndent = raw.match(/^[ \t]+/m)?.[0] ?? " ";
171
189
  writeFileSync(tsconfigPath, stringify(tsconfig, null, detectedIndent) + "\n");
172
190
  console.log(
173
- "[shiftapi] Updated tsconfig.json to extend .shiftapi/tsconfig.json"
191
+ "[shiftapi] Updated tsconfig.json with @shiftapi/client path mapping."
174
192
  );
175
193
  }
176
194
 
@@ -186,5 +204,5 @@ export {
186
204
  virtualModuleTemplate,
187
205
  regenerateTypes,
188
206
  writeGeneratedFiles,
189
- patchTsConfig
207
+ patchTsConfigPaths
190
208
  };
@@ -8,7 +8,7 @@ declare function regenerateTypes(serverEntry: string, goRoot: string, baseUrl: s
8
8
  declare function writeGeneratedFiles(typesRoot: string, generatedDts: string, baseUrl: string, options?: {
9
9
  clientJsContent?: string;
10
10
  }): void;
11
- declare function patchTsConfig(tsconfigDir: string, typesRoot: string): void;
11
+ declare function patchTsConfigPaths(tsconfigDir: string, typesRoot: string): void;
12
12
 
13
13
  /**
14
14
  * Extracts the OpenAPI spec from a Go shiftapi server by running it with
@@ -25,7 +25,7 @@ declare function generateTypes(spec: object): Promise<string>;
25
25
 
26
26
  declare function dtsTemplate(generatedTypes: string): string;
27
27
  declare function clientJsTemplate(baseUrl: string): string;
28
- declare function nextClientJsTemplate(port: number, baseUrl: string): string;
28
+ declare function nextClientJsTemplate(port: number, baseUrl: string, devApiPrefix?: string): string;
29
29
  declare function virtualModuleTemplate(baseUrl: string, devApiPrefix?: string): string;
30
30
 
31
31
  declare const MODULE_ID = "@shiftapi/client";
@@ -44,4 +44,4 @@ declare class GoServerManager {
44
44
 
45
45
  declare function findFreePort(startPort: number): Promise<number>;
46
46
 
47
- export { DEV_API_PREFIX, GoServerManager, MODULE_ID, RESOLVED_MODULE_ID, clientJsTemplate, dtsTemplate, extractSpec, findFreePort, generateTypes, nextClientJsTemplate, patchTsConfig, regenerateTypes, virtualModuleTemplate, writeGeneratedFiles };
47
+ export { DEV_API_PREFIX, GoServerManager, MODULE_ID, RESOLVED_MODULE_ID, clientJsTemplate, dtsTemplate, extractSpec, findFreePort, generateTypes, nextClientJsTemplate, patchTsConfigPaths, regenerateTypes, virtualModuleTemplate, writeGeneratedFiles };
package/dist/internal.js CHANGED
@@ -7,11 +7,11 @@ import {
7
7
  extractSpec,
8
8
  generateTypes,
9
9
  nextClientJsTemplate,
10
- patchTsConfig,
10
+ patchTsConfigPaths,
11
11
  regenerateTypes,
12
12
  virtualModuleTemplate,
13
13
  writeGeneratedFiles
14
- } from "./chunk-TE7E7CKV.js";
14
+ } from "./chunk-DQX3QC7F.js";
15
15
  import {
16
16
  defineConfig,
17
17
  findConfigDir,
@@ -138,7 +138,7 @@ export {
138
138
  generateTypes,
139
139
  loadConfig,
140
140
  nextClientJsTemplate,
141
- patchTsConfig,
141
+ patchTsConfigPaths,
142
142
  regenerateTypes,
143
143
  virtualModuleTemplate,
144
144
  writeGeneratedFiles
package/dist/prepare.js CHANGED
@@ -2,9 +2,9 @@
2
2
  import {
3
3
  extractSpec,
4
4
  generateTypes,
5
- patchTsConfig,
5
+ patchTsConfigPaths,
6
6
  writeGeneratedFiles
7
- } from "./chunk-TE7E7CKV.js";
7
+ } from "./chunk-DQX3QC7F.js";
8
8
  import {
9
9
  loadConfig
10
10
  } from "./chunk-EQN44FQG.js";
@@ -26,7 +26,7 @@ async function main() {
26
26
  const spec = extractSpec(serverEntry, resolve(goRoot));
27
27
  const types = await generateTypes(spec);
28
28
  writeGeneratedFiles(configDir, types, baseUrl);
29
- patchTsConfig(cwd, configDir);
29
+ patchTsConfigPaths(cwd, configDir);
30
30
  console.log("[shiftapi] Done. Generated .shiftapi/client.d.ts and .shiftapi/client.js");
31
31
  }
32
32
  main().catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shiftapi",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "CLI and codegen for shiftapi – fully-typed TypeScript clients from Go servers",
5
5
  "author": "Frank Chiarulli Jr. <frank@frankchiarulli.com>",
6
6
  "license": "MIT",