-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved performance of path manipulations
- Loading branch information
1 parent
2536b04
commit f5df606
Showing
7 changed files
with
97 additions
and
18 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
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
45 changes: 45 additions & 0 deletions
45
packages/jest-haste-map/src/lib/__tests__/fast_path.test.js
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,45 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import path from 'path'; | ||
import {relative, resolve} from '../fast_path'; | ||
|
||
describe('fastPath.relative', () => { | ||
it('should get relative paths inside the root', () => { | ||
const root = path.join(__dirname, 'foo', 'bar'); | ||
const filename = path.join(__dirname, 'foo', 'bar', 'baz', 'foobar'); | ||
const relativeFilename = path.join('baz', 'foobar'); | ||
expect(relative(root, filename)).toBe(relativeFilename); | ||
}); | ||
|
||
it('should get relative paths outside the root', () => { | ||
const root = path.join(__dirname, 'foo', 'bar'); | ||
const filename = path.join(__dirname, 'foo', 'baz', 'foobar'); | ||
const relativeFilename = path.join('..', 'baz', 'foobar'); | ||
expect(relative(root, filename)).toBe(relativeFilename); | ||
}); | ||
}); | ||
|
||
describe('fastPath.resolve', () => { | ||
it('should get the absolute path for paths inside the root', () => { | ||
const root = path.join(__dirname, 'foo', 'bar'); | ||
const relativeFilename = path.join('baz', 'foobar'); | ||
const filename = path.join(__dirname, 'foo', 'bar', 'baz', 'foobar'); | ||
expect(resolve(root, relativeFilename)).toBe(filename); | ||
}); | ||
|
||
it('should get the absolute path for paths outside the root', () => { | ||
const root = path.join(__dirname, 'foo', 'bar'); | ||
const relativeFilename = path.join('..', 'baz', 'foobar'); | ||
const filename = path.join(__dirname, 'foo', 'baz', 'foobar'); | ||
expect(resolve(root, relativeFilename)).toBe(filename); | ||
}); | ||
}); |
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,24 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import path from 'path'; | ||
|
||
export function relative(rootDir: string, filename: string): string { | ||
return filename.indexOf(rootDir) === 0 | ||
? filename.substr(rootDir.length + 1) | ||
: path.relative(rootDir, filename); | ||
} | ||
|
||
const INDIRECTION_FRAGMENT = '..' + path.sep; | ||
|
||
export function resolve(rootDir: string, relativeFilename: string): string { | ||
return relativeFilename.indexOf(INDIRECTION_FRAGMENT) === 0 | ||
? path.resolve(rootDir, relativeFilename) | ||
: rootDir + path.sep + relativeFilename; | ||
} |
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