Skip to content

Commit

Permalink
fix(core): import-projects generator shouldn't fail
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Oct 24, 2022
1 parent b5e5ef1 commit 8c2188d
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 82 deletions.
27 changes: 23 additions & 4 deletions e2e/core-e2e/tests/nx-dotnet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,19 @@ describe('nx-dotnet e2e', () => {
});
});

describe('nx g import-projects', () => {
fdescribe('nx g import-projects', () => {
it('should import apps, libs, and test', async () => {
updateFile(
'.nx-dotnet.rc.json',
JSON.stringify(
{
nugetPackages: {},
inferProjects: false,
},
null,
2,
),
);
const testApp = uniq('app');
const testLib = uniq('lib');
const testAppTest = `${testApp}-test`;
Expand All @@ -272,9 +283,6 @@ describe('nx-dotnet e2e', () => {

const workspace = new Workspaces(e2eDir).readWorkspaceConfiguration();

console.log({ testApp, testLib, testAppTest });
console.log(workspace.projects);

expect(workspace.projects[testApp].targets?.serve).toBeDefined();
expect(workspace.projects[testApp].targets?.build).toBeDefined();
expect(workspace.projects[testApp].targets?.lint).toBeDefined();
Expand All @@ -287,6 +295,17 @@ describe('nx-dotnet e2e', () => {

await runNxCommandAsync(`build ${testApp}`);
checkFilesExist(`dist/apps/${testApp}`);

updateFile(
'.nx-dotnet.rc.json',
JSON.stringify(
{
nugetPackages: {},
},
null,
2,
),
);
});
});

Expand Down
1 change: 0 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"namedInputs": {
"default": ["{projectRoot}/**/*", "sharedGlobals", "projectSpecificFiles"],
"sharedGlobals": [
"{workspaceRoot}/workspace.json",
"{workspaceRoot}/tsconfig.base.json",
"{workspaceRoot}/tslint.json",
"{workspaceRoot}/nx.json",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/generators/app/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
},
"standalone": {
"type": "boolean",
"description": "Should the project use project.json? If false, the project config is inside workspace.json"
"description": "Should the project use project.json? If false, the project config is inside workspace.json",
"x-deprecated": "New Nx workspaces are created without workspace.json, thus inferring this option as true."
},
"solutionFile": {
"description": "Determines if the project should be added to a solution file.",
Expand Down
30 changes: 15 additions & 15 deletions packages/core/src/generators/import-projects/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ jest.mock('../init/generator', () => ({
}));

describe('import-projects generator', () => {
let appTree: Tree;
let tree: Tree;
let dotnetClient: DotNetClient;

beforeEach(() => {
appTree = createTreeWithEmptyWorkspace();
tree = createTreeWithEmptyWorkspace();
dotnetClient = new DotNetClient(mockDotnetFactory());
});

Expand All @@ -57,10 +57,10 @@ describe('import-projects generator', () => {

it('should run successfully if no new projects are found', async () => {
jest.spyOn(utils, 'glob').mockResolvedValue([]);
const promise = generator(appTree, dotnetClient);
const oldProjects = getProjects(appTree);
const promise = generator(tree, null, dotnetClient);
const oldProjects = getProjects(tree);
await expect(promise).resolves.not.toThrow();
const newProjects = getProjects(appTree);
const newProjects = getProjects(tree);
expect(oldProjects).toEqual(newProjects);
});

Expand All @@ -81,10 +81,10 @@ describe('import-projects generator', () => {
);
jest.spyOn(fs, 'readFileSync').mockReturnValue(MOCK_TEST_PROJECT);
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => null);
appTree.write('apps/my-api/my-api.csproj', MOCK_API_PROJECT);
const promise = generator(appTree, dotnetClient);
tree.write('apps/my-api/my-api.csproj', MOCK_API_PROJECT);
const promise = generator(tree, null, dotnetClient);
await expect(promise).resolves.not.toThrow();
expect(readProjectConfiguration(appTree, 'my-test-api')).toBeDefined();
expect(readProjectConfiguration(tree, 'my-test-api')).toBeDefined();
});

it('should run add test target if test projects are found', async () => {
Expand All @@ -104,15 +104,15 @@ describe('import-projects generator', () => {
);
jest.spyOn(fs, 'readFileSync').mockReturnValue(MOCK_TEST_PROJECT);
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => null);
appTree.write('apps/my-api-test/my-api-test.csproj', MOCK_TEST_PROJECT);
const promise = generator(appTree, dotnetClient);
tree.write('apps/my-api-test/my-api-test.csproj', MOCK_TEST_PROJECT);
const promise = generator(tree, null, dotnetClient);
await expect(promise).resolves.not.toThrow();
expect(readProjectConfiguration(appTree, 'my-test-api-test')).toBeDefined();
expect(readProjectConfiguration(tree, 'my-test-api-test')).toBeDefined();
expect(
readProjectConfiguration(appTree, 'my-test-api-test').targets?.test,
readProjectConfiguration(tree, 'my-test-api-test').targets?.test,
).toBeDefined();
expect(
readProjectConfiguration(appTree, 'my-test-api-test').targets?.serve,
readProjectConfiguration(tree, 'my-test-api-test').targets?.serve,
).not.toBeDefined();
});

Expand All @@ -122,7 +122,7 @@ describe('import-projects generator', () => {
).initGenerator;

jest.spyOn(utils, 'glob').mockResolvedValue([]);
await generator(appTree, dotnetClient);
expect(initGenerator).toHaveBeenCalledWith(appTree, null, dotnetClient);
await generator(tree, null, dotnetClient);
expect(initGenerator).toHaveBeenCalledWith(tree, null, dotnetClient);
});
});
1 change: 1 addition & 0 deletions packages/core/src/generators/import-projects/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { initGenerator } from '../init/generator';

export default async function (
host: Tree,
options: null, // The second option is provided at runtime by Nx for options passed in to the generator.
dotnetClient = new DotNetClient(dotnetFactory()),
) {
const installTask = await initGenerator(host, null, dotnetClient);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/generators/lib/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
},
"standalone": {
"type": "boolean",
"description": "Should the project use project.json? If false, the project config is inside workspace.json"
"description": "Should the project use project.json? If false, the project config is inside workspace.json",
"x-deprecated": "New Nx workspaces are created without workspace.json, thus inferring this option as true."
},
"solutionFile": {
"description": "Determines if the project should be added to a solution file.",
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/generators/nuget-reference/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jest.mock('../../../../utils/src/lib/utility-functions/workspace');
jest.mock('inquirer');

describe('nuget-reference generator', () => {
let appTree: Tree;
let tree: Tree;

const options: NugetReferenceGeneratorSchema = {
packageName: 'test',
Expand All @@ -27,16 +27,16 @@ describe('nuget-reference generator', () => {
let dotnetClient: DotNetClient;

beforeEach(() => {
appTree = createTreeWithEmptyWorkspace();
appTree.write(
tree = createTreeWithEmptyWorkspace();
tree.write(
'workspace.json',
JSON.stringify({
projects: {
test: {},
},
}),
);
appTree.write(
tree.write(
'nx.json',
JSON.stringify({
projects: {
Expand All @@ -47,7 +47,7 @@ describe('nuget-reference generator', () => {
}),
);

updateConfig(appTree, { nugetPackages: {} });
updateConfig(tree, { nugetPackages: {} });
(prompt as jest.MockedFunction<typeof prompt>)
.mockReset()
.mockImplementation((async () => {
Expand All @@ -58,13 +58,13 @@ describe('nuget-reference generator', () => {
});

it('runs calls dotnet add package reference', async () => {
await generator(appTree, options, dotnetClient);
await generator(tree, options, dotnetClient);
const mock = dotnetClient as jest.Mocked<DotNetClient>;
expect(mock.addPackageReference).toHaveBeenCalledTimes(1);
});

it('only prompts user once on version mismatch / miss', async () => {
await generator(appTree, options, dotnetClient);
await generator(tree, options, dotnetClient);
expect(prompt).toHaveBeenCalledTimes(1);
});

Expand All @@ -77,10 +77,10 @@ describe('nuget-reference generator', () => {
.mockReset()
.mockResolvedValue(projectFilePath);

updateConfig(appTree, {
updateConfig(tree, {
nugetPackages: { [options.packageName]: '1.2.3' },
});
await generator(appTree, options, dotnetClient);
await generator(tree, options, dotnetClient);
const mock = dotnetClient as jest.Mocked<DotNetClient>;
expect(mock.addPackageReference).toHaveBeenCalledWith(
projectFilePath,
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/generators/sync/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export default async function (host: Tree) {
false,
pkg,
);
// console.log('Resolved:', resolved)
config.nugetPackages[pkg] = resolved;
if (resolved !== ALLOW_MISMATCH) {
updateDependencyVersions(host, pkg, resolved);
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/generators/test/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe('nx-dotnet test generator', () => {

await generator(appTree, options, dotnetClient);
expect(projectGenerator).toHaveBeenCalled();
console.log(projectGenerator.mock.calls[0][1]);
expect(projectGenerator.mock.calls[0][1].projectType).toEqual(
'application',
);
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/generators/test/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export default async function (
const directory = projectPaths.slice(1, -1).join('/'); // The middle portions contain the original path.
const [name] = projectPaths.slice(-1); // The final folder contains the original name.

console.log(project);

const projectGeneratorOptions: NxDotnetProjectGeneratorSchema = {
...options,
testProjectNameSuffix: options.suffix,
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/generators/test/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
},
"standalone": {
"type": "boolean",
"description": "Should the project use project.json? If false, the project config is inside workspace.json"
"description": "Should the project use project.json? If false, the project config is inside workspace.json",
"x-deprecated": "New Nx workspaces are created without workspace.json, thus inferring this option as true."
},
"solutionFile": {
"description": "Determines if the project should be added to a solution file.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ describe('nx-dotnet test project generator', () => {
it('should set outputs for build target', async () => {
await GenerateTestProject(appTree, options, dotnetClient);
const config = readProjectConfiguration(appTree, testProjectName);
console.log(config.targets?.build.options);
const outputPath = config.targets?.build.outputs?.[0];
expect(outputPath).toEqual(
'{workspaceRoot}/dist/apps/domain/existing-app-test',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/graph/process-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function visitProject(
projectFile = getProjectFileForNxProjectSync(project);
} catch (e) {
if (process.env['NX_VERBOSE_LOGGING'] === 'true') {
console.log(e);
console.error(e);
}
}
if (projectFile !== null) {
Expand Down
1 change: 0 additions & 1 deletion packages/dotnet/src/lib/core/dotnet.client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ ASP.NET Core gRPC Service grpc [C#]

const client = new DotNetClient(dotnetFactory());
const results = client.listInstalledTemplates({ search: 'asp' });
console.log(results);
for (const result of results) {
expect(result.templateName).toMatch(/^asp.*/i);
}
Expand Down
21 changes: 3 additions & 18 deletions packages/nx-ghpages/src/executors/deploy/executor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { logger } from '@nrwl/devkit';
import { logger, workspaceRoot } from '@nrwl/devkit';

import { exec as execCallback } from 'child_process';
import { stat } from 'fs';
import { dirname, join } from 'path';
import { join } from 'path';
import { promisify } from 'util';

import { BuildExecutorSchema } from './schema';
Expand All @@ -16,7 +16,7 @@ async function exists(path: string) {
}

export default async function deployExecutor(options: BuildExecutorSchema) {
const directory = join(await findWorkspaceRoot(), options.directory);
const directory = join(workspaceRoot, options.directory);

if (!(await exists(directory))) {
logger.error(`Output directory does not exist! ${directory}`);
Expand Down Expand Up @@ -65,22 +65,7 @@ export default async function deployExecutor(options: BuildExecutorSchema) {
});
logger.info('Pushing to GH Pages -- COMPLETE');

console.log('After exec statements');

return {
success: true,
};
}

async function findWorkspaceRoot(dir: string = process.cwd()): Promise<string> {
if (dirname(dir) === dir) {
throw new Error(`The cwd isn't part of an Nx workspace`);
}
if (
(await exists(join(dir, 'angular.json'))) ||
(await exists(join(dir, 'workspace.json')))
) {
return dir;
}
return findWorkspaceRoot(dirname(dir));
}
2 changes: 0 additions & 2 deletions packages/utils/src/lib/utility-functions/childprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export async function handleChildProcessPassthrough(
let resolver: () => void;

const exitHandler = async () => {
console.log('Exit Handler Called');

if (childProcess) {
childProcess.kill('SIGINT');
childProcess.kill('SIGINT');
Expand Down
1 change: 0 additions & 1 deletion tools/scripts/patch-package-versions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export function PatchPackageVersions(
: projectConfiguration.targets?.build.options?.outputPath;
const pkgPath = p ? `${p}/package.json` : null;
if (!pkgPath || !existsSync(pkgPath)) {
console.log('pkgPath not found:', pkgPath);
return;
}
const pkg = readJson(pkgPath);
Expand Down
21 changes: 0 additions & 21 deletions tools/utils/get-affected.ts

This file was deleted.

1 change: 0 additions & 1 deletion tools/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './get-affected';
export * from './nx';
export * from './fs';

0 comments on commit 8c2188d

Please sign in to comment.