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: Add language to appmap.yml #152

Merged
merged 2 commits into from
May 22, 2024
Merged

Conversation

dustinbyrne
Copy link
Contributor

By default, this is set to javascript. Any existing configurations will be migrated automatically.

- path: .
exclude:
- node_modules
Copy link
Contributor

Choose a reason for hiding this comment

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

Because appmap-node always puts this exclude entry in the generated config file, you could consider testing for the presence of “node_modules” in the config file string before performing the language fix up. Probably not needed but would add a bit of protection.

Copy link
Contributor Author

@dustinbyrne dustinbyrne May 21, 2024

Choose a reason for hiding this comment

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

It's only setting language if it's currently missing. In other words, if it's set to something like ruby, nothing will happen. Do you think we need to go beyond that?

By default, this is set to `javascript`. Any existing configurations
will be migrated automatically.
@dustinbyrne dustinbyrne force-pushed the feat/add-language-appmap-yml branch from facc4e1 to a9f37b3 Compare May 21, 2024 20:17
Comment on lines 9 to 12
exclude:
- warn
- assert # exclude because this is captured only in windows No newline at end of file
- assert # exclude because this is captured only in windows
language: javascript
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes automatically migrated during yarn jest

@dustinbyrne dustinbyrne marked this pull request as ready for review May 21, 2024 20:26

function readConfigFile(document: Document): ConfigFile {
const config = document.toJSON() as Record<string, unknown>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't do a forced coercion like that. Instead, coerce to unknown and let asserts below carve the actual type.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be fair, TypeScript doesn't provide great options for this situation. When loading data from a file, there is not much alternative to type coercion.

Copy link
Collaborator

@dividedmind dividedmind May 22, 2024

Choose a reason for hiding this comment

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

That's not true. What I suggested is literally how to do it and it works really well:

const input: unknown = JSON.parse(inputText);
assert(input && typeof input === "object");
// typescript knows input is object here
if ("key" in input && typeof input.key === "string")
  process(input.key /* TypeScript knows it's a string here! */);

Copy link
Contributor

Choose a reason for hiding this comment

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

OK but I mean, so what? If the file is somehow mangled or corrupted, it's still going to error.

import { basename, join, resolve } from "node:path";
import { cwd } from "node:process";

import { PackageJson } from "type-fest";
import YAML from "yaml";
import YAML, { Document } from "yaml";
Copy link
Collaborator

Choose a reason for hiding this comment

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

You probably only need type Document here.

YAML.stringify({
name: "test-package",
appmap_dir: "appmap",
packages: [{ path: "." }],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a test of migration with user comments, to check they're preserved?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say skip this. Let's get this out the door.

@kgilpin kgilpin merged commit 9de9ae9 into main May 22, 2024
6 checks passed
@kgilpin kgilpin deleted the feat/add-language-appmap-yml branch May 22, 2024 14:04
@appland-release
Copy link

🎉 This PR is included in version 2.23.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants