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

Build the frontend by esbuild instead of webpack #1063

Merged
merged 113 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 108 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
6bf9856
install esbuild
baurine Nov 15, 2021
c4f0493
install live-server and chokidar
baurine Nov 15, 2021
e38de03
init ui-esbuild folder
baurine Nov 16, 2021
95d254e
test compile css
baurine Nov 16, 2021
4acb3e9
compile less
baurine Nov 16, 2021
7ac21dc
test build prod
baurine Nov 16, 2021
c5e60e5
compile module less
baurine Nov 16, 2021
cc6c615
refine build
baurine Nov 16, 2021
bc8295e
test less variable
baurine Nov 16, 2021
b53c605
compile scss
baurine Nov 16, 2021
5623843
rename
baurine Nov 16, 2021
2f148fc
compile antd
baurine Nov 16, 2021
c3ac7c5
compile fluentui
baurine Nov 16, 2021
238ec57
wip
baurine Nov 17, 2021
7b4f2a1
wip
baurine Nov 17, 2021
eced827
test DatePicker
baurine Nov 17, 2021
e8863c4
compile @ant-design/icons
baurine Nov 17, 2021
d3808ee
compile svg
baurine Nov 17, 2021
450bb89
refine
baurine Nov 17, 2021
40f6167
unify builder.js
baurine Nov 17, 2021
3fef299
compile yaml
baurine Nov 17, 2021
cb9c4e8
hack postcss2
baurine Nov 17, 2021
c61ed0d
test alias paths
baurine Nov 17, 2021
588fd61
compile basic dynamic import
baurine Nov 17, 2021
fd9d8d9
compile lazy load component
baurine Nov 17, 2021
2f44161
improve dev build speed
baurine Nov 17, 2021
6536f8b
update readme
baurine Nov 17, 2021
9b64acc
refine
baurine Nov 18, 2021
e71fb87
backup original ui folder
baurine Nov 18, 2021
6db8e10
wip
baurine Nov 18, 2021
21ceaf6
remove ~ when @import antd less
baurine Nov 18, 2021
2e66a1a
try (ok)
baurine Nov 18, 2021
7248f20
pass esbuild compile
baurine Nov 18, 2021
64bb9ae
compile diagnoseReportApp
baurine Nov 19, 2021
50df3d3
remove expermental files
baurine Nov 19, 2021
85e559c
handle i18n
baurine Nov 19, 2021
8dd25cd
handle svg
baurine Nov 19, 2021
ea52d9b
handle svg as background
baurine Nov 19, 2021
ac1857a
watch more folders
baurine Nov 19, 2021
80c7312
wip - try not splitting code
baurine Nov 22, 2021
40e4422
add back less-loader
baurine Nov 23, 2021
058198b
fix primary color
baurine Nov 23, 2021
1df6a38
Merge remote-tracking branch 'refs/remotes/baurine/esbuild' into esbuild
baurine Nov 23, 2021
fe5b22a
test
baurine Nov 23, 2021
7f925ac
fix runtime crash
baurine Nov 23, 2021
1ced955
fix formatSQL crash
baurine Nov 23, 2021
0253809
handle env files
baurine Nov 24, 2021
8038644
eliminate tons of language highlight files
baurine Nov 24, 2021
b1fd304
refine copy public assets
baurine Nov 25, 2021
15ddefb
proxy diagnoseReport
baurine Nov 25, 2021
6849743
handle publicPathPrefix
baurine Nov 25, 2021
ffb18cf
handle distro
baurine Nov 25, 2021
6ac24b9
use back `build` as out dir
baurine Nov 25, 2021
2b2cc7b
refine
baurine Nov 25, 2021
5ce9796
refine gulp scripts
baurine Nov 25, 2021
9ddbedc
refine
baurine Nov 25, 2021
8c7cddd
add comments
baurine Nov 26, 2021
11f18f9
handle type check (wip)
baurine Nov 26, 2021
05c7db6
pass type check
baurine Nov 26, 2021
2202af2
check type in CI
baurine Nov 26, 2021
2d33cb5
log build time
baurine Nov 26, 2021
cfda3e8
cache postcss2 result
baurine Nov 29, 2021
5f7ad7e
fix sentry runtime crash
baurine Nov 29, 2021
ab279ca
build lib/antd.less
baurine Nov 29, 2021
45b8a2f
fix sider menu collapsed style
baurine Nov 30, 2021
0ec2eae
fix Bar component style
baurine Nov 30, 2021
987c6b3
fix BaseSelect style
baurine Dec 1, 2021
1f66bc9
make BaseSelect work again
baurine Dec 2, 2021
bd4bb5f
fix BaseSelect animation
baurine Dec 2, 2021
c1f1896
Merge remote-tracking branch 'origin/master' into esbuild
baurine Dec 2, 2021
4531af1
fix yarn.lock conflicts
baurine Dec 2, 2021
b26b482
fix CI
baurine Dec 2, 2021
24989c8
upgrade node version in CI
baurine Dec 2, 2021
d5442b6
handle speedscope
baurine Dec 2, 2021
51f8959
support baseURL
baurine Dec 2, 2021
22ba497
refine
baurine Dec 2, 2021
88862b9
refine
baurine Dec 2, 2021
3b28574
refine
baurine Dec 2, 2021
30ee649
Merge remote-tracking branch 'origin/master' into esbuild
baurine Dec 6, 2021
ad74c57
no need process-slim after some lib is upgraded
baurine Dec 6, 2021
c79550b
Merge remote-tracking branch 'origin/master' into esbuild
baurine Dec 8, 2021
c76c449
refine process.env
baurine Dec 8, 2021
0f7749d
Merge remote-tracking branch 'origin/master' into esbuild
baurine Dec 9, 2021
943ec88
use @baurine/esbuild-plugin-postcss3
baurine Dec 10, 2021
99b5b00
Merge remote-tracking branch 'origin/master' into esbuild
baurine Dec 10, 2021
8007e2e
Distribution dynamic config (#2)
baurine Dec 13, 2021
87c8b79
Revert "Distribution dynamic config (#2)" (#3)
baurine Dec 13, 2021
b4af6df
Merge remote-tracking branch 'origin/master' into esbuild
baurine Dec 24, 2021
12ece77
adjust for distro dynamic config
baurine Dec 24, 2021
d3a1979
Merge remote-tracking branch 'origin/master' into esbuild
baurine Jan 17, 2022
8ccb6c7
update yarn.lock
baurine Jan 17, 2022
e87773b
fix `yarn build`
baurine Jan 17, 2022
781b6c3
fix `yarn tsc`
baurine Jan 17, 2022
b830bbe
refine, use autoprefixer
baurine Jan 17, 2022
6e31304
refine
baurine Jan 17, 2022
0bf0efc
Merge remote-tracking branch 'origin/master' into esbuild
baurine Jan 17, 2022
79e58e2
do tsc check when dev
baurine Jan 18, 2022
18b83cb
Merge remote-tracking branch 'origin/master' into esbuild
baurine Jan 18, 2022
dacb9d1
Merge remote-tracking branch 'origin/master' into esbuild
baurine Jan 20, 2022
c4745fd
config eslint
baurine Jan 21, 2022
c567a10
eslint watch
baurine Jan 21, 2022
ce12e39
fix lint
baurine Jan 21, 2022
8c27ecf
Merge remote-tracking branch 'origin/master' into esbuild
baurine Jan 21, 2022
0510692
fix: update cy get selector (#5)
YiniXu9506 Jan 24, 2022
472b469
fix(topsql): `react-hooks/exhaustive-deps` lint (#4)
shhdgit Jan 24, 2022
823d13d
fix lint
baurine Jan 24, 2022
090c16b
fix broken style
baurine Jan 24, 2022
aa9f33b
update cypress selector and hide code coverage temporary (#6)
YiniXu9506 Jan 24, 2022
b9cb4b7
do tsc and eslint check for production build
baurine Jan 25, 2022
7087880
remove unused code
baurine Jan 25, 2022
e33782f
revert unnecessary changes
baurine Jan 25, 2022
f6a26ba
Merge branch 'esbuild' of github.com:baurine/tidb-dashboard into esbuild
baurine Jan 25, 2022
fc9e482
fix production build
baurine Jan 25, 2022
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
12 changes: 10 additions & 2 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: "12.x"
node-version: "16.x"
- uses: actions/setup-go@v1
with:
go-version: "1.13.5"
Expand All @@ -67,11 +67,19 @@ jobs:
make yarn_dependencies
- name: Check format
run: |
yarn prettier --check . || (echo "::error ::Please format your code using 'yarn fmt'"; exit 1)
yarn prettier --check . || (echo "::error ::Please format your code by using 'yarn fmt'"; exit 1)
working-directory: ui
- name: Lint
run: |
yarn lint || (echo "::error ::Please lint your code by using 'yarn lint'"; exit 1)
working-directory: ui
- name: Build UI
run: |
make ui
env:
NO_MINIMIZE: true
CI: true
- name: Check type
run: |
yarn tsc || (echo "::error ::Please check your code type by using 'yarn tsc'"; exit 1)
baurine marked this conversation as resolved.
Show resolved Hide resolved
working-directory: ui
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Run the type check after lib/client/api codes are generated by building UI, else this job will fail.

2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: "12.x"
node-version: "16.x"
- uses: actions/setup-go@v1
with:
go-version: "1.13.5"
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: "12.x"
node-version: "16.x"
- uses: actions/setup-go@v1
with:
go-version: "1.13.5"
Expand Down Expand Up @@ -159,10 +159,10 @@ jobs:
cat ui/start_tiup.log
echo "==============="
cat ui/wait_tiup.log
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: ./ui/.nyc_output/out.json
fail_ci_if_error: true
flags: e2e_test
verbose: true
# - name: Upload coverage to Codecov
Copy link
Member

Choose a reason for hiding this comment

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

What's wrong with this block?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

The introduced esbuild causes the plugin in .babelrc does not work. I am working on this.

# uses: codecov/codecov-action@v2
# with:
# files: ./ui/.nyc_output/out.json
# fail_ci_if_error: true
# flags: e2e_test
# verbose: true
2 changes: 1 addition & 1 deletion pkg/apiserver/profiling/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type TaskGroupModel struct {
ProfileDurationSecs uint `json:"profile_duration_secs"`
TargetStats model.RequestTargetStatistics `json:"target_stats" gorm:"embedded;embedded_prefix:target_stats_"`
StartedAt int64 `json:"started_at"`
RequstedProfilingTypes TaskProfilingTypeList `json:"requsted_profiling_types"`
RequstedProfilingTypes TaskProfilingTypeList `json:"requsted_profiling_types" swaggertype:"array,string"`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

breezewish marked this conversation as resolved.
Show resolved Hide resolved
}

func (TaskGroupModel) TableName() string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/profiling/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
type StartRequest struct {
Targets []model.RequestTargetNode `json:"targets"`
DurationSecs uint `json:"duration_secs"`
RequstedProfilingTypes TaskProfilingTypeList `json:"requsted_profiling_types"`
RequstedProfilingTypes TaskProfilingTypeList `json:"requsted_profiling_types" swaggertype:"array,string"`
breezewish marked this conversation as resolved.
Show resolved Hide resolved
}

type StartRequestSession struct {
Expand Down
10 changes: 7 additions & 3 deletions scripts/start_tiup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ tidb_version=$1
mode=$2

TIUP_BIN_DIR=$HOME/.tiup/bin/tiup
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

if [ $mode = "restart" ]; then
# get process id
Expand All @@ -15,12 +16,15 @@ if [ $mode = "restart" ]; then
echo "killing $id"
kill -9 $id;
done

# Run Tiup
$TIUP_BIN_DIR playground ${tidb_version} --db.config=$DIR/tiup.config.toml --tiflash=0 &> start_tiup.log &
else
echo "install tiup"
# Install TiUP
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
$TIUP_BIN_DIR update playground
fi

# Run Tiup
$TIUP_BIN_DIR playground ${tidb_version} --tiflash=0 &> start_tiup.log &
# Run Tiup
$TIUP_BIN_DIR playground ${tidb_version} --tiflash=0 &> start_tiup.log &
fi
2 changes: 2 additions & 0 deletions scripts/tiup.config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[log]
slow-threshold = 800
2 changes: 1 addition & 1 deletion ui/.env.development
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PORT=3001
PUBLIC_URL='/dashboard'
REACT_APP_VERSION=$npm_package_version
REACT_APP_NAME=$npm_package_name
REACT_APP_SENTRY_DSN=https://[email protected]/5721090
REACT_APP_SENTRY_ENABLED=false
# REACT_APP_RELEASE_VERSION is set in config-overrides.js
Expand Down
3 changes: 1 addition & 2 deletions ui/.env.production
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
INLINE_RUNTIME_CHUNK=false
PUBLIC_URL=__PUBLIC_PATH_PREFIX__/
PUBLIC_URL=__PUBLIC_PATH_PREFIX__
breezewish marked this conversation as resolved.
Show resolved Hide resolved
REACT_APP_VERSION=$npm_package_version
REACT_APP_NAME=$npm_package_name
REACT_APP_SENTRY_DSN=https://[email protected]/5721090
REACT_APP_SENTRY_ENABLED=true
# REACT_APP_RELEASE_VERSION is set in config-overrides.js
Expand Down
10 changes: 10 additions & 0 deletions ui/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
extends: ['react-app'],
ignorePatterns: ['lib/client/api/*.ts'],
rules: {
'react/react-in-jsx-scope': 'error',
'jsx-a11y/anchor-is-valid': 'off',
'jsx-a11y/alt-text': 'off',
'import/no-anonymous-default-export': 'off',
},
}
4 changes: 3 additions & 1 deletion ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ dist/

npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn-error.log*

.eslintcache
211 changes: 211 additions & 0 deletions ui/builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
const fs = require('fs-extra')
const os = require('os')
const chalk = require('chalk')
const { start } = require('live-server')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Use live-server to start a dev server in the dev mode.

const { createProxyMiddleware } = require('http-proxy-middleware')
const { watch } = require('chokidar')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Use chokidar lib to watch files changes in the dev mode.

const { build } = require('esbuild')
const postCssPlugin = require('@baurine/esbuild-plugin-postcss3')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fix the upstream bugs and support cache in the forked plugin

const { yamlPlugin } = require('esbuild-plugin-yaml')
const autoprefixer = require('autoprefixer')

const isDev = process.env.NODE_ENV !== 'production'

// handle .env
if (isDev) {
fs.copyFileSync('./.env.development', './.env')
} else {
fs.copyFileSync('./.env.production', './.env')
}
// load .env file
require('dotenv').config()

const dashboardApiPrefix =
process.env.REACT_APP_DASHBOARD_API_URL || 'http://127.0.0.1:12333'
const devServerPort = process.env.PORT
const devServerParams = {
port: devServerPort,
root: 'build',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we should define a global var const outputDir = 'build' instead of hard-code.

open: '/dashboard',
// Set base URL
// https://github.com/tapio/live-server/issues/287 - How can I serve from a base URL?
proxy: [['/dashboard', `http://127.0.0.1:${devServerPort}`]],
Copy link
Collaborator Author

@baurine baurine Dec 3, 2021

Choose a reason for hiding this comment

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

Maybe we should use process.env.PUBLIC_URL as base URL instead of hard-code.

middleware: isDev && [
function (req, _res, next) {
if (/\/dashboard\/api\/diagnose\/reports\/\S+\/detail/.test(req.url)) {
req.url = '/diagnoseReport.html'
}
next()
},
createProxyMiddleware('/dashboard/api/diagnose/reports/*/data.js', {
target: dashboardApiPrefix,
changeOrigin: true,
}),
],
Comment on lines +33 to +44
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To support access diagnosis report page in the dev mode.

}

const lessModifyVars = {
'@primary-color': '#3351ff',
'@body-background': '#fff',
'@tooltip-bg': 'rgba(0, 0, 0, 0.9)',
'@tooltip-max-width': '500px',
}
const lessGlobalVars = {
'@padding-page': '48px',
'@gray-1': '#fff',
'@gray-2': '#fafafa',
'@gray-3': '#f5f5f5',
'@gray-4': '#f0f0f0',
'@gray-5': '#d9d9d9',
'@gray-6': '#bfbfbf',
'@gray-7': '#8c8c8c',
'@gray-8': '#595959',
'@gray-9': '#262626',
'@gray-10': '#000',
}

function getInternalVersion() {
const version = fs
.readFileSync('../release-version', 'utf8')
.split(os.EOL)
.map((l) => l.trim())
.filter((l) => !l.startsWith('#') && l !== '')[0]
if (version === '') {
throw new Error(
`invalid release version, please check the release-version @tidb-dashboard/root`
)
}
return version
}

function genDefine() {
const define = {}
for (const k in process.env) {
if (k.startsWith('REACT_APP_')) {
let envVal = process.env[k]
// Example: REACT_APP_VERSION=$npm_package_version
// Expect output: REACT_APP_VERSION=0.1.0
if (envVal.startsWith('$')) {
envVal = process.env[envVal.substring(1)]
}
define[`process.env.${k}`] = JSON.stringify(envVal)
}
}
define['process.env.REACT_APP_RELEASE_VERSION'] = JSON.stringify(
getInternalVersion()
)
return define
}

// customized plugin: log time
const logTime = (_options = {}) => ({
name: 'logTime',
setup(build) {
let time

build.onStart(() => {
time = new Date()
console.log(`Build started`)
})

build.onEnd(() => {
console.log(`Build ended: ${chalk.yellow(`${new Date() - time}ms`)}`)
})
},
})

const esbuildParams = {
color: true,
entryPoints: {
dashboardApp: 'src/index.ts',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The original entry point name for dashboardApp is dashboard, it will generate the dasbhoard.css and dashboard.js, but it conflicts with the base url /dashboard, so I change the entry point name to dashboardApp.

diagnoseReport: 'diagnoseReportApp/index.tsx',
},
loader: { '.ts': 'tsx' },
outdir: 'build',
minify: !isDev,
format: 'esm',
bundle: true,
sourcemap: true,
logLevel: 'error',
incremental: true,
splitting: true,
platform: 'browser',
plugins: [
postCssPlugin.default({
lessOptions: {
modifyVars: lessModifyVars,
globalVars: lessGlobalVars,
javascriptEnabled: true,
},
enableCache: true,
plugins: [autoprefixer],
}),
yamlPlugin(),
logTime(),
],
define: genDefine(),
inject: ['./process-shim.js'], // fix runtime crash
}

function buildHtml(inputFilename, outputFilename) {
let result = fs.readFileSync(inputFilename).toString()

const placeholders = ['PUBLIC_URL']
placeholders.forEach((key) => {
result = result.replace(new RegExp(`%${key}%`, 'g'), process.env[key])
})

// handle distro strings res, only for dev mode
const distroStringsResFilePath = './build/distro-res/strings.json'
if (isDev && fs.existsSync(distroStringsResFilePath)) {
const distroStringsRes = require(distroStringsResFilePath)
result = result.replace(
'__DISTRO_STRINGS_RES__',
btoa(JSON.stringify(distroStringsRes))
)
}

fs.writeFileSync(outputFilename, result)
}

function handleAssets() {
fs.copySync('./public', './build')
if (isDev) {
copyDistroRes()
}

buildHtml('./public/index.html', './build/index.html')
buildHtml('./public/diagnoseReport.html', './build/diagnoseReport.html')
}

function copyDistroRes() {
const distroResPath = '../bin/distro-res'
if (fs.existsSync(distroResPath)) {
fs.copySync(distroResPath, './build/distro-res')
}
}

async function main() {
fs.removeSync('./build')

const builder = await build(esbuildParams)
handleAssets()

if (isDev) {
start(devServerParams)

const tsConfig = require('./tsconfig.json')
tsConfig.include.forEach((folder) => {
watch(`${folder}/**/*`, { ignoreInitial: true }).on('all', () => {
builder.rebuild()
})
})
watch('public/**/*', { ignoreInitial: true }).on('all', () => {
handleAssets()
})
} else {
process.exit(0)
}
}

main()
2 changes: 1 addition & 1 deletion ui/cypress.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"defaultCommandTimeout": 120000,
"defaultCommandTimeout": 10000,
"responseTimeout": 60000,
"requestTimeout": 60000,
"screenshotOnRunFailure": false,
Expand Down
Loading