Skip to content

fix(plugin): declare esbuild so plugin install can compile TypeScript#2014

Open
truffle-dev wants to merge 1 commit into
jackwener:mainfrom
truffle-dev:fix/opencli-declare-esbuild-for-plugin-transpile
Open

fix(plugin): declare esbuild so plugin install can compile TypeScript#2014
truffle-dev wants to merge 1 commit into
jackwener:mainfrom
truffle-dev:fix/opencli-declare-esbuild-for-plugin-transpile

Conversation

@truffle-dev

Copy link
Copy Markdown
Contributor

Description

opencli plugin create scaffolds a TypeScript plugin. Installing it with opencli plugin install file://<dir> runs transpilePluginTs (src/plugin.ts) to compile the source to .js via resolveEsbuildBin. That resolver only finds esbuild when it happens to be present — and in this repo esbuild is a purely transitive devDependency (it's in neither dependencies nor devDependencies; package-lock.json flags it "dev": true). So a production install (npm i -g @jackwener/opencli) ships no esbuild at all. The transpile then no-ops with a warning, no .js is produced, and discoverPluginDir (src/discovery.ts) aborts with no compiled .js found — breaking the documented createinstall flow.

This declares esbuild as an optionalDependency so it installs alongside the CLI on supported platforms, while preserving the existing graceful degradation in resolveEsbuildBin / transpilePluginTs for platforms where the optional binary can't be installed. optionalDependencies is the idiomatic fit here (it mirrors how esbuild itself ships its platform binaries) and keeps the lean production-dependency footprint — esbuild is installed by default but never hard-fails the install.

Tradeoff for your call: if you'd rather guarantee the transpiler is always present, this could be a hard dependencies entry instead; optionalDependencies is the lighter promise that matches the code's already-graceful behaviour when esbuild is absent.

Related issue: Closes #1959

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🌐 New site adapter
  • 📝 Documentation
  • ♻️ Refactor
  • 🔧 CI / build / tooling

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Screenshots / Output

Added a regression test next to the existing resolveEsbuildBin test. The existing test passes today only because esbuild is present transitively in dev, which masks the production gap; the new test asserts esbuild is a declared production-installable dependency.

Red on main (no declaration):

 FAIL  src/plugin.test.ts > resolveEsbuildBin > declares esbuild as a production-installable dependency
   expect(declared).toBe(true)  ->  received false

Green with this change:

 Test Files  1 passed (1)
      Tests  73 passed (73)

npx tsc --noEmit exits 0. package.json and package-lock.json stay in sync (regenerated with npm install --package-lock-only), so npm ci is unaffected.

`opencli plugin create` scaffolds a TypeScript plugin, and installing it
(`opencli plugin install file://...`) runs transpilePluginTs to compile
the source to .js. That step calls resolveEsbuildBin, which finds esbuild
only when it happens to be present — in this repo esbuild is a purely
transitive devDependency, so a production install (`npm i -g
@jackwener/opencli`) ships no esbuild at all. The transpile then no-ops
with a warning, no .js is produced, and discoverPluginDir aborts with
"no compiled .js found", breaking the documented create→install flow.

Declare esbuild as an optionalDependency so it installs alongside the CLI
on supported platforms, while keeping the existing graceful degradation
in resolveEsbuildBin/transpilePluginTs for platforms where the optional
binary can't be installed. Add a regression test asserting esbuild is
declared in dependencies or optionalDependencies — the existing
resolveEsbuildBin test passes today only because esbuild is present
transitively in dev, which masks the production gap.

Closes jackwener#1959
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.

[Bug]: no compiled .js found.

1 participant