diff --git a/packages-legacy/workspace/testing.ts b/packages-legacy/workspace/testing.ts deleted file mode 100644 index c5803c6566117..0000000000000 --- a/packages-legacy/workspace/testing.ts +++ /dev/null @@ -1 +0,0 @@ -export * from '@nx/workspace/testing'; diff --git a/packages/workspace/index.ts b/packages/workspace/index.ts index 3741c8c50e21b..d981afc80d415 100644 --- a/packages/workspace/index.ts +++ b/packages/workspace/index.ts @@ -23,26 +23,9 @@ export { serializeTarget, } from './src/utils/cli-config-utils'; -export { - getWorkspace, - updateWorkspace, - updateBuilderConfig, -} from './src/utils/workspace'; export { Linter } from './src/utils/lint'; -export { addInstallTask } from './src/utils/rules/add-install-task'; -export { formatFiles } from './src/utils/rules/format-files'; -export { deleteFile } from './src/utils/rules/deleteFile'; - -export { visitNotIgnoredFiles } from './src/utils/rules/visit-not-ignored-files'; -import * as strings from './src/utils/strings'; - -// TODO(v17): Remove this export. -export { checkAndCleanWithSemver } from './src/utils/version-utils'; - export { moveGenerator } from './src/generators/move/move'; export { removeGenerator } from './src/generators/remove/remove'; export { runCommandsGenerator } from './src/generators/run-commands/run-commands'; export { convertToNxProjectGenerator } from './src/generators/convert-to-nx-project/convert-to-nx-project'; - -export const stringUtils = strings; diff --git a/packages/workspace/package.json b/packages/workspace/package.json index 18f0efa20a903..c69f4a59909bb 100644 --- a/packages/workspace/package.json +++ b/packages/workspace/package.json @@ -64,8 +64,6 @@ "@nx/devkit": "file:../devkit", "chalk": "^4.1.0", "enquirer": "~2.3.6", - "ignore": "^5.0.4", - "rxjs": "^7.8.0", "tslib": "^2.3.0", "yargs-parser": "21.1.1" }, diff --git a/packages/workspace/src/utilities/run-tasks-in-serial.ts b/packages/workspace/src/utilities/run-tasks-in-serial.ts deleted file mode 100644 index 8aaabc8ae30be..0000000000000 --- a/packages/workspace/src/utilities/run-tasks-in-serial.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { GeneratorCallback } from '@nx/devkit'; - -/** - * Run tasks in serial - * - * @deprecated This function will be removed from `@nx/workspace` in version 17. Prefer importing it from `@nx/devkit`. - * @param tasks The tasks to run in serial. - */ -export function runTasksInSerial( - ...tasks: GeneratorCallback[] -): GeneratorCallback { - return async () => { - for (const task of tasks) { - await task(); - } - }; -} diff --git a/packages/workspace/src/utilities/typescript.ts b/packages/workspace/src/utilities/typescript.ts index ede5ebf3b5014..3d61d05ac96fd 100644 --- a/packages/workspace/src/utilities/typescript.ts +++ b/packages/workspace/src/utilities/typescript.ts @@ -91,17 +91,3 @@ import { getRelativePathToRootTsConfig as _getRelativePathToRootTsConfig, getRootTsConfigPathInTree as _getRootTsConfigPathInTree, } from './ts-config'; - -/** - * @deprecated Please import this from @nx/js instead. This function will be removed in v17 - */ -export function getRelativePathToRootTsConfig(tree: Tree, targetPath: string) { - return _getRelativePathToRootTsConfig(tree, targetPath); -} - -/** - * @deprecated Please import this from @nx/js instead. This function will be removed in v17 - */ -export function getRootTsConfigPathInTree(tree: Tree) { - return _getRootTsConfigPathInTree(tree); -} diff --git a/packages/workspace/src/utilities/version-utils.ts b/packages/workspace/src/utilities/version-utils.ts deleted file mode 100644 index 90b9d78a0f8d4..0000000000000 --- a/packages/workspace/src/utilities/version-utils.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { checkAndCleanWithSemver as _checkAndCleanWithSemver } from '@nx/devkit/src/utils/semver'; -import { logger } from '@nx/devkit'; - -/** @deprecated Use checkAndCleanWithSemver from @nx/devkit/src/utils/semver instead. - * TODO(v17): Remove this function from workspace. Keep it for now since there are projects that use it (e.g. https://github.com/gperdomor/nx-tools). - */ -export function checkAndCleanWithSemver(pkgName: string, version: string) { - logger.warn( - `checkAndCleanWithSemver has been moved to @nx/devkit/src/utils/semver` - ); - return _checkAndCleanWithSemver(pkgName, version); -} diff --git a/packages/workspace/src/utils/ast-utils.ts b/packages/workspace/src/utils/ast-utils.ts index df9ff1d6a0b08..019c8ad2b4c7a 100644 --- a/packages/workspace/src/utils/ast-utils.ts +++ b/packages/workspace/src/utils/ast-utils.ts @@ -1,3 +1 @@ -import { getSourceNodes } from '../utilities/typescript/get-source-nodes'; - export { getSourceNodes } from '../utilities/typescript/get-source-nodes'; diff --git a/packages/workspace/src/utils/fileutils.ts b/packages/workspace/src/utils/fileutils.ts deleted file mode 100644 index ba5ce91a8402f..0000000000000 --- a/packages/workspace/src/utils/fileutils.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { - createReadStream, - createWriteStream, - existsSync, - mkdirSync, - renameSync as fsRenameSync, - writeFileSync, -} from 'fs'; -import { basename, dirname, resolve } from 'path'; -import { - createDirectory, - directoryExists, - fileExists, - isRelativePath, - readJsonFile, - writeJsonFile, -} from 'nx/src/utils/fileutils'; - -export { fileExists, directoryExists, isRelativePath, createDirectory }; - -/** - * @deprecated This will be removed in v17. - */ -export function writeToFile(filePath: string, str: string) { - mkdirSync(dirname(filePath), { recursive: true }); - writeFileSync(filePath, str); -} - -/** - * @deprecated This will be removed in v17. - * This method is specifically for updating a JSON file using the filesystem - * - * @remarks - * If you are looking to update a JSON file in a tree, look for ./ast-utils#updateJsonInTree - * @param path Path of the JSON file on the filesystem - * @param callback Manipulation of the JSON data - */ -export function updateJsonFile(path: string, callback: (a: any) => any) { - const json = readJsonFile(path); - callback(json); - writeJsonFile(path, json); -} - -/** - * @deprecated This will be removed in v17. - */ -export function copyFile(file: string, target: string) { - const f = basename(file); - const source = createReadStream(file); - const dest = createWriteStream(resolve(target, f)); - source.pipe(dest); - source.on('error', (e) => console.error(e)); -} - -/** - * @deprecated This will be removed in v17. - */ -export function renameSync( - from: string, - to: string, - cb: (err: Error | null) => void -) { - try { - if (!existsSync(from)) { - throw new Error(`Path: ${from} does not exist`); - } else if (existsSync(to)) { - throw new Error(`Path: ${to} already exists`); - } - - // Make sure parent path exists - const parentPath = resolve(to, '..'); - createDirectory(parentPath); - - fsRenameSync(from, to); - cb(null); - } catch (e) { - cb(e); - } -} diff --git a/packages/workspace/src/utils/rules/add-install-task.ts b/packages/workspace/src/utils/rules/add-install-task.ts deleted file mode 100644 index 9fe4d381801fd..0000000000000 --- a/packages/workspace/src/utils/rules/add-install-task.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Rule } from '@angular-devkit/schematics'; - -let installAdded = false; - -/** - * @deprecated This will be removed in v17. Prefer writing Nx Generators with @nx/devkit. This function can be replaced with 'addDependenciesToPackageJson' from @nx/devkit. - */ -export function addInstallTask( - options: { skipInstall: boolean } = { skipInstall: false } -): Rule { - const { - NodePackageInstallTask, - } = require('@angular-devkit/schematics/tasks'); - return (_, context) => { - if (!options.skipInstall && !installAdded) { - context.addTask(new NodePackageInstallTask()); - installAdded = true; - } - }; -} diff --git a/packages/workspace/src/utils/rules/deleteFile.ts b/packages/workspace/src/utils/rules/deleteFile.ts deleted file mode 100644 index bfe6b45b79f5e..0000000000000 --- a/packages/workspace/src/utils/rules/deleteFile.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { Rule, Tree } from '@angular-devkit/schematics'; - -/** - * Remove a file from the Virtual Schematic Tree - * @deprecated This will be removed in v17. Prefer writing Nx Generators with @nx/devkit. This function can be replaced with 'Tree.delete' from @nx/devkit. - */ -export function deleteFile(from: string): Rule { - return (host: Tree) => host.delete(from); -} diff --git a/packages/workspace/src/utils/rules/format-files.ts b/packages/workspace/src/utils/rules/format-files.ts deleted file mode 100644 index cac8cf4401700..0000000000000 --- a/packages/workspace/src/utils/rules/format-files.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { - CreateFileAction, - noop, - OverwriteFileAction, - Rule, - SchematicContext, - Tree, -} from '@angular-devkit/schematics'; -import { from } from 'rxjs'; -import { filter, map, mergeMap } from 'rxjs/operators'; -import * as path from 'path'; -import { workspaceRoot } from '@nx/devkit'; - -/** - * @deprecated This will be removed in v17. Prefer writing Nx Generators with @nx/devkit. This function can be replaced with 'formatFiles' from @nx/devkit. - */ -export function formatFiles( - options: { skipFormat: boolean } = { skipFormat: false }, - directory: string = '' -): Rule { - let prettier; - try { - prettier = require('prettier'); - } catch (e) {} - - if (options.skipFormat) { - return noop(); - } - - return (host: Tree, context: SchematicContext) => { - if (!prettier) { - return host; - } - - const files = new Set( - host.actions - .filter((action) => action.kind !== 'd' && action.kind !== 'r') - .map((action: OverwriteFileAction | CreateFileAction) => ({ - path: action.path, - content: action.content.toString(), - })) - ); - if (files.size === 0) { - return host; - } - return from(files).pipe( - filter((file) => host.exists(file.path)), - mergeMap(async (file) => { - const systemPath = path.join(workspaceRoot, file.path); - let options: any = { - filepath: systemPath, - }; - const resolvedOptions = await prettier.resolveConfig(systemPath); - if (resolvedOptions) { - options = { - ...options, - ...resolvedOptions, - }; - } - const support = await prettier.getFileInfo(systemPath, options); - if (support.ignored || !support.inferredParser) { - return; - } - - try { - host.overwrite( - file.path, - // In prettier v3 the format result is a promise - await (prettier.format(file.content, options) as - | Promise - | string) - ); - } catch (e) { - context.logger.warn( - `Could not format ${file.path} because ${e.message}` - ); - } - }), - map(() => host) - ); - }; -} diff --git a/packages/workspace/src/utils/rules/visit-not-ignored-files.ts b/packages/workspace/src/utils/rules/visit-not-ignored-files.ts deleted file mode 100644 index b31f7237ff189..0000000000000 --- a/packages/workspace/src/utils/rules/visit-not-ignored-files.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { join, normalize, Path } from '@angular-devkit/core'; -import { - callRule, - Rule, - SchematicContext, - Tree, -} from '@angular-devkit/schematics'; -import ignore from 'ignore'; - -/** - * @deprecated This will be removed in v17. Prefer writing Nx Generators with @nx/devkit. This function can be replaced with 'visitNotIgnoredFiles' from @nx/devkit. - */ -export function visitNotIgnoredFiles( - visitor: (file: Path, host: Tree, context: SchematicContext) => void | Rule, - dir: Path = normalize('') -): Rule { - return (host, context) => { - let ig: ReturnType | undefined; - if (host.exists('.gitignore')) { - ig = ignore(); - ig.add(host.read('.gitignore').toString()); - } - - function visit(_dir: Path) { - if (_dir && ig?.ignores(_dir)) { - return; - } - const dirEntry = host.getDir(_dir); - dirEntry.subfiles.forEach((file) => { - if (ig?.ignores(join(_dir, file))) { - return; - } - const maybeRule = visitor(join(_dir, file), host, context); - if (maybeRule) { - callRule(maybeRule, host, context).subscribe(); - } - }); - - dirEntry.subdirs.forEach((subdir) => { - visit(join(_dir, subdir)); - }); - } - - visit(dir); - }; -} diff --git a/packages/workspace/src/utils/strings.spec.ts b/packages/workspace/src/utils/strings.spec.ts deleted file mode 100644 index 346545405ca45..0000000000000 --- a/packages/workspace/src/utils/strings.spec.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { classify, dasherize } from './strings'; - -describe('String utils', () => { - describe('dasherize', () => { - it('should format camel casing', () => { - expect(dasherize('twoWords')).toEqual('two-words'); - }); - - it('should camel casing with abbreviations', () => { - expect(dasherize('twoWORDS')).toEqual('two-words'); - }); - - it('should format spaces', () => { - expect(dasherize('two words')).toEqual('two-words'); - }); - - it('should format underscores', () => { - expect(dasherize('two_words')).toEqual('two-words'); - }); - - it('should format periods', () => { - expect(dasherize('two.words')).toEqual('two-words'); - }); - - it('should format dashes', () => { - expect(dasherize('two-words')).toEqual('two-words'); - }); - - it('should return single words', () => { - expect(dasherize('word')).toEqual('word'); - }); - }); - - describe('classify', () => { - it('should format camel casing', () => { - expect(classify('twoWords')).toEqual('TwoWords'); - }); - - it('should camel casing with abbreviations', () => { - expect(classify('twoWORDS')).toEqual('TwoWORDS'); - }); - - it('should format spaces', () => { - expect(classify('two words')).toEqual('TwoWords'); - }); - - it('should format underscores', () => { - expect(classify('two_words')).toEqual('TwoWords'); - }); - - it('should format periods', () => { - expect(classify('two.words')).toEqual('Two.Words'); - }); - - it('should format dashes', () => { - expect(classify('two-words')).toEqual('TwoWords'); - }); - - it('should return single words', () => { - expect(classify('word')).toEqual('Word'); - }); - }); -}); diff --git a/packages/workspace/src/utils/strings.ts b/packages/workspace/src/utils/strings.ts deleted file mode 100644 index 546cb2b23441b..0000000000000 --- a/packages/workspace/src/utils/strings.ts +++ /dev/null @@ -1,165 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ -const STRING_DASHERIZE_REGEXP = /[ _.]/g; -const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g; -const STRING_CAMELIZE_REGEXP = /(-|_|\.|\s)+(.)?/g; -const STRING_UNDERSCORE_REGEXP_1 = /([a-z\d])([A-Z]+)/g; -const STRING_UNDERSCORE_REGEXP_2 = /-|\s+/g; - -/** - * Converts a camelized string into all lower case separated by underscores. - * - ```javascript - decamelize('innerHTML'); // 'inner_html' - decamelize('action_name'); // 'action_name' - decamelize('css-class-name'); // 'css-class-name' - decamelize('my favorite items'); // 'my favorite items' - ``` - - @method decamelize - @deprecated This will be removed from `@nx/workspace` in version 17. Prefer `@nx/js` when importing. - @param {String} str The string to decamelize. - @return {String} the decamelized string. - */ -export function decamelize(str: string): string { - return str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase(); -} - -/** - Replaces underscores, spaces, periods, or camelCase with dashes. - - ```javascript - dasherize('innerHTML'); // 'inner-html' - dasherize('action_name'); // 'action-name' - dasherize('css-class-name'); // 'css-class-name' - dasherize('my favorite items'); // 'my-favorite-items' - dasherize('nrwl.io'); // 'nrwl-io' - ``` - - @method dasherize - @deprecated This will be removed from `@nx/workspace` in version 17. Prefer `@nx/js` when importing. - @param {String} str The string to dasherize. - @return {String} the dasherized string. - */ -export function dasherize(str?: string): string { - return decamelize(str || '').replace(STRING_DASHERIZE_REGEXP, '-'); -} - -/** - Returns the lowerCamelCase form of a string. - - ```javascript - camelize('innerHTML'); // 'innerHTML' - camelize('action_name'); // 'actionName' - camelize('css-class-name'); // 'cssClassName' - camelize('my favorite items'); // 'myFavoriteItems' - camelize('My Favorite Items'); // 'myFavoriteItems' - ``` - - @method camelize - @deprecated This will be removed from `@nx/workspace` in version 17. Prefer `@nx/js` when importing. - @param {String} str The string to camelize. - @return {String} the camelized string. - */ -export function camelize(str: string): string { - return str - .replace( - STRING_CAMELIZE_REGEXP, - (_match: string, _separator: string, chr: string) => { - return chr ? chr.toUpperCase() : ''; - } - ) - .replace(/^([A-Z])/, (match: string) => match.toLowerCase()); -} - -/** - Returns the UpperCamelCase form of a string. - - ```javascript - 'innerHTML'.classify(); // 'InnerHTML' - 'action_name'.classify(); // 'ActionName' - 'css-class-name'.classify(); // 'CssClassName' - 'my favorite items'.classify(); // 'MyFavoriteItems' - ``` - - @method classify - @deprecated This will be removed from `@nx/workspace` in version 17. Prefer `@nx/js` when importing. - @param {String} str the string to classify - @return {String} the classified string - */ -export function classify(str: string): string { - return str - .split('.') - .map((part) => capitalize(camelize(part))) - .join('.'); -} - -/** - More general than decamelize. Returns the lower\_case\_and\_underscored - form of a string. - - ```javascript - 'innerHTML'.underscore(); // 'inner_html' - 'action_name'.underscore(); // 'action_name' - 'css-class-name'.underscore(); // 'css_class_name' - 'my favorite items'.underscore(); // 'my_favorite_items' - ``` - - @method underscore - @deprecated This will be removed from `@nx/workspace` in version 17. Prefer `@nx/js` when importing. - @param {String} str The string to underscore. - @return {String} the underscored string. - */ -export function underscore(str: string): string { - return str - .replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2') - .replace(STRING_UNDERSCORE_REGEXP_2, '_') - .toLowerCase(); -} - -/** - Returns the Capitalized form of a string - - ```javascript - 'innerHTML'.capitalize() // 'InnerHTML' - 'action_name'.capitalize() // 'Action_name' - 'css-class-name'.capitalize() // 'Css-class-name' - 'my favorite items'.capitalize() // 'My favorite items' - ``` - - @method capitalize - @deprecated This will be removed from `@nx/workspace` in version 17. Prefer `@nx/js` when importing. - @param {String} str The string to capitalize. - @return {String} The capitalized string. - */ -export function capitalize(str: string): string { - return str.charAt(0).toUpperCase() + str.slice(1); -} - -/** - * @deprecated This will be removed from `@nx/workspace` in version 17. Prefer `@nx/js` when importing. - */ -export function group(name: string, group: string | undefined) { - return group ? `${group}/${name}` : name; -} - -/** - * @deprecated This will be removed from `@nx/workspace` in version 17. Prefer `@nx/js` when importing. - */ -export function featurePath( - group: boolean | undefined, - flat: boolean | undefined, - path: string, - name: string -) { - if (group && !flat) { - return `../../${path}/${name}/`; - } - - return group ? `../${path}/` : './'; -} diff --git a/packages/workspace/src/utils/testing-utils.ts b/packages/workspace/src/utils/testing-utils.ts deleted file mode 100644 index 96916677b489d..0000000000000 --- a/packages/workspace/src/utils/testing-utils.ts +++ /dev/null @@ -1,129 +0,0 @@ -import { _test_addWorkspaceFile } from '@angular-devkit/core/src/workspace/core'; -import { Architect, BuilderContext, Target } from '@angular-devkit/architect'; -import { TestingArchitectHost } from '@angular-devkit/architect/testing'; -import { json, JsonObject } from '@angular-devkit/core'; -import { ScheduleOptions } from '@angular-devkit/architect/src/api'; -import { LoggerApi, LogLevel } from '@angular-devkit/core/src/logger'; - -class NoopLogger implements LoggerApi { - private _log = ''; - - createChild(name: string) { - return new NoopLogger() as any; - } - - includes(substr: string) { - return this._log.includes(substr); - } - - debug(message: string, metadata?: JsonObject): void { - this._log += message; - } - - error(message: string, metadata?: JsonObject): void { - this._log += message; - } - - fatal(message: string, metadata?: JsonObject): void { - this._log += message; - } - - info(message: string, metadata?: JsonObject): void { - this._log += message; - } - - log(level: LogLevel, message: string, metadata?: JsonObject): void { - this._log += message; - } - - warn(message: string, metadata?: JsonObject): void { - this._log += message; - } -} - -/** - * Mock context which makes testing builders easier - * @deprecated This will be removed in v17. Prefer writing Nx Generators with @nx/devkit. - */ -export class MockBuilderContext implements BuilderContext { - id: 0; - - builder: any = {}; - analytics = null; - - target: Target = { - project: null, - target: null, - }; - - logger = new NoopLogger(); - - get currentDirectory() { - return this.architectHost.currentDirectory; - } - - get workspaceRoot() { - return this.architectHost.workspaceRoot; - } - - constructor( - private architect: Architect, - private architectHost: TestingArchitectHost - ) {} - - async addBuilderFromPackage(path: string) { - return await this.architectHost.addBuilderFromPackage(path); - } - - async addTarget(target: Target, builderName: string) { - return this.architectHost.addTarget(target, builderName); - } - - getBuilderNameForTarget(target: Target) { - return this.architectHost.getBuilderNameForTarget(target); - } - - scheduleTarget( - target: Target, - overrides?: JsonObject, - scheduleOptions?: ScheduleOptions - ) { - return this.architect.scheduleTarget(target, overrides, scheduleOptions); - } - - scheduleBuilder( - name: string, - overrides?: JsonObject, - scheduleOptions?: ScheduleOptions - ) { - return this.architect.scheduleBuilder(name, overrides, scheduleOptions); - } - - getTargetOptions(target: Target): Promise { - return this.architectHost.getOptionsForTarget(target); - } - - validateOptions( - options: JsonObject, - builderName: string - ): Promise { - return Promise.resolve(options as T); - } - - reportRunning() {} - - reportStatus(status: string) {} - - reportProgress(current: number, total?: number, status?: string) {} - - addTeardown(teardown: () => Promise | void) {} - - async getProjectMetadata( - target: Target | string - ): Promise { - return ( - this.architectHost && - this.architectHost.getProjectMetadata(target as string) - ); - } -} diff --git a/packages/workspace/src/utils/version-utils.ts b/packages/workspace/src/utils/version-utils.ts deleted file mode 100644 index a01e1e86aaa07..0000000000000 --- a/packages/workspace/src/utils/version-utils.ts +++ /dev/null @@ -1 +0,0 @@ -export * from '../utilities/version-utils'; diff --git a/packages/workspace/src/utils/workspace.ts b/packages/workspace/src/utils/workspace.ts deleted file mode 100644 index f264b88649b28..0000000000000 --- a/packages/workspace/src/utils/workspace.ts +++ /dev/null @@ -1,126 +0,0 @@ -import type { Rule, Tree } from '@angular-devkit/schematics'; -import { JsonArray, JsonObject, workspaces } from '@angular-devkit/core'; -import { - ProjectDefinition, - TargetDefinition, -} from '@angular-devkit/core/src/workspace'; - -function createHost(tree: Tree): workspaces.WorkspaceHost { - return { - async readFile(path: string): Promise { - const data = tree.read(path); - if (!data) { - throw new Error('File not found.'); - } - - return data.toString(); - }, - async writeFile(path: string, data: string): Promise { - return tree.overwrite(path, data); - }, - async isDirectory(path: string): Promise { - // approximate a directory check - // special case needed when testing wrapped schematics - if (path === '/') return true; - return !tree.exists(path) && tree.getDir(path).subfiles.length > 0; - }, - async isFile(path: string): Promise { - return tree.exists(path); - }, - }; -} - -/** - * @deprecated This will be removed in v17. Prefer writing Nx Generators with @nx/devkit. This function can be replaced with 'getProjects' with Nx Devkit. - */ -export async function getWorkspace(tree: Tree, path = '/') { - const host = createHost(tree); - - const { workspace } = await workspaces.readWorkspace(path, host); - - return workspace; -} - -/** - * @deprecated This will be removed in v17. Prefer writing Nx Generators with @nx/devkit. This function can be replaced with 'updateProjectConfiguration' with Nx Devkit. - */ -export function updateWorkspace( - updater: ( - workspace: workspaces.WorkspaceDefinition - ) => void | PromiseLike -): Rule; -/** - * @deprecated This will be removed in v17. Prefer writing Nx Generators with @nx/devkit. This function can be replaced with 'updateProjectConfiguration' with Nx Devkit. - */ -export function updateWorkspace( - workspace: workspaces.WorkspaceDefinition -): Rule; -/** - * @deprecated This will be removed in v17. Prefer writing Nx Generators with @nx/devkit. This function can be replaced with 'updateProjectConfiguration' with Nx Devkit. - */ -export function updateWorkspace( - updaterOrWorkspace: - | workspaces.WorkspaceDefinition - | ((workspace: workspaces.WorkspaceDefinition) => void | PromiseLike) -): Rule { - return async (tree: Tree) => { - const host = createHost(tree); - - if (typeof updaterOrWorkspace === 'function') { - const { workspace } = await workspaces.readWorkspace('/', host); - - const result = updaterOrWorkspace(workspace); - if (result !== undefined) { - await result; - } - - await workspaces.writeWorkspace(workspace, host); - } else { - await workspaces.writeWorkspace(updaterOrWorkspace, host); - } - }; -} - -/** - * Updates builder options for options and configurations for given builder names - * @deprecated This will be removed in v17. Prefer writing Nx Generators with @nx/devkit. This function can be replaced with 'forEachExecutorOptions' with Nx Devkit. - */ -export function updateBuilderConfig( - updater: ( - currentValue: Record< - string, - string | number | boolean | JsonArray | JsonObject - >, - target?: TargetDefinition, - project?: ProjectDefinition - ) => Record, - ...builderNames: string[] -) { - return updateWorkspace((workspace) => { - if (!workspace.projects) { - return; - } - workspace.projects.forEach((project) => { - project.targets.forEach((target) => { - if (!builderNames.includes(target.builder)) { - return; - } - if (target.options) { - target.options = updater(target.options, target, project); - } - if (!target.configurations) { - return; - } - Object.entries(target.configurations).forEach( - ([configName, options]) => { - target.configurations[configName] = updater( - options, - target, - project - ); - } - ); - }); - }); - }); -} diff --git a/packages/workspace/testing.ts b/packages/workspace/testing.ts deleted file mode 100644 index 2c8111b732cf5..0000000000000 --- a/packages/workspace/testing.ts +++ /dev/null @@ -1 +0,0 @@ -export { MockBuilderContext } from './src/utils/testing-utils';