Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(nx-plugin): port compiler option into nx-plugin generator (#9299)
  • Loading branch information
AgentEnder committed Mar 11, 2022
1 parent b122417 commit 208d5c0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 10 deletions.
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

1 comment on commit 208d5c0

@vercel
Copy link

@vercel vercel bot commented on 208d5c0 Mar 11, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.