@atlaskit/forge-react-types 0.13.0 → 0.14.1

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +93 -80
  2. package/LICENSE.md +6 -8
  3. package/dist/types/components/__generated__/ButtonProps.codegen.d.ts +1 -1
  4. package/dist/types/components/__generated__/CheckboxGroupProps.codegen.d.ts +2 -2
  5. package/dist/types/components/__generated__/DatePickerProps.codegen.d.ts +1 -1
  6. package/dist/types/components/__generated__/FormProps.codegen.d.ts +2 -2
  7. package/dist/types/components/__generated__/IconProps.codegen.d.ts +2 -2
  8. package/dist/types/components/__generated__/ListItemProps.codegen.d.ts +2 -2
  9. package/dist/types/components/__generated__/ListProps.codegen.d.ts +2 -2
  10. package/dist/types/components/__generated__/types.codegen.d.ts +2 -2
  11. package/dist/types-ts4.5/components/__generated__/ButtonProps.codegen.d.ts +1 -1
  12. package/dist/types-ts4.5/components/__generated__/CheckboxGroupProps.codegen.d.ts +2 -2
  13. package/dist/types-ts4.5/components/__generated__/DatePickerProps.codegen.d.ts +1 -1
  14. package/dist/types-ts4.5/components/__generated__/FormProps.codegen.d.ts +2 -2
  15. package/dist/types-ts4.5/components/__generated__/IconProps.codegen.d.ts +2 -2
  16. package/dist/types-ts4.5/components/__generated__/ListItemProps.codegen.d.ts +2 -2
  17. package/dist/types-ts4.5/components/__generated__/ListProps.codegen.d.ts +2 -2
  18. package/dist/types-ts4.5/components/__generated__/types.codegen.d.ts +2 -2
  19. package/package.json +8 -10
  20. package/scripts/codegen/codeGenerator.ts +306 -347
  21. package/scripts/codegen/componentPropTypes.ts +167 -212
  22. package/scripts/codegen-runner.ts +4 -4
  23. package/src/components/__generated__/ButtonProps.codegen.tsx +358 -358
  24. package/src/components/__generated__/CheckboxGroupProps.codegen.tsx +8 -8
  25. package/src/components/__generated__/DatePickerProps.codegen.tsx +12 -12
  26. package/src/components/__generated__/FormProps.codegen.tsx +4 -4
  27. package/src/components/__generated__/IconProps.codegen.tsx +364 -364
  28. package/src/components/__generated__/ListItemProps.codegen.tsx +3 -3
  29. package/src/components/__generated__/ListProps.codegen.tsx +4 -4
  30. package/src/components/__generated__/types.codegen.ts +20 -20
  31. package/src/index.ts +58 -58
@@ -8,12 +8,11 @@ import fs from 'fs';
8
8
  import { generateComponentPropTypeSourceCode } from './codeGenerator';
9
9
 
10
10
  const forgeUIProject = new Project({
11
- tsConfigFilePath: require.resolve('@atlassian/forge-ui/tsconfig.json'),
12
- skipAddingFilesFromTsConfig: true,
11
+ tsConfigFilePath: require.resolve('@atlassian/forge-ui/tsconfig.json'),
12
+ skipAddingFilesFromTsConfig: true,
13
13
  });
14
14
 
15
- const isExportSpecifier = (node: Node): node is ExportSpecifier =>
16
- 'getExportDeclaration' in node;
15
+ const isExportSpecifier = (node: Node): node is ExportSpecifier => 'getExportDeclaration' in node;
17
16
 
18
17
  const isSourceFile = (node: Node): node is SourceFile => 'getFilePath' in node;
19
18
 
@@ -24,176 +23,146 @@ const isSourceFile = (node: Node): node is SourceFile => 'getFilePath' in node;
24
23
  * in the index file will resolve to:
25
24
  * platform/packages/forge/forge-ui/src/components/UIKit2-codegen/badge/__generated__/index.partial.tsx
26
25
  */
27
- const loadComponentSourceFile = (
28
- componentSymbol: Symbol,
29
- project: Project,
30
- ): SourceFile | null => {
31
- const declaration = componentSymbol.getDeclarations()[0];
32
- if (!declaration || !isExportSpecifier(declaration)) {
33
- return null;
34
- }
35
- const importSrcDeclaration = declaration
36
- .getExportDeclaration()
37
- .getModuleSpecifier()
38
- ?.getSymbol()
39
- ?.getValueDeclaration();
40
- if (!importSrcDeclaration || !isSourceFile(importSrcDeclaration)) {
41
- return null;
42
- }
43
- const importSrc = importSrcDeclaration.getFilePath();
44
- const sourceFile = project.addSourceFileAtPath(importSrc);
45
- const baseComponentSymbol = findBaseSymbolFromSourceFile(
46
- sourceFile,
47
- componentSymbol,
48
- );
49
- if (!baseComponentSymbol) {
50
- return sourceFile;
51
- }
52
- // recursively resolve the source file of the base component symbol, it is
53
- // needed for TagProps
54
- let nestedSourceFile = loadComponentSourceFile(baseComponentSymbol!, project);
55
- try {
56
- return nestedSourceFile ?? sourceFile;
57
- } finally {
58
- if (nestedSourceFile) {
59
- // unload the parent source file if nested source file is found
60
- project.removeSourceFile(sourceFile);
61
- }
62
- }
26
+ const loadComponentSourceFile = (componentSymbol: Symbol, project: Project): SourceFile | null => {
27
+ const declaration = componentSymbol.getDeclarations()[0];
28
+ if (!declaration || !isExportSpecifier(declaration)) {
29
+ return null;
30
+ }
31
+ const importSrcDeclaration = declaration
32
+ .getExportDeclaration()
33
+ .getModuleSpecifier()
34
+ ?.getSymbol()
35
+ ?.getValueDeclaration();
36
+ if (!importSrcDeclaration || !isSourceFile(importSrcDeclaration)) {
37
+ return null;
38
+ }
39
+ const importSrc = importSrcDeclaration.getFilePath();
40
+ const sourceFile = project.addSourceFileAtPath(importSrc);
41
+ const baseComponentSymbol = findBaseSymbolFromSourceFile(sourceFile, componentSymbol);
42
+ if (!baseComponentSymbol) {
43
+ return sourceFile;
44
+ }
45
+ // recursively resolve the source file of the base component symbol, it is
46
+ // needed for TagProps
47
+ let nestedSourceFile = loadComponentSourceFile(baseComponentSymbol!, project);
48
+ try {
49
+ return nestedSourceFile ?? sourceFile;
50
+ } finally {
51
+ if (nestedSourceFile) {
52
+ // unload the parent source file if nested source file is found
53
+ project.removeSourceFile(sourceFile);
54
+ }
55
+ }
63
56
  };
64
57
 
65
- const findBaseSymbolFromSourceFile = (
66
- sourceFile: SourceFile,
67
- symbol: Symbol,
68
- ) => {
69
- return sourceFile.getExportSymbols().find((exportSymbol) => {
70
- return (
71
- exportSymbol.getName() === symbol.getName() ||
72
- exportSymbol.getName() === symbol.getAliasedSymbol()!.getName()
73
- );
74
- });
58
+ const findBaseSymbolFromSourceFile = (sourceFile: SourceFile, symbol: Symbol) => {
59
+ return sourceFile.getExportSymbols().find((exportSymbol) => {
60
+ return (
61
+ exportSymbol.getName() === symbol.getName() ||
62
+ exportSymbol.getName() === symbol.getAliasedSymbol()!.getName()
63
+ );
64
+ });
75
65
  };
76
66
 
77
67
  const makeComponentPropTypeSourceCode = (
78
- componentSymbol: Symbol,
79
- componentSourceFile: SourceFile,
68
+ componentSymbol: Symbol,
69
+ componentSourceFile: SourceFile,
80
70
  ) => {
81
- const baseComponentSymbol = findBaseSymbolFromSourceFile(
82
- componentSourceFile,
83
- componentSymbol,
84
- );
85
- if (!baseComponentSymbol) {
86
- throw new Error(
87
- 'Could not find base component symbol for component: ' +
88
- componentSymbol.getName(),
89
- );
90
- }
91
-
92
- return generateComponentPropTypeSourceCode(
93
- componentSymbol,
94
- componentSourceFile,
95
- );
71
+ const baseComponentSymbol = findBaseSymbolFromSourceFile(componentSourceFile, componentSymbol);
72
+ if (!baseComponentSymbol) {
73
+ throw new Error(
74
+ 'Could not find base component symbol for component: ' + componentSymbol.getName(),
75
+ );
76
+ }
77
+
78
+ return generateComponentPropTypeSourceCode(componentSymbol, componentSourceFile);
96
79
  };
97
80
 
98
81
  const generateComponentPropTypeSourceFiles = (
99
- componentOutputDir: string,
100
- componentPropTypeSymbols: Symbol[],
82
+ componentOutputDir: string,
83
+ componentPropTypeSymbols: Symbol[],
101
84
  ) => {
102
- // eslint-disable-next-line no-console
103
- console.log('Generating component prop type source files');
104
-
105
- // iterate component prop declarations in the index file
106
- componentPropTypeSymbols.forEach((componentSymbol) => {
107
- const componentSourceFile = loadComponentSourceFile(
108
- componentSymbol,
109
- forgeUIProject,
110
- );
111
- if (componentSourceFile) {
112
- try {
113
- const sourceCode = makeComponentPropTypeSourceCode(
114
- componentSymbol,
115
- componentSourceFile,
116
- );
117
- const sourceFilePath = resolve(
118
- componentOutputDir,
119
- `${componentSymbol.getName()}.codegen.tsx`,
120
- );
121
-
122
- const signedSourceCode = createSignedArtifact(
123
- sourceCode,
124
- 'yarn workspace @atlaskit/forge-react-types codegen',
125
- {
126
- description: `Extract component prop types from UIKit 2 components - ${componentSymbol.getName()}`,
127
- dependencies: [componentSourceFile.getFilePath()],
128
- outputFolder: componentOutputDir,
129
- },
130
- );
131
- fs.writeFileSync(sourceFilePath, signedSourceCode);
132
-
133
- // eslint-disable-next-line no-console
134
- console.log(
135
- `Generated component prop type file: ${componentSymbol.getName()}`,
136
- );
137
- } finally {
138
- forgeUIProject.removeSourceFile(componentSourceFile);
139
- }
140
- } else {
141
- // eslint-disable-next-line no-console
142
- console.error(
143
- `Could not find source file for component: ${componentSymbol.getName()}`,
144
- );
145
- }
146
- });
85
+ // eslint-disable-next-line no-console
86
+ console.log('Generating component prop type source files');
87
+
88
+ // iterate component prop declarations in the index file
89
+ componentPropTypeSymbols.forEach((componentSymbol) => {
90
+ const componentSourceFile = loadComponentSourceFile(componentSymbol, forgeUIProject);
91
+ if (componentSourceFile) {
92
+ try {
93
+ const sourceCode = makeComponentPropTypeSourceCode(componentSymbol, componentSourceFile);
94
+ const sourceFilePath = resolve(
95
+ componentOutputDir,
96
+ `${componentSymbol.getName()}.codegen.tsx`,
97
+ );
98
+
99
+ const signedSourceCode = createSignedArtifact(
100
+ sourceCode,
101
+ 'yarn workspace @atlaskit/forge-react-types codegen',
102
+ {
103
+ description: `Extract component prop types from UIKit 2 components - ${componentSymbol.getName()}`,
104
+ dependencies: [componentSourceFile.getFilePath()],
105
+ outputFolder: componentOutputDir,
106
+ },
107
+ );
108
+ fs.writeFileSync(sourceFilePath, signedSourceCode);
109
+
110
+ // eslint-disable-next-line no-console
111
+ console.log(`Generated component prop type file: ${componentSymbol.getName()}`);
112
+ } finally {
113
+ forgeUIProject.removeSourceFile(componentSourceFile);
114
+ }
115
+ } else {
116
+ // eslint-disable-next-line no-console
117
+ console.error(`Could not find source file for component: ${componentSymbol.getName()}`);
118
+ }
119
+ });
147
120
  };
148
121
 
149
- const updatePackageJsonWithADSComponentDependencies = (
150
- componentOutputDir: string,
151
- ) => {
152
- // collect all @atlaskit dependencies from the generated code in the component output dir
153
- const componentOutputProject = new Project({
154
- tsConfigFilePath: require.resolve('../../tsconfig.json'),
155
- });
156
- const utilizedPackages = componentOutputProject
157
- .getSourceFiles(`${componentOutputDir}/*.tsx`)
158
- .reduce((packages, source) => {
159
- source.getImportDeclarations().forEach((importDeclaration) => {
160
- const importPath = importDeclaration.getModuleSpecifierValue();
161
- // clean up import path so it contains only @atlaskit/package-name (without @atlaskit/package-name/further)
162
- const packageMatch = importPath.match(/(@atlaskit\/[^/]+)/);
163
- if (packageMatch) {
164
- packages.add(packageMatch[1]);
165
- }
166
- });
167
- return packages;
168
- }, new Set<string>());
169
-
170
- // eslint-disable-next-line no-console
171
- console.log('Updating package.json with ADS component dependencies');
172
-
173
- const forgeUIPackageJson = JSON.parse(
174
- fs
175
- .readFileSync(require.resolve('@atlassian/forge-ui/package.json'))
176
- .toString(),
177
- );
178
- const packageJsonPath = resolve(__dirname, '..', '..', 'package.json');
179
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
180
-
181
- // remove all existing @atlaskit dependencies from packageJson
182
- const updatedDependencies = Object.entries<string>(packageJson.dependencies)
183
- .filter(([key]) => !key.startsWith('@atlaskit/'))
184
- .concat(
185
- Object.entries<string>(forgeUIPackageJson.dependencies).filter(([key]) =>
186
- utilizedPackages.has(key),
187
- ),
188
- )
189
- .sort(([a], [b]) => a.localeCompare(b))
190
- .reduce<Record<string, string>>((acc, [key, value]) => {
191
- acc[key] = value;
192
- return acc;
193
- }, {});
194
-
195
- packageJson.dependencies = updatedDependencies;
196
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
122
+ const updatePackageJsonWithADSComponentDependencies = (componentOutputDir: string) => {
123
+ // collect all @atlaskit dependencies from the generated code in the component output dir
124
+ const componentOutputProject = new Project({
125
+ tsConfigFilePath: require.resolve('../../tsconfig.json'),
126
+ });
127
+ const utilizedPackages = componentOutputProject
128
+ .getSourceFiles(`${componentOutputDir}/*.tsx`)
129
+ .reduce((packages, source) => {
130
+ source.getImportDeclarations().forEach((importDeclaration) => {
131
+ const importPath = importDeclaration.getModuleSpecifierValue();
132
+ // clean up import path so it contains only @atlaskit/package-name (without @atlaskit/package-name/further)
133
+ const packageMatch = importPath.match(/(@atlaskit\/[^/]+)/);
134
+ if (packageMatch) {
135
+ packages.add(packageMatch[1]);
136
+ }
137
+ });
138
+ return packages;
139
+ }, new Set<string>());
140
+
141
+ // eslint-disable-next-line no-console
142
+ console.log('Updating package.json with ADS component dependencies');
143
+
144
+ const forgeUIPackageJson = JSON.parse(
145
+ fs.readFileSync(require.resolve('@atlassian/forge-ui/package.json')).toString(),
146
+ );
147
+ const packageJsonPath = resolve(__dirname, '..', '..', 'package.json');
148
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
149
+
150
+ // remove all existing @atlaskit dependencies from packageJson
151
+ const updatedDependencies = Object.entries<string>(packageJson.dependencies)
152
+ .filter(([key]) => !key.startsWith('@atlaskit/'))
153
+ .concat(
154
+ Object.entries<string>(forgeUIPackageJson.dependencies).filter(([key]) =>
155
+ utilizedPackages.has(key),
156
+ ),
157
+ )
158
+ .sort(([a], [b]) => a.localeCompare(b))
159
+ .reduce<Record<string, string>>((acc, [key, value]) => {
160
+ acc[key] = value;
161
+ return acc;
162
+ }, {});
163
+
164
+ packageJson.dependencies = updatedDependencies;
165
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
197
166
  };
198
167
 
199
168
  /**
@@ -201,59 +170,45 @@ const updatePackageJsonWithADSComponentDependencies = (
201
170
  * to __generated__ folder.
202
171
  */
203
172
  const generateSharedTypesFile = (componentOutputDir: string) => {
204
- // eslint-disable-next-line no-console
205
- console.log('Generating shared types file');
206
-
207
- const uiKit2TypesFile = require.resolve(
208
- '@atlassian/forge-ui/UIKit2-codegen/types',
209
- );
210
-
211
- const signedSourceCode = createSignedArtifact(
212
- fs.readFileSync(uiKit2TypesFile, 'utf8'),
213
- 'yarn workspace @atlaskit/forge-react-types codegen',
214
- {
215
- description: 'Shared types file from UIKit 2',
216
- dependencies: [uiKit2TypesFile],
217
- outputFolder: componentOutputDir,
218
- },
219
- );
220
-
221
- const typesFilePath = resolve(componentOutputDir, 'types.codegen.ts');
222
- fs.writeFileSync(typesFilePath, signedSourceCode);
173
+ // eslint-disable-next-line no-console
174
+ console.log('Generating shared types file');
175
+
176
+ const uiKit2TypesFile = require.resolve('@atlassian/forge-ui/UIKit2-codegen/types');
177
+
178
+ const signedSourceCode = createSignedArtifact(
179
+ fs.readFileSync(uiKit2TypesFile, 'utf8'),
180
+ 'yarn workspace @atlaskit/forge-react-types codegen',
181
+ {
182
+ description: 'Shared types file from UIKit 2',
183
+ dependencies: [uiKit2TypesFile],
184
+ outputFolder: componentOutputDir,
185
+ },
186
+ );
187
+
188
+ const typesFilePath = resolve(componentOutputDir, 'types.codegen.ts');
189
+ fs.writeFileSync(typesFilePath, signedSourceCode);
223
190
  };
224
191
 
225
192
  const generateComponentPropTypes = (componentPropTypeFilter?: string) => {
226
- const componentOutputDir = resolve(
227
- __dirname,
228
- '..',
229
- '..',
230
- 'src',
231
- 'components',
232
- '__generated__',
233
- );
234
- const componentIndexSourceFile = forgeUIProject.addSourceFileAtPath(
235
- require.resolve('@atlassian/forge-ui/UIKit2-codegen'),
236
- );
237
- try {
238
- const componentPropTypeSymbols = componentIndexSourceFile
239
- .getExportSymbols()
240
- .filter((symbol) =>
241
- symbol.getName().endsWith(componentPropTypeFilter ?? 'Props'),
242
- )
243
- .sort((a, b) => a.getName().localeCompare(b.getName()));
244
-
245
- // generate share types file first
246
- generateSharedTypesFile(componentOutputDir);
247
-
248
- generateComponentPropTypeSourceFiles(
249
- componentOutputDir,
250
- componentPropTypeSymbols,
251
- );
252
-
253
- updatePackageJsonWithADSComponentDependencies(componentOutputDir);
254
- } finally {
255
- forgeUIProject.removeSourceFile(componentIndexSourceFile);
256
- }
193
+ const componentOutputDir = resolve(__dirname, '..', '..', 'src', 'components', '__generated__');
194
+ const componentIndexSourceFile = forgeUIProject.addSourceFileAtPath(
195
+ require.resolve('@atlassian/forge-ui/UIKit2-codegen'),
196
+ );
197
+ try {
198
+ const componentPropTypeSymbols = componentIndexSourceFile
199
+ .getExportSymbols()
200
+ .filter((symbol) => symbol.getName().endsWith(componentPropTypeFilter ?? 'Props'))
201
+ .sort((a, b) => a.getName().localeCompare(b.getName()));
202
+
203
+ // generate share types file first
204
+ generateSharedTypesFile(componentOutputDir);
205
+
206
+ generateComponentPropTypeSourceFiles(componentOutputDir, componentPropTypeSymbols);
207
+
208
+ updatePackageJsonWithADSComponentDependencies(componentOutputDir);
209
+ } finally {
210
+ forgeUIProject.removeSourceFile(componentIndexSourceFile);
211
+ }
257
212
  };
258
213
 
259
214
  export { generateComponentPropTypes };
@@ -1,9 +1,9 @@
1
1
  import { generateComponentPropTypes } from './codegen';
2
2
 
3
3
  if (process.argv.length < 3) {
4
- generateComponentPropTypes();
4
+ generateComponentPropTypes();
5
5
  } else {
6
- // e.g yarn workspace @atlaskit/forge-react-types codegen ButtonProp
7
- const componentPropTypeFilter = process.argv[2];
8
- generateComponentPropTypes(componentPropTypeFilter);
6
+ // e.g yarn workspace @atlaskit/forge-react-types codegen ButtonProp
7
+ const componentPropTypeFilter = process.argv[2];
8
+ generateComponentPropTypes(componentPropTypeFilter);
9
9
  }