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

Typescript Compliance #55

Merged
merged 12 commits into from
Mar 1, 2024
Merged

Typescript Compliance #55

merged 12 commits into from
Mar 1, 2024

Conversation

kanthesha
Copy link
Contributor

We want to make sure that for a given project:

  • The project contains a tsconfig.json file, and the content of the file matches the same file in the module template
  • The project contains a tsconfig.build.json file, and the content of the file matches the same file in the module template
  • The project contains a tsup.config.ts file, and the content of the file matches the same file in the module template
  • The project contains @types/node, ts-node, tsup, and typescript as dev dependencies, and the versions match the same dev dependencies as in the module template
  • The project contains the same build and build:types package scripts as in the module template
  • The project's package.json has an exports field, and all of the keys in exports should be present in the project's exports field and the values should match.
  • The project's package.json has a main field, and its value should match the same field in the module template.
  • The project's package.json has a module field, and its value should match the same field in the module template.
  • The project's package.json has a types field, and its value should match the same field in the module template.
  • The project's package.json has a files field, and its value should match the same field in the module template.
    If project's package.json contains a lavamoat field, and that contains allowScripts, then a tsup>esbuild property should be present and should match the same one in the module template.

Fixes #8

Copy link

socket-security bot commented Feb 16, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report↗︎

@kanthesha kanthesha marked this pull request as ready for review February 19, 2024 10:09
@kanthesha kanthesha requested a review from a team as a code owner February 19, 2024 10:09
Copy link
Collaborator

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

I forgot how many bullet points were in this ticket 😅 Good work on refactoring some of these rules. I left some suggestions on how we can simplify that code even further potentially. I need to still go through the test files and check them but this should be enough for now I imagine!

src/main.test.ts Outdated Show resolved Hide resolved
src/rules/package-engines-node-field-conforms.test.ts Outdated Show resolved Hide resolved
src/rule-helpers.ts Outdated Show resolved Hide resolved
src/rule-helpers.ts Outdated Show resolved Hide resolved
src/rule-helpers.test.ts Outdated Show resolved Hide resolved
src/rules/package-module-conform.ts Outdated Show resolved Hide resolved
src/rules/package-module-conform.ts Outdated Show resolved Hide resolved
src/rules/package-main-conform.ts Outdated Show resolved Hide resolved
src/rules/package-lavamoat-tsup-conforms.ts Show resolved Hide resolved
src/rules/package-lavamoat-tsup-conforms.ts Show resolved Hide resolved
Copy link
Collaborator

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Getting close! All of the logic looks correct to me, but I do want to make sure that the deep containment logic is being tested appropriately.

Comment on lines +587 to +595
buildPackageManifestMock(),
);
const project = buildMetaMaskRepository({
shortname: 'project',
directoryPath: path.join(sandbox.directoryPath, 'project'),
});
await writeFile(
path.join(project.directoryPath, 'package.json'),
buildPackageManifestMock(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think about adding main to the set of properties we're passing here? Same for below:

Suggested change
buildPackageManifestMock(),
);
const project = buildMetaMaskRepository({
shortname: 'project',
directoryPath: path.join(sandbox.directoryPath, 'project'),
});
await writeFile(
path.join(project.directoryPath, 'package.json'),
buildPackageManifestMock(),
buildPackageManifestMock({
main: 'main.js',
}),
);
const project = buildMetaMaskRepository({
shortname: 'project',
directoryPath: path.join(sandbox.directoryPath, 'project'),
});
await writeFile(
path.join(project.directoryPath, 'package.json'),
buildPackageManifestMock({
main: 'main.js',
}),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is already there as a default set of properties. The suggested change may make it easy for the reader to understand what we are exactly passing as a main property! But at the same time, for some, it may also confuse, when it is already there, why this test is overriding with something else, when there's no need.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose it depends on how familiar the reader is with these tests. Someone who is familiar may not feel the need, if they already know that buildPackageManifestMock includes main.js in its list of defaults. I think it will be more common that these tests will appear fresh to even us, so the easier we can make it for ourselves to understand the test, the better.

If you think it would be confusing, though, then would it work to choose a different value in this case? Something like index.js instead of main.js, perhaps.

src/rule-helpers.test.ts Outdated Show resolved Hide resolved
src/rule-helpers.test.ts Outdated Show resolved Hide resolved
src/rule-helpers.test.ts Outdated Show resolved Hide resolved
src/rule-helpers.test.ts Outdated Show resolved Hide resolved
src/rules/package-lavamoat-tsup-conforms.test.ts Outdated Show resolved Hide resolved
src/rules/package-lavamoat-tsup-conforms.test.ts Outdated Show resolved Hide resolved
src/rule-helpers.ts Outdated Show resolved Hide resolved
src/rules/package-lavamoat-tsup-conforms.ts Show resolved Hide resolved
@kanthesha kanthesha self-assigned this Feb 27, 2024
Copy link
Collaborator

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

A few more minor things. I did test this out though and everything seems to work!

src/rules/package-exports-field-conforms.ts Outdated Show resolved Hide resolved
src/rules/package-files-field-conforms.ts Outdated Show resolved Hide resolved
src/rules/package-lavamoat-tsup-conforms.ts Outdated Show resolved Hide resolved
src/rules/package-types-field-conforms.ts Outdated Show resolved Hide resolved
Copy link

socket-security bot commented Mar 1, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@types/lodash@4.14.202 None 0 862 kB types

View full report↗︎

Copy link
Collaborator

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Looks good!

@kanthesha kanthesha merged commit 292060c into main Mar 1, 2024
22 checks passed
@kanthesha kanthesha deleted the typescript-compliance branch March 1, 2024 17:15
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.

Add checks for TypeScript compliance
2 participants