@nocobase/server 0.13.0-alpha.9 → 0.14.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/app-supervisor.js +3 -1
- package/lib/application.d.ts +3 -1
- package/lib/application.js +16 -2
- package/lib/commands/pm.js +28 -2
- package/lib/gateway/index.d.ts +1 -0
- package/lib/gateway/index.js +33 -10
- package/lib/helper.d.ts +1 -0
- package/lib/helper.js +11 -2
- package/lib/migrations/20230912193824-package-name-unique.d.ts +4 -0
- package/lib/migrations/20230912193824-package-name-unique.js +66 -0
- package/lib/plugin-manager/clientStaticUtils.d.ts +23 -0
- package/lib/plugin-manager/clientStaticUtils.js +119 -0
- package/lib/plugin-manager/constants.d.ts +7 -0
- package/lib/plugin-manager/constants.js +126 -0
- package/lib/plugin-manager/deps.d.ts +2 -0
- package/lib/plugin-manager/deps.js +74 -0
- package/lib/plugin-manager/index.d.ts +1 -1
- package/lib/plugin-manager/index.js +2 -2
- package/lib/plugin-manager/middleware.d.ts +2 -0
- package/lib/plugin-manager/{clientStaticMiddleware.js → middleware.js} +14 -9
- package/lib/plugin-manager/options/collection.js +1 -0
- package/lib/plugin-manager/options/resource.d.ts +5 -1
- package/lib/plugin-manager/options/resource.js +116 -10
- package/lib/plugin-manager/plugin-manager-repository.d.ts +2 -0
- package/lib/plugin-manager/plugin-manager-repository.js +9 -0
- package/lib/plugin-manager/plugin-manager.d.ts +33 -3
- package/lib/plugin-manager/plugin-manager.js +226 -40
- package/lib/plugin-manager/types.d.ts +15 -0
- package/lib/plugin-manager/types.js +15 -0
- package/lib/plugin-manager/utils.d.ts +102 -0
- package/lib/plugin-manager/utils.js +523 -0
- package/lib/plugin.d.ts +1 -0
- package/lib/plugin.js +37 -0
- package/package.json +17 -12
- package/lib/gateway/handle-plugin-static-file.d.ts +0 -3
- package/lib/gateway/handle-plugin-static-file.js +0 -85
- package/lib/plugin-manager/clientStaticMiddleware.d.ts +0 -8
package/lib/app-supervisor.js
CHANGED
|
@@ -213,7 +213,9 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
213
213
|
});
|
|
214
214
|
app.on("__started", async (_app, options) => {
|
|
215
215
|
const { maintainingStatus } = options;
|
|
216
|
-
if (maintainingStatus && ["install", "upgrade", "pm.enable", "pm.disable"].includes(
|
|
216
|
+
if (maintainingStatus && ["install", "upgrade", "pm.add", "pm.update", "pm.enable", "pm.disable", "pm.remove"].includes(
|
|
217
|
+
maintainingStatus.command.name
|
|
218
|
+
)) {
|
|
217
219
|
this.setAppStatus(app.name, "running", {
|
|
218
220
|
refresh: true
|
|
219
221
|
});
|
package/lib/application.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { AuthManager } from '@nocobase/auth';
|
|
|
5
5
|
import { Cache, ICacheConfig } from '@nocobase/cache';
|
|
6
6
|
import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';
|
|
7
7
|
import { AppLoggerOptions, Logger } from '@nocobase/logger';
|
|
8
|
-
import {
|
|
8
|
+
import { ResourceOptions, Resourcer } from '@nocobase/resourcer';
|
|
9
9
|
import { AsyncEmitter, ToposortOptions } from '@nocobase/utils';
|
|
10
10
|
import { Command, CommandOptions, ParseOptions } from 'commander';
|
|
11
11
|
import { IncomingMessage, Server, ServerResponse } from 'http';
|
|
@@ -83,6 +83,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
83
83
|
private _maintaining;
|
|
84
84
|
private _maintainingCommandStatus;
|
|
85
85
|
private _maintainingStatusBeforeCommand;
|
|
86
|
+
private _actionCommand;
|
|
86
87
|
constructor(options: ApplicationOptions);
|
|
87
88
|
protected _loaded: boolean;
|
|
88
89
|
get loaded(): boolean;
|
|
@@ -136,6 +137,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
136
137
|
throwError?: boolean;
|
|
137
138
|
}): Promise<Command>;
|
|
138
139
|
start(options?: StartOptions): Promise<void>;
|
|
140
|
+
emitStartedEvent(): Promise<void>;
|
|
139
141
|
isStarted(): Promise<boolean>;
|
|
140
142
|
tryReloadOrRestart(): Promise<void>;
|
|
141
143
|
restart(options?: StartOptions): Promise<void>;
|
package/lib/application.js
CHANGED
|
@@ -73,6 +73,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
73
73
|
_maintaining = false;
|
|
74
74
|
_maintainingCommandStatus;
|
|
75
75
|
_maintainingStatusBeforeCommand;
|
|
76
|
+
_actionCommand;
|
|
76
77
|
_loaded;
|
|
77
78
|
get loaded() {
|
|
78
79
|
return this._loaded;
|
|
@@ -198,7 +199,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
198
199
|
this.log.info(`app.reload()`);
|
|
199
200
|
const oldDb = this._db;
|
|
200
201
|
this.init();
|
|
201
|
-
|
|
202
|
+
if (!oldDb.closed()) {
|
|
203
|
+
await oldDb.close();
|
|
204
|
+
}
|
|
202
205
|
}
|
|
203
206
|
this.setMaintainingMessage("init plugins");
|
|
204
207
|
await this.pm.initPlugins();
|
|
@@ -242,6 +245,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
242
245
|
}
|
|
243
246
|
createCli() {
|
|
244
247
|
const command = new import_commander.Command("nocobase").usage("[command] [options]").hook("preAction", async (_, actionCommand) => {
|
|
248
|
+
this._actionCommand = actionCommand;
|
|
245
249
|
this.activatedCommand = {
|
|
246
250
|
name: (0, import_helper.getCommandFullName)(actionCommand)
|
|
247
251
|
};
|
|
@@ -293,7 +297,13 @@ const _Application = class _Application extends import_koa.default {
|
|
|
293
297
|
throw error;
|
|
294
298
|
}
|
|
295
299
|
} finally {
|
|
300
|
+
const _actionCommand = this._actionCommand;
|
|
301
|
+
if (_actionCommand) {
|
|
302
|
+
_actionCommand["_optionValues"] = {};
|
|
303
|
+
_actionCommand["_optionValueSources"] = {};
|
|
304
|
+
}
|
|
296
305
|
this.activatedCommand = null;
|
|
306
|
+
this._actionCommand = null;
|
|
297
307
|
}
|
|
298
308
|
}
|
|
299
309
|
async start(options = {}) {
|
|
@@ -314,10 +324,13 @@ const _Application = class _Application extends import_koa.default {
|
|
|
314
324
|
await this.emitAsync("beforeStart", this, options);
|
|
315
325
|
this.setMaintainingMessage("emit afterStart");
|
|
316
326
|
await this.emitAsync("afterStart", this, options);
|
|
327
|
+
await this.emitStartedEvent();
|
|
328
|
+
this.stopped = false;
|
|
329
|
+
}
|
|
330
|
+
async emitStartedEvent() {
|
|
317
331
|
await this.emitAsync("__started", this, {
|
|
318
332
|
maintainingStatus: import_lodash.default.cloneDeep(this._maintainingCommandStatus)
|
|
319
333
|
});
|
|
320
|
-
this.stopped = false;
|
|
321
334
|
}
|
|
322
335
|
async isStarted() {
|
|
323
336
|
return this._started;
|
|
@@ -334,6 +347,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
334
347
|
return;
|
|
335
348
|
}
|
|
336
349
|
this._started = false;
|
|
350
|
+
await this.emitAsync("beforeStop");
|
|
337
351
|
await this.reload(options);
|
|
338
352
|
await this.start(options);
|
|
339
353
|
this.emit("__restarted", this, options);
|
package/lib/commands/pm.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
8
|
var __export = (target, all) => {
|
|
@@ -15,20 +17,44 @@ 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
|
var pm_exports = {};
|
|
20
30
|
__export(pm_exports, {
|
|
21
31
|
default: () => pm_default
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(pm_exports);
|
|
34
|
+
var import_lodash = __toESM(require("lodash"));
|
|
24
35
|
var import_plugin_command_error = require("../errors/plugin-command-error");
|
|
25
36
|
var pm_default = /* @__PURE__ */ __name((app) => {
|
|
26
37
|
const pm = app.command("pm");
|
|
27
38
|
pm.command("create").arguments("plugin").action(async (plugin) => {
|
|
28
39
|
await app.pm.create(plugin);
|
|
29
40
|
});
|
|
30
|
-
pm.command("add").
|
|
31
|
-
|
|
41
|
+
pm.command("add").argument("<pkg>").option("--registry [registry]").option("--auth-token [authToken]").option("--version [version]").action(async (name, options, cli) => {
|
|
42
|
+
console.log("pm.add", name, options);
|
|
43
|
+
try {
|
|
44
|
+
await app.pm.addViaCLI(name, import_lodash.default.cloneDeep(options));
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw new import_plugin_command_error.PluginCommandError(`Failed to add plugin: ${error.message}`);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
pm.command("update").argument("<packageName>").option("--path [path]").option("--url [url]").option("--registry [registry]").option("--auth-token [authToken]").option("--version [version]").action(async (packageName, options) => {
|
|
50
|
+
try {
|
|
51
|
+
await app.pm.update({
|
|
52
|
+
...options,
|
|
53
|
+
packageName
|
|
54
|
+
});
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new import_plugin_command_error.PluginCommandError(`Failed to update plugin: ${error.message}`);
|
|
57
|
+
}
|
|
32
58
|
});
|
|
33
59
|
pm.command("enable").arguments("<plugins...>").action(async (plugins) => {
|
|
34
60
|
try {
|
package/lib/gateway/index.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export declare class Gateway extends EventEmitter {
|
|
|
45
45
|
requestHandler(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
46
46
|
getRequestHandleAppName(req: IncomingRequest): Promise<string>;
|
|
47
47
|
getCallback(): any;
|
|
48
|
+
watch(): Promise<void>;
|
|
48
49
|
run(options: RunOptions): Promise<void>;
|
|
49
50
|
isStart(): boolean;
|
|
50
51
|
isHelp(): boolean;
|
package/lib/gateway/index.js
CHANGED
|
@@ -36,9 +36,12 @@ __export(gateway_exports, {
|
|
|
36
36
|
Gateway: () => Gateway
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(gateway_exports);
|
|
39
|
+
var import_utils = require("@nocobase/utils");
|
|
40
|
+
var import_plugin_symlink = require("@nocobase/utils/plugin-symlink");
|
|
39
41
|
var import_commander = require("commander");
|
|
40
42
|
var import_compression = __toESM(require("compression"));
|
|
41
43
|
var import_events = require("events");
|
|
44
|
+
var import_fs = __toESM(require("fs"));
|
|
42
45
|
var import_http = __toESM(require("http"));
|
|
43
46
|
var import_node_util = require("node:util");
|
|
44
47
|
var import_path = require("path");
|
|
@@ -47,6 +50,7 @@ var import_serve_handler = __toESM(require("serve-handler"));
|
|
|
47
50
|
var import_url = require("url");
|
|
48
51
|
var import_xpipe = __toESM(require("xpipe"));
|
|
49
52
|
var import_app_supervisor = require("../app-supervisor");
|
|
53
|
+
var import_plugin_manager = require("../plugin-manager");
|
|
50
54
|
var import_errors = require("./errors");
|
|
51
55
|
var import_ipc_socket_client = require("./ipc-socket-client");
|
|
52
56
|
var import_ipc_socket_server = require("./ipc-socket-server");
|
|
@@ -118,18 +122,17 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
118
122
|
public: (0, import_path.resolve)(process.cwd())
|
|
119
123
|
});
|
|
120
124
|
}
|
|
121
|
-
if (pathname.startsWith("/
|
|
125
|
+
if (pathname.startsWith(import_plugin_manager.PLUGIN_STATICS_PATH) && !pathname.includes("/server/")) {
|
|
122
126
|
await compress(req, res);
|
|
127
|
+
const packageName = (0, import_plugin_manager.getPackageNameByExposeUrl)(pathname);
|
|
128
|
+
const publicDir = (0, import_plugin_manager.getPackageDirByExposeUrl)(pathname);
|
|
129
|
+
const destination = pathname.replace(import_plugin_manager.PLUGIN_STATICS_PATH, "").replace(packageName, "");
|
|
123
130
|
return (0, import_serve_handler.default)(req, res, {
|
|
124
|
-
public:
|
|
131
|
+
public: publicDir,
|
|
125
132
|
rewrites: [
|
|
126
133
|
{
|
|
127
|
-
source:
|
|
128
|
-
destination
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
source: "/api/plugins/client/@:org/:plugin/:file",
|
|
132
|
-
destination: "/@:org/:plugin/dist/client/:file"
|
|
134
|
+
source: pathname,
|
|
135
|
+
destination
|
|
133
136
|
}
|
|
134
137
|
]
|
|
135
138
|
});
|
|
@@ -173,9 +176,21 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
173
176
|
getCallback() {
|
|
174
177
|
return this.requestHandler.bind(this);
|
|
175
178
|
}
|
|
179
|
+
async watch() {
|
|
180
|
+
if (!process.env.IS_DEV_CMD) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const file = (0, import_path.resolve)(process.cwd(), "storage/app.watch.ts");
|
|
184
|
+
if (!import_fs.default.existsSync(file)) {
|
|
185
|
+
await import_fs.default.promises.writeFile(file, `export const watchId = '${(0, import_utils.uid)()}';`, "utf-8");
|
|
186
|
+
}
|
|
187
|
+
require(file);
|
|
188
|
+
}
|
|
176
189
|
async run(options) {
|
|
177
190
|
const isStart = this.isStart();
|
|
191
|
+
let ipcClient;
|
|
178
192
|
if (isStart) {
|
|
193
|
+
await this.watch();
|
|
179
194
|
const startOptions = this.getStartOptions();
|
|
180
195
|
const port = startOptions.port || process.env.APP_PORT || 13e3;
|
|
181
196
|
const host = startOptions.host || process.env.APP_HOST || "0.0.0.0";
|
|
@@ -184,15 +199,23 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
184
199
|
host
|
|
185
200
|
});
|
|
186
201
|
} else if (!this.isHelp()) {
|
|
187
|
-
|
|
202
|
+
ipcClient = await this.tryConnectToIPCServer();
|
|
188
203
|
if (ipcClient) {
|
|
189
204
|
await ipcClient.write({ type: "passCliArgv", payload: { argv: process.argv } });
|
|
190
205
|
ipcClient.close();
|
|
191
206
|
return;
|
|
192
207
|
}
|
|
193
208
|
}
|
|
209
|
+
if (isStart || !ipcClient) {
|
|
210
|
+
await (0, import_plugin_symlink.createStoragePluginsSymlink)();
|
|
211
|
+
}
|
|
194
212
|
const mainApp = import_app_supervisor.AppSupervisor.getInstance().bootMainApp(options.mainAppOptions);
|
|
195
|
-
mainApp.runAsCLI(
|
|
213
|
+
mainApp.runAsCLI(process.argv, {
|
|
214
|
+
throwError: true,
|
|
215
|
+
from: "node"
|
|
216
|
+
}).catch((e) => {
|
|
217
|
+
console.error(e);
|
|
218
|
+
});
|
|
196
219
|
}
|
|
197
220
|
isStart() {
|
|
198
221
|
const argv = process.argv;
|
package/lib/helper.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export declare function createResourcer(options: ApplicationOptions): Resourcer;
|
|
|
8
8
|
export declare function registerMiddlewares(app: Application, options: ApplicationOptions): void;
|
|
9
9
|
export declare const createAppProxy: (app: Application) => Application<import("./application").DefaultState, import("./application").DefaultContext>;
|
|
10
10
|
export declare const getCommandFullName: (command: Command) => string;
|
|
11
|
+
export declare const tsxRerunning: () => Promise<void>;
|
package/lib/helper.js
CHANGED
|
@@ -33,14 +33,18 @@ __export(helper_exports, {
|
|
|
33
33
|
createI18n: () => createI18n,
|
|
34
34
|
createResourcer: () => createResourcer,
|
|
35
35
|
getCommandFullName: () => getCommandFullName,
|
|
36
|
-
registerMiddlewares: () => registerMiddlewares
|
|
36
|
+
registerMiddlewares: () => registerMiddlewares,
|
|
37
|
+
tsxRerunning: () => tsxRerunning
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(helper_exports);
|
|
39
40
|
var import_cors = __toESM(require("@koa/cors"));
|
|
40
41
|
var import_database = __toESM(require("@nocobase/database"));
|
|
41
42
|
var import_resourcer = require("@nocobase/resourcer");
|
|
43
|
+
var import_utils = require("@nocobase/utils");
|
|
44
|
+
var import_fs = __toESM(require("fs"));
|
|
42
45
|
var import_i18next = __toESM(require("i18next"));
|
|
43
46
|
var import_koa_bodyparser = __toESM(require("koa-bodyparser"));
|
|
47
|
+
var import_path = require("path");
|
|
44
48
|
var import_middlewares = require("./middlewares");
|
|
45
49
|
var import_data_template = require("./middlewares/data-template");
|
|
46
50
|
var import_data_wrapping = require("./middlewares/data-wrapping");
|
|
@@ -139,6 +143,10 @@ const getCommandFullName = /* @__PURE__ */ __name((command) => {
|
|
|
139
143
|
}
|
|
140
144
|
return names.join(".");
|
|
141
145
|
}, "getCommandFullName");
|
|
146
|
+
const tsxRerunning = /* @__PURE__ */ __name(async () => {
|
|
147
|
+
const file = (0, import_path.resolve)(process.cwd(), "storage/app.watch.ts");
|
|
148
|
+
await import_fs.default.promises.writeFile(file, `export const watchId = '${(0, import_utils.uid)()}';`, "utf-8");
|
|
149
|
+
}, "tsxRerunning");
|
|
142
150
|
// Annotate the CommonJS export names for ESM import in node:
|
|
143
151
|
0 && (module.exports = {
|
|
144
152
|
createAppProxy,
|
|
@@ -146,5 +154,6 @@ const getCommandFullName = /* @__PURE__ */ __name((command) => {
|
|
|
146
154
|
createI18n,
|
|
147
155
|
createResourcer,
|
|
148
156
|
getCommandFullName,
|
|
149
|
-
registerMiddlewares
|
|
157
|
+
registerMiddlewares,
|
|
158
|
+
tsxRerunning
|
|
150
159
|
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var package_name_unique_exports = {};
|
|
20
|
+
__export(package_name_unique_exports, {
|
|
21
|
+
default: () => package_name_unique_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(package_name_unique_exports);
|
|
24
|
+
var import_database = require("@nocobase/database");
|
|
25
|
+
var import_migration = require("../migration");
|
|
26
|
+
var import_plugin_manager = require("../plugin-manager");
|
|
27
|
+
const _package_name_unique_default = class _package_name_unique_default extends import_migration.Migration {
|
|
28
|
+
async up() {
|
|
29
|
+
const collection = this.db.getCollection("applicationPlugins");
|
|
30
|
+
if (!collection) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const tableNameWithSchema = collection.getTableNameWithSchema();
|
|
34
|
+
const field = collection.getField("packageName");
|
|
35
|
+
if (await field.existsInDb()) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
await this.db.sequelize.getQueryInterface().addColumn(tableNameWithSchema, field.columnName(), {
|
|
39
|
+
type: import_database.DataTypes.STRING
|
|
40
|
+
});
|
|
41
|
+
await this.db.sequelize.getQueryInterface().addConstraint(tableNameWithSchema, {
|
|
42
|
+
type: "unique",
|
|
43
|
+
fields: [field.columnName()]
|
|
44
|
+
});
|
|
45
|
+
const repository = this.db.getRepository("applicationPlugins");
|
|
46
|
+
const plugins = await repository.find();
|
|
47
|
+
for (const plugin of plugins) {
|
|
48
|
+
const { name } = plugin;
|
|
49
|
+
if (plugin.packageName) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const packageName = import_plugin_manager.PluginManager.getPackageName(name);
|
|
53
|
+
await repository.update({
|
|
54
|
+
filter: {
|
|
55
|
+
name
|
|
56
|
+
},
|
|
57
|
+
values: {
|
|
58
|
+
packageName
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
console.log(name, packageName);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
__name(_package_name_unique_default, "default");
|
|
66
|
+
let package_name_unique_default = _package_name_unique_default;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const PLUGIN_STATICS_PATH = "/static/plugins/";
|
|
2
|
+
/**
|
|
3
|
+
* get package.json path for specific NPM package
|
|
4
|
+
*/
|
|
5
|
+
export declare function getDepPkgPath(packageName: string, cwd?: string): string;
|
|
6
|
+
export declare function getPackageDir(packageName: string): string;
|
|
7
|
+
export declare function getPackageFilePath(packageName: string, filePath: string): string;
|
|
8
|
+
export declare function getPackageFilePathWithExistCheck(packageName: string, filePath: string): {
|
|
9
|
+
filePath: string;
|
|
10
|
+
exists: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function getExposeUrl(packageName: string, filePath: string): string;
|
|
13
|
+
export declare function getExposeReadmeUrl(packageName: string, lang: string): string;
|
|
14
|
+
export declare function getExposeChangelogUrl(packageName: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* get package name by client static url
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* getPluginNameByClientStaticUrl('/static/plugins/dayjs/index.js') => 'dayjs'
|
|
20
|
+
* getPluginNameByClientStaticUrl('/static/plugins/@nocobase/foo/README.md') => '@nocobase/foo'
|
|
21
|
+
*/
|
|
22
|
+
export declare function getPackageNameByExposeUrl(pathname: string): string;
|
|
23
|
+
export declare function getPackageDirByExposeUrl(pathname: string): string;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
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
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var clientStaticUtils_exports = {};
|
|
30
|
+
__export(clientStaticUtils_exports, {
|
|
31
|
+
PLUGIN_STATICS_PATH: () => PLUGIN_STATICS_PATH,
|
|
32
|
+
getDepPkgPath: () => getDepPkgPath,
|
|
33
|
+
getExposeChangelogUrl: () => getExposeChangelogUrl,
|
|
34
|
+
getExposeReadmeUrl: () => getExposeReadmeUrl,
|
|
35
|
+
getExposeUrl: () => getExposeUrl,
|
|
36
|
+
getPackageDir: () => getPackageDir,
|
|
37
|
+
getPackageDirByExposeUrl: () => getPackageDirByExposeUrl,
|
|
38
|
+
getPackageFilePath: () => getPackageFilePath,
|
|
39
|
+
getPackageFilePathWithExistCheck: () => getPackageFilePathWithExistCheck,
|
|
40
|
+
getPackageNameByExposeUrl: () => getPackageNameByExposeUrl
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(clientStaticUtils_exports);
|
|
43
|
+
var import_fs = __toESM(require("fs"));
|
|
44
|
+
var import_path = __toESM(require("path"));
|
|
45
|
+
const PLUGIN_STATICS_PATH = "/static/plugins/";
|
|
46
|
+
function getDepPkgPath(packageName, cwd) {
|
|
47
|
+
try {
|
|
48
|
+
return require.resolve(`${packageName}/package.json`, { paths: cwd ? [cwd] : void 0 });
|
|
49
|
+
} catch {
|
|
50
|
+
const mainFile = require.resolve(`${packageName}`, { paths: cwd ? [cwd] : void 0 });
|
|
51
|
+
const packageDir = mainFile.slice(0, mainFile.indexOf(packageName.replace("/", import_path.default.sep)) + packageName.length);
|
|
52
|
+
return import_path.default.join(packageDir, "package.json");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
__name(getDepPkgPath, "getDepPkgPath");
|
|
56
|
+
function getPackageDir(packageName) {
|
|
57
|
+
const packageJsonPath = getDepPkgPath(packageName);
|
|
58
|
+
return import_path.default.dirname(packageJsonPath);
|
|
59
|
+
}
|
|
60
|
+
__name(getPackageDir, "getPackageDir");
|
|
61
|
+
function getPackageFilePath(packageName, filePath) {
|
|
62
|
+
const packageDir = getPackageDir(packageName);
|
|
63
|
+
return import_path.default.join(packageDir, filePath);
|
|
64
|
+
}
|
|
65
|
+
__name(getPackageFilePath, "getPackageFilePath");
|
|
66
|
+
function getPackageFilePathWithExistCheck(packageName, filePath) {
|
|
67
|
+
const absolutePath = getPackageFilePath(packageName, filePath);
|
|
68
|
+
const exists = import_fs.default.existsSync(absolutePath);
|
|
69
|
+
return {
|
|
70
|
+
filePath: absolutePath,
|
|
71
|
+
exists
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
__name(getPackageFilePathWithExistCheck, "getPackageFilePathWithExistCheck");
|
|
75
|
+
function getExposeUrl(packageName, filePath) {
|
|
76
|
+
return `${PLUGIN_STATICS_PATH}${packageName}/${filePath}`;
|
|
77
|
+
}
|
|
78
|
+
__name(getExposeUrl, "getExposeUrl");
|
|
79
|
+
function getExposeReadmeUrl(packageName, lang) {
|
|
80
|
+
let READMEPath = null;
|
|
81
|
+
if (getPackageFilePathWithExistCheck(packageName, `README.${lang}.md`).exists) {
|
|
82
|
+
READMEPath = `README.${lang}.md`;
|
|
83
|
+
} else if (getPackageFilePathWithExistCheck(packageName, "README.md").exists) {
|
|
84
|
+
READMEPath = "README.md";
|
|
85
|
+
}
|
|
86
|
+
return READMEPath ? getExposeUrl(packageName, READMEPath) : null;
|
|
87
|
+
}
|
|
88
|
+
__name(getExposeReadmeUrl, "getExposeReadmeUrl");
|
|
89
|
+
function getExposeChangelogUrl(packageName) {
|
|
90
|
+
const { exists } = getPackageFilePathWithExistCheck(packageName, "CHANGELOG.md");
|
|
91
|
+
return exists ? getExposeUrl(packageName, "CHANGELOG.md") : null;
|
|
92
|
+
}
|
|
93
|
+
__name(getExposeChangelogUrl, "getExposeChangelogUrl");
|
|
94
|
+
function getPackageNameByExposeUrl(pathname) {
|
|
95
|
+
pathname = pathname.replace(PLUGIN_STATICS_PATH, "");
|
|
96
|
+
const pathArr = pathname.split("/");
|
|
97
|
+
if (pathname.startsWith("@")) {
|
|
98
|
+
return pathArr.slice(0, 2).join("/");
|
|
99
|
+
}
|
|
100
|
+
return pathArr[0];
|
|
101
|
+
}
|
|
102
|
+
__name(getPackageNameByExposeUrl, "getPackageNameByExposeUrl");
|
|
103
|
+
function getPackageDirByExposeUrl(pathname) {
|
|
104
|
+
return getPackageDir(getPackageNameByExposeUrl(pathname));
|
|
105
|
+
}
|
|
106
|
+
__name(getPackageDirByExposeUrl, "getPackageDirByExposeUrl");
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
PLUGIN_STATICS_PATH,
|
|
110
|
+
getDepPkgPath,
|
|
111
|
+
getExposeChangelogUrl,
|
|
112
|
+
getExposeReadmeUrl,
|
|
113
|
+
getExposeUrl,
|
|
114
|
+
getPackageDir,
|
|
115
|
+
getPackageDirByExposeUrl,
|
|
116
|
+
getPackageFilePath,
|
|
117
|
+
getPackageFilePathWithExistCheck,
|
|
118
|
+
getPackageNameByExposeUrl
|
|
119
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const APP_NAME = "nocobase";
|
|
2
|
+
export declare const DEFAULT_PLUGIN_STORAGE_PATH = "storage/plugins";
|
|
3
|
+
export declare const DEFAULT_PLUGIN_PATH = "packages/plugins/";
|
|
4
|
+
export declare const pluginPrefix: string[];
|
|
5
|
+
export declare const requireRegex: RegExp;
|
|
6
|
+
export declare const importRegex: RegExp;
|
|
7
|
+
export declare const EXTERNAL: string[];
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
APP_NAME: () => APP_NAME,
|
|
21
|
+
DEFAULT_PLUGIN_PATH: () => DEFAULT_PLUGIN_PATH,
|
|
22
|
+
DEFAULT_PLUGIN_STORAGE_PATH: () => DEFAULT_PLUGIN_STORAGE_PATH,
|
|
23
|
+
EXTERNAL: () => EXTERNAL,
|
|
24
|
+
importRegex: () => importRegex,
|
|
25
|
+
pluginPrefix: () => pluginPrefix,
|
|
26
|
+
requireRegex: () => requireRegex
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(constants_exports);
|
|
29
|
+
const APP_NAME = "nocobase";
|
|
30
|
+
const DEFAULT_PLUGIN_STORAGE_PATH = "storage/plugins";
|
|
31
|
+
const DEFAULT_PLUGIN_PATH = "packages/plugins/";
|
|
32
|
+
const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(",");
|
|
33
|
+
const requireRegex = /require\s*\(['"`](.*?)['"`]\)/g;
|
|
34
|
+
const importRegex = /^import(?:['"\s]*([\w*${}\s,]+)from\s*)?['"\s]['"\s](.*[@\w_-]+)['"\s].*/gm;
|
|
35
|
+
const EXTERNAL = [
|
|
36
|
+
// nocobase
|
|
37
|
+
"@nocobase/acl",
|
|
38
|
+
"@nocobase/actions",
|
|
39
|
+
"@nocobase/auth",
|
|
40
|
+
"@nocobase/cache",
|
|
41
|
+
"@nocobase/client",
|
|
42
|
+
"@nocobase/database",
|
|
43
|
+
"@nocobase/evaluators",
|
|
44
|
+
"@nocobase/logger",
|
|
45
|
+
"@nocobase/resourcer",
|
|
46
|
+
"@nocobase/sdk",
|
|
47
|
+
"@nocobase/server",
|
|
48
|
+
"@nocobase/test",
|
|
49
|
+
"@nocobase/utils",
|
|
50
|
+
// @nocobase/auth
|
|
51
|
+
"jsonwebtoken",
|
|
52
|
+
// @nocobase/cache
|
|
53
|
+
"cache-manager",
|
|
54
|
+
// @nocobase/database
|
|
55
|
+
"sequelize",
|
|
56
|
+
"umzug",
|
|
57
|
+
"async-mutex",
|
|
58
|
+
// @nocobase/evaluators
|
|
59
|
+
"@formulajs/formulajs",
|
|
60
|
+
"mathjs",
|
|
61
|
+
// @nocobase/logger
|
|
62
|
+
"winston",
|
|
63
|
+
"winston-daily-rotate-file",
|
|
64
|
+
// koa
|
|
65
|
+
"koa",
|
|
66
|
+
"@koa/cors",
|
|
67
|
+
"@koa/router",
|
|
68
|
+
"multer",
|
|
69
|
+
"@koa/multer",
|
|
70
|
+
"koa-bodyparser",
|
|
71
|
+
"koa-static",
|
|
72
|
+
"koa-send",
|
|
73
|
+
// react
|
|
74
|
+
"react",
|
|
75
|
+
"react-dom",
|
|
76
|
+
"react/jsx-runtime",
|
|
77
|
+
// react-router
|
|
78
|
+
"react-router",
|
|
79
|
+
"react-router-dom",
|
|
80
|
+
// antd
|
|
81
|
+
"antd",
|
|
82
|
+
"antd-style",
|
|
83
|
+
"@ant-design/icons",
|
|
84
|
+
"@ant-design/cssinjs",
|
|
85
|
+
// i18next
|
|
86
|
+
"i18next",
|
|
87
|
+
"react-i18next",
|
|
88
|
+
// dnd-kit 相关
|
|
89
|
+
"@dnd-kit/accessibility",
|
|
90
|
+
"@dnd-kit/core",
|
|
91
|
+
"@dnd-kit/modifiers",
|
|
92
|
+
"@dnd-kit/sortable",
|
|
93
|
+
"@dnd-kit/utilities",
|
|
94
|
+
// formily 相关
|
|
95
|
+
"@formily/antd-v5",
|
|
96
|
+
"@formily/core",
|
|
97
|
+
"@formily/react",
|
|
98
|
+
"@formily/json-schema",
|
|
99
|
+
"@formily/path",
|
|
100
|
+
"@formily/validator",
|
|
101
|
+
"@formily/shared",
|
|
102
|
+
"@formily/reactive",
|
|
103
|
+
"@formily/reactive-react",
|
|
104
|
+
// utils
|
|
105
|
+
"dayjs",
|
|
106
|
+
"mysql2",
|
|
107
|
+
"pg",
|
|
108
|
+
"pg-hstore",
|
|
109
|
+
"sqlite3",
|
|
110
|
+
"supertest",
|
|
111
|
+
"axios",
|
|
112
|
+
"@emotion/css",
|
|
113
|
+
"ahooks",
|
|
114
|
+
"lodash",
|
|
115
|
+
"china-division"
|
|
116
|
+
];
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
APP_NAME,
|
|
120
|
+
DEFAULT_PLUGIN_PATH,
|
|
121
|
+
DEFAULT_PLUGIN_STORAGE_PATH,
|
|
122
|
+
EXTERNAL,
|
|
123
|
+
importRegex,
|
|
124
|
+
pluginPrefix,
|
|
125
|
+
requireRegex
|
|
126
|
+
});
|