Skip to content

Commit e948a0f

Browse files
authoredAug 4, 2022
feat: remove UMD build (#645)
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
1 parent 0f433e5 commit e948a0f

18 files changed

+137
-823
lines changed
 

‎README.md

+2-28
Original file line numberDiff line numberDiff line change
@@ -358,35 +358,9 @@ To load this module directly into modern browsers that [support loading ECMAScri
358358

359359
### UMD
360360

361-
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:
361+
As of `uuid@9` [UMD (Universal Module Definition)](https://github.com/umdjs/umd) builds are no longer shipped with this library.
362362

363-
**Using [UNPKG](https://unpkg.com/uuid@latest/dist/umd/)**:
364-
365-
```html
366-
<script src="https://unpkg.com/uuid@latest/dist/umd/uuidv4.min.js"></script>
367-
```
368-
369-
**Using [jsDelivr](https://cdn.jsdelivr.net/npm/uuid@latest/dist/umd/)**:
370-
371-
```html
372-
<script src="https://cdn.jsdelivr.net/npm/uuid@latest/dist/umd/uuidv4.min.js"></script>
373-
```
374-
375-
**Using [cdnjs](https://cdnjs.com/libraries/uuid)**:
376-
377-
```html
378-
<script src="https://cdnjs.cloudflare.com/ajax/libs/uuid/8.1.0/uuidv4.min.js"></script>
379-
```
380-
381-
These CDNs all provide the same [`uuidv4()`](#uuidv4options-buffer-offset) method:
382-
383-
```html
384-
<script>
385-
uuidv4(); // ⇨ '55af1e37-0734-46d8-b070-a1e42e4fc392'
386-
</script>
387-
```
388-
389-
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.
363+
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.
390364

391365
## Known issues
392366

‎README_js.md

+2-28
Original file line numberDiff line numberDiff line change
@@ -367,35 +367,9 @@ To load this module directly into modern browsers that [support loading ECMAScri
367367

368368
### UMD
369369

370-
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:
370+
As of `uuid@9` [UMD (Universal Module Definition)](https://github.com/umdjs/umd) builds are no longer shipped with this library.
371371

372-
**Using [UNPKG](https://unpkg.com/uuid@latest/dist/umd/)**:
373-
374-
```html
375-
<script src="https://unpkg.com/uuid@latest/dist/umd/uuidv4.min.js"></script>
376-
```
377-
378-
**Using [jsDelivr](https://cdn.jsdelivr.net/npm/uuid@latest/dist/umd/)**:
379-
380-
```html
381-
<script src="https://cdn.jsdelivr.net/npm/uuid@latest/dist/umd/uuidv4.min.js"></script>
382-
```
383-
384-
**Using [cdnjs](https://cdnjs.com/libraries/uuid)**:
385-
386-
```html
387-
<script src="https://cdnjs.cloudflare.com/ajax/libs/uuid/8.1.0/uuidv4.min.js"></script>
388-
```
389-
390-
These CDNs all provide the same [`uuidv4()`](#uuidv4options-buffer-offset) method:
391-
392-
```html
393-
<script>
394-
uuidv4(); // ⇨ '55af1e37-0734-46d8-b070-a1e42e4fc392'
395-
</script>
396-
```
397-
398-
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.
372+
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.
399373

400374
## Known issues
401375

‎examples/benchmark/README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
```
44
npm install
5-
npm test
65
```
76

8-
To run the benchmark in the browser open `benchmark.html` and check the console.
7+
## Node.js
8+
9+
To run the benchmark in Node.js, run `npm test`.
10+
11+
## Browser
12+
13+
To run the benchmark in the browser run `npm run start`, open `benchmark.html`, and check the console.
914

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

‎examples/benchmark/benchmark.html

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
<!DOCTYPE html>
22
<title>UUID Benchmark</title>
33
<p>Please open the Developer Console to view output</p>
4-
<script src="./node_modules/uuid/dist/umd/uuidv1.min.js"></script>
5-
<script src="./node_modules/uuid/dist/umd/uuidv3.min.js"></script>
6-
<script src="./node_modules/uuid/dist/umd/uuidv4.min.js"></script>
7-
<script src="./node_modules/uuid/dist/umd/uuidv5.min.js"></script>
8-
<script src="./node_modules/uuid/dist/umd/uuidParse.min.js"></script>
9-
<script src="./node_modules/uuid/dist/umd/uuidStringify.min.js"></script>
10-
<script src="./node_modules/lodash/lodash.js"></script>
11-
<script src="./node_modules/benchmark/benchmark.js"></script>
12-
<script src="./benchmark.js"></script>
4+
<script type="module" src="./browser.js"></script>

‎examples/benchmark/benchmark.js

+69-77
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,77 @@
1-
// eslint-disable-next-line no-unused-vars
2-
/* global Benchmark:false, uuidv1:false, uuidv3:false, uuidv4:false, uuidv5:false */
3-
const Benchmark = (typeof window !== 'undefined' && window.Benchmark) || require('benchmark');
4-
const uuidv1 = (typeof window !== 'undefined' && window.uuidv1) || require('uuid').v1;
5-
const uuidv4 = (typeof window !== 'undefined' && window.uuidv4) || require('uuid').v4;
6-
const uuidv3 = (typeof window !== 'undefined' && window.uuidv3) || require('uuid').v3;
7-
const uuidv5 = (typeof window !== 'undefined' && window.uuidv5) || require('uuid').v5;
8-
const uuidParse = (typeof window !== 'undefined' && window.uuidParse) || require('uuid').parse;
9-
const uuidStringify =
10-
(typeof window !== 'undefined' && window.uuidStringify) || require('uuid').stringify;
1+
export default function benchmark(uuid, Benchmark) {
2+
console.log('Starting. Tests take ~1 minute to run ...');
113

12-
console.log('Starting. Tests take ~1 minute to run ...');
4+
function testParseAndStringify() {
5+
const suite = new Benchmark.Suite({
6+
onError(event) {
7+
console.error(event.target.error);
8+
},
9+
});
1310

14-
function testParseAndStringify() {
15-
const suite = new Benchmark.Suite({
16-
onError(event) {
17-
console.error(event.target.error);
18-
},
19-
});
11+
const BYTES = [
12+
0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08,
13+
0x4b,
14+
];
2015

21-
const BYTES = [
22-
0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08, 0x4b,
23-
];
16+
suite
17+
.add('uuid.stringify()', function () {
18+
uuid.stringify(BYTES);
19+
})
20+
.add('uuid.parse()', function () {
21+
uuid.parse('0f5abcd1-c194-47f3-905b-2df7263a084b');
22+
})
23+
.on('cycle', function (event) {
24+
console.log(event.target.toString());
25+
})
26+
.on('complete', function () {
27+
console.log('---\n');
28+
})
29+
.run();
30+
}
2431

25-
suite
26-
.add('uuidStringify()', function () {
27-
uuidStringify(BYTES);
28-
})
29-
.add('uuidParse()', function () {
30-
uuidParse('0f5abcd1-c194-47f3-905b-2df7263a084b');
31-
})
32-
.on('cycle', function (event) {
33-
console.log(event.target.toString());
34-
})
35-
.on('complete', function () {
36-
console.log('---\n');
37-
})
38-
.run();
39-
}
32+
function testGeneration() {
33+
const array = new Array(16);
4034

41-
function testGeneration() {
42-
const array = new Array(16);
35+
const suite = new Benchmark.Suite({
36+
onError(event) {
37+
console.error(event.target.error);
38+
},
39+
});
4340

44-
const suite = new Benchmark.Suite({
45-
onError(event) {
46-
console.error(event.target.error);
47-
},
48-
});
41+
suite
42+
.add('uuid.v1()', function () {
43+
uuid.v1();
44+
})
45+
.add('uuid.v1() fill existing array', function () {
46+
try {
47+
uuid.v1(null, array, 0);
48+
} catch (err) {
49+
// The spec (https://tools.ietf.org/html/rfc4122#section-4.2.1.2) defines that only 10M/s v1
50+
// UUIDs can be generated on a single node. This library throws an error if we hit that limit
51+
// (which can happen on modern hardware and modern Node.js versions).
52+
}
53+
})
54+
.add('uuid.v4()', function () {
55+
uuid.v4();
56+
})
57+
.add('uuid.v4() fill existing array', function () {
58+
uuid.v4(null, array, 0);
59+
})
60+
.add('uuid.v3()', function () {
61+
uuid.v3('hello.example.com', uuid.v3.DNS);
62+
})
63+
.add('uuid.v5()', function () {
64+
uuid.v5('hello.example.com', uuid.v5.DNS);
65+
})
66+
.on('cycle', function (event) {
67+
console.log(event.target.toString());
68+
})
69+
.on('complete', function () {
70+
console.log('Fastest is ' + this.filter('fastest').map('name'));
71+
})
72+
.run();
73+
}
4974

50-
suite
51-
.add('uuidv1()', function () {
52-
uuidv1();
53-
})
54-
.add('uuidv1() fill existing array', function () {
55-
try {
56-
uuidv1(null, array, 0);
57-
} catch (err) {
58-
// The spec (https://tools.ietf.org/html/rfc4122#section-4.2.1.2) defines that only 10M/s v1
59-
// UUIDs can be generated on a single node. This library throws an error if we hit that limit
60-
// (which can happen on modern hardware and modern Node.js versions).
61-
}
62-
})
63-
.add('uuidv4()', function () {
64-
uuidv4();
65-
})
66-
.add('uuidv4() fill existing array', function () {
67-
uuidv4(null, array, 0);
68-
})
69-
.add('uuidv3()', function () {
70-
uuidv3('hello.example.com', uuidv3.DNS);
71-
})
72-
.add('uuidv5()', function () {
73-
uuidv5('hello.example.com', uuidv5.DNS);
74-
})
75-
.on('cycle', function (event) {
76-
console.log(event.target.toString());
77-
})
78-
.on('complete', function () {
79-
console.log('Fastest is ' + this.filter('fastest').map('name'));
80-
})
81-
.run();
75+
testParseAndStringify();
76+
testGeneration();
8277
}
83-
84-
testParseAndStringify();
85-
testGeneration();

‎examples/benchmark/browser.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as uuid from './node_modules/uuid/dist/esm-browser/index.js';
2+
import './node_modules/lodash/lodash.js';
3+
import './node_modules/benchmark/benchmark.js';
4+
5+
import benchmark from './benchmark.js';
6+
7+
benchmark(uuid, window.Benchmark);

‎examples/benchmark/node.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as uuid from 'uuid';
2+
import Benchmark from 'benchmark';
3+
4+
import benchmark from './benchmark.js';
5+
6+
benchmark(uuid, Benchmark);

‎examples/benchmark/package-lock.json

+38-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/benchmark/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"test": "node benchmark.js"
6+
"build": "true",
7+
"start": "npm run build && npx http-server . -o",
8+
"test": "node node.js"
79
},
810
"dependencies": {
911
"uuid": "file:../../.local/uuid"
1012
},
1113
"devDependencies": {
1214
"benchmark": "^2.1.4"
13-
}
15+
},
16+
"type": "module"
1417
}

‎examples/browser-umd/README.md

-8
This file was deleted.

‎examples/browser-umd/example.html

-14
This file was deleted.

‎examples/browser-umd/example.js

-54
This file was deleted.

‎examples/browser-umd/package-lock.json

-87
This file was deleted.

‎examples/browser-umd/package.json

-12
This file was deleted.

‎package-lock.json

-421
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"@babel/preset-env": "7.18.9",
5757
"@commitlint/cli": "17.0.3",
5858
"@commitlint/config-conventional": "17.0.3",
59-
"@rollup/plugin-node-resolve": "13.3.0",
6059
"bundlewatch": "0.3.3",
6160
"eslint": "8.20.0",
6261
"eslint-config-prettier": "8.5.0",
@@ -72,8 +71,6 @@
7271
"optional-dev-dependency": "2.0.1",
7372
"prettier": "2.7.1",
7473
"random-seed": "0.3.0",
75-
"rollup": "2.77.2",
76-
"rollup-plugin-terser": "7.0.2",
7774
"runmd": "1.3.6",
7875
"standard-version": "9.5.0"
7976
},

‎rollup.config.js

-30
This file was deleted.

‎scripts/build.sh

-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,3 @@ done
6060

6161
echo "Removing browser-specific files from esm-node"
6262
rm -f "$DIR"/esm-node/*-browser.js
63-
64-
# UMD Build
65-
mkdir "$DIR/umd"
66-
rollup -c

0 commit comments

Comments
 (0)
Please sign in to comment.