Skip to content

Commit 26cb8ae

Browse files
authored
Change package to be ES module (#9)
Change package to be ES module
2 parents a622e52 + dd1aae4 commit 26cb8ae

File tree

7 files changed

+31
-23
lines changed

7 files changed

+31
-23
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ dist: trusty
44
before_script:
55
- npm install
66
- 'export PATH=$PWD/node_modules/.bin:$PATH'
7-
node_js: 6
7+
node_js: node
88
script:
99
- xvfb-run npm run test

jasmine-run.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import glob from 'glob';
2+
import Jasmine from 'jasmine';
3+
4+
const jasmine = new Jasmine();
5+
6+
const pattern = process.argv[2] || 'test/spec/*.js';
7+
8+
// Load your specs
9+
glob(pattern, function (er, files) {
10+
Promise.all(
11+
files
12+
// Use relative paths
13+
.map(f => f.replace(/^([^\/])/, './$1'))
14+
.map(f => import(f)
15+
.catch(e => {
16+
console.error('** Error loading ' + f + ': ');
17+
console.error(e);
18+
process.exit(1);
19+
}))
20+
)
21+
.then(() => jasmine.execute());
22+
});

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"version": "2.0.0",
44
"description": "JSON Patch Operational Transformations - resolves outdated JSON Patches (RFC6902) in real-time JSON collaboration",
55
"main": "src/json-patch-ot.js",
6+
"type": "module",
67
"typings": "index.d.ts",
78
"scripts": {
8-
"test": "jasmine test/spec/transformSpec.js"
9+
"test": "node --experimental-modules jasmine-run.js test/spec/transformSpec.js"
910
},
1011
"repository": {
1112
"type": "git",
@@ -25,9 +26,6 @@
2526
"url": "https://github.com/Palindrom/JSON-Patch-OT/issues"
2627
},
2728
"homepage": "https://github.com/Palindrom/JSON-Patch-OT",
28-
"engines": {
29-
"node": ">= 0.4.0"
30-
},
3129
"devDependencies": {
3230
"grunt": "^1.0.4",
3331
"grunt-bump": "^0.8.0",

src/json-patch-ot.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,5 @@ var JSONPatchOT = (function(){
149149
return JSONPatchOT;
150150
}());
151151

152-
if(typeof module !== 'undefined') {
153-
module.exports = JSONPatchOT;
154-
module.exports.default = JSONPatchOT;
155-
module.exports.__esModule = true;
156-
}
152+
export default JSONPatchOT;
153+
export { JSONPatchOT };

test/SpecRunner.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@
1111
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
1212
<script src="../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
1313

14-
<!-- include source files here... -->
15-
<script src="../src/json-patch-ot.js"></script>
16-
1714
<!-- include spec files here... -->
18-
<script src="spec/transformSpec.js"></script>
19-
15+
<script type="module" src="spec/transformSpec.js"></script>
2016

2117
</head>
2218

test/SpecRunnerMin.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@
1111
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
1212
<script src="../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
1313

14-
<!-- include source files here... -->
15-
<script src="../dist/json-patch-ot.min.js"></script>
16-
1714
<!-- include spec files here... -->
18-
<script src="spec/transformSpec.js"></script>
19-
15+
<script type="module" src="spec/transformSpec.js"></script>
2016

2117
</head>
2218

test/spec/transformSpec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
var obj;
22

3-
if(typeof JSONPatchOT === 'undefined') {
4-
JSONPatchOT = require('../../src/json-patch-ot');
5-
}
3+
import { JSONPatchOT } from '../../src/json-patch-ot.js';
4+
65
describe("JSONPatchOT when `.transform`s", function(){
76

87
describe("given JSON Patch sequence, and", function(){

0 commit comments

Comments
 (0)