Skip to content

fix(#2736): canonicalize PURE annotations in dist-es5 (module) output#2744

Merged
hectorhdzg merged 2 commits into
microsoft:mainfrom
hectorhdzg:fix/2736-pure-annotations-dist-es5
Jun 18, 2026
Merged

fix(#2736): canonicalize PURE annotations in dist-es5 (module) output#2744
hectorhdzg merged 2 commits into
microsoft:mainfrom
hectorhdzg:fix/2736-pure-annotations-dist-es5

Conversation

@hectorhdzg

@hectorhdzg hectorhdzg commented Jun 18, 2026

Copy link
Copy Markdown
Member

Modern bundlers (Rolldown / Vite 8) prefer the package "module" entry, which resolves to the per-module dist-es5 tsc output. TypeScript emits parenthesized PURE annotations with whitespace after the opening paren (e.g. ( /*#__PURE__*/"http.")), which Rolldown rejects with [INVALID_ANNOTATION]. The existing rollup fixPureAnnotations() pass only covers the bundled dist/es5 ("main") output, so the ESM consumer path stayed broken (#2737 only fixed the bundle).

Changes:

  • Add shared tools/pureAnnotations.js (single source of truth for the canonicalization regex), reused by both rollup.base.config.js and the new grunt task.
  • Add "fix-pure" grunt multitask that canonicalizes dist-es5/**/*.js after the tsc compile; wired into the shared tsBuildActions pipeline for all packages.
  • Extract shared getDistPackageRoots() in gruntfile.js (reused by validate-es5 and fix-pure).
  • Keep the wrapping parens (required for older Rollup/Webpack/Terser to tree-shake the constants), per maintainer guidance.
  • Extend AISKU/AppInsightsCore size tests to assert canonical PURE form in the dist-es5 module output.

Fixes #2736

…e) output

Modern bundlers (Rolldown / Vite 8) prefer the package "module" entry,
which resolves to the per-module dist-es5 tsc output. TypeScript emits
parenthesized PURE annotations with whitespace after the opening paren
(e.g. `( /*#__PURE__*/"http.")`), which Rolldown rejects with
[INVALID_ANNOTATION]. The existing rollup fixPureAnnotations() pass only
covers the bundled dist/es5 ("main") output, so the ESM consumer path
stayed broken (microsoft#2737 only fixed the bundle).

Changes:
- Add shared tools/pureAnnotations.js (single source of truth for the
  canonicalization regex), reused by both rollup.base.config.js and the
  new grunt task.
- Add "fix-pure" grunt multitask that canonicalizes dist-es5/**/*.js after
  the tsc compile; wired into the shared tsBuildActions pipeline for all
  packages.
- Extract shared getDistPackageRoots() in gruntfile.js (reused by
  validate-es5 and fix-pure).
- Keep the wrapping parens (required for older Rollup/Webpack/Terser to
  tree-shake the constants), per maintainer guidance.
- Extend AISKU/AppInsightsCore size tests to assert canonical PURE form in
  the dist-es5 module output.
- Document the fix in RELEASES.md (3.4.2).
@hectorhdzg hectorhdzg requested a review from a team as a code owner June 18, 2026 22:32
Copilot AI review requested due to automatic review settings June 18, 2026 22:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes ESM consumer builds by canonicalizing parenthesized PURE annotations in the per-module dist-es5 TypeScript output (the module entry), aligning it with the existing rollup-bundle normalization done for dist/es5 (the main entry) to avoid Rolldown/Vite 8 [INVALID_ANNOTATION] warnings.

Changes:

  • Introduces a shared PURE-annotation canonicalization helper (tools/pureAnnotations.js) and reuses it in both rollup and a new grunt post-process step.
  • Adds a new fix-pure grunt multitask and wires it into the shared tsBuildActions() pipeline to rewrite dist-es5/**/*.js after compile.
  • Extends AISKU and AppInsightsCore size tests to assert non-canonical PURE spacing is not present in dist-es5 module outputs.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/pureAnnotations.js Adds shared regex + helper to canonicalize spaced PURE annotations to the flush form.
tools/grunt-tasks/fixPureAnnotations.js New grunt multitask (fix-pure) to rewrite emitted dist-es5 JS files after tsc compile.
rollup.base.config.js Reuses shared canonicalization helper inside fixPureAnnotations() renderChunk step.
gruntfile.js Adds fix-pure config + integrates the task into tsBuildActions(); extracts shared package-root mapping.
shared/AppInsightsCore/Tests/Unit/src/ai/AppInsightsCoreSize.Tests.ts Adds a dist-es5 PURE-annotation validation fetch/test alongside existing dist validation.
AISKU/Tests/Unit/src/AISKUSize.Tests.ts Adds a dist-es5 PURE-annotation validation fetch/test alongside existing dist validation.
RELEASES.md Documents the Rolldown/Vite 8 PURE annotation fix and references #2736.

Comment thread tools/pureAnnotations.js Outdated
Comment thread tools/grunt-tasks/fixPureAnnotations.js
…resolves it

rollup's --bundleConfigAsCjs writes the bundled config into the subpackage dir and does not run the commonjs plugin, so a relative require()/CJS import of the shared helper failed to resolve. Convert the shared helper to an ES module and import it directly in rollup.base.config.js (rollup inlines it); the CommonJS grunt task now loads it via async dynamic import().
@hectorhdzg hectorhdzg merged commit bebed79 into microsoft:main Jun 18, 2026
9 checks passed
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.

[Bug] Vite 8 / Rolldown build warnings: INVALID_ANNOTATION for misplaced /#PURE/ comments

4 participants