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

feat(permit): refactor permit-utils package #3258

Merged
merged 45 commits into from
Oct 27, 2023
Merged

Conversation

alfetopito
Copy link
Collaborator

@alfetopito alfetopito commented Oct 20, 2023

Summary

Refactoring permit fns into an isolated lib.

Removed all internal dependencies to have the lib isolated:
image

This lib is also to be published to npm in my personal account for now https://www.npmjs.com/package/alfetopito-permit-utils?activeTab=code

TODO:

  • Add GH action to publish libs - need devops/Anxo help with permissions, will be done in another PR

To Test

  1. Permit should work as before

@vercel
Copy link

vercel bot commented Oct 20, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
swap-dev ✅ Ready (Inspect) Visit Preview Oct 27, 2023 4:52pm

🌃 Cosmos ↗︎

@socket-security
Copy link

socket-security bot commented Oct 20, 2023

Updated dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@1inch/permit-signed-approvals-utils 1.4.8...1.4.10 None +48/-12 18.6 MB 1inch-robot
@cowprotocol/app-data 1.1.0-RC.0...1.1.0 None +2/-1 199 kB cowprotocol_dev

Comment on lines +2 to +3
"name": "@cowprotocol/permit-utils",
"version": "0.0.1-RC.0",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These fields define the final npm package.

Comment on lines +14 to +16
"publish": {
"command": "node tools/scripts/publish.mjs permit-utils {args.tag} {args.otp}",
"dependsOn": ["build"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Command used to publish:

npx nx run permit-utils:publish [--tag <tag>] [--otp <otp>]

Right now published to my personal account with a different package name https://www.npmjs.com/package/alfetopito-permit-utils?activeTab=code

Comment on lines 1 to 6
export { checkIsCallDataAValidPermit } from './lib/checkIsCallDataAValidPermit'
export { generatePermitHook } from './lib/generatePermitHook'
export { getPermitUtilsInstance } from './lib/getPermitUtilsInstance'
export { getTokenPermitInfo } from './lib/getTokenPermitInfo'

export type { PermitHookData, PermitHookParams, PermitInfo, PermitType, SupportedPermitInfo } from './types'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lib interface

@@ -1,11 +1,9 @@
import { GP_VAULT_RELAYER } from '@cowprotocol/common-const'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove all internal cross dependencies

package.json Outdated Show resolved Hide resolved
Comment on lines +30 to +38
// Fetch the version from "package.json" before publishing
let version
try {
const json = JSON.parse(readFileSync(`package.json`).toString())
version = json.version
} catch (e) {
console.error(chalk.bold.red(`Error reading package.json file from library build output.`))
process.exit(1)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed the default publish command to use the package's version rathern than updating it based on cli param


// Execute "npm publish" to publish
const publishCommand = `npm publish --access public --tag ${tag === 'undefined' ? 'next' : tag}`
const publishCommand = `npm publish --access public --tag ${tag === 'undefined' ? 'next' : tag} ${otp? `--otp ${otp}`:''}`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Optional opt param, as I needed to publish it locally under my account.
Shouldn't be needed when moving this over to CI 🤞

project.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Collaborator

@shoom3301 shoom3301 left a comment

Choose a reason for hiding this comment

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

Haven't tested, but code looks good!

Comment on lines +5 to +10
"dependencies": {
"ethers": "^5.7.2",
"@1inch/permit-signed-approvals-utils": "^1.4.10",
"@cowprotocol/app-data": "^1.1.0",
"tslib": "^2.6.1"
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Had to duplicate the dependencies here so package consumers install them too

Comment on lines +11 to +19
"module": "./index.js",
"main": "./index.cjs",
"exports": {
".": {
"import": "./index.js",
"require": "./index.cjs"
}
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is so package can be consumed either the ES way (index.js) or CommonJS way (index.cjs)

},
rollupOptions: {
// External packages that should not be bundled into your library.
external: [/@1inch/, /@cowprotocol/, /@ethersproject/],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Explicitly removing third party dependencies to not have them included in the bundle.
They are instead added as part of package.json dependencies.

@alfetopito alfetopito merged commit 28ea672 into develop Oct 27, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 27, 2023
@alfetopito alfetopito deleted the permit/export-package branch October 30, 2023 09:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants