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
fix: handle strings the same in cjs, esm, and deno #139
base: master
Are you sure you want to change the base?
Conversation
It seems a bit weird to double up the dependencies, but I guess if those modules were shipped as hybrid esm/cjs, it'd be the same amount of code anyway. The only hazard is that the esm versions will probably get bugfixes that aren't going to be backported, but all three of them seem extremely stable, so I think the risk is low. |
Is nyc used when testing this library? I left the Istanbul comments in, but maybe they should be removed? |
Failure is from the standardx linter, will fix shortly. |
Switched from nyc to c8 in #80, so I think the comments can go. |
Hm, the standardx complaint is kind of confusing. It seems like it doesn't like |
You have the file named for explicit CommonJS ( Given you want to get access to both implementations and using require+import, should that be Update: well, tried that and didn't help! |
Hacking about without a deep understanding yet, but got new test running. The esm tests are a bit loose as not covered by standardx yet. Renamed to
Reworked to use imports consistently:
Then % npx mocha test/esm/cjs-esm-compare.mjs
consistent wrapping
✔ should produce matching output in cjs and esm
1 passing (6ms) |
Yes, dynamic I suppose it could be refactored to be a |
Ah, didn't notice Updated the existing esm test to verify the correct behavior, instead of verifying the incorrect behavior. Should be passing now, everything looks good locally. |
- Use trimStart/trimEnd instead of deprecated trimLeft/trimRight
This also ports some of the `// istanbul ignore` comments to their associated `/* c8 ignore start/stop */` equivalents, and coverage-ignores some value fallbacks that are there for safety but can never be hit in normal usage. Fix: yargs#138
a7db817
to
8ee2fad
Compare
Previously, it was verifying *incorrect* behavior.
8ee2fad
to
f236663
Compare
Ah, needed to update deno test as well. |
For interest I had a look at the impact in package size. As might be expected, installed size about doubles since two of everything. 😅 Details
|
Anything else needing to be done to land this? Some folks getting upset at me using a git dep while waiting. |
(Apparently the build fails when installing learna for some reason.) |
Nothing else from you at this point from me anyway, thanks. I'll review it as a supply-both approach to getting wrapping working in esm et al. A high level question is whether we want to land a double-dependency update, and I'll want input from @bcoe on that. I know people have expressed concerns about number of dependencies and size of Yargs install in past so this is of some concern, which is why I checked install sizes for reference. (And Benjamin has also mentioned heading for ESM whether esm-first or esm-only at some point.)
I don't have a timeline for you. Could you work around the limitation in the meantime by using require from esm and getting the CommonJs implementation? (I am not sure whether this makes any sense for your runtime setup.) |
I'll just publish my fork as @isaacs/cliui for now. Was just being lazy. I don't mind littering my npm account, it's a garbage pile of throwaway junk after all these years anyway lol |
The
> yarn why string-width
yarn why v1.22.19
[1/4] Why do we have the module "string-width"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "string-width@5.1.2"
info Reasons this module exists
- "web-ext#update-notifier#boxen" depends on it
- Hoisted from "web-ext#update-notifier#boxen#string-width"
- Hoisted from "web-ext#update-notifier#boxen#widest-line#string-width"
- Hoisted from "web-ext#update-notifier#boxen#wrap-ansi#string-width"
- Hoisted from "rimraf#glob#jackspeak#@isaacs#cliui#string-width"
info Disk size without dependencies: "200KB"
info Disk size with unique dependencies: "280KB"
info Disk size with transitive dependencies: "300KB"
info Number of shared dependencies: 4
Done in 0.54s.
> yarn why string-width-cjs
yarn why v1.22.19
[1/4] Why do we have the module "string-width-cjs"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "string-width-cjs@4.2.3"
info Reasons this module exists
- "yargs" depends on it
- Hoisted from "yargs#string-width-cjs"
- Hoisted from "yargs#cliui#string-width-cjs"
- Hoisted from "web-ext#yargs#string-width-cjs"
- Hoisted from "yargs#cliui#wrap-ansi-cjs#string-width-cjs"
- Hoisted from "web-ext#addons-linter#yargs#string-width-cjs"
- Hoisted from "rimraf#glob#jackspeak#@isaacs#cliui#string-width-cjs"
- Hoisted from "web-ext#update-notifier#boxen#ansi-align#string-width-cjs"
info Disk size without dependencies: "84KB"
info Disk size with unique dependencies: "164KB"
info Disk size with transitive dependencies: "184KB"
info Number of shared dependencies: 4
Done in 0.55s. |
Seems like the same as this issue: isaacs/jackspeak#5 This is a yarn bug, I think. I'm not sure what the best workaround is, but package aliases ought to be supported and sometimes it gets confused by them. |
Playing with an idea. We are using rollup to generate the cjs anyway. Could possibly use rollup to include the older dependencies directly so the npm aliases are only a dev dependency and bypass the yarn problem. But lose dedupe with other installs. This config generates a self-contained file to demonstrate idea, but the output file includes multiple copies of some dependencies. (I didn't work out the TypeScript/rollup interaction to tune the config better.)
|
@isaacs Does using a CommonJS implementation in ESM work for clients of jackspeak? You mentioned Related: In older discussion, Deno and Yargs browser support were the scenarios of concern for "true ESM": #89 (comment) |
"True ESM" is definitely the goal in principle, as eventually I would like tap to work in deno and browsers, so I've been shipping full hybrid builds for everything. That said, the stuff using cliui won't ever work in browsers per se, and most of the cli runner is pretty node specific, so getting to deno support will be a big lift as well, so just shipping CJS is fine, too. The main thing for me here is, |
Good info, thanks @isaacs The reason I am considering different approaches is that the underling lack of ansi support in ESM flavour of cliui generated a few issues across yargs in a couple of years. Using the npm aliases via jackspeak generated a couple of reports within days (due to breaking builds). Which we only know now because you tried an approach @isaacs , full credit for that! |
When yarn3 attempts to run audit on a project with https://github.com/isaacs/cliui/blame/main/package.json#L53 Repro with details: |
I wasn't able to reproduce this. I cloned out your repo, and ran (on Mac):
|
This comment was marked as outdated.
This comment was marked as outdated.
I pulled from correct repo, but still can not reproduce. What commands are you running that are showing an issue? |
Sorry! |
...?! Yarn doesn't audit transitive deps by default?? |
🤷♂️ c'est la vie |
Ok, reproduced now. I have an alternative PR for |
I meet the same issue with yarn. I went through all comments, but I didn't find any solution except using npm. And I used npm, it can works. Hopefully it can be solved in the future. |
@shadowspawn I've tried your PR and confirmed it doesn't have the same problem as |
I encountered the same issue since yesterday. However, after switching to PNPM, the problem was resolved. Running the command 'yarn why cliui' pointed me to the @ngneat/transloco. Thanks for the guidance; you all made my day! |
For yarn 1 users hitting this page because of runtime failures with cliui and string-width, try upgrading to yarn v1.22.22 or higher. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a yarn 1 update available, I think this is now ok.
I have an alternative PR open which uses rollup plugins rather than a package manager alias to support the cjs/esm implementations, different tradeoffs but similar outcome: #143.
This also ports some of the
// istanbul ignore
comments to theirassociated
/* c8 ignore start/stop */
equivalents, andcoverage-ignores some value fallbacks that are there for safety but can
never be hit in normal usage.
Fix: #138