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

fix: Compile each project individually #969

Merged
merged 2 commits into from
May 3, 2024
Merged

fix: Compile each project individually #969

merged 2 commits into from
May 3, 2024

Conversation

akash1810
Copy link
Member

@akash1810 akash1810 commented May 2, 2024

What does this change, and why?

The common package has a compile error:

TS2742: The inferred type of createPullRequest cannot be named without a reference to `octokit-plugin-create-pull-request/node_modules/@octokit/types`. This is likely not portable. A type annotation is necessary.

It looks like compiling at the root isn't granular enough, as the error wasn't reported during builds.

This change resolves the compilation error, and updates to compiling each project individually. Sadly, this lengthens the build time.

This was discovered as part, and is a required, of #965.

How has it been verified?

See the build logs.

@akash1810 akash1810 requested review from a team as code owners May 2, 2024 10:50
@@ -6,7 +6,8 @@
"test": "npm run test --workspaces --if-present",
"test-update": "jest -u",
"synth": "npm run synth --workspace=cdk",
"typecheck": "tsc",
"pretypecheck": "npm -w common run typecheck",
"typecheck": "npm run typecheck --workspaces",
Copy link
Member Author

Choose a reason for hiding this comment

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

Its worth noting we were previously compiling each project individually (see #520). The difference now though is we're not using the --if-present flag, so the concerns mentioned in #520 do not hold.

@@ -6,7 +6,8 @@
"test": "npm run test --workspaces --if-present",
"test-update": "jest -u",
"synth": "npm run synth --workspace=cdk",
"typecheck": "tsc",
"pretypecheck": "npm -w common run typecheck",
Copy link
Member Author

Choose a reason for hiding this comment

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

pretypecheck will always run before typecheck see https://docs.npmjs.com/cli/v10/using-npm/scripts#pre--post-scripts. We need to compile the shared package first, as other projects depend on it, and it doesn't look like TypeScript understands this dependency.

@@ -4,7 +4,8 @@
"type": "module",
"scripts": {
"postinstall": "prisma generate",
"test": "jest --detectOpenHandles --config ../../jest.config.js --selectProjects common"
"test": "jest --detectOpenHandles --config ../../jest.config.js --selectProjects common",
"typecheck": "tsc"
Copy link
Member Author

Choose a reason for hiding this comment

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

When compiling the common package, write the resulting files to disk (i.e. no --noEmit flag), so that it can be used by the other projects during their compile.

@@ -3,7 +3,8 @@
"version": "0.0.0",
"scripts": {
"start": "./script/start",
"test": "find . | egrep '.yml|.yaml' | xargs yamllint"
"test": "find . | egrep '.yml|.yaml' | xargs yamllint",
"typecheck": "echo 'Nothing to typecheck'"
Copy link
Member Author

Choose a reason for hiding this comment

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

This package has no TypeScript code, so there's nothing to do.

@@ -4,7 +4,8 @@
"description": "Diagrams as code",
"type": "module",
"scripts": {
"generate": "mmdc -i diagram.mmd -o output.svg "
"generate": "mmdc -i diagram.mmd -o output.svg ",
"typecheck": "echo 'Nothing to typecheck'"
Copy link
Member Author

Choose a reason for hiding this comment

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

This package has no TypeScript code, so there's nothing to do.

akash1810 added 2 commits May 3, 2024 09:53
The `common` package has a compile error:

```
TS2742: The inferred type of createPullRequest cannot be named without a reference to `octokit-plugin-create-pull-request/node_modules/@octokit/types`. This is likely not portable. A type annotation is necessary.
```

It looks like compiling at the root isn't granular enough, as the error wasn't reported during builds.

This change updates to compiling each project individually, so that we catch such issues at CI.
There is a compilation error currently:

```
TS2742: The inferred type of createPullRequest cannot be named without a reference to `octokit-plugin-create-pull-request/node_modules/@octokit/types`. This is likely not portable. A type annotation is necessary.
```

The return type of `composeCreatePullRequest` is a bit tricky to infer.

We're (currently) only using the `html_url` property, so update `createPullRequest` to return that,
and therefore the return type of `createPullRequest` becomes `Promise<string | undefined>`.
@@ -46,6 +52,8 @@ export async function createPullRequest(
files,
})),
});

return response?.data.html_url;
Copy link
Member Author

@akash1810 akash1810 May 3, 2024

Choose a reason for hiding this comment

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

This is the main change here, and resolves the compilation error in the PR description.

The return type of composeCreatePullRequest is a bit tricky to infer. As we're (currently) only using the html_url property, update createPullRequest to return that, and therefore the return type of createPullRequest becomes Promise<string | undefined>.

export async function createPullRequest(
octokit: Octokit,
{
props: CreatePullRequestOptions,
Copy link
Member Author

@akash1810 akash1810 May 3, 2024

Choose a reason for hiding this comment

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

This change moves the object destructing out of the function signature, in an attempt to improve readability. This is totally subjective though!

Copy link
Contributor

@NovemberTang NovemberTang left a comment

Choose a reason for hiding this comment

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

Is it worth doing a test run of snyk-integrator to make sure it still behaves as expected?

@akash1810
Copy link
Member Author

akash1810 commented May 3, 2024

Is it worth doing a test run of snyk-integrator to make sure it still behaves as expected?

Absolutely! How? Is createPullRequest called on CODE, as IIUC CODE doesn't raise PRs? Is there a switch to toggle to change this?

@NovemberTang
Copy link
Contributor

Is it worth doing a test run of snyk-integrator to make sure it still behaves as expected?

Absolutely! How? Is createPullRequest called on CODE, as IIUC CODE doesn't raise PRs? Is there a switch to toggle to change this?

Yeah there's a couple of ways to do this. You can either:

  • Temporarily modify the Stage env var in the console to from CODE to PROD, bypassing the flag
  • Deploy your branch to PROD
  • Remove the stage awareness in the source code, build it, and paste it into the text editor in the console

@akash1810
Copy link
Member Author

akash1810 commented May 3, 2024

  • Deploy your branch to PROD

I've done this, with a resulting PR of #976.

@NovemberTang and I have been discussing the snyk-integrator over chat. Here's a summary for others:

In general, masquerading as PROD should be avoided as there are potentially unknown side-effects. For example, imagine there are multiple stage aware branches in the application, we'll trigger all of them when only wanting to test one. Testing on PROD isn't ideal, for similar reasons.

Mutating the lambda within the AWS console should also be avoided, as it removes the audit trail, and introduces elements of human error. Updating the lambda with a traditional deployment means all the CI checks have passed, increasing confidence.

In this specific scenario, only one piece of the application is stage aware, and that is the part we are wanting to test. Whilst there are opportunities to refactor parts of the code to create more pure functions, it is most pragmatic to test on PROD, as this PR unblocks others. We will make the refactors in follow up PRs.

@akash1810 akash1810 merged commit de489ad into main May 3, 2024
2 checks passed
@akash1810 akash1810 deleted the aa/tsc branch May 3, 2024 13:36
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.

2 participants