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

Add is-node & fix is-browser-window not to check for SimpleDOM #35

Merged
merged 2 commits into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions can-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ require('./document/document');
require('./location/location');
require('./mutation-observer/mutation-observer');
require('./is-browser-window/is-browser-window');
require('./is-node/is-node');

module.exports = globals;
7 changes: 6 additions & 1 deletion is-browser-window/is-browser-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

var globals = require('can-globals/can-globals-instance');

// This module depends on isNode being defined
require('../is-node/is-node');

/**
* @module {function} can-globals/is-browser-window/is-browser-window is-browser-window
* @parent can-globals/modules
Expand All @@ -22,8 +25,10 @@ var globals = require('can-globals/can-globals-instance');
*/

globals.define('isBrowserWindow', function(){
var isNode = globals.getKeyValue('isNode');
return typeof window !== "undefined" &&
typeof document !== "undefined" && typeof SimpleDOM === "undefined";
typeof document !== "undefined" &&
isNode === false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the isNode I'm not 100% sure on long-term. I think NWJS should be considered a browser window. I'm not sure how we can sniff this out, but isNode ==== false is fine for now. We'll need something later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done-autorender has a change for when running in nwjs. I agree though, using clientWidth or something would be a better solution long-term.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened an issue to fix this long-term: #36

});

module.exports = globals.makeExport('isBrowserWindow');
10 changes: 10 additions & 0 deletions is-node/is-node-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

var QUnit = require('../../test-wrapper');
var isNode = require('./is-node');

QUnit.module("can-globals/is-node/is-node");

QUnit.test("basics", function(assert){
assert.equal(typeof isNode(), "boolean");
});
28 changes: 28 additions & 0 deletions is-node/is-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

var globals = require('can-globals/can-globals-instance');

/**
* @module {function} can-globals/is-node/is-node is-node
* @parent can-globals/modules
* @description Determines if your code is running in [Node.js](https://nodejs.org).
* @signature `isNode()`
*
* ```js
* var isNode = require("can-globals/is-node/is-node");
* var GLOBAL = require("can-globals/global/global");
*
* if(isNode()) {
* console.log(GLOBAL() === global); // -> true
* }
* ```
*
* @return {Boolean} True if running in Node.js
*/

globals.define('isNode', function(){
return typeof process === "object" &&
{}.toString.call(process) === "[object process]";
});

module.exports = globals.makeExport('isNode');
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ require('./can-globals-test');
require('./global/global-test');
require('./location/location-test');
require('./is-browser-window/is-browser-window-test');
require('./is-node/is-node-test');