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

Upgrade Rollup, its plugins, Jest and more #492

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

Andarist
Copy link
Member

For now, it's just a draft - because Rollup v3 has not been released yet as stable. It's just a PR to get ourselves ready for its release. Since Rollup v3 bumps the node version requirement - we probably should release a new major too if we want to land this right after their release.

@Andarist Andarist requested a review from emmatown August 31, 2022 12:12
@changeset-bot
Copy link

changeset-bot bot commented Aug 31, 2022

🦋 Changeset detected

Latest commit: d253cbc

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

This PR includes changesets to release 1 package
Name Type
@preconstruct/cli Major

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

@codecov
Copy link

codecov bot commented Aug 31, 2022

Codecov Report

Patch coverage: 71.42% and project coverage change: -0.24 ⚠️

Comparison is base (d2cd411) 90.75% compared to head (1bef070) 90.52%.

❗ Current head 1bef070 differs from pull request most recent head d253cbc. Consider uploading reports for the commit d253cbc to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #492      +/-   ##
==========================================
- Coverage   90.75%   90.52%   -0.24%     
==========================================
  Files          35       35              
  Lines        1547     1509      -38     
  Branches      436      428       -8     
==========================================
- Hits         1404     1366      -38     
+ Misses        137      136       -1     
- Partials        6        7       +1     
Impacted Files Coverage Δ
packages/cli/src/worker-client.ts 70.58% <ø> (ø)
packages/cli/src/rollup-plugins/resolve.ts 70.58% <50.00%> (-2.75%) ⬇️
packages/cli/src/build/config.ts 81.15% <100.00%> (ø)
packages/cli/src/build/index.ts 91.11% <100.00%> (-1.75%) ⬇️
packages/cli/test-utils/index.ts 97.81% <100.00%> (+0.40%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

{"version":3,"file":"scope-test.umd.min.js","sources":["../src/index.js"],"sourcesContent":["import { x } from \\"somewhere\\";\\nconsole.log(x);\\nexport default \\"something\\";"],"names":["console","log"],"mappings":"qOACAA,QAAQC,wBACO"}
`);
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/scope-test.umd.min.js.map ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
{"version":3,"file":"scope-test.umd.min.js","sources":["../src/index.js","../node_modules/somewhere/index.js"],"sourcesContent":["import { x } from \\"somewhere\\";\\nconsole.log(x);\\nexport default \\"something\\";","export let x = process.env.NODE_ENV;"],"names":["console","log"],"mappings":"qOACAA,QAAQC,ICD2B,oBDEpB"}
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't notice this change previously, it seems like a possible improvement though 🤔

@@ -1211,6 +1211,6 @@ test("importing css fails with a nice error", async () => {
"src/blah.css": "",
});
await expect(build(dir)).rejects.toMatchInlineSnapshot(
`[Error: 🎁 @scope/test only .ts, .tsx, .js, .jsx, and .json files can be imported but "./blah.css" is imported in "src/index.js"]`
`[Error: 🎁 @scope/test only .ts, .tsx, .js, .jsx, and .json files can be imported but "blah.css" is imported in "src/index.js"]`
Copy link
Member Author

Choose a reason for hiding this comment

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

The change is caused by the added path.relative call here: https://github.com/preconstruct/preconstruct/pull/492/files#diff-81fa7127f1a6e4820814f89af91be081857155992595217ccf33830d6116e91eR59

Right now source is already resolved - I don't know how to trace it back to how it was written in the original source code. If we can't trace it back perhaps we should add ./ to computed relative paths if they happen to be in the same directory as the importer?

expect(err.message).toMatchInlineSnapshot(
`"🎁 @imports-outside-pkg-dir/pkg-a all relative imports in a package should only import modules inside of their package directory but \\"src/index.js\\" is importing \\"../../some-file\\""`
);
expect(err.message).toMatchInlineSnapshot(`
Copy link
Member Author

Choose a reason for hiding this comment

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

this test currently fails (just like the one here) because resolveId gets called twice for the same thing (with different arguments though, one of the calls seems to see the original location of the source code and not the temp directory used in tests, so it probably has followed a symlink, OTOH testdir helper that is used there doesn't use fixture directories, it writes to temp directly, so I'm not sure what happens there yet, or maybe I've just drawn wrong conclusions and need to recheck this).

The added extension also seems related to this problem - it seems that now resolveId gets called with and without the extension. I'm not sure if something has changed in Rollup or in @rollup/plugin-node-resolve or where. We probably want to just bail out from resolution if we detect that the file lies outside of the pkg dir. It probably has been accomplished before by throwing an error but perhaps now another strategy has to be used or something

@@ -111,6 +111,7 @@ export function getRollupConfigs(pkg: Package, aliases: Aliases) {
dir: pkg.directory,
exports: "named" as const,
interop,
esModule: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

Rollup has changed the default (here) and I assume that we want to retain __esModule property

@@ -48,9 +48,6 @@ function writeOutputFile(
outputFile.map.toString()
);
}
if (outputOptions.sourcemap !== "hidden") {
Copy link
Member Author

Choose a reason for hiding this comment

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

it seems that they now emit this on their own so we don't have to append it manually

@@ -56,7 +56,10 @@ export default function flowAndNodeDevProdEntry(
if (!resolved.external && !allowedExtensionRegex.test(resolved.id)) {
warnings.push(
new FatalError(
`only .ts, .tsx, .js, .jsx, and .json files can be imported but "${source}" is imported in ${
`only .ts, .tsx, .js, .jsx, and .json files can be imported but "${path.relative(
Copy link
Member Author

Choose a reason for hiding this comment

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

both of those added path.relative calls could potentially be hoisted (the call is the same), maybe they even need to be wrapped with normalizePath but I'm not sure if that's required here yet. They might also contain a bug right now because they assume that importer is defined but according to the types (and some of the surrounding code here) it's actually nullable - the tests "pass" though and this doesn't crash. It would be good to add tests covering for the case when the importer is missing.

@emmatown emmatown mentioned this pull request Nov 9, 2022
@emmatown emmatown force-pushed the rollup-upgrade branch 3 times, most recently from 9b11d8b to d90f745 Compare April 10, 2023 05:55
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.

None yet

2 participants