Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(nx-plugin): tslib is not set as a dependency when using create-package generator #22429

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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<CreatePackageSchema>
Expand Down Expand Up @@ -128,4 +130,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<PackageJson>(
tree,
joinPathFragments(root, 'package.json')
);

expect(dependencies).toEqual(
expect.objectContaining({
'create-nx-workspace': nxVersion,
tslib: tsLibVersion,
})
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ 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';
import { NormalizedSchema, normalizeSchema } from './utils/normalize-schema';
import { hasGenerator } from '../../utils/has-generator';
import { join } from 'path';
import { tsLibVersion } from '@nx/js/src/utils/versions';

export async function createPackageGenerator(
host: Tree,
Expand All @@ -39,6 +41,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,
{
Expand Down Expand Up @@ -112,6 +118,7 @@ async function createCliPackage(
};
packageJson.dependencies = {
'create-nx-workspace': nxVersion,
...(options.bundler === 'tsc' && { tslib: tsLibVersion }),
};
return packageJson;
}
Expand Down