LGTM, but we still need to establish the conventions that people will expect

Is an npm module equivalent to an angular module?

If so, `require('angular-animate').directive("myDirective", ...);` should 
register a new directive in the ngAnimate module. But, in this scenario, 
`require('angular')` doesn't give you what you'd expect, which would be the 
`angular` global object.

There is also the case where one angular module exports multiple modules, 
like ngMock.

One way to go would be `require('angular-mocks/e2e')` or 
`require('angular-mocks/animate')` for the e2e and animation mock modules, 
and `require('angular-mocks')` for the main unit test mocks.

Or alternatively, exporting an object containing properties which are the 
modules to be mocked.

I would love to hear feedback from people using angular + browserify to 
figure out the conventions that would be most useful there.

On Tuesday, 13 January 2015 21:51:20 UTC-5, Ben Clinkinbeard wrote:
>
> Summary
>
> Change the publish script to support idiomatic CommonJS usage when 
> installed from npm.
>
> Motivation
>
> Now that the Angular modules are available on npm, supporting proper 
> CommonJS use via require() is the next logical step. This use case is 
> widely expected by developers using npm for dependency management.
>
>
> Without this change, developers still have to use a script tag to include 
> Angular modules from within the node_modules folder. This is extremely 
> uncommon with npm packages, and does nothing to enable Browserify and 
> webpack support.
>
> Compatibility Risk
>
> Little to no risk as only the publish shell script needs to be changed.
>
> Ongoing Technical Constraints
>
> There should be virtually no ongoing maintenance needed since it's just a 
> publish script.
>
> Plans for Implementation
>
> Simple changes to the publish script will be made to remove the main field 
> from the package.json files and generate an index.js file for each package 
> so that it is used when requiring by name. The index.js file will require() 
> the standard built file and export a value(s) appropriate for the module.
>
>
> The core angular module will export the angular object.
>
>
> The supporting modules will export their module name (ngAnimate, ngRoute, 
> etc.) with the exception of angular-mocks, which exports 3 values: ngMock, 
> ngMockE2E, ngAnimateMock
>
>
> This would enable code akin to the following:
>
>
> var angular = require('angular');
>
> angular.module('app', [
>
> require('angular-animate'),
>
> require('angular-route'),
>
> require('angular-mocks').ngMock
>
> ]);
>
> Prior Art
> The overwhelming expectation, when a developer installs a package from 
> npm, is that they can then use require('package-name') to load it. This 
> change will bring Angular in line with the rest of the npm ecosystem.
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to