75lb/renamer

Compatibility with yarn pnp?

mxro opened this issue · 7 comments

mxro commented

Is this module compatible with Yarn Plug and Play

When running renamer in a Yarn workspace using yarn 2, I get the following error message:

command-line-plugin tried to access command-line-args, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: command-line-args (via "command-line-args")
Required by: command-line-plugin@npm:0.2.0 (via /Users/mrohde/repos/typescript-monorepo-starter/.yarn/cache/command-line-plugin-npm-0.2.0-94229159f8-3.zip/node_modules/command-line-plugin/)

Require stack:
- /Users/mrohde/repos/typescript-monorepo-starter/.yarn/cache/command-line-plugin-npm-0.2.0-94229159f8-3.zip/node_modules/command-line-plugin/index.js
- /Users/mrohde/repos/typescript-monorepo-starter/.yarn/cache/renamer-npm-2.0.0-a2acda74ae-3.zip/node_modules/renamer/lib/cli-app.js
- /Users/mrohde/repos/typescript-monorepo-starter/.yarn/cache/renamer-npm-2.0.0-a2acda74ae-3.zip/node_modules/renamer/bin/cli.js

See Yarn 2 Release

Thank you for this tool!

Workaround: Downgrading to renamer@^0.7.0 resolves the issue.

75lb commented

Hi, i've pushed a fix for this in a beta release with the tag next - could you check it works please?

npm install renamer@next

I just need to test the prerelease on multiple platforms before making it live..

mxro commented

Thank you for looking into this so quickly 👍

I upgraded to renamer@next and now I'm getting this error:

internal/modules/cjs/loader.js:984
    throw new ERR_REQUIRE_ESM(filename);
    ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/mrohde/repos/typescript-monorepo-starter/.yarn/cache/renamer-npm-3.0.0-0-8784a2473a-3.zip/node_modules/renamer/bin/cli.mjs
    at Module.load (internal/modules/cjs/loader.js:984:11)
    at Function.module_1.Module._load (/Users/mrohde/repos/typescript-monorepo-starter/.pnp.js:23734:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_REQUIRE_ESM'

This is using yarn-2.0.0-rc.33.js with workspaces enabled. My node version is v12.18.0. Let me know if you need any more information.

75lb commented

Ok, thanks for the detailed report.

I have rewritten renamer using ECMAScript Modules (which you just tested on the prerelease) but this version clearly needs some extra work..

So, I applied the fix for this issue on the main branch and released it in v2.0.1. The ESModules version can wait.

Please upgrade:

npm install renamer
mxro commented

Thank you for looking into this straight away 💯

I've upgraded to the latest version using yarn up renamer@^2.0.1.

The error message does not come up anymore.

Unfortunately, it seems to get stuck on applying:

renamer --find .d.ts --replace .ts \"./src/generated/**\"

Process can only be quit using Ctrl +C or similar means.

When changing back with yarn up renamer@^0.7.0 it works again. I'm on Mac OS 10.13.6.

75lb commented

if renamer hangs, it is because no filenames were passed as command line arguments so it is waiting for input on stdin..

If you're on a mac, use single quotes..

renamer --find .d.ts --replace .ts './src/generated/**'
mxro commented

Thank you for getting back to me!

I have changed the command to renamer --find .d.ts --replace .ts './src/generated/**'.

Unfortunately, it still hangs after upgrading to renamer@^2.0.1

Screen Shot 2020-06-08 at 6 22 52 am

75lb commented

Closing as this hanging issue is not a bug with renamer itself.