@nocobase/server 1.3.39-beta → 1.4.0-alpha
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/application.d.ts +9 -9
- package/lib/application.js +21 -15
- package/lib/commands/start.js +9 -6
- package/lib/index.d.ts +4 -2
- package/lib/index.js +19 -5
- package/lib/locale/locale.d.ts +1 -0
- package/lib/locale/locale.js +3 -1
- package/lib/plugin-manager/deps.js +1 -1
- package/lib/plugin-manager/findPackageNames.d.ts +16 -0
- package/lib/plugin-manager/findPackageNames.js +183 -0
- package/lib/plugin-manager/options/resource.js +4 -2
- package/lib/plugin-manager/plugin-manager-repository.d.ts +1 -0
- package/lib/plugin-manager/plugin-manager-repository.js +18 -5
- package/lib/plugin-manager/plugin-manager.d.ts +4 -1
- package/lib/plugin-manager/plugin-manager.js +116 -170
- package/lib/run-plugin-static-imports.d.ts +1 -0
- package/lib/run-plugin-static-imports.js +52 -0
- package/package.json +15 -15
package/lib/application.d.ts
CHANGED
|
@@ -149,28 +149,28 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
149
149
|
* @internal
|
|
150
150
|
*/
|
|
151
151
|
perfHistograms: Map<string, RecordableHistogram>;
|
|
152
|
+
/**
|
|
153
|
+
* @internal
|
|
154
|
+
*/
|
|
155
|
+
syncManager: SyncManager;
|
|
156
|
+
requestLogger: Logger;
|
|
152
157
|
protected plugins: Map<string, Plugin<any>>;
|
|
153
158
|
protected _appSupervisor: AppSupervisor;
|
|
154
|
-
protected _started: Date | null;
|
|
155
159
|
private _authenticated;
|
|
156
160
|
private _maintaining;
|
|
157
161
|
private _maintainingCommandStatus;
|
|
158
162
|
private _maintainingStatusBeforeCommand;
|
|
159
163
|
private _actionCommand;
|
|
160
|
-
|
|
161
|
-
* @internal
|
|
162
|
-
*/
|
|
163
|
-
syncManager: SyncManager;
|
|
164
|
-
requestLogger: Logger;
|
|
164
|
+
constructor(options: ApplicationOptions);
|
|
165
165
|
private _sqlLogger;
|
|
166
|
+
get sqlLogger(): Logger;
|
|
166
167
|
protected _logger: SystemLogger;
|
|
167
|
-
|
|
168
|
+
get logger(): SystemLogger;
|
|
169
|
+
protected _started: Date | null;
|
|
168
170
|
/**
|
|
169
171
|
* @experimental
|
|
170
172
|
*/
|
|
171
173
|
get started(): Date;
|
|
172
|
-
get logger(): SystemLogger;
|
|
173
|
-
get sqlLogger(): Logger;
|
|
174
174
|
get log(): SystemLogger;
|
|
175
175
|
protected _loaded: boolean;
|
|
176
176
|
/**
|
package/lib/application.js
CHANGED
|
@@ -107,33 +107,33 @@ const _Application = class _Application extends import_koa.default {
|
|
|
107
107
|
* @internal
|
|
108
108
|
*/
|
|
109
109
|
perfHistograms = /* @__PURE__ */ new Map();
|
|
110
|
+
/**
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
syncManager;
|
|
114
|
+
requestLogger;
|
|
110
115
|
plugins = /* @__PURE__ */ new Map();
|
|
111
116
|
_appSupervisor = import_app_supervisor.AppSupervisor.getInstance();
|
|
112
|
-
_started = null;
|
|
113
117
|
_authenticated = false;
|
|
114
118
|
_maintaining = false;
|
|
115
119
|
_maintainingCommandStatus;
|
|
116
120
|
_maintainingStatusBeforeCommand;
|
|
117
121
|
_actionCommand;
|
|
118
|
-
/**
|
|
119
|
-
* @internal
|
|
120
|
-
*/
|
|
121
|
-
syncManager;
|
|
122
|
-
requestLogger;
|
|
123
122
|
_sqlLogger;
|
|
123
|
+
get sqlLogger() {
|
|
124
|
+
return this._sqlLogger;
|
|
125
|
+
}
|
|
124
126
|
_logger;
|
|
127
|
+
get logger() {
|
|
128
|
+
return this._logger;
|
|
129
|
+
}
|
|
130
|
+
_started = null;
|
|
125
131
|
/**
|
|
126
132
|
* @experimental
|
|
127
133
|
*/
|
|
128
134
|
get started() {
|
|
129
135
|
return this._started;
|
|
130
136
|
}
|
|
131
|
-
get logger() {
|
|
132
|
-
return this._logger;
|
|
133
|
-
}
|
|
134
|
-
get sqlLogger() {
|
|
135
|
-
return this._sqlLogger;
|
|
136
|
-
}
|
|
137
137
|
get log() {
|
|
138
138
|
return this._logger;
|
|
139
139
|
}
|
|
@@ -369,6 +369,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
369
369
|
await oldDb.close();
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
|
+
if (this.cacheManager) {
|
|
373
|
+
await this.cacheManager.close();
|
|
374
|
+
}
|
|
372
375
|
this._cacheManager = await (0, import_cache2.createCacheManager)(this, this.options.cacheManager);
|
|
373
376
|
this.log.debug("init plugins");
|
|
374
377
|
this.setMaintainingMessage("init plugins");
|
|
@@ -379,9 +382,11 @@ const _Application = class _Application extends import_koa.default {
|
|
|
379
382
|
if ((options == null ? void 0 : options.hooks) !== false) {
|
|
380
383
|
await this.emitAsync("beforeLoad", this, options);
|
|
381
384
|
}
|
|
382
|
-
this.telemetry.
|
|
383
|
-
|
|
384
|
-
this.telemetry.
|
|
385
|
+
if (!this.telemetry.started) {
|
|
386
|
+
this.telemetry.init();
|
|
387
|
+
if ((_a = this.options.telemetry) == null ? void 0 : _a.enabled) {
|
|
388
|
+
this.telemetry.start();
|
|
389
|
+
}
|
|
385
390
|
}
|
|
386
391
|
await this.pm.load(options);
|
|
387
392
|
if (options == null ? void 0 : options.sync) {
|
|
@@ -661,6 +666,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
661
666
|
await this.reInit();
|
|
662
667
|
await this.db.sync();
|
|
663
668
|
await this.load({ hooks: false });
|
|
669
|
+
this._loaded = false;
|
|
664
670
|
this.log.debug("emit beforeInstall", { method: "install" });
|
|
665
671
|
this.setMaintainingMessage("call beforeInstall hook...");
|
|
666
672
|
await this.emitAsync("beforeInstall", this, options);
|
package/lib/commands/start.js
CHANGED
|
@@ -40,20 +40,23 @@ __export(start_exports, {
|
|
|
40
40
|
default: () => start_default
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(start_exports);
|
|
43
|
-
var
|
|
44
|
-
var import_fs = __toESM(require("fs"));
|
|
43
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
45
44
|
var import_path = require("path");
|
|
46
45
|
var import_application_not_install = require("../errors/application-not-install");
|
|
47
46
|
/* istanbul ignore file -- @preserve */
|
|
48
47
|
var start_default = /* @__PURE__ */ __name((app) => {
|
|
49
48
|
app.command("start").auth().option("--db-sync").option("--quickstart").action(async (...cliArgs) => {
|
|
50
49
|
const [options] = cliArgs;
|
|
51
|
-
const file = (0, import_path.resolve)(process.cwd(), "storage
|
|
52
|
-
const upgrading = await
|
|
50
|
+
const file = (0, import_path.resolve)(process.cwd(), "storage/.upgrading");
|
|
51
|
+
const upgrading = await import_fs_extra.default.exists(file);
|
|
53
52
|
if (upgrading) {
|
|
54
|
-
|
|
53
|
+
if (!process.env.VITEST) {
|
|
54
|
+
if (await app.isInstalled()) {
|
|
55
|
+
await app.upgrade();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
55
58
|
try {
|
|
56
|
-
await
|
|
59
|
+
await import_fs_extra.default.rm(file, { recursive: true, force: true });
|
|
57
60
|
} catch (error) {
|
|
58
61
|
}
|
|
59
62
|
} else if (options.quickstart) {
|
package/lib/index.d.ts
CHANGED
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
export * from './app-supervisor';
|
|
9
10
|
export * from './application';
|
|
10
11
|
export { Application as default } from './application';
|
|
12
|
+
export * from './gateway';
|
|
11
13
|
export * as middlewares from './middlewares';
|
|
12
14
|
export * from './migration';
|
|
13
15
|
export * from './plugin';
|
|
14
16
|
export * from './plugin-manager';
|
|
15
|
-
export * from './gateway';
|
|
16
|
-
export * from './app-supervisor';
|
|
17
17
|
export * from './sync-manager';
|
|
18
18
|
export declare const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
|
19
|
+
export { appendToBuiltInPlugins, findAllPlugins, findBuiltInPlugins, findLocalPlugins, packageNameTrim, } from './plugin-manager/findPackageNames';
|
|
20
|
+
export { runPluginStaticImports } from './run-plugin-static-imports';
|
package/lib/index.js
CHANGED
|
@@ -38,29 +38,43 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
38
38
|
var src_exports = {};
|
|
39
39
|
__export(src_exports, {
|
|
40
40
|
OFFICIAL_PLUGIN_PREFIX: () => OFFICIAL_PLUGIN_PREFIX,
|
|
41
|
+
appendToBuiltInPlugins: () => import_findPackageNames.appendToBuiltInPlugins,
|
|
41
42
|
default: () => import_application.Application,
|
|
42
|
-
|
|
43
|
+
findAllPlugins: () => import_findPackageNames.findAllPlugins,
|
|
44
|
+
findBuiltInPlugins: () => import_findPackageNames.findBuiltInPlugins,
|
|
45
|
+
findLocalPlugins: () => import_findPackageNames.findLocalPlugins,
|
|
46
|
+
middlewares: () => middlewares,
|
|
47
|
+
packageNameTrim: () => import_findPackageNames.packageNameTrim,
|
|
48
|
+
runPluginStaticImports: () => import_run_plugin_static_imports.runPluginStaticImports
|
|
43
49
|
});
|
|
44
50
|
module.exports = __toCommonJS(src_exports);
|
|
51
|
+
__reExport(src_exports, require("./app-supervisor"), module.exports);
|
|
45
52
|
__reExport(src_exports, require("./application"), module.exports);
|
|
46
53
|
var import_application = require("./application");
|
|
54
|
+
__reExport(src_exports, require("./gateway"), module.exports);
|
|
47
55
|
var middlewares = __toESM(require("./middlewares"));
|
|
48
56
|
__reExport(src_exports, require("./migration"), module.exports);
|
|
49
57
|
__reExport(src_exports, require("./plugin"), module.exports);
|
|
50
58
|
__reExport(src_exports, require("./plugin-manager"), module.exports);
|
|
51
|
-
__reExport(src_exports, require("./gateway"), module.exports);
|
|
52
|
-
__reExport(src_exports, require("./app-supervisor"), module.exports);
|
|
53
59
|
__reExport(src_exports, require("./sync-manager"), module.exports);
|
|
60
|
+
var import_findPackageNames = require("./plugin-manager/findPackageNames");
|
|
61
|
+
var import_run_plugin_static_imports = require("./run-plugin-static-imports");
|
|
54
62
|
const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
|
55
63
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
64
|
0 && (module.exports = {
|
|
57
65
|
OFFICIAL_PLUGIN_PREFIX,
|
|
66
|
+
appendToBuiltInPlugins,
|
|
67
|
+
findAllPlugins,
|
|
68
|
+
findBuiltInPlugins,
|
|
69
|
+
findLocalPlugins,
|
|
58
70
|
middlewares,
|
|
71
|
+
packageNameTrim,
|
|
72
|
+
runPluginStaticImports,
|
|
73
|
+
...require("./app-supervisor"),
|
|
59
74
|
...require("./application"),
|
|
75
|
+
...require("./gateway"),
|
|
60
76
|
...require("./migration"),
|
|
61
77
|
...require("./plugin"),
|
|
62
78
|
...require("./plugin-manager"),
|
|
63
|
-
...require("./gateway"),
|
|
64
|
-
...require("./app-supervisor"),
|
|
65
79
|
...require("./sync-manager")
|
|
66
80
|
});
|
package/lib/locale/locale.d.ts
CHANGED
package/lib/locale/locale.js
CHANGED
|
@@ -71,7 +71,9 @@ const _Locale = class _Locale {
|
|
|
71
71
|
await this.get(this.defaultLang);
|
|
72
72
|
}
|
|
73
73
|
async reload() {
|
|
74
|
-
|
|
74
|
+
const storers = Array.from(this.resourceStorers.getValues());
|
|
75
|
+
const promises = storers.map((storer) => storer.reset());
|
|
76
|
+
await Promise.all([this.cache.reset(), ...promises]);
|
|
75
77
|
}
|
|
76
78
|
setLocaleFn(name, fn) {
|
|
77
79
|
this.localeFn.set(name, fn);
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
declare function trim(packageNames: string[]): Promise<any[]>;
|
|
10
|
+
export declare function findPackageNames(): Promise<any[]>;
|
|
11
|
+
export declare function findBuiltInPlugins(): Promise<any[]>;
|
|
12
|
+
export declare function findLocalPlugins(): Promise<any[]>;
|
|
13
|
+
export declare function findAllPlugins(): Promise<any[]>;
|
|
14
|
+
export declare const packageNameTrim: typeof trim;
|
|
15
|
+
export declare function appendToBuiltInPlugins(nameOrPkg: string): Promise<void>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
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 findPackageNames_exports = {};
|
|
39
|
+
__export(findPackageNames_exports, {
|
|
40
|
+
appendToBuiltInPlugins: () => appendToBuiltInPlugins,
|
|
41
|
+
findAllPlugins: () => findAllPlugins,
|
|
42
|
+
findBuiltInPlugins: () => findBuiltInPlugins,
|
|
43
|
+
findLocalPlugins: () => findLocalPlugins,
|
|
44
|
+
findPackageNames: () => findPackageNames,
|
|
45
|
+
packageNameTrim: () => packageNameTrim
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(findPackageNames_exports);
|
|
48
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
49
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
50
|
+
var import_lodash = __toESM(require("lodash"));
|
|
51
|
+
var import_path = __toESM(require("path"));
|
|
52
|
+
var import__ = require("./");
|
|
53
|
+
function splitNames(name) {
|
|
54
|
+
return (name || "").split(",").filter(Boolean);
|
|
55
|
+
}
|
|
56
|
+
__name(splitNames, "splitNames");
|
|
57
|
+
async function trim(packageNames) {
|
|
58
|
+
const nameOrPkgs = import_lodash.default.uniq(packageNames).filter(Boolean);
|
|
59
|
+
const names = [];
|
|
60
|
+
for (const nameOrPkg of nameOrPkgs) {
|
|
61
|
+
const { name, packageName } = await import__.PluginManager.parseName(nameOrPkg);
|
|
62
|
+
try {
|
|
63
|
+
await import__.PluginManager.getPackageJson(packageName);
|
|
64
|
+
names.push(name);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return names;
|
|
69
|
+
}
|
|
70
|
+
__name(trim, "trim");
|
|
71
|
+
async function findPackageNames() {
|
|
72
|
+
const patterns = [
|
|
73
|
+
"./packages/plugins/*/package.json",
|
|
74
|
+
"./packages/plugins/*/*/package.json",
|
|
75
|
+
"./packages/pro-plugins/*/*/package.json",
|
|
76
|
+
"./storage/plugins/*/package.json",
|
|
77
|
+
"./storage/plugins/*/*/package.json"
|
|
78
|
+
];
|
|
79
|
+
try {
|
|
80
|
+
const packageJsonPaths = await (0, import_fast_glob.default)(patterns, {
|
|
81
|
+
cwd: process.cwd(),
|
|
82
|
+
absolute: true,
|
|
83
|
+
ignore: ["**/external-db-data-source/**"]
|
|
84
|
+
});
|
|
85
|
+
const packageNames = await Promise.all(
|
|
86
|
+
packageJsonPaths.map(async (packageJsonPath) => {
|
|
87
|
+
const packageJson = await import_fs_extra.default.readJson(packageJsonPath);
|
|
88
|
+
return packageJson.name;
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
const excludes = [
|
|
92
|
+
"@nocobase/plugin-audit-logs",
|
|
93
|
+
"@nocobase/plugin-backup-restore",
|
|
94
|
+
"@nocobase/plugin-charts",
|
|
95
|
+
"@nocobase/plugin-disable-pm-add",
|
|
96
|
+
"@nocobase/plugin-mobile-client",
|
|
97
|
+
"@nocobase/plugin-mock-collections",
|
|
98
|
+
"@nocobase/plugin-multi-app-share-collection",
|
|
99
|
+
"@nocobase/plugin-notifications",
|
|
100
|
+
"@nocobase/plugin-snapshot-field",
|
|
101
|
+
"@nocobase/plugin-workflow-test"
|
|
102
|
+
];
|
|
103
|
+
const nocobasePlugins = await findNocobasePlugins();
|
|
104
|
+
const { APPEND_PRESET_BUILT_IN_PLUGINS = "", APPEND_PRESET_LOCAL_PLUGINS = "" } = process.env;
|
|
105
|
+
return trim(
|
|
106
|
+
import_lodash.default.difference(packageNames, excludes).filter(Boolean).concat(nocobasePlugins).concat(splitNames(APPEND_PRESET_BUILT_IN_PLUGINS)).concat(splitNames(APPEND_PRESET_LOCAL_PLUGINS))
|
|
107
|
+
);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
__name(findPackageNames, "findPackageNames");
|
|
113
|
+
async function getPackageJson() {
|
|
114
|
+
const packageJson = await import_fs_extra.default.readJson(
|
|
115
|
+
import_path.default.resolve(process.env.NODE_MODULES_PATH, "@nocobase/preset-nocobase/package.json")
|
|
116
|
+
);
|
|
117
|
+
return packageJson;
|
|
118
|
+
}
|
|
119
|
+
__name(getPackageJson, "getPackageJson");
|
|
120
|
+
async function findNocobasePlugins() {
|
|
121
|
+
try {
|
|
122
|
+
const packageJson = await getPackageJson();
|
|
123
|
+
const pluginNames = Object.keys(packageJson.dependencies).filter((name) => name.startsWith("@nocobase/plugin-"));
|
|
124
|
+
return trim(pluginNames);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
__name(findNocobasePlugins, "findNocobasePlugins");
|
|
130
|
+
async function findBuiltInPlugins() {
|
|
131
|
+
const { APPEND_PRESET_BUILT_IN_PLUGINS = "" } = process.env;
|
|
132
|
+
try {
|
|
133
|
+
const packageJson = await getPackageJson();
|
|
134
|
+
return trim(packageJson.builtIn.concat(splitNames(APPEND_PRESET_BUILT_IN_PLUGINS)));
|
|
135
|
+
} catch (error) {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
__name(findBuiltInPlugins, "findBuiltInPlugins");
|
|
140
|
+
async function findLocalPlugins() {
|
|
141
|
+
const { APPEND_PRESET_LOCAL_PLUGINS = "" } = process.env;
|
|
142
|
+
const plugins1 = await findNocobasePlugins();
|
|
143
|
+
const plugins2 = await findPackageNames();
|
|
144
|
+
const builtInPlugins = await findBuiltInPlugins();
|
|
145
|
+
const packageJson = await getPackageJson();
|
|
146
|
+
const items = await trim(
|
|
147
|
+
import_lodash.default.difference(
|
|
148
|
+
plugins1.concat(plugins2).concat(splitNames(APPEND_PRESET_LOCAL_PLUGINS)),
|
|
149
|
+
builtInPlugins.concat(await trim(packageJson.deprecated))
|
|
150
|
+
)
|
|
151
|
+
);
|
|
152
|
+
return items;
|
|
153
|
+
}
|
|
154
|
+
__name(findLocalPlugins, "findLocalPlugins");
|
|
155
|
+
async function findAllPlugins() {
|
|
156
|
+
const builtInPlugins = await findBuiltInPlugins();
|
|
157
|
+
const localPlugins = await findLocalPlugins();
|
|
158
|
+
return import_lodash.default.uniq(builtInPlugins.concat(localPlugins));
|
|
159
|
+
}
|
|
160
|
+
__name(findAllPlugins, "findAllPlugins");
|
|
161
|
+
const packageNameTrim = trim;
|
|
162
|
+
async function appendToBuiltInPlugins(nameOrPkg) {
|
|
163
|
+
const APPEND_PRESET_BUILT_IN_PLUGINS = process.env.APPEND_PRESET_BUILT_IN_PLUGINS || "";
|
|
164
|
+
const keys = APPEND_PRESET_BUILT_IN_PLUGINS.split(",");
|
|
165
|
+
const { name, packageName } = await import__.PluginManager.parseName(nameOrPkg);
|
|
166
|
+
if (keys.includes(packageName)) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (keys.includes(name)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
process.env.APPEND_PRESET_BUILT_IN_PLUGINS += "," + nameOrPkg;
|
|
173
|
+
}
|
|
174
|
+
__name(appendToBuiltInPlugins, "appendToBuiltInPlugins");
|
|
175
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
176
|
+
0 && (module.exports = {
|
|
177
|
+
appendToBuiltInPlugins,
|
|
178
|
+
findAllPlugins,
|
|
179
|
+
findBuiltInPlugins,
|
|
180
|
+
findLocalPlugins,
|
|
181
|
+
findPackageNames,
|
|
182
|
+
packageNameTrim
|
|
183
|
+
});
|
|
@@ -146,7 +146,8 @@ var resource_default = {
|
|
|
146
146
|
async list(ctx, next) {
|
|
147
147
|
const locale = ctx.getCurrentLocale();
|
|
148
148
|
const pm = ctx.app.pm;
|
|
149
|
-
|
|
149
|
+
const plugin = pm.get("nocobase");
|
|
150
|
+
ctx.body = await plugin.getAllPlugins(locale);
|
|
150
151
|
await next();
|
|
151
152
|
},
|
|
152
153
|
async listEnabled(ctx, next) {
|
|
@@ -179,7 +180,8 @@ var resource_default = {
|
|
|
179
180
|
if (!filterByTk) {
|
|
180
181
|
ctx.throw(400, "plugin name invalid");
|
|
181
182
|
}
|
|
182
|
-
|
|
183
|
+
const plugin = pm.get("nocobase");
|
|
184
|
+
ctx.body = await plugin.getPluginInfo(filterByTk, locale);
|
|
183
185
|
await next();
|
|
184
186
|
}
|
|
185
187
|
}
|
|
@@ -54,6 +54,8 @@ const _PluginManagerRepository = class _PluginManagerRepository extends import_d
|
|
|
54
54
|
setPluginManager(pm) {
|
|
55
55
|
this.pm = pm;
|
|
56
56
|
}
|
|
57
|
+
async createByName(nameOrPkgs) {
|
|
58
|
+
}
|
|
57
59
|
async has(nameOrPkg) {
|
|
58
60
|
const { name } = await import_plugin_manager.PluginManager.parseName(nameOrPkg);
|
|
59
61
|
const instance = await this.findOne({
|
|
@@ -103,11 +105,19 @@ const _PluginManagerRepository = class _PluginManagerRepository extends import_d
|
|
|
103
105
|
return pluginNames;
|
|
104
106
|
}
|
|
105
107
|
async updateVersions() {
|
|
106
|
-
const items = await this.find(
|
|
108
|
+
const items = await this.find({
|
|
109
|
+
filter: {
|
|
110
|
+
enabled: true
|
|
111
|
+
}
|
|
112
|
+
});
|
|
107
113
|
for (const item of items) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
try {
|
|
115
|
+
const json = await import_plugin_manager.PluginManager.getPackageJson(item.packageName);
|
|
116
|
+
item.set("version", json.version);
|
|
117
|
+
await item.save();
|
|
118
|
+
} catch (error) {
|
|
119
|
+
this.pm.app.log.error(error);
|
|
120
|
+
}
|
|
111
121
|
}
|
|
112
122
|
}
|
|
113
123
|
/**
|
|
@@ -136,7 +146,10 @@ const _PluginManagerRepository = class _PluginManagerRepository extends import_d
|
|
|
136
146
|
return [];
|
|
137
147
|
}
|
|
138
148
|
return await this.find({
|
|
139
|
-
sort: "id"
|
|
149
|
+
sort: "id",
|
|
150
|
+
filter: {
|
|
151
|
+
enabled: true
|
|
152
|
+
}
|
|
140
153
|
});
|
|
141
154
|
}
|
|
142
155
|
async init() {
|
|
@@ -13,6 +13,7 @@ import Application from '../application';
|
|
|
13
13
|
import { Plugin } from '../plugin';
|
|
14
14
|
import { PluginManagerRepository } from './plugin-manager-repository';
|
|
15
15
|
import { PluginData } from './types';
|
|
16
|
+
import { checkAndGetCompatible } from './utils';
|
|
16
17
|
export declare const sleep: (timeout?: number) => Promise<unknown>;
|
|
17
18
|
export interface PluginManagerOptions {
|
|
18
19
|
app: Application;
|
|
@@ -28,6 +29,7 @@ export declare class AddPresetError extends Error {
|
|
|
28
29
|
}
|
|
29
30
|
export declare class PluginManager {
|
|
30
31
|
options: PluginManagerOptions;
|
|
32
|
+
static checkAndGetCompatible: typeof checkAndGetCompatible;
|
|
31
33
|
/**
|
|
32
34
|
* @internal
|
|
33
35
|
*/
|
|
@@ -57,10 +59,11 @@ export declare class PluginManager {
|
|
|
57
59
|
*/
|
|
58
60
|
_repository: PluginManagerRepository;
|
|
59
61
|
get repository(): PluginManagerRepository;
|
|
62
|
+
static packageExists(nameOrPkg: string): Promise<boolean>;
|
|
60
63
|
/**
|
|
61
64
|
* @internal
|
|
62
65
|
*/
|
|
63
|
-
static getPackageJson(
|
|
66
|
+
static getPackageJson(nameOrPkg: string): Promise<any>;
|
|
64
67
|
/**
|
|
65
68
|
* @internal
|
|
66
69
|
*/
|
|
@@ -47,10 +47,9 @@ __export(plugin_manager_exports, {
|
|
|
47
47
|
module.exports = __toCommonJS(plugin_manager_exports);
|
|
48
48
|
var import_topo = __toESM(require("@hapi/topo"));
|
|
49
49
|
var import_utils = require("@nocobase/utils");
|
|
50
|
-
var import_plugin_symlink = require("@nocobase/utils/plugin-symlink");
|
|
51
50
|
var import_execa = __toESM(require("execa"));
|
|
52
51
|
var import_fast_glob = __toESM(require("fast-glob"));
|
|
53
|
-
var
|
|
52
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
54
53
|
var import_lodash = __toESM(require("lodash"));
|
|
55
54
|
var import_path = require("path");
|
|
56
55
|
var import_helper = require("../helper");
|
|
@@ -120,12 +119,18 @@ const _PluginManager = class _PluginManager {
|
|
|
120
119
|
get repository() {
|
|
121
120
|
return this.app.db.getRepository("applicationPlugins");
|
|
122
121
|
}
|
|
122
|
+
static async packageExists(nameOrPkg) {
|
|
123
|
+
const { packageName } = await this.parseName(nameOrPkg);
|
|
124
|
+
const file = (0, import_path.resolve)(process.env.NODE_MODULES_PATH, packageName, "package.json");
|
|
125
|
+
return import_fs_extra.default.exists(file);
|
|
126
|
+
}
|
|
123
127
|
/**
|
|
124
128
|
* @internal
|
|
125
129
|
*/
|
|
126
|
-
static async getPackageJson(
|
|
127
|
-
const
|
|
128
|
-
const
|
|
130
|
+
static async getPackageJson(nameOrPkg) {
|
|
131
|
+
const { packageName } = await this.parseName(nameOrPkg);
|
|
132
|
+
const file = await import_fs_extra.default.realpath((0, import_path.resolve)(process.env.NODE_MODULES_PATH, packageName, "package.json"));
|
|
133
|
+
const data = await import_fs_extra.default.readFile(file, { encoding: "utf-8" });
|
|
129
134
|
return JSON.parse(data);
|
|
130
135
|
}
|
|
131
136
|
/**
|
|
@@ -135,7 +140,7 @@ const _PluginManager = class _PluginManager {
|
|
|
135
140
|
const prefixes = this.getPluginPkgPrefix();
|
|
136
141
|
for (const prefix of prefixes) {
|
|
137
142
|
const pkg = (0, import_path.resolve)(process.env.NODE_MODULES_PATH, `${prefix}${name}`, "package.json");
|
|
138
|
-
const exists = await
|
|
143
|
+
const exists = await import_fs_extra.default.exists(pkg);
|
|
139
144
|
if (exists) {
|
|
140
145
|
return `${prefix}${name}`;
|
|
141
146
|
}
|
|
@@ -193,8 +198,7 @@ const _PluginManager = class _PluginManager {
|
|
|
193
198
|
*/
|
|
194
199
|
static async resolvePlugin(pluginName, isUpgrade = false, isPkg = false) {
|
|
195
200
|
if (typeof pluginName === "string") {
|
|
196
|
-
const packageName =
|
|
197
|
-
this.clearCache(packageName);
|
|
201
|
+
const { packageName } = await this.parseName(pluginName);
|
|
198
202
|
return await (0, import_utils.importModule)(packageName);
|
|
199
203
|
} else {
|
|
200
204
|
return pluginName;
|
|
@@ -219,7 +223,7 @@ const _PluginManager = class _PluginManager {
|
|
|
219
223
|
return this.parsedNames[nameOrPkg];
|
|
220
224
|
}
|
|
221
225
|
const exists = /* @__PURE__ */ __name(async (name, isPreset = false) => {
|
|
222
|
-
return
|
|
226
|
+
return import_fs_extra.default.exists(
|
|
223
227
|
(0, import_path.resolve)(process.env.NODE_MODULES_PATH, `@nocobase/${isPreset ? "preset" : "plugin"}-${name}`, "package.json")
|
|
224
228
|
);
|
|
225
229
|
}, "exists");
|
|
@@ -271,7 +275,7 @@ const _PluginManager = class _PluginManager {
|
|
|
271
275
|
const createPlugin = /* @__PURE__ */ __name(async (name2) => {
|
|
272
276
|
const pluginDir = (0, import_path.resolve)(process.cwd(), "packages/plugins", name2);
|
|
273
277
|
if (options == null ? void 0 : options.forceRecreate) {
|
|
274
|
-
await
|
|
278
|
+
await import_fs_extra.default.rm(pluginDir, { recursive: true, force: true });
|
|
275
279
|
}
|
|
276
280
|
const { PluginGenerator } = require("@nocobase/cli/src/plugin-generator");
|
|
277
281
|
const generator = new PluginGenerator({
|
|
@@ -284,16 +288,6 @@ const _PluginManager = class _PluginManager {
|
|
|
284
288
|
await generator.run();
|
|
285
289
|
}, "createPlugin");
|
|
286
290
|
await createPlugin(pluginName);
|
|
287
|
-
try {
|
|
288
|
-
await this.app.db.auth({ retry: 1 });
|
|
289
|
-
const installed = await this.app.isInstalled();
|
|
290
|
-
if (!installed) {
|
|
291
|
-
console.log(`yarn pm add ${pluginName}`);
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
} catch (error) {
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
291
|
this.app.log.info("attempt to add the plugin to the app");
|
|
298
292
|
const { name, packageName } = await _PluginManager.parseName(pluginName);
|
|
299
293
|
const json = await _PluginManager.getPackageJson(packageName);
|
|
@@ -302,15 +296,6 @@ const _PluginManager = class _PluginManager {
|
|
|
302
296
|
packageName,
|
|
303
297
|
version: json.version
|
|
304
298
|
});
|
|
305
|
-
await this.repository.updateOrCreate({
|
|
306
|
-
values: {
|
|
307
|
-
name,
|
|
308
|
-
packageName,
|
|
309
|
-
version: json.version
|
|
310
|
-
},
|
|
311
|
-
filterKeys: ["name"]
|
|
312
|
-
});
|
|
313
|
-
await sleep(1e3);
|
|
314
299
|
await (0, import_helper.tsxRerunning)();
|
|
315
300
|
}
|
|
316
301
|
async add(plugin, options = {}, insert = false, isUpgrade = false) {
|
|
@@ -355,14 +340,6 @@ const _PluginManager = class _PluginManager {
|
|
|
355
340
|
if (options.packageName) {
|
|
356
341
|
this.pluginAliases.set(options.packageName, instance);
|
|
357
342
|
}
|
|
358
|
-
if (insert && options.name) {
|
|
359
|
-
await this.repository.updateOrCreate({
|
|
360
|
-
values: {
|
|
361
|
-
...options
|
|
362
|
-
},
|
|
363
|
-
filterKeys: ["name"]
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
343
|
await instance.afterAdd();
|
|
367
344
|
}
|
|
368
345
|
/**
|
|
@@ -485,16 +462,69 @@ const _PluginManager = class _PluginManager {
|
|
|
485
462
|
async enable(nameOrPkg) {
|
|
486
463
|
let pluginNames = nameOrPkg;
|
|
487
464
|
if (nameOrPkg === "*") {
|
|
488
|
-
const
|
|
489
|
-
pluginNames =
|
|
465
|
+
const plugin = this.get("nocobase");
|
|
466
|
+
pluginNames = await plugin.findLocalPlugins();
|
|
467
|
+
}
|
|
468
|
+
pluginNames = await this.sort(pluginNames);
|
|
469
|
+
try {
|
|
470
|
+
const added = {};
|
|
471
|
+
for (const name of pluginNames) {
|
|
472
|
+
const { name: pluginName } = await _PluginManager.parseName(name);
|
|
473
|
+
if (this.has(pluginName)) {
|
|
474
|
+
added[pluginName] = true;
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
await this.add(pluginName);
|
|
478
|
+
}
|
|
479
|
+
for (const name of pluginNames) {
|
|
480
|
+
const { name: pluginName } = await _PluginManager.parseName(name);
|
|
481
|
+
const plugin = this.get(pluginName);
|
|
482
|
+
if (!plugin) {
|
|
483
|
+
throw new Error(`${pluginName} plugin does not exist`);
|
|
484
|
+
}
|
|
485
|
+
if (added[pluginName]) {
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
const instance = await this.repository.findOne({
|
|
489
|
+
filter: {
|
|
490
|
+
name: pluginName
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
if (instance) {
|
|
494
|
+
plugin.enabled = instance.enabled;
|
|
495
|
+
plugin.installed = instance.installed;
|
|
496
|
+
}
|
|
497
|
+
if (plugin.enabled) {
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
await plugin.beforeLoad();
|
|
501
|
+
}
|
|
502
|
+
for (const name of pluginNames) {
|
|
503
|
+
const { name: pluginName } = await _PluginManager.parseName(name);
|
|
504
|
+
const plugin = this.get(pluginName);
|
|
505
|
+
if (!plugin) {
|
|
506
|
+
throw new Error(`${pluginName} plugin does not exist`);
|
|
507
|
+
}
|
|
508
|
+
if (added[pluginName]) {
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
if (plugin.enabled) {
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
await plugin.loadCollections();
|
|
515
|
+
await plugin.load();
|
|
516
|
+
}
|
|
517
|
+
} catch (error) {
|
|
518
|
+
await this.app.tryReloadOrRestart({
|
|
519
|
+
recover: true
|
|
520
|
+
});
|
|
521
|
+
throw error;
|
|
490
522
|
}
|
|
491
|
-
pluginNames = this.sort(pluginNames);
|
|
492
523
|
this.app.log.debug(`enabling plugin ${pluginNames.join(",")}`);
|
|
493
524
|
this.app.setMaintainingMessage(`enabling plugin ${pluginNames.join(",")}`);
|
|
494
525
|
const toBeUpdated = [];
|
|
495
526
|
for (const name of pluginNames) {
|
|
496
527
|
const { name: pluginName } = await _PluginManager.parseName(name);
|
|
497
|
-
console.log("pluginName", pluginName);
|
|
498
528
|
const plugin = this.get(pluginName);
|
|
499
529
|
if (!plugin) {
|
|
500
530
|
throw new Error(`${pluginName} plugin does not exist`);
|
|
@@ -505,7 +535,6 @@ const _PluginManager = class _PluginManager {
|
|
|
505
535
|
await this.app.emitAsync("beforeEnablePlugin", pluginName);
|
|
506
536
|
try {
|
|
507
537
|
await plugin.beforeEnable();
|
|
508
|
-
plugin.enabled = true;
|
|
509
538
|
toBeUpdated.push(pluginName);
|
|
510
539
|
} catch (error) {
|
|
511
540
|
if (nameOrPkg === "*") {
|
|
@@ -518,16 +547,7 @@ const _PluginManager = class _PluginManager {
|
|
|
518
547
|
if (toBeUpdated.length === 0) {
|
|
519
548
|
return;
|
|
520
549
|
}
|
|
521
|
-
await this.repository.update({
|
|
522
|
-
filter: {
|
|
523
|
-
name: toBeUpdated
|
|
524
|
-
},
|
|
525
|
-
values: {
|
|
526
|
-
enabled: true
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
550
|
try {
|
|
530
|
-
await this.app.reload();
|
|
531
551
|
this.app.log.debug(`syncing database in enable plugin ${toBeUpdated.join(",")}...`);
|
|
532
552
|
this.app.setMaintainingMessage(`syncing database in enable plugin ${toBeUpdated.join(",")}...`);
|
|
533
553
|
await this.app.db.sync();
|
|
@@ -540,32 +560,31 @@ const _PluginManager = class _PluginManager {
|
|
|
540
560
|
plugin.installed = true;
|
|
541
561
|
}
|
|
542
562
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
563
|
+
for (const pluginName of toBeUpdated) {
|
|
564
|
+
const { name } = await _PluginManager.parseName(pluginName);
|
|
565
|
+
const packageJson = await _PluginManager.getPackageJson(pluginName);
|
|
566
|
+
const values = {
|
|
567
|
+
name,
|
|
568
|
+
packageName: packageJson == null ? void 0 : packageJson.name,
|
|
569
|
+
enabled: true,
|
|
570
|
+
installed: true,
|
|
571
|
+
version: packageJson == null ? void 0 : packageJson.version
|
|
572
|
+
};
|
|
573
|
+
await this.repository.updateOrCreate({
|
|
574
|
+
values,
|
|
575
|
+
filterKeys: ["name"]
|
|
576
|
+
});
|
|
577
|
+
}
|
|
551
578
|
for (const pluginName of toBeUpdated) {
|
|
552
579
|
const plugin = this.get(pluginName);
|
|
553
580
|
this.app.log.debug(`emit afterEnablePlugin event...`);
|
|
554
581
|
await plugin.afterEnable();
|
|
582
|
+
plugin.enabled = true;
|
|
555
583
|
await this.app.emitAsync("afterEnablePlugin", pluginName);
|
|
556
584
|
this.app.log.debug(`afterEnablePlugin event emitted`);
|
|
557
585
|
}
|
|
558
586
|
await this.app.tryReloadOrRestart();
|
|
559
587
|
} catch (error) {
|
|
560
|
-
await this.repository.update({
|
|
561
|
-
filter: {
|
|
562
|
-
name: toBeUpdated
|
|
563
|
-
},
|
|
564
|
-
values: {
|
|
565
|
-
enabled: false,
|
|
566
|
-
installed: false
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
588
|
await this.app.tryReloadOrRestart({
|
|
570
589
|
recover: true
|
|
571
590
|
});
|
|
@@ -594,32 +613,24 @@ const _PluginManager = class _PluginManager {
|
|
|
594
613
|
if (toBeUpdated.length === 0) {
|
|
595
614
|
return;
|
|
596
615
|
}
|
|
597
|
-
await this.repository.update({
|
|
598
|
-
filter: {
|
|
599
|
-
name: toBeUpdated
|
|
600
|
-
},
|
|
601
|
-
values: {
|
|
602
|
-
enabled: false
|
|
603
|
-
}
|
|
604
|
-
});
|
|
605
616
|
try {
|
|
606
|
-
|
|
607
|
-
for (const pluginName of pluginNames) {
|
|
617
|
+
for (const pluginName of toBeUpdated) {
|
|
608
618
|
const plugin = this.get(pluginName);
|
|
609
619
|
this.app.log.debug(`emit afterDisablePlugin event...`);
|
|
610
620
|
await plugin.afterDisable();
|
|
611
621
|
await this.app.emitAsync("afterDisablePlugin", pluginName);
|
|
612
622
|
this.app.log.debug(`afterDisablePlugin event emitted`);
|
|
613
623
|
}
|
|
614
|
-
} catch (error) {
|
|
615
624
|
await this.repository.update({
|
|
616
625
|
filter: {
|
|
617
626
|
name: toBeUpdated
|
|
618
627
|
},
|
|
619
628
|
values: {
|
|
620
|
-
enabled:
|
|
629
|
+
enabled: false
|
|
621
630
|
}
|
|
622
631
|
});
|
|
632
|
+
await this.app.tryReloadOrRestart();
|
|
633
|
+
} catch (error) {
|
|
623
634
|
await this.app.tryReloadOrRestart({
|
|
624
635
|
recover: true
|
|
625
636
|
});
|
|
@@ -643,71 +654,42 @@ const _PluginManager = class _PluginManager {
|
|
|
643
654
|
records.map(async (plugin) => {
|
|
644
655
|
const dir = (0, import_path.resolve)(process.env.NODE_MODULES_PATH, plugin.packageName);
|
|
645
656
|
try {
|
|
646
|
-
const realDir = await
|
|
657
|
+
const realDir = await import_fs_extra.default.realpath(dir);
|
|
658
|
+
console.log("realDir", realDir);
|
|
647
659
|
this.app.log.debug(`rm -rf ${realDir}`);
|
|
648
|
-
return
|
|
660
|
+
return import_fs_extra.default.rm(realDir, { force: true, recursive: true });
|
|
649
661
|
} catch (error) {
|
|
650
662
|
return false;
|
|
651
663
|
}
|
|
652
664
|
})
|
|
653
665
|
);
|
|
654
|
-
await (0, import_execa.default)("yarn", ["nocobase", "postinstall"]);
|
|
655
666
|
}, "removeDir");
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
name: pluginNames
|
|
660
|
-
}
|
|
661
|
-
});
|
|
662
|
-
this.app.log.warn(`force remove plugins ${pluginNames.join(",")}`);
|
|
663
|
-
} else {
|
|
664
|
-
await this.app.load();
|
|
665
|
-
for (const pluginName of pluginNames) {
|
|
666
|
-
const plugin = this.get(pluginName);
|
|
667
|
-
if (!plugin) {
|
|
668
|
-
continue;
|
|
669
|
-
}
|
|
670
|
-
if (plugin.enabled) {
|
|
671
|
-
throw new Error(`plugin is enabled [${pluginName}]`);
|
|
672
|
-
}
|
|
673
|
-
await plugin.beforeRemove();
|
|
674
|
-
}
|
|
675
|
-
await this.repository.destroy({
|
|
676
|
-
filter: {
|
|
677
|
-
name: pluginNames
|
|
678
|
-
}
|
|
679
|
-
});
|
|
680
|
-
const plugins = [];
|
|
681
|
-
for (const pluginName of pluginNames) {
|
|
682
|
-
const plugin = this.get(pluginName);
|
|
683
|
-
if (!plugin) {
|
|
684
|
-
continue;
|
|
685
|
-
}
|
|
686
|
-
plugins.push(plugin);
|
|
687
|
-
this.del(pluginName);
|
|
688
|
-
await plugin.afterRemove();
|
|
689
|
-
}
|
|
690
|
-
if (await this.app.isStarted()) {
|
|
691
|
-
await this.app.tryReloadOrRestart();
|
|
667
|
+
await this.repository.destroy({
|
|
668
|
+
filter: {
|
|
669
|
+
name: pluginNames
|
|
692
670
|
}
|
|
693
|
-
}
|
|
694
|
-
if (
|
|
671
|
+
});
|
|
672
|
+
if (!this.app.db.getCollection("applications")) {
|
|
695
673
|
await removeDir();
|
|
696
674
|
}
|
|
697
|
-
await (0, import_execa.default)("yarn", ["nocobase", "refresh"], {
|
|
698
|
-
env: process.env
|
|
699
|
-
});
|
|
700
675
|
}
|
|
701
676
|
/**
|
|
702
677
|
* @internal
|
|
703
678
|
*/
|
|
704
679
|
async addViaCLI(urlOrName, options, emitStartedEvent = true) {
|
|
680
|
+
const writeFile = /* @__PURE__ */ __name(async () => {
|
|
681
|
+
if (process.env.VITEST) {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
const file = (0, import_path.resolve)(process.cwd(), "storage/.upgrading");
|
|
685
|
+
this.app.log.debug("pending upgrade");
|
|
686
|
+
await import_fs_extra.default.writeFile(file, "upgrading");
|
|
687
|
+
}, "writeFile");
|
|
688
|
+
await writeFile();
|
|
705
689
|
if (Array.isArray(urlOrName)) {
|
|
706
690
|
for (const packageName of urlOrName) {
|
|
707
691
|
await this.addViaCLI(packageName, import_lodash.default.omit(options, "name"), false);
|
|
708
692
|
}
|
|
709
|
-
await this.app.emitStartedEvent();
|
|
710
|
-
await (0, import_execa.default)("yarn", ["nocobase", "postinstall"]);
|
|
711
693
|
return;
|
|
712
694
|
}
|
|
713
695
|
if ((0, import_utils.isURL)(urlOrName)) {
|
|
@@ -718,7 +700,7 @@ const _PluginManager = class _PluginManager {
|
|
|
718
700
|
},
|
|
719
701
|
emitStartedEvent
|
|
720
702
|
);
|
|
721
|
-
} else if (await
|
|
703
|
+
} else if (await import_fs_extra.default.exists(urlOrName)) {
|
|
722
704
|
await this.addByCompressedFileUrl(
|
|
723
705
|
{
|
|
724
706
|
...options,
|
|
@@ -736,19 +718,6 @@ const _PluginManager = class _PluginManager {
|
|
|
736
718
|
},
|
|
737
719
|
emitStartedEvent
|
|
738
720
|
);
|
|
739
|
-
} else {
|
|
740
|
-
const { name, packageName } = await _PluginManager.parseName(urlOrName);
|
|
741
|
-
const opts = {
|
|
742
|
-
...options,
|
|
743
|
-
name,
|
|
744
|
-
packageName
|
|
745
|
-
};
|
|
746
|
-
await this.repository.findOne({ filter: { packageName } });
|
|
747
|
-
await this.add(name, opts, true);
|
|
748
|
-
}
|
|
749
|
-
if (emitStartedEvent) {
|
|
750
|
-
await this.app.emitStartedEvent();
|
|
751
|
-
await (0, import_execa.default)("yarn", ["nocobase", "postinstall"]);
|
|
752
721
|
}
|
|
753
722
|
}
|
|
754
723
|
/**
|
|
@@ -773,18 +742,7 @@ const _PluginManager = class _PluginManager {
|
|
|
773
742
|
async addByFile(options, throwError = true) {
|
|
774
743
|
const { file, authToken } = options;
|
|
775
744
|
const { packageName, tempFile, tempPackageContentDir } = await (0, import_utils2.downloadAndUnzipToTempDir)(file, authToken);
|
|
776
|
-
const { name } = await _PluginManager.parseName(packageName);
|
|
777
|
-
if (this.has(name)) {
|
|
778
|
-
await (0, import_utils2.removeTmpDir)(tempFile, tempPackageContentDir);
|
|
779
|
-
if (throwError) {
|
|
780
|
-
throw new Error(`plugin name [${name}] already exists`);
|
|
781
|
-
} else {
|
|
782
|
-
this.app.log.warn(`plugin name [${name}] already exists`);
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
745
|
await (0, import_utils2.copyTempPackageToStorageAndLinkToNodeModules)(tempFile, tempPackageContentDir, packageName);
|
|
787
|
-
return this.add(name, { packageName }, true);
|
|
788
746
|
}
|
|
789
747
|
/**
|
|
790
748
|
* @internal
|
|
@@ -795,18 +753,7 @@ const _PluginManager = class _PluginManager {
|
|
|
795
753
|
compressedFileUrl,
|
|
796
754
|
authToken
|
|
797
755
|
);
|
|
798
|
-
const { name } = await _PluginManager.parseName(packageName);
|
|
799
|
-
if (this.has(name)) {
|
|
800
|
-
await (0, import_utils2.removeTmpDir)(tempFile, tempPackageContentDir);
|
|
801
|
-
if (throwError) {
|
|
802
|
-
throw new Error(`plugin name [${name}] already exists`);
|
|
803
|
-
} else {
|
|
804
|
-
this.app.log.warn(`plugin name [${name}] already exists`);
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
756
|
await (0, import_utils2.copyTempPackageToStorageAndLinkToNodeModules)(tempFile, tempPackageContentDir, packageName);
|
|
809
|
-
return this.add(name, { packageName }, true);
|
|
810
757
|
}
|
|
811
758
|
async update(nameOrPkg, options, emitStartedEvent = true) {
|
|
812
759
|
const upgrade = /* @__PURE__ */ __name(async () => {
|
|
@@ -820,7 +767,7 @@ const _PluginManager = class _PluginManager {
|
|
|
820
767
|
return;
|
|
821
768
|
}
|
|
822
769
|
const file = (0, import_path.resolve)(process.cwd(), "storage/app-upgrading");
|
|
823
|
-
await
|
|
770
|
+
await import_fs_extra.default.writeFile(file, "", "utf-8");
|
|
824
771
|
await (0, import_helper.tsxRerunning)();
|
|
825
772
|
await (0, import_execa.default)("yarn", ["nocobase", "pm2-restart"], {
|
|
826
773
|
env: process.env
|
|
@@ -835,7 +782,7 @@ const _PluginManager = class _PluginManager {
|
|
|
835
782
|
const opts = { ...options };
|
|
836
783
|
if ((0, import_utils.isURL)(nameOrPkg)) {
|
|
837
784
|
opts.compressedFileUrl = nameOrPkg;
|
|
838
|
-
} else if (await
|
|
785
|
+
} else if (await import_fs_extra.default.exists(nameOrPkg)) {
|
|
839
786
|
opts.compressedFileUrl = nameOrPkg;
|
|
840
787
|
}
|
|
841
788
|
if (opts.compressedFileUrl) {
|
|
@@ -888,7 +835,6 @@ const _PluginManager = class _PluginManager {
|
|
|
888
835
|
repository: this.repository
|
|
889
836
|
});
|
|
890
837
|
const { name } = await _PluginManager.parseName(packageName);
|
|
891
|
-
await this.add(name, { name, version, packageName }, true, true);
|
|
892
838
|
}
|
|
893
839
|
/**
|
|
894
840
|
* @internal
|
|
@@ -1070,22 +1016,22 @@ const _PluginManager = class _PluginManager {
|
|
|
1070
1016
|
}
|
|
1071
1017
|
this["_initPresetPlugins"] = true;
|
|
1072
1018
|
}
|
|
1073
|
-
sort(names) {
|
|
1074
|
-
var _a, _b, _c;
|
|
1019
|
+
async sort(names) {
|
|
1075
1020
|
const pluginNames = import_lodash.default.castArray(names);
|
|
1076
1021
|
if (pluginNames.length === 1) {
|
|
1077
1022
|
return pluginNames;
|
|
1078
1023
|
}
|
|
1079
1024
|
const sorter = new import_topo.default.Sorter();
|
|
1080
1025
|
for (const pluginName of pluginNames) {
|
|
1081
|
-
const
|
|
1082
|
-
const peerDependencies = Object.keys((
|
|
1083
|
-
sorter.add(pluginName, { after: peerDependencies, group: (
|
|
1026
|
+
const packageJson = await _PluginManager.getPackageJson(pluginName);
|
|
1027
|
+
const peerDependencies = Object.keys((packageJson == null ? void 0 : packageJson.peerDependencies) || {});
|
|
1028
|
+
sorter.add(pluginName, { after: peerDependencies, group: (packageJson == null ? void 0 : packageJson.packageName) || pluginName });
|
|
1084
1029
|
}
|
|
1085
1030
|
return sorter.nodes;
|
|
1086
1031
|
}
|
|
1087
1032
|
};
|
|
1088
1033
|
__name(_PluginManager, "PluginManager");
|
|
1034
|
+
__publicField(_PluginManager, "checkAndGetCompatible", import_utils2.checkAndGetCompatible);
|
|
1089
1035
|
__publicField(_PluginManager, "parsedNames", {});
|
|
1090
1036
|
let PluginManager = _PluginManager;
|
|
1091
1037
|
var plugin_manager_default = PluginManager;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runPluginStaticImports(): Promise<void>;
|
|
@@ -0,0 +1,52 @@
|
|
|
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 __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var run_plugin_static_imports_exports = {};
|
|
29
|
+
__export(run_plugin_static_imports_exports, {
|
|
30
|
+
runPluginStaticImports: () => runPluginStaticImports
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(run_plugin_static_imports_exports);
|
|
33
|
+
var import_server = require("@nocobase/server");
|
|
34
|
+
async function runPluginStaticImports() {
|
|
35
|
+
const packages = await (0, import_server.findAllPlugins)();
|
|
36
|
+
for (const name of packages) {
|
|
37
|
+
const { packageName } = await import_server.PluginManager.parseName(name);
|
|
38
|
+
try {
|
|
39
|
+
const plugin = require(packageName);
|
|
40
|
+
if (plugin && plugin.staticImport) {
|
|
41
|
+
await plugin.staticImport();
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
__name(runPluginStaticImports, "runPluginStaticImports");
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
runPluginStaticImports
|
|
52
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0-alpha",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -10,23 +10,23 @@
|
|
|
10
10
|
"@koa/cors": "^3.1.0",
|
|
11
11
|
"@koa/multer": "^3.0.2",
|
|
12
12
|
"@koa/router": "^9.4.0",
|
|
13
|
-
"@nocobase/acl": "1.
|
|
14
|
-
"@nocobase/actions": "1.
|
|
15
|
-
"@nocobase/auth": "1.
|
|
16
|
-
"@nocobase/cache": "1.
|
|
17
|
-
"@nocobase/data-source-manager": "1.
|
|
18
|
-
"@nocobase/database": "1.
|
|
19
|
-
"@nocobase/evaluators": "1.
|
|
20
|
-
"@nocobase/logger": "1.
|
|
21
|
-
"@nocobase/resourcer": "1.
|
|
22
|
-
"@nocobase/sdk": "1.
|
|
23
|
-
"@nocobase/telemetry": "1.
|
|
24
|
-
"@nocobase/utils": "1.
|
|
13
|
+
"@nocobase/acl": "1.4.0-alpha",
|
|
14
|
+
"@nocobase/actions": "1.4.0-alpha",
|
|
15
|
+
"@nocobase/auth": "1.4.0-alpha",
|
|
16
|
+
"@nocobase/cache": "1.4.0-alpha",
|
|
17
|
+
"@nocobase/data-source-manager": "1.4.0-alpha",
|
|
18
|
+
"@nocobase/database": "1.4.0-alpha",
|
|
19
|
+
"@nocobase/evaluators": "1.4.0-alpha",
|
|
20
|
+
"@nocobase/logger": "1.4.0-alpha",
|
|
21
|
+
"@nocobase/resourcer": "1.4.0-alpha",
|
|
22
|
+
"@nocobase/sdk": "1.4.0-alpha",
|
|
23
|
+
"@nocobase/telemetry": "1.4.0-alpha",
|
|
24
|
+
"@nocobase/utils": "1.4.0-alpha",
|
|
25
25
|
"@types/decompress": "4.2.7",
|
|
26
26
|
"@types/ini": "^1.3.31",
|
|
27
27
|
"@types/koa-send": "^4.1.3",
|
|
28
28
|
"@types/multer": "^1.4.5",
|
|
29
|
-
"axios": "^
|
|
29
|
+
"axios": "^1.7.0",
|
|
30
30
|
"chalk": "^4.1.1",
|
|
31
31
|
"commander": "^9.2.0",
|
|
32
32
|
"cron": "^2.4.4",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"@types/serve-handler": "^6.1.1",
|
|
55
55
|
"@types/ws": "^8.5.5"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "f097a2bddec152522b5645bd5d451f4c866d2060"
|
|
58
58
|
}
|