Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with TypeScript declaration files #205

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions libs/lib-1/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@nrwl/web/babel",
{
"useBuiltIns": "usage"
}
]
]
}
18 changes: 18 additions & 0 deletions libs/lib-1/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions libs/lib-1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# lib-1

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build lib-1` to build the library.

## Running unit tests

Run `nx test lib-1` to execute the unit tests via [Jest](https://jestjs.io).
15 changes: 15 additions & 0 deletions libs/lib-1/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable */
export default {
displayName: 'lib-1',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/libs/lib-1',
};
5 changes: 5 additions & 0 deletions libs/lib-1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@nx-example/lib-1",
"version": "0.0.1",
"type": "commonjs"
}
33 changes: 33 additions & 0 deletions libs/lib-1/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/lib-1/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/lib-1",
"main": "libs/lib-1/src/index.ts",
"tsConfig": "libs/lib-1/tsconfig.lib.json",
"assets": ["libs/lib-1/*.md"]
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/lib-1/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/libs/lib-1"],
"options": {
"jestConfig": "libs/lib-1/jest.config.ts",
"passWithNoTests": true
}
}
},
"tags": []
}
1 change: 1 addition & 0 deletions libs/lib-1/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/lib-1';
7 changes: 7 additions & 0 deletions libs/lib-1/src/lib/lib-1.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { lib1 } from './lib-1';

describe('lib1', () => {
it('should work', () => {
expect(lib1()).toEqual('lib-1');
});
});
3 changes: 3 additions & 0 deletions libs/lib-1/src/lib/lib-1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type TestFunction = (arg: string) => string;

export const testValue = '2';
22 changes: 22 additions & 0 deletions libs/lib-1/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions libs/lib-1/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": []
},
"include": ["**/*.ts"],
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"]
}
9 changes: 9 additions & 0 deletions libs/lib-1/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
}
10 changes: 10 additions & 0 deletions libs/lib-2/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@nrwl/web/babel",
{
"useBuiltIns": "usage"
}
]
]
}
18 changes: 18 additions & 0 deletions libs/lib-2/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions libs/lib-2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# lib-2

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build lib-2` to build the library.

## Running unit tests

Run `nx test lib-2` to execute the unit tests via [Jest](https://jestjs.io).
15 changes: 15 additions & 0 deletions libs/lib-2/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable */
export default {
displayName: 'lib-2',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/libs/lib-2',
};
5 changes: 5 additions & 0 deletions libs/lib-2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@nx-example/lib-2",
"version": "0.0.1",
"type": "commonjs"
}
33 changes: 33 additions & 0 deletions libs/lib-2/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/lib-2/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/lib-2",
"main": "libs/lib-2/src/index.ts",
"tsConfig": "libs/lib-2/tsconfig.lib.json",
"assets": ["libs/lib-2/*.md"]
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/lib-2/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/libs/lib-2"],
"options": {
"jestConfig": "libs/lib-2/jest.config.ts",
"passWithNoTests": true
}
}
},
"tags": []
}
2 changes: 2 additions & 0 deletions libs/lib-2/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './lib/lib-2';
export * from './lib/test';
7 changes: 7 additions & 0 deletions libs/lib-2/src/lib/lib-2.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { lib2 } from './lib-2';

describe('lib2', () => {
it('should work', () => {
expect(lib2()).toEqual('lib-2');
});
});
3 changes: 3 additions & 0 deletions libs/lib-2/src/lib/lib-2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { TestFunction } from '@nx-example/lib-1';

export const testFunction: TestFunction = (arg: string) => arg;
6 changes: 6 additions & 0 deletions libs/lib-2/src/lib/test-2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { testValue } from '@nx-example/lib-1';
import { testFunction } from './lib-2';

export const test = testFunction;

console.log(testValue);
3 changes: 3 additions & 0 deletions libs/lib-2/src/lib/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { testFunction } from './lib-2';

export const test = testFunction;
22 changes: 22 additions & 0 deletions libs/lib-2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions libs/lib-2/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": []
},
"include": ["**/*.ts"],
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"]
}
9 changes: 9 additions & 0 deletions libs/lib-2/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@nrwl/devkit": "14.2.0-rc.1",
"@nrwl/eslint-plugin-nx": "14.2.0-rc.1",
"@nrwl/jest": "14.2.0-rc.1",
"@nrwl/js": "14.2.0-rc.1",
"@nrwl/linter": "14.2.0-rc.1",
"@nrwl/nx-cloud": "14.0.5",
"@nrwl/react": "14.2.0-rc.1",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"baseUrl": ".",
"paths": {
"@nx-example/cart/cart-page": ["libs/cart/cart-page/src/index.ts"],
"@nx-example/lib-1": ["libs/lib-1/src/index.ts"],
"@nx-example/lib-2": ["libs/lib-2/src/index.ts"],
"@nx-example/products/home-page": [
"libs/products/home-page/src/index.ts"
],
Expand Down
2 changes: 2 additions & 0 deletions workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"cart": "apps/cart",
"cart-cart-page": "libs/cart/cart-page",
"cart-e2e": "apps/cart-e2e",
"lib-1": "libs/lib-1",
"lib-2": "libs/lib-2",
"products": "apps/products",
"products-e2e": "apps/products-e2e",
"products-home-page": "libs/products/home-page",
Expand Down