-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onResolve shouldn't change output path for entry points #945
Comments
If it’s not too much trouble to ask, can you provide a minimal reproducible repo? |
This happens because esbuild only interprets paths in the An easy solution to this is to just use the |
@evanw Your conclusions are clear and I agree with them (I read some threads about it). However, my assumption is to find the same file paths as I passed to const path = require('path');
require('esbuild').build({
entryPoints: [
'out_test/foo.js'
],
bundle: true,
outdir: 'out_test_build',
plugins: [{
name: 'example',
setup({ onResolve }) {
onResolve({ filter: /.*/ }, args => {
if (args.kind === 'entry-point') {
return {
path: path.resolve('out_test/bar.js')
};
}
});
}
}]
}); In this case I've got In short, my concern is about keeping file path for entry points, since we are looking for them in output. If entry point file paths are changing somehow (according to internal rules), there are not clue how to match input entry point files and output. Even metafile has no any mention of {
"inputs": {
"out_test/bar.js": {
"bytes": 23,
"imports": []
}
},
"outputs": {
"out_test_build/bar.js": {
"imports": [],
"exports": [],
"entryPoint": "out_test/bar.js",
"inputs": {
"out_test/bar.js": {
"bytesInOutput": 25
}
},
"bytes": 61
}
}
} I believe that |
Looks like, a case with a HTTP URLs doesn't work either: onResolve({ filter: /.*/ }, args => {
if (args.kind === 'entry-point') {
return {
namespace: 'test',
path: 'http://example.com/generate?' + args.path
};
}
});
onLoad({ namespace: 'test', filter: /.*/}, args => {
return {
// actually there should be fetch() or something like that
contents: 'console.log(' + JSON.stringify(args.path) + ')'
};
}); This example also results in the error "Two output files share the same path but have different contents". |
@evanw Caught myself thinking that maybe you meant that non-file reference might to be used in require('esbuild').build({
entryPoints: [
'unicorn',
'http://example.com/whatever'
],
...
}); That makes sense. Although this looks very exotic. Anyway, it's still unclear how |
Ah, I see. I think this sounds like a reasonable change. Unfortunately it's a breaking change so I'd like to wait for the next round of breaking changes to fix this. Along with that change, I think it would also be good to optionally support an entry point map for further flexibility, although that's another breaking API change on the Go public API side: require('esbuild').build({
entryPoints: {
'output-name-1.js': 'unicorn',
'output-name-2.js': 'http://example.com/whatever'
],
...
}); |
At the risk of this being an elaborate +1, I'd like to share my use case. I think would be resolved by #553 or the entrypoint map. A useful pattern for working with import View from "./index.svelte"
new View({
props: JSON.parse(document.getElementById('props').textContent),
target: document.getElementById('container'),
hydrate: true
}) Ideally, this JS file is a virtual entrypoint and you just have
I'm not sure the best way to solve this. In this case, these are virtual files, but since they are file-like I'd expect the output path to be I should be able to workaround this issue by appending JS to the bottom of the compiled Svelte file and being careful about scope. No virtual files needed then. One more thing is that this used to work after this issue. I'm picking this project back up so the code hasn't changed much since then 😊 Update: The workaround of appending JS to the bottom worked fine. It's cool to see how the variables get renamed but the names still match up because the renaming happens later in the pipeline. 🙂 |
By default,
esbuild
replicates file structure into the output directory. So, the following setup:Will produce a result on
outdir
:That's what we expected. However, if we're using
onResolve
for an entry point andonLoad
to generate a content this way:We get an error:
It is surprising that we can't resolve entry points to the same reference, since later its content may be loaded/generated (using
onLoad
) depending on other resolve parameters. But ok, let's keep original path and pass extra parameters throughpluginData
:In this case, we get another error:
Looks like
esbuild
is losing dir path for entry points. I triedoutbase
but it has no effect.Is this the expected behaviour?
I believe an entry point path should be untouched disregarding
onResolve
/onLoad
is used or not. Otherwise it's lead to unexpected errors. Also make hard to recognise entry points in a result, since paths are different from those which we pass toentryPoints
. As a workaround for now, we map entry point paths to an unique name (like1.js
,2.css
,3.js
etc) and re-map them back in result'soutputFiles
.The text was updated successfully, but these errors were encountered: