From ca4bf9f14a0a189712e66730d4d6a88842567157 Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Wed, 5 Apr 2023 14:05:59 +0200 Subject: [PATCH] feat(core): remove @nrwl/workspace:lib --- docs/generated/manifests/menus.json | 8 - docs/generated/manifests/packages.json | 9 - docs/generated/packages-metadata.json | 9 - docs/shared/deprecated/default-collection.md | 1 - .../generators/composing-generators.md | 2 +- .../recipes/generators/creating-files.md | 2 +- .../recipes/generators/generator-options.md | 2 +- .../recipes/generators/local-generators.md | 2 +- e2e/jest/src/jest.test.ts | 16 +- e2e/linter/src/linter.test.ts | 20 +- e2e/nx-init/src/nx-project-graph.test.ts | 8 +- e2e/nx-misc/src/extras.test.ts | 4 +- e2e/nx-misc/src/watch.test.ts | 6 +- e2e/nx-misc/src/workspace.test.ts | 46 +- e2e/nx-run/src/cache.test.ts | 2 +- e2e/nx-run/src/invoke-runner.test.ts | 22 +- e2e/nx-run/src/run.test.ts | 2 +- e2e/utils/test-utils.ts | 1 - .../src/create-nx-workspace-npm.test.ts | 17 - nx-dev/nx-dev-e2e/src/e2e/packages.cy.ts | 4 - .../update-cypress-configs-presets.spec.ts | 2 +- .../update-cy-mount-usage.spec.ts | 2 +- .../update-15-1-0/cypress-11.spec.ts | 2 +- packages/expo/src/utils/add-linting.spec.ts | 2 +- .../update-jest-config-ext.spec.ts | 2 +- .../update-exports-jest-config.spec.ts | 6 +- .../update-configs-jest-28.spec.ts | 2 +- .../update-tests-jest-28.spec.ts | 14 +- .../update-configs-jest-29.spec.ts.snap | 4 +- .../update-configs-jest-29.spec.ts | 18 +- .../update-tests-jest-29.spec.ts | 6 +- packages/js/src/generators/library/library.ts | 5 + .../update-13-8-5/update-swcrc.spec.ts | 2 +- .../convert-tslint-to-eslint.ts | 2 +- .../src/generators/library/library.spec.ts | 9 +- .../node/src/generators/library/library.ts | 5 +- .../update-configs-jest-29.spec.ts.snap | 4 +- .../update-configs-jest-29.spec.ts | 18 +- .../update-tests-jest-29.spec.ts | 6 +- packages/nx/src/command-line/generate.ts | 2 +- .../src/utils/add-linting.spec.ts | 2 +- .../configuration/configuration-v7.spec.ts | 6 +- .../configuration/configuration.spec.ts | 2 +- .../cypress-project/cypress-project.spec.ts | 2 +- packages/storybook/src/utils/testing.ts | 3 +- packages/workspace/generators.json | 16 - packages/workspace/generators.ts | 1 - packages/workspace/index.ts | 1 - .../generators/library/files/lib/README.md | 14 - .../library/files/lib/__dot__babelrc__tmpl__ | 3 - .../library/files/lib/package.json__tmpl__ | 4 - .../library/files/lib/src/index.ts__tmpl__ | 1 - .../lib/src/lib/__fileName__.spec.ts__tmpl__ | 7 - .../files/lib/src/lib/__fileName__.ts__tmpl__ | 3 - .../library/files/lib/tsconfig.json | 13 - .../library/files/lib/tsconfig.lib.json | 10 - .../library/files/root/tsconfig.base.json | 20 - .../src/generators/library/library.spec.ts | 804 ------------------ .../src/generators/library/library.ts | 281 ------ .../src/generators/library/schema.d.ts | 23 - .../src/generators/library/schema.json | 112 --- .../move/lib/check-destination.spec.ts | 7 +- .../move/lib/move-project-files.spec.ts | 8 +- .../move/lib/update-cypress-config.spec.ts | 6 +- .../move/lib/update-eslintrc-json.spec.ts | 6 +- .../move/lib/update-imports.spec.ts | 15 +- .../move/lib/update-jest-config.spec.ts | 15 +- .../move/lib/update-package-json.spec.ts | 12 +- .../lib/update-project-root-files.spec.ts | 11 +- .../generators/move/lib/update-readme.spec.ts | 6 +- .../move/lib/update-storybook-config.spec.ts | 11 +- .../src/generators/move/move.spec.ts | 5 +- .../remove/lib/check-dependencies.spec.ts | 2 +- .../remove/lib/remove-project.spec.ts | 11 +- .../remove/lib/update-jest-config.spec.ts | 11 +- .../remove/lib/update-tsconfig.spec.ts | 6 +- .../run-commands/run-commands.spec.ts | 4 +- .../files/index.ts__tmpl__ | 2 +- 78 files changed, 231 insertions(+), 1531 deletions(-) delete mode 100644 packages/workspace/src/generators/library/files/lib/README.md delete mode 100644 packages/workspace/src/generators/library/files/lib/__dot__babelrc__tmpl__ delete mode 100644 packages/workspace/src/generators/library/files/lib/package.json__tmpl__ delete mode 100644 packages/workspace/src/generators/library/files/lib/src/index.ts__tmpl__ delete mode 100644 packages/workspace/src/generators/library/files/lib/src/lib/__fileName__.spec.ts__tmpl__ delete mode 100644 packages/workspace/src/generators/library/files/lib/src/lib/__fileName__.ts__tmpl__ delete mode 100644 packages/workspace/src/generators/library/files/lib/tsconfig.json delete mode 100644 packages/workspace/src/generators/library/files/lib/tsconfig.lib.json delete mode 100644 packages/workspace/src/generators/library/files/root/tsconfig.base.json delete mode 100644 packages/workspace/src/generators/library/library.spec.ts delete mode 100644 packages/workspace/src/generators/library/library.ts delete mode 100644 packages/workspace/src/generators/library/schema.d.ts delete mode 100644 packages/workspace/src/generators/library/schema.json diff --git a/docs/generated/manifests/menus.json b/docs/generated/manifests/menus.json index bb8b36b3ff9e5d..7044f92abe3cf3 100644 --- a/docs/generated/manifests/menus.json +++ b/docs/generated/manifests/menus.json @@ -6648,14 +6648,6 @@ "isExternal": false, "disableCollapsible": false }, - { - "id": "library", - "path": "/packages/workspace/generators/library", - "name": "library", - "children": [], - "isExternal": false, - "disableCollapsible": false - }, { "id": "workspace-generator", "path": "/packages/workspace/generators/workspace-generator", diff --git a/docs/generated/manifests/packages.json b/docs/generated/manifests/packages.json index 3f9f14a9f622a7..9a5addf6f9e32e 100644 --- a/docs/generated/manifests/packages.json +++ b/docs/generated/manifests/packages.json @@ -3030,15 +3030,6 @@ "path": "/packages/workspace/generators/new", "type": "generator" }, - "/packages/workspace/generators/library": { - "description": "Create a library.", - "file": "generated/packages/workspace/generators/library.json", - "hidden": false, - "name": "library", - "originalFilePath": "/packages/workspace/src/generators/library/schema.json", - "path": "/packages/workspace/generators/library", - "type": "generator" - }, "/packages/workspace/generators/workspace-generator": { "description": "Generates a workspace generator.", "file": "generated/packages/workspace/generators/workspace-generator.json", diff --git a/docs/generated/packages-metadata.json b/docs/generated/packages-metadata.json index c9faa9146b7747..7e29a16176ff7f 100644 --- a/docs/generated/packages-metadata.json +++ b/docs/generated/packages-metadata.json @@ -2996,15 +2996,6 @@ "path": "workspace/generators/new", "type": "generator" }, - { - "description": "Create a library.", - "file": "generated/packages/workspace/generators/library.json", - "hidden": false, - "name": "library", - "originalFilePath": "/packages/workspace/src/generators/library/schema.json", - "path": "workspace/generators/library", - "type": "generator" - }, { "description": "Generates a workspace generator.", "file": "generated/packages/workspace/generators/workspace-generator.json", diff --git a/docs/shared/deprecated/default-collection.md b/docs/shared/deprecated/default-collection.md index fa50a2c0d5a1e3..8cdd285fddd83e 100644 --- a/docs/shared/deprecated/default-collection.md +++ b/docs/shared/deprecated/default-collection.md @@ -34,7 +34,6 @@ This property is no longer needed because the Nx cli automatically will prompt y @nrwl/js:library @nrwl/next:library @nrwl/react:library -@nrwl/workspace:library None of the above ``` diff --git a/docs/shared/recipes/generators/composing-generators.md b/docs/shared/recipes/generators/composing-generators.md index d0ca6f99205665..ad64ee88df18dd 100644 --- a/docs/shared/recipes/generators/composing-generators.md +++ b/docs/shared/recipes/generators/composing-generators.md @@ -7,7 +7,7 @@ Generators are useful individually, but reusing and composing generators allows Nx Devkit generators can be imported and invoked like any javascript function. They often return a `Promise`, so they can be used with the `await` keyword to mimic synchronous code. Because this is standard javascript, control flow logic can be adjusted with `if` blocks and `for` loops as usual. ```typescript -import { libraryGenerator } from '@nrwl/workspace/generators'; +import { libraryGenerator } from '@nrwl/js'; export default async function (tree: Tree, schema: any) { await libraryGenerator( diff --git a/docs/shared/recipes/generators/creating-files.md b/docs/shared/recipes/generators/creating-files.md index 35154b71dd9413..01d9fe1f9507eb 100644 --- a/docs/shared/recipes/generators/creating-files.md +++ b/docs/shared/recipes/generators/creating-files.md @@ -41,7 +41,7 @@ import { joinPathFragments, readProjectConfiguration, } from '@nrwl/devkit'; -import { libraryGenerator } from '@nrwl/workspace/generators'; +import { libraryGenerator } from '@nrwl/js'; export default async function (tree: Tree, schema: any) { await libraryGenerator(tree, { name: schema.name }); diff --git a/docs/shared/recipes/generators/generator-options.md b/docs/shared/recipes/generators/generator-options.md index 09d0df483a5c3c..2812eb41f35a07 100644 --- a/docs/shared/recipes/generators/generator-options.md +++ b/docs/shared/recipes/generators/generator-options.md @@ -15,7 +15,7 @@ Import the TypeScript schema into your generator file and replace the `any` in y ```typescript import { Tree, formatFiles, installPackagesTask } from '@nrwl/devkit'; -import { libraryGenerator } from '@nrwl/workspace/generators'; +import { libraryGenerator } from '@nrwl/js'; export default async function (tree: Tree, schema: GeneratorOptions) { await libraryGenerator(tree, { name: `${schema.name}-${schema.type || ''}` }); diff --git a/docs/shared/recipes/generators/local-generators.md b/docs/shared/recipes/generators/local-generators.md index 27bcb360f923a6..22dbc676a542ca 100644 --- a/docs/shared/recipes/generators/local-generators.md +++ b/docs/shared/recipes/generators/local-generators.md @@ -51,7 +51,7 @@ The initial generator function creates a library. ```typescript import { Tree, formatFiles, installPackagesTask } from '@nrwl/devkit'; -import { libraryGenerator } from '@nrwl/workspace/generators'; +import { libraryGenerator } from '@nrwl/js'; export default async function (tree: Tree, schema: any) { await libraryGenerator(tree, { name: schema.name }); diff --git a/e2e/jest/src/jest.test.ts b/e2e/jest/src/jest.test.ts index be7a96f08ad5e3..689e56e0194e5c 100644 --- a/e2e/jest/src/jest.test.ts +++ b/e2e/jest/src/jest.test.ts @@ -4,12 +4,9 @@ import { runCLI, runCLIAsync, uniq, - readJson, updateFile, expectJestTestsToPass, cleanupProject, - readFile, - checkFilesExist, } from '@nrwl/e2e/utils'; describe('Jest', () => { @@ -20,7 +17,6 @@ describe('Jest', () => { afterAll(() => cleanupProject()); it('should be able test projects using jest', async () => { - await expectJestTestsToPass('@nrwl/workspace:lib'); await expectJestTestsToPass('@nrwl/js:lib'); }, 500000); @@ -28,10 +24,8 @@ describe('Jest', () => { const testGlobal = `'My Test Global'`; const mylib = uniq('mylib'); const utilLib = uniq('util-lib'); - runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`); - runCLI( - `generate @nrwl/workspace:lib ${utilLib} --importPath=@global-fun/globals` - ); + runCLI(`generate @nrwl/js:lib ${mylib} --unit-test-runner jest`); + runCLI(`generate @nrwl/js:lib ${utilLib} --importPath=@global-fun/globals`); updateFile( `libs/${utilLib}/src/index.ts`, stripIndents` @@ -102,13 +96,13 @@ describe('Jest', () => { it('should set the NODE_ENV to `test`', async () => { const mylib = uniq('mylib'); - runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`); + runCLI(`generate @nrwl/js:lib ${mylib} --unit-test-runner jest`); updateFile( `libs/${mylib}/src/lib/${mylib}.spec.ts`, ` test('can access jest global', () => { - expect(process.env.NODE_ENV).toBe('test'); + expect(process.env['NODE_ENV']).toBe('test'); }); ` ); @@ -120,7 +114,7 @@ describe('Jest', () => { it('should support multiple `coverageReporters` through CLI', async () => { const mylib = uniq('mylib'); - runCLI(`generate @nrwl/workspace:lib ${mylib} --unit-test-runner jest`); + runCLI(`generate @nrwl/js:lib ${mylib} --unit-test-runner jest`); updateFile( `libs/${mylib}/src/lib/${mylib}.spec.ts`, diff --git a/e2e/linter/src/linter.test.ts b/e2e/linter/src/linter.test.ts index c4262b69275fb8..8c1c2fd7ef56d2 100644 --- a/e2e/linter/src/linter.test.ts +++ b/e2e/linter/src/linter.test.ts @@ -29,7 +29,7 @@ describe('Linter', () => { beforeAll(() => { projScope = newProject(); runCLI(`generate @nrwl/react:app ${myapp} --tags=validtag`); - runCLI(`generate @nrwl/workspace:lib ${mylib}`); + runCLI(`generate @nrwl/js:lib ${mylib}`); }); afterAll(() => cleanupProject()); @@ -194,10 +194,8 @@ describe('Linter', () => { runCLI(`generate @nrwl/react:app ${myapp2}`); runCLI(`generate @nrwl/react:lib ${lazylib}`); - runCLI( - `generate @nrwl/workspace:lib ${invalidtaglib} --tags=invalidtag` - ); - runCLI(`generate @nrwl/workspace:lib ${validtaglib} --tags=validtag`); + runCLI(`generate @nrwl/js:lib ${invalidtaglib} --tags=invalidtag`); + runCLI(`generate @nrwl/js:lib ${validtaglib} --tags=validtag`); const eslint = readJson('.eslintrc.json'); eslint.overrides[0].rules[ @@ -255,9 +253,9 @@ describe('Linter', () => { const libC = uniq('tslib-c'); beforeAll(() => { - runCLI(`generate @nrwl/workspace:lib ${libA}`); - runCLI(`generate @nrwl/workspace:lib ${libB}`); - runCLI(`generate @nrwl/workspace:lib ${libC}`); + runCLI(`generate @nrwl/js:lib ${libA}`); + runCLI(`generate @nrwl/js:lib ${libB}`); + runCLI(`generate @nrwl/js:lib ${libC}`); /** * create tslib-a structure @@ -506,7 +504,7 @@ describe('Linter', () => { expect(appEslint.overrides[1].extends).toBeDefined(); expect(e2eEslint.overrides[0].extends).toBeDefined(); - runCLI(`generate @nrwl/workspace:lib ${mylib} --unitTestRunner=jest`); + runCLI(`generate @nrwl/js:lib ${mylib} --unitTestRunner=jest`); verifySuccessfulMigratedSetup(myapp, mylib); appEslint = readJson(`.eslintrc.json`); @@ -535,7 +533,7 @@ describe('Linter', () => { expect(appEslint.overrides[1].extends).toBeDefined(); expect(e2eEslint.overrides[0].extends).toBeDefined(); - runCLI(`generate @nrwl/workspace:lib ${mylib} --no-interactive`); + runCLI(`generate @nrwl/js:lib ${mylib} --no-interactive`); verifySuccessfulMigratedSetup(myapp, mylib); appEslint = readJson(`.eslintrc.json`); @@ -566,7 +564,7 @@ describe('Linter', () => { expect(appEslint.overrides[1].extends).toBeDefined(); expect(e2eEslint.overrides[0].extends).toBeDefined(); - runCLI(`generate @nrwl/workspace:lib ${mylib} --no-interactive`); + runCLI(`generate @nrwl/js:lib ${mylib} --no-interactive`); verifySuccessfulMigratedSetup(myapp, mylib); appEslint = readJson(`.eslintrc.json`); diff --git a/e2e/nx-init/src/nx-project-graph.test.ts b/e2e/nx-init/src/nx-project-graph.test.ts index 86f68e047ab2f6..37cf4e6551bb33 100644 --- a/e2e/nx-init/src/nx-project-graph.test.ts +++ b/e2e/nx-init/src/nx-project-graph.test.ts @@ -14,7 +14,7 @@ describe('project graph creation', () => { it('should correctly build the nxdeps.json containing files for the project', () => { const libName = uniq('mylib'); - runCLI(`generate @nrwl/workspace:lib ${libName}`); + runCLI(`generate @nrwl/js:lib ${libName}`); runCLI(`graph --file=graph.json`); const { graph: graphJson } = readJson('graph.json'); @@ -25,7 +25,7 @@ describe('project graph creation', () => { it("should correctly build the nxdeps.json containing files for the project when root is ''", () => { const libName = uniq('mylib'); - runCLI(`generate @nrwl/workspace:lib ${libName}`); + runCLI(`generate @nrwl/js:lib ${libName}`); updateJson(`libs/${libName}/project.json`, (json) => ({ ...json, root: '', @@ -41,8 +41,8 @@ describe('project graph creation', () => { const libName = uniq('mylib'); const secondLibName = uniq('mysecondlib'); - runCLI(`generate @nrwl/workspace:lib ${libName}`); - runCLI(`generate @nrwl/workspace:lib ${secondLibName}`); + runCLI(`generate @nrwl/js:lib ${libName}`); + runCLI(`generate @nrwl/js:lib ${secondLibName}`); updateJson(`libs/${libName}/project.json`, (json) => ({ ...json, root: '', diff --git a/e2e/nx-misc/src/extras.test.ts b/e2e/nx-misc/src/extras.test.ts index 513810de6e1768..8246423c78f52b 100644 --- a/e2e/nx-misc/src/extras.test.ts +++ b/e2e/nx-misc/src/extras.test.ts @@ -99,7 +99,7 @@ describe('Extra Nx Misc Tests', () => { describe('Run Commands', () => { const mylib = uniq('lib'); beforeAll(() => { - runCLI(`generate @nrwl/workspace:lib ${mylib}`); + runCLI(`generate @nrwl/js:lib ${mylib}`); }); it('should not override environment variables already set when setting a custom env file path', async () => { @@ -229,7 +229,7 @@ describe('Extra Nx Misc Tests', () => { const folder = `dist/libs/${mylib}/some-folder`; - runCLI(`generate @nrwl/workspace:lib ${mylib}`); + runCLI(`generate @nrwl/js:lib ${mylib}`); runCLI( `generate @nrwl/workspace:run-commands build --command=echo --outputs=${folder}/ --project=${mylib}` diff --git a/e2e/nx-misc/src/watch.test.ts b/e2e/nx-misc/src/watch.test.ts index 8daa1d4b8aa713..b67e687cebb173 100644 --- a/e2e/nx-misc/src/watch.test.ts +++ b/e2e/nx-misc/src/watch.test.ts @@ -17,9 +17,9 @@ describe('Nx Commands', () => { let proj3 = uniq('proj3'); beforeAll(() => { newProject({ packageManager: 'npm' }); - runCLI(`generate @nrwl/workspace:lib ${proj1}`); - runCLI(`generate @nrwl/workspace:lib ${proj2}`); - runCLI(`generate @nrwl/workspace:lib ${proj3}`); + runCLI(`generate @nrwl/js:lib ${proj1}`); + runCLI(`generate @nrwl/js:lib ${proj2}`); + runCLI(`generate @nrwl/js:lib ${proj3}`); }); afterAll(() => cleanupProject()); diff --git a/e2e/nx-misc/src/workspace.test.ts b/e2e/nx-misc/src/workspace.test.ts index 3c6aa105e396b3..9cbcf34b10ca0e 100644 --- a/e2e/nx-misc/src/workspace.test.ts +++ b/e2e/nx-misc/src/workspace.test.ts @@ -27,12 +27,12 @@ describe('Workspace Tests', () => { afterAll(() => cleanupProject()); - describe('@nrwl/workspace:library', () => { + describe('@nrwl/js:library', () => { it('should create a library that can be tested and linted', async () => { const libName = uniq('mylib'); const dirName = uniq('dir'); - runCLI(`generate @nrwl/workspace:lib ${libName} --directory ${dirName}`); + runCLI(`generate @nrwl/js:lib ${libName} --directory ${dirName}`); checkFilesExist( `libs/${dirName}/${libName}/src/index.ts`, @@ -46,15 +46,15 @@ describe('Workspace Tests', () => { expect(result).toContain('All files pass linting.'); // Test - await expectJestTestsToPass('@nrwl/workspace:lib'); + await expectJestTestsToPass('@nrwl/js:lib'); }, 100000); it('should be able to use and be used by other libs', () => { const consumerLib = uniq('consumer'); const producerLib = uniq('producer'); - runCLI(`generate @nrwl/workspace:lib ${consumerLib}`); - runCLI(`generate @nrwl/workspace:lib ${producerLib}`); + runCLI(`generate @nrwl/js:lib ${consumerLib}`); + runCLI(`generate @nrwl/js:lib ${producerLib}`); updateFile( `libs/${producerLib}/src/lib/${producerLib}.ts`, @@ -88,7 +88,7 @@ describe('Workspace Tests', () => { it('should be able to be built when it is buildable', () => { const buildableLib = uniq('buildable'); - runCLI(`generate @nrwl/workspace:lib ${buildableLib} --buildable`); + runCLI(`generate @nrwl/js:lib ${buildableLib} --buildable`); const result = runCLI(`build ${buildableLib}`); @@ -310,7 +310,7 @@ describe('Workspace Tests', () => { const lib1 = uniq('mylib'); const lib2 = uniq('mylib'); const lib3 = uniq('mylib'); - runCLI(`generate @nrwl/workspace:lib ${lib1}/data-access`); + runCLI(`generate @nrwl/js:lib ${lib1}/data-access`); updateFile( `libs/${lib1}/data-access/src/lib/${lib1}-data-access.ts`, @@ -326,7 +326,7 @@ describe('Workspace Tests', () => { * Create a library which imports a class from lib1 */ - runCLI(`generate @nrwl/workspace:lib ${lib2}/ui`); + runCLI(`generate @nrwl/js:lib ${lib2}/ui`); updateFile( `libs/${lib2}/ui/src/lib/${lib2}-ui.ts`, @@ -339,7 +339,7 @@ describe('Workspace Tests', () => { * Create a library which has an implicit dependency on lib1 */ - runCLI(`generate @nrwl/workspace:lib ${lib3}`); + runCLI(`generate @nrwl/js:lib ${lib3}`); updateProjectConfig(lib3, (config) => { config.implicitDependencies = [`${lib1}-data-access`]; return config; @@ -446,7 +446,7 @@ describe('Workspace Tests', () => { const lib2 = uniq('mylib'); const lib3 = uniq('mylib'); runCLI( - `generate @nrwl/workspace:lib ${lib1}/data-access --importPath=${importPath}` + `generate @nrwl/js:lib ${lib1}/data-access --importPath=${importPath}` ); updateFile( @@ -463,7 +463,7 @@ describe('Workspace Tests', () => { * Create a library which imports a class from lib1 */ - runCLI(`generate @nrwl/workspace:lib ${lib2}/ui`); + runCLI(`generate @nrwl/js:lib ${lib2}/ui`); updateFile( `libs/${lib2}/ui/src/lib/${lib2}-ui.ts`, @@ -476,7 +476,7 @@ describe('Workspace Tests', () => { * Create a library which has an implicit dependency on lib1 */ - runCLI(`generate @nrwl/workspace:lib ${lib3}`); + runCLI(`generate @nrwl/js:lib ${lib3}`); updateProjectConfig(lib3, (config) => { config.implicitDependencies = [`${lib1}-data-access`]; return config; @@ -579,7 +579,7 @@ describe('Workspace Tests', () => { nxJson.workspaceLayout = { libsDir: 'packages' }; updateFile('nx.json', JSON.stringify(nxJson)); - runCLI(`generate @nrwl/workspace:lib ${lib1}/data-access`); + runCLI(`generate @nrwl/js:lib ${lib1}/data-access`); updateFile( `packages/${lib1}/data-access/src/lib/${lib1}-data-access.ts`, @@ -595,7 +595,7 @@ describe('Workspace Tests', () => { * Create a library which imports a class from lib1 */ - runCLI(`generate @nrwl/workspace:lib ${lib2}/ui`); + runCLI(`generate @nrwl/js:lib ${lib2}/ui`); updateFile( `packages/${lib2}/ui/src/lib/${lib2}-ui.ts`, @@ -608,7 +608,7 @@ describe('Workspace Tests', () => { * Create a library which has an implicit dependency on lib1 */ - runCLI(`generate @nrwl/workspace:lib ${lib3}`); + runCLI(`generate @nrwl/js:lib ${lib3}`); updateProjectConfig(lib3, (config) => { config.implicitDependencies = [`${lib1}-data-access`]; return config; @@ -707,7 +707,7 @@ describe('Workspace Tests', () => { const lib1 = uniq('lib1'); const lib2 = uniq('lib2'); const lib3 = uniq('lib3'); - runCLI(`generate @nrwl/workspace:lib ${lib1}`); + runCLI(`generate @nrwl/js:lib ${lib1}`); updateFile( `libs/${lib1}/src/lib/${lib1}.ts`, @@ -723,7 +723,7 @@ describe('Workspace Tests', () => { * Create a library which imports a class from lib1 */ - runCLI(`generate @nrwl/workspace:lib ${lib2}/ui`); + runCLI(`generate @nrwl/js:lib ${lib2}/ui`); updateFile( `libs/${lib2}/ui/src/lib/${lib2}-ui.ts`, @@ -736,7 +736,7 @@ describe('Workspace Tests', () => { * Create a library which has an implicit dependency on lib1 */ - runCLI(`generate @nrwl/workspace:lib ${lib3}`); + runCLI(`generate @nrwl/js:lib ${lib3}`); updateProjectConfig(lib3, (config) => { config.implicitDependencies = [lib1]; return config; @@ -841,7 +841,7 @@ describe('Workspace Tests', () => { const lib1 = uniq('mylib'); const lib2 = uniq('mylib'); const lib3 = uniq('mylib'); - runCLI(`generate @nrwl/workspace:lib ${lib1}/data-access`); + runCLI(`generate @nrwl/js:lib ${lib1}/data-access`); let rootTsConfig = readJson('tsconfig.base.json'); expect( rootTsConfig.compilerOptions.paths[`@${proj}/${lib1}/data-access`] @@ -864,7 +864,7 @@ describe('Workspace Tests', () => { * Create a library which imports a class from lib1 */ - runCLI(`generate @nrwl/workspace:lib ${lib2}/ui`); + runCLI(`generate @nrwl/js:lib ${lib2}/ui`); updateFile( `libs/${lib2}/ui/src/lib/${lib2}-ui.ts`, @@ -877,7 +877,7 @@ describe('Workspace Tests', () => { * Create a library which has an implicit dependency on lib1 */ - runCLI(`generate @nrwl/workspace:lib ${lib3}`); + runCLI(`generate @nrwl/js:lib ${lib3}`); updateProjectConfig(lib3, (config) => { config.implicitDependencies = [`${lib1}-data-access`]; return config; @@ -955,14 +955,14 @@ describe('Workspace Tests', () => { const lib1 = uniq('myliba'); const lib2 = uniq('mylibb'); - runCLI(`generate @nrwl/workspace:lib ${lib1}`); + runCLI(`generate @nrwl/js:lib ${lib1}`); expect(exists(tmpProjPath(`libs/${lib1}`))).toBeTruthy(); /** * Create a library which has an implicit dependency on lib1 */ - runCLI(`generate @nrwl/workspace:lib ${lib2}`); + runCLI(`generate @nrwl/js:lib ${lib2}`); updateProjectConfig(lib2, (config) => { config.implicitDependencies = [lib1]; return config; diff --git a/e2e/nx-run/src/cache.test.ts b/e2e/nx-run/src/cache.test.ts index 1e3729b34dea0a..7412df84cca627 100644 --- a/e2e/nx-run/src/cache.test.ts +++ b/e2e/nx-run/src/cache.test.ts @@ -144,7 +144,7 @@ describe('cache', () => { it('should support using globs as outputs', async () => { const mylib = uniq('mylib'); - runCLI(`generate @nrwl/workspace:library ${mylib}`); + runCLI(`generate @nrwl/js:library ${mylib}`); updateProjectConfig(mylib, (c) => { c.targets.build = { executor: 'nx:run-commands', diff --git a/e2e/nx-run/src/invoke-runner.test.ts b/e2e/nx-run/src/invoke-runner.test.ts index 5d9faa7b048d5c..eb27ab6331aaef 100644 --- a/e2e/nx-run/src/invoke-runner.test.ts +++ b/e2e/nx-run/src/invoke-runner.test.ts @@ -1,24 +1,12 @@ import { - checkFilesExist, cleanupProject, - fileExists, - isWindows, newProject, - readFile, - readJson, - readProjectConfig, - removeFile, runCLI, - runCLIAsync, runCommand, - tmpProjPath, uniq, updateFile, - updateJson, updateProjectConfig, } from '@nrwl/e2e/utils'; -import { PackageJson } from 'nx/src/utils/package-json'; -import * as path from 'path'; describe('Invoke Runner', () => { let proj: string; @@ -27,7 +15,7 @@ describe('Invoke Runner', () => { it('should invoke runner imperatively ', async () => { const mylib = uniq('mylib'); - runCLI(`generate @nrwl/workspace:lib ${mylib}`); + runCLI(`generate @nrwl/js:lib ${mylib}`); updateProjectConfig(mylib, (c) => { c.targets['prebuild'] = { command: 'echo prebuild', @@ -41,15 +29,15 @@ describe('Invoke Runner', () => { updateFile( 'runner.js', ` - const { initTasksRunner } = require('nx/src/index'); - + const { initTasksRunner } = require('nx/src/index'); + async function main(){ const r = await initTasksRunner({}); - + await r.invoke({tasks: [{id: '${mylib}:prebuild', target: {project: '${mylib}', target: 'prebuild'}, overrides: {__overrides_unparsed__: ''}}]}); await r.invoke({tasks: [{id: '${mylib}:build', target: {project: '${mylib}', target: 'build'}, overrides: {__overrides_unparsed__: ''}}]}); } - + main().then(q => { console.log("DONE") process.exit(0) diff --git a/e2e/nx-run/src/run.test.ts b/e2e/nx-run/src/run.test.ts index d069c83c1cd144..ff49c471e36910 100644 --- a/e2e/nx-run/src/run.test.ts +++ b/e2e/nx-run/src/run.test.ts @@ -29,7 +29,7 @@ describe('Nx Running Tests', () => { describe('(forwarding params)', () => { let proj = uniq('proj'); beforeAll(() => { - runCLI(`generate @nrwl/workspace:lib ${proj}`); + runCLI(`generate @nrwl/js:lib ${proj}`); updateProjectConfig(proj, (c) => { c.targets['echo'] = { command: 'echo ECHO:', diff --git a/e2e/utils/test-utils.ts b/e2e/utils/test-utils.ts index 40f8ce77e975dc..1504cd8f646ca2 100644 --- a/e2e/utils/test-utils.ts +++ b/e2e/utils/test-utils.ts @@ -15,7 +15,6 @@ type GeneratorsWithDefaultTests = | '@nrwl/react:app' | '@nrwl/next:app' | '@nrwl/angular:app' - | '@nrwl/workspace:lib' | '@nrwl/web:app'; /** diff --git a/e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts b/e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts index bde47d6f419db5..aa41cabb595e73 100644 --- a/e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts +++ b/e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts @@ -48,23 +48,6 @@ describe('create-nx-workspace --preset=npm', () => { }); }, 1_000_000); - it('should add workspace library', () => { - packageInstall('@nrwl/workspace', wsName); - - const libName = uniq('lib'); - - expect(() => - runCLI( - `generate @nrwl/workspace:library ${libName} --skipPackageJson --no-interactive` - ) - ).not.toThrowError(); - checkFilesExist('tsconfig.base.json'); - const tsconfig = readJson(`tsconfig.base.json`); - expect(tsconfig.compilerOptions.paths).toEqual({ - [libName]: [`packages/${libName}/src/index.ts`], - }); - }); - it('should add js library', () => { packageInstall('@nrwl/js', wsName); diff --git a/nx-dev/nx-dev-e2e/src/e2e/packages.cy.ts b/nx-dev/nx-dev-e2e/src/e2e/packages.cy.ts index 35d9306a809b10..de2f293a10e785 100644 --- a/nx-dev/nx-dev-e2e/src/e2e/packages.cy.ts +++ b/nx-dev/nx-dev-e2e/src/e2e/packages.cy.ts @@ -452,10 +452,6 @@ describe('nx-dev: Packages Section', () => { title: '@nrwl/workspace:new', path: '/packages/workspace/generators/new', }, - { - title: '@nrwl/workspace:library', - path: '/packages/workspace/generators/library', - }, { title: '@nrwl/workspace:workspace-generator', path: '/packages/workspace/generators/workspace-generator', diff --git a/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.spec.ts b/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.spec.ts index be52ef7c46c8c8..2e9e9feb66faee 100644 --- a/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.spec.ts +++ b/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.spec.ts @@ -11,7 +11,7 @@ import { } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { cypressProjectGenerator } from '../../generators/cypress-project/cypress-project'; -import { libraryGenerator } from '@nrwl/workspace'; +import { libraryGenerator } from '@nrwl/js'; let projectGraph: ProjectGraph; jest.mock('@nrwl/devkit', () => { diff --git a/packages/cypress/src/migrations/update-15-0-0/update-cy-mount-usage.spec.ts b/packages/cypress/src/migrations/update-15-0-0/update-cy-mount-usage.spec.ts index bc5bf7024f1f87..81110731bb57f8 100644 --- a/packages/cypress/src/migrations/update-15-0-0/update-cy-mount-usage.spec.ts +++ b/packages/cypress/src/migrations/update-15-0-0/update-cy-mount-usage.spec.ts @@ -10,7 +10,7 @@ import { updateCyFile, updateCyMountUsage, } from './update-cy-mount-usage'; -import { libraryGenerator } from '@nrwl/workspace'; +import { libraryGenerator } from '@nrwl/js'; import { cypressComponentProject } from '../../generators/cypress-component-project/cypress-component-project'; jest.mock('../../utils/cypress-version'); diff --git a/packages/cypress/src/migrations/update-15-1-0/cypress-11.spec.ts b/packages/cypress/src/migrations/update-15-1-0/cypress-11.spec.ts index 442781759790fc..697919f6375b88 100644 --- a/packages/cypress/src/migrations/update-15-1-0/cypress-11.spec.ts +++ b/packages/cypress/src/migrations/update-15-1-0/cypress-11.spec.ts @@ -1,5 +1,5 @@ import { addProjectConfiguration, Tree } from '@nrwl/devkit'; -import { libraryGenerator } from '@nrwl/workspace'; +import { libraryGenerator } from '@nrwl/js'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import updateToCypress11 from './cypress-11'; import { installedCypressVersion } from '../../utils/cypress-version'; diff --git a/packages/expo/src/utils/add-linting.spec.ts b/packages/expo/src/utils/add-linting.spec.ts index 959d456759954f..485d67e6796088 100644 --- a/packages/expo/src/utils/add-linting.spec.ts +++ b/packages/expo/src/utils/add-linting.spec.ts @@ -1,7 +1,7 @@ import { readProjectConfiguration, Tree } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Linter } from '@nrwl/linter'; -import { libraryGenerator } from '@nrwl/workspace/src/generators/library/library'; +import { libraryGenerator } from '@nrwl/js'; import { addLinting } from './add-linting'; describe('Add Linting', () => { diff --git a/packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.spec.ts b/packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.spec.ts index e818efe8168865..25ff2eeef401eb 100644 --- a/packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.spec.ts +++ b/packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.spec.ts @@ -6,7 +6,7 @@ import { updateProjectConfiguration, } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator as workspaceLib } from '@nrwl/workspace'; +import { libraryGenerator as workspaceLib } from '@nrwl/js'; import jestInitGenerator from '../../generators/init/init'; import { updateJestConfigExt } from './update-jest-config-ext'; diff --git a/packages/jest/src/migrations/update-14-1-5/update-exports-jest-config.spec.ts b/packages/jest/src/migrations/update-14-1-5/update-exports-jest-config.spec.ts index ff9c5bd1b2c682..80b23488e22fdd 100644 --- a/packages/jest/src/migrations/update-14-1-5/update-exports-jest-config.spec.ts +++ b/packages/jest/src/migrations/update-14-1-5/update-exports-jest-config.spec.ts @@ -7,7 +7,7 @@ import { readJson, } from '@nrwl/devkit'; import { createTree, createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator as workspaceLib } from '@nrwl/workspace'; +import { libraryGenerator as workspaceLib } from '@nrwl/js'; import { updateExportsJestConfig, updateRootFiles, @@ -172,8 +172,8 @@ module.exports = { stripIndents` const { getJestProjects } = require('@nrwl/jest'); const nxPreset = require('@nrwl/jest/preset'); - - + + const someFn = () => ({more: 'stuff'}); module.export.abc = someFn; module.exports = { diff --git a/packages/jest/src/migrations/update-14-6-0/update-configs-jest-28.spec.ts b/packages/jest/src/migrations/update-14-6-0/update-configs-jest-28.spec.ts index 442a9a1c78e399..01eb3f60bd108b 100644 --- a/packages/jest/src/migrations/update-14-6-0/update-configs-jest-28.spec.ts +++ b/packages/jest/src/migrations/update-14-6-0/update-configs-jest-28.spec.ts @@ -1,6 +1,6 @@ import { readJson, updateJson } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator as workspaceLib } from '@nrwl/workspace'; +import { libraryGenerator as workspaceLib } from '@nrwl/js'; import { checkDeps, updateConfigsJest28, diff --git a/packages/jest/src/migrations/update-14-6-0/update-tests-jest-28.spec.ts b/packages/jest/src/migrations/update-14-6-0/update-tests-jest-28.spec.ts index 156ebf20217244..b51ec783cd4c85 100644 --- a/packages/jest/src/migrations/update-14-6-0/update-tests-jest-28.spec.ts +++ b/packages/jest/src/migrations/update-14-6-0/update-tests-jest-28.spec.ts @@ -1,5 +1,5 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator as workspaceLib } from '@nrwl/workspace'; +import { libraryGenerator as workspaceLib } from '@nrwl/js'; import { readProjectConfiguration, updateProjectConfiguration, @@ -139,10 +139,10 @@ describe('Jest Migration - jest 28 test files', () => { const { somethingElse } = require('ts-jest/utils'); import * from ts from 'typescript' const mockTs = mocked(ts); - + describe('something expected', () => { it('should do something', () => { - const actual = somethingExpected('abc'); + const actual = somethingExpected('abc'); expect(1 + 1).toBe(2); }); }) @@ -155,10 +155,10 @@ describe('Jest Migration - jest 28 test files', () => { const { somethingElse } = require('ts-jest/utils'); import * from ts from 'typescript' const mockTs = mocked(ts); - + describe('something expected', () => { it('should do something', () => { - const actual = somethingExpected('abc'); + const actual = somethingExpected('abc'); expect(1 + 1).toBe(2); }); }) @@ -176,7 +176,7 @@ describe('Jest Migration - jest 28 test files', () => { describe('something expected', () => { it('should do something', () => { - const actual = somethingExpected('abc'); + const actual = somethingExpected('abc'); expect(1 + 1).toBe(2); }); }) @@ -190,7 +190,7 @@ describe('Jest Migration - jest 28 test files', () => { describe('something expected', () => { it('should do something', () => { - const actual = somethingExpected('abc'); + const actual = somethingExpected('abc'); expect(1 + 1).toBe(2); }); }) diff --git a/packages/jest/src/migrations/update-15-8-0/__snapshots__/update-configs-jest-29.spec.ts.snap b/packages/jest/src/migrations/update-15-8-0/__snapshots__/update-configs-jest-29.spec.ts.snap index 340613e88ffcfe..d91eddd17d1493 100644 --- a/packages/jest/src/migrations/update-15-8-0/__snapshots__/update-configs-jest-29.spec.ts.snap +++ b/packages/jest/src/migrations/update-15-8-0/__snapshots__/update-configs-jest-29.spec.ts.snap @@ -360,8 +360,8 @@ abc: [1234, true, {abc: 'yes'}] }, exports[`Jest Migration - jest 29 update configs should work snapshotFormat is defined 2`] = ` "module.exports = { transform: { - '^.+\\\\\\\\.[tj]sx?$': ['ts-jest', { - tsconfig: '/tsconfig.spec.json' + '^.+\\\\\\\\.[tj]sx?$': ['ts-jest', { + tsconfig: '/tsconfig.spec.json' }], }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'] diff --git a/packages/jest/src/migrations/update-15-8-0/update-configs-jest-29.spec.ts b/packages/jest/src/migrations/update-15-8-0/update-configs-jest-29.spec.ts index 9bea2ef8bce04c..60b56502ee4e30 100644 --- a/packages/jest/src/migrations/update-15-8-0/update-configs-jest-29.spec.ts +++ b/packages/jest/src/migrations/update-15-8-0/update-configs-jest-29.spec.ts @@ -6,7 +6,7 @@ import { updateProjectConfiguration, } from '@nrwl/devkit'; import { updateConfigsJest29 } from './update-configs-jest-29'; -import { libraryGenerator } from '@nrwl/workspace'; +import { libraryGenerator } from '@nrwl/js'; let projectGraph: ProjectGraph; jest.mock('@nrwl/devkit', () => ({ @@ -55,9 +55,9 @@ describe('Jest Migration - jest 29 update configs', () => { module.exports = { ...nxPreset, testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'], - globals: { + globals: { 'ts-jest': { - tsconfig: '/tsconfig.spec.json' + tsconfig: '/tsconfig.spec.json' }, something: 'else', abc: [1234, true, {abc: 'yes'}] @@ -307,8 +307,8 @@ module.exports = { '^.+\\\\.[tj]sx?$': 'babel-jest', }, globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json' + 'ts-jest': { + tsconfig: '/tsconfig.spec.json' }, something: 'else', abc: [1234, true, {abc: 'yes'}] @@ -331,8 +331,8 @@ module.exports = { testEnvironment: 'node', preset: '../../jest.preset.js', globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json' + 'ts-jest': { + tsconfig: '/tsconfig.spec.json' }, something: 'else', abc: [1234, true, {abc: 'yes'}] @@ -430,9 +430,9 @@ transform: { }, // I am a comment and shouldn't be removed moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], -globals: { +globals: { 'ts-jest': { - tsconfig: '/tsconfig.spec.json' + tsconfig: '/tsconfig.spec.json' }, something: 'else', abc: [1234, true, {abc: 'yes'}] diff --git a/packages/jest/src/migrations/update-15-8-0/update-tests-jest-29.spec.ts b/packages/jest/src/migrations/update-15-8-0/update-tests-jest-29.spec.ts index 4e42f14677190e..ed8e71eac7c2f0 100644 --- a/packages/jest/src/migrations/update-15-8-0/update-tests-jest-29.spec.ts +++ b/packages/jest/src/migrations/update-15-8-0/update-tests-jest-29.spec.ts @@ -5,7 +5,7 @@ import { updateProjectConfiguration, } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator } from '@nrwl/workspace'; +import { libraryGenerator } from '@nrwl/js'; import { updateTestsJest29 } from './update-tests-jest-29'; let projectGraph: ProjectGraph; @@ -92,9 +92,9 @@ transform: { '^.+\\\\.[tj]sx?$': 'ts-jest' }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], -globals: { +globals: { 'ts-jest': { - tsconfig: '/tsconfig.spec.json' + tsconfig: '/tsconfig.spec.json' } }, displayName: 'jest', diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index 23be7456e67c49..7b48617f7a1f55 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -428,6 +428,11 @@ function normalizeOptions( options.bundler = options.bundler ?? options.compiler ?? 'tsc'; + // ensure programmatic runs have an expected default + if (!options.config) { + options.config = 'project'; + } + if (options.publishable) { if (!options.importPath) { throw new Error( diff --git a/packages/js/src/migrations/update-13-8-5/update-swcrc.spec.ts b/packages/js/src/migrations/update-13-8-5/update-swcrc.spec.ts index f9e62c0d172195..087366cd0463b0 100644 --- a/packages/js/src/migrations/update-13-8-5/update-swcrc.spec.ts +++ b/packages/js/src/migrations/update-13-8-5/update-swcrc.spec.ts @@ -7,7 +7,7 @@ import { updateProjectConfiguration, } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator } from '@nrwl/workspace'; +import { libraryGenerator } from '@nrwl/js'; import { defaultExclude } from '../../utils/swc/add-swc-config'; import update from './update-swcrc'; diff --git a/packages/nest/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.ts b/packages/nest/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.ts index e35308e847ab77..6f90313a008961 100755 --- a/packages/nest/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.ts +++ b/packages/nest/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.ts @@ -12,7 +12,7 @@ import { import { addLint as addLintingToLibraryGenerator, NormalizedSchema as AddLintForLibrarySchema, -} from '@nrwl/workspace/src/generators/library/library'; +} from '@nrwl/js/src/generators/library/library'; import type { Linter } from 'eslint'; export async function conversionGenerator( diff --git a/packages/node/src/generators/library/library.spec.ts b/packages/node/src/generators/library/library.spec.ts index 3b502bd9cac776..acfeaa5f73578e 100644 --- a/packages/node/src/generators/library/library.spec.ts +++ b/packages/node/src/generators/library/library.spec.ts @@ -1,6 +1,5 @@ import { getProjects, - NxJsonConfiguration, readJson, readProjectConfiguration, Tree, @@ -95,6 +94,9 @@ describe('lib', () => { const tsconfigJson = readJson(tree, 'libs/my-lib/tsconfig.json'); expect(tsconfigJson).toMatchInlineSnapshot(` Object { + "compilerOptions": Object { + "module": "commonjs", + }, "extends": "../../tsconfig.base.json", "files": Array [], "include": Array [], @@ -461,9 +463,9 @@ describe('lib', () => { preset: '../../jest.preset.js', testEnvironment: 'node', transform: { - '^.+\\\\\\\\.[tj]sx?$': 'babel-jest', + '^.+\\\\\\\\.[tj]s$': 'babel-jest', }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], + moduleFileExtensions: ['ts', 'js', 'html'], coverageDirectory: '../../coverage/libs/my-lib', }; " @@ -486,6 +488,7 @@ describe('lib', () => { readJson(tree, 'libs/my-lib/tsconfig.json').compilerOptions ).toEqual({ allowJs: true, + module: 'commonjs', }); expect(readJson(tree, 'libs/my-lib/tsconfig.lib.json').include).toEqual([ 'src/**/*.ts', diff --git a/packages/node/src/generators/library/library.ts b/packages/node/src/generators/library/library.ts index ee20afdb4227f6..68981a181bb446 100644 --- a/packages/node/src/generators/library/library.ts +++ b/packages/node/src/generators/library/library.ts @@ -17,7 +17,7 @@ import { } from '@nrwl/devkit'; import { getImportPath } from 'nx/src/utils/path'; import { Schema } from './schema'; -import { libraryGenerator as workspaceLibraryGenerator } from '@nrwl/workspace/generators'; +import { libraryGenerator as jsLibraryGenerator } from '@nrwl/js'; import { join } from 'path'; import { addSwcDependencies } from '@nrwl/js/src/utils/swc/add-swc-dependencies'; @@ -49,8 +49,9 @@ export async function libraryGenerator(tree: Tree, schema: Schema) { ); } - const libraryInstall = await workspaceLibraryGenerator(tree, { + const libraryInstall = await jsLibraryGenerator(tree, { ...schema, + bundler: schema.buildable ? 'tsc' : 'none', importPath: options.importPath, testEnvironment: 'node', skipFormat: true, diff --git a/packages/nx-plugin/src/migrations/update-15-9-0/__snapshots__/update-configs-jest-29.spec.ts.snap b/packages/nx-plugin/src/migrations/update-15-9-0/__snapshots__/update-configs-jest-29.spec.ts.snap index ee4c851e66d458..24f14904c00144 100644 --- a/packages/nx-plugin/src/migrations/update-15-9-0/__snapshots__/update-configs-jest-29.spec.ts.snap +++ b/packages/nx-plugin/src/migrations/update-15-9-0/__snapshots__/update-configs-jest-29.spec.ts.snap @@ -360,8 +360,8 @@ abc: [1234, true, {abc: 'yes'}] }, exports[`Nx Plugin Migration - jest 29 update configs should work snapshotFormat is defined 2`] = ` "module.exports = { transform: { - '^.+\\\\\\\\.[tj]sx?$': ['ts-jest', { - tsconfig: '/tsconfig.spec.json' + '^.+\\\\\\\\.[tj]sx?$': ['ts-jest', { + tsconfig: '/tsconfig.spec.json' }], }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'] diff --git a/packages/nx-plugin/src/migrations/update-15-9-0/update-configs-jest-29.spec.ts b/packages/nx-plugin/src/migrations/update-15-9-0/update-configs-jest-29.spec.ts index 8a73cfac6c931d..7af07e9c24ee57 100644 --- a/packages/nx-plugin/src/migrations/update-15-9-0/update-configs-jest-29.spec.ts +++ b/packages/nx-plugin/src/migrations/update-15-9-0/update-configs-jest-29.spec.ts @@ -6,7 +6,7 @@ import { updateProjectConfiguration, } from '@nrwl/devkit'; import { updateConfigsJest29 } from './jest-29-configs'; -import { libraryGenerator } from '@nrwl/workspace'; +import { libraryGenerator } from '@nrwl/js'; let projectGraph: ProjectGraph; jest.mock('@nrwl/devkit', () => ({ @@ -55,9 +55,9 @@ describe('Nx Plugin Migration - jest 29 update configs', () => { module.exports = { ...nxPreset, testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'], - globals: { + globals: { 'ts-jest': { - tsconfig: '/tsconfig.spec.json' + tsconfig: '/tsconfig.spec.json' }, something: 'else', abc: [1234, true, {abc: 'yes'}] @@ -307,8 +307,8 @@ module.exports = { '^.+\\\\.[tj]sx?$': 'babel-jest', }, globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json' + 'ts-jest': { + tsconfig: '/tsconfig.spec.json' }, something: 'else', abc: [1234, true, {abc: 'yes'}] @@ -331,8 +331,8 @@ module.exports = { testEnvironment: 'node', preset: '../../jest.preset.js', globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json' + 'ts-jest': { + tsconfig: '/tsconfig.spec.json' }, something: 'else', abc: [1234, true, {abc: 'yes'}] @@ -431,9 +431,9 @@ transform: { }, // I am a comment and shouldn't be removed moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], -globals: { +globals: { 'ts-jest': { - tsconfig: '/tsconfig.spec.json' + tsconfig: '/tsconfig.spec.json' }, something: 'else', abc: [1234, true, {abc: 'yes'}] diff --git a/packages/nx-plugin/src/migrations/update-15-9-0/update-tests-jest-29.spec.ts b/packages/nx-plugin/src/migrations/update-15-9-0/update-tests-jest-29.spec.ts index 63be11c244940c..399948d495cebc 100644 --- a/packages/nx-plugin/src/migrations/update-15-9-0/update-tests-jest-29.spec.ts +++ b/packages/nx-plugin/src/migrations/update-15-9-0/update-tests-jest-29.spec.ts @@ -5,7 +5,7 @@ import { updateProjectConfiguration, } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator } from '@nrwl/workspace'; +import { libraryGenerator } from '@nrwl/js'; import { updateTestsJest29 } from './jest-29-tests'; let projectGraph: ProjectGraph; @@ -92,9 +92,9 @@ transform: { '^.+\\\\.[tj]sx?$': 'ts-jest' }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], -globals: { +globals: { 'ts-jest': { - tsconfig: '/tsconfig.spec.json' + tsconfig: '/tsconfig.spec.json' } }, displayName: 'jest', diff --git a/packages/nx/src/command-line/generate.ts b/packages/nx/src/command-line/generate.ts index b36af34ba9bcf9..275b275354625e 100644 --- a/packages/nx/src/command-line/generate.ts +++ b/packages/nx/src/command-line/generate.ts @@ -235,7 +235,7 @@ async function convertToGenerateOptions( } if (!collectionName) { - throwInvalidInvocation(['@nrwl/workspace:library']); + throwInvalidInvocation(['@nrwl/js:library']); } const res = { diff --git a/packages/react-native/src/utils/add-linting.spec.ts b/packages/react-native/src/utils/add-linting.spec.ts index f3975364aa2227..0925d6898f29e8 100644 --- a/packages/react-native/src/utils/add-linting.spec.ts +++ b/packages/react-native/src/utils/add-linting.spec.ts @@ -1,7 +1,7 @@ import { readProjectConfiguration, Tree } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Linter } from '@nrwl/linter'; -import { libraryGenerator } from '@nrwl/workspace/src/generators/library/library'; +import { libraryGenerator } from '@nrwl/js'; import { addLinting } from './add-linting'; describe('Add Linting', () => { diff --git a/packages/storybook/src/generators/configuration/configuration-v7.spec.ts b/packages/storybook/src/generators/configuration/configuration-v7.spec.ts index 4dd50ad6c68648..f2407d256643fd 100644 --- a/packages/storybook/src/generators/configuration/configuration-v7.spec.ts +++ b/packages/storybook/src/generators/configuration/configuration-v7.spec.ts @@ -13,7 +13,7 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import * as enquirer from 'enquirer'; import { Linter } from '@nrwl/linter'; -import { libraryGenerator } from '@nrwl/workspace/generators'; +import { libraryGenerator } from '@nrwl/js'; import { TsConfig } from '../../utils/utilities'; import { storybook7Version } from '../../utils/versions'; import configurationGenerator from './configuration'; @@ -44,7 +44,7 @@ describe('@nrwl/storybook:configuration for Storybook v7', () => { }); await libraryGenerator(tree, { name: 'test-ui-lib', - standaloneConfig: false, + bundler: 'none', }); writeJson(tree, 'package.json', { devDependencies: { @@ -126,7 +126,6 @@ describe('@nrwl/storybook:configuration for Storybook v7', () => { await libraryGenerator(tree, { name: 'test-ui-lib2', linter: Linter.EsLint, - standaloneConfig: false, }); updateJson(tree, 'libs/test-ui-lib2/.eslintrc.json', (json) => { @@ -157,7 +156,6 @@ describe('@nrwl/storybook:configuration for Storybook v7', () => { await libraryGenerator(tree, { name: 'test-ui-lib2', linter: Linter.EsLint, - standaloneConfig: false, }); await configurationGenerator(tree, { diff --git a/packages/storybook/src/generators/configuration/configuration.spec.ts b/packages/storybook/src/generators/configuration/configuration.spec.ts index 685c2b82bd22ba..e2729b966964d5 100644 --- a/packages/storybook/src/generators/configuration/configuration.spec.ts +++ b/packages/storybook/src/generators/configuration/configuration.spec.ts @@ -11,7 +11,7 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import * as enquirer from 'enquirer'; import { Linter } from '@nrwl/linter'; -import { libraryGenerator } from '@nrwl/workspace/generators'; +import { libraryGenerator } from '@nrwl/js'; import { nxVersion } from '../../utils/versions'; import { TsConfig } from '../../utils/utilities'; import configurationGenerator from './configuration'; diff --git a/packages/storybook/src/generators/cypress-project/cypress-project.spec.ts b/packages/storybook/src/generators/cypress-project/cypress-project.spec.ts index 14f89ca4fe316f..2da2b928892bbe 100644 --- a/packages/storybook/src/generators/cypress-project/cypress-project.spec.ts +++ b/packages/storybook/src/generators/cypress-project/cypress-project.spec.ts @@ -2,7 +2,7 @@ import { installedCypressVersion } from '@nrwl/cypress/src/utils/cypress-version import { readJson, readProjectConfiguration, Tree } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Linter } from '@nrwl/linter'; -import { libraryGenerator } from '@nrwl/workspace/generators'; +import { libraryGenerator } from '@nrwl/js'; import { cypressProjectGenerator } from './cypress-project'; jest.mock('@nrwl/cypress/src/utils/cypress-version'); diff --git a/packages/storybook/src/utils/testing.ts b/packages/storybook/src/utils/testing.ts index b76491b6d7d542..176770ab1c4a98 100644 --- a/packages/storybook/src/utils/testing.ts +++ b/packages/storybook/src/utils/testing.ts @@ -5,7 +5,7 @@ import { Tree as NrwlTree } from '@nrwl/devkit'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { createEmptyWorkspace } from '@nrwl/workspace/testing'; -import libraryGenerator from '@nrwl/workspace/src/generators/library/library'; +import { libraryGenerator } from '@nrwl/js'; import { Linter } from '@nrwl/linter'; const testRunner = new SchematicTestRunner( @@ -60,7 +60,6 @@ export async function createTestUILibNoNgDevkit( skipTsConfig: false, unitTestRunner: 'none', name: libName, - standaloneConfig: false, }); return appTree; diff --git a/packages/workspace/generators.json b/packages/workspace/generators.json index 72b4ed655c1240..685b08a059a2bc 100644 --- a/packages/workspace/generators.json +++ b/packages/workspace/generators.json @@ -14,14 +14,6 @@ "aliases": ["rm"], "description": "Remove an application or library." }, - "library": { - "factory": "./src/generators/library/library#librarySchematic", - "schema": "./src/generators/library/schema.json", - "aliases": ["lib"], - "x-type": "library", - "description": "Create a library.", - "x-deprecated": "Use @nrwl/js:lib instead. This will be removed in Nx v16" - }, "workspace-generator": { "factory": "./src/generators/workspace-generator/workspace-generator", "schema": "./src/generators/workspace-generator/schema.json", @@ -67,14 +59,6 @@ "description": "Create a workspace.", "hidden": true }, - "library": { - "factory": "./src/generators/library/library#libraryGenerator", - "schema": "./src/generators/library/schema.json", - "aliases": ["lib"], - "x-type": "library", - "description": "Create a library.", - "x-deprecated": "Use @nrwl/js:lib instead. This will be removed in Nx v16." - }, "workspace-generator": { "factory": "./src/generators/workspace-generator/workspace-generator", "schema": "./src/generators/workspace-generator/schema.json", diff --git a/packages/workspace/generators.ts b/packages/workspace/generators.ts index 9d860fa7307da3..89edfe9c328314 100644 --- a/packages/workspace/generators.ts +++ b/packages/workspace/generators.ts @@ -1,4 +1,3 @@ -export { libraryGenerator } from './src/generators/library/library'; export { npmPackageGenerator } from './src/generators/npm-package/npm-package'; export { moveGenerator } from './src/generators/move/move'; export { removeGenerator } from './src/generators/remove/remove'; diff --git a/packages/workspace/index.ts b/packages/workspace/index.ts index 80934442ec7b10..03e6349a270241 100644 --- a/packages/workspace/index.ts +++ b/packages/workspace/index.ts @@ -45,7 +45,6 @@ import * as strings from './src/utils/strings'; // TODO(v17): Remove this export. export { checkAndCleanWithSemver } from './src/utils/version-utils'; -export { libraryGenerator } from './src/generators/library/library'; export { moveGenerator } from './src/generators/move/move'; export { removeGenerator } from './src/generators/remove/remove'; export { runCommandsGenerator } from './src/generators/run-commands/run-commands'; diff --git a/packages/workspace/src/generators/library/files/lib/README.md b/packages/workspace/src/generators/library/files/lib/README.md deleted file mode 100644 index 6c5d01351e2ede..00000000000000 --- a/packages/workspace/src/generators/library/files/lib/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# <%= name %> - -This library was generated with [Nx](https://nx.dev). -<% if (hasUnitTestRunner) { %> - -## Running unit tests - -Run `<%= cliCommand %> test <%= name %>` to execute the unit tests via [Jest](https://jestjs.io). -<% } %><% if (hasLinter) { %> - -## Running lint - -Run `<%= cliCommand %> lint <%= name %>` to execute the lint via [ESLint](https://eslint.org/). -<% } %> diff --git a/packages/workspace/src/generators/library/files/lib/__dot__babelrc__tmpl__ b/packages/workspace/src/generators/library/files/lib/__dot__babelrc__tmpl__ deleted file mode 100644 index 9cbf9798bc1e9a..00000000000000 --- a/packages/workspace/src/generators/library/files/lib/__dot__babelrc__tmpl__ +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": [["@nrwl/js/babel", { "useBuiltIns": "usage" }]] -} diff --git a/packages/workspace/src/generators/library/files/lib/package.json__tmpl__ b/packages/workspace/src/generators/library/files/lib/package.json__tmpl__ deleted file mode 100644 index e3a3ad83c46eb5..00000000000000 --- a/packages/workspace/src/generators/library/files/lib/package.json__tmpl__ +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "<%= importPath %>", - "version": "0.0.1" -} diff --git a/packages/workspace/src/generators/library/files/lib/src/index.ts__tmpl__ b/packages/workspace/src/generators/library/files/lib/src/index.ts__tmpl__ deleted file mode 100644 index 32176b3ef175e1..00000000000000 --- a/packages/workspace/src/generators/library/files/lib/src/index.ts__tmpl__ +++ /dev/null @@ -1 +0,0 @@ -export * from './lib/<%= fileName %>'; diff --git a/packages/workspace/src/generators/library/files/lib/src/lib/__fileName__.spec.ts__tmpl__ b/packages/workspace/src/generators/library/files/lib/src/lib/__fileName__.spec.ts__tmpl__ deleted file mode 100644 index 35b0948b950878..00000000000000 --- a/packages/workspace/src/generators/library/files/lib/src/lib/__fileName__.spec.ts__tmpl__ +++ /dev/null @@ -1,7 +0,0 @@ -import { <%= propertyName %> } from './<%= fileName %>'; - -describe('<%= propertyName %>', () => { - it('should work', () => { - expect(<%= propertyName %>()).toEqual('<%= name %>'); - }) -}) \ No newline at end of file diff --git a/packages/workspace/src/generators/library/files/lib/src/lib/__fileName__.ts__tmpl__ b/packages/workspace/src/generators/library/files/lib/src/lib/__fileName__.ts__tmpl__ deleted file mode 100644 index ae311e3ac41f0b..00000000000000 --- a/packages/workspace/src/generators/library/files/lib/src/lib/__fileName__.ts__tmpl__ +++ /dev/null @@ -1,3 +0,0 @@ -export function <%= propertyName %>(): string { - return '<%= name %>'; -} diff --git a/packages/workspace/src/generators/library/files/lib/tsconfig.json b/packages/workspace/src/generators/library/files/lib/tsconfig.json deleted file mode 100644 index 8bf55e434eef11..00000000000000 --- a/packages/workspace/src/generators/library/files/lib/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "<%= rootTsConfigPath %>",<% if (js) { %> - "compilerOptions": { - "allowJs": true - },<% } %> - "files": [], - "include": [], - "references": [ - { - "path": "./tsconfig.lib.json" - } - ] -} diff --git a/packages/workspace/src/generators/library/files/lib/tsconfig.lib.json b/packages/workspace/src/generators/library/files/lib/tsconfig.lib.json deleted file mode 100644 index 78fad8cab4f08d..00000000000000 --- a/packages/workspace/src/generators/library/files/lib/tsconfig.lib.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "<%= offsetFromRoot %>dist/out-tsc", - "declaration": true, - "types": [] - }, - "include": ["src/**/*.ts"<% if (js) { %>, "src/**/*.js"<% } %>], - "exclude": ["jest.config.ts","src/**/*.spec.ts"<% if (js) { %>, "src/**/*.spec.js"<% } %>] -} diff --git a/packages/workspace/src/generators/library/files/root/tsconfig.base.json b/packages/workspace/src/generators/library/files/root/tsconfig.base.json deleted file mode 100644 index 11253ac5c2b7bc..00000000000000 --- a/packages/workspace/src/generators/library/files/root/tsconfig.base.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compileOnSave": false, - "compilerOptions": { - "rootDir": ".", - "sourceMap": true, - "declaration": false, - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "importHelpers": true, - "target": "es2015", - "module": "esnext", - "lib": ["es2017", "dom"], - "skipLibCheck": true, - "skipDefaultLibCheck": true, - "baseUrl": ".", - "paths": {} - }, - "exclude": ["node_modules", "tmp"] -} diff --git a/packages/workspace/src/generators/library/library.spec.ts b/packages/workspace/src/generators/library/library.spec.ts deleted file mode 100644 index 2bb3ef7cb6e082..00000000000000 --- a/packages/workspace/src/generators/library/library.spec.ts +++ /dev/null @@ -1,804 +0,0 @@ -import { - getProjects, - readJson, - readProjectConfiguration, - Tree, - updateJson, -} from '@nrwl/devkit'; -import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; - -import { libraryGenerator } from './library'; -import { Schema } from './schema.d'; - -describe('lib', () => { - let tree: Tree; - const defaultOptions: Omit = { - skipTsConfig: false, - unitTestRunner: 'jest', - skipFormat: false, - linter: 'eslint', - simpleModuleName: false, - testEnvironment: 'jsdom', - js: false, - pascalCaseFiles: false, - strict: true, - }; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - describe('not nested', () => { - it('should create project configuration', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - }); - - const config = readProjectConfiguration(tree, 'my-lib'); - expect(config.root).toEqual('libs/my-lib'); - expect(config.targets.build).toBeUndefined(); - }); - - it('should update tags', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - tags: 'one,two', - }); - const projects = Object.fromEntries(getProjects(tree)); - expect(projects).toMatchObject({ - 'my-lib': { - tags: ['one', 'two'], - }, - }); - }); - - it('should update root tsconfig.base.json', async () => { - await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' }); - const tsconfigJson = readJson(tree, '/tsconfig.base.json'); - expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([ - 'libs/my-lib/src/index.ts', - ]); - }); - - it('should update root tsconfig.json when no tsconfig.base.json', async () => { - tree.rename('tsconfig.base.json', 'tsconfig.json'); - - await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' }); - - const tsconfigJson = readJson(tree, '/tsconfig.json'); - expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([ - 'libs/my-lib/src/index.ts', - ]); - }); - - it('should update root tsconfig.json (no existing path mappings)', async () => { - updateJson(tree, 'tsconfig.base.json', (json) => { - json.compilerOptions.paths = undefined; - return json; - }); - - await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' }); - const tsconfigJson = readJson(tree, '/tsconfig.base.json'); - expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([ - 'libs/my-lib/src/index.ts', - ]); - }); - - it('should create a local tsconfig.json', async () => { - await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' }); - const tsconfigJson = readJson(tree, 'libs/my-lib/tsconfig.json'); - expect(tsconfigJson).toMatchInlineSnapshot(` - Object { - "compilerOptions": Object { - "forceConsistentCasingInFileNames": true, - "noFallthroughCasesInSwitch": true, - "noImplicitReturns": true, - "strict": true, - }, - "extends": "../../tsconfig.base.json", - "files": Array [], - "include": Array [], - "references": Array [ - Object { - "path": "./tsconfig.lib.json", - }, - Object { - "path": "./tsconfig.spec.json", - }, - ], - } - `); - }); - - it('should extend from root tsconfig.json when no tsconfig.base.json', async () => { - tree.rename('tsconfig.base.json', 'tsconfig.json'); - - await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' }); - - const tsconfigJson = readJson(tree, 'libs/my-lib/tsconfig.json'); - expect(tsconfigJson.extends).toBe('../../tsconfig.json'); - }); - - it('should extend the local tsconfig.json with tsconfig.spec.json', async () => { - await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' }); - const tsconfigJson = readJson(tree, 'libs/my-lib/tsconfig.spec.json'); - expect(tsconfigJson.extends).toEqual('./tsconfig.json'); - }); - - it('should extend the local tsconfig.json with tsconfig.lib.json', async () => { - await libraryGenerator(tree, { ...defaultOptions, name: 'myLib' }); - const tsconfigJson = readJson(tree, 'libs/my-lib/tsconfig.lib.json'); - expect(tsconfigJson.extends).toEqual('./tsconfig.json'); - }); - - it('should generate files', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - }); - - expect(tree.exists(`libs/my-lib/jest.config.ts`)).toBeTruthy(); - expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8')) - .toMatchInlineSnapshot(` - "/* eslint-disable */ - export default { - displayName: 'my-lib', - preset: '../../jest.preset.js', - transform: { - '^.+\\\\\\\\.[tj]sx?$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/libs/my-lib', - }; - " - `); - expect(tree.exists('libs/my-lib/src/index.ts')).toBeTruthy(); - expect(tree.exists('libs/my-lib/src/lib/my-lib.ts')).toBeTruthy(); - expect(tree.exists('libs/my-lib/src/lib/my-lib.spec.ts')).toBeTruthy(); - expect(tree.exists('libs/my-lib/README.md')).toBeTruthy(); - expect(tree.exists('libs/my-lib/package.json')).toBeFalsy(); - - const ReadmeContent = tree.read('libs/my-lib/README.md', 'utf-8'); - expect(ReadmeContent).toContain('nx test my-lib'); - }); - - it('should add project to the jest config', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - }); - - expect(tree.read('jest.config.ts', 'utf-8')).toMatchInlineSnapshot( - ` - "import { getJestProjects } from '@nrwl/jest'; - - export default { - projects: getJestProjects(), - }; - " - ` - ); - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib2', - }); - - expect(tree.read('jest.config.ts', 'utf-8')).toMatchInlineSnapshot( - ` - "import { getJestProjects } from '@nrwl/jest'; - - export default { - projects: getJestProjects(), - }; - " - ` - ); - }); - }); - - describe('nested', () => { - it('should update tags', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - tags: 'one', - }); - let projects = Object.fromEntries(getProjects(tree)); - expect(projects).toMatchObject({ - 'my-dir-my-lib': { - tags: ['one'], - }, - }); - - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib2', - directory: 'myDir', - tags: 'one,two', - simpleModuleName: true, - }); - projects = Object.fromEntries(getProjects(tree)); - expect(projects).toMatchObject({ - 'my-dir-my-lib': { - tags: ['one'], - }, - 'my-dir-my-lib2': { - tags: ['one', 'two'], - }, - }); - }); - - it('should generate files', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - }); - expect(tree.exists(`libs/my-dir/my-lib/jest.config.ts`)).toBeTruthy(); - expect(tree.exists('libs/my-dir/my-lib/src/index.ts')).toBeTruthy(); - expect( - tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.ts') - ).toBeTruthy(); - expect( - tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.spec.ts') - ).toBeTruthy(); - expect(tree.exists('libs/my-dir/my-lib/src/index.ts')).toBeTruthy(); - expect(tree.exists(`libs/my-dir/my-lib/.eslintrc.json`)).toBeTruthy(); - expect(tree.exists(`libs/my-dir/my-lib/package.json`)).toBeFalsy(); - }); - - it('should create project configurations', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - }); - - const config = readProjectConfiguration(tree, 'my-dir-my-lib'); - expect(config.root).toEqual('libs/my-dir/my-lib'); - expect(config.targets.lint).toEqual({ - executor: '@nrwl/linter:eslint', - outputs: ['{options.outputFile}'], - options: { - lintFilePatterns: ['libs/my-dir/my-lib/**/*.ts'], - }, - }); - }); - - it('should update root tsconfig.base.json', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - }); - const tsconfigJson = readJson(tree, '/tsconfig.base.json'); - expect(tsconfigJson.compilerOptions.paths['@proj/my-dir/my-lib']).toEqual( - ['libs/my-dir/my-lib/src/index.ts'] - ); - expect( - tsconfigJson.compilerOptions.paths['my-dir-my-lib/*'] - ).toBeUndefined(); - }); - - it('should update root tsconfig.json when no tsconfig.base.json', async () => { - tree.rename('tsconfig.base.json', 'tsconfig.json'); - - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - }); - - const tsconfigJson = readJson(tree, '/tsconfig.json'); - expect(tsconfigJson.compilerOptions.paths['@proj/my-dir/my-lib']).toEqual( - ['libs/my-dir/my-lib/src/index.ts'] - ); - expect( - tsconfigJson.compilerOptions.paths['my-dir-my-lib/*'] - ).toBeUndefined(); - }); - - it('should create a local tsconfig.json', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - }); - - const tsconfigJson = readJson(tree, 'libs/my-dir/my-lib/tsconfig.json'); - expect(tsconfigJson.extends).toBe('../../../tsconfig.base.json'); - expect(tsconfigJson.references).toEqual([ - { - path: './tsconfig.lib.json', - }, - { - path: './tsconfig.spec.json', - }, - ]); - }); - - it('should extend from root tsconfig.json when no tsconfig.base.json', async () => { - tree.rename('tsconfig.base.json', 'tsconfig.json'); - - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - }); - - const tsconfigJson = readJson(tree, 'libs/my-dir/my-lib/tsconfig.json'); - expect(tsconfigJson.extends).toBe('../../../tsconfig.json'); - }); - }); - - describe('--linter', () => { - describe('eslint', () => { - it('should add eslint dependencies', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - }); - - const packageJson = readJson(tree, 'package.json'); - expect(packageJson.devDependencies['eslint']).toBeDefined(); - expect(packageJson.devDependencies['@nrwl/linter']).toBeDefined(); - expect( - packageJson.devDependencies['@nrwl/eslint-plugin-nx'] - ).toBeDefined(); - }); - - describe('not nested', () => { - it('should create project configurations', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - }); - - expect(readProjectConfiguration(tree, 'my-lib').targets.lint).toEqual( - { - executor: '@nrwl/linter:eslint', - outputs: ['{options.outputFile}'], - options: { - lintFilePatterns: ['libs/my-lib/**/*.ts'], - }, - } - ); - }); - - it('should create a local .eslintrc.json', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - }); - - const eslintJson = readJson(tree, 'libs/my-lib/.eslintrc.json'); - expect(eslintJson).toMatchInlineSnapshot(` - Object { - "extends": Array [ - "../../.eslintrc.json", - ], - "ignorePatterns": Array [ - "!**/*", - ], - "overrides": Array [ - Object { - "files": Array [ - "*.ts", - "*.tsx", - "*.js", - "*.jsx", - ], - "rules": Object {}, - }, - Object { - "files": Array [ - "*.ts", - "*.tsx", - ], - "rules": Object {}, - }, - Object { - "files": Array [ - "*.js", - "*.jsx", - ], - "rules": Object {}, - }, - ], - } - `); - }); - }); - - describe('nested', () => { - it('should create project configuration', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - }); - - expect( - readProjectConfiguration(tree, 'my-dir-my-lib').targets.lint - ).toEqual({ - executor: '@nrwl/linter:eslint', - outputs: ['{options.outputFile}'], - options: { - lintFilePatterns: ['libs/my-dir/my-lib/**/*.ts'], - }, - }); - }); - - it('should create a local .eslintrc.json', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - }); - - const eslintJson = readJson( - tree, - 'libs/my-dir/my-lib/.eslintrc.json' - ); - expect(eslintJson).toMatchInlineSnapshot(` - Object { - "extends": Array [ - "../../../.eslintrc.json", - ], - "ignorePatterns": Array [ - "!**/*", - ], - "overrides": Array [ - Object { - "files": Array [ - "*.ts", - "*.tsx", - "*.js", - "*.jsx", - ], - "rules": Object {}, - }, - Object { - "files": Array [ - "*.ts", - "*.tsx", - ], - "rules": Object {}, - }, - Object { - "files": Array [ - "*.js", - "*.jsx", - ], - "rules": Object {}, - }, - ], - } - `); - }); - }); - }); - }); - - describe('--unit-test-runner none', () => { - it('should not generate test configuration nor spec file', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - unitTestRunner: 'none', - }); - - expect(tree.exists('libs/my-lib/tsconfig.spec.json')).toBeFalsy(); - expect(tree.exists('libs/my-lib/jest.config.ts')).toBeFalsy(); - expect(tree.exists('libs/my-lib/src/lib/my-lib.spec.ts')).toBeFalsy(); - - const config = readProjectConfiguration(tree, 'my-lib'); - expect(config.targets.test).toBeUndefined(); - expect(config.targets.lint).toMatchInlineSnapshot(` - Object { - "executor": "@nrwl/linter:eslint", - "options": Object { - "lintFilePatterns": Array [ - "libs/my-lib/**/*.ts", - ], - }, - "outputs": Array [ - "{options.outputFile}", - ], - } - `); - }); - }); - - describe('--strict', () => { - it('should update the projects tsconfig with strict false', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - strict: false, - }); - const tsconfigJson = readJson(tree, '/libs/my-lib/tsconfig.json'); - - expect(tsconfigJson.compilerOptions?.strict).not.toBeDefined(); - expect( - tsconfigJson.compilerOptions?.forceConsistentCasingInFileNames - ).not.toBeDefined(); - expect(tsconfigJson.compilerOptions?.noImplicitReturns).not.toBeDefined(); - expect( - tsconfigJson.compilerOptions?.noFallthroughCasesInSwitch - ).not.toBeDefined(); - }); - - it('should default to strict true', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - }); - const tsconfigJson = readJson(tree, '/libs/my-lib/tsconfig.json'); - - expect(tsconfigJson.compilerOptions.strict).toBeTruthy(); - expect( - tsconfigJson.compilerOptions.forceConsistentCasingInFileNames - ).toBeTruthy(); - expect(tsconfigJson.compilerOptions.noImplicitReturns).toBeTruthy(); - expect( - tsconfigJson.compilerOptions.noFallthroughCasesInSwitch - ).toBeTruthy(); - }); - }); - - describe('--importPath', () => { - it('should update the tsconfig with the given import path', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - importPath: '@myorg/lib', - }); - const tsconfigJson = readJson(tree, '/tsconfig.base.json'); - - expect(tsconfigJson.compilerOptions.paths['@myorg/lib']).toBeDefined(); - }); - - it('should fail if the same importPath has already been used', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib1', - importPath: '@myorg/lib', - }); - - try { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib2', - importPath: '@myorg/lib', - }); - } catch (e) { - expect(e.message).toContain( - 'You already have a library using the import path' - ); - } - - expect.assertions(1); - }); - }); - - describe('--js flag', () => { - it('should generate js files instead of ts files', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - js: true, - }); - expect(tree.exists(`libs/my-lib/jest.config.js`)).toBeTruthy(); - expect(tree.exists('libs/my-lib/src/index.js')).toBeTruthy(); - expect(tree.exists('libs/my-lib/src/lib/my-lib.js')).toBeTruthy(); - expect(tree.exists('libs/my-lib/src/lib/my-lib.spec.js')).toBeTruthy(); - }); - - it('should update tsconfig.json with compilerOptions.allowJs: true', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - js: true, - }); - expect( - readJson(tree, 'libs/my-lib/tsconfig.json').compilerOptions - ).toEqual({ - forceConsistentCasingInFileNames: true, - noFallthroughCasesInSwitch: true, - noImplicitReturns: true, - strict: true, - allowJs: true, - }); - }); - - it('should update tsconfig.lib.json include with **/*.js glob', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - js: true, - }); - expect(readJson(tree, 'libs/my-lib/tsconfig.lib.json').include).toEqual([ - 'src/**/*.ts', - 'src/**/*.js', - ]); - }); - - it('should update root tsconfig.json with a js file path', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - js: true, - }); - const tsconfigJson = readJson(tree, '/tsconfig.base.json'); - expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([ - 'libs/my-lib/src/index.js', - ]); - }); - - it('should generate js files for nested libs as well', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - js: true, - }); - expect(tree.exists(`libs/my-dir/my-lib/jest.config.js`)).toBeTruthy(); - expect(tree.exists('libs/my-dir/my-lib/src/index.js')).toBeTruthy(); - expect( - tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.js') - ).toBeTruthy(); - expect( - tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.spec.js') - ).toBeTruthy(); - expect(tree.exists('libs/my-dir/my-lib/src/index.js')).toBeTruthy(); - }); - - it('should configure the project for linting js files', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - js: true, - }); - expect( - readProjectConfiguration(tree, 'my-dir-my-lib').targets.lint.options - .lintFilePatterns - ).toEqual(['libs/my-dir/my-lib/**/*.js']); - expect(readJson(tree, 'libs/my-dir/my-lib/.eslintrc.json')) - .toMatchInlineSnapshot(` - Object { - "extends": Array [ - "../../../.eslintrc.json", - ], - "ignorePatterns": Array [ - "!**/*", - ], - "overrides": Array [ - Object { - "files": Array [ - "*.ts", - "*.tsx", - "*.js", - "*.jsx", - ], - "rules": Object {}, - }, - Object { - "files": Array [ - "*.ts", - "*.tsx", - ], - "rules": Object {}, - }, - Object { - "files": Array [ - "*.js", - "*.jsx", - ], - "rules": Object {}, - }, - ], - } - `); - }); - }); - - describe(`--babelJest`, () => { - it('should use babel for jest', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - babelJest: true, - } as Schema); - - expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8')) - .toMatchInlineSnapshot(` - "/* eslint-disable */ - export default { - displayName: 'my-lib', - preset: '../../jest.preset.js', - transform: { - '^.+\\\\\\\\.[tj]sx?$': 'babel-jest', - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/libs/my-lib', - }; - " - `); - }); - }); - - describe('--pascalCaseFiles', () => { - it('should generate files with upper case names', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - pascalCaseFiles: true, - }); - expect(tree.exists('libs/my-lib/src/lib/MyLib.ts')).toBeTruthy(); - expect(tree.exists('libs/my-lib/src/lib/MyLib.spec.ts')).toBeTruthy(); - }); - - it('should generate files with upper case names for nested libs as well', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - directory: 'myDir', - pascalCaseFiles: true, - }); - expect( - tree.exists('libs/my-dir/my-lib/src/lib/MyDirMyLib.ts') - ).toBeTruthy(); - expect( - tree.exists('libs/my-dir/my-lib/src/lib/MyDirMyLib.spec.ts') - ).toBeTruthy(); - }); - }); - - describe('--skipBabelrc', () => { - it('should skip generating .babelrc when --skipBabelrc=true', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - skipBabelrc: true, - }); - expect(tree.exists('libs/my-lib/.babelrc')).toBeFalsy(); - }); - - it('should generate .babelrc by default', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - }); - expect(tree.exists('libs/my-lib/.babelrc')).toBeTruthy(); - }); - }); - - describe('--buildable', () => { - it('should add build target', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - buildable: true, - }); - expect( - readProjectConfiguration(tree, 'my-lib').targets.build.executor - ).toBe('@nrwl/js:tsc'); - }); - - it('should generate a package.json file', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'myLib', - buildable: true, - }); - - expect(tree.exists('libs/my-lib/package.json')).toBeTruthy(); - }); - }); -}); diff --git a/packages/workspace/src/generators/library/library.ts b/packages/workspace/src/generators/library/library.ts deleted file mode 100644 index ad1afb7b431d05..00000000000000 --- a/packages/workspace/src/generators/library/library.ts +++ /dev/null @@ -1,281 +0,0 @@ -import { - addDependenciesToPackageJson, - addProjectConfiguration, - convertNxGenerator, - ensurePackage, - extractLayoutDirectory, - formatFiles, - generateFiles, - GeneratorCallback, - getWorkspaceLayout, - joinPathFragments, - names, - offsetFromRoot, - ProjectConfiguration, - runTasksInSerial, - toJS, - Tree, - updateJson, -} from '@nrwl/devkit'; -import { getImportPath } from 'nx/src/utils/path'; -import { join } from 'path'; - -import { - getRelativePathToRootTsConfig, - getRootTsConfigFileName, - getRootTsConfigPathInTree, -} from '../../utilities/ts-config'; -import { nxVersion, typescriptVersion } from '../../utils/versions'; -import type { Schema } from './schema'; - -export interface NormalizedSchema extends Schema { - name: string; - fileName: string; - projectRoot: string; - projectDirectory: string; - libsDir: string; - parsedTags: string[]; - importPath?: string; -} - -function addProject(tree: Tree, options: NormalizedSchema) { - const projectConfiguration: ProjectConfiguration = { - root: options.projectRoot, - sourceRoot: joinPathFragments(options.projectRoot, 'src'), - projectType: 'library', - targets: {}, - tags: options.parsedTags, - }; - - if (options.buildable) { - addDependenciesToPackageJson(tree, {}, { '@nrwl/js': nxVersion }); - projectConfiguration.targets.build = { - executor: '@nrwl/js:tsc', - outputs: ['{options.outputPath}'], - options: { - outputPath: - options.libsDir != '.' - ? `dist/${options.libsDir}/${options.projectDirectory}` - : `dist/${options.projectDirectory}`, - main: `${options.projectRoot}/src/index` + (options.js ? '.js' : '.ts'), - tsConfig: `${options.projectRoot}/tsconfig.lib.json`, - assets: [`${options.projectRoot}/*.md`], - }, - }; - } - - addProjectConfiguration(tree, options.name, projectConfiguration); -} - -export async function addLint( - tree: Tree, - options: NormalizedSchema -): Promise { - const { lintProjectGenerator } = ensurePackage('@nrwl/linter', nxVersion); - return lintProjectGenerator(tree, { - project: options.name, - linter: options.linter, - skipFormat: true, - tsConfigPaths: [ - joinPathFragments(options.projectRoot, 'tsconfig.lib.json'), - ], - unitTestRunner: options.unitTestRunner, - eslintFilePatterns: [ - `${options.projectRoot}/**/*.${options.js ? 'js' : 'ts'}`, - ], - setParserOptionsProject: options.setParserOptionsProject, - }); -} - -function updateTsConfig(tree: Tree, options: NormalizedSchema) { - updateJson(tree, join(options.projectRoot, 'tsconfig.json'), (json) => { - if (options.strict) { - json.compilerOptions = { - ...json.compilerOptions, - forceConsistentCasingInFileNames: true, - strict: true, - noImplicitReturns: true, - noFallthroughCasesInSwitch: true, - }; - } - - return json; - }); -} - -function updateRootTsConfig(host: Tree, options: NormalizedSchema) { - updateJson(host, getRootTsConfigPathInTree(host), (json) => { - const c = json.compilerOptions; - c.paths = c.paths || {}; - delete c.paths[options.name]; - - if (c.paths[options.importPath]) { - throw new Error( - `You already have a library using the import path "${options.importPath}". Make sure to specify a unique one.` - ); - } - - c.paths[options.importPath] = [ - joinPathFragments( - options.projectRoot, - './src', - 'index.' + (options.js ? 'js' : 'ts') - ), - ]; - - return json; - }); -} - -function createFiles(tree: Tree, options: NormalizedSchema) { - const { className, name, propertyName } = names(options.name); - - const rootOffset = offsetFromRoot(options.projectRoot); - generateFiles(tree, join(__dirname, './files/lib'), options.projectRoot, { - ...options, - dot: '.', - className, - name, - propertyName, - js: !!options.js, - cliCommand: 'nx', - strict: undefined, - tmpl: '', - offsetFromRoot: rootOffset, - rootTsConfigPath: getRelativePathToRootTsConfig(tree, options.projectRoot), - hasUnitTestRunner: options.unitTestRunner !== 'none', - hasLinter: options.linter !== 'none', - }); - - if (options.unitTestRunner === 'none') { - tree.delete( - join(options.projectRoot, 'src/lib', `${options.fileName}.spec.ts`) - ); - } - - if (options.skipBabelrc) { - tree.delete(join(options.projectRoot, '.babelrc')); - } - - if (options.js) { - toJS(tree); - } - - if (!options.buildable) { - tree.delete(join(options.projectRoot, 'package.json')); - } - - updateTsConfig(tree, options); -} - -async function addJest( - tree: Tree, - options: NormalizedSchema -): Promise { - const { jestProjectGenerator } = ensurePackage('@nrwl/jest', nxVersion); - return await jestProjectGenerator(tree, { - ...options, - project: options.name, - setupFile: 'none', - supportTsx: true, - babelJest: options.babelJest, - skipSerializers: true, - testEnvironment: options.testEnvironment, - skipFormat: true, - }); -} - -function addTypescript(tree: Tree, options: NormalizedSchema) { - // add tsconfig.base.json - if (!options.skipTsConfig && !getRootTsConfigFileName()) { - generateFiles(tree, joinPathFragments(__dirname, './files/root'), '.', {}); - } - - return !options.js - ? addDependenciesToPackageJson(tree, {}, { typescript: typescriptVersion }) - : () => {}; -} - -export async function libraryGenerator(tree: Tree, schema: Schema) { - const options = normalizeOptions(tree, schema); - const tasks: GeneratorCallback[] = []; - - addTypescript(tree, options); - createFiles(tree, options); - addProject(tree, options); - - if (options.linter !== 'none') { - const lintCallback = await addLint(tree, options); - tasks.push(lintCallback); - } - if (options.unitTestRunner === 'jest') { - const jestCallback = await addJest(tree, options); - tasks.push(jestCallback); - } - if (!options.skipTsConfig) { - updateRootTsConfig(tree, options); - } - - if (!options.skipFormat) { - await formatFiles(tree); - } - - return runTasksInSerial(...tasks); -} - -export default libraryGenerator; -export const librarySchematic = convertNxGenerator(libraryGenerator); - -function normalizeOptions(tree: Tree, options: Schema): NormalizedSchema { - const name = names(options.name).fileName; - const { layoutDirectory, projectDirectory } = extractLayoutDirectory( - options.directory ? `${names(options.directory).fileName}/${name}` : name - ); - - if (!options.unitTestRunner) { - options.unitTestRunner = 'jest'; - } - - if (!options.linter) { - const { Linter } = ensurePackage('@nrwl/linter', nxVersion); - options.linter = Linter.EsLint; - } - - const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-'); - const fileName = getCaseAwareFileName({ - fileName: options.simpleModuleName ? name : projectName, - pascalCaseFiles: options.pascalCaseFiles, - }); - - const { libsDir: defaultLibsDir, npmScope } = getWorkspaceLayout(tree); - const libsDir = layoutDirectory ?? defaultLibsDir; - - const projectRoot = joinPathFragments(libsDir, projectDirectory); - - const parsedTags = options.tags - ? options.tags.split(',').map((s) => s.trim()) - : []; - - const importPath = - options.importPath || getImportPath(npmScope, projectDirectory); - - return { - ...options, - fileName, - name: projectName, - projectRoot, - projectDirectory, - parsedTags, - importPath, - libsDir, - }; -} - -function getCaseAwareFileName(options: { - pascalCaseFiles: boolean; - fileName: string; -}) { - const normalized = names(options.fileName); - - return options.pascalCaseFiles ? normalized.className : normalized.fileName; -} diff --git a/packages/workspace/src/generators/library/schema.d.ts b/packages/workspace/src/generators/library/schema.d.ts deleted file mode 100644 index c9dae74e971559..00000000000000 --- a/packages/workspace/src/generators/library/schema.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -// nx-ignore-next-line -const { Linter } = require('@nrwl/linter'); - -export interface Schema { - name: string; - directory?: string; - skipTsConfig?: boolean; - skipFormat?: boolean; - tags?: string; - simpleModuleName?: boolean; - unitTestRunner?: 'jest' | 'none'; - linter?: Linter; - testEnvironment?: 'jsdom' | 'node'; - importPath?: string; - js?: boolean; - babelJest?: boolean; - pascalCaseFiles?: boolean; - strict?: boolean; - skipBabelrc?: boolean; - buildable?: boolean; - setParserOptionsProject?: boolean; - standaloneConfig?: boolean; -} diff --git a/packages/workspace/src/generators/library/schema.json b/packages/workspace/src/generators/library/schema.json deleted file mode 100644 index 36fece6dee8886..00000000000000 --- a/packages/workspace/src/generators/library/schema.json +++ /dev/null @@ -1,112 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "$id": "NxTypescriptLibrary", - "cli": "nx", - "title": "Create a TypeScript Library", - "description": "Create a TypeScript Library.", - "type": "object", - "examples": [ - { - "command": "nx g lib mylib --directory=myapp", - "description": "Generate `libs/myapp/mylib`" - } - ], - "properties": { - "name": { - "type": "string", - "description": "Library name.", - "$default": { - "$source": "argv", - "index": 0 - }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "^[a-zA-Z].*$" - }, - "directory": { - "type": "string", - "description": "A directory where the lib is placed.", - "x-priority": "important" - }, - "linter": { - "description": "The tool to use for running lint checks.", - "type": "string", - "enum": ["eslint"], - "default": "eslint" - }, - "unitTestRunner": { - "type": "string", - "enum": ["jest", "none"], - "description": "Test runner to use for unit tests.", - "default": "jest" - }, - "tags": { - "type": "string", - "description": "Add tags to the library (used for linting)." - }, - "skipFormat": { - "description": "Skip formatting files.", - "type": "boolean", - "default": false, - "x-priority": "internal" - }, - "skipTsConfig": { - "type": "boolean", - "description": "Do not update `tsconfig.json` for development experience.", - "default": false - }, - "testEnvironment": { - "type": "string", - "enum": ["jsdom", "node"], - "description": "The test environment to use if `unitTestRunner` is set to `jest`.", - "default": "jsdom" - }, - "importPath": { - "type": "string", - "description": "The library name used to import it, like `@myorg/my-awesome-lib`.", - "x-priority": "important" - }, - "babelJest": { - "type": "boolean", - "description": "Use `babel` instead `ts-jest`.", - "default": false - }, - "pascalCaseFiles": { - "type": "boolean", - "description": "Use pascal case file names.", - "alias": "P", - "default": false - }, - "js": { - "type": "boolean", - "description": "Generate JavaScript files rather than TypeScript files.", - "default": false - }, - "strict": { - "type": "boolean", - "description": "Whether to enable `tsconfig` strict mode or not.", - "default": true - }, - "skipBabelrc": { - "type": "boolean", - "description": "Do not generate `.babelrc` file. Useful for Node libraries that are not compiled by Babel.", - "default": false - }, - "buildable": { - "type": "boolean", - "default": false, - "description": "Generate a buildable library." - }, - "setParserOptionsProject": { - "type": "boolean", - "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.", - "default": false - }, - "standaloneConfig": { - "description": "Split the project configuration into `/project.json` rather than including it inside `workspace.json`.", - "type": "boolean", - "default": true, - "x-deprecated": "Nx only supports standaloneConfig" - } - }, - "required": ["name"] -} diff --git a/packages/workspace/src/generators/move/lib/check-destination.spec.ts b/packages/workspace/src/generators/move/lib/check-destination.spec.ts index 13acfcf1f4e768..9a921dfcb18276 100644 --- a/packages/workspace/src/generators/move/lib/check-destination.spec.ts +++ b/packages/workspace/src/generators/move/lib/check-destination.spec.ts @@ -1,4 +1,6 @@ import { + ensurePackage, + NX_VERSION, ProjectConfiguration, readProjectConfiguration, Tree, @@ -6,7 +8,9 @@ import { import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Schema } from '../schema'; import { checkDestination } from './check-destination'; -import { libraryGenerator } from '../../library/library'; + +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); describe('checkDestination', () => { let tree: Tree; @@ -36,7 +40,6 @@ describe('checkDestination', () => { it('should throw an error if the path already exists', async () => { await libraryGenerator(tree, { name: 'my-other-lib', - standaloneConfig: false, }); const schema: Schema = { diff --git a/packages/workspace/src/generators/move/lib/move-project-files.spec.ts b/packages/workspace/src/generators/move/lib/move-project-files.spec.ts index 61dbea3d14264c..dfff34e7b4d69e 100644 --- a/packages/workspace/src/generators/move/lib/move-project-files.spec.ts +++ b/packages/workspace/src/generators/move/lib/move-project-files.spec.ts @@ -1,20 +1,24 @@ import { + ensurePackage, + NX_VERSION, ProjectConfiguration, readProjectConfiguration, Tree, } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator } from '../../library/library'; import { NormalizedSchema } from '../schema'; import { moveProjectFiles } from './move-project-files'; +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); + describe('moveProject', () => { let tree: Tree; let projectConfig: ProjectConfiguration; beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await libraryGenerator(tree, { name: 'my-lib', standaloneConfig: false }); + await libraryGenerator(tree, { name: 'my-lib' }); projectConfig = readProjectConfiguration(tree, 'my-lib'); }); diff --git a/packages/workspace/src/generators/move/lib/update-cypress-config.spec.ts b/packages/workspace/src/generators/move/lib/update-cypress-config.spec.ts index fe66d7f0a92741..b5d31afa660df4 100644 --- a/packages/workspace/src/generators/move/lib/update-cypress-config.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-cypress-config.spec.ts @@ -1,4 +1,6 @@ import { + ensurePackage, + NX_VERSION, ProjectConfiguration, readJson, readProjectConfiguration, @@ -6,10 +8,12 @@ import { writeJson, } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator } from '../../library/library'; import { NormalizedSchema } from '../schema'; import { updateCypressConfig } from './update-cypress-config'; +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); + describe('updateCypressConfig', () => { let tree: Tree; let schema: NormalizedSchema; diff --git a/packages/workspace/src/generators/move/lib/update-eslintrc-json.spec.ts b/packages/workspace/src/generators/move/lib/update-eslintrc-json.spec.ts index 9a356d964334cd..d10cd84d1af9f5 100644 --- a/packages/workspace/src/generators/move/lib/update-eslintrc-json.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-eslintrc-json.spec.ts @@ -1,4 +1,6 @@ import { + ensurePackage, + NX_VERSION, readJson, readProjectConfiguration, Tree, @@ -6,10 +8,12 @@ import { } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Linter } from '../../../utils/lint'; -import { libraryGenerator } from '../../library/library'; import { NormalizedSchema } from '../schema'; import { updateEslintrcJson } from './update-eslintrc-json'; +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); + describe('updateEslint', () => { let tree: Tree; let schema: NormalizedSchema; diff --git a/packages/workspace/src/generators/move/lib/update-imports.spec.ts b/packages/workspace/src/generators/move/lib/update-imports.spec.ts index 27ad6b9661e514..fefe65c97afb52 100644 --- a/packages/workspace/src/generators/move/lib/update-imports.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-imports.spec.ts @@ -1,10 +1,18 @@ -import { readJson, readProjectConfiguration, Tree } from '@nrwl/devkit'; +import { + ensurePackage, + NX_VERSION, + readJson, + readProjectConfiguration, + Tree, +} from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator } from '../../library/library'; import { Schema } from '../schema'; import { updateImports } from './update-imports'; import { normalizeSchema } from './normalize-schema'; +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); + describe('updateImports', () => { let tree: Tree; let schema: Schema; @@ -25,6 +33,7 @@ describe('updateImports', () => { // source and destination to make sure that the workspace has libraries with those names. await libraryGenerator(tree, { name: 'my-destination', + config: 'project', }); await libraryGenerator(tree, { name: 'my-source', @@ -247,7 +256,7 @@ describe('updateImports', () => { tree.write( importerFilePath, `import { MyClass } from '@proj/my-source'; - + export MyExtendedClass extends MyClass {};` ); schema.updateImportPath = false; diff --git a/packages/workspace/src/generators/move/lib/update-jest-config.spec.ts b/packages/workspace/src/generators/move/lib/update-jest-config.spec.ts index 6a2b2388566be5..6f6aed0b4e021a 100644 --- a/packages/workspace/src/generators/move/lib/update-jest-config.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-jest-config.spec.ts @@ -1,9 +1,16 @@ -import { readProjectConfiguration, Tree } from '@nrwl/devkit'; +import { + ensurePackage, + NX_VERSION, + readProjectConfiguration, + Tree, +} from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator } from '../../library/library'; import { NormalizedSchema } from '../schema'; import { updateJestConfig } from './update-jest-config'; +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); + describe('updateJestConfig', () => { let tree: Tree; @@ -148,7 +155,7 @@ describe('updateJestConfig', () => { tree.write( rootJestConfigPath, `const { getJestProjects } = require('@nrwl/jest'); - + module.exports = { projects: [...getJestProjects(), '/libs/some/test/dir/my-source'] }; @@ -187,7 +194,7 @@ module.exports = { tree.write( rootJestConfigPath, `const { getJestProjects } = require('@nrwl/jest'); - + module.exports = { projects: [...getJestProjects(), '/libs/some/test/dir/my-source', '/libs/foo'] }; diff --git a/packages/workspace/src/generators/move/lib/update-package-json.spec.ts b/packages/workspace/src/generators/move/lib/update-package-json.spec.ts index cf764e5eabc4d6..9bbe6955332154 100644 --- a/packages/workspace/src/generators/move/lib/update-package-json.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-package-json.spec.ts @@ -1,9 +1,17 @@ -import { readJson, Tree, writeJson } from '@nrwl/devkit'; +import { + ensurePackage, + NX_VERSION, + readJson, + Tree, + writeJson, +} from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator } from '../../library/library'; import { NormalizedSchema } from '../schema'; import { updatePackageJson } from './update-package-json'; +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); + describe('updatePackageJson', () => { let tree: Tree; let schema: NormalizedSchema; diff --git a/packages/workspace/src/generators/move/lib/update-project-root-files.spec.ts b/packages/workspace/src/generators/move/lib/update-project-root-files.spec.ts index 20f661f1d5c731..2e5d7354f6484d 100644 --- a/packages/workspace/src/generators/move/lib/update-project-root-files.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-project-root-files.spec.ts @@ -1,9 +1,16 @@ -import { readProjectConfiguration, Tree } from '@nrwl/devkit'; +import { + ensurePackage, + NX_VERSION, + readProjectConfiguration, + Tree, +} from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator } from '../../library/library'; import { NormalizedSchema } from '../schema'; import { updateProjectRootFiles } from './update-project-root-files'; +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); + describe('updateProjectRootFiles', () => { let tree: Tree; diff --git a/packages/workspace/src/generators/move/lib/update-readme.spec.ts b/packages/workspace/src/generators/move/lib/update-readme.spec.ts index 726617b4a51d14..8245dbaab8859d 100644 --- a/packages/workspace/src/generators/move/lib/update-readme.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-readme.spec.ts @@ -1,10 +1,12 @@ -import { Tree } from '@nrwl/devkit'; +import { ensurePackage, NX_VERSION, Tree } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { join } from 'path'; -import { libraryGenerator } from '../../library/library'; import { NormalizedSchema } from '../schema'; import { updateReadme } from './update-readme'; +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); + describe('updateReadme', () => { let tree: Tree; let schema: NormalizedSchema; diff --git a/packages/workspace/src/generators/move/lib/update-storybook-config.spec.ts b/packages/workspace/src/generators/move/lib/update-storybook-config.spec.ts index 0c7130ef9006b9..8c170e88711774 100644 --- a/packages/workspace/src/generators/move/lib/update-storybook-config.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-storybook-config.spec.ts @@ -1,9 +1,16 @@ -import { readProjectConfiguration, Tree } from '@nrwl/devkit'; +import { + ensurePackage, + NX_VERSION, + readProjectConfiguration, + Tree, +} from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator } from '../../library/library'; import { NormalizedSchema } from '../schema'; import { updateStorybookConfig } from './update-storybook-config'; +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); + describe('updateStorybookConfig', () => { let tree: Tree; diff --git a/packages/workspace/src/generators/move/move.spec.ts b/packages/workspace/src/generators/move/move.spec.ts index 34bc313db7ec1b..26b8eb72640708 100644 --- a/packages/workspace/src/generators/move/move.spec.ts +++ b/packages/workspace/src/generators/move/move.spec.ts @@ -1,7 +1,8 @@ -import { readJson, Tree } from '@nrwl/devkit'; +import { ensurePackage, NX_VERSION, readJson, Tree } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { moveGenerator } from './move'; -import { libraryGenerator } from '../library/library'; + +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); describe('move', () => { let tree: Tree; diff --git a/packages/workspace/src/generators/remove/lib/check-dependencies.spec.ts b/packages/workspace/src/generators/remove/lib/check-dependencies.spec.ts index 4cebf93104f4c2..69c39889ab80f6 100644 --- a/packages/workspace/src/generators/remove/lib/check-dependencies.spec.ts +++ b/packages/workspace/src/generators/remove/lib/check-dependencies.spec.ts @@ -8,7 +8,7 @@ import { import { Schema } from '../schema'; import { checkDependencies } from './check-dependencies'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { libraryGenerator } from '../../library/library'; +// import { libraryGenerator } from '../../library/library'; // let projectGraph: ProjectGraph; // jest.mock('../../../core/project-graph', () => ({ // ...jest.requireActual('../../../core/project-graph'), diff --git a/packages/workspace/src/generators/remove/lib/remove-project.spec.ts b/packages/workspace/src/generators/remove/lib/remove-project.spec.ts index b74617ac772e8f..2d3ef6bd3b4979 100644 --- a/packages/workspace/src/generators/remove/lib/remove-project.spec.ts +++ b/packages/workspace/src/generators/remove/lib/remove-project.spec.ts @@ -1,9 +1,16 @@ -import { readProjectConfiguration, Tree } from '@nrwl/devkit'; +import { + ensurePackage, + NX_VERSION, + readProjectConfiguration, + Tree, +} from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Schema } from '../schema'; -import { libraryGenerator } from '../../library/library'; import { removeProject } from '@nrwl/workspace/src/generators/remove/lib/remove-project'; +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); + describe('moveProject', () => { let schema: Schema; let tree: Tree; diff --git a/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts b/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts index 61db43f1b0e390..566a3c8f94cad7 100644 --- a/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts +++ b/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts @@ -1,4 +1,9 @@ -import { readProjectConfiguration, Tree } from '@nrwl/devkit'; +import { + ensurePackage, + NX_VERSION, + readProjectConfiguration, + Tree, +} from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { readFileSync } from 'fs'; @@ -6,7 +11,9 @@ import { join } from 'path'; import { Schema } from '../schema'; import { updateJestConfig } from './update-jest-config'; -import { libraryGenerator } from '../../library/library'; + +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); describe('updateRootJestConfig', () => { let tree: Tree; diff --git a/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts b/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts index 056ef413849068..900537c9d6bab7 100644 --- a/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts +++ b/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts @@ -1,4 +1,6 @@ import { + ensurePackage, + NX_VERSION, ProjectGraph, readJson, readProjectConfiguration, @@ -7,7 +9,9 @@ import { import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Schema } from '../schema'; import { updateTsconfig } from './update-tsconfig'; -import { libraryGenerator } from '../../library/library'; + +// avoid circular deps +const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); let graph: ProjectGraph; jest.mock('@nrwl/devkit', () => { diff --git a/packages/workspace/src/generators/run-commands/run-commands.spec.ts b/packages/workspace/src/generators/run-commands/run-commands.spec.ts index 0a111177bdd7ff..7f8137d37d1596 100644 --- a/packages/workspace/src/generators/run-commands/run-commands.spec.ts +++ b/packages/workspace/src/generators/run-commands/run-commands.spec.ts @@ -1,6 +1,6 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import runCommands from './run-commands'; -import { libraryGenerator } from '../library/library'; +import { ensurePackage, NX_VERSION } from '@nrwl/devkit'; import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; describe('run-commands', () => { @@ -14,6 +14,8 @@ describe('run-commands', () => { outputs: 'dist/a, dist/b, dist/c', }; + // avoid circular deps + const { libraryGenerator } = ensurePackage('@nrwl/js', NX_VERSION); await libraryGenerator(tree, { name: 'lib', }); diff --git a/packages/workspace/src/generators/workspace-generator/files/index.ts__tmpl__ b/packages/workspace/src/generators/workspace-generator/files/index.ts__tmpl__ index 1bbe1f066df96d..a3857c16f33536 100644 --- a/packages/workspace/src/generators/workspace-generator/files/index.ts__tmpl__ +++ b/packages/workspace/src/generators/workspace-generator/files/index.ts__tmpl__ @@ -1,5 +1,5 @@ import { Tree, formatFiles, installPackagesTask } from '@nrwl/devkit'; -import { libraryGenerator } from '@nrwl/workspace/generators'; +import { libraryGenerator } from '@nrwl/js'; export default async function(tree: Tree, schema: any) { await libraryGenerator(tree, {name: schema.name});