alexisvincent / systemjs-hot-reloader

reloads your modules as needed so that you can have satisfyingly fast feedback loop when developing your app
MIT License
228 stars 36 forks source link

NodeJS support #61

Open guybedford opened 8 years ago

guybedford commented 8 years ago

I wonder if it would be possible to create a variation of this project that works for Node apps running SystemJS? That could potentially just use the hot-reloader component with some built-in file watching method of sorts, that could just need to be imported to work.

Just putting this down here as a feature to consider, feel free to close as well.

salfield commented 8 years ago

For me this would ease the speed of NodeJS development in SystemJS considerably. What would be necessary in order to adapt hot-reloader to make this possible?

AntonyBlakey commented 8 years ago

This would be useful in the main process of electron apps.

AntonyBlakey commented 8 years ago

I now have this working with electron + jspm + typescript + react + mobx, for both the electron main process (which is node) and the renderer processes (which is a browser).

The starter project is at: https://github.com/AntonyBlakey/starter-electron-jspm-typescript-react-mobx and the reloader that it uses (a modified version of this one) is at: https://github.com/AntonyBlakey/systemjs-hot-reloader.

The key was to separate the reloader from the socket creation, because socket.io-client needs to be imported differently in the two contexts. Also socket.io-client refers to navigator.userAgent without any guards (which IMO is a bug in that package), so you need to setup a fake global.

I don't have a fix for the jspm + typescript typings issue, but that's not too hard to work around either by replicating the jspm installs as npm installs, or symlinking automatically between jspm_packages/npm and npm_modules, or using typings to install from jspm_packages

alexisvincent commented 7 years ago

@AntonyBlakey Would you be willing to bring your changes into this project. systemjs-hot-reloader now has separate logic and eventing api. Perhaps at systemjs-hot-reloader/node

mpfau commented 7 years ago

@alexisvincent Do you have an idea on how import {module} from '@hot' could work on node?

We are currently trying to run our testcases on node. They can't be run because node is not aware of '@hot', obviously...

alexisvincent commented 7 years ago

@mpfau This depends on what your tests are being transpiled to. How are you running your tests on node? (Since import from is not valid node)

mpfau commented 7 years ago

@alexisvincent found a workaround to stub @hot in node

const Module = require('module').Module;
Module._cache['@hot'] = {exports: {module: undefined}}
const resolveFilenameNode = Module._resolveFilename
Module._resolveFilename = function(request, parent, isMain) {
    if (request === '@hot') return request
    return resolveFilenameNode(request, parent, isMain)
}
alexisvincent commented 7 years ago

Very nice. Out of interest, what testing framework are you using.

mpfau commented 7 years ago

We recently switched from tape to ospec (https://github.com/lhorie/mithril.js/tree/rewrite/ospec). It has been written by the very smart Leo Horie (author of mithril).