Repository navigation
Report the package's own version and smoke-test the packed package - #107
Merged
Merged
Conversation
yargs' argument-less .version() guesses from the package.json above its own node_modules, so an installed md-code printed the consumer project's version or 'unknown'. Pass VERSION explicitly. Add scripts/smoke-test-package.mjs (npm run test:package), which packs, installs into a temp project, and checks the bins, sync/check, the library import, and the tarball contents; run it in CI.
Use node with npm_execpath so Windows paths with spaces work without shell quoting, and stop with a hint when not run through npm or when dist/ is missing.
Owner
Author
Second-pass reviewRoot cause confirmed. yargs 18's ESM shim sets
Fixed in c2fa887
Noted, not changed
CI green on Node 22 and 24, including the new smoke step. |
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.
Summary
md-code --versionprints the wrong version when markdown-code is installed as a project dependency or run throughnpx, including the published 1.2.0:npm install markdown-codenpx markdown-codeunknownnpm install -g markdown-codecli.tscalled yargs'.version()with no argument. yargs then guesses the version by looking forpackage.jsonabove the firstnode_modulesin yargs' install path. In this repo, that's ourpackage.json, so the tests passed. Installed as a dependency, it's the consumer's project. Undernpx, it finds nopackage.json.Changes
cli.ts:.version(VERSION).src/version.tsalready reads the package's ownpackage.jsonrelative todist/.scripts/smoke-test-package.mjs(npm run test:package, run afternpm run build):dist/,LICENSE,README.md,package.jsonand the logo, includingdist/index.d.ts;md-code --versionandmarkdown-code --versionprint the package version;syncandcheckon a small project;syncMarkdownFilesandVERSION.test:allincludes it, and it's documented inCONTRIBUTING.mdandAGENTS.md.The script runs npm as
node $npm_execpathwith no shell, so paths with spaces work on Windows too, ready for the cross-platform CI matrix in the next PR. It stops with a hint if it isn't run through npm or ifdist/is missing.Tests
Against the unfixed CLI, the smoke test fails with
'0.0.0' !== '1.2.0';0.0.0is the temp project's own version. With the fix, it passes. The in-repo--versiontest can't catch this, because inside the repo yargs finds the rightpackage.json.npm run lintand fixed any issues.npm run buildto verify the project builds.npm testto ensure all tests pass. (317 passed, plusnpm run test:package)