Skip to content

Commit

Permalink
feat: bundle packages to be Ecmascript modules (T-186) (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
desfero committed Jan 12, 2023
1 parent 5f46cde commit cc453cc
Show file tree
Hide file tree
Showing 67 changed files with 475 additions and 348 deletions.
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} />
<p>Handle: {profile?.handle}</p>
<p>Name: {profile?.name}</p>
<p>Bio: {profile?.bio}</p>
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,
"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 && tsc --emitDeclarationOnly",
"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.

3 changes: 1 addition & 2 deletions packages/api-bindings/tsconfig.json
Expand Up @@ -2,7 +2,6 @@
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/esm",
"declarationDir": "dist/esm"
"outDir": "dist"
}
}
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),
],
});
22 changes: 8 additions & 14 deletions packages/blockchain-bindings/package.json
Expand Up @@ -10,26 +10,19 @@
"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"
},
"./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/**/*"
],
"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 && tsc --emitDeclarationOnly",
"clean": "rimraf ./dist",
"test": "jest --passWithNoTests",
"eslint:fix": "pnpm run eslint --fix",
Expand Down Expand Up @@ -60,6 +53,7 @@
"jest": "^29.3.1",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.3",
"tsup": "^6.5.0",
"typescript": "^4.9.3"
},
"prettier": "@lens-protocol/prettier-config",
Expand Down
4 changes: 2 additions & 2 deletions packages/blockchain-bindings/src/errors.ts
@@ -1,12 +1,12 @@
// eslint-disable-next-line no-restricted-imports
import { errorCodes } from 'eth-rpc-errors';

export type ProviderErrorCode = typeof errorCodes['provider'];
export type ProviderErrorCode = (typeof errorCodes)['provider'];
export type ProviderErrors = ProviderErrorCode[keyof ProviderErrorCode];

export const ProviderErrorCode: ProviderErrorCode = errorCodes.provider;

export type RpcErrorCode = typeof errorCodes['rpc'];
export type RpcErrorCode = (typeof errorCodes)['rpc'];
export type RpcErrors = RpcErrorCode[keyof RpcErrorCode];

export const RpcErrorCode: RpcErrorCode = errorCodes.rpc;
Expand Down
8 changes: 0 additions & 8 deletions packages/blockchain-bindings/tsconfig.build-cjs.json

This file was deleted.

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

This file was deleted.

3 changes: 1 addition & 2 deletions packages/blockchain-bindings/tsconfig.json
Expand Up @@ -2,7 +2,6 @@
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/esm",
"declarationDir": "dist/esm"
"outDir": "dist"
}
}
22 changes: 22 additions & 0 deletions packages/blockchain-bindings/tsup.config.ts
@@ -0,0 +1,22 @@
import { defineConfig } from 'tsup';

import { dependencies, devDependencies, peerDependencies } 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),
...Object.keys(peerDependencies),
// 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 && tsc --emitDeclarationOnly",
"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.

3 changes: 1 addition & 2 deletions packages/domain/tsconfig.json
Expand Up @@ -2,7 +2,6 @@
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"outDir": "dist/esm",
"declarationDir": "dist/esm"
"outDir": "dist"
}
}

0 comments on commit cc453cc

Please sign in to comment.