Skip to content

fix: load ESM generators via dynamic import() + bump to generator ESM majors (APPBLD-4615) - #937

Merged
AnujVishwakarma-src merged 2 commits into
adobe:masterfrom
AnujVishwakarma-src:APPBLD-4615-plugin-app-generators-esm
Sep 24, 2026
Merged

AnujVishwakarma-src merged 2 commits into
adobe:masterfrom
AnujVishwakarma-src:APPBLD-4615-plugin-app-generators-esm

Conversation

@AnujVishwakarma-src

@AnujVishwakarma-src AnujVishwakarma-src commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

L4 — consume the ESM generator fleet (aio-cli-plugin-app stays CommonJS)

The generator packages are now ESM-only. This plugin is not converted to ESM — it loads them via dynamic import() instead of require():

  • src/commands/app/init.js (runCodeGenerators), add/ci.js, delete/ci.js: require('@adobe/generator-aio-app') / require('@adobe/generator-app-common-lib') → await import(...) inside the async methods (.default for generator-aio-app). Prevents ERR_REQUIRE_ESM.
  • Range bumps: generator-aio-app ^9→^10, generator-app-common-lib ^3→^4.
  • yeoman-environment is already loaded via dynamic import() (create-yeoman-environment.js); env.instantiate() runs the imported ESM generator classes unchanged.

Validation: the affected command suites (init / add-ci / delete-ci) pass 65/65 against a local link to the ESM generator-aio-app + published generator-app-common-lib@4.0.0. Lint clean.

NOTE: the tar CRITICAL (via yeoman-environment@4 → node-gyp@10 → tar@6.2.1) is intentionally not in this PR — it needs a yeoman-environment ^4→^6/7 API-major bump and will be a separate focused PR.


Pre-merge validation (2026-09-24)

Re-validated end-to-end on the PR branch with aio-cli 11.1.4 + this plugin-app branch linked (aio plugins link) + aio-cli-plugin-app-templates@2.1.4 linked, Node 26. Each of the 3 converted files is exercised through a real aio command (not just unit mocks).

Layer What Result
Unit full npm test (init / add-ci / delete-ci suites included) 853 tests pass, 100% coverage, eslint clean
Resolution generators in the plugin-app tree generator-aio-app 10.1.0, hub 4.1.0, both type: module (ESM)
Import path dynamic import() from plugin-app context both ESM packages load; no ERR_REQUIRE_ESM / no "constructor is not a constructor"
E2E — aio app init init.js runs generator-aio-app@10 application generator via import() ✔ full app scaffolded end-to-end
E2E — aio app add ci add/ci.js import(generator-aio-app@10) → add-ci ESM generator ✔ created deploy_prod / deploy_stage / pr_test workflows
E2E — aio app delete ci delete/ci.js import(@adobe/generator-app-common-lib) constants ✔ deleted CI files locally
E2E — aio app add extension (excshell) full add-extension flow incl. app-templates 2.1.4 ESM pin ✔ Finished running template @adobe/generator-app-excshell; only a post-step login gate (Missing orgId) after the code under test
tar scope yeoman-environment@4.4.3 → tar@6.2.1 still present correctly out of scope for this PR — owned by APPBLD-5140 (separate, next)

Note on login gates: aio app add action / add extension's org/project-config steps require a logged-in Adobe context; those gates trigger after the ESM-generator-load code under test, so they don't affect this validation.

AnujVishwakarma-src and others added 2 commits September 16, 2026 10:16
… majors (APPBLD-4615)

The generator packages are now ESM-only. aio-cli-plugin-app stays CommonJS but
must load them via dynamic import() instead of require():
- src/commands/app/init.js (runCodeGenerators), add/ci.js, delete/ci.js:
  require('@adobe/generator-aio-app') / require('@adobe/generator-app-common-lib')
  -> await import(...) inside the async methods (.default for generator-aio-app).
- Bumps generator-aio-app ^9 -> ^10 and generator-app-common-lib ^3 -> ^4.

yeoman-environment is already loaded via dynamic import() (create-yeoman-environment.js).
No ESM conversion of the plugin itself; env.instantiate() runs the imported ESM
generator classes unchanged. Affected command test suites pass (65/65).

Depends on @adobe/generator-aio-app@10 being published.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
generator-aio-app@10 is ESM-only; the top-level require() in the test threw
'Must use import to load ES Module' once 10.0.0 published. Load it via import()
in beforeAll, matching the command's runtime load.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AnujVishwakarma-src
AnujVishwakarma-src marked this pull request as ready for review September 16, 2026 06:04
@AnujVishwakarma-src

Copy link
Copy Markdown
Contributor Author

/upload-coverage

@github-actions

Copy link
Copy Markdown
Contributor

Coverage artifact not found. Re-run CI first, then comment /upload-coverage again.

@AnujVishwakarma-src

Copy link
Copy Markdown
Contributor Author

/upload-coverage

@AnujVishwakarma-src
AnujVishwakarma-src merged commit 8f021be into adobe:master Sep 24, 2026
11 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.

1 participant