feat(angular): add release option to angular publishable libraries (#29869)

This commit is contained in:
Emily Xiong 2025-02-18 07:54:35 -08:00 committed by GitHub
parent 377f5f6dfc
commit 4f70cdb721
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 75 additions and 4 deletions

View File

@ -26,6 +26,7 @@ expect.addSnapshotSerializer({
.replaceAll(/size:\s*\d*\s?B/g, 'size: XXXB') .replaceAll(/size:\s*\d*\s?B/g, 'size: XXXB')
.replaceAll(/\d*\.\d*\s?kB/g, 'XXX.XXX kb') .replaceAll(/\d*\.\d*\s?kB/g, 'XXX.XXX kb')
.replaceAll(/\d*B\s+src\//g, 'XXB src/') .replaceAll(/\d*B\s+src\//g, 'XXB src/')
.replaceAll(/\d*B\s+lib\//g, 'XXB lib/')
.replaceAll(/\d*B\s+index/g, 'XXB index') .replaceAll(/\d*B\s+index/g, 'XXB index')
.replaceAll(/total files:\s+\d*/g, 'total files: X') .replaceAll(/total files:\s+\d*/g, 'total files: X')
.replaceAll(/\d*B\s+README.md/g, 'XXB README.md') .replaceAll(/\d*B\s+README.md/g, 'XXB README.md')
@ -51,7 +52,7 @@ describe('release publishable libraries', () => {
beforeAll(async () => { beforeAll(async () => {
newProject({ newProject({
packages: ['@nx/js', '@nx/react'], packages: ['@nx/js', '@nx/react', '@nx/angular'],
}); });
// Normalize git committer information so it is deterministic in snapshots // Normalize git committer information so it is deterministic in snapshots
@ -67,7 +68,7 @@ describe('release publishable libraries', () => {
// This is the verdaccio instance that the e2e tests themselves are working from // This is the verdaccio instance that the e2e tests themselves are working from
e2eRegistryUrl = execSync('npm config get registry').toString().trim(); e2eRegistryUrl = execSync('npm config get registry').toString().trim();
}, 60000); }, 100000);
beforeEach(() => { beforeEach(() => {
try { try {
@ -190,4 +191,61 @@ describe('release publishable libraries', () => {
NX Successfully ran target nx-release-publish for project {project-name} NX Successfully ran target nx-release-publish for project {project-name}
`); `);
}); });
it('should be able to release publishable angular library', async () => {
const angularLib = uniq('my-pkg-');
runCLI(
`generate @nx/angular:lib packages/${angularLib} --publishable --importPath=@proj/${angularLib} --no-interactive`
);
const releaseOutput = runCLI(`release --specifier 0.0.4 --yes`);
expect(releaseOutput).toMatchInlineSnapshot(`
NX Executing pre-version command
NX Running release version for project: {project-name}
{project-name} 🔍 Reading data for package "@proj/{project-name}" from dist/packages/{project-name}/package.json
{project-name} 📄 Resolved the current version as 0.0.3 from git tag "v0.0.3".
{project-name} 📄 Using the provided version specifier "0.0.4".
{project-name} New version 0.0.4 written to dist/packages/{project-name}/package.json
"name": "@proj/{project-name}",
- "version": "0.0.1",
+ "version": "0.0.4",
"peerDependencies": {
}
+
NX Staging changed files with git
No files to stage. Skipping git add.
NX Generating an entry in CHANGELOG.md for v0.0.4
+ ## 0.0.4 (YYYY-MM-DD)
+
+ This was a version bump only, there were no code changes.
+
## 0.0.3 (YYYY-MM-DD)
This was a version bump only, there were no code changes.
NX Staging changed files with git
NX Committing changes with git
NX Tagging commit with git
NX Running target nx-release-publish for project {project-name}:
- {project-name}
> nx run {project-name}:nx-release-publish
📦 @proj/{project-name}@0.0.4
=== Tarball Contents ===
XXB README.md
XXX.XXX kb fesm2022/proj-{project-name}.mjs
XXX.XXX kb fesm2022/proj-{project-name}.mjs.map
XXB index.d.ts
XXB lib/{project-name}/{project-name}.component.d.ts
XXXB package.json
=== Tarball Details ===
name: @proj/{project-name}
version: 0.0.4
filename: proj-{project-name}-0.0.4.tgz
package size: XXX.XXX kb
unpacked size: XXX.XXX kb
shasum: {SHASUM}
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
total files: X
Published to ${e2eRegistryUrl} with tag "latest"
NX Successfully ran target nx-release-publish for project {project-name}
`);
});
}); });

View File

@ -3,8 +3,9 @@ import { addProjectConfiguration, joinPathFragments } from '@nx/devkit';
import type { AngularProjectConfiguration } from '../../../utils/types'; import type { AngularProjectConfiguration } from '../../../utils/types';
import type { NormalizedSchema } from './normalized-schema'; import type { NormalizedSchema } from './normalized-schema';
import { addBuildTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils'; import { addBuildTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';
import { addReleaseConfigForNonTsSolution } from '@nx/js/src/generators/library/utils/add-release-config';
export function addProject( export async function addProject(
tree: Tree, tree: Tree,
libraryOptions: NormalizedSchema['libraryOptions'] libraryOptions: NormalizedSchema['libraryOptions']
) { ) {
@ -41,6 +42,14 @@ export function addProject(
}, },
defaultConfiguration: 'production', defaultConfiguration: 'production',
}; };
if (libraryOptions.publishable) {
await addReleaseConfigForNonTsSolution(
tree,
libraryOptions.name,
project
);
}
} }
addProjectConfiguration(tree, libraryOptions.name, project); addProjectConfiguration(tree, libraryOptions.name, project);

View File

@ -33,6 +33,7 @@ import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-com
import { UnitTestRunner } from '../../utils/test-runners'; import { UnitTestRunner } from '../../utils/test-runners';
import { addVitest } from '../utils/add-vitest'; import { addVitest } from '../utils/add-vitest';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup'; import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { releaseTasks } from '@nx/js/src/generators/library/utils/add-release-config';
export async function libraryGenerator( export async function libraryGenerator(
tree: Tree, tree: Tree,
@ -73,7 +74,7 @@ export async function libraryGenerator(
ensureAngularDependencies(tree); ensureAngularDependencies(tree);
} }
const project = addProject(tree, libraryOptions); const project = await addProject(tree, libraryOptions);
createFiles(tree, options, project); createFiles(tree, options, project);
updateTsConfig(tree, libraryOptions); updateTsConfig(tree, libraryOptions);
@ -112,6 +113,9 @@ export async function libraryGenerator(
true true
); );
addBuildableLibrariesPostCssDependencies(tree); addBuildableLibrariesPostCssDependencies(tree);
if (libraryOptions.publishable) {
await releaseTasks(tree);
}
} }
addTsConfigPath(tree, libraryOptions.importPath, [ addTsConfigPath(tree, libraryOptions.importPath, [