fix: gen tsconfig.paths.json bug (#2708)
* fix: gen tsconfig.paths.json bug * fix: load remote plugin error * fix: bug
This commit is contained in:
parent
8fe4640f79
commit
836b34a6a4
@ -190,13 +190,8 @@ exports.genTsConfigPaths = function genTsConfigPaths() {
|
||||
const packageJsonName = require(packageFile).name;
|
||||
const packageDir = dirname(packageFile);
|
||||
const relativePath = packageDir.slice(cwdLength + 1).replace(/\\/, '/');
|
||||
const hasClient = fg.sync(['client', 'client.ts', 'client.tsx', 'client.js', 'client.jsx'], {
|
||||
cwd: join(packageDir, 'src'),
|
||||
}).length;
|
||||
if (hasClient) {
|
||||
paths[`${packageJsonName}/client`] = [`${relativePath}/src/client`];
|
||||
}
|
||||
paths[packageJsonName] = [`${relativePath}/src`];
|
||||
paths[`${packageJsonName}/client`] = [`${relativePath}/src/client`];
|
||||
});
|
||||
|
||||
const tsConfigJsonPath = join(cwd, './tsconfig.paths.json');
|
||||
|
@ -45,7 +45,6 @@ export class PluginManager {
|
||||
const plugins = await getPlugins({
|
||||
requirejs: this.app.requirejs,
|
||||
pluginData: pluginList,
|
||||
baseURL: this.app.apiClient.axios?.defaults?.baseURL,
|
||||
devDynamicImport: this.app.devDynamicImport,
|
||||
});
|
||||
for await (const plugin of plugins) {
|
||||
|
@ -9,30 +9,40 @@ export function defineDevPlugins(plugins: Record<string, typeof Plugin>) {
|
||||
});
|
||||
}
|
||||
|
||||
export function getRemotePlugins(
|
||||
requirejs: any,
|
||||
pluginData: PluginData[] = [],
|
||||
baseURL = '',
|
||||
): Promise<Array<typeof Plugin>> {
|
||||
if (baseURL.endsWith('/')) {
|
||||
baseURL = baseURL.slice(0, -1);
|
||||
}
|
||||
if (baseURL.endsWith('/api')) {
|
||||
baseURL = baseURL.slice(0, -4);
|
||||
}
|
||||
export function definePluginClient(packageName: string) {
|
||||
window.define(`${packageName}/client`, ['exports', packageName], function (_exports: any, _plugin: any) {
|
||||
Object.defineProperty(_exports, '__esModule', {
|
||||
value: true,
|
||||
});
|
||||
Object.keys(_plugin).forEach(function (key) {
|
||||
if (key === 'default' || key === '__esModule') return;
|
||||
if (key in _exports && _exports[key] === _plugin[key]) return;
|
||||
Object.defineProperty(_exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _plugin[key];
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function getRemotePlugins(requirejs: any, pluginData: PluginData[] = []): Promise<Array<typeof Plugin>> {
|
||||
requirejs.requirejs.config({
|
||||
waitSeconds: 120,
|
||||
paths: pluginData.reduce<Record<string, string>>((memo, item) => {
|
||||
memo[item.packageName] = `${baseURL}${item.url}?noExt`;
|
||||
memo[`${item.packageName}/client`] = `${baseURL}${item.url}?noExtAndIsClient`;
|
||||
return memo;
|
||||
paths: pluginData.reduce<Record<string, string>>((acc, cur) => {
|
||||
acc[cur.packageName] = `${cur.url}?noExt`;
|
||||
return acc;
|
||||
}, {}),
|
||||
});
|
||||
|
||||
const packageNames = pluginData.map((item) => item.packageName);
|
||||
packageNames.forEach((packageName) => {
|
||||
definePluginClient(packageName);
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
requirejs.requirejs(
|
||||
pluginData.map((item) => item.packageName),
|
||||
packageNames,
|
||||
(...plugins: (typeof Plugin & { default?: typeof Plugin })[]) => {
|
||||
const res = plugins.filter((item) => item).map((item) => item.default || item);
|
||||
resolve(res);
|
||||
@ -56,12 +66,11 @@ export function getRemotePlugins(
|
||||
interface GetPluginsOption {
|
||||
requirejs: RequireJS;
|
||||
pluginData: PluginData[];
|
||||
baseURL?: string;
|
||||
devDynamicImport?: DevDynamicImport;
|
||||
}
|
||||
|
||||
export async function getPlugins(options: GetPluginsOption): Promise<Array<typeof Plugin>> {
|
||||
const { requirejs, pluginData, baseURL, devDynamicImport } = options;
|
||||
const { requirejs, pluginData, devDynamicImport } = options;
|
||||
|
||||
if (pluginData.length === 0) return [];
|
||||
|
||||
@ -87,10 +96,10 @@ export async function getPlugins(options: GetPluginsOption): Promise<Array<typeo
|
||||
return plugins;
|
||||
}
|
||||
|
||||
const remotePluginList = await getRemotePlugins(requirejs, remotePlugins, baseURL);
|
||||
const remotePluginList = await getRemotePlugins(requirejs, remotePlugins);
|
||||
plugins.push(...remotePluginList);
|
||||
return plugins;
|
||||
}
|
||||
|
||||
return getRemotePlugins(requirejs, pluginData, baseURL);
|
||||
return getRemotePlugins(requirejs, pluginData);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { css, useAPIClient, useRequest } from '@nocobase/client';
|
||||
import { Select, Space, Spin, Typography } from 'antd';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { SwaggerUIBundle } from 'swagger-ui-dist';
|
||||
import SwaggerUIBundle from 'swagger-ui-dist/swagger-ui-bundle';
|
||||
import 'swagger-ui-dist/swagger-ui.css';
|
||||
import { useTranslation } from '../locale';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user