Commit Graph

701 Commits

Author SHA1 Message Date
Adam Ernst 62dcb400ca Back out D6509723
Reviewed By: danzimm

Differential Revision: D6529249

fbshipit-source-id: 71c4ca9f83edfd030f77f3b67290b5751384c731
2017-12-09 13:46:35 -08:00
David Aurelio ae5ebc8078 No compound assignement operators
Summary:
Addresses a performance regression introduced by automatic linting: Compound assignment operators are much slower than keeping assignment separate on `let` bindings in certain versions of v8.

This reverts the relevant changes and configures eslint to *disallow* these operators explicitly in `metro-source-map`.

Reviewed By: mjesun

Differential Revision: D6520485

fbshipit-source-id: 16f35f5cd691ce6b1924480cbc30fbaa1275f730
2017-12-09 13:46:35 -08:00
Rafael Oleza c5e83dd86a Log bundling errors to scuba
Reviewed By: davidaurelio

Differential Revision: D6519623

fbshipit-source-id: a8e54639a041e300bb98d8a9744490fdeae17d1a
2017-12-09 13:30:05 -08:00
Adam Liechty f347e4ff47 Expose createModuleIdFactory as bundler option
Summary:
**Summary**

`createModuleIdFactory` is already used in `metro` internally, but is currently always a fixed function.
This enables `metro.runBuild()` to be run with a custom module ID factory.

One use case: building a base bundle, on top of which other application-specific bundles could reference modules in the base.  The application-specific IDs need to not conflict with those in the base bundle, and all references to modules in the base must resolve to the correct ID in the base bundle.  A custom ID factory can make all this possible.

**Test plan**

<!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. -->

Using `metro.runBuild(...)` with these changes, I was able to substitute in a custom ID factory

```javascript
const fs = require('fs')
const metro = require('metro')

const baseManifestFileContents = JSON.parse(fs.readFileSync('./baseManifest.json'))
// baseManifest looks like:
// { "modules": { ...
//    "react/index.js": { "id": 12 },
//    "react/cjs/react.production.min.js": { "id": 13 }, ...  } }

const opts = {
  dev: false,
  entry: 'index.js',
  out: './out.bundle',
  platform: 'ios',
  projectRoots: ['.', 'node_modules'],
  config: {
    createModuleIdFactory: createModuleIdFactory(baseManifestFileContents)
  }
}

metro.runBuild(opts)

// Creates a sample custom ID factory
function createModuleIdFactory(manifestFileContents) {
  return function createModuleIdFactory() {
    const fileToIdMap = new Map()
    let nextId = manifestFileContents ? getNextIdAfterBaseManifest(manifestFileContents) : 0

    return path => {
      const sourcePath = path
        .replace(process.cwd() + '/node_modules/', '')
        .replace(process.cwd(), '.')

      // If module is in the base manifest, return its ID
      if (manifestFileContents && manifestFileContents.modules[sourcePath]) {
        return manifestFileContents.modules[sourcePath].id
      }

      // Otherwise, get it from the map or create a new ID
      if (!fileToIdMap.has(path)) {
        fileToIdMap.set(path, nextId)
        nextId += 1
      }
      return fileToIdMap.get(path)
    }
  }

  function getNextIdAfterBaseManifest(manifestFileContents) {
    return Object.keys(manifestFileContents.modules).reduce((id, key) => {
      if (manifestFileContents.modules[key].id > id) {
        return manifestFileContents.modules[key].id
      }
      return id
    }, 0) + 1
  }
}
```

With the sample module ID factory above, the output looks like the following, where defined module IDs start at a higher number to avoid the base module IDs, but may depend on modules in the base bundle (lower numbers).

```javascript
...
__d(function(r,o,t,i,n){t.exports=r.ErrorUtils},551,[]);
__d(function(n,t,o,r,u){'use strict';var e,c=t(u[0]);e=c.now?function(){return c.now()}:function(){return Date.now()},o.exports=e},552,[553]);
...
__d(function(e,t,r,s,l){'use strict'; ...},564,[18,565,27]);
...
```
Closes https://github.com/facebook/metro/pull/100

Reviewed By: mjesun

Differential Revision: D6508351

Pulled By: rafeca

fbshipit-source-id: f2cfe5c373a6c83c8ae6c526435538633a7c9c2a
2017-12-08 06:29:23 -08:00
Rafael Oleza 6d7ba472ee Consolidate AssetData flow types
Reviewed By: jeanlauliac

Differential Revision: D6497429

fbshipit-source-id: cd9abe2d8c5b2b7eb48d8a0335ea5bfa8ac13269
2017-12-08 04:44:26 -08:00
Rafael Oleza 452ee5962d Add metro-source-map dependency to metro package
Reviewed By: cpojer

Differential Revision: D6509723

fbshipit-source-id: da92908c9272148112a98defed328d64cc1bf791
2017-12-08 04:16:06 -08:00
Jean Lauliac 2ecf6c9450 metro: introduce asyncRequire function
Reviewed By: davidaurelio

Differential Revision: D6498107

fbshipit-source-id: a9c4ab634e60f19b7058205eddcd248f57f63500
2017-12-07 10:49:27 -08:00
Peter van der Zee 636c0ed5c9 Kick off metro-core by moving the source-map generator
Reviewed By: rafeca

Differential Revision: D6448594

fbshipit-source-id: 8498ae8ff62e5afc6ae92c56b7c15cdaf8acd3a1
2017-12-07 09:33:50 -08:00
Adam Ernst 9e4cfb4c93 Upgrade to 1.9.1
Reviewed By: vjeux

Differential Revision: D6497877

fbshipit-source-id: 3b88b96e375ddf1fbe039a0593569bbdde40a2dc
2017-12-06 17:31:38 -08:00
Miguel Jimenez Esun 3a377ee0a7 Upgrade Jest to "21.3.0-beta.13"
Reviewed By: rafeca

Differential Revision: D6497197

fbshipit-source-id: b816f4b02cf35abee4ce4098c30291b32656ed04
2017-12-06 09:04:51 -08:00
Rafael Oleza 758ce871e6 Get rid of AssetServer
Reviewed By: mjesun

Differential Revision: D6488612

fbshipit-source-id: e6144f0e143c0008d47342077b4a2c6c15765edc
2017-12-06 07:32:47 -08:00
Rafael Oleza 5bff35f09e Remove getAssetData() method from AssetServer
Reviewed By: mjesun

Differential Revision: D6488537

fbshipit-source-id: 48c27e9cf5802c62fb25aac592ac1c5bcd6cc87f
2017-12-06 07:32:46 -08:00
Jean Lauliac 0e6f72b1ed metro: cleanup collectDependencies
Reviewed By: rafeca

Differential Revision: D6474108

fbshipit-source-id: fd497a248d3552a75e572b1ef8365cc5424c2c00
2017-12-06 03:17:09 -08:00
Rafael Oleza 0e583a981f Get rid of outdated_dependencies
Reviewed By: jeanlauliac

Differential Revision: D6485979

fbshipit-source-id: 8cf21a8c531d96df93f66e1cc465fe7ae044ef8e
2017-12-05 10:45:24 -08:00
Rafael Oleza d8cb904104 Bump metro@0.23.0
Reviewed By: davidaurelio

Differential Revision: D6484402

fbshipit-source-id: e934edc5319aec3c6f36927a0c8d5b48c304719e
2017-12-05 09:28:57 -08:00
Peter van der Zee dfa05cbcd4 Enable flow type for a file and fix a related typo/bug
Reviewed By: rafeca

Differential Revision: D6473575

fbshipit-source-id: 7b96b6bfb2aff96e6d4697ad29fd96fb85d1ceda
2017-12-05 01:31:30 -08:00
Rafael Oleza 5c06a80fd7 Remove old wrapping logic
Reviewed By: davidaurelio

Differential Revision: D6439155

fbshipit-source-id: 3332b9c7952c90411d0c595f184f92aeffd4ddd2
2017-12-04 16:46:17 -08:00
Rafael Oleza 8c43848a1e Move the asset JS generation logic to the worker
Summary:
With this, we do all the transformation and wrapping of files inside the workers, which mean faster initial builds (because parallelization and caching), and more legacy code that can be removed (see the following diff).

I've done some tests locally, and while the initial builds are slightly faster, the increase is not super substantial (the big win was in the diff were I moved the wrapping of JS files, in this diff only the assets transformation has speed up).

The most important thing that this diff enables is the possibility of doing the minification of modules also in the worker. This will mean that we can cache minified files and prod builds will get significantly faster - almost as fast as development builds (this will be relevant mainly for the opensource community).

Reviewed By: davidaurelio

Differential Revision: D6439144

fbshipit-source-id: ba2200569a668fcbe68dbfa2b3b60b3db6673326
2017-12-04 16:46:15 -08:00
Rafael Oleza f3ea76a0b4 Simplify AssetModule logic
Reviewed By: jeanlauliac

Differential Revision: D6438714

fbshipit-source-id: ec1cfe0d439b1dcb07a0861872df5318f468396a
2017-12-04 16:46:15 -08:00
Rafael Oleza fbdbd7ae2c Make Module.getName() return relative paths for non-haste modules
Reviewed By: davidaurelio

Differential Revision: D6473739

fbshipit-source-id: d459040f99148ae4be0d58c40d5eef7bb5e2b929
2017-12-04 16:46:15 -08:00
Rafael Oleza e324b229bb Make getAssetData() method stateless
Reviewed By: davidaurelio

Differential Revision: D6436349

fbshipit-source-id: 3544ae2824ada191f8ad8909f3b6cef13f208975
2017-12-04 16:46:13 -08:00
Rafael Oleza 8b28294bbd Do not cache hash generation in the AssetServer
Reviewed By: davidaurelio

Differential Revision: D6436249

fbshipit-source-id: eebbd92ebfdf1c8f12dbbcf3f5a66166fb1bc828
2017-12-04 16:46:11 -08:00
Rafael Oleza 5fb41e6fc8 Move AssetServer methods that do not require any state out of AssetServer
Reviewed By: davidaurelio

Differential Revision: D6436227

fbshipit-source-id: f276c88b6c954e864c966758a9ec0a17f0aca55f
2017-12-04 16:46:10 -08:00
Marshall Roch 7924e70fe4 @allow-large-files [flow] deploy flow 0.60
Reviewed By: gabelevi

Differential Revision: D6466441

fbshipit-source-id: c51eeb53a2465498ad77b3865b5f8c03758d1d35
2017-12-04 13:30:30 -08:00
Rafael Oleza 3016e74efd Add X-Metro-Files-Changed-Count header to Delta responses
Reviewed By: davidaurelio

Differential Revision: D6473909

fbshipit-source-id: bd71693816007bf961f4b3a7f10b7b6380d158e0
2017-12-04 13:00:12 -08:00
Rafael Oleza b456f7b61a Remove old extract-dependencies logic
Reviewed By: davidaurelio

Differential Revision: D6447749

fbshipit-source-id: 39c4960da65a9d8ab1e2615d48f5c2868a17f82b
2017-12-04 08:14:55 -08:00
Jean Lauliac 03e735d232 metro: fix collect-dependencies for the async/BundleSegments case
Reviewed By: cpojer

Differential Revision: D6462925

fbshipit-source-id: ca83176a7c7f47346daf16703cefb86172dc35b5
2017-12-02 04:58:52 -08:00
Rafael Oleza de7f1d90f2 Support null transformer AST output
Summary: This fixes https://github.com/facebook/metro/issues/99, which causes issues when metro tries to build files that are ignored by babel (if babel transformer ignores a file, it returns a null AST, which makes the collectDependencies logic break).

Reviewed By: mjesun

Differential Revision: D6466878

fbshipit-source-id: b5030e03775b982958a0b9204f4efccc8940ae4d
2017-12-02 00:28:42 -08:00
Rafael Oleza 5d76d340e5 Check for inverseDependencies existance before calling HMR
Differential Revision: D6449768

fbshipit-source-id: d9fe8b54fec0754ffb8ce2db1e87f180862a57a3
2017-12-01 08:59:20 -08:00
Rafael Oleza 8cf97e332f Use async/await in AssetServer methods
Reviewed By: davidaurelio

Differential Revision: D6435849

fbshipit-source-id: c665dfd6737e636f06c7056a89609730a5041a53
2017-11-30 04:03:29 -08:00
Rafael Oleza e19f82d408 Remove unused param from AssetServer
Reviewed By: jeanlauliac

Differential Revision: D6435881

fbshipit-source-id: 1d6d354e63a67f566e69d894bc22999e32b9a76f
2017-11-30 04:03:29 -08:00
Rafael Oleza 750e62bcdf Remove transformAndExtractDependencies() method in worker
Reviewed By: mjesun, davidaurelio

Differential Revision: D6433590

fbshipit-source-id: ef3c31d73a831fabe2a6f1be6051b0cb5c7e6c55
2017-11-30 04:03:29 -08:00
Jean Lauliac 86aba17329 metro: clean up Module option, remove some from state
Reviewed By: davidaurelio

Differential Revision: D6435957

fbshipit-source-id: eaed8f5c1d4d18d6ff0bde34892f059a01fe1a65
2017-11-30 04:03:29 -08:00
Jean Lauliac ec4a0ce527 packager-worker-for-buck: resolve at bundling time using js_library resolution information
Reviewed By: davidaurelio

Differential Revision: D6414372

fbshipit-source-id: 7bb0404e51a6130dfc89adb9476ad829020e76f0
2017-11-30 04:03:29 -08:00
Christoph Nakazawa 66b381a5c7 Export Config/defaults on Metro's main module
Reviewed By: arcanis

Differential Revision: D6435529

fbshipit-source-id: a9549dc5900025fcc798ccb92b49e96c982c2e1e
2017-11-30 04:03:29 -08:00
cpojer 0f7ad193c7 Rename metro-bundler to metro
Reviewed By: davidaurelio

Differential Revision: D6413420

fbshipit-source-id: f13184b8157de2c3aeaa7f2647becc175f62cdbb
2017-11-30 11:56:25 +00:00
Maël Nison 9249ebcea7 Adds a (deprecated) --reset-cache option
Reviewed By: BYK

Differential Revision: D6424553

fbshipit-source-id: f84064f86a985ab19794ea3d94410dceac77a95b
2017-11-29 00:45:23 -08:00
Burak Yigit Kaya cf9ef1b30f Make `assetTransforms` option available to the new metro CLI
Reviewed By: arcanis

Differential Revision: D6424404

fbshipit-source-id: 30c56128b914d86491fce6276775d75e7b497146
2017-11-29 00:45:23 -08:00
Peter van der Zee 37995e2196 Add a bundle type to logger output and type
Reviewed By: rafeca

Differential Revision: D6405599

fbshipit-source-id: 2f3da971d55fae28fbd94ed9f60d3bc2be176d6a
2017-11-28 04:55:00 -08:00
Rafael Oleza b0de96c74a Small refactor in module resolution
Reviewed By: jeanlauliac

Differential Revision: D6417509

fbshipit-source-id: 9c6abb8ceebb7048c775c9c9d21cd881f7e56c1f
2017-11-28 04:35:55 -08:00
Maël Nison 5cc0939454 Automatically watches the metro configuration file
Reviewed By: BYK

Differential Revision: D6408358

fbshipit-source-id: d167534c9c51c3c079148d982ef4ab44c8be0d75
2017-11-28 04:35:55 -08:00
Miguel Jimenez Esun b282031517 Make tests compatible with the latest Jest version
Reviewed By: cpojer

Differential Revision: D6419868

fbshipit-source-id: f01a3f4d54ca1aa3539d92363a51f70247642463
2017-11-28 03:34:45 -08:00
Rafael Oleza ac2aa718c0 Bump metro-bundler@0.22.1
Reviewed By: mjesun

Differential Revision: D6415105

fbshipit-source-id: 51687fd20fc5958a3b18d704ffa100400d208057
2017-11-27 11:29:54 -08:00
Rafael Oleza d46e4ecb6a Keep the dependencyMaps consistent between runs
Reviewed By: mjesun

Differential Revision: D6413998

fbshipit-source-id: fd0ff9a82dcca23603977456b51213216c370f8d
2017-11-27 08:52:03 -08:00
Maël Nison 167bda72b0 Fixes various issues on the Metro CLI
Reviewed By: rafeca

Differential Revision: D6407718

fbshipit-source-id: 871dd77fad4fcf8f6b0fa628bacc0dfb6cb51484
2017-11-27 04:36:12 -08:00
Burak Yigit Kaya 319220d870 Do not return a promise from transformers unless we have to
Reviewed By: mjesun

Differential Revision: D6405568

fbshipit-source-id: 09463442aecdb844e18498c3b3ce169d2915fe77
2017-11-27 02:32:39 -08:00
Rafael Oleza 091f8560f2 Make inlineRequires boolean when passed to the transformer
Reviewed By: mjesun

Differential Revision: D6408081

fbshipit-source-id: 812c8e3983677f4133ef3080525859a4a70418b7
2017-11-26 11:20:57 -08:00
Rafael Oleza 2d03a34bbc Remove isJSON() method from Module
Reviewed By: cpojer

Differential Revision: D6408739

fbshipit-source-id: 3f1b76ca54937fbc433d4e7a804a9703a3a2ccb7
2017-11-24 13:06:22 -08:00
Rafael Oleza 75047399d8 Simplify transform options + pass minify to the transformer
Reviewed By: mjesun

Differential Revision: D6406614

fbshipit-source-id: 722e8e209c7b7c922139f0777b9b3bd2a77bf735
2017-11-24 13:06:22 -08:00
Christoph Nakazawa 06466e4f6e Remove some of the whitespace from the progess output
Reviewed By: rafeca

Differential Revision: D6408458

fbshipit-source-id: 2e6c50baedbd53ce4271edc337fada3b628d9c63
2017-11-24 11:56:57 -08:00
Rafael Oleza b08ce130fd Move wrapModule logic for scripts, modules and JSON files to the transformer
Reviewed By: davidaurelio

Differential Revision: D6389116

fbshipit-source-id: fa43bd54669849c22b6b9d155ab07676b2455ef7
2017-11-23 15:40:03 -08:00
Rafael Oleza b193fc3436 BREAKING: metro transformers should only output AST
Reviewed By: jeanlauliac

Differential Revision: D6396416

fbshipit-source-id: e4c6f0c0feb1ac638dc13dd3eb400f1bc72b5d44
2017-11-23 15:40:03 -08:00
Jean Lauliac f434d43f54 metro-bundler: RAM bundles cannot contain scripts masquerading as modules
Reviewed By: davidaurelio

Differential Revision: D6405614

fbshipit-source-id: 6c21fd30d6246f50c34e9f23a193452737a3b67b
2017-11-23 12:10:21 -08:00
Peter van der Zee ccd8eae0b0 Fix terminal string chunker to ignore non-printable color seqs
Reviewed By: rafeca

Differential Revision: D6405127

fbshipit-source-id: 94fd12a04db43a790af34fdee36be9d7f8ecf59d
2017-11-23 10:11:54 -08:00
Burak Yigit Kaya b7ba5c7ee1 Support async transformers
Reviewed By: rafeca, mjesun

Differential Revision: D6405491

fbshipit-source-id: 7110135e9f75ab43c03710abfa8e582577662ab3
2017-11-23 09:56:44 -08:00
Peter van der Zee a766a4a499 Update http progress output in cli; add platform, shorten rest
Reviewed By: rafeca, davidaurelio

Differential Revision: D6395717

fbshipit-source-id: 0fed7f29539bb59bc300d88b09a99be13bbb42ba
2017-11-23 08:27:13 -08:00
Rafael Oleza 6557272f8c Avoid losing deltas when unexpected errors happen on the DeltaTransformer
Reviewed By: jeanlauliac

Differential Revision: D6402261

fbshipit-source-id: 6a1a18c1bd7d4f7cecd5a5e9114f6eb493d40b4d
2017-11-23 08:27:13 -08:00
Rafael Oleza 70dadc63f9 Update Readme + change default transform
Reviewed By: cpojer

Differential Revision: D6401596

fbshipit-source-id: 8928abb825933edd84c508a4f04f50c748725722
2017-11-23 03:06:48 -08:00
Burak Yigit Kaya 7b5ae96479 Add option to bypass AssetRegistry and sending assets to transforms
Reviewed By: rafeca

Differential Revision: D6385816

fbshipit-source-id: b94fb125bee0576cfb25170aa86a253c10a3d862
2017-11-23 02:38:19 -08:00
Rafael Oleza 5f58ae0e84 Metro reads AST from transformers if available
Reviewed By: BYK

Differential Revision: D6396330

fbshipit-source-id: 10539a1cce81b090a781df7d75515d52ece9ef9c
2017-11-22 13:36:20 -08:00
Rafael Oleza c9e0589171 Allow HMR client accept wrapped modules from metro
Reviewed By: davidaurelio

Differential Revision: D6385273

fbshipit-source-id: 15109332aceb4c0523c668a54b1bf40d8e8fba80
2017-11-22 11:37:20 -08:00
Jean Lauliac 52a76cb5af packager-worker-for-buck: refactor and fix source map output
Reviewed By: davidaurelio

Differential Revision: D6385199

fbshipit-source-id: f104f7b000dde131b57b671d14d4ec4e0d30d7a2
2017-11-22 05:08:49 -08:00
Peter van der Zee efceeacd77 Move Option types from Server to shared/types.flow
Reviewed By: davidaurelio

Differential Revision: D6384292

fbshipit-source-id: 58cba889f549cbd7a8c82856d5283048f4f2a8c5
2017-11-22 03:57:33 -08:00
Rafael Oleza d4b7cb5d08 Bump metro to v0.21.1
Reviewed By: mjesun

Differential Revision: D6385524

fbshipit-source-id: 189f03466f8e84a9ac3acfd1aa0faf4f39d394f2
2017-11-21 10:28:18 -08:00
Jean Lauliac 507fbd7d7e packager-worker-for-buck: store resolutions at library level
Reviewed By: davidaurelio

Differential Revision: D6359267

fbshipit-source-id: 795d451c6ff32c07842e9e067778136180a9988e
2017-11-21 07:08:28 -08:00
Rafael Oleza 6ec09775ef Upgrade uglify-es to 3.1.9
Reviewed By: davidaurelio

Differential Revision: D6309485

fbshipit-source-id: 17d8b66a2a676a9a556509e28a48ee703fc6da89
2017-11-21 06:44:11 -08:00
Rafael Oleza 085dd97fa0 Change getModuleId() signature to directly accept a path
Reviewed By: mjesun

Differential Revision: D6373180

fbshipit-source-id: d6b49431adf85e7587cf0fe858d9dc9b9afeee06
2017-11-21 05:45:44 -08:00
Rafael Oleza e58b7f1d73 Do not calculate inverseDependencies when processing a standard delta bundle
Reviewed By: mjesun

Differential Revision: D6373006

fbshipit-source-id: 86863595b1e5f0417e898f19f21ed83147b46db3
2017-11-21 05:45:44 -08:00
Jean Lauliac b77f177f92 metro-bundler: add additional tip for resolution errors
Summary: Rebase of a PR, closes https://github.com/facebook/metro-bundler/pull/39/files

Reviewed By: cpojer

Differential Revision: D6372967

fbshipit-source-id: 84c77b7e445269638616abde56b728ea6d3e475c
2017-11-21 02:23:09 -08:00
Maël Nison c2c99c4c1b Fixes for the Metro cli
Reviewed By: BYK

Differential Revision: D6348698

fbshipit-source-id: 3a00d9af7e03c5d636e2a51ce95842ca7d45b6e1
2017-11-20 10:47:46 -08:00
Rafael Oleza eb1ddfdcd9 Fix initializing packager logging
Reviewed By: cpojer

Differential Revision: D6359527

fbshipit-source-id: 0741955ca0efd6d5735637407e1bc140f04c3bbf
2017-11-18 17:10:51 -08:00
Christoph Nakazawa 6d756334a8 Fix CI
Reviewed By: rafeca

Differential Revision: D6368078

fbshipit-source-id: 04232ac3762ce4c9581c694a60c1372b2f495af0
2017-11-18 10:45:32 -08:00
Christoph Nakazawa 2c6aa5c5d8 Remove unused vars
Reviewed By: davidaurelio

Differential Revision: D6362298

fbshipit-source-id: 8a79663e4f83d7b15919f2a1a8dd9416900f3203
2017-11-18 01:10:15 -08:00
Christoph Nakazawa 5fdef3bdb2 Update Flow and Lerna for the Metro repo
Summary: I'm working on getting CI to pass. As a first step, I'll upgrade the lerna setup to use Yarn's workspaces (when yarn is run from the Metro root) as well as upgrading Flow to the same version we use in xplat. I also copied over the Jest type definitions. This should fix all type errors for a start.

Reviewed By: davidaurelio

Differential Revision: D6361276

fbshipit-source-id: 4e8661b7d5fe4e3f6dd1e6923891bd2d23c9b4db
2017-11-18 01:10:15 -08:00
Maël Nison c6b0134398 Removes debug
Reviewed By: rafeca

Differential Revision: D6358889

fbshipit-source-id: f04a6dd33dac72d0ad9ceb56c49215ebc53452ff
2017-11-17 07:51:46 -08:00
Jean Lauliac f0a4418b5b metro-bundler: ModuleGraph: nit: reduce code nesting
Reviewed By: davidaurelio

Differential Revision: D6324409

fbshipit-source-id: da7626772cb24b4f3749962e72e5952982b917d6
2017-11-15 06:22:04 -08:00
Rafael Oleza c04393b397 Fix sending multipart delta responses
Reviewed By: jeanlauliac

Differential Revision: D6328147

fbshipit-source-id: fcd16e64180a49bad0a0c606ab0f2bdd2d9ac0ee
2017-11-15 03:06:04 -08:00
Jean Lauliac 56e790f958 metro-bundler: ModuleGraph: fix in-memory node-haste impl error
Reviewed By: cpojer

Differential Revision: D6323532

fbshipit-source-id: 067be85171d8d8839c977bd2aa7fdc7efc178f0a
2017-11-14 06:08:17 -08:00
Benjamin Weggersen b75f385524 Normalize module name to have platform specific folder separators
Summary:
<!-- 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? -->

It is currently not possible to resolve specific module imports (such as `react-native/Libraries/Image/AssetRegistry` using forward slashes as folder separators) using a custom mapping defined in `extraNodeModules` on Windows. This PR solves this issue by normalizing module names to use platform-specific folder separators before splitting the module name using `path.sep` as separators.

**Test plan**

<!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. -->

We use `extraNodeModules` to create a mapping between `react-native` and a forked and scoped version of react-native (i.e. `scope/react-native`). If we import a specific file from react-native (such as [`react-native/Libraries/Image/AssetRegistry`](https://github.com/facebook/react-native/blob/master/local-cli/core/Constants.js), which gets referenced when importing image assets), `ModuleResolution.js` is not able to extract the first folder name on Windows. This first folder name is the name of the module (`react-native` in the previous example) and is used to query `extraNodeModules` for possible matches. It is not able to find this folder name because the module name is split using `path.sep` as a separator, which is `'\\'` on Windows. Most module names use forward slashes as folder separators. The solution is to normalize `toModuleName` before we split on `path.sep`.
Closes https://github.com/facebook/metro-bundler/pull/89

Differential Revision: D6312391

Pulled By: jeanlauliac

fbshipit-source-id: 920c52633e8c9584ecb2bdd309dc4a8516c3199b
2017-11-14 02:52:35 -08:00
Maël Nison 1bd30c977d Adds an experimental metro-cli to metro-bundler
Reviewed By: davidaurelio

Differential Revision: D6129384

fbshipit-source-id: b32049ad17aeae74cde23dbaa79845e6a4a51507
2017-11-13 17:36:35 -08:00
Rafael Oleza e1b5fe79fa Remove ModuleTransport/ResolutionResponse modules and lots of logic from Resolver/ResolutionRequest
Reviewed By: davidaurelio

Differential Revision: D6284728

fbshipit-source-id: 53d27cd65b8c96ed6d6872eb16a9b5d1e14db85e
2017-11-13 16:43:36 -08:00
Rafael Oleza 860dcc4867 Use current DependencyGraph tests as integration tests for the traverseDependency logic
Reviewed By: davidaurelio

Differential Revision: D6284627

fbshipit-source-id: 7e3f21c53142238f7d50444627c417388a4c1d1d
2017-11-13 16:43:36 -08:00
Rafael Oleza f1728e4c7b Add support for the postProcessModules param
Reviewed By: davidaurelio

Differential Revision: D6277777

fbshipit-source-id: b9a0341f17f3829ccc3daf7db89275f07e435803
2017-11-13 16:43:36 -08:00
Caleb Meredith 42a547551f Flow 0.59 xplat/js deploy
Reviewed By: avikchaudhuri

Differential Revision: D6300238

fbshipit-source-id: a6839fa2a9bbc50c3832a3f5b1cac2a6d2bd96b7
2017-11-10 21:12:40 -08:00
Rafael Oleza 1dec296000 Downgrade uglify-js from 3.1.8 to 3.1.1
Summary:
Uglify@3.1.7 is causing some perf issues (more specifically, this commit: 5b4b07e9a7) that are impacting TTI on RN views and increased memory usage.

More specifically, code like:

```
function nonTrivialFn(pre) {
  return pre + Math.random();
}
function hotFunctionCalledALotOfTimes(num) {
  return nonTrivialFn(num + Math.random());
}
hotFunctionCalledALotOfTimes(3);
hotFunctionCalledALotOfTimes(5);
```

in v3.1.7 gets converted to:

```
function hotFunctionCalledALotOfTimes(num){
  return function(pre) {
    return pre + Math.random();
  }(num + Math.random())
}
hotFunctionCalledALotOfTimes(3);
hotFunctionCalledALotOfTimes(5);
```

This causes a function creation each time `hotFunctionCalledALotOfTimes` is called.

By comparison, in v3.1.6, that previous code was converted to:

```
function nonTrivialFn(pre){
  return pre + Math.random()
}
function hotFunctionCalledALotOfTimes(num){
  return nonTrivialFn(num + Math.random())
}
hotFunctionCalledALotOfTimes(3);
hotFunctionCalledALotOfTimes(5);
```

Reviewed By: jeanlauliac, alexeylang

Differential Revision: D6296740

fbshipit-source-id: b3988d886e607103ec3ae6b9763b2f0411a8aa3c
2017-11-10 04:52:50 -08:00
Miguel Jimenez Esun e08b34239e Add asset size to the module
Reviewed By: jeanlauliac

Differential Revision: D6284248

fbshipit-source-id: 3b860d7b123a1d2470c7b6c7e9e9082d0622c369
2017-11-10 03:20:52 -08:00
Rafael Oleza e7b4e50813 Fix flow types of sourcemaps
Reviewed By: davidaurelio

Differential Revision: D6271757

fbshipit-source-id: abf9c91a4ebd36eb4cd77acf75c40f85fbecd5f9
2017-11-08 13:03:43 -08:00
Rafael Oleza 7b93876541 Remove old Bundler/* logic
Reviewed By: mjesun

Differential Revision: D6259048

fbshipit-source-id: b39e4c602a0af9d2ad91b72a699b1369526ac9f2
2017-11-08 13:03:43 -08:00
Rafael Oleza 2eefccc72a Remove old bundler code from Server class
Reviewed By: mjesun

Differential Revision: D6255868

fbshipit-source-id: 74695129199c8be43e13c97f2ae2ca2c03b801eb
2017-11-08 13:03:43 -08:00
Rafael Oleza 8f45fb6bf3 BREAKING: Bump metro-bundler to v0.21.0
Summary:
`metro-bundler` v0.21 contains a rewritten bundling mechanism, with simplified logic and much faster rebuild times, called delta bundler. This release contains a couple of breaking changes:

* Now, when using a custom transformer, the list of additional babel plugins to apply are passed to the `transform()` method. These are used in non-dev mode for optimization purposes (Check 367a5f5db8 (diff-40653f0c822ac59a5af13d5b4ab31d84) to see how to handle them from the transformer).
* Now, when using a custom transformer outputting `rawMappings`, the transformer does not need to call the `compactMappings` method before returning (check d74685fd1d (diff-40653f0c822ac59a5af13d5b4ab31d84) for more info).
* We've removed support for two config parameters: `postProcessModules` and `postProcessBundleSourcemap`.

Reviewed By: davidaurelio

Differential Revision: D6186035

fbshipit-source-id: 242c5c2a954c6b9b6f339d345f888eaa44704579
2017-11-08 09:20:17 -08:00
Rafael Oleza 08ed373a60 Add postMinifyModule param support to Delta Bundler
Reviewed By: mjesun

Differential Revision: D6264450

fbshipit-source-id: 1dd0bc8c5957d99b6f4b6722c843fe9cc284ec3a
2017-11-08 07:07:46 -08:00
Rafael Oleza 98518c9fff Add ramGroups and preloadedModules support when creating RAM bundles
Reviewed By: davidaurelio

Differential Revision: D6250307

fbshipit-source-id: b7143fa31ded9fcaa28025f05b9d28013361ea0e
2017-11-08 07:07:46 -08:00
Miguel Jimenez Esun 91f724d69d Update Jest to 21.3.0-beta.8
Reviewed By: davidaurelio

Differential Revision: D6221784

fbshipit-source-id: 189e895378635dd21d14d6fb1f93510a52c90742
2017-11-08 06:50:53 -08:00
Rafael Oleza ed55e0a53f Remove cyclic dependency when getting the transform options
Reviewed By: davidaurelio

Differential Revision: D6231766

fbshipit-source-id: ae200a4507febcd47bcc636d0e62f01eb6a93477
2017-11-08 04:07:07 -08:00
Andreas Amsenius b0c79aa193 Upgrade uglify-es to fix minification issues
Summary:
**Summary**

Minification fails or minified bundle may crash due to uglify-es bugs which have been fixed recently. See https://github.com/facebook/react-native/issues/16689

**Test plan**

Try to production bundle a project using ex-navigation, which fails with:
```
Maximum call stack size exceeded
```

Use this patch and see that bundling suceeds. There are also minified runtime errors solved by this change, see https://github.com/facebook/react-native/issues/16689 for more information.
Closes https://github.com/facebook/metro-bundler/pull/85

Reviewed By: mjesun

Differential Revision: D6259177

Pulled By: rafeca

fbshipit-source-id: 55987eb338b06938181c0da74d104d23eeb135b6
2017-11-07 08:28:17 -08:00
Rafael Oleza 8fe2d588bc Use Delta Bundler to get all bundle assets
Reviewed By: mjesun

Differential Revision: D6255563

fbshipit-source-id: fe08021ef6be8528ddcbb553be62e8a8cf2bcf0a
2017-11-07 08:10:32 -08:00
Miguel Jimenez Esun d4dcd4c6fa Migrate metro-bundler to jest-worker
Summary:
This diff migrates Metro Bundler from `worker-farm` to `jest-worker`:

* Fully removes the custom patched `worker-farm` fork.
* Removes //a lot// of non-clear Flow types used to cast functions from callbacks to promises.
* Reduces cyclomatic complexity of the `Transformer` class by using `async`/`await`.
* Cleans all additional methods inside `JSTransformer/index.js`, by moving them to a single class and properly scoping them.

**Note:**  this diff does not still enable the ability to bind files to workers by using `computeWorkerKey`; this will come at a later stage.

Reviewed By: davidaurelio

Differential Revision: D6247532

fbshipit-source-id: 51259360a5c15117996777a3be74b73b583f595e
2017-11-07 07:52:16 -08:00
Jean Lauliac 81bfef0389 metro-bundler: allow different run-before-main-module depending on entry point
Reviewed By: davidaurelio

Differential Revision: D6248242

fbshipit-source-id: 9471820fce926e676170e3024bd48c9d7335c1a7
2017-11-07 07:41:58 -08:00
David Aurelio 2c5a2fec66 fix `$FlowFixMe`
Reviewed By: rafeca

Differential Revision: D6258938

fbshipit-source-id: 7331d0a3216c1714099139fe6c6ab8fe11771fae
2017-11-07 06:22:55 -08:00
Jean Lauliac dbb2d44c42 metro-bundler: collect-dependencies: expose async deps
Summary: To determine whether segment boundaries are properly covered by async imports rather than requires, we need to get knowledge about it higher up in the stack. This changeset exposes which of the dependencies are async as an array of indices within the `dependencies` array (I'd prefer avoiding duplicating the strings because they could get inconsistent, and I don't want to have 2 separate arrays of names either because we'd have to modify a bunch of stuff across the stack to support that).

Reviewed By: davidaurelio

Differential Revision: D6220236

fbshipit-source-id: 1ee36bc7c59f7f27e089f7771a24c45c8bd57b5d
2017-11-06 03:40:10 -08:00