Skip to content

feat: added support for cjs and esm#793

Merged
erunion merged 4 commits intoreadmeio:mainfrom
PrisisForks:added-support-cjs-esm
Sep 1, 2023
Merged

feat: added support for cjs and esm#793
erunion merged 4 commits intoreadmeio:mainfrom
PrisisForks:added-support-cjs-esm

Conversation

@prisis
Copy link
Copy Markdown
Contributor

@prisis prisis commented Aug 26, 2023

🚥 Resolves #774

🧰 Changes

  • Added support for cjs and esm with tsup
  • Upgraded the node version from 14 to 16 because of the used eslint version, node 14 cant be supported (eslint-typescript use ??= syntax).

🧬 QA & Testing

Check the output for cjs and esm

@erunion erunion requested review from erunion and kanadgupta August 30, 2023 00:17
@erunion erunion added the enhancement New feature or request label Aug 30, 2023
Copy link
Copy Markdown
Member

@erunion erunion left a comment

Choose a reason for hiding this comment

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

oh wow! thanks so much for this. i'm going to wait for @kanadgupta to take a look at it before merging it in.

Copy link
Copy Markdown
Contributor

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

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

Hey thanks for this @prisis! I did some preliminary investigation and noticed a few issues below. Happy to jump in and help this get across the finish line when I'm back in office next week.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it looks like this file got converted to lockfileVersion 1, mind bumping it to v3? if you're using npm v8 or higher you should be able to run this (source):

npm i --lockfile-version 3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, had a old version of npm (using most of the time pnpm :D)

"description": "Comprehensive tooling for working with OpenAPI definitions",
"license": "MIT",
"author": "ReadMe <support@readme.io> (https://readme.com)",
"sideEffects": false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what's this for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"./package.json": "./package.json"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A lot of packages are you this export for example preact or nextjs

This can be used to support more then one version of a package

import pkg from "oas/package.json"

pkg.version....

tsup.config.ts Outdated
clean: true,
splitting: true,
shims: true,
target: tsconfig.compilerOptions.target as 'es2020',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't think this is needed. per their docs:

The value for target defaults to compilerOptions.target in your tsconfig.json

Suggested change
target: tsconfig.compilerOptions.target as 'es2020',

tsup.config.ts Outdated

export default defineConfig((options: Options) => ({
...options,
entry: ['src/index.ts'],
Copy link
Copy Markdown
Contributor

@kanadgupta kanadgupta Aug 31, 2023

Choose a reason for hiding this comment

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

not your fault here since we don't really document but this well, but we rely on a few individual non-exported files from this library over in rdme (example). i tried checking out this branch locally and npm link-ing but wasn't able to get this working (even with the changes below) so this will require some deeper investigation 😕 is there a way to get tsup to compile without bundling?

Suggested change
entry: ['src/index.ts'],
entry: ['src/index.ts', 'src/rmoas.types.ts', 'src/analyzer/index.ts', 'src/lib/reducer.ts'],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will add the operation.ts to the list too, saw it someware

Copy link
Copy Markdown
Member

@erunion erunion left a comment

Choose a reason for hiding this comment

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

amazing, thank you.

@erunion erunion merged commit d653415 into readmeio:main Sep 1, 2023
@stijnvanhulle
Copy link
Copy Markdown
Contributor

stijnvanhulle commented Sep 11, 2023

Love this!

I was just trying out the Bun test runner and noticed a bug(probably in Bun itself). Bun test was importing a d.t.s which is part of the oas-normalize package: https://github.com/readmeio/oas-normalize/blob/main/src/.sink.d.ts.

This is of course fine but then I was wondering with the change done here we only can import package.json and files in the dist folder(ESM). So why not add files or add src to the .npmIgnore file?

This will reduce the size of the package(duplicated code) and make sure that we import from dist instead of src.

Thoughts on this? @erunion @prisis

@erunion
Copy link
Copy Markdown
Member

erunion commented Sep 11, 2023

@stijnvanhulle Sure, want to submit a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for ESM

4 participants