feat(vue): add release option to vue publishable libraries (#29867)
This commit is contained in:
parent
2c0b5d3c8e
commit
e8acab6ae0
@ -52,7 +52,7 @@ describe('release publishable libraries in workspace with ts solution setup', ()
|
|||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
newProject({
|
newProject({
|
||||||
packages: ['@nx/js', '@nx/react'],
|
packages: ['@nx/js', '@nx/react', '@nx/vue'],
|
||||||
preset: 'ts',
|
preset: 'ts',
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -192,4 +192,59 @@ describe('release publishable libraries in workspace with ts solution setup', ()
|
|||||||
NX Successfully ran target nx-release-publish for project @proj/{project-name}
|
NX Successfully ran target nx-release-publish for project @proj/{project-name}
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be able to release publishable vue library', async () => {
|
||||||
|
const vueLib = uniq('my-pkg-');
|
||||||
|
runCLI(
|
||||||
|
`generate @nx/vue:lib packages/${vueLib} --bundler=vite --publishable --importPath=@proj/${vueLib} --no-interactive`
|
||||||
|
);
|
||||||
|
runCLI('sync');
|
||||||
|
|
||||||
|
const releaseOutput = runCLI(`release --specifier 0.0.4 --yes`);
|
||||||
|
expect(releaseOutput).toMatchInlineSnapshot(`
|
||||||
|
NX Executing pre-version command
|
||||||
|
NX Running release version for project: @proj/{project-name}
|
||||||
|
@proj/{project-name} 🔍 Reading data for package "@proj/{project-name}" from packages/{project-name}/package.json
|
||||||
|
@proj/{project-name} 📄 Resolved the current version as 0.0.1 from packages/{project-name}/package.json
|
||||||
|
@proj/{project-name} 📄 Using the provided version specifier "0.0.4".
|
||||||
|
@proj/{project-name} ✍️ New version 0.0.4 written to packages/{project-name}/package.json
|
||||||
|
"name": "@proj/{project-name}",
|
||||||
|
- "version": "0.0.1",
|
||||||
|
+ "version": "0.0.4",
|
||||||
|
"type": "module",
|
||||||
|
NX Updating PM lock file
|
||||||
|
NX Staging changed files with git
|
||||||
|
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 @proj/{project-name}:
|
||||||
|
- @proj/{project-name}
|
||||||
|
> nx run @proj/{project-name}:nx-release-publish
|
||||||
|
📦 @proj/{project-name}@0.0.4
|
||||||
|
=== Tarball Contents ===
|
||||||
|
XXB README.md
|
||||||
|
XXB dist/index.d.ts
|
||||||
|
XXB dist/index.d.ts.map
|
||||||
|
XXB dist/index.js
|
||||||
|
XXXB package.json
|
||||||
|
=== Tarball Details ===
|
||||||
|
name: @proj/{project-name}
|
||||||
|
version: 0.0.4
|
||||||
|
filename: proj-{project-name}-0.0.4.tgz
|
||||||
|
package size: XXXB
|
||||||
|
unpacked size: XXXB
|
||||||
|
shasum: {SHASUM}
|
||||||
|
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
|
total files: X
|
||||||
|
Published to ${e2eRegistryUrl} with tag "latest"
|
||||||
|
NX Successfully ran target nx-release-publish for project @proj/{project-name}
|
||||||
|
`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -52,7 +52,7 @@ describe('release publishable libraries', () => {
|
|||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
newProject({
|
newProject({
|
||||||
packages: ['@nx/js', '@nx/react', '@nx/angular'],
|
packages: ['@nx/js', '@nx/react', '@nx/angular', '@nx/vue'],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Normalize git committer information so it is deterministic in snapshots
|
// Normalize git committer information so it is deterministic in snapshots
|
||||||
@ -248,4 +248,58 @@ 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 vue library', async () => {
|
||||||
|
const vueLib = uniq('my-pkg-');
|
||||||
|
runCLI(
|
||||||
|
`generate @nx/vue:lib packages/${vueLib} --bundler=vite --publishable --importPath=@proj/${vueLib} --no-interactive`
|
||||||
|
);
|
||||||
|
runCLI('sync');
|
||||||
|
|
||||||
|
const releaseOutput = runCLI(`release --specifier 0.0.5 --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.4 from git tag "v0.0.4".
|
||||||
|
{project-name} 📄 Using the provided version specifier "0.0.5".
|
||||||
|
{project-name} ✍️ New version 0.0.5 written to dist/packages/{project-name}/package.json
|
||||||
|
"name": "@proj/{project-name}",
|
||||||
|
- "version": "0.0.1",
|
||||||
|
+ "version": "0.0.5",
|
||||||
|
"main": "./index.js",
|
||||||
|
NX Staging changed files with git
|
||||||
|
No files to stage. Skipping git add.
|
||||||
|
NX Generating an entry in CHANGELOG.md for v0.0.5
|
||||||
|
+ ## 0.0.5 (YYYY-MM-DD)
|
||||||
|
+
|
||||||
|
+ This was a version bump only, there were no code changes.
|
||||||
|
+
|
||||||
|
## 0.0.4 (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.5
|
||||||
|
=== Tarball Contents ===
|
||||||
|
XXB README.md
|
||||||
|
XXB index.d.ts
|
||||||
|
XXB index.mjs
|
||||||
|
XXXB package.json
|
||||||
|
=== Tarball Details ===
|
||||||
|
name: @proj/{project-name}
|
||||||
|
version: 0.0.5
|
||||||
|
filename: proj-{project-name}-0.0.5.tgz
|
||||||
|
package size: XXXB
|
||||||
|
unpacked size: XXXB
|
||||||
|
shasum: {SHASUM}
|
||||||
|
integrity: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
|
total files: X
|
||||||
|
Published to ${e2eRegistryUrl} with tag "latest"
|
||||||
|
NX Successfully ran target nx-release-publish for project {project-name}
|
||||||
|
`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -36,15 +36,15 @@ export function createLibraryFiles(host: Tree, options: NormalizedSchema) {
|
|||||||
(options.publishable || options.bundler !== 'none')
|
(options.publishable || options.bundler !== 'none')
|
||||||
) {
|
) {
|
||||||
writeJson(host, joinPathFragments(options.projectRoot, 'package.json'), {
|
writeJson(host, joinPathFragments(options.projectRoot, 'package.json'), {
|
||||||
name: options.name,
|
name: options.importPath ?? options.projectName,
|
||||||
version: '0.0.1',
|
version: '0.0.1',
|
||||||
main: './index.js',
|
main: './index.js',
|
||||||
types: './index.d.ts',
|
types: './index.d.ts',
|
||||||
exports: {
|
exports: {
|
||||||
'.': {
|
'.': {
|
||||||
|
types: './index.d.ts',
|
||||||
import: './index.mjs',
|
import: './index.mjs',
|
||||||
require: './index.js',
|
require: './index.js',
|
||||||
types: './index.d.ts',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -58,7 +58,7 @@ export async function normalizeOptions(
|
|||||||
addPlugin,
|
addPlugin,
|
||||||
...options,
|
...options,
|
||||||
projectName: isUsingTsSolutionConfig
|
projectName: isUsingTsSolutionConfig
|
||||||
? getImportPath(host, projectName)
|
? importPath ?? getImportPath(host, projectName)
|
||||||
: projectName,
|
: projectName,
|
||||||
bundler,
|
bundler,
|
||||||
fileName,
|
fileName,
|
||||||
|
|||||||
@ -577,7 +577,6 @@ module.exports = [
|
|||||||
[
|
[
|
||||||
"name",
|
"name",
|
||||||
"version",
|
"version",
|
||||||
"private",
|
|
||||||
"module",
|
"module",
|
||||||
"types",
|
"types",
|
||||||
"exports",
|
"exports",
|
||||||
|
|||||||
@ -4,10 +4,11 @@ import {
|
|||||||
GeneratorCallback,
|
GeneratorCallback,
|
||||||
installPackagesTask,
|
installPackagesTask,
|
||||||
joinPathFragments,
|
joinPathFragments,
|
||||||
|
readProjectConfiguration,
|
||||||
runTasksInSerial,
|
runTasksInSerial,
|
||||||
toJS,
|
toJS,
|
||||||
Tree,
|
Tree,
|
||||||
updateJson,
|
updateProjectConfiguration,
|
||||||
writeJson,
|
writeJson,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { addTsConfigPath, initGenerator as jsInitGenerator } from '@nx/js';
|
import { addTsConfigPath, initGenerator as jsInitGenerator } from '@nx/js';
|
||||||
@ -23,13 +24,17 @@ import { ensureDependencies } from '../../utils/ensure-dependencies';
|
|||||||
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
|
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
|
||||||
import { getRelativeCwd } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
import { getRelativeCwd } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
||||||
import { relative } from 'path';
|
import { relative } from 'path';
|
||||||
import { getImportPath } from '@nx/js/src/utils/get-import-path';
|
|
||||||
import {
|
import {
|
||||||
addProjectToTsSolutionWorkspace,
|
addProjectToTsSolutionWorkspace,
|
||||||
updateTsconfigFiles,
|
updateTsconfigFiles,
|
||||||
} from '@nx/js/src/utils/typescript/ts-solution-setup';
|
} from '@nx/js/src/utils/typescript/ts-solution-setup';
|
||||||
import { determineEntryFields } from './lib/determine-entry-fields';
|
import { determineEntryFields } from './lib/determine-entry-fields';
|
||||||
import { sortPackageJsonFields } from '@nx/js/src/utils/package-json/sort-fields';
|
import { sortPackageJsonFields } from '@nx/js/src/utils/package-json/sort-fields';
|
||||||
|
import {
|
||||||
|
addReleaseConfigForNonTsSolution,
|
||||||
|
addReleaseConfigForTsSolution,
|
||||||
|
releaseTasks,
|
||||||
|
} from '@nx/js/src/generators/library/utils/add-release-config';
|
||||||
|
|
||||||
export function libraryGenerator(tree: Tree, schema: Schema) {
|
export function libraryGenerator(tree: Tree, schema: Schema) {
|
||||||
return libraryGeneratorInternal(tree, { addPlugin: false, ...schema });
|
return libraryGeneratorInternal(tree, { addPlugin: false, ...schema });
|
||||||
@ -38,8 +43,6 @@ export function libraryGenerator(tree: Tree, schema: Schema) {
|
|||||||
export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {
|
export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {
|
||||||
const tasks: GeneratorCallback[] = [];
|
const tasks: GeneratorCallback[] = [];
|
||||||
|
|
||||||
tasks.push(await jsInitGenerator(tree, { ...schema, skipFormat: true }));
|
|
||||||
|
|
||||||
const options = await normalizeOptions(tree, schema);
|
const options = await normalizeOptions(tree, schema);
|
||||||
if (options.publishable === true && !schema.importPath) {
|
if (options.publishable === true && !schema.importPath) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -47,6 +50,8 @@ export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.push(await jsInitGenerator(tree, { ...options, skipFormat: true }));
|
||||||
|
|
||||||
// If we are using the new TS solution
|
// If we are using the new TS solution
|
||||||
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
||||||
if (options.isUsingTsSolutionConfig) {
|
if (options.isUsingTsSolutionConfig) {
|
||||||
@ -55,9 +60,8 @@ export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {
|
|||||||
|
|
||||||
if (options.isUsingTsSolutionConfig) {
|
if (options.isUsingTsSolutionConfig) {
|
||||||
writeJson(tree, joinPathFragments(options.projectRoot, 'package.json'), {
|
writeJson(tree, joinPathFragments(options.projectRoot, 'package.json'), {
|
||||||
name: getImportPath(tree, options.name),
|
name: options.projectName,
|
||||||
version: '0.0.1',
|
version: '0.0.1',
|
||||||
private: true,
|
|
||||||
...determineEntryFields(options),
|
...determineEntryFields(options),
|
||||||
files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined,
|
files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined,
|
||||||
nx: options.parsedTags?.length
|
nx: options.parsedTags?.length
|
||||||
@ -67,7 +71,7 @@ export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {
|
|||||||
: undefined,
|
: undefined,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
addProjectConfiguration(tree, options.name, {
|
addProjectConfiguration(tree, options.projectName, {
|
||||||
root: options.projectRoot,
|
root: options.projectRoot,
|
||||||
sourceRoot: joinPathFragments(options.projectRoot, 'src'),
|
sourceRoot: joinPathFragments(options.projectRoot, 'src'),
|
||||||
projectType: 'library',
|
projectType: 'library',
|
||||||
@ -114,16 +118,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) {
|
if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) {
|
||||||
addTsConfigPath(tree, options.importPath, [
|
addTsConfigPath(tree, options.importPath, [
|
||||||
joinPathFragments(
|
joinPathFragments(
|
||||||
@ -156,6 +150,25 @@ export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {
|
|||||||
|
|
||||||
sortPackageJsonFields(tree, options.projectRoot);
|
sortPackageJsonFields(tree, options.projectRoot);
|
||||||
|
|
||||||
|
if (options.publishable) {
|
||||||
|
const projectConfig = readProjectConfiguration(tree, options.projectName);
|
||||||
|
if (options.isUsingTsSolutionConfig) {
|
||||||
|
await addReleaseConfigForTsSolution(
|
||||||
|
tree,
|
||||||
|
options.projectName,
|
||||||
|
projectConfig
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await addReleaseConfigForNonTsSolution(
|
||||||
|
tree,
|
||||||
|
options.projectName,
|
||||||
|
projectConfig
|
||||||
|
);
|
||||||
|
}
|
||||||
|
updateProjectConfiguration(tree, options.projectName, projectConfig);
|
||||||
|
tasks.push(await releaseTasks(tree));
|
||||||
|
}
|
||||||
|
|
||||||
if (!options.skipFormat) await formatFiles(tree);
|
if (!options.skipFormat) await formatFiles(tree);
|
||||||
|
|
||||||
// Always run install to link packages.
|
// Always run install to link packages.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user