Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 494044

Summary: Detect the proper environment: node, commonjs, requirejs,...
Product: [ECD] Orion Reporter: Olivier Thomann <Olivier_Thomann>
Component: JS ToolsAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: curtis.windatt.public, Michael_Rennie, Silenio_Quarti
Version: 11.0   
Target Milestone: 12.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 477377    

Description Olivier Thomann CLA 2016-05-19 11:53:08 EDT
We need a better way to handle the environment detection. See bug 477377.
When we have a code like this:
/*eslint-env browser, amd */

// case 1 - fails
define(function() { var b = require("xxxxb");

// case 2 - works
//define(["xxxxb"], function(b) {
	
	
	function hi () {
		console.log("hi");
	}
	b.test1("str");
	b.test2("str");
	hi();
});

We set the environments for the require call to be "node". The consequence of that is that we are doing the lookup of xxxxb as a node module instead of a file in the current folder.
Comment 1 Michael Rennie CLA 2016-05-19 12:25:13 EDT
The example is not valid requirejs - so we only think you are using node (the require call).

If however, you change the define call to be correct:

define("id", [], function() {})

or 

define([], function() {})

then we tag the AST as AMD and node - which tells us that we need to treat this like commonjs and perform a workspace lookup on the required library.
Comment 2 Michael Rennie CLA 2016-05-19 12:34:48 EDT
(In reply to Michael Rennie from comment #1)
> The example is not valid requirejs - so we only think you are using node
> (the require call).

I should have been more specific here - its not valid for us to compute dependencies - since a module with no id or dep array has none - see the docs about it: http://requirejs.org/docs/api.html#deffunc.

This is where things get a bit confusing - define is being used, with no deps, so think it is not interesting, but for the sake of getting the commonjs env guessed correctly, it looks like we should care.
Comment 4 Olivier Thomann CLA 2016-05-20 13:56:57 EDT
*** Bug 477377 has been marked as a duplicate of this bug. ***