@util.js/node-files 0.41.0 → 0.41.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/lib/Files.js +1 -4
- package/package.json +6 -6
- package/test/FilesTest.js +44 -28
- package/test/Files_sanitizeFilename_Test.js +2 -2
package/index.js
CHANGED
package/lib/Files.js
CHANGED
|
@@ -79,7 +79,7 @@ module.exports = class Files {
|
|
|
79
79
|
return callback(new TypeError("We expected pathA to be defined."));
|
|
80
80
|
if (!objects().isDefined(pathB))
|
|
81
81
|
return callback(new TypeError("We expected pathB to be defined."));
|
|
82
|
-
|
|
82
|
+
const diff = childProcess().spawn("diff", [pathA, pathB]);
|
|
83
83
|
diff.on("close", (code) => {
|
|
84
84
|
callback(null, code === 0);
|
|
85
85
|
});
|
|
@@ -567,9 +567,6 @@ function get(dependency) {
|
|
|
567
567
|
);
|
|
568
568
|
}
|
|
569
569
|
|
|
570
|
-
function asyncwaterfall() {
|
|
571
|
-
return get("async-waterfall");
|
|
572
|
-
}
|
|
573
570
|
function childProcess() {
|
|
574
571
|
return get("child_process");
|
|
575
572
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Chris Topher <c@creemama.com>",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@util.js/objects": "0.41.
|
|
5
|
-
"@util.js/promises": "0.41.
|
|
6
|
-
"@util.js/strings": "0.41.
|
|
7
|
-
"graceful-fs": "4.2.
|
|
4
|
+
"@util.js/objects": "0.41.2",
|
|
5
|
+
"@util.js/promises": "0.41.2",
|
|
6
|
+
"@util.js/strings": "0.41.2",
|
|
7
|
+
"graceful-fs": "4.2.10",
|
|
8
8
|
"mkdirp": "1.0.4",
|
|
9
9
|
"ncp": "2.0.0",
|
|
10
10
|
"read-last-lines": "1.8.0",
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
"type": "git",
|
|
39
39
|
"url": "https://github.com/creemama/utiljs/tree/master/packages/utiljs-node-files"
|
|
40
40
|
},
|
|
41
|
-
"version": "0.41.
|
|
42
|
-
"gitHead": "
|
|
41
|
+
"version": "0.41.2",
|
|
42
|
+
"gitHead": "174b81ec0ead0221b9bb6617bc254b025bd20a5a"
|
|
43
43
|
}
|
package/test/FilesTest.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const { assert, expect } = require("chai")
|
|
4
|
-
|
|
3
|
+
const { assert, expect } = require("chai");
|
|
4
|
+
const files = require("..");
|
|
5
5
|
|
|
6
6
|
describe("Files", function () {
|
|
7
7
|
const waterfall = require("async-waterfall");
|
|
8
|
-
const targetDir = __dirname
|
|
8
|
+
const targetDir = files.join(__dirname, "..", "target");
|
|
9
9
|
const emptyDir = targetDir + "/emptyDir";
|
|
10
10
|
const jsonDir = targetDir + "/filesWithExtension";
|
|
11
11
|
files.mkdirpSync(targetDir);
|
|
@@ -349,8 +349,8 @@ describe("Files", function () {
|
|
|
349
349
|
expect(await files.diff(__filename, __filename)).to.be.ok;
|
|
350
350
|
});
|
|
351
351
|
it("should return false if both paths are different files", (callback) => {
|
|
352
|
-
const pathA = __dirname
|
|
353
|
-
const pathB = __dirname
|
|
352
|
+
const pathA = files.join(__dirname, "FilesTest.js");
|
|
353
|
+
const pathB = files.join(__dirname, "..", "index.js");
|
|
354
354
|
expect(files.isFile(pathA)).to.be.ok;
|
|
355
355
|
expect(files.isFile(pathB)).to.be.ok;
|
|
356
356
|
files.diff(pathA, pathB, (error, result) => {
|
|
@@ -360,7 +360,7 @@ describe("Files", function () {
|
|
|
360
360
|
});
|
|
361
361
|
});
|
|
362
362
|
it("should return false if both paths are different directories", (callback) => {
|
|
363
|
-
files.diff(__dirname, __dirname
|
|
363
|
+
files.diff(__dirname, files.join(__dirname, ".."), (error, result) => {
|
|
364
364
|
expect(error).to.be.null;
|
|
365
365
|
expect(result).to.be.false;
|
|
366
366
|
callback();
|
|
@@ -476,6 +476,10 @@ describe("Files", function () {
|
|
|
476
476
|
files.filesWithExtension(
|
|
477
477
|
{ dir: emptyDir, ext: "json" },
|
|
478
478
|
(error, result) => {
|
|
479
|
+
if (error) {
|
|
480
|
+
done(error);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
479
483
|
try {
|
|
480
484
|
expect(result).to.have.members([]);
|
|
481
485
|
done();
|
|
@@ -502,6 +506,10 @@ describe("Files", function () {
|
|
|
502
506
|
files.filesWithExtension(
|
|
503
507
|
{ dir: jsonDir + "/", ext: "json" },
|
|
504
508
|
(error, result) => {
|
|
509
|
+
if (error) {
|
|
510
|
+
done(error);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
505
513
|
try {
|
|
506
514
|
expect(result).to.have.members([
|
|
507
515
|
jsonDir + "/package.json",
|
|
@@ -527,6 +535,10 @@ describe("Files", function () {
|
|
|
527
535
|
it("should return [] if ext is empty", (done) => {
|
|
528
536
|
prepareDirWithJsonFiles().then(() => {
|
|
529
537
|
files.filesWithExtension({ dir: jsonDir, ext: "" }, (error, result) => {
|
|
538
|
+
if (error) {
|
|
539
|
+
done(error);
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
530
542
|
try {
|
|
531
543
|
expect(result).to.have.members([]);
|
|
532
544
|
done();
|
|
@@ -632,20 +644,23 @@ describe("Files", function () {
|
|
|
632
644
|
expect(truth).to.be.ok;
|
|
633
645
|
});
|
|
634
646
|
it("should be false for FilesTest.js", (done) => {
|
|
635
|
-
files.isDirectory(
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
647
|
+
files.isDirectory(
|
|
648
|
+
files.join(__dirname, "FilesTest.js"),
|
|
649
|
+
function (error, truth) {
|
|
650
|
+
try {
|
|
651
|
+
expect(error).to.be.null;
|
|
652
|
+
expect(truth).to.be.false;
|
|
653
|
+
done();
|
|
654
|
+
} catch (err) {
|
|
655
|
+
done(err);
|
|
656
|
+
}
|
|
642
657
|
}
|
|
643
|
-
|
|
658
|
+
);
|
|
644
659
|
});
|
|
645
660
|
it("should error for UnlikelyToExist.js", async function () {
|
|
646
661
|
try {
|
|
647
|
-
await files.isDirectory(__dirname
|
|
648
|
-
|
|
662
|
+
await files.isDirectory(files.join(__dirname, "UnlikelyToExist.js"));
|
|
663
|
+
expect.fail("We expected #isDirectory to throw an exception.");
|
|
649
664
|
} catch (error) {
|
|
650
665
|
expect(error).to.be.an.instanceof(Error);
|
|
651
666
|
}
|
|
@@ -671,11 +686,12 @@ describe("Files", function () {
|
|
|
671
686
|
expect(files.isDirectorySync(__dirname)).to.be.ok;
|
|
672
687
|
});
|
|
673
688
|
it("should return false for FilesTest.js", () => {
|
|
674
|
-
expect(files.isDirectorySync(__dirname
|
|
689
|
+
expect(files.isDirectorySync(files.join(__dirname, "FilesTest.js"))).to.be
|
|
690
|
+
.false;
|
|
675
691
|
});
|
|
676
692
|
it("should throw an exception for UnlikelyToExist.js", () => {
|
|
677
693
|
expect(() => {
|
|
678
|
-
files.isDirectorySync(__dirname
|
|
694
|
+
files.isDirectorySync(files.join(__dirname, "UnlikelyToExist.js"));
|
|
679
695
|
}).to.throw(/ENOENT.*/);
|
|
680
696
|
});
|
|
681
697
|
it("should throw an exception for /unlikely/to/exist/dir/", () => {
|
|
@@ -702,7 +718,7 @@ describe("Files", function () {
|
|
|
702
718
|
expect(truth).to.be.false;
|
|
703
719
|
});
|
|
704
720
|
it("should be true for FilesTest.js", (done) => {
|
|
705
|
-
files.isFile(__dirname
|
|
721
|
+
files.isFile(files.join(__dirname, "FilesTest.js"), (error, truth) => {
|
|
706
722
|
try {
|
|
707
723
|
expect(error).to.be.null;
|
|
708
724
|
expect(truth).to.be.ok;
|
|
@@ -714,8 +730,8 @@ describe("Files", function () {
|
|
|
714
730
|
});
|
|
715
731
|
it("should error for UnlikelyToExist.js", async function () {
|
|
716
732
|
try {
|
|
717
|
-
await files.isFile(__dirname
|
|
718
|
-
|
|
733
|
+
await files.isFile(files.join(__dirname, "UnlikelyToExist.js"));
|
|
734
|
+
expect.fail("We expected #isFile to throw an exception.");
|
|
719
735
|
} catch (error) {
|
|
720
736
|
expect(error).to.be.an.instanceof(Error);
|
|
721
737
|
}
|
|
@@ -741,11 +757,11 @@ describe("Files", function () {
|
|
|
741
757
|
expect(files.isFileSync(__dirname)).to.be.false;
|
|
742
758
|
});
|
|
743
759
|
it("should return false for FilesTest.js", () => {
|
|
744
|
-
expect(files.isFileSync(__dirname
|
|
760
|
+
expect(files.isFileSync(files.join(__dirname, "FilesTest.js"))).to.be.ok;
|
|
745
761
|
});
|
|
746
762
|
it("should throw an exception for UnlikelyToExist.js", () => {
|
|
747
763
|
expect(function () {
|
|
748
|
-
files.isFileSync(__dirname
|
|
764
|
+
files.isFileSync(files.join(__dirname, "UnlikelyToExist.js"));
|
|
749
765
|
}).to.throw(/ENOENT.*/);
|
|
750
766
|
});
|
|
751
767
|
it("should throw an exception for /unlikely/to/exist/dir/", () => {
|
|
@@ -757,7 +773,7 @@ describe("Files", function () {
|
|
|
757
773
|
|
|
758
774
|
describe("#mkdirp and #rmrf", function () {
|
|
759
775
|
it("should create and destroy a new directory hierarchy", function (done) {
|
|
760
|
-
|
|
776
|
+
const testDir = targetDir + "/this/is/a/nested/dir";
|
|
761
777
|
waterfall(
|
|
762
778
|
[
|
|
763
779
|
function (cb) {
|
|
@@ -799,7 +815,7 @@ describe("Files", function () {
|
|
|
799
815
|
|
|
800
816
|
describe("#rmrf", function () {
|
|
801
817
|
it("should delete files", function (done) {
|
|
802
|
-
|
|
818
|
+
const testFile = targetDir + "/frog.txt";
|
|
803
819
|
files.mkdirpSync(targetDir);
|
|
804
820
|
files.closeSync(files.openSync(testFile, "w"));
|
|
805
821
|
waterfall(
|
|
@@ -830,7 +846,7 @@ describe("Files", function () {
|
|
|
830
846
|
|
|
831
847
|
describe("#mkdirpSync and #rmrfSync", function () {
|
|
832
848
|
it("should create and destroy a new directory hierarchy", function () {
|
|
833
|
-
|
|
849
|
+
const testDir = targetDir + "/this/is/a/nested/dir";
|
|
834
850
|
files.rmrfSync(targetDir);
|
|
835
851
|
expect(function () {
|
|
836
852
|
files.isDirectorySync(targetDir);
|
|
@@ -1044,7 +1060,7 @@ describe("Files", function () {
|
|
|
1044
1060
|
});
|
|
1045
1061
|
|
|
1046
1062
|
it("should create an empty file", function (done) {
|
|
1047
|
-
|
|
1063
|
+
const touchFile = targetDir + "/foo.bar";
|
|
1048
1064
|
expect(function () {
|
|
1049
1065
|
files.isFileSync(touchFile);
|
|
1050
1066
|
}).to.throw(/ENOENT.*/);
|
|
@@ -1091,7 +1107,7 @@ describe("Files", function () {
|
|
|
1091
1107
|
it("should write a file and notify a callback", (callback) => {
|
|
1092
1108
|
const testFile = targetDir + "/writeFileTestCallback.txt";
|
|
1093
1109
|
files.rmrf(testFile, (error) => {
|
|
1094
|
-
if (error) return
|
|
1110
|
+
if (error) return callback(error);
|
|
1095
1111
|
files.mkdirp(targetDir, (erro) => {
|
|
1096
1112
|
if (erro) return callback(erro);
|
|
1097
1113
|
files.writeFile(testFile, "writeFileTest", "utf8", (err) => {
|