@nocobase/utils 2.1.0-alpha.4 → 2.1.0-alpha.45

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/README.md CHANGED
@@ -1,17 +1,24 @@
1
1
  # NocoBase
2
2
 
3
3
  <video width="100%" controls>
4
- <source src="https://static-docs.nocobase.com/NocoBase0510.mp4" type="video/mp4">
4
+ <source src="https://github.com/user-attachments/assets/4d11a87b-00e2-48f3-9bf7-389d21072d13" type="video/mp4">
5
5
  </video>
6
6
 
7
+ <p align="center">
8
+ <a href="https://trendshift.io/repositories/4112" target="_blank"><img src="https://trendshift.io/api/badge/repositories/4112" alt="nocobase%2Fnocobase | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
9
+ <a href="https://www.producthunt.com/posts/nocobase?embed=true&utm_source=badge-top-post-topic-badge&utm_medium=badge&utm_souce=badge-nocobase" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/top-post-topic-badge.svg?post_id=456520&theme=light&period=weekly&topic_id=267" alt="NocoBase - Scalability&#0045;first&#0044;&#0032;open&#0045;source&#0032;no&#0045;code&#0032;platform | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
10
+ </p>
7
11
 
8
12
  ## What is NocoBase
9
13
 
10
- NocoBase is a scalability-first, open-source no-code development platform.
11
- Instead of investing years of time and millions of dollars in research and development, deploy NocoBase in a few minutes and you'll have a private, controllable, and extremely scalable no-code development platform!
14
+ NocoBase is the most extensible AI-powered no-code platform.
15
+ Total control. Infinite extensibility. AI collaboration.
16
+ Enable your team to adapt quickly and cut costs dramatically.
17
+ No years of development. No millions wasted.
18
+ Deploy NocoBase in minutes — and take control of everything.
12
19
 
13
20
  Homepage:
14
- https://www.nocobase.com/
21
+ https://www.nocobase.com/
15
22
 
16
23
  Online Demo:
17
24
  https://demo.nocobase.com/new
@@ -19,12 +26,74 @@ https://demo.nocobase.com/new
19
26
  Documents:
20
27
  https://docs.nocobase.com/
21
28
 
22
- Commericial license & plugins:
23
- https://www.nocobase.com/en/commercial
29
+ Forum:
30
+ https://forum.nocobase.com/
24
31
 
25
- License agreement:
26
- https://www.nocobase.com/en/agreement
32
+ Use Cases:
33
+ https://www.nocobase.com/en/blog/tags/customer-stories
27
34
 
35
+ ## Release Notes
28
36
 
29
- ## Contact Us:
30
- hello@nocobase.com
37
+ Our [blog](https://www.nocobase.com/en/blog/timeline) is regularly updated with release notes and provides a weekly summary.
38
+
39
+ ## Distinctive features
40
+
41
+ ### 1. Data model-driven, not form/table–driven
42
+
43
+ Instead of being constrained by forms or tables, NocoBase adopts a data model–driven approach, separating data structure from user interface to unlock unlimited possibilities.
44
+
45
+ - UI and data structure are fully decoupled
46
+ - Multiple blocks and actions can be created for the same table or record in any quantity or form
47
+ - Supports the main database, external databases, and third-party APIs as data sources
48
+
49
+ ![model](https://static-docs.nocobase.com/model.png)
50
+
51
+ ### 2. AI employees, integrated into your business systems
52
+ Unlike standalone AI demos, NocoBase allows you to embed AI capabilities seamlessly into your interfaces, workflows, and data context, making AI truly useful in real business scenarios.
53
+
54
+ - Define AI employees for roles such as translator, analyst, researcher, or assistant
55
+ - Seamless AI–human collaboration in interfaces and workflows
56
+ - Ensure AI usage is secure, transparent, and customizable for your business needs
57
+
58
+ ![AI-employee](https://static-docs.nocobase.com/ai-employee-home.png)
59
+
60
+ ### 3. What you see is what you get, incredibly easy to use
61
+
62
+ While enabling the development of complex business systems, NocoBase keeps the experience simple and intuitive.
63
+
64
+ - One-click switch between usage mode and configuration mode
65
+ - Pages serve as a canvas to arrange blocks and actions, similar to Notion
66
+ - Configuration mode is designed for ordinary users, not just programmers
67
+
68
+ ![wysiwyg](https://static-docs.nocobase.com/wysiwyg.gif)
69
+
70
+ ### 4. Everything is a plugin, designed for extension
71
+ Adding more no-code features will never cover every business case. NocoBase is built for extension through its plugin-based microkernel architecture.
72
+
73
+ - All functionalities are plugins, similar to WordPress
74
+ - Plugins are ready to use upon installation
75
+ - Pages, blocks, actions, APIs, and data sources can all be extended through custom plugins
76
+
77
+ ![plugins](https://static-docs.nocobase.com/plugins.png)
78
+
79
+ ## Installation
80
+
81
+ NocoBase supports three installation methods:
82
+
83
+ - <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/docker-compose">Installing With Docker (👍Recommended)</a>
84
+
85
+ Suitable for no-code scenarios, no code to write. When upgrading, just download the latest image and reboot.
86
+
87
+ - <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/create-nocobase-app">Installing from create-nocobase-app CLI</a>
88
+
89
+ The business code of the project is completely independent and supports low-code development.
90
+
91
+ - <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/git-clone">Installing from Git source code</a>
92
+
93
+ If you want to experience the latest unreleased version, or want to participate in the contribution, you need to make changes and debug on the source code, it is recommended to choose this installation method, which requires a high level of development skills, and if the code has been updated, you can git pull the latest code.
94
+
95
+ ## How NocoBase works
96
+
97
+ <video width="100%" controls>
98
+ <source src="https://github.com/user-attachments/assets/8d183b44-9bb5-4792-b08f-bc08fe8dfaaf" type="video/mp4">
99
+ </video>
package/lib/index.d.ts CHANGED
@@ -44,4 +44,6 @@ export * from './variable-usage';
44
44
  export * from './wrap-middleware';
45
45
  export * from './run-sql';
46
46
  export * from './liquidjs';
47
+ export * from './server-request';
48
+ export * from './storage-path';
47
49
  export { lodash };
package/lib/index.js CHANGED
@@ -80,6 +80,8 @@ __reExport(src_exports, require("./variable-usage"), module.exports);
80
80
  __reExport(src_exports, require("./wrap-middleware"), module.exports);
81
81
  __reExport(src_exports, require("./run-sql"), module.exports);
82
82
  __reExport(src_exports, require("./liquidjs"), module.exports);
83
+ __reExport(src_exports, require("./server-request"), module.exports);
84
+ __reExport(src_exports, require("./storage-path"), module.exports);
83
85
  // Annotate the CommonJS export names for ESM import in node:
84
86
  0 && (module.exports = {
85
87
  Schema,
@@ -119,5 +121,7 @@ __reExport(src_exports, require("./liquidjs"), module.exports);
119
121
  ...require("./variable-usage"),
120
122
  ...require("./wrap-middleware"),
121
123
  ...require("./run-sql"),
122
- ...require("./liquidjs")
124
+ ...require("./liquidjs"),
125
+ ...require("./server-request"),
126
+ ...require("./storage-path")
123
127
  });
@@ -128,6 +128,10 @@ function isDate(input) {
128
128
  return input instanceof Date || Object.prototype.toString.call(input) === "[object Date]";
129
129
  }
130
130
  __name(isDate, "isDate");
131
+ function isDateFieldWithoutTimezone(field) {
132
+ return (field == null ? void 0 : field.type) === "dateOnly" || (field == null ? void 0 : field.type) === "datetimeNoTz" || (field == null ? void 0 : field.constructor.name) === "DateOnlyField" || (field == null ? void 0 : field.constructor.name) === "DatetimeNoTzField";
133
+ }
134
+ __name(isDateFieldWithoutTimezone, "isDateFieldWithoutTimezone");
131
135
  const dateValueWrapper = /* @__PURE__ */ __name((value, timezone) => {
132
136
  if (!value) {
133
137
  return null;
@@ -195,7 +199,7 @@ const parseFilter = /* @__PURE__ */ __name(async (filter, opts = {}) => {
195
199
  }
196
200
  if (isDateOperator(operator)) {
197
201
  const field = getField == null ? void 0 : getField(path);
198
- if ((field == null ? void 0 : field.constructor.name) === "DateOnlyField" || (field == null ? void 0 : field.constructor.name) === "DatetimeNoTzField") {
202
+ if (isDateFieldWithoutTimezone(field)) {
199
203
  if (value.type) {
200
204
  return (0, import_dateRangeUtils.getDayRangeByParams)({ ...value, timezone: (field == null ? void 0 : field.timezone) || timezone });
201
205
  }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { AxiosRequestConfig, AxiosResponse } from 'axios';
10
+ /**
11
+ * Match a hostname against a domain pattern.
12
+ * `*.example.com` matches exactly one subdomain level (e.g. `foo.example.com`)
13
+ * but not `example.com` itself or deeper levels like `a.b.example.com`.
14
+ */
15
+ export declare function matchesDomainPattern(hostname: string, pattern: string): boolean;
16
+ /**
17
+ * Validate a URL against the SERVER_REQUEST_WHITELIST environment variable.
18
+ *
19
+ * Throws an error if:
20
+ * - The URL scheme is not http or https.
21
+ * - SERVER_REQUEST_WHITELIST is set and the host does not match any entry.
22
+ *
23
+ * Silently returns for relative URLs (no scheme) so that internal API calls
24
+ * that use a relative path are not affected.
25
+ *
26
+ * Prefer using {@link serverRequest} over calling this directly.
27
+ */
28
+ export declare function checkUrlAgainstWhitelist(url?: string): void;
29
+ /**
30
+ * Drop-in replacement for `axios.request()` with built-in SSRF protection.
31
+ *
32
+ * Validates `config.url` against {@link checkUrlAgainstWhitelist} before
33
+ * forwarding to axios. Use this instead of calling axios directly for all
34
+ * server-initiated outbound HTTP requests.
35
+ */
36
+ export declare function serverRequest<T = any>(config: AxiosRequestConfig): Promise<AxiosResponse<T>>;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var server_request_exports = {};
39
+ __export(server_request_exports, {
40
+ checkUrlAgainstWhitelist: () => checkUrlAgainstWhitelist,
41
+ matchesDomainPattern: () => matchesDomainPattern,
42
+ serverRequest: () => serverRequest
43
+ });
44
+ module.exports = __toCommonJS(server_request_exports);
45
+ var import_ipaddr = __toESM(require("ipaddr.js"));
46
+ var import_axios = __toESM(require("axios"));
47
+ const ALLOWED_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]);
48
+ function matchesIpEntry(hostname, entry) {
49
+ try {
50
+ let addr = import_ipaddr.default.parse(hostname);
51
+ if (addr.kind() === "ipv6" && addr.isIPv4MappedAddress()) {
52
+ addr = addr.toIPv4Address();
53
+ }
54
+ if (entry.includes("/")) {
55
+ const cidr = import_ipaddr.default.parseCIDR(entry);
56
+ if (addr.kind() !== cidr[0].kind()) return false;
57
+ if (addr.kind() === "ipv4") {
58
+ return addr.match(cidr);
59
+ }
60
+ return addr.match(cidr);
61
+ }
62
+ let entryAddr = import_ipaddr.default.parse(entry);
63
+ if (entryAddr.kind() === "ipv6" && entryAddr.isIPv4MappedAddress()) {
64
+ entryAddr = entryAddr.toIPv4Address();
65
+ }
66
+ return addr.toString() === entryAddr.toString();
67
+ } catch {
68
+ return false;
69
+ }
70
+ }
71
+ __name(matchesIpEntry, "matchesIpEntry");
72
+ function matchesDomainPattern(hostname, pattern) {
73
+ const h = hostname.toLowerCase();
74
+ const p = pattern.toLowerCase();
75
+ if (p.startsWith("*.")) {
76
+ const suffix = p.slice(1);
77
+ if (!h.endsWith(suffix) || h.length <= suffix.length) return false;
78
+ const prefix = h.slice(0, h.length - suffix.length);
79
+ return !prefix.includes(".");
80
+ }
81
+ return h === p;
82
+ }
83
+ __name(matchesDomainPattern, "matchesDomainPattern");
84
+ function matchesEntry(hostname, entry) {
85
+ const e = entry.trim();
86
+ if (!e) return false;
87
+ return import_ipaddr.default.isValid(hostname) ? matchesIpEntry(hostname, e) : matchesDomainPattern(hostname, e);
88
+ }
89
+ __name(matchesEntry, "matchesEntry");
90
+ function checkUrlAgainstWhitelist(url) {
91
+ if (!url) return;
92
+ if (!url.includes("://")) return;
93
+ let parsed;
94
+ try {
95
+ parsed = new URL(url);
96
+ } catch {
97
+ return;
98
+ }
99
+ if (!ALLOWED_PROTOCOLS.has(parsed.protocol)) {
100
+ throw new Error(
101
+ `URL scheme "${parsed.protocol.replace(":", "")}" is not allowed. Only http and https are permitted.`
102
+ );
103
+ }
104
+ const whitelist = process.env.SERVER_REQUEST_WHITELIST;
105
+ if (!whitelist || !whitelist.trim()) return;
106
+ const entries = whitelist.split(",").map((e) => e.trim()).filter(Boolean);
107
+ if (entries.length === 0) return;
108
+ const { hostname } = parsed;
109
+ const host = hostname.startsWith("[") && hostname.endsWith("]") ? hostname.slice(1, -1) : hostname;
110
+ for (const entry of entries) {
111
+ if (matchesEntry(host, entry)) return;
112
+ }
113
+ throw new Error(
114
+ `Outbound request to "${host}" is blocked. Add it to SERVER_REQUEST_WHITELIST to allow this request.`
115
+ );
116
+ }
117
+ __name(checkUrlAgainstWhitelist, "checkUrlAgainstWhitelist");
118
+ async function serverRequest(config) {
119
+ checkUrlAgainstWhitelist(config.url);
120
+ return import_axios.default.request(config);
121
+ }
122
+ __name(serverRequest, "serverRequest");
123
+ // Annotate the CommonJS export names for ESM import in node:
124
+ 0 && (module.exports = {
125
+ checkUrlAgainstWhitelist,
126
+ matchesDomainPattern,
127
+ serverRequest
128
+ });
@@ -0,0 +1,25 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ /**
10
+ * Absolute path to the application storage root (same rules as CLI `resolveStorageRoot` in `cli-v1/src/util.js`).
11
+ */
12
+ export declare function resolveStorageRoot(): string;
13
+ /**
14
+ * Join path segments under the application storage root.
15
+ * Resolution matches CLI `resolveStorageRoot()` / `initEnv`: use `STORAGE_PATH` when set
16
+ * (absolute or relative to cwd), otherwise `<cwd>/storage`.
17
+ *
18
+ * @example storagePathJoin('tmp')
19
+ * @example storagePathJoin('cache', 'apps', appName)
20
+ */
21
+ export declare function storagePathJoin(...segments: string[]): string;
22
+ /**
23
+ * Resolve plugin storage path: `PLUGIN_STORAGE_PATH` first, else `<STORAGE_PATH>/plugins`.
24
+ */
25
+ export declare function resolvePluginStoragePath(): string;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var storage_path_exports = {};
39
+ __export(storage_path_exports, {
40
+ resolvePluginStoragePath: () => resolvePluginStoragePath,
41
+ resolveStorageRoot: () => resolveStorageRoot,
42
+ storagePathJoin: () => storagePathJoin
43
+ });
44
+ module.exports = __toCommonJS(storage_path_exports);
45
+ var import_path = __toESM(require("path"));
46
+ function resolveStorageRoot() {
47
+ const raw = process.env.STORAGE_PATH;
48
+ if (raw) {
49
+ return import_path.default.isAbsolute(raw) ? raw : import_path.default.resolve(process.cwd(), raw);
50
+ }
51
+ return import_path.default.resolve(process.cwd(), "storage");
52
+ }
53
+ __name(resolveStorageRoot, "resolveStorageRoot");
54
+ function storagePathJoin(...segments) {
55
+ return import_path.default.join(resolveStorageRoot(), ...segments);
56
+ }
57
+ __name(storagePathJoin, "storagePathJoin");
58
+ function resolvePluginStoragePath() {
59
+ if (process.env.PLUGIN_STORAGE_PATH) {
60
+ const pluginStoragePath = process.env.PLUGIN_STORAGE_PATH;
61
+ return import_path.default.isAbsolute(pluginStoragePath) ? pluginStoragePath : import_path.default.resolve(process.cwd(), pluginStoragePath);
62
+ }
63
+ return storagePathJoin("plugins");
64
+ }
65
+ __name(resolvePluginStoragePath, "resolvePluginStoragePath");
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ resolvePluginStoragePath,
69
+ resolveStorageRoot,
70
+ storagePathJoin
71
+ });
package/package.json CHANGED
@@ -1,23 +1,25 @@
1
1
  {
2
2
  "name": "@nocobase/utils",
3
- "version": "2.1.0-alpha.4",
3
+ "version": "2.1.0-alpha.45",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
- "license": "AGPL-3.0",
6
+ "license": "Apache-2.0",
7
7
  "dependencies": {
8
8
  "@budibase/handlebars-helpers": "0.14.0",
9
9
  "@hapi/topo": "^6.0.0",
10
10
  "@rc-component/mini-decimal": "^1.1.0",
11
+ "axios": "^1.7.0",
11
12
  "dayjs": "^1.11.9",
12
13
  "deepmerge": "^4.2.2",
13
14
  "flat-to-nested": "^1.1.1",
14
15
  "fs-extra": "^11.1.1",
15
16
  "graphlib": "^2.1.8",
16
17
  "handlebars": "^4.7.8",
18
+ "ipaddr.js": "^1.9.1",
17
19
  "liquidjs": "^10.23.0",
18
20
  "multer": "^1.4.5-lts.2",
19
21
  "object-path": "^0.11.8",
20
22
  "ses": "^1.14.0"
21
23
  },
22
- "gitHead": "32c682485e5f1878b9165be2e9de18000d98f935"
24
+ "gitHead": "e9e24987e12d0ad10a5db8815b1e1b7b447f1938"
23
25
  }
@@ -4,3 +4,4 @@ export declare function createStoragePluginSymLink(pluginName: any): Promise<voi
4
4
  export declare function createStoragePluginsSymlink(): Promise<void>;
5
5
  export declare function createDevPluginSymLink(pluginName: any): Promise<void>;
6
6
  export declare function createDevPluginsSymlink(): Promise<void>;
7
+ export declare function syncPluginSymlinks(): Promise<void>;
package/plugin-symlink.js CHANGED
@@ -1,6 +1,15 @@
1
- const { resolve } = require('path');
1
+ const path = require('path');
2
+ const { resolve } = path;
2
3
  const fs = require('fs-extra');
3
4
 
5
+ function resolvePluginStoragePath() {
6
+ if (process.env.PLUGIN_STORAGE_PATH) {
7
+ const p = process.env.PLUGIN_STORAGE_PATH;
8
+ return path.isAbsolute(p) ? p : path.resolve(process.cwd(), p);
9
+ }
10
+ return path.join(process.env.STORAGE_PATH || path.resolve(process.cwd(), 'storage'), 'plugins');
11
+ }
12
+
4
13
  /**
5
14
  * Recursively get plugin names from a directory
6
15
  * @param {string} target - Target directory to scan
@@ -28,6 +37,36 @@ async function getStoragePluginNames(target) {
28
37
  return plugins;
29
38
  }
30
39
 
40
+ async function getPluginNamesFromSourceRoot(rootPath) {
41
+ if (!(await fs.pathExists(rootPath))) {
42
+ return [];
43
+ }
44
+ return await getStoragePluginNames(rootPath);
45
+ }
46
+
47
+ async function isValidPluginSourcePath(candidate) {
48
+ return await fs.pathExists(resolve(candidate, 'package.json'));
49
+ }
50
+
51
+ function getPluginSourceRoots(storagePluginsPath) {
52
+ return [
53
+ resolve(process.cwd(), 'packages/plugins'),
54
+ resolve(process.cwd(), 'packages/pro-plugins'),
55
+ storagePluginsPath,
56
+ ];
57
+ }
58
+
59
+ async function resolvePluginSourcePath(pluginName, storagePluginsPath) {
60
+ const sourceRoots = getPluginSourceRoots(storagePluginsPath);
61
+ for (const rootPath of sourceRoots) {
62
+ const candidate = resolve(rootPath, pluginName);
63
+ if (await isValidPluginSourcePath(candidate)) {
64
+ return candidate;
65
+ }
66
+ }
67
+ return '';
68
+ }
69
+
31
70
  /**
32
71
  * Ensure the organization directory exists for scoped packages
33
72
  * @param {string} nodeModulesPath - Path to node_modules
@@ -43,22 +82,35 @@ async function ensureOrgDirectory(nodeModulesPath, pluginName) {
43
82
  }
44
83
 
45
84
  /**
46
- * Check if a symlink already points to the correct target
47
- * @param {string} linkPath - Path to the symlink
48
- * @param {string} targetPath - Expected target path
49
- * @returns {Promise<boolean>} True if symlink exists and points to target
85
+ * Check whether node_modules entry is a real directory, symlink, or missing
86
+ * @param {string} linkPath - Path inside node_modules
87
+ * @returns {Promise<'missing'|'dir'|'symlink'|'other'>}
50
88
  */
51
- async function isSymlinkValid(linkPath, targetPath) {
89
+ async function getNodeModulesEntryType(linkPath) {
52
90
  try {
53
- if (await fs.pathExists(linkPath)) {
54
- const realPath = await fs.realpath(linkPath);
55
- return realPath === targetPath;
91
+ const statResult = await fs.lstat(linkPath);
92
+ if (statResult.isSymbolicLink()) {
93
+ return 'symlink';
94
+ }
95
+ if (statResult.isDirectory()) {
96
+ return 'dir';
56
97
  }
98
+ return 'other';
57
99
  } catch (error) {
58
- // If realpath fails, the symlink is invalid
100
+ if (error.code === 'ENOENT') {
101
+ return 'missing';
102
+ }
103
+ return 'other';
104
+ }
105
+ }
106
+
107
+ async function isSymlinkValid(linkPath, targetPath) {
108
+ try {
109
+ const realPath = await fs.realpath(linkPath);
110
+ return realPath === targetPath;
111
+ } catch {
59
112
  return false;
60
113
  }
61
- return false;
62
114
  }
63
115
 
64
116
  /**
@@ -110,13 +162,18 @@ async function createPluginSymLink(pluginName, sourcePath, nodeModulesPath, plug
110
162
  return;
111
163
  }
112
164
 
165
+ const linkPath = resolve(nodeModulesPath, pluginName);
166
+ const entryType = await getNodeModulesEntryType(linkPath);
167
+
168
+ if (entryType === 'dir') {
169
+ return;
170
+ }
171
+
113
172
  // Ensure organization directory exists for scoped packages
114
173
  await ensureOrgDirectory(nodeModulesPath, pluginName);
115
174
 
116
- const linkPath = resolve(nodeModulesPath, pluginName);
117
-
118
175
  // Check if symlink already points to the correct target
119
- if (await isSymlinkValid(linkPath, targetPath)) {
176
+ if (entryType === 'symlink' && (await isSymlinkValid(linkPath, targetPath))) {
120
177
  return; // Symlink is already correct, no need to recreate
121
178
  }
122
179
 
@@ -133,10 +190,9 @@ async function createPluginSymLink(pluginName, sourcePath, nodeModulesPath, plug
133
190
  /**
134
191
  * Create a symlink for a storage plugin
135
192
  * @param {string} pluginName - Name of the plugin
136
- * @returns {Promise<void>}
137
193
  */
138
194
  async function createStoragePluginSymLink(pluginName) {
139
- const storagePluginsPath = resolve(process.cwd(), 'storage/plugins');
195
+ const storagePluginsPath = resolvePluginStoragePath();
140
196
  const nodeModulesPath = process.env.NODE_MODULES_PATH;
141
197
  await createPluginSymLink(pluginName, storagePluginsPath, nodeModulesPath, 'storage');
142
198
  }
@@ -146,7 +202,7 @@ async function createStoragePluginSymLink(pluginName) {
146
202
  * @returns {Promise<void>}
147
203
  */
148
204
  async function createStoragePluginsSymlink() {
149
- const storagePluginsPath = resolve(process.cwd(), 'storage/plugins');
205
+ const storagePluginsPath = resolvePluginStoragePath();
150
206
  if (!(await fs.pathExists(storagePluginsPath))) {
151
207
  return;
152
208
  }
@@ -178,7 +234,56 @@ async function createDevPluginsSymlink() {
178
234
  await Promise.all(pluginNames.map((pluginName) => createDevPluginSymLink(pluginName)));
179
235
  }
180
236
 
237
+ /**
238
+ * Create symlinks for all plugins from all sources
239
+ * @returns {Promise<void>}
240
+ */
241
+ async function syncPluginSymlinks() {
242
+ const nodeModulesPath = process.env.NODE_MODULES_PATH;
243
+ if (!nodeModulesPath) {
244
+ return;
245
+ }
246
+
247
+ const storagePluginsPath = resolvePluginStoragePath();
248
+ const sourceRoots = getPluginSourceRoots(storagePluginsPath);
249
+ const pluginNames = new Set();
250
+
251
+ for (const rootPath of sourceRoots) {
252
+ const names = await getPluginNamesFromSourceRoot(rootPath);
253
+ names.forEach((name) => pluginNames.add(name));
254
+ }
255
+
256
+ await Promise.all(
257
+ [...pluginNames].map(async (pluginName) => {
258
+ const linkPath = resolve(nodeModulesPath, pluginName);
259
+ const entryType = await getNodeModulesEntryType(linkPath);
260
+
261
+ if (entryType === 'dir') {
262
+ return;
263
+ }
264
+
265
+ const sourcePath = await resolvePluginSourcePath(pluginName, storagePluginsPath);
266
+ if (!sourcePath) {
267
+ if (entryType === 'symlink' || entryType === 'other') {
268
+ await removeExistingLink(linkPath, pluginName, 'plugin');
269
+ }
270
+ return;
271
+ }
272
+
273
+ if (entryType === 'symlink' && (await isSymlinkValid(linkPath, sourcePath))) {
274
+ return;
275
+ }
276
+
277
+ await ensureOrgDirectory(nodeModulesPath, pluginName);
278
+ await removeExistingLink(linkPath, pluginName, 'plugin');
279
+ await fs.symlink(sourcePath, linkPath, 'dir');
280
+ }),
281
+ );
282
+ }
283
+
284
+ exports.resolvePluginStoragePath = resolvePluginStoragePath;
181
285
  exports.createStoragePluginSymLink = createStoragePluginSymLink;
182
286
  exports.createStoragePluginsSymlink = createStoragePluginsSymlink;
183
287
  exports.createDevPluginSymLink = createDevPluginSymLink;
184
288
  exports.createDevPluginsSymlink = createDevPluginsSymlink;
289
+ exports.syncPluginSymlinks = syncPluginSymlinks;