Comments (10)
To me, "no extension" means "a script I can execute from the command line". In other words, I try to avoid a file extension for any file with a shebang at the top and chmod +x
applied to it. Maybe that's just me though! 🤷
If it helps, here's an example of how another project recently accomplished this: code, issue.
from zx.
It will cool to have VSCode extension for zx. And with it we can allow omitting extension.
from zx.
Actually we can make a workaround this problem by writing script with extension to separate file and executing it.
from zx.
Done!
from zx.
Actually we can make a workaround this problem by writing script with extension to separate file and executing it.
Thank you for implementing this feature.
Right now the mjs script is generated in the same folder as the executable, and it is cleaned up when the script exits. But if you close the script midway with ctrl + c, or any type of process.exit() is executed from within the script, this generated file is unfortunately not cleaned up. Moreover, in future invocations (and possible cancellations) newer and newer files are generated (with random suffixes to prevent clashes) and they pile up.
Is there a particular reason for generating this temporary file in the same location as the original script? I don't think making sure that the cleanup happens properly in each case would be trivial (or possible). Would it be better to generate this in a system's temp folder so that no matter what happens, they are cleaned by the system automatically? If such a change makes sense, maybe I can attempt a PR for it.
from zx.
With you have .mjs
or .js
editors will understand 😉
Also, mjs/js makes the distinction between ESM/CommonJS modules.
It's possible to add support for "empty extension", but I think the explicit extension is better.
from zx.
Concrete use case:
At my company we share a lot of tools. We put common scripts in a bin folder. These are written in the language most suitable for the task and it should be easy to replace these scripts with a new implementation as requirements change. Therefore, there can be no file extension in our script files.
The shebang should be plenty to go on for syntax highlighting. I respect that tooling isn't really there yet but it should be up to the users of this.
from zx.
A quick workaround for this is that use a new shell script.
For example , assume that you've written a script called foo.mjs
but you want to invoke it without extension i.e. foo
. Then you could write a shell script called foo
with content like this:
#!/usr/bin/env bash
zx /path/to/foo.mjs
Then put it into somewhere in your $PATH.
As far as I know, the mjs file extension is a must for Nodejs import statement. Here is the doc esm import specifiers .
from zx.
That would be nice! For me (and probably others) the temp files will most likely be exposed on the PATH, since the original file was exposed through it's containing folder. This will contaminate a lot of stuff, autocompletion, for instance.
from zx.
#!/usr/bin/env npx zx
1) enables syntax highlight for js 2) also downloads zx if it's not available
from zx.
Related Issues (20)
- Setting stdio/err to inherit throws error HOT 1
- Typo in 8.0 release description HOT 1
- Feature request: automatically add a newline after commands that don't end their output with one HOT 4
- The type for `glob` is `any` after 8.0.0 HOT 5
- Port listening doesn't stop when using `CTRL+C` HOT 11
- Feature request: add `usePwsh` helper for PowerShell 7+ HOT 3
- Why zx instead of Python ? HOT 2
- Markdown script didn't work for CRLF file
- Is Node.js 12.17.0 supported for zx as a package ? HOT 7
- Single file executable?
- Docs: Typo in setup docs
- fetch's document link is wrong HOT 4
- bun compatibility: get rid of async_hooks.createHook call HOT 3
- cannot concatenate strings with ${} HOT 4
- Understanding `zx` roadmap and idea 🙏 HOT 6
- YAML.parseAllDocuments is no longer accessible HOT 8
- Provide better out of the box TypeScript support HOT 2
- Could not resolve "zx/globals.cjs" HOT 4
- Since 8.1.4 YAML.parseAllDocuments is not allowed from zx HOT 6
- Importing this package into CJS project triggers false-positive TypeScript error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zx.