-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(assets): support exceptions to exclude patterns (#4473)
* chore: better test * fix: folder exclusion * additional test cases * refactor existing tests * chore: add new test files * fix: listFilesRecursively refactor (wip) * fix: finish refactoring listFilesRecursively * fix: implement mkdirpSync * fix: symlink discovery * fix: don't follow symlinks early * fix: create empty directories * chore: remove useless let * fix: symlink fingerprinting * fix: don't throw when fingerprinting directories * chore: remove unneeded 'exclude' cloning * chore: refactor mkdirp calls * chore: refactor AssetFile * chore: refactor recursion * chore: prevent unneeded stats call * chore: createFsStructureFromTree, remove empty files * chore: cleanup * fix: empty-directory test * feat: shouldExcludeDeep * chore: fromTree in @/assert, cleanup fn, test * feat: shouldExcludeDirectory * chore: refactor listFiles with new methods (missing symlinks) * feat: add symlink support to fromTree * fix: fromTree external directory symlink * fix: listFiles symlink support * chore: additional contridactory test * chore: fix docs * chore: ExcludeRules class refactor * chore: evaluateFile refactor * chore: further evaluateFile refactor * chore: evaluateDirectory refactor * chore: move FsUtils to assets * chore: move FsUtils to assets (unstaged files)
- Loading branch information
1 parent
004dfd4
commit b7b4336
Showing
14 changed files
with
1,109 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Slightly refactored version of fs-extra mkdirpSync | ||
// https://github.com/jprichardson/node-fs-extra/blob/d1a01e735e81688e08688557d7a254fa8297d98e/lib/mkdirs/mkdirs.js | ||
|
||
import fs = require('fs'); | ||
import path = require('path'); | ||
|
||
const INVALID_PATH_CHARS = /[<>:"|?*]/; | ||
const o777 = parseInt('0777', 8); | ||
|
||
function getRootPath(p: string) { | ||
const paths = path.normalize(path.resolve(p)).split(path.sep); | ||
if (paths.length > 0) { return paths[0]; } | ||
return null; | ||
} | ||
|
||
function invalidWin32Path(p: string) { | ||
const rp = getRootPath(p); | ||
p = p.replace(rp || '', ''); | ||
return INVALID_PATH_CHARS.test(p); | ||
} | ||
|
||
export function mkdirpSync(p: string, opts?: any, made?: any) { | ||
if (!opts || typeof opts !== 'object') { | ||
opts = { mode: opts }; | ||
} | ||
|
||
let mode = opts.mode; | ||
const xfs = opts.fs || fs; | ||
|
||
if (process.platform === 'win32' && invalidWin32Path(p)) { | ||
const errInval = new Error(p + ' contains invalid WIN32 path characters.'); | ||
// @ts-ignore | ||
errInval.code = 'EINVAL'; | ||
throw errInval; | ||
} | ||
|
||
if (mode === undefined) { | ||
// tslint:disable-next-line: no-bitwise | ||
mode = o777 & (~process.umask()); | ||
} | ||
if (!made) { made = null; } | ||
|
||
p = path.resolve(p); | ||
|
||
try { | ||
xfs.mkdirSync(p, mode); | ||
made = made || p; | ||
} catch (err0) { | ||
if (err0.code === 'ENOENT') { | ||
if (path.dirname(p) === p) { throw err0; } | ||
made = mkdirpSync(path.dirname(p), opts, made); | ||
mkdirpSync(p, opts, made); | ||
} else { | ||
// In the case of any other error, just see if there's a dir there | ||
// already. If so, then hooray! If not, then something is borked. | ||
let stat; | ||
try { | ||
stat = xfs.statSync(p); | ||
} catch (err1) { | ||
throw err0; | ||
} | ||
if (!stat.isDirectory()) { throw err0; } | ||
} | ||
} | ||
|
||
return made; | ||
} |
Oops, something went wrong.