Skip to content

Commit

Permalink
docs(en): merging all conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
docschina-bot committed Oct 23, 2023
2 parents 01d7fb5 + be81b00 commit fedbecc
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 220 deletions.
366 changes: 183 additions & 183 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"esbuild": "0.19.3",
"esbuild": "0.19.4",
"fast-watch": "1.0.0",
"highlight.js": "10.4.1",
"js-yaml": "3.14.0",
Expand Down
8 changes: 5 additions & 3 deletions src/analyze/flame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
setDarkModeListener,
setResizeEventListener,
setWheelEventListener,
shortenDataURLForDisplay,
splitPathBySlash,
stripDisabledPathPrefix,
textToHTML,
} from './helpers'
Expand Down Expand Up @@ -71,15 +73,15 @@ let analyzeDirectoryTree = (metafile: Metafile): Tree => {

for (let o in outputs) {
// Find the common directory prefix, not including the file name
let parts = o.split('/')
let parts = splitPathBySlash(o)
parts.pop()
commonPrefix = commonPrefixFinder(parts.join('/'), commonPrefix)
}

for (let o in outputs) {
if (isSourceMapPath(o)) continue

let name = commonPrefix ? o.split('/').slice(commonPrefix.length).join('/') : o
let name = commonPrefix ? splitPathBySlash(o).slice(commonPrefix.length).join('/') : o
let node: TreeNodeInProgress = { name_: name, inputPath_: '', bytesInOutput_: 0, children_: {} }
let output = outputs[o]
let inputs = output.inputs
Expand Down Expand Up @@ -425,7 +427,7 @@ export let createFlame = (metafile: Metafile): HTMLDivElement => {

// Show a tooltip for hovered nodes
if (node) {
let tooltip = node.inputPath_
let tooltip = node.name_ === node.inputPath_ ? shortenDataURLForDisplay(node.inputPath_) : node.inputPath_
let nameSplit = tooltip.length - node.name_.length
tooltip = textToHTML(tooltip.slice(0, nameSplit)) + '<b>' + textToHTML(tooltip.slice(nameSplit)) + '</b>'
if (colorMode === COLOR.FORMAT) tooltip += textToHTML(formatColorToText(cssBackgroundForInputPath(node.inputPath_), ' – '))
Expand Down
34 changes: 31 additions & 3 deletions src/analyze/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,36 @@ export let createSpanWithClass = (className: string, text: string): HTMLSpanElem
return span
}

export let shortenDataURLForDisplay = (path: string): string => {
// Data URLs can be really long. This shortens them to something suitable for
// display in a tooltip. This shortening behavior is also what esbuild does.
if (path.startsWith('data:') && path.indexOf(',') >= 0) {
path = path.slice(0, 65).replace(/\n/g, '\\n')
return '<' + (path.length > 64 ? path.slice(0, 64) + '...' : path) + '>'
}
return path
}

export let splitPathBySlash = (path: string): string[] => {
// Treat data URLs (e.g. "data:text/plain;base64,ABCD") as a single path element
if (path.startsWith('data:') && path.indexOf(',') >= 0) {
return [path]
}

const parts = path.split('/')

// Replace ['a:', '', 'b'] at the start of the path with ['a://b']. This
// handles paths that look like a URL scheme such as "https://example.com".
if (parts.length >= 3 && parts[1] === '' && parts[0].endsWith(':')) {
parts.splice(0, 3, parts.slice(0, 3).join('/'))
}

return parts
}

export let commonPrefixFinder = (path: string, commonPrefix: string[] | undefined): string[] => {
let parts = path.split('/')
if (path === '') return []
let parts = splitPathBySlash(path)
if (!commonPrefix) return parts

// Note: This deliberately loops one past the end of the array so it can compare against "undefined"
Expand All @@ -102,7 +130,7 @@ export let commonPrefixFinder = (path: string, commonPrefix: string[] | undefine
}

export let commonPostfixFinder = (path: string, commonPostfix: string[] | undefined): string[] => {
let parts = path.split('/')
let parts = splitPathBySlash(path)
if (!commonPostfix) return parts.reverse()

// Note: This deliberately loops one past the end of the array so it can compare against "undefined"
Expand Down Expand Up @@ -138,7 +166,7 @@ export let posixRelPath = (path: string, relToDir: string): string => {
}

export let nodeModulesPackagePathOrNull = (path: string): string | null => {
let parts = path.split('/')
let parts = splitPathBySlash(path)
for (let i = parts.length - 1; i >= 0; i--) {
if (parts[i] === 'node_modules') {
parts = parts.slice(i + 1)
Expand Down
4 changes: 0 additions & 4 deletions src/analyze/sunburst.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@
padding: 0 10px;
vertical-align: top;
white-space: pre;

& span {
opacity: 0.5;
}
}

& .size {
Expand Down
9 changes: 5 additions & 4 deletions src/analyze/sunburst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
setDarkModeListener,
setResizeEventListener,
setWheelEventListener,
shortenDataURLForDisplay,
splitPathBySlash,
stripDisabledPathPrefix,
textToHTML,
} from './helpers'
Expand Down Expand Up @@ -382,11 +384,11 @@ export let createSunburst = (metafile: Metafile): HTMLDivElement => {
// Show a tooltip for hovered nodes
if (node && node !== animatedNode.parent_) {
let tooltip = node.inputPath_
if (node.parent_) {
if (node.parent_ && node.parent_.inputPath_ !== '') {
let i = node.parent_.inputPath_.length
tooltip = textToHTML(tooltip.slice(0, i)) + '<b>' + textToHTML(tooltip.slice(i)) + '</b>'
} else {
tooltip = '<b>' + textToHTML(tooltip) + '</b>'
tooltip = '<b>' + textToHTML(shortenDataURLForDisplay(tooltip)) + '</b>'
}
if (colorMode === COLOR.FORMAT) tooltip += textToHTML(formatColorToText(cssBackgroundForInputPath(node.inputPath_), ' – '))
else tooltip += ' – ' + textToHTML(bytesToText(node.bytesInOutput_))
Expand Down Expand Up @@ -549,10 +551,9 @@ export let createSunburst = (metafile: Metafile): HTMLDivElement => {
rowEl.tabIndex = 0
barsEl.appendChild(rowEl)

let prefix = /^[^/]*\/?/.exec(name)![0]
let nameEl = document.createElement('div')
nameEl.className = styles.name
nameEl.innerHTML = textToHTML(prefix) + '<span>' + name.slice(prefix.length) + '</span>'
nameEl.innerHTML = textToHTML(name === child.inputPath_ ? shortenDataURLForDisplay(name) : name)
rowEl.appendChild(nameEl)

let sizeEl = document.createElement('div')
Expand Down
4 changes: 2 additions & 2 deletions src/analyze/tree.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hasOwnProperty } from "./helpers"
import { hasOwnProperty, splitPathBySlash } from "./helpers"

export interface TreeNodeInProgress {
name_: string
Expand All @@ -15,7 +15,7 @@ export let orderChildrenBySize = (
}

export let accumulatePath = (root: TreeNodeInProgress, path: string, bytesInOutput: number): number => {
let parts = path.split('/')
let parts = splitPathBySlash(path)
let n = parts.length
let parent = root
let inputPath = ''
Expand Down
5 changes: 3 additions & 2 deletions src/analyze/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { showWhyFile } from './whyfile'
import {
commonPostfixFinder,
commonPrefixFinder,
splitPathBySlash,
textToHTML,
} from './helpers'

Expand Down Expand Up @@ -41,13 +42,13 @@ let generateWarnings = (metafile: Metafile): HTMLElement[] => {
}

for (let path of array) {
let parts = path.split('/')
let parts = splitPathBySlash(path)
if (commonPrefix) parts = parts.slice(commonPrefix.length)
commonPostfix = commonPostfixFinder(parts.join('/'), commonPostfix)
}

for (let path of array.sort()) {
let parts = path.split('/').map(textToHTML)
let parts = splitPathBySlash(path).map(textToHTML)
let itemEl = document.createElement('li')
let html = '<pre><a href="javascript:void 0">'
let postfix = ''
Expand Down
74 changes: 60 additions & 14 deletions src/content/faq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ body:
- figcaption: JavaScript benchmark
- benchmark:
'[esbuild](https://esbuild.github.io/)': 0.37
'[parcel 2](https://parceljs.org/)': 30.50
'[rollup](https://rollupjs.org/) + [terser](https://terser.org/)': 32.07
'[webpack 5](https://webpack.js.org/)': 39.70
'[esbuild](https://esbuild.github.io/)': 0.39
'[parcel 2](https://parceljs.org/)': 14.91
'[rollup 4](https://rollupjs.org/) + [terser](https://terser.org/)': 34.10
'[webpack 5](https://webpack.js.org/)': 41.21

- p: >
This benchmark approximates a large JavaScript codebase by duplicating
Expand All @@ -142,12 +142,12 @@ body:
[esbuild repo](https://github.com/evanw/esbuild).
- table: |
| Bundler | Time | Relative slowdown | Absolute speed | Output size |
| :-------------- | ------: | ----------------: | -------------: | ----------: |
| esbuild | 0.37s | 1x | 1479.6 kloc/s | 5.80mb |
| parcel 2 | 30.50s | 80x | 17.9 kloc/s | 5.87mb |
| rollup + terser | 32.07s | 84x | 17.1 kloc/s | 5.81mb |
| webpack 5 | 39.70s | 104x | 13.8 kloc/s | 5.84mb |
| Bundler | Time | Relative slowdown | Absolute speed | Output size |
| :---------------- | ------: | ----------------: | -------------: | ----------: |
| esbuild | 0.39s | 1x | 1403.7 kloc/s | 5.80mb |
| parcel 2 | 14.91s | 38x | 36.7 kloc/s | 5.78mb |
| rollup 4 + terser | 34.10s | 87x | 16.1 kloc/s | 5.82mb |
| webpack 5 | 41.21s | 106x | 13.3 kloc/s | 5.84mb |
- p: >
Each time reported is the best of three runs. I'm running esbuild with
Expand All @@ -163,8 +163,8 @@ body:
- figcaption: TypeScript benchmark
- benchmark:
'[esbuild](https://esbuild.github.io/)': 0.10
'[parcel 2](https://parceljs.org/)': 8.18
'[webpack 5](https://webpack.js.org/)': 15.96
'[parcel 2](https://parceljs.org/)': 6.91
'[webpack 5](https://webpack.js.org/)': 16.69

- p: >
This benchmark uses the old [Rome](https://github.com/rome/tools) code base
Expand All @@ -177,8 +177,8 @@ body:
| Bundler | Time | Relative slowdown | Absolute speed | Output size |
| :-------- | ------: | ----------------: | -------------: | ----------: |
| esbuild | 0.10s | 1x | 1318.4 kloc/s | 0.97mb |
| parcel 2 | 8.18s | 82x | 16.1 kloc/s | 0.97mb |
| webpack 5 | 15.96s | 160x | 8.3 kloc/s | 1.27mb |
| parcel 2 | 6.91ѕ | 69x | 16.1 kloc/s | 0.96mb |
| webpack 5 | 16.69ѕ | 167x | 8.3 kloc/s | 1.27mb |
- p: >
Each time reported is the best of three runs. I'm running esbuild with
Expand Down Expand Up @@ -367,6 +367,52 @@ body:
- >
Use another build tool instead of esbuild
- h2#old-go-version: Outdated version of Go

- p: >
If you use an automated dependency vulnerability scanner, you may get a
report that the version of the Go compiler that esbuild uses and/or the
version of `golang.org/x/sys` (esbuild's only dependency) is outdated.
These reports are benign and should be ignored.
- p: >
This happens because esbuild's code is deliberately intended to be
compilable with Go 1.13. Later versions of Go have dropped support for
certain older platforms that I want esbuild to be able to run on (e.g.
older versions of macOS). While esbuild's published binaries are compiled
with a much newer version of the Go compiler (and therefore don't work
on older versions of macOS), you are currently still able to compile the
latest version of esbuild for yourself with Go 1.13 and use it on older
versions of macOS because esbuild's code can still be compiled with Go
as far back as 1.13.
- p: >
People and/or automated tools sometimes see the `go 1.13` line in [`go.mod`](https://github.com/evanw/esbuild/blob/main/go.mod)
and complain that esbuild's published binaries are built with Go 1.13, which
is a really old version of Go. However, that's not true. That line in `go.mod`
only specifies the minimum compiler version. It has nothing to do with the
version of Go that esbuild's published binaries are built with, which is a
much newer version of Go. [Please read the documentation.](https://go.dev/ref/mod#go-mod-file-go)
- p: >
People also sometimes want esbuild to update the `golang.org/x/sys` dependency
because there is a known vulnerability in the version that esbuild uses
(specifically [GO-2022-0493](https://pkg.go.dev/vuln/GO-2022-0493)
about the `Faccessat` function). The problem that prevents esbuild from
updating to a newer version of the `golang.org/x/sys` dependency is that
newer versions have started using the `unsafe.Slice` function, which was
first introduced in Go 1.17 (and therefore doesn't compile in older
versions of Go). However, this vulnerability report is irrelevant because
a) esbuild doesn't ever call that function in the first place and b)
esbuild is a build tool, not a sandbox, and esbuild's file system access
is not security-sensitive.
- p: >
I'm not going to drop compatibility with older platforms and prevent some
people from being able to use esbuild just to work around irrelevant
vulnerability reports. Please ignore any reports about the issues described
above.
- h2: Minified newlines

- p: >
Expand Down
8 changes: 4 additions & 4 deletions src/content/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ index:
- blockquote: 极速 JavaScript 打包器

- benchmark.animated:
'[esbuild](https://esbuild.github.io/)': 0.37
'[parcel 2](https://parceljs.org/)': 30.50
'[rollup](https://rollupjs.org/) + [terser](https://terser.org/)': 32.07
'[webpack 5](https://webpack.js.org/)': 39.70
'[esbuild](https://esbuild.github.io/)': 0.39
'[parcel 2](https://parceljs.org/)': 14.91
'[rollup 4](https://rollupjs.org/) + [terser](https://terser.org/)': 34.10
'[webpack 5](https://webpack.js.org/)': 41.21

- figcaption: >
以上数据:分别是使用各工具的默认配置,
Expand Down
5 changes: 5 additions & 0 deletions src/scripts/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,15 @@ async function generateMain(key, main) {
if (tag === 'toc') {
let toc = `<ul>\n`
for (let { tag: t, value: v } of main.body) {
<<<<<<< HEAD
if (t === 'h2') {
let newValue = escapeHTML(v)
toc += ` <li><a href="#${escapeAttribute(toID(v))}">${md.renderInline(newValue.trim())}</a></li>\n`
}
=======
if (t === 'h2') toc += `<li><a href="#${escapeAttribute(toID(v))}">${md.renderInline(v.trim())}</a></li>\n`
else if (t.startsWith('h2#')) toc += `<li><a href="#${escapeAttribute(toID(t.slice(3) || v))}">${md.renderInline(v.trim())}</a></li>\n`
>>>>>>> be81b00dabbaedbe30e5f0b8ac6b4a7dc7b0e4c5
}
return toc + `</ul>`
}
Expand Down

0 comments on commit fedbecc

Please sign in to comment.