Skip to content

Commit e69fd3d

Browse files
nathanhammondmathiasbynens
authored andcommitted
1 parent a541fe6 commit e69fd3d

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Generated files
2+
punycode.es6.js
3+
14
# Coverage report
25
coverage
36

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This JavaScript library is the result of comparing, optimizing and documenting d
1212

1313
This project was [bundled](https://github.com/joyent/node/blob/master/lib/punycode.js) with Node.js from [v0.6.2+](https://github.com/joyent/node/compare/975f1930b1...61e796decc) until [v7](https://github.com/nodejs/node/pull/7941) (soft-deprecated).
1414

15-
The current version supports recent versions of Node.js only. For the old version that offers the same functionality with broader support, including Rhino, Ringo, Narwhal, and web browsers, see [v1.4.1](https://github.com/bestiejs/punycode.js/releases/tag/v1.4.1).
15+
The current version supports recent versions of Node.js only. It provides a CommonJS module and an ES6 module. For the old version that offers the same functionality with broader support, including Rhino, Ringo, Narwhal, and web browsers, see [v1.4.1](https://github.com/bestiejs/punycode.js/releases/tag/v1.4.1).
1616

1717
## Installation
1818

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "A robust Punycode converter that fully complies to RFC 3492 and RFC 5891, and works on nearly all JavaScript platforms.",
55
"homepage": "https://mths.be/punycode",
66
"main": "punycode.js",
7+
"jsnext:main": "punycode.es6.js",
78
"engines": {
89
"node": ">=6"
910
},
@@ -34,10 +35,12 @@
3435
"bugs": "https://github.com/bestiejs/punycode.js/issues",
3536
"files": [
3637
"LICENSE-MIT.txt",
37-
"punycode.js"
38+
"punycode.js",
39+
"punycode.es6.js"
3840
],
3941
"scripts": {
40-
"test": "mocha tests"
42+
"test": "mocha tests",
43+
"prepublish": "node scripts/prepublish.js"
4144
},
4245
"devDependencies": {
4346
"codecov": "^1.0.1",

scripts/prepublish.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
const regex = /module\.exports = punycode;/;
7+
8+
const sourceContents = fs.readFileSync(path.resolve(__dirname, '../punycode.js'), 'utf-8');
9+
10+
if (!regex.test(sourceContents)) {
11+
throw new Error('The underlying library has changed. Please update the prepublish script.');
12+
}
13+
14+
const outputContents = sourceContents.replace(regex, 'export default punycode;');
15+
16+
fs.writeFileSync(path.resolve(__dirname, '../punycode.es6.js'), outputContents);

0 commit comments

Comments
 (0)