Skip to content

Commit

Permalink
Remove conditional exports (#555)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
fruchtose-stripe authored Feb 20, 2024
1 parent 87585ec commit f5a9d57
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist
*.log
.vim
.vscode/
pure
33 changes: 10 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# ⚠️ v3.0.x Notice
# Stripe.js as a CommonJS module or ES module

We are aware of an issue impacting builds for some TypeScript users in our
package releases **v3.0.0**, **v3.0.1**, **v3.0.2** and recommend users to
upgrade to our latest package release
[**v3.0.3**](https://github.com/stripe/stripe-js/releases/tag/v3.0.3) which
contains a fix.

# Stripe.js ES Module

Use [Stripe.js](https://stripe.com/docs/stripe-js) as an ES module.
This package allows [Stripe.js](https://stripe.com/docs/stripe-js) to be
imported as a CommonJS module or ES module.

**Note**: To be
[PCI compliant](https://stripe.com/docs/security/guide#validating-pci-compliance),
Expand Down Expand Up @@ -86,18 +79,6 @@ 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
Expand Down Expand Up @@ -137,9 +118,12 @@ one. When you call `loadStripe`, it will use the existing script tag.

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

```js
// CommonJS module import
const {loadStripe} = require('@stripe/stripe-js/pure');
// ES module import
import {loadStripe} from '@stripe/stripe-js/pure';

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

```js
// CommonJS module import
const {loadStripe} = require('@stripe/stripe-js/pure');
// ES module import
import {loadStripe} from '@stripe/stripe-js/pure';

loadStripe.setLoadParameters({advancedFraudSignals: false});
Expand Down
28 changes: 3 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,9 @@
"repository": "github:stripe/stripe-js",
"main": "dist/stripe.js",
"module": "dist/stripe.mjs",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/stripe.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/stripe.js"
}
},
"./pure": {
"import": {
"types": "./dist/pure.d.mts",
"default": "./dist/pure.mjs"
},
"require": {
"types": "./dist/pure.d.ts",
"default": "./dist/pure.js"
}
}
},
"jsnext:main": "dist/stripe.mjs",
"types": "types/index.d.ts",
"typings": "types/index.d.ts",
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"scripts": {
"test": "yarn lint && yarn test:unit && yarn test:types && yarn typecheck",
"test:unit": "jest",
Expand All @@ -53,7 +31,7 @@
"files": [
"dist",
"src",
"types"
"pure"
],
"engines": {
"node": ">=12.16"
Expand Down
8 changes: 4 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ export default [
{
input: 'src/pure.ts',
output: [
{file: 'dist/pure.js', format: 'cjs'},
{file: 'dist/pure.mjs', format: 'es'},
{file: 'pure/index.js', format: 'cjs'},
{file: 'pure/index.mjs', format: 'es'},
],
plugins: PLUGINS,
},
{
input: 'types/pure.d.ts',
output: [
{file: './dist/pure.d.ts', format: 'cjs'},
{file: './dist/pure.d.mts', format: 'es'},
{file: './pure/index.d.ts', format: 'cjs'},
{file: './pure/index.d.mts', format: 'es'},
],
plugins: [dts()],
},
Expand Down

0 comments on commit f5a9d57

Please sign in to comment.