Skip to content

[fix] Restore plugin script global aliases - #892

Open
sekiroxxxx wants to merge 1 commit into
cocos:mainfrom
sekiroxxxx:fix/plugin-script-globals-compat
Open

[fix] Restore plugin script global aliases#892
sekiroxxxx wants to merge 1 commit into
cocos:mainfrom
sekiroxxxx:fix/plugin-script-globals-compat

Conversation

@sekiroxxxx

Copy link
Copy Markdown
Contributor

Background

Older PinK versions persisted simulateGlobals: true when users cleared the
plugin script “Simulate Globals” field. That metadata remains in existing
projects. cocos-cli later treats the value as an alias array during plugin
script import, causing the reimport to fail.

Custom aliases also replaced the default self, window, global, and
globalThis aliases instead of extending them.

Root cause

The JavaScript importer only supplied default aliases when simulateGlobals
was undefined. It neither normalized persisted values at the importer
boundary nor merged valid custom aliases with the default aliases.

Changes

  • Resolve plugin script global aliases in one importer utility.
  • Treat legacy boolean and other non-array values as no custom aliases.
  • Merge default aliases with custom aliases and remove duplicates.
  • Bump the importer version so existing plugin scripts are reimported.
  • Add focused coverage for missing values, custom aliases, legacy booleans,
    and duplicate aliases.

Impact

This only changes alias resolution for enclosed plugin scripts:

  • Legacy invalid metadata can be imported again.
  • Custom aliases no longer replace default aliases.
  • Global execution scope, module isolation, and platform load flags are unchanged.

Test plan

  1. Reimport a plugin script with legacy simulateGlobals: true; the import
    should succeed with the default aliases.
  2. Configure one custom alias and run the plugin script; both the default and
    custom aliases should be available.
  3. Configure duplicate default or custom aliases; the generated alias list
    should contain each alias once.

Verification

  • Focused Jest coverage passes with four alias-resolution cases.
  • ESLint and git diff --check pass.
  • The full TypeScript check is blocked because the clean worktree lacks the
    generated src/i18n/types/generated directory, which is unrelated to this
    change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant