Skip to content

Commit

Permalink
Fix exports (#371)
Browse files Browse the repository at this point in the history
* fix(throwerror): fix throwerror.ts file name

* fix(exports): fix missing .js extensions in includes and ignoreelements

* chore(dependencies): update dependencies

* fix(exports): make top-level exports match the directory names

* fix lint

* add node v22.x to CI matrix

* remove esm from the build

* don't redirect stderr to /dev/null
  • Loading branch information
trxcllnt authored Jul 10, 2024
1 parent e32fc16 commit d461eae
Show file tree
Hide file tree
Showing 45 changed files with 893 additions and 743 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ jobs:
- {bundler: rollup, target: ix}
- {bundler: webpack, target: ix}
steps:
- name: Setup node v20.x
- name: Setup node v22.x
uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 22.x
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Construct cache keys
run: |
echo node_modules_key='["${{ runner.os }}", "node_modules", "20.x", "${{ hashFiles('package.json', 'yarn.lock') }}"]' >> $GITHUB_ENV;
echo targets_key='["${{ runner.os }}", "targets", "20.x", "ix", "", "${{ hashFiles('package.json', 'yarn.lock', 'tsconfig.json', 'src/**/*', 'tsconfigs/**/*') }}"]' >> $GITHUB_ENV;
echo node_modules_key='["${{ runner.os }}", "node_modules", "22.x", "${{ hashFiles('package.json', 'yarn.lock') }}"]' >> $GITHUB_ENV;
echo targets_key='["${{ runner.os }}", "targets", "22.x", "ix", "", "${{ hashFiles('package.json', 'yarn.lock', 'tsconfig.json', 'src/**/*', 'tsconfigs/**/*') }}"]' >> $GITHUB_ENV;
- name: Cache targets
uses: actions/cache@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: Setup node v20.x
- name: Setup node v22.x
uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 22.x

- name: Checkout
uses: actions/checkout@v4
Expand All @@ -20,7 +20,7 @@ jobs:

- name: Construct cache keys
run: |
echo node_modules_key='["${{ runner.os }}", "node_modules", "20.x", "${{ hashFiles('package.json', 'yarn.lock') }}"]' >> $GITHUB_ENV;
echo node_modules_key='["${{ runner.os }}", "node_modules", "22.x", "${{ hashFiles('package.json', 'yarn.lock') }}"]' >> $GITHUB_ENV;
- name: Cache node_modules
uses: actions/cache@v4
Expand Down
51 changes: 44 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [16.x, 18.x, 20.x]
node: [16.x, 18.x, 20.x, 22.x]
target: [es5, es2015, esnext]
module: [cjs, esm, umd]
include:
- {node: 16.x, target: ix}
- {node: 18.x, target: ix}
- {node: 20.x, target: ix}
- {node: 20.x, target: src, args: --coverage}
- {node: 22.x, target: ix}
- {node: 22.x, target: src, args: --coverage}
steps:
- name: Setup node v${{ matrix.node }}
uses: actions/setup-node@v4
Expand Down Expand Up @@ -98,6 +99,8 @@ jobs:
t: "${{ matrix.target }}"
m: "${{ matrix.module }}"
run: |
set -e;
targetdir="./targets${t:+/${t}}${m:+/${m}}";
pkg_name="$(jq -r '.name' "${targetdir}/package.json")";
pkg_type="$(jq -r '.type' "${targetdir}/package.json")";
Expand All @@ -108,16 +111,50 @@ jobs:
cd "${_tmp}/node_modules/${pkg_name}";
npm i;
cd "${_tmp}/";
import_paths=(
"${pkg_name}"
"${pkg_name}/Ix"
"${pkg_name}/Ix.iterable"
"${pkg_name}/Ix.iterable.operators"
"${pkg_name}/Ix.asynciterable"
"${pkg_name}/Ix.asynciterable.operators"
"${pkg_name}/iterable/index"
"${pkg_name}/iterable/operators"
"${pkg_name}/iterable/operators/index"
"${pkg_name}/asynciterable/index"
"${pkg_name}/asynciterable/operators"
"${pkg_name}/asynciterable/operators/index"
);
test_import_esm() {
local path;
for path in "${import_paths[@]}"; do
node --input-type=module -e "import '${path}'";
done
}
test_import_cjs() {
local path;
for path in "${import_paths[@]}"; do
node --input-type=commonjs -e "require('${path}')";
done
}
set -x;
if test "${pkg_type}" = "module"; then
# Test importing as ESModule
node --input-type=module -e "import '${pkg_name}'";
test_import_esm;
elif test "$m" = umd; then
# Test importing UMD as both CommonJS and ESM
test_import_cjs;
test_import_esm;
else
# Test importing as CommonJS
node --input-type=commonjs -e "require('${pkg_name}')";
# Test importing CommonJS module but allow it to fail
node --input-type=module -e "import '${pkg_name}'" || true;
# Test importing others as both CommonJS and ESM, but allow ESM to fail
test_import_cjs;
test_import_esm || true;
fi
set +x;
cd /;
rm -rf "${_tmp}";
18 changes: 9 additions & 9 deletions docs/asynciterable/converting.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Very often we have an existing data structure that we wish to convert to an asyn
The `as` method converts directly to an async-iterable, whereas with `from` method allows us to modify the collection as it is created, mimicking the the [`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from) method.

```typescript
import { as, from } from 'ix/Ix.asynciterable';
import { as, from } from 'ix/asynciterable';

// As with Array and Set
const result1 = as([1, 2, 3]); // From array
Expand Down Expand Up @@ -52,7 +52,7 @@ IxJS also gives seamless support for Observables, for those that implement the `

```typescript
import { observableOf } from 'rxjs';
import { as } from 'ix/Ix.asynciterable';
import { as } from 'ix/asynciterable';

const source = observableOf(1, 2, 3);
const results = as(source);
Expand All @@ -67,7 +67,7 @@ for await (const item of results) {
Streams and AsyncIterables go hand in hand as a pull to push model. DOM Streams are a newer concept, bringing streaming capabilities into the browser, and with IxJS, we can then convert those DOM streams into AsyncIterables using the `fromDOMStream` method.

```typescript
import { fromDOMStream } from 'ix/Ix.asynciterable';
import { fromDOMStream } from 'ix/asynciterable';

const response = await fetch('someurl');

Expand Down Expand Up @@ -97,7 +97,7 @@ We can then introduce IxJS by using the `fromNodeStream` which allows us then to

```typescript
import * as fs from 'fs';
import { fromNodeStream } from 'ix/Ix.node';
import { fromNodeStream } from 'ix/node';

const readable = fs.createReadStream('tmp.txt', {encoding: 'utf8'});
const source = fromNodeStream(readable);
Expand All @@ -111,9 +111,9 @@ Or we can use `asAsyncIterable()` to take advantage of Node Streams' fluent `pip

```typescript
import * as fs from 'fs';
import { map } from 'ix/Ix.asynciterable.operators';
import { flatMap } from 'ix/Ix.asynciterable.operators';
import { asAsyncIterable } from 'ix/Ix.node';
import { map } from 'ix/asynciterable/operators';
import { flatMap } from 'ix/asynciterable/operators';
import { asAsyncIterable } from 'ix/node';

const source = fs
.createReadStream('tmp.txt', {encoding: 'utf8'})
Expand All @@ -134,7 +134,7 @@ Although we traditionally think of events being push only such as Subject/Observ

```typescript
import { EventEmitter } from 'events';
import { fromEvent } from 'ix/Ix.asynciterable';
import { fromEvent } from 'ix/asynciterable';

function getEvents() {
const emitter = new EventEmitter();
Expand All @@ -160,7 +160,7 @@ The other type of binding is `fromEventPattern` which allows you to have an add

```typescript
import { EventEmitter } from 'events';
import { fromEventPattern } from 'ix/Ix.asynciterable';
import { fromEventPattern } from 'ix/asynciterable';

function getEvents() {
const emitter = new EventEmitter();
Expand Down
18 changes: 9 additions & 9 deletions docs/asynciterable/creating.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let value, done;
Very rarely will we ever need to create these async-iterables by hand, however, if you need a collection that you can add to as well as iterate, we have the `AsyncSink` class. This class serves as a basis for some of our operators such as binding to events and DOM and Node.js streams.

```typescript
import { AsyncSink } from 'ix/Ix.asynciterable';
import { AsyncSink } from 'ix/asynciterable';

const sink = new AsyncSink();
sink.write(1);
Expand All @@ -75,7 +75,7 @@ let value, done;
Now that we know the basics, we can take the async-iterable from above and create an AsyncIterable from the source using the `create` method. This takes in a function which takes in an optional `AbortSignal` for cancellation, and you return the the `[Symbol.asyncIterator]` method implementation. It's up to you whether to cancel based upon the incoming `AbortSignal`, whether to throw an `AbortError` or not.

```typescript
import { create } from 'ix/Ix.asynciterable';
import { create } from 'ix/asynciterable';

const source = {
data: [1, 2, 3],
Expand Down Expand Up @@ -104,7 +104,7 @@ for await (const item of results) {
Understanding the basics gets us so far, but we want to be able to easily create async-iterable sequences, for example, from known values. To do this, we have the `of` factory function which takes any number of arguments and converts those arguments into an async-iterable sequence. This implementation mimicks that of [`Array.of`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)

```typescript
import { of } from 'ix/Ix.asynciterable';
import { of } from 'ix/asynciterable';

const source = of(1, 2, 3, 4, 5);

Expand All @@ -118,7 +118,7 @@ for await (const item of source) {
There may be cases when you want to return an empty sequence, when iterated will always say it is complete. For that, we have the `empty` method.

```typescript
import { empty } from 'ix/Ix.asynciterable';
import { empty } from 'ix/asynciterable';

const source = empty();

Expand All @@ -130,7 +130,7 @@ const { value, done } = it.next();
There may also be cases where you never want the sequence to return. In the case of `never`, it can be used in places like `race` where the other sequence will always win.

```typescript
import { never, of, race } from 'ix/Ix.asynciterable';
import { never, of, race } from 'ix/asynciterable';

const source = race(of(1), never());

Expand All @@ -148,7 +148,7 @@ let value, done;
Another way we can create async-iterable sequences is with a range. For example, if we want 10 numbers starting at 1, we can use the `range` factory method to call `range(1, 10)`.

```typescript
import { range } from 'ix/Ix.asynciterable';
import { range } from 'ix/asynciterable';

const source = range(1, 10);

Expand All @@ -174,7 +174,7 @@ for (
The `generate` method has the same parameters as this for loop, as in our example here.

```typescript
import { generate } from 'ix/Ix.asynciterable';
import { generate } from 'ix/asynciterable';

const source = generate(
0, // Initial State
Expand All @@ -191,7 +191,7 @@ for await (const item of source) {
In addition to the `generate` method, we have the `generateTime` which adds a time element to the sequence to delay in milliseconds between results.

```typescript
import { generate } from 'ix/Ix.asynciterable';
import { generate } from 'ix/asynciterable';

const source = generate(
0, // Initial State
Expand All @@ -211,7 +211,7 @@ for await (const item of source) {
There are many factory functions that carry over from RxJS over to IxJS including `interval` where we can yield a value at a specified interval. For example, we can loop through a sequence, yielding a value every 1 second.

```typescript
import { interval } from 'ix/Ix.asynciterable';
import { interval } from 'ix/asynciterable';

const source = interval(1000 /* ms */);

Expand Down
18 changes: 9 additions & 9 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ The Interactive Extensions for JavaScript (IxJS) is a set of methods on top of `
Starting in ES6, the [`Symbol.iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator) method was introduced to allow for iteration over collections such as `Array`, `Map`, `Set` and even ``Generator`. IxJS introduces a number of creation factories and operators that operate on these `Iterable` collections lazily. Each factory can be imported from `'ix/iterable'` and operators from `'ix/iterable/operators'` such as the following creating an iterable via `of` and then transforming each item using the `map` operator. You can then iterate over the resulting collection using [`for ... of`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of) syntax, or the use of the `forEach` method.

```typescript
import { of } from 'ix/Ix.iterable';
import { map } from 'ix/Ix.iterable.operators';
import { of } from 'ix/iterable';
import { map } from 'ix/iterable/operators';

const source = of(1, 2, 3, 4, 5);
const result = source.pipe(
Expand All @@ -23,7 +23,7 @@ for (const item of result) {
Alternatively, you can program using dot-notation where we add methods to the `IterableX` object so we can program in a fluent style. We can bring in only the factories operators we need, therefore not needing to bring in the entire library with all its operators. The factories can be brought in via `'ix/add/iterable/<name>'` and operators via `'ix/add/iterable-operators/<name>'`, where `name` is replaced with the factory or operator of your choice.

```typescript
import { IterableX as Iterable } from 'ix/Ix.iterable';
import { IterableX as Iterable } from 'ix/iterable';

// Add factory and operators
import 'ix/add/iterable/of';
Expand Down Expand Up @@ -66,11 +66,11 @@ That's only the beginning with IxJS and each section below covers more in detail

## AsyncIterable

In ES2018, the concept of asynchronous iteration was introduced, which allowed the same kind of iteration we had in ES6, but for asynchronous sequences using the [`Symbol.asyncIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator) method for things such as asynchronous generators. IxJS here introduces a whole set of factories and operators on async iterables to serve as a standard class library, covering the same operators as `Iterable`, but also adding in asynchronous operations such as `race`, but also time based operations as well. Each factory such as `from`, an `of` can be imported via `'ix/Ix.asynciterable'` as well as operators such as `map` and `filter` can be imported via `'ix/Ix.asynciterable.operators'`. Once created, uou can then iterate over the resulting collection using [`for await ... of`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) syntax, or the use of the `forEach` method.
In ES2018, the concept of asynchronous iteration was introduced, which allowed the same kind of iteration we had in ES6, but for asynchronous sequences using the [`Symbol.asyncIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator) method for things such as asynchronous generators. IxJS here introduces a whole set of factories and operators on async iterables to serve as a standard class library, covering the same operators as `Iterable`, but also adding in asynchronous operations such as `race`, but also time based operations as well. Each factory such as `from`, an `of` can be imported via `'ix/asynciterable'` as well as operators such as `map` and `filter` can be imported via `'ix/asynciterable/operators'`. Once created, uou can then iterate over the resulting collection using [`for await ... of`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) syntax, or the use of the `forEach` method.

```typescript
import { as } from 'ix/Ix.asynciterable';
import { map } from 'ix/Ix.asynciterable.operators';
import { as } from 'ix/asynciterable';
import { map } from 'ix/asynciterable/operators';

const soureFactory = async function*() {
yield 1;
Expand All @@ -92,8 +92,8 @@ for await (const item of results) {
The [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) for the web brought in a new way to think about getting data using Promises instead of the legacy `XMLHttpRequest` API. With this also brought in the idea of cancellation via the [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) and [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal), also known as the Abort API. IxJS also supports this with a number of async aggregate operations such as `first`, `last` accepting an `AbortSignal` but also introducing `AbortSignal` support to pass through the entire chain. This section gives a very brief introduction for support but is documented later on below.

```typescript
import { as, last } from 'ix/Ix.asynciterable';
import { map, withAbort } from 'ix/Ix.asynciterable.operators';
import { as, last } from 'ix/asynciterable';
import { map, withAbort } from 'ix/asynciterable/operators';

const sourceFactory = async function*() {
yield 1;
Expand Down Expand Up @@ -123,7 +123,7 @@ for await (const item of result) {
If you prefer the fluent style of method chaining, IxJS also supports this for async-iterables via the `AsyncIterableX` object. Then you can add the factories or operators of your choosing without bringing in the entire library. The factories can be brought in via `'ix/add/asynciterable/<name>'` and operators via `'ix/add/asynciterable-operators/<name>'`, where `name` is replaced with the factory or operator of your choice.

```typescript
import { AsyncIterableX as AsyncIterable } from 'ix/Ix.asynciterable';
import { AsyncIterableX as AsyncIterable } from 'ix/asynciterable';
import 'ix/add/asynciterable/as';
import 'ix/add/asynciterable/last';
import 'ix/add/asynciterable-operators/map';
Expand Down
14 changes: 7 additions & 7 deletions gulp/bundle-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ export const esbuildTask = ((cache) => memoizeTask(cache, function pkgEsbuild(ta
].reduce((aliases, ext) => {
return [
'Ix',
'Ix.dom',
'Ix.node',
'Ix.iterable',
'Ix.asynciterable',
'Ix.iterable.operators',
'Ix.asynciterable.operators'
'dom',
'node',
'iterable',
'asynciterable',
'iterable/operators',
'asynciterable/operators'
].reduce((aliases, entrypoint) => ({
...aliases,
[`ix/${entrypoint}.${ext}`]: Path.join(pkgDir, `${entrypoint}.${ext}`)
Expand Down Expand Up @@ -135,7 +135,7 @@ export const webpackTask = ((cache) => memoizeTask(cache, function pkgWebpack(ta
]
},
resolve: {
extensions: ['.mjs', '.cjs', '.js'],
extensions: ['.mjs', '.js'],
alias: { 'ix': pkgDir }
},
stats: 'errors-only',
Expand Down
Loading

0 comments on commit d461eae

Please sign in to comment.