Skip to content

Commit

Permalink
feat(api): proper esm support and codegen overhauls (#754)
Browse files Browse the repository at this point in the history
* feat(api): wip of proper esm support and codegen overhauls

* docs: documenting why we're exporting `createSDK` the way we are

* chore(deps): bumping ts-morph

* fix: overhauling schemas to now be stored in a `schemas/` directory

* fix: storage system didn't properly create subdirectories

* fix: broken test

* fix: flaky test in ci

* fix: bringing back some tests

* feat: refactoring codegen'd sdks to be placed into a `src/` directory

* fix: pinning installed sdk dependencies to known working versions

* fix: cjs compatibility with our `types` file being exported in `index`

* fix: removing some dead code

* fix: compatibility with node 20 on `npm run debug:bin`

* v7.0.0-alpha.5

* fix: minor `tsup` codegen fixes (#759)

* chore: minor tsconfig cleanup

* fix: point to correct api-core pkg version

* fix: install TS as dev-dep

* fix: add this to silence the JSON import warning

* refactor: slight cleanup

* Update packages/api/src/codegen/languages/typescript/index.ts

* Revert "refactor: slight cleanup"

This reverts commit 3b82df8.

* Update packages/api/test/codegen/languages/typescript/index.test.ts

Co-authored-by: Kanad Gupta <[email protected]>

* Update packages/api/test/codegen/languages/typescript/index.test.ts

Co-authored-by: Kanad Gupta <[email protected]>

* fix: pr feedback

* fix: ts ignore typo

---------

Co-authored-by: Kanad Gupta <[email protected]>
Co-authored-by: Kanad Gupta <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2023
1 parent a9618e5 commit e739d30
Show file tree
Hide file tree
Showing 246 changed files with 685 additions and 1,109 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
## 7.0.0-alpha.5 (2023-10-16)

* fix: bringing back some tests ([d33e655](https://github.com/readmeio/api/commit/d33e655))
* fix: broken test ([9ade11b](https://github.com/readmeio/api/commit/9ade11b))
* fix: cjs compatibility with our `types` file being exported in `index` ([330a3a1](https://github.com/readmeio/api/commit/330a3a1))
* fix: compatibility with node 20 on `npm run debug:bin` ([9fd0370](https://github.com/readmeio/api/commit/9fd0370))
* fix: flaky test in ci ([8e11923](https://github.com/readmeio/api/commit/8e11923))
* fix: overhauling schemas to now be stored in a `schemas/` directory ([6463a02](https://github.com/readmeio/api/commit/6463a02))
* fix: pinning installed sdk dependencies to known working versions ([d4e5d5a](https://github.com/readmeio/api/commit/d4e5d5a))
* fix: removing some dead code ([488041e](https://github.com/readmeio/api/commit/488041e))
* fix: storage system didn't properly create subdirectories ([654194e](https://github.com/readmeio/api/commit/654194e))
* fix(api): nestling generated schemas into a new `schemas/` directory (#756) ([ec74118](https://github.com/readmeio/api/commit/ec74118)), closes [#756](https://github.com/readmeio/api/issues/756)
* fix(api): storage dir not being set properly (#753) ([fa31dd4](https://github.com/readmeio/api/commit/fa31dd4)), closes [#753](https://github.com/readmeio/api/issues/753)
* feat: migrate `api` and `core` to ESM (#733) ([f65bc79](https://github.com/readmeio/api/commit/f65bc79)), closes [#733](https://github.com/readmeio/api/issues/733)
* feat: refactoring codegen'd sdks to be placed into a `src/` directory ([7d7b4cc](https://github.com/readmeio/api/commit/7d7b4cc))
* feat(api): wip of proper esm support and codegen overhauls ([8e5558d](https://github.com/readmeio/api/commit/8e5558d))
* chore(deps-dev): bump the minor-development-deps group with 4 updates (#750) ([5259bb7](https://github.com/readmeio/api/commit/5259bb7)), closes [#750](https://github.com/readmeio/api/issues/750)
* chore(deps): bump vitest from 0.34.5 to 0.34.6 (#751) ([ef4b36c](https://github.com/readmeio/api/commit/ef4b36c)), closes [#751](https://github.com/readmeio/api/issues/751)
* chore(deps): bumping ts-morph ([e2e1259](https://github.com/readmeio/api/commit/e2e1259))
* docs: documenting why we're exporting `createSDK` the way we are ([84872e6](https://github.com/readmeio/api/commit/84872e6))
* refactor: remove `make-dir` as a dep (#746) ([ab41a72](https://github.com/readmeio/api/commit/ab41a72)), closes [#746](https://github.com/readmeio/api/issues/746)
* refactor(api): minor refactors to how some internal language classes are used (#755) ([518736d](https://github.com/readmeio/api/commit/518736d)), closes [#755](https://github.com/readmeio/api/issues/755)



## 7.0.0-alpha.3 (2023-09-27)

* chore(deps): bump fetch-har (#745) ([d7a5d0c](https://github.com/readmeio/api/commit/d7a5d0c)), closes [#745](https://github.com/readmeio/api/issues/745)
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"packages": ["packages/*"],
"version": "7.0.0-alpha.3"
"version": "7.0.0-alpha.5"
}
100 changes: 59 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/api/bin/api.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
#!/usr/bin/env NODE_OPTIONS=--no-warnings node
import '../dist/bin.js';
8 changes: 4 additions & 4 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api",
"version": "7.0.0-alpha.3",
"version": "7.0.0-alpha.5",
"description": "Magical SDK generation from an OpenAPI definition 🪄",
"type": "module",
"bin": {
Expand All @@ -9,7 +9,7 @@
"scripts": {
"attw": "attw --pack --format table-flipped",
"build": "tsc",
"debug:bin": "node -r ts-node/register src/bin.ts",
"debug:bin": "node --loader ts-node/esm src/bin.ts",
"lint:types": "tsc --noEmit",
"prebuild": "rm -rf dist/; npm run version",
"prepack": "npm run build",
Expand Down Expand Up @@ -38,6 +38,7 @@
"swagger"
],
"dependencies": {
"@readme/api-core": "file:../core",
"@readme/openapi-parser": "^2.4.0",
"chalk": "^4.1.2",
"commander": "^11.0.0",
Expand All @@ -54,12 +55,11 @@
"prompts": "^2.4.2",
"semver": "^7.3.8",
"ssri": "^10.0.1",
"ts-morph": "^17.0.1",
"ts-morph": "^20.0.0",
"validate-npm-package-name": "^5.0.0"
},
"devDependencies": {
"@api/test-utils": "file:../test-utils",
"@readme/api-core": "file:../core",
"@readme/oas-examples": "^5.12.0",
"@types/js-yaml": "^4.0.5",
"@types/lodash.camelcase": "^4.3.7",
Expand Down
13 changes: 11 additions & 2 deletions packages/api/src/codegen/codegenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ export default abstract class CodeGenerator {

userAgent: string;

requiredPackages!: Record<string, { reason: string; url: string }>;
requiredPackages!: Record<
string,
{
reason: string;
url: string;
version: string;
}
>;

constructor(spec: Oas, specPath: string, identifier: string) {
this.spec = spec;
Expand Down Expand Up @@ -55,10 +62,12 @@ export default abstract class CodeGenerator {
}
}

abstract compile(): Promise<Record<string, string>>;
abstract generate(): Promise<Record<string, string>>;

abstract install(storage: Storage, opts?: InstallerOptions): Promise<void>;

abstract compile(storage: Storage, opts?: InstallerOptions): Promise<void>;

hasRequiredPackages() {
return Boolean(Object.keys(this.requiredPackages));
}
Expand Down
18 changes: 5 additions & 13 deletions packages/api/src/codegen/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import type Oas from 'oas';

import TSGenerator from './languages/typescript/index.js';

export type SupportedLanguages = 'js' | 'js-cjs' | 'js-esm' | 'ts';
export enum SupportedLanguages {
JS = 'js',
}

export default function codegenFactory(
language: SupportedLanguages,
Expand All @@ -12,18 +14,8 @@ export default function codegenFactory(
identifier: string,
): CodeGenerator {
switch (language) {
case 'js':
throw new TypeError('An export format of CommonJS or ECMAScript is required for JavaScript compilation.');

case 'js-cjs':
case 'js-esm':
case 'ts':
return new TSGenerator(spec, specPath, identifier, {
outputJS: ['js-cjs', 'js-esm'].includes(language),

// TS will always generate with ESM-like exports.
compilerTarget: language === 'js-cjs' ? 'cjs' : 'esm',
});
case SupportedLanguages.JS:
return new TSGenerator(spec, specPath, identifier);

default:
throw new TypeError(`Unsupported language supplied: ${language}`);
Expand Down
Loading

0 comments on commit e739d30

Please sign in to comment.