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

M3-5873: Build api-v4 and validation with tsup with backwards compatibility #8484

Merged
merged 7 commits into from
Aug 11, 2022

Conversation

bnussman
Copy link
Member

@bnussman bnussman commented Aug 4, 2022

✨ Description

  • Use tsup for building @linode/api-v4 and @linode/validation

📝 Details

  • Deprecates yarn up in favor of yarn dev
  • Runs a dev server for @linode/validation so it rebuilds automatically when you are using yarn dev / yarn up
  • Changes any src/ prefixed imports in @linode/api-v4 and @linode/validation to be relative path imports (../)
    • We should do this to keeps those packages simple. Aliases can causes extra complexity and is not beneficial in small packages like ours.
  • Configure Cloud Manger's jest to use @linode/api-v4 and @linode/validation's srcinstead of lib.
    • We do this because jest was having trouble resolving exports because of its lackluster esm or exports support.
  • Type generation is handled by tsc
  • Use incremental tsc compilation for @linode/api-v4 and @linode/validation for faster typechecking
  • We are going to publish esm, commonjs, and iife as 3 bundled formats
    • This results in 3 respective index.jss for each format (excluding type files)
    • Cloud Manager consumes esm
    • Jest will consume commonjs
    • Dependencies are only bundled into the index.js file for the iife format so it is suitable for web use

🧪 How to test

  • Test all of Cloud Manager, @linode/api-v4, and @linode/validation
  • Run yarn from root dir to update dependencies
  • run rm -rf packages/api-v4/lib && rm -rf packages/validation/lib && rm packages/api-v4/index.js && rm packages/api-v4/index.d.ts && rm packages/validation/index.js && rm packages/validation/index.d.ts to clear old builds of api-v4 and validation
  • run yarn up

@bnussman bnussman self-assigned this Aug 4, 2022
@bnussman bnussman changed the title Use \tsup\ for api-v4 and validation with backwards compatibility Use tsup for api-v4 and validation with backwards compatibility Aug 4, 2022
Comment on lines +286 to +287
"@linode/api-v4/lib(.*)$": "<rootDir>/../api-v4/src/$1",
"@linode/validation/lib(.*)$": "<rootDir>/../validation/src/$1"
Copy link
Member Author

@bnussman bnussman Aug 5, 2022

Choose a reason for hiding this comment

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

This should be able to be removed after we update Jest. Newer versions of Jest support the exports values in the package.json, and hopefully Jest will pull the required commonjs files

Edit: I tested it and confirmed that a jest upgrade allows us to remove these. We can do that down the road

@bnussman bnussman changed the title Use tsup for api-v4 and validation with backwards compatibility M3-5873: Build api-v4 and validation with tsup with backwards compatibility Aug 5, 2022
Copy link
Contributor

@jdamore-linode jdamore-linode left a comment

Choose a reason for hiding this comment

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

I'm gonna finish reviewing this later, but so far I'm liking everything I see! Nice work!

@@ -2,14 +2,14 @@ import {
createDatabaseSchema,
updateDatabaseSchema,
} from '@linode/validation/lib/databases.schema';
import { BETA_API_ROOT as API_ROOT } from 'src/constants';
import { BETA_API_ROOT as API_ROOT } from '../constants';
Copy link
Contributor

Choose a reason for hiding this comment

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

No problem here, but curious why there's a need to change to relative paths -- does tsup have issues with TypeScript's path aliases? If so, is the path property in tsconfig.json still necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

tsup handled it fine, it actually was a problem with the temporary jest change above

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah that makes sense. Thanks!

"build:node": "yarn build --config webpack.node.config.js",
"start": "concurrently --raw \"tsc -w --preserveWatchOutput\" \"tsup --watch\"",
"build": "concurrently --raw \"tsc\" \"tsup\"",
"build:node": "echo not needed",
Copy link
Contributor

Choose a reason for hiding this comment

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

The only other reference I can find to build:node is in .github/workflows/ci.yml. I'll do some more searching later, but maybe we can get rid of this script altogether?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was worried our internal pipeline used it, but it appears like it does not. I'll remove it.

Copy link
Contributor

@jdamore-linode jdamore-linode left a comment

Choose a reason for hiding this comment

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

Really, really nice! Great work @bnussman

Copy link
Contributor

@DevDW DevDW left a comment

Choose a reason for hiding this comment

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

Going to finish testing this in-depth first thing tomorrow but for now I've confirmed that the app compiles and Cloud appears to be functioning well

Copy link
Contributor

@DevDW DevDW left a comment

Choose a reason for hiding this comment

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

Great job! Resurfaced a question and once this gets released, some updates will need to be made to https://www.npmjs.com/package/@linode/api-v4 and maybe https://www.npmjs.com/package/@linode/validation to keep them accurate.

"@linode/api-v4": "^0.75.0",
"@linode/validation": "0.12.0",
"@linode/api-v4": "*",
"@linode/validation": "*",
Copy link
Contributor

Choose a reason for hiding this comment

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

Going to resurface this question #8447 (comment). Were you able to find any documentation? Is yarn going to pull the correct versions as specified in the corresponding package.json files?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did a bit of looking and didn't find anything super great, but here is the docs on how versioning with the * works.

https://classic.yarnpkg.com/lang/en/docs/dependency-versions/#toc-x-ranges

I found some looking around and people say that yarn will resolve the * to the latest version of a dependency and will check a monorepo's workspaces first

https://blog.charlesloubao.com/one-line-javascript-tip-1-how-to-install-a-local/

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.

3 participants