File tree Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 22
33const fs = require ( 'fs' ) ;
44const path = require ( 'path' ) ;
5- const mkdirp = require ( 'mkdirp' ) ;
65const os = require ( 'os' ) ;
6+ const utils = require ( './lib/utils' ) ;
77const baseBundleDirpath = path . join ( __dirname , '.karma' ) ;
88
99const hostname = os . hostname ( ) ;
@@ -111,7 +111,7 @@ module.exports = config => {
111111 console . error ( 'No SauceLabs credentials present' ) ;
112112 }
113113 }
114- mkdirp . sync ( bundleDirpath ) ;
114+ utils . mkdir ( bundleDirpath ) ;
115115 } else {
116116 console . error ( 'CI mode disabled' ) ;
117117 }
Original file line number Diff line number Diff line change 99
1010const fs = require ( 'fs' ) ;
1111const path = require ( 'path' ) ;
12- const mkdirp = require ( 'mkdirp ' ) ;
12+ const utils = require ( '../utils ' ) ;
1313
1414exports . command = 'init <path>' ;
1515
@@ -24,7 +24,7 @@ exports.builder = yargs =>
2424exports . handler = argv => {
2525 const destdir = argv . path ;
2626 const srcdir = path . join ( __dirname , '..' , '..' ) ;
27- mkdirp . sync ( destdir ) ;
27+ utils . mkdir ( destdir ) ;
2828 const css = fs . readFileSync ( path . join ( srcdir , 'mocha.css' ) ) ;
2929 const js = fs . readFileSync ( path . join ( srcdir , 'mocha.js' ) ) ;
3030 const tmpl = fs . readFileSync (
Original file line number Diff line number Diff line change @@ -853,3 +853,20 @@ exports.supportsEsModules = function() {
853853 }
854854 }
855855} ;
856+
857+ /**
858+ * Recursively mkdir, like `mkdirp`
859+ *
860+ * @description
861+ * This function is to create a new directory and any necessary subdirectories at the directory.
862+ * `fs.mkdir` with {recursive: true} can be a replacement for vulnerable `mkdirp`.
863+ *
864+ * @private
865+ * @param {string } pathname - Directory path to create.
866+ * @returns {undefined } void
867+ */
868+ exports . mkdir = function ( pathname ) {
869+ if ( ! fs . existsSync ( pathname ) ) {
870+ fs . mkdirSync ( pathname , { recursive : true } ) ;
871+ }
872+ } ;
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ var utils = require('../../lib/utils');
44var fs = require ( 'fs' ) ;
55var path = require ( 'path' ) ;
66var os = require ( 'os' ) ;
7- var mkdirp = require ( 'mkdirp' ) ;
87var rimraf = require ( 'rimraf' ) ;
98
109describe ( 'file utils' , function ( ) {
@@ -119,7 +118,7 @@ describe('file utils', function() {
119118 afterEach ( removeTempDir ) ;
120119
121120 function makeTempDir ( ) {
122- mkdirp . sync ( tmpDir ) ;
121+ utils . mkdir ( tmpDir ) ;
123122 }
124123
125124 function removeTempDir ( ) {
You can’t perform that action at this time.
0 commit comments