nx 13.9.3 → 13.10.0-beta.1

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.
@@ -1,31 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergePluginTargetsWithNxTargets = exports.loadNxPlugins = void 0;
3
+ exports.resolveLocalNxPlugin = exports.readPluginPackageJson = exports.mergePluginTargetsWithNxTargets = exports.loadNxPlugins = void 0;
4
4
  const fast_glob_1 = require("fast-glob");
5
5
  const fs_1 = require("fs");
6
- const path_1 = require("path");
6
+ const path = require("path");
7
7
  const app_root_1 = require("../utils/app-root");
8
8
  const fileutils_1 = require("../utils/fileutils");
9
- function findPluginPackageJson(path, plugin) {
10
- while (true) {
11
- if (!path.startsWith(app_root_1.appRootPath)) {
12
- throw new Error("Couldn't find a package.json for Nx plugin:" + plugin);
13
- }
14
- if ((0, fs_1.existsSync)((0, path_1.join)(path, 'package.json'))) {
15
- return (0, path_1.join)(path, 'package.json');
16
- }
17
- path = (0, path_1.dirname)(path);
18
- }
19
- }
9
+ const register_1 = require("../utils/register");
10
+ const workspace_1 = require("./workspace");
11
+ // Short lived cache (cleared between cmd runs)
12
+ // holding resolved nx plugin objects.
13
+ // Allows loadNxPlugins to be called multiple times w/o
14
+ // executing resolution mulitple times.
20
15
  let nxPluginCache = null;
21
- function loadNxPlugins(plugins) {
16
+ function loadNxPlugins(plugins, paths = [app_root_1.appRootPath]) {
22
17
  return (plugins === null || plugins === void 0 ? void 0 : plugins.length)
23
18
  ? nxPluginCache ||
24
- (nxPluginCache = plugins.map((path) => {
25
- const pluginPath = require.resolve(path, {
26
- paths: [app_root_1.appRootPath],
27
- });
28
- const { name } = (0, fileutils_1.readJsonFile)(findPluginPackageJson(pluginPath, path));
19
+ (nxPluginCache = plugins.map((moduleName) => {
20
+ let pluginPath;
21
+ try {
22
+ pluginPath = require.resolve(moduleName, {
23
+ paths,
24
+ });
25
+ }
26
+ catch (e) {
27
+ if (e.code === 'MODULE_NOT_FOUND') {
28
+ const plugin = resolveLocalNxPlugin(moduleName);
29
+ const main = readPluginMainFromProjectConfiguration(plugin.projectConfig);
30
+ pluginPath = main ? path.join(app_root_1.appRootPath, main) : plugin.path;
31
+ }
32
+ else {
33
+ throw e;
34
+ }
35
+ }
36
+ const packageJsonPath = path.join(pluginPath, 'package.json');
37
+ const { name } = !['.ts', '.js'].some((x) => x === path.extname(pluginPath)) && // Not trying to point to a ts or js file
38
+ (0, fs_1.existsSync)(packageJsonPath) // plugin has a package.json
39
+ ? (0, fileutils_1.readJsonFile)(packageJsonPath) // read name from package.json
40
+ : { name: path.basename(pluginPath) }; // use the name of the file we point to
29
41
  const plugin = require(pluginPath);
30
42
  plugin.name = name;
31
43
  return plugin;
@@ -41,13 +53,110 @@ function mergePluginTargetsWithNxTargets(projectRoot, targets, plugins) {
41
53
  continue;
42
54
  }
43
55
  const projectFiles = (0, fast_glob_1.sync)(`+(${plugin.projectFilePatterns.join('|')})`, {
44
- cwd: (0, path_1.join)(app_root_1.appRootPath, projectRoot),
56
+ cwd: path.join(app_root_1.appRootPath, projectRoot),
45
57
  });
46
58
  for (const projectFile of projectFiles) {
47
- newTargets = Object.assign(Object.assign({}, newTargets), plugin.registerProjectTargets((0, path_1.join)(projectRoot, projectFile)));
59
+ newTargets = Object.assign(Object.assign({}, newTargets), plugin.registerProjectTargets(path.join(projectRoot, projectFile)));
48
60
  }
49
61
  }
50
62
  return Object.assign(Object.assign({}, newTargets), targets);
51
63
  }
52
64
  exports.mergePluginTargetsWithNxTargets = mergePluginTargetsWithNxTargets;
65
+ function readPluginPackageJson(pluginName, paths = [app_root_1.appRootPath]) {
66
+ let packageJsonPath;
67
+ try {
68
+ packageJsonPath = require.resolve(`${pluginName}/package.json`, {
69
+ paths,
70
+ });
71
+ }
72
+ catch (e) {
73
+ if (e.code === 'MODULE_NOT_FOUND') {
74
+ const localPluginPath = resolveLocalNxPlugin(pluginName);
75
+ if (localPluginPath) {
76
+ const localPluginPackageJson = path.join(localPluginPath.path, 'package.json');
77
+ return {
78
+ path: localPluginPackageJson,
79
+ json: (0, fileutils_1.readJsonFile)(localPluginPackageJson),
80
+ };
81
+ }
82
+ }
83
+ throw e;
84
+ }
85
+ return { json: (0, fileutils_1.readJsonFile)(packageJsonPath), path: packageJsonPath };
86
+ }
87
+ exports.readPluginPackageJson = readPluginPackageJson;
88
+ /**
89
+ * Builds a plugin package and returns the path to output
90
+ * @param importPath What is the import path that refers to a potential plugin?
91
+ * @returns The path to the built plugin, or null if it doesn't exist
92
+ */
93
+ const localPluginCache = {};
94
+ function resolveLocalNxPlugin(importPath, root = app_root_1.appRootPath) {
95
+ var _a;
96
+ (_a = localPluginCache[importPath]) !== null && _a !== void 0 ? _a : (localPluginCache[importPath] = lookupLocalPlugin(importPath, root));
97
+ return localPluginCache[importPath];
98
+ }
99
+ exports.resolveLocalNxPlugin = resolveLocalNxPlugin;
100
+ let tsNodeAndPathsRegistered = false;
101
+ function registerTSTranspiler() {
102
+ if (!tsNodeAndPathsRegistered) {
103
+ (0, register_1.registerTsProject)(app_root_1.appRootPath, 'tsconfig.base.json');
104
+ }
105
+ tsNodeAndPathsRegistered = true;
106
+ }
107
+ function lookupLocalPlugin(importPath, root = app_root_1.appRootPath) {
108
+ const workspace = new workspace_1.Workspaces(root).readWorkspaceConfiguration({
109
+ _ignorePluginInference: true,
110
+ });
111
+ const plugin = findNxProjectForImportPath(importPath, workspace, root);
112
+ if (!plugin) {
113
+ return null;
114
+ }
115
+ if (!tsNodeAndPathsRegistered) {
116
+ registerTSTranspiler();
117
+ }
118
+ const projectConfig = workspace.projects[plugin];
119
+ return { path: path.join(root, projectConfig.root), projectConfig };
120
+ }
121
+ function findNxProjectForImportPath(importPath, workspace, root = app_root_1.appRootPath) {
122
+ var _a;
123
+ const tsConfigPaths = readTsConfigPaths(root);
124
+ const possiblePaths = (_a = tsConfigPaths[importPath]) === null || _a === void 0 ? void 0 : _a.map((p) => path.resolve(root, p));
125
+ if (tsConfigPaths[importPath]) {
126
+ const projectRootMappings = Object.entries(workspace.projects).reduce((m, [project, config]) => {
127
+ m[path.resolve(root, config.root)] = project;
128
+ return m;
129
+ }, {});
130
+ for (const root of Object.keys(projectRootMappings)) {
131
+ if (possiblePaths.some((p) => p.startsWith(root))) {
132
+ return projectRootMappings[root];
133
+ }
134
+ }
135
+ if (process.env.NX_VERBOSE_LOGGING) {
136
+ console.log('Unable to find local plugin', possiblePaths, projectRootMappings);
137
+ }
138
+ throw new Error('Unable to resolve local plugin with import path ' + importPath);
139
+ }
140
+ }
141
+ let tsconfigPaths;
142
+ function readTsConfigPaths(root = app_root_1.appRootPath) {
143
+ if (!tsconfigPaths) {
144
+ const tsconfigPath = ['tsconfig.base.json', 'tsconfig.json']
145
+ .map((x) => path.join(root, x))
146
+ .filter((x) => (0, fs_1.existsSync)(x))[0];
147
+ if (!tsconfigPath) {
148
+ throw new Error('unable to find tsconfig.base.json or tsconfig.json');
149
+ }
150
+ const { compilerOptions } = (0, fileutils_1.readJsonFile)(tsconfigPath);
151
+ tsconfigPaths = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.paths;
152
+ }
153
+ return tsconfigPaths;
154
+ }
155
+ function readPluginMainFromProjectConfiguration(plugin) {
156
+ var _a, _b, _c;
157
+ const { main } = ((_a = Object.values(plugin.targets).find((x) => ['@nrwl/js:tsc', '@nrwl/js:swc', '@nrwl/node:package'].includes(x.executor))) === null || _a === void 0 ? void 0 : _a.options) ||
158
+ ((_c = (_b = plugin.targets) === null || _b === void 0 ? void 0 : _b.build) === null || _c === void 0 ? void 0 : _c.options) ||
159
+ {};
160
+ return main;
161
+ }
53
162
  //# sourceMappingURL=nx-plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nx-plugin.js","sourceRoot":"","sources":["../../../../../packages/nx/src/shared/nx-plugin.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AACjC,2BAAgC;AAChC,+BAAqC;AACr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MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,eAAU,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,IAAI,CAAC,YAAY,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;SACvE;QACD,MAAM,EAAE,eAAe,EAAE,GAAG,IAAA,wBAAY,EAAC,YAAY,CAAC,CAAC;QACvD,aAAa,GAAG,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,KAAK,CAAC;KACxC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAS,sCAAsC,CAC7C,MAA4B;;IAE5B,MAAM,EAAE,IAAI,EAAE,GACZ,CAAA,MAAA,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACvC,CAAC,cAAc,EAAE,cAAc,EAAE,oBAAoB,CAAC,CAAC,QAAQ,CAC7D,CAAC,CAAC,QAAQ,CACX,CACF,0CAAE,OAAO;SACV,MAAA,MAAA,MAAM,CAAC,OAAO,0CAAE,KAAK,0CAAE,OAAO,CAAA;QAC9B,EAAE,CAAC;IACL,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -20,7 +20,7 @@ export declare function buildTargetFromScript(script: string, nx: NxProjectPacka
20
20
  executor: string;
21
21
  options: any;
22
22
  outputs?: string[];
23
- dependsOn?: import("./workspace").TargetDependencyConfig[];
23
+ dependsOn?: import("./workspace.model").TargetDependencyConfig[];
24
24
  configurations?: {
25
25
  [config: string]: any;
26
26
  };
@@ -4,7 +4,7 @@ exports.lookupUnmatched = exports.convertSmartDefaultsIntoNamedParams = exports.
4
4
  const tslib_1 = require("tslib");
5
5
  const logger_1 = require("./logger");
6
6
  function handleErrors(isVerbose, fn) {
7
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
7
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
8
  try {
9
9
  return yield fn();
10
10
  }
@@ -364,7 +364,7 @@ function combineOptionsForExecutor(commandLineOpts, config, target, schema, defa
364
364
  }
365
365
  exports.combineOptionsForExecutor = combineOptionsForExecutor;
366
366
  function combineOptionsForGenerator(commandLineOpts, collectionName, generatorName, wc, schema, isInteractive, defaultProjectName, relativeCwd, isVerbose = false) {
367
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
367
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
368
368
  const generatorDefaults = wc
369
369
  ? getGeneratorDefaults(defaultProjectName, wc, collectionName, generatorName)
370
370
  : {};
@@ -441,7 +441,7 @@ function getGeneratorDefaults(projectName, wc, collectionName, generatorName) {
441
441
  return defaults;
442
442
  }
443
443
  function promptForValues(opts, schema) {
444
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
444
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
445
445
  const prompts = [];
446
446
  Object.entries(schema.properties).forEach(([k, v]) => {
447
447
  if (v['x-prompt'] && opts[k] === undefined) {
@@ -1,227 +1,17 @@
1
- import type { NxJsonConfiguration } from './nx';
2
- import { TaskGraph } from './tasks';
3
1
  import { Ignore } from 'ignore';
4
- export interface Workspace extends WorkspaceJsonConfiguration, NxJsonConfiguration {
5
- projects: Record<string, ProjectConfiguration>;
6
- }
7
- /**
8
- * Workspace configuration
9
- */
10
- export interface WorkspaceJsonConfiguration {
11
- /**
12
- * Version of the configuration format
13
- */
14
- version: number;
15
- /**
16
- * Projects' projects
17
- */
18
- projects: {
19
- [projectName: string]: ProjectConfiguration;
20
- };
21
- }
22
- export interface RawWorkspaceJsonConfiguration extends Omit<WorkspaceJsonConfiguration, 'projects'> {
23
- projects: {
24
- [projectName: string]: ProjectConfiguration | string;
25
- };
26
- }
27
- /**
28
- * Type of project supported
29
- */
30
- export declare type ProjectType = 'library' | 'application';
31
- /**
32
- * Project configuration
33
- */
34
- export interface ProjectConfiguration {
35
- /**
36
- * Project's name. Optional if specified in workspace.json
37
- */
38
- name?: string;
39
- /**
40
- * Project's targets
41
- */
42
- targets?: {
43
- [targetName: string]: TargetConfiguration;
44
- };
45
- /**
46
- * Project's location relative to the root of the workspace
47
- */
48
- root: string;
49
- /**
50
- * The location of project's sources relative to the root of the workspace
51
- */
52
- sourceRoot?: string;
53
- /**
54
- * Project type
55
- */
56
- projectType?: ProjectType;
57
- /**
58
- * List of default values used by generators.
59
- *
60
- * These defaults are project specific.
61
- *
62
- * Example:
63
- *
64
- * ```
65
- * {
66
- * "@nrwl/react": {
67
- * "library": {
68
- * "style": "scss"
69
- * }
70
- * }
71
- * }
72
- * ```
73
- */
74
- generators?: {
75
- [collectionName: string]: {
76
- [generatorName: string]: any;
77
- };
78
- };
79
- /**
80
- * List of projects which are added as a dependency
81
- */
82
- implicitDependencies?: string[];
83
- /**
84
- * List of tags used by nx-enforce-module-boundaries / project graph
85
- */
86
- tags?: string[];
87
- }
88
- export interface TargetDependencyConfig {
89
- /**
90
- * This the projects that the targets belong to
91
- *
92
- * 'self': This target depends on another target of the same project
93
- * 'deps': This target depends on targets of the projects of it's deps.
94
- */
95
- projects: 'self' | 'dependencies';
96
- /**
97
- * The name of the target
98
- */
99
- target: string;
100
- }
101
- /**
102
- * Target's configuration
103
- */
104
- export interface TargetConfiguration {
105
- /**
106
- * The executor/builder used to implement the target.
107
- *
108
- * Example: '@nrwl/web:rollup'
109
- */
110
- executor: string;
111
- /**
112
- * List of the target's outputs. The outputs will be cached by the Nx computation
113
- * caching engine.
114
- */
115
- outputs?: string[];
116
- /**
117
- * This describes other targets that a target depends on.
118
- */
119
- dependsOn?: TargetDependencyConfig[];
120
- /**
121
- * Target's options. They are passed in to the executor.
122
- */
123
- options?: any;
124
- /**
125
- * Sets of options
126
- */
127
- configurations?: {
128
- [config: string]: any;
129
- };
130
- /**
131
- * A default named configuration to use when a target configuration is not provided.
132
- */
133
- defaultConfiguration?: string;
134
- }
2
+ import { ExecutorConfig, Generator, ProjectConfiguration, WorkspaceJsonConfiguration } from './workspace.model';
3
+ import type { NxJsonConfiguration } from './nx';
4
+ export * from './workspace.model';
135
5
  export declare function workspaceConfigName(root: string): "angular.json" | "workspace.json";
136
- /**
137
- * A callback function that is executed after changes are made to the file system
138
- */
139
- export declare type GeneratorCallback = () => void | Promise<void>;
140
- /**
141
- * A function that schedules updates to the filesystem to be done atomically
142
- */
143
- export declare type Generator<T = unknown> = (tree: any, schema: T) => void | GeneratorCallback | Promise<void | GeneratorCallback>;
144
- export interface ExecutorConfig {
145
- schema: any;
146
- hasherFactory?: () => any;
147
- implementationFactory: () => Executor;
148
- batchImplementationFactory?: () => TaskGraphExecutor;
149
- }
150
- /**
151
- * Implementation of a target of a project
152
- */
153
- export declare type Executor<T = any> = (
154
- /**
155
- * Options that users configure or pass via the command line
156
- */
157
- options: T, context: ExecutorContext) => Promise<{
158
- success: boolean;
159
- }> | AsyncIterableIterator<{
160
- success: boolean;
161
- }>;
162
- /**
163
- * Implementation of a target of a project that handles multiple projects to be batched
164
- */
165
- export declare type TaskGraphExecutor<T = any> = (
166
- /**
167
- * Graph of Tasks to be executed
168
- */
169
- taskGraph: TaskGraph,
170
- /**
171
- * Map of Task IDs to options for the task
172
- */
173
- options: Record<string, T>,
174
- /**
175
- * Set of overrides for the overall execution
176
- */
177
- overrides: T, context: ExecutorContext) => Promise<Record<string, {
178
- success: boolean;
179
- terminalOutput: string;
180
- }>>;
181
- /**
182
- * Context that is passed into an executor
183
- */
184
- export interface ExecutorContext {
185
- /**
186
- * The root of the workspace
187
- */
188
- root: string;
189
- /**
190
- * The name of the project being executed on
191
- */
192
- projectName?: string;
193
- /**
194
- * The name of the target being executed
195
- */
196
- targetName?: string;
197
- /**
198
- * The name of the configuration being executed
199
- */
200
- configurationName?: string;
201
- /**
202
- * The configuration of the target being executed
203
- */
204
- target?: TargetConfiguration;
205
- /**
206
- * The full workspace configuration
207
- */
208
- workspace: WorkspaceJsonConfiguration & NxJsonConfiguration;
209
- /**
210
- * The current working directory
211
- */
212
- cwd: string;
213
- /**
214
- * Enable verbose logging
215
- */
216
- isVerbose: boolean;
217
- }
218
6
  export declare class Workspaces {
219
7
  private root;
220
8
  private cachedWorkspaceConfig;
221
9
  constructor(root: string);
222
10
  relativeCwd(cwd: string): string;
223
11
  calculateDefaultProjectName(cwd: string, wc: WorkspaceJsonConfiguration & NxJsonConfiguration): string;
224
- readWorkspaceConfiguration(): WorkspaceJsonConfiguration & NxJsonConfiguration;
12
+ readWorkspaceConfiguration(opts?: {
13
+ _ignorePluginInference?: boolean;
14
+ }): WorkspaceJsonConfiguration & NxJsonConfiguration;
225
15
  isNxExecutor(nodeModule: string, executor: string): boolean;
226
16
  isNxGenerator(collectionName: string, generatorName: string): boolean;
227
17
  readExecutor(nodeModule: string, executor: string): ExecutorConfig;
@@ -247,11 +37,11 @@ export declare function resolveNewFormatWithInlineProjects(w: any, root?: string
247
37
  * Todo: Should refactor, not duplicate.
248
38
  */
249
39
  export declare function toProjectName(fileName: string, nxJson: NxJsonConfiguration): string;
250
- export declare function globForProjectFiles(root: string, nxJson?: NxJsonConfiguration): string[];
40
+ export declare function globForProjectFiles(root: any, nxJson?: NxJsonConfiguration, ignorePluginInference?: boolean): string[];
251
41
  export declare function deduplicateProjectFiles(files: string[], ig?: Ignore): string[];
252
42
  export declare function inferProjectFromNonStandardFile(file: string, nxJson: NxJsonConfiguration): ProjectConfiguration & {
253
43
  name: string;
254
44
  };
255
- export declare function buildWorkspaceConfigurationFromGlobs(nxJson: NxJsonConfiguration, projectFiles?: string[], // making this parameter allows devkit to pick up newly created projects
45
+ export declare function buildWorkspaceConfigurationFromGlobs(nxJson: NxJsonConfiguration, projectFiles: string[], // making this parameter allows devkit to pick up newly created projects
256
46
  readJson?: (string: any) => any): WorkspaceJsonConfiguration;
257
47
  export declare function renamePropertyWithStableKeys(obj: any, from: string, to: string): void;
@@ -2,16 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renamePropertyWithStableKeys = exports.buildWorkspaceConfigurationFromGlobs = exports.inferProjectFromNonStandardFile = exports.deduplicateProjectFiles = exports.globForProjectFiles = exports.toProjectName = exports.resolveNewFormatWithInlineProjects = exports.resolveOldFormatWithInlineProjects = exports.toOldFormatOrNull = exports.toNewFormatOrNull = exports.toNewFormat = exports.reformattedWorkspaceJsonOrNull = exports.Workspaces = exports.workspaceConfigName = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const fast_glob_1 = require("fast-glob");
5
6
  const fs_1 = require("fs");
7
+ const ignore_1 = require("ignore");
6
8
  const path = require("path");
9
+ const perf_hooks_1 = require("perf_hooks");
7
10
  const app_root_1 = require("../utils/app-root");
8
11
  const fileutils_1 = require("../utils/fileutils");
9
12
  const logger_1 = require("./logger");
10
- const fast_glob_1 = require("fast-glob");
11
- const ignore_1 = require("ignore");
12
- const path_1 = require("path");
13
- const perf_hooks_1 = require("perf_hooks");
14
13
  const nx_plugin_1 = require("./nx-plugin");
14
+ const path_1 = require("path");
15
+ tslib_1.__exportStar(require("./workspace.model"), exports);
15
16
  function workspaceConfigName(root) {
16
17
  if ((0, fs_1.existsSync)(path.join(root, 'angular.json'))) {
17
18
  return 'angular.json';
@@ -44,7 +45,7 @@ class Workspaces {
44
45
  }
45
46
  return wc.defaultProject;
46
47
  }
47
- readWorkspaceConfiguration() {
48
+ readWorkspaceConfiguration(opts) {
48
49
  if (this.cachedWorkspaceConfig)
49
50
  return this.cachedWorkspaceConfig;
50
51
  const nxJsonPath = path.join(this.root, 'nx.json');
@@ -55,7 +56,7 @@ class Workspaces {
55
56
  : null;
56
57
  const workspace = workspacePath && (0, fs_1.existsSync)(workspacePath)
57
58
  ? this.readFromWorkspaceJson()
58
- : buildWorkspaceConfigurationFromGlobs(nxJson, globForProjectFiles(this.root, nxJson), (path) => (0, fileutils_1.readJsonFile)((0, path_1.join)(this.root, path)));
59
+ : buildWorkspaceConfigurationFromGlobs(nxJson, globForProjectFiles(this.root, nxJson, opts === null || opts === void 0 ? void 0 : opts._ignorePluginInference), (path) => (0, fileutils_1.readJsonFile)((0, path_1.join)(this.root, path)));
59
60
  assertValidWorkspaceConfiguration(nxJson);
60
61
  this.cachedWorkspaceConfig = Object.assign(Object.assign({}, workspace), nxJson);
61
62
  return this.cachedWorkspaceConfig;
@@ -125,10 +126,7 @@ class Workspaces {
125
126
  }
126
127
  readExecutorsJson(nodeModule, executor) {
127
128
  var _a, _b, _c;
128
- const packageJsonPath = require.resolve(`${nodeModule}/package.json`, {
129
- paths: this.resolvePaths(),
130
- });
131
- const packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
129
+ const { json: packageJson, path: packageJsonPath } = (0, nx_plugin_1.readPluginPackageJson)(nodeModule, this.resolvePaths());
132
130
  const executorsFile = (_a = packageJson.executors) !== null && _a !== void 0 ? _a : packageJson.builders;
133
131
  if (!executorsFile) {
134
132
  throw new Error(`The "${nodeModule}" package does not support Nx executors.`);
@@ -150,10 +148,7 @@ class Workspaces {
150
148
  });
151
149
  }
152
150
  else {
153
- const packageJsonPath = require.resolve(`${collectionName}/package.json`, {
154
- paths: this.resolvePaths(),
155
- });
156
- const packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
151
+ const { json: packageJson, path: packageJsonPath } = (0, nx_plugin_1.readPluginPackageJson)(collectionName, this.resolvePaths());
157
152
  const generatorsFile = (_a = packageJson.generators) !== null && _a !== void 0 ? _a : packageJson.schematics;
158
153
  if (!generatorsFile) {
159
154
  throw new Error(`The "${collectionName}" package does not support Nx generators.`);
@@ -356,7 +351,7 @@ function getGlobPatternsFromPackageManagerWorkspaces(root) {
356
351
  return ['**/package.json'];
357
352
  }
358
353
  }
359
- function globForProjectFiles(root, nxJson) {
354
+ function globForProjectFiles(root, nxJson, ignorePluginInference = false) {
360
355
  // Deal w/ Caching
361
356
  const cacheKey = [root, ...((nxJson === null || nxJson === void 0 ? void 0 : nxJson.plugins) || [])].join(',');
362
357
  if (projectGlobCache && cacheKey === projectGlobCacheKey)
@@ -365,8 +360,10 @@ function globForProjectFiles(root, nxJson) {
365
360
  const projectGlobPatterns = [
366
361
  '**/project.json',
367
362
  ...getGlobPatternsFromPackageManagerWorkspaces(root),
368
- ...getGlobPatternsFromPlugins(nxJson),
369
363
  ];
364
+ if (!ignorePluginInference) {
365
+ projectGlobPatterns.push(...getGlobPatternsFromPlugins(nxJson));
366
+ }
370
367
  const combinedProjectGlobPattern = '{' + projectGlobPatterns.join(',') + '}';
371
368
  perf_hooks_1.performance.mark('start-glob-for-projects');
372
369
  /**
@@ -424,7 +421,7 @@ function deduplicateProjectFiles(files, ig) {
424
421
  }
425
422
  exports.deduplicateProjectFiles = deduplicateProjectFiles;
426
423
  function buildProjectConfigurationFromPackageJson(path, packageJson, nxJson) {
427
- var _a;
424
+ var _a, _b, _c, _d;
428
425
  const directory = (0, path_1.dirname)(path).split('\\').join('/');
429
426
  const npmPrefix = `@${nxJson.npmScope}/`;
430
427
  let name = (_a = packageJson.name) !== null && _a !== void 0 ? _a : toProjectName(directory, nxJson);
@@ -435,6 +432,11 @@ function buildProjectConfigurationFromPackageJson(path, packageJson, nxJson) {
435
432
  root: directory,
436
433
  sourceRoot: directory,
437
434
  name,
435
+ projectType: ((_b = nxJson.workspaceLayout) === null || _b === void 0 ? void 0 : _b.appsDir) != ((_c = nxJson.workspaceLayout) === null || _c === void 0 ? void 0 : _c.libsDir) &&
436
+ ((_d = nxJson.workspaceLayout) === null || _d === void 0 ? void 0 : _d.appsDir) &&
437
+ directory.startsWith(nxJson.workspaceLayout.appsDir)
438
+ ? 'application'
439
+ : 'library',
438
440
  };
439
441
  }
440
442
  function inferProjectFromNonStandardFile(file, nxJson) {
@@ -445,7 +447,7 @@ function inferProjectFromNonStandardFile(file, nxJson) {
445
447
  };
446
448
  }
447
449
  exports.inferProjectFromNonStandardFile = inferProjectFromNonStandardFile;
448
- function buildWorkspaceConfigurationFromGlobs(nxJson, projectFiles = globForProjectFiles(app_root_1.appRootPath, nxJson), // making this parameter allows devkit to pick up newly created projects
450
+ function buildWorkspaceConfigurationFromGlobs(nxJson, projectFiles, // making this parameter allows devkit to pick up newly created projects
449
451
  readJson = fileutils_1.readJsonFile // making this an arg allows us to reuse in devkit
450
452
  ) {
451
453
  const projects = {};
@@ -474,7 +476,7 @@ readJson = fileutils_1.readJsonFile // making this an arg allows us to reuse in
474
476
  // this results in targets being inferred by Nx from package scripts,
475
477
  // and the root / sourceRoot both being the directory.
476
478
  if (fileName === 'package.json') {
477
- const _a = buildProjectConfigurationFromPackageJson(file, readJson(file), nxJson), { name } = _a, config = (0, tslib_1.__rest)(_a, ["name"]);
479
+ const _a = buildProjectConfigurationFromPackageJson(file, readJson(file), nxJson), { name } = _a, config = tslib_1.__rest(_a, ["name"]);
478
480
  if (!projects[name]) {
479
481
  projects[name] = config;
480
482
  }
@@ -485,7 +487,7 @@ readJson = fileutils_1.readJsonFile // making this an arg allows us to reuse in
485
487
  else {
486
488
  // This project was created from an nx plugin.
487
489
  // The only thing we know about the file is its location
488
- const _b = inferProjectFromNonStandardFile(file, nxJson), { name } = _b, config = (0, tslib_1.__rest)(_b, ["name"]);
490
+ const _b = inferProjectFromNonStandardFile(file, nxJson), { name } = _b, config = tslib_1.__rest(_b, ["name"]);
489
491
  if (!projects[name]) {
490
492
  projects[name] = config;
491
493
  }