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

feat(core): add nx.json, workspace.json, and project.json JSON schemas #10228

Merged
merged 9 commits into from
May 10, 2022
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"@xstate/immer": "^0.2.0",
"@xstate/inspect": "^0.5.1",
"@xstate/react": "^1.6.3",
"ajv": "^8.11.0",
"angular": "1.8.0",
"autoprefixer": "^10.2.5",
"babel-jest": "27.5.1",
Expand Down Expand Up @@ -305,4 +306,4 @@
"**/xmlhttprequest-ssl": "~1.6.2",
"minimist": "^1.2.6"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ describe('e2e migrator', () => {
expect(angularJson.projects['app1-e2e']).toBe('apps/app1-e2e');
const e2eProject = readProjectConfiguration(tree, 'app1-e2e');
expect(e2eProject).toStrictEqual({
$schema: '../../node_modules/nx/schemas/project-schema.json',
root: 'apps/app1-e2e',
sourceRoot: 'apps/app1-e2e/src',
projectType: 'application',
Expand Down Expand Up @@ -457,6 +458,7 @@ describe('e2e migrator', () => {
expect(angularJson.projects['app1-e2e']).toBe('apps/app1-e2e');
const e2eProject = readProjectConfiguration(tree, 'app1-e2e');
expect(e2eProject).toStrictEqual({
$schema: '../../node_modules/nx/schemas/project-schema.json',
root: 'apps/app1-e2e',
sourceRoot: 'apps/app1-e2e/src',
projectType: 'application',
Expand Down Expand Up @@ -521,6 +523,7 @@ describe('e2e migrator', () => {

const e2eProject = readProjectConfiguration(tree, 'app1-e2e');
expect(e2eProject).toStrictEqual({
$schema: '../../node_modules/nx/schemas/project-schema.json',
root: 'apps/app1-e2e',
sourceRoot: 'apps/app1-e2e/src',
projectType: 'application',
Expand Down Expand Up @@ -573,6 +576,7 @@ describe('e2e migrator', () => {

const e2eProject = readProjectConfiguration(tree, 'app1-e2e');
expect(e2eProject).toStrictEqual({
$schema: '../../node_modules/nx/schemas/project-schema.json',
root: 'apps/app1-e2e',
sourceRoot: 'apps/app1-e2e/src',
projectType: 'application',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ describe('set-build-libs-from-source migration', () => {
};
addProjectConfiguration(tree, 'app1', project);

// add $schema to projectConfig manually
project['$schema'] = '../../node_modules/nx/schemas/project-schema.json';

await migration(tree);

const resultingProject = readProjectConfiguration(tree, 'app1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('React default development configuration', () => {

const config = readProjectConfiguration(tree, 'example');
expect(config).toEqual({
$schema: '../../node_modules/nx/schemas/project-schema.json',
root: 'apps/example',
projectType: 'application',
});
Expand Down
6 changes: 6 additions & 0 deletions packages/nx/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"version": "14.0.6",
"description": "Remove root property from project.json files",
"factory": "./src/migrations/update-14-0-6/remove-roots"
},
"14-2-0-add-json-schema": {
"cli": "nx",
"version": "14.2.0-beta.0",
"description": "Add JSON Schema to Nx configuration files",
"factory": "./src/migrations/update-14-2-0/add-json-schema"
}
}
}
2 changes: 1 addition & 1 deletion packages/nx/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path = require('path');
import json = require('./migrations.json');

describe('Node migrations', () => {
describe('Nx migrations', () => {
it('should have valid paths', () => {
Object.values(json.generators).forEach((m) => {
expect(() =>
Expand Down
127 changes: 127 additions & 0 deletions packages/nx/schemas/nx-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://nx.dev/core-concepts/configuration#nxjson",
"title": "JSON schema for Nx configuration",
"type": "object",
"properties": {
"implicitDependencies": {
"type": "object",
"description": "Map of files to projects that implicitly depend on them."
},
"affected": {
"type": "object",
"description": "Default options for `nx affected`.",
"properties": {
"defaultBase": {
"type": "string",
"description": "Default based branch used by affected commands."
}
},
"additionalProperties": false
},
"npmScope": {
"type": "string",
"description": "NPM Scope that the workspace uses."
},
"tasksRunnerOptions": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/tasksRunnerOptions"
}
},
"targetDependencies": {
"type": "object",
"description": "Dependencies between different target names across all projects.",
"additionalProperties": {
"$ref": "#/definitions/targetDependencyConfig"
}
},
"workspaceLayout": {
"type": "object",
"description": "Where new apps + libs should be placed.",
"properties": {
"libsDir": {
"type": "string",
"description": "Default folder name for libs."
},
"appsDir": {
"type": "string",
"description": "Default folder name for apps."
}
},
"additionalProperties": false
},
"cli": {
"$ref": "#/definitions/cliOptions"
},
"generators": {
"$ref": "#/definitions/generatorOptions"
},
"plugins": {
"type": "array",
"description": "Plugins for extending the project graph.",
"items": {
"type": "string"
}
},
"defaultProject": {
"type": "string",
"description": "Default project. When project isn't provided, the default project will be used."
}
},
"definitions": {
"cliOptions": {
"type": "object",
"description": "Default generator collection.",
"properties": {
"packageManager": {
"type": "string",
"description": "The default package manager to use.",
"enum": ["yarn", "pnpm", "npm"]
},
"defaultCollection": {
"type": "string",
"description": "The default schematics collection to use."
}
}
},
"generatorOptions": {
"type": "object",
"description": "List of default values used by generators."
},
"tasksRunnerOptions": {
"type": "object",
"description": "Available Task Runners.",
"properties": {
"runner": {
"type": "string",
"description": "Path to resolve the runner."
},
"options": {
"type": "object",
"description": "Default options for the runner."
}
},
"additionalProperties": false
},
"targetDependencyConfig": {
"type": "array",
"description": "Target dependency.",
"items": {
"type": "object",
"properties": {
"projects": {
"type": "string",
"description": "The projects that the targets belong to.",
"enum": ["self", "dependencies"]
},
"target": {
"type": "string",
"description": "The name of the target."
}
},
"additionalProperties": false
}
}
}
}
68 changes: 68 additions & 0 deletions packages/nx/schemas/project-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://nx.dev/project-schema",
"title": "JSON schema for Nx projects",
"type": "object",
"properties": {
"targets": {
"type": "object",
"description": "Configures all the targets which define what tasks you can run against the project",
"additionalProperties": {
"type": "object",
"properties": {
"executor": {
"description": "The function that Nx will invoke when you run this target",
"type": "string"
},
"options": {
"type": "object"
},
"outputs": {
"type": "array",
"items": {
"type": "string"
}
},
"configurations": {
"type": "object",
"description": "provides extra sets of values that will be merged into the options map",
"additionalProperties": {
"type": "object"
}
},
"dependsOn": {
"type": "array",
"description": "Target dependency.",
"items": {
"type": "object",
"properties": {
"projects": {
"type": "string",
"description": "The projects that the targets belong to.",
"enum": ["self", "dependencies"]
},
"target": {
"type": "string",
"description": "The name of the target."
}
},
"additionalProperties": false
}
}
}
}
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"implicitDependencies": {
"type": "array",
"items": {
"type": "string"
}
}
}
}