Skip to content

Commit d1f4be6

Browse files
committed
fixed JSONification contract
`#toJSON` is not supposed to stringify the respective value itself: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior /cc @moonglum
1 parent 3e7fae3 commit d1f4be6

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

lib/manifest.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,14 @@ module.exports = class Manifest {
4343
this._index.set(key, uri);
4444

4545
let fp = this.filepath;
46-
return fp ? createFile(fp, this.toJSON()) : Promise.resolve(null);
46+
return fp ? createFile(fp, JSON.stringify(this) + "\n") : Promise.resolve(null);
4747
}
4848

4949
toJSON() {
5050
let index = this._index;
51-
let manifest = Array.from(index.keys()).sort().reduce((memo, key) => {
51+
return Array.from(index.keys()).sort().reduce((memo, key) => {
5252
memo[key] = index.get(key);
5353
return memo;
5454
}, {});
55-
return JSON.stringify(manifest) + "\n";
5655
}
5756
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
"lint": "eslint --cache lib bin/* test test/bin/* && echo ✓"
2626
},
2727
"dependencies": {
28-
"browserslist": "~4.3.0",
28+
"browserslist": "~4.3.4",
2929
"minimist": "~1.2.0",
3030
"mkdirp": "~0.5.1",
3131
"nite-owl": "~3.3.2"
3232
},
3333
"devDependencies": {
3434
"eslint-config-fnd": "^1.6.0",
3535
"mocha": "^5.2.0",
36-
"npm-run-all": "^4.1.3",
36+
"npm-run-all": "^4.1.5",
3737
"release-util-fnd": "^1.1.1"
3838
}
3939
}

test/test_manifest.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ describe("manifest", _ => {
2424
let manifest = new Manifest(root);
2525
return manifest.set("foo.png", "foo-abc123.png").
2626
then(_ => { // eslint-disable-next-line quotes
27-
assertSame(manifest.toJSON(), `{"foo.png":"/foo-abc123.png"}\n`);
27+
assertSame(JSON.stringify(manifest), `{"foo.png":"/foo-abc123.png"}`);
2828

2929
return manifest.set("bar.css", "bar-def456.css");
3030
}).
3131
then(_ => {
32-
assertSame(manifest.toJSON(), // eslint-disable-next-line quotes
33-
`{"bar.css":"/bar-def456.css","foo.png":"/foo-abc123.png"}\n`);
32+
assertSame(JSON.stringify(manifest), // eslint-disable-next-line quotes
33+
`{"bar.css":"/bar-def456.css","foo.png":"/foo-abc123.png"}`);
3434

3535
return manifest.set("xox.js", "xox-ghi789.js");
3636
}).
3737
then(_ => {
38-
assertSame(manifest.toJSON(), // eslint-disable-next-line quotes
39-
`{"bar.css":"/bar-def456.css","foo.png":"/foo-abc123.png","xox.js":"/xox-ghi789.js"}\n`);
38+
assertSame(JSON.stringify(manifest), // eslint-disable-next-line quotes
39+
`{"bar.css":"/bar-def456.css","foo.png":"/foo-abc123.png","xox.js":"/xox-ghi789.js"}`);
4040
});
4141
});
4242
});

0 commit comments

Comments
 (0)