@nitrogenbuilder/connector-payload 1.2.1 → 1.2.2

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.
@@ -1,10 +1,31 @@
1
+ import { existsSync } from "node:fs";
1
2
  import fs from "node:fs/promises";
3
+ import { createRequire } from "node:module";
2
4
  import path from "node:path";
3
5
  import { fileURLToPath } from "node:url";
4
6
  import { NextResponse } from "next/server";
5
7
  const __filename = fileURLToPath(import.meta.url);
6
8
  const __dirname = path.dirname(__filename);
7
- const ASSETS_DIR = path.resolve(__dirname, "..", "editor-assets");
9
+ // Next bundles npm packages into server chunks, so in a production build
10
+ // __dirname points into .next/server and the relative lookup fails. Resolve
11
+ // the installed package on disk through Node's resolver instead (works from
12
+ // inside a bundle because createRequire resolves against the host app's real
13
+ // node_modules), and keep the relative path as a fallback for unbundled /
14
+ // linked-dev execution where the package specifier may not resolve.
15
+ function resolveAssetsDir() {
16
+ try {
17
+ const nodeRequire = createRequire(import.meta.url);
18
+ const pkgRoot = path.dirname(nodeRequire.resolve("@nitrogenbuilder/connector-payload/package.json"));
19
+ const dir = path.join(pkgRoot, "dist", "editor-assets");
20
+ if (existsSync(dir))
21
+ return dir;
22
+ }
23
+ catch {
24
+ // fall through to the relative fallback
25
+ }
26
+ return path.resolve(__dirname, "..", "editor-assets");
27
+ }
28
+ const ASSETS_DIR = resolveAssetsDir();
8
29
  function getContentType(filePath) {
9
30
  switch (path.extname(filePath).toLowerCase()) {
10
31
  case ".css":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitrogenbuilder/connector-payload",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Nitrogen page builder connector plugin for Payload CMS 3.x",
5
5
  "author": "Leonardo Dentzien <leo@torchmedia.ca>",
6
6
  "type": "module",
@@ -23,7 +23,8 @@
23
23
  "types": "./dist/editor/NitrogenEditorAssetsRoute.d.ts",
24
24
  "default": "./dist/editor/NitrogenEditorAssetsRoute.js"
25
25
  },
26
- "./components/*": "./dist/components/*"
26
+ "./components/*": "./dist/components/*",
27
+ "./package.json": "./package.json"
27
28
  },
28
29
  "files": [
29
30
  "dist"