Skip to content

Conversation

@mcmire
Copy link
Contributor

@mcmire mcmire commented Sep 5, 2025

Explanation

tsx has a couple of advantages over ts-node:

  • Running a script with tsx is about 20% faster than with ts-node.
  • tsx is also easier to use. I've run into problems in the past where ts-node doesn't seem to honor the TypeScript config like tsc does, but tsx "just works".

References

(N/A)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

Note

Switches TypeScript script runner from ts-node to tsx and updates scripts, shebangs, and dependencies accordingly.

  • Tooling:
    • Replace ts-node with tsx across script runners in package.json (create-package, generate-method-action-types, lint:eslint, lint:teams, update-readme-content).
    • Update shebangs in scripts/generate-method-action-types.ts, scripts/generate-preview-build-message.ts, and scripts/update-readme-content.ts to #!yarn tsx.
    • Swap devDependency ts-nodetsx; update lavamoat.allowScripts to include tsx>esbuild.
    • Refresh yarn.lock: remove ts-node (and related packages) and add tsx with esbuild platform binaries and related entries.

Written by Cursor Bugbot for commit 2076008. This will update automatically on new commits. Configure here.

`tsx` has a couple of advantages over `ts-node`:

- Running a script with `tsx` is about 20% faster than with `ts-node`.
- `tsx` is also easier to use. I've had problems where `ts-node` doesn't
  seem to honor the TypeScript config like `tsc` does, but `tsx` "just
  works".
@socket-security
Copy link

socket-security bot commented Sep 5, 2025

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring alerts on:

View full report

@mcmire
Copy link
Contributor Author

mcmire commented Sep 5, 2025

@SocketSecurity ignore npm/[email protected]

We have disabled the postinstall script for esbuild via LavaMoat.

@mcmire
Copy link
Contributor Author

mcmire commented Sep 5, 2025

@SocketSecurity ignore npm/[email protected]

I reviewed this and I don't think this is an issue. I believe tsx forks itself and it communicates with its parent process as it's running (or something).

@mcmire mcmire marked this pull request as ready for review September 5, 2025 17:57
@mcmire mcmire enabled auto-merge (squash) October 14, 2025 19:10
@mcmire mcmire merged commit 82101f9 into main Oct 14, 2025
243 checks passed
@mcmire mcmire deleted the replace-ts-node-with-tsx branch October 14, 2025 19:16
cryptodev-2s added a commit that referenced this pull request Oct 17, 2025
## Explanation

### What is the current state of things and why does it need to change?

The `publish-preview.yml` GitHub Actions workflow is still using
`ts-node` to execute the `generate-preview-build-message.ts` script.
However, the project has recently migrated from `ts-node` to `tsx`
[PR](#6481)

## References

- N/A

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
  - No test changes needed for this workflow update
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
  - No documentation changes needed
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
  - No changelog needed as this is an internal workflow change
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
  - No breaking changes - internal workflow update only

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> <sup>[Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) is
generating a summary for commit
8aea010. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
georgewrmarshall added a commit to MetaMask/metamask-design-system that referenced this pull request Oct 22, 2025
)

## **Description**

This change mirrors the successful optimization implemented in
[MetaMask/core#6481](https://github.com/MetaMask/core/pull/6481/files)
and provides significant performance improvements for TypeScript script
execution in large monorepos.

## **Related issues**

Fixes: N/A

## **Manual testing steps**

- [x] Run `yarn lint` and verify it completes successfully without
hanging
- [x] Run `yarn lint:eslint` individually to confirm ESLint processing
works
- [x] Test `yarn create-component:react` to ensure component generation
still works
- [x] Test `yarn update-readme-content` to verify documentation scripts
work
- [x] Verify all other scripts using TypeScript execution continue to
function

## **Screenshots/Recordings**

Not applicable - this is a build/tooling performance optimization
without visual changes.

## **Pre-merge author checklist**

- [x] I have reviewed the Files changed tab
- [x] All CI checks pass (yarn lint now works without hanging)
- [x] The same scripts work in all workspace packages
- [x] All TypeScript script executions use the faster `tsx` instead of
`ts-node`
- [x] LavaMoat configuration updated to allow `tsx>esbuild` instead of
`ts-node>@swc/core`
- [x] Dependency configuration updated in depcheck to ignore `tsx`
instead of `ts-node`
- [x] Script shebang lines updated in all affected files
- [x] I have tested this PR on my local machine

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

## **Technical Details**

**Files Changed:**
- **Root package.json**: Updated 3 scripts (`create-package`,
`lint:eslint`, `update-readme-content`)
- **Dependency updates**: Replaced `ts-node` with `tsx` in
devDependencies
- **LavaMoat config**: Updated to allow `tsx>esbuild` instead of
`ts-node>@swc/core`
- **Package scripts**: Updated React and React Native packages to use
`tsx`
- **Build scripts**: Updated shebang lines and direct script calls
- **Depcheck config**: Updated to ignore `tsx` instead of `ts-node`

**Performance Impact:**
- **Before**: `yarn lint` would hang indefinitely
- **After**: `yarn lint` completes successfully in reasonable time
- **Benefit**: Enables faster development cycles and unblocks CI/CD
pipelines

**References:**
- Inspired by MetaMask/core optimization:
https://github.com/MetaMask/core/pull/6481/files
- `tsx` documentation: https://github.com/esbuild-kit/tsx

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Replace ts-node with tsx for TypeScript scripts, updating scripts,
configs, shebangs, and dependencies.
> 
> - **Tooling**:
> - Migrate TypeScript script runner from `ts-node` to `tsx` across
repo.
> - Update script invocations in root `package.json` (`create-package`,
`lint:eslint`, `update-readme-content`).
> - Switch package scripts in `packages/design-system-react` and
`packages/design-system-react-native` (`create-component`,
`generate-icons`, `generate-icons:index`).
> - Update build step in
`packages/design-system-react-native/scripts/build.js` to call `tsx`.
> - Change shebangs in `scripts/generate-preview-build-message.ts` and
`scripts/update-readme-content.ts` to `#!yarn tsx`.
> - **Config**:
> - Update LavaMoat `allowScripts` from `ts-node>@swc/core` to
`tsx>esbuild`.
>   - Adjust `.depcheckrc.yml` ignores to `tsx`.
> - **Dependencies**:
> - Remove `ts-node`; add `tsx` and related `esbuild` entries; refresh
`yarn.lock`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
d403f8d. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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.

3 participants