Skip to content

Commit

Permalink
Fix mismatched types between entrypoint and pure modules (#565)
Browse files Browse the repository at this point in the history
* Change types generation strategy to avoid duplicate declarations

* Remove rollup-plugin-dts
  • Loading branch information
fruchtose-stripe committed Mar 14, 2024
1 parent c71c4aa commit 0230bbd
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 49 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -4,5 +4,4 @@ node_modules
dist
*.log
.vim
.vscode/
pure
.vscode/
1 change: 1 addition & 0 deletions lib/index.d.mts
@@ -0,0 +1 @@
export * from '../dist';
1 change: 1 addition & 0 deletions lib/index.d.ts
@@ -0,0 +1 @@
export * from '../dist';
2 changes: 2 additions & 0 deletions lib/index.js
@@ -0,0 +1,2 @@
// eslint-disable-next-line no-undef
module.exports = require('../dist/stripe');
1 change: 1 addition & 0 deletions lib/index.mjs
@@ -0,0 +1 @@
export * from '../dist/stripe.mjs';
19 changes: 10 additions & 9 deletions package.json
Expand Up @@ -3,18 +3,19 @@
"version": "3.0.8",
"description": "Stripe.js loading utility",
"repository": "github:stripe/stripe-js",
"main": "dist/stripe.js",
"module": "dist/stripe.mjs",
"jsnext:main": "dist/stripe.mjs",
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"main": "lib/index.js",
"module": "lib/index.mjs",
"jsnext:main": "lib/index.mjs",
"types": "lib/index.d.ts",
"typings": "lib/index.d.ts",
"scripts": {
"test": "yarn lint && yarn test:unit && yarn test:types && yarn typecheck",
"test:unit": "jest",
"test:types": "zx ./tests/types/scripts/test.mjs",
"lint": "eslint '{src,types}/**/*.{ts,js}' && yarn prettier-check",
"typecheck": "tsc",
"build": "yarn clean && yarn rollup -c",
"copy-types": "./scripts/copy-types",
"build": "yarn clean && yarn rollup -c && yarn copy-types",
"clean": "rimraf dist",
"prepublishOnly": "echo \"\nPlease use ./scripts/publish instead\n\" && exit 1",
"prettier": "prettier './**/*.{js,ts,md,html,css}' --write",
Expand All @@ -30,8 +31,9 @@
"homepage": "https://stripe.com/docs/js",
"files": [
"dist",
"src",
"pure"
"lib",
"pure",
"src"
],
"engines": {
"node": ">=12.16"
Expand All @@ -56,7 +58,6 @@
"rimraf": "^2.6.2",
"rollup": "^1.29.0",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-typescript2": "^0.25.3",
"ts-jest": "^24.3.0",
"typescript": "^4.1.2",
Expand Down
1 change: 1 addition & 0 deletions pure/index.d.mts
@@ -0,0 +1 @@
export * from '../dist/pure';
1 change: 1 addition & 0 deletions pure/index.d.ts
@@ -0,0 +1 @@
export * from '../dist/pure';
1 change: 1 addition & 0 deletions pure/index.js
@@ -0,0 +1 @@
module.exports = require('../dist/pure');
1 change: 1 addition & 0 deletions pure/index.mjs
@@ -0,0 +1 @@
export * from '../dist/pure.mjs';
25 changes: 4 additions & 21 deletions rollup.config.js
@@ -1,6 +1,5 @@
import babel from 'rollup-plugin-babel';
import ts from 'rollup-plugin-typescript2';
import {dts} from 'rollup-plugin-dts';
import replace from '@rollup/plugin-replace';

import pkg from './package.json';
Expand All @@ -21,33 +20,17 @@ export default [
{
input: 'src/index.ts',
output: [
{file: pkg.main, format: 'cjs'},
{file: pkg.module, format: 'es'},
{file: 'dist/index.js', format: 'cjs'},
{file: 'dist/index.mjs', format: 'es'},
],
plugins: PLUGINS,
},
{
input: 'types/index.d.ts',
output: [
{file: './dist/index.d.ts', format: 'cjs'},
{file: './dist/index.d.mts', format: 'es'},
],
plugins: [dts()],
},
{
input: 'src/pure.ts',
output: [
{file: 'pure/index.js', format: 'cjs'},
{file: 'pure/index.mjs', format: 'es'},
{file: 'dist/pure.js', format: 'cjs'},
{file: 'dist/pure.mjs', format: 'es'},
],
plugins: PLUGINS,
},
{
input: 'types/pure.d.ts',
output: [
{file: './pure/index.d.ts', format: 'cjs'},
{file: './pure/index.d.mts', format: 'es'},
],
plugins: [dts()],
},
];
21 changes: 21 additions & 0 deletions scripts/copy-types
@@ -0,0 +1,21 @@
#!/bin/bash

# Sets the source and destination directories
SRC_DIR="./types"
DEST_DIR="./dist"

# Finds all .d.ts files in the source directory and copies them
find "$SRC_DIR" -type f -name '*.d.ts' | while read -r src_file; do
# Constructs the destination file path
dest_file="${src_file/$SRC_DIR/$DEST_DIR}"
dest_file_mts="${dest_file/%.d.ts/.d.mts}"

# Creates the destination directory if it doesn't exist
mkdir -p "$(dirname "$dest_file")"

# Copys the .d.ts file to the destination directory
cp "$src_file" "$dest_file"
cp "$src_file" "$dest_file_mts"
done

echo "All .d.ts files have been copied from $SRC_DIR to $DEST_DIR."
18 changes: 1 addition & 17 deletions yarn.lock
Expand Up @@ -1050,7 +1050,7 @@
resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72"
integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==

"@jridgewell/sourcemap-codec@^1.4.10", "@jridgewell/sourcemap-codec@^1.4.14", "@jridgewell/sourcemap-codec@^1.4.15":
"@jridgewell/sourcemap-codec@^1.4.10", "@jridgewell/sourcemap-codec@^1.4.14":
version "1.4.15"
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32"
integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==
Expand Down Expand Up @@ -3774,13 +3774,6 @@ magic-string@^0.25.5:
dependencies:
sourcemap-codec "^1.4.4"

magic-string@^0.30.4:
version "0.30.7"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.30.7.tgz#0cecd0527d473298679da95a2d7aeb8c64048505"
integrity sha512-8vBuFF/I/+OSLRmdf2wwFCJCz+nSn0m6DPvGH1fS/KiQoSaR+sETbov0eIk9KhEKy8CYqIkIAnbohxT/4H0kuA==
dependencies:
"@jridgewell/sourcemap-codec" "^1.4.15"

make-dir@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-2.1.0.tgz#5f0310e18b8be898cc07009295a30ae41e91e6f5"
Expand Down Expand Up @@ -4668,15 +4661,6 @@ rollup-plugin-babel@^4.3.3:
"@babel/helper-module-imports" "^7.0.0"
rollup-pluginutils "^2.8.1"

rollup-plugin-dts@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-dts/-/rollup-plugin-dts-6.1.0.tgz#56e9c5548dac717213c6a4aa9df523faf04f75ae"
integrity sha512-ijSCPICkRMDKDLBK9torss07+8dl9UpY9z1N/zTeA1cIqdzMlpkV3MOOC7zukyvQfDyxa1s3Dl2+DeiP/G6DOw==
dependencies:
magic-string "^0.30.4"
optionalDependencies:
"@babel/code-frame" "^7.22.13"

rollup-plugin-typescript2@^0.25.3:
version "0.25.3"
resolved "https://registry.yarnpkg.com/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.25.3.tgz#a5fb2f0f85488789334ce540abe6c7011cbdf40f"
Expand Down

0 comments on commit 0230bbd

Please sign in to comment.