Skip to content

Commit

Permalink
build: Specify type declaration file in exports (#158)
Browse files Browse the repository at this point in the history
It's currently not possible to use interfaces and types in consuming
projects with `moduleResolution: bundler` configured, because the
`.d.mts` file contains bundled js code instead of the type declarations.

The issue stems from [this
commit](b13d10f).
The original intention was to rename `.d.ts` into `.d.mts` and
`.d.cts`. However, the result was that `.cjs` and `.mts` files were
mistakenly renamed to `.d.cts` and `.d.mts`, respectively.

It had good intentions, because it's true that typescript will
prioritize reading a `.mts` file over a `.d.ts` file when using `esm`.

To fix this, this PR removes this step in the build process, and
explicitely defines the path for type declartions in the package exports
instead.
  • Loading branch information
reobin authored Jan 23, 2025
1 parent 8e7a020 commit 247f2f6
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 53 deletions.
9 changes: 5 additions & 4 deletions packages/drops/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/drops",
"version": "0.7.4",
"version": "0.7.5",
"description": "Drops module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -9,7 +9,8 @@
"exports": {
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.mjs",
"browser": "./dist/umd/index.js"
"browser": "./dist/umd/index.js",
"types": "./dist/cjs/index.d.ts"
},
"type": "module",
"repository": {
Expand All @@ -30,7 +31,7 @@
},
"packageManager": "[email protected]",
"dependencies": {
"@poap-xyz/providers": "0.7.4",
"@poap-xyz/utils": "0.7.4"
"@poap-xyz/providers": "0.7.5",
"@poap-xyz/utils": "0.7.5"
}
}
5 changes: 3 additions & 2 deletions packages/frames/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/frames",
"version": "1.1.0",
"version": "1.1.1",
"description": "Frames module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -9,7 +9,8 @@
"exports": {
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.mjs",
"browser": "./dist/umd/index.js"
"browser": "./dist/umd/index.js",
"types": "./dist/cjs/index.d.ts"
},
"type": "module",
"repository": {
Expand Down
9 changes: 5 additions & 4 deletions packages/moments/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/moments",
"version": "0.7.4",
"version": "0.7.5",
"description": "Moments module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -9,7 +9,8 @@
"exports": {
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.mjs",
"browser": "./dist/umd/index.js"
"browser": "./dist/umd/index.js",
"types": "./dist/cjs/index.d.ts"
},
"type": "module",
"repository": {
Expand All @@ -30,8 +31,8 @@
},
"packageManager": "[email protected]",
"dependencies": {
"@poap-xyz/providers": "0.7.4",
"@poap-xyz/utils": "0.7.4",
"@poap-xyz/providers": "0.7.5",
"@poap-xyz/utils": "0.7.5",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand Down
9 changes: 5 additions & 4 deletions packages/poaps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/poaps",
"version": "0.7.4",
"version": "0.7.5",
"description": "Poaps module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -9,7 +9,8 @@
"exports": {
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.mjs",
"browser": "./dist/umd/index.js"
"browser": "./dist/umd/index.js",
"types": "./dist/cjs/index.d.ts"
},
"type": "module",
"repository": {
Expand All @@ -30,7 +31,7 @@
},
"packageManager": "[email protected]",
"dependencies": {
"@poap-xyz/providers": "0.7.4",
"@poap-xyz/utils": "0.7.4"
"@poap-xyz/providers": "0.7.5",
"@poap-xyz/utils": "0.7.5"
}
}
7 changes: 4 additions & 3 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/providers",
"version": "0.7.4",
"version": "0.7.5",
"description": "Providers module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -9,7 +9,8 @@
"exports": {
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.mjs",
"browser": "./dist/umd/index.js"
"browser": "./dist/umd/index.js",
"types": "./dist/cjs/index.d.ts"
},
"type": "module",
"repository": {
Expand All @@ -30,7 +31,7 @@
},
"packageManager": "[email protected]",
"dependencies": {
"@poap-xyz/utils": "0.7.4",
"@poap-xyz/utils": "0.7.5",
"axios": "^1.6.8",
"lodash.chunk": "^4.2.0"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/utils",
"version": "0.7.4",
"version": "0.7.5",
"description": "Utils module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -9,7 +9,8 @@
"exports": {
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.mjs",
"browser": "./dist/umd/index.js"
"browser": "./dist/umd/index.js",
"types": "./dist/cjs/index.d.ts"
},
"type": "module",
"repository": {
Expand Down
28 changes: 3 additions & 25 deletions rollup.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import nodePolyfills from 'rollup-plugin-node-polyfills';

const pkg = require(path.resolve(process.cwd(), 'package.json'));

const replaceExtension = (filePath, newExtension) => {
const currentExtension = path.extname(filePath);
const fileNameWithoutExtension = filePath.slice(0, -currentExtension.length);
return `${fileNameWithoutExtension}.${newExtension}`;
};

const configs = [
{
context: 'window',
Expand All @@ -26,9 +20,7 @@ const configs = [
},
cache: false,
plugins: [
typescript({
tsconfig: `./tsconfig.json`,
}),
typescript({ tsconfig: './tsconfig.json' }),
nodeResolve({
browser: true,
}),
Expand All @@ -37,7 +29,7 @@ const configs = [
],
},
{
input: `./src/index.ts`,
input: './src/index.ts',
output: [
{
file: pkg.main,
Expand All @@ -51,24 +43,10 @@ const configs = [
sourcemap: true,
exports: 'named',
},
{
file: replaceExtension(pkg.typings, 'cts'),
format: 'cjs',
sourcemap: false,
exports: 'named',
},
{
file: replaceExtension(pkg.module, 'd.mts'),
format: 'esm',
sourcemap: false,
exports: 'named',
},
],
external: ['axios'],
plugins: [
typescript({
tsconfig: `./tsconfig.json`,
}),
typescript({ tsconfig: './tsconfig.json' }),
nodeResolve({
preferBuiltins: true,
browser: false,
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@poap-xyz/drops@workspace:packages/drops"
dependencies:
"@poap-xyz/providers": 0.7.4
"@poap-xyz/utils": 0.7.4
"@poap-xyz/providers": 0.7.5
"@poap-xyz/utils": 0.7.5
languageName: unknown
linkType: soft

Expand All @@ -948,8 +948,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@poap-xyz/moments@workspace:packages/moments"
dependencies:
"@poap-xyz/providers": 0.7.4
"@poap-xyz/utils": 0.7.4
"@poap-xyz/providers": 0.7.5
"@poap-xyz/utils": 0.7.5
"@types/uuid": ^9.0.2
uuid: ^9.0.0
languageName: unknown
Expand All @@ -959,24 +959,24 @@ __metadata:
version: 0.0.0-use.local
resolution: "@poap-xyz/poaps@workspace:packages/poaps"
dependencies:
"@poap-xyz/providers": 0.7.4
"@poap-xyz/utils": 0.7.4
"@poap-xyz/providers": 0.7.5
"@poap-xyz/utils": 0.7.5
languageName: unknown
linkType: soft

"@poap-xyz/[email protected].4, @poap-xyz/providers@workspace:packages/providers":
"@poap-xyz/[email protected].5, @poap-xyz/providers@workspace:packages/providers":
version: 0.0.0-use.local
resolution: "@poap-xyz/providers@workspace:packages/providers"
dependencies:
"@poap-xyz/utils": 0.7.4
"@poap-xyz/utils": 0.7.5
axios: ^1.6.8
axios-mock-adapter: ^1.21.4
jest-fetch-mock: ^3.0.3
lodash.chunk: ^4.2.0
languageName: unknown
linkType: soft

"@poap-xyz/[email protected].4, @poap-xyz/utils@workspace:packages/utils":
"@poap-xyz/[email protected].5, @poap-xyz/utils@workspace:packages/utils":
version: 0.0.0-use.local
resolution: "@poap-xyz/utils@workspace:packages/utils"
languageName: unknown
Expand Down

0 comments on commit 247f2f6

Please sign in to comment.