@shiftapi/next 0.0.19 → 0.0.21
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/dist/index.js +44 -66
- 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,
|
|
@@ -42,73 +42,47 @@ function applyShiftAPI(nextConfig, opts) {
|
|
|
42
42
|
return nextConfig;
|
|
43
43
|
}
|
|
44
44
|
const isDev = process.env.NODE_ENV !== "production";
|
|
45
|
-
const shiftapiClientPath = resolve(configDir, ".shiftapi", "client.js");
|
|
46
45
|
const require2 = createRequire(import.meta.url);
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
46
|
+
const openapiDistDir = resolve(require2.resolve("openapi-fetch/package.json"), "..", "dist");
|
|
47
|
+
const openapiSource = readFileSync(resolve(openapiDistDir, "index.js"), "utf-8");
|
|
48
|
+
const openapiDts = readFileSync(resolve(openapiDistDir, "index.d.ts"), "utf-8");
|
|
49
|
+
const initPromise = initializeAsync(projectRoot, configDir, isDev, openapiSource, openapiDts, opts);
|
|
50
50
|
const patched = { ...nextConfig };
|
|
51
|
-
const
|
|
52
|
-
patched.
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
cfg.resolve.alias["openapi-fetch"] = openapiPath;
|
|
58
|
-
cfg.plugins = cfg.plugins || [];
|
|
59
|
-
cfg.plugins.push({
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
-
apply(compiler) {
|
|
62
|
-
compiler.hooks.beforeCompile.tapPromise("ShiftAPI", async () => {
|
|
63
|
-
await initPromise;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
return cfg;
|
|
68
|
-
};
|
|
69
|
-
const existingTurbopack = nextConfig.turbopack ?? {};
|
|
70
|
-
const existingResolveAlias = existingTurbopack.resolveAlias ?? {};
|
|
71
|
-
patched.turbopack = {
|
|
72
|
-
...existingTurbopack,
|
|
73
|
-
resolveAlias: {
|
|
74
|
-
...existingResolveAlias,
|
|
75
|
-
"@shiftapi/client": shiftapiClientPath,
|
|
76
|
-
"openapi-fetch": openapiPath
|
|
51
|
+
const existingRewrites = nextConfig.rewrites;
|
|
52
|
+
patched.rewrites = async () => {
|
|
53
|
+
const { port } = await initPromise;
|
|
54
|
+
if (!isDev) {
|
|
55
|
+
if (!existingRewrites) return [];
|
|
56
|
+
return existingRewrites();
|
|
77
57
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
58
|
+
const shiftapiRewrite = {
|
|
59
|
+
source: `${DEV_API_PREFIX}/:path*`,
|
|
60
|
+
destination: `http://localhost:${port}/:path*`
|
|
61
|
+
};
|
|
62
|
+
if (!existingRewrites) {
|
|
63
|
+
return {
|
|
64
|
+
beforeFiles: [shiftapiRewrite],
|
|
65
|
+
afterFiles: [],
|
|
66
|
+
fallback: []
|
|
86
67
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
afterFiles: [],
|
|
91
|
-
fallback: []
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
const existing = await existingRewrites();
|
|
95
|
-
if (Array.isArray(existing)) {
|
|
96
|
-
return {
|
|
97
|
-
beforeFiles: [shiftapiRewrite],
|
|
98
|
-
afterFiles: existing,
|
|
99
|
-
fallback: []
|
|
100
|
-
};
|
|
101
|
-
}
|
|
68
|
+
}
|
|
69
|
+
const existing = await existingRewrites();
|
|
70
|
+
if (Array.isArray(existing)) {
|
|
102
71
|
return {
|
|
103
|
-
beforeFiles: [shiftapiRewrite
|
|
104
|
-
afterFiles: existing
|
|
105
|
-
fallback:
|
|
72
|
+
beforeFiles: [shiftapiRewrite],
|
|
73
|
+
afterFiles: existing,
|
|
74
|
+
fallback: []
|
|
106
75
|
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
beforeFiles: [shiftapiRewrite, ...existing.beforeFiles ?? []],
|
|
79
|
+
afterFiles: existing.afterFiles ?? [],
|
|
80
|
+
fallback: existing.fallback ?? []
|
|
107
81
|
};
|
|
108
|
-
}
|
|
82
|
+
};
|
|
109
83
|
return patched;
|
|
110
84
|
}
|
|
111
|
-
async function initializeAsync(projectRoot, configDir, isDev, opts) {
|
|
85
|
+
async function initializeAsync(projectRoot, configDir, isDev, openapiSource, openapiDts, opts) {
|
|
112
86
|
const { config } = await loadConfig(projectRoot, opts?.configPath);
|
|
113
87
|
const serverEntry = config.server;
|
|
114
88
|
const baseUrl = config.baseUrl ?? "/";
|
|
@@ -123,12 +97,14 @@ async function initializeAsync(projectRoot, configDir, isDev, opts) {
|
|
|
123
97
|
baseUrl,
|
|
124
98
|
goRoot,
|
|
125
99
|
parsedUrl,
|
|
126
|
-
basePort
|
|
100
|
+
basePort,
|
|
101
|
+
openapiSource,
|
|
102
|
+
openapiDts
|
|
127
103
|
);
|
|
128
104
|
}
|
|
129
|
-
return initializeBuild(projectRoot, configDir, serverEntry, baseUrl, goRoot, basePort);
|
|
105
|
+
return initializeBuild(projectRoot, configDir, serverEntry, baseUrl, goRoot, basePort, openapiSource, openapiDts);
|
|
130
106
|
}
|
|
131
|
-
async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoot, parsedUrl, basePort) {
|
|
107
|
+
async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoot, parsedUrl, basePort, openapiSource, openapiDts) {
|
|
132
108
|
const goPort = await findFreePort(basePort);
|
|
133
109
|
if (goPort !== basePort) {
|
|
134
110
|
console.log(`[shiftapi] Port ${basePort} is in use, using ${goPort}`);
|
|
@@ -147,7 +123,7 @@ async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoo
|
|
|
147
123
|
const result = await _regenerateTypes(serverEntry, goRoot, baseUrl, true, "");
|
|
148
124
|
generatedDts = result.types;
|
|
149
125
|
const clientJs = nextClientJsTemplate(goPort, baseUrl, DEV_API_PREFIX);
|
|
150
|
-
writeGeneratedFiles(configDir, generatedDts, baseUrl, { clientJsContent: clientJs });
|
|
126
|
+
writeGeneratedFiles(configDir, generatedDts, baseUrl, { clientJsContent: clientJs, openapiSource, openapiDts });
|
|
151
127
|
patchTsConfigPaths(projectRoot, configDir);
|
|
152
128
|
console.log("[shiftapi] Types generated.");
|
|
153
129
|
} catch (err) {
|
|
@@ -175,7 +151,9 @@ async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoo
|
|
|
175
151
|
generatedDts = result.types;
|
|
176
152
|
const clientJs = nextClientJsTemplate(goPort, baseUrl, DEV_API_PREFIX);
|
|
177
153
|
writeGeneratedFiles(configDir, generatedDts, baseUrl, {
|
|
178
|
-
clientJsContent: clientJs
|
|
154
|
+
clientJsContent: clientJs,
|
|
155
|
+
openapiSource,
|
|
156
|
+
openapiDts
|
|
179
157
|
});
|
|
180
158
|
console.log("[shiftapi] Types regenerated.");
|
|
181
159
|
}
|
|
@@ -207,11 +185,11 @@ async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoo
|
|
|
207
185
|
});
|
|
208
186
|
return { port: goPort };
|
|
209
187
|
}
|
|
210
|
-
async function initializeBuild(projectRoot, configDir, serverEntry, baseUrl, goRoot, basePort) {
|
|
188
|
+
async function initializeBuild(projectRoot, configDir, serverEntry, baseUrl, goRoot, basePort, openapiSource, openapiDts) {
|
|
211
189
|
try {
|
|
212
190
|
const result = await _regenerateTypes(serverEntry, goRoot, baseUrl, false, "");
|
|
213
191
|
const clientJs = nextClientJsTemplate(basePort, baseUrl);
|
|
214
|
-
writeGeneratedFiles(configDir, result.types, baseUrl, { clientJsContent: clientJs });
|
|
192
|
+
writeGeneratedFiles(configDir, result.types, baseUrl, { clientJsContent: clientJs, openapiSource, openapiDts });
|
|
215
193
|
patchTsConfigPaths(projectRoot, configDir);
|
|
216
194
|
console.log("[shiftapi] Types generated for build.");
|
|
217
195
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shiftapi/next",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
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.
|
|
33
|
+
"shiftapi": "0.0.21"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^25.2.3",
|