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

feat: decouple versions from attributions file #5

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

iliapolo
Copy link
Contributor

Currently, the attributions document we generate contains version information of the dependency. For example:

** @tootallnate/[email protected] - https://www.npmjs.com/package/@tootallnate/once/v/1.1.2 | MIT

This creates some rough edges around automatic dependency upgrades. When dependencies are upgraded, the versions naturally change, this means that the attributions need to be regenerated (otherwise validation will fail). Since dependency upgrades are usually automatically approved, any changes to the attribution document are merged without human review, which goes against our best practice recommendation.

A solution could be to disable auto approval of dependency upgrades, but this creates a significant maintenance burden. In practice, we are only trying to avoid automatically merging substantial changes to the attribution document, where substantial means any change that isn't simply a version bump. (e.g license has changed, new transitive dependency added...)

The solution proposed in this PR is to split the attributions in two:

  1. A THIRD_PARTY_LICENSES file to hold license information without versions.
  2. A THIRD_PARTY_LICENSES.versions.json file that contains which versions are used for each dependency.

The THIRD_PARTY_LICENSES is checked into source control and validated as is now, but the THIRD_PARTY_LICENSES.versions.json is generated on-demand at packaging time. This way, consumers are able to distinguish between PRs that actually change license information, and ones that simply bump version numbers. They can then comprise a workflow for appropriately approving / reviewing each.

@iliapolo iliapolo requested review from rix0rrr and a team April 25, 2022 18:58
*
* @default true
*/
readonly sourcemap?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this option to be able to write deterministic snapshot tests.

.option('test', { type: 'string', desc: 'Validation command to sanity test the bundle after its created' })
.command('validate', 'Validate the package is ready for bundling', args => args
.option('fix', { type: 'boolean', default: false, alias: 'f', desc: 'Fix any fixable violations' }),
)
.command('write', 'Write the bundled version of the project to a temp directory')
.command('pack', 'Write the bundle and create the tarball')
.command('pack', 'Write the bundle and create the tarball', args => args
.option('target', { type: 'string', desc: 'Target directory of the tarball' }),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed this option was missing from the CLI, so decided to add it here since it going to be needed fairly soon.

});

const bundleDir = bundle.write();

expect(fs.existsSync(path.join(bundleDir, pkg.entrypoint))).toBeTruthy();
expect(fs.existsSync(path.join(bundleDir, 'package.json'))).toBeTruthy();
expect(fs.existsSync(path.join(bundleDir, 'THIRD_PARTY_LICENSES'))).toBeTruthy();
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 should never have been here, the tests used to mistakenly create empty attribution files, and this test specifically doesn't do validation.


expect(entrypoint).toMatchSnapshot();
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 asserts that the entry-point is actually a result of bundling


expect(entrypoint).toMatchSnapshot();
expect(Object.keys(manifest.devDependencies)).toEqual(['dep1', 'dep2']);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a missing assertion

Comment on lines -70 to -81
const attributions = [
'The consumer package includes the following third-party software/licensing:',
'',
`** ${dep1.name}@${dep1.version} - https://www.npmjs.com/package/${dep1.name}/v/${dep1.version} | MIT`,
'',
'----------------',
'',
`** ${dep2.name}@${dep2.version} - https://www.npmjs.com/package/${dep2.name}/v/${dep2.version} | Apache-2.0`,
'',
'----------------',
'',
];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of this is simply not needed, I was trying to manually create the expected attribution file so the test passes validation, instead of simply generating it as part of the test.


test('validate and fix', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed since validation with fix is now called (and asserted on) from the packing test

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.

1 participant