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: bundle packages to be Ecmascript modules (T-186) #64

Merged
merged 8 commits into from Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/nextjs/next.config.js
@@ -1,6 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
// Until the @apollo-client fixes the ESM modules support (https://github.com/apollographql/apollo-feature-requests/issues/287)
// it's required to either transpile the `@lens-protocol` packages or make sure they won't get `imported` during SSR.
transpilePackages: ['@lens-protocol/react', '@lens-protocol/wagmi'],
};

module.exports = nextConfig;
5 changes: 1 addition & 4 deletions examples/web-wagmi/src/profiles/components/ProfileCard.tsx
@@ -1,5 +1,4 @@
import { ProfileFieldsFragment } from '@lens-protocol/react';
import { Link } from 'react-router-dom';

import { ProfilePicture } from './ProfilePicture';

Expand All @@ -10,9 +9,7 @@ type ProfileCardProps = {
export function ProfileCard({ profile }: ProfileCardProps) {
return (
<article>
<Link to={`/profile/handle/${profile.handle}`}>
<ProfilePicture picture={profile.picture} />
</Link>
<ProfilePicture picture={profile.picture} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no support, for now, to provide route param with the handle so it was pointing to a nonexisting route.

<p>Handle: {profile?.handle}</p>
<p>Name: {profile?.name}</p>
<p>Bio: {profile?.bio}</p>
Expand Down
@@ -1,5 +1,4 @@
import { CommentFragment, MirrorFragment, PostFragment } from '@lens-protocol/react';
import { Link } from 'react-router-dom';

import { ProfilePicture } from '../../profiles/components/ProfilePicture';

Expand All @@ -10,9 +9,7 @@ type PublicationProps = {
export function PublicationCard({ publication }: PublicationProps) {
return (
<article>
<Link to={`/profile/handle/${publication.profile.handle}`}>
<ProfilePicture picture={publication.profile.picture} />
</Link>
<ProfilePicture picture={publication.profile.picture} />
<p>{publication.profile.name ?? `@${publication.profile.handle}`}</p>
<p>{publication.metadata.content}</p>
</article>
Expand Down
2 changes: 1 addition & 1 deletion examples/web-wagmi/tsconfig.json
Expand Up @@ -3,7 +3,7 @@
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"allowJs": true,
Copy link
Member

Choose a reason for hiding this comment

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

Is this intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All changes to the package.json in src/packages are intentional, this one is just making everything in sync across all tsconfig.

"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/api-bindings/mocks/package.json
@@ -1,4 +1,4 @@
{
"type": "module",
"main": "../dist/esm/mocks.js"
"main": "../dist/mocks.js"
}
34 changes: 11 additions & 23 deletions packages/api-bindings/package.json
Expand Up @@ -10,37 +10,24 @@
"type": "module",
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./mocks": {
"import": {
"types": "./dist/esm/mocks.d.ts",
"default": "./dist/esm/mocks.js"
},
"require": {
"types": "./dist/cjs/mocks.d.ts",
"default": "./dist/cjs/mocks.js"
}
}
"types": "./dist/mocks.d.ts",
"default": "./dist/mocks.js"
},
"./package.json": "./package.json"
},
"types": "./dist/cjs/index.d.ts",
"main": "./dist/cjs/index.js",
"types": "./dist/index.d.ts",
"main": "./dist/index.js",
"sideEffects": false,
"files": [
"dist/**/*",
"mocks"
],
"scripts": {
"build:cjs": "tsc -p ./tsconfig.build-cjs.json",
"build:esm": "tsc -p ./tsconfig.build.json",
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs",
"build": "pnpm clean && tsup",
"clean": "rimraf ./dist",
"test": "jest --passWithNoTests",
"eslint:fix": "pnpm run eslint --fix",
Expand Down Expand Up @@ -79,7 +66,8 @@
"jest": "^29.3.1",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.3",
"typescript": "^4.9.3"
"typescript": "^4.9.3",
"tsup": "^6.5.0"
},
"prettier": "@lens-protocol/prettier-config"
}
8 changes: 0 additions & 8 deletions packages/api-bindings/tsconfig.build-cjs.json

This file was deleted.

9 changes: 0 additions & 9 deletions packages/api-bindings/tsconfig.build.json

This file was deleted.

14 changes: 14 additions & 0 deletions packages/api-bindings/tsup.config.ts
@@ -0,0 +1,14 @@
import { defineConfig } from 'tsup';

import { dependencies, devDependencies } from './package.json';

export default defineConfig({
entry: ['src/index.ts', 'src/mocks.ts'],
format: ['esm'],
dts: true,
external: [
...Object.keys(dependencies),
// required to not bundle `jest` into exported mocks
...Object.keys(devDependencies),
],
});
2 changes: 1 addition & 1 deletion packages/domain/entities/package.json
@@ -1,4 +1,4 @@
{
"type": "module",
"main": "../dist/esm/entities/index.js"
"main": "../dist/entities/index.js"
}
3 changes: 2 additions & 1 deletion packages/domain/jest.config.js
@@ -1,5 +1,6 @@
export default {
preset: 'ts-jest',
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'node',
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
transformIgnorePatterns: [`/node_modules/(?!@lens-protocol/*)`],
};
2 changes: 1 addition & 1 deletion packages/domain/mocks/package.json
@@ -1,4 +1,4 @@
{
"type": "module",
"main": "../dist/esm/mocks.js"
"main": "../dist/mocks.js"
}
49 changes: 12 additions & 37 deletions packages/domain/package.json
Expand Up @@ -8,48 +8,24 @@
"url": "git://github.com/lens-protocol/lens-sdk.git"
},
"type": "module",
"main": "./dist/cjs/index.js",
"types": "./dist/cjs/index.d.ts",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"./entities": {
"import": {
"types": "./dist/esm/entities/index.d.ts",
"default": "./dist/esm/entities/index.js"
},
"require": {
"types": "./dist/cjs/entities/index.d.ts",
"default": "./dist/cjs/entities/index.js"
}
"types": "./dist/entities/index.d.ts",
"default": "./dist/entities/index.js"
},
"./use-cases": {
"import": {
"types": "./dist/esm/use-cases/index.d.ts",
"default": "./dist/esm/use-cases/index.js"
},
"require": {
"types": "./dist/cjs/use-cases/index.d.ts",
"default": "./dist/cjs/use-cases/index.js"
}
"types": "./dist/use-cases/index.d.ts",
"default": "./dist/use-cases/index.js"
},
"./use-cases/*": {
"import": {
"types": "./dist/esm/use-cases/*/index.d.ts",
"default": "./dist/esm/use-cases/*/index.js"
},
"require": {
"types": "./dist/cjs/use-cases/*/index.d.ts",
"default": "./dist/cjs/use-cases/*/index.js"
}
"types": "./dist/use-cases/*/index.d.ts",
"default": "./dist/use-cases/*/index.js"
},
"./mocks": {
"import": {
"types": "./dist/esm/mocks.d.ts",
"default": "./dist/esm/mocks.js"
},
"require": {
"types": "./dist/cjs/mocks.d.ts",
"default": "./dist/cjs/mocks.js"
}
"types": "./dist/mocks.d.ts",
"default": "./dist/mocks.js"
},
"./package.json": "./package.json"
},
Expand All @@ -61,9 +37,7 @@
"mocks"
],
"scripts": {
"build:cjs": "tsc -p tsconfig.build-cjs.json",
"build:esm": "tsc -p tsconfig.build.json",
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs",
"build": "pnpm clean && tsup",
"clean": "rimraf ./dist",
"eslint:fix": "pnpm run eslint --fix",
"eslint": "eslint src",
Expand Down Expand Up @@ -94,6 +68,7 @@
"rimraf": "^3.0.2",
"ts-jest": "^29.0.3",
"typescript": "^4.9.3",
"tsup": "^6.5.0",
"wait-for-expect": "^3.0.2"
},
"prettier": "@lens-protocol/prettier-config"
Expand Down
2 changes: 1 addition & 1 deletion packages/domain/tsconfig.base.json
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"allowJs": false,
"allowJs": true,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
Expand Down
8 changes: 0 additions & 8 deletions packages/domain/tsconfig.build-cjs.json

This file was deleted.

9 changes: 0 additions & 9 deletions packages/domain/tsconfig.build.json

This file was deleted.

21 changes: 21 additions & 0 deletions packages/domain/tsup.config.ts
@@ -0,0 +1,21 @@
import { defineConfig } from 'tsup';

import { dependencies, devDependencies } from './package.json';

export default defineConfig({
entry: [
'src/index.ts',
'src/mocks.ts',
'src/entities/index.ts',
'src/use-cases/index.ts',
'src/use-cases/**/index.ts',
],

format: ['esm'],
dts: true,
external: [
...Object.keys(dependencies),
// required to not bundle `jest` into exported mocks
...Object.keys(devDependencies),
],
});
2 changes: 1 addition & 1 deletion packages/domain/use-cases/lifecycle/package.json
@@ -1,4 +1,4 @@
{
"type": "module",
"main": "../../dist/esm/use-cases/lifecycle/index.js"
"main": "../../dist/use-cases/lifecycle/index.js"
}
2 changes: 1 addition & 1 deletion packages/domain/use-cases/package.json
@@ -1,4 +1,4 @@
{
"type": "module",
"main": "../dist/esm/use-cases/index.js"
"main": "../dist/use-cases/index.js"
}
2 changes: 1 addition & 1 deletion packages/domain/use-cases/profile/package.json
@@ -1,4 +1,4 @@
{
"type": "module",
"main": "../../dist/esm/use-cases/profile/index.js"
"main": "../../dist/use-cases/profile/index.js"
}
2 changes: 1 addition & 1 deletion packages/domain/use-cases/publications/package.json
@@ -1,4 +1,4 @@
{
"type": "module",
"main": "../../dist/esm/use-cases/publications/index.js"
"main": "../../dist/use-cases/publications/index.js"
}
2 changes: 1 addition & 1 deletion packages/domain/use-cases/transactions/package.json
@@ -1,4 +1,4 @@
{
"type": "module",
"main": "../../dist/esm/use-cases/transactions/index.js"
"main": "../../dist/use-cases/transactions/index.js"
}
2 changes: 1 addition & 1 deletion packages/domain/use-cases/wallets/package.json
@@ -1,4 +1,4 @@
{
"type": "module",
"main": "../../dist/esm/use-cases/wallets/index.js"
"main": "../../dist/use-cases/wallets/index.js"
}
3 changes: 2 additions & 1 deletion packages/react/jest.config.js
@@ -1,6 +1,7 @@
export default {
preset: 'ts-jest',
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'jsdom',
testRegex: '/__tests__/.*|(\\.|/)spec\\.tsx?$',
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
transformIgnorePatterns: [`/node_modules/(?!@lens-protocol/*)`],
};
31 changes: 9 additions & 22 deletions packages/react/package.json
Expand Up @@ -10,38 +10,24 @@
"type": "module",
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./web": {
"import": {
"types": "./dist/esm/web/index.d.ts",
"default": "./dist/esm/web/index.js"
},
"require": {
"types": "./dist/cjs/web/index.d.ts",
"default": "./dist/cjs/web/index.js"
}
"types": "./dist/web/index.d.ts",
"default": "./dist/web/index.js"
},
"./package.json": "./package.json"
},
"types": "./dist/cjs/index.d.ts",
"main": "./dist/cjs/index.js",
"types": "./dist/index.d.ts",
"main": "./dist/index.js",
"sideEffects": false,
"files": [
"dist",
"web"
],
"scripts": {
"build:cjs": "tsc -p ./tsconfig.build-cjs.json",
"build:esm": "tsc -p ./tsconfig.build.json",
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs",
"build": "pnpm clean && tsup",
"clean": "rimraf ./dist",
"eslint:fix": "pnpm run eslint --fix",
"eslint": "eslint src",
Expand Down Expand Up @@ -94,7 +80,8 @@
"react-dom": "^18.2.0",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.3",
"typescript": "^4.9.3"
"typescript": "^4.9.3",
"tsup": "^6.5.0"
},
"peerDependencies": {
"ethers": "^5.7.2",
Expand Down