Skip to content

Commit

Permalink
chore(repo): docs and format
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Apr 6, 2022
1 parent b6467d4 commit e224b57
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 13 deletions.
7 changes: 7 additions & 0 deletions docs/generated/api-nx-devkit/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ It only uses language primitives and immutable objects
### Other Interfaces

- [NxPlugin](../../nx-devkit/index#nxplugin)
- [PackageJson](../../nx-devkit/index#packagejson)

### Project Graph Interfaces

Expand Down Expand Up @@ -226,6 +227,12 @@ A plugin for Nx

---

### PackageJson

**PackageJson**: `Object`

---

## Project Graph Interfaces

### FileData
Expand Down
34 changes: 34 additions & 0 deletions docs/generated/packages/nx-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,40 @@
"aliases": [],
"hidden": false,
"path": "/packages/nx-plugin/src/executors/e2e/schema.json"
},
{
"name": "plugin-lint",
"implementation": "/packages/nx-plugin/src/executors/plugin-lint/plugin-lint.impl.ts",
"schema": {
"title": "Nx Plugin Lint Target",
"description": "Checks a Nx Plugin for validity.",
"cli": "nx",
"type": "object",
"properties": {
"validateSchemas": {
"description": "Should the schema files be validated?",
"type": "boolean",
"default": true
},
"validateImplementationLocations": {
"type": "boolean",
"description": "Should the implementation locations be validated?",
"default": true
},
"packageJson": {
"type": "string",
"description": "The path to the package.json file for the plugin",
"default": "generators.json"
}
},
"additionalProperties": false,
"required": ["packageJson"],
"presets": []
},
"description": "Checks a Nx plugin for validity.",
"aliases": [],
"hidden": false,
"path": "/packages/nx-plugin/src/executors/plugin-lint/schema.json"
}
]
}
5 changes: 5 additions & 0 deletions docs/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,11 @@
"name": "e2e executor",
"id": "e2e",
"path": "/packages/nx-plugin/executors/e2e"
},
{
"name": "plugin-lint executor",
"id": "plugin-lint",
"path": "/packages/nx-plugin/executors/plugin-lint"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion docs/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
"name": "nx-plugin",
"path": "generated/packages/nx-plugin.json",
"schemas": {
"executors": ["e2e"],
"executors": ["e2e", "plugin-lint"],
"generators": [
"plugin",
"e2e-project",
Expand Down
4 changes: 1 addition & 3 deletions packages/devkit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export type {
ProjectTargetConfigurator,
} from 'nx/src/utils/nx-plugin';

export type {
PackageJson
} from 'nx/src/utils/package-json'
export type { PackageJson } from 'nx/src/utils/package-json';

/**
* @category Workspace
Expand Down
6 changes: 3 additions & 3 deletions packages/linter/src/executors/lint/compat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convertNxExecutor } from "@nrwl/devkit"
import executor from './lint.impl'
import { convertNxExecutor } from '@nrwl/devkit';
import executor from './lint.impl';

export default convertNxExecutor(executor)
export default convertNxExecutor(executor);
33 changes: 27 additions & 6 deletions packages/nx-plugin/src/executors/plugin-lint/plugin-lint.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function validateExecutorsJson(
executorsJsonPath: string,
opts: NxPluginLintExecutorOptions
) {
logger.log(`- ${executorsJsonPath}`);
const executorsCollection = readJsonFileRelativeToPackageJson(
opts.packageJson,
executorsJsonPath
Expand All @@ -80,6 +81,7 @@ function validateGeneratorsJson(
opts: NxPluginLintExecutorOptions,
requireSchemaFile: boolean
) {
logger.log(`- ${generatorsJsonPath}`);
const generatorsCollection = readJsonFileRelativeToPackageJson(
opts.packageJson,
generatorsJsonPath
Expand All @@ -94,7 +96,11 @@ function validateEntries(
opts: NxPluginLintExecutorOptions,
requireSchemaFile: boolean
) {
for (const [name, entry] of Object.entries(json[field] || {})) {
const entries = Object.entries(json[field] || {});
if (entries.length) {
logger.log(` - ${field}`);
}
for (const [name, entry] of entries) {
validateEntry(name, entry as any, opts, requireSchemaFile);
}
}
Expand All @@ -115,31 +121,39 @@ function validateEntry(
}: NxPluginLintExecutorOptions,
requireSchemaFile: boolean
) {
logger.log(` - ${name}`);
// Checks schema file is valid json
if (validateSchemas && (entry.schema || requireSchemaFile)) {
let schemaError = false;
const schemaFilePath = path.join(
workspaceRoot,
path.dirname(packageJson),
entry.schema
);
if (!existsSync(schemaFilePath)) {
logger.error("Couldn't find schema file for " + name);
logger.error("Couldn't find schema file for " + name);
success = false;
schemaError = true;
} else {
try {
readJsonFile(schemaFilePath);
} catch (e) {
logger.error(`Couldn't parse schema file ${schemaFilePath}
logger.error(`Couldn't parse schema file ${schemaFilePath}
${e}`);
success = false;
schemaError = true;
}
}
if (!schemaError) {
logger.log(` ✔ valid schema`);
}
}

// Check implementation points to real file
// Checks schema file is valid json
if (validateImplementationLocations) {
let validImplementation = true;
const root = path.join(workspaceRoot, path.dirname(packageJson));
const relativeImplementationPath = entry.implementation ?? entry.factory;
const [implementationPath, identifier] = path
Expand All @@ -151,25 +165,32 @@ function validateEntry(
paths: [workspaceRoot],
});
} catch (e) {
logger.error("Couldn't find implementation file for " + name);
logger.error("Couldn't find implementation file for " + name);
success = false;
validImplementation = false;
}
if (identifier) {
const m = require(resolvedPath);
if (!(identifier in m && typeof m[identifier] === 'function')) {
logger.error(
`${name} - ${identifier} is not a function in ${relativeImplementationPath}`
` ${identifier} is not a function in ${relativeImplementationPath}`
);
success = false;
validImplementation = false;
}
}
if (validImplementation) {
logger.log(' ✔ valid implementation');
}
}

// Check valid version (only used for migrations)
if (entry.version) {
if (!valid(entry.version)) {
logger.error('Invalid version for migration ' + name);
logger.error('Invalid version for migration');
success = false;
} else {
logger.log(' ✔ valid version');
}
}
}
Expand Down

0 comments on commit e224b57

Please sign in to comment.