Skip to content

Commit 8a7a53e

Browse files
committed
fixup! fixup! feat(workspace-plugin): implement inferred plugins for clean,format,type-check targets
1 parent aef8d5d commit 8a7a53e

6 files changed

+42
-11
lines changed

tools/workspace-plugin/src/plugins/clean-plugin.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe(`clean-plugin`, () => {
3939
});
4040

4141
it('should create nodes', async () => {
42-
const results = await createNodesFunction(['proj/project.json'], {}, context);
42+
const results = await createNodesFunction(['proj/project.json'], { targetName: 'clean' }, context);
4343

4444
expect(results).toMatchInlineSnapshot(`
4545
Array [

tools/workspace-plugin/src/plugins/clean-plugin.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import { dirname } from 'node:path';
1010

1111
import { assertProjectExists, projectConfigGlob } from './shared';
1212

13-
interface CleanPluginOptions {}
13+
interface CleanPluginOptions {
14+
targetName?: string;
15+
}
1416

1517
export const createNodesV2: CreateNodesV2<CleanPluginOptions> = [
1618
projectConfigGlob,
@@ -27,6 +29,12 @@ export const createNodesV2: CreateNodesV2<CleanPluginOptions> = [
2729
];
2830

2931
// ===================================================================================================================
32+
function normalizeOptions(options: CleanPluginOptions | undefined): Required<CleanPluginOptions> {
33+
options ??= {};
34+
options.targetName ??= 'type-check';
35+
36+
return options as Required<CleanPluginOptions>;
37+
}
3038

3139
function createNodesInternal(
3240
configFilePath: string,
@@ -39,6 +47,8 @@ function createNodesInternal(
3947
return {};
4048
}
4149

50+
const normalizedOptions = normalizeOptions(options);
51+
4252
const targetConfig: TargetConfiguration = {
4353
executor: '@fluentui/workspace-plugin:clean',
4454
};
@@ -47,7 +57,7 @@ function createNodesInternal(
4757
projects: {
4858
[projectRoot]: {
4959
targets: {
50-
clean: targetConfig,
60+
[normalizedOptions.targetName]: targetConfig,
5161
},
5262
},
5363
},

tools/workspace-plugin/src/plugins/format-plugin.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe(`format-plugin`, () => {
4242
// await tempFs.createFiles({
4343

4444
// });
45-
const results = await createNodesFunction(['proj/project.json'], {}, context);
45+
const results = await createNodesFunction(['proj/project.json'], { targetName: 'format' }, context);
4646

4747
expect(results).toMatchInlineSnapshot(`
4848
Array [

tools/workspace-plugin/src/plugins/format-plugin.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { dirname } from 'node:path';
1111

1212
import { assertProjectExists, projectConfigGlob } from './shared';
1313

14-
interface FormatPluginOptions {}
14+
interface FormatPluginOptions {
15+
targetName?: string;
16+
}
1517

1618
const pmc = getPackageManagerCommand();
1719

@@ -30,6 +32,12 @@ export const createNodesV2: CreateNodesV2<FormatPluginOptions> = [
3032
];
3133

3234
// ===================================================================================================================
35+
function normalizeOptions(options: FormatPluginOptions | undefined): Required<FormatPluginOptions> {
36+
options ??= {};
37+
options.targetName ??= 'format';
38+
39+
return options as Required<FormatPluginOptions>;
40+
}
3341

3442
function createNodesInternal(
3543
configFilePath: string,
@@ -42,6 +50,8 @@ function createNodesInternal(
4250
return {};
4351
}
4452

53+
const normalizedOptions = normalizeOptions(options);
54+
4555
const targetConfig: TargetConfiguration = {
4656
command: 'prettier --write {projectRoot}',
4757
cache: true,
@@ -71,7 +81,7 @@ function createNodesInternal(
7181
projects: {
7282
[projectRoot]: {
7383
targets: {
74-
format: targetConfig,
84+
[normalizedOptions.targetName]: targetConfig,
7585
},
7686
},
7787
},

tools/workspace-plugin/src/plugins/type-check-plugin.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe(`type-check-plugin`, () => {
4444
'proj/tsconfig.lib.json': '{}',
4545
'proj/tsconfig.spec.json': '{}',
4646
});
47-
const results = await createNodesFunction(['proj/tsconfig.json'], {}, context);
47+
const results = await createNodesFunction(['proj/tsconfig.json'], { targetName: 'type-check' }, context);
4848

4949
expect(results).toMatchInlineSnapshot(`
5050
Array [

tools/workspace-plugin/src/plugins/type-check-plugin.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import { dirname } from 'node:path';
1010

1111
import { assertProjectExists } from './shared';
1212

13-
interface TypeCheckPluginOptions {}
13+
interface TypeCheckPluginOptions {
14+
targetName?: string;
15+
}
1416

1517
const typescriptConfigGlob = '**/tsconfig.json';
1618

@@ -19,7 +21,7 @@ export const createNodesV2: CreateNodesV2<TypeCheckPluginOptions> = [
1921
(configFiles, options, context) => {
2022
return createNodesFromFiles(
2123
(configFile, options, context) => {
22-
return createNodesInternal(configFile, options ?? {}, context);
24+
return createNodesInternal(configFile, options, context);
2325
},
2426
configFiles,
2527
options,
@@ -30,9 +32,16 @@ export const createNodesV2: CreateNodesV2<TypeCheckPluginOptions> = [
3032

3133
// ===================================================================================================================
3234

35+
function normalizeOptions(options: TypeCheckPluginOptions | undefined): Required<TypeCheckPluginOptions> {
36+
options ??= {};
37+
options.targetName ??= 'type-check';
38+
39+
return options as Required<TypeCheckPluginOptions>;
40+
}
41+
3342
function createNodesInternal(
3443
configFilePath: string,
35-
options: TypeCheckPluginOptions,
44+
options: TypeCheckPluginOptions | undefined,
3645
context: CreateNodesContextV2,
3746
): CreateNodesResult {
3847
const projectRoot = dirname(configFilePath);
@@ -41,6 +50,8 @@ function createNodesInternal(
4150
return {};
4251
}
4352

53+
const normalizedOptions = normalizeOptions(options);
54+
4455
const targetConfig: TargetConfiguration = {
4556
executor: '@fluentui/workspace-plugin:type-check',
4657
cache: true,
@@ -55,7 +66,7 @@ function createNodesInternal(
5566
projects: {
5667
[projectRoot]: {
5768
targets: {
58-
'type-check': targetConfig,
69+
[normalizedOptions.targetName]: targetConfig,
5970
},
6071
},
6172
},

0 commit comments

Comments
 (0)