Detect CommonJS usage by exports variable only #318

Closed
wants to merge 1 commit into from

3 participants

@chrisberkhout

Because PhantomJS uses a CommonJS interface, but also has a window variable defined.

@chrisberkhout chrisberkhout Detect CommonJS usage by exports variable only (because PhantomJS use…
…s a CommonJS interface, but also has a window variable defined).
d5f60dc
@infews

Is there some docs somewhere about CommonJS for us to follow to detect this? This code seems to change every so often in pull requests and I'd like to solve this problem once and for all.

@chrisberkhout

Hi Davis,

This is quite brief but seems to be the authoritative spec:
http://www.commonjs.org/specs/modules/1.0/

The "Module Context" section mentions require and exports, but not window. The linked executable specs also don't mention window.

Adding a check on require (that it's a function) might be a more complete check of the spec-defined conditions for CommonJS modules, but I'd prefer to just check for exports, because that's all Jasmine needs when exporting itself.

If someone has browser-based code that defines a global exports that can't be used to export a module, I don't have a problem with that breaking.

What do you think?

@chrisberkhout

Later version of the same spec (same conclusion):
http://wiki.commonjs.org/wiki/Modules/1.1.1

@chrisberkhout

This slide of a presentation linked to by the spec suggests that a CommonJS-module environment may provide a window variable:
https://docs.google.com/presentation/d/1KlPxgocvzpTq44KTF4xZ6TnzGRsy628hP5he7bXVB3I/edit#slide=id.i73

@akre54

Just ran into this myself. Can we get some dev love on this? The only requirement of commonjs is a free exports object (or optionally a module with an exports property).

@infews

@akre54 are you using 2.0rc5?

@akre54

@infews I'm using 1.3.1 via grunt-contrib-jasmine. Let me check with latest.

@akre54

Just upgraded. Perfect, thanks. Maybe close this issue so others like me don't think it's still outstanding?

@infews

Per above. Closing. Thanks @akre54.

@infews infews closed this Dec 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment