Proposal: Package Importer and built-in Node implementation#3660
Proposal: Package Importer and built-in Node implementation#3660
Conversation
* main: [Calculation API] Fix some issues brought up during implementation (sass#3631) Bump tj-actions/changed-files from 37.0.5 to 37.1.0 (sass#3632) [Calc Functions] Match the spec's behavior better for percentages (sass#3630) Bump tj-actions/changed-files from 37.0.2 to 37.0.5 (sass#3627) Fix a reference to a dead link (sass#3625)
Co-authored-by: Ed Rivas <ed@jerivas.com>
|
One thing that might be missing in the embedded protocol is the current working directory. I suppose we want to lookup |
@ntkme Does the Containing Url proposal address this need? I think has been accepted but not implemented. |
|
The containing url proposal was to provide the containing url of a import to custom importer functions (from compiler to host). Here we're considering providing the working directory for input that does not have a url (from host to compiler). E.g. In node REPL, you can run |
|
I agree with @ntkme, we need to have some way to pass in an |
proposal/package-importer.d.ts.md
Outdated
| ```proto | ||
| message CompileRequest { | ||
| message Importer { | ||
| PackageImporter packageImporter = 14; |
There was a problem hiding this comment.
This should be a new member of the Importer.importer oneof, since it's a new type of importer. Also, it doesn't need index 14; the index just needs to be unique within the Importer record.
There was a problem hiding this comment.
Ah, right, I forgot to update to mirror the move in the JS API from a flag to a Importer object.
I updated this in 8658bc3.
For the entryPointUrl, I added a NodePackageImporter message with a string entry_point_url. The other option I considered but rejected was flattening the object with a single key into-
oneof importer {
string node_package_importer_entry_point_url = 4;
}The nested message style I went with would allow for easier future additions, but I'm fine with either option (or something else).
@ntkme Thanks for catching and explaining this- does this address the need?
|
Do we want to support loading from In node
https://nodejs.org/api/modules.html#requireresolverequest-options https://github.com/nodejs/node/blob/v20.0.0/lib/internal/modules/cjs/loader.js#L1397-L1425 |
| * Let `pkgImporter` be a [Node Package Importer] with an associated | ||
| `entryPointURL` of `require.main.filename`. |
There was a problem hiding this comment.
When running node REPL require.main is null. Node has a hack internally to make the import work by adding the working directory as the local search path:
I suppose we can set entryPointURL to file://${process.cwd()}/ (node the slash at the end is important), which will give us enough information on the compiler side.
|
My instinct is that trying to resolve from globally-installed packages will cause more headache than value for users. @alexander-akait what's the prior art here with sass-loader? Does it look for dependencies from |
proposal/package-importer.d.ts.md
Outdated
| is instantiated with an associated `entry_point_url` set to the value of | ||
| `file://${process.cwd()}/`. |
There was a problem hiding this comment.
This is confusing—if the entry_point_url is a field of the proto, isn't it up to the host to provide it rather than the spec?
There was a problem hiding this comment.
Ah, yes. Does this need to be specified elsewhere for the host, or is that not part of the spec?
There was a problem hiding this comment.
The JS host isn't part of the spec, except in that it has to follow the JS API spec.
|
Not hearing from @alexander-akait, I think the safest bet is to just not support global load paths for now. It'd be easier to add them later than it would be to remove them. @jamesnw can you add a design note documenting the rationale here? |
I added this in e733b78. ECMAScript modules (used with I suspect that Webpack would use CommonJS resolution for |
|
@nex3 I've made the changes we talked about yesterday, and this is ready for another review. Thanks! |
See #2739