feat(core): flatten default base config to base (#19964)
This commit is contained in:
parent
17e2248098
commit
95b77f8fb0
@ -1,5 +1,9 @@
|
|||||||
# Interface: NxAffectedConfig
|
# Interface: NxAffectedConfig
|
||||||
|
|
||||||
|
**`Deprecated`**
|
||||||
|
|
||||||
|
Use [NxJsonConfiguration#defaultBase](../../devkit/documents/NxJsonConfiguration#defaultbase) instead
|
||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
|||||||
@ -21,6 +21,7 @@ Nx.json configuration
|
|||||||
- [affected](../../devkit/documents/NxJsonConfiguration#affected): NxAffectedConfig
|
- [affected](../../devkit/documents/NxJsonConfiguration#affected): NxAffectedConfig
|
||||||
- [cacheDirectory](../../devkit/documents/NxJsonConfiguration#cachedirectory): string
|
- [cacheDirectory](../../devkit/documents/NxJsonConfiguration#cachedirectory): string
|
||||||
- [cli](../../devkit/documents/NxJsonConfiguration#cli): Object
|
- [cli](../../devkit/documents/NxJsonConfiguration#cli): Object
|
||||||
|
- [defaultBase](../../devkit/documents/NxJsonConfiguration#defaultbase): string
|
||||||
- [defaultProject](../../devkit/documents/NxJsonConfiguration#defaultproject): string
|
- [defaultProject](../../devkit/documents/NxJsonConfiguration#defaultproject): string
|
||||||
- [extends](../../devkit/documents/NxJsonConfiguration#extends): string
|
- [extends](../../devkit/documents/NxJsonConfiguration#extends): string
|
||||||
- [generators](../../devkit/documents/NxJsonConfiguration#generators): Object
|
- [generators](../../devkit/documents/NxJsonConfiguration#generators): Object
|
||||||
@ -47,6 +48,10 @@ Nx.json configuration
|
|||||||
|
|
||||||
Default options for `nx affected`
|
Default options for `nx affected`
|
||||||
|
|
||||||
|
**`Deprecated`**
|
||||||
|
|
||||||
|
use [defaultBase](../../devkit/documents/NxJsonConfiguration#defaultbase) instead. For more information see https://nx.dev/deprecated/affected-config#affected-config
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### cacheDirectory
|
### cacheDirectory
|
||||||
@ -72,6 +77,14 @@ Default generator collection. It is used when no collection is provided.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### defaultBase
|
||||||
|
|
||||||
|
• `Optional` **defaultBase**: `string`
|
||||||
|
|
||||||
|
Default value for --base used by `nx affected` and `nx format`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### defaultProject
|
### defaultProject
|
||||||
|
|
||||||
• `Optional` **defaultProject**: `string`
|
• `Optional` **defaultProject**: `string`
|
||||||
|
|||||||
@ -19,6 +19,7 @@ use ProjectsConfigurations or NxJsonConfiguration
|
|||||||
- [affected](../../devkit/documents/Workspace#affected): NxAffectedConfig
|
- [affected](../../devkit/documents/Workspace#affected): NxAffectedConfig
|
||||||
- [cacheDirectory](../../devkit/documents/Workspace#cachedirectory): string
|
- [cacheDirectory](../../devkit/documents/Workspace#cachedirectory): string
|
||||||
- [cli](../../devkit/documents/Workspace#cli): Object
|
- [cli](../../devkit/documents/Workspace#cli): Object
|
||||||
|
- [defaultBase](../../devkit/documents/Workspace#defaultbase): string
|
||||||
- [defaultProject](../../devkit/documents/Workspace#defaultproject): string
|
- [defaultProject](../../devkit/documents/Workspace#defaultproject): string
|
||||||
- [extends](../../devkit/documents/Workspace#extends): string
|
- [extends](../../devkit/documents/Workspace#extends): string
|
||||||
- [generators](../../devkit/documents/Workspace#generators): Object
|
- [generators](../../devkit/documents/Workspace#generators): Object
|
||||||
@ -47,6 +48,10 @@ use ProjectsConfigurations or NxJsonConfiguration
|
|||||||
|
|
||||||
Default options for `nx affected`
|
Default options for `nx affected`
|
||||||
|
|
||||||
|
**`Deprecated`**
|
||||||
|
|
||||||
|
use [defaultBase](../../devkit/documents/NxJsonConfiguration#defaultbase) instead. For more information see https://nx.dev/deprecated/affected-config#affected-config
|
||||||
|
|
||||||
#### Inherited from
|
#### Inherited from
|
||||||
|
|
||||||
[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[affected](../../devkit/documents/NxJsonConfiguration#affected)
|
[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[affected](../../devkit/documents/NxJsonConfiguration#affected)
|
||||||
@ -84,6 +89,18 @@ Default generator collection. It is used when no collection is provided.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### defaultBase
|
||||||
|
|
||||||
|
• `Optional` **defaultBase**: `string`
|
||||||
|
|
||||||
|
Default value for --base used by `nx affected` and `nx format`.
|
||||||
|
|
||||||
|
#### Inherited from
|
||||||
|
|
||||||
|
[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[defaultBase](../../devkit/documents/NxJsonConfiguration#defaultbase)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### defaultProject
|
### defaultProject
|
||||||
|
|
||||||
• `Optional` **defaultProject**: `string`
|
• `Optional` **defaultProject**: `string`
|
||||||
|
|||||||
@ -16,9 +16,7 @@ The following is an expanded example showing all options. Your `nx.json` will li
|
|||||||
],
|
],
|
||||||
"parallel": 4,
|
"parallel": 4,
|
||||||
"cacheDirectory": "tmp/my-nx-cache",
|
"cacheDirectory": "tmp/my-nx-cache",
|
||||||
"affected": {
|
"defaultBase": "main",
|
||||||
"defaultBase": "main"
|
|
||||||
},
|
|
||||||
"namedInputs": {
|
"namedInputs": {
|
||||||
"default": ["{projectRoot}/**/*"],
|
"default": ["{projectRoot}/**/*"],
|
||||||
"production": ["!{projectRoot}/**/*.spec.tsx"]
|
"production": ["!{projectRoot}/**/*.spec.tsx"]
|
||||||
@ -123,9 +121,9 @@ nx run-many -t build --runner=another
|
|||||||
|
|
||||||
The official types of `runner` supported by Nx are `"nx/tasks-runners/default"` and `"nx-cloud"`.
|
The official types of `runner` supported by Nx are `"nx/tasks-runners/default"` and `"nx-cloud"`.
|
||||||
|
|
||||||
## Affected
|
## Default Base
|
||||||
|
|
||||||
Tells Nx which branch and HEAD to use when calculating affected projects.
|
Tells Nx which base branch to use when calculating affected projects.
|
||||||
|
|
||||||
- `defaultBase` defines the default base branch, defaults to `main`.
|
- `defaultBase` defines the default base branch, defaults to `main`.
|
||||||
|
|
||||||
|
|||||||
@ -143,9 +143,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
|
|||||||
// check nx.json
|
// check nx.json
|
||||||
const nxJson = readJson('nx.json');
|
const nxJson = readJson('nx.json');
|
||||||
expect(nxJson).toEqual({
|
expect(nxJson).toEqual({
|
||||||
affected: {
|
|
||||||
defaultBase: 'main',
|
defaultBase: 'main',
|
||||||
},
|
|
||||||
namedInputs: {
|
namedInputs: {
|
||||||
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
||||||
production: [
|
production: [
|
||||||
|
|||||||
@ -80,9 +80,7 @@ exports[`workspace move to nx layout should create a root eslint config 1`] = `
|
|||||||
|
|
||||||
exports[`workspace move to nx layout should create nx.json 1`] = `
|
exports[`workspace move to nx layout should create nx.json 1`] = `
|
||||||
{
|
{
|
||||||
"affected": {
|
|
||||||
"defaultBase": "main",
|
"defaultBase": "main",
|
||||||
},
|
|
||||||
"defaultProject": "myApp",
|
"defaultProject": "myApp",
|
||||||
"namedInputs": {
|
"namedInputs": {
|
||||||
"default": [
|
"default": [
|
||||||
|
|||||||
@ -50,9 +50,7 @@ export function createNxJson(
|
|||||||
const targets = getWorkspaceCommonTargets(tree);
|
const targets = getWorkspaceCommonTargets(tree);
|
||||||
|
|
||||||
writeJson<NxJsonConfiguration>(tree, 'nx.json', {
|
writeJson<NxJsonConfiguration>(tree, 'nx.json', {
|
||||||
affected: {
|
|
||||||
defaultBase: options.defaultBase ?? deduceDefaultBase(),
|
defaultBase: options.defaultBase ?? deduceDefaultBase(),
|
||||||
},
|
|
||||||
namedInputs: {
|
namedInputs: {
|
||||||
sharedGlobals: [],
|
sharedGlobals: [],
|
||||||
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
||||||
|
|||||||
@ -89,6 +89,11 @@
|
|||||||
"description": "Updates .env to disabled adding plugins when generating projects in an existing Nx workspace",
|
"description": "Updates .env to disabled adding plugins when generating projects in an existing Nx workspace",
|
||||||
"implementation": "./src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces",
|
"implementation": "./src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces",
|
||||||
"x-repair-skip": true
|
"x-repair-skip": true
|
||||||
|
},
|
||||||
|
"move-default-base-to-nx-json-root": {
|
||||||
|
"version": "18.1.0-beta.3",
|
||||||
|
"description": "Moves affected.defaultBase to defaultBase in `nx.json`",
|
||||||
|
"implementation": "./src/migrations/update-17-2-0/move-default-base"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,12 @@
|
|||||||
"description": "Default based branch used by affected commands."
|
"description": "Default based branch used by affected commands."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false,
|
||||||
|
"deprecated": "Use `defaultBase` instead. Support for setting `defaultBase` in `affected` will be removed in Nx 19."
|
||||||
|
},
|
||||||
|
"defaultBase": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Default --base used by affected logic."
|
||||||
},
|
},
|
||||||
"tasksRunnerOptions": {
|
"tasksRunnerOptions": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|||||||
@ -55,6 +55,7 @@ export const allowedProjectExtensions = [
|
|||||||
export const allowedWorkspaceExtensions = [
|
export const allowedWorkspaceExtensions = [
|
||||||
'implicitDependencies',
|
'implicitDependencies',
|
||||||
'affected',
|
'affected',
|
||||||
|
'defaultBase',
|
||||||
'tasksRunnerOptions',
|
'tasksRunnerOptions',
|
||||||
'workspaceLayout',
|
'workspaceLayout',
|
||||||
'plugins',
|
'plugins',
|
||||||
|
|||||||
@ -58,8 +58,7 @@ export function createNxJsonFile(
|
|||||||
delete nxJson.targetDefaults;
|
delete nxJson.targetDefaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxJson.affected ??= {};
|
nxJson.defaultBase ??= deduceDefaultBase();
|
||||||
nxJson.affected.defaultBase ??= deduceDefaultBase();
|
|
||||||
writeJsonFile(nxJsonPath, nxJson);
|
writeJsonFile(nxJsonPath, nxJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,9 @@ export interface ImplicitJsonSubsetDependency<T = '*' | string[]> {
|
|||||||
[key: string]: T | ImplicitJsonSubsetDependency<T>;
|
[key: string]: T | ImplicitJsonSubsetDependency<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link NxJsonConfiguration#defaultBase } instead
|
||||||
|
*/
|
||||||
export interface NxAffectedConfig {
|
export interface NxAffectedConfig {
|
||||||
/**
|
/**
|
||||||
* Default based branch used by affected commands.
|
* Default based branch used by affected commands.
|
||||||
@ -272,8 +275,15 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
|
|||||||
targetDefaults?: TargetDefaults;
|
targetDefaults?: TargetDefaults;
|
||||||
/**
|
/**
|
||||||
* Default options for `nx affected`
|
* Default options for `nx affected`
|
||||||
|
* @deprecated use {@link defaultBase} instead. For more information see https://nx.dev/deprecated/affected-config#affected-config
|
||||||
*/
|
*/
|
||||||
affected?: NxAffectedConfig;
|
affected?: NxAffectedConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default value for --base used by `nx affected` and `nx format`.
|
||||||
|
*/
|
||||||
|
defaultBase?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Where new apps + libs should be placed
|
* Where new apps + libs should be placed
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -0,0 +1,47 @@
|
|||||||
|
import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace';
|
||||||
|
import { Tree } from '../../generators/tree';
|
||||||
|
import { readNxJson, updateNxJson } from '../../generators/utils/nx-json';
|
||||||
|
|
||||||
|
import update from './move-default-base';
|
||||||
|
|
||||||
|
describe('update-17.1.0 migration', () => {
|
||||||
|
let tree: Tree;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shouldn't do anything if affected.defaultBase is not set", () => {
|
||||||
|
tree.write('nx.json', JSON.stringify({}));
|
||||||
|
update(tree);
|
||||||
|
expect(readNxJson(tree)).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shouldn't remove affected if other keys present", () => {
|
||||||
|
updateNxJson(tree, {
|
||||||
|
affected: {
|
||||||
|
defaultBase: 'master',
|
||||||
|
otherKey: 'otherValue',
|
||||||
|
} as any,
|
||||||
|
});
|
||||||
|
update(tree);
|
||||||
|
expect(readNxJson(tree)).toEqual({
|
||||||
|
affected: {
|
||||||
|
otherKey: 'otherValue',
|
||||||
|
},
|
||||||
|
defaultBase: 'master',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove affected if no other keys present', () => {
|
||||||
|
updateNxJson(tree, {
|
||||||
|
affected: {
|
||||||
|
defaultBase: 'master',
|
||||||
|
} as any,
|
||||||
|
});
|
||||||
|
update(tree);
|
||||||
|
expect(readNxJson(tree)).toEqual({
|
||||||
|
defaultBase: 'master',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
import { readNxJson, updateNxJson } from '../../generators/utils/nx-json';
|
||||||
|
import { Tree } from '../../generators/tree';
|
||||||
|
import { NxJsonConfiguration } from '../../config/nx-json';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates existing workspaces to move nx.json's affected.defaultBase to nx.json's base.
|
||||||
|
*/
|
||||||
|
export default function update(host: Tree) {
|
||||||
|
const nxJson = readNxJson(host) as NxJsonConfiguration & {
|
||||||
|
affected: { defaultBase?: string };
|
||||||
|
};
|
||||||
|
if (nxJson?.affected?.defaultBase) {
|
||||||
|
nxJson.defaultBase = nxJson.affected.defaultBase;
|
||||||
|
delete nxJson.affected.defaultBase;
|
||||||
|
if (Object.keys(nxJson.affected).length === 0) {
|
||||||
|
delete nxJson.affected;
|
||||||
|
}
|
||||||
|
updateNxJson(host, nxJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -142,7 +142,8 @@ export function splitArgsIntoNxArgsAndOverrides(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!nxArgs.base) {
|
if (!nxArgs.base) {
|
||||||
nxArgs.base = nxJson.affected?.defaultBase || 'main';
|
nxArgs.base =
|
||||||
|
nxJson.defaultBase ?? nxJson.affected?.defaultBase ?? 'main';
|
||||||
|
|
||||||
// No user-provided arguments to set the affected criteria, so inform the user of the defaults being used
|
// No user-provided arguments to set the affected criteria, so inform the user of the defaults being used
|
||||||
if (
|
if (
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import {
|
|||||||
NxJsonConfiguration,
|
NxJsonConfiguration,
|
||||||
PackageManager,
|
PackageManager,
|
||||||
readJson,
|
readJson,
|
||||||
|
readNxJson,
|
||||||
Tree,
|
Tree,
|
||||||
updateJson,
|
updateJson,
|
||||||
writeJson,
|
writeJson,
|
||||||
@ -114,6 +115,21 @@ describe('CI Workflow generator', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should prefix nx.json base with origin/ if ci is bitbucket-pipelines', async () => {
|
||||||
|
setNxCloud(tree);
|
||||||
|
|
||||||
|
const nxJson = readNxJson(tree);
|
||||||
|
nxJson.defaultBase = 'my-branch';
|
||||||
|
writeJson(tree, 'nx.json', nxJson);
|
||||||
|
|
||||||
|
await ciWorkflowGenerator(tree, {
|
||||||
|
ci: 'bitbucket-pipelines',
|
||||||
|
name: 'CI',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(readNxJson(tree).defaultBase).toEqual('origin/my-branch');
|
||||||
|
});
|
||||||
|
|
||||||
it('should generate gitlab config', async () => {
|
it('should generate gitlab config', async () => {
|
||||||
setNxCloud(tree);
|
setNxCloud(tree);
|
||||||
await ciWorkflowGenerator(tree, { ci: 'gitlab', name: 'CI' });
|
await ciWorkflowGenerator(tree, { ci: 'gitlab', name: 'CI' });
|
||||||
|
|||||||
@ -85,17 +85,16 @@ function normalizeOptions(options: Schema, tree: Tree): Substitutes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function defaultBranchNeedsOriginPrefix(nxJson: NxJsonConfiguration): boolean {
|
function defaultBranchNeedsOriginPrefix(nxJson: NxJsonConfiguration): boolean {
|
||||||
return !nxJson.affected?.defaultBase?.startsWith('origin/');
|
const base = nxJson.defaultBase ?? nxJson.affected?.defaultBase;
|
||||||
|
return !base?.startsWith('origin/');
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendOriginPrefix(nxJson: NxJsonConfiguration): NxJsonConfiguration {
|
function appendOriginPrefix(nxJson: NxJsonConfiguration): NxJsonConfiguration {
|
||||||
return {
|
if (nxJson?.affected?.defaultBase) {
|
||||||
...nxJson,
|
nxJson.affected.defaultBase = `origin/${nxJson.affected.defaultBase}`;
|
||||||
affected: {
|
}
|
||||||
...(nxJson.affected ?? {}),
|
if (nxJson.defaultBase || !nxJson.affected) {
|
||||||
defaultBase: nxJson.affected?.defaultBase
|
nxJson.defaultBase = `origin/${nxJson.defaultBase ?? deduceDefaultBase()}`;
|
||||||
? `origin/${nxJson.affected.defaultBase}`
|
}
|
||||||
: 'origin/main',
|
return nxJson;
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,9 +64,7 @@ function createNxJson(
|
|||||||
) {
|
) {
|
||||||
const nxJson: NxJsonConfiguration & { $schema: string } = {
|
const nxJson: NxJsonConfiguration & { $schema: string } = {
|
||||||
$schema: './node_modules/nx/schemas/nx-schema.json',
|
$schema: './node_modules/nx/schemas/nx-schema.json',
|
||||||
affected: {
|
|
||||||
defaultBase,
|
defaultBase,
|
||||||
},
|
|
||||||
targetDefaults:
|
targetDefaults:
|
||||||
process.env.NX_ADD_PLUGINS === 'false'
|
process.env.NX_ADD_PLUGINS === 'false'
|
||||||
? {
|
? {
|
||||||
@ -82,7 +80,7 @@ function createNxJson(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (defaultBase === 'main') {
|
if (defaultBase === 'main') {
|
||||||
delete nxJson.affected;
|
delete nxJson.defaultBase;
|
||||||
}
|
}
|
||||||
if (preset !== Preset.NPM) {
|
if (preset !== Preset.NPM) {
|
||||||
nxJson.namedInputs = {
|
nxJson.namedInputs = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user