From dbea6d5ce828e343afc068f2e7e183dbc5a7efdc Mon Sep 17 00:00:00 2001 From: donniean <12584040+donniean@users.noreply.github.com> Date: Mon, 15 Jul 2024 18:32:55 +0800 Subject: [PATCH] build: release new version dependencies (#4082) (#4253) * build: remove useless dependencies * chore: remove unused @ks-console/shared-docs import * style: format * build: add publish-packages.local * build: clean up dependencies * chore: update import path in shared * build: update peerDependencies in core * chore: update * build: add minify for @ks-console/shared * chore: remove extensions/ * Revert "chore: remove extensions/" This reverts commit 148a6819216d14c37e1a16ba81b77a75bf6b35a2. * fix: resolve error * build: remove @ks-console/shared in extensions * build: remove libs from extension externals * build: remove @kubed/diff-viewer and @kubed/log-viewer in extension extenals * chore: add minify progress --------- Signed-off-by: donniean --- package.json | 21 ++++-- packages/appstore/package.json | 1 - packages/bootstrap/cli/webpack.js | 2 +- packages/bootstrap/package.json | 6 +- packages/bootstrap/webpack/config.js | 22 +++--- .../bootstrap/webpack/webpack.base.conf.js | 1 + .../bootstrap/webpack/webpack.dll.conf.js | 2 +- .../webpack/webpack.extension.conf.js | 22 +++--- packages/console/package.json | 12 +++- packages/core/package.json | 4 +- packages/shared/package.json | 11 ++- .../src/components/Apps/AppPreview/index.tsx | 2 +- .../AppLogInfo/AppLogInfo.tsx | 2 +- .../PopoverContent/PopoverContent.tsx | 2 +- .../ProjectLayout/ListLayout/index.tsx | 3 +- .../WorkspaceLayout/ListLayout/index.tsx | 4 +- .../src/components/WorkspaceLayout/index.tsx | 2 +- .../shared/src/stores/useClustersStore.ts | 2 +- packages/shared/src/utils/licenses.ts | 4 +- packages/shared/src/utils/nav.ts | 2 +- packages/shared/src/utils/workloads.ts | 2 +- scripts/build-packages.js | 50 ++++++++----- scripts/constants.ts | 66 +++++++++++++++++ scripts/libs/create-rollup-config.js | 2 +- scripts/publish-packages.local.ts | 11 +++ scripts/terser.config.json | 7 ++ server/configs/systemImports.js | 22 +++--- yarn.lock | 70 ++++++++++++++++--- 28 files changed, 265 insertions(+), 92 deletions(-) create mode 100644 scripts/constants.ts create mode 100644 scripts/publish-packages.local.ts create mode 100644 scripts/terser.config.json diff --git a/package.json b/package.json index 4bcdb5a9ff4..ee2740e5c42 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,12 @@ "url": "git@git@github.com:kubesphere/console.git" }, "license": "AGPL-3.0", - "workspaces": ["packages/*", "extensions/*", "server", "locales"], + "workspaces": [ + "packages/*", + "extensions/*", + "server", + "locales" + ], "scripts": { "build": "yarn build:dll && yarn build:locales && yarn build:prod && yarn build:server", "build:dll": "ksc build:dll -s true", @@ -16,17 +21,20 @@ "build:packages": "esno scripts/build-packages.js", "build:prod": "cross-env dll=true ksc build:prod -s true", "build:server": "NODE_ENV=production webpack --config scripts/webpack.server.js --stats errors-only", - "clean": "rimraf packages/*/{esm,cjs,lib,dist} packages/**/*.tsbuildinfo locales/dist", + "clean": "rimraf packages/*/{esm,cjs,lib,dist} packages/**/*.tsbuildinfo locales/dist dist", "create:ext": "ksc create:ext", "dev": "concurrently -k --raw 'yarn dev:client' 'yarn dev:server'", "dev:client": "NODE_ENV=development ksc dev -s true", "dev:server": "NODE_ENV=development ksc-server", + "publish:packages:local": "yarn clean && yarn build:locales && yarn build:server && yarn build:packages && esno scripts/publish-packages.local.ts", "serve": "NODE_ENV=production node server/server.js" }, - "browserslist": ["> 1%", "last 2 versions", "not ie <= 8"], + "browserslist": [ + "> 1%", + "last 2 versions", + "not ie <= 8" + ], "dependencies": { - "@dnd-kit/core": "^6.1.0", - "@dnd-kit/sortable": "^8.0.0", "@kubed/charts": "^0.0.22", "@kubed/code-editor": "^0.0.27", "@kubed/components": "^0.2.8", @@ -124,7 +132,6 @@ "execa": "^6.1.0", "fast-glob": "^3.2.11", "file-loader": "^6.0.0", - "for-editor": "^0.3.5", "fork-ts-checker-webpack-plugin": "^6.3.5", "friendly-errors-webpack-plugin": "^1.7.0", "fs-extra": "^10.0.0", @@ -148,7 +155,7 @@ "shelljs": "^0.8.4", "style-loader": "^1.1.3", "systemjs-webpack-interop": "^2.3.7", - "terser": "^5.9.0", + "terser": "^5.31.1", "terser-webpack-plugin": "^5.2.4", "ts-loader": "^9.2.6", "typescript": "4.5.5", diff --git a/packages/appstore/package.json b/packages/appstore/package.json index 495067c2383..829e68e77cf 100644 --- a/packages/appstore/package.json +++ b/packages/appstore/package.json @@ -10,7 +10,6 @@ "nanoid": "^3.0.0" }, "peerDependencies": { - "@ks-console/console": "^4.1.0", "@ks-console/shared": "^4.1.0", "@kubed/code-editor": "^0.0.27", "@kubed/components": "^0.2.8", diff --git a/packages/bootstrap/cli/webpack.js b/packages/bootstrap/cli/webpack.js index 3d441242360..43ebc3aa7ca 100644 --- a/packages/bootstrap/cli/webpack.js +++ b/packages/bootstrap/cli/webpack.js @@ -15,7 +15,7 @@ const alias = { '@ks-console/core': resolve('packages/core/src'), '@ks-console/console': resolve('packages/console/src'), '@ks-console/appstore': resolve('packages/appstore/src'), - '@ks-console/shared-docs': resolve('packages/shared-docs/src'), + // '@ks-console/shared-docs': resolve('packages/shared-docs/src'), }; async function devServer(setAlias, checkUpgrade) { diff --git a/packages/bootstrap/package.json b/packages/bootstrap/package.json index fa4680bf9c9..ab630d5d4ec 100644 --- a/packages/bootstrap/package.json +++ b/packages/bootstrap/package.json @@ -13,13 +13,13 @@ }, "browserslist": ["> 1%", "last 2 versions", "not ie <= 8"], "dependencies": { - "@ks-console/appstore": "^4.1.0", - "@ks-console/console": "^4.1.0", - "@ks-console/core": "^4.1.0", "@ks-console/locales": "^4.1.0", "mustache": "^4.2.0", "npm-checky": "^1.0.4" }, + "devDependencies": { + "path-browserify": "^1.0.1" + }, "engines": { "node": ">= 16.0.0" }, diff --git a/packages/bootstrap/webpack/config.js b/packages/bootstrap/webpack/config.js index 1fbb7548930..def8a549236 100644 --- a/packages/bootstrap/webpack/config.js +++ b/packages/bootstrap/webpack/config.js @@ -20,21 +20,23 @@ const config = { }; const systemImports = { + // '@ks-console/shared': 'core:@kubed/@ks-console/shared', + '@kubed/charts': 'core:@kubed/charts', + '@kubed/code-editor': 'core:@kubed/code-editor', + '@kubed/components': 'core:@kubed/components', + // '@kubed/diff-viewer': 'core:@kubed/diff-viewer', + '@kubed/hooks': 'core:@kubed/hooks', + '@kubed/icons': 'core:@kubed/icons', + // '@kubed/log-viewer': 'core:@kubed/log-viewer', + // dayjs: 'core:dayjs', + // lodash: 'core:lodash', react: 'core:react', 'react-dom': 'core:react-dom', + // 'react-markdown': 'core:react-markdown', + 'react-query': 'core:react-query', 'react-router-dom': 'core:react-router-dom', 'styled-components': 'core:styled-components', - lodash: 'core:lodash', - 'react-query': 'core:react-query', - 'react-markdown': 'core:react-markdown', - '@kubed/components': 'core:@kubed/components', - '@kubed/hooks': 'core:@kubed/hooks', - '@kubed/icons': 'core:@kubed/icons', - '@kubed/code-editor': 'core:@kubed/code-editor', - '@kubed/charts': 'core:@kubed/charts', - '@ks-console/shared': 'core:@kubed/@ks-console/shared', 'wujie-react': 'core:wujie-react', - dayjs: 'core:dayjs', }; const locales = ['ar', 'en', 'es', 'fr', 'hi', 'ko', 'lt', 'pl', 'tc', 'tr', 'zh']; diff --git a/packages/bootstrap/webpack/webpack.base.conf.js b/packages/bootstrap/webpack/webpack.base.conf.js index 7735661424a..4cd62e54cd3 100644 --- a/packages/bootstrap/webpack/webpack.base.conf.js +++ b/packages/bootstrap/webpack/webpack.base.conf.js @@ -32,6 +32,7 @@ const webpackBaseConfig = merge(configs, { alias: { 'styled-components': resolve('node_modules/styled-components'), }, + fallback: { path: require.resolve('path-browserify') }, }, module: { rules: [ diff --git a/packages/bootstrap/webpack/webpack.dll.conf.js b/packages/bootstrap/webpack/webpack.dll.conf.js index 5cd4cde6974..c60985026f2 100644 --- a/packages/bootstrap/webpack/webpack.dll.conf.js +++ b/packages/bootstrap/webpack/webpack.dll.conf.js @@ -19,7 +19,7 @@ const config = { entry: { common: [ 'react', - 'react-is', + // 'react-is', 'react-dom', 'react-router-dom', 'react-query', diff --git a/packages/bootstrap/webpack/webpack.extension.conf.js b/packages/bootstrap/webpack/webpack.extension.conf.js index e29aaa2f2ce..e7b26ac4d45 100644 --- a/packages/bootstrap/webpack/webpack.extension.conf.js +++ b/packages/bootstrap/webpack/webpack.extension.conf.js @@ -105,20 +105,22 @@ module.exports = merge( }, ], externals: [ - 'react', - 'react-is', - 'react-dom', - 'react-router-dom', - 'react-query', - 'lodash', + // '@ks-console/shared', + '@kubed/charts', + '@kubed/code-editor', '@kubed/components', + // '@kubed/diff-viewer', '@kubed/hooks', '@kubed/icons', - '@kubed/code-editor', - '@kubed/charts', - '@ks-console/shared', + // '@kubed/log-viewer', + // 'lodash', + 'react', + 'react-dom', + // 'react-is', + // 'react-markdown', + 'react-query', + 'react-router-dom', 'styled-components', - 'react-markdown', 'wujie-react', ], }, diff --git a/packages/console/package.json b/packages/console/package.json index 90bd66c890f..98378ba9d4a 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -5,8 +5,15 @@ "main": "cjs/index.js", "module": "esm/index.js", "types": "lib/src/index.d.ts", - "files": ["cjs", "esm", "lib"], + "files": [ + "cjs", + "esm", + "lib" + ], "dependencies": { + "@dnd-kit/core": "^6.1.0", + "@dnd-kit/sortable": "^8.0.0", + "@dnd-kit/utilities": "^3.2.2", "async-validator": "4.2.5", "file-saver": "^2.0.5", "for-editor": "^0.3.5", @@ -16,8 +23,7 @@ "react-markdown": "^7.1.1", "react-table": "^7.7.0", "react-textarea-autosize": "^8.3.2", - "wujie-react": "^1.0.6", - "zod": "^3.22.4" + "wujie-react": "^1.0.6" }, "devDependencies": { "@types/react-input-autosize": "^2.2.1" diff --git a/packages/core/package.json b/packages/core/package.json index e9de44c18a9..26b3e272d43 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -15,7 +15,6 @@ "lodash": "^4.17.20", "minimatch": "^9.0.3", "react-draggable": "^4.4.5", - "react-markdown": "^7.1.1", "react-syntax-highlighter": "^15.5.0", "react-use": "^17.4.2", "remark-gfm": "^3.0.1", @@ -24,9 +23,12 @@ "wujie-react": "^1.0.6" }, "devDependencies": { + "@types/netmask": "^2.0.5", "@types/react-syntax-highlighter": "^15.5.11" }, "peerDependencies": { + "@ks-console/appstore": "^4.1.0", + "@ks-console/console": "^4.1.0", "@ks-console/shared": "^4.1.0", "@kubed/charts": "^0.0.22", "@kubed/code-editor": "^0.0.27", diff --git a/packages/shared/package.json b/packages/shared/package.json index e843d2537ab..8d4543f9791 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -2,10 +2,11 @@ "name": "@ks-console/shared", "version": "4.1.0", "description": "", - "main": "cjs/index.js", - "module": "esm/index.js", + "module": "lib/index.js", "types": "lib/index.d.ts", - "files": ["cjs", "esm", "lib"], + "files": [ + "lib" + ], "dependencies": { "@kubed/stook": "^0.0.4", "async-validator": "4.2.5", @@ -15,7 +16,6 @@ "js-base64": "^3.7.2", "js-yaml": "^3.13.1", "nanoid": "^3.0.0", - "netmask": "^2.0.1", "path-to-regexp": "^2.2.1", "react-infinite-scroll-hook": "^4.1.1", "react-markdown": "^7.1.1", @@ -31,8 +31,7 @@ "devDependencies": { "@types/file-saver": "^2.0.5", "@types/js-yaml": "^4.0.5", - "@types/nanoid": "^2.1.0", - "@types/netmask": "^1.0.30" + "@types/nanoid": "^2.1.0" }, "peerDependencies": { "@kubed/charts": "^0.0.22", diff --git a/packages/shared/src/components/Apps/AppPreview/index.tsx b/packages/shared/src/components/Apps/AppPreview/index.tsx index 757b906d031..de1ef7d952d 100644 --- a/packages/shared/src/components/Apps/AppPreview/index.tsx +++ b/packages/shared/src/components/Apps/AppPreview/index.tsx @@ -1,7 +1,7 @@ import React, { useMemo, useEffect } from 'react'; import { Loading } from '@kubed/components'; -import { Markdown } from '@ks-console/shared'; +import { Markdown } from '../../Markdown'; import TextPreview from '../../TextPreview'; import { openpitrixStore } from '../../../stores'; diff --git a/packages/shared/src/components/Apps/AppStatusWithLogInfo/AppLogInfo/AppLogInfo.tsx b/packages/shared/src/components/Apps/AppStatusWithLogInfo/AppLogInfo/AppLogInfo.tsx index 00a1dc0ddf7..75414df608f 100644 --- a/packages/shared/src/components/Apps/AppStatusWithLogInfo/AppLogInfo/AppLogInfo.tsx +++ b/packages/shared/src/components/Apps/AppStatusWithLogInfo/AppLogInfo/AppLogInfo.tsx @@ -3,7 +3,7 @@ import { useDisclosure } from '@kubed/hooks'; import { AppLogModal } from '../../../Modals/AppLogModal'; import { TooltipIcon } from './TooltipIcon'; import { typeProps } from './PopoverContent'; -import { StatusIndicatorProps } from '@ks-console/shared'; +import type { StatusIndicatorProps } from '../../../StatusIndicator'; import { getStatusDotColor } from '../../../StatusIndicator/utils'; export interface LogButtonProps extends Pick { diff --git a/packages/shared/src/components/Apps/AppStatusWithLogInfo/AppLogInfo/PopoverContent/PopoverContent.tsx b/packages/shared/src/components/Apps/AppStatusWithLogInfo/AppLogInfo/PopoverContent/PopoverContent.tsx index 77eab3b9c32..6d804c69ce0 100644 --- a/packages/shared/src/components/Apps/AppStatusWithLogInfo/AppLogInfo/PopoverContent/PopoverContent.tsx +++ b/packages/shared/src/components/Apps/AppStatusWithLogInfo/AppLogInfo/PopoverContent/PopoverContent.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { StatusIndicatorProps } from '@ks-console/shared'; +import type { StatusIndicatorProps } from '../../../../StatusIndicator'; import { getAppStatusStateInfo, typeProps } from './status'; import { Wrapper, diff --git a/packages/shared/src/components/ProjectLayout/ListLayout/index.tsx b/packages/shared/src/components/ProjectLayout/ListLayout/index.tsx index c92ebfd5d44..7e84d5116b4 100644 --- a/packages/shared/src/components/ProjectLayout/ListLayout/index.tsx +++ b/packages/shared/src/components/ProjectLayout/ListLayout/index.tsx @@ -7,7 +7,8 @@ import { Project, Enterprise } from '@kubed/icons'; import { NavMenu } from '../../Layouts/NavMenu'; import NavTitle from '../../Layouts/NavTitle'; -import { ListPageSide, FavoriteHistory } from '@ks-console/shared'; +import { FavoriteHistory } from '../../FavoriteHistory'; +import ListPageSide from '../../Layouts/ListPageSide'; import { getActions } from '../../../utils'; import type { FormattedNamespace } from '../../../types'; import { useGlobalStore, workspaceStore, permissionStore, projectNewStore } from '../../../stores'; diff --git a/packages/shared/src/components/WorkspaceLayout/ListLayout/index.tsx b/packages/shared/src/components/WorkspaceLayout/ListLayout/index.tsx index e54baddbe7a..01e3e995ad9 100644 --- a/packages/shared/src/components/WorkspaceLayout/ListLayout/index.tsx +++ b/packages/shared/src/components/WorkspaceLayout/ListLayout/index.tsx @@ -1,9 +1,11 @@ -import { FavoriteHistory, ListPageSide } from '@ks-console/shared'; import { useModal } from '@kubed/components'; import { Enterprise } from '@kubed/icons'; import React, { useEffect, useMemo } from 'react'; import { Outlet, useLocation, useNavigate, useParams } from 'react-router-dom'; import styled from 'styled-components'; + +import ListPageSide from '../../Layouts/ListPageSide'; +import { FavoriteHistory } from '../../FavoriteHistory'; import { permissionStore, useGlobalStore, workspaceStore } from '../../../stores'; import { NavMenu, NavMenuItem } from '../../Layouts/NavMenu'; import NavTitle from '../../Layouts/NavTitle'; diff --git a/packages/shared/src/components/WorkspaceLayout/index.tsx b/packages/shared/src/components/WorkspaceLayout/index.tsx index dd07ed81781..c58e7b78747 100644 --- a/packages/shared/src/components/WorkspaceLayout/index.tsx +++ b/packages/shared/src/components/WorkspaceLayout/index.tsx @@ -6,7 +6,7 @@ import { Loading } from '@kubed/components'; import { Outlet, useParams } from 'react-router-dom'; import { useWorkspaceSelectedClusterStore, workspaceStore } from '../../stores'; import { fetchRules } from '../../utils/apis'; -import { useClusterStore } from '@ks-console/shared'; +import { useClusterStore } from '../../stores/useClustersStore'; const { fetchDetail, useFetchWorkspaceClustersQuery } = workspaceStore; diff --git a/packages/shared/src/stores/useClustersStore.ts b/packages/shared/src/stores/useClustersStore.ts index ac64026b81f..942a281e570 100644 --- a/packages/shared/src/stores/useClustersStore.ts +++ b/packages/shared/src/stores/useClustersStore.ts @@ -1,5 +1,5 @@ import { create } from 'zustand'; -import { FormattedCluster } from '@ks-console/shared'; +import type { FormattedCluster } from '../types/cluster'; type UseClusterStore = { clusters: FormattedCluster[]; diff --git a/packages/shared/src/utils/licenses.ts b/packages/shared/src/utils/licenses.ts index cbaa5b7c75c..32653850902 100644 --- a/packages/shared/src/utils/licenses.ts +++ b/packages/shared/src/utils/licenses.ts @@ -1,5 +1,5 @@ -import type { FormattedLicense } from '@ks-console/shared'; -import { getGlobalLicenseInfo } from '@ks-console/shared'; +import type { FormattedLicense } from '../types/license'; +import { getGlobalLicenseInfo } from './globals'; function getLicenseErrorInfo({ formattedLicense, diff --git a/packages/shared/src/utils/nav.ts b/packages/shared/src/utils/nav.ts index d52d9732504..17834e8cdcf 100644 --- a/packages/shared/src/utils/nav.ts +++ b/packages/shared/src/utils/nav.ts @@ -8,7 +8,7 @@ import { hasExtensionModuleAnnotation, hasExtensionModuleAnnotationCluster, } from './checker'; -import { getLicenseErrorInfoFromLicenses } from '@ks-console/shared'; +import { getLicenseErrorInfoFromLicenses } from '../utils/licenses'; export const hasClusterModule = (cluster: string, module: string) => { return get( diff --git a/packages/shared/src/utils/workloads.ts b/packages/shared/src/utils/workloads.ts index f75bce8d844..670b528e6da 100644 --- a/packages/shared/src/utils/workloads.ts +++ b/packages/shared/src/utils/workloads.ts @@ -1,6 +1,6 @@ import { get, set, merge, isEmpty } from 'lodash'; import { OriginalWorkload, OriginalJob } from '../types'; -import { getApiVersion } from '@ks-console/shared'; +import { getApiVersion } from './getApiVersion'; export const getWorkloadUpdateTime = (record: OriginalWorkload) => { const annotations = get(record, 'metadata.annotations', {}); diff --git a/scripts/build-packages.js b/scripts/build-packages.js index f8b3f73bfe0..548ddd68ba7 100644 --- a/scripts/build-packages.js +++ b/scripts/build-packages.js @@ -3,10 +3,13 @@ import path from 'path'; import chalk from 'chalk'; import fs from 'fs-extra'; import { execa } from 'execa'; +import shelljs from 'shelljs'; import fg from 'fast-glob'; import { Logger } from './libs/logger'; import createRollupConfig from './libs/create-rollup-config'; +import { PATHS, PACKAGES_TO_BUILD } from './constants'; + const logger = new Logger('build-package'); async function locatePackage(packageName) { @@ -23,14 +26,27 @@ async function compile(config) { return Promise.all(outputs.map(output => build.write(output))); } -async function generateDts(packagePath) { +async function tsc(packagePath) { await execa('yarn', ['tsc', '--build'], { cwd: packagePath, }); +} + +async function minify(packagePath) { + const terserConfigFilePath = path.resolve(PATHS.root, 'scripts', 'terser.config.json'); const files = await fg(['lib/**/*.js'], { cwd: packagePath }); - return Promise.all(files.map(file => fs.remove(path.join(packagePath, file)))); + const total = files.length; + let index = 0; + + shelljs.cd(packagePath); + + files.forEach(file => { + const command = `terser ${file} --config-file ${terserConfigFilePath} --output ${file}`; + shelljs.exec(command); + logger.info(`minify ${++index} / ${total}`); + }); } async function buildPackage(packageName, options) { @@ -45,25 +61,26 @@ async function buildPackage(packageName, options) { try { const startTime = Date.now(); - ['cjs', 'esm'].forEach(item => { + ['cjs', 'esm', 'lib', 'dist'].forEach(item => { fs.removeSync(path.join(packagePath, item)); }); if (packageName === '@ks-console/shared') { fs.removeSync(path.join(packagePath, 'lib')); fs.removeSync(path.join(packagePath, 'tsconfig.tsbuildinfo')); - await generateDts(packagePath); - } - - for (const format of options?.formats) { - const config = await createRollupConfig({ - ...options, - basePath: packagePath, - format, - }); - - logger.info(`Building to ${chalk.cyan(format)} format...`); - await compile(config); + await tsc(packagePath); + await minify(packagePath); + } else { + for (const format of options?.formats) { + const config = await createRollupConfig({ + ...options, + basePath: packagePath, + format, + }); + + logger.info(`Building to ${chalk.cyan(format)} format...`); + await compile(config); + } } logger.info( @@ -79,8 +96,7 @@ async function buildPackage(packageName, options) { } function build() { - const packages = ['@ks-console/shared', '@ks-console/console', '@ks-console/core', '@ks-console/appstore', '@ks-console/shared-docs']; - packages.forEach(async (packageName) => { + PACKAGES_TO_BUILD.forEach(async ({ packageName }) => { await buildPackage(packageName, { formats: ['es', 'cjs'], minify: true, diff --git a/scripts/constants.ts b/scripts/constants.ts new file mode 100644 index 00000000000..39763348512 --- /dev/null +++ b/scripts/constants.ts @@ -0,0 +1,66 @@ +import path from 'node:path'; + +const PATHS = { + root: path.resolve(__dirname, '../'), +} as const; + +const resolvePath = (...paths) => path.resolve(PATHS.root, ...paths); + +const resolvePackagePath = (...paths) => resolvePath('packages', ...paths); + +const PACKAGES = [ + { + packageName: '@ks-console/locales', + absolutePath: resolvePath('locales'), + isBuild: false, + isPublish: true, + }, + { + packageName: '@ks-console/appstore', + absolutePath: resolvePackagePath('appstore'), + isBuild: true, + isPublish: true, + }, + { + packageName: '@ks-console/bootstrap', + absolutePath: resolvePackagePath('bootstrap'), + isBuild: false, + isPublish: true, + }, + { + packageName: '@ks-console/console', + absolutePath: resolvePackagePath('console'), + isBuild: true, + isPublish: true, + }, + { + packageName: '@ks-console/core', + absolutePath: resolvePackagePath('core'), + isBuild: true, + isPublish: true, + }, + { + packageName: '@ks-console/shared', + absolutePath: resolvePackagePath('shared'), + isBuild: true, + isPublish: true, + }, + { + packageName: '@ks-console/shared-docs', + absolutePath: resolvePackagePath('shared-docs'), + isBuild: false, + isPublish: false, + }, + { + packageName: '@ks-console/server', + absolutePath: resolvePath('server'), + isBuild: false, + isPublish: true, + }, +] as const; + +const PACKAGES_TO_BUILD = PACKAGES.filter(({ isBuild }) => isBuild); + +const PACKAGES_TO_PUBLISH = PACKAGES.filter(({ isPublish }) => isPublish); + +export { PATHS, PACKAGES, PACKAGES_TO_BUILD, PACKAGES_TO_PUBLISH }; diff --git a/scripts/libs/create-rollup-config.js b/scripts/libs/create-rollup-config.js index 237f2b4832d..b1d68b52a7b 100644 --- a/scripts/libs/create-rollup-config.js +++ b/scripts/libs/create-rollup-config.js @@ -4,7 +4,7 @@ import commonjs from '@rollup/plugin-commonjs'; import nodeExternals from 'rollup-plugin-node-externals'; import { nodeResolve } from '@rollup/plugin-node-resolve'; import esbuild from 'rollup-plugin-esbuild'; -import json from "@rollup/plugin-json"; +import json from '@rollup/plugin-json'; export default async function createRollupConfig(config) { const packageJson = JSON.parse( diff --git a/scripts/publish-packages.local.ts b/scripts/publish-packages.local.ts new file mode 100644 index 00000000000..eca95ede617 --- /dev/null +++ b/scripts/publish-packages.local.ts @@ -0,0 +1,11 @@ +import shelljs from 'shelljs'; + +import { PACKAGES_TO_PUBLISH } from './constants'; + +shelljs.cd('packages'); + +PACKAGES_TO_PUBLISH.forEach(({ absolutePath }) => { + shelljs.cd(absolutePath); + const command = `yalc publish`; + shelljs.exec(command); +}); diff --git a/scripts/terser.config.json b/scripts/terser.config.json new file mode 100644 index 00000000000..94655f8220f --- /dev/null +++ b/scripts/terser.config.json @@ -0,0 +1,7 @@ +{ + "compress": true, + "mangle": true, + "output": { + "comments": false + } +} diff --git a/server/configs/systemImports.js b/server/configs/systemImports.js index 78d3fca2550..21bff3adca1 100644 --- a/server/configs/systemImports.js +++ b/server/configs/systemImports.js @@ -1,19 +1,21 @@ const systemImports = { + // '@ks-console/shared': 'core:@kubed/@ks-console/shared', + '@kubed/charts': 'core:@kubed/charts', + '@kubed/code-editor': 'core:@kubed/code-editor', + '@kubed/components': 'core:@kubed/components', + // '@kubed/diff-viewer': 'core:@kubed/diff-viewer', + '@kubed/hooks': 'core:@kubed/hooks', + '@kubed/icons': 'core:@kubed/icons', + // '@kubed/log-viewer': 'core:@kubed/log-viewer', + // dayjs: 'core:dayjs', + // lodash: 'core:lodash', react: 'core:react', 'react-dom': 'core:react-dom', + // 'react-markdown': 'core:react-markdown', + 'react-query': 'core:react-query', 'react-router-dom': 'core:react-router-dom', 'styled-components': 'core:styled-components', - lodash: 'core:lodash', - 'react-query': 'core:react-query', - 'react-markdown': 'core:react-markdown', - '@kubed/components': 'core:@kubed/components', - '@kubed/hooks': 'core:@kubed/hooks', - '@kubed/icons': 'core:@kubed/icons', - '@kubed/code-editor': 'core:@kubed/code-editor', - '@kubed/charts': 'core:@kubed/charts', - '@ks-console/shared': 'core:@kubed/@ks-console/shared', 'wujie-react': 'core:wujie-react', - dayjs: 'core:dayjs', }; module.exports = systemImports; diff --git a/yarn.lock b/yarn.lock index da3705110aa..582d362d06d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1760,6 +1760,15 @@ "@jridgewell/sourcemap-codec" "^1.4.10" "@jridgewell/trace-mapping" "^0.3.9" +"@jridgewell/gen-mapping@^0.3.5": + version "0.3.5" + resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz#dcce6aff74bdf6dad1a95802b69b04a2fcb1fb36" + integrity sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg== + dependencies: + "@jridgewell/set-array" "^1.2.1" + "@jridgewell/sourcemap-codec" "^1.4.10" + "@jridgewell/trace-mapping" "^0.3.24" + "@jridgewell/resolve-uri@3.1.0", "@jridgewell/resolve-uri@^3.1.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78" @@ -1770,6 +1779,19 @@ resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72" integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw== +"@jridgewell/set-array@^1.2.1": + version "1.2.1" + resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.2.1.tgz#558fb6472ed16a4c850b889530e6b36438c49280" + integrity sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A== + +"@jridgewell/source-map@^0.3.3": + version "0.3.6" + resolved "https://registry.yarnpkg.com/@jridgewell/source-map/-/source-map-0.3.6.tgz#9d71ca886e32502eb9362c9a74a46787c36df81a" + integrity sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ== + dependencies: + "@jridgewell/gen-mapping" "^0.3.5" + "@jridgewell/trace-mapping" "^0.3.25" + "@jridgewell/sourcemap-codec@1.4.14", "@jridgewell/sourcemap-codec@^1.4.10": version "1.4.14" resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24" @@ -1788,6 +1810,14 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" +"@jridgewell/trace-mapping@^0.3.24", "@jridgewell/trace-mapping@^0.3.25": + version "0.3.25" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz#15f190e98895f3fc23276ee14bc76b675c2e50f0" + integrity sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ== + dependencies: + "@jridgewell/resolve-uri" "^3.1.0" + "@jridgewell/sourcemap-codec" "^1.4.14" + "@jridgewell/trace-mapping@^0.3.9": version "0.3.17" resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.17.tgz#793041277af9073b0951a7fe0f0d8c4c98c36985" @@ -1796,6 +1826,11 @@ "@jridgewell/resolve-uri" "3.1.0" "@jridgewell/sourcemap-codec" "1.4.14" +"@ks-console/locales@^0.0.1": + version "0.0.1" + resolved "https://registry.yarnpkg.com/@ks-console/locales/-/locales-0.0.1.tgz#4542c710f84deb5d2e9fb9dcd1359662e1e7c12f" + integrity sha512-/00omyXY+sgVPqfV3R4iNwA3ijjiA4TryPoLmEC77+RftadmK9QAL9UNY8ggW04+L+DIqVYn6Q8WP8jsISgP9Q== + "@kubed/charts@^0.0.22": version "0.0.22" resolved "https://registry.yarnpkg.com/@kubed/charts/-/charts-0.0.22.tgz#cea54aedb8be49217d031e31f722feeff60b7f9a" @@ -2688,10 +2723,10 @@ dependencies: "@types/node" "*" -"@types/netmask@^1.0.30": - version "1.0.30" - resolved "https://registry.yarnpkg.com/@types/netmask/-/netmask-1.0.30.tgz#b68005e3e3c19f517ced4610bb69dce2e0c5babb" - integrity sha512-Kl1xAICLv1Y7/WsNXkPKldRMz3QmXUYMIzr3rMXnIBDy9c4/sYG7V6P6u7Ja3w+uNtNQrRudJduqVoYX/DxfZg== +"@types/netmask@^2.0.5": + version "2.0.5" + resolved "https://registry.yarnpkg.com/@types/netmask/-/netmask-2.0.5.tgz#8eeedf87a08e993c14d70fae9c17837c868f4ca3" + integrity sha512-9Q5iw9+pHZBVLDG700dlQSWWHTYvOb8KfPjfQTNckCYky4IyjV2xh81+RgC1CCwqv92bYLpz1cVKyJav0B88uQ== "@types/node@*": version "16.11.6" @@ -3237,6 +3272,11 @@ acorn@^8.0.4, acorn@^8.4.1: resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.5.0.tgz#4512ccb99b3698c752591e9bb4472e38ad43cee2" integrity sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q== +acorn@^8.8.2: + version "8.12.1" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.12.1.tgz#71616bdccbe25e27a54439e0046e89ca76df2248" + integrity sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg== + add-stream@^1.0.0: version "1.0.0" resolved "https://registry.npmmirror.com/add-stream/-/add-stream-1.0.0.tgz#6a7990437ca736d5e1288db92bd3266d5f5cb2aa" @@ -11498,6 +11538,11 @@ passthrough-counter@^1.0.0: resolved "https://registry.yarnpkg.com/passthrough-counter/-/passthrough-counter-1.0.0.tgz#1967d9e66da572b5c023c787db112a387ab166fa" integrity sha1-GWfZ5m2lcrXAI8eH2xEqOHqxZvo= +path-browserify@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd" + integrity sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g== + path-exists@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515" @@ -14558,7 +14603,17 @@ terser-webpack-plugin@^5.1.3, terser-webpack-plugin@^5.2.4: source-map "^0.6.1" terser "^5.7.2" -terser@^5.7.2, terser@^5.9.0: +terser@^5.31.1: + version "5.31.1" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.31.1.tgz#735de3c987dd671e95190e6b98cfe2f07f3cf0d4" + integrity sha512-37upzU1+viGvuFtBo9NPufCb9dwM0+l9hMxYyWfBA+fbwrPqNJAhbZ6W47bBFnZHKHTUBnMvi87434qq+qnxOg== + dependencies: + "@jridgewell/source-map" "^0.3.3" + acorn "^8.8.2" + commander "^2.20.0" + source-map-support "~0.5.20" + +terser@^5.7.2: version "5.9.0" resolved "https://registry.yarnpkg.com/terser/-/terser-5.9.0.tgz#47d6e629a522963240f2b55fcaa3c99083d2c351" integrity sha512-h5hxa23sCdpzcye/7b8YqbE5OwKca/ni0RQz1uRX3tGh8haaGHqcuSqbGRybuAKNdntZ0mDgFNXPJ48xQ2RXKQ== @@ -16104,11 +16159,6 @@ yocto-queue@^0.1.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== -zod@^3.22.4: - version "3.22.4" - resolved "https://registry.npmmirror.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff" - integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg== - zustand@^4.5.1: version "4.5.1" resolved "https://registry.npmmirror.com/zustand/-/zustand-4.5.1.tgz#2088956ee454759fb8b866ca335a2373e76736c5"