-
Notifications
You must be signed in to change notification settings - Fork 15
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
Update the packaging to split the bundles into esmodule and commonjs #55
Changes from all commits
ce140d0
690d076
2b3c81b
093bb7c
8655ea2
5eac38f
6240ed4
8582416
a0c6d89
0948633
f2cd08d
29f9a8b
1d9f48c
c3787d8
fa552d3
1aa8081
25ed3c3
344670c
26e4756
bced3d6
6921be4
bab4eab
d2bef72
8b81f99
11f5318
5e5a30a
d641fd9
1838118
f3b8215
67e61dd
d44851a
dd584ed
162873c
8709eb7
7ba8214
0647405
d103a04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,7 @@ Thumbs.db | |
|
||
# secrets | ||
graphqlHeaders.json | ||
|
||
# bundling | ||
.rollup.cache/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,5 +56,6 @@ | |
"!{projectRoot}/tsconfig.spec.json", | ||
"!{projectRoot}/jest.config.[jt]s" | ||
] | ||
} | ||
}, | ||
"neverConnectToCloud": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
QUICKNODE_GRAPH_API_KEY=replaceme |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
QUICKNODE_GQL_API_KEY=replaceme | ||
QUICKNODE_GRAPH_API_KEY=replaceme | ||
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
overwrite: true | ||
documents: | ||
- src/**/*.gql | ||
- src/**/!(*.d).{ts,tsx} | ||
schema: | ||
- https://api.quicknode.com/graphql: | ||
headers: | ||
content-type: application/json | ||
x-api-key: '${QUICKNODE_GRAPH_API_KEY}' | ||
generates: | ||
src/api/graphql/generatedTypes.ts: | ||
plugins: | ||
- typescript | ||
- typescript-operations | ||
- typed-document-node | ||
config: | ||
namingConvention: ./codegenCustomNaming.cjs | ||
exportFragmentSpreadSubTypes: true | ||
inlineFragmentTypes: combine | ||
fragmentMasking: false | ||
src/api/graphql/fragmentMatcher.ts: | ||
plugins: | ||
- fragment-matcher | ||
src/api/graphql/schema.json: | ||
plugins: | ||
- introspection |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,13 @@ | |
}, | ||
"license": "MIT", | ||
"version": "1.0.0-alpha.0", | ||
"main": "./src/index.js", | ||
"module": "./src/index.esm.js", | ||
"types": "./src/index.d.ts", | ||
"main": "./cjs/index.js", | ||
"module": "./esm/index.js", | ||
"types": "./index.d.ts", | ||
"dependencies": { | ||
"@urql/core": "^4.0.7", | ||
"@urql/exchange-graphcache": "^6.0.4", | ||
"cross-fetch": "^3.1.6", | ||
"graphql": "^16.5.0" | ||
"cross-fetch": "^3.1.6" | ||
}, | ||
"devDependencies": { | ||
"@graphql-codegen/cli": "2.13.8", | ||
|
@@ -30,10 +29,18 @@ | |
"@types/mocha": "^10.0.1", | ||
"@types/node": "^18.13.0", | ||
"@types/supertest": "^2.0.12", | ||
"dotenv": "^16.0.3", | ||
"eslint-plugin-no-only-tests": "^3.1.0", | ||
"graphql": "^16.6.0", | ||
"supertest": "^6.2.4" | ||
}, | ||
"scripts": { | ||
"codegen": "graphql-codegen --config codegen.ts" | ||
"codegen": "graphql-codegen --require dotenv/config" | ||
}, | ||
"exports": { | ||
".": { | ||
"import": "./esm/index.js", | ||
"require": "./cjs/index.js" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the part that dynamically will import the correct bundle based on whether the package is imported with |
||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import typescript from '@rollup/plugin-typescript'; | ||
import copy from 'rollup-plugin-copy'; | ||
import externals from 'rollup-plugin-node-externals'; | ||
import dts from 'rollup-plugin-dts'; | ||
import json from '@rollup/plugin-json'; | ||
import path from 'path'; | ||
import { URL } from 'url'; | ||
|
||
// esm patch for __dirname | ||
const __dirname = new URL('.', import.meta.url).pathname; | ||
const rootDir = path.resolve(__dirname); | ||
const toAbsoluteDir = (relativeDir) => path.resolve(rootDir, relativeDir); | ||
|
||
const bundle = (config) => ({ | ||
input: toAbsoluteDir('./src/index.ts'), | ||
...config, | ||
}); | ||
|
||
// The shared rollup plugins for esm and cjs bundles | ||
const sharedPlugins = [ | ||
externals(), // Exclude node_modules from bundle | ||
json({ compact: true }), | ||
typescript({ | ||
tsconfig: toAbsoluteDir('tsconfig.lib.json'), | ||
}), | ||
]; | ||
|
||
export default [ | ||
bundle({ | ||
output: { | ||
file: 'dist/packages/libs/sdk/esm/index.js', | ||
format: 'esm', | ||
}, | ||
plugins: [...sharedPlugins], | ||
}), | ||
bundle({ | ||
output: { | ||
file: 'dist/packages/libs/sdk/cjs/index.js', | ||
format: 'cjs', | ||
exports: 'named', | ||
}, | ||
plugins: [ | ||
...sharedPlugins, | ||
copy({ | ||
targets: [ | ||
{ | ||
src: [toAbsoluteDir('README.md'), toAbsoluteDir('package.json')], | ||
dest: 'dist/packages/libs/sdk/', | ||
}, | ||
], | ||
}), | ||
], | ||
}), | ||
bundle({ | ||
plugins: [ | ||
dts({ | ||
input: toAbsoluteDir('./src/index.ts'), | ||
}), | ||
], // Rollup the .d.ts files | ||
output: { | ||
file: 'dist/packages/libs/sdk/index.d.ts', | ||
format: 'es', | ||
}, | ||
}), | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { API } from '../../src'; | ||
|
||
const opts: Record<string, any> = { | ||
graphApiKey: process.env['QUICKNODE_GQL_API_KEY'] || '', | ||
graphApiKey: process.env['QUICKNODE_GRAPH_API_KEY'] || '', | ||
}; | ||
|
||
export const apiClient = new API(opts); |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not ideal but I had to add this back, it was removed in #56 because I thought we no longer needed it. I'm seeing this error, if I re-record the failing tests it will show up on other previously passing tests. This was similar to the apollo errors I saw that required this, IIRC it basically came down to race conditions because of the speed at the tests are executed. Can look into it more when I get a chance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Getting the actual error, it's the same as the one I ran into with Apollo, I have to dig into it a bit more of the why here, it could have something to do with the http request mocking
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// @ts-ignore | ||
afterEach(async () => { | ||
// pause after tests to avoid race conditions | ||
await new Promise((resolve) => setTimeout(resolve, 100)); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,7 +159,7 @@ export class NftsController { | |
private async getByWalletAddress( | ||
variables: WalletNFTsByAddressQueryVariablesType & NonQueryInput | ||
): Promise<WalletNFTsByAddressFormattedResult> { | ||
const { chain, contractAddresses, ...queryVariables } = variables; | ||
const { chain, ...queryVariables } = variables; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a small change that I missed from 42a6627, I noticed in the intellisense options when testing out the built package |
||
const userChain = chain || this.defaultChain; | ||
const query: Record<ChainName, TypedDocumentNode<any, any>> = { | ||
ethereum: CodegenEthMainnetWalletNFTsByAddressDocument, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just updated the name here and in the docs and code for consistency