mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove react-packager indirection.
Summary: This moves the `src` directory one level up and removes the `react-packager` folder. Personally, I always disliked this indirection. I'm reorganizing some things in RNP, so this seems to make sense. Not sure if I forgot to update any paths. Can anyone advice if there are more places that need change? Reviewed By: jeanlauliac Differential Revision: D4487867 fbshipit-source-id: d63f9c79d6238300df9632d2e6a4e6a4196d5ccb
This commit is contained in:
committed by
Facebook Github Bot
parent
0ecc4047af
commit
a2c84d14ce
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {dirname, join, parse} = require('path');
|
||||
|
||||
module.exports = class HasteFS {
|
||||
directories: Set<string>;
|
||||
directoryEntries: Map<string, Array<string>>;
|
||||
files: Set<string>;
|
||||
|
||||
constructor(files: Array<string>) {
|
||||
this.directories = buildDirectorySet(files);
|
||||
this.directoryEntries = buildDirectoryEntries(files.map(parse));
|
||||
this.files = new Set(files);
|
||||
}
|
||||
|
||||
closest(path: string, fileName: string): ?string {
|
||||
let {dir, root} = parse(path);
|
||||
do {
|
||||
const candidate = join(dir, fileName);
|
||||
if (this.files.has(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
dir = dirname(dir);
|
||||
} while (dir !== '.' && dir !== root);
|
||||
return null;
|
||||
}
|
||||
|
||||
dirExists(path: string) {
|
||||
return this.directories.has(path);
|
||||
}
|
||||
|
||||
exists(path: string) {
|
||||
return this.files.has(path);
|
||||
}
|
||||
|
||||
getAllFiles() {
|
||||
return Array.from(this.files.keys());
|
||||
}
|
||||
|
||||
matches(directory: string, pattern: RegExp) {
|
||||
const entries = this.directoryEntries.get(directory);
|
||||
return entries ? entries.filter(pattern.test, pattern) : [];
|
||||
}
|
||||
};
|
||||
|
||||
function buildDirectorySet(files) {
|
||||
const directories = new Set();
|
||||
files.forEach(path => {
|
||||
let {dir, root} = parse(path);
|
||||
while (dir !== '.' && dir !== root && !directories.has(dir)) {
|
||||
directories.add(dir);
|
||||
dir = dirname(dir);
|
||||
}
|
||||
});
|
||||
return directories;
|
||||
}
|
||||
|
||||
function buildDirectoryEntries(files) {
|
||||
const directoryEntries = new Map();
|
||||
files.forEach(({base, dir}) => {
|
||||
const entries = directoryEntries.get(dir);
|
||||
if (entries) {
|
||||
entries.push(base);
|
||||
} else {
|
||||
directoryEntries.set(dir, [base]);
|
||||
}
|
||||
});
|
||||
return directoryEntries;
|
||||
}
|
||||
Reference in New Issue
Block a user