Skip to content

Commit

Permalink
Support inline enum and update rollup/terser version to latest. (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar authored Sep 19, 2024
1 parent 3000a69 commit 6d7dbe1
Show file tree
Hide file tree
Showing 33 changed files with 5,389 additions and 935 deletions.
2,487 changes: 2,000 additions & 487 deletions .api/public.d.ts

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
"no-mixed-spaces-and-tabs": "off",
"no-cond-assign": "off",
"import/no-extraneous-dependencies": ["error"],
"@typescript-eslint/explicit-function-return-type": [
"error"
],
"@typescript-eslint/explicit-function-return-type": ["error", { "allowIIFEs": true }],
"@typescript-eslint/ban-types": [
"error",
{
Expand All @@ -47,6 +45,16 @@
"semi": [
"error",
"always"
],
"indent": [
"error", 4, {
"SwitchCase": 0,
"ignoredNodes": [
"FunctionExpression > .params[decorators.length > 0]",
"FunctionExpression > .params > :matches(Decorator, :not(:first-child))",
"ClassBody.body > PropertyDefinition[decorators.length > 0] > .key"
]
}
]
}
}
6 changes: 6 additions & 0 deletions modules/build-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"@babel/parser": "^7.20.13",
"@babel/traverse": "^7.20.13",

"magic-string": "^0.30.10",
"@rollup/plugin-replace": "5.0.7",
"@rollup/pluginutils": "5.1.0",
"ast-kit": "1.0.0",
"fast-glob": "3.3.2",

"@types/resolve": "^1.20.2",
"dedent": "^0.7.0",
"fs-extra": "~11.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ export default function recordDecorators(): babel.PluginObj<any> {
}


const currentClassName = nodePath.node.id.name;
const currentClassName = nodePath.node.id?.name;
if (!currentClassName) {
return;
}
const classDecoratorNodes: any[] | undefined | null = nodePath.node.decorators;
let classDecoratorResults: DecoratorParseResult[] = [];
if (!classDecoratorNodes) { // filter #3, no decorators for current class
Expand Down
25 changes: 21 additions & 4 deletions modules/build-engine/src/engine-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { externalWasmLoader } from './rollup-plugins/external-wasm-loader';
import { StatsQuery } from '@ccbuild/stats-query';
import { filePathToModuleRequest } from '@ccbuild/utils';
import { rpNamedChunk } from './rollup-plugins/systemjs-named-register-plugin';
import { rpInlineEnum } from './rollup-plugins/inline-enum';

// import babel
import babel = Transformer.core;
Expand All @@ -28,7 +29,7 @@ import RollupBabelInputPluginOptions = Bundler.plugins.babel.RollupBabelInputPlu
import json = Bundler.plugins.json;
import resolve = Bundler.plugins.nodeResolve;
import commonjs = Bundler.plugins.commonjs;
import rpTerser = Bundler.plugins.terser.terser;
import rpTerser = Bundler.plugins.terser;
import rpVirtual = Bundler.plugins.virtual;
import { ModuleQuery } from '@ccbuild/modularize';
// import rpProgress = Bundler.plugins.progress;
Expand Down Expand Up @@ -241,6 +242,12 @@ export async function buildJsEngine(options: Required<buildEngine.Options>): Pro
));
}

const inlineEnumPlugins = await rpInlineEnum({
scanDir: ps.join(engineRoot, 'cocos'),
// exclude: ['*.jsb.ts'],
// scanPattern: '**/*.{cts,mts,ts,tsx}'
});

rollupPlugins.push(
externalWasmLoader({
externalRoot: ps.join(engineRoot, 'native/external'),
Expand Down Expand Up @@ -297,7 +304,13 @@ export async function buildJsEngine(options: Required<buildEngine.Options>): Pro
],
sourceMap: false,
}),
);

if (options.inlineEnum) {
rollupPlugins.push(...inlineEnumPlugins);
}

rollupPlugins.push(
rpBabel({
skipPreflightCheck: true,
...babelOptions,
Expand Down Expand Up @@ -325,10 +338,14 @@ export async function buildJsEngine(options: Required<buildEngine.Options>): Pro
unsafe_methods: true,
passes: 2, // first: remove deadcodes and const objects, second: drop variables
},
mangle: doUglify,
keep_fnames: !doUglify,
mangle: {
properties: {
regex: /^[a-zA-Z_][a-zA-Z0-9_]{3,}\$$/,
}
},
keep_fnames: false,
output: {
beautify: !doUglify,
beautify: false,
},

// https://github.com/rollup/rollup/issues/3315
Expand Down
Loading

0 comments on commit 6d7dbe1

Please sign in to comment.