feat!: drop node@16 support (#883)

This commit is contained in:
Robert Kieffer
2025-06-28 10:37:33 -10:00
committed by GitHub
parent 3f79e41857
commit 70d5e0f169
21 changed files with 91 additions and 362 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x, 20.x, 22.x, 24.x]
node-version: [18.x, 20.x, 22.x, 24.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
+2 -1
View File
@@ -1,8 +1,9 @@
*.tgz
browserstack.err
dist/
dist-browser/
.build/
local.log
logs/
node_modules/
examples/**/package-lock.json
examples/**/package-lock.json
+8 -19
View File
@@ -8,7 +8,6 @@ For the creation of [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html) (form
- **Complete** - Support for all RFC9562 UUID versions
- **Cross-platform** - Support for...
- ESM & Common JS
- [Typescript](#support)
- [Chrome, Safari, Firefox, and Edge](#support)
- [NodeJS](#support)
@@ -19,10 +18,8 @@ For the creation of [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html) (form
<!-- prettier-ignore -->
> [!NOTE]
> `uuid@11` is now available: See the [CHANGELOG](./CHANGELOG.md) for details. TL;DR:
> * TypeScript support is now included (remove `@types/uuid` from your dependencies)
> * Subtle changes to how the `options` arg is interpreted for `v1()`, `v6()`, and `v7()`. [See details](#options-handling-for-timestamp-uuids)
> * Binary UUIDs are now `Uint8Array`s. (May impact callers of `parse()`, `stringify()`, or that pass an `option#buf` argument to `v1()`-`v7()`.)
>
> As of `uuid@12` CommonJS is no longer supported. See [ESM Module FAQ](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
## Quickstart
@@ -34,20 +31,12 @@ npm install uuid
**2. Create a UUID**
ESM-syntax (must use named exports):
```javascript
import { v4 as uuidv4 } from 'uuid';
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
```
... CommonJS:
```javascript
const { v4: uuidv4 } = require('uuid');
uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
```
For timestamp UUIDs, namespace UUIDs, and other options read on ...
## API Summary
@@ -198,7 +187,7 @@ Example:
```javascript
import { v1 as uuidv1 } from 'uuid';
uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-9bdd-2b0d7b3dcb6d'
uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-9b5d-ab8dfbbd4bed'
```
Example using `options`:
@@ -253,7 +242,7 @@ Example:
```javascript
import { v4 as uuidv4 } from 'uuid';
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
```
Example using predefined `random` values:
@@ -329,7 +318,7 @@ This method takes the same arguments as uuid.v1().
```javascript
import { v6 as uuidv6 } from 'uuid';
uuidv6(); // ⇨ '1e940672-c5ea-64c0-9b5d-ab8dfbbd4bed'
uuidv6(); // ⇨ '1e940672-c5ea-64c1-9bdd-2b0d7b3dcb6d'
```
Example using `options`:
@@ -376,7 +365,7 @@ Example:
```javascript
import { v7 as uuidv7 } from 'uuid';
uuidv7(); // ⇨ '01695553-c90c-705a-b56d-778dfbbd4bed'
uuidv7(); // ⇨ '01695553-c90c-745a-b76f-770d7b3dcb6d'
```
### ~~uuid.v8()~~
@@ -483,7 +472,7 @@ Prior to `uuid@11`, it was possible for `options` state to interfere with the in
**Browsers**: `uuid` [builds are tested](/uuidjs/uuid/blob/main/wdio.conf.js) against the latest version of desktop Chrome, Safari, Firefox, and Edge. Mobile versions of these same browsers are expected to work but aren't currently tested.
**Node**: `uuid` [builds are tested](https://github.com/uuidjs/uuid/blob/main/.github/workflows/ci.yml#L26-L27) against node ([LTS releases](https://github.com/nodejs/Release)), plus one prior. E.g. `node@18` is in maintainence mode, and `node@22` is the current LTS release. So `uuid` supports `node@16`-`node@22`.
**Node**: `uuid` [builds are tested](https://github.com/uuidjs/uuid/blob/main/.github/workflows/ci.yml#L26-L27) against node ([LTS releases](https://github.com/nodejs/Release)), plus one prior. E.g. At the time of this writing `node@20` is the "maintenance" release and `node@24` is the "current" release, so `uuid` supports `node@18`-`node@24`.
**Typescript**: TS versions released within the past two years are supported. [source](https://github.com/microsoft/TypeScript/issues/49088#issuecomment-2468723715)
+9 -18
View File
@@ -1,20 +1,22 @@
```javascript --hide
import crypto from 'crypto';
runmd.onRequire = (path) => {
if (path == 'rng') return fun;
return path.replace(/^uuid/, './dist/cjs/');
return path.replace(/^uuid/, './dist/');
};
// Shim Date and crypto so generated ids are consistent across doc revisions
runmd.Date.now = () => 1551914748172;
let seed = 0xdefaced;
require('crypto').randomFillSync = function (a) {
for (let i = 0; i < 16; i++) a[i] = (seed = (seed * 0x41a7) & 0x7fffffff) & 0xff;
crypto.randomFillSync = function (a) {
for (let i = 0; i < a.length; i++) a[i] = (seed = (seed * 0x41a7) & 0x7fffffff) & 0xff;
return a;
};
// Prevent usage of native randomUUID implementation to ensure deterministic UUIDs
require('crypto').randomUUID = undefined;
crypto.randomUUID = undefined;
```
# uuid [![CI](https://github.com/uuidjs/uuid/workflows/CI/badge.svg)](https://github.com/uuidjs/uuid/actions?query=workflow%3ACI) [![Browser](https://github.com/uuidjs/uuid/workflows/Browser/badge.svg)](https://github.com/uuidjs/uuid/actions/workflows/browser.yml)
@@ -23,7 +25,6 @@ For the creation of [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html) (form
- **Complete** - Support for all RFC9562 UUID versions
- **Cross-platform** - Support for...
- ESM & Common JS
- [Typescript](#support)
- [Chrome, Safari, Firefox, and Edge](#support)
- [NodeJS](#support)
@@ -34,10 +35,8 @@ For the creation of [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html) (form
<!-- prettier-ignore -->
> [!NOTE]
> `uuid@11` is now available: See the [CHANGELOG](./CHANGELOG.md) for details. TL;DR:
> * TypeScript support is now included (remove `@types/uuid` from your dependencies)
> * Subtle changes to how the `options` arg is interpreted for `v1()`, `v6()`, and `v7()`. [See details](#options-handling-for-timestamp-uuids)
> * Binary UUIDs are now `Uint8Array`s. (May impact callers of `parse()`, `stringify()`, or that pass an `option#buf` argument to `v1()`-`v7()`.)
>
> As of `uuid@12` CommonJS is no longer supported. See [ESM Module FAQ](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
## Quickstart
@@ -49,17 +48,9 @@ npm install uuid
**2. Create a UUID**
ESM-syntax (must use named exports):
```javascript --run
import { v4 as uuidv4 } from 'uuid';
uuidv4(); // RESULT
```
... CommonJS:
```javascript --run
const { v4: uuidv4 } = require('uuid');
uuidv4(); // RESULT
```
@@ -492,7 +483,7 @@ Prior to `uuid@11`, it was possible for `options` state to interfere with the in
**Browsers**: `uuid` [builds are tested](/uuidjs/uuid/blob/main/wdio.conf.js) against the latest version of desktop Chrome, Safari, Firefox, and Edge. Mobile versions of these same browsers are expected to work but aren't currently tested.
**Node**: `uuid` [builds are tested](https://github.com/uuidjs/uuid/blob/main/.github/workflows/ci.yml#L26-L27) against node ([LTS releases](https://github.com/nodejs/Release)), plus one prior. E.g. `node@18` is in maintainence mode, and `node@22` is the current LTS release. So `uuid` supports `node@16`-`node@22`.
**Node**: `uuid` [builds are tested](https://github.com/uuidjs/uuid/blob/main/.github/workflows/ci.yml#L26-L27) against node ([LTS releases](https://github.com/nodejs/Release)), plus one prior. E.g. At the time of this writing `node@20` is the "maintenance" release and `node@24` is the "current" release, so `uuid` supports `node@18`-`node@24`.
**Typescript**: TS versions released within the past two years are supported. [source](https://github.com/microsoft/TypeScript/issues/49088#issuecomment-2468723715)
+9 -9
View File
@@ -1,8 +1,8 @@
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const terser = require('@rollup/plugin-terser');
import { nodeResolve } from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
const plugins = [nodeResolve({ browser: true }), terser()];
module.exports = [
export default [
{
input: './example-all.js',
output: {
@@ -44,7 +44,7 @@ module.exports = [
input: './size-v1.js',
output: {
file: 'dist/v1-size.js',
format: 'cjs',
format: 'es',
},
plugins,
},
@@ -52,7 +52,7 @@ module.exports = [
input: './size-v3.js',
output: {
file: 'dist/v3-size.js',
format: 'cjs',
format: 'es',
},
plugins,
},
@@ -60,7 +60,7 @@ module.exports = [
input: './size-v4.js',
output: {
file: 'dist/v4-size.js',
format: 'cjs',
format: 'es',
},
plugins,
},
@@ -68,7 +68,7 @@ module.exports = [
input: './size-v5.js',
output: {
file: 'dist/v5-size.js',
format: 'cjs',
format: 'es',
},
plugins,
},
@@ -76,7 +76,7 @@ module.exports = [
input: './size-v6.js',
output: {
file: 'dist/v6-size.js',
format: 'cjs',
format: 'es',
},
plugins,
},
@@ -84,7 +84,7 @@ module.exports = [
input: './size-v7.js',
output: {
file: 'dist/v7-size.js',
format: 'cjs',
format: 'es',
},
plugins,
},
@@ -1,9 +0,0 @@
<!doctype html>
<html>
<head>
<title>UUID esmodule webpack example</title>
</head>
<body>
<script type="text/javascript" src="./dist/allRequire.js"></script>
</body>
</html>
@@ -1,96 +0,0 @@
const uuid = require('uuid');
const {
NIL: NIL_UUID,
MAX: MAX_UUID,
parse: uuidParse,
stringify: uuidStringify,
v1: uuidv1,
v1ToV6: uuidv1ToV6,
v3: uuidv3,
v4: uuidv4,
v5: uuidv5,
v6: uuidv6,
v6ToV1: uuidv6ToV1,
v7: uuidv7,
validate: uuidValidate,
version: uuidVersion,
} = uuid;
const { default: testpage } = require('../utils/testpage');
testpage(function (addTest, done) {
addTest('Named exports');
addTest('uuidv1()', uuidv1());
addTest('uuidv4()', uuidv4());
addTest('uuidv7()', uuidv7());
// ... using predefined DNS namespace (for domain names)
addTest('uuidv3() DNS', uuidv3('hello.example.com', uuidv3.DNS));
// ... using predefined URL namespace (for, well, URLs)
addTest('uuidv3() URL', uuidv3('http://example.com/hello', uuidv3.URL));
// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c';
addTest('uuidv3() MY_NAMESPACE', uuidv3('Hello, World!', MY_NAMESPACE));
// ... using predefined DNS namespace (for domain names)
addTest('uuidv5() DNS', uuidv5('hello.example.com', uuidv5.DNS));
// ... using predefined URL namespace (for, well, URLs)
addTest('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL));
// v6 <-> v1 conversion
const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
addTest('uuidv1ToV6()', uuidv1ToV6(V1_ID));
addTest('uuidv6ToV1()', uuidv6ToV1(V6_ID));
// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
addTest('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));
addTest('uuidv6()', uuidv6());
// Utility functions
addTest('NIL_UUID', NIL_UUID);
addTest('MAX_UUID', MAX_UUID);
addTest('uuidParse()', uuidParse(MY_NAMESPACE));
addTest('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
addTest('uuidValidate()', uuidValidate(MY_NAMESPACE));
addTest('uuidVersion()', uuidVersion(MY_NAMESPACE));
addTest('Default export');
addTest('uuid.v1()', uuid.v1());
addTest('uuid.v4()', uuid.v4());
addTest('uuid.v7()', uuid.v7());
addTest('uuid.v3() DNS', uuid.v3('hello.example.com', uuid.v3.DNS));
addTest('uuid.v3() URL', uuid.v3('http://example.com/hello', uuid.v3.URL));
addTest('uuid.v3() MY_NAMESPACE', uuid.v3('Hello, World!', MY_NAMESPACE));
addTest('uuid.v5() DNS', uuid.v5('hello.example.com', uuid.v5.DNS));
addTest('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
addTest('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));
addTest('uuid.v6()', uuid.v6());
addTest('uuid.v1ToV6()', uuid.v1ToV6(V1_ID));
addTest('uuid.v6ToV1()', uuid.v6ToV1(V6_ID));
addTest('uuid.NIL', uuid.NIL);
addTest('uuid.MAX', uuid.MAX);
addTest('uuid.parse()', uuid.parse(MY_NAMESPACE));
addTest('uuid.stringify()', uuid.stringify(uuid.parse(MY_NAMESPACE)));
addTest('uuid.validate()', uuid.validate(MY_NAMESPACE));
addTest('uuid.version()', uuid.version(MY_NAMESPACE));
done();
});
@@ -5,7 +5,6 @@ module.exports = {
},
entry: {
all: './example-all.js',
allRequire: './example-all-require.js',
v1: './example-v1.js',
v4: './example-v4.js',
v7: './example-v7.js',
-6
View File
@@ -1,6 +0,0 @@
# uuid example Node.js CommonJS
```
npm install
npm test
```
-92
View File
@@ -1,92 +0,0 @@
const {
NIL: NIL_UUID,
MAX: MAX_UUID,
parse: uuidParse,
stringify: uuidStringify,
v1: uuidv1,
v1ToV6: uuidv1ToV6,
v3: uuidv3,
v4: uuidv4,
v5: uuidv5,
v6: uuidv6,
v6ToV1: uuidv6ToV1,
v7: uuidv7,
validate: uuidValidate,
version: uuidVersion,
} = require('uuid');
const uuid = require('uuid');
const pkg = require('uuid/package.json');
console.log('uuidv1()', uuidv1());
console.log('uuidv4()', uuidv4());
console.log('uuidv7()', uuidv7());
// ... using predefined DNS namespace (for domain names)
console.log('uuidv3() DNS', uuidv3('hello.example.com', uuidv3.DNS));
// ... using predefined URL namespace (for, well, URLs)
console.log('uuidv3() URL', uuidv3('http://example.com/hello', uuidv3.URL));
// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c';
console.log('uuidv3() MY_NAMESPACE', uuidv3('Hello, World!', MY_NAMESPACE));
// ... using predefined DNS namespace (for domain names)
console.log('uuidv5() DNS', uuidv5('hello.example.com', uuidv5.DNS));
// ... using predefined URL namespace (for, well, URLs)
console.log('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL));
// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
console.log('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));
console.log('uuidv6()', uuidv6());
// v6 <-> v1 conversion
const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
console.log('uuidv1ToV6()', uuidv1ToV6(V1_ID));
console.log('uuidv6ToV1()', uuidv6ToV1(V6_ID));
// Utility functions
console.log('NIL_UUID', NIL_UUID);
console.log('MAX_UUID', MAX_UUID);
console.log('uuidParse()', uuidParse(MY_NAMESPACE));
console.log('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
console.log('uuidValidate()', uuidValidate(MY_NAMESPACE));
console.log('uuidVersion()', uuidVersion(MY_NAMESPACE));
console.log('Same with default export');
console.log('uuid.v1()', uuid.v1());
console.log('uuid.v4()', uuid.v4());
console.log('uuid.v7()', uuid.v7());
console.log('uuid.v3() DNS', uuid.v3('hello.example.com', uuid.v3.DNS));
console.log('uuid.v3() URL', uuid.v3('http://example.com/hello', uuid.v3.URL));
console.log('uuid.v3() MY_NAMESPACE', uuid.v3('Hello, World!', MY_NAMESPACE));
console.log('uuid.v5() DNS', uuid.v5('hello.example.com', uuid.v5.DNS));
console.log('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
console.log('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));
console.log('uuid.v6()', uuid.v6());
console.log('uuid.v1ToV6()', uuid.v1ToV6(V1_ID));
console.log('uuid.v6ToV1()', uuid.v6ToV1(V6_ID));
console.log('uuid.NIL', uuid.NIL);
console.log('uuid.MAX', uuid.MAX);
console.log('uuid.parse()', uuid.parse(MY_NAMESPACE));
console.log('uuid.stringify()', uuid.stringify(uuid.parse(MY_NAMESPACE)));
console.log('uuid.validate()', uuid.validate(MY_NAMESPACE));
console.log('uuid.version()', uuid.version(MY_NAMESPACE));
// Some tools like react-native need to introspect the package.json file
console.log('pkg.name', pkg.name);
-12
View File
@@ -1,12 +0,0 @@
{
"name": "uuid-example-node-commonjs",
"version": "0.0.0",
"private": true,
"scripts": {
"pretest": "rm -fr node_modules && npm install --no-package-lock",
"test": "node example.js"
},
"dependencies": {
"uuid": "file:../../.build/uuid.tgz"
}
}
+1 -1
View File
@@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"scripts": {
"test:package": "( node --version | grep -vq 'v16' ) || ( node --experimental-json-modules package.mjs )",
"test:package": "( node --version | grep -vq 'v18' ) || ( node package.mjs )",
"test:example": "node example.mjs",
"pretest": "rm -fr node_modules && npm install --no-package-lock",
"test": "npm-run-all test:*"
+1 -2
View File
@@ -1,6 +1,5 @@
/** @jest-environment jsdom */
const uuid = require('uuid');
import * as uuid from 'uuid';
test('uuidv4()', () => {
const val = uuid.v4();
+1 -1
View File
@@ -1,4 +1,4 @@
const uuid = require('uuid');
import * as uuid from 'uuid';
test('uuidv4()', () => {
const val = uuid.v4();
+4 -3
View File
@@ -2,15 +2,16 @@
"name": "uuid-example-node-jest",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"pretest": "rm -fr node_modules && npm install --no-package-lock",
"test": "jest"
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest"
},
"dependencies": {
"uuid": "file:../../.build/uuid.tgz"
},
"devDependencies": {
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0"
"jest": "30.0.2",
"jest-environment-jsdom": "30.0.2"
}
}
+9 -21
View File
@@ -20,32 +20,21 @@
],
"license": "MIT",
"bin": {
"uuid": "./dist/esm/bin/uuid"
"uuid": "./dist/bin/uuid"
},
"sideEffects": false,
"main": "./dist/cjs/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"node": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"browser": {
"import": "./dist/esm-browser/index.js",
"require": "./dist/cjs-browser/index.js"
},
"default": "./dist/esm-browser/index.js"
"browser": "./dist-browser/index.js",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"module": "./dist/esm/index.js",
"browser": {
"./dist/esm/index.js": "./dist/esm-browser/index.js",
"./dist/cjs/index.js": "./dist/cjs-browser/index.js"
},
"files": [
"dist",
"!dist/**/test"
"dist-browser",
"!**/test"
],
"devDependencies": {
"@babel/eslint-parser": "7.27.1",
@@ -80,7 +69,7 @@
},
"scripts": {
"build": "./scripts/build.sh",
"build:watch": "tsc --watch -p tsconfig.esm.json",
"build:watch": "tsc --watch -p tsconfig.json",
"bundlewatch": "npm run pretest:browser && bundlewatch --config bundlewatch.config.json",
"docs:diff": "npm run docs && git diff --quiet README.md",
"docs": "npm run build && npx runmd --output=README.md README_js.md",
@@ -88,7 +77,6 @@
"eslint:fix": "eslint --fix src/ test/ examples/ *.[jt]s",
"examples:browser:rollup:build": "cd examples/browser-rollup && npm run build",
"examples:browser:webpack:build": "cd examples/browser-webpack && npm run build",
"examples:node:commonjs:test": "cd examples/node-commonjs && npm test",
"examples:node:esmodules:test": "cd examples/node-esmodules && npm test",
"examples:node:jest:test": "cd examples/node-jest && npm test",
"examples:node:typescript:test": "cd examples/typescript && npm test",
@@ -107,8 +95,8 @@
"test:benchmark": "cd examples/benchmark && npm test",
"test:browser": "wdio run ./wdio.conf.js",
"test:node": "npm-run-all --parallel examples:node:**",
"test:watch": "node --test --enable-source-maps --watch dist/esm/test/*.js",
"test": "node --test --enable-source-maps dist/esm/test/*.js"
"test:watch": "node --test --enable-source-maps --watch dist/test/*.js",
"test": "node --test --enable-source-maps dist/test/*.js"
},
"repository": {
"type": "git",
+33 -40
View File
@@ -1,10 +1,8 @@
#!/bin/bash -eu
# This script generates 4 builds, as follows:
# - dist/esm: ESM build for Node.js
# - dist/esm-browser: ESM build for the Browser
# - dist/cjs: CommonJS build for Node.js
# - dist/cjs-browser: CommonJS build for the Browser
# - dist: ESM build for Node.js
# - dist-browser: ESM build for the Browser
#
# Note: that the "preferred" build for testing (local and CI) is the ESM build,
# except where we specifically test the other builds
@@ -12,53 +10,48 @@
set -e # exit on error
# Change to project root
ROOT="$(pwd)/$(dirname "$0")/.."
cd "$ROOT" || exit 1
ROOT=$(builtin cd $(pwd)/$(dirname "$0")/..; pwd)
# Prep TS output dir
DIST_DIR="$ROOT/dist"
rm -rf "$DIST_DIR"
mkdir -p "$DIST_DIR"
NODE_DIST_DIR="$ROOT/dist"
BROWSER_DIST_DIR="$ROOT/dist-browser"
echo "Building in $NODE_DIST_DIR and $BROWSER_DIST_DIR"
cd "$ROOT" || exit 1
rm -rf "$NODE_DIST_DIR" "$BROWSER_DIST_DIR"
mkdir -p "$NODE_DIST_DIR"
# Build each module type
for MODULE_TYPE in esm cjs; do
echo "Building ${MODULE_TYPE}"
echo "Compiling TypeScript files to $NODE_DIST_DIR"
NODE_DIST_DIR="$DIST_DIR/${MODULE_TYPE}"
BROWSER_DIST_DIR="$DIST_DIR/${MODULE_TYPE}-browser"
tsc -p tsconfig.json
tsc -p tsconfig.${MODULE_TYPE}.json
# Clone files for browser builds
cp -pr "$NODE_DIST_DIR" "$BROWSER_DIST_DIR"
# Clone files for browser builds
cp -pr ${NODE_DIST_DIR} ${BROWSER_DIST_DIR}
# Remove browser files from non-browser builds
for FILE in ${NODE_DIST_DIR}/*-browser*; do
rm -f $FILE
done
# Remove browser files from non-browser builds
for FILE in ${NODE_DIST_DIR}/*-browser*;do
rm -f $FILE
# Move browser files into place for browser builds
(
# Temporarily cd into BROWSER_DIST_DIR to avoid having to deal with
# "-browser" appearing in both the dir name and file name of FILE's full
# path
cd "$BROWSER_DIST_DIR"
for FILE in *-browser*;do
mv "$FILE" "${FILE/-browser/}"
done
# Move browser files into place for browser builds
(
# Temporarily cd into BROWSER_DIST_DIR to avoid having to deal with
# "-browser" appearing in both the dir name and file name of FILE's full
# path
cd ${BROWSER_DIST_DIR}
# Remove type definitions
find . -name '*.d.ts' -exec rm -f {} \;
)
for FILE in *-browser*;do
mv $FILE ${FILE/-browser/}
done
)
# esm/cjs-specific logic
if [ "$MODULE_TYPE" = "esm" ]; then
# ESM: copy bin files to dist
cp -pr "$DIST_DIR/../src/bin" "$NODE_DIST_DIR"
else
# CJS: Add package.json that specifies type: commonjs
echo "{\"type\":\"commonjs\"}" > "$NODE_DIST_DIR/package.json"
echo "{\"type\":\"commonjs\"}" > "$BROWSER_DIST_DIR/package.json"
fi
done
# Copy bin files to dist
cp -pr "$NODE_DIST_DIR/../src/bin" "$NODE_DIST_DIR"
if [ "${1-}" != "--no-pack" ]; then
# Prep tarball dir
-10
View File
@@ -1,10 +0,0 @@
{
"compilerOptions": {
"declaration": true,
"removeComments": true,
"skipLibCheck": true,
"strict": true,
"target": "ES2022"
},
"exclude": ["dist", "examples"]
}
-8
View File
@@ -1,8 +0,0 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "./dist/cjs"
}
}
-8
View File
@@ -1,8 +0,0 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "./dist/esm"
}
}
+13 -4
View File
@@ -1,4 +1,13 @@
// NOTE: Do not extend or alter this file. This file is only here to point
// VSCode to the correct config file. (There's no way of configuring the path
// VSCode uses for the tsconfig.json file)
{ "extends": "./tsconfig.esm.json" }
{
"compilerOptions": {
"declaration": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "./dist",
"removeComments": true,
"skipLibCheck": true,
"strict": true,
"target": "ES2022"
},
"exclude": ["dist", "examples"]
}