Last change
on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
969 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | const {dirname} = require('path')
|
---|
| 2 | const {findMade, findMadeSync} = require('./find-made.js')
|
---|
| 3 | const {mkdirpManual, mkdirpManualSync} = require('./mkdirp-manual.js')
|
---|
| 4 |
|
---|
| 5 | const mkdirpNative = (path, opts) => {
|
---|
| 6 | opts.recursive = true
|
---|
| 7 | const parent = dirname(path)
|
---|
| 8 | if (parent === path)
|
---|
| 9 | return opts.mkdirAsync(path, opts)
|
---|
| 10 |
|
---|
| 11 | return findMade(opts, path).then(made =>
|
---|
| 12 | opts.mkdirAsync(path, opts).then(() => made)
|
---|
| 13 | .catch(er => {
|
---|
| 14 | if (er.code === 'ENOENT')
|
---|
| 15 | return mkdirpManual(path, opts)
|
---|
| 16 | else
|
---|
| 17 | throw er
|
---|
| 18 | }))
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | const mkdirpNativeSync = (path, opts) => {
|
---|
| 22 | opts.recursive = true
|
---|
| 23 | const parent = dirname(path)
|
---|
| 24 | if (parent === path)
|
---|
| 25 | return opts.mkdirSync(path, opts)
|
---|
| 26 |
|
---|
| 27 | const made = findMadeSync(opts, path)
|
---|
| 28 | try {
|
---|
| 29 | opts.mkdirSync(path, opts)
|
---|
| 30 | return made
|
---|
| 31 | } catch (er) {
|
---|
| 32 | if (er.code === 'ENOENT')
|
---|
| 33 | return mkdirpManualSync(path, opts)
|
---|
| 34 | else
|
---|
| 35 | throw er
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | module.exports = {mkdirpNative, mkdirpNativeSync}
|
---|
Note:
See
TracBrowser
for help on using the repository browser.