Skip to content

Commit

Permalink
sync three.js
Browse files Browse the repository at this point in the history
  • Loading branch information
liyangyang0901 committed May 30, 2023
2 parents dbdc202 + a4fa9da commit 9b6a740
Show file tree
Hide file tree
Showing 2,748 changed files with 143,578 additions and 165,676 deletions.
61 changes: 61 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"root": true,
"env": {
"browser": true,
"node": true,
"es2018": true
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"extends": [
"mdcs",
"plugin:compat/recommended"
],
"plugins": [
"html",
"import"
],
"settings": {
"polyfills": [
"WebGL2RenderingContext"
]
},
"globals": {
"__THREE_DEVTOOLS__": "readonly",
"potpack": "readonly",
"fflate": "readonly",
"Stats": "readonly",
"XRWebGLBinding": "readonly",
"XRWebGLLayer": "readonly",
"GPUShaderStage": "readonly",
"GPUBufferUsage": "readonly",
"GPUTextureUsage": "readonly",
"GPUTexture": "readonly",
"GPUMapMode": "readonly",
"QUnit": "readonly",
"Ammo": "readonly",
"XRRigidTransform": "readonly",
"XRMediaBinding": "readonly",
"CodeMirror": "readonly",
"esprima": "readonly",
"jsonlint": "readonly"
},
"rules": {
"no-throw-literal": [
"error"
],
"quotes": [
"error",
"single"
],
"prefer-const": [
"error",
{
"destructuring": "any",
"ignoreReadBeforeAssign": false
}
]
}
}
16 changes: 16 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": [
"config:base",
":disableDependencyDashboard"
],
"timezone": "Asia/Tokyo",
"schedule": ["after 1am and before 7am every monday"],
"packageRules": [
{
"matchDepTypes": ["devDependencies"],
"matchUpdateTypes": ["patch", "minor", "pin", "digest"],
"groupName": "devDependencies (non-major)",
"automerge": true
}
]
}
55 changes: 30 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,80 +17,85 @@ permissions:

jobs:
lint:
name: "Lint testing"
name: Lint testing
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: 'npm'
- name: Install packages
- name: Install dependencies
run: npm ci

- name: === Lint testing ===
run: npm run lint

unit:
name: "Unit testing"
name: Unit testing
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: 'npm'
- name: Install packages
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build

- name: === Unit testing ===
run: npm run test-unit

e2e:
name: "E2E testing"
name: E2E testing
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
os: [ windows-latest, ubuntu-latest ]
CI: [ 0, 1, 2, 3, 4, 5, 6, 7 ]
os: [ windows-latest, ubuntu-latest, macos-latest ]
CI: [ 0, 1, 2, 3 ]
env:
CI: ${{ matrix.CI }}
FORCE_COLOR: 1
steps:
- name: Git checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: 'npm'
- name: Install packages
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build

- name: === E2E testing ===
run: npm run test-e2e
- name: Upload output screenshots
uses: actions/upload-artifact@v3
if: always()
with:
name: Output screenshots
path: test/e2e/output-screenshots
if-no-files-found: ignore

e2e-cov:
name: "Examples ready for release"
name: Examples ready for release
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: 'npm'
- name: Install packages
- name: Install dependencies
run: npm ci

- name: === Examples ready for release ===
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/read-size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Read size

on:
pull_request:
paths:
- 'src/**'
- 'package.json'
- 'utils/build/**'

# This workflow runs in a read-only environment. We can safely checkout
# the PR code here.
# Reference:
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
permissions:
contents: read

jobs:
read-size:
name: Tree-shaking
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: === Test tree-shaking ===
run: npm run test-treeshake
- name: Read bundle sizes
id: read-size
run: |
FILESIZE=$(stat --format=%s build/three.module.min.js)
gzip -k build/three.module.min.js
FILESIZE_GZIP=$(stat --format=%s build/three.module.min.js.gz)
TREESHAKEN=$(stat --format=%s test/treeshake/index.bundle.min.js)
gzip -k test/treeshake/index.bundle.min.js
TREESHAKEN_GZIP=$(stat --format=%s test/treeshake/index.bundle.min.js.gz)
PR=${{ github.event.pull_request.number }}
# write the output in a json file to upload it as artifact
node -pe "JSON.stringify({ filesize: $FILESIZE, gzip: $FILESIZE_GZIP, treeshaken: $TREESHAKEN, treeshakenGzip: $TREESHAKEN_GZIP, pr: $PR })" > sizes.json
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: sizes
path: sizes.json
156 changes: 156 additions & 0 deletions .github/workflows/report-size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: Report size

on:
workflow_run:
workflows: ["Read size"]
types:
- completed

# This workflow needs to be run with "pull-requests: write" permissions to
# be able to comment on the pull request. We can't checkout the PR code
# in this workflow.
# Reference:
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
permissions:
pull-requests: write

jobs:
report-size:
name: Comment on PR
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Log GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"

# Using actions/download-artifact doesn't work here
# https://github.com/actions/download-artifact/issues/60
- name: Download artifact
uses: actions/github-script@v6
id: download-artifact
with:
result-encoding: string
script: |
const fs = require('fs/promises');
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const matchArtifact = artifacts.data.artifacts.find((artifact) => artifact.name === 'sizes');
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
await fs.writeFile('sizes.zip', Buffer.from(download.data));
await exec.exec('unzip sizes.zip');
const json = await fs.readFile('sizes.json', 'utf8');
return json;
# This runs on the base branch of the PR, meaning "dev"
- name: Git checkout
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: === Test tree-shaking ===
run: npm run test-treeshake
- name: Read sizes
id: read-size
run: |
FILESIZE_BASE=$(stat --format=%s build/three.module.min.js)
gzip -k build/three.module.min.js
FILESIZE_BASE_GZIP=$(stat --format=%s build/three.module.min.js.gz)
TREESHAKEN_BASE=$(stat --format=%s test/treeshake/index.bundle.min.js)
gzip -k test/treeshake/index.bundle.min.js
TREESHAKEN_BASE_GZIP=$(stat --format=%s test/treeshake/index.bundle.min.js.gz)
# log to console
echo "FILESIZE_BASE=$FILESIZE_BASE"
echo "FILESIZE_BASE_GZIP=$FILESIZE_BASE_GZIP"
echo "TREESHAKEN_BASE=$TREESHAKEN_BASE"
echo "TREESHAKEN_BASE_GZIP=$TREESHAKEN_BASE_GZIP"
echo "FILESIZE_BASE=$FILESIZE_BASE" >> $GITHUB_OUTPUT
echo "FILESIZE_BASE_GZIP=$FILESIZE_BASE_GZIP" >> $GITHUB_OUTPUT
echo "TREESHAKEN_BASE=$TREESHAKEN_BASE" >> $GITHUB_OUTPUT
echo "TREESHAKEN_BASE_GZIP=$TREESHAKEN_BASE_GZIP" >> $GITHUB_OUTPUT
- name: Format sizes
id: format
# It's important these are passed as env variables.
# https://securitylab.github.com/research/github-actions-untrusted-input/
env:
FILESIZE: ${{ fromJSON(steps.download-artifact.outputs.result).filesize }}
FILESIZE_GZIP: ${{ fromJSON(steps.download-artifact.outputs.result).gzip }}
FILESIZE_BASE: ${{ steps.read-size.outputs.FILESIZE_BASE }}
FILESIZE_BASE_GZIP: ${{ steps.read-size.outputs.FILESIZE_BASE_GZIP }}
TREESHAKEN: ${{ fromJSON(steps.download-artifact.outputs.result).treeshaken }}
TREESHAKEN_GZIP: ${{ fromJSON(steps.download-artifact.outputs.result).treeshakenGzip }}
TREESHAKEN_BASE: ${{ steps.read-size.outputs.TREESHAKEN_BASE }}
TREESHAKEN_BASE_GZIP: ${{ steps.read-size.outputs.TREESHAKEN_BASE_GZIP }}
run: |
FILESIZE_FORM=$(node ./test/treeshake/utils/format-size.js "$FILESIZE")
FILESIZE_GZIP_FORM=$(node ./test/treeshake/utils/format-size.js "$FILESIZE_GZIP")
FILESIZE_BASE_FORM=$(node ./test/treeshake/utils/format-size.js "$FILESIZE_BASE")
FILESIZE_BASE_GZIP_FORM=$(node ./test/treeshake/utils/format-size.js "$FILESIZE_BASE_GZIP")
FILESIZE_DIFF=$(node ./test/treeshake/utils/format-diff.js "$FILESIZE" "$FILESIZE_BASE")
TREESHAKEN_FORM=$(node ./test/treeshake/utils/format-size.js "$TREESHAKEN")
TREESHAKEN_GZIP_FORM=$(node ./test/treeshake/utils/format-size.js "$TREESHAKEN_GZIP")
TREESHAKEN_BASE_FORM=$(node ./test/treeshake/utils/format-size.js "$TREESHAKEN_BASE")
TREESHAKEN_BASE_GZIP_FORM=$(node ./test/treeshake/utils/format-size.js "$TREESHAKEN_BASE_GZIP")
TREESHAKEN_DIFF=$(node ./test/treeshake/utils/format-diff.js "$TREESHAKEN" "$TREESHAKEN_BASE")
echo "FILESIZE=$FILESIZE_FORM" >> $GITHUB_OUTPUT
echo "FILESIZE_GZIP=$FILESIZE_GZIP_FORM" >> $GITHUB_OUTPUT
echo "FILESIZE_BASE=$FILESIZE_BASE_FORM" >> $GITHUB_OUTPUT
echo "FILESIZE_BASE_GZIP=$FILESIZE_BASE_GZIP_FORM" >> $GITHUB_OUTPUT
echo "FILESIZE_DIFF=$FILESIZE_DIFF" >> $GITHUB_OUTPUT
echo "TREESHAKEN=$TREESHAKEN_FORM" >> $GITHUB_OUTPUT
echo "TREESHAKEN_GZIP=$TREESHAKEN_GZIP_FORM" >> $GITHUB_OUTPUT
echo "TREESHAKEN_BASE=$TREESHAKEN_BASE_FORM" >> $GITHUB_OUTPUT
echo "TREESHAKEN_BASE_GZIP=$TREESHAKEN_BASE_GZIP_FORM" >> $GITHUB_OUTPUT
echo "TREESHAKEN_DIFF=$TREESHAKEN_DIFF" >> $GITHUB_OUTPUT
- name: Find existing comment
uses: peter-evans/find-comment@v2
id: find-comment
with:
issue-number: ${{ fromJSON(steps.download-artifact.outputs.result).pr }}
comment-author: 'github-actions[bot]'
body-includes: Bundle size
- name: Comment on PR
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ fromJSON(steps.download-artifact.outputs.result).pr }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
### 📦 Bundle size
_Full ESM build, minified and gzipped._
| Filesize `${{ github.ref_name }}` | Filesize PR | Diff |
|----------|---------|------|
| ${{ steps.format.outputs.FILESIZE_BASE }} (${{ steps.format.outputs.FILESIZE_BASE_GZIP }}) | ${{ steps.format.outputs.FILESIZE }} (${{ steps.format.outputs.FILESIZE_GZIP }}) | ${{ steps.format.outputs.FILESIZE_DIFF }} |
### 🌳 Bundle size after tree-shaking
_Minimal build including a renderer, camera, empty scene, and dependencies._
| Filesize `${{ github.ref_name }}` | Filesize PR | Diff |
|----------|---------|------|
| ${{ steps.format.outputs.TREESHAKEN_BASE }} (${{ steps.format.outputs.TREESHAKEN_BASE_GZIP }}) | ${{ steps.format.outputs.TREESHAKEN }} (${{ steps.format.outputs.TREESHAKEN_GZIP }}) | ${{ steps.format.outputs.TREESHAKEN_DIFF }} |
Loading

0 comments on commit 9b6a740

Please sign in to comment.