Skip to content

Commit a679c77

Browse files
Merge pull request #214 from hypermod-io/fix-validate-error
Fix validate error
2 parents 340d756 + 6e3ab50 commit a679c77

File tree

11 files changed

+60
-39
lines changed

11 files changed

+60
-39
lines changed

.changeset/silent-steaks-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hypermod/validator': patch
3+
---
4+
5+
Fixes usage of fetchConfig to account for undefined. Now errors should be reported correctly

.changeset/slimy-mangos-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hypermod/fetcher': patch
3+
---
4+
5+
Correctly types fetchConfig function to correctly show that this function can return `undefined`

.changeset/wild-pigs-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hypermod/mod-atlaskit__textfield': patch
3+
---
4+
5+
Removes unused variables

community/@atlaskit__textfield/src/5.0.0/__tests__/remove-imports.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ function transformer(
1515
return source.toSource(options.printOptions);
1616
}
1717

18-
const importToDoComment = `
19-
/* TODO: (@hypermod) This file uses exports used to help theme @atlaskit/textfield which
20-
has now been removed due to its poor performance characteristics. */`;
21-
2218
describe('Remove imports', () => {
2319
it('should remove theme imports from Textfield and leave a comment', async () => {
2420
const result = await applyTransform(

community/@atlaskit__textfield/src/5.0.0/__tests__/remove-prop.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ function transformer(
1515
return source.toSource(options.printOptions);
1616
}
1717

18-
const themeToDoComment = `
19-
/* TODO: (@hypermod) This file uses the @atlaskit/textfield \`theme\` prop which
20-
has now been removed due to its poor performance characteristics. We have not replaced
21-
theme with an equivalent API due to minimal usage of the \`theme\` prop.
22-
The appearance of TextField will have likely changed. */`;
23-
2418
describe('Remove prop', () => {
2519
it('should remove theme from Textfield and leave a comment', async () => {
2620
const result = await applyTransform(

community/hypermod/src/defineInlineTest-to-applyTransform/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import core, { API, FileInfo, Options, Collection } from 'jscodeshift';
22

3-
import { hasImportDeclaration, hasImportSpecifier } from '@hypermod/utils';
3+
import { hasImportSpecifier } from '@hypermod/utils';
44

55
export default function transformer(
66
file: FileInfo,

packages/fetcher/src/index.spec.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ describe('fetcher', () => {
4242
{ virtual: true },
4343
);
4444

45-
const { filePath, config } = await fetchConfig(mockBasePath);
45+
const configMeta = await fetchConfig(mockBasePath);
4646

47-
expect(config).toEqual(mockConfig);
48-
expect(filePath).toEqual(mockFilePath);
47+
expect(configMeta!.config).toEqual(mockConfig);
48+
expect(configMeta!.filePath).toEqual(mockFilePath);
4949
});
5050

5151
it('fetches config with named export', async () => {
@@ -57,10 +57,12 @@ describe('fetcher', () => {
5757
},
5858
);
5959

60-
const { filePath, config } = await fetchConfig(mockBasePath);
60+
const configMeta = await fetchConfig(mockBasePath);
6161

62-
expect(config).toEqual(mockConfig);
63-
expect(filePath).toEqual(path.join(mockBasePath, 'hypermod.config.js'));
62+
expect(configMeta!.config).toEqual(mockConfig);
63+
expect(configMeta!.filePath).toEqual(
64+
path.join(mockBasePath, 'hypermod.config.js'),
65+
);
6466
});
6567

6668
it('fetches first matched config when multiple are found', async () => {
@@ -81,10 +83,10 @@ describe('fetcher', () => {
8183
path.join(mockBasePath, 'codemods', 'hypermod.config.tsx'),
8284
];
8385

84-
const { config, filePath } = await fetchConfig(mockBasePath);
86+
const configMeta = await fetchConfig(mockBasePath);
8587

86-
expect(config).toEqual(mockConfig);
87-
expect(filePath).toEqual(
88+
expect(configMeta!.config).toEqual(mockConfig);
89+
expect(configMeta!.filePath).toEqual(
8890
path.join(mockBasePath, 'src', 'hypermod.config.ts'),
8991
);
9092
});
@@ -107,13 +109,13 @@ describe('fetcher', () => {
107109
require: jest.fn().mockReturnValue(mockConfig),
108110
};
109111

110-
const { filePath, config } = await fetchPackage(
112+
const configMeta = await fetchPackage(
111113
'fake-package',
112114
mockPackageManager as unknown as PluginManager,
113115
);
114116

115-
expect(config).toEqual(mockConfig);
116-
expect(filePath).toEqual(mockFilePath);
117+
expect(configMeta!.config).toEqual(mockConfig);
118+
expect(configMeta!.filePath).toEqual(mockFilePath);
117119
});
118120

119121
it('should throw if fetching fails', async () => {
@@ -146,13 +148,15 @@ describe('fetcher', () => {
146148
}),
147149
};
148150

149-
const { config, filePath } = await fetchRemotePackage(
151+
const configMeta = await fetchRemotePackage(
150152
'fake-package',
151153
mockPackageManager as unknown as PluginManager,
152154
);
153155

154-
expect(config).toEqual(mockConfig);
155-
expect(filePath).toEqual(mockBasePath + '/hypermod.config.js');
156+
expect(configMeta!.config).toEqual(mockConfig);
157+
expect(configMeta!.filePath).toEqual(
158+
mockBasePath + '/hypermod.config.js',
159+
);
156160
});
157161

158162
it('should throw if fetching fails', async () => {
@@ -179,13 +183,13 @@ describe('fetcher', () => {
179183
}),
180184
};
181185

182-
const { config, filePath } = await fetchRemotePackage(
186+
const configMeta = await fetchRemotePackage(
183187
'fake-package',
184188
mockPackageManager as unknown as PluginManager,
185189
);
186190

187-
expect(config).toEqual(mockConfig);
188-
expect(filePath).toEqual(mockBasePath + '/index.js');
191+
expect(configMeta!.config).toEqual(mockConfig);
192+
expect(configMeta!.filePath).toEqual(mockBasePath + '/index.js');
189193
});
190194

191195
it('throws if entrypoint-based config does not contain a valid config (and there are no config files available elsewhere)', async () => {

packages/fetcher/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ function requireConfig(filePath: string, resolvedPath: string) {
2828
}
2929
}
3030

31-
export async function fetchConfig(filePath: string): Promise<ConfigMeta> {
31+
export async function fetchConfig(
32+
filePath: string,
33+
): Promise<ConfigMeta | undefined> {
3234
const configs = await fetchConfigs(filePath);
3335
return configs[0];
3436
}
@@ -94,7 +96,7 @@ export async function fetchPackage(
9496
export async function fetchRemotePackage(
9597
packageName: string,
9698
packageManager: PluginManager,
97-
): Promise<ConfigMeta> {
99+
): Promise<ConfigMeta | undefined> {
98100
if (['javascript', 'typescript'].includes(packageName)) {
99101
throw new Error(`'${packageName}' is ignored as a remote package.`);
100102
}

packages/validator/src/index.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ describe('validator', () => {
134134
);
135135
});
136136

137+
it('should error if config file is not found', async () => {
138+
const filePath = 'path/to/';
139+
140+
(fetchConfig as jest.Mock).mockResolvedValue(undefined);
141+
142+
await expect(isValidConfigAtPath(filePath)).rejects.toThrowError(
143+
`Unable to locate config file at path: ${filePath}`,
144+
);
145+
});
146+
137147
it('should error if config contains multiple invalid properties', async () => {
138148
(fetchConfig as jest.Mock).mockResolvedValue({
139149
location: 'path/to/hypermod.config.js',

packages/validator/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,25 @@ export function isValidConfig(config: CodeshiftConfig) {
3838
}
3939

4040
export async function isValidConfigAtPath(filePath: string) {
41-
const { config } = await fetchConfig(filePath);
41+
const configMeta = await fetchConfig(filePath);
4242

43-
if (!config) {
43+
if (!configMeta) {
4444
throw new Error(`Unable to locate config file at path: ${filePath}`);
4545
}
4646

47-
const invalidProperites = getInvalidProperties(config);
47+
const invalidProperites = getInvalidProperties(configMeta.config);
4848
if (invalidProperites.length) {
4949
throw new Error(
5050
`Invalid transform ids found: ${invalidProperites.join(', ')}`,
5151
);
5252
}
5353

54-
if (!hasValidTransforms(config)) {
54+
if (!hasValidTransforms(configMeta.config)) {
5555
throw new Error(`Invalid transform ids found for config at "${filePath}".
5656
Please make sure all transforms are identified by a valid semver version. ie 10.0.0`);
5757
}
5858

59-
if (!hasValidPresets(config)) {
59+
if (!hasValidPresets(configMeta.config)) {
6060
throw new Error(`Invalid preset ids found for config at "${filePath}".
6161
Please make sure all presets are kebab case and contain no spaces or special characters. ie sort-imports-by-scope`);
6262
}

0 commit comments

Comments
 (0)