Skip to content

Commit 7b0f96b

Browse files
authoredApr 26, 2023
feat(nx-plugin): simplify generated plugin code (#16590)
1 parent 010ddee commit 7b0f96b

File tree

13 files changed

+24
-29
lines changed

13 files changed

+24
-29
lines changed
 

‎docs/generated/packages/plugin/generators/create-package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"name": {
1313
"type": "string",
1414
"description": "The package name of cli, e.g. `create-framework-package`. Note this must be a valid NPM name to be published.",
15+
"pattern": "create-.+|^@.+/create(?:-.+)?",
1516
"$default": { "$source": "argv", "index": 0 },
1617
"x-priority": "important"
1718
},

‎e2e/workspace-create/src/create-nx-plugin.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,5 @@ describe('create-nx-plugin', () => {
7171
checkFilesExist(`dist/create-${pluginName}-package/bin/index.js`);
7272

7373
expect(() => runCLI(`e2e e2e`)).not.toThrow();
74-
expect(() => runCLI(`e2e create-${pluginName}-package-e2e`)).not.toThrow();
7574
});
7675
});

‎packages/create-nx-plugin/bin/create-nx-plugin.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ async function main(parsedArgs: yargs.Arguments<CreateNxPluginArguments>) {
133133
],
134134
});
135135

136-
const workspaceInfo = await createWorkspace('@nx/plugin', populatedArguments);
136+
const workspaceInfo = await createWorkspace(
137+
`@nx/plugin@${nxVersion}`,
138+
populatedArguments
139+
);
137140

138141
showNxWarning(parsedArgs.pluginName);
139142

‎packages/create-nx-workspace/bin/create-nx-workspace.ts

+4
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
165165

166166
if (isKnownPreset(parsedArgs.preset)) {
167167
pointToTutorialAndCourse(parsedArgs.preset as Preset);
168+
} else {
169+
output.log({
170+
title: `Successfully applied preset: ${parsedArgs.preset}`,
171+
});
168172
}
169173
}
170174

‎packages/create-nx-workspace/src/create-workspace-options.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export interface CreateWorkspaceOptions {
55
name: string; // Workspace name (e.g. org name)
66
packageManager: PackageManager; // Package manager to use
77
nxCloud: boolean; // Enable Nx Cloud
8-
presetVersion?: string; // Version of the preset to use
98
/**
109
* @description Enable interactive mode with presets
1110
* @default true

‎packages/create-nx-workspace/src/create-workspace.ts

-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import { createSandbox } from './create-sandbox';
55
import { createEmptyWorkspace } from './create-empty-workspace';
66
import { createPreset } from './create-preset';
77
import { setupCI } from './utils/ci/setup-ci';
8-
import { messages, recordStat } from './utils/nx/ab-testing';
98
import { initializeGitRepo } from './utils/git/git';
10-
import { nxVersion } from './utils/nx/nx-version';
119
import { getThirdPartyPreset } from './utils/preset/get-third-party-preset';
1210
import { mapErrorToBodyLines } from './utils/error-utils';
1311

‎packages/js/src/generators/library/library.spec.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -957,11 +957,8 @@ describe('lib', () => {
957957

958958
const config = readProjectConfiguration(tree, 'my-lib');
959959
expect(config.targets.publish).toEqual({
960-
executor: 'nx:run-commands',
961-
options: {
962-
command:
963-
'node tools/scripts/publish.mjs my-lib {args.ver} {args.tag}',
964-
},
960+
command:
961+
'node tools/scripts/publish.mjs my-lib {args.ver} {args.tag}',
965962
dependsOn: ['build'],
966963
});
967964
});

‎packages/js/src/generators/library/library.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,7 @@ function addProject(
197197
const publishScriptPath = addMinimalPublishScript(tree);
198198

199199
projectConfiguration.targets.publish = {
200-
executor: 'nx:run-commands',
201-
options: {
202-
command: `node ${publishScriptPath} ${options.name} {args.ver} {args.tag}`,
203-
},
200+
command: `node ${publishScriptPath} ${options.name} {args.ver} {args.tag}`,
204201
dependsOn: ['build'],
205202
};
206203
}

‎packages/plugin/src/generators/create-package/create-package.ts

-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ export async function createPackageGenerator(
3939
tasks.push(installTask);
4040

4141
await createCliPackage(host, options, pluginPackageName);
42-
if (options.e2eTestRunner !== 'none') {
43-
tasks.push(await addE2eProject(host, options));
44-
}
4542

4643
if (!options.skipFormat) {
4744
await formatFiles(host);

‎packages/plugin/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ async function main() {
1010

1111
console.log(`Creating the workspace: ${name}`);
1212

13+
// This assumes "<%= preset %>" and "<%= projectName %>" are at the same version
14+
// eslint-disable-next-line @typescript-eslint/no-var-requires
15+
const presetVersion = require('../package.json').version,
16+
1317
// TODO: update below to customize the workspace
14-
const { directory } = await createWorkspace('<%= preset %>', {
15-
name,
18+
const { directory } = await createWorkspace(`<%= preset %>@${presetVersion}`, {
19+
name,
1620
nxCloud: false,
1721
packageManager: 'npm',
18-
// This assumes "<%= preset %>" and "<%= projectName %>" are at the same version
19-
// eslint-disable-next-line @typescript-eslint/no-var-requires
20-
presetVersion: require('../package.json').version,
2122
});
2223

2324
console.log(`Successfully created the workspace: ${directory}.`);
2425
}
2526

26-
main();
27+
main();

‎packages/plugin/src/generators/create-package/files/e2e/__name__.spec.ts__tmpl__

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import {
2-
uniq,
32
runCreatePackageCli,
43
removeTmpProject,
54
} from '@nx/plugin/testing';
65

76
describe('<%= name %> e2e', () => {
8-
const project = uniq('<%= name %>');
7+
const project = '<%= name %>';
98
let createPackageResult;
109

1110
beforeAll(async () => {

‎packages/plugin/src/generators/create-package/schema.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"name": {
1010
"type": "string",
1111
"description": "The package name of cli, e.g. `create-framework-package`. Note this must be a valid NPM name to be published.",
12+
"pattern": "create-.+|^@.+/create(?:-.+)?",
1213
"$default": {
1314
"$source": "argv",
1415
"index": 0

‎packages/plugin/src/generators/e2e-project/files/tests/__pluginName__.spec.ts__tmpl__

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
readJson,
55
runNxCommandAsync,
66
runNxCommand,
7-
uniq,
87
} from '@nx/plugin/testing';
98

109
describe('<%= pluginName %> e2e', () => {
@@ -18,17 +17,17 @@ describe('<%= pluginName %> e2e', () => {
1817
ensureNxProject('<%= npmPackageName %>', '<%= pluginOutputPath %>');
1918
});
2019

21-
afterAll(() => {
20+
afterAll(async () => {
2221
// `nx reset` kills the daemon, and performs
2322
// some work which can help clean up e2e leftovers
24-
runNxCommandAsync('reset');
23+
await runNxCommandAsync('reset');
2524
});
2625

2726

2827
// Add some tests here to check that your plugin functionality works as expected.
2928
// A sample test is included below to give you some ideas.
3029
xit('should be able to build generated projects', async () => {
31-
const name = uniq('proj');
30+
const name = 'proj';
3231
const generator = 'PLACEHOLDER';
3332
await runNxCommandAsync(`generate <%= npmPackageName %>:${generator} --name ${name}`);
3433
expect(() => runNxCommand('build ${proj}')).not.toThrow();

1 commit comments

Comments
 (1)

vercel[bot] commented on Apr 26, 2023

@vercel[bot]

Successfully deployed to the following URLs:

nx-dev – ./

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

Please sign in to comment.