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

support .ts in bundle-source #2415

Closed
turadg opened this issue Aug 17, 2024 · 3 comments
Closed

support .ts in bundle-source #2415

turadg opened this issue Aug 17, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@turadg
Copy link
Member

turadg commented Aug 17, 2024

What is the Problem Being Solved?

TypeScript is very popular and the JsDoc syntax for it has many limitations compared to .ts. (Some described in Agoric/agoric-sdk#5760)

A developer who wants to write in .ts can transpile before bundling with Endo, but that increases work, room for error, and the transformation chain to audit.

Description of the Design

bundle-source would bundle .ts files directly by transparently transforming them to .js using something like https://bloomberg.github.io/ts-blank-space/ or @swc/wasm-typescript used in Node's new .ts support.

Security Considerations

Transforming code can make it harder to audit the bundled code. But conversely, type annotations can mislead in an audit.

Given the complexities of audits and the trade-offs with runtime constraints, solving auditing will require purpose-built tooling: #1656

Scaling Considerations

Test Plan

Compatibility Considerations

Upgrade Considerations

@turadg turadg added the enhancement New feature or request label Aug 17, 2024
@mhofman
Copy link
Contributor

mhofman commented Aug 19, 2024

Striping TS types and purely replacing with whitespace may cause semantic JS difference, and some cases need special handling. Any mechanism that support TS in bundle source need to correctly handle these cases and not change the runtime semantics.

Some pointers:

@kungfooman
Copy link

Pure ESM has so many advantages... just being able to do <script type="module" src="..."></script> with an import map... TS destroys nice ESM and also makes code unreadable. Simple one liner JS functions that are easy to document with JSDoc become type monsters where you can't even differ between real code and type sugar any longer without starring at ASCII soup for 5 minutes.

For what? The beginning of the end.

@turadg
Copy link
Member Author

turadg commented Sep 27, 2024

@kriskowal kriskowal self-assigned this Nov 7, 2024
kriskowal added a commit that referenced this issue Nov 12, 2024
…ension options (for TS) (#2625)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants