Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Usage documentation is unclear #27

Open
msikma opened this issue Aug 26, 2022 · 2 comments
Open

Usage documentation is unclear #27

msikma opened this issue Aug 26, 2022 · 2 comments
Labels
question Further information is requested

Comments

@msikma
Copy link

msikma commented Aug 26, 2022

Question

I've been trying to test out this program on one of my projects, but somehow I've been unable to succeed. I think I may be using it wrong but from the documentation I'm not entirely sure how this is happening.

My project uses Yarn workspaces, with the following structure:

package.json
packages\
packages\callisto-cli
packages\callisto-core
...

Each package has its own package.json.

My first intuition was to run cjstoesm packages/**/*.* since that's what the first example shows. That somehow causes it to attempt to create a directory named after the first file, which crashes:

$ cjstoesm packages/**/*.*
node:fs:1385
  handleErrorFromBinding(ctx);
  ^

Error: EEXIST: file already exists, mkdir '/Users/msikma/Projects/callisto-test/packages/callisto-cli/package.json'
    at Object.mkdirSync (node:fs:1385:3)
    at Object.writeFile (file:///usr/local/lib/node_modules/cjstoesm/dist/cli/index.js:3348:24)
    at Object.writeFile (/usr/local/lib/node_modules/cjstoesm/node_modules/typescript/lib/typescript.js:18750:14)
    at printSourceFileOrBundle (/usr/local/lib/node_modules/cjstoesm/node_modules/typescript/lib/typescript.js:111960:16)
    at emitJsFileOrBundle (/usr/local/lib/node_modules/cjstoesm/node_modules/typescript/lib/typescript.js:111836:13)
    at emitSourceFileOrBundle (/usr/local/lib/node_modules/cjstoesm/node_modules/typescript/lib/typescript.js:111757:13)
    at forEachEmittedFile (/usr/local/lib/node_modules/cjstoesm/node_modules/typescript/lib/typescript.js:111498:34)
    at Object.emitFiles (/usr/local/lib/node_modules/cjstoesm/node_modules/typescript/lib/typescript.js:111738:9)
    at emitWorker (/usr/local/lib/node_modules/cjstoesm/node_modules/typescript/lib/typescript.js:119072:33)
    at /usr/local/lib/node_modules/cjstoesm/node_modules/typescript/lib/typescript.js:119049:72 {
  errno: -17,
  syscall: 'mkdir',
  code: 'EEXIST',
  path: '/Users/msikma/Projects/callisto-test/packages/callisto-cli/package.json'
}

Node.js v18.3.0

Then I saw that in the animated example, the glob is encased in quotes, which means it passes on the glob literally instead of expanding it first, so I tried that:

cjstoesm "packages/**/*.*"
✔ packages/callisto-cli/index.js

This worked on one package (although it killed all the empty lines in it and removed the copyright notice at the top for some reason, but that's a different issue), but somehow it failed to work on the callisto-core package. It just didn't detect it somehow. Same if I use packages/**.

I decided to try using the output directory option, so I ran cjstoesm "packages/**/*.*" "packages_new". Again this only worked for the callisto-cli package (which has only one index.js file) and not for the callisto-core package. It also did not replicate the package directory structure.

Is there some way I'm doing it wrong? What would be the appropriate invocation for my situation? Also, is there a way to prevent the converter from removing additional whitespace in my files? (Here's the old and new.) I appreciate any help!

@msikma msikma added the question Further information is requested label Aug 26, 2022
@anselmbradford
Copy link

I get the same Error: EEXIST: file already exists error when running via npx and no files get converted.

@vikaspotluri123
Copy link

vikaspotluri123 commented Jan 30, 2023

I ran into the error as well. It turns out that if you use a shell glob, cjstoesm incorrectly reads the second file as the output directory.

As a workaround, I'm using find + xargs. It's not ideal, but it works.

# `lib` is the folder to search, `*.ts` is the glob
find lib -name '*.ts' | xargs -I {} npx cjstoesm {}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants