diff --git a/docs/generated/packages/nx-plugin/executors/e2e.json b/docs/generated/packages/nx-plugin/executors/e2e.json index 4edf67f6d562dd..89242348217120 100644 --- a/docs/generated/packages/nx-plugin/executors/e2e.json +++ b/docs/generated/packages/nx-plugin/executors/e2e.json @@ -117,7 +117,8 @@ "runInBand": { "alias": "i", "description": "Run all tests serially in the current process (rather than creating a worker pool of child processes that run tests). This is sometimes useful for debugging, but such use cases are pretty rare. Useful for CI. (https://jestjs.io/docs/cli#--runinband)", - "type": "boolean" + "type": "boolean", + "default": true }, "showConfig": { "description": "Print your Jest config and then exits. (https://jestjs.io/docs/en/cli#--showconfig)", diff --git a/docs/generated/packages/nx-plugin/generators/create-package.json b/docs/generated/packages/nx-plugin/generators/create-package.json index 720abcaa8a2bf3..bd20a069a297aa 100644 --- a/docs/generated/packages/nx-plugin/generators/create-package.json +++ b/docs/generated/packages/nx-plugin/generators/create-package.json @@ -50,27 +50,12 @@ "default": false, "x-priority": "internal" }, - "skipTsConfig": { - "type": "boolean", - "default": false, - "description": "Do not update tsconfig.json for development experience.", - "x-priority": "internal" - }, - "setParserOptionsProject": { - "type": "boolean", - "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.", - "default": false - }, "compiler": { "type": "string", "enum": ["tsc", "swc"], "default": "tsc", "description": "The compiler used by the build and test targets." }, - "importPath": { - "type": "string", - "description": "How the plugin will be published, like `create-framework-app`. Note this must be a valid NPM name. Will use name if not provided." - }, "e2eTestRunner": { "type": "string", "enum": ["jest", "none"], diff --git a/docs/generated/packages/nx-plugin/generators/executor.json b/docs/generated/packages/nx-plugin/generators/executor.json index bf88b95a5ab945..65b68e9538d002 100644 --- a/docs/generated/packages/nx-plugin/generators/executor.json +++ b/docs/generated/packages/nx-plugin/generators/executor.json @@ -49,6 +49,12 @@ "type": "boolean", "default": false, "description": "Do not add an eslint configuration for plugin json files." + }, + "skipFormat": { + "type": "boolean", + "description": "Skip formatting files.", + "default": false, + "x-priority": "internal" } }, "required": ["project", "name"], diff --git a/e2e/workspace-create/src/create-nx-plugin.test.ts b/e2e/workspace-create/src/create-nx-plugin.test.ts index ab825957c285e1..6d5a40e9728424 100644 --- a/e2e/workspace-create/src/create-nx-plugin.test.ts +++ b/e2e/workspace-create/src/create-nx-plugin.test.ts @@ -21,7 +21,6 @@ describe('create-nx-plugin', () => { runCreatePlugin(pluginName, { packageManager, - extraArgs: `--createPackageName=create-${wsName}-package`, }); checkFilesExist( @@ -46,14 +45,25 @@ describe('create-nx-plugin', () => { checkFilesExist( `dist/package.json`, `dist/generators.json`, - `dist/executors.json`, - `dist/src/index.js` + `dist/executors.json` ); + }); + + it('should be able to create a repo with create workspace cli', () => { + const pluginName = uniq('plugin'); + + runCreatePlugin(pluginName, { + packageManager, + extraArgs: `--createPackageName=create-${pluginName}-package`, + }); + + runCLI(`build ${pluginName}`); + checkFilesExist(`dist/package.json`, `dist/generators.json`); runCLI(`build create-${pluginName}-package`); checkFilesExist(`dist/create-${pluginName}-package/bin/index.js`); expect(() => runCLI(`e2e e2e`)).not.toThrow(); - expect(() => runCLI(`e2e create-${wsName}-package-e2e`)).not.toThrow(); + expect(() => runCLI(`e2e create-${pluginName}-package-e2e`)).not.toThrow(); }); }); diff --git a/packages/create-nx-plugin/bin/create-nx-plugin.ts b/packages/create-nx-plugin/bin/create-nx-plugin.ts index 5dc3121b6c1ae3..4638b8ab98c4b3 100644 --- a/packages/create-nx-plugin/bin/create-nx-plugin.ts +++ b/packages/create-nx-plugin/bin/create-nx-plugin.ts @@ -47,7 +47,7 @@ async function determinePluginName( parsedArgs: CreateNxPluginArguments ): Promise { if (parsedArgs.pluginName) { - return Promise.resolve(parsedArgs.pluginName); + return parsedArgs.pluginName; } const results = await enquirer.prompt<{ pluginName: string }>([ @@ -55,16 +55,9 @@ async function determinePluginName( name: 'pluginName', message: `Plugin name `, type: 'input', - validate: (s_1) => (s_1.length ? true : 'Name cannot be empty'), + validate: (s_1) => (s_1.length ? true : 'Plugin name cannot be empty'), }, ]); - if (!results.pluginName) { - output.error({ - title: 'Invalid name', - bodyLines: [`Name cannot be empty`], - }); - process.exit(1); - } return results.pluginName; } @@ -72,13 +65,13 @@ async function determineCreatePackageName( parsedArgs: CreateNxPluginArguments ): Promise { if (parsedArgs.createPackageName) { - return Promise.resolve(parsedArgs.createPackageName); + return parsedArgs.createPackageName; } const results = await enquirer.prompt<{ createPackageName: string }>([ { name: 'createPackageName', - message: `Create package name (optional) `, + message: `Create a package which can be used by npx to create a new workspace (Leave blank to not create this package)`, type: 'input', }, ]); diff --git a/packages/nx-plugin/src/executors/e2e/e2e.impl.ts b/packages/nx-plugin/src/executors/e2e/e2e.impl.ts index d3f2c82eb699fe..75678f9f00b7c6 100644 --- a/packages/nx-plugin/src/executors/e2e/e2e.impl.ts +++ b/packages/nx-plugin/src/executors/e2e/e2e.impl.ts @@ -59,7 +59,7 @@ async function runTests( context: ExecutorContext ): Promise { const { success } = await jestExecutor( - { runInBand: true, ...jestOptions, watch: false }, + { ...jestOptions, watch: false }, context ); diff --git a/packages/nx-plugin/src/executors/e2e/schema.json b/packages/nx-plugin/src/executors/e2e/schema.json index 78581cc6723e9d..d830e71d9d1a07 100644 --- a/packages/nx-plugin/src/executors/e2e/schema.json +++ b/packages/nx-plugin/src/executors/e2e/schema.json @@ -128,7 +128,8 @@ "runInBand": { "alias": "i", "description": "Run all tests serially in the current process (rather than creating a worker pool of child processes that run tests). This is sometimes useful for debugging, but such use cases are pretty rare. Useful for CI. (https://jestjs.io/docs/cli#--runinband)", - "type": "boolean" + "type": "boolean", + "default": true }, "showConfig": { "description": "Print your Jest config and then exits. (https://jestjs.io/docs/en/cli#--showconfig)", diff --git a/packages/nx-plugin/src/generators/create-package/create-package.spec.ts b/packages/nx-plugin/src/generators/create-package/create-package.spec.ts index 5e51ddda15ed1c..0b8a1f36c61754 100644 --- a/packages/nx-plugin/src/generators/create-package/create-package.spec.ts +++ b/packages/nx-plugin/src/generators/create-package/create-package.spec.ts @@ -3,9 +3,10 @@ import { readJson, readProjectConfiguration, Tree, -} from '@nrwl/devkit'; -import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { Linter } from '@nrwl/linter'; +} from '@nx/devkit'; +import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; +import { Linter } from '@nx/linter'; +import { PackageJson } from 'nx/src/utils/package-json'; import pluginGenerator from '../plugin/plugin'; import { createPackageGenerator } from './create-package'; import { CreatePackageSchema } from './schema'; @@ -13,7 +14,7 @@ import { CreatePackageSchema } from './schema'; const getSchema: ( overrides?: Partial ) => CreatePackageSchema = (overrides = {}) => ({ - name: 'create-package', + name: 'create-a-workspace', project: 'my-plugin', compiler: 'tsc', skipTsConfig: false, @@ -21,7 +22,6 @@ const getSchema: ( skipLintChecks: false, linter: Linter.EsLint, unitTestRunner: 'jest', - minimal: true, ...overrides, }); @@ -43,20 +43,19 @@ describe('NxPlugin Create Package Generator', () => { it('should update the project.json file', async () => { await createPackageGenerator(tree, getSchema()); - const project = readProjectConfiguration(tree, 'create-package'); - expect(project.root).toEqual('libs/create-package'); - expect(project.sourceRoot).toEqual('libs/create-package/bin'); + const project = readProjectConfiguration(tree, 'create-a-workspace'); + expect(project.root).toEqual('libs/create-a-workspace'); + expect(project.sourceRoot).toEqual('libs/create-a-workspace/bin'); expect(project.targets.build).toEqual({ - executor: '@nrwl/js:tsc', + executor: '@nx/js:tsc', outputs: ['{options.outputPath}'], options: { - outputPath: 'dist/libs/create-package', - tsConfig: 'libs/create-package/tsconfig.lib.json', - main: 'libs/create-package/bin/index.ts', - assets: [], - buildableProjectDepsInPackageJsonType: 'dependencies', + outputPath: 'dist/libs/create-a-workspace', + tsConfig: 'libs/create-a-workspace/tsconfig.lib.json', + main: 'libs/create-a-workspace/bin/index.ts', + assets: ['libs/create-a-workspace/*.md'], + updateBuildableProjectDepsInPackageJson: false, }, - dependsOn: ['^build'], }); }); @@ -67,8 +66,11 @@ describe('NxPlugin Create Package Generator', () => { directory: 'plugins', } as Partial) ); - const project = readProjectConfiguration(tree, 'plugins-create-package'); - expect(project.root).toEqual('libs/plugins/create-package'); + const project = readProjectConfiguration( + tree, + 'plugins-create-a-workspace' + ); + expect(project.root).toEqual('libs/plugins/create-a-workspace'); }); it('should specify tsc as compiler', async () => { @@ -79,9 +81,12 @@ describe('NxPlugin Create Package Generator', () => { }) ); - const { build } = readProjectConfiguration(tree, 'create-package').targets; + const { build } = readProjectConfiguration( + tree, + 'create-a-workspace' + ).targets; - expect(build.executor).toEqual('@nrwl/js:tsc'); + expect(build.executor).toEqual('@nx/js:tsc'); }); it('should specify swc as compiler', async () => { @@ -92,35 +97,23 @@ describe('NxPlugin Create Package Generator', () => { }) ); - const { build } = readProjectConfiguration(tree, 'create-package').targets; + const { build } = readProjectConfiguration( + tree, + 'create-a-workspace' + ).targets; - expect(build.executor).toEqual('@nrwl/js:swc'); + expect(build.executor).toEqual('@nx/js:swc'); }); it("should use name as default for the package.json's name", async () => { await createPackageGenerator(tree, getSchema()); - const { root } = readProjectConfiguration(tree, 'create-package'); - const { name } = readJson<{ name: string }>( - tree, - joinPathFragments(root, 'package.json') - ); - - expect(name).toEqual('create-package'); - }); - - it('should use importPath as the package.json name', async () => { - await createPackageGenerator( - tree, - getSchema({ importPath: '@my-company/create-package' }) - ); - - const { root } = readProjectConfiguration(tree, 'create-package'); - const { name } = readJson<{ name: string }>( + const { root } = readProjectConfiguration(tree, 'create-a-workspace'); + const { name } = readJson( tree, joinPathFragments(root, 'package.json') ); - expect(name).toEqual('@my-company/create-package'); + expect(name).toEqual('create-a-workspace'); }); }); diff --git a/packages/nx-plugin/src/generators/create-package/create-package.ts b/packages/nx-plugin/src/generators/create-package/create-package.ts index 16023e4f245b01..0163b4e0c757dd 100644 --- a/packages/nx-plugin/src/generators/create-package/create-package.ts +++ b/packages/nx-plugin/src/generators/create-package/create-package.ts @@ -10,14 +10,15 @@ import { updateJson, GeneratorCallback, runTasksInSerial, -} from '@nrwl/devkit'; -import { libraryGenerator as jsLibraryGenerator } from '@nrwl/js'; -import { join } from 'path'; -import { nxVersion } from '../../utils/versions'; + joinPathFragments, +} from '@nx/devkit'; +import { libraryGenerator as jsLibraryGenerator } from '@nx/js'; +import { nxVersion } from 'nx/src/utils/versions'; import generatorGenerator from '../generator/generator'; import { CreatePackageSchema } from './schema'; import { NormalizedSchema, normalizeSchema } from './utils/normalize-schema'; import e2eProjectGenerator from '../e2e-project/e2e'; +import { hasGenerator } from '../../utils/has-generator'; export async function createPackageGenerator( host: Tree, @@ -26,10 +27,7 @@ export async function createPackageGenerator( const tasks: GeneratorCallback[] = []; const options = normalizeSchema(host, schema); - const pluginPackageName = await addPresetGenerator(host, { - ...options, - skipFormat: true, - }); + const pluginPackageName = await addPresetGenerator(host, options); const installTask = addDependenciesToPackageJson( host, @@ -42,7 +40,7 @@ export async function createPackageGenerator( await createCliPackage(host, options, pluginPackageName); if (options.e2eTestRunner !== 'none') { - tasks.push(await addE2eProject(host, options, pluginPackageName)); + tasks.push(await addE2eProject(host, options)); } if (!options.skipFormat) { @@ -63,15 +61,16 @@ async function addPresetGenerator( schema: NormalizedSchema ): Promise { const { root: projectRoot } = readProjectConfiguration(host, schema.project); - if (!host.exists(`${projectRoot}/src/generators/preset`)) { + if (!hasGenerator(host, schema.project, 'preset')) { await generatorGenerator(host, { name: 'preset', project: schema.project, unitTestRunner: schema.unitTestRunner, + skipFormat: true, }); } - return readJson(host, join(projectRoot, 'package.json'))?.name; + return readJson(host, joinPathFragments(projectRoot, 'package.json'))?.name; } async function createCliPackage( @@ -85,43 +84,50 @@ async function createCliPackage( config: 'project', publishable: true, bundler: options.bundler, - importPath: options.importPath, + importPath: options.name, + skipFormat: true, skipTsConfig: true, }); - host.delete(join(options.projectRoot, 'src')); + host.delete(joinPathFragments(options.projectRoot, 'src')); // Add the bin entry to the package.json - updateJson(host, join(options.projectRoot, 'package.json'), (packageJson) => { - packageJson.bin = { - [options.name]: './bin/index.js', - }; - packageJson.dependencies = { - 'create-nx-workspace': nxVersion, - }; - return packageJson; - }); + updateJson( + host, + joinPathFragments(options.projectRoot, 'package.json'), + (packageJson) => { + packageJson.bin = { + [options.name]: './bin/index.js', + }; + packageJson.dependencies = { + 'create-nx-workspace': nxVersion, + }; + return packageJson; + } + ); // update project build target to use the bin entry const projectConfiguration = readProjectConfiguration( host, options.projectName ); - projectConfiguration.sourceRoot = join(options.projectRoot, 'bin'); - projectConfiguration.targets.build.options.main = join( + projectConfiguration.sourceRoot = joinPathFragments( + options.projectRoot, + 'bin' + ); + projectConfiguration.targets.build.options.main = joinPathFragments( options.projectRoot, 'bin/index.ts' ); - projectConfiguration.targets.build.options.buildableProjectDepsInPackageJsonType = - 'dependencies'; - projectConfiguration.targets.build.dependsOn = ['^build']; + projectConfiguration.targets.build.options.updateBuildableProjectDepsInPackageJson = + false; projectConfiguration.implicitDependencies = [options.project]; updateProjectConfiguration(host, options.projectName, projectConfiguration); // Add bin files to tsconfg.lib.json updateJson( host, - join(options.projectRoot, 'tsconfig.lib.json'), + joinPathFragments(options.projectRoot, 'tsconfig.lib.json'), (tsConfig) => { tsConfig.include.push('bin/**/*.ts'); return tsConfig; @@ -130,7 +136,7 @@ async function createCliPackage( generateFiles( host, - join(__dirname, './files/create-framework-package'), + joinPathFragments(__dirname, './files/create-framework-package'), options.projectRoot, { ...options, @@ -146,11 +152,7 @@ async function createCliPackage( * @param options * @returns */ -async function addE2eProject( - host: Tree, - options: NormalizedSchema, - pluginPackageName: string -) { +async function addE2eProject(host: Tree, options: NormalizedSchema) { const pluginProjectConfiguration = readProjectConfiguration( host, options.project @@ -170,7 +172,6 @@ async function addE2eProject( projectDirectory: options.projectDirectory, pluginOutputPath, npmPackageName: options.name, - minimal: false, skipFormat: true, rootProject: false, }); @@ -191,11 +192,10 @@ async function addE2eProject( generateFiles( host, - join(__dirname, './files/e2e'), + joinPathFragments(__dirname, './files/e2e'), e2eProjectConfiguration.sourceRoot, { ...options, - pluginPackageName, pluginOutputPath, cliOutputPath, tmpl: '', diff --git a/packages/nx-plugin/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ b/packages/nx-plugin/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ index 6d03412ec1bc6d..e76aec671a10d4 100644 --- a/packages/nx-plugin/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ +++ b/packages/nx-plugin/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ @@ -8,8 +8,10 @@ async function main() { throw new Error('Please provide a name for the workspace'); } + console.log(`Creating the workspace: ${name}`); + // TODO: update below to customize the workspace - await createWorkspace('<%= preset %>', { + const { directory } = await createWorkspace('<%= preset %>', { name, nxCloud: false, packageManager: 'npm', @@ -18,7 +20,7 @@ async function main() { presetVersion: require('../package.json').version, }); - console.log(`Successfully created the workspace: ${name}.`); + console.log(`Successfully created the workspace: ${directory}.`); } main(); \ No newline at end of file diff --git a/packages/nx-plugin/src/generators/create-package/files/e2e/__name__.spec.ts__tmpl__ b/packages/nx-plugin/src/generators/create-package/files/e2e/__name__.spec.ts__tmpl__ index fe6751532999b4..e0e0f6adda52e8 100644 --- a/packages/nx-plugin/src/generators/create-package/files/e2e/__name__.spec.ts__tmpl__ +++ b/packages/nx-plugin/src/generators/create-package/files/e2e/__name__.spec.ts__tmpl__ @@ -2,7 +2,7 @@ import { uniq, runCreatePackageCli, removeTmpProject, -} from '@nrwl/nx-plugin/testing'; +} from '@nx/nx-plugin/testing'; describe('<%= name %> e2e', () => { const project = uniq('<%= name %>'); @@ -11,10 +11,11 @@ describe('<%= name %> e2e', () => { beforeAll(async () => { // Create project using CLI command createPackageResult = await runCreatePackageCli( - '<%= pluginPackageName %>', - '<%= pluginOutputPath %>', - '<%= cliOutputPath %>', - project + project, + { + pluginLibraryBuildPath: '<%= pluginOutputPath %>', + createPackageLibraryBuildPath: '<%= cliOutputPath %>', + } ); }, 240_000); diff --git a/packages/nx-plugin/src/generators/create-package/schema.d.ts b/packages/nx-plugin/src/generators/create-package/schema.d.ts index 10cfc1e9041865..6acf4c1f775f92 100644 --- a/packages/nx-plugin/src/generators/create-package/schema.d.ts +++ b/packages/nx-plugin/src/generators/create-package/schema.d.ts @@ -1,4 +1,4 @@ -import type { Linter } from '@nrwl/linter'; +import type { Linter } from '@nx/linter'; export interface CreatePackageSchema { name: string; @@ -6,14 +6,11 @@ export interface CreatePackageSchema { // options to create cli package, passed to js library generator directory?: string; - skipTsConfig: boolean; skipFormat: boolean; tags?: string; unitTestRunner: 'jest' | 'none'; linter: Linter; - setParserOptionsProject?: boolean; compiler: 'swc' | 'tsc'; - importPath?: string; // options to create e2e project, passed to e2e project generator e2eTestRunner?: 'jest' | 'none'; diff --git a/packages/nx-plugin/src/generators/create-package/schema.json b/packages/nx-plugin/src/generators/create-package/schema.json index 682ea3459c436f..38927754193545 100644 --- a/packages/nx-plugin/src/generators/create-package/schema.json +++ b/packages/nx-plugin/src/generators/create-package/schema.json @@ -52,27 +52,12 @@ "default": false, "x-priority": "internal" }, - "skipTsConfig": { - "type": "boolean", - "default": false, - "description": "Do not update tsconfig.json for development experience.", - "x-priority": "internal" - }, - "setParserOptionsProject": { - "type": "boolean", - "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.", - "default": false - }, "compiler": { "type": "string", "enum": ["tsc", "swc"], "default": "tsc", "description": "The compiler used by the build and test targets." }, - "importPath": { - "type": "string", - "description": "How the plugin will be published, like `create-framework-app`. Note this must be a valid NPM name. Will use name if not provided." - }, "e2eTestRunner": { "type": "string", "enum": ["jest", "none"], diff --git a/packages/nx-plugin/src/generators/create-package/utils/normalize-schema.ts b/packages/nx-plugin/src/generators/create-package/utils/normalize-schema.ts index 67f4febc150243..cb85d7f0f8d10e 100644 --- a/packages/nx-plugin/src/generators/create-package/utils/normalize-schema.ts +++ b/packages/nx-plugin/src/generators/create-package/utils/normalize-schema.ts @@ -4,7 +4,7 @@ import { joinPathFragments, names, Tree, -} from '@nrwl/devkit'; +} from '@nx/devkit'; import { CreatePackageSchema } from '../schema'; export interface NormalizedSchema extends CreatePackageSchema { @@ -30,7 +30,6 @@ export function normalizeSchema( : name; const projectName = fullProjectDirectory.replace(new RegExp('/', 'g'), '-'); const projectRoot = joinPathFragments(libsDir, fullProjectDirectory); - const importPath = schema.importPath ?? name; return { ...schema, bundler: schema.compiler ?? 'tsc', @@ -39,6 +38,5 @@ export function normalizeSchema( projectRoot, name, projectDirectory: fullProjectDirectory, - importPath, }; } diff --git a/packages/nx-plugin/src/generators/e2e-project/files/tests/__pluginName__.spec.ts__tmpl__ b/packages/nx-plugin/src/generators/e2e-project/files/tests/__pluginName__.spec.ts__tmpl__ index cd101be7877143..8f5570f4e07ff4 100644 --- a/packages/nx-plugin/src/generators/e2e-project/files/tests/__pluginName__.spec.ts__tmpl__ +++ b/packages/nx-plugin/src/generators/e2e-project/files/tests/__pluginName__.spec.ts__tmpl__ @@ -32,6 +32,6 @@ describe('<%= pluginName %> e2e', () => { const generator = 'PLACEHOLDER'; await runNxCommandAsync(`generate <%= npmPackageName %>:${generator} --name ${name}`); expect(() => runNxCommand('build ${proj}')).not.toThrow(); - expect(() => checkFilesExist([`dist/${name}/index.js`])).not.toThrow(); + expect(() => checkFilesExist(`dist/${name}/index.js`)).not.toThrow(); }); }); diff --git a/packages/nx-plugin/src/generators/executor/executor.ts b/packages/nx-plugin/src/generators/executor/executor.ts index f24c6ece4b61cc..d461931b3ac2ab 100644 --- a/packages/nx-plugin/src/generators/executor/executor.ts +++ b/packages/nx-plugin/src/generators/executor/executor.ts @@ -9,6 +9,7 @@ import { writeJson, readJson, ExecutorsJson, + formatFiles, } from '@nx/devkit'; import type { Tree } from '@nx/devkit'; import type { Schema } from './schema'; @@ -176,6 +177,10 @@ export async function executorGenerator(host: Tree, schema: Schema) { } await updateExecutorJson(host, options); + + if (!schema.skipFormat) { + await formatFiles(host); + } } export default executorGenerator; diff --git a/packages/nx-plugin/src/generators/executor/schema.d.ts b/packages/nx-plugin/src/generators/executor/schema.d.ts index 6946c85d5bbba4..4e896a3f909f60 100644 --- a/packages/nx-plugin/src/generators/executor/schema.d.ts +++ b/packages/nx-plugin/src/generators/executor/schema.d.ts @@ -5,4 +5,5 @@ export interface Schema { unitTestRunner: 'jest' | 'none'; includeHasher: boolean; skipLintChecks?: boolean; + skipFormat?: boolean; } diff --git a/packages/nx-plugin/src/generators/executor/schema.json b/packages/nx-plugin/src/generators/executor/schema.json index e7d3f1b9467a28..4337938fa6654f 100644 --- a/packages/nx-plugin/src/generators/executor/schema.json +++ b/packages/nx-plugin/src/generators/executor/schema.json @@ -51,6 +51,12 @@ "type": "boolean", "default": false, "description": "Do not add an eslint configuration for plugin json files." + }, + "skipFormat": { + "type": "boolean", + "description": "Skip formatting files.", + "default": false, + "x-priority": "internal" } }, "required": ["project", "name"], diff --git a/packages/nx-plugin/src/generators/generator/generator.ts b/packages/nx-plugin/src/generators/generator/generator.ts index a54670b6d17941..23936b80dd9d1e 100644 --- a/packages/nx-plugin/src/generators/generator/generator.ts +++ b/packages/nx-plugin/src/generators/generator/generator.ts @@ -4,8 +4,6 @@ import { joinPathFragments, Tree, writeJson, -} from '@nx/devkit'; -import { convertNxGenerator, generateFiles, getWorkspaceLayout, diff --git a/packages/nx-plugin/src/generators/plugin/plugin.spec.ts b/packages/nx-plugin/src/generators/plugin/plugin.spec.ts index 6abb31d39c3928..92f9a67866d0a3 100644 --- a/packages/nx-plugin/src/generators/plugin/plugin.spec.ts +++ b/packages/nx-plugin/src/generators/plugin/plugin.spec.ts @@ -7,6 +7,7 @@ import { } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { Linter } from '@nx/linter'; +import { PackageJson } from 'nx/src/utils/package-json'; import { pluginGenerator } from './plugin'; import { Schema } from './schema'; @@ -161,7 +162,7 @@ describe('NxPlugin Plugin Generator', () => { await pluginGenerator(tree, getSchema()); const { root } = readProjectConfiguration(tree, 'my-plugin'); - const { name } = readJson<{ name: string }>( + const { name } = readJson( tree, joinPathFragments(root, 'package.json') ); @@ -178,7 +179,7 @@ describe('NxPlugin Plugin Generator', () => { await pluginGenerator(tree, getSchema()); const { root } = readProjectConfiguration(tree, 'my-plugin'); - const { name } = readJson<{ name: string }>( + const { name } = readJson( tree, joinPathFragments(root, 'package.json') ); @@ -193,7 +194,7 @@ describe('NxPlugin Plugin Generator', () => { ); const { root } = readProjectConfiguration(tree, 'my-plugin'); - const { name } = readJson<{ name: string }>( + const { name } = readJson( tree, joinPathFragments(root, 'package.json') ); diff --git a/packages/nx-plugin/src/generators/plugin/plugin.ts b/packages/nx-plugin/src/generators/plugin/plugin.ts index 318f9835acc756..765ee97fd0e7af 100644 --- a/packages/nx-plugin/src/generators/plugin/plugin.ts +++ b/packages/nx-plugin/src/generators/plugin/plugin.ts @@ -88,7 +88,7 @@ export async function pluginGenerator(host: Tree, schema: Schema) { ); tasks.push(addTsLibDependencies(host)); - + tasks.push( addDependenciesToPackageJson( host, diff --git a/packages/nx-plugin/src/generators/plugin/schema.d.ts b/packages/nx-plugin/src/generators/plugin/schema.d.ts index 5de5ce4613354e..294249c817f5b1 100644 --- a/packages/nx-plugin/src/generators/plugin/schema.d.ts +++ b/packages/nx-plugin/src/generators/plugin/schema.d.ts @@ -4,9 +4,9 @@ export interface Schema { name: string; directory?: string; importPath?: string; - skipTsConfig: boolean; - skipFormat: boolean; - skipLintChecks: boolean; + skipTsConfig?: boolean; // default is false + skipFormat?: boolean; // default is false + skipLintChecks?: boolean; // default is false e2eTestRunner?: 'jest' | 'none'; tags?: string; unitTestRunner: 'jest' | 'none'; diff --git a/packages/nx-plugin/src/generators/preset/generator.ts b/packages/nx-plugin/src/generators/preset/generator.ts index db52f95d30e77b..533cc9c86cc28f 100644 --- a/packages/nx-plugin/src/generators/preset/generator.ts +++ b/packages/nx-plugin/src/generators/preset/generator.ts @@ -22,8 +22,6 @@ export default async function (tree: Tree, options: PresetGeneratorSchema) { ? options.pluginName.split('/')[1] : options.pluginName, skipFormat: true, - skipLintChecks: false, - skipTsConfig: false, unitTestRunner: 'jest', importPath: options.pluginName, rootProject: true, @@ -39,10 +37,8 @@ export default async function (tree: Tree, options: PresetGeneratorSchema) { name: options.createPackageName, project: options.pluginName, skipFormat: true, - skipTsConfig: false, unitTestRunner: 'jest', linter: Linter.EsLint, - setParserOptionsProject: false, compiler: 'tsc', }); tasks.push(cliTask); diff --git a/packages/nx-plugin/src/utils/testing-utils/create-package-cli.ts b/packages/nx-plugin/src/utils/testing-utils/create-package-cli.ts index 4efff9a20b0b1a..b983fe590f68b1 100644 --- a/packages/nx-plugin/src/utils/testing-utils/create-package-cli.ts +++ b/packages/nx-plugin/src/utils/testing-utils/create-package-cli.ts @@ -1,4 +1,4 @@ -import { names, workspaceRoot } from '@nrwl/devkit'; +import { workspaceRoot } from '@nx/devkit'; import { tmpFolder } from './paths'; import { fork } from 'child_process'; @@ -6,30 +6,38 @@ import { fork } from 'child_process'; * This function is used to run the create package CLI command. * It builds the plugin library and the create package library and run the create package command with for the plugin library. * It needs to be ran inside an Nx project. It would assume that an Nx project already exists. - * @param pluginLibraryName e.g. my-plugin + * @param projectToBeCreated project name to be created using the cli * @param pluginLibraryBuildPath e.g. dist/packages/my-plugin * @param createPackageLibraryBuildPath e.g. dist/packages/create-my-plugin-package - * @param projectToBeCreated project name to be created using the cli + * @param extraArguments extra arguments to be passed to the create package command + * @param verbose if true, NX_VERBOSE_LOGGING will be set to true * @returns results for the create package command */ export function runCreatePackageCli( - pluginLibraryName: string, - pluginLibraryBuildPath: string, - createPackageLibraryBuildPath: string, - projectToBeCreated: string + projectToBeCreated: string, + { + pluginLibraryBuildPath, + createPackageLibraryBuildPath, + extraArguments, + verbose, + }: { + pluginLibraryBuildPath: string; + createPackageLibraryBuildPath: string; + extraArguments?: string[]; + verbose?: boolean; + } ): Promise { return new Promise((resolve, reject) => { const childProcess = fork( `${workspaceRoot}/${createPackageLibraryBuildPath}/bin/index.js`, - [projectToBeCreated, '--verbose'], + [projectToBeCreated, ...(extraArguments || [])], { stdio: ['pipe', 'pipe', 'pipe', 'ipc'], env: { ...process.env, - [`NX_E2E_${ - names(pluginLibraryName).constantName - }_VERSION`]: `file:${workspaceRoot}/${pluginLibraryBuildPath}`, - NX_VERBOSE_LOGGING: 'true', + [`NX_E2E_PRESET_VERSION`]: `file:${workspaceRoot}/${pluginLibraryBuildPath}`, + // only add NX_VERBOSE_LOGGING if verbose is true + ...(verbose && { NX_VERBOSE_LOGGING: 'true' }), }, cwd: tmpFolder(), } diff --git a/packages/nx-plugin/src/utils/testing-utils/nx-project.ts b/packages/nx-plugin/src/utils/testing-utils/nx-project.ts index 9e589002977889..706d7289b86283 100644 --- a/packages/nx-plugin/src/utils/testing-utils/nx-project.ts +++ b/packages/nx-plugin/src/utils/testing-utils/nx-project.ts @@ -8,7 +8,7 @@ import { execSync } from 'child_process'; import { dirname } from 'path'; import { ensureDirSync } from 'fs-extra'; import { tmpProjPath } from './paths'; -import { cleanup, directoryExists } from './utils'; +import { cleanup } from './utils'; function runNxNewCommand(args?: string, silent?: boolean) { const localTmpDir = dirname(tmpProjPath()); diff --git a/packages/nx-plugin/src/utils/testing-utils/paths.ts b/packages/nx-plugin/src/utils/testing-utils/paths.ts index 8defb9e6e0b3e5..0cd239f9ac53a4 100644 --- a/packages/nx-plugin/src/utils/testing-utils/paths.ts +++ b/packages/nx-plugin/src/utils/testing-utils/paths.ts @@ -1,5 +1,7 @@ +import { workspaceRoot } from '@nx/devkit'; + export function tmpFolder() { - return `${process.cwd()}/tmp`; + return `${workspaceRoot}/tmp`; } /** @@ -22,6 +24,6 @@ export function tmpProjPath(path?: string) { */ export function tmpBackupProjPath(path?: string) { return path - ? `${process.cwd()}/tmp/nx-e2e/proj-backup/${path}` - : `${process.cwd()}/tmp/nx-e2e/proj-backup`; + ? `${workspaceRoot}/tmp/nx-e2e/proj-backup/${path}` + : `${workspaceRoot}/tmp/nx-e2e/proj-backup`; } diff --git a/packages/workspace/src/generators/new/generate-preset.ts b/packages/workspace/src/generators/new/generate-preset.ts index 6ea3b6752260ae..83e6670c15ed3b 100644 --- a/packages/workspace/src/generators/new/generate-preset.ts +++ b/packages/workspace/src/generators/new/generate-preset.ts @@ -2,7 +2,6 @@ import { addDependenciesToPackageJson, getPackageManagerCommand, Tree, - names, } from '@nx/devkit'; import { Preset } from '../utils/presets'; import { @@ -150,14 +149,12 @@ function getPresetDependencies({ return { dependencies: {}, dev: { '@nx/node': nxVersion } }; default: { - presetVersion = - process.env?.[`NX_E2E_${names(preset).constantName}_VERSION`] ?? // read from env variable for e2e testing - presetVersion ?? - getNpmPackageVersion(preset); return { dev: {}, dependencies: { - [preset]: presetVersion, + [preset]: + process.env['NX_E2E_PRESET_VERSION'] ?? + getNpmPackageVersion(preset, presetVersion), }, }; } diff --git a/packages/workspace/src/generators/new/new.ts b/packages/workspace/src/generators/new/new.ts index 006245e161e526..bb9e7b13978264 100644 --- a/packages/workspace/src/generators/new/new.ts +++ b/packages/workspace/src/generators/new/new.ts @@ -30,7 +30,6 @@ interface Schema { standaloneApi?: boolean; routing?: boolean; packageManager?: PackageManager; - presetVersion?: string; } export interface NormalizedSchema extends Schema {