Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 261620 Details for
Bug 492688
Read node_modules relative to the package.json file
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Updated patch
492688.patch (text/plain), 5.09 KB, created by
Olivier Thomann
on 2016-05-10 20:35:20 EDT
(
hide
)
Description:
Updated patch
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2016-05-10 20:35:20 EDT
Size:
5.09 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js >index cb8a7b6..39fb7f1 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js >@@ -248,7 +248,7 @@ define([ > response.args.logical = _l; > if(request.args.file.env === 'node') { > if (!/^[\.]+/.test(_l)) { >- _nodeRead(response, _l, fileClient); >+ _nodeRead(response, _l, request.args.file.file, fileClient, null, 0, true); > } else { > _readRelative(request, response, _l, fileClient); > } >@@ -331,6 +378,7 @@ define([ > * @since 12.0 > */ > function _failedRead(response, fileName, err) { >+ console.log(fileName); > response.args.message = err.toString(); > response.args.error = i18nUtil.formatMessage(javascriptMessages['failedToReadFile'], fileName); > ternWorker.postMessage(response); >@@ -274,40 +274,87 @@ define([ > /** > * @since 12.0 > */ >- function _nodeRead(response, filePath, fileclient) { >- var project = jsProject.getProjectPath(); >- if(project) { >- return fileclient.read(project+"node_modules/"+filePath+"/package.json", false, false, {readIfExists: true}).then(function(json) { >- if(json) { >- var val = JSON.parse(json); >- var mainPath = null; >- var main = val.main; >- if (main) { >- if (!/(\.js)$/.test(main)) { >- main += ".js"; >- } >- mainPath = project + "node_modules/" + filePath + "/" + main; >- } else { >- main = "index.js"; >- mainPath = project + "node_modules/" + filePath + "/index.js"; >- } >- return fileclient.read(mainPath).then(function(contents) { >- response.args.contents = contents; >- response.args.file = mainPath; >- response.args.path = main; >- ternWorker.postMessage(response); >- }, >- function(err) { >- _failedRead(response, "node_modules", err); >- }); >+ function _nodeRead(response, moduleName, filePath, fileclient, error, depth, subModules) { >+ if (depth > 2) { >+ console.log("Don't read '" + moduleName + "': too deep"); >+ return _failedRead(response, moduleName, "Too deep"); >+ } >+ var index = filePath.lastIndexOf('/', filePath.length - 2); >+ if (index === -1) { >+ return _failedRead(response, moduleName, error === null ? 'Could not read module ' + moduleName : error); >+ } >+ var parentFolder = filePath.substr(0, index + 1); // include the trailing / in the folder path >+ if (parentFolder === filePath) { >+ console.log("Infinite loop reading '" + filePath); >+ return _failedRead(response, moduleName, "Infinite loop"); >+ } >+ var modulePath = parentFolder + "node_modules/" + moduleName; >+ if (moduleName.indexOf('/') !== -1 && subModules) { >+ // module name contains / >+ var fileToLoad = modulePath; >+ if (!/(\.js)$/.test(modulePath)) { >+ fileToLoad += ".js"; >+ }/* >+ return fileclient.read(fileToLoad, false, false, {readIfExists: true}).then(function(contents) { >+ if (contents) { >+ response.args.contents = contents; >+ response.args.file = fileToLoad; >+ response.args.path = fileToLoad; >+ console.log(fileToLoad); >+ ternWorker.postMessage(response); >+ } else { >+ _nodeRead(response, moduleName, filePath, fileclient, "No contents", depth, false); > } >- _failedRead(response, filePath, "No contents"); > }, > function(err) { >- _failedRead(response, filePath, err); >+ _nodeRead(response, moduleName, filePath, fileclient, err, depth, false); >+ });*/ >+ if (!/(\.js)$/.test(modulePath)) { >+ fileToLoad += ".js"; >+ } >+ return fileclient.read(filePath).then(function(contents) { >+ if (contents) { >+ response.args.contents = contents; >+ ternWorker.postMessage(response); >+ } else { >+ _nodeRead(response, moduleName, filePath, fileclient, "No contents", depth, false); >+ } >+ }, >+ function(err) { >+ _nodeRead(response, moduleName, filePath, fileclient, err, depth, false); > }); >- } >- _failedRead(response, filePath, "No project context"); >+ } >+ return fileclient.read(modulePath+"/package.json", false, false, {readIfExists: true}).then(function(json) { >+ if(json) { >+ var val = JSON.parse(json); >+ var mainPath = null; >+ var main = val.main; >+ if (main) { >+ if (!/(\.js)$/.test(main)) { >+ main += ".js"; >+ } >+ } else { >+ main = "index.js"; >+ } >+ mainPath = modulePath + "/" + main; >+ return fileclient.read(mainPath).then(function(contents) { >+ response.args.contents = contents; >+ response.args.file = mainPath; >+ response.args.path = main; >+ console.log(mainPath); >+ ternWorker.postMessage(response); >+ }, >+ function(err) { >+ console.log("Fail to read " + mainPath); >+ _failedRead(response, "node_modules", err); >+ }); >+ } >+ _nodeRead(response, moduleName, parentFolder, fileclient, "No contents", depth + 1, true); >+ }, >+ function(err) { >+ // if it fails, try to parent folder >+ _nodeRead(response, moduleName, parentFolder, fileclient, err, depth + 1, true); >+ }); > } > /** > * @since 12.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 492688
:
261382
|
261383
|
261620
|
261765