fix(plugin): declare esbuild so plugin install can compile TypeScript#2014
Open
truffle-dev wants to merge 1 commit into
Open
fix(plugin): declare esbuild so plugin install can compile TypeScript#2014truffle-dev wants to merge 1 commit into
truffle-dev wants to merge 1 commit into
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
opencli plugin createscaffolds a TypeScript plugin. Installing it withopencli plugin install file://<dir>runstranspilePluginTs(src/plugin.ts) to compile the source to.jsviaresolveEsbuildBin. That resolver only finds esbuild when it happens to be present — and in this repo esbuild is a purely transitive devDependency (it's in neitherdependenciesnordevDependencies;package-lock.jsonflags 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.jsis produced, anddiscoverPluginDir(src/discovery.ts) aborts withno compiled .js found— breaking the documentedcreate→installflow.This declares esbuild as an
optionalDependencyso it installs alongside the CLI on supported platforms, while preserving the existing graceful degradation inresolveEsbuildBin/transpilePluginTsfor platforms where the optional binary can't be installed.optionalDependenciesis 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
dependenciesentry instead;optionalDependenciesis the lighter promise that matches the code's already-graceful behaviour when esbuild is absent.Related issue: Closes #1959
Type of Change
Checklist
Screenshots / Output
Added a regression test next to the existing
resolveEsbuildBintest. 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):Green with this change:
npx tsc --noEmitexits 0.package.jsonandpackage-lock.jsonstay in sync (regenerated withnpm install --package-lock-only), sonpm ciis unaffected.