From cafb49ac846b4f585272d85ef8823cdf899ab031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Jona=C5=A1?= Date: Wed, 12 Apr 2023 21:28:09 +0200 Subject: [PATCH] feat(core): remove @nrwl/workspace:lib (#16122) --- docs/generated/manifests/menus.json | 8 - docs/generated/manifests/packages.json | 9 - docs/generated/packages-metadata.json | 9 - .../packages/web/documents/overview.md | 5 +- docs/shared/deprecated/default-collection.md | 1 - docs/shared/packages/web/web-plugin.md | 5 +- .../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/js/src/js.test.ts | 75 +- 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 | 465 +++++----- e2e/nx-run/src/cache.test.ts | 2 +- e2e/nx-run/src/invoke-runner.test.ts | 22 +- e2e/nx-run/src/run.test.ts | 6 +- e2e/utils/test-utils.ts | 1 - 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 | 6 +- .../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 | 5 - .../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 +- .../src/generators/application/application.ts | 6 - 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 | 5 +- .../move/lib/move-project-files.spec.ts | 6 +- .../move/lib/update-cypress-config.spec.ts | 4 +- .../move/lib/update-eslintrc-json.spec.ts | 4 +- .../move/lib/update-imports.spec.ts | 7 +- .../move/lib/update-jest-config.spec.ts | 8 +- .../generators/move/lib/update-jest-config.ts | 6 +- .../move/lib/update-package-json.spec.ts | 4 +- .../lib/update-project-root-files.spec.ts | 4 +- .../generators/move/lib/update-readme.spec.ts | 4 +- .../move/lib/update-storybook-config.spec.ts | 4 +- .../src/generators/move/move.spec.ts | 4 +- .../remove/lib/check-dependencies.spec.ts | 2 +- .../remove/lib/remove-project.spec.ts | 4 +- .../remove/lib/update-jest-config.spec.ts | 4 +- .../remove/lib/update-tsconfig.spec.ts | 4 +- .../run-commands/run-commands.spec.ts | 4 +- .../files/index.ts__tmpl__ | 2 +- 82 files changed, 430 insertions(+), 1775 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 914dfae4d0a36..af9c7a3b5dc02 100644 --- a/docs/generated/manifests/menus.json +++ b/docs/generated/manifests/menus.json @@ -6762,14 +6762,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 5b374ba9183d2..7c0dcdc7cab4f 100644 --- a/docs/generated/manifests/packages.json +++ b/docs/generated/manifests/packages.json @@ -3006,15 +3006,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 0879f2e7c0a47..1714a33ddc44a 100644 --- a/docs/generated/packages-metadata.json +++ b/docs/generated/packages-metadata.json @@ -2974,15 +2974,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/generated/packages/web/documents/overview.md b/docs/generated/packages/web/documents/overview.md index c84eb6f06519b..dcd117ec4ee12 100644 --- a/docs/generated/packages/web/documents/overview.md +++ b/docs/generated/packages/web/documents/overview.md @@ -41,9 +41,8 @@ To create a generic TypeScript library (i.e. non-framework specific), use the [` ```shell nx g @nrwl/js:lib my-new-lib -# If you want the library to be buildable or publishable to npm -nx g @nrwl/web:lib my-new-lib --buildable -nx g @nrwl/web:lib my-new-lib \ +# If you want the library to be publishable to npm +nx g @nrwl/js:lib my-new-lib \ --publishable \ --importPath=@myorg/my-new-lib ``` diff --git a/docs/shared/deprecated/default-collection.md b/docs/shared/deprecated/default-collection.md index fa50a2c0d5a1e..8cdd285fddd83 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/packages/web/web-plugin.md b/docs/shared/packages/web/web-plugin.md index c84eb6f06519b..dcd117ec4ee12 100644 --- a/docs/shared/packages/web/web-plugin.md +++ b/docs/shared/packages/web/web-plugin.md @@ -41,9 +41,8 @@ To create a generic TypeScript library (i.e. non-framework specific), use the [` ```shell nx g @nrwl/js:lib my-new-lib -# If you want the library to be buildable or publishable to npm -nx g @nrwl/web:lib my-new-lib --buildable -nx g @nrwl/web:lib my-new-lib \ +# If you want the library to be publishable to npm +nx g @nrwl/js:lib my-new-lib \ --publishable \ --importPath=@myorg/my-new-lib ``` diff --git a/docs/shared/recipes/generators/composing-generators.md b/docs/shared/recipes/generators/composing-generators.md index d0ca6f9920566..ad64ee88df18d 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 35154b71dd941..01d9fe1f9507e 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 09d0df483a5c3..2812eb41f35a0 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 27bcb360f923a..22dbc676a542c 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 be7a96f08ad5e..689e56e0194e5 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/js/src/js.test.ts b/e2e/js/src/js.test.ts index 4ab8cced35d0d..dd38f365f5bca 100644 --- a/e2e/js/src/js.test.ts +++ b/e2e/js/src/js.test.ts @@ -1,10 +1,12 @@ import { + checkFilesDoNotExist, + checkFilesExist, cleanupProject, createFile, - expectJestTestsToPass, newProject, readJson, runCLI, + runCLIAsync, uniq, updateFile, updateJson, @@ -87,7 +89,72 @@ export function ${lib}Wildcard() { ); }, 240_000); - it('should run default jest tests', async () => { - await expectJestTestsToPass('@nrwl/js:lib'); - }, 240_000); + it('should create a library that can be linted and tested', async () => { + const libName = uniq('mylib'); + const dirName = uniq('dir'); + + runCLI(`generate @nrwl/js:lib ${libName} --directory ${dirName}`); + + checkFilesExist( + `libs/${dirName}/${libName}/src/index.ts`, + `libs/${dirName}/${libName}/README.md` + ); + + // Lint + const result = runCLI(`lint ${dirName}-${libName}`); + + expect(result).toContain(`Linting "${dirName}-${libName}"...`); + expect(result).toContain('All files pass linting.'); + + // Test + const testResult = await runCLIAsync(`test ${dirName}-${libName}`); + expect(testResult.combinedOutput).toContain( + 'Test Suites: 1 passed, 1 total' + ); + }, 500_000); + + it('should be able to use and be used by other libs', () => { + const consumerLib = uniq('consumer'); + const producerLib = uniq('producer'); + + runCLI(`generate @nrwl/js:lib ${consumerLib} --bundler=none`); + runCLI(`generate @nrwl/js:lib ${producerLib} --bundler=none`); + + updateFile( + `libs/${producerLib}/src/lib/${producerLib}.ts`, + 'export const a = 0;' + ); + + updateFile( + `libs/${consumerLib}/src/lib/${consumerLib}.ts`, + ` + import { a } from '@${scope}/${producerLib}'; + + export function ${consumerLib}() { + return a + 1; + }` + ); + updateFile( + `libs/${consumerLib}/src/lib/${consumerLib}.spec.ts`, + ` + import { ${consumerLib} } from './${consumerLib}'; + + describe('', () => { + it('should return 1', () => { + expect(${consumerLib}()).toEqual(1); + }); + });` + ); + + runCLI(`test ${consumerLib}`); + }); + + it('should not be able to be built when it has no bundler', () => { + const nonBuildable = uniq('buildable'); + runCLI(`generate @nrwl/js:lib ${nonBuildable} --bundler=none`); + + expect(() => runCLI(`build ${nonBuildable}`)).toThrow(); + + checkFilesDoNotExist(`dist/libs/${nonBuildable}/README.md`); + }); }); diff --git a/e2e/linter/src/linter.test.ts b/e2e/linter/src/linter.test.ts index c4262b69275fb..8c1c2fd7ef56d 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 86f68e047ab2f..37cf4e6551bb3 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 513810de6e176..8246423c78f52 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 8daa1d4b8aa71..b67e687cebb17 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 3c6aa105e396b..e15b3144734cd 100644 --- a/e2e/nx-misc/src/workspace.test.ts +++ b/e2e/nx-misc/src/workspace.test.ts @@ -6,7 +6,6 @@ import { runCLI, uniq, updateFile, - expectJestTestsToPass, readFile, exists, updateProjectConfig, @@ -16,6 +15,7 @@ import { getPackageManagerCommand, getSelectedPackageManager, runCommand, + runCreateWorkspace, } from '@nrwl/e2e/utils'; let proj: string; @@ -27,86 +27,6 @@ describe('Workspace Tests', () => { afterAll(() => cleanupProject()); - describe('@nrwl/workspace: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}`); - - checkFilesExist( - `libs/${dirName}/${libName}/src/index.ts`, - `libs/${dirName}/${libName}/README.md` - ); - - // Lint - const result = runCLI(`lint ${dirName}-${libName}`); - - expect(result).toContain(`Linting "${dirName}-${libName}"...`); - expect(result).toContain('All files pass linting.'); - - // Test - await expectJestTestsToPass('@nrwl/workspace: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}`); - - updateFile( - `libs/${producerLib}/src/lib/${producerLib}.ts`, - 'export const a = 0;' - ); - - updateFile( - `libs/${consumerLib}/src/lib/${consumerLib}.ts`, - ` - import { a } from '@${proj}/${producerLib}'; - - export function ${consumerLib}() { - return a + 1; - }` - ); - updateFile( - `libs/${consumerLib}/src/lib/${consumerLib}.spec.ts`, - ` - import { ${consumerLib} } from './${consumerLib}'; - - describe('', () => { - it('should return 1', () => { - expect(${consumerLib}()).toEqual(1); - }); - });` - ); - - runCLI(`test ${consumerLib}`); - }); - - it('should be able to be built when it is buildable', () => { - const buildableLib = uniq('buildable'); - - runCLI(`generate @nrwl/workspace:lib ${buildableLib} --buildable`); - - const result = runCLI(`build ${buildableLib}`); - - expect(result).toContain( - `Compiling TypeScript files for project "${buildableLib}"...` - ); - expect(result).toContain( - `Done compiling TypeScript files for project "${buildableLib}".` - ); - - checkFilesExist(`dist/libs/${buildableLib}/README.md`); - - const json = readJson(`dist/libs/${buildableLib}/package.json`); - expect(json.main).toEqual('./src/index.js'); - expect(json.types).toEqual('./src/index.d.ts'); - }); - }); - describe('@nrwl/workspace:npm-package', () => { it('should create a minimal npm package', () => { const npmPackage = uniq('npm-package'); @@ -130,178 +50,6 @@ describe('Workspace Tests', () => { }); }); - describe('workspace-generator', () => { - let custom: string; - let failing: string; - - beforeEach(() => { - custom = uniq('custom'); - failing = uniq('custom-failing'); - runCLI( - `g @nrwl/workspace:workspace-generator ${custom} --no-interactive` - ); - runCLI( - `g @nrwl/workspace:workspace-generator ${failing} --no-interactive` - ); - - checkFilesExist( - `tools/generators/${custom}/index.ts`, - `tools/generators/${custom}/schema.json` - ); - checkFilesExist( - `tools/generators/${failing}/index.ts`, - `tools/generators/${failing}/schema.json` - ); - }); - - it('should compile only generator files with dependencies', () => { - const workspace = uniq('workspace'); - - updateFile( - 'tools/utils/command-line-utils.ts', - ` - export const noop = () => {} - ` - ); - updateFile( - 'tools/utils/logger.ts', - ` - export const log = (...args: any[]) => console.log(...args) - ` - ); - updateFile( - `tools/generators/utils.ts`, - ` - export const noop = ()=>{} - ` - ); - updateFile(`tools/generators/${custom}/index.ts`, (content) => { - return ` - import { log } from '../../utils/logger'; \n - ${content} - `; - }); - - runCLI(`workspace-generator ${custom} ${workspace} --no-interactive -d`); - - expect(() => - checkFilesExist( - `dist/out-tsc/tools/generators/${custom}/index.js`, - `dist/out-tsc/tools/generators/utils.js`, - `dist/out-tsc/tools/utils/logger.js` - ) - ).not.toThrow(); - expect(() => - checkFilesExist(`dist/out-tsc/tools/utils/utils.js`) - ).toThrow(); - }); - - it('should support workspace-specific generators', async () => { - const json = readJson(`tools/generators/${custom}/schema.json`); - json.properties['directory'] = { - type: 'string', - description: 'lib directory', - }; - json.properties['skipTsConfig'] = { - type: 'boolean', - description: 'skip changes to tsconfig', - }; - json.properties['inlineprop'] = json.properties['name']; - json.required = ['inlineprop']; - delete json.properties['name']; - - updateFile( - `tools/generators/${custom}/schema.json`, - JSON.stringify(json) - ); - - const indexFile = readFile(`tools/generators/${custom}/index.ts`); - updateFile( - `tools/generators/${custom}/index.ts`, - indexFile.replace( - 'name: schema.name', - 'name: schema.inlineprop, directory: schema.directory, skipTsConfig: schema.skipTsConfig' - ) - ); - - const helpOutput = runCLI(`workspace-generator ${custom} --help`); - expect(helpOutput).toContain( - `workspace-generator ${custom} [inlineprop] (options)` - ); - expect(helpOutput).toContain(`--directory`); - expect(helpOutput).toContain(`--skipTsConfig`); - - const workspace = uniq('workspace'); - const dryRunOutput = runCLI( - `workspace-generator ${custom} ${workspace} --no-interactive --directory=dir --skipTsConfig=true -d` - ); - expect(exists(`libs/dir/${workspace}/src/index.ts`)).toEqual(false); - expect(dryRunOutput).toContain( - `CREATE libs/dir/${workspace}/src/index.ts` - ); - - runCLI( - `workspace-generator ${custom} ${workspace} --no-interactive --directory=dir` - ); - checkFilesExist(`libs/dir/${workspace}/src/index.ts`); - - const jsonFailing = readJson(`tools/generators/${failing}/schema.json`); - jsonFailing.properties = {}; - jsonFailing.required = []; - updateFile( - `tools/generators/${failing}/schema.json`, - JSON.stringify(jsonFailing) - ); - - updateFile( - `tools/generators/${failing}/index.ts`, - ` - export default function() { - throw new Error(); - } - ` - ); - - try { - await runCLI(`workspace-generator ${failing} --no-interactive`); - fail(`Should exit 1 for a workspace-generator that throws an error`); - } catch (e) {} - - const listOutput = runCLI('workspace-generator --list-generators'); - expect(listOutput).toContain(custom); - expect(listOutput).toContain(failing); - }, 1000000); - - it('should support angular devkit schematics', () => { - const angularDevkitSchematic = uniq('angular-devkit-schematic'); - runCLI( - `g @nrwl/workspace:workspace-generator ${angularDevkitSchematic} --no-interactive` - ); - - const json = readJson( - `tools/generators/${angularDevkitSchematic}/schema.json` - ); - json.properties = {}; - json.required = []; - delete json.cli; - updateFile( - `tools/generators/${angularDevkitSchematic}/schema.json`, - JSON.stringify(json) - ); - - updateFile( - `tools/generators/${angularDevkitSchematic}/index.ts`, - ` - export default function() { - return (tree) => tree; - } - ` - ); - - runCLI(`workspace-generator ${angularDevkitSchematic} --no-interactive`); - }); - }); - describe('move project', () => { /** * Tries moving a library from ${lib}/data-access -> shared/${lib}/data-access @@ -310,7 +58,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 +74,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 +87,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 +194,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 +211,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 +224,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 +327,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 +343,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 +356,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 +455,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 +471,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 +484,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 +589,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 +612,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 +625,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 +703,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; @@ -1008,3 +756,180 @@ describe('Workspace Tests', () => { }); }); }); + +describe('workspace-generator', () => { + const packageManager = getSelectedPackageManager() || 'pnpm'; + const proj = uniq('workspace'); + + beforeAll(() => { + runCreateWorkspace(proj, { + preset: 'ts', + packageManager, + }); + }); + + afterAll(() => cleanupProject()); + + let custom: string; + let failing: string; + + beforeEach(() => { + custom = uniq('custom'); + failing = uniq('custom-failing'); + runCLI(`g @nrwl/workspace:workspace-generator ${custom} --no-interactive`); + runCLI(`g @nrwl/workspace:workspace-generator ${failing} --no-interactive`); + + checkFilesExist( + `tools/generators/${custom}/index.ts`, + `tools/generators/${custom}/schema.json` + ); + checkFilesExist( + `tools/generators/${failing}/index.ts`, + `tools/generators/${failing}/schema.json` + ); + }); + + it('should compile only generator files with dependencies', () => { + const workspace = uniq('workspace'); + + updateFile( + 'tools/utils/command-line-utils.ts', + ` + export const noop = () => {} + ` + ); + updateFile( + 'tools/utils/logger.ts', + ` + export const log = (...args: any[]) => console.log(...args) + ` + ); + updateFile( + `tools/generators/utils.ts`, + ` + export const noop = ()=>{} + ` + ); + updateFile(`tools/generators/${custom}/index.ts`, (content) => { + return ` + import { log } from '../../utils/logger'; \n + ${content} + `; + }); + + runCLI(`workspace-generator ${custom} ${workspace} --no-interactive -d`); + + expect(() => + checkFilesExist( + `dist/out-tsc/tools/generators/${custom}/index.js`, + `dist/out-tsc/tools/generators/utils.js`, + `dist/out-tsc/tools/utils/logger.js` + ) + ).not.toThrow(); + expect(() => + checkFilesExist(`dist/out-tsc/tools/utils/utils.js`) + ).toThrow(); + }); + + it('should support workspace-specific generators', async () => { + const json = readJson(`tools/generators/${custom}/schema.json`); + json.properties['directory'] = { + type: 'string', + description: 'lib directory', + }; + json.properties['skipTsConfig'] = { + type: 'boolean', + description: 'skip changes to tsconfig', + }; + json.properties['inlineprop'] = json.properties['name']; + json.required = ['inlineprop']; + delete json.properties['name']; + + updateFile(`tools/generators/${custom}/schema.json`, JSON.stringify(json)); + + const indexFile = readFile(`tools/generators/${custom}/index.ts`); + updateFile( + `tools/generators/${custom}/index.ts`, + indexFile.replace( + 'name: schema.name', + 'name: schema.inlineprop, directory: schema.directory, skipTsConfig: schema.skipTsConfig' + ) + ); + + const helpOutput = runCLI(`workspace-generator ${custom} --help`); + expect(helpOutput).toContain( + `workspace-generator ${custom} [inlineprop] (options)` + ); + expect(helpOutput).toContain(`--directory`); + expect(helpOutput).toContain(`--skipTsConfig`); + + const workspace = uniq('workspace'); + const dryRunOutput = runCLI( + `workspace-generator ${custom} ${workspace} --no-interactive --directory=dir --skipTsConfig=true -d` + ); + expect(exists(`packages/dir/${workspace}/src/index.ts`)).toEqual(false); + expect(dryRunOutput).toContain( + `CREATE packages/dir/${workspace}/src/index.ts` + ); + + runCLI( + `workspace-generator ${custom} ${workspace} --no-interactive --directory=dir` + ); + checkFilesExist(`packages/dir/${workspace}/src/index.ts`); + + const jsonFailing = readJson(`tools/generators/${failing}/schema.json`); + jsonFailing.properties = {}; + jsonFailing.required = []; + updateFile( + `tools/generators/${failing}/schema.json`, + JSON.stringify(jsonFailing) + ); + + updateFile( + `tools/generators/${failing}/index.ts`, + ` + export default function() { + throw new Error(); + } + ` + ); + + try { + await runCLI(`workspace-generator ${failing} --no-interactive`); + fail(`Should exit 1 for a workspace-generator that throws an error`); + } catch (e) {} + + const listOutput = runCLI('workspace-generator --list-generators'); + expect(listOutput).toContain(custom); + expect(listOutput).toContain(failing); + }, 1000000); + + it('should support angular devkit schematics', () => { + const angularDevkitSchematic = uniq('angular-devkit-schematic'); + runCLI( + `g @nrwl/workspace:workspace-generator ${angularDevkitSchematic} --no-interactive` + ); + + const json = readJson( + `tools/generators/${angularDevkitSchematic}/schema.json` + ); + json.properties = {}; + json.required = []; + delete json.cli; + updateFile( + `tools/generators/${angularDevkitSchematic}/schema.json`, + JSON.stringify(json) + ); + + updateFile( + `tools/generators/${angularDevkitSchematic}/index.ts`, + ` + export default function() { + return (tree) => tree; + } + ` + ); + + runCLI(`workspace-generator ${angularDevkitSchematic} --no-interactive`); + }); +}); diff --git a/e2e/nx-run/src/cache.test.ts b/e2e/nx-run/src/cache.test.ts index 1e3729b34dea0..7412df84cca62 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 5d9faa7b048d5..eb27ab6331aae 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 ffb46fd4eaca2..24441c619bbc8 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:', @@ -333,8 +333,8 @@ describe('Nx Running Tests', () => { mylib1 = uniq('mylib1'); mylib2 = uniq('mylib1'); runCLI(`generate @nrwl/web:app ${myapp}`); - runCLI(`generate @nrwl/web:lib ${mylib1} --buildable`); - runCLI(`generate @nrwl/web:lib ${mylib2} --buildable`); + runCLI(`generate @nrwl/js:lib ${mylib1}`); + runCLI(`generate @nrwl/js:lib ${mylib2}`); updateFile( `apps/${myapp}/src/main.ts`, diff --git a/e2e/utils/test-utils.ts b/e2e/utils/test-utils.ts index 40f8ce77e975d..1504cd8f646ca 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/nx-dev/nx-dev-e2e/src/e2e/packages.cy.ts b/nx-dev/nx-dev-e2e/src/e2e/packages.cy.ts index 9d21af8a50aee..459f2bff00482 100644 --- a/nx-dev/nx-dev-e2e/src/e2e/packages.cy.ts +++ b/nx-dev/nx-dev-e2e/src/e2e/packages.cy.ts @@ -451,10 +451,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 be52ef7c46c8c..2e9e9feb66fae 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 bc5bf7024f1f8..81110731bb57f 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 442781759790f..697919f6375b8 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 959d456759954..485d67e679608 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 e818efe816886..25ff2eeef401e 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 ff9c5bd1b2c68..80b23488e22fd 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 442a9a1c78e39..01eb3f60bd108 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 156ebf2021724..b51ec783cd4c8 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 340613e88ffcf..d91eddd17d149 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 9bea2ef8bce04..60b56502ee4e3 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 4e42f14677190..ed8e71eac7c2f 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 d94e955032091..139cc8531939e 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -434,6 +434,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 f9e62c0d17219..087366cd0463b 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 e35308e847ab7..6f90313a00896 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 3b502bd9cac77..acfeaa5f73578 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 ee20afdb4227f..8ec461dddbc10 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,10 @@ export async function libraryGenerator(tree: Tree, schema: Schema) { ); } - const libraryInstall = await workspaceLibraryGenerator(tree, { + const libraryInstall = await jsLibraryGenerator(tree, { ...schema, + bundler: schema.buildable ? 'tsc' : 'none', + includeBabelRc: schema.babelJest, 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 ee4c851e66d45..24f14904c0014 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 8a73cfac6c931..7af07e9c24ee5 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 63be11c244940..399948d495ceb 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 b36af34ba9bcf..df88fd589da6e 100644 --- a/packages/nx/src/command-line/generate.ts +++ b/packages/nx/src/command-line/generate.ts @@ -1,6 +1,5 @@ import * as chalk from 'chalk'; import { prompt } from 'enquirer'; -import { readJsonFile } from '../utils/fileutils'; import { readNxJson } from '../config/configuration'; import { ProjectsConfigurations } from '../config/workspace-json-project-json'; @@ -234,10 +233,6 @@ async function convertToGenerateOptions( generatorName = 'new'; } - if (!collectionName) { - throwInvalidInvocation(['@nrwl/workspace:library']); - } - const res = { collectionName, generatorName, diff --git a/packages/react-native/src/utils/add-linting.spec.ts b/packages/react-native/src/utils/add-linting.spec.ts index f3975364aa222..0925d6898f29e 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 0cc54d2a6c216..7a3189a5f7d47 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: { @@ -130,7 +130,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) => { @@ -160,7 +159,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 a44bc119e8ebb..a3598298a681c 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 14f89ca4fe316..2da2b928892bb 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 b76491b6d7d54..176770ab1c4a9 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/web/src/generators/application/application.ts b/packages/web/src/generators/application/application.ts index 0f89e7b339d09..bff98f88a287e 100644 --- a/packages/web/src/generators/application/application.ts +++ b/packages/web/src/generators/application/application.ts @@ -176,12 +176,6 @@ function setDefaults(tree: Tree, options: NormalizedSchema) { e2eTestRunner: options.e2eTestRunner, ...nxJson.generators['@nrwl/web:application'], }; - nxJson.generators['@nrwl/web:library'] = { - style: options.style, - linter: options.linter, - unitTestRunner: options.unitTestRunner, - ...nxJson.generators['@nrwl/web:library'], - }; updateNxJson(tree, nxJson); } diff --git a/packages/workspace/generators.json b/packages/workspace/generators.json index 72b4ed655c124..685b08a059a2b 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 9d860fa7307da..89edfe9c32831 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 cae4276052430..3bd716849233c 100644 --- a/packages/workspace/index.ts +++ b/packages/workspace/index.ts @@ -41,7 +41,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 6c5d01351e2ed..0000000000000 --- 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 9cbf9798bc1e9..0000000000000 --- 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 e3a3ad83c46eb..0000000000000 --- 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 32176b3ef175e..0000000000000 --- 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 35b0948b95087..0000000000000 --- 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 ae311e3ac41f0..0000000000000 --- 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 8bf55e434eef1..0000000000000 --- 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 78fad8cab4f08..0000000000000 --- 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 11253ac5c2b7b..0000000000000 --- 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 2bb3ef7cb6e08..0000000000000 --- 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 ad1afb7b431d0..0000000000000 --- 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 c9dae74e97155..0000000000000 --- 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 36fece6dee888..0000000000000 --- 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 13acfcf1f4e76..2cdfa9a795065 100644 --- a/packages/workspace/src/generators/move/lib/check-destination.spec.ts +++ b/packages/workspace/src/generators/move/lib/check-destination.spec.ts @@ -6,7 +6,9 @@ import { import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Schema } from '../schema'; import { checkDestination } from './check-destination'; -import { libraryGenerator } from '../../library/library'; + +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); describe('checkDestination', () => { let tree: Tree; @@ -36,7 +38,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 61dbea3d14264..861489fc03f2b 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 @@ -4,17 +4,19 @@ import { 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'; +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); + 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 fe66d7f0a9274..088242c6eb4af 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 @@ -6,10 +6,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'; +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); + 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 9a356d964334c..a62c100a42dd9 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 @@ -6,10 +6,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'; +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); + 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 27ad6b9661e51..6b57fcf53b759 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,12 @@ import { 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'; +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); + describe('updateImports', () => { let tree: Tree; let schema: Schema; @@ -25,6 +27,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 +250,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 6a2b2388566be..707129c719155 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,11 @@ import { 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'; +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); + describe('updateJestConfig', () => { let tree: Tree; @@ -148,7 +150,7 @@ describe('updateJestConfig', () => { tree.write( rootJestConfigPath, `const { getJestProjects } = require('@nrwl/jest'); - + module.exports = { projects: [...getJestProjects(), '/libs/some/test/dir/my-source'] }; @@ -187,7 +189,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-jest-config.ts b/packages/workspace/src/generators/move/lib/update-jest-config.ts index 256134ac7e8b3..3181aea9bc80e 100644 --- a/packages/workspace/src/generators/move/lib/update-jest-config.ts +++ b/packages/workspace/src/generators/move/lib/update-jest-config.ts @@ -22,7 +22,11 @@ export function updateJestConfig( if (tree.exists(jestConfigPath)) { const oldContent = tree.read(jestConfigPath, 'utf-8'); - const findName = new RegExp(`'${schema.projectName}'`, 'g'); + // ensure both single and double quotes are replaced + const findName = new RegExp( + `'${schema.projectName}'|"${schema.projectName}"|\`${schema.projectName}\``, + 'g' + ); const findDir = new RegExp(project.root, 'g'); const newContent = oldContent 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 cf764e5eabc4d..4d2ee39149a36 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,11 @@ import { 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'; +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); + 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 20f661f1d5c73..2c17898991cb1 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,11 @@ import { 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'; +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); + 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 726617b4a51d1..15cf99cd5160f 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 { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { join } from 'path'; -import { libraryGenerator } from '../../library/library'; import { NormalizedSchema } from '../schema'; import { updateReadme } from './update-readme'; +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); + 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 0c7130ef9006b..3919d1e3f8600 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,11 @@ import { 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'; +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); + 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 34bc313db7ec1..aaa39bba075d6 100644 --- a/packages/workspace/src/generators/move/move.spec.ts +++ b/packages/workspace/src/generators/move/move.spec.ts @@ -1,7 +1,9 @@ import { readJson, Tree } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { moveGenerator } from './move'; -import { libraryGenerator } from '../library/library'; + +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); 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 4cebf93104f4c..69c39889ab80f 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 b74617ac772e8..b00de890980b0 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,11 @@ import { 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'; +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); + 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 215b7c74797ee..0011832cdf849 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 @@ -6,7 +6,9 @@ import { join } from 'path'; import { Schema } from '../schema'; import { updateJestConfig } from './update-jest-config'; -import { libraryGenerator } from '../../library/library'; + +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); 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 056ef41384906..9fb6dcd805d9d 100644 --- a/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts +++ b/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts @@ -7,7 +7,9 @@ import { import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Schema } from '../schema'; import { updateTsconfig } from './update-tsconfig'; -import { libraryGenerator } from '../../library/library'; + +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); 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 0a111177bdd7f..7151bde0b5f7d 100644 --- a/packages/workspace/src/generators/run-commands/run-commands.spec.ts +++ b/packages/workspace/src/generators/run-commands/run-commands.spec.ts @@ -1,8 +1,10 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import runCommands from './run-commands'; -import { libraryGenerator } from '../library/library'; import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; +// nx-ignore-next-line +const { libraryGenerator } = require('@nrwl/js'); + describe('run-commands', () => { it('should generate a target', async () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); 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 1bbe1f066df96..a3857c16f3353 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});