From 2bf0a3a050ccc9fd939c2a882ecf74bcb6fee186 Mon Sep 17 00:00:00 2001 From: Robert Fruchtman Date: Thu, 15 Feb 2024 13:37:28 -0800 Subject: [PATCH 1/4] Use rollup-plugin-dts to emit types --- package.json | 9 +++++---- rollup.config.js | 17 +++++++++++++++++ yarn.lock | 18 +++++++++++++++++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 53a97e29..4feb4a95 100644 --- a/package.json +++ b/package.json @@ -8,21 +8,21 @@ "exports": { ".": { "import": { - "types": "./types/index.d.ts", + "types": "./dist/index.d.mts", "default": "./dist/stripe.mjs" }, "require": { - "types": "./types/index.d.ts", + "types": "./dist/index.d.ts", "default": "./dist/stripe.js" } }, "./pure": { "import": { - "types": "./types/pure.d.ts", + "types": "./dist/pure.d.mts", "default": "./dist/pure.mjs" }, "require": { - "types": "./types/pure.d.ts", + "types": "./dist/pure.d.ts", "default": "./dist/pure.js" } } @@ -78,6 +78,7 @@ "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", diff --git a/rollup.config.js b/rollup.config.js index 19618f01..9b7fed83 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,5 +1,6 @@ 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'; @@ -25,6 +26,14 @@ export default [ ], 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: [ @@ -33,4 +42,12 @@ export default [ ], plugins: PLUGINS, }, + { + input: 'types/pure.d.ts', + output: [ + {file: './dist/pure.d.ts', format: 'cjs'}, + {file: './dist/pure.d.mts', format: 'es'}, + ], + plugins: [dts()], + }, ]; diff --git a/yarn.lock b/yarn.lock index ad25e6be..e189966f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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.10", "@jridgewell/sourcemap-codec@^1.4.14", "@jridgewell/sourcemap-codec@^1.4.15": version "1.4.15" resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32" integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg== @@ -3774,6 +3774,13 @@ 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" @@ -4661,6 +4668,15 @@ 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" From d4bdc83cead23ad570b7325a223e03a9e2c373bb Mon Sep 17 00:00:00 2001 From: Robert Fruchtman Date: Thu, 15 Feb 2024 13:37:46 -0800 Subject: [PATCH 2/4] Fix type reference for pure module --- types/pure.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/pure.d.ts b/types/pure.d.ts index ac13eaf7..1da55053 100644 --- a/types/pure.d.ts +++ b/types/pure.d.ts @@ -1,5 +1,5 @@ -/// +import {loadStripe as _loadStripe} from './index'; -export const loadStripe: typeof import('@stripe/stripe-js').loadStripe & { +export const loadStripe: typeof _loadStripe & { setLoadParameters: (params: {advancedFraudSignals: boolean}) => void; }; From b2ac3ca3937f3b0f7d6aca9cb85f3ad1fa625891 Mon Sep 17 00:00:00 2001 From: Robert Fruchtman Date: Thu, 15 Feb 2024 14:26:51 -0800 Subject: [PATCH 3/4] Use current Node for workflow --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 352fc6c5..3ace3cb4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 14.x + node-version: 20.x - run: yarn install --frozen-lockfile - run: yarn run lint - run: yarn run typecheck From a7dd9c66e7875142c7debcd1674d699bc8e0e743 Mon Sep 17 00:00:00 2001 From: Robert Fruchtman Date: Thu, 15 Feb 2024 14:35:25 -0800 Subject: [PATCH 4/4] Update README for TypeScript support --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 4fb51710..bb5e11e7 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ of features of Stripe.js. ## Minimum requirements - Node.js: v12.16 +- TypeScript: v.3.1.1 ## Installation @@ -77,6 +78,18 @@ Note that we may release new [minor and patch](https://semver.org/) versions of `@stripe/stripe-js` with small but backwards-incompatible fixes to the type declarations. These changes will not affect Stripe.js itself. +### [`moduleResolution`](https://www.typescriptlang.org/tsconfig#moduleResolution) support + +This package supports the following module resolution strategies: + +- `bundler` +- `node16` +- `nodenext` + +This package does not support `node10` or `node` strategies, which do not +support ES6 modules. Using `node16` or `nodenext` is recommended as a +replacement configuration. + ## Ensuring Stripe.js is available everywhere To best leverage Stripe’s advanced fraud functionality, ensure that Stripe.js is