Skip to content

Add api.mainModules for package entry globs#14429

Open
lemontron wants to merge 1 commit into
meteor:develfrom
lemontron:package-support-main-modules
Open

Add api.mainModules for package entry globs#14429
lemontron wants to merge 1 commit into
meteor:develfrom
lemontron:package-support-main-modules

Conversation

@lemontron
Copy link
Copy Markdown

@lemontron lemontron commented May 24, 2026

I really need this!

I have been using @rollup/plugin-multi-entry and I would like to bring this feature to meteor in a very meteor way.

Summary

  • add api.mainModules(patterns, arch, options) for Meteor packages
  • synthesize a package main module that re-exports all matched source files
  • document the API and add modules app fixtures for legacy and modern test apps

Verification

  • git diff --check
  • /Users/james/code/meteor/meteor run --once --port 3101 in a focused throwaway app using api.mainModules('src/**/*.js')

Summary by CodeRabbit

  • New Features

    • Introduced api.mainModules() method for package authors to generate entry points from multiple source files using glob patterns, enabling cleaner modular package structures.
  • Documentation

    • Updated API documentation with new api.mainModules reference and usage examples.

Review Change Stack

@netlify
Copy link
Copy Markdown

netlify Bot commented May 24, 2026

Deploy Preview for v3-meteor-api-docs ready!

Name Link
🔨 Latest commit 7511ea2
🔍 Latest deploy log https://app.netlify.com/projects/v3-meteor-api-docs/deploys/6a12785228fc970008c570ae
😎 Deploy Preview https://deploy-preview-14429.docs-online.meteor.com
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 24, 2026

Deploy Preview for v3-migration-docs canceled.

Name Link
🔨 Latest commit 7511ea2
🔍 Latest deploy log https://app.netlify.com/projects/v3-migration-docs/deploys/6a12785252170c0008442f13

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 24, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 24, 2026

📝 Walkthrough

Walkthrough

This PR introduces api.mainModules(), a new Meteor package API that enables package authors to configure multiple source files as entry points via glob patterns. Instead of manually creating a re-exporting main module, authors can declare api.mainModules("src/**/*.js") and Meteor automatically generates the aggregating module.

Changes

api.mainModules Implementation

Layer / File(s) Summary
Package API contract: mainModules state and validation
tools/isobuild/package-api.js
Adds mainModules(paths, arch, fileOptions) method to PackageAPI. Per-architecture state includes new mainModules field (initially null). Calling mainModule() clears mainModules and vice versa to enforce mutual exclusion. Lazy-export validation treats lazy mainModules same as lazy main.
Compiler support for synthetic in-memory sources
tools/isobuild/compiler.js
Detects sources with in-memory data field and uses it directly instead of reading from disk. Hashes synthetic sources via watch.sha1(source.data). Synthetic sources skip watchSet registration; non-synthetic sources preserve existing watch behavior.
Package source: glob filtering and synthetic module injection
tools/isobuild/package-source.js
Reads mainModules from build result. Implements glob-to-regex matching to filter eligible source paths. Generates synthetic ES module that re-exports from matched files, then injects it as a synthetic source entry with matched file options.
User documentation and API references
docs/source/api/packagejs.md, docs/source/packages/modules.md, v3-docs/docs/api/package.md, v3-docs/docs/packages/modules.md
Updates cross-references to mention both api.mainModule and api.mainModules. Adds new subsections explaining that api.mainModules() accepts glob patterns, generates a re-exporting main module equivalent to manually re-exporting matched files.
Test package definitions using api.mainModules
tools/tests/apps/modules-modern/packages/main-modules-package/package.js, tools/tests/apps/modules/packages/main-modules-package/package.js
Two test packages declare api.mainModules("src/**/*.js") to expose all JavaScript source files as a single composite entry point. Both depend on ecmascript for module syntax.
Test package source modules with named exports
tools/tests/apps/modules-modern/packages/main-modules-package/src/{alpha,beta,nested/gamma}.js, tools/tests/apps/modules/packages/main-modules-package/src/{alpha,beta,nested/gamma}.js
Six source files total (three per test package environment) each exporting a named string constant. These files are glob-matched and re-exported by the synthetic main module.
Test cases verifying package exports
tools/tests/apps/modules-modern/tests.js, tools/tests/apps/modules/tests.js
Async tests load meteor/main-modules-package and verify the synthetic main module exposes alpha, beta, and gamma exports with expected string values. Tests run in both app environments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

Project:Docs

Suggested reviewers

  • fredmaiaarantes
  • italojs
  • henriquealbert
  • Grubba27
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add api.mainModules for package entry globs' is clear, specific, and directly describes the primary change: introducing a new API method for handling multiple package entry points via glob patterns.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nachocodoner nachocodoner added the Candidate 3.x.x Promising ideas or features that could fit in the 3.x direction, but not planned or committed yet label May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Candidate 3.x.x Promising ideas or features that could fit in the 3.x direction, but not planned or committed yet Project:Docs Project:Isobuild Project:Tool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants