Skip to content

Commit

Permalink
feat: remove UMD build (#645)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Remove the minified UMD build from the package.

Minified code is hard to audit and since this is a widely used library
it seems more appropriate nowadays to optimize for auditability than to
ship a legacy module format that, at best, serves educational purposes
nowadays.

For production browser use cases, users should be using a bundler. For
educational purposes, today's online sandboxes like replit.com offer
convenient ways to load npm modules, so the use case for UMD through
repos like UNPKG or jsDelivr has largely vanished.

Fixes #620
  • Loading branch information
ctavan committed Aug 4, 2022
1 parent 0f433e5 commit e948a0f
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 823 deletions.
30 changes: 2 additions & 28 deletions README.md
Expand Up @@ -358,35 +358,9 @@ To load this module directly into modern browsers that [support loading ECMAScri

### UMD

To load this module directly into older browsers you can use the [UMD (Universal Module Definition)](https://github.com/umdjs/umd) builds from any of the following CDNs:
As of `uuid@9` [UMD (Universal Module Definition)](https://github.com/umdjs/umd) builds are no longer shipped with this library.

**Using [UNPKG](https://unpkg.com/uuid@latest/dist/umd/)**:

```html
<script src="https://unpkg.com/uuid@latest/dist/umd/uuidv4.min.js"></script>
```

**Using [jsDelivr](https://cdn.jsdelivr.net/npm/uuid@latest/dist/umd/)**:

```html
<script src="https://cdn.jsdelivr.net/npm/uuid@latest/dist/umd/uuidv4.min.js"></script>
```

**Using [cdnjs](https://cdnjs.com/libraries/uuid)**:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/uuid/8.1.0/uuidv4.min.js"></script>
```

These CDNs all provide the same [`uuidv4()`](#uuidv4options-buffer-offset) method:

```html
<script>
uuidv4(); // ⇨ '55af1e37-0734-46d8-b070-a1e42e4fc392'
</script>
```

Methods for the other algorithms ([`uuidv1()`](#uuidv1options-buffer-offset), [`uuidv3()`](#uuidv3name-namespace-buffer-offset) and [`uuidv5()`](#uuidv5name-namespace-buffer-offset)) are available from the files `uuidv1.min.js`, `uuidv3.min.js` and `uuidv5.min.js` respectively.
If you need a UMD build of this library, use a bundler like Webpack or Rollup. Alternatively, refer to the documentation of [`uuid@8.3.2`](https://github.com/uuidjs/uuid/blob/v8.3.2/README.md#umd) which was the last version that shipped UMD builds.

## Known issues

Expand Down
30 changes: 2 additions & 28 deletions README_js.md
Expand Up @@ -367,35 +367,9 @@ To load this module directly into modern browsers that [support loading ECMAScri

### UMD

To load this module directly into older browsers you can use the [UMD (Universal Module Definition)](https://github.com/umdjs/umd) builds from any of the following CDNs:
As of `uuid@9` [UMD (Universal Module Definition)](https://github.com/umdjs/umd) builds are no longer shipped with this library.

**Using [UNPKG](https://unpkg.com/uuid@latest/dist/umd/)**:

```html
<script src="https://unpkg.com/uuid@latest/dist/umd/uuidv4.min.js"></script>
```

**Using [jsDelivr](https://cdn.jsdelivr.net/npm/uuid@latest/dist/umd/)**:

```html
<script src="https://cdn.jsdelivr.net/npm/uuid@latest/dist/umd/uuidv4.min.js"></script>
```

**Using [cdnjs](https://cdnjs.com/libraries/uuid)**:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/uuid/8.1.0/uuidv4.min.js"></script>
```

These CDNs all provide the same [`uuidv4()`](#uuidv4options-buffer-offset) method:

```html
<script>
uuidv4(); // ⇨ '55af1e37-0734-46d8-b070-a1e42e4fc392'
</script>
```

Methods for the other algorithms ([`uuidv1()`](#uuidv1options-buffer-offset), [`uuidv3()`](#uuidv3name-namespace-buffer-offset) and [`uuidv5()`](#uuidv5name-namespace-buffer-offset)) are available from the files `uuidv1.min.js`, `uuidv3.min.js` and `uuidv5.min.js` respectively.
If you need a UMD build of this library, use a bundler like Webpack or Rollup. Alternatively, refer to the documentation of [`uuid@8.3.2`](https://github.com/uuidjs/uuid/blob/v8.3.2/README.md#umd) which was the last version that shipped UMD builds.

## Known issues

Expand Down
9 changes: 7 additions & 2 deletions examples/benchmark/README.md
Expand Up @@ -2,10 +2,15 @@

```
npm install
npm test
```

To run the benchmark in the browser open `benchmark.html` and check the console.
## Node.js

To run the benchmark in Node.js, run `npm test`.

## Browser

To run the benchmark in the browser run `npm run start`, open `benchmark.html`, and check the console.

Example output (`uuid@8.0.0`, MacBook Pro (Retina, 13-inch, Early 2015), 3.1 GHz Dual-Core Intel Core i7):

Expand Down
10 changes: 1 addition & 9 deletions examples/benchmark/benchmark.html
@@ -1,12 +1,4 @@
<!DOCTYPE html>
<title>UUID Benchmark</title>
<p>Please open the Developer Console to view output</p>
<script src="./node_modules/uuid/dist/umd/uuidv1.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidv3.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidv4.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidv5.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidParse.min.js"></script>
<script src="./node_modules/uuid/dist/umd/uuidStringify.min.js"></script>
<script src="./node_modules/lodash/lodash.js"></script>
<script src="./node_modules/benchmark/benchmark.js"></script>
<script src="./benchmark.js"></script>
<script type="module" src="./browser.js"></script>
146 changes: 69 additions & 77 deletions examples/benchmark/benchmark.js
@@ -1,85 +1,77 @@
// eslint-disable-next-line no-unused-vars
/* global Benchmark:false, uuidv1:false, uuidv3:false, uuidv4:false, uuidv5:false */
const Benchmark = (typeof window !== 'undefined' && window.Benchmark) || require('benchmark');
const uuidv1 = (typeof window !== 'undefined' && window.uuidv1) || require('uuid').v1;
const uuidv4 = (typeof window !== 'undefined' && window.uuidv4) || require('uuid').v4;
const uuidv3 = (typeof window !== 'undefined' && window.uuidv3) || require('uuid').v3;
const uuidv5 = (typeof window !== 'undefined' && window.uuidv5) || require('uuid').v5;
const uuidParse = (typeof window !== 'undefined' && window.uuidParse) || require('uuid').parse;
const uuidStringify =
(typeof window !== 'undefined' && window.uuidStringify) || require('uuid').stringify;
export default function benchmark(uuid, Benchmark) {
console.log('Starting. Tests take ~1 minute to run ...');

console.log('Starting. Tests take ~1 minute to run ...');
function testParseAndStringify() {
const suite = new Benchmark.Suite({
onError(event) {
console.error(event.target.error);
},
});

function testParseAndStringify() {
const suite = new Benchmark.Suite({
onError(event) {
console.error(event.target.error);
},
});
const BYTES = [
0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08,
0x4b,
];

const BYTES = [
0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08, 0x4b,
];
suite
.add('uuid.stringify()', function () {
uuid.stringify(BYTES);
})
.add('uuid.parse()', function () {
uuid.parse('0f5abcd1-c194-47f3-905b-2df7263a084b');
})
.on('cycle', function (event) {
console.log(event.target.toString());
})
.on('complete', function () {
console.log('---\n');
})
.run();
}

suite
.add('uuidStringify()', function () {
uuidStringify(BYTES);
})
.add('uuidParse()', function () {
uuidParse('0f5abcd1-c194-47f3-905b-2df7263a084b');
})
.on('cycle', function (event) {
console.log(event.target.toString());
})
.on('complete', function () {
console.log('---\n');
})
.run();
}
function testGeneration() {
const array = new Array(16);

function testGeneration() {
const array = new Array(16);
const suite = new Benchmark.Suite({
onError(event) {
console.error(event.target.error);
},
});

const suite = new Benchmark.Suite({
onError(event) {
console.error(event.target.error);
},
});
suite
.add('uuid.v1()', function () {
uuid.v1();
})
.add('uuid.v1() fill existing array', function () {
try {
uuid.v1(null, array, 0);
} catch (err) {
// The spec (https://tools.ietf.org/html/rfc4122#section-4.2.1.2) defines that only 10M/s v1
// UUIDs can be generated on a single node. This library throws an error if we hit that limit
// (which can happen on modern hardware and modern Node.js versions).
}
})
.add('uuid.v4()', function () {
uuid.v4();
})
.add('uuid.v4() fill existing array', function () {
uuid.v4(null, array, 0);
})
.add('uuid.v3()', function () {
uuid.v3('hello.example.com', uuid.v3.DNS);
})
.add('uuid.v5()', function () {
uuid.v5('hello.example.com', uuid.v5.DNS);
})
.on('cycle', function (event) {
console.log(event.target.toString());
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run();
}

suite
.add('uuidv1()', function () {
uuidv1();
})
.add('uuidv1() fill existing array', function () {
try {
uuidv1(null, array, 0);
} catch (err) {
// The spec (https://tools.ietf.org/html/rfc4122#section-4.2.1.2) defines that only 10M/s v1
// UUIDs can be generated on a single node. This library throws an error if we hit that limit
// (which can happen on modern hardware and modern Node.js versions).
}
})
.add('uuidv4()', function () {
uuidv4();
})
.add('uuidv4() fill existing array', function () {
uuidv4(null, array, 0);
})
.add('uuidv3()', function () {
uuidv3('hello.example.com', uuidv3.DNS);
})
.add('uuidv5()', function () {
uuidv5('hello.example.com', uuidv5.DNS);
})
.on('cycle', function (event) {
console.log(event.target.toString());
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run();
testParseAndStringify();
testGeneration();
}

testParseAndStringify();
testGeneration();
7 changes: 7 additions & 0 deletions examples/benchmark/browser.js
@@ -0,0 +1,7 @@
import * as uuid from './node_modules/uuid/dist/esm-browser/index.js';
import './node_modules/lodash/lodash.js';
import './node_modules/benchmark/benchmark.js';

import benchmark from './benchmark.js';

benchmark(uuid, window.Benchmark);
6 changes: 6 additions & 0 deletions examples/benchmark/node.js
@@ -0,0 +1,6 @@
import * as uuid from 'uuid';
import Benchmark from 'benchmark';

import benchmark from './benchmark.js';

benchmark(uuid, Benchmark);
82 changes: 38 additions & 44 deletions examples/benchmark/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions examples/benchmark/package.json
Expand Up @@ -3,12 +3,15 @@
"version": "0.0.0",
"private": true,
"scripts": {
"test": "node benchmark.js"
"build": "true",
"start": "npm run build && npx http-server . -o",
"test": "node node.js"
},
"dependencies": {
"uuid": "file:../../.local/uuid"
},
"devDependencies": {
"benchmark": "^2.1.4"
}
},
"type": "module"
}

0 comments on commit e948a0f

Please sign in to comment.