-
Notifications
You must be signed in to change notification settings - Fork 28
feat(api): codegen'd sdks now look a little bit nicer #769
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
Conversation
| // Because we're returning the raw source files for TS generation we also need to separately | ||
| // emit out our declaration files so we can put those into a separate file in the installed | ||
| // SDK directory. | ||
| ...this.project | ||
| .emitToMemory({ emitOnlyDtsFiles: true }) | ||
| .getFiles() | ||
| .map(sourceFile => ({ | ||
| [path.basename(sourceFile.filePath)]: sourceFile.text, | ||
| })), |
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.
This is no longer used and is safe to be removed. It was a remaining artifact of the previous CJS and (attempted) ESM export work where we were generating .d.ts files ourselves.
| initializer: writer => { | ||
| // `ts-morph` doesn't have any way to cleanly create an IIFE. | ||
| writer.writeLine('(() => { return new SDK(); })()'); | ||
| writer.write('(() => { return new SDK(); })()'); |
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.
Changing this from .writeLine() to .write() fixes a quirk where the ending ; would get placed on the following line because .writeLine() terminates the thing we're writing with a \n.
const createSDK = (() => { return new SDK(); })()
;and now
const createSDK = (() => { return new SDK(); })();it's the little things
| str = str.replace(REF_PLACEHOLDER_REGEX, '$1'); | ||
|
|
||
| writer.writeLine(`${str} as const`); | ||
| writer.write(`${str} as const`); |
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.
Same as the other semicolon fix. These schemas were getting generated like the following:
const schema = {"type": "string"} as const
;They're now this:
const schema = {"type": "string"} as const;| * | ||
| * @see {@link https://ts-morph.com/manipulation/formatting} | ||
| */ | ||
| sourceFile.formatText(); |
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.
nice, TIL! kinda curious about the performance of this vs prettier vs others (but don't think we need to investigate that any time soon)
Co-authored-by: Kanad Gupta <8854718+kanadgupta@users.noreply.github.com>
🧰 Changes
This is a big changeset but the only changes that happened here are the following:
UPDATE_FIXTURES=1environment variable.ts-morph's formatting API.1Footnotes
https://ts-morph.com/manipulation/formatting ↩