From b62659b7da0aedb0fe1558c65be148b6e6d570e0 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 17 Oct 2024 23:16:12 +0800 Subject: [PATCH] Fix transform id while checking moduleOverrides. Update version to 2.2.16 (#69) --- modules/build-engine/src/engine-js/index.ts | 15 ++++++++----- .../rollup-plugins/inline-enum/index.ts | 5 ++++- modules/utils/src/path.ts | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- .../__snapshots__/engine-js.test.ts.snap | 22 +++++++++++++++++++ test/test-engine-source/cc.config.json | 14 +++++++++--- .../cocos/enums/TestOverride.jsb.ts | 17 ++++++++++++++ .../cocos/enums/TestOverride.ts | 14 ++++++++++++ test/test-engine-source/cocos/enums/index.ts | 1 + .../cocos/enums/test-override-entry.jsb.ts | 4 ++++ .../cocos/enums/test-override-entry.ts | 8 +++++++ 12 files changed, 98 insertions(+), 12 deletions(-) create mode 100644 test/test-engine-source/cocos/enums/TestOverride.jsb.ts create mode 100644 test/test-engine-source/cocos/enums/TestOverride.ts create mode 100644 test/test-engine-source/cocos/enums/test-override-entry.jsb.ts create mode 100644 test/test-engine-source/cocos/enums/test-override-entry.ts diff --git a/modules/build-engine/src/engine-js/index.ts b/modules/build-engine/src/engine-js/index.ts index ba56c55d..5af8a7ea 100644 --- a/modules/build-engine/src/engine-js/index.ts +++ b/modules/build-engine/src/engine-js/index.ts @@ -2,6 +2,7 @@ import fs from 'fs-extra'; import ps from 'path'; import { babel as Transformer } from '@ccbuild/transformer'; import { rollup as Bundler } from '@ccbuild/bundler'; +import { ps as pathUtils } from '@ccbuild/utils'; import realFs from 'fs'; import tsConfigPaths from './rollup-plugins/ts-paths'; import moduleQueryPlugin from './rollup-plugins/module-query-plugin'; @@ -49,9 +50,6 @@ const realPath = (function (): (file: string) => Promise { }); })(); -function makePathEqualityKey(path: string): string { - return process.platform === 'win32' ? path.toLocaleLowerCase() : path; -} export async function buildJsEngine(options: Required): Promise { const doUglify = !!options.compress; @@ -116,7 +114,7 @@ export async function buildJsEngine(options: Required): Pro platform: options.platform, buildTimeConstants, })).reduce((result, [k, v]) => { - result[makePathEqualityKey(k)] = v; + result[pathUtils.makePathEqualityKey(k)] = v; return result; }, {} as Record); @@ -269,7 +267,7 @@ export async function buildJsEngine(options: Required): Pro } }, load(this, id: string): string | null { - const key = makePathEqualityKey(id); + const key = pathUtils.makePathEqualityKey(id); if (!(key in moduleOverrides)) { return null; } @@ -406,6 +404,13 @@ export async function buildJsEngine(options: Required): Pro const treeshakeConfig = statsQuery.getTreeShakeConfig(); const noSideEffectFiles = treeshakeConfig?.noSideEffectFiles; if (noSideEffectFiles && noSideEffectFiles.length > 0) { + for (const noSideEffectFile of noSideEffectFiles) { + const absolutePath = ps.join(engineRoot, noSideEffectFile); + if (!fs.pathExistsSync(absolutePath)) { + console.error(`>>> ERROR: noSideEffectFile: ( ${noSideEffectFile} ) doesn't exist!`); + } + } + rollupOptions.treeshake = { moduleSideEffects: (id: string): boolean => { const relativePath = formatPath(ps.relative(engineRoot, id)); diff --git a/modules/build-engine/src/engine-js/rollup-plugins/inline-enum/index.ts b/modules/build-engine/src/engine-js/rollup-plugins/inline-enum/index.ts index d4fb88a6..4b10e933 100644 --- a/modules/build-engine/src/engine-js/rollup-plugins/inline-enum/index.ts +++ b/modules/build-engine/src/engine-js/rollup-plugins/inline-enum/index.ts @@ -6,6 +6,7 @@ import ReplacePlugin from '@rollup/plugin-replace'; import { type Options, resolveOptions } from './core/options'; import { IDefines, scanEnums } from './core/enum'; import { rollup as Bundler } from '@ccbuild/bundler'; +import { ps as pathUtils } from '@ccbuild/utils'; import rollup = Bundler.core; @@ -55,6 +56,7 @@ export async function rpInlineEnum(rawOptions: Options, meta?: any): Promise