@shiftapi/next 0.0.20 → 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.
Files changed (2) hide show
  1. package/dist/index.js +28 -44
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -42,60 +42,44 @@ 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
46
  const openapiDistDir = resolve(require2.resolve("openapi-fetch/package.json"), "..", "dist");
48
47
  const openapiSource = readFileSync(resolve(openapiDistDir, "index.js"), "utf-8");
49
48
  const openapiDts = readFileSync(resolve(openapiDistDir, "index.d.ts"), "utf-8");
50
49
  const initPromise = initializeAsync(projectRoot, configDir, isDev, openapiSource, openapiDts, opts);
51
50
  const patched = { ...nextConfig };
52
- const existingWebpack = nextConfig.webpack;
53
- patched.webpack = (config, context) => {
54
- const cfg = existingWebpack ? existingWebpack(config, context) : config;
55
- cfg.resolve = cfg.resolve || {};
56
- cfg.resolve.alias = cfg.resolve.alias || {};
57
- cfg.resolve.alias["@shiftapi/client"] = shiftapiClientPath;
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
- if (isDev) {
70
- const existingRewrites = nextConfig.rewrites;
71
- patched.rewrites = async () => {
72
- const { port } = await initPromise;
73
- const shiftapiRewrite = {
74
- source: `${DEV_API_PREFIX}/:path*`,
75
- destination: `http://localhost:${port}/:path*`
51
+ const existingRewrites = nextConfig.rewrites;
52
+ patched.rewrites = async () => {
53
+ const { port } = await initPromise;
54
+ if (!isDev) {
55
+ if (!existingRewrites) return [];
56
+ return existingRewrites();
57
+ }
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: []
76
67
  };
77
- if (!existingRewrites) {
78
- return {
79
- beforeFiles: [shiftapiRewrite],
80
- afterFiles: [],
81
- fallback: []
82
- };
83
- }
84
- const existing = await existingRewrites();
85
- if (Array.isArray(existing)) {
86
- return {
87
- beforeFiles: [shiftapiRewrite],
88
- afterFiles: existing,
89
- fallback: []
90
- };
91
- }
68
+ }
69
+ const existing = await existingRewrites();
70
+ if (Array.isArray(existing)) {
92
71
  return {
93
- beforeFiles: [shiftapiRewrite, ...existing.beforeFiles ?? []],
94
- afterFiles: existing.afterFiles ?? [],
95
- fallback: existing.fallback ?? []
72
+ beforeFiles: [shiftapiRewrite],
73
+ afterFiles: existing,
74
+ fallback: []
96
75
  };
76
+ }
77
+ return {
78
+ beforeFiles: [shiftapiRewrite, ...existing.beforeFiles ?? []],
79
+ afterFiles: existing.afterFiles ?? [],
80
+ fallback: existing.fallback ?? []
97
81
  };
98
- }
82
+ };
99
83
  return patched;
100
84
  }
101
85
  async function initializeAsync(projectRoot, configDir, isDev, openapiSource, openapiDts, opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shiftapi/next",
3
- "version": "0.0.20",
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.20"
33
+ "shiftapi": "0.0.21"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^25.2.3",