diff --git a/docs/generated/devkit/nrwl_devkit.md b/docs/generated/devkit/nrwl_devkit.md index a253317955679d..aa751536ede7b5 100644 --- a/docs/generated/devkit/nrwl_devkit.md +++ b/docs/generated/devkit/nrwl_devkit.md @@ -101,8 +101,6 @@ It only uses language primitives and immutable objects - [applySharedFunction](../../devkit/documents/nrwl_devkit#applysharedfunction) - [convertNxExecutor](../../devkit/documents/nrwl_devkit#convertnxexecutor) - [convertNxGenerator](../../devkit/documents/nrwl_devkit#convertnxgenerator) -- [createLockFile](../../devkit/documents/nrwl_devkit#createlockfile) -- [createPackageJson](../../devkit/documents/nrwl_devkit#createpackagejson) - [createProjectGraphAsync](../../devkit/documents/nrwl_devkit#createprojectgraphasync) - [defaultTasksRunner](../../devkit/documents/nrwl_devkit#defaulttasksrunner) - [detectPackageManager](../../devkit/documents/nrwl_devkit#detectpackagemanager) @@ -1054,53 +1052,6 @@ Convert an Nx Generator into an Angular Devkit Schematic. --- -### createLockFile - -▸ **createLockFile**(`packageJson`, `packageManager?`): `string` - -**`Deprecated`** - -Import this from @nrwl/js instead - -#### Parameters - -| Name | Type | -| :--------------- | :-------------------------------------------------------------------- | -| `packageJson` | `PackageJson` | -| `packageManager` | [`PackageManager`](../../devkit/documents/nrwl_devkit#packagemanager) | - -#### Returns - -`string` - ---- - -### createPackageJson - -▸ **createPackageJson**(`projectName`, `graph`, `options?`): `PackageJson` - -**`Deprecated`** - -Import this from @nrwl/js instead - -#### Parameters - -| Name | Type | -| :---------------------------- | :---------------------------------------------------------------- | -| `projectName` | `string` | -| `graph` | [`ProjectGraph`](../../devkit/documents/nrwl_devkit#projectgraph) | -| `options` | `Object` | -| `options.helperDependencies?` | `string`[] | -| `options.isProduction?` | `boolean` | -| `options.root?` | `string` | -| `options.target?` | `string` | - -#### Returns - -`PackageJson` - ---- - ### createProjectGraphAsync ▸ **createProjectGraphAsync**(`opts?`): `Promise`<[`ProjectGraph`](../../devkit/documents/nrwl_devkit#projectgraph)\> diff --git a/docs/generated/packages/devkit/documents/nrwl_devkit.md b/docs/generated/packages/devkit/documents/nrwl_devkit.md index a253317955679d..aa751536ede7b5 100644 --- a/docs/generated/packages/devkit/documents/nrwl_devkit.md +++ b/docs/generated/packages/devkit/documents/nrwl_devkit.md @@ -101,8 +101,6 @@ It only uses language primitives and immutable objects - [applySharedFunction](../../devkit/documents/nrwl_devkit#applysharedfunction) - [convertNxExecutor](../../devkit/documents/nrwl_devkit#convertnxexecutor) - [convertNxGenerator](../../devkit/documents/nrwl_devkit#convertnxgenerator) -- [createLockFile](../../devkit/documents/nrwl_devkit#createlockfile) -- [createPackageJson](../../devkit/documents/nrwl_devkit#createpackagejson) - [createProjectGraphAsync](../../devkit/documents/nrwl_devkit#createprojectgraphasync) - [defaultTasksRunner](../../devkit/documents/nrwl_devkit#defaulttasksrunner) - [detectPackageManager](../../devkit/documents/nrwl_devkit#detectpackagemanager) @@ -1054,53 +1052,6 @@ Convert an Nx Generator into an Angular Devkit Schematic. --- -### createLockFile - -▸ **createLockFile**(`packageJson`, `packageManager?`): `string` - -**`Deprecated`** - -Import this from @nrwl/js instead - -#### Parameters - -| Name | Type | -| :--------------- | :-------------------------------------------------------------------- | -| `packageJson` | `PackageJson` | -| `packageManager` | [`PackageManager`](../../devkit/documents/nrwl_devkit#packagemanager) | - -#### Returns - -`string` - ---- - -### createPackageJson - -▸ **createPackageJson**(`projectName`, `graph`, `options?`): `PackageJson` - -**`Deprecated`** - -Import this from @nrwl/js instead - -#### Parameters - -| Name | Type | -| :---------------------------- | :---------------------------------------------------------------- | -| `projectName` | `string` | -| `graph` | [`ProjectGraph`](../../devkit/documents/nrwl_devkit#projectgraph) | -| `options` | `Object` | -| `options.helperDependencies?` | `string`[] | -| `options.isProduction?` | `boolean` | -| `options.root?` | `string` | -| `options.target?` | `string` | - -#### Returns - -`PackageJson` - ---- - ### createProjectGraphAsync ▸ **createProjectGraphAsync**(`opts?`): `Promise`<[`ProjectGraph`](../../devkit/documents/nrwl_devkit#projectgraph)\> diff --git a/docs/generated/packages/jest/documents/overview.md b/docs/generated/packages/jest/documents/overview.md index 116d4ea0e8417b..e2170b09eb23a0 100644 --- a/docs/generated/packages/jest/documents/overview.md +++ b/docs/generated/packages/jest/documents/overview.md @@ -120,7 +120,7 @@ In order to use Jest's global setup/teardown functions that reference nx librari Nx provides a helper function that you can import within your setup/teardown file. ```typescript {% fileName="global-setup.ts" %} -import { registerTsProject } from 'nx/src/plugins/js/utils/register'; +import { registerTsProject } from '@nrwl/js'; const cleanupRegisteredPaths = registerTsProject('.', 'tsconfig.base.json'); import { yourFancyFunction } from '@some-org/my-util-library'; diff --git a/docs/shared/packages/jest/jest-plugin.md b/docs/shared/packages/jest/jest-plugin.md index 116d4ea0e8417b..e2170b09eb23a0 100644 --- a/docs/shared/packages/jest/jest-plugin.md +++ b/docs/shared/packages/jest/jest-plugin.md @@ -120,7 +120,7 @@ In order to use Jest's global setup/teardown functions that reference nx librari Nx provides a helper function that you can import within your setup/teardown file. ```typescript {% fileName="global-setup.ts" %} -import { registerTsProject } from 'nx/src/plugins/js/utils/register'; +import { registerTsProject } from '@nrwl/js'; const cleanupRegisteredPaths = registerTsProject('.', 'tsconfig.base.json'); import { yourFancyFunction } from '@some-org/my-util-library'; diff --git a/e2e/jest/src/jest.test.ts b/e2e/jest/src/jest.test.ts index 28bdfe6dbe8835..a51ca0a678edb6 100644 --- a/e2e/jest/src/jest.test.ts +++ b/e2e/jest/src/jest.test.ts @@ -48,7 +48,7 @@ describe('Jest', () => { updateFile( `libs/${mylib}/setup.ts`, stripIndents` - const { registerTsProject } = require('nx/src/plugins/js/utils/register'); + const { registerTsProject } = require('@nrwl/js'); const cleanup = registerTsProject('.', 'tsconfig.base.json'); import {setup} from '@global-fun/globals'; @@ -61,7 +61,7 @@ describe('Jest', () => { updateFile( `libs/${mylib}/teardown.ts`, stripIndents` - import { registerTsProject } from 'nx/src/plugins/js/utils/register'; + import { registerTsProject } from '@nrwl/js'; const cleanup = registerTsProject('.', 'tsconfig.base.json'); import {teardown} from '@global-fun/globals'; diff --git a/e2e/node/src/node.test.ts b/e2e/node/src/node.test.ts index 211ed7a05efaa4..83b0f0e3a5e767 100644 --- a/e2e/node/src/node.test.ts +++ b/e2e/node/src/node.test.ts @@ -14,7 +14,6 @@ import { packageManagerLockFile, promisifiedTreeKill, readFile, - readJson, runCLI, runCLIAsync, runCommand, @@ -26,7 +25,7 @@ import { } from '@nrwl/e2e/utils'; import { exec, execSync } from 'child_process'; import * as http from 'http'; -import { getLockFileName } from 'nx/src/plugins/js'; +import { getLockFileName } from '@nrwl/js'; import { satisfies } from 'semver'; function getData(port, path = '/api'): Promise { diff --git a/packages/angular/src/builders/webpack-dev-server/webpack-dev-server.impl.ts b/packages/angular/src/builders/webpack-dev-server/webpack-dev-server.impl.ts index 525d24dbb67236..72bd953f4701a8 100644 --- a/packages/angular/src/builders/webpack-dev-server/webpack-dev-server.impl.ts +++ b/packages/angular/src/builders/webpack-dev-server/webpack-dev-server.impl.ts @@ -17,7 +17,7 @@ import type { Schema } from './schema'; import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs'; import { from } from 'rxjs'; import { switchMap } from 'rxjs/operators'; -import { getRootTsConfigPath } from 'nx/src/plugins/js'; +import { getRootTsConfigPath } from '@nrwl/js'; type BuildTargetOptions = { tsConfig: string; diff --git a/packages/angular/src/generators/component-cypress-spec/lib/get-component-selector.ts b/packages/angular/src/generators/component-cypress-spec/lib/get-component-selector.ts index 8c570beb5f56b1..f2388a7903770a 100644 --- a/packages/angular/src/generators/component-cypress-spec/lib/get-component-selector.ts +++ b/packages/angular/src/generators/component-cypress-spec/lib/get-component-selector.ts @@ -1,6 +1,6 @@ import type { Tree } from '@nrwl/devkit'; import { ensureTypescript } from '@nrwl/js/src/utils/typescript/ensure-typescript'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import type { PropertyAssignment } from 'typescript'; import { diff --git a/packages/angular/src/generators/utils/storybook-ast/module-info.ts b/packages/angular/src/generators/utils/storybook-ast/module-info.ts index 7338ed9105361f..3f6d6d551d2700 100644 --- a/packages/angular/src/generators/utils/storybook-ast/module-info.ts +++ b/packages/angular/src/generators/utils/storybook-ast/module-info.ts @@ -5,7 +5,7 @@ import { stripIndents, visitNotIgnoredFiles, } from '@nrwl/devkit'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import { extname } from 'path'; import type { ClassDeclaration, diff --git a/packages/angular/src/generators/utils/storybook-ast/storybook-inputs.ts b/packages/angular/src/generators/utils/storybook-ast/storybook-inputs.ts index 12cc7132e2f027..ece7f0598b2db5 100644 --- a/packages/angular/src/generators/utils/storybook-ast/storybook-inputs.ts +++ b/packages/angular/src/generators/utils/storybook-ast/storybook-inputs.ts @@ -1,5 +1,5 @@ import type { Tree } from '@nrwl/devkit'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import { getSourceNodes } from '@nrwl/js'; import type { PropertyDeclaration } from 'typescript'; import { getTsSourceFile } from '../../../utils/nx-devkit/ast-utils'; diff --git a/packages/angular/src/utils/nx-devkit/ast-utils.ts b/packages/angular/src/utils/nx-devkit/ast-utils.ts index afe09551f46a0d..6fb39163a583b0 100644 --- a/packages/angular/src/utils/nx-devkit/ast-utils.ts +++ b/packages/angular/src/utils/nx-devkit/ast-utils.ts @@ -1,5 +1,5 @@ import type * as ts from 'typescript'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import { getImport, getSourceNodes, diff --git a/packages/devkit/src/utils/module-federation/share.ts b/packages/devkit/src/utils/module-federation/share.ts index 12e62d5bdd5cf0..0c91a911665acb 100644 --- a/packages/devkit/src/utils/module-federation/share.ts +++ b/packages/devkit/src/utils/module-federation/share.ts @@ -12,7 +12,7 @@ import { collectWorkspaceLibrarySecondaryEntryPoints, } from './secondary-entry-points'; // eslint-disable-next-line @typescript-eslint/no-restricted-imports -import { getRootTsConfigPath } from 'nx/src/plugins/js'; +import { getRootTsConfigPath } from 'nx/src/plugins/js/utils/typescript'; import type { ProjectGraph } from 'nx/src/config/project-graph'; import { requireNx } from '../../../nx'; diff --git a/packages/devkit/src/utils/module-federation/typescript.ts b/packages/devkit/src/utils/module-federation/typescript.ts index cf0c068c19d2d5..8868312aee1eb2 100644 --- a/packages/devkit/src/utils/module-federation/typescript.ts +++ b/packages/devkit/src/utils/module-federation/typescript.ts @@ -1,7 +1,7 @@ import { existsSync } from 'fs'; import { ParsedCommandLine } from 'typescript'; // eslint-disable-next-line @typescript-eslint/no-restricted-imports -import { getRootTsConfigPath } from 'nx/src/plugins/js'; +import { getRootTsConfigPath } from 'nx/src/plugins/js/utils/typescript'; import { dirname } from 'path'; let tsConfig: ParsedCommandLine; diff --git a/packages/eslint-plugin-nx/src/resolve-workspace-rules.ts b/packages/eslint-plugin-nx/src/resolve-workspace-rules.ts index 1acb853f4ede30..fcbeb2fb6ed4cd 100644 --- a/packages/eslint-plugin-nx/src/resolve-workspace-rules.ts +++ b/packages/eslint-plugin-nx/src/resolve-workspace-rules.ts @@ -1,6 +1,6 @@ import type { TSESLint } from '@typescript-eslint/utils'; import { existsSync } from 'fs'; -import { registerTsProject } from 'nx/src/plugins/js/utils/register'; +import { registerTsProject } from '@nrwl/js'; import { WORKSPACE_PLUGIN_DIR, WORKSPACE_RULE_NAMESPACE } from './constants'; type ESLintRules = Record>; diff --git a/packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts b/packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts index c91563daa50fd6..7b281c6c476863 100644 --- a/packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts +++ b/packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts @@ -8,7 +8,7 @@ import { } from '@nrwl/devkit'; import { findProject, getSourceFilePath } from '../utils/runtime-lint-utils'; import { existsSync } from 'fs'; -import { registerTsProject } from 'nx/src/plugins/js/utils/register'; +import { registerTsProject } from '@nrwl/js'; import * as path from 'path'; import { createESLintRule } from '../utils/create-eslint-rule'; diff --git a/packages/eslint-plugin-nx/src/utils/ast-utils.ts b/packages/eslint-plugin-nx/src/utils/ast-utils.ts index e4296ffe192cbf..670a0fae832b87 100644 --- a/packages/eslint-plugin-nx/src/utils/ast-utils.ts +++ b/packages/eslint-plugin-nx/src/utils/ast-utils.ts @@ -3,7 +3,7 @@ import { ProjectGraphProjectNode, readJsonFile, } from '@nrwl/devkit'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import { existsSync, readFileSync } from 'fs'; import { dirname } from 'path'; import ts = require('typescript'); diff --git a/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.ts b/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.ts index 63a599b1ad5e53..133c93d39b3cd1 100644 --- a/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.ts +++ b/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.ts @@ -18,10 +18,7 @@ import { findProjectForPath, ProjectRootMappings, } from 'nx/src/project-graph/utils/find-project-for-path'; -import { - getRootTsConfigFileName, - resolveModuleByImport, -} from 'nx/src/plugins/js'; +import { getRootTsConfigFileName, resolveModuleByImport } from '@nrwl/js'; export type Deps = { [projectName: string]: ProjectGraphDependency[] }; type SingleSourceTagConstraint = { diff --git a/packages/expo/src/generators/component/lib/add-import.ts b/packages/expo/src/generators/component/lib/add-import.ts index d0d46cdf5e3e86..55f3b85b057b45 100644 --- a/packages/expo/src/generators/component/lib/add-import.ts +++ b/packages/expo/src/generators/component/lib/add-import.ts @@ -1,4 +1,4 @@ -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import * as ts from 'typescript'; import { ChangeType, StringChange } from '@nrwl/devkit'; diff --git a/packages/js/src/index.ts b/packages/js/src/index.ts index da0fd72d39a763..b10786748f87e9 100644 --- a/packages/js/src/index.ts +++ b/packages/js/src/index.ts @@ -11,5 +11,19 @@ export * from './utils/assets'; export * from './utils/package-json/update-package-json'; export { libraryGenerator } from './generators/library/library'; export { initGenerator } from './generators/init/init'; -export { createLockFile } from 'nx/src/plugins/js'; -export { createPackageJson } from 'nx/src/plugins/js'; + +export { + createLockFile, + getLockFileName, +} from 'nx/src/plugins/js/lock-file/lock-file'; +export { createPackageJson } from 'nx/src/plugins/js/package-json/create-package-json'; +export { + findNodes, + getRootTsConfigPath, + // readTsConfig, + resolveModuleByImport, +} from 'nx/src/plugins/js/utils/typescript'; +export { + registerTsProject, + registerTsConfigPaths, +} from 'nx/src/plugins/js/utils/register'; diff --git a/packages/js/src/utils/package-json/update-package-json.ts b/packages/js/src/utils/package-json/update-package-json.ts index 11d79dad91d8e2..0dc5cea568bff7 100644 --- a/packages/js/src/utils/package-json/update-package-json.ts +++ b/packages/js/src/utils/package-json/update-package-json.ts @@ -1,5 +1,4 @@ -import { createLockFile, getLockFileName } from 'nx/src/plugins/js'; -import { createPackageJson } from 'nx/src/plugins/js'; +import { createLockFile, getLockFileName, createPackageJson } from '../../'; import { ExecutorContext, getOutputsForTargetAndConfiguration, diff --git a/packages/js/src/utils/typescript/ast-utils.ts b/packages/js/src/utils/typescript/ast-utils.ts index 4d57d7bc20fe0b..7dbc661fdbc700 100644 --- a/packages/js/src/utils/typescript/ast-utils.ts +++ b/packages/js/src/utils/typescript/ast-utils.ts @@ -2,7 +2,7 @@ import type { Tree } from '@nrwl/devkit'; import type * as ts from 'typescript'; // TODO(colum): replace when https://github.com/nrwl/nx/pull/15497 is merged import { getSourceNodes } from '@nrwl/workspace/src/utilities/typescript'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '../..'; import { ensureTypescript } from './ensure-typescript'; let tsModule: typeof import('typescript'); diff --git a/packages/js/src/utils/typescript/ts-config.ts b/packages/js/src/utils/typescript/ts-config.ts index 6743ecaa8a4c7b..5b95518f6f57d6 100644 --- a/packages/js/src/utils/typescript/ts-config.ts +++ b/packages/js/src/utils/typescript/ts-config.ts @@ -42,9 +42,13 @@ export function getRelativePathToRootTsConfig( return offsetFromRoot(targetPath) + getRootTsConfigPathInTree(tree); } -export function getRootTsConfigFileName(tree: Tree): string | null { +export function getRootTsConfigFileName(tree?: Tree): string | null { for (const tsConfigName of ['tsconfig.base.json', 'tsconfig.json']) { - if (tree.exists(tsConfigName)) { + const pathExists = tree + ? tree.exists(tsConfigName) + : existsSync(join(workspaceRoot, tsConfigName)); + + if (pathExists) { return tsConfigName; } } diff --git a/packages/next/src/executors/build/build.impl.ts b/packages/next/src/executors/build/build.impl.ts index 23ef4fd8ff3ca8..178c98ba83c5d8 100644 --- a/packages/next/src/executors/build/build.impl.ts +++ b/packages/next/src/executors/build/build.impl.ts @@ -5,7 +5,7 @@ import { workspaceRoot, writeJsonFile, } from '@nrwl/devkit'; -import { createLockFile, createPackageJson } from '@nrwl/js'; +import { createLockFile, createPackageJson, getLockFileName } from '@nrwl/js'; import build from 'next/dist/build'; import { join, resolve } from 'path'; import { copySync, existsSync, mkdir, writeFileSync } from 'fs-extra'; @@ -18,8 +18,6 @@ import { createNextConfigFile } from './lib/create-next-config-file'; import { checkPublicDirectory } from './lib/check-project'; import { NextBuildBuilderOptions } from '../../utils/types'; -import { getLockFileName } from 'nx/src/plugins/js'; - export default async function buildExecutor( options: NextBuildBuilderOptions, context: ExecutorContext diff --git a/packages/nx/src/command-line/format.ts b/packages/nx/src/command-line/format.ts index 7543209508ce21..bcb801314ab3f0 100644 --- a/packages/nx/src/command-line/format.ts +++ b/packages/nx/src/command-line/format.ts @@ -12,7 +12,10 @@ import * as yargs from 'yargs'; import * as prettier from 'prettier'; import { sortObjectByKeys } from '../utils/object-sort'; -import { getRootTsConfigFileName, getRootTsConfigPath } from '../plugins/js'; +import { + getRootTsConfigFileName, + getRootTsConfigPath, +} from '../plugins/js/utils/typescript'; import { createProjectGraphAsync } from '../project-graph/project-graph'; import { filterAffected } from '../project-graph/affected/affected-project-graph'; import { readNxJson } from '../config/configuration'; diff --git a/packages/nx/src/devkit-exports.ts b/packages/nx/src/devkit-exports.ts index 2082225c551aa9..47b76914e9fc6d 100644 --- a/packages/nx/src/devkit-exports.ts +++ b/packages/nx/src/devkit-exports.ts @@ -225,18 +225,3 @@ export { Hash, Hasher } from './hasher/hasher'; * @category Utils */ export { cacheDir } from './utils/cache-directory'; - -import { createLockFile as _createLockFile } from './plugins/js'; -import { createPackageJson as _createPackageJson } from './plugins/js'; - -/** - * @category Package Manager - */ -/** - * @deprecated Import this from @nrwl/js instead - */ -export const createLockFile = _createLockFile; -/** - * @deprecated Import this from @nrwl/js instead - */ -export const createPackageJson = _createPackageJson; diff --git a/packages/nx/src/plugins/js/index.ts b/packages/nx/src/plugins/js/index.ts index 7f7fb19ef00f97..b3cbdc915bffbe 100644 --- a/packages/nx/src/plugins/js/index.ts +++ b/packages/nx/src/plugins/js/index.ts @@ -18,19 +18,6 @@ import { workspaceRoot } from '../../utils/workspace-root'; import { ensureDirSync } from 'fs-extra'; import { removeNpmNodes } from './lock-file/remove-npm-nodes'; -/** - * Exports section - */ -export { - findNodes, - getRootTsConfigPath, - getRootTsConfigFileName, - readTsConfig, - resolveModuleByImport, -} from './utils/typescript'; -export { getLockFileName, createLockFile } from './lock-file/lock-file'; -export { createPackageJson } from './package-json/create-package-json'; - export const processProjectGraph: ProjectGraphProcessor = async ( graph, context diff --git a/packages/nx/src/project-graph/build-project-graph.ts b/packages/nx/src/project-graph/build-project-graph.ts index 9f6a950fa140d6..8e525fcb9c09e4 100644 --- a/packages/nx/src/project-graph/build-project-graph.ts +++ b/packages/nx/src/project-graph/build-project-graph.ts @@ -16,7 +16,7 @@ import { buildWorkspaceProjectNodes } from './build-nodes'; import { loadNxPlugins } from '../utils/nx-plugin'; import { defaultFileHasher } from '../hasher/file-hasher'; import { createProjectFileMap } from './file-map-utils'; -import { getRootTsConfigPath } from '../plugins/js'; +import { getRootTsConfigPath } from '../plugins/js/utils/typescript'; import { ProjectFileMap, ProjectGraph, diff --git a/packages/react-native/src/generators/component/lib/add-import.ts b/packages/react-native/src/generators/component/lib/add-import.ts index 2ad2d05b944729..4995e84afffa9b 100644 --- a/packages/react-native/src/generators/component/lib/add-import.ts +++ b/packages/react-native/src/generators/component/lib/add-import.ts @@ -1,4 +1,4 @@ -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import type * as ts from 'typescript'; import { ChangeType, StringChange } from '@nrwl/devkit'; import { ensureTypescript } from '@nrwl/js/src/utils/typescript/ensure-typescript'; diff --git a/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.ts b/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.ts index 8923f9f69b2777..5fabc5bdf60c45 100644 --- a/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.ts +++ b/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.ts @@ -7,7 +7,7 @@ import { } from '@nrwl/devkit'; import ts = require('typescript'); -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; export async function migrateToWebPack5(tree: Tree) { allReactProjectsWithStorybookConfiguration(tree).forEach((project) => { diff --git a/packages/react/src/migrations/update-14-0-0/update-react-dom-render-for-v18.ts b/packages/react/src/migrations/update-14-0-0/update-react-dom-render-for-v18.ts index e682974ab188b5..c930755f7e8abd 100644 --- a/packages/react/src/migrations/update-14-0-0/update-react-dom-render-for-v18.ts +++ b/packages/react/src/migrations/update-14-0-0/update-react-dom-render-for-v18.ts @@ -7,7 +7,7 @@ import { Tree, formatFiles, } from '@nrwl/devkit'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import * as ts from 'typescript'; export async function update(tree: Tree) { diff --git a/packages/react/src/module-federation/ast-utils.ts b/packages/react/src/module-federation/ast-utils.ts index cf32dbf6e969da..2bb8cc7fbfe0eb 100644 --- a/packages/react/src/module-federation/ast-utils.ts +++ b/packages/react/src/module-federation/ast-utils.ts @@ -1,6 +1,6 @@ import type * as ts from 'typescript'; import { ChangeType, StringChange } from '@nrwl/devkit'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import { findClosestOpening, findElements, diff --git a/packages/react/src/utils/ast-utils.ts b/packages/react/src/utils/ast-utils.ts index b4aa0a38a39f93..59490c148b2117 100644 --- a/packages/react/src/utils/ast-utils.ts +++ b/packages/react/src/utils/ast-utils.ts @@ -1,5 +1,5 @@ import type * as ts from 'typescript'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import { ChangeType, logger, diff --git a/packages/storybook/src/executors/utils.ts b/packages/storybook/src/executors/utils.ts index 9d167b95b46d0a..1aad833570b3dc 100644 --- a/packages/storybook/src/executors/utils.ts +++ b/packages/storybook/src/executors/utils.ts @@ -1,5 +1,5 @@ import { joinPathFragments, logger } from '@nrwl/devkit'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import 'dotenv/config'; import { existsSync, readFileSync } from 'fs'; import { join } from 'path'; diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts index 193eac62d0b225..ec2e0bd037417b 100644 --- a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts +++ b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts @@ -6,7 +6,7 @@ import { import { joinPathFragments, writeJson } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { storybookVersion } from '@nrwl/storybook'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import * as ts from 'typescript'; import { SyntaxKind } from 'typescript'; import { nxVersion } from '../../../utils/versions'; diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts index bdcdd894db5c3d..50e5e2a2e2fa1f 100644 --- a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts +++ b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts @@ -9,7 +9,7 @@ import { visitNotIgnoredFiles, } from '@nrwl/devkit'; import { fileExists } from '@nrwl/workspace/src/utilities/fileutils'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import { join, normalize } from 'path'; import { SyntaxKind } from 'typescript'; import { getTsSourceFile } from '../../../utils/utilities'; diff --git a/packages/storybook/src/utils/utilities.ts b/packages/storybook/src/utils/utilities.ts index abc75d371e289b..6fab7c4400b032 100644 --- a/packages/storybook/src/utils/utilities.ts +++ b/packages/storybook/src/utils/utilities.ts @@ -7,7 +7,7 @@ import { import { CompilerOptions } from 'typescript'; import { storybookVersion } from './versions'; import { statSync } from 'fs'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import ts = require('typescript'); import { gte, lt, major } from 'semver'; import { join } from 'path'; diff --git a/packages/vite/src/executors/build/build.impl.ts b/packages/vite/src/executors/build/build.impl.ts index 7a0b9cd55c7bb5..6b379dd8e903b2 100644 --- a/packages/vite/src/executors/build/build.impl.ts +++ b/packages/vite/src/executors/build/build.impl.ts @@ -11,7 +11,7 @@ import { existsSync } from 'fs'; import { resolve } from 'path'; import { createAsyncIterable } from '@nrwl/devkit/src/utils/async-iterable'; -import { registerTsConfigPaths } from 'nx/src/plugins/js/utils/register'; +import { registerTsConfigPaths } from '@nrwl/js'; export async function* viteBuildExecutor( options: ViteBuildExecutorOptions, diff --git a/packages/vite/src/executors/dev-server/dev-server.impl.ts b/packages/vite/src/executors/dev-server/dev-server.impl.ts index 840f1337e8a078..1f05321a571e55 100644 --- a/packages/vite/src/executors/dev-server/dev-server.impl.ts +++ b/packages/vite/src/executors/dev-server/dev-server.impl.ts @@ -11,7 +11,7 @@ import { import { ViteDevServerExecutorOptions } from './schema'; import { ViteBuildExecutorOptions } from '../build/schema'; -import { registerTsConfigPaths } from 'nx/src/plugins/js/utils/register'; +import { registerTsConfigPaths } from '@nrwl/js'; import { resolve } from 'path'; export async function* viteDevServerExecutor( diff --git a/packages/vite/src/migrations/update-15-3-1/update-vite-tsconfig-paths.ts b/packages/vite/src/migrations/update-15-3-1/update-vite-tsconfig-paths.ts index bafd477608b2fa..9cf06a53da851e 100644 --- a/packages/vite/src/migrations/update-15-3-1/update-vite-tsconfig-paths.ts +++ b/packages/vite/src/migrations/update-15-3-1/update-vite-tsconfig-paths.ts @@ -7,7 +7,7 @@ import { } from '@nrwl/devkit'; import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils'; import { tsquery } from '@phenomnomnominal/tsquery'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import { normalizeViteConfigFilePathWithTree } from '../../utils/generator-utils'; import ts = require('typescript'); diff --git a/packages/vite/src/utils/vite-config-edit-utils.ts b/packages/vite/src/utils/vite-config-edit-utils.ts index c55320006cd8c1..dc13d345ea7164 100644 --- a/packages/vite/src/utils/vite-config-edit-utils.ts +++ b/packages/vite/src/utils/vite-config-edit-utils.ts @@ -1,5 +1,5 @@ import { applyChangesToString, ChangeType, Tree } from '@nrwl/devkit'; -import { findNodes } from 'nx/src/plugins/js'; +import { findNodes } from '@nrwl/js'; import { TargetFlags } from './generator-utils'; import type { Node, ReturnStatement } from 'typescript'; diff --git a/packages/webpack/src/plugins/generate-package-json-plugin.ts b/packages/webpack/src/plugins/generate-package-json-plugin.ts index b2675d0af73213..ee1c0c0a4531f6 100644 --- a/packages/webpack/src/plugins/generate-package-json-plugin.ts +++ b/packages/webpack/src/plugins/generate-package-json-plugin.ts @@ -10,7 +10,7 @@ import { HelperDependency, readTsConfig, } from '@nrwl/js'; -import { getLockFileName } from 'nx/src/plugins/js'; +import { getLockFileName } from '@nrwl/js'; const pluginName = 'GeneratePackageJsonPlugin'; diff --git a/packages/workspace/src/generators/move/lib/update-imports.ts b/packages/workspace/src/generators/move/lib/update-imports.ts index 2f27598972ed12..fdbd514376896e 100644 --- a/packages/workspace/src/generators/move/lib/update-imports.ts +++ b/packages/workspace/src/generators/move/lib/update-imports.ts @@ -13,8 +13,10 @@ import { getImportPath, } from '@nrwl/devkit'; import type * as ts from 'typescript'; -import { getRootTsConfigPathInTree } from '../../../utilities/ts-config'; -import { findNodes } from 'nx/src/plugins/js'; +import { + getRootTsConfigPathInTree, + findNodes, +} from '../../../utilities/ts-config'; import { NormalizedSchema } from '../schema'; import { normalizeSlashes } from './utils'; import { relative } from 'path'; diff --git a/packages/workspace/src/utilities/ts-config.ts b/packages/workspace/src/utilities/ts-config.ts index f30687b3006268..08480ea271236e 100644 --- a/packages/workspace/src/utilities/ts-config.ts +++ b/packages/workspace/src/utilities/ts-config.ts @@ -1,6 +1,7 @@ import { offsetFromRoot, Tree, workspaceRoot } from '@nrwl/devkit'; import { existsSync } from 'fs'; import { dirname, join } from 'path'; +import type { Node, SyntaxKind } from 'typescript'; import { ensureTypescript } from './typescript'; let tsModule: typeof import('typescript'); @@ -47,3 +48,38 @@ export function getRootTsConfigFileName(): string | null { return null; } + +export function findNodes( + node: Node, + kind: SyntaxKind | SyntaxKind[], + max = Infinity +): Node[] { + if (!node || max == 0) { + return []; + } + + const arr: Node[] = []; + const hasMatch = Array.isArray(kind) + ? kind.includes(node.kind) + : node.kind === kind; + if (hasMatch) { + arr.push(node); + max--; + } + if (max > 0) { + for (const child of node.getChildren()) { + findNodes(child, kind, max).forEach((node) => { + if (max > 0) { + arr.push(node); + } + max--; + }); + + if (max <= 0) { + break; + } + } + } + + return arr; +} diff --git a/packages/workspace/src/utilities/typescript.ts b/packages/workspace/src/utilities/typescript.ts index b1e5d10575dda2..4f233a0c2ad8db 100644 --- a/packages/workspace/src/utilities/typescript.ts +++ b/packages/workspace/src/utilities/typescript.ts @@ -4,7 +4,6 @@ import type * as ts from 'typescript'; import { typescriptVersion } from '../utils/versions'; export { compileTypeScript } from './typescript/compilation'; export type { TypeScriptCompilationOptions } from './typescript/compilation'; -export { findNodes } from './typescript/find-nodes'; // TODO(v16): remove this export { getSourceNodes } from './typescript/get-source-nodes'; const normalizedAppRoot = workspaceRoot.replace(/\\/g, '/'); diff --git a/packages/workspace/src/utilities/typescript/find-nodes.ts b/packages/workspace/src/utilities/typescript/find-nodes.ts deleted file mode 100644 index f3aa2909e70851..00000000000000 --- a/packages/workspace/src/utilities/typescript/find-nodes.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { findNodes as _findNodes } from 'nx/src/plugins/js'; -import type { Node, SyntaxKind } from 'typescript'; - -// TODO(v16): This should be removed. - -/** - * @deprecated This function is deprecated and no longer supported. - */ -export function findNodes( - node: Node, - kind: SyntaxKind | SyntaxKind[], - max = Infinity -) { - console.warn('"findNodes" is deprecated and no longer supported.'); - return _findNodes(node, kind, max); -}