Giter Site home page Giter Site logo

whackage's Introduction

whackage

npm version Maintenance Status

Multi-repo development tooling for React Native


What is this?

whackage provides a hot-reload-friendly workflow for developing across multiple React Native packages

React Native packager, the development server that bundles your app's JavaScript sources, has a few rough edges when it comes to developing apps and libraries that span across multiple repositories. It doesn't handle symlinks reliably, and the Haste module system gets easily confused by @providesModule declarations in subdependencies.

Whackage is an npm link replacement that works with React Native. It synchronizes changes in your local workspace to your project's node_modules without using symlinks, and automatically generates a packager blacklist for linked modules to avoid Haste naming collisions.

We wrote whackage to scratch our own itch when working on Victory Native. It's a blunt instrument, but it works well. Hope you find it useful!

How-to

Quick start

# install whackage globally
npm i -g whackage

# rest of the steps happen in your project root directory
cd ~/your-project-directory

# create new whackage.json
whack init

# create a link to a package you want to make changes to
whack link ../path/to/other/package

# start react native packager and the whackage server (equivalent to npm start)
whack run start

More detailed instructions of each step below:

Prerequisites

  • node >=4
  • npm >=3
  • OSX/Linux. Windows currently not supported, but PRs welcome.
  • rsync (most likely pre-installed on your system)

Install

Install whackage globally:

npm i -g whackage

Initialize whackage in your project

You'll now have access to the whack command on your command line. To get started, generate an empty whackage.json in your project's root directory:

whack init

Link modules

You can then link local copies of React Native libraries to your project with whack link <path>, e.g.:

whack link ../victory-core-native
whack link ../victory-chart-native

You'll now have a whackage.json file that looks as follows:

{
  "include": "/**/*.js",
  "exclude": ["/node_modules/*", ".babelrc", ".git"],
  "dependencies": {
    "victory-chart-native": "../victory-chart-native",
    "victory-core-native": "../victory-core-native"
  }
}

The dependencies map specifies which modules to synchronize, and paths to directories where to look for the sources.

By default whackage watches changes to .js files, and ignores your sources' node_modules and git metadata. We also skip copying Babel configurations, because the React Native packager does not support per-module configurations, and project-specific presets often causes the Babel transpilation step to fail.

You can configure the include and exclude glob patterns as needed.

Start packager

Start the packager server with whack run <command>, where command is the npm script you normally use to start your development server.

If you usually start the server with npm start, the corresponding whackage command is:

whack run start

(Alternatively, if your start task is npm run server:dev, you'd use whack run server:dev!)

When started, the whackage server will overwrite the specified dependencies in your node_modules with the sources you linked with whack link, and start a file watcher that synchronizes changes made in the source directories into your node_modules as they happen.

It will also specify a CLI config which adds the node_modules within linked source directories to the Haste blacklist to avoid @providesModules naming collisions.

Update transitive dependencies

When you whack link a package, whackage automatically installs and flattens transitive dependencies into your project. If you change the dependencies of your linked packages, you'll need to run whack install to add them to your project:

whack install victory-chart-native

Or sync all transitive dependencies or all linked packages:

whack install

Stop whacking

When you're done making changes to your local packages, you can remove the whackage.json entry and reset the module to its original state:

whack unlink victory-chart-native

To reset your your original dependencies, but keep the whackage.json around for the next time you want to work with that package, simply nuke your node_modules:

rm -rf node_modules && npm i

API

Run whack --help for a list of all available commands and options.

Misc

Why the name?

It's wacky, it's hacky, and it rhymes with package. Also it whacks your node_modules.

Contributing

Found an issue or a missing feature? Congratulations! ๐ŸŽ‰ That is the prize you win as an early adopter! GitHub issues and pull requests are more than welcome.

Please note

This project is in a pre-release state. The API may be considered relatively stable, but changes may still occur.

MIT licensed

Maintenance Status

Archived: This project is no longer maintained by Formidable. We are no longer responding to issues or pull requests unless they relate to security concerns. We encourage interested developers to fork this project and make it their own!

whackage's People

Contributors

admmasters avatar boygirl avatar jevakallio avatar jpdriver avatar kant avatar poison avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

whackage's Issues

Pre-launch todo-list

Things to do before launch:

  • Blacklist .babelrc
  • Check that linked packages are also installed to the host project
  • Check that none of the linked packages are symlinks
  • Verify rsync availability across linux distros (or remove rsync)
  • Synchronise changes to npm dependencies (or document how to work-around)
  • whack reset to restore whacked deps
  • API documentation and better CLI messages
  • Preserve packager stdout colors and add some flair to whackage console output

Module import resolution is "out of sync"

I'm not sure if this is me just not understanding how module import resolution works with whackage involved, or if there's a way to work around this, but here's the gist of what I'm seeing. I have a package that I'm developing that is intended to be used to share code across multiple similar apps. That said we have many graphql queries that will share fragments, and to avoid duplication I want to put them in the shared library.

Pseudo fragment:

// shared-fragments.js
import gql from 'graphql-tag';

export const sharedUserFields = gql`
  fragment UserFields on User {
    id
    name
    email
  }
`;

// module index.js
export { sharedUserFields } from './shared-fragments';

Pseudo import in an app consuming this:

import { sharedUserFields } from 'my-shared-module';

export const query = gql`
  query UserQuery {
    user {
      ...UserFields
    }
  }
  ${sharedUserFields}
`;

This code works fine if the shared fragment is colocated in the consuming app itself, but what I'm seeing is that the sharedUserFields export is undefined at the time this code is executed, but if I import it later in the app (say at render time) it's exactly what I expect it to be. Unfortunately, any use of the graphql tag is also running at compile time and getting the same results.

Has anyone run into this issue? I'm guessing that once I publish this package and use it directly from node modules, this won't be an issue, but it causes a lot of pain in development when trying to develop the module and the app simultaneously using whack run start.

hot reloading not working

Hi, I think I'm seeing the exact same issue as #6

It seems that the whack server isn't watching my local dependancies while the server is running. I do get my updated files if I kill and restart the server. Is this expected?

Would be totally sick if I didn't have to restart the server, though even the current behavior is still a significant step up from before :)

Node: 8.4
npm: 5.5.1
rsync: 2.6.9
whackage: 1.2.0
RN: 0.49.5
Mac OS X Sierra

Thanks!

`whack link` blows away `node_modules/.bin`

On a clean install (create-react-native-app and then yarn run eject) the whack link command removes a slew of executables found in node_modules/.bin, including react-native so the whack run start command does not work.

Did I do something wrong?

npm: 5.5.1

Error: rsync exited with code 12

Hey guys,

I'm getting the following error:

$ whack run packager
error { Error: rsync exited with code 12
    at ChildProcess.<anonymous> (/usr/local/lib/node_modules/whackage/node_modules/rsyncwrapper/lib/rsyncwrapper.js:184:23)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:192:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12) code: 12 }

Usage: npm <command>

where <command> is one of:
    access, adduser, bin, bugs, c, cache, completion, config,
    ddp, dedupe, deprecate, dist-tag, docs, doctor, edit,
    explore, get, help, help-search, i, init, install,
    install-test, it, link, list, ln, login, logout, ls,
    outdated, owner, pack, ping, prefix, prune, publish, rb,
    rebuild, repo, restart, root, run, run-script, s, se,
    search, set, shrinkwrap, star, stars, start, stop, t, team,
    test, tst, un, uninstall, unpublish, unstar, up, update, v,
    version, view, whoami

npm <cmd> -h     quick help on <cmd>
npm -l           display full usage info
npm help <term>  search for help on <term>
npm help npm     involved overview

Any ideas how to resolve it? Thanks!

Doesn't work with react-native >=0.52

The output is:

$ whack run start
[whackage] init /Users/.../client-blocks -> node_modules/client-blocks

> react-native start "--config" "/usr/local/lib/node_modules/whackage/src/packager/rn-cli.config.js"

Scanning folders for symlinks in /Users/.../app/node_modules (19ms)

Cannot find module '/Users/.../app/node_modules/react-native/packager/blacklist'

It looks like they renamed metro-bundler to metro facebook/react-native@654fed4

bundling failed

This occurs on react-native run-ios & react-native run-android after running whack run start ("start": "node node_modules/react-native/local-cli/cli.js start")

Output:

Looking for JS files in
   /usr/local/lib/node_modules/whackage/src/packager

Loading dependency graph, done.
::ffff:127.0.0.1 - - [14/Nov/2018:15:38:06 +0000] "GET /onchange HTTP/1.1" - - "-" "
okhttp/3.11.0"
 BUNDLE  [ios, dev] ../../../../usr/local/lib/node_modules/whackage/src/packager/ind
ex.js โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ 0.0% (0/1)::1 - - [14/Nov/2018:15:38:11 +0000] "GET /index.bu
ndle?platform=ios&dev=true&minify=false HTTP/1.1" 200 - "-" "foo/1 CFNetw
error: bundling failed: Error: The resource `/usr/local/lib/node_modules/whackage/sr
c/packager/index.js` was not found.
    at /foo/node_modules/metro/src/IncrementalBundler.js
:122:24
    at gotStat (fs.js:1775:21)
    at /foo/node_modules/graceful-fs/polyfills.js:282:31
    at FSReqWrap.oncomplete (fs.js:152:21)
 BUNDLE  [ios, dev] ../../../../usr/local/lib/node_modules/whackage/src/packager/ind
ex.js โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ 0.0% (0/1), failed.

Output on Emulator:

Failed to load bundle(http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false) with error:(The resource `/usr/local/lib/node_modules/whackage/src/packager/index.js` was not found. (null))

__38-[RCTCxxBridge loadSource:onProgress:]_block_invoke.248
    RCTCxxBridge.mm:429
___ZL36attemptAsynchronousLoadOfBundleAtURLP5NSURLU13block_pointerFvP18RCTLoadingProgressEU13block_pointerFvP7NSErrorP9RCTSourceE_block_invoke.118
__80-[RCTMultipartDataTask URLSession:streamTask:didBecomeInputStream:outputStream:]_block_invoke
-[RCTMultipartStreamReader emitChunk:headers:callback:done:]
-[RCTMultipartStreamReader readAllPartsWithCompletionCallback:progressCallback:]
-[RCTMultipartDataTask URLSession:streamTask:didBecomeInputStream:outputStream:]
__88-[NSURLSession delegate_streamTask:didBecomeInputStream:outputStream:completionHandler:]_block_invoke
__NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__
-[NSBlockOperation main]
-[__NSOperationInternal _start:]
__NSOQSchedule_f
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_continuation_pop
_dispatch_async_redirect_invoke
_dispatch_root_queue_drain
_dispatch_worker_thread2
_pthread_wqthread
start_wqthread

Why this is deprecated?

Hello guys,
This is just a question, are you using other tool to manage multiple repositories like meta or bit?

Logo Proposal for Whackage

Hi, I'm a graphic designer and I like to collaborate with open source projects. Would you like me to design a Logo for whackage?
It would be nice to see your README with a good logo.

Overrides local rn-cli.config.js

When using whack run start local configuration in my rn-cli.config.js is not applied. It looks like the --config argument is passed to the packager, which causes it to use only that config file. It would be nice if the two configs were merged somehow.

[whackage] Package my-library is not a registered dependency in my-app

Hello! I'm trying repeat it:
https://formidable.com/blog/2016/12/01/introducing-whackage/

$ whack link ../../my-library
here is error:
[whackage] Package my-library is not a registered dependency in my-app

After added in dependency I have new error:

`events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: spawn npm ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:229:19)
    at onErrorNT (internal/child_process.js:406:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:235:12)
    at onErrorNT (internal/child_process.js:406:16)
    [... lines matching original stack trace ...]
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)`

node - v10.7.0
npm - 6.1.0

whack link appears to symlink

It appears that whackage creates a symlink just like npm link does.

> whack init
> whack link ../my-react-native-library
[whackage] Package my-react-native-library is not a registered dependency in my-app

I add "my-react-native-library": "0.0.1" to packages.json dependencies and try again

> whack link ../my-react-native-library

This works now, and packages.json dependency is now: "my-react-native-library": "file:../my-react-native-library"

> whack run start
[whackage] Package my-react-native-library appears to be symlinked. Overwriting symlinks is not currently supported. Unlink package and try again.
node v8.1.3
npm 5.1.0

Help needed

I followed the instructions, however I can't get it to work properly.
whackage detects the file changes, but still I need to kill the whack/npm server each time I make a change, otherwise it won't reload the changes.

Cannot find module - crash when trying to run whackage

> node node_modules/react-native/local-cli/cli.js start "--config" "/Users/kennethlynne/Documents/GitHub/differ-mobile/node_modules/whackage/src/packager/rn-cli.config.js"

module.js:472
    throw err;
    ^

Error: Cannot find module '/Users/kennethlynne/Documents/GitHub/differ-mobile/node_modules/react-native/packager/blacklist'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/kennethlynne/Documents/GitHub/differ-mobile/node_modules/whackage/src/packager/rn-cli.config.js:2:19)
    at Module._compile (module.js:571:32)
    at Module._extensions..js (module.js:580:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/kennethlynne/Documents/GitHub/differ-mobile/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)

Using react-native 0.48.4

whack commands not working

I am getting the same error on every whack command I run; on npm v4.0.3 and nvm v4.3.2

Tims-MacBook-Air:apps TimMobileBytes$ whack --help
/Users/TimMobileBytes/.nvm/versions/node/v4.3.2/lib/node_modules/whackage/src/commands/init.js:32
module.exports = function init({ force }) {
                               ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/Users/TimMobileBytes/.nvm/versions/node/v4.3.2/lib/node_modules/whackage/index.js:8:5)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.