Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compartment-mapper): expose extraParsers option #2190

Conversation

boneskull
Copy link
Collaborator

Description

The extraParsers option is an optional mapping of file extension (without leading .) to parser name. Consumers can use it to associate a file extension with a specific parser, e.g., {"node": "bytes"} or override the default mappings.

The specific use-case is enabling creation of compartment map descriptors for Node.js native modules (e.g., index.node) without needing a parsers: {node: 'bytes'} property in the package.json of the package containing the native module.

Because we are unlikely to be the maintainers of any given package exposing a native module, we do not have control over its package.json; to add the needed parsers field would require forking or using patch-package or something else. With this change, the consumer can add extraParsers: {node: 'bytes'} to any supported API call.

The API calls supporting the new option should be any that end up calling link() in link.js; this is where the mapping is concatenated with the default set of parsers.

Upgrade Considerations

This is a backwards-compatible change.

This change:

1. Creates a minimal interface for the `fs`, `url`, and `crypto` objects as passed into `makeReadPowers()`. This makes it easier to duck-type the objects.
2. Fixes the invalid type of `MaybeReadPowers`; properties (defined thru `@property`) are ignored in a `@typedef` of that `@typedef` does not extend `object`/`Object`.
3. Added necessary type assertion in `powers.js`
4. Adds return type to `makeReadPowersSloppy()`

# Conflicts:
#	packages/compartment-mapper/src/types.js
@boneskull
Copy link
Collaborator Author

boneskull commented Mar 28, 2024

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @boneskull and the rest of your teammates on Graphite Graphite

@kriskowal
Copy link
Member

I think my choice of "parsers" in package.json was a misnomer. I changed it to languageForExtension internally, but can’t bring myself to be that verbose in package.json. I could bring myself to be that verbose for the option, though. Would you consider fallbackLanguageForExtension? That’d clarify that it shouldn’t override a local choice.

This extracts a function, `loadCompartmentForArchive()`, from `digestLocation()` in `archive.js`, and exposes it.  This function returns archival-ready data structures, in addition to a record of the compartment renames which `makeArchiveCompartmentMap()` performs.

The intent is to leverage the module resolution performed by the function, which is reflected in its output.  A consumer can use the information therein to perform additional operations on the tree (e.g., parse ASTs).

# Conflicts:
#	packages/compartment-mapper/src/types.js
The `fallbackLanguageForExtension` option is an optional mapping of file extension to parser name.  Consumers can use it to associate a file extension with a specific parser, e.g., `{"node": "bytes"}` or override the default mappings.

The specific use-case is enabling creation of compartment map descriptors for Node.js native modules (e.g., `index.node`) _without_ needing a `parsers: {node: 'bytes'}` property in the `package.json` of the package containing the native module.
@boneskull boneskull force-pushed the boneskull/expose-extra-parsers branch from cd03184 to 41af691 Compare April 1, 2024 19:51
@boneskull boneskull force-pushed the boneskull/load-compartment-for-archive branch from 7dfbd98 to 7834bec Compare April 1, 2024 19:51
@boneskull boneskull force-pushed the boneskull/load-compartment-for-archive branch from 7834bec to fa8c103 Compare June 3, 2024 23:12
@boneskull boneskull closed this Jun 7, 2024
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.

None yet

2 participants