Skip to content

Commit

Permalink
build: use ng-packagr
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Dec 26, 2020
1 parent 8edb8f1 commit c4451a7
Show file tree
Hide file tree
Showing 22 changed files with 95 additions and 110 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
npm install ngrx-immer
```

> Do not forget to install immer
## Resources

- [Immer docs](https://immerjs.github.io/immer/docs/introduction)
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
preset: 'ts-jest',
rootDir: 'src',
};
50 changes: 7 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,26 @@
{
"name": "ngrx-immer",
"version": "0.0.2",
"description": "Immer wrappers around NgRx methods createReducer, on, and ComponentStore",
"keywords": [
"NgRx",
"Redux",
"Angular",
"Immer"
],
"author": "Tim Deschryver",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/timdeschryver/ngrx-immer.git"
},
"bugs": {
"url": "https://github.com/timdeschryver/ngrx-immer/issues"
},
"homepage": "https://github.com/timdeschryver/ngrx-immer#readme",
"private": false,
"sideEffects": false,
"main": "cjs/shared.js",
"module": "esm/shared.js",
"types": "esm/shared.d.ts",
"publishConfig": {
"access": "public"
},
"version": "0.0.0",
"scripts": {
"test": "jest",
"prebuild": "rimraf dist && rimraf *.tgz",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc -p tsconfig-build-cjs.json",
"build:esm": "tsc -p tsconfig-build-esm.json",
"postbuild": "cpy **/package.json ../dist --cwd=./src --parents && cpy package.json dist && cpy README.md dist"
},
"peerDependencies": {
"immer": ">=7.0.0"
},
"peerDependenciesMeta": {
"@ngrx/component-store": {
"optional": true
},
"@ngrx/store": {
"optional": true
}
"build": "ng-packagr -p src/ng-package.json",
"postbuild": "cpy README.md dist"
},
"devDependencies": {
"@angular/compiler": "^11.0.5",
"@angular/compiler-cli": "^11.0.5",
"@angular/core": "^11.0.2",
"@ngrx/component-store": "^10.1.0",
"@ngrx/store": "^10.1.1",
"@types/jest": "^26.0.15",
"cpy-cli": "^3.1.1",
"immer": "^8.0.0",
"jest": "^26.6.3",
"ng-packagr": "^11.0.3",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"rxjs": "^6.6.3",
"ts-jest": "^26.4.4",
"typescript": "^4.1.2"
"typescript": "^4.0.5"
}
}
2 changes: 1 addition & 1 deletion src/component-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { Observable, Subscription } from 'rxjs';
import { ComponentStore } from '@ngrx/component-store';

import { immerReducer } from '../shared';
import { immerReducer } from 'ngrx-immer/shared';

/**
* Immer wrapper around `ImmerComponentStore` to mutate state
Expand Down
8 changes: 5 additions & 3 deletions src/component-store/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"main": "../cjs/component-store/index.js",
"module": "../esm/component-store/index.js",
"types": "../esm/component-store/index.d.ts"
"ngPackage": {
"lib": {
"entryFile": "index.ts"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { skip, take } from 'rxjs/operators';
import { ImmerComponentStore } from '..';
import { ImmerComponentStore } from 'ngrx-immer/component-store';

const initialState: { shows: string[] } = {
shows: [],
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './shared';
7 changes: 7 additions & 0 deletions src/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../dist",
"lib": {
"entryFile": "index.ts"
}
}
37 changes: 37 additions & 0 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "ngrx-immer",
"version": "0.0.4",
"description": "Immer wrappers around NgRx methods createReducer, on, and ComponentStore",
"keywords": [
"NgRx",
"Redux",
"Angular",
"Immer",
"Local State",
"Component State",
"State management"
],
"author": "Tim Deschryver",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/timdeschryver/ngrx-immer.git"
},
"bugs": {
"url": "https://github.com/timdeschryver/ngrx-immer/issues"
},
"homepage": "https://github.com/timdeschryver/ngrx-immer#readme",
"private": false,
"sideEffects": false,
"peerDependencies": {
"immer": ">=7.0.0"
},
"peerDependenciesMeta": {
"@ngrx/component-store": {
"optional": true
},
"@ngrx/store": {
"optional": true
}
}
}
File renamed without changes.
7 changes: 7 additions & 0 deletions src/shared/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ngPackage": {
"lib": {
"entryFile": "index.ts"
}
}
}
2 changes: 1 addition & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@ngrx/store';
import { Draft } from 'immer';

import { immerReducer } from '../shared';
import { immerReducer } from 'ngrx-immer/shared';

/**
* An immer reducer that allows a void return
Expand Down
8 changes: 5 additions & 3 deletions src/store/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"main": "../cjs/store/index.js",
"module": "../esm/store/index.js",
"types": "../esm/store/index.d.ts"
"ngPackage": {
"lib": {
"entryFile": "index.ts"
}
}
}
10 changes: 5 additions & 5 deletions src/store/tests/create-immer-reducer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAction, on, props } from '@ngrx/store';
import { createImmerReducer, immerOn } from '..';
import { createImmerReducer, immerOn } from 'ngrx-immer/store';

const addItem = createAction('add item', props<{ item: string }>());
const deleteItem = createAction('delete item', props<{ index: number }>());
Expand All @@ -15,13 +15,13 @@ const reducer = createImmerReducer<{ items: string[]; otherItems: string[] }>(
state.items.push(item);
return state;
}),
// works with `immerOn`
immerOn(deleteItem, (state, { index }) => {
on(deleteItem, (state, { index }) => {
state.items.splice(index, 1);
return state;
}),
on(addOtherItem, (state, { item }) => {
// works with `immerOn`
immerOn(addOtherItem, (state, { item }) => {
state.otherItems.push(item);
return state;
}),
);

Expand Down
2 changes: 1 addition & 1 deletion src/store/tests/immer-on.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createReducer, createAction, props } from '@ngrx/store';
import { immerOn } from '..';
import { immerOn } from 'ngrx-immer/store';

const addItem = createAction('add item', props<{ item: string }>());
const deleteItem = createAction('delete item', props<{ index: number }>());
Expand Down
8 changes: 0 additions & 8 deletions tsconfig-build-cjs.json

This file was deleted.

8 changes: 0 additions & 8 deletions tsconfig-build-esm.json

This file was deleted.

9 changes: 0 additions & 9 deletions tsconfig-build.json

This file was deleted.

22 changes: 0 additions & 22 deletions tsconfig.base.json

This file was deleted.

14 changes: 11 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"baseUrl": ".",
"rootDir": ".",
"strict": true ,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true ,
"noUnusedParameters": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"paths": {
"ngrx-immer": ["./src"],
"ngrx-immer/shared": ["./src/shared"],
"ngrx-immer/component-store": ["./src/component-store"],
"ngrx-immer/store": ["./src/store"]
}
},
"exclude": ["node_modules"]
}
4 changes: 2 additions & 2 deletions tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.base.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": ["@types/jest"],
"types": ["@types/jest"]
},
"include": ["**/tests/*.test.ts"]
}

0 comments on commit c4451a7

Please sign in to comment.