Skip to content
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

NodeJS support #61

Open
guybedford opened this issue Feb 29, 2016 · 9 comments
Open

NodeJS support #61

guybedford opened this issue Feb 29, 2016 · 9 comments

Comments

@guybedford
Copy link
Collaborator

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
Copy link

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
Copy link

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

@AntonyBlakey
Copy link

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
Copy link
Owner

@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
Copy link
Contributor

mpfau commented Mar 16, 2017

@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
Copy link
Owner

@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
Copy link
Contributor

mpfau commented Mar 16, 2017

@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
Copy link
Owner

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

@mpfau
Copy link
Contributor

mpfau commented Mar 16, 2017

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants