-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
Issue running grep with input globs using script interface #555
Comments
Hi @navin-moorthy, Which error do you get when running the following command? import { execFile } from 'child_process'
import { promisify } from 'util'
const pExecFile = promisify(execFile)
const { stdout } = await pExecFile(`grep --exclude script/setup.js --exclude script/setup-test-e2e.js --exclude-dir node_modules -i *.* **/*.*`, { shell: true }) |
I do not get any error while running But I get this error while running without Error Details
> node script/setup-test-e2e.js
node:internal/errors:490
ErrorCaptureStackTrace(err);
^
Error: spawn grep --exclude script/setup.js --exclude script/setup-test-e2e.js --exclude-dir node_modules -i /JoshuaKGoldberg/ *.* **/*.* ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:476:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn grep --exclude script/setup.js --exclude script/setup-test-e2e.js --exclude-dir node_modules -i /JoshuaKGoldberg/ *.* **/*.*',
path: 'grep --exclude script/setup.js --exclude script/setup-test-e2e.js --exclude-dir node_modules -i /JoshuaKGoldberg/ *.* **/*.*',
spawnargs: [],
cmd: 'grep --exclude script/setup.js --exclude script/setup-test-e2e.js --exclude-dir node_modules -i /JoshuaKGoldberg/ *.* **/*.*',
stdout: '',
stderr: ''
} While running below command, const { stdout } = await $`grep --exclude script/setup.js --exclude script/setup-test-e2e.js --exclude-dir node_modules -i /JoshuaKGoldberg/ *.* **/*.*`; I get this error, Error Details
> node script/setup-test-e2e.js
file:///Users/github/template-typescript-node-package/node_modules/.pnpm/execa@7.1.1/node_modules/execa/lib/error.js:59
error = new Error(message);
^
Error: Command failed with exit code 2: grep --exclude script/setup.js --exclude script/setup-test-e2e.js --exclude-dir node_modules -i /JoshuaKGoldberg/ *.* **/*.*
grep: *.*: No such file or directory
grep: **/*.*: No such file or directory
at makeError (file:///Users/github/template-typescript-node-package/node_modules/.pnpm/execa@7.1.1/node_modules/execa/lib/error.js:59:11)
at handlePromise (file:///Users/github/template-typescript-node-package/node_modules/.pnpm/execa@7.1.1/node_modules/execa/index.js:124:26)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///Users/github/template-typescript-node-package/script/setup-test-e2e.js:38:20 {
shortMessage: 'Command failed with exit code 2: grep --exclude script/setup.js --exclude script/setup-test-e2e.js --exclude-dir node_modules -i /JoshuaKGoldberg/ *.* **/*.*',
command: 'grep --exclude script/setup.js --exclude script/setup-test-e2e.js --exclude-dir node_modules -i /JoshuaKGoldberg/ *.* **/*.*',
escapedCommand: 'grep --exclude "script/setup.js" --exclude "script/setup-test-e2e.js" --exclude-dir node_modules -i "/JoshuaKGoldberg/" "*.*" "**/*.*"',
exitCode: 2,
signal: undefined,
signalDescription: undefined,
stdout: '',
stderr: 'grep: *.*: No such file or directory\n' +
'grep: **/*.*: No such file or directory',
failed: true,
timedOut: false,
isCanceled: false,
killed: false
}
Node.js v18.15.0 stderr: 'grep: *.*: No such file or directory\n' + 'grep: **/*.*: No such file or directory' But running this directly in terminal runs well grep --exclude script/setup.js --exclude script/setup-test-e2e.js --exclude-dir node_modules -i /JoshuaKGoldberg/ *.* **/*.* |
Thanks for the response @navin-moorthy, It does not appear to be an error with Execa itself, but to confirm this, I would need to reproduce your setup. Would you it be possible for you to create a repository reproducing the above behavior? Thanks! |
@ehmicky, here is the file https://github.com/JoshuaKGoldberg/template-typescript-node-package/blob/main/script/setup-test-e2e.js that is in discussion. You can checkout & run Additional Reference: JoshuaKGoldberg/create-typescript-app#357 |
Hi @navin-moorthy, I have tried to reproduce, but I am not encountering the same error as above. Would you be able to create a minimal GitHub repository which reproduces the above problem? Typically, it would only contain a single file to execute without any additional setup, with as few lines of code as possible to re-create the above error. Thanks! |
Here is the minimal reproduction in codesandbox - https://codesandbox.io/p/sandbox/quizzical-galois-bou50c?file=%2Findex.js Github repo - https://github.com/navin-moorthy/execa-issue--555 Additional info, |
Thanks @navin-moorthy, This example removes const output = await $`grep --exclude-dir=node_modules/* -i template *.* **/*.*`;
When you add const output = await $({ shell: true })`grep --exclude-dir=node_modules/* -i template *.* **/*.*`;
|
Thanks @ehmicky for the explanation 👍 |
I found this quite useful using globby - https://github.com/google/zx/blob/main/docs/quotes.md#globbing-and-, https://github.com/google/zx/blob/main/README.md#globby-package This solution works without const files = await globby(["*.*", "**/*.*"]);
const output = await $`grep --exclude-dir=node_modules/* -i ${files}`; |
<!-- 👋 Hi, thanks for sending a PR to template-typescript-node-package! 💖. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [x] Addresses an existing open issue: fixes #357 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/template-typescript-node-package/blob/main/.github/CONTRIBUTING.md) were taken ## Overview <!-- Description of what is changed and how the code change does that. --> Added [`globby`](https://github.com/sindresorhus/globby) package. Reason - sindresorhus/execa#555 (comment) --------- Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Error in terminal:
grep: **/*.*: no such file or directory
References: JoshuaKGoldberg/create-typescript-app#357, JoshuaKGoldberg/create-typescript-app#349 (comment)
The text was updated successfully, but these errors were encountered: