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

Rewrite [resolution] dependencies from lockfile version #1693

Merged
merged 93 commits into from May 20, 2022

Conversation

cristiano-belloni
Copy link
Contributor

@cristiano-belloni cristiano-belloni commented May 6, 2022

This PR adds the [resolution] tag in the CDN template to point to the pinned version as resolved from yarn.lock. Example (assuming a package.json entry of "react": "^17.0.0" and a yarn.lock resolution of 17.0.2):

EXTERNAL_CDN_TEMPLATE Re-written import in dist
"https://cdn.skypack.dev/[name]@[version]" import React from "https://cdn.skypack.dev/react@^17.0.0"
"https://cdn.skypack.dev/[name]@[resolution]" import React from "https://cdn.skypack.dev/react@17.0.2"

@changeset-bot
Copy link

changeset-bot bot commented May 6, 2022

🦋 Changeset detected

Latest commit: a8f0a22

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

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

@coveralls
Copy link
Collaborator

coveralls commented May 6, 2022

Coverage Status

Coverage decreased (-0.2%) to 26.708% when pulling a8f0a22 on feature/lockfile-driven-deps into e964c9c on main.

@cristiano-belloni cristiano-belloni changed the base branch from main to feature/esm-views May 6, 2022 18:05
@cristiano-belloni cristiano-belloni changed the title Rewrite pinned dependencies from lockfile Rewrite [resolution] dependencies from lockfile version May 9, 2022
@steveukx steveukx added this to the ESM View Support milestone May 10, 2022
Base automatically changed from feature/esm-views to main May 12, 2022 13:35
@cristiano-belloni cristiano-belloni marked this pull request as ready for review May 12, 2022 14:29
}),
{},
);
.replace('[version]', version || externalResolutions[name])
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a case where version would not be defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a case where version would not be defined?

Good question. There is at the moment, because we relaxed our criteria to only warn in case a version is nor present in (on e of the) package.json. The reason is that some widely used libraries rely on transitive dependencies (dm me for more info)

createRewriteDependenciesPlugin(
{
...dependencies,
'react-dom': dependencies.react,
Copy link
Contributor

Choose a reason for hiding this comment

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

Surely react-dom must be a dependency in the tree for starting a view to work, so we should use the resolution version from the repo in the case where react-dom is a different version to react?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -11,10 +11,21 @@ import type { Dependency } from '@schemastore/package';

type FileType = '.css' | '.js';

export const indexFile = `
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems a bit non-descript. Is this not DEFAULT_ESM_VIEW_INDEX_TEMPLATE?

const lockDeps = await buildDepTree(
// Build a dependency tree from the lockfile, using target dependencies and root dependencies in order of specificity
JSON.stringify(
Object.assign(Object.create(null), targetManifest, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe object { ...spread } might be easier to read here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is following a comment by @steveukx - there might be dependencies called as object default members.

Copy link
Contributor

Choose a reason for hiding this comment

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

This one would be fine as a { ...spread } - it wasn't in the other case because the resulting object was used with a if (key in object) check without an object.hasOwnProperty(key) filter.

Copy link
Contributor

Choose a reason for hiding this comment

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

This one would be fine as a { ...spread } - it wasn't in the other case because the resulting object was used with a if (key in object) check without an object.hasOwnProperty(key) filter.

@steveukx steveukx requested a review from cangarugula May 16, 2022 09:43
@cristiano-belloni cristiano-belloni merged commit 7c6369b into main May 20, 2022
@cristiano-belloni cristiano-belloni deleted the feature/lockfile-driven-deps branch May 20, 2022 09:31
This was referenced May 20, 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.

None yet

4 participants