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

Support inline enum and update rollup/terser version to latest. #65

Merged
merged 22 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
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
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 @@ -15,9 +15,9 @@
/// type definitions varies by versions
// import * as t from '@babel/types';
declare namespace t {
type Identifier = any;

Check warning on line 18 in modules/build-engine/src/engine-js/babel-plugins/decorator-parser.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
type Import = any;

Check warning on line 19 in modules/build-engine/src/engine-js/babel-plugins/decorator-parser.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
type StringLiteral = any;

Check warning on line 20 in modules/build-engine/src/engine-js/babel-plugins/decorator-parser.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
type SequenceExpression = any;
type ClassDeclaration = any;
type ObjectExpression = any;
Expand Down Expand Up @@ -344,7 +344,10 @@
}


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,}\$$/,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Support minify properties of which name ends with $

}
},
keep_fnames: false,
output: {
beautify: !doUglify,
beautify: false,
},

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