@shiftapi/next 0.0.18 → 0.0.20

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.
Files changed (2) hide show
  1. package/dist/index.js +17 -27
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/index.ts
2
2
  import { resolve } from "path";
3
- import { watch } from "fs";
3
+ import { readFileSync, watch } from "fs";
4
4
  import { createRequire } from "module";
5
5
  import {
6
6
  loadConfig,
@@ -44,9 +44,10 @@ function applyShiftAPI(nextConfig, opts) {
44
44
  const isDev = process.env.NODE_ENV !== "production";
45
45
  const shiftapiClientPath = resolve(configDir, ".shiftapi", "client.js");
46
46
  const require2 = createRequire(import.meta.url);
47
- const openapiPkgDir = resolve(require2.resolve("openapi-fetch/package.json"), "..");
48
- const openapiPath = resolve(openapiPkgDir, "dist", "index.js");
49
- const initPromise = initializeAsync(projectRoot, configDir, isDev, opts);
47
+ const openapiDistDir = resolve(require2.resolve("openapi-fetch/package.json"), "..", "dist");
48
+ const openapiSource = readFileSync(resolve(openapiDistDir, "index.js"), "utf-8");
49
+ const openapiDts = readFileSync(resolve(openapiDistDir, "index.d.ts"), "utf-8");
50
+ const initPromise = initializeAsync(projectRoot, configDir, isDev, openapiSource, openapiDts, opts);
50
51
  const patched = { ...nextConfig };
51
52
  const existingWebpack = nextConfig.webpack;
52
53
  patched.webpack = (config, context) => {
@@ -54,7 +55,6 @@ function applyShiftAPI(nextConfig, opts) {
54
55
  cfg.resolve = cfg.resolve || {};
55
56
  cfg.resolve.alias = cfg.resolve.alias || {};
56
57
  cfg.resolve.alias["@shiftapi/client"] = shiftapiClientPath;
57
- cfg.resolve.alias["openapi-fetch"] = openapiPath;
58
58
  cfg.plugins = cfg.plugins || [];
59
59
  cfg.plugins.push({
60
60
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -66,20 +66,6 @@ function applyShiftAPI(nextConfig, opts) {
66
66
  });
67
67
  return cfg;
68
68
  };
69
- const existingExperimental = nextConfig.experimental ?? {};
70
- const existingTurbo = existingExperimental.turbo ?? {};
71
- const existingResolveAlias = existingTurbo.resolveAlias ?? {};
72
- patched.experimental = {
73
- ...existingExperimental,
74
- turbo: {
75
- ...existingTurbo,
76
- resolveAlias: {
77
- ...existingResolveAlias,
78
- "@shiftapi/client": shiftapiClientPath,
79
- "openapi-fetch": openapiPath
80
- }
81
- }
82
- };
83
69
  if (isDev) {
84
70
  const existingRewrites = nextConfig.rewrites;
85
71
  patched.rewrites = async () => {
@@ -112,7 +98,7 @@ function applyShiftAPI(nextConfig, opts) {
112
98
  }
113
99
  return patched;
114
100
  }
115
- async function initializeAsync(projectRoot, configDir, isDev, opts) {
101
+ async function initializeAsync(projectRoot, configDir, isDev, openapiSource, openapiDts, opts) {
116
102
  const { config } = await loadConfig(projectRoot, opts?.configPath);
117
103
  const serverEntry = config.server;
118
104
  const baseUrl = config.baseUrl ?? "/";
@@ -127,12 +113,14 @@ async function initializeAsync(projectRoot, configDir, isDev, opts) {
127
113
  baseUrl,
128
114
  goRoot,
129
115
  parsedUrl,
130
- basePort
116
+ basePort,
117
+ openapiSource,
118
+ openapiDts
131
119
  );
132
120
  }
133
- return initializeBuild(projectRoot, configDir, serverEntry, baseUrl, goRoot, basePort);
121
+ return initializeBuild(projectRoot, configDir, serverEntry, baseUrl, goRoot, basePort, openapiSource, openapiDts);
134
122
  }
135
- async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoot, parsedUrl, basePort) {
123
+ async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoot, parsedUrl, basePort, openapiSource, openapiDts) {
136
124
  const goPort = await findFreePort(basePort);
137
125
  if (goPort !== basePort) {
138
126
  console.log(`[shiftapi] Port ${basePort} is in use, using ${goPort}`);
@@ -151,7 +139,7 @@ async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoo
151
139
  const result = await _regenerateTypes(serverEntry, goRoot, baseUrl, true, "");
152
140
  generatedDts = result.types;
153
141
  const clientJs = nextClientJsTemplate(goPort, baseUrl, DEV_API_PREFIX);
154
- writeGeneratedFiles(configDir, generatedDts, baseUrl, { clientJsContent: clientJs });
142
+ writeGeneratedFiles(configDir, generatedDts, baseUrl, { clientJsContent: clientJs, openapiSource, openapiDts });
155
143
  patchTsConfigPaths(projectRoot, configDir);
156
144
  console.log("[shiftapi] Types generated.");
157
145
  } catch (err) {
@@ -179,7 +167,9 @@ async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoo
179
167
  generatedDts = result.types;
180
168
  const clientJs = nextClientJsTemplate(goPort, baseUrl, DEV_API_PREFIX);
181
169
  writeGeneratedFiles(configDir, generatedDts, baseUrl, {
182
- clientJsContent: clientJs
170
+ clientJsContent: clientJs,
171
+ openapiSource,
172
+ openapiDts
183
173
  });
184
174
  console.log("[shiftapi] Types regenerated.");
185
175
  }
@@ -211,11 +201,11 @@ async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoo
211
201
  });
212
202
  return { port: goPort };
213
203
  }
214
- async function initializeBuild(projectRoot, configDir, serverEntry, baseUrl, goRoot, basePort) {
204
+ async function initializeBuild(projectRoot, configDir, serverEntry, baseUrl, goRoot, basePort, openapiSource, openapiDts) {
215
205
  try {
216
206
  const result = await _regenerateTypes(serverEntry, goRoot, baseUrl, false, "");
217
207
  const clientJs = nextClientJsTemplate(basePort, baseUrl);
218
- writeGeneratedFiles(configDir, result.types, baseUrl, { clientJsContent: clientJs });
208
+ writeGeneratedFiles(configDir, result.types, baseUrl, { clientJsContent: clientJs, openapiSource, openapiDts });
219
209
  patchTsConfigPaths(projectRoot, configDir);
220
210
  console.log("[shiftapi] Types generated for build.");
221
211
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shiftapi/next",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "Next.js integration for fully-typed TypeScript clients from shiftapi Go servers",
5
5
  "author": "Frank Chiarulli Jr. <frank@frankchiarulli.com>",
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "openapi-fetch": "^0.13.0",
33
- "shiftapi": "0.0.18"
33
+ "shiftapi": "0.0.20"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^25.2.3",