-
Notifications
You must be signed in to change notification settings - Fork 17
Enable non-relative imports with more node_modules granularity #19
Comments
I'll take this opportunity to document the history of the decisions that led to the current approach, before discussing your proposal :) Approach #1: no
|
Thank you for that great rundown on the history of javascript dependencies! Here are more notes on how to make this work for a project and reasoning around why it would be a good idea to have more control of the IDE Comprehension via path mapping Adding path mapping to tsconfig.json in the source would enable IDEs to resolve the module types correctly. Path mapping enables typescript to check within a list of paths when it encounters a non-relative import and resolve the path for the typings. Unlike webpack's resolve.modules it does not transpile the import to a relative import. People get pretty salty (as shown by this issue) about the lack of transpilation to realitive imports in the typescript compiler because it results in output that might not be able to resolve the modules that it compiled with. Adding path mapping to the tsconfig.json appears to carry through so that the typescript compilation will work with these rules. But if you try to run the transpiled code it will fail without something like tsconfig-paths to assist with the module resolution at runtime or adding symlinks to the modules in Consistency with popular nodejs tools Manipulating symlinks in the node_modules repository is how many of the popular nodejs tools manipulate dependencies locally. Examples of tools that manipulate symlinks in the So having a finer grained control of the symlinks in the node_modules directory would enable more compatibility with situations that people have with other tools. I think that it is also worth noting that npm is can install from a local tarball as well. ConclusionCurrently, I agree that the build directory should maintain the same structure as the source directory, but having more control over what is in I'm not sure if I understand the issues that are introduced when an engineer updates to a new package. If there are multiple JsModuleInfo providers that expose the same Please let me know if I am not making any sense :) and thanks for pointing me in the direction of that |
When I mentioned the issue about an engineer updating a package, I had in mind cases like when upgrading If I understand the plan correctly, I think it sounds good. As I've said with #6, I'm not too happy with the current approach of In terms of handling conflicts of module names, I'd rather we start by making it an error and then see whether it's actually necessary to allow overriding. I have a feeling when someone needs to override, it could be a sign that something else is wrong with how the codebase is structured maybe? In terms of implementation, are you comfortable getting your hands dirty with this? I'm happy to provide guidance and help lay out the foundations that are required. I also want to make sure you don't spend a lot of time implementing an approach that wouldn't end up being approved, so feel free to send out early WIP drafts my way. |
Yeah, the engineer should still use a package manager to manage the dependencies on their end. Makes sure that the node_modules directory is created in the workspace where the IDE expects it. I will share some WIP once I get going on this :) |
Another possible option that I have seen recently is yarn's plug-n-play. Don't know if this is ready for prime time, but could be efficient because we would not need to symlink in the node modules. The plug-n-play design would allow for generating a |
@enriched That sounds great actually. I think that feature has very high chances of becoming the de facto standard in the future, so leveraging it doesn't seems like a big risk. |
Currently these rules recreate the same folder structure as the workspace for the build and symlink to an installed
node_modules
folder . To be able to refer to modules in a non-relative way (egimport { greet } from "greeter"
rather than import { greet } from "../../../libs/shared-package/greeter" we can createnode_modules
folder with multiple hardlinks inside of it, similar to how pnpm does it.Moving forward this could also enable more fine grained control of the npm modules that are available to a build. eg:
To implement this, the existing
NpmPackagesInfo
provider will be handled by hardlinking all folders in installed_dir not starting with@
and all subfolders of folders starting with@
. Any dep with aJsLibraryInfo
provider will have itscompiled_javascript_dir
hardlinked into the node_modules directory if it has a newmodule_name
field in it (the hardlink will be named module_name).@fwouts does this proposal fit with these rules?
The text was updated successfully, but these errors were encountered: