-
Notifications
You must be signed in to change notification settings - Fork 41
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
Wrapping logic seems to be weirdly different between ESM vs CJS versions #138
Comments
Ah, it looks like the cjs version is setting up the Mixin with different values: const stringWidth = require('string-width');
const stripAnsi = require('strip-ansi');
const wrap = require('wrap-ansi');
function ui(opts) {
return cliui(opts, {
stringWidth,
stripAnsi,
wrap
});
} Whereas the mjs does this: import { wrap, stripAnsi } from './build/lib/string-utils.js'
export default function ui (opts) {
return cliui(opts, {
stringWidth: (str) => {
return [...str].length
},
stripAnsi,
wrap
})
} So the difference appears to be that the functions in |
Confirmed, this fixes the issue: diff --git a/index.mjs b/index.mjs
index bc7a022..ccb76e7 100644
--- a/index.mjs
+++ b/index.mjs
@@ -1,6 +1,8 @@
// Bootstrap cliui with CommonJS dependencies:
import { cliui } from './build/lib/index.js'
-import { wrap, stripAnsi } from './build/lib/string-utils.js'
+import { stripAnsi } from './build/lib/string-utils.js'
+import { createRequire } from 'module'
+const wrap = createRequire(import.meta.url)('wrap-ansi')
export default function ui (opts) {
return cliui(opts, { I'm guessing the reason for not using It'd probably be best to ditch wrap-ansi entirely (including in the cjs version) and fix the |
Ugh, and it'd be trivial to update strip-ansi, wrap-ansi, and string-width to ESM, but that would drop support for cjs, because those modules are ESM-only. Can do it with a npm alias, idk if that's too weird, but it would at least fix the issue. |
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
See also: #89 Related: yargs/yargs#2112 (comment) |
Fixed by #139 |
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
Any update on this? @shadowspawn (PR #143 ) Experiencing the following issue with jest;
|
No update Interested in knowing more about your context to understand what the error message might be about, and whether the proposed PR will help. This issue is about cliui not wrapping when used from esm which is due to complications around Is your project pulling in |
So our project uses jest for unit testing, where a lower level dependency uses string-width.
I can create a small test environment |
I've created a test environment; https://github.com/Netail/jest-string-width |
Great, thanks @Netail , I'll give that a try in next couple of days. (I can see in the |
Reproduced with Yarn 1. The Jest problem is triggered by the use of aliases in #139 which is published in Details
I was able to get a working install by deleting the This output is from the example repo and an install with the original The only installed package that uses alias
The suspect entry in the
|
@arcanis This is another example of the "yarn 1 deduplicating aliased packages incorrectly" issue. @Netail I have not checked, but I'm willing to be that this would not be a problem with any other package manager. Try using npm, pnpm, or latest yarn (v4). Yarn 1 should not be used, as long as this bug prevents it from correctly resolving dependency graphs. |
When installing yarn ( |
I tried to release a 1.22.22 release which should fix this issue. Running the reproduction in eslint/eslint#17215 (reply in thread) with |
I retested reproduction from @Netail . Looks good with I needed to delete the For reference, the yarn fix is: yarnpkg/yarn#9023 |
(I'll try a couple of different reproductions from #139 as well.) |
Yes seems like my issue has been resolved with v1.22.22, that's great! Thank you guys very much :) |
I reproduced problems with packages used in #139 (comment) with |
Just for a feedback, I've had this problem and upgrading to yarn 1.22.22 as cited worked perfectly. |
Example:
I'm not sure why, but the esm results seem to wrap at very confusing places, differently from the cjs version.
The text was updated successfully, but these errors were encountered: