From 3a05712e540089a7b0759785fbaaa0632e07a26b Mon Sep 17 00:00:00 2001 From: Jason Gerbes Date: Thu, 16 Jun 2022 15:22:56 +1200 Subject: [PATCH 1/3] Create JS lib-1 and lib-2 --- libs/lib-1/.babelrc | 10 ++++++++++ libs/lib-1/.eslintrc.json | 18 +++++++++++++++++ libs/lib-1/README.md | 11 +++++++++++ libs/lib-1/jest.config.ts | 15 +++++++++++++++ libs/lib-1/package.json | 5 +++++ libs/lib-1/project.json | 33 ++++++++++++++++++++++++++++++++ libs/lib-1/src/index.ts | 1 + libs/lib-1/src/lib/lib-1.spec.ts | 7 +++++++ libs/lib-1/src/lib/lib-1.ts | 3 +++ libs/lib-1/tsconfig.json | 22 +++++++++++++++++++++ libs/lib-1/tsconfig.lib.json | 10 ++++++++++ libs/lib-1/tsconfig.spec.json | 9 +++++++++ libs/lib-2/.babelrc | 10 ++++++++++ libs/lib-2/.eslintrc.json | 18 +++++++++++++++++ libs/lib-2/README.md | 11 +++++++++++ libs/lib-2/jest.config.ts | 15 +++++++++++++++ libs/lib-2/package.json | 5 +++++ libs/lib-2/project.json | 33 ++++++++++++++++++++++++++++++++ libs/lib-2/src/index.ts | 1 + libs/lib-2/src/lib/lib-2.spec.ts | 7 +++++++ libs/lib-2/src/lib/lib-2.ts | 3 +++ libs/lib-2/tsconfig.json | 22 +++++++++++++++++++++ libs/lib-2/tsconfig.lib.json | 10 ++++++++++ libs/lib-2/tsconfig.spec.json | 9 +++++++++ package.json | 1 + tsconfig.base.json | 2 ++ workspace.json | 2 ++ 27 files changed, 293 insertions(+) create mode 100644 libs/lib-1/.babelrc create mode 100644 libs/lib-1/.eslintrc.json create mode 100644 libs/lib-1/README.md create mode 100644 libs/lib-1/jest.config.ts create mode 100644 libs/lib-1/package.json create mode 100644 libs/lib-1/project.json create mode 100644 libs/lib-1/src/index.ts create mode 100644 libs/lib-1/src/lib/lib-1.spec.ts create mode 100644 libs/lib-1/src/lib/lib-1.ts create mode 100644 libs/lib-1/tsconfig.json create mode 100644 libs/lib-1/tsconfig.lib.json create mode 100644 libs/lib-1/tsconfig.spec.json create mode 100644 libs/lib-2/.babelrc create mode 100644 libs/lib-2/.eslintrc.json create mode 100644 libs/lib-2/README.md create mode 100644 libs/lib-2/jest.config.ts create mode 100644 libs/lib-2/package.json create mode 100644 libs/lib-2/project.json create mode 100644 libs/lib-2/src/index.ts create mode 100644 libs/lib-2/src/lib/lib-2.spec.ts create mode 100644 libs/lib-2/src/lib/lib-2.ts create mode 100644 libs/lib-2/tsconfig.json create mode 100644 libs/lib-2/tsconfig.lib.json create mode 100644 libs/lib-2/tsconfig.spec.json diff --git a/libs/lib-1/.babelrc b/libs/lib-1/.babelrc new file mode 100644 index 00000000..e24a5465 --- /dev/null +++ b/libs/lib-1/.babelrc @@ -0,0 +1,10 @@ +{ + "presets": [ + [ + "@nrwl/web/babel", + { + "useBuiltIns": "usage" + } + ] + ] +} diff --git a/libs/lib-1/.eslintrc.json b/libs/lib-1/.eslintrc.json new file mode 100644 index 00000000..9d9c0db5 --- /dev/null +++ b/libs/lib-1/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/lib-1/README.md b/libs/lib-1/README.md new file mode 100644 index 00000000..6e91d809 --- /dev/null +++ b/libs/lib-1/README.md @@ -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). diff --git a/libs/lib-1/jest.config.ts b/libs/lib-1/jest.config.ts new file mode 100644 index 00000000..7c71e64a --- /dev/null +++ b/libs/lib-1/jest.config.ts @@ -0,0 +1,15 @@ +/* eslint-disable */ +export default { + displayName: 'lib-1', + preset: '../../jest.preset.js', + globals: { + 'ts-jest': { + tsconfig: '/tsconfig.spec.json', + }, + }, + transform: { + '^.+\\.[tj]s$': 'ts-jest', + }, + moduleFileExtensions: ['ts', 'js', 'html'], + coverageDirectory: '../../coverage/libs/lib-1', +}; diff --git a/libs/lib-1/package.json b/libs/lib-1/package.json new file mode 100644 index 00000000..78becf23 --- /dev/null +++ b/libs/lib-1/package.json @@ -0,0 +1,5 @@ +{ + "name": "@nx-example/lib-1", + "version": "0.0.1", + "type": "commonjs" +} diff --git a/libs/lib-1/project.json b/libs/lib-1/project.json new file mode 100644 index 00000000..94b49398 --- /dev/null +++ b/libs/lib-1/project.json @@ -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": [] +} diff --git a/libs/lib-1/src/index.ts b/libs/lib-1/src/index.ts new file mode 100644 index 00000000..21b2cbbe --- /dev/null +++ b/libs/lib-1/src/index.ts @@ -0,0 +1 @@ +export * from './lib/lib-1'; diff --git a/libs/lib-1/src/lib/lib-1.spec.ts b/libs/lib-1/src/lib/lib-1.spec.ts new file mode 100644 index 00000000..9105833d --- /dev/null +++ b/libs/lib-1/src/lib/lib-1.spec.ts @@ -0,0 +1,7 @@ +import { lib1 } from './lib-1'; + +describe('lib1', () => { + it('should work', () => { + expect(lib1()).toEqual('lib-1'); + }); +}); diff --git a/libs/lib-1/src/lib/lib-1.ts b/libs/lib-1/src/lib/lib-1.ts new file mode 100644 index 00000000..5cf50547 --- /dev/null +++ b/libs/lib-1/src/lib/lib-1.ts @@ -0,0 +1,3 @@ +export function lib1(): string { + return 'lib-1'; +} diff --git a/libs/lib-1/tsconfig.json b/libs/lib-1/tsconfig.json new file mode 100644 index 00000000..f5b85657 --- /dev/null +++ b/libs/lib-1/tsconfig.json @@ -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" + } + ] +} diff --git a/libs/lib-1/tsconfig.lib.json b/libs/lib-1/tsconfig.lib.json new file mode 100644 index 00000000..e85ef50f --- /dev/null +++ b/libs/lib-1/tsconfig.lib.json @@ -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"] +} diff --git a/libs/lib-1/tsconfig.spec.json b/libs/lib-1/tsconfig.spec.json new file mode 100644 index 00000000..546f1287 --- /dev/null +++ b/libs/lib-1/tsconfig.spec.json @@ -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"] +} diff --git a/libs/lib-2/.babelrc b/libs/lib-2/.babelrc new file mode 100644 index 00000000..e24a5465 --- /dev/null +++ b/libs/lib-2/.babelrc @@ -0,0 +1,10 @@ +{ + "presets": [ + [ + "@nrwl/web/babel", + { + "useBuiltIns": "usage" + } + ] + ] +} diff --git a/libs/lib-2/.eslintrc.json b/libs/lib-2/.eslintrc.json new file mode 100644 index 00000000..9d9c0db5 --- /dev/null +++ b/libs/lib-2/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/lib-2/README.md b/libs/lib-2/README.md new file mode 100644 index 00000000..d8a5f4b5 --- /dev/null +++ b/libs/lib-2/README.md @@ -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). diff --git a/libs/lib-2/jest.config.ts b/libs/lib-2/jest.config.ts new file mode 100644 index 00000000..378bc2ec --- /dev/null +++ b/libs/lib-2/jest.config.ts @@ -0,0 +1,15 @@ +/* eslint-disable */ +export default { + displayName: 'lib-2', + preset: '../../jest.preset.js', + globals: { + 'ts-jest': { + tsconfig: '/tsconfig.spec.json', + }, + }, + transform: { + '^.+\\.[tj]s$': 'ts-jest', + }, + moduleFileExtensions: ['ts', 'js', 'html'], + coverageDirectory: '../../coverage/libs/lib-2', +}; diff --git a/libs/lib-2/package.json b/libs/lib-2/package.json new file mode 100644 index 00000000..4f369f46 --- /dev/null +++ b/libs/lib-2/package.json @@ -0,0 +1,5 @@ +{ + "name": "@nx-example/lib-2", + "version": "0.0.1", + "type": "commonjs" +} diff --git a/libs/lib-2/project.json b/libs/lib-2/project.json new file mode 100644 index 00000000..19e11b5e --- /dev/null +++ b/libs/lib-2/project.json @@ -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": [] +} diff --git a/libs/lib-2/src/index.ts b/libs/lib-2/src/index.ts new file mode 100644 index 00000000..ab045190 --- /dev/null +++ b/libs/lib-2/src/index.ts @@ -0,0 +1 @@ +export * from './lib/lib-2'; diff --git a/libs/lib-2/src/lib/lib-2.spec.ts b/libs/lib-2/src/lib/lib-2.spec.ts new file mode 100644 index 00000000..c1d9dc27 --- /dev/null +++ b/libs/lib-2/src/lib/lib-2.spec.ts @@ -0,0 +1,7 @@ +import { lib2 } from './lib-2'; + +describe('lib2', () => { + it('should work', () => { + expect(lib2()).toEqual('lib-2'); + }); +}); diff --git a/libs/lib-2/src/lib/lib-2.ts b/libs/lib-2/src/lib/lib-2.ts new file mode 100644 index 00000000..27467f22 --- /dev/null +++ b/libs/lib-2/src/lib/lib-2.ts @@ -0,0 +1,3 @@ +export function lib2(): string { + return 'lib-2'; +} diff --git a/libs/lib-2/tsconfig.json b/libs/lib-2/tsconfig.json new file mode 100644 index 00000000..f5b85657 --- /dev/null +++ b/libs/lib-2/tsconfig.json @@ -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" + } + ] +} diff --git a/libs/lib-2/tsconfig.lib.json b/libs/lib-2/tsconfig.lib.json new file mode 100644 index 00000000..e85ef50f --- /dev/null +++ b/libs/lib-2/tsconfig.lib.json @@ -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"] +} diff --git a/libs/lib-2/tsconfig.spec.json b/libs/lib-2/tsconfig.spec.json new file mode 100644 index 00000000..546f1287 --- /dev/null +++ b/libs/lib-2/tsconfig.spec.json @@ -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"] +} diff --git a/package.json b/package.json index 2683cfe6..86f06121 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tsconfig.base.json b/tsconfig.base.json index 418e6fa3..2fd3296d 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -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" ], diff --git a/workspace.json b/workspace.json index 852b9779..3e0cefe3 100644 --- a/workspace.json +++ b/workspace.json @@ -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", From 1a1ca19527249d1d4f7e0b874971de262c9ca32f Mon Sep 17 00:00:00 2001 From: Jason Gerbes Date: Thu, 16 Jun 2022 15:44:33 +1200 Subject: [PATCH 2/3] Add example of issue --- libs/lib-1/src/lib/lib-1.ts | 4 +--- libs/lib-2/src/index.ts | 1 + libs/lib-2/src/lib/lib-2.ts | 6 +++--- libs/lib-2/src/lib/test.ts | 3 +++ 4 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 libs/lib-2/src/lib/test.ts diff --git a/libs/lib-1/src/lib/lib-1.ts b/libs/lib-1/src/lib/lib-1.ts index 5cf50547..ce40ea70 100644 --- a/libs/lib-1/src/lib/lib-1.ts +++ b/libs/lib-1/src/lib/lib-1.ts @@ -1,3 +1 @@ -export function lib1(): string { - return 'lib-1'; -} +export type TestFunction = (arg: string) => string; diff --git a/libs/lib-2/src/index.ts b/libs/lib-2/src/index.ts index ab045190..9ebbdc1b 100644 --- a/libs/lib-2/src/index.ts +++ b/libs/lib-2/src/index.ts @@ -1 +1,2 @@ export * from './lib/lib-2'; +export * from './lib/test'; diff --git a/libs/lib-2/src/lib/lib-2.ts b/libs/lib-2/src/lib/lib-2.ts index 27467f22..f9b8957c 100644 --- a/libs/lib-2/src/lib/lib-2.ts +++ b/libs/lib-2/src/lib/lib-2.ts @@ -1,3 +1,3 @@ -export function lib2(): string { - return 'lib-2'; -} +import { TestFunction } from '@nx-example/lib-1'; + +export const testFunction: TestFunction = (arg: string) => arg; diff --git a/libs/lib-2/src/lib/test.ts b/libs/lib-2/src/lib/test.ts new file mode 100644 index 00000000..5717fbcf --- /dev/null +++ b/libs/lib-2/src/lib/test.ts @@ -0,0 +1,3 @@ +import { testFunction } from './lib-2'; + +export const test = testFunction; From 0d7679f42c9759ab165b0572a5d9c7ef97290eb1 Mon Sep 17 00:00:00 2001 From: Jason Gerbes Date: Thu, 16 Jun 2022 16:44:45 +1200 Subject: [PATCH 3/3] Add test-2 --- libs/lib-1/src/lib/lib-1.ts | 2 ++ libs/lib-2/src/lib/test-2.ts | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 libs/lib-2/src/lib/test-2.ts diff --git a/libs/lib-1/src/lib/lib-1.ts b/libs/lib-1/src/lib/lib-1.ts index ce40ea70..258e5cd6 100644 --- a/libs/lib-1/src/lib/lib-1.ts +++ b/libs/lib-1/src/lib/lib-1.ts @@ -1 +1,3 @@ export type TestFunction = (arg: string) => string; + +export const testValue = '2'; diff --git a/libs/lib-2/src/lib/test-2.ts b/libs/lib-2/src/lib/test-2.ts new file mode 100644 index 00000000..8b262cc2 --- /dev/null +++ b/libs/lib-2/src/lib/test-2.ts @@ -0,0 +1,6 @@ +import { testValue } from '@nx-example/lib-1'; +import { testFunction } from './lib-2'; + +export const test = testFunction; + +console.log(testValue);