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

Add undist script #2474

Merged
merged 6 commits into from
Jan 14, 2025
Merged

Add undist script #2474

merged 6 commits into from
Jan 14, 2025

Conversation

jamesnw
Copy link
Collaborator

@jamesnw jamesnw commented Dec 19, 2024

As we migrate more keys to BCD, adding or changing keys will be more challenging. We essentially will need to "undist" the .dist file, and move the keys without comments over to the .yml file.

Some examples-

# Move compat_features keys to webgpu.yml
npm run undist features/webgpu.yml.dist

# It works for paths ending in ".yml", ".yml.dist" or without either
npm run undist features/lh

# It sorts the keys by default, but this can be disabled
npm run undist features/is -- --no-s

# You can add keys, either as multiple options or space separated
npm run undist features/modal -- -a new.key -a another.new.key -a multiple keys

# I'll probably run dist immediately after
npm run undist features/inert -- -a new.key; npm run dist

I'm wondering if the positional argument should be a feature id rather than a path, as this is only useful for features, and not drafts.

I opted to make this work on a single file rather than multiple to enable the add functionality, as that use case seems the most common.

@github-actions github-actions bot added the tools and infrastructure Project internal tooling, such as linters, GitHub Actions, or repo settings label Dec 19, 2024
Copy link
Collaborator

@Elchi3 Elchi3 left a comment

Choose a reason for hiding this comment

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

LGTM, this is really useful!
I have one nit where you might want to throw an error.

I'm wondering if the positional argument should be a feature id rather than a path, as this is only useful for features, and not drafts.

Yeah, I had the same feeling but given the dist script also uses paths I would go for consistency for now.

scripts/undist.ts Show resolved Hide resolved
Copy link
Collaborator

@ddbeck ddbeck left a comment

Choose a reason for hiding this comment

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

This is good. I have a few optional suggestions for you, @jamesnw. But you're welcome to merge at your discretion.

Comment on lines 43 to 44
// Accept `-a key1,key2,key3` as well as `-a key1 -a key2 -a key3`
const additions = add.flatMap((addition) => addition.split(","));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Both -a key1 key2 key3 and -a key1 -a key2 -a key3 already work. Does a comma-separated version allow for something that the other two forms don't already cover? My inclination is to not support an unusual shell notation, unless there's an explicit use case for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call- removed!

Comment on lines 29 to 38
let base = path;
if (path.endsWith(".yml.dist")) {
base = path.slice(0, -9);
} else if (path.endsWith(".yml")) {
base = path.slice(0, -4);
}
return {
yml: `${base}.yml`,
dist: `${base}.yml.dist`,
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Importing node:path could avoid some magic numbers. Something like this:

Suggested change
let base = path;
if (path.endsWith(".yml.dist")) {
base = path.slice(0, -9);
} else if (path.endsWith(".yml")) {
base = path.slice(0, -4);
}
return {
yml: `${base}.yml`,
dist: `${base}.yml.dist`,
};
const { name, ext } = path.parse(path);
const id = ext === ".dist" ? path.basename(name) : name;
return {
yml: `${id}.yml`,
dist: `${id}.yml.dist`,
};

scripts/undist.ts Outdated Show resolved Hide resolved
@jamesnw jamesnw merged commit bd9cc72 into web-platform-dx:main Jan 14, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools and infrastructure Project internal tooling, such as linters, GitHub Actions, or repo settings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants