-
Notifications
You must be signed in to change notification settings - Fork 11
Fix syntax error in TypeScript when shape filenames contain hyphens #122
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
base: main
Are you sure you want to change the base?
Changes from all commits
1db9948
ba830f4
9044922
99b55f9
d97cb64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import loading from "loading-cli"; | |
| import { dirname } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import { forAllShapes } from "./util/forAllShapes.js"; | ||
| import toValidIdentifier from "to-valid-identifier"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of using this library to convert the identifier. Here are some examples from its readme: While "$" is a valid javascript variable name, it seems clunky. I'd rather have hyphens simply removed from the variable name.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend against removing hyphens entirely, as this risks name conflicts (e.g. if we have |
||
|
|
||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
|
|
@@ -46,6 +47,8 @@ export async function build(options: BuildOptions) { | |
| } | ||
| // Convert the content to types | ||
| const [typings, context] = await schemaConverterShex(schema); | ||
| // Convert fileName to a valid TypeScript identifier for use in generated code | ||
| const identifierName = toValidIdentifier(fileName); | ||
| await Promise.all( | ||
| ["context", "schema", "shapeTypes", "typings"].map( | ||
| async (templateName) => { | ||
|
|
@@ -54,6 +57,7 @@ export async function build(options: BuildOptions) { | |
| { | ||
| typings: typings.typings, | ||
| fileName, | ||
| identifierName, | ||
| schema: JSON.stringify(schema, null, 2), | ||
| context: JSON.stringify(context, null, 2), | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
to-valid-identifierpackage requires Node.js >=20, but this package.json doesn't specify anenginesfield to enforce this requirement. Consider adding anenginesfield to prevent installation issues on older Node.js versions. For example:This would make the requirement explicit and prevent users from encountering runtime errors when using Node.js versions below 20.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node that Node 18 is now EOL'd (https://nodejs.org/en/about/previous-releases)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
enginesfield with"node": ">=20"in d97cb64.