Skip to content

Commit 1b99bf0

Browse files
Merge branch 'v4'
2 parents ef5c9e9 + 7ffbb95 commit 1b99bf0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+9958
-738
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ jobs:
1717
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
1818
steps:
1919
- name: Checkout
20-
uses: actions/checkout@v3
20+
uses: actions/checkout@v4
2121
with:
2222
ref: ${{ github.event.release.target_commitish }}
2323
- name: Validate and extract release information
2424
id: release
2525
uses: manovotny/[email protected]
2626
- name: Use Node.js ${{ matrix.node-version }}
27-
uses: actions/setup-node@v3
27+
uses: actions/setup-node@v4
2828
with:
2929
node-version: ${{ matrix.node-version }}
3030
registry-url: 'https://registry.npmjs.org'

.github/workflows/pull-request.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ jobs:
1515
)
1616
steps:
1717
- name: Check out merge commit of pull request
18-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
1919
with:
2020
ref: ${{ github.event.pull_request.merge_commit_sha }}
2121
submodules: true
2222
- name: Use Node.js 20
23-
uses: actions/setup-node@v3
23+
uses: actions/setup-node@v4
2424
with:
2525
node-version: 20
2626
cache: npm
@@ -30,3 +30,4 @@ jobs:
3030
- run: npm run test:types
3131
- run: npm run test:unit
3232
- run: npm run test:wpt:node
33+
- run: npm run test:bundlers

.github/workflows/push.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ jobs:
1212
!contains(github.event.head_commit.message, '[skip ci]')
1313
steps:
1414
- name: Check out commit
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v4
1616
with:
1717
submodules: true
1818
- name: Use Node.js ${{ matrix.node-version }}
19-
uses: actions/setup-node@v3
19+
uses: actions/setup-node@v4
2020
with:
2121
node-version: ${{ matrix.node-version }}
2222
cache: npm
@@ -26,12 +26,13 @@ jobs:
2626
- run: npm run test:types
2727
- run: npm run test:unit
2828
- run: npm run test:wpt:node
29+
- run: npm run test:bundlers
2930

3031
test-browser:
3132
name: ${{ matrix.browser }}
3233
runs-on: ubuntu-latest
3334
container:
34-
image: mcr.microsoft.com/playwright:v1.40.0-jammy
35+
image: mcr.microsoft.com/playwright:v1.42.0-jammy
3536
strategy:
3637
fail-fast: false
3738
matrix:
@@ -40,11 +41,11 @@ jobs:
4041
!contains(github.event.head_commit.message, '[skip ci]')
4142
steps:
4243
- name: Check out commit
43-
uses: actions/checkout@v3
44+
uses: actions/checkout@v4
4445
with:
4546
submodules: true
4647
- name: Use Node.js 20
47-
uses: actions/setup-node@v3
48+
uses: actions/setup-node@v4
4849
with:
4950
node-version: 20
5051
cache: npm

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ typings/
137137

138138
### Project
139139
/dist/
140-
!/dist/types/ts3.6/polyfill.d.ts
141140
/lib/
142141
/temp/
142+
/types/ponyfill.d.ts
143+
/types/tsdoc-metadata.json

.idea/web-streams-polyfill.iml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@
1010
> - 🏠 Internal
1111
> - 💅 Polish
1212
13+
## Unreleased
14+
15+
* 💥 Rework the list of variants to have more modern defaults.
16+
The table below shows how to upgrade your v3 import to their equivalent v4 import.
17+
See the [migration guide](https://github.com/MattiasBuelens/web-streams-polyfill/blob/v4/MIGRATING.md) for more information.
18+
([#82](https://github.com/MattiasBuelens/web-streams-polyfill/issues/82), [#139](https://github.com/MattiasBuelens/web-streams-polyfill/pull/139))
19+
* 💥 Remove the ES2018 variant, in favor of the ES2015 variant.
20+
* 💥 Switch to [subpath exports](https://nodejs.org/api/packages.html#subpath-exports) for variants.
21+
* Node 12 or higher is required to `import` or `require()` a variant.
22+
* When using TypeScript, version 4.7 or higher is now required. Additionally, [`moduleResolution`](https://www.typescriptlang.org/tsconfig#moduleResolution) must be set to `"node16"`, `"nodenext"` or `"bundler"`.
23+
* 🚀 Support [importing as ESM in Node](https://nodejs.org/api/esm.html).
24+
* 💅 Minify all code in the published package, to reduce the download size.
25+
* 💅 Rework `ReadableStream.from()` implementation to avoid depending on `async function*` down-leveling for ES5. ([#144](https://github.com/MattiasBuelens/web-streams-polyfill/pull/144))
26+
27+
| v3 import | v4 import | description |
28+
| --- | --- | --- |
29+
| `web-streams-polyfill` | `web-streams-polyfill/polyfill/es5` | ES5+ polyfill |
30+
| `web-streams-polyfill/es6` | `web-streams-polyfill/polyfill` | ES2015+ polyfill |
31+
| `web-streams-polyfill/es2018` | `web-streams-polyfill/polyfill` | ES2015+ polyfill |
32+
| `web-streams-polyfill/ponyfill` | `web-streams-polyfill/es5` | ES5+ ponyfill |
33+
| `web-streams-polyfill/ponyfill/es6` | `web-streams-polyfill` | ES2015+ ponyfill |
34+
| `web-streams-polyfill/ponyfill/es2018` | `web-streams-polyfill` | ES2015+ ponyfill |
35+
1336
## 3.3.3 (2024-02-16)
1437

1538
* 🐛 Fix `ReadableStream` to match TypeScript's `AsyncIterable<R>` type. ([#141](https://github.com/MattiasBuelens/web-streams-polyfill/issues/141), [#142](https://github.com/MattiasBuelens/web-streams-polyfill/pull/142))

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- `npm run test:wpt` runs the [Web Platform Tests for Streams][wpt-streams] against the generated JavaScript bundle, to verify that the polyfill's run-time behavior matches the specification.
1313
- `npm run test:types` runs the TypeScript compiler against some reference code that uses the generated type definitions, to verify that the code successfully passes the type check.
1414
- `npm run test:unit` runs a few unit tests in a Node environment, to verify that the polyfill also works without a browser environment.
15+
- `npm run test:bundlers` runs integration tests with popular bundlers, to verify that they can correctly resolve and bundle the polyfill.
1516

1617
## Miscellaneous
1718

MIGRATING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Migrating
2+
3+
## Version 3 to 4
4+
5+
Version 4 restructures the library's exports to have more modern defaults, and employs modern best practices for publishing npm packages.
6+
7+
* The default export (i.e. `import "web-streams-polyfill"`) is now the *ponyfill* variant instead of the *polyfill* variant, to avoid modifying the global scope. If you do want to install the polyfill on the global scope, switch to
8+
the `polyfill` variant.
9+
* The default export uses ES2015 syntax and targets modern Node and browser environments. If you need to support ES5 environments, switch to either the `es5` or `polyfill/es5` variant.
10+
* The polyfill variant no longer re-exports the ponyfill, so `import { ReadableStream } from "web-streams-polyfill/polyfill"` won't work. Instead, use the global `ReadableStream` variable directly after loading the polyfill, or switch to the default (non-polyfill) variant.
11+
* The project uses [Node's subpath exports](https://nodejs.org/api/packages.html#packages_package_entry_points) to provide each variant as a [dual module (UMD/ESM)](https://nodejs.org/api/packages.html#packages_dual_commonjs_es_module_packages). You need Node 12.20.0 or higher to resolve these variants. If you're using a bundler (like webpack or Rollup), you need to make sure it's up-to-date too. If you're using TypeScript, your [`moduleResolution`](https://www.typescriptlang.org/tsconfig#moduleResolution) must be set to `"node16"`, `"nodenext"` or `"bundler"`.
12+
13+
Version 4 also focuses on reducing the download size of the published npm package.
14+
15+
* All published JavaScript code is now minified, without source maps. If you need to debug the polyfill, you can [clone it](https://github.com/MattiasBuelens/web-streams-polyfill) and [build it yourself](https://github.com/MattiasBuelens/web-streams-polyfill/blob/master/CONTRIBUTING.md).
16+
* The ES2018 variant was removed, since it had only minor differences with the ES2015 variant. If you were using this variant, switch to the default export instead.
17+
18+
The following table shows how to upgrade your v3 import to their equivalent v4 import:
19+
20+
| v3 import | v4 import | description |
21+
| --- | --- | --- |
22+
| `web-streams-polyfill` | `web-streams-polyfill/polyfill/es5` | ES5+ polyfill |
23+
| `web-streams-polyfill/es6` | `web-streams-polyfill/polyfill` | ES2015+ polyfill |
24+
| `web-streams-polyfill/es2018` | `web-streams-polyfill/polyfill` | ES2015+ polyfill |
25+
| `web-streams-polyfill/ponyfill` | `web-streams-polyfill/es5` | ES5+ ponyfill |
26+
| `web-streams-polyfill/ponyfill/es6` | `web-streams-polyfill` | ES2015+ ponyfill |
27+
| `web-streams-polyfill/ponyfill/es2018` | `web-streams-polyfill` | ES2015+ ponyfill |

README.md

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,80 @@ Web Streams, based on the WHATWG spec reference implementation.
1414
## Usage
1515

1616
This library comes in multiple variants:
17-
* `web-streams-polyfill`: a polyfill that replaces the native stream implementations.
18-
Recommended for use in web apps supporting older browsers through a `<script>` tag.
19-
* `web-streams-polyfill/es6`: a polyfill targeting ES2015+ environments.
20-
Recommended for use in web apps supporting modern browsers through a `<script>` tag.
21-
* `web-streams-polyfill/es2018`: a polyfill targeting ES2018+ environments.
22-
* `web-streams-polyfill/ponyfill`: a [ponyfill] that provides
23-
the stream implementations without replacing any globals.
24-
Recommended for use in legacy Node applications, or in web libraries supporting older browsers.
25-
* `web-streams-polyfill/ponyfill/es6`: a ponyfill targeting ES2015+ environments.
17+
* `web-streams-polyfill`: a [ponyfill] that provides the stream implementations
18+
without replacing any globals, targeting ES2015+ environments.
2619
Recommended for use in Node 6+ applications, or in web libraries supporting modern browsers.
27-
* `web-streams-polyfill/ponyfill/es2018`: a ponyfill targeting ES2018+ environments.
28-
Recommended for use in Node 10+ applications.
20+
* `web-streams-polyfill/es5`: a ponyfill targeting ES5+ environments.
21+
Recommended for use in legacy Node applications, or in web libraries supporting older browsers.
22+
* `web-streams-polyfill/polyfill`: a polyfill that replaces the native stream implementations,
23+
targeting ES2015+ environments.
24+
Recommended for use in web apps supporting modern browsers through a `<script>` tag.
25+
* `web-streams-polyfill/polyfill/es5`: a polyfill targeting ES5+ environments.
26+
Recommended for use in web apps supporting older browsers through a `<script>` tag.
2927

3028
Each variant also includes TypeScript type definitions, compatible with the DOM type definitions for streams included in TypeScript.
29+
These type definitions require TypeScript version 4.7 or higher.
30+
31+
In version 4, the list of variants was reworked to have more modern defaults and to reduce the download size of the package.
32+
See the [migration guide][migrating] for more information.
3133

3234
Usage as a polyfill:
3335
```html
3436
<!-- option 1: hosted by unpkg CDN -->
35-
<script src="https://unpkg.com/web-streams-polyfill/dist/polyfill.min.js"></script>
37+
<script src="https://unpkg.com/web-streams-polyfill/dist/polyfill.js"></script>
3638
<!-- option 2: self hosted -->
37-
<script src="/path/to/web-streams-polyfill/dist/polyfill.min.js"></script>
39+
<script src="/path/to/web-streams-polyfill/dist/polyfill.js"></script>
3840
<script>
3941
var readable = new ReadableStream();
4042
</script>
4143
```
4244
Usage as a Node module:
4345
```js
44-
var streams = require("web-streams-polyfill/ponyfill");
46+
var streams = require("web-streams-polyfill");
4547
var readable = new streams.ReadableStream();
4648
```
47-
Usage as a ES2015 module:
49+
Usage as a ponyfill from within a ES2015 module:
50+
```js
51+
import { ReadableStream } from "web-streams-polyfill";
52+
const readable = new ReadableStream();
53+
```
54+
Usage as a polyfill from within an ES2015 module:
4855
```js
49-
import { ReadableStream } from "web-streams-polyfill/ponyfill";
56+
import "web-streams-polyfill/polyfill";
5057
const readable = new ReadableStream();
5158
```
5259

5360
## Compatibility
5461

55-
The `polyfill` and `ponyfill` variants work in any ES5-compatible environment that has a global `Promise`.
62+
The `polyfill` and `ponyfill` variants work in any ES2015-compatible environment.
63+
64+
The `polyfill/es5` and `ponyfill/es5` variants work in any ES5-compatible environment that has a global `Promise`.
5665
If you need to support older browsers or Node versions that do not have a native `Promise` implementation
5766
(check the [support table][promise-support]), you must first include a `Promise` polyfill
5867
(e.g. [promise-polyfill][promise-polyfill]).
5968

60-
The `polyfill/es6` and `ponyfill/es6` variants work in any ES2015-compatible environment.
61-
62-
The `polyfill/es2018` and `ponyfill/es2018` variants work in any ES2018-compatible environment.
63-
6469
[Async iterable support for `ReadableStream`][rs-asynciterator] is available in all variants, but requires an ES2018-compatible environment or a polyfill for `Symbol.asyncIterator`.
6570

6671
[`WritableStreamDefaultController.signal`][ws-controller-signal] is available in all variants, but requires a global `AbortController` constructor. If necessary, consider using a polyfill such as [abortcontroller-polyfill].
6772

6873
[Reading with a BYOB reader][mdn-byob-read] is available in all variants, but requires `ArrayBuffer.prototype.transfer()` or `structuredClone()` to exist in order to correctly transfer the given view's buffer. If not available, then the buffer won't be transferred during the read.
6974

75+
### Tooling compatibility
76+
77+
This package uses [subpath exports](https://nodejs.org/api/packages.html#subpath-exports) for its variants. As such, you need Node 12 or higher in order to `import` or `require()` such a variant.
78+
79+
When using TypeScript, make sure your [`moduleResolution`](https://www.typescriptlang.org/tsconfig#moduleResolution) is set to `"node16"`, `"nodenext"` or `"bundler"`.
80+
7081
## Compliance
7182

7283
The polyfill implements [version `4dc123a` (13 Nov 2023)][spec-snapshot] of the streams specification.
7384

7485
The polyfill is tested against the same [web platform tests][wpt] that are used by browsers to test their native implementations.
7586
The polyfill aims to pass all tests, although it allows some exceptions for practical reasons:
76-
* The `es2018` variant passes all of the tests.
77-
* The `es6` variant passes the same tests as the `es2018` variant, except for the [test for the prototype of `ReadableStream`'s async iterator][wpt-async-iterator-prototype].
87+
* The default (ES2015) variant passes all of the tests, except for the [test for the prototype of `ReadableStream`'s async iterator][wpt-async-iterator-prototype].
7888
Retrieving the correct `%AsyncIteratorPrototype%` requires using an async generator (`async function* () {}`), which is invalid syntax before ES2018.
7989
Instead, the polyfill [creates its own version][stub-async-iterator-prototype] which is functionally equivalent to the real prototype.
80-
* The `es5` variant passes the same tests as the `es6` variant, except for various tests about specific characteristics of the constructors, properties and methods.
90+
* The ES5 variant passes the same tests as the ES2015 variant, except for various tests about specific characteristics of the constructors, properties and methods.
8191
These test failures do not affect the run-time behavior of the polyfill.
8292
For example:
8393
* The `name` property of down-leveled constructors is incorrect.
@@ -97,6 +107,7 @@ Thanks to these people for their work on [the original polyfill][creatorrr-polyf
97107
[spec]: https://streams.spec.whatwg.org
98108
[ref-impl]: https://github.com/whatwg/streams
99109
[ponyfill]: https://github.com/sindresorhus/ponyfill
110+
[migrating]: https://github.com/MattiasBuelens/web-streams-polyfill/blob/v4/MIGRATING.md
100111
[promise-support]: https://kangax.github.io/compat-table/es6/#test-Promise
101112
[promise-polyfill]: https://www.npmjs.com/package/promise-polyfill
102113
[rs-asynciterator]: https://streams.spec.whatwg.org/#rs-asynciterator

api-extractor.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*
4646
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
4747
*/
48-
"mainEntryPointFilePath": "<projectFolder>/lib/polyfill.d.ts",
48+
"mainEntryPointFilePath": "<projectFolder>/lib/ponyfill.d.ts",
4949

5050
/**
5151
* A list of NPM package names whose exports should be treated as part of this package.
@@ -195,7 +195,7 @@
195195
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
196196
* DEFAULT VALUE: "<projectFolder>/dist/<unscopedPackageName>.d.ts"
197197
*/
198-
"untrimmedFilePath": "<projectFolder>/dist/types/ts3.6/ponyfill.d.ts",
198+
"untrimmedFilePath": "<projectFolder>/types/ponyfill.d.ts",
199199

200200
/**
201201
* Specifies the output path for a .d.ts rollup file to be generated with trimming for a "beta" release.
@@ -256,7 +256,7 @@
256256
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
257257
* DEFAULT VALUE: "<lookup>"
258258
*/
259-
"tsdocMetadataFilePath": "<projectFolder>/dist/types/tsdoc-metadata.json"
259+
"tsdocMetadataFilePath": "<projectFolder>/types/tsdoc-metadata.json"
260260
},
261261
/**
262262
* Specifies what type of newlines API Extractor should use when writing output files. By default, the output files

0 commit comments

Comments
 (0)