@matvdt/js-toolkit 0.0.1-canary.8 → 0.0.1-canary.9

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,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/payload-cms/server/index.ts
@@ -31,23 +41,31 @@ module.exports = __toCommonJS(server_exports);
31
41
  var import_react = require("react");
32
42
 
33
43
  // src/payload-cms/server/get-payload.ts
44
+ var import_node_path = __toESM(require("path"), 1);
45
+ var import_node_url = require("url");
34
46
  var import_payload = require("payload");
35
- var import_node = require("payload/node");
36
- var getPayload = async (config) => {
37
- if (config) {
38
- return (0, import_payload.getPayload)({ config });
39
- }
40
- const configPath = await (0, import_node.findConfig)();
41
- if (!configPath) {
42
- throw new Error(
43
- "[@matvdt/js-toolkit] No payload.config.ts/js file was found in the project root folder."
44
- );
47
+ async function loadPayloadConfig() {
48
+ const candidates = [
49
+ "payload.config.ts",
50
+ "payload.config.js",
51
+ "src/payload.config.ts",
52
+ "src/payload.config.js"
53
+ ];
54
+ for (const candidate of candidates) {
55
+ const absolutePath = import_node_path.default.resolve(process.cwd(), candidate);
56
+ try {
57
+ const configModule = await import((0, import_node_url.pathToFileURL)(absolutePath).href);
58
+ return configModule.default;
59
+ } catch {
60
+ continue;
61
+ }
45
62
  }
46
- const configModule = await import(
47
- /* webpackIgnore: true */
48
- configPath
63
+ throw new Error(
64
+ "[@matvdt/js-toolkit] Could not find payload.config.ts. Pass it explicitly to getPayload(config), or ensure it exists at a standard location relative to the project root."
49
65
  );
50
- const resolvedConfig = await (configModule.default || configModule);
66
+ }
67
+ var getPayload = async (config) => {
68
+ const resolvedConfig = config ?? await loadPayloadConfig();
51
69
  return (0, import_payload.getPayload)({ config: resolvedConfig });
52
70
  };
53
71
 
@@ -2,23 +2,31 @@
2
2
  import { cache } from "react";
3
3
 
4
4
  // src/payload-cms/server/get-payload.ts
5
+ import path from "path";
6
+ import { pathToFileURL } from "url";
5
7
  import { getPayload as getPayloadSDK } from "payload";
6
- import { findConfig } from "payload/node";
7
- var getPayload = async (config) => {
8
- if (config) {
9
- return getPayloadSDK({ config });
10
- }
11
- const configPath = await findConfig();
12
- if (!configPath) {
13
- throw new Error(
14
- "[@matvdt/js-toolkit] No payload.config.ts/js file was found in the project root folder."
15
- );
8
+ async function loadPayloadConfig() {
9
+ const candidates = [
10
+ "payload.config.ts",
11
+ "payload.config.js",
12
+ "src/payload.config.ts",
13
+ "src/payload.config.js"
14
+ ];
15
+ for (const candidate of candidates) {
16
+ const absolutePath = path.resolve(process.cwd(), candidate);
17
+ try {
18
+ const configModule = await import(pathToFileURL(absolutePath).href);
19
+ return configModule.default;
20
+ } catch {
21
+ continue;
22
+ }
16
23
  }
17
- const configModule = await import(
18
- /* webpackIgnore: true */
19
- configPath
24
+ throw new Error(
25
+ "[@matvdt/js-toolkit] Could not find payload.config.ts. Pass it explicitly to getPayload(config), or ensure it exists at a standard location relative to the project root."
20
26
  );
21
- const resolvedConfig = await (configModule.default || configModule);
27
+ }
28
+ var getPayload = async (config) => {
29
+ const resolvedConfig = config ?? await loadPayloadConfig();
22
30
  return getPayloadSDK({ config: resolvedConfig });
23
31
  };
24
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matvdt/js-toolkit",
3
- "version": "0.0.1-canary.8",
3
+ "version": "0.0.1-canary.9",
4
4
  "description": "JS/TS toolkit",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",