Initial repository structure.

This commit is contained in:
cpojer 2017-01-26 12:56:40 +00:00
commit f8eda9b735
29 changed files with 3813 additions and 0 deletions

10
.babelrc Normal file
View File

@ -0,0 +1,10 @@
{
"plugins": [
"syntax-trailing-function-commas",
"transform-flow-strip-types",
"transform-es2015-destructuring",
"transform-es2015-parameters",
"transform-async-to-generator"
],
"retainLines": true
}

10
.eslintignore Normal file
View File

@ -0,0 +1,10 @@
**/coverage/**
**/node_modules/**
**/vendor/**
bin/
docs/
examples/react-native
flow-typed/**
packages/*/build/**
types/**
website/

4
.eslintrc Normal file
View File

@ -0,0 +1,4 @@
{
"extends": "eslint-config-fb-strict",
"parser": "babel-eslint"
}

5
.flowconfig Normal file
View File

@ -0,0 +1,5 @@
[ignore]
[options]
module.name_mapper='^types/\(.*\)$' -> '<PROJECT_ROOT>/types/\1.js'
module.name_mapper='\(metro-[^/]*\)' -> '<PROJECT_ROOT>/packages/\1/src/index.js'

11
.github/ISSUE_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,11 @@
<!-- *Before creating an issue please make sure you are using the latest version of metro-bundler, try re-installing your node_modules folder and run metro-bundler once with `--reset-cache` to see if that fixes the problem you are experiencing.* -->
**Do you want to request a *feature* or report a *bug*?**
**What is the current behavior?**
**If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can `yarn install` and `yarn test`.**
**What is the expected behavior?**
**Please provide your exact metro-bundler configuration and mention your metro-bundler, node, yarn/npm version and operating system.**

9
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,9 @@
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. The two fields below are mandatory. -->
**Summary**
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
**Test plan**
<!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. -->

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
.eslintcache
/node_modules
/packages/*/build/
/packages/*/node_modules/
/coverage
lerna-debug.log
npm-debug.log*

3
.npmignore Normal file
View File

@ -0,0 +1,3 @@
**/__mocks__/**
**/__tests__/**
src

18
.travis.yml Normal file
View File

@ -0,0 +1,18 @@
language: node_js
node_js:
- "4"
- "6"
- "7"
sudo: false
cache:
yarn: true
directories:
- ".eslintcache"
- "node_modules"
script:
- yarn test

5
CHANGELOG.md Normal file
View File

@ -0,0 +1,5 @@
## master
## metro-bundler 0.1.0
* Initial Release

88
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,88 @@
# Contributing to metro-bundler
metro-bundler is one of Facebook's open source projects that is both under very active development and is also being used to ship code to everybody on [facebook.com](https://www.facebook.com). We're still working out the kinks to make contributing to this project as easy and transparent as possible, but we're not quite there yet. Hopefully this document makes the process for contributing clear and answers some questions that you may have.
## [Code of Conduct](https://code.facebook.com/codeofconduct)
Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read [the full text](https://code.facebook.com/codeofconduct) so that you can understand what actions will and will not be tolerated.
## Our Development Process
The core team works directly on GitHub and all work is public.
### `master` is unsafe
We will do our best to keep `master` in good shape, with tests passing at all times. But in order to move fast, we will make API changes that your application might not be compatible with. We will do our best to communicate these changes and always version appropriately so you can lock into a specific version if need be.
### Workflow and Pull Requests
The core team will be monitoring for pull requests. When we get one, we'll run some Facebook-specific integration tests on it first. From here, we'll need to get another person to sign off on the changes and then merge the pull request. For API changes we may need to fix internal uses, which could cause some delay. We'll do our best to provide updates and feedback throughout the process.
*Before* submitting a pull request, please make sure the following is done…
1. Fork the repo and create your branch from `master`.
```sh
git clone https://github.com/facebook/metro-bundler
cd metro-bundler
git checkout -b my_branch
```
2. Run `npm install`. We recommend that you use `npm` version 3 or later.
```sh
npm install
```
3. If you've added code that should be tested, add tests. You
can use watch mode that continuously transforms changed files
to make your life easier.
```sh
# in the background
npm run watch
```
4. If you've changed APIs, update the documentation.
5. Ensure the test suite passes via `npm test`.
6. If you haven't already, complete the CLA.
### Contributor License Agreement (CLA)
In order to accept your pull request, we need you to submit a CLA. You only need to do this once, so if you've done this for another Facebook open source project, you're good to go. If you are submitting a pull request for the first time, just let us know that you have completed the CLA and we can cross-check with your GitHub username.
[Complete your CLA here.](https://code.facebook.com/cla)
### Bugs
### Where to Find Known Issues
We will be using GitHub Issues for our public bugs. We will keep a close eye on this and try to make it clear when we have an internal fix in progress. Before filing a new issue, try to make sure your problem doesn't already exist.
### Reporting New Issues
The best way to get your bug fixed is to provide a reduced test case. Please provide a public repository with a runnable example.
### Security Bugs
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe disclosure of security bugs. With that in mind, please do not file public issues; go through the process outlined on that page.
## How to Get in Touch
* Discord - [#metro-bundler](https://discordapp.com/channels/102860784329052160/103622435865104384) on [Reactiflux](http://www.reactiflux.com/)
### Code Conventions
* 2 spaces for indentation (no tabs).
* 80 character line length strongly preferred.
* Prefer `'` over `"`.
* ES2015 syntax when possible.
* `'use strict';`.
* Use [Flow types](http://flowtype.org/).
* Use semicolons;
* Trailing commas,
* Avd abbr wrds.
## License
By contributing to metro-bundler, you agree that your contributions will be licensed under its BSD license.

30
LICENSE Normal file
View File

@ -0,0 +1,30 @@
BSD License
For metro-bundler software
Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name Facebook nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

33
PATENTS Normal file
View File

@ -0,0 +1,33 @@
Additional Grant of Patent Rights Version 2
"Software" means the metro-bundler software distributed by Facebook, Inc.
Facebook, Inc. (“Facebook”) hereby grants to each recipient of the Software
(“you”) a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
(subject to the termination provision below) license under any Necessary
Claims, to make, have made, use, sell, offer to sell, import, and otherwise
transfer the Software. For avoidance of doubt, no license is granted under
Facebook's rights in any patent claims that are infringed by (i) modifications
to the Software made by you or any third party or (ii) the Software in
combination with any software or other technology.
The license granted hereunder will terminate, automatically and without notice,
if you (or any of your subsidiaries, corporate affiliates or agents) initiate
directly or indirectly, or take a direct financial interest in, any Patent
Assertion: (i) against Facebook or any of its subsidiaries or corporate
affiliates, (ii) against any party if such Patent Assertion arises in whole or
in part from any software, technology, product or service of Facebook or any of
its subsidiaries or corporate affiliates, or (iii) against any party relating
to the Software. Notwithstanding the foregoing, if Facebook or any of its
subsidiaries or corporate affiliates files a lawsuit alleging patent
infringement against you in the first instance, and you respond by filing a
patent infringement counterclaim in that lawsuit against that party that is
unrelated to the Software, the license granted hereunder will not terminate
under section (i) of this paragraph due to such counterclaim.
A "Necessary Claim" is a claim of a patent owned by Facebook that is
necessarily infringed by the Software standing alone.
A "Patent Assertion" is any lawsuit or other action alleging direct, indirect,
or contributory infringement or inducement to infringe any patent, including a
cross-claim or counterclaim.

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# [metro-bundler](http://facebook.github.io/metro-bundler/) [![Build Status](https://travis-ci.org/facebook/metro-bundler.svg?branch=master)](https://travis-ci.org/facebook/metro-bundler) [![Windows Build Status](https://ci.appveyor.com/api/projects/status/8n38o44k585hhvhd/branch/master?svg=true)](https://ci.appveyor.com/project/Daniel15/metro-bundler/branch/master) [![npm version](https://badge.fury.io/js/metro-bundler.svg)](http://badge.fury.io/js/metro-bundler)
The JavaScript bundler for React Native

27
appveyor.yml Normal file
View File

@ -0,0 +1,27 @@
environment:
matrix:
#- nodejs_version: "4"
- nodejs_version: "6"
install:
- ps: Install-Product node $env:nodejs_version x64
- node --version
- yarn --version
- yarn install
cache:
- node_modules
- .eslintcache
test_script:
- yarn run build
- yarn test
# Don't actually build.
build: off
notifications:
- provider: Email
on_build_success: false
on_build_failure: false
on_build_status_changed: false

34
flow-typed/console.js vendored Normal file
View File

@ -0,0 +1,34 @@
/**
* Copyright (c) 2014-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';
declare module "console" {
declare export class Console {
constructor(stdout: mixed, stderr: mixed): void;
assert(value: mixed, message?: string, ...messageParts: Array<mixed>): void;
dir(data: mixed, options?: Object): void;
error(msg: string, ...msgParts: Array<mixed>): void;
error(data: mixed): void;
info(msg: string, ...msgParts: Array<mixed>): void;
info(data: mixed): void;
log(msg: string, ...msgParts: Array<mixed>): void;
log(data: mixed): void;
time(label: string): void;
timeEnd(label: string): void;
trace(msg: string, ...msgParts: Array<mixed>): void;
warn(msg: string, ...msgParts: Array<mixed>): void;
warn(data: mixed): void;
}
}

169
flow-typed/graceful-fs.js vendored Normal file
View File

@ -0,0 +1,169 @@
/**
* Copyright (c) 2014-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';
declare module "graceful-fs" {
declare class Stats {
dev: number;
ino: number;
mode: number;
nlink: number;
uid: number;
gid: number;
rdev: number;
size: number;
blksize: number;
blocks: number;
atime: Date;
mtime: Date;
ctime: Date;
isFile(): boolean;
isDirectory(): boolean;
isBlockDevice(): boolean;
isCharacterDevice(): boolean;
isSymbolicLink(): boolean;
isFIFO(): boolean;
isSocket(): boolean;
}
declare class FSWatcher extends events$EventEmitter {
close(): void
}
declare class ReadStream extends stream$Readable {
close(): void
}
declare class WriteStream extends stream$Writable {
close(): void
}
declare function gracefulify(fs: Object): void;
declare function rename(oldPath: string, newPath: string, callback?: (err: ?Error) => void): void;
declare function renameSync(oldPath: string, newPath: string): void;
declare function ftruncate(fd: number, len: number, callback?: (err: ?Error) => void): void;
declare function ftruncateSync(fd: number, len: number): void;
declare function truncate(path: string, len: number, callback?: (err: ?Error) => void): void;
declare function truncateSync(path: string, len: number): void;
declare function chown(path: string, uid: number, gid: number, callback?: (err: ?Error) => void): void;
declare function chownSync(path: string, uid: number, gid: number): void;
declare function fchown(fd: number, uid: number, gid: number, callback?: (err: ?Error) => void): void;
declare function fchownSync(fd: number, uid: number, gid: number): void;
declare function lchown(path: string, uid: number, gid: number, callback?: (err: ?Error) => void): void;
declare function lchownSync(path: string, uid: number, gid: number): void;
declare function chmod(path: string, mode: number | string, callback?: (err: ?Error) => void): void;
declare function chmodSync(path: string, mode: number | string): void;
declare function fchmod(fd: number, mode: number | string, callback?: (err: ?Error) => void): void;
declare function fchmodSync(fd: number, mode: number | string): void;
declare function lchmod(path: string, mode: number | string, callback?: (err: ?Error) => void): void;
declare function lchmodSync(path: string, mode: number | string): void;
declare function stat(path: string, callback?: (err: ?Error, stats: Stats) => any): void;
declare function statSync(path: string): Stats;
declare function fstat(fd: number, callback?: (err: ?Error, stats: Stats) => any): void;
declare function fstatSync(fd: number): Stats;
declare function lstat(path: string, callback?: (err: ?Error, stats: Stats) => any): void;
declare function lstatSync(path: string): Stats;
declare function link(srcpath: string, dstpath: string, callback?: (err: ?Error) => void): void;
declare function linkSync(srcpath: string, dstpath: string): void;
declare function symlink(srcpath: string, dtspath: string, type?: string, callback?: (err: ?Error) => void): void;
declare function symlinkSync(srcpath: string, dstpath: string, type: string): void;
declare function readlink(path: string, callback: (err: ?Error, linkString: string) => void): void;
declare function readlinkSync(path: string): string;
declare function realpath(path: string, cache?: Object, callback?: (err: ?Error, resolvedPath: string) => void): void;
declare function realpathSync(path: string, cache?: Object): string;
declare function unlink(path: string, callback?: (err: ?Error) => void): void;
declare function unlinkSync(path: string): void;
declare function rmdir(path: string, callback?: (err: ?Error) => void): void;
declare function rmdirSync(path: string): void;
declare function mkdir(path: string, mode?: number, callback?: (err: ?Error) => void): void;
declare function mkdirSync(path: string, mode?: number): void;
declare function readdir(path: string, callback?: (err: ?Error, files: Array<string>) => void): void;
declare function readdirSync(path: string): Array<string>;
declare function close(fd: number, callback?: (err: ?Error) => void): void;
declare function closeSync(fd: number): void;
declare function open(path: string, flags: string, mode?: number, callback?: (err: ?Error, fd: number) => void): void;
declare function openSync(path: string, flags: string, mode?: number): number;
declare function utimes(path: string, atime: number, mtime: number, callback?: (err: ?Error) => void): void;
declare function utimesSync(path: string, atime: number, mtime: number): void;
declare function futimes(fd: number, atime: number, mtime: number, callback?: (err: ?Error) => void): void;
declare function futimesSync(fd: number, atime: number, mtime: number): void;
declare function fsync(fd: number, callback?: (err: ?Error) => void): void;
declare function fsyncSync(fd: number): void;
declare var write: (fd: number, buffer: Buffer, offset: number, length: number, position?: mixed, callback?: (err: ?Error, write: number, str: string) => void) => void
| (fd: number, data: mixed, position?: mixed, encoding?: string, callback?: (err: ?Error, write: number, str: string) => void) => void;
declare var writeSync: (fd: number, buffer: Buffer, offset: number, length: number, position?: number) => number
| (fd: number, data: mixed, position?: mixed, encoding?: string) => number;
declare function read(
fd: number,
buffer: Buffer,
offset: number,
length: number,
position: ?number,
callback?: (err: ?Error, bytesRead: number, buffer: Buffer) => void
): void;
declare function readSync(
fd: number,
buffer: Buffer,
offset: number,
length: number,
position: number
): number;
declare function readFile(
filename: string,
callback: (err: ?Error, data: Buffer) => void
): void;
declare function readFile(
filename: string,
encoding: string,
callback: (err: ?Error, data: string) => void
): void;
declare function readFile(
filename: string,
options: { encoding: string; flag?: string },
callback: (err: ?Error, data: string) => void
): void;
declare function readFile(
filename: string,
options: { flag?: string },
callback: (err: ?Error, data: Buffer) => void
): void;
declare function readFileSync(filename: string, _: void): Buffer;
declare function readFileSync(filename: string, encoding: string): string;
declare function readFileSync(filename: string, options: { encoding: string, flag?: string }): string;
declare function readFileSync(filename: string, options: { encoding?: void, flag?: string }): Buffer;
declare function writeFile(
filename: string,
data: Buffer | string,
options?: Object | string,
callback?: (err: ?Error) => void
): void;
declare function writeFileSync(
filename: string,
data: Buffer | string,
options?: Object | string
): void;
declare function appendFile(filename: string, data: string | Buffer, options?: Object, callback?: (err: ?Error) => void): void;
declare function appendFileSync(filename: string, data: string | Buffer, options?: Object): void;
declare function watchFile(filename: string, options?: Object, listener?: (curr: Stats, prev: Stats) => void): void;
declare function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void;
declare function watch(filename: string, options?: Object, listener?: (event: string, filename: string) => void): FSWatcher;
declare function exists(path: string, callback?: (exists: boolean) => void): void;
declare function existsSync(path: string): boolean;
declare function access(path: string, mode?: any, callback?: (err: ?Error) => void): void;
declare function accessSync(path: string, mode?: any): void;
declare function createReadStream(path: string, options?: Object): ReadStream;
declare function createWriteStream(path: string, options?: Object): WriteStream;
declare var F_OK: number;
declare var R_OK: number;
declare var W_OK: number;
declare var X_OK: number;
}

7
lerna.json Normal file
View File

@ -0,0 +1,7 @@
{
"lerna": "2.0.0-beta.32",
"version": "0.1.0",
"packages": [
"packages/*"
]
}

46
package.json Normal file
View File

@ -0,0 +1,46 @@
{
"private": true,
"devDependencies": {
"babel-core": "^6.18.2",
"babel-eslint": "^7.1.1",
"babel-plugin-syntax-trailing-function-commas": "^6.13.0",
"babel-plugin-transform-async-to-generator": "^6.16.0",
"babel-plugin-transform-es2015-destructuring": "^6.19.0",
"babel-plugin-transform-es2015-parameters": "^6.18.0",
"babel-plugin-transform-flow-strip-types": "^6.18.0",
"chalk": "^1.1.3",
"codecov": "^1.0.1",
"eslint": "^3.11.1",
"eslint-config-fb-strict": "^18.0.0",
"eslint-plugin-babel": "^4.0.0",
"eslint-plugin-flow-vars": "^0.5.0",
"eslint-plugin-flowtype": "^2.28.2",
"eslint-plugin-react": "^6.7.1",
"flow-bin": "^0.37.4",
"glob": "^7.1.1",
"istanbul-api": "^1.1.0",
"istanbul-lib-coverage": "^1.0.0",
"lerna": "2.0.0-beta.32",
"micromatch": "^2.3.11",
"mkdirp": "^0.5.1"
},
"scripts": {
"build-clean": "rm -rf ./packages/*/build",
"build": "node ./scripts/build.js",
"clean-all": "rm -rf ./node_modules; rm -rf ./packages/*/node_modules; yarn run build-clean",
"jest-coverage": "yarn run jest -- --coverage",
"lint": "eslint . --cache",
"postinstall": "node ./scripts/postinstall.js && node ./scripts/build.js",
"publish": "yarn run build-clean && yarn run build && lerna publish",
"test-ci": "yarn run typecheck && yarn run lint && yarn run build && yarn run jest-coverage -- -i && node scripts/mapCoverage.js && codecov",
"test": "yarn run typecheck && yarn run lint && yarn run build && yarn run jest && yarn run test-examples",
"typecheck": "flow check",
"watch": "yarn run build; node ./scripts/watch.js"
},
"jest": {
"testEnvironment": "node"
},
"dependencies": {
"jest": "^18.1.0"
}
}

View File

View File

@ -0,0 +1,26 @@
{
"name": "metro-bundler",
"description": "The JavaScript bundler for React Native",
"version": "0.1.0",
"main": "build/index.js",
"bin": {
"metro-bundler": "./bin/metro-bundler.js"
},
"engines": {
"node": ">= 4"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/metro-bundler"
},
"bugs": {
"url": "https://github.com/facebook/metro-bundler/issues"
},
"homepage": "http://facebook.github.io/metro-bundler/",
"keywords": [
"bundler",
"react",
"react-native"
],
"license": "BSD-3-Clause"
}

5
scripts/.eslintrc Normal file
View File

@ -0,0 +1,5 @@
{
"rules": {
"babel/func-params-comma-dangle": 0
}
}

20
scripts/_getPackages.js Normal file
View File

@ -0,0 +1,20 @@
/**
* Copyright (c) 2014, 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.
*/
'use strict';
const fs = require('fs');
const path = require('path');
const PACKAGES_DIR = path.resolve(__dirname, '../packages');
// Get absolute paths of all directories under packages/*
module.exports = function getPackages() {
return fs.readdirSync(PACKAGES_DIR)
.map(file => path.resolve(PACKAGES_DIR, file))
.filter(f => fs.lstatSync(path.resolve(f)).isDirectory());
};

63
scripts/_runCommands.js Normal file
View File

@ -0,0 +1,63 @@
/**
* Copyright (c) 2014, 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.
*/
'use strict';
const chalk = require('chalk');
const spawnSync = require('child_process').spawnSync;
/**
* @example `runCommands('npm test', packageDirectory)`
* @example `runCommands(['npm test', 'npm publish'], packageDirectory)`
* @param {boolean} options.suppressOutput don't print output to stdout
*/
module.exports = function runCommands(commands, cwd, options) {
options || (options = {});
if (!cwd) {
cwd = __dirname;
}
[].concat(commands).forEach(commandAndArgs => {
const cmd = commandAndArgs.split(' ')[0];
const args = commandAndArgs.split(' ').slice(1);
let msg = chalk.green('-> ') + chalk.underline.bold('running:') +
' ' + chalk.bold.cyan(cmd + ' ' + args.join(' '));
if (cwd) {
msg += ' cwd: ' + chalk.underline.bold(cwd);
}
const spawnOpts = {cwd};
if (options.suppressOutput) {
msg += chalk.red(' (output supressed)');
} else {
Object.assign(spawnOpts, {stdio: [0, 1, 1]});
}
console.log(msg);
const result = spawnSync(cmd, args, spawnOpts);
if (result.error || result.status !== 0) {
result.error && console.log(chalk.red(result.error));
// print output if it was suppressed
if (options.suppressOutput) {
result.stdout && console.log(result.stdout.toString());
result.stderr && console.log(chalk.red(result.stderr.toString()));
}
console.log(chalk.red(
`-> failed running: ${cmd + ' ' + args.join(' ')}`
));
process.exit(1);
}
});
};

111
scripts/build.js Normal file
View File

@ -0,0 +1,111 @@
/**
* Copyright (c) 2014, 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.
*/
'use strict';
/**
* script to build (transpile) files.
* By default it transpiles all files for all packages and writes them
* into `build/` directory.
* Non-js or files matching IGNORE_PATTERN will be copied without transpiling.
*
* Example:
* node ./scripts/build.js
* node ./scripts/build.js /user/c/metro-bundler/packages/metro-abc/src/abc.js
*/
const babel = require('babel-core');
const chalk = require('chalk');
const fs = require('fs');
const getPackages = require('./_getPackages');
const glob = require('glob');
const micromatch = require('micromatch');
const path = require('path');
const spawnSync = require('child_process').spawnSync;
const SRC_DIR = 'src';
const JS_FILES_PATTERN = '**/*.js';
const IGNORE_PATTERN = '**/__tests__/**';
const PACKAGES_DIR = path.resolve(__dirname, '../packages');
const babelOptions = JSON.parse(fs.readFileSync(
path.resolve(__dirname, '..', '.babelrc'),
'utf8'
));
babelOptions.babelrc = false;
const fixedWidth = str => {
const WIDTH = 80;
const strs = str.match(new RegExp(`(.{1,${WIDTH}})`, 'g'));
let lastString = strs[strs.length - 1];
if (lastString.length < WIDTH) {
lastString += Array(WIDTH - lastString.length).join(chalk.dim('.'));
}
return strs.slice(0, -1).concat(lastString).join('\n');
};
function buildPackage(p) {
const srcDir = path.resolve(p, SRC_DIR);
const pattern = path.resolve(srcDir, '**/*');
const files = glob.sync(pattern, {nodir: true});
process.stdout.write(
fixedWidth(`${path.basename(p)}\n`)
);
files.forEach(file => buildFile(file, true));
process.stdout.write(`[ ${chalk.green('OK')} ]\n`);
}
function buildFile(file, silent) {
const packageName = path.relative(PACKAGES_DIR, file).split(path.sep)[0];
const packageSrcPath = path.resolve(PACKAGES_DIR, packageName, 'src');
const packageBuildPath = path.resolve(PACKAGES_DIR, packageName, 'build');
const relativeToSrcPath = path.relative(packageSrcPath, file);
const destPath = path.resolve(packageBuildPath, relativeToSrcPath);
spawnSync('mkdir', ['-p', path.dirname(destPath)]);
if (micromatch.isMatch(file, IGNORE_PATTERN)) {
silent || process.stdout.write(
chalk.dim(' \u2022 ') +
path.relative(PACKAGES_DIR, file) +
' (ignore)\n'
);
} else if (!micromatch.isMatch(file, JS_FILES_PATTERN)) {
fs.createReadStream(file).pipe(fs.createWriteStream(destPath));
silent || process.stdout.write(
chalk.red(' \u2022 ') +
path.relative(PACKAGES_DIR, file) +
chalk.red(' \u21D2 ') +
path.relative(PACKAGES_DIR, destPath) +
' (copy)' +
'\n'
);
} else {
const transformed = babel.transformFileSync(file, babelOptions).code;
spawnSync('mkdir', ['-p', path.dirname(destPath)]);
fs.writeFileSync(destPath, transformed);
silent || process.stdout.write(
chalk.green(' \u2022 ') +
path.relative(PACKAGES_DIR, file) +
chalk.green(' \u21D2 ') +
path.relative(PACKAGES_DIR, destPath) +
'\n'
);
}
}
const files = process.argv.slice(2);
if (files.length) {
files.forEach(buildFile);
} else {
process.stdout.write(chalk.bold.inverse('Building packages\n'));
getPackages().forEach(buildPackage);
process.stdout.write('\n');
}

49
scripts/mapCoverage.js Normal file
View File

@ -0,0 +1,49 @@
/**
* Copyright (c) 2014, 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.
*/
'use strict';
/**
* Because we have a build step, sometimes we can test files from both
* `packages/metro-whatever/build/*` and `packages/metro-whatever/src/*`
*
* If we require file by its relative path like:
* // inside `metro-whatever/src/__tests__/index.js`
* require('../index.js'); // this will require `metro-whatever/src/index.js`
*
* But if we require it by a package name, this will go through node_modules
* and lerna index.js link. So the actual file will be required from `build/`
* // inside another packages
* // this will go through lerna and require `metro-whatever/build/index.js
* require('metro-whatever')
*
* these files are identical (one is preprocessed, another is transformed on
* the fly), but the coverage paths are different.
* This script will map coverage results from both locations to one and
* produce a full coverage report.
*/
const createReporter = require('istanbul-api').createReporter;
const coverage = require('../coverage/coverage-final.json');
const istanbulCoverage = require('istanbul-lib-coverage');
const map = istanbulCoverage.createCoverageMap();
const reporter = createReporter();
const mapFileCoverage = fileCoverage => {
fileCoverage.path = fileCoverage.path
.replace(/(.*packages\/.*\/)(build)(\/.*)/, '$1src$3');
return fileCoverage;
};
Object.keys(coverage).forEach(
filename => map.addFileCoverage(mapFileCoverage(coverage[filename]))
);
reporter.addAll(['json', 'lcov', 'text']);
reporter.write(map);

21
scripts/postinstall.js Normal file
View File

@ -0,0 +1,21 @@
/**
* Copyright (c) 2014-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.
*/
'use strict';
const path = require('path');
const isWindows = process.platform === 'win32';
const runCommands = require('./_runCommands');
console.log(`Setting up metro-bundler's development environment...`);
const lerna = isWindows ? 'lerna.cmd' : 'lerna';
const lernaCmd = path.resolve(
__dirname,
'../node_modules/.bin/' + lerna + ' bootstrap'
);
runCommands(lernaCmd, path.resolve(__dirname, '..'));

74
scripts/watch.js Normal file
View File

@ -0,0 +1,74 @@
/**
* Copyright (c) 2014, 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.
*/
'use strict';
/**
* Watch files for changes and rebuild (copy from 'src/' to `build/`) if changed
*/
const fs = require('fs');
const getPackages = require('./_getPackages');
const execSync = require('child_process').execSync;
const chalk = require('chalk');
const path = require('path');
const BUILD_CMD = `node ${path.resolve(__dirname, './build.js')}`;
let filesToBuild = new Map();
const exists = filename => {
try {
return fs.statSync(filename).isFile();
} catch (e) {}
return false;
};
const rebuild = filename => filesToBuild.set(filename, true);
getPackages().forEach(p => {
const srcDir = path.resolve(p, 'src');
try {
fs.accessSync(srcDir, fs.F_OK);
fs.watch(path.resolve(p, 'src'), {recursive: true}, (event, filename) => {
const filePath = path.resolve(srcDir, filename);
if (
(event === 'change' || event === 'rename') &&
exists(filePath)
) {
console.log(chalk.green('->'), `${event}: ${filename}`);
rebuild(filePath);
} else {
const buildFile = path.resolve(srcDir, '..', 'build', filename);
try {
fs.unlinkSync(buildFile);
process.stdout.write(
chalk.red(' \u2022 ') +
path.relative(path.resolve(srcDir, '..', '..'), buildFile) +
' (deleted)' +
'\n'
);
} catch (e) {}
}
});
} catch (e) {
// doesn't exist
}
});
setInterval(() => {
const files = Array.from(filesToBuild.keys());
if (files.length) {
filesToBuild = new Map();
try {
execSync(`${BUILD_CMD} ${files.join(' ')}`, {stdio: [0, 1, 2]});
} catch (e) {}
}
}, 100);
console.log(chalk.red('->'), chalk.cyan('Watching for changes...'));

2925
yarn.lock Normal file

File diff suppressed because it is too large Load Diff