Skip to content

Commit

Permalink
fix(vue): add release option for vue publishable library
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Feb 4, 2025
1 parent 0762eb6 commit fe594f1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
10 changes: 10 additions & 0 deletions e2e/release/src/publishable-libraries-release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,14 @@ describe('publishable libraries release', () => {
versionOutput = runCLI(`release patch`);
expect(versionOutput).toContain('Executing pre-version command');
});

it('should be able to release publishable vue library', async () => {
const vueLib = uniq('vue-lib');
runCLI(
`generate @nx/js:lib ${vueLib} --publishable --importPath=@proj/${vueLib}`
);

let versionOutput = runCLI(`release patch`);
expect(versionOutput).toContain('Executing pre-version command');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function createLibraryFiles(host: Tree, options: NormalizedSchema) {
(options.publishable || options.bundler !== 'none')
) {
writeJson(host, joinPathFragments(options.projectRoot, 'package.json'), {
name: options.name,
name: options.importPath ?? options.name,
version: '0.0.1',
main: './index.js',
types: './index.d.ts',
Expand Down
29 changes: 18 additions & 11 deletions packages/vue/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import {
GeneratorCallback,
installPackagesTask,
joinPathFragments,
readProjectConfiguration,
runTasksInSerial,
toJS,
Tree,
updateJson,
updateProjectConfiguration,
writeJson,
} from '@nx/devkit';
import { addTsConfigPath, initGenerator as jsInitGenerator } from '@nx/js';
Expand All @@ -30,6 +31,10 @@ import {
} from '@nx/js/src/utils/typescript/ts-solution-setup';
import { determineEntryFields } from './lib/determine-entry-fields';
import { sortPackageJsonFields } from '@nx/js/src/utils/package-json/sort-fields';
import {
addReleaseOptionForPublishableTarget,
releaseTasks,
} from '@nx/js/src/generators/library/utils/add-release-config';

export function libraryGenerator(tree: Tree, schema: Schema) {
return libraryGeneratorInternal(tree, { addPlugin: false, ...schema });
Expand Down Expand Up @@ -114,16 +119,6 @@ export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {
});
}

if (
!options.isUsingTsSolutionConfig &&
(options.publishable || options.bundler !== 'none')
) {
updateJson(tree, `${options.projectRoot}/package.json`, (json) => {
json.name = options.importPath;
return json;
});
}

if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) {
addTsConfigPath(tree, options.importPath, [
joinPathFragments(
Expand Down Expand Up @@ -156,6 +151,18 @@ export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {

sortPackageJsonFields(tree, options.projectRoot);

if (options.publishable) {
tasks.push(await releaseTasks(tree));
const projectConfig = readProjectConfiguration(tree, options.name);
await addReleaseOptionForPublishableTarget(
tree,
options.name,
projectConfig,
options.isUsingTsSolutionConfig
);
updateProjectConfiguration(tree, options.name, projectConfig);
}

if (!options.skipFormat) await formatFiles(tree);

// Always run install to link packages.
Expand Down

0 comments on commit fe594f1

Please sign in to comment.