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

Publish generator and client to npm #240

Merged
merged 37 commits into from
May 6, 2024
Merged

Publish generator and client to npm #240

merged 37 commits into from
May 6, 2024

Conversation

david-crespo
Copy link
Collaborator

@david-crespo david-crespo commented May 1, 2024

Closes #8
Closes #232

2024-05-02-deno-oxide-api-script

@david-crespo
Copy link
Collaborator Author

This is pretty close, but I'm running into an issue where the output file doesn't want to execute with node, neither the ESM or CJS one. This is from running the file directly, but I was able to get the same error with npx @oxide/openapi-gen-ts. So at least that means publishing is working.

$ ./dist/index.js
file:///Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.js:13
  throw Error('Dynamic require of "' + x + '" is not supported');
        ^

Error: Dynamic require of "util" is not supported
    at file:///Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.js:13:9
    at node_modules/@apidevtools/swagger-parser/lib/util.js (file:///Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.js:55:17)
    at __require2 (file:///Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.js:19:50)
    at node_modules/@apidevtools/swagger-parser/lib/validators/schema.js (file:///Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.js:14562:17)
    at __require2 (file:///Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.js:19:50)
    at node_modules/@apidevtools/swagger-parser/lib/index.js (file:///Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.js:19602:26)
    at __require2 (file:///Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.js:19:50)
    at file:///Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.js:19735:37
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)

Node.js v20.12.2
$ ./dist/index.cjs
/Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.cjs:383
      module.exports = Object.assign(module.exports.default, module.exports);
                              ^

TypeError: Cannot convert undefined or null to object
    at Function.assign (<anonymous>)
    at node_modules/@jsdevtools/ono/esm/index.js (/Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.cjs:383:31)
    at __init (/Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.cjs:10:56)
    at node_modules/@apidevtools/swagger-parser/lib/validators/schema.js (/Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.cjs:14560:26)
    at __require (/Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.cjs:13:50)
    at node_modules/@apidevtools/swagger-parser/lib/index.js (/Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.cjs:19599:26)
    at __require (/Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.cjs:13:50)
    at Object.<anonymous> (/Users/david/oxide/oxide.ts/packages/openapi-gen-ts/dist/index.cjs:19732:37)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)

@david-crespo
Copy link
Collaborator Author

It worked in console!

diff --git a/tools/generate_api_client.sh b/tools/generate_api_client.sh
index d6bd0d39..6779632e 100755
--- a/tools/generate_api_client.sh
+++ b/tools/generate_api_client.sh
@@ -17,7 +17,7 @@ GEN_DIR="$PWD/app/api/__generated__"
 
 SPEC_URL="https://raw.githubusercontent.com/oxidecomputer/omicron/$OMICRON_SHA/openapi/nexus.json"
 
-npx tsx ../oxide.ts/generator/index.ts $SPEC_URL $GEN_DIR
+npx @oxide/[email protected] $SPEC_URL $GEN_DIR
 npx prettier --write --log-level error "$GEN_DIR"
 
 # hack until we start pulling this from npm. we don't want this file
$ npm run gen-api

> [email protected] gen-api
> ./tools/generate_api_client.sh

++ head -n 1 OMICRON_VERSION
+ OMICRON_SHA=f3e2c929a72e5f1a6fba5243caa9ab09a76c9152
+ GEN_DIR=/Users/david/oxide/console/app/api/__generated__
+ SPEC_URL=https://raw.githubusercontent.com/oxidecomputer/omicron/f3e2c929a72e5f1a6fba5243caa9ab09a76c9152/openapi/nexus.json
+ npx @oxide/[email protected] https://raw.githubusercontent.com/oxidecomputer/omicron/f3e2c929a72e5f1a6fba5243caa9ab09a76c9152/openapi/nexus.json /Users/david/oxide/console/app/api/__generated__

> [email protected] npx
> openapi-gen-ts https://raw.githubusercontent.com/oxidecomputer/omicron/f3e2c929a72e5f1a6fba5243caa9ab09a76c9152/openapi/nexus.json /Users/david/oxide/console/app/api/__generated__

+ npx prettier --write --log-level error /Users/david/oxide/console/app/api/__generated__

> [email protected] npx
> prettier --write --log-level error /Users/david/oxide/console/app/api/__generated__

+ rm /Users/david/oxide/console/app/api/__generated__/type-test.ts
+ cat

@david-crespo
Copy link
Collaborator Author

I am about ready to merge this and tackle the linked followup issues separately.

@david-crespo david-crespo force-pushed the npm branch 3 times, most recently from dfdbe2c to 69c9165 Compare May 6, 2024 15:15
@david-crespo david-crespo merged commit a3b9d1e into main May 6, 2024
3 checks passed
@david-crespo david-crespo deleted the npm branch May 6, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make generator easier to call Publish generated client to npm
1 participant