Skip to content

Commit

Permalink
Typescript Compliance (#55)
Browse files Browse the repository at this point in the history
<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?

Are there any issues or other links reviewers should consult to
understand this pull request better? For instance:

* Fixes #12345
* See: #67890
-->
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
  • Loading branch information
kanthesha authored Mar 1, 2024
1 parent ec7b73e commit 292060c
Show file tree
Hide file tree
Showing 37 changed files with 2,263 additions and 346 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"chalk": "^4.1.2",
"dependency-graph": "^0.11.0",
"execa": "^5.1.1",
"lodash": "^4.17.21",
"superstruct": "^1.0.3",
"yargs": "^17.7.2"
},
Expand All @@ -68,6 +69,7 @@
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.66",
"@types/jest": "^28.1.6",
"@types/lodash": "^4.14.202",
"@types/node": "^16",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
Expand Down
166 changes: 141 additions & 25 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import stripAnsi from 'strip-ansi';
import { main } from './main';
import { FakeOutputLogger } from '../tests/fake-output-logger';
import type { PrimaryExecaFunction } from '../tests/helpers';
import { fakeDateOnly, withinSandbox } from '../tests/helpers';
import {
buildPackageManifestMock,
fakeDateOnly,
withinSandbox,
} from '../tests/helpers';
import { setupToolWithMockRepositories } from '../tests/setup-tool-with-mock-repositories';

jest.mock('execa');
Expand Down Expand Up @@ -70,17 +74,21 @@ describe('main', () => {
);
await writeFile(
path.join(repository.directoryPath, 'package.json'),
JSON.stringify({
packageManager: 'yarn',
engines: { node: 'test' },
buildPackageManifestMock({
devDependencies: {
eslint: '1.1.0',
test: '1.0.0',
jest: '1.0.0',
'jest-it-up': '1.0.0',
'@types/node': '1.0.0',
'ts-node': '1.0.0',
tsup: '1.0.0',
typescript: '1.0.0',
},
scripts: {
test: 'test script',
'test:watch': 'test watch script',
build: 'test build',
'build:types': 'test build types',
},
}),
);
Expand All @@ -96,6 +104,18 @@ describe('main', () => {
path.join(repository.directoryPath, 'jest.config.js'),
'content for jest.config.js',
);
await writeFile(
path.join(repository.directoryPath, 'tsconfig.json'),
'content for tsconfig.json',
);
await writeFile(
path.join(repository.directoryPath, 'tsconfig.build.json'),
'content for tsconfig.build.json',
);
await writeFile(
path.join(repository.directoryPath, 'tsup.config.ts'),
'content for tsup.config.ts',
);
}
const outputLogger = new FakeOutputLogger();

Expand All @@ -122,6 +142,14 @@ repo-1
- Do the lint-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the jest-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the test-related \`scripts\` in \`package.json\` conform? ✅
- Do the typescript-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the typescript-related \`scripts\` in \`package.json\` conform? ✅
- Does the \`exports\` field in \`package.json\` conform? ✅
- Does the \`main\` field in \`package.json\` conform? ✅
- Does the \`module\` field in \`package.json\` conform? ✅
- Does the \`types\` field in \`package.json\` conform? ✅
- Does the \`files\` field in \`package.json\` conform? ✅
- Does LavaMoat allow scripts for \`tsup>esbuild\`? ✅
- Is \`README.md\` present? ✅
- Does the README conform by recommending the correct Yarn version to install? ✅
- Does the README conform by recommending node install from nodejs.org? ✅
Expand All @@ -130,8 +158,11 @@ repo-1
- Does the \`src/\` directory exist? ✅
- Is \`.nvmrc\` present, and does it conform? ✅
- Is \`jest.config.js\` present, and does it conform? ✅
- Is \`tsconfig.json\` present, and does it conform? ✅
- Is \`tsconfig.build.json\` present, and does it conform? ✅
- Is \`tsup.config.ts\` present, and does it conform? ✅
Results: 15 passed, 0 failed, 15 total
Results: 26 passed, 0 failed, 26 total
Elapsed time: 0 ms
Expand All @@ -145,6 +176,14 @@ repo-2
- Do the lint-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the jest-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the test-related \`scripts\` in \`package.json\` conform? ✅
- Do the typescript-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the typescript-related \`scripts\` in \`package.json\` conform? ✅
- Does the \`exports\` field in \`package.json\` conform? ✅
- Does the \`main\` field in \`package.json\` conform? ✅
- Does the \`module\` field in \`package.json\` conform? ✅
- Does the \`types\` field in \`package.json\` conform? ✅
- Does the \`files\` field in \`package.json\` conform? ✅
- Does LavaMoat allow scripts for \`tsup>esbuild\`? ✅
- Is \`README.md\` present? ✅
- Does the README conform by recommending the correct Yarn version to install? ✅
- Does the README conform by recommending node install from nodejs.org? ✅
Expand All @@ -153,8 +192,11 @@ repo-2
- Does the \`src/\` directory exist? ✅
- Is \`.nvmrc\` present, and does it conform? ✅
- Is \`jest.config.js\` present, and does it conform? ✅
- Is \`tsconfig.json\` present, and does it conform? ✅
- Is \`tsconfig.build.json\` present, and does it conform? ✅
- Is \`tsup.config.ts\` present, and does it conform? ✅
Results: 15 passed, 0 failed, 15 total
Results: 26 passed, 0 failed, 26 total
Elapsed time: 0 ms
`,
Expand Down Expand Up @@ -215,8 +257,14 @@ repo-1
- \`.nvmrc\` does not exist in this project.
- Is \`jest.config.js\` present, and does it conform? ❌
- \`jest.config.js\` does not exist in this project.
Results: 0 passed, 7 failed, 7 total
- Is \`tsconfig.json\` present, and does it conform? ❌
- \`tsconfig.json\` does not exist in this project.
- Is \`tsconfig.build.json\` present, and does it conform? ❌
- \`tsconfig.build.json\` does not exist in this project.
- Is \`tsup.config.ts\` present, and does it conform? ❌
- \`tsup.config.ts\` does not exist in this project.
Results: 0 passed, 10 failed, 10 total
Elapsed time: 0 ms
Expand All @@ -239,8 +287,14 @@ repo-2
- \`.nvmrc\` does not exist in this project.
- Is \`jest.config.js\` present, and does it conform? ❌
- \`jest.config.js\` does not exist in this project.
Results: 0 passed, 7 failed, 7 total
- Is \`tsconfig.json\` present, and does it conform? ❌
- \`tsconfig.json\` does not exist in this project.
- Is \`tsconfig.build.json\` present, and does it conform? ❌
- \`tsconfig.build.json\` does not exist in this project.
- Is \`tsup.config.ts\` present, and does it conform? ❌
- \`tsup.config.ts\` does not exist in this project.
Results: 0 passed, 10 failed, 10 total
Elapsed time: 0 ms
`,
Expand Down Expand Up @@ -307,8 +361,14 @@ repo-2
- \`.nvmrc\` does not exist in this project.
- Is \`jest.config.js\` present, and does it conform? ❌
- \`jest.config.js\` does not exist in this project.
Results: 1 passed, 6 failed, 7 total
- Is \`tsconfig.json\` present, and does it conform? ❌
- \`tsconfig.json\` does not exist in this project.
- Is \`tsconfig.build.json\` present, and does it conform? ❌
- \`tsconfig.build.json\` does not exist in this project.
- Is \`tsup.config.ts\` present, and does it conform? ❌
- \`tsup.config.ts\` does not exist in this project.
Results: 1 passed, 9 failed, 10 total
Elapsed time: 0 ms
`.trimStart(),
Expand Down Expand Up @@ -361,17 +421,21 @@ Elapsed time: 0 ms
);
await writeFile(
path.join(repository.directoryPath, 'package.json'),
JSON.stringify({
packageManager: 'yarn',
engines: { node: 'test' },
buildPackageManifestMock({
devDependencies: {
eslint: '1.1.0',
test: '1.0.0',
jest: '1.0.0',
'jest-it-up': '1.0.0',
'@types/node': '1.0.0',
'ts-node': '1.0.0',
tsup: '1.0.0',
typescript: '1.0.0',
},
scripts: {
test: 'test script',
'test:watch': 'test watch script',
build: 'test build',
'build:types': 'test build types',
},
}),
);
Expand All @@ -387,6 +451,18 @@ Elapsed time: 0 ms
path.join(repository.directoryPath, 'jest.config.js'),
'content for jest.config.js',
);
await writeFile(
path.join(repository.directoryPath, 'tsconfig.json'),
'content for tsconfig.json',
);
await writeFile(
path.join(repository.directoryPath, 'tsconfig.build.json'),
'content for tsconfig.build.json',
);
await writeFile(
path.join(repository.directoryPath, 'tsup.config.ts'),
'content for tsup.config.ts',
);
}
const outputLogger = new FakeOutputLogger();

Expand All @@ -413,6 +489,14 @@ repo-1
- Do the lint-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the jest-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the test-related \`scripts\` in \`package.json\` conform? ✅
- Do the typescript-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the typescript-related \`scripts\` in \`package.json\` conform? ✅
- Does the \`exports\` field in \`package.json\` conform? ✅
- Does the \`main\` field in \`package.json\` conform? ✅
- Does the \`module\` field in \`package.json\` conform? ✅
- Does the \`types\` field in \`package.json\` conform? ✅
- Does the \`files\` field in \`package.json\` conform? ✅
- Does LavaMoat allow scripts for \`tsup>esbuild\`? ✅
- Is \`README.md\` present? ✅
- Does the README conform by recommending the correct Yarn version to install? ✅
- Does the README conform by recommending node install from nodejs.org? ✅
Expand All @@ -421,8 +505,11 @@ repo-1
- Does the \`src/\` directory exist? ✅
- Is \`.nvmrc\` present, and does it conform? ✅
- Is \`jest.config.js\` present, and does it conform? ✅
- Is \`tsconfig.json\` present, and does it conform? ✅
- Is \`tsconfig.build.json\` present, and does it conform? ✅
- Is \`tsup.config.ts\` present, and does it conform? ✅
Results: 15 passed, 0 failed, 15 total
Results: 26 passed, 0 failed, 26 total
Elapsed time: 0 ms
Expand All @@ -436,6 +523,14 @@ repo-2
- Do the lint-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the jest-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the test-related \`scripts\` in \`package.json\` conform? ✅
- Do the typescript-related \`devDependencies\` in \`package.json\` conform? ✅
- Do the typescript-related \`scripts\` in \`package.json\` conform? ✅
- Does the \`exports\` field in \`package.json\` conform? ✅
- Does the \`main\` field in \`package.json\` conform? ✅
- Does the \`module\` field in \`package.json\` conform? ✅
- Does the \`types\` field in \`package.json\` conform? ✅
- Does the \`files\` field in \`package.json\` conform? ✅
- Does LavaMoat allow scripts for \`tsup>esbuild\`? ✅
- Is \`README.md\` present? ✅
- Does the README conform by recommending the correct Yarn version to install? ✅
- Does the README conform by recommending node install from nodejs.org? ✅
Expand All @@ -444,8 +539,11 @@ repo-2
- Does the \`src/\` directory exist? ✅
- Is \`.nvmrc\` present, and does it conform? ✅
- Is \`jest.config.js\` present, and does it conform? ✅
- Is \`tsconfig.json\` present, and does it conform? ✅
- Is \`tsconfig.build.json\` present, and does it conform? ✅
- Is \`tsup.config.ts\` present, and does it conform? ✅
Results: 15 passed, 0 failed, 15 total
Results: 26 passed, 0 failed, 26 total
Elapsed time: 0 ms
`,
Expand Down Expand Up @@ -506,8 +604,14 @@ repo-1
- \`.nvmrc\` does not exist in this project.
- Is \`jest.config.js\` present, and does it conform? ❌
- \`jest.config.js\` does not exist in this project.
Results: 0 passed, 7 failed, 7 total
- Is \`tsconfig.json\` present, and does it conform? ❌
- \`tsconfig.json\` does not exist in this project.
- Is \`tsconfig.build.json\` present, and does it conform? ❌
- \`tsconfig.build.json\` does not exist in this project.
- Is \`tsup.config.ts\` present, and does it conform? ❌
- \`tsup.config.ts\` does not exist in this project.
Results: 0 passed, 10 failed, 10 total
Elapsed time: 0 ms
Expand All @@ -530,8 +634,14 @@ repo-2
- \`.nvmrc\` does not exist in this project.
- Is \`jest.config.js\` present, and does it conform? ❌
- \`jest.config.js\` does not exist in this project.
Results: 0 passed, 7 failed, 7 total
- Is \`tsconfig.json\` present, and does it conform? ❌
- \`tsconfig.json\` does not exist in this project.
- Is \`tsconfig.build.json\` present, and does it conform? ❌
- \`tsconfig.build.json\` does not exist in this project.
- Is \`tsup.config.ts\` present, and does it conform? ❌
- \`tsup.config.ts\` does not exist in this project.
Results: 0 passed, 10 failed, 10 total
Elapsed time: 0 ms
`,
Expand Down Expand Up @@ -597,8 +707,14 @@ repo-2
- \`.nvmrc\` does not exist in this project.
- Is \`jest.config.js\` present, and does it conform? ❌
- \`jest.config.js\` does not exist in this project.
Results: 1 passed, 6 failed, 7 total
- Is \`tsconfig.json\` present, and does it conform? ❌
- \`tsconfig.json\` does not exist in this project.
- Is \`tsconfig.build.json\` present, and does it conform? ❌
- \`tsconfig.build.json\` does not exist in this project.
- Is \`tsup.config.ts\` present, and does it conform? ❌
- \`tsup.config.ts\` does not exist in this project.
Results: 1 passed, 9 failed, 10 total
Elapsed time: 0 ms
`,
Expand Down
Loading

0 comments on commit 292060c

Please sign in to comment.