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

Migrate from TSDX to publishing untranspiled .ts source files #587

Merged
merged 18 commits into from
Oct 13, 2024

Conversation

karlhorky
Copy link
Member

@karlhorky karlhorky commented Oct 13, 2024

Closes #126

Switch from the unmaintained TSDX to publishing untranspiled .ts source files, to:

  1. Remove outdated and insecure dependencies
  2. Reduce total number of dependencies
  3. Reduce build / publishing infrastructure

(Unconventional) method: Use shebang with pnpm exec tsx to execute TypeScript on the consumer machine:

#!/usr/bin/env -S pnpm exec tsx

const a: number = 1;
console.log(a);

The pnpm shim (@zkochan/cmd-shim) also uses the correct binary (bun) because of shebang parsing, eg. for bun-pr:

cat /Users/k/Library/pnpm/bun-pr
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -z "$NODE_PATH" ]; then
  export NODE_PATH="/Users/k/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/bun-pr/node_modules:/Users/k/Library/pnpm/global/5/.pnpm/[email protected]/node_modules:/Users/k/Library/pnpm/global/5/.pnpm/node_modules"
else
  export NODE_PATH="/Users/k/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/bun-pr/node_modules:/Users/k/Library/pnpm/global/5/.pnpm/[email protected]/node_modules:/Users/k/Library/pnpm/global/5/.pnpm/node_modules:$NODE_PATH"
fi
if [ -x "$basedir/bun" ]; then
  exec "$basedir/bun"  "$basedir/global/5/node_modules/bun-pr/bun-pr.ts" "$@"
else
  exec bun  "$basedir/global/5/node_modules/bun-pr/bun-pr.ts" "$@"
fi

@zkochan/cmd-shim will also generate correct commands for exec -S ... commands:

TODO:

  • Switch bin/preflight.js to bin/preflight.ts
  • Switch node shebang to pnpx tsx shebang
  • Fix path
  • Install current Preflight globally before testing
  • Remove tsdx dependencies
  • Simplify TypeScript configuration
    • Single tsconfig.json in root
  • Publish prerelease version
  • Test
  • Remove TS compilation from Docker container
  • Upgrade Docker container to Node.js v22
  • Use node --experimental-type-stripping in Docker container
  • Build Docker container
  • Test Docker container

Prior Art

This is not the most common, widespread pattern for publishing TypeScript, but there are some examples of prior art for this:

  1. bun-pr
  2. Maki

Alternatives Considered

  1. Use shebang with Node.js --experimental-strip-types flag

    #!/usr/bin/env -S node --experimental-strip-types
    
    const a: number = 1;
    console.log(a);

    Downside: Currently Node.js cannot strip types in node_modules

  2. Use shebang with Bun

    #!/usr/bin/env bun
    
    const a: number = 1;
    console.log(a);

    Downside: Currently Bun is not installed on student computers, potential Bun incompatibilities

Copy link

codesandbox-ci bot commented Oct 13, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

socket-security bot commented Oct 13, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] environment Transitive: eval, filesystem, shell, unsafe +347 47.7 MB karlhorky
npm/[email protected] Transitive: filesystem +3 680 kB hirokiosame

🚮 Removed packages: npm/[email protected]

View full report↗︎

Copy link

github-actions bot commented Oct 13, 2024

size-limit report 📦

Path Size
dist/preflight.esm.js 6.39 KB (-0.17% 🔽)

@karlhorky
Copy link
Member Author

karlhorky commented Oct 13, 2024

Nice, the 0a1b8cde0bb20fcb8d5ae80f1f274ecee7931f6c version published by CodeSandbox CI works - executing published, untranspiled .ts files 🚀

➜  preflight git:(remove-tsdx) pnpm add --global https://pkg.csb.dev/upleveled/preflight/commit/0a1b8cde/@upleveled/preflight
 WARN  6 deprecated subdependencies found: @oclif/[email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Packages: +144
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 825, reused 801, downloaded 1, added 1, done

/Users/k/Library/pnpm/global/5:
+ @upleveled/preflight 7.0.9

Done in 2.5s
➜  preflight git:(remove-tsdx) preflight
🚀 UpLeveled Preflight v7.0.9
✔ All changes committed to Git
✔ node_modules/ folder ignored in Git
✔ No extraneous files committed to Git
✔ No secrets committed to Git
✔ Use single package manager
✔ Project folder name matches correct format
⚠ No dependency problems
  ✖ No unused dependencies
    › Unused dependencies found:
      * depcheck
      * @size-limit/file
      * postinstall-postinstall
      * tslib

      Remove these dependencies by running the following command for each dependency:

      $ pnpm remove <dependency name here>

  ✔ No dependencies without types
✔ GitHub repo has deployed project link under About
✖ ESLint
  › ESLint problems found in the following files:
    bin/preflight.ts

    Open these files in your editor - there should be problems to fix

✔ Prettier
✖ ESLint config is latest version
  › Your current version of the UpLeveled ESLint Config (8.7.3) is older than the latest version 8.7.4 - upgrade by running all lines of the install instructions on
    https://www.npmjs.com/package/eslint-config-upleveled

✔ Preflight is latest version

@karlhorky karlhorky changed the title Migrate from tsdx to publishing untranspiled .ts source files Migrate from TSDX to publishing untranspiled .ts source files Oct 13, 2024
@karlhorky karlhorky merged commit cd2105f into main Oct 13, 2024
7 checks passed
@karlhorky karlhorky deleted the remove-tsdx branch October 13, 2024 21:56
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.

Migrate off tsdx
1 participant