Commit Graph

1775 Commits

Author SHA1 Message Date
Jean Lauliac f044f42030 metro-buck: add e2e testing of command
Reviewed By: davidaurelio

Differential Revision: D6533842

fbshipit-source-id: b641559eb3085bac57ab3a1cc80a3f2f86b7ec92
2017-12-11 11:16:21 -08:00
Maël Nison f66eb477ba Adds an indirection layer to enhance the Metro middleware
Reviewed By: BYK

Differential Revision: D6436722

fbshipit-source-id: d864960e2eb7c8c2a96e9869c0b340cc6257808e
2017-12-11 10:15:08 -08:00
Rafael Oleza fa08cb3c99 Add metro-source-map dependency to metro package
Differential Revision: D6532856

fbshipit-source-id: c6df2ad47e2befbff809103da4dcea7b5eb71dad
2017-12-11 10:01:47 -08:00
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 53290f5b9c Update flow-bin version
Reviewed By: mjesun

Differential Revision: D6519545

fbshipit-source-id: da9f5dd6029d5bfea4b6c758ca3df9caa5c5fa35
2017-12-08 05:28:57 -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
Peter Elmers 826a9489ca Fix 404 on front page 'Learn more' link
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. -->

Currently index.js points to snapshot-testing which doesn't exist. Perhaps the intent was to link to the API page so that is what I changed.

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

front page 'learn more' link should work

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

Reviewed By: cpojer

Differential Revision: D6511913

Pulled By: pelmers

fbshipit-source-id: 2a68a817cf4a318fb7dbfd5ea9a10fbea9e72620
2017-12-07 13:01:55 -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
Rafael Oleza 3721464107 Update opengraph image
Reviewed By: mjesun

Differential Revision: D6496190

fbshipit-source-id: 6d8e2a462743d0f3af829713f43b6059af6a9548
2017-12-06 06:15:14 -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
Steven Luscher 31eb3a6529 Capitalized ‘Express’
Summary:
It's a brand name.
Closes https://github.com/facebook/metro/pull/103

Reviewed By: cpojer

Differential Revision: D6484138

Pulled By: steveluscher

fbshipit-source-id: 98d0aa9a2a7da1068b12a918b83c9a83bc19f4ae
2017-12-05 11:29:42 -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
Steven Luscher 989d209e5d Corrected grammar in ‘getting started‘
Summary:
Active voice, etc.
Closes https://github.com/facebook/metro/pull/102

Reviewed By: cpojer

Differential Revision: D6484141

Pulled By: steveluscher

fbshipit-source-id: c54c6c719497ee9612b816e9a3de4ca5fea8f4a5
2017-12-05 01:43:35 -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
Eli White 42b7e6fcdf Remove $FixMe flow suppression
Reviewed By: sahrens, kassens

Differential Revision: D6426829

fbshipit-source-id: b10e33117cf4adf6bb39fc95a9ffa1e268e7c835
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
Christoph Nakazawa 575142d0c2 Add script to automatically deploy the website
Reviewed By: rafeca

Differential Revision: D6435717

fbshipit-source-id: dbbf4fed745ac460becc03ca2c4f4ae3a0249314
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