diff --git a/packages/plugin/src/generators/create-package/create-package.spec.ts b/packages/plugin/src/generators/create-package/create-package.spec.ts index b76013fca5ff3f..7ee61f7b3aab18 100644 --- a/packages/plugin/src/generators/create-package/create-package.spec.ts +++ b/packages/plugin/src/generators/create-package/create-package.spec.ts @@ -11,6 +11,8 @@ import pluginGenerator from '../plugin/plugin'; import { createPackageGenerator } from './create-package'; import { CreatePackageSchema } from './schema'; import { setCwd } from '@nx/devkit/internal-testing-utils'; +import { tsLibVersion } from '@nx/js/src/utils/versions'; +import { nxVersion } from 'nx/src/utils/versions'; const getSchema: ( overrides?: Partial @@ -126,4 +128,21 @@ describe('NxPlugin Create Package Generator', () => { expect(name).toEqual('create-a-workspace'); }); + + it("should have valid default package.json's dependencies", async () => { + await createPackageGenerator(tree, getSchema()); + + const { root } = readProjectConfiguration(tree, 'create-a-workspace'); + const { dependencies } = readJson( + tree, + joinPathFragments(root, 'package.json') + ); + + expect(dependencies).toEqual( + expect.objectContaining({ + 'create-nx-workspace': nxVersion, + tslib: tsLibVersion, + }) + ); + }); }); diff --git a/packages/plugin/src/generators/create-package/create-package.ts b/packages/plugin/src/generators/create-package/create-package.ts index 8ee3e9217dd11a..ec0784e99a3a25 100644 --- a/packages/plugin/src/generators/create-package/create-package.ts +++ b/packages/plugin/src/generators/create-package/create-package.ts @@ -13,6 +13,7 @@ import { updateProjectConfiguration, } from '@nx/devkit'; import { libraryGenerator as jsLibraryGenerator } from '@nx/js'; +import { addTsLibDependencies } from '@nx/js/src/utils/typescript/add-tslib-dependencies'; import { nxVersion } from 'nx/src/utils/versions'; import generatorGenerator from '../generator/generator'; import { CreatePackageSchema } from './schema'; @@ -39,6 +40,10 @@ export async function createPackageGeneratorInternal( const options = await normalizeSchema(host, schema); const pluginPackageName = await addPresetGenerator(host, options); + if (options.bundler === 'tsc') { + tasks.push(addTsLibDependencies(host)); + } + const installTask = addDependenciesToPackageJson( host, {