Skip to content

Commit

Permalink
remove core module shims
Browse files Browse the repository at this point in the history
browser-resolve is only responsible for handling the browser field
resolution. Consumers of this module who wish to provide alternatives to
the core node modules should specify a `modules` option when calling
resolve. The modules object is a key/value of core modulename -> path.
  • Loading branch information
defunctzombie committed Apr 29, 2013
1 parent 1eebfe1 commit 2799bcc
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 2,394 deletions.
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@

node.js resolve algorithm with [browser](https://gist.github.com/shtylman/4339901) field support.

# example
## api

## relative
### resolve(pkg, opts={}, cb)

Resolve a module path and call `cb(err, path)`

Options:

* filename - the calling filename where the require call originated (in the source)
* paths - require.paths array to use if nothing is found on the normal node_modules recursive walk
* packageFilter - transform the parsed package.json contents before looking at the "main" field
* modules - object with module id/name -> path mappings to consult before doing manual resolution (use to provide core modules)

This comment has been minimized.

Copy link
@alexgorbatchev

alexgorbatchev May 13, 2013

@shtylman I do agree that modules should be externalized but this is currently breaking browserify if it try to update to latest browser-resolve. Did you by chance move these out into another module that I can't find?

This comment has been minimized.

Copy link
@defunctzombie

defunctzombie via email May 13, 2013

Author Collaborator

This comment has been minimized.

Copy link
@alexgorbatchev

alexgorbatchev May 14, 2013

Also true :) but we all shall move forward together teehee so I extracted builtins files that were in this module prior to this commit into https://github.com/alexgorbatchev/node-browser-builtins and I have a fork of https://github.com/alexgorbatchev/node-browserify that works with all of it together.

This comment has been minimized.

Copy link
@defunctzombie

defunctzombie May 14, 2013

Author Collaborator

I think the builtins should be directly in browserify and not in another module super module which just lists them again. Anyhow, that is not up to me to decide, I just know they do not belong in this module.


## basic usage

you can resolve files like `require.resolve()`:
``` js
Expand All @@ -19,13 +30,17 @@ $ node example/resolve.js
/home/substack/projects/node-browser-resolve/index.js
```

## core
## core modules

or if you `require()` core modules you'll get a version that works in browsers:
By default, core modules (http, dgram, etc) will return their same name as the path. If you want to have specific paths returned, specify a `modules` property in the options object.

``` js
var shims = {
http: '/your/path/to/http.js'
};

var resolve = require('browser-resolve');
resolve('fs', null, function(err, path) {
resolve('fs', { modules: shims }, function(err, path) {
console.log(path);
});
```
Expand All @@ -35,11 +50,8 @@ $ node example/builtin.js
/home/substack/projects/node-browser-resolve/builtin/fs.js
```

## custom

and you can use the
[browser field](https://gist.github.com/shtylman/4339901) to load
browser-specific versions of modules:
## browser field
browser-specific versions of modules

``` js
{
Expand Down Expand Up @@ -113,3 +125,9 @@ $ node example/skip.js
# license

MIT

# upgrade notes

Prior to v1.x this library provided shims for node core modules. These have since been removed. If you want to have alternative core modules provided, use the `modules` option when calling resolve.

This was done to allow package managers to choose which shims they want to use without browser-resolve being the central point of update.
314 changes: 0 additions & 314 deletions builtin/assert.js

This file was deleted.

2 changes: 0 additions & 2 deletions builtin/child_process.js

This file was deleted.

Empty file removed builtin/dgram.js
Empty file.
Loading

0 comments on commit 2799bcc

Please sign in to comment.