GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Load JavaScript modules from Node packages by billti · Pull Request #7075 · microsoft/TypeScript Conversation
Member
I'm not looking to push this now, but opening for discussion on both a) the approach in the implementation, and b) some design questions it raises. This change would allow for the loading of JavaScript modules from a search of top level Node packages. This could be useful in TypeScript, but is especially useful in editing JavaScript. To avoid transitively loading 100s of JavaScript files from an NPM installed dependency graph, this sets a limit on how deep in the dependency chain to crawl (which only applies to JavaScript, not TypeScript files). For example, if In order to avoid recompiling/overwriting JavaScript files installed under Vladimir Matveev (@vladima) The approach below no longer modifies the
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
This was referenced
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea here is that looking up the fist 2 chars is cheeper than running a regexp. is there a reason why we need to change it?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
Mohamed Hegazy (@mhegazy) This should be pretty comprehensive now. It tracks if a JavaScript file was loaded from searching node_modules so it knows not to compile it (a minor tweak to this logic could also solve #6964 if desired). It also tracks if a module has some imports skipped, so that if the same module is later processed higher up the import graph it will re-processes the imports. I added a few project tests to test a) the eliding once the max depth is reached,b) increasing the depth via the config option, and c) the reprocessing of imports if a module is later imported higher up the chain. I used Project tests as with baselines its hard to add files that exist but aren't root files (as the files under node_modules need to be imported but not root files). The project tests also contain useful info about what files were input, resolved, and output. Let me know if you have any other suggestions for improvements. p.s. I had to fix a regular expression to get the Project tests working with the .js files (else it was putting a full path from my machine in the error baselines), but that did change a lot of other baselines (for the better). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /// <reference types="alpha" /> | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| !!! message TS4090: Conflicting library definitions for 'alpha' found at 'index.d.ts' and 'index.d.ts'. Copy the correct file to the 'typings' folder to resolve this conflict. | ||
| !!! message TS4090: Conflicting library definitions for 'alpha' found at '/node_modules/bar/node_modules/alpha/index.d.ts' and '/node_modules/foo/node_modules/alpha/index.d.ts'. Copy the correct file to the 'typings' folder to resolve this conflict. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixing the regular expression makes messages such as this useful.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
How about this change? Note that I'm using a Map for the collection of file names as this seems quicker on large projects with lots of modules from node_modules, than using a array of file paths and scanning this every time to check for existence (and splicing when I need to remove an entry). I could use a simple string[] if that seems cleaner, but this works well currently. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I would have preferred a function that takes a file path and returns a boolean. but this is fine too. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
can you mark this as |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Like so? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The build is taking forever :-/ I'm sure it'll pass... but waiting as a precaution. I'll port and merge this to release-2.0 also unless you have any objections. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
no objections. thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.