-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Running a .mjs-script through symlink with early exit creates copy of the script #993
Comments
After some digging, I notice that its a combination of a few pieces of code. Namely these: if (ext === '') {
const tmpFilename = fs.existsSync(`${filepath}.mjs`)
? `${base}-${randomId()}.mjs`
: `${base}.mjs`
return writeAndImport(
await fs.readFile(filepath),
path.join(dir, tmpFilename),
origin
)
} Here - if there is no extension, we make a copy, now with an extension, and with a random ID in my case, to avoid collisions. export async function writeAndImport(
script: string | Buffer,
filepath: string,
origin = filepath
) {
await fs.writeFile(filepath, script.toString())
try {
await importPath(filepath, origin)
} finally {
await fs.rm(filepath)
}
} Here - we write the new filename, and once we have executed the script, we remove the file again with a await import(url.pathToFileURL(filepath).toString()) Here there actual execution happens. Though - if this executes a A fix - in my case - could be to execute the file without the extension, which works just fine. Removing the first block of code above does it. I don't know why the block was added in the first place - I don't see any comments or information in the git commit message. However - there is still an issue with Another solution would be to execute the script in another thread, so we avoid having Feedback will be appreciated. :) |
* Thinking about replacing |
At least there will only be one file then, but it still doesn't fix the issue, right? |
Check this out: v8.2.4-dev.c8ca866 |
Works as intended. :) Thanks! |
To follow up on #579 - I don't know why it was considered completed, as there is no resolution mentioned in the issue.
I still experience this issue with zx 8.2.4.
To replicate, make a file called
test.mjs
with one line:.. then make a symlink to the file with
ln test.mjs test
, and run withzx test
.You'll start seeing a copy of
test.mjs
for every execution, showing up in the directory with names like:test-zz5yo0hugt.mjs
test-ysdh5sy58g.mjs
The text was updated successfully, but these errors were encountered: