Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nx-plugin): port compiler option into nx-plugin generator #9299

Merged
merged 1 commit into from Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/generated/api-nx-plugin/generators/plugin.md
Expand Up @@ -43,6 +43,16 @@ Type: `string`

Plugin name

### compiler

Default: `tsc`

Type: `string`

Possible values: `tsc`, `swc`

The compiler used by the build and test targets

### directory

Alias(es): d
Expand Down
68 changes: 58 additions & 10 deletions packages/nx-plugin/src/generators/plugin/plugin.spec.ts
@@ -1,6 +1,20 @@
import { pluginGenerator } from './plugin';
import { Tree, readProjectConfiguration } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { Schema } from './schema';
import { Linter } from '@nrwl/linter';

const getSchema: (overrides?: Partial<Schema>) => Schema = (
overrides = {}
) => ({
name: 'my-plugin',
compiler: 'tsc',
skipTsConfig: false,
skipFormat: false,
linter: Linter.EsLint,
unitTestRunner: 'jest',
...overrides,
});

describe('NxPlugin Plugin Generator', () => {
let tree: Tree;
Expand All @@ -10,7 +24,7 @@ describe('NxPlugin Plugin Generator', () => {
});

it('should update the workspace.json file', async () => {
await pluginGenerator(tree, { name: 'myPlugin' } as any);
await pluginGenerator(tree, getSchema());
const project = readProjectConfiguration(tree, 'my-plugin');
expect(project.root).toEqual('libs/my-plugin');
expect(project.targets.build).toEqual({
Expand Down Expand Up @@ -63,18 +77,21 @@ describe('NxPlugin Plugin Generator', () => {
});

it('should place the plugin in a directory', async () => {
await pluginGenerator(tree, {
name: 'myPlugin',
directory: 'plugins',
} as any);
await pluginGenerator(
tree,
getSchema({
name: 'myPlugin',
directory: 'plugins',
})
);
const project = readProjectConfiguration(tree, 'plugins-my-plugin');
const projectE2e = readProjectConfiguration(tree, 'plugins-my-plugin-e2e');
expect(project.root).toEqual('libs/plugins/my-plugin');
expect(projectE2e.root).toEqual('apps/plugins/my-plugin-e2e');
});

it('should create schematic and builder files', async () => {
await pluginGenerator(tree, { name: 'myPlugin' } as any);
await pluginGenerator(tree, getSchema({ name: 'myPlugin' }));

[
'libs/my-plugin/project.json',
Expand Down Expand Up @@ -103,10 +120,13 @@ describe('NxPlugin Plugin Generator', () => {
describe('--unitTestRunner', () => {
describe('none', () => {
it('should not generate test files', async () => {
await pluginGenerator(tree, {
name: 'myPlugin',
unitTestRunner: 'none',
} as any);
await pluginGenerator(
tree,
getSchema({
name: 'myPlugin',
unitTestRunner: 'none',
})
);

[
'libs/my-plugin/src/generators/my-plugin/generator.ts',
Expand All @@ -120,4 +140,32 @@ describe('NxPlugin Plugin Generator', () => {
});
});
});

describe('--compiler', () => {
it('should specify tsc as compiler', async () => {
await pluginGenerator(
tree,
getSchema({
compiler: 'tsc',
})
);

const { build } = readProjectConfiguration(tree, 'my-plugin').targets;

expect(build.executor).toEqual('@nrwl/js:tsc');
});

it('should specify swc as compiler', async () => {
await pluginGenerator(
tree,
getSchema({
compiler: 'swc',
})
);

const { build } = readProjectConfiguration(tree, 'my-plugin').targets;

expect(build.executor).toEqual('@nrwl/js:swc');
});
});
});
1 change: 1 addition & 0 deletions packages/nx-plugin/src/generators/plugin/schema.d.ts
Expand Up @@ -11,4 +11,5 @@ export interface Schema {
linter: Linter;
standaloneConfig?: boolean;
setParserOptionsProject?: boolean;
compiler: 'swc' | 'tsc';
}
6 changes: 6 additions & 0 deletions packages/nx-plugin/src/generators/plugin/schema.json
Expand Up @@ -64,6 +64,12 @@
"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"
}
},
"required": ["name"],
Expand Down