Skip to content

Commit

Permalink
feat(misc): update pr with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Apr 19, 2023
1 parent ac95251 commit 68d5ad0
Show file tree
Hide file tree
Showing 28 changed files with 148 additions and 173 deletions.
3 changes: 2 additions & 1 deletion docs/generated/packages/jest/executors/jest.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,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)",
Expand Down
15 changes: 0 additions & 15 deletions docs/generated/packages/nx-plugin/generators/create-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/nx-plugin/generators/executor.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 2 additions & 2 deletions e2e/workspace-create/src/create-nx-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('create-nx-plugin', () => {

runCreatePlugin(pluginName, {
packageManager,
extraArgs: `--createPackageName=create-${wsName}-package`,
extraArgs: `--createPackageName=create-${pluginName}-package`,
});

checkFilesExist(
Expand Down Expand Up @@ -54,6 +54,6 @@ describe('create-nx-plugin', () => {
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();
});
});
15 changes: 4 additions & 11 deletions packages/create-nx-plugin/bin/create-nx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,31 @@ async function determinePluginName(
parsedArgs: CreateNxPluginArguments
): Promise<string> {
if (parsedArgs.pluginName) {
return Promise.resolve(parsedArgs.pluginName);
return parsedArgs.pluginName;
}

const results = await enquirer.prompt<{ pluginName: string }>([
{
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;
}

async function determineCreatePackageName(
parsedArgs: CreateNxPluginArguments
): Promise<string> {
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',
},
]);
Expand Down
3 changes: 2 additions & 1 deletion packages/jest/src/executors/jest/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,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)",
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-plugin/src/executors/e2e/e2e.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function runTests(
context: ExecutorContext
): Promise<boolean> {
const { success } = await jestExecutor(
{ runInBand: true, ...jestOptions, watch: false },
{ ...jestOptions, watch: false },
context
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ 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';

const getSchema: (
overrides?: Partial<CreatePackageSchema>
) => CreatePackageSchema = (overrides = {}) => ({
name: 'create-package',
name: 'create-a-workspace',
project: 'my-plugin',
compiler: 'tsc',
skipTsConfig: false,
skipFormat: false,
skipLintChecks: false,
linter: Linter.EsLint,
unitTestRunner: 'jest',
minimal: true,
...overrides,
});

Expand All @@ -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'],
});
});

Expand All @@ -67,8 +66,11 @@ describe('NxPlugin Create Package Generator', () => {
directory: 'plugins',
} as Partial<CreatePackageSchema>)
);
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 () => {
Expand All @@ -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 () => {
Expand All @@ -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<PackageJson>(
tree,
joinPathFragments(root, 'package.json')
);

expect(name).toEqual('@my-company/create-package');
expect(name).toEqual('create-a-workspace');
});
});
Loading

0 comments on commit 68d5ad0

Please sign in to comment.