Skip to content

Commit

Permalink
Output ESM format to browsers instead of IIFE
Browse files Browse the repository at this point in the history
  • Loading branch information
cowwoc committed Nov 29, 2023
1 parent bf850e2 commit 036b6ed
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 34 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ A [fluent API](https://en.wikipedia.org/wiki/Fluent_interface) for enforcing
To get started, add this dependency:

```shell
npm install --save @cowwoc/[email protected].0
npm install --save @cowwoc/[email protected].1
```

or [pnpm](https://pnpm.io/):

```shell
pnpm add @cowwoc/[email protected].0
pnpm add @cowwoc/[email protected].1
```

The contents of the API classes depend on which [modules](wiki/Supported_Libraries.md) are enabled.
Expand All @@ -40,29 +40,29 @@ class Address

class PublicAPI
{
constructor(name: string | null, age: number, address: Address | undefined)
{
// To validate user input, cast them to "unknown" prior to type-checks.
requireThat(name as unknown, "name").isString().length().isBetween(1, 30);
requireThat(age as unknown, "age").isNumber().isBetween(18, 30);

// Methods that conduct runtime type-checks, such as isString() or isNotNull(), update the
// compile-time type returned by getActual().
const nameIsString: string = requireThat(name as unknown, "name").isString().getActual();
const address: Address = requireThat(address as unknown, "address").isInstance(Address).getActual();
}
constructor(name: string | null, age: number, address: Address | undefined)
{
// To validate user input, cast them to "unknown" prior to type-checks.
requireThat(name as unknown, "name").isString().length().isBetween(1, 30);
requireThat(age as unknown, "age").isNumber().isBetween(18, 30);

// Methods that conduct runtime type-checks, such as isString() or isNotNull(), update the
// compile-time type returned by getActual().
const nameIsString: string = requireThat(name as unknown, "name").isString().getActual();
const address: Address = requireThat(address as unknown, "address").isInstance(Address).getActual();
}
}

class PrivateAPI
{
public static toCamelCase(text): string
{
// Trusted input does not need to be casted to "unknown". The input type will be inferred
// and runtime checks will be skipped. Notice the lack of isString() or isNumber() invocations
// in the following code.
assertThat(r => r.requireThat(name, "name").length().isBetween(1, 30));
assertThat(r => r.requireThat(age, "age").isBetween(18, 30));
}
public static toCamelCase(text): string
{
// Trusted input does not need to be casted to "unknown". The input type will be inferred
// and runtime checks will be skipped. Notice the lack of isString() or isNumber() invocations
// in the following code.
assertThat(r => r.requireThat(name, "name").length().isBetween(1, 30));
assertThat(r => r.requireThat(age, "age").isBetween(18, 30));
}
}
```

Expand Down
12 changes: 0 additions & 12 deletions build.mts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ class Build
{
input: "src/index.mts",
plugins,
// Assume that the top-level "this" is "window" since we are targeting a browser environment
context: "window",
onwarn(warning, warn)
{
// Ignore false alarm about circular dependencies involving internal.mts
Expand All @@ -161,16 +159,6 @@ class Build
});
await bundle.write(
{
// On the browser, module exports need to be translated into global variables (properties of "window"):
// https://github.com/rollup/rollup/issues/494#issuecomment-268243574
name: "window",
extend: true,
format: "iife",
globals:
{
lodash: "_",
tty: "tty"
},
sourcemap: true,
dir: "target/publish/browser"
});
Expand Down
4 changes: 4 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Minor updates involving cosmetic changes have been omitted from this list. See
https://github.com/cowwoc/requirements.java/commits/master for a full list.

## Version 3.3.1 - 2023/11/29

* Bugfix: Output ESM format to browsers instead of IIFE

## Version 3.3.0 - 2023/11/29

* Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cowwoc/requirements",
"version": "3.3.0",
"version": "3.3.1",
"keywords": [
"preconditions",
"postconditions",
Expand Down

0 comments on commit 036b6ed

Please sign in to comment.