Skip to content

Commit

Permalink
fix(nx-plugin): executors that spread async generators should work lo…
Browse files Browse the repository at this point in the history
…cally (#9956)
  • Loading branch information
AgentEnder committed Apr 28, 2022
1 parent 2ff9ad7 commit c3d30a4
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 119 deletions.
20 changes: 20 additions & 0 deletions e2e/nx-plugin/src/nx-plugin.fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const ASYNC_GENERATOR_EXECUTOR_CONTENTS = `import { ExecutorContext } from '@nrwl/devkit';
async function* asyncGenerator(
) {
for (let i = 5; i < 10; i++) {
yield new Promise((res) => setTimeout(() => res({ success: true }), 5));
}
yield { success: true };
}
export default async function* execute(
options: unknown,
context: ExecutorContext
) {
for (let i = 5; i < 10; i++) {
yield new Promise((res) => setTimeout(() => res({ success: true }), 5));
}
yield* asyncGenerator();
}
`;
24 changes: 23 additions & 1 deletion e2e/nx-plugin/src/nx-plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ProjectConfiguration } from '@nrwl/devkit';
import {
checkFilesExist,
expectTestsPass,
Expand All @@ -15,6 +16,8 @@ import {
removeFile,
} from '@nrwl/e2e/utils';

import { ASYNC_GENERATOR_EXECUTOR_CONTENTS } from './nx-plugin.fixtures';

describe('Nx Plugin', () => {
let npmScope: string;
beforeEach(() => {
Expand Down Expand Up @@ -237,17 +240,36 @@ describe('Nx Plugin', () => {

it('should be able to use local generators and executors', async () => {
const generator = uniq('generator');
const executor = uniq('executor');
const generatedProject = uniq('project');

runCLI(
`generate @nrwl/nx-plugin:generator ${generator} --project=${plugin}`
);

runCLI(
`generate @nrwl/nx-plugin:executor ${executor} --project=${plugin}`
);

updateFile(
`libs/${plugin}/src/executors/${executor}/executor.ts`,
ASYNC_GENERATOR_EXECUTOR_CONTENTS
);

runCLI(
`generate @${npmScope}/${plugin}:${generator} --name ${generatedProject}`
);

updateFile(`libs/${generatedProject}/project.json`, (f) => {
const project: ProjectConfiguration = JSON.parse(f);
project.targets['execute'] = {
executor: `@${npmScope}/${plugin}:${executor}`,
};
return JSON.stringify(project, null, 2);
});

expect(() => checkFilesExist(`libs/${generatedProject}`)).not.toThrow();
expect(() => runCLI(`build ${generatedProject}`)).not.toThrow();
expect(() => runCLI(`execute ${generatedProject}`)).not.toThrow();
});
});

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"@storybook/react": "~6.4.12",
"@svgr/webpack": "^6.1.2",
"@swc-node/register": "^1.4.2",
"@swc/core": "^1.2.152",
"@swc/core": "^1.2.173",
"@swc/jest": "^0.2.20",
"@testing-library/react": "13.1.1",
"@tippyjs/react": "^4.2.6",
Expand Down Expand Up @@ -271,6 +271,7 @@
"@tailwindcss/forms": "^0.4.0",
"@tailwindcss/typography": "^0.5.0",
"classnames": "^2.3.1",
"cliui": "^7.0.2",
"core-js": "^3.6.5",
"enquirer": "~2.3.6",
"fast-glob": "3.2.7",
Expand All @@ -294,11 +295,10 @@
"rehype-slug": "^4.0.1",
"remark-gfm": "^1.0.0",
"send": "0.17.1",
"string-width": "^4.2.3",
"tailwindcss": "^3.0.13",
"tslib": "^2.3.0",
"weak-napi": "^2.0.2",
"cliui": "^7.0.2",
"string-width": "^4.2.3"
"weak-napi": "^2.0.2"
},
"resolutions": {
"ng-packagr/rxjs": "6.6.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"homepage": "https://nx.dev",
"dependencies": {
"@swc/core": "^1.2.152",
"@swc/core": "^1.2.173",
"@swc-node/register": "^1.4.2",
"fast-glob": "3.2.7",
"jsonc-parser": "3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/utils/nx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function readTsConfigPaths(root: string = workspaceRoot) {
const { compilerOptions } = readJsonFile(tsconfigPath);
tsconfigPaths = compilerOptions?.paths;
}
return tsconfigPaths;
return tsconfigPaths ?? {};
}

function readPluginMainFromProjectConfiguration(
Expand Down

1 comment on commit c3d30a4

@vercel
Copy link

@vercel vercel bot commented on c3d30a4 Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx.dev
nx-five.vercel.app
nx-dev-nrwl.vercel.app

Please sign in to comment.