Skip to content

Commit f5a9d57

Browse files
Remove conditional exports (#555)
* Remove conditional exports * Fixup docs * Declare pure directory to obviate need to import `pure.mjs` This change requires moving the output of `pure` distribution files.
1 parent 87585ec commit f5a9d57

File tree

4 files changed

+18
-52
lines changed

4 files changed

+18
-52
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ dist
55
*.log
66
.vim
77
.vscode/
8+
pure

README.md

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
# ⚠️ v3.0.x Notice
1+
# Stripe.js as a CommonJS module or ES module
22

3-
We are aware of an issue impacting builds for some TypeScript users in our
4-
package releases **v3.0.0**, **v3.0.1**, **v3.0.2** and recommend users to
5-
upgrade to our latest package release
6-
[**v3.0.3**](https://github.com/stripe/stripe-js/releases/tag/v3.0.3) which
7-
contains a fix.
8-
9-
# Stripe.js ES Module
10-
11-
Use [Stripe.js](https://stripe.com/docs/stripe-js) as an ES module.
3+
This package allows [Stripe.js](https://stripe.com/docs/stripe-js) to be
4+
imported as a CommonJS module or ES module.
125

136
**Note**: To be
147
[PCI compliant](https://stripe.com/docs/security/guide#validating-pci-compliance),
@@ -86,18 +79,6 @@ Note that we may release new [minor and patch](https://semver.org/) versions of
8679
`@stripe/stripe-js` with small but backwards-incompatible fixes to the type
8780
declarations. These changes will not affect Stripe.js itself.
8881

89-
### [`moduleResolution`](https://www.typescriptlang.org/tsconfig#moduleResolution) support
90-
91-
This package supports the following module resolution strategies:
92-
93-
- `bundler`
94-
- `node16`
95-
- `nodenext`
96-
97-
This package does not support `node10` or `node` strategies, which do not
98-
support ES6 modules. Using `node16` or `nodenext` is recommended as a
99-
replacement configuration.
100-
10182
## Ensuring Stripe.js is available everywhere
10283

10384
To best leverage Stripe’s advanced fraud functionality, ensure that Stripe.js is
@@ -137,9 +118,12 @@ one. When you call `loadStripe`, it will use the existing script tag.
137118

138119
If you would like to use `loadStripe` in your application, but defer loading the
139120
Stripe.js script until `loadStripe` is first called, use the alternative
140-
`@stripe/stripe-js/pure` import path:
121+
`@stripe/stripe-js/pure` import module:
141122

142123
```js
124+
// CommonJS module import
125+
const {loadStripe} = require('@stripe/stripe-js/pure');
126+
// ES module import
143127
import {loadStripe} from '@stripe/stripe-js/pure';
144128

145129
// Stripe.js will not be loaded until `loadStripe` is called
@@ -153,6 +137,9 @@ If you would like to
153137
altogether, use `loadStripe.setLoadParameters`:
154138

155139
```js
140+
// CommonJS module import
141+
const {loadStripe} = require('@stripe/stripe-js/pure');
142+
// ES module import
156143
import {loadStripe} from '@stripe/stripe-js/pure';
157144

158145
loadStripe.setLoadParameters({advancedFraudSignals: false});

package.json

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,9 @@
55
"repository": "github:stripe/stripe-js",
66
"main": "dist/stripe.js",
77
"module": "dist/stripe.mjs",
8-
"exports": {
9-
".": {
10-
"import": {
11-
"types": "./dist/index.d.mts",
12-
"default": "./dist/stripe.mjs"
13-
},
14-
"require": {
15-
"types": "./dist/index.d.ts",
16-
"default": "./dist/stripe.js"
17-
}
18-
},
19-
"./pure": {
20-
"import": {
21-
"types": "./dist/pure.d.mts",
22-
"default": "./dist/pure.mjs"
23-
},
24-
"require": {
25-
"types": "./dist/pure.d.ts",
26-
"default": "./dist/pure.js"
27-
}
28-
}
29-
},
308
"jsnext:main": "dist/stripe.mjs",
31-
"types": "types/index.d.ts",
32-
"typings": "types/index.d.ts",
9+
"types": "dist/index.d.ts",
10+
"typings": "dist/index.d.ts",
3311
"scripts": {
3412
"test": "yarn lint && yarn test:unit && yarn test:types && yarn typecheck",
3513
"test:unit": "jest",
@@ -53,7 +31,7 @@
5331
"files": [
5432
"dist",
5533
"src",
56-
"types"
34+
"pure"
5735
],
5836
"engines": {
5937
"node": ">=12.16"

rollup.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ export default [
3737
{
3838
input: 'src/pure.ts',
3939
output: [
40-
{file: 'dist/pure.js', format: 'cjs'},
41-
{file: 'dist/pure.mjs', format: 'es'},
40+
{file: 'pure/index.js', format: 'cjs'},
41+
{file: 'pure/index.mjs', format: 'es'},
4242
],
4343
plugins: PLUGINS,
4444
},
4545
{
4646
input: 'types/pure.d.ts',
4747
output: [
48-
{file: './dist/pure.d.ts', format: 'cjs'},
49-
{file: './dist/pure.d.mts', format: 'es'},
48+
{file: './pure/index.d.ts', format: 'cjs'},
49+
{file: './pure/index.d.mts', format: 'es'},
5050
],
5151
plugins: [dts()],
5252
},

0 commit comments

Comments
 (0)