Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 492688 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js (-31 / +64 lines)
Lines 331-336 define([ Link Here
331
	 * @since 12.0
363
	 * @since 12.0
332
	 */
364
	 */
333
	function _failedRead(response, fileName, err) {
365
	function _failedRead(response, fileName, err) {
366
		if (TRACE) console.log("Fail to read " + fileName + " - " + (err.error ? err.error : "<no error>"));
334
		response.args.message = err.toString();
367
		response.args.message = err.toString();
335
		response.args.error = i18nUtil.formatMessage(javascriptMessages['failedToReadFile'], fileName);
368
		response.args.error = i18nUtil.formatMessage(javascriptMessages['failedToReadFile'], fileName);
336
		ternWorker.postMessage(response);
369
		ternWorker.postMessage(response);
Lines 274-313 define([ Link Here
274
	/**
274
	/**
275
	 * @since 12.0
275
	 * @since 12.0
276
	 */
276
	 */
277
	function _nodeRead(response, filePath, fileclient) {
277
	function _nodeRead(response, moduleName, filePath, fileclient, error, depth, subModules) {
278
		var project = jsProject.getProjectPath();
278
		if (depth > 2) {
279
		if(project) {
279
			if (TRACE) console.log("Don't read '" + moduleName + "': too deep");
280
			return fileclient.read(project+"node_modules/"+filePath+"/package.json", false, false, {readIfExists: true}).then(function(json) {
280
			return _failedRead(response, moduleName, "Too deep");
281
				if(json) {
281
		}
282
					var val = JSON.parse(json);
282
		var index = filePath.lastIndexOf('/', filePath.length - 2);
283
					var mainPath = null;
283
		if (index === -1) {
284
					var main = val.main;
284
			return _failedRead(response, moduleName, error === null ? 'Could not read module ' + moduleName : error);
285
					if (main) {
285
		}
286
						if (!/(\.js)$/.test(main)) {
286
		var parentFolder = filePath.substr(0, index + 1); // include the trailing / in the folder path
287
							main += ".js";
287
		if (parentFolder === filePath) {
288
						}
288
			if (TRACE) console.log("Infinite loop reading '" + filePath);
289
						mainPath = project + "node_modules/" + filePath + "/" + main;
289
			return _failedRead(response, moduleName, "Infinite loop");
290
					} else {
290
		}
291
						main = "index.js";
291
		var modulePath = parentFolder + "node_modules/" + moduleName;
292
						mainPath = project + "node_modules/" + filePath + "/index.js";
292
		if (moduleName.indexOf('/') !== -1 && subModules) {
293
					}
293
			// module name contains /
294
					return fileclient.read(mainPath).then(function(contents) {
294
			var fileToLoad = modulePath;
295
						response.args.contents = contents;
295
			if (!/(\.js)$/.test(modulePath)) {
296
						response.args.file = mainPath;
296
				fileToLoad += ".js";
297
						response.args.path = main;
297
			}
298
						ternWorker.postMessage(response);
298
			if (!/(\.js)$/.test(modulePath)) {
299
					},
299
				fileToLoad += ".js";
300
					function(err) {
300
			}
301
						_failedRead(response, "node_modules", err);
301
			return fileclient.read(filePath).then(function(contents) {
302
					});
302
				if (contents) {
303
					response.args.contents = contents;
304
					ternWorker.postMessage(response);
305
				} else {
306
					_nodeRead(response, moduleName, filePath, fileclient, "No contents", depth, false);
303
				}
307
				}
304
				_failedRead(response, filePath, "No contents");
305
			},
308
			},
306
			function(err) {
309
			function(err) {
307
				_failedRead(response, filePath, err);
310
				_nodeRead(response, moduleName, filePath, fileclient, err, depth, false);
308
			});
311
			});
309
		} 
312
		}
310
		_failedRead(response, filePath, "No project context");
313
		return fileclient.read(modulePath+"/package.json", false, false, {readIfExists: true}).then(function(json) {
314
			if(json) {
315
				var val = JSON.parse(json);
316
				var mainPath = null;
317
				var main = val.main;
318
				if (main) {
319
					if (!/(\.js)$/.test(main)) {
320
						main += ".js";
321
					}
322
				} else {
323
					main = "index.js";
324
				}
325
				mainPath = modulePath + "/" + main;
326
				return fileclient.read(mainPath).then(function(contents) {
327
					response.args.contents = contents;
328
					response.args.file = mainPath;
329
					response.args.path = main;
330
					if (TRACE) console.log(mainPath);
331
					ternWorker.postMessage(response);
332
				},
333
				function(err) {
334
					_failedRead(response, "node_modules", err);
335
				});
336
			}
337
			_nodeRead(response, moduleName, parentFolder, fileclient, "No contents", depth + 1, true);
338
		},
339
		function(err) {
340
			// if it fails, try to parent folder
341
			_nodeRead(response, moduleName, parentFolder, fileclient, err, depth + 1, true);
342
		});
311
	}
343
	}
312
	/**
344
	/**
313
	 * @since 12.0
345
	 * @since 12.0
Lines 248-254 define([ Link Here
248
			response.args.logical = _l;
248
			response.args.logical = _l;
249
			if(request.args.file.env === 'node') {
249
			if(request.args.file.env === 'node') {
250
				if (!/^[\.]+/.test(_l)) {
250
				if (!/^[\.]+/.test(_l)) {
251
					_nodeRead(response, _l, fileClient);
251
					_nodeRead(response, _l, request.args.file.file, fileClient, null, 0, true);
252
				} else {
252
				} else {
253
					_readRelative(request, response, _l, fileClient);
253
					_readRelative(request, response, _l, fileClient);
254
				}
254
				}
(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/ternPlugins/resolver.js (-1 / +1 lines)
Lines 57-63 define([ Link Here
57
		};
57
		};
58
  		server.startAsyncAction();
58
  		server.startAsyncAction();
59
  		_resolved[key].pending = true;
59
  		_resolved[key].pending = true;
60
  		_resolved[key].timeout = setTimeout(resetPending, 5000, key);
60
  		_resolved[key].timeout = setTimeout(resetPending, 10000, key);
61
		server.options.getFile({logical: key, file: loc, env: _resolved[key].env}, function(err, _file) {
61
		server.options.getFile({logical: key, file: loc, env: _resolved[key].env}, function(err, _file) {
62
			clearTimeout(_resolved[key].timeout);
62
			clearTimeout(_resolved[key].timeout);
63
			_resolved[key].file = _file.file;
63
			_resolved[key].file = _file.file;

Return to bug 492688