Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: plugin-layout不强依赖plugin-access #209

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/fes-plugin-layout/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ export default (api) => {
}),
});

const HAS_PLUGIN_ACCESS = api.hasPlugins(['@fesjs/plugin-access']);

api.writeTmpFile({
path: join(namespace, 'helpers/pluginAccess.js'),
content: Mustache.render(readFileSync(join(__dirname, 'runtime/helpers/pluginAccess.js.tpl'), 'utf-8'), {
HAS_PLUGIN_ACCESS,
}),
});

api.writeTmpFile({
path: absRuntimeFilePath,
content: Mustache.render(readFileSync(join(__dirname, 'runtime/runtime.js.tpl'), 'utf-8'), {
HAS_PLUGIN_ACCESS,
}),
});

api.copyTmpFiles({
namespace,
path: join(__dirname, 'runtime'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码的主要目的是根据环境和配置来生成临时文件。以下是对代码的简要审查:

  1. HAS_PLUGIN_ACCESS 是通过调用 api.hasPlugins(['@fesjs/plugin-access']) 来判断是否有特定插件的访问权限。

  2. 首先,使用 api.writeTmpFile() 方法创建一个临时文件,在指定的路径下写入内容。该文件的路径为 namespace 下的 'helpers/pluginAccess.js',内容是根据模板文件 runtime/helpers/pluginAccess.js.tplHAS_PLUGIN_ACCESS 的值渲染而成。

  3. 接下来,再次使用 api.writeTmpFile() 方法创建另一个临时文件,路径为 absRuntimeFilePath,内容也是根据模板文件 runtime/runtime.js.tplHAS_PLUGIN_ACCESS 的值渲染而成。

  4. 最后,使用 api.copyTmpFiles() 方法将当前目录下的 runtime 目录中的文件复制到指定的 namespace 目录下。

关于潜在的错误风险和改进建议,由于提供的代码片段不完整,无法全面评估其安全性和逻辑正确性。但可以注意以下几点:

  1. 确保模板文件 runtime/helpers/pluginAccess.js.tplruntime/runtime.js.tpl 存在并包含所需的内容。

  2. 确保操作的相关路径和命名空间的正确性。

  3. 检查代码中可能存在的错误处理逻辑,例如异常捕获和错误处理。

  4. 确保在文件操作期间考虑到并发访问的安全性,特别是当多个线程或进程同时访问相同的临时文件时。

请注意,这仅是对代码片段的简要审查。要进行全面的代码评估和测试,需要更详细地了解代码的整体结构、上下文以及用途。

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line
{{#HAS_PLUGIN_ACCESS}}
import { hasAccessSync } from '../../plugin-access/core';

if (!hasAccessSync) {
Expand Down Expand Up @@ -32,3 +32,11 @@ export const transform = (menus) =>
return menu;
})
.filter(Boolean);

{{/HAS_PLUGIN_ACCESS}}

{{^HAS_PLUGIN_ACCESS}}

export const transform = (menus) => menus;

{{/HAS_PLUGIN_ACCESS}}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// eslint-disable-next-line import/extensions
{{#HAS_PLUGIN_ACCESS}}
import { access as accessApi } from '../plugin-access/core';
// eslint-disable-next-line import/extensions
import getConfig from './helpers/getConfig';

if (!accessApi) {
Expand Down Expand Up @@ -42,3 +41,5 @@ export const access = (memo) => {
...memo,
};
};

{{/HAS_PLUGIN_ACCESS}}
140 changes: 21 additions & 119 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.