@shiftapi/next 0.0.19 → 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.
- package/dist/index.js +17 -23
- 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
|
|
48
|
-
const
|
|
49
|
-
const
|
|
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,16 +66,6 @@ function applyShiftAPI(nextConfig, opts) {
|
|
|
66
66
|
});
|
|
67
67
|
return cfg;
|
|
68
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
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
69
|
if (isDev) {
|
|
80
70
|
const existingRewrites = nextConfig.rewrites;
|
|
81
71
|
patched.rewrites = async () => {
|
|
@@ -108,7 +98,7 @@ function applyShiftAPI(nextConfig, opts) {
|
|
|
108
98
|
}
|
|
109
99
|
return patched;
|
|
110
100
|
}
|
|
111
|
-
async function initializeAsync(projectRoot, configDir, isDev, opts) {
|
|
101
|
+
async function initializeAsync(projectRoot, configDir, isDev, openapiSource, openapiDts, opts) {
|
|
112
102
|
const { config } = await loadConfig(projectRoot, opts?.configPath);
|
|
113
103
|
const serverEntry = config.server;
|
|
114
104
|
const baseUrl = config.baseUrl ?? "/";
|
|
@@ -123,12 +113,14 @@ async function initializeAsync(projectRoot, configDir, isDev, opts) {
|
|
|
123
113
|
baseUrl,
|
|
124
114
|
goRoot,
|
|
125
115
|
parsedUrl,
|
|
126
|
-
basePort
|
|
116
|
+
basePort,
|
|
117
|
+
openapiSource,
|
|
118
|
+
openapiDts
|
|
127
119
|
);
|
|
128
120
|
}
|
|
129
|
-
return initializeBuild(projectRoot, configDir, serverEntry, baseUrl, goRoot, basePort);
|
|
121
|
+
return initializeBuild(projectRoot, configDir, serverEntry, baseUrl, goRoot, basePort, openapiSource, openapiDts);
|
|
130
122
|
}
|
|
131
|
-
async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoot, parsedUrl, basePort) {
|
|
123
|
+
async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoot, parsedUrl, basePort, openapiSource, openapiDts) {
|
|
132
124
|
const goPort = await findFreePort(basePort);
|
|
133
125
|
if (goPort !== basePort) {
|
|
134
126
|
console.log(`[shiftapi] Port ${basePort} is in use, using ${goPort}`);
|
|
@@ -147,7 +139,7 @@ async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoo
|
|
|
147
139
|
const result = await _regenerateTypes(serverEntry, goRoot, baseUrl, true, "");
|
|
148
140
|
generatedDts = result.types;
|
|
149
141
|
const clientJs = nextClientJsTemplate(goPort, baseUrl, DEV_API_PREFIX);
|
|
150
|
-
writeGeneratedFiles(configDir, generatedDts, baseUrl, { clientJsContent: clientJs });
|
|
142
|
+
writeGeneratedFiles(configDir, generatedDts, baseUrl, { clientJsContent: clientJs, openapiSource, openapiDts });
|
|
151
143
|
patchTsConfigPaths(projectRoot, configDir);
|
|
152
144
|
console.log("[shiftapi] Types generated.");
|
|
153
145
|
} catch (err) {
|
|
@@ -175,7 +167,9 @@ async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoo
|
|
|
175
167
|
generatedDts = result.types;
|
|
176
168
|
const clientJs = nextClientJsTemplate(goPort, baseUrl, DEV_API_PREFIX);
|
|
177
169
|
writeGeneratedFiles(configDir, generatedDts, baseUrl, {
|
|
178
|
-
clientJsContent: clientJs
|
|
170
|
+
clientJsContent: clientJs,
|
|
171
|
+
openapiSource,
|
|
172
|
+
openapiDts
|
|
179
173
|
});
|
|
180
174
|
console.log("[shiftapi] Types regenerated.");
|
|
181
175
|
}
|
|
@@ -207,11 +201,11 @@ async function initializeDev(projectRoot, configDir, serverEntry, baseUrl, goRoo
|
|
|
207
201
|
});
|
|
208
202
|
return { port: goPort };
|
|
209
203
|
}
|
|
210
|
-
async function initializeBuild(projectRoot, configDir, serverEntry, baseUrl, goRoot, basePort) {
|
|
204
|
+
async function initializeBuild(projectRoot, configDir, serverEntry, baseUrl, goRoot, basePort, openapiSource, openapiDts) {
|
|
211
205
|
try {
|
|
212
206
|
const result = await _regenerateTypes(serverEntry, goRoot, baseUrl, false, "");
|
|
213
207
|
const clientJs = nextClientJsTemplate(basePort, baseUrl);
|
|
214
|
-
writeGeneratedFiles(configDir, result.types, baseUrl, { clientJsContent: clientJs });
|
|
208
|
+
writeGeneratedFiles(configDir, result.types, baseUrl, { clientJsContent: clientJs, openapiSource, openapiDts });
|
|
215
209
|
patchTsConfigPaths(projectRoot, configDir);
|
|
216
210
|
console.log("[shiftapi] Types generated for build.");
|
|
217
211
|
} 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.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.
|
|
33
|
+
"shiftapi": "0.0.20"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^25.2.3",
|