@nx/react 0.0.0-pr-27552-8322864 → 0.0.0-pr-27504-68aa5d2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +6 -6
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +1 -4
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +1 -4
- package/src/generators/application/schema.d.ts +2 -2
- package/src/generators/component-cypress-spec/component-cypress-spec.js +5 -10
- package/src/generators/component-story/component-story.js +2 -1
- package/src/generators/component-test/component-test.js +1 -2
- package/src/generators/component-test/files/__fileName__.cy__ext__ +2 -2
- package/src/generators/federate-module/schema.d.ts +1 -3
- package/src/generators/host/schema.d.ts +2 -2
- package/src/generators/library/schema.d.ts +2 -2
- package/src/generators/remote/schema.d.ts +2 -2
- package/src/generators/storybook-configuration/schema.d.ts +2 -2
- package/src/utils/ast-utils.d.ts +1 -5
- package/src/utils/ast-utils.js +14 -93
- package/src/utils/component-props.d.ts +2 -3
- package/src/utils/component-props.js +16 -28
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
# Nx: Smart Monorepos · Fast CI
|
|
24
24
|
|
|
25
|
-
Nx is a build system
|
|
25
|
+
Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
|
|
26
26
|
|
|
27
27
|
This package is a [React plugin for Nx](https://nx.dev/nx-api/react).
|
|
28
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-27504-68aa5d2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
|
|
6
6
|
"repository": {
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"minimatch": "9.0.3",
|
|
40
40
|
"tslib": "^2.3.0",
|
|
41
41
|
"@module-federation/enhanced": "~0.2.3",
|
|
42
|
-
"@nx/devkit": "0.0.0-pr-
|
|
43
|
-
"@nx/js": "0.0.0-pr-
|
|
44
|
-
"@nx/eslint": "0.0.0-pr-
|
|
45
|
-
"@nx/web": "0.0.0-pr-
|
|
46
|
-
"@nrwl/react": "0.0.0-pr-
|
|
42
|
+
"@nx/devkit": "0.0.0-pr-27504-68aa5d2",
|
|
43
|
+
"@nx/js": "0.0.0-pr-27504-68aa5d2",
|
|
44
|
+
"@nx/eslint": "0.0.0-pr-27504-68aa5d2",
|
|
45
|
+
"@nx/web": "0.0.0-pr-27504-68aa5d2",
|
|
46
|
+
"@nrwl/react": "0.0.0-pr-27504-68aa5d2"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
@@ -187,10 +187,7 @@ async function* moduleFederationDevServer(options, context) {
|
|
|
187
187
|
}, pathToManifestFile);
|
|
188
188
|
options.staticRemotesPort ??= remotes.staticRemotePort;
|
|
189
189
|
// Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin
|
|
190
|
-
process.env.NX_MF_DEV_REMOTES = JSON.stringify(
|
|
191
|
-
...(remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName) ?? []),
|
|
192
|
-
p.name,
|
|
193
|
-
]);
|
|
190
|
+
process.env.NX_MF_DEV_REMOTES = JSON.stringify(remotes.devRemotes.map((r) => (typeof r === 'string' ? r : r.remoteName)));
|
|
194
191
|
const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
|
|
195
192
|
const mappedLocationsOfStaticRemotes = await buildStaticRemotes(staticRemotesConfig, nxBin, context, options);
|
|
196
193
|
const devRemoteIters = await startRemotes(remotes.devRemotes, context, options, 'serve');
|
package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js
CHANGED
|
@@ -162,10 +162,7 @@ async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
|
|
|
162
162
|
root: context.root,
|
|
163
163
|
}, pathToManifestFile);
|
|
164
164
|
options.staticRemotesPort ??= remotes.staticRemotePort;
|
|
165
|
-
process.env.NX_MF_DEV_REMOTES = JSON.stringify(
|
|
166
|
-
...(remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName) ?? []),
|
|
167
|
-
projectConfig.name,
|
|
168
|
-
]);
|
|
165
|
+
process.env.NX_MF_DEV_REMOTES = JSON.stringify(remotes.devRemotes.map((r) => (typeof r === 'string' ? r : r.remoteName)));
|
|
169
166
|
const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticSsrRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
|
|
170
167
|
const mappedLocationsOfStaticRemotes = await buildSsrStaticRemotes(staticRemotesConfig, nxBin, context, options);
|
|
171
168
|
const devRemoteIters = await startRemotes(remotes.devRemotes, context, options);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
|
-
import type { Linter
|
|
2
|
+
import type { Linter } from '@nx/eslint';
|
|
3
3
|
import type { SupportedStyles } from '../../../typings/style';
|
|
4
4
|
|
|
5
5
|
export interface Schema {
|
|
@@ -12,7 +12,7 @@ export interface Schema {
|
|
|
12
12
|
unitTestRunner?: 'jest' | 'vitest' | 'none';
|
|
13
13
|
inSourceTests?: boolean;
|
|
14
14
|
e2eTestRunner: 'cypress' | 'playwright' | 'none';
|
|
15
|
-
linter: Linter
|
|
15
|
+
linter: Linter;
|
|
16
16
|
pascalCaseFiles?: boolean;
|
|
17
17
|
classComponent?: boolean;
|
|
18
18
|
routing?: boolean;
|
|
@@ -25,7 +25,7 @@ function getArgsDefaultValue(property) {
|
|
|
25
25
|
[tsModule.SyntaxKind.BooleanKeyword]: false,
|
|
26
26
|
};
|
|
27
27
|
const resolvedValue = typeNameToDefault[property];
|
|
28
|
-
if (resolvedValue === undefined) {
|
|
28
|
+
if (typeof resolvedValue === undefined) {
|
|
29
29
|
return '';
|
|
30
30
|
}
|
|
31
31
|
else if (typeof resolvedValue === 'string') {
|
|
@@ -74,18 +74,13 @@ function createComponentSpecFile(tree, { project, componentPath, js, cypressProj
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
function findPropsAndGenerateFileForCypress(tree, sourceFile, cmpDeclaration, e2eLibIntegrationFolderPath, componentName, project, js, fromNodeArray) {
|
|
77
|
-
const
|
|
77
|
+
const propsInterface = (0, ast_utils_1.getComponentPropsInterface)(sourceFile, cmpDeclaration);
|
|
78
78
|
let props = [];
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
82
|
-
}
|
|
83
|
-
props = info.props.map((member) => {
|
|
79
|
+
if (propsInterface) {
|
|
80
|
+
props = propsInterface.members.map((member) => {
|
|
84
81
|
return {
|
|
85
82
|
name: member.name.text,
|
|
86
|
-
defaultValue:
|
|
87
|
-
? getArgsDefaultValue(member.kind)
|
|
88
|
-
: getArgsDefaultValue(member.type.kind),
|
|
83
|
+
defaultValue: getArgsDefaultValue(member.type.kind),
|
|
89
84
|
};
|
|
90
85
|
});
|
|
91
86
|
}
|
|
@@ -45,13 +45,14 @@ function createComponentStoriesFile(host, { project, componentPath, interactionT
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
function findPropsAndGenerateFile(host, sourceFile, cmpDeclaration, componentDirectory, name, interactionTests, isPlainJs, fromNodeArray) {
|
|
48
|
-
const { props, argTypes } = (0, component_props_1.
|
|
48
|
+
const { propsTypeName, props, argTypes } = (0, component_props_1.getDefaultsForComponent)(sourceFile, cmpDeclaration);
|
|
49
49
|
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, `./files${isPlainJs ? '/jsx' : '/tsx'}`), (0, devkit_1.normalizePath)(componentDirectory), {
|
|
50
50
|
tmpl: '',
|
|
51
51
|
componentFileName: fromNodeArray
|
|
52
52
|
? `${name}--${cmpDeclaration.name.text}`
|
|
53
53
|
: name,
|
|
54
54
|
componentImportFileName: name,
|
|
55
|
+
propsTypeName,
|
|
55
56
|
props,
|
|
56
57
|
argTypes,
|
|
57
58
|
componentName: cmpDeclaration.name.text,
|
|
@@ -38,7 +38,7 @@ function generateSpecsForComponents(tree, filePath) {
|
|
|
38
38
|
const defaultExport = (0, ast_utils_1.getComponentNode)(sourceFile);
|
|
39
39
|
if (cmpNodes?.length) {
|
|
40
40
|
const components = cmpNodes.map((cmp) => {
|
|
41
|
-
const defaults = (0, component_props_1.
|
|
41
|
+
const defaults = (0, component_props_1.getDefaultsForComponent)(sourceFile, cmp);
|
|
42
42
|
const isDefaultExport = defaultExport
|
|
43
43
|
? defaultExport.name.text === cmp.name.text
|
|
44
44
|
: false;
|
|
@@ -47,7 +47,6 @@ function generateSpecsForComponents(tree, filePath) {
|
|
|
47
47
|
props: [...defaults.props, ...defaults.argTypes],
|
|
48
48
|
name: cmp.name.text,
|
|
49
49
|
typeName: defaults.propsTypeName,
|
|
50
|
-
inlineTypeString: defaults.inlineTypeString,
|
|
51
50
|
};
|
|
52
51
|
});
|
|
53
52
|
const namedImports = components
|
|
@@ -2,8 +2,8 @@ import * as React from 'react'
|
|
|
2
2
|
<%- importStatement %>
|
|
3
3
|
|
|
4
4
|
<% for (let cmp of components) { %>
|
|
5
|
-
describe(<%= cmp.name %>.name, () => {<% if (cmp.
|
|
6
|
-
let props:
|
|
5
|
+
describe(<%= cmp.name %>.name, () => {<% if (cmp.typeName) { %>
|
|
6
|
+
let props: <%= cmp.typeName%>;
|
|
7
7
|
|
|
8
8
|
beforeEach(() => {
|
|
9
9
|
props = {<% for (let prop of cmp.props) { %>
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Linter, LinterType } from '@nx/eslint';
|
|
2
|
-
|
|
3
1
|
export interface Schema {
|
|
4
2
|
name: string;
|
|
5
3
|
path: string;
|
|
@@ -8,7 +6,7 @@ export interface Schema {
|
|
|
8
6
|
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
9
7
|
e2eTestRunner?: 'cypress' | 'playwright' | 'none';
|
|
10
8
|
host?: string;
|
|
11
|
-
linter?: Linter
|
|
9
|
+
linter?: Linter;
|
|
12
10
|
skipFormat?: boolean;
|
|
13
11
|
style?: SupportedStyles;
|
|
14
12
|
unitTestRunner?: 'jest' | 'vitest' | 'none';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
|
-
import type { Linter
|
|
2
|
+
import type { Linter } from '@nx/eslint';
|
|
3
3
|
import type { SupportedStyles } from '../../../typings/style';
|
|
4
4
|
|
|
5
5
|
export interface Schema {
|
|
@@ -11,7 +11,7 @@ export interface Schema {
|
|
|
11
11
|
e2eTestRunner: 'cypress' | 'playwright' | 'none';
|
|
12
12
|
globalCss?: boolean;
|
|
13
13
|
js?: boolean;
|
|
14
|
-
linter: Linter
|
|
14
|
+
linter: Linter;
|
|
15
15
|
name: string;
|
|
16
16
|
pascalCaseFiles?: boolean;
|
|
17
17
|
remotes?: string[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
|
-
import type { Linter
|
|
2
|
+
import type { Linter } from '@nx/eslint';
|
|
3
3
|
import type { SupportedStyles } from '../../../typings/style';
|
|
4
4
|
|
|
5
5
|
export interface Schema {
|
|
@@ -14,7 +14,7 @@ export interface Schema {
|
|
|
14
14
|
importPath?: string;
|
|
15
15
|
inSourceTests?: boolean;
|
|
16
16
|
js?: boolean;
|
|
17
|
-
linter: Linter
|
|
17
|
+
linter: Linter;
|
|
18
18
|
name: string;
|
|
19
19
|
pascalCaseFiles?: boolean;
|
|
20
20
|
publishable?: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
|
-
import type { Linter
|
|
2
|
+
import type { Linter } from '@nx/eslint';
|
|
3
3
|
import type { SupportedStyles } from '../../../typings/style';
|
|
4
4
|
import type { NormalizedSchema as ApplicationNormalizedSchema } from '../application/schema';
|
|
5
5
|
|
|
@@ -13,7 +13,7 @@ export interface Schema {
|
|
|
13
13
|
globalCss?: boolean;
|
|
14
14
|
host?: string;
|
|
15
15
|
js?: boolean;
|
|
16
|
-
linter: Linter
|
|
16
|
+
linter: Linter;
|
|
17
17
|
name: string;
|
|
18
18
|
pascalCaseFiles?: boolean;
|
|
19
19
|
routing?: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Linter
|
|
1
|
+
import { Linter } from '@nx/eslint';
|
|
2
2
|
|
|
3
3
|
export interface StorybookConfigureSchema {
|
|
4
4
|
project: string;
|
|
@@ -6,7 +6,7 @@ export interface StorybookConfigureSchema {
|
|
|
6
6
|
generateStories?: boolean;
|
|
7
7
|
js?: boolean;
|
|
8
8
|
tsConfiguration?: boolean;
|
|
9
|
-
linter?: Linter
|
|
9
|
+
linter?: Linter;
|
|
10
10
|
ignorePaths?: string[];
|
|
11
11
|
configureStaticServe?: boolean;
|
|
12
12
|
configureCypress?: boolean;
|
package/src/utils/ast-utils.d.ts
CHANGED
|
@@ -26,8 +26,4 @@ export declare function updateReduxStore(sourcePath: string, source: ts.SourceFi
|
|
|
26
26
|
modulePath: string;
|
|
27
27
|
}): StringChange[];
|
|
28
28
|
export declare function getComponentNode(sourceFile: ts.SourceFile): ts.Node | null;
|
|
29
|
-
export declare function
|
|
30
|
-
props: Array<ts.PropertySignature | ts.BindingElement>;
|
|
31
|
-
propsTypeName: string | null;
|
|
32
|
-
inlineTypeString: string | null;
|
|
33
|
-
} | null;
|
|
29
|
+
export declare function getComponentPropsInterface(sourceFile: ts.SourceFile, cmpDeclaration: ts.Node): ts.InterfaceDeclaration | null;
|
package/src/utils/ast-utils.js
CHANGED
|
@@ -18,7 +18,7 @@ exports.addStaticRouter = addStaticRouter;
|
|
|
18
18
|
exports.addReduxStoreToMain = addReduxStoreToMain;
|
|
19
19
|
exports.updateReduxStore = updateReduxStore;
|
|
20
20
|
exports.getComponentNode = getComponentNode;
|
|
21
|
-
exports.
|
|
21
|
+
exports.getComponentPropsInterface = getComponentPropsInterface;
|
|
22
22
|
const js_1 = require("@nx/js");
|
|
23
23
|
const devkit_1 = require("@nx/devkit");
|
|
24
24
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
@@ -470,58 +470,24 @@ function getComponentNode(sourceFile) {
|
|
|
470
470
|
}
|
|
471
471
|
return defaultExport;
|
|
472
472
|
}
|
|
473
|
-
function
|
|
473
|
+
function getComponentPropsInterface(sourceFile, cmpDeclaration) {
|
|
474
474
|
if (!tsModule) {
|
|
475
475
|
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
476
476
|
}
|
|
477
477
|
let propsTypeName = null;
|
|
478
|
-
let inlineTypeString = null;
|
|
479
|
-
const props = [];
|
|
480
|
-
const processParameters = (parameters) => {
|
|
481
|
-
if (!parameters.length) {
|
|
482
|
-
return null;
|
|
483
|
-
}
|
|
484
|
-
const propsParam = parameters[0];
|
|
485
|
-
if (propsParam.type) {
|
|
486
|
-
if (tsModule.isTypeReferenceNode(propsParam.type)) {
|
|
487
|
-
// function Cmp(props: Props) {}
|
|
488
|
-
propsTypeName = propsParam.type.typeName.getText();
|
|
489
|
-
}
|
|
490
|
-
else if (tsModule.isTypeLiteralNode(propsParam.type)) {
|
|
491
|
-
// function Cmp(props: {a: string, b: number}) {}
|
|
492
|
-
props.push(...propsParam.type.members);
|
|
493
|
-
inlineTypeString = propsParam.type.getText();
|
|
494
|
-
}
|
|
495
|
-
else {
|
|
496
|
-
// we don't support other types (e.g. union types)
|
|
497
|
-
return false;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
else if (tsModule.isObjectBindingPattern(propsParam.name)) {
|
|
501
|
-
// function Cmp({a, b}) {}
|
|
502
|
-
props.push(...propsParam.name.elements);
|
|
503
|
-
inlineTypeString = `{\n${propsParam.name.elements
|
|
504
|
-
.map((x) => `${x.name.getText()}: unknown;\n`)
|
|
505
|
-
.join('')}}`;
|
|
506
|
-
}
|
|
507
|
-
else {
|
|
508
|
-
// function Cmp(props) {}
|
|
509
|
-
return false;
|
|
510
|
-
}
|
|
511
|
-
return true;
|
|
512
|
-
};
|
|
513
478
|
if (tsModule.isFunctionDeclaration(cmpDeclaration)) {
|
|
514
|
-
const
|
|
515
|
-
if (
|
|
516
|
-
|
|
479
|
+
const propsParam = cmpDeclaration.parameters.find((x) => tsModule.isParameter(x) && x.name.text === 'props');
|
|
480
|
+
if (propsParam?.type?.['typeName']) {
|
|
481
|
+
propsTypeName = propsParam.type.typeName.text;
|
|
517
482
|
}
|
|
518
483
|
}
|
|
519
|
-
else if (
|
|
520
|
-
cmpDeclaration.initializer &&
|
|
484
|
+
else if (cmpDeclaration.initializer &&
|
|
521
485
|
tsModule.isArrowFunction(cmpDeclaration.initializer)) {
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
486
|
+
const arrowFn = cmpDeclaration
|
|
487
|
+
.initializer;
|
|
488
|
+
const propsParam = arrowFn.parameters.find((x) => tsModule.isParameter(x) && x.name.text === 'props');
|
|
489
|
+
if (propsParam?.type?.['typeName']) {
|
|
490
|
+
propsTypeName = propsParam.type.typeName.text;
|
|
525
491
|
}
|
|
526
492
|
}
|
|
527
493
|
else if (
|
|
@@ -545,56 +511,11 @@ function parseComponentPropsInfo(sourceFile, cmpDeclaration) {
|
|
|
545
511
|
return null;
|
|
546
512
|
}
|
|
547
513
|
if (propsTypeName) {
|
|
548
|
-
|
|
549
|
-
if (!foundProps) {
|
|
550
|
-
return null;
|
|
551
|
-
}
|
|
552
|
-
for (const prop of foundProps) {
|
|
553
|
-
props.push(prop);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
return {
|
|
557
|
-
propsTypeName,
|
|
558
|
-
props,
|
|
559
|
-
inlineTypeString,
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
function getPropsFromTypeName(sourceFile, propsTypeName) {
|
|
563
|
-
const matchingNode = (0, js_1.findNodes)(sourceFile, [
|
|
564
|
-
tsModule.SyntaxKind.InterfaceDeclaration,
|
|
565
|
-
tsModule.SyntaxKind.TypeAliasDeclaration,
|
|
566
|
-
]).find((x) => {
|
|
567
|
-
if (tsModule.isTypeAliasDeclaration(x) ||
|
|
568
|
-
tsModule.isInterfaceDeclaration(x)) {
|
|
514
|
+
return (0, js_1.findNodes)(sourceFile, tsModule.SyntaxKind.InterfaceDeclaration).find((x) => {
|
|
569
515
|
return x.name.getText() === propsTypeName;
|
|
570
|
-
}
|
|
571
|
-
return false;
|
|
572
|
-
});
|
|
573
|
-
if (!matchingNode) {
|
|
574
|
-
return null;
|
|
575
|
-
}
|
|
576
|
-
const props = [];
|
|
577
|
-
if (tsModule.isTypeAliasDeclaration(matchingNode)) {
|
|
578
|
-
if (tsModule.isTypeLiteralNode(matchingNode.type)) {
|
|
579
|
-
for (const prop of matchingNode.type.members) {
|
|
580
|
-
props.push(prop);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
else if (tsModule.isTypeReferenceNode(matchingNode.type)) {
|
|
584
|
-
const result = getPropsFromTypeName(sourceFile, matchingNode.type.typeName.getText());
|
|
585
|
-
if (result) {
|
|
586
|
-
props.push(...result);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
else {
|
|
590
|
-
// we don't support other types of type aliases (e.g. union types)
|
|
591
|
-
return null;
|
|
592
|
-
}
|
|
516
|
+
});
|
|
593
517
|
}
|
|
594
518
|
else {
|
|
595
|
-
|
|
596
|
-
props.push(prop);
|
|
597
|
-
}
|
|
519
|
+
return null;
|
|
598
520
|
}
|
|
599
|
-
return props;
|
|
600
521
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
2
|
export declare function getArgsDefaultValue(property: ts.SyntaxKind): string;
|
|
3
|
-
export declare function
|
|
4
|
-
propsTypeName: string
|
|
5
|
-
inlineTypeString: string | null;
|
|
3
|
+
export declare function getDefaultsForComponent(sourceFile: ts.SourceFile, cmpDeclaration: ts.Node): {
|
|
4
|
+
propsTypeName: string;
|
|
6
5
|
props: {
|
|
7
6
|
name: string;
|
|
8
7
|
defaultValue: any;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getArgsDefaultValue = getArgsDefaultValue;
|
|
4
|
-
exports.
|
|
4
|
+
exports.getDefaultsForComponent = getDefaultsForComponent;
|
|
5
5
|
exports.getImportForType = getImportForType;
|
|
6
6
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
7
7
|
const ast_utils_1 = require("./ast-utils");
|
|
@@ -17,53 +17,41 @@ function getArgsDefaultValue(property) {
|
|
|
17
17
|
[tsModule.SyntaxKind.BooleanKeyword]: false,
|
|
18
18
|
};
|
|
19
19
|
const resolvedValue = typeNameToDefault[property];
|
|
20
|
-
if (resolvedValue === undefined) {
|
|
20
|
+
if (typeof resolvedValue === undefined) {
|
|
21
21
|
return "''";
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
24
|
return resolvedValue;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function getDefaultsForComponent(sourceFile, cmpDeclaration) {
|
|
28
28
|
if (!tsModule) {
|
|
29
29
|
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const propsInterface = (0, ast_utils_1.getComponentPropsInterface)(sourceFile, cmpDeclaration);
|
|
32
32
|
let propsTypeName = null;
|
|
33
|
-
let inlineTypeString = null;
|
|
34
33
|
let props = [];
|
|
35
34
|
let argTypes = [];
|
|
36
|
-
if (
|
|
37
|
-
propsTypeName =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
actionText: `${member.name.getText()} executed!`,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
return {
|
|
50
|
-
name: member.name.getText(),
|
|
51
|
-
defaultValue: getArgsDefaultValue(member.type.kind),
|
|
52
|
-
};
|
|
53
|
-
}
|
|
35
|
+
if (propsInterface) {
|
|
36
|
+
propsTypeName = propsInterface.name.text;
|
|
37
|
+
props = propsInterface.members.map((member) => {
|
|
38
|
+
if (member.type.kind === tsModule.SyntaxKind.FunctionType) {
|
|
39
|
+
argTypes.push({
|
|
40
|
+
name: member.name.text,
|
|
41
|
+
type: 'action',
|
|
42
|
+
actionText: `${member.name.text} executed!`,
|
|
43
|
+
});
|
|
54
44
|
}
|
|
55
45
|
else {
|
|
56
|
-
// it's a binding element, which doesn't have a type, e.g.:
|
|
57
|
-
// const Cmp = ({ a, b }) => {}
|
|
58
46
|
return {
|
|
59
|
-
name: member.name.
|
|
60
|
-
defaultValue: getArgsDefaultValue(member.kind),
|
|
47
|
+
name: member.name.text,
|
|
48
|
+
defaultValue: getArgsDefaultValue(member.type.kind),
|
|
61
49
|
};
|
|
62
50
|
}
|
|
63
51
|
});
|
|
64
52
|
props = props.filter((p) => p && p.defaultValue !== undefined);
|
|
65
53
|
}
|
|
66
|
-
return { propsTypeName,
|
|
54
|
+
return { propsTypeName, props, argTypes };
|
|
67
55
|
}
|
|
68
56
|
function getImportForType(sourceFile, typeName) {
|
|
69
57
|
return sourceFile.statements.find((statement) => tsModule.isImportDeclaration(statement) &&
|