Standardize mapping of browser URLs to file paths (for Resource plugins) #691
Replies: 8 comments 1 reply
-
Could maybe help and look into handling relative paths for theme packs? |
Beta Was this translation helpful? Give feedback.
-
Also wonder if plugin-user-workspace should not assume a local workspace match and be more like plugin-node-modules? So instead of const bareUrl = this.getBareUrlPath(url);
const workspaceUrl = fs.existsSync(path.join(userWorkspace, bareUrl))
? path.join(userWorkspace, bareUrl)
: path.join(userWorkspace, this.resolveRelativeUrl(userWorkspace, bareUrl)); It would be const bareUrl = this.getBareUrlPath(url);
const workspaceUrl = fs.existsSync(path.join(userWorkspace, bareUrl))
? path.join(userWorkspace, bareUrl)
: this.resolveRelativeUrl(userWorkspace, bareUrl)
? path.join(userWorkspace, this.resolveRelativeUrl(userWorkspace, bareUrl))
: bareUrl; |
Beta Was this translation helpful? Give feedback.
-
This also relates to I think to some of the rough edges encountered so far with Theme Packs, in terms of being able to straddle development vs consumption of a theme pack plugin, all while using Greenwood - #682 (comment) |
Beta Was this translation helpful? Give feedback.
-
Another thing to keep in mind is that if we are recursively walking these directories to resolve nested paths, then we might end up giving a false sense of assurance when resolving files in development, that would break for Rollup since the paths are not "exactly" correct. For example, take this structure src/
components/
posts-lists/
posts-lists.js
services/
posts-service.js In post-lists.js you could do this , which would be incorrect 🚫 import { postsService } from '../services/posts-service.js'; instead you need an additional import { postsService } from '../../services/posts-service.js'; So while this is fine during development with our resolve convenience, the first example will break though for Rollup So while it is convenient, it does have to be "right", since if it just breaks in Rollup, it would be better to break in development, too. |
Beta Was this translation helpful? Give feedback.
-
Another observation, around query string handling. As alluded to in the description of this discussion, mapping URLs to files mostly works, but things like query strings ( Perhaps running |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Found this, |
Beta Was this translation helpful? Give feedback.
-
Created an issue to take this on - #949 |
Beta Was this translation helpful? Give feedback.
-
Overview
As has come up in a couple recent issues which I believe are part a result of the fallout from #520 (changed the ordering of how default plugins run)
graph.json
always returns an ES module #604204
response #690We have a little bit of a conundrum in this particular section of code which does the bulk of the work to resolve URLs in the browser to actual files on disk for the following (in this order)
Basically given the following types of URLs
something.css?type=css
/api/events?query=something
The issues boil down to
fs.readFile('something.css?type=css
)Considerations
Query Params
graph.json
always returns an ES module #604Because of needing to support query params for API calls or appending hints for non-standard ESM, we have two options
barePathUrl
to strip query paramsAlthough solution 2 has been working, it's a bit of a "hidden" API, so not sure if there is enough docs for it, or a better way to handle this. But it avoid downstream plugins from breaking because of the file reading issue.
Resolvers
204
response #690After Greenwood resolvers go first, the results of those never get passed to next plugins, because we always pass the original URL to each resolvers, instead of saying forwarding the results of the node_modules resolver to any other resolvers that may want to reuse that logic.
There is a referenced issue to just forward the resolved URL, which seems fine for now. But there is another issue that to support relative URLs, which helps with things like #689 (comment), we have to make sure that (for example), user workspace resolver ONLY looks in the user workspaceinstead of trying to a node_modules path and reducing it down to something that might actually be in the user's workspace, by coincidence.
Not sure if we need to something like a negative resolve check to make sure user workspace isn't going to inadvertently resolve to some other legitimate resource? Otherwise, we can't always deny all possibilities, like we can since we know about node_modules
Beta Was this translation helpful? Give feedback.
All reactions