+11
-6
@@ -10,9 +10,14 @@ 'use strict'; | ||
| var isolated = function (files, callback) { | ||
| var isolated = function (options, callback) { | ||
| if (!callback) { | ||
| callback = files; | ||
| files = undefined; | ||
| callback = options; | ||
| options = {}; | ||
| } | ||
| options.files = options.files || undefined; | ||
| options.preserveTimestamps = !!options.preserveTimestamps; | ||
| temp.mkdir(null, function (errMkdir, directory) { | ||
| var files; | ||
| if (errMkdir) { | ||
@@ -22,7 +27,7 @@ return callback(errMkdir); | ||
| if (!files) { | ||
| if (!options.files) { | ||
| return callback(null, directory); | ||
| } | ||
| files = _.flatten([ files ]); | ||
| files = _.flatten([ options.files ]); | ||
@@ -33,3 +38,3 @@ async.each(files, function (fileWithPath, done) { | ||
| fs.copy(fileWithPath, path.join(directory, fileWithoutPath), { | ||
| preserveTimestamps: true | ||
| preserveTimestamps: options.preserveTimestamps | ||
| }, function (errCopy) { | ||
@@ -36,0 +41,0 @@ if (errCopy) { |
+2
-2
| { | ||
| "name": "isolated", | ||
| "version": "0.2.1", | ||
| "version": "0.3.0", | ||
| "description": "isolated provides one-time folders for unit tests.", | ||
@@ -13,3 +13,3 @@ "contributors": [ | ||
| "dependencies": { | ||
| "async": "1.3.0", | ||
| "async": "1.4.0", | ||
| "fs-extra": "0.22.1", | ||
@@ -16,0 +16,0 @@ "lodash": "3.10.0", |
+19
-2
@@ -31,3 +31,5 @@ # isolated | ||
| test('...', function (done) { | ||
| isolated('foo.txt', function (err, directory) { | ||
| isolated({ | ||
| files: 'foo.txt' | ||
| }, function (err, directory) { | ||
| // ... | ||
@@ -42,3 +44,5 @@ }); | ||
| test('...', function (done) { | ||
| isolated([ 'foo.txt', 'bar.txt' ], function (err, directory) { | ||
| isolated({ | ||
| files: [ 'foo.txt', 'bar.txt' ] | ||
| }, function (err, directory) { | ||
| // ... | ||
@@ -49,2 +53,15 @@ }); | ||
| Sometimes you may want isolate to preserve the sources` timestamps. For that additionally provide the `preserveTimestamps` option and set it to `true`. | ||
| ```javascript | ||
| test('...', function (done) { | ||
| isolated({ | ||
| files: [ 'foo.txt', 'bar.txt' ], | ||
| preserveTimestamps: true | ||
| }, function (err, directory) { | ||
| // ... | ||
| }); | ||
| }); | ||
| ``` | ||
| ## Running the build | ||
@@ -51,0 +68,0 @@ |
@@ -30,3 +30,5 @@ 'use strict'; | ||
| test('copies the specified file to the isolated directory.', function (done) { | ||
| isolated(foo, function (errIsolated, directory) { | ||
| isolated({ | ||
| files: foo | ||
| }, function (errIsolated, directory) { | ||
| assert.that(errIsolated).is.null(); | ||
@@ -44,3 +46,5 @@ | ||
| test('copies the specified files to the isolated directory.', function (done) { | ||
| isolated([ foo, bar ], function (errIsolated, directory) { | ||
| isolated({ | ||
| files: [ foo, bar ] | ||
| }, function (errIsolated, directory) { | ||
| assert.that(errIsolated).is.null(); | ||
@@ -59,3 +63,5 @@ | ||
| test('copies the specified directory to the isolated directory.', function (done) { | ||
| isolated(data, function (errIsolated, directory) { | ||
| isolated({ | ||
| files: data | ||
| }, function (errIsolated, directory) { | ||
| assert.that(errIsolated).is.null(); | ||
@@ -71,3 +77,32 @@ | ||
| }); | ||
| test('does not preserve timestamps.', function (done) { | ||
| isolated({ | ||
| files: foo | ||
| }, function (errIsolated, directory) { | ||
| assert.that(errIsolated).is.null(); | ||
| fs.stat(path.join(directory, 'foo.txt'), function (errStat, stat) { | ||
| assert.that(errStat).is.null(); | ||
| assert.that(stat.mtime.getTime()).is.greaterThan(Date.now() - 1000); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); | ||
| test('preserves timestamps on request.', function (done) { | ||
| isolated({ | ||
| files: foo, | ||
| preserveTimestamps: true | ||
| }, function (errIsolated, directory) { | ||
| assert.that(errIsolated).is.null(); | ||
| fs.stat(path.join(directory, 'foo.txt'), function (errStat, stat) { | ||
| assert.that(errStat).is.null(); | ||
| assert.that(stat.mtime.getTime()).is.lessThan(Date.now() - 1000); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); | ||
| /* eslint-enable handle-callback-err */ | ||
| }); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
8149
21.48%143
31.19%80
26.98%+ Added
- Removed
Updated