Skip to content

Use rechoir and interpret for scripts.#258

Closed
knpwrs wants to merge 1 commit intoshelljs:masterfrom
knpwrs:rechoir
Closed

Use rechoir and interpret for scripts.#258
knpwrs wants to merge 1 commit intoshelljs:masterfrom
knpwrs:rechoir

Conversation

@knpwrs
Copy link
Copy Markdown
Contributor

@knpwrs knpwrs commented Dec 3, 2015

This adds support for babel, iced coffeescript, typescript, jsx (maybe somebody is generating HTML in a script, eh?), etc.

This can be modified to still execute out-of-process which may be desirable because of the require('../global') statement. Alternatively, we could require non-globally and leave everything in the shjs file.

@nfischer
Copy link
Copy Markdown
Member

Looks like a good addition. Does anyone else in the community want support for these languages?

@TimothyGu
Copy link
Copy Markdown
Contributor

The notion of being able to automatically use Babel to transpile the script sounds fairly appealing to me.

@nfischer
Copy link
Copy Markdown
Member

@ariporad @arturadib what do you guys think? Is it worth the dependency? I have yet to test if this handles exit codes properly and things such as that (which I think are more important than supporting arbitrary languages)

@arturadib
Copy link
Copy Markdown
Collaborator

agreed @nfischer , if nothing breaks like exit codes, that's fine. I don't think we have tests for shjs so maybe add those in with consideration for what behavior we need to preserve first, then see if this passes those?

@nfischer
Copy link
Copy Markdown
Member

Sounds like a good idea. I might be able to write up some basic unit tests in bash for shjs, just to make sure that stderr and exit code are preserved (since exec() used to have issues with those)

@ariporad
Copy link
Copy Markdown
Contributor

Once #304 lands, we can see if this breaks shjs.

@ariporad ariporad added this to the v0.6.0 milestone Jan 24, 2016
@ariporad ariporad self-assigned this Jan 24, 2016
@ariporad
Copy link
Copy Markdown
Contributor

@knpwrs: Could you rebase off master? Thanks!

@knpwrs
Copy link
Copy Markdown
Contributor Author

knpwrs commented Jan 28, 2016

The three-way merge is looking a little hairy:

image

Are you guys looking to preserve anything in particular? Or should I just take my changes?

@nfischer
Copy link
Copy Markdown
Member

@knpwrs most of your stuff you should keep. Make sure this is compatible with file names with spaces and node binary paths with spaces, that's all

@knpwrs
Copy link
Copy Markdown
Contributor Author

knpwrs commented Jan 30, 2016

Travis failed on one version of node. Appveyor failed a test that I was trying to fix locally on my Mac. I don't currently have access to a Windows machine to debug.

@nfischer
Copy link
Copy Markdown
Member

@knpwrs This passes travis. I think someone wrote a bad test for touch(). I'll investigate

@nfischer
Copy link
Copy Markdown
Member

nfischer commented Feb 1, 2016

@knpwrs I dug through the results on my windows 7 box. I see errors that look like Error: Cannot find module 'C:\Users\Username\C:\path\to\shelljs\test.... Notice that C:\ is in there twice. That might be specific to my system, but it's a bug that I wasn't able to quickly get past. My guess is that one of the dependencies doesn't have good Windows support for how you're trying to use it.

If you'd like to debug, feel free to use appveyor as you wish (you can push commits with helpful logging statements, and remove them later). Otherwise, I vote to close the issue, since it isn't worth losing Windows support.

@nfischer nfischer removed this from the v0.6.0 milestone Feb 1, 2016
@ariporad
Copy link
Copy Markdown
Contributor

@knpwrs: What's the status on this? I'd really like to get this merged, I miss not having ES6 in my shelljs scripts.

@knpwrs
Copy link
Copy Markdown
Contributor Author

knpwrs commented Feb 14, 2016

I've just been super busy. My only real option for testing on Windows is a VM, but I don't think I'll really be able to get anywhere this week.

@TimothyGu
Copy link
Copy Markdown
Contributor

I can take a look.

@TimothyGu
Copy link
Copy Markdown
Contributor

Alright this PR has more than a bunch of issues.

  • Consistently use LF line endings #355 is needed for me to get the tests working without modifications
  • it seems like test/shjs.js wasn't rebased correctly: __dirname and a bunch of other fixes are not present

After fixing all of the above, there is only one change needed to fix the issue reported by @nfischer, which is changing path.join to path.resolve in shjs.

The incremental diff is attached.

diff --git a/bin/shjs b/bin/shjs
index 9ad0e1a..75ca58b 100755
--- a/bin/shjs
+++ b/bin/shjs
@@ -36,4 +36,4 @@ var path = require('path');
 var extensions = require('interpret').extensions;
 var rechoir = require('rechoir');
 rechoir.prepare(extensions, scriptName);
-require(require.resolve(path.join(process.cwd(), scriptName)));
+require(require.resolve(path.resolve(process.cwd(), scriptName)));
diff --git a/test/shjs.js b/test/shjs.js
index 02380a6..8b95faa 100644
--- a/test/shjs.js
+++ b/test/shjs.js
@@ -4,8 +4,8 @@ var assert = require('assert');

 function runScript(name) {
   // prefix with 'node ' for Windows, don't prefix for OSX/Linux
-  var cmd = (process.platform === 'win32' ? 'node' : '') + path.resolve(__dirname, '../bin/shjs');
-  var script = path.join('resources', 'shjs', name);
+  var cmd = (process.platform === 'win32' ? 'node ' : '') + path.resolve(__dirname, '../bin/shjs');
+  var script = path.resolve(__dirname, 'resources', 'shjs', name);
   return shell.exec(cmd + ' ' + script, { silent: true });
 }

@nfischer
Copy link
Copy Markdown
Member

@TimothyGu thanks! Awesome work!

@nfischer
Copy link
Copy Markdown
Member

@TimothyGu @knpwrs Could we get this rebased? I think most of the blocking issues have been resolved. Thanks!

@nfischer nfischer mentioned this pull request Mar 5, 2016
@nfischer
Copy link
Copy Markdown
Member

nfischer commented Mar 5, 2016

I refactored this into an up-to-date PR (see #384). It seems to be passing CI so far. If that one is good, I think we should go with that and close this one.

@nfischer
Copy link
Copy Markdown
Member

#384 is merged, so I'm closing this. Thanks @knpwrs for the PR!

@nfischer nfischer closed this Mar 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants