Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import {
readJson,
stripIndents,
addProjectConfiguration,
readWorkspaceConfiguration,
updateJson,
logger,
updateProjectConfiguration,
serializeJson,
names,
visitNotIgnoredFiles,
writeJson,
WorkspaceConfiguration,
ProjectConfiguration,
joinPathFragments,
readNxJson,
NxJsonConfiguration,
} from '@nx/devkit';

import { PackageJson, TsConfig } from '../../types';
Expand Down Expand Up @@ -387,7 +387,7 @@ describe('migrate-converged-pkg generator', () => {
});

it(`should not add 3rd party packages that use same scope as our repo `, async () => {
const workspaceConfig = readWorkspaceConfiguration(tree);
const workspaceConfig = assertAndReadNxJson(tree);
const normalizedPkgName = getNormalizedPkgName({ pkgName: options.name, workspaceConfig });
const thirdPartyPackageName = '@proj/jango-fet';

Expand Down Expand Up @@ -502,7 +502,7 @@ describe('migrate-converged-pkg generator', () => {

describe(`storybook updates`, () => {
function setup(config: Partial<{ createDummyStories: boolean }> = {}) {
const workspaceConfig = readWorkspaceConfiguration(tree);
const workspaceConfig = assertAndReadNxJson(tree);
const projectConfig = readProjectConfiguration(tree, options.name);
const normalizedProjectName = options.name.replace(`@${workspaceConfig.npmScope}/`, '');
const projectStorybookConfigPath = `${projectConfig.root}/.storybook`;
Expand Down Expand Up @@ -1479,7 +1479,7 @@ describe('migrate-converged-pkg generator', () => {
// ==== helpers ====

function getScopedPkgName(tree: Tree, pkgName: string) {
const workspaceConfig = readWorkspaceConfiguration(tree);
const workspaceConfig = assertAndReadNxJson(tree);

return `@${workspaceConfig.npmScope}/${pkgName}`;
}
Expand All @@ -1495,7 +1495,7 @@ function setupDummyPackage(
projectConfiguration: Partial<ReadProjectConfiguration>;
}>,
) {
const workspaceConfig = readWorkspaceConfiguration(tree);
const workspaceConfig = assertAndReadNxJson(tree);
const defaults = {
version: '9.0.0-alpha.40',
dependencies: {
Expand Down Expand Up @@ -1632,7 +1632,7 @@ function append(tree: Tree, filePath: string, content: string) {
return tree;
}

function getNormalizedPkgName(options: { pkgName: string; workspaceConfig: WorkspaceConfiguration }) {
function getNormalizedPkgName(options: { pkgName: string; workspaceConfig: NxJsonConfiguration }) {
return options.pkgName.replace(`@${options.workspaceConfig.npmScope}/`, '');
}

Expand All @@ -1644,3 +1644,13 @@ function getNormalizedPkgName(options: { pkgName: string; workspaceConfig: Works
function getFixture(src: string) {
return fs.readFileSync(path.join(__dirname, '__fixtures__', src), 'utf-8');
}

function assertAndReadNxJson(tree: Tree) {
const nxJson = readNxJson(tree);

if (!nxJson) {
throw new Error('nx.json doesnt exist');
}

return nxJson;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import {
Tree,
readProjectConfiguration,
readWorkspaceConfiguration,
serializeJson,
addProjectConfiguration,
readJson,
readNxJson,
} from '@nx/devkit';

import generator from './index';
Expand Down Expand Up @@ -200,7 +200,7 @@ function setupDummyPackage(
projectConfiguration: Partial<ReturnType<typeof readProjectConfiguration>>;
}>,
) {
const workspaceConfig = readWorkspaceConfiguration(tree);
const workspaceConfig = assertAndReadNxJson(tree);
const defaults = {
version: '9.0.0-alpha.40',
dependencies: {
Expand Down Expand Up @@ -240,3 +240,13 @@ function setupDummyPackage(

return tree;
}

function assertAndReadNxJson(tree: Tree) {
const nxJson = readNxJson(tree);

if (!nxJson) {
throw new Error('nx.json doesnt exist');
}

return nxJson;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import {
Tree,
readProjectConfiguration,
readWorkspaceConfiguration,
stripIndents,
addProjectConfiguration,
serializeJson,
WorkspaceConfiguration,
parseJson,
getProjects,
joinPathFragments,
ProjectConfiguration,
readJson,
updateJson,
NxJsonConfiguration,
readNxJson,
} from '@nx/devkit';

import generator from './index';
Expand Down Expand Up @@ -273,7 +272,7 @@ function setupDummyPackage(
projectConfiguration: Partial<ReadProjectConfiguration>;
}>,
) {
const workspaceConfig = readWorkspaceConfiguration(tree);
const workspaceConfig = assertAndReadNxJson(tree);
const defaults = {
version: '9.0.0-alpha.40',
dependencies: {
Expand Down Expand Up @@ -386,6 +385,16 @@ function setupDummyPackage(
return tree;
}

function getNormalizedPkgName(options: { pkgName: string; workspaceConfig: WorkspaceConfiguration }) {
function getNormalizedPkgName(options: { pkgName: string; workspaceConfig: NxJsonConfiguration }) {
return options.pkgName.replace(`@${options.workspaceConfig.npmScope}/`, '');
}

function assertAndReadNxJson(tree: Tree) {
const nxJson = readNxJson(tree);

if (!nxJson) {
throw new Error('nx.json doesnt exist');
}

return nxJson;
}
16 changes: 13 additions & 3 deletions tools/workspace-plugin/src/generators/rc-caret/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import {
Tree,
readProjectConfiguration,
readWorkspaceConfiguration,
serializeJson,
addProjectConfiguration,
readJson,
readNxJson,
} from '@nx/devkit';

import generator from './index';
Expand All @@ -24,7 +24,7 @@ describe('rc-caret generator', () => {
jest.spyOn(console, 'warn').mockImplementation(noop);

tree = createTreeWithEmptyWorkspace();
npmScope = readWorkspaceConfiguration(tree).npmScope ?? '@proj';
npmScope = assertAndReadNxJson(tree).npmScope ?? '@proj';
});

it('should work for dependencies', async () => {
Expand Down Expand Up @@ -131,7 +131,7 @@ function setupDummyPackage(
projectConfiguration: Partial<ReturnType<typeof readProjectConfiguration>>;
}>,
) {
const workspaceConfig = readWorkspaceConfiguration(tree);
const workspaceConfig = assertAndReadNxJson(tree);
const defaults = {
name: `@${workspaceConfig.npmScope}/react-components`,
version: '9.0.0-alpha.40',
Expand Down Expand Up @@ -171,3 +171,13 @@ function setupDummyPackage(

return tree;
}

function assertAndReadNxJson(tree: Tree) {
const nxJson = readNxJson(tree);

if (!nxJson) {
throw new Error('nx.json doesnt exist');
}

return nxJson;
}
14 changes: 12 additions & 2 deletions tools/workspace-plugin/src/generators/recipe-generator/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tree, formatFiles, generateFiles, readWorkspaceConfiguration, joinPathFragments } from '@nx/devkit';
import { Tree, formatFiles, generateFiles, joinPathFragments, readNxJson } from '@nx/devkit';
import { RecipeGeneratorGeneratorSchema } from './schema';
import { getProjectConfig } from '../../utils';

Expand All @@ -13,7 +13,7 @@ export default async function (tree: Tree, schema: RecipeGeneratorGeneratorSchem
}

function normalizeOptions(tree: Tree, schema: RecipeGeneratorGeneratorSchema) {
const workspaceConfig = readWorkspaceConfiguration(tree);
const workspaceConfig = assertAndReadNxJson(tree);
const recipesProject = getProjectConfig(tree, {
packageName: `@${workspaceConfig.npmScope}/recipes-react-components`,
});
Expand Down Expand Up @@ -46,3 +46,13 @@ function validateSchema(tree: Tree, schema: RecipeGeneratorGeneratorSchema) {

return newSchema;
}

function assertAndReadNxJson(tree: Tree) {
const nxJson = readNxJson(tree);

if (!nxJson) {
throw new Error('nx.json doesnt exist');
}

return nxJson;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import {
Tree,
readProjectConfiguration,
readWorkspaceConfiguration,
serializeJson,
addProjectConfiguration,
readJson,
readNxJson,
} from '@nx/devkit';

import generator from './index';
Expand Down Expand Up @@ -308,7 +308,7 @@ function setupDummyPackage(
beachball: PackageJsonWithBeachball['beachball'];
}>,
) {
const workspaceConfig = readWorkspaceConfiguration(tree);
const workspaceConfig = assertAndReadNxJson(tree);
const defaults = {
version: '9.0.0-alpha.40',
dependencies: {
Expand Down Expand Up @@ -349,3 +349,13 @@ function setupDummyPackage(

return tree;
}

function assertAndReadNxJson(tree: Tree) {
const nxJson = readNxJson(tree);

if (!nxJson) {
throw new Error('nx.json doesnt exist');
}

return nxJson;
}