Skip to content

Commit

Permalink
Merge branch 'master' into fix-transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Nov 20, 2022
2 parents 050ea1a + d02fbf0 commit 7e7e6e7
Show file tree
Hide file tree
Showing 41 changed files with 5,771 additions and 5,857 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
node-version: 16.x
- run: npm ci
- name: build stats
run: npm run build -- -s
run: npm run build
- name: persist
id: b
uses: actions/github-script@v6
Expand All @@ -36,8 +36,7 @@ jobs:
script: |
const fs = require('fs');
return JSON.stringify({
size: JSON.parse(fs.readFileSync('cli_output/build_size.json')),
stats: JSON.parse(fs.readFileSync('cli_output/build_stats.json')),
size: { fabric: { minified: fs.statSync('dist/fabric.min.js').size, bundled: fs.statSync('dist/fabric.js').size } }
});
- name: checkout src files
run: git checkout origin/master -- src
Expand All @@ -51,16 +50,15 @@ jobs:
script: |
const fs = require('fs');
return JSON.stringify({
size: JSON.parse(fs.readFileSync('cli_output/build_size.json')),
stats: JSON.parse(fs.readFileSync('cli_output/build_stats.json')),
size: { fabric: { minified: fs.statSync('dist/fabric.min.js').size, bundled: fs.statSync('dist/fabric.js').size } }
});
- name: process
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const { run } = await import('${{ github.workspace }}/scripts/buildStats.mjs');
const res = await run({
const { run_simple } = await import('${{ github.workspace }}/scripts/buildStats.mjs');
const res = await run_simple({
github,
context,
core,
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
## [next]

- ci(): patch TS transformer [#8409](https://github.com/fabricjs/fabric.js/pull/8409)
- chore(TS): migrate Collection [#8433](https://github.com/fabricjs/fabric.js/pull/8433)
- ci(): Simplify filestats even more [#8449](https://github.com/fabricjs/fabric.js/pull/8449)
- chore(TS): migrate filter backends [#8403](https://github.com/fabricjs/fabric.js/pull/8403)
- chore(TS): migrate Text classes/mixins [#8408](https://github.com/fabricjs/fabric.js/pull/8408)
- chore(TS): migrate Path [#8412](https://github.com/fabricjs/fabric.js/pull/8412)
- ci(): remove unwanted build stats (from [#8395](https://github.com/fabricjs/fabric.js/pull/8395)) [#8416](https://github.com/fabricjs/fabric.js/pull/8416)
- chore(TS): migrate Line [#8413](https://github.com/fabricjs/fabric.js/pull/8413)
- chore(TS): migrate Polyline/Polygon [#8417](https://github.com/fabricjs/fabric.js/pull/8417)
- chore(TS): migrate Rect [#8411](https://github.com/fabricjs/fabric.js/pull/8411)
- chore(TS): migrate Ellipse [#8408](https://github.com/fabricjs/fabric.js/pull/8408)
- chore(TS): migrate Triangle to TS [#8410](https://github.com/fabricjs/fabric.js/pull/8410)
- chore(TS): migrate Circle to TS [#8406](https://github.com/fabricjs/fabric.js/pull/8406)
Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import './src/shapes/group.class';
import './src/shapes/active_selection.class'; // optional interaction
import './src/shapes/image.class';
import './src/mixins/object_straightening.mixin'; // optional objectstraightening
import './src/filters/webgl_backend.class'; // optional image_filters
import './src/filters/2d_backend.class'; // optional image_filters
import './src/filters/WebGLProbe'; // optional image_filters
import './src/filters/base_filter.class'; // optional image_filters
import './src/filters/colormatrix_filter.class'; // optional image_filters
import './src/filters/brightness_filter.class'; // optional image_filters
Expand All @@ -58,7 +57,6 @@ import './src/filters/gamma_filter.class'; // optional image_filters
import './src/filters/composed_filter.class'; // optional image_filters
import './src/filters/hue_rotation.class'; // optional image_filters
import './src/shapes/text.class'; // optional text
import './src/mixins/text_style.mixin'; // optional text
import './src/shapes/itext.class'; // optional itext
import './src/mixins/itext_behavior.mixin'; // optional itext
import './src/mixins/itext_click_behavior.mixin'; // optional itext
Expand Down
16 changes: 0 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
"ps-list": "^8.1.0",
"qunit": "^2.17.2",
"rollup": "^2.75.6",
"rollup-plugin-analyzer": "^4.0.0",
"rollup-plugin-size-snapshot": "^0.12.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-ts": "^3.0.2",
Expand Down
29 changes: 6 additions & 23 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import json from '@rollup/plugin-json';
import { writeFileSync } from 'fs';
import analyze from 'rollup-plugin-analyzer';
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
import { terser } from 'rollup-plugin-terser';
import ts from 'rollup-plugin-ts';

const runStats = Number(process.env.BUILD_STATS);
let analyzed = false;

const splitter = /\n|\s|,/g;

// https://rollupjs.org/guide/en/#configuration-files
export default {
input: process.env.BUILD_INPUT?.split(splitter) || ['./index.js'],
output: [
{
file: process.env.BUILD_OUTPUT || './dist/fabric.js',
name: 'fabric',
format: 'cjs',
sourcemap: true,
},
Number(process.env.MINIFY)
? {
file: process.env.BUILD_MIN_OUTPUT || './dist/fabric.min.js',
Expand All @@ -28,32 +31,12 @@ export default {
],
}
: null,
{
file: process.env.BUILD_OUTPUT || './dist/fabric.js',
name: 'fabric',
format: 'cjs',
sourcemap: true,
},
],
// see list of plugins (not comprehensive): https://github.com/rollup/awesome
plugins: [
json(),
ts({
/* Plugin options */
}),
runStats &&
analyze({
onAnalysis(analysis) {
if (analyzed) {
// We only want reports on the minified output
throw '';
}
writeFileSync(
'cli_output/build_stats.json',
JSON.stringify(analysis, null, 2)
);
analyzed = true;
},
}),
],
};
132 changes: 66 additions & 66 deletions scripts/buildStats.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import _ from 'lodash';

const REQUESTED_COMMENTS_PER_PAGE = 20;

const COMMENT_MARKER = '<!-- BUILD STATS COMMENT -->';

const MAX_COMMENT_CHARS = 65536;

const INACCURATE_COMMENT =
'\n*inaccurate, see [link](https://github.com/doesdev/rollup-plugin-analyzer#why-is-the-reported-size-not-the-same-as-the-file-on-disk)';

function printSize(a, b) {
const diff = b - a;
return `${b.toFixed(3)} (**${Math.sign(diff) > 0 ? '+' : ''}${diff.toFixed(
3
diff !== 0 ? 3 : 0
)}**)`;
}

function printSizeByte(a, b) {
function printSizeKByte(a, b) {
return printSize(a / 1024, b / 1024);
}

Expand Down Expand Up @@ -46,42 +41,12 @@ export async function findCommentId(github, context) {
export async function run({ github, context, a, b }) {
const {
repo: { owner, repo },
payload: {
pull_request: { base, head },
},
} = context;
const changedFiles = (
await github.rest.repos.compareCommits({
base: base.sha,
head: head.sha,
owner,
repo,
})
).data.files
.map(({ filename }) => filename)
.filter((file) => file.startsWith('src'));

const files = {};
b.stats.modules.forEach((b) => {
const file = b.id.replace(/^(\\|\/)/, '');
if (!changedFiles.includes(file)) {
return;
}
const aOut = {
origSize: 0,
size: 0,
...(a.stats.modules.find(({ id }) => id === b.id) || {}),
};
files[file] = {
a: { sizeBefore: aOut.origSize, sizeAfter: aOut.size },
b: { sizeBefore: b.origSize, sizeAfter: b.size },
};
});

const table = [
['file / KB (diff)', 'bundled', 'reduced*', 'minified', 'gzipped'],
['---', '---', '---', '---', '---'],
..._.map(b.size, (_b, file) => {
['file / KB (diff)', 'bundled', 'minified', 'gzipped'],
['---', '---', '---', '---'],
...Object.entries(b.size).map(([file, _b]) => {
const _a = {
bundled: 0,
minified: 0,
Expand All @@ -90,36 +55,71 @@ export async function run({ github, context, a, b }) {
};
return [
file,
printSizeByte(_a.bundled, _b.bundled),
'',
printSizeByte(_a.minified, _b.minified),
printSizeByte(_a.gzipped, _b.gzipped),
printSizeKByte(_a.bundled, _b.bundled),
printSizeKByte(_a.minified, _b.minified),
printSizeKByte(_a.gzipped, _b.gzipped),
];
}),
];

const body = [
COMMENT_MARKER,
'**Build Stats**',
'',
...table.map((row) => ['', ...row, ''].join(' | ')),
'',
]
.join('\n')
.slice(0, MAX_COMMENT_CHARS);

const commentId = await findCommentId(github, context);

await (commentId
? github.rest.issues.updateComment({
repo,
owner,
comment_id: commentId,
body,
})
: github.rest.issues.createComment({
repo,
owner,
issue_number: context.payload.pull_request.number,
body,
}));
}

export async function run_simple({ github, context, a, b }) {
const {
repo: { owner, repo },
} = context;

const table = [
['file / KB (diff)', 'bundled', 'minified'],
['---', '---', '---'],
...Object.entries(b.size).map(([file, _b]) => {
const _a = {
bundled: 0,
minified: 0,
...(a.size[file] || {}),
};
return [
file,
printSizeKByte(_a.bundled, _b.bundled),
printSizeKByte(_a.minified, _b.minified),
];
}),
..._.orderBy(
_.map(files, ({ a, b }, key) => {
return [
key,
printSizeByte(a.sizeBefore, b.sizeBefore),
printSizeByte(a.sizeAfter, b.sizeAfter),
];
}),
[0],
['asc']
),
];

const body =
[
COMMENT_MARKER,
'**Build Stats**',
'',
...table.map((row) => ['', ...row, ''].join(' | ')),
'',
]
.join('\n')
.slice(0, MAX_COMMENT_CHARS - INACCURATE_COMMENT.length) +
INACCURATE_COMMENT;
const body = [
COMMENT_MARKER,
'**Build Stats**',
'',
...table.map((row) => ['', ...row, ''].join(' | ')),
'',
]
.join('\n')
.slice(0, MAX_COMMENT_CHARS);

const commentId = await findCommentId(github, context);

Expand Down
Loading

0 comments on commit 7e7e6e7

Please sign in to comment.