Catalog npm
Back to packageRELEASE DETAILS

0.0.3

npm

22ndtech-common-lib

22ndtech Angular Library

Published20 Aug 2017
Direct dependencies32
Transitive dependenciesNot calculated

README

Current package documentation

Warning

This quickstart is under active development and hasn't yet reached its final form.

It may not be fully compatible with current versions of Angular.

22ndtech Common Lib

Build Status

This is a simple library defining the common functions and data structures for 22ndtech development efforts, implementing the Angular Package Format v4.0.

Features:

  • a simple example library
  • unit tests for the library
  • a demo application that consumes the library in JIT mode and runs in watch mode
  • an integration app that consumes the library in JIT and AOT mode and runs e2e tests

Common tasks are present as npm scripts:

  • npm start to run a live-reload server with the demo app
  • npm run test to test in watch mode, or npm run test:once to only run once
  • npm run build to build the library
  • npm run lint to lint
  • npm run clean to clean
  • npm run integration to run the integration e2e tests
  • npm install ./relative/path/to/lib after npm run build to test locally in another app

If you need to debug the integration app, please check ./integration/README.md.

The 22ndtech Common Library

This library implements

Warning: Do this only in the beginning to avoid accidentally deleting your own git setup!

What's in the 22ndtech Common Lib?

src/ ├── demo/ | └── app/ | ├── app.component.ts | └── app.module.ts └── lib/ ├── index.ts └── src/ ├── component/ | └── lib.component.ts ├── service/ | └── lib.service.ts └── module.ts


Each file has a distinct purpose and evolves independently as the application grows.

Files outside `src/` concern building, deploying, and testing your app.
They include configuration files and external dependencies.

Files inside `src/lib/` "belong" to your library, while `src/demo/` contains a demo application
that loads your library.

Libraries do not run by themselves, so it's very useful to have this "demo" app while developing 
to see how your library would look like to consumers.

When you run `npm start`, the demo application is served.

The following are all in `src/`

<table width="100%">
  <col width="20%">
  </col>
  <col width="80%">
  </col>
  <tr>
    <th>
      File
    </th>
    <th>
      Purpose
    </th>
  </tr>
  <tr>
    <td>
      <code>demo/app/app.component.ts</code>
    </td>
    <td>
      A demo component that renders the library component and a value from the library service.
    </td>
  </tr>
  <tr>
    <td>
      <code>demo/app/app.module.ts</code>
    </td>
    <td>
      A demo <code>NgModule</code> that imports the Library <code>LibModule</code>.
    </td>
  </tr>
  <tr>
    <td>
      <code>lib/src/component/app.component.ts</code>
    </td>
    <td>
      A sample library component that renders an <code>h2</code> tag.
    </td>
  </tr>
  <tr>
    <td>
      <code>lib/src/service/lib.service.ts</code>
    </td>
    <td>
      A sample library service that exports a value.
    </td>
  </tr>
  <tr>
    <td>
      <code>lib/src/module.ts</code>
    </td>
    <td>
      The library's main <code>NgModule</code>, <code>LibModule</code>.
    </td>
  </tr>
  <tr>
    <td>
      <code>lib/index.ts</code>
    </td>
    <td>
      The public API of your library, where you choose what to export to consumers.
    </td>
  </tr>
</table>


## The build step

You can build the library by running `npm run build`. 
This will generate a `dist/` directory with all the entry points described above.

All the logic for creating the build can be found in `./build.js`. It consists of roughly 5 steps:

- Compile with the AOT Compiler (AOT compiler or `ngc`) for ES5 and ES2015.
- Inline html and css inside the generated JavaScript files.
- Copy typings, metatada, html and css.
- Create each bundle using Rollup.
- Copy `LICENSE`, `package.json` and `README.md` files


## Testing libraries

While testing is always important, it's **especially** important in libraries because consumer
applications might break due to bugs in libraries.

But the fact that a library is consumed by another application is also what makes it hard to test.

To properly test a library, you need to have an integration tests.
An integration test is to libraries what an end-to-end test is to applications.
It tests how an app would install and use your library.

The **22ndtech Common lib** includes a directory called `integration` containing a standalone
app that consumes your built library in both AOT and JIT modes, with end-to-end tests to verify
it works.

To run the integration tests, do `npm run integration` which does the following:
- Build your library.
- Enter the integration app's directory.
- Install dependencies.
- Build the app in AOT mode.
- Test the app in AOT mode.
- Test the app in JIT mode.

Running integration tests gives you greater confidence that your library is properly built.

In addition to integration tests, you can also run unit tests in watch mode via `npm run test`,
or single-run via `npm run test:once`.

You can also test the library by installing it in another local repository you have. 
To do so, first build your lib via `npm run build`.
Then install it from your other repo using a relative path to the dist folder: 
`npm install relative/path/to/library/dist`.


## Appendix: Supporting AOT

AOT plays an important role in optimizing Angular applications. 
It's therefore important that third party libraries be published in a format compatible with AOT
compilation.
Otherwise it will not be possible to include the library in an AOT compiled application.

Only code written in TypeScript can be AOT compiled.
 
Before publishing the library must first be compiled using the AOT compiler (`ngc`). 
`ngc` extends the `tsc` compiler by adding extensions to support AOT compilation in addition to
regular TypeScript compilation.   

AOT compilation outputs three files that must be included in order to be compatible with AOT.

*Transpiled JavaScript*

As usual the original TypeScript is transpiled to regular JavaScript.

*Typings files*

JavaScript has no way of representing typings. 
In order to preserve the original typings, `ngc` will generate `.d.ts` typings files.

*Meta Data JSON files*

`ngc` outputs a metadata.json file for every `Component` and `NgModule`.
These meta data files represent the information in the original `NgModule` and `Component`
decorators.   

The meta data may reference external templates or css files.
These external files must be included with the library.

### NgFactories

`ngc` generates a series of files with an `.ngfactory` suffix as well.
These files represent the AOT compiled source, but should not be included with the published library.

Instead the `ngc` compiler in the consuming application will generate `.ngfactory` files based
on the JavaScript, Typings and meta data shipped with the library. 

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 32

Native requirements
32 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@angular/cli
Environment
{
  "local_name": "@angular/cli",
  "alias": false,
  "peer_metadata": null
}
^1.2.0development
@angular/common
Environment
{
  "local_name": "@angular/common",
  "alias": false,
  "peer_metadata": null
}
~4.1.3development
@angular/compiler
Environment
{
  "local_name": "@angular/compiler",
  "alias": false,
  "peer_metadata": null
}
~4.1.3development
@angular/compiler-cli
Environment
{
  "local_name": "@angular/compiler-cli",
  "alias": false,
  "peer_metadata": null
}
~4.1.3development
@angular/core
Environment
{
  "local_name": "@angular/core",
  "alias": false,
  "peer_metadata": null
}
~4.1.3development
@angular/platform-browser
Environment
{
  "local_name": "@angular/platform-browser",
  "alias": false,
  "peer_metadata": null
}
~4.1.3development
@angular/platform-browser-dynamic
Environment
{
  "local_name": "@angular/platform-browser-dynamic",
  "alias": false,
  "peer_metadata": null
}
~4.1.3development
@angular/router
Environment
{
  "local_name": "@angular/router",
  "alias": false,
  "peer_metadata": null
}
~4.1.3development
@types/jasmine
Environment
{
  "local_name": "@types/jasmine",
  "alias": false,
  "peer_metadata": null
}
2.5.36development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^6.0.46development
camelcase
Environment
{
  "local_name": "camelcase",
  "alias": false,
  "peer_metadata": null
}
^4.0.0development
concurrently
Environment
{
  "local_name": "concurrently",
  "alias": false,
  "peer_metadata": null
}
3.4.0development
core-js
Environment
{
  "local_name": "core-js",
  "alias": false,
  "peer_metadata": null
}
^2.4.1development
glob
Environment
{
  "local_name": "glob",
  "alias": false,
  "peer_metadata": null
}
^7.1.1development
jasmine-core
Environment
{
  "local_name": "jasmine-core",
  "alias": false,
  "peer_metadata": null
}
^2.5.2development
karma
Environment
{
  "local_name": "karma",
  "alias": false,
  "peer_metadata": null
}
^1.5.0development
karma-chrome-launcher
Environment
{
  "local_name": "karma-chrome-launcher",
  "alias": false,
  "peer_metadata": null
}
^2.0.0development
karma-cli
Environment
{
  "local_name": "karma-cli",
  "alias": false,
  "peer_metadata": null
}
^1.0.1development
karma-html-reporter
Environment
{
  "local_name": "karma-html-reporter",
  "alias": false,
  "peer_metadata": null
}
^0.2.7development
karma-jasmine
Environment
{
  "local_name": "karma-jasmine",
  "alias": false,
  "peer_metadata": null
}
^1.1.0development
karma-jasmine-html-reporter
Environment
{
  "local_name": "karma-jasmine-html-reporter",
  "alias": false,
  "peer_metadata": null
}
^0.2.2development
lite-server
Environment
{
  "local_name": "lite-server",
  "alias": false,
  "peer_metadata": null
}
^2.2.2development
rimraf
Environment
{
  "local_name": "rimraf",
  "alias": false,
  "peer_metadata": null
}
^2.6.1development
rollup
Environment
{
  "local_name": "rollup",
  "alias": false,
  "peer_metadata": null
}
^0.42.0development
rollup-plugin-sourcemaps
Environment
{
  "local_name": "rollup-plugin-sourcemaps",
  "alias": false,
  "peer_metadata": null
}
^0.4.1development
rollup-plugin-uglify
Environment
{
  "local_name": "rollup-plugin-uglify",
  "alias": false,
  "peer_metadata": null
}
^2.0.1development
rxjs
Environment
{
  "local_name": "rxjs",
  "alias": false,
  "peer_metadata": null
}
^5.0.1development
standard-version
Environment
{
  "local_name": "standard-version",
  "alias": false,
  "peer_metadata": null
}
^4.0.0development
systemjs
Environment
{
  "local_name": "systemjs",
  "alias": false,
  "peer_metadata": null
}
^0.19.40development
tslint
Environment
{
  "local_name": "tslint",
  "alias": false,
  "peer_metadata": null
}
^4.4.2development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^2.2.1development
zone.js
Environment
{
  "local_name": "zone.js",
  "alias": false,
  "peer_metadata": null
}
^0.8.4development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "4bc10a40dbf0993aa60489eef73e225c090ab3a2",
  "tarball": "https://registry.npmjs.org/22ndtech-common-lib/-/22ndtech-common-lib-0.0.3.tgz",
  "integrity": "sha512-F5x0280hfc1m540WlZ+MaNdncTIshVnFpA2oM1k//ggiWNZKOK72S9Pw6Az95RfDWWr8ePAad/zqTcyo7qb9eg==",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIB3TKJ52sJAbOYuIm33GZL5b4UVsVTmH3k9Qca9pIRSxAiEAiNK4yzynkxixtt5Y03tjS3n39cubI9XX30ChdwMDPE8="
    }
  ]
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:00 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:8bf2fa67a574db946c92e4df486c06de078387ddfec0ff085fed3beab07fa273

Other collected versions

0.0.179 Dec0.0.169 Dec0.0.157 Dec0.0.147 Dec0.0.1328 Nov0.0.1228 NovView all collected versions →