Skip to content

Commit

Permalink
cleanup(angular): address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Mar 7, 2022
1 parent 7996a79 commit 1da8cab
Show file tree
Hide file tree
Showing 22 changed files with 103 additions and 78 deletions.
@@ -1,6 +1,6 @@
import type { Tree } from '@nrwl/devkit';
import { generateFiles, joinPathFragments, offsetFromRoot } from '@nrwl/devkit';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { generateFiles, joinPathFragments } from '@nrwl/devkit';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import type { NormalizedSchema } from './normalized-schema';

export function createFiles(
Expand All @@ -16,9 +16,10 @@ export function createFiles(
options.appProjectRoot,
{
...options,
rootTsConfigPath: `${offsetFromRoot(
rootTsConfigPath: getRelativePathToRootTsConfig(
host,
options.appProjectRoot
)}${getRootTsConfigPathInTree(host)}`,
),
tpl: '',
}
);
Expand Down
Expand Up @@ -6,7 +6,7 @@ import {
updateJson,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import type { NormalizedSchema } from './normalized-schema';

export function updateE2eProject(tree: Tree, options: NormalizedSchema) {
Expand Down Expand Up @@ -61,9 +61,7 @@ export function updateE2eProject(tree: Tree, options: NormalizedSchema) {
updateJson(tree, `${options.e2eProjectRoot}/tsconfig.json`, (json) => {
return {
...json,
extends: `${offsetFromRoot(
options.e2eProjectRoot
)}${getRootTsConfigPathInTree(tree)}`,
extends: getRelativePathToRootTsConfig(tree, options.e2eProjectRoot),
};
});
}
7 changes: 4 additions & 3 deletions packages/angular/src/generators/library/lib/update-project.ts
Expand Up @@ -9,7 +9,7 @@ import {
updateProjectConfiguration,
} from '@nrwl/devkit';
import { replaceAppNameWithPath } from '@nrwl/workspace';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import * as path from 'path';
import { NormalizedSchema } from './normalized-schema';
import { updateNgPackage } from './update-ng-package';
Expand Down Expand Up @@ -119,9 +119,10 @@ function createFiles(host: Tree, options: NormalizedSchema) {
options.projectRoot,
{
...options,
rootTsConfigPath: `${offsetFromRoot(
rootTsConfigPath: getRelativePathToRootTsConfig(
host,
options.projectRoot
)}${getRootTsConfigPathInTree(host)}`,
),
tpl: '',
}
);
Expand Down
Expand Up @@ -5,7 +5,7 @@ import {
logger,
offsetFromRoot,
} from '@nrwl/devkit';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import type { Schema } from '../schema';

const SHARED_SINGLETON_LIBRARIES = [
Expand All @@ -32,7 +32,6 @@ export function generateWebpackConfig(
);
}

const rootOffset = offsetFromRoot(appRoot);
generateFiles(
host,
joinPathFragments(__dirname, '../files/webpack'),
Expand All @@ -44,8 +43,8 @@ export function generateWebpackConfig(
remotes: remotesWithPorts ?? [],
sourceRoot: appRoot,
sharedLibraries: SHARED_SINGLETON_LIBRARIES,
offsetFromRoot: rootOffset,
rootTsConfigPath: rootOffset + getRootTsConfigPathInTree(host),
offsetFromRoot: offsetFromRoot(appRoot),
rootTsConfigPath: getRelativePathToRootTsConfig(host, appRoot),
}
);
}
@@ -1,17 +1,16 @@
import type { Tree } from '@nrwl/devkit';
import {
joinPathFragments,
offsetFromRoot,
readProjectConfiguration,
updateJson,
} from '@nrwl/devkit';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';

export function updateTsConfig(tree: Tree, project: string): void {
const { root } = readProjectConfiguration(tree, project);
const workerTsConfigPath = joinPathFragments(root, 'tsconfig.worker.json');
updateJson(tree, workerTsConfigPath, (json) => {
json.extends = offsetFromRoot(root) + getRootTsConfigPathInTree(tree);
json.extends = getRelativePathToRootTsConfig(tree, root);
return json;
});
}
Expand Up @@ -16,7 +16,7 @@ import {
} from '@nrwl/devkit';
import { Linter, lintProjectGenerator } from '@nrwl/linter';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';

import { join } from 'path';
// app
Expand All @@ -34,14 +34,13 @@ export interface CypressProjectSchema extends Schema {
}

function createFiles(tree: Tree, options: CypressProjectSchema) {
const rootOffset = offsetFromRoot(options.projectRoot);
generateFiles(tree, join(__dirname, './files'), options.projectRoot, {
tmpl: '',
...options,
project: options.project || 'Project',
ext: options.js ? 'js' : 'ts',
offsetFromRoot: rootOffset,
rootTsConfigPath: rootOffset + getRootTsConfigPathInTree(tree),
offsetFromRoot: offsetFromRoot(options.projectRoot),
rootTsConfigPath: getRelativePathToRootTsConfig(tree, options.projectRoot),
});

const cypressVersion = installedCypressVersion();
Expand Down
7 changes: 3 additions & 4 deletions packages/detox/src/generators/application/lib/create-files.ts
@@ -1,14 +1,13 @@
import { generateFiles, offsetFromRoot, toJS, Tree } from '@nrwl/devkit';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import { join } from 'path';
import { NormalizedSchema } from './normalize-options';

export function createFiles(host: Tree, options: NormalizedSchema) {
const rootOffset = offsetFromRoot(options.projectRoot);
generateFiles(host, join(__dirname, '../files/app'), options.projectRoot, {
...options,
offsetFromRoot: rootOffset,
rootTsConfigPath: rootOffset + getRootTsConfigPathInTree(host),
offsetFromRoot: offsetFromRoot(options.projectRoot),
rootTsConfigPath: getRelativePathToRootTsConfig(host, options.projectRoot),
});
if (options.js) {
toJS(host);
Expand Down
4 changes: 2 additions & 2 deletions packages/devkit/src/generators/format-files.ts
Expand Up @@ -132,12 +132,12 @@ function sortTsConfig(tree: Tree) {
}
}

function getRootTsConfigPath(tree: Tree): string | undefined {
function getRootTsConfigPath(tree: Tree): string | null {
for (const path of ['tsconfig.base.json', 'tsconfig.json']) {
if (tree.exists(path)) {
return path;
}
}

return undefined;
return null;
}
10 changes: 6 additions & 4 deletions packages/js/src/generators/library/library.ts
Expand Up @@ -16,7 +16,10 @@ import {
import { jestProjectGenerator } from '@nrwl/jest';
import { Linter, lintProjectGenerator } from '@nrwl/linter';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import {
getRelativePathToRootTsConfig,
getRootTsConfigPathInTree,
} from '@nrwl/workspace/src/utilities/typescript';
import { join } from 'path';
import { LibraryGeneratorSchema } from '../../utils/schema';
import { addSwcConfig } from '../../utils/swc/add-swc-config';
Expand Down Expand Up @@ -162,7 +165,6 @@ function updateTsConfig(tree: Tree, options: NormalizedSchema) {
function createFiles(tree: Tree, options: NormalizedSchema, filesDir: string) {
const { className, name, propertyName } = names(options.name);

const rootOffset = offsetFromRoot(options.projectRoot);
generateFiles(tree, filesDir, options.projectRoot, {
...options,
dot: '.',
Expand All @@ -173,8 +175,8 @@ function createFiles(tree: Tree, options: NormalizedSchema, filesDir: string) {
cliCommand: 'nx',
strict: undefined,
tmpl: '',
offsetFromRoot: rootOffset,
rootTsConfigPath: rootOffset + getRootTsConfigPathInTree(tree),
offsetFromRoot: offsetFromRoot(options.projectRoot),
rootTsConfigPath: getRelativePathToRootTsConfig(tree, options.projectRoot),
buildable: options.buildable === true,
hasUnitTestRunner: options.unitTestRunner !== 'none',
});
Expand Down
Expand Up @@ -11,7 +11,7 @@ import {
updateWorkspaceConfiguration,
} from '@nrwl/devkit';
import { addPropertyToJestConfig, jestProjectGenerator } from '@nrwl/jest';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import { join } from 'path';
import { workspaceLintPluginDir } from '../../utils/workspace-lint-rules';

Expand All @@ -34,11 +34,10 @@ export async function lintWorkspaceRulesProjectGenerator(tree: Tree) {
});

// Generate the required files
const rootOffset = offsetFromRoot(WORKSPACE_PLUGIN_DIR);
generateFiles(tree, join(__dirname, 'files'), workspaceLintPluginDir, {
tmpl: '',
offsetFromRoot: rootOffset,
rootTsConfigPath: rootOffset + getRootTsConfigPathInTree(tree),
offsetFromRoot: offsetFromRoot(WORKSPACE_PLUGIN_DIR),
rootTsConfigPath: getRelativePathToRootTsConfig(tree, WORKSPACE_PLUGIN_DIR),
});

/**
Expand Down
Expand Up @@ -4,16 +4,18 @@ import {
createAppJsx,
createStyleRules,
} from './create-application-files.helpers';
import { generateFiles, names, offsetFromRoot, toJS, Tree } from '@nrwl/devkit';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { generateFiles, names, toJS, Tree } from '@nrwl/devkit';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';

export function createApplicationFiles(host: Tree, options: NormalizedSchema) {
const templateVariables = {
...names(options.name),
...options,
tmpl: '',
rootTsConfigPath:
offsetFromRoot(options.appProjectRoot) + getRootTsConfigPathInTree(host),
rootTsConfigPath: getRelativePathToRootTsConfig(
host,
options.appProjectRoot
),
appContent: createAppJsx(options.name),
styleContent: createStyleRules(),
pageStyleContent: `.page {}`,
Expand Down
10 changes: 6 additions & 4 deletions packages/node/src/generators/application/application.ts
Expand Up @@ -28,7 +28,7 @@ import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-ser

import { Schema } from './schema';
import { initGenerator } from '../init/init';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';

export interface NormalizedSchema extends Schema {
appProjectRoot: string;
Expand Down Expand Up @@ -109,13 +109,15 @@ function addProject(tree: Tree, options: NormalizedSchema) {
}

function addAppFiles(tree: Tree, options: NormalizedSchema) {
const offset = offsetFromRoot(options.appProjectRoot);
generateFiles(tree, join(__dirname, './files/app'), options.appProjectRoot, {
tmpl: '',
name: options.name,
root: options.appProjectRoot,
offset,
rootTsConfigPath: offset + getRootTsConfigPathInTree(tree),
offset: offsetFromRoot(options.appProjectRoot),
rootTsConfigPath: getRelativePathToRootTsConfig(
tree,
options.appProjectRoot
),
});
if (options.js) {
toJS(tree);
Expand Down
6 changes: 2 additions & 4 deletions packages/nx-plugin/src/generators/e2e-project/e2e.ts
Expand Up @@ -7,13 +7,12 @@ import {
generateFiles,
addProjectConfiguration,
updateProjectConfiguration,
offsetFromRoot,
} from '@nrwl/devkit';
import type { Tree } from '@nrwl/devkit';
import type { Schema } from './schema';
import * as path from 'path';
import { jestProjectGenerator } from '@nrwl/jest';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';

interface NormalizedSchema extends Schema {
projectRoot: string;
Expand Down Expand Up @@ -52,8 +51,7 @@ function addFiles(host: Tree, options: NormalizedSchema) {
generateFiles(host, path.join(__dirname, './files'), options.projectRoot, {
...options,
tmpl: '',
rootTsConfigPath:
offsetFromRoot(options.projectRoot) + getRootTsConfigPathInTree(host),
rootTsConfigPath: getRelativePathToRootTsConfig(host, options.projectRoot),
});
}

Expand Down
@@ -1,14 +1,16 @@
import { generateFiles, offsetFromRoot, toJS, Tree } from '@nrwl/devkit';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import { join } from 'path';
import { NormalizedSchema } from './normalize-options';

export function createApplicationFiles(host: Tree, options: NormalizedSchema) {
const rootOffset = offsetFromRoot(options.appProjectRoot);
generateFiles(host, join(__dirname, '../files/app'), options.appProjectRoot, {
...options,
offsetFromRoot: rootOffset,
rootTsConfigPath: rootOffset + getRootTsConfigPathInTree(host),
offsetFromRoot: offsetFromRoot(options.appProjectRoot),
rootTsConfigPath: getRelativePathToRootTsConfig(
host,
options.appProjectRoot
),
});
if (options.unitTestRunner === 'none') {
host.delete(join(options.appProjectRoot, `/src/app/App.spec.tsx`));
Expand Down
13 changes: 9 additions & 4 deletions packages/react-native/src/generators/library/library.ts
Expand Up @@ -19,7 +19,10 @@ import { addLinting } from '../../utils/add-linting';
import { addJest } from '../../utils/add-jest';
import { NormalizedSchema, normalizeOptions } from './lib/normalize-options';
import { Schema } from './schema';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import {
getRelativePathToRootTsConfig,
getRootTsConfigPathInTree,
} from '@nrwl/workspace/src/utilities/typescript';

export async function reactNativeLibraryGenerator(
host: Tree,
Expand Down Expand Up @@ -156,7 +159,6 @@ function updateBaseTsConfig(host: Tree, options: NormalizedSchema) {
}

function createFiles(host: Tree, options: NormalizedSchema) {
const rootOffset = offsetFromRoot(options.projectRoot);
generateFiles(
host,
joinPathFragments(__dirname, './files/lib'),
Expand All @@ -165,8 +167,11 @@ function createFiles(host: Tree, options: NormalizedSchema) {
...options,
...names(options.name),
tmpl: '',
offsetFromRoot: rootOffset,
rootTsConfigPath: rootOffset + getRootTsConfigPathInTree(host),
offsetFromRoot: offsetFromRoot(options.projectRoot),
rootTsConfigPath: getRelativePathToRootTsConfig(
host,
options.projectRoot
),
}
);

Expand Down
Expand Up @@ -9,7 +9,7 @@ import {
updateJson,
} from '@nrwl/devkit';
import { join } from 'path';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';

function updateTsConfig(host: Tree, options: NormalizedSchema) {
updateJson(
Expand Down Expand Up @@ -47,13 +47,15 @@ export function createApplicationFiles(host: Tree, options: NormalizedSchema) {
styleSolutionSpecificAppFiles = '../files/css-module';
}

const rootOffset = offsetFromRoot(options.appProjectRoot);
const templateVariables = {
...names(options.name),
...options,
tmpl: '',
offsetFromRoot: rootOffset,
rootTsConfigPath: rootOffset + getRootTsConfigPathInTree(host),
offsetFromRoot: offsetFromRoot(options.appProjectRoot),
rootTsConfigPath: getRelativePathToRootTsConfig(
host,
options.appProjectRoot
),
};

generateFiles(
Expand Down

0 comments on commit 1da8cab

Please sign in to comment.