From 4372a8330c929868c74f7497d8094c5494e0eddb Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2698393+2betop@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:22:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20amis-editor=20?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E9=9D=A2=E6=9D=BF=E6=B2=A1=E6=9C=89=E7=BF=BB?= =?UTF-8?q?=E8=AF=91=E7=9A=84=E9=97=AE=E9=A2=98=20(#10974)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/rollup.config.js | 56 +++++++++---------- packages/amis-core/src/index.tsx | 4 ++ packages/amis-editor-core/rollup.config.js | 36 ++++++++---- packages/amis-editor-core/src/index.ts | 4 ++ packages/amis-editor/rollup.config.js | 39 ++++++++----- packages/amis-editor/src/index.tsx | 2 +- packages/amis-editor/src/validator.tsx | 1 + packages/amis-formula/rollup.config.js | 32 ++++++++--- .../amis-theme-editor-helper/rollup.config.js | 32 ++++++++--- packages/amis-ui/rollup.config.js | 40 +++++++------ packages/amis/rollup.config.js | 49 ++++++++-------- 11 files changed, 182 insertions(+), 113 deletions(-) diff --git a/packages/amis-core/rollup.config.js b/packages/amis-core/rollup.config.js index 9271493e1..f21c71f8b 100644 --- a/packages/amis-core/rollup.config.js +++ b/packages/amis-core/rollup.config.js @@ -15,6 +15,7 @@ import { dependencies } from './package.json'; import path from 'path'; +import fs from 'fs'; const isDev = process.env.NODE_ENV !== 'production'; @@ -22,38 +23,30 @@ const settings = { globals: {} }; -const external = id => { - const result = new RegExp( - `^(?:${Object.keys(dependencies) - .concat([ - 'react', - 'react-dom', - 'react-overlays', - 'warning', - 'tslib', - 'dom-helpers', - '@restart/hooks', - 'entities', - 'linkify-it', - 'markdown-it', - 'prop-types', - 'markdown-it-html5-media', - 'mdurl', - 'uc.micro', - '@babel/runtime' - ]) - .map(value => - value.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d') - ) - .join('|')})` - ).test(id); +const pkgs = []; +// 读取所有的node_modules目录,获取所有的包名 +[ + path.join(__dirname, './node_modules'), + path.join(__dirname, '../../node_modules') +].forEach(dir => { + if (fs.existsSync(dir)) { + fs.readdirSync(dir).forEach(item => { + if (item.startsWith('.')) { + return; + } - if (!result && ~id.indexOf('node_modules')) { - console.log(id); + if (item.startsWith('@')) { + fs.readdirSync(path.join(dir, item)).forEach(subItem => { + pkgs.push(item + '/' + subItem); + }); + } + + return pkgs.push(item); + }); } - - return result; -}; +}); +const external = id => + pkgs.some(pkg => id.startsWith(pkg) || ~id.indexOf(`node_modules/${pkg}`)); const input = './src/index.tsx'; /** 获取子包编译后的入口路径,需要使用相对路径 */ @@ -200,7 +193,8 @@ function getPlugins(format = 'esm') { }), replace({ preventAssignment: true, - __buildVersion: version + __buildVersion: version, + __buildTime: () => new Date().toISOString() }), typescript(typeScriptOptions), commonjs({ diff --git a/packages/amis-core/src/index.tsx b/packages/amis-core/src/index.tsx index 4a6d848aa..80d262769 100644 --- a/packages/amis-core/src/index.tsx +++ b/packages/amis-core/src/index.tsx @@ -125,6 +125,10 @@ import {StatusScoped} from './StatusScoped'; // @ts-ignore export const version = '__buildVersion'; +(window as any).amisVersionInfo = { + version: '__buildVersion', + buildTime: '__buildTime' +}; export { clearStoresCache, diff --git a/packages/amis-editor-core/rollup.config.js b/packages/amis-editor-core/rollup.config.js index 47e7bd628..e7e1111f5 100644 --- a/packages/amis-editor-core/rollup.config.js +++ b/packages/amis-editor-core/rollup.config.js @@ -14,8 +14,8 @@ import { dependencies } from './package.json'; import path from 'path'; -import svgr from '@svgr/rollup'; import fs from 'fs'; +import svgr from '@svgr/rollup'; import i18nPlugin from 'plugin-react-i18n'; import postcssImport from 'postcss-import'; import minify from 'postcss-minify'; @@ -30,15 +30,30 @@ const settings = { globals: {} }; +const pkgs = []; +// 读取所有的node_modules目录,获取所有的包名 +[ + path.join(__dirname, './node_modules'), + path.join(__dirname, '../../node_modules') +].forEach(dir => { + if (fs.existsSync(dir)) { + fs.readdirSync(dir).forEach(item => { + if (item.startsWith('.')) { + return; + } + + if (item.startsWith('@')) { + fs.readdirSync(path.join(dir, item)).forEach(subItem => { + pkgs.push(item + '/' + subItem); + }); + } + + return pkgs.push(item); + }); + } +}); const external = id => - new RegExp( - `^(?:${Object.keys(dependencies) - .concat(fs.readdirSync(path.join(__dirname, '../../node_modules'))) - .map(value => - value.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d') - ) - .join('|')})` - ).test(id); + pkgs.some(pkg => id.startsWith(pkg) || ~id.indexOf(`node_modules/${pkg}`)); const input = './src/index.ts'; export default [ @@ -152,7 +167,8 @@ function getPlugins(format = 'esm') { }), replace({ preventAssignment: true, - __buildVersion: version + __buildVersion: version, + __buildTime: () => new Date().toISOString() }), commonjs({ sourceMap: false diff --git a/packages/amis-editor-core/src/index.ts b/packages/amis-editor-core/src/index.ts index 8eed62013..7c4d5c3b0 100644 --- a/packages/amis-editor-core/src/index.ts +++ b/packages/amis-editor-core/src/index.ts @@ -44,6 +44,10 @@ import WidthDraggableContainer from './component/base/WidthDraggableContainer'; import {SchemaFrom} from './component/base/SchemaForm'; export const version = '__buildVersion'; +(window as any).amisEditorVersionInfo = { + version: '__buildVersion', + buildTime: '__buildTime' +}; export default Editor; diff --git a/packages/amis-editor/rollup.config.js b/packages/amis-editor/rollup.config.js index 4c898fde9..8c630227c 100644 --- a/packages/amis-editor/rollup.config.js +++ b/packages/amis-editor/rollup.config.js @@ -14,8 +14,8 @@ import { dependencies } from './package.json'; import path from 'path'; -import svgr from '@svgr/rollup'; import fs from 'fs'; +import svgr from '@svgr/rollup'; import i18nPlugin from 'plugin-react-i18n'; import moment from 'moment'; @@ -23,22 +23,33 @@ const i18nConfig = require('./i18nConfig'); const settings = { globals: {}, - commonConfig: { - footer: `window.amisEditorVersionInfo={version:'${version}',buildTime:'${moment().format( - 'YYYY-MM-DD' - )}'};` - } + commonConfig: {} }; +const pkgs = []; +// 读取所有的node_modules目录,获取所有的包名 +[ + path.join(__dirname, './node_modules'), + path.join(__dirname, '../../node_modules') +].forEach(dir => { + if (fs.existsSync(dir)) { + fs.readdirSync(dir).forEach(item => { + if (item.startsWith('.')) { + return; + } + + if (item.startsWith('@')) { + fs.readdirSync(path.join(dir, item)).forEach(subItem => { + pkgs.push(item + '/' + subItem); + }); + } + + return pkgs.push(item); + }); + } +}); const external = id => - new RegExp( - `^(?:${Object.keys(dependencies) - .concat(fs.readdirSync(path.join(__dirname, '../../node_modules'))) - .map(value => - value.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d') - ) - .join('|')})` - ).test(id); + pkgs.some(pkg => id.startsWith(pkg) || ~id.indexOf(`node_modules/${pkg}`)); const input = './src/index.tsx'; export default [ diff --git a/packages/amis-editor/src/index.tsx b/packages/amis-editor/src/index.tsx index 2aa90e77f..711719b05 100644 --- a/packages/amis-editor/src/index.tsx +++ b/packages/amis-editor/src/index.tsx @@ -1,5 +1,5 @@ import 'amis'; -import './locale/index'; +export * from './locale/index'; export * from 'amis-editor-core'; export * from './builder'; import './tpl/index'; diff --git a/packages/amis-editor/src/validator.tsx b/packages/amis-editor/src/validator.tsx index ebc197daa..9b65d68df 100644 --- a/packages/amis-editor/src/validator.tsx +++ b/packages/amis-editor/src/validator.tsx @@ -1,3 +1,4 @@ +import './locale/index'; /** * @file 所有可用验证器 */ diff --git a/packages/amis-formula/rollup.config.js b/packages/amis-formula/rollup.config.js index 5def7254a..72841b4e8 100644 --- a/packages/amis-formula/rollup.config.js +++ b/packages/amis-formula/rollup.config.js @@ -13,20 +13,36 @@ import { dependencies } from './package.json'; import path from 'path'; +import fs from 'fs'; const settings = { globals: {} }; +const pkgs = []; +// 读取所有的node_modules目录,获取所有的包名 +[ + path.join(__dirname, './node_modules'), + path.join(__dirname, '../../node_modules') +].forEach(dir => { + if (fs.existsSync(dir)) { + fs.readdirSync(dir).forEach(item => { + if (item.startsWith('.')) { + return; + } + + if (item.startsWith('@')) { + fs.readdirSync(path.join(dir, item)).forEach(subItem => { + pkgs.push(item + '/' + subItem); + }); + } + + return pkgs.push(item); + }); + } +}); const external = id => - new RegExp( - `^(?:${Object.keys(dependencies) - .concat([]) - .map(value => - value.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d') - ) - .join('|')})` - ).test(id); + pkgs.some(pkg => id.startsWith(pkg) || ~id.indexOf(`node_modules/${pkg}`)); export default [ { diff --git a/packages/amis-theme-editor-helper/rollup.config.js b/packages/amis-theme-editor-helper/rollup.config.js index 1aa0e7e68..ca2776c5a 100644 --- a/packages/amis-theme-editor-helper/rollup.config.js +++ b/packages/amis-theme-editor-helper/rollup.config.js @@ -15,6 +15,7 @@ import { dependencies } from './package.json'; import path from 'path'; +import fs from 'fs'; import svgr from '@svgr/rollup'; import fs from 'fs'; import i18nPlugin from 'plugin-react-i18n'; @@ -25,15 +26,30 @@ const settings = { globals: {} }; +const pkgs = []; +// 读取所有的node_modules目录,获取所有的包名 +[ + path.join(__dirname, './node_modules'), + path.join(__dirname, '../../node_modules') +].forEach(dir => { + if (fs.existsSync(dir)) { + fs.readdirSync(dir).forEach(item => { + if (item.startsWith('.')) { + return; + } + + if (item.startsWith('@')) { + fs.readdirSync(path.join(dir, item)).forEach(subItem => { + pkgs.push(item + '/' + subItem); + }); + } + + return pkgs.push(item); + }); + } +}); const external = id => - new RegExp( - `^(?:${Object.keys(dependencies ?? {}) - .concat(fs.readdirSync(path.join(__dirname, '../../node_modules'))) - .map(value => - value.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d') - ) - .join('|')})` - ).test(id); + pkgs.some(pkg => id.startsWith(pkg) || ~id.indexOf(`node_modules/${pkg}`)); const input = ['./src/index.ts']; export default [ diff --git a/packages/amis-ui/rollup.config.js b/packages/amis-ui/rollup.config.js index b5bfe4c09..5d0fe1dd8 100644 --- a/packages/amis-ui/rollup.config.js +++ b/packages/amis-ui/rollup.config.js @@ -19,29 +19,37 @@ import { dependencies } from './package.json'; import path from 'path'; +import fs from 'fs'; import svgr from '@svgr/rollup'; const settings = { globals: {} }; +const pkgs = []; +// 读取所有的node_modules目录,获取所有的包名 +[ + path.join(__dirname, './node_modules'), + path.join(__dirname, '../../node_modules') +].forEach(dir => { + if (fs.existsSync(dir)) { + fs.readdirSync(dir).forEach(item => { + if (item.startsWith('.')) { + return; + } + + if (item.startsWith('@')) { + fs.readdirSync(path.join(dir, item)).forEach(subItem => { + pkgs.push(item + '/' + subItem); + }); + } + + return pkgs.push(item); + }); + } +}); const external = id => - new RegExp( - `^(?:${Object.keys(dependencies) - .concat([ - 'linkify-it', - 'react-is', - 'markdown-it', - 'markdown-it-html5-media', - 'mdurl', - 'uc.micro', - 'entities' - ]) - .map(value => - value.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d') - ) - .join('|')})` - ).test(id); + pkgs.some(pkg => id.startsWith(pkg) || ~id.indexOf(`node_modules/${pkg}`)); const input = [ './src/index.tsx', './src/components/ColorPicker.tsx', // 默认不加载的需要手动维护列表,否则不会编译 diff --git a/packages/amis/rollup.config.js b/packages/amis/rollup.config.js index 66ab0f48d..dbe37fb96 100644 --- a/packages/amis/rollup.config.js +++ b/packages/amis/rollup.config.js @@ -14,42 +14,41 @@ import { dependencies } from './package.json'; import path from 'path'; +import fs from 'fs'; import svgr from '@svgr/rollup'; import moment from 'moment'; import babel from 'rollup-plugin-babel'; const settings = { globals: {}, - commonConfig: { - footer: `window.amisVersionInfo={version:'${version}',buildTime:'${moment().format( - 'YYYY-MM-DD' - )}'};` - } + commonConfig: {} }; -const external = id => { - const result = new RegExp( - `^(?:${Object.keys(dependencies) - .concat([ - 'monaco-editor', - 'react', - 'react-dom', - 'rc-input-number', - '@rc-component/mini-decimal', - '@babel/runtime' - ]) - .map(value => - value.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d') - ) - .join('|')})` - ).test(id); +const pkgs = []; +// 读取所有的node_modules目录,获取所有的包名 +[ + path.join(__dirname, './node_modules'), + path.join(__dirname, '../../node_modules') +].forEach(dir => { + if (fs.existsSync(dir)) { + fs.readdirSync(dir).forEach(item => { + if (item.startsWith('.')) { + return; + } - if (!result && ~id.indexOf('node_modules')) { - console.log(id); + if (item.startsWith('@')) { + fs.readdirSync(path.join(dir, item)).forEach(subItem => { + pkgs.push(item + '/' + subItem); + }); + } + + return pkgs.push(item); + }); } +}); +const external = id => + pkgs.some(pkg => id.startsWith(pkg) || ~id.indexOf(`node_modules/${pkg}`)); - return result; -}; const input = './src/index.tsx'; /** 获取子包编译后的入口路径,需要使用相对路径 */