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/prerender urls esm #1667

Merged
merged 9 commits into from
Mar 22, 2022
Merged

Fix/prerender urls esm #1667

merged 9 commits into from
Mar 22, 2022

Conversation

rschristian
Copy link
Member

What kind of change does this PR introduce?

Bugfix

Did you add tests for your changes?

Yes

Summary

Closes #1662

As the linked issue mentions, we require() the user's prerender-urls.js file which disallows import/export keywords. I'm guessing this used to work due to ESM not really being solidified in Node? Not entirely sure.

Fixed this by mirroring the process we already use for the user's preact.config.js files.

Does this PR introduce a breaking change?

No

@rschristian rschristian requested a review from a team as a code owner February 25, 2022 08:03
@changeset-bot
Copy link

changeset-bot bot commented Feb 25, 2022

🦋 Changeset detected

Latest commit: 4412b7d

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

This PR includes changesets to release 1 package
Name Type
preact-cli 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

Copy link
Member Author

@rschristian rschristian left a comment

Choose a reason for hiding this comment

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

One thing that might also be worth bringing up: I noticed that if a user provides a prerender-urls file, and it cannot be found or is malformed, we give a warning and move on with the default values. If the same happens for the preact.config, we throw an error and exit immediately.

Do we want to change this behavior so they match? I can't say I really have a preference for which way we go.

"jest": "^27.0.1",
"jest": "^24.9.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

Chased down the weird config file hack I introduced in #1623, turns out to be an issue in esm (the package, not the format) in Jest > v25.

Issue filed at jestjs/jest#12493, but I needed to use ESM within Jest and that hack only worked for CJS config files in our test suite. Downgrading shouldn't be problematic, so I went this route.

Comment on lines -124 to +122
if (result instanceof Array) {
if (Array.isArray(result)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why this stopped working, but probably shouldn't be using instanceof anyhow

Comment on lines -117 to -119
info(`Fetching URLs from ${config.prerenderUrls}`);
result = await result();
info(`Fetched URLs from ${config.prerenderUrls}`);
Copy link
Member Author

@rschristian rschristian Feb 25, 2022

Choose a reason for hiding this comment

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

I don't think these info messages really provided any useful information.

@rschristian rschristian force-pushed the fix/prerender-urls-esm branch from 84e5ed6 to 8732592 Compare February 25, 2022 08:16
@rschristian rschristian force-pushed the fix/prerender-urls-esm branch from 96a14f7 to 89a91dd Compare February 25, 2022 08:56
@rschristian rschristian marked this pull request as draft February 25, 2022 10:36
@rschristian rschristian marked this pull request as ready for review February 25, 2022 20:27
@rschristian
Copy link
Member Author

rschristian commented Mar 6, 2022

I was looking to add similar file handling for the babelConfig in v4 and the difference in preact config vs prerender urls was bothering me so I fixed it up here by extracting out a reusable handler for such situations.

No longer will a missing preact.config.js file result in a broken build; instead, it will continue on using the default (but printing a warning).

@rschristian rschristian force-pushed the fix/prerender-urls-esm branch from 4245c8d to 91d7501 Compare March 9, 2022 04:33
@rschristian rschristian merged commit a56d904 into master Mar 22, 2022
@rschristian rschristian deleted the fix/prerender-urls-esm branch March 22, 2022 19:40
@preact-bot preact-bot mentioned this pull request Mar 22, 2022
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.

Unexpected token export when using prerenderUrls
2 participants