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

Relax our dependency criteria #1503

Merged
merged 6 commits into from
Mar 25, 2022
Merged

Conversation

cristiano-belloni
Copy link
Contributor

@cristiano-belloni cristiano-belloni commented Mar 24, 2022

  • Allow devDependencies to be in the dependency manifest
  • Prevent throwing when generating the manifest if there are transitive deps, show a warning that this will be an error in next major

@changeset-bot
Copy link

changeset-bot bot commented Mar 24, 2022

🦋 Changeset detected

Latest commit: a1a2e8d

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 Mar 24, 2022

Coverage Status

Coverage increased (+0.05%) to 28.742% when pulling a1a2e8d on feature/relax-get-dependencies into 178796b on main.

@cristiano-belloni cristiano-belloni changed the title relax our dependency criteria Relax our dependency criteria Mar 24, 2022
const rootPackageJsonDependencies = rootManifest.dependencies || {};
const targetPackageJsonDependencies = targetManifest.dependencies || {};
const rootPackageJsonDevDependencies = rootManifest.devDependencies || {};
const targetPackageJsonDevDependencies = targetManifest.devDependencies || {};
Copy link
Contributor

@steveukx steveukx Mar 24, 2022

Choose a reason for hiding this comment

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

nit: as an option for making this a bit less verbose:

const deps = Object.assign(Object.create(null).
  targetManifest.devDependencies,
  rootManifest.devDependencies, 
  targetManifest.dependencies, 
  rootManifest.dependencies, 
);

// ...
manifest[depName] = deps[depName];
if (manifest[depName] === undefined) {
  logger.error(...);
}

Copy link
Contributor Author

@cristiano-belloni cristiano-belloni Mar 24, 2022

Choose a reason for hiding this comment

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

Done with

const deps = {
    ...rootManifest.dependencies,
    ...targetManifest.dependencies,
    ...rootManifest.devDependencies,
    ...targetManifest.devDependencies,
  };

@steveukx
Copy link
Contributor

Are there any tests of the build command that could cover this change?

@cristiano-belloni
Copy link
Contributor Author

cristiano-belloni commented Mar 24, 2022

Are there any tests of the build command that could cover this change?

We have snapshot tests for the dependency manifest, which pass without modifications because we just relaxed our criteria (so there's no change). We don't have any test of the build command failing because of some deps not in package.json (but we wouldn't need them now, since with this PR it would never fail).

rootPackageJsonDependencies[depName] ??
targetPackageJsonDevDependencies[depName] ??
rootPackageJsonDevDependencies[depName];
const depVersion = deps[depName];
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a potential prototype pollution - if the depName happens to be toString then it will be a property of deps whether it's specified or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed: using Object.assign(Object.create(null), ...) with a type assertion

@cristiano-belloni cristiano-belloni merged commit 1a39571 into main Mar 25, 2022
@cristiano-belloni cristiano-belloni deleted the feature/relax-get-dependencies branch March 25, 2022 10:59
@github-actions github-actions bot mentioned this pull request Mar 25, 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.

3 participants