Skip to content
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

fix: correctly handle entry-point path when publishing #258

Merged
merged 2 commits into from
Jan 19, 2022

Conversation

petebacondarwin
Copy link
Contributor

@petebacondarwin petebacondarwin commented Jan 18, 2022

The publish command was failing when the entry-point was specified in the wrangler.toml file and the entry-point imported another file.

This was because we were using the metafile.inputs to guess the entry-point file path. But the order in which the source-files were added to this object was not well defined, and so we could end up failing to find a match.

This fix avoids this by using the fact that the metadata.outputs object will only contain one element that has the entrypoint property - and then using that as the entry-point path. For runtime safety, we now assert that there cannot be zero or multiple such elements.

Fixes #252

@changeset-bot
Copy link

changeset-bot bot commented Jan 18, 2022

🦋 Changeset detected

Latest commit: c940680

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@threepointone
Copy link
Contributor

I introduced conflicts to your PR in #262 ,sorry!

@threepointone
Copy link
Contributor

threepointone commented Jan 19, 2022

We should land this, but I'm deeply concerned with the ambiguity we've introduced. wrangler dev can now point to either something hidden inside a wrangler.toml file somewhere, or an index.js file locally, or (not implemented yet) the main field in a parent package.json, or (not implemeted yet) the entry field in wrangler.toml, and there's no way to tell without running the command. We should resolve this before we ship to GA.

imo, we should deprecate build.upload.main, not implement the proposed entry field, and not read from package.json. We should only have explicit path in CLI.

cc @Electroid

} else {
// If the script name comes from the config, then it is relative to the wrangler.toml file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me about two hours to get my head around all these different paths. See also the bit below where we have to resolve the entryPoint paths in the metafile.outputs relative to destination.path!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

madness!

@@ -1,7 +1,8 @@
import assert from "node:assert";
import path from "node:path";
import { readFile } from "node:fs/promises";
import esbuild from "esbuild";
import * as esbuild from "esbuild";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, this change was necessary because (for some reason) the default was not being picked up when being run inside Jest...

The `publish` command was failing when the entry-point was specified in the wrangler.toml file and the entry-point imported another file.

This was because we were using the `metafile.inputs` to guess the entry-point file path. But the order in which the source-files were added to this object was not well defined, and so we could end up failing to find a match.

This fix avoids this by using the fact that the `metadata.outputs` object will only contain one element that has the `entrypoint` property - and then using that as the entry-point path. For runtime safety, we now assert that there cannot be zero or multiple such elements.

Fixes cloudflare#252
Watch the files in the wrangler workspace, and run the tests when anything changes:

```sh
> npm run test-watch -w wrangler
```

This will also run all the tests in a single process (rather than in parallel shards) and will increase the test-timeout to 50 seconds, which is helpful when debugging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrangler publish fails when ESModule is used
2 participants