practicalmeteor/spacejam

Windows support?

Closed this issue · 9 comments

Now that Meteor is about to release official support for Windows, would there be interest in making spacejam run on Windows? I know it's intended for CI, which runs on *nix machines, but for local development, it would be useful to have Windows support. Right now, I get

> spacejam --mongo-url mongodb:// test-packages ./

spacejam: spawning meteor
spacejam: killing meteor

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:988:11)
    at Process.ChildProcess._handle.onexit (child_process.js:779:34)

Would be nice, but I won't work on this one until windows support is officially out there and stable.

Just got the same issue. Any plans on supporting Windows?
The above issue is easily fixable just by using cross-spawn here https://github.com/practicalmeteor/spacejam/blob/master/lib/ChildProcess.js#L14 instead of child_process.
However I did not have time to check if any other problems will not pop up after that one.

@wojtkowiak thanks for the pointer, will check it out.

serut commented

Hi,
It's working great on windows with this commit
As you know, psargs and ppid are not supported under windows, so I needed to remove this test https://github.com/serut/spacejam/commit/ffaa9c9d26d8ed60d83f6315350743082786799b#diff-0b5f1f297c7739069dfef6aa7cc959c1L29.
Is it really important to check that mongod has the PPID of meteor ?
Another solution would be to edit practicalmeteor/ps to ignore psargs and ppid if the running platform is windows.

I had this issue as well (Windows 10) and wanted to fix it because my Cloud9 *nix VM tends to run out of disk space so I need an alternative local IDE and meteor installation.
Running meteor test-packages runs fine out of the box btw.

So here's how I got it to work (it's not exactly the same as the commit does):

  • made backups of all the files in my npm\node_modules\spacejam\lib folder
  • use cross-spawn-async in ChildProcess Line 14
ChildProcess._spawn = require("cross-spawn-async").spawn;
  • added Windows-specific code to findAllChildren function in MeteorMongodb.js Line 40:
if (process.platform === 'win32') {
  var resultList = [];
  var bat = require('child_process').spawn('cmd.exe', ['/c', 'getChildren.bat ' + this.meteorPid]);

  bat.stdout.on('data', function (data) {
    var childPid = data.toString().trim();
    resultList.push({pid: parseInt(childPid)});
  });

  bat.stderr.on('data', function (data) {
    return log.warn("spacejam: Warning: Error enumerating mongod children:\n", data);
  });

  bat.on('exit', function (code) {
    if (code != 0) {
      return log.warn("spacejam: Warning: Enumerating mongod children returned with error code: ", code);
    }
    log.info("MongoDB children:\n", resultList);
    this.mongodChilds = resultList;
    if (resultList.length === 0) {
      return log.warn("spacejam: Warning: Couldn't find any mongod children:\n", err);
    } else if (resultList.length > 1) {
      return log.warn("spacejam: Warning: Found more than one mongod child:\n", resultList);
    } else {
      return log.debug("Found meteor mongod child with pid: ", resultList[0].pid);
    }
  });

  return;
}
  • created a batch file getChildren.bat to implement getting child processes because *nix ps doesn't cut it on Windows:
@echo off & setlocal enabledelayedexpansion
set PPID=%1
for /F "skip=1 tokens=1" %%a in ('wmic process where "ParentProcessID=%PPID%" get processid') do for %%b in (%%a) do (
  echo %%a
)
  • I did NOT have to rename Phantomjs.js to PhantomjsRunner.js
    I tested with and without renaming and could not see a difference.
  • what I did have to do was install phantomjs globally (npm i -g phantomjs) because otherwise Spacejam failed to spawn it. It seems just installing spacejam with -g does not suffice because phantomjs does not end up being on the PATH, resulting in the dreaded "spawn ENOENT" error.

After those steps, spacejam ran my package test with test-in-console driver as normal. I ran spacejam with the "--loglevel debug" option to see what's happening. I'm still not sure everything works correctly and I still get "spacejam: Unknown error with exit code 'null'. Exiting." after the tests have run.

Also the spawned node and mongod processes still hang around until I double Ctrl-c in the console, so the code I added might not be enough although it duplicates the ps.lookup behaviour. If anyone finds out more about it, please share your findings. For now I'm happy the tests work. All of this was on Meteor 1.2.1 platform and I'm switching to Meteor 1.3 and refactoring my packages to use module imports/exports. After that, spacejam might not be needed anymore, but we'll see. In any case this post might be useful for other scenarios that need Windows support...

As an aside, you can slightly modify the batch file to get the parent of a process instead, like this:

@echo off & setlocal enabledelayedexpansion
set PID=%1
set PPID=undefined
for /F "tokens=2 delims==" %%a in ('wmic process where "ProcessID=%PID%" get parentprocessid /value') do (
  if "%PPID%"=="undefined" set PPID=%%a
  goto break
)

:break
echo %PPID%

I put those batch files in the root of my meteor project, but they could be put somewhere else as well I guess, as the spawn function also has options to specify path and working director and whatnot.

serut commented
  • I did NOT have to rename Phantomjs.js to PhantomjsRunner.js I tested with and without renaming and could not see a difference.
  • what I did have to do was install phantomjs globally (npm i -g phantomjs) because otherwise Spacejam failed to spawn it. It seems just installing spacejam with -g does not suffice because phantomjs does not end up being on the PATH, resulting in the dreaded "spawn ENOENT" error.

Yes windows looks first in the directory and then in the PATH ...! But I found an alternative, I use the full path of phantomjs:
master...serut:master#diff-46f7a2c55394d7160b95c6cfd50c64b9R40
Note that my repository works great on windows, but it doesn't look anymore if mongod is a child of meteor

jsep commented

Thanks @schoepke and @serut I'm working with windows support and your contributions are welcome, if you want you can create a pull request.

@schoepke you can use spacejam for your app tests as well, the latest release of spacejam has support meteor test command.

jsep commented

Hello @serut @schoepke @wojtkowiak @dandv I've just release a new version of spacejam that supports windows, I've include all your suggestions.

To try the new version run this:

npm install -g spacejam@1.6.2-rc.1

It was not working for me.

I was getting the following error:

Error: Cannot find module 'coffee-script/register'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (C:\Users\bruno\AppData\Roaming\npm\node_modules\spacejam\bin\spacejam:3:1)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
Exited with code: 1.
Error executing child process: Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "spacejam --mongo-url mongodb:// test-packages ./meteor"
module.js:327
    throw err;

And it just fixed by doing:
npm install -g coffee-script