@nocobase/utils 2.1.0-alpha.17 → 2.1.0-alpha.19

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/lib/index.d.ts CHANGED
@@ -45,4 +45,5 @@ export * from './wrap-middleware';
45
45
  export * from './run-sql';
46
46
  export * from './liquidjs';
47
47
  export * from './server-request';
48
+ export * from './storage-path';
48
49
  export { lodash };
package/lib/index.js CHANGED
@@ -81,6 +81,7 @@ __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
83
  __reExport(src_exports, require("./server-request"), module.exports);
84
+ __reExport(src_exports, require("./storage-path"), module.exports);
84
85
  // Annotate the CommonJS export names for ESM import in node:
85
86
  0 && (module.exports = {
86
87
  Schema,
@@ -121,5 +122,6 @@ __reExport(src_exports, require("./server-request"), module.exports);
121
122
  ...require("./wrap-middleware"),
122
123
  ...require("./run-sql"),
123
124
  ...require("./liquidjs"),
124
- ...require("./server-request")
125
+ ...require("./server-request"),
126
+ ...require("./storage-path")
125
127
  });
@@ -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 p = process.env.PLUGIN_STORAGE_PATH;
61
+ return import_path.default.isAbsolute(p) ? p : import_path.default.resolve(process.cwd(), p);
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/utils",
3
- "version": "2.1.0-alpha.17",
3
+ "version": "2.1.0-alpha.19",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -21,5 +21,5 @@
21
21
  "object-path": "^0.11.8",
22
22
  "ses": "^1.14.0"
23
23
  },
24
- "gitHead": "586cb00f56557e66168b9720d0e0193a1b752067"
24
+ "gitHead": "3d13700360eac1c0f9dbf6a5f167ed396a294a3c"
25
25
  }
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
@@ -136,7 +145,7 @@ async function createPluginSymLink(pluginName, sourcePath, nodeModulesPath, plug
136
145
  * @returns {Promise<void>}
137
146
  */
138
147
  async function createStoragePluginSymLink(pluginName) {
139
- const storagePluginsPath = resolve(process.cwd(), 'storage/plugins');
148
+ const storagePluginsPath = resolvePluginStoragePath();
140
149
  const nodeModulesPath = process.env.NODE_MODULES_PATH;
141
150
  await createPluginSymLink(pluginName, storagePluginsPath, nodeModulesPath, 'storage');
142
151
  }
@@ -146,7 +155,7 @@ async function createStoragePluginSymLink(pluginName) {
146
155
  * @returns {Promise<void>}
147
156
  */
148
157
  async function createStoragePluginsSymlink() {
149
- const storagePluginsPath = resolve(process.cwd(), 'storage/plugins');
158
+ const storagePluginsPath = resolvePluginStoragePath();
150
159
  if (!(await fs.pathExists(storagePluginsPath))) {
151
160
  return;
152
161
  }
@@ -178,6 +187,7 @@ async function createDevPluginsSymlink() {
178
187
  await Promise.all(pluginNames.map((pluginName) => createDevPluginSymLink(pluginName)));
179
188
  }
180
189
 
190
+ exports.resolvePluginStoragePath = resolvePluginStoragePath;
181
191
  exports.createStoragePluginSymLink = createStoragePluginSymLink;
182
192
  exports.createStoragePluginsSymlink = createStoragePluginsSymlink;
183
193
  exports.createDevPluginSymLink = createDevPluginSymLink;