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): Thread commonjs- and module- languageForExtension options (for TS) #2625

Merged

Conversation

kriskowal
Copy link
Member

Refs: #2415

Description

Toward support for type-erasure style TypeScript support in Endo, .ts files may correspond to .mts or .cts behavior in the same way that .js can correspond to either .mjs or .cjs, depending on "type": in the enveloping package.json (which is not necessarily the enveloping package, e.g., src/package.json beneath package.json!). We already implement this machinery for JavaScript, so this change threads additional options beside languageForExtension (which would map .mts and .cts to language behaviors) but also commonjsLanguageForExtension and moduleLanguageForExtension, which would get folded into the language-for-extension mapping on a package-by-package basis.

Security Considerations

None. Absent from this design is any possibility that a file would be alternately implemented as TypeScript or JavaScript.

Scaling Considerations

None.

Documentation Considerations

Includes an update to README for the new features and the undocumented features it is based upon. Includes a mention in NEWS.

Testing Considerations

TODO

Compatibility Considerations

By design error, languageForExtension threaded through link before this change, when it should have been threaded through mapNodeModules, since that is the machine that is aware of the type field in package.json. This change moves that internal mechanism and then adds commonjsLanguageForExtension and moduleLanguageForExtension. By common usage, this move is transparent since the option is taken at the top and simply diverted internally.

However, the languageForExtension property could be manually threaded through makeArchiveLite and omitted from the options for mapNodeModules. I’ve elected to treat this breaking change as a bug fix since I find it unlikely anyone has taken advantage of these relatively new “lite” functions. The “lite” functions are part of the refactoring necessary to approach native XS compartment and modules.

Upgrade Considerations

None.

@kriskowal kriskowal changed the title Kriskowal compartment mapper module vs commonjs options feat(compartment-mapper): Thread commonjs- and module- languageForExtension options (for TS) Nov 7, 2024
@kriskowal kriskowal force-pushed the kriskowal-compartment-mapper-d-ts branch from 071e61e to 6d146a4 Compare November 7, 2024 20:57
@kriskowal kriskowal force-pushed the kriskowal-compartment-mapper-module-vs-commonjs-options branch from caffdaa to 0a25959 Compare November 7, 2024 20:57
@kriskowal kriskowal force-pushed the kriskowal-compartment-mapper-d-ts branch from 6d146a4 to 905d9da Compare November 8, 2024 01:02
@kriskowal kriskowal force-pushed the kriskowal-compartment-mapper-module-vs-commonjs-options branch from 0a25959 to 42b8b18 Compare November 8, 2024 01:02
@kriskowal kriskowal marked this pull request as ready for review November 8, 2024 01:02
errorTrapping: 'none',
});

scaffold(
Copy link
Member Author

Choose a reason for hiding this comment

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

For reviewers new to Compartment Mapper, scaffold generates a combination of test cases where a single fixture is expected to produce the same behavior for multiple flows:

  • executed directly off a file system
  • loaded off the file system then later executed
  • archived off the file system, then parsed, then executed
    &c

@kriskowal kriskowal requested a review from turadg November 8, 2024 01:10
Base automatically changed from kriskowal-compartment-mapper-d-ts to master November 8, 2024 01:15
@kriskowal kriskowal force-pushed the kriskowal-compartment-mapper-module-vs-commonjs-options branch 5 times, most recently from f77329b to d6ce6de Compare November 9, 2024 00:17
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

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

LGTM!

I'm new to this package so I don't have an opinion on the design decisions. The code changes all look good.

mjs: 'mjs',
cjs: 'cjs',
Copy link
Member

Choose a reason for hiding this comment

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

consider alphabetizing or leaving where it was

);
}
const invalidLanguages = values(packageLanguageForExtension).filter(
language => !languages.has(language),
Copy link
Member

Choose a reason for hiding this comment

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

language and languages look very similar. consider,

Suggested change
language => !languages.has(language),
l => !languages.has(l),

@kriskowal kriskowal force-pushed the kriskowal-compartment-mapper-module-vs-commonjs-options branch 6 times, most recently from 60b295c to 300f46c Compare November 12, 2024 00:40
@kriskowal kriskowal force-pushed the kriskowal-compartment-mapper-module-vs-commonjs-options branch from 300f46c to 389de7b Compare November 12, 2024 00:49
@kriskowal kriskowal enabled auto-merge November 12, 2024 00:50
@kriskowal kriskowal merged commit 110ab7c into master Nov 12, 2024
15 checks passed
@kriskowal kriskowal deleted the kriskowal-compartment-mapper-module-vs-commonjs-options branch November 12, 2024 01:01
kriskowal added a commit that referenced this pull request Nov 12, 2024
Closes: #2415 

## Description

This change introduces support for TypeScript through type-erasure,
using ts-blank-space, which converts type annotations to equivalent
blank space. As is consistent with `node --experimental-strip-types`,
this only applies to modules with the `.ts`, `.mts`, or `.cts`
extensions in packages that are not under `node_modules`, to discourage
publishing TypeScript as a source language to npm.

### Security Considerations

The choice of `ts-blank-space` is intended to minimize runtime behavior
difference between TypeScript and JavaScript, such that a reviewer or a
debugger of the generated JavaScript aligns with the expected behavior
and original text, to the extent that is possible. This should compose
well with #2444.

### Scaling Considerations

None.

### Documentation Considerations

Contains README and NEWS.

### Testing Considerations

Contains spot check tests for TypeScript in the endoScript and
endoZipBase64 formats. We stand on much more rigorous testing of the
underlying workspace-language-for-extension feature in Compartment
Mapper #2625.

### Compatibility Considerations

This does not break any prior usage.

### Upgrade Considerations

None.
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.

2 participants