@nx/plugin 16.8.0-beta.0 → 16.8.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/generators.json CHANGED
@@ -4,17 +4,17 @@
4
4
  "extends": ["@nx/workspace"],
5
5
  "generators": {
6
6
  "plugin": {
7
- "factory": "./src/generators/plugin/plugin",
7
+ "factory": "./src/generators/plugin/plugin#pluginGeneratorInternal",
8
8
  "schema": "./src/generators/plugin/schema.json",
9
9
  "description": "Create a Nx Plugin."
10
10
  },
11
11
  "create-package": {
12
- "factory": "./src/generators/create-package/create-package",
12
+ "factory": "./src/generators/create-package/create-package#createPackageGeneratorInternal",
13
13
  "schema": "./src/generators/create-package/schema.json",
14
14
  "description": "Create a package which can be used by npx to create a new workspace"
15
15
  },
16
16
  "e2e-project": {
17
- "factory": "./src/generators/e2e-project/e2e",
17
+ "factory": "./src/generators/e2e-project/e2e#e2eProjectGeneratorInternal",
18
18
  "schema": "./src/generators/e2e-project/schema.json",
19
19
  "description": "Create a E2E application for a Nx Plugin."
20
20
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/plugin",
3
- "version": "16.8.0-beta.0",
3
+ "version": "16.8.0-beta.2",
4
4
  "private": false,
5
5
  "description": "This plugin is used to create Nx plugins! It contains generators for generating common plugin features like generators, executors, migrations and more.",
6
6
  "repository": {
@@ -28,13 +28,12 @@
28
28
  "migrations": "./migrations.json"
29
29
  },
30
30
  "dependencies": {
31
- "@nrwl/nx-plugin": "16.8.0-beta.0",
32
- "@nx/devkit": "16.8.0-beta.0",
33
- "@nx/jest": "16.8.0-beta.0",
34
- "@nx/js": "16.8.0-beta.0",
35
- "@nx/linter": "16.8.0-beta.0",
31
+ "@nrwl/nx-plugin": "16.8.0-beta.2",
32
+ "@nx/devkit": "16.8.0-beta.2",
33
+ "@nx/jest": "16.8.0-beta.2",
34
+ "@nx/js": "16.8.0-beta.2",
35
+ "@nx/linter": "16.8.0-beta.2",
36
36
  "@phenomnomnominal/tsquery": "~5.0.1",
37
- "dotenv": "~16.3.1",
38
37
  "fs-extra": "^11.1.0",
39
38
  "tslib": "^2.3.0"
40
39
  },
@@ -42,5 +41,5 @@
42
41
  "access": "public"
43
42
  },
44
43
  "type": "commonjs",
45
- "gitHead": "818352404283c1d34ab303d91b3bd16474f54916"
44
+ "gitHead": "9bcc04742f9e1516d8c1ddbfb1907770c347876f"
46
45
  }
@@ -1,4 +1,3 @@
1
- import 'dotenv/config';
2
1
  import type { ExecutorContext } from '@nx/devkit';
3
2
  import type { NxPluginE2EExecutorOptions } from './schema';
4
3
  export declare function nxPluginE2EExecutor(options: NxPluginE2EExecutorOptions, context: ExecutorContext): AsyncGenerator<{
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nxPluginE2EExecutor = void 0;
4
4
  const tslib_1 = require("tslib");
5
- require("dotenv/config");
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  const jest_impl_1 = require("@nx/jest/src/executors/jest/jest.impl");
8
7
  // TODO(v18): remove this
@@ -1,5 +1,6 @@
1
1
  import { Tree, GeneratorCallback } from '@nx/devkit';
2
2
  import { CreatePackageSchema } from './schema';
3
3
  export declare function createPackageGenerator(host: Tree, schema: CreatePackageSchema): Promise<GeneratorCallback>;
4
+ export declare function createPackageGeneratorInternal(host: Tree, schema: CreatePackageSchema): Promise<GeneratorCallback>;
4
5
  export default createPackageGenerator;
5
6
  export declare const createPackageSchematic: (generatorOptions: CreatePackageSchema) => (tree: any, context: any) => Promise<any>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPackageSchematic = exports.createPackageGenerator = void 0;
3
+ exports.createPackageSchematic = exports.createPackageGeneratorInternal = exports.createPackageGenerator = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const js_1 = require("@nx/js");
@@ -10,9 +10,15 @@ const normalize_schema_1 = require("./utils/normalize-schema");
10
10
  const has_generator_1 = require("../../utils/has-generator");
11
11
  const path_1 = require("path");
12
12
  function createPackageGenerator(host, schema) {
13
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
+ return yield createPackageGeneratorInternal(host, Object.assign({ projectNameAndRootFormat: 'derived' }, schema));
15
+ });
16
+ }
17
+ exports.createPackageGenerator = createPackageGenerator;
18
+ function createPackageGeneratorInternal(host, schema) {
13
19
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
20
  const tasks = [];
15
- const options = (0, normalize_schema_1.normalizeSchema)(host, schema);
21
+ const options = yield (0, normalize_schema_1.normalizeSchema)(host, schema);
16
22
  const pluginPackageName = yield addPresetGenerator(host, options);
17
23
  const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, {
18
24
  'create-nx-workspace': versions_1.nxVersion,
@@ -28,7 +34,7 @@ function createPackageGenerator(host, schema) {
28
34
  return (0, devkit_1.runTasksInSerial)(...tasks);
29
35
  });
30
36
  }
31
- exports.createPackageGenerator = createPackageGenerator;
37
+ exports.createPackageGeneratorInternal = createPackageGeneratorInternal;
32
38
  /**
33
39
  * Add a preset generator to the plugin if it doesn't exist
34
40
  * @param host
@@ -1,3 +1,4 @@
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-directory-utils';
1
2
  import type { Linter } from '@nx/linter';
2
3
 
3
4
  export interface CreatePackageSchema {
@@ -6,6 +7,7 @@ export interface CreatePackageSchema {
6
7
 
7
8
  // options to create cli package, passed to js library generator
8
9
  directory?: string;
10
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
9
11
  skipFormat: boolean;
10
12
  tags?: string;
11
13
  unitTestRunner: 'jest' | 'none';
@@ -37,6 +37,11 @@
37
37
  "type": "string",
38
38
  "description": "A directory where the app is placed."
39
39
  },
40
+ "projectNameAndRootFormat": {
41
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
42
+ "type": "string",
43
+ "enum": ["as-provided", "derived"]
44
+ },
40
45
  "linter": {
41
46
  "description": "The tool to use for running lint checks.",
42
47
  "type": "string",
@@ -2,9 +2,7 @@ import { Tree } from '@nx/devkit';
2
2
  import { CreatePackageSchema } from '../schema';
3
3
  export interface NormalizedSchema extends CreatePackageSchema {
4
4
  bundler: 'swc' | 'tsc';
5
- libsDir: string;
6
5
  projectName: string;
7
6
  projectRoot: string;
8
- projectDirectory: string;
9
7
  }
10
- export declare function normalizeSchema(host: Tree, schema: CreatePackageSchema): NormalizedSchema;
8
+ export declare function normalizeSchema(host: Tree, schema: CreatePackageSchema): Promise<NormalizedSchema>;
@@ -1,21 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeSchema = void 0;
4
- const devkit_1 = require("@nx/devkit");
4
+ const tslib_1 = require("tslib");
5
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
5
6
  function normalizeSchema(host, schema) {
6
7
  var _a;
7
- const { layoutDirectory, projectDirectory } = (0, devkit_1.extractLayoutDirectory)(schema.directory);
8
- const { libsDir: defaultLibsDir } = (0, devkit_1.getWorkspaceLayout)(host);
9
- const libsDir = layoutDirectory !== null && layoutDirectory !== void 0 ? layoutDirectory : defaultLibsDir;
10
- const name = (0, devkit_1.names)(schema.name).fileName;
11
- const fullProjectDirectory = projectDirectory
12
- ? `${(0, devkit_1.names)(projectDirectory).fileName}/${name}`
13
- : name;
14
- const projectName = fullProjectDirectory.replace(new RegExp('/', 'g'), '-');
15
- const projectRoot = (0, devkit_1.joinPathFragments)(libsDir, fullProjectDirectory);
16
- return Object.assign(Object.assign({}, schema), { bundler: (_a = schema.compiler) !== null && _a !== void 0 ? _a : 'tsc', libsDir,
17
- projectName,
18
- projectRoot,
19
- name, projectDirectory: fullProjectDirectory });
8
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
+ const { projectName, names: projectNames, projectRoot, projectNameAndRootFormat, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
10
+ name: schema.name,
11
+ projectType: 'library',
12
+ directory: schema.directory,
13
+ projectNameAndRootFormat: schema.projectNameAndRootFormat,
14
+ callingGenerator: '@nx/plugin:create-package',
15
+ });
16
+ schema.projectNameAndRootFormat = projectNameAndRootFormat;
17
+ return Object.assign(Object.assign({}, schema), { bundler: (_a = schema.compiler) !== null && _a !== void 0 ? _a : 'tsc', projectName,
18
+ projectRoot, name: projectNames.projectSimpleName });
19
+ });
20
20
  }
21
21
  exports.normalizeSchema = normalizeSchema;
@@ -2,5 +2,6 @@ import type { Tree } from '@nx/devkit';
2
2
  import { GeneratorCallback } from '@nx/devkit';
3
3
  import type { Schema } from './schema';
4
4
  export declare function e2eProjectGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
5
+ export declare function e2eProjectGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
5
6
  export default e2eProjectGenerator;
6
7
  export declare const e2eProjectSchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
@@ -1,28 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.e2eProjectSchematic = exports.e2eProjectGenerator = void 0;
3
+ exports.e2eProjectSchematic = exports.e2eProjectGeneratorInternal = exports.e2eProjectGenerator = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
7
  const jest_1 = require("@nx/jest");
7
8
  const js_1 = require("@nx/js");
8
9
  const generator_1 = require("@nx/js/src/generators/setup-verdaccio/generator");
9
10
  const add_local_registry_scripts_1 = require("@nx/js/src/utils/add-local-registry-scripts");
10
- const path_1 = require("path");
11
11
  const linter_1 = require("@nx/linter");
12
+ const path_1 = require("path");
12
13
  function normalizeOptions(host, options) {
13
14
  var _a;
14
- const { layoutDirectory, projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.projectDirectory);
15
- const { appsDir: defaultAppsDir } = (0, devkit_1.getWorkspaceLayout)(host);
16
- const appsDir = layoutDirectory !== null && layoutDirectory !== void 0 ? layoutDirectory : defaultAppsDir;
17
- const projectName = options.rootProject ? 'e2e' : `${options.pluginName}-e2e`;
18
- const projectRoot = projectDirectory && !options.rootProject
19
- ? (0, devkit_1.joinPathFragments)(appsDir, `${projectDirectory}-e2e`)
20
- : options.rootProject
21
- ? projectName
22
- : (0, devkit_1.joinPathFragments)(appsDir, projectName);
23
- const pluginPropertyName = (0, devkit_1.names)(options.pluginName).propertyName;
24
- return Object.assign(Object.assign({}, options), { projectName, linter: (_a = options.linter) !== null && _a !== void 0 ? _a : linter_1.Linter.EsLint, pluginPropertyName,
25
- projectRoot });
15
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ const projectName = options.rootProject ? 'e2e' : `${options.pluginName}-e2e`;
17
+ let projectRoot;
18
+ if (options.projectNameAndRootFormat === 'as-provided') {
19
+ const projectNameAndRootOptions = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
20
+ name: projectName,
21
+ projectType: 'application',
22
+ directory: options.rootProject || !options.projectDirectory
23
+ ? projectName
24
+ : `${options.projectDirectory}-e2e`,
25
+ projectNameAndRootFormat: `as-provided`,
26
+ callingGenerator: '@nx/plugin:e2e-project',
27
+ });
28
+ projectRoot = projectNameAndRootOptions.projectRoot;
29
+ }
30
+ else {
31
+ const { layoutDirectory, projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.projectDirectory);
32
+ const { appsDir: defaultAppsDir } = (0, devkit_1.getWorkspaceLayout)(host);
33
+ const appsDir = layoutDirectory !== null && layoutDirectory !== void 0 ? layoutDirectory : defaultAppsDir;
34
+ projectRoot = options.rootProject
35
+ ? projectName
36
+ : projectDirectory
37
+ ? (0, devkit_1.joinPathFragments)(appsDir, `${projectDirectory}-e2e`)
38
+ : (0, devkit_1.joinPathFragments)(appsDir, projectName);
39
+ }
40
+ const pluginPropertyName = (0, devkit_1.names)(options.pluginName).propertyName;
41
+ return Object.assign(Object.assign({}, options), { projectName, linter: (_a = options.linter) !== null && _a !== void 0 ? _a : linter_1.Linter.EsLint, pluginPropertyName,
42
+ projectRoot });
43
+ });
26
44
  }
27
45
  function validatePlugin(host, pluginName) {
28
46
  try {
@@ -82,10 +100,16 @@ function addLintingToApplication(tree, options) {
82
100
  });
83
101
  }
84
102
  function e2eProjectGenerator(host, schema) {
103
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
104
+ return yield e2eProjectGeneratorInternal(host, Object.assign({ projectNameAndRootFormat: 'derived' }, schema));
105
+ });
106
+ }
107
+ exports.e2eProjectGenerator = e2eProjectGenerator;
108
+ function e2eProjectGeneratorInternal(host, schema) {
85
109
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
86
110
  const tasks = [];
87
111
  validatePlugin(host, schema.pluginName);
88
- const options = normalizeOptions(host, schema);
112
+ const options = yield normalizeOptions(host, schema);
89
113
  addFiles(host, options);
90
114
  tasks.push(yield (0, generator_1.setupVerdaccio)(host, {
91
115
  skipFormat: true,
@@ -100,6 +124,6 @@ function e2eProjectGenerator(host, schema) {
100
124
  return (0, devkit_1.runTasksInSerial)(...tasks);
101
125
  });
102
126
  }
103
- exports.e2eProjectGenerator = e2eProjectGenerator;
127
+ exports.e2eProjectGeneratorInternal = e2eProjectGeneratorInternal;
104
128
  exports.default = e2eProjectGenerator;
105
129
  exports.e2eProjectSchematic = (0, devkit_1.convertNxGenerator)(e2eProjectGenerator);
@@ -1,9 +1,11 @@
1
- import { Linter } from '@nx/linter';
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-directory-utils';
2
+ import type { Linter } from '@nx/linter';
2
3
 
3
4
  export interface Schema {
4
5
  pluginName: string;
5
6
  npmPackageName: string;
6
7
  projectDirectory?: string;
8
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
7
9
  pluginOutputPath?: string;
8
10
  jestConfig?: string;
9
11
  linter?: Linter;
@@ -21,6 +21,11 @@
21
21
  "type": "string",
22
22
  "description": "the directory where the plugin is placed."
23
23
  },
24
+ "projectNameAndRootFormat": {
25
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
26
+ "type": "string",
27
+ "enum": ["as-provided", "derived"]
28
+ },
24
29
  "pluginOutputPath": {
25
30
  "type": "string",
26
31
  "description": "the output path of the plugin after it builds.",
@@ -5,6 +5,8 @@ const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const logger_1 = require("nx/src/utils/logger");
7
7
  const package_json_1 = require("nx/src/utils/package-json");
8
+ const eslint_file_1 = require("@nx/linter/src/generators/utils/eslint-file");
9
+ const flat_config_1 = require("@nx/linter/src/utils/flat-config");
8
10
  function pluginLintCheckGenerator(host, options) {
9
11
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
12
  const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
@@ -52,17 +54,14 @@ function addMigrationJsonChecks(host, options, packageJson) {
52
54
  eslintTargetConfiguration.options.lintFilePatterns.push(migrationsJsonPath);
53
55
  (0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfiguration);
54
56
  // Update project level eslintrc
55
- (0, devkit_1.updateJson)(host, `${projectConfiguration.root}/.eslintrc.json`, (c) => {
56
- const override = c.overrides.find((o) => {
57
- var _a, _b, _c, _d;
58
- return ((_b = Object.keys((_a = o.rules) !== null && _a !== void 0 ? _a : {})) === null || _b === void 0 ? void 0 : _b.includes('@nx/nx-plugin-checks')) ||
59
- ((_d = Object.keys((_c = o.rules) !== null && _c !== void 0 ? _c : {})) === null || _d === void 0 ? void 0 : _d.includes('@nrwl/nx/nx-plugin-checks'));
60
- });
61
- if (Array.isArray(override === null || override === void 0 ? void 0 : override.files) &&
62
- !override.files.includes(relativeMigrationsJsonPath)) {
63
- override.files.push(relativeMigrationsJsonPath);
64
- }
65
- return c;
57
+ (0, eslint_file_1.updateOverrideInLintConfig)(host, projectConfiguration.root, (o) => {
58
+ var _a, _b, _c, _d;
59
+ return ((_b = Object.keys((_a = o.rules) !== null && _a !== void 0 ? _a : {})) === null || _b === void 0 ? void 0 : _b.includes('@nx/nx-plugin-checks')) ||
60
+ ((_d = Object.keys((_c = o.rules) !== null && _c !== void 0 ? _c : {})) === null || _d === void 0 ? void 0 : _d.includes('@nrwl/nx/nx-plugin-checks'));
61
+ }, (o) => {
62
+ const fileSet = new Set(Array.isArray(o.files) ? o.files : [o.files]);
63
+ fileSet.add(relativeMigrationsJsonPath);
64
+ return Object.assign(Object.assign({}, o), { files: Array.from(fileSet) });
66
65
  });
67
66
  }
68
67
  }
@@ -100,64 +99,62 @@ function updateProjectTarget(host, options, packageJson) {
100
99
  (0, devkit_1.updateProjectConfiguration)(host, options.projectName, project);
101
100
  }
102
101
  function updateProjectEslintConfig(host, options, packageJson) {
103
- var _a, _b, _c;
104
- // Update the project level lint configuration to specify
105
- // the plugin schema rule for generated files
106
- const eslintPath = `${options.root}/.eslintrc.json`;
107
- if (host.exists(eslintPath)) {
108
- const eslintConfig = (0, devkit_1.readJson)(host, eslintPath);
109
- (_a = eslintConfig.overrides) !== null && _a !== void 0 ? _a : (eslintConfig.overrides = []);
110
- let entry = eslintConfig.overrides.find((x) => {
102
+ if ((0, eslint_file_1.isEslintConfigSupported)(host, options.root)) {
103
+ const lookup = (o) => {
111
104
  var _a, _b;
112
- return Object.keys((_a = x.rules) !== null && _a !== void 0 ? _a : {}).includes('@nx/nx-plugin-checks') ||
113
- Object.keys((_b = x.rules) !== null && _b !== void 0 ? _b : {}).includes('@nrwl/nx/nx-plugin-checks');
114
- });
115
- const newentry = !entry;
116
- entry !== null && entry !== void 0 ? entry : (entry = { files: [] });
117
- entry.files = [
118
- ...new Set([
119
- ...((_b = entry.files) !== null && _b !== void 0 ? _b : []),
120
- ...[
121
- './package.json',
122
- packageJson.generators,
123
- packageJson.executors,
124
- packageJson.schematics,
125
- packageJson.builders,
126
- ].filter((f) => !!f),
127
- ]),
128
- ];
129
- entry.parser = 'jsonc-eslint-parser';
130
- (_c = entry.rules) !== null && _c !== void 0 ? _c : (entry.rules = {
131
- '@nx/nx-plugin-checks': 'error',
132
- });
133
- if (newentry) {
134
- eslintConfig.overrides.push(entry);
105
+ return Object.keys((_a = o.rules) !== null && _a !== void 0 ? _a : {}).includes('@nx/nx-plugin-checks') ||
106
+ Object.keys((_b = o.rules) !== null && _b !== void 0 ? _b : {}).includes('@nrwl/nx/nx-plugin-checks');
107
+ };
108
+ const files = [
109
+ './package.json',
110
+ packageJson.generators,
111
+ packageJson.executors,
112
+ packageJson.schematics,
113
+ packageJson.builders,
114
+ ].filter((f) => !!f);
115
+ const parser = (0, flat_config_1.useFlatConfig)(host)
116
+ ? { languageOptions: { parser: 'jsonc-eslint-parser' } }
117
+ : { parser: 'jsonc-eslint-parser' };
118
+ if ((0, eslint_file_1.lintConfigHasOverride)(host, options.root, lookup)) {
119
+ // update it
120
+ (0, eslint_file_1.updateOverrideInLintConfig)(host, options.root, lookup, (o) => (Object.assign(Object.assign(Object.assign(Object.assign({}, o), { files: [
121
+ ...new Set([
122
+ ...(Array.isArray(o.files) ? o.files : [o.files]),
123
+ ...files,
124
+ ]),
125
+ ] }), parser), { rules: Object.assign(Object.assign({}, o.rules), { '@nx/nx-plugin-checks': 'error' }) })));
126
+ }
127
+ else {
128
+ // add it
129
+ (0, eslint_file_1.addOverrideToLintConfig)(host, options.root, Object.assign(Object.assign({ files }, parser), { rules: {
130
+ '@nx/nx-plugin-checks': 'error',
131
+ } }));
135
132
  }
136
- (0, devkit_1.writeJson)(host, eslintPath, eslintConfig);
137
133
  }
138
134
  }
139
135
  // Update the root eslint to specify a parser for json files
140
136
  // This is required, otherwise every json file that is not overriden
141
137
  // will display false errors in the IDE
142
138
  function updateRootEslintConfig(host) {
143
- var _a;
144
- if (host.exists('.eslintrc.json')) {
145
- const rootESLint = (0, devkit_1.readJson)(host, '.eslintrc.json');
146
- (_a = rootESLint.overrides) !== null && _a !== void 0 ? _a : (rootESLint.overrides = []);
147
- if (!eslintConfigContainsJsonOverride(rootESLint)) {
148
- rootESLint.overrides.push({
139
+ if ((0, eslint_file_1.isEslintConfigSupported)(host)) {
140
+ if (!(0, eslint_file_1.lintConfigHasOverride)(host, '', (o) => {
141
+ var _a;
142
+ return Array.isArray(o.files)
143
+ ? o.files.some((f) => f.match(/\.json$/))
144
+ : !!((_a = o.files) === null || _a === void 0 ? void 0 : _a.match(/\.json$/));
145
+ }, true)) {
146
+ (0, eslint_file_1.addOverrideToLintConfig)(host, '', {
149
147
  files: '*.json',
150
148
  parser: 'jsonc-eslint-parser',
151
149
  rules: {},
152
- });
153
- (0, devkit_1.writeJson)(host, '.eslintrc.json', rootESLint);
150
+ }, { checkBaseConfig: true });
154
151
  }
155
152
  }
156
153
  else {
157
154
  devkit_1.output.note({
158
155
  title: 'Unable to update root eslint config.',
159
156
  bodyLines: [
160
- 'We only automatically update the root eslint config if it is json.',
157
+ 'We only automatically update the root eslint config if it is json or flat config.',
161
158
  'If you are using a different format, you will need to update it manually.',
162
159
  'You need to set the parser to jsonc-eslint-parser for json files.',
163
160
  ],
@@ -180,14 +177,6 @@ function setupVsCodeLintingForJsonFiles(host) {
180
177
  }
181
178
  (0, devkit_1.writeJson)(host, '.vscode/settings.json', existing);
182
179
  }
183
- function eslintConfigContainsJsonOverride(eslintConfig) {
184
- return eslintConfig.overrides.some((x) => {
185
- if (typeof x.files === 'string' && x.files.includes('.json')) {
186
- return true;
187
- }
188
- return Array.isArray(x.files) && x.files.some((f) => f.includes('.json'));
189
- });
190
- }
191
180
  function projectIsEsLintEnabled(project) {
192
181
  return !!getEsLintOptions(project);
193
182
  }
@@ -1,5 +1,6 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import type { Schema } from './schema';
3
3
  export declare function pluginGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
4
+ export declare function pluginGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
4
5
  export default pluginGenerator;
5
6
  export declare const pluginSchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pluginSchematic = exports.pluginGenerator = void 0;
3
+ exports.pluginSchematic = exports.pluginGeneratorInternal = exports.pluginGenerator = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const js_1 = require("@nx/js");
@@ -54,7 +54,13 @@ function updatePluginConfig(host, options) {
54
54
  }
55
55
  function pluginGenerator(host, schema) {
56
56
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
57
- const options = (0, normalize_schema_1.normalizeOptions)(host, schema);
57
+ return yield pluginGeneratorInternal(host, Object.assign({ projectNameAndRootFormat: 'derived' }, schema));
58
+ });
59
+ }
60
+ exports.pluginGenerator = pluginGenerator;
61
+ function pluginGeneratorInternal(host, schema) {
62
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
63
+ const options = yield (0, normalize_schema_1.normalizeOptions)(host, schema);
58
64
  const tasks = [];
59
65
  tasks.push(yield (0, js_1.libraryGenerator)(host, Object.assign(Object.assign({}, schema), { config: 'project', bundler: options.bundler, publishable: options.publishable, importPath: options.npmPackageName, skipFormat: true })));
60
66
  if (options.bundler === 'tsc') {
@@ -77,10 +83,11 @@ function pluginGenerator(host, schema) {
77
83
  tasks.push(yield (0, e2e_1.e2eProjectGenerator)(host, {
78
84
  pluginName: options.name,
79
85
  projectDirectory: options.projectDirectory,
80
- pluginOutputPath: `dist/${options.libsDir}/${options.projectDirectory}`,
86
+ pluginOutputPath: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? options.name : options.projectRoot),
81
87
  npmPackageName: options.npmPackageName,
82
88
  skipFormat: true,
83
89
  rootProject: options.rootProject,
90
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
84
91
  }));
85
92
  }
86
93
  if (options.linter === linter_1.Linter.EsLint && !options.skipLintChecks) {
@@ -92,6 +99,6 @@ function pluginGenerator(host, schema) {
92
99
  return (0, devkit_1.runTasksInSerial)(...tasks);
93
100
  });
94
101
  }
95
- exports.pluginGenerator = pluginGenerator;
102
+ exports.pluginGeneratorInternal = pluginGeneratorInternal;
96
103
  exports.default = pluginGenerator;
97
104
  exports.pluginSchematic = (0, devkit_1.convertNxGenerator)(pluginGenerator);
@@ -1,8 +1,10 @@
1
- import { Linter } from '@nx/linter';
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-directory-utils';
2
+ import type { Linter } from '@nx/linter';
2
3
 
3
4
  export interface Schema {
4
5
  name: string;
5
6
  directory?: string;
7
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
6
8
  importPath?: string;
7
9
  skipTsConfig?: boolean; // default is false
8
10
  skipFormat?: boolean; // default is false
@@ -20,12 +20,18 @@
20
20
  "index": 0
21
21
  },
22
22
  "x-prompt": "What name would you like to use for the plugin?",
23
- "x-priority": "important"
23
+ "x-priority": "important",
24
+ "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$"
24
25
  },
25
26
  "directory": {
26
27
  "type": "string",
27
28
  "description": "A directory where the plugin is placed."
28
29
  },
30
+ "projectNameAndRootFormat": {
31
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
32
+ "type": "string",
33
+ "enum": ["as-provided", "derived"]
34
+ },
29
35
  "importPath": {
30
36
  "type": "string",
31
37
  "description": "How the plugin will be published, like `@myorg/my-awesome-plugin`. Note this must be a valid NPM name.",
@@ -3,7 +3,6 @@ import { Schema } from '../schema';
3
3
  export interface NormalizedSchema extends Schema {
4
4
  name: string;
5
5
  fileName: string;
6
- libsDir: string;
7
6
  projectRoot: string;
8
7
  projectDirectory: string;
9
8
  parsedTags: string[];
@@ -11,4 +10,4 @@ export interface NormalizedSchema extends Schema {
11
10
  bundler: 'swc' | 'tsc';
12
11
  publishable: boolean;
13
12
  }
14
- export declare function normalizeOptions(host: Tree, options: Schema): NormalizedSchema;
13
+ export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -1,32 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const devkit_1 = require("@nx/devkit");
5
- const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
6
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
7
  function normalizeOptions(host, options) {
7
8
  var _a, _b;
8
- const { layoutDirectory, projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
9
- const { libsDir: defaultLibsDir } = (0, devkit_1.getWorkspaceLayout)(host);
10
- const libsDir = layoutDirectory !== null && layoutDirectory !== void 0 ? layoutDirectory : defaultLibsDir;
11
- const name = (0, devkit_1.names)(options.name).fileName;
12
- const fullProjectDirectory = projectDirectory
13
- ? `${(0, devkit_1.names)(projectDirectory).fileName}/${name}`
14
- : options.rootProject
15
- ? '.'
16
- : name;
17
- const projectName = options.rootProject
18
- ? name
19
- : fullProjectDirectory.replace(new RegExp('/', 'g'), '-');
20
- const fileName = projectName;
21
- const projectRoot = options.rootProject
22
- ? fullProjectDirectory
23
- : (0, devkit_1.joinPathFragments)(libsDir, fullProjectDirectory);
24
- const parsedTags = options.tags
25
- ? options.tags.split(',').map((s) => s.trim())
26
- : [];
27
- const npmPackageName = options.importPath || (0, get_import_path_1.getImportPath)(host, name);
28
- return Object.assign(Object.assign({}, options), { bundler: (_a = options.compiler) !== null && _a !== void 0 ? _a : 'tsc', fileName,
29
- libsDir, name: projectName, projectRoot, projectDirectory: fullProjectDirectory, parsedTags,
30
- npmPackageName, publishable: (_b = options.publishable) !== null && _b !== void 0 ? _b : false });
9
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
+ const { projectName, projectRoot, importPath: npmPackageName, projectNameAndRootFormat, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
11
+ name: options.name,
12
+ projectType: 'library',
13
+ directory: options.directory,
14
+ importPath: options.importPath,
15
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
16
+ rootProject: options.rootProject,
17
+ callingGenerator: '@nx/plugin:plugin',
18
+ });
19
+ options.projectNameAndRootFormat = projectNameAndRootFormat;
20
+ options.rootProject = projectRoot === '.';
21
+ let projectDirectory = projectRoot;
22
+ if (options.projectNameAndRootFormat === 'derived') {
23
+ let { layoutDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
24
+ if (!layoutDirectory) {
25
+ const { libsDir } = (0, devkit_1.getWorkspaceLayout)(host);
26
+ layoutDirectory = libsDir;
27
+ }
28
+ if (projectRoot.startsWith(`${layoutDirectory}/`)) {
29
+ projectDirectory = projectRoot.replace(`${layoutDirectory}/`, '');
30
+ }
31
+ }
32
+ const parsedTags = options.tags
33
+ ? options.tags.split(',').map((s) => s.trim())
34
+ : [];
35
+ return Object.assign(Object.assign({}, options), { bundler: (_a = options.compiler) !== null && _a !== void 0 ? _a : 'tsc', fileName: projectName, name: projectName, projectRoot,
36
+ projectDirectory,
37
+ parsedTags,
38
+ npmPackageName, publishable: (_b = options.publishable) !== null && _b !== void 0 ? _b : false });
39
+ });
31
40
  }
32
41
  exports.normalizeOptions = normalizeOptions;