Skip to content

Commit cdee7d8

Browse files
authored
chore: remove unneeded internal primitives.json output (#2387)
* chore: remove unneeded internal primitives.json output * chore: update unit test to use PrimitiveCatalog export
1 parent 355c8e6 commit cdee7d8

File tree

2 files changed

+6
-35
lines changed

2 files changed

+6
-35
lines changed

packages/react/__tests__/exports.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
33
import type { PrimitiveCatalogType } from '../src/types/catalog';
4+
import { PrimitiveCatalog } from '@aws-amplify/ui-react/internal';
45

56
// Jest doesn't support `exports` maps, so we have to reference `dist` directly.
67
// See: https://github.com/facebook/jest/issues/9771
@@ -161,32 +162,16 @@ describe('@aws-amplify/ui-react/internal', () => {
161162
});
162163
});
163164

164-
const getCatalogJSON = (): PrimitiveCatalogType => {
165-
try {
166-
const rawJSON = fs
167-
.readFileSync(path.join(__dirname, '../dist/primitives.json'))
168-
.toString();
169-
170-
return JSON.parse(rawJSON) as PrimitiveCatalogType;
171-
} catch (err) {
172-
console.error('Error reading primitives catalog JSON file:', err);
173-
}
174-
175-
return {};
176-
};
177-
178165
describe('primitive catalog', () => {
179-
const catalog = getCatalogJSON();
180-
181-
it.each(Object.entries(catalog))(
166+
it.each(Object.entries(PrimitiveCatalog))(
182167
'should contain properties for %s primitive',
183168
(name, primitive) => {
184169
expect(Object.keys(primitive.properties).length).toBeGreaterThan(0);
185170
}
186171
);
187172

188173
it('should match primitives list snapshot', () => {
189-
expect(Object.keys(catalog)).toMatchInlineSnapshot(`
174+
expect(Object.keys(PrimitiveCatalog)).toMatchInlineSnapshot(`
190175
Array [
191176
"Alert",
192177
"Badge",

packages/react/scripts/generatePrimitiveCatalog.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,34 +181,20 @@ for (const [componentName, [node]] of source.getExportedDeclarations()) {
181181
}
182182
}
183183

184-
/**
185-
* Generate the JSON string of the PrimitiveCatalog
186-
* this is being exported under the /primitives.json subpath and can be used as
187-
* import PrimitiveCatalog from '@aws-amplify/ui-react/primitives.json'
188-
*/
189-
const jsonString = JSON.stringify(catalog, null, 2);
190-
191184
/**
192185
* Generate the es module of the PrimitiveCatalog
193186
* this is being exported under the /internal/primitives-catalog subpath and can be used as
194187
* import { PrimitiveCatalog } from '@aws-amplify/ui-react/internal/primitives-catalog'
195188
*/
189+
const primitiveCatalog = JSON.stringify(catalog, null, 2);
196190
const exportString = `import { PrimitiveCatalogType } from './types/catalog';
197-
export const PrimitiveCatalog: PrimitiveCatalogType = ${jsonString};`;
191+
export const PrimitiveCatalog: PrimitiveCatalogType = ${primitiveCatalog};`;
198192

199-
// Generates dist folder file since it's deleted in `prebuild`
200-
// NOTE: This line can be removed when we remove primitives.json output
201-
const distFolderPath = `${path.resolve(__dirname, '..')}/dist`;
202-
if (!fs.existsSync(distFolderPath)) {
203-
fs.mkdirSync(distFolderPath);
204-
}
205-
206-
const JSONoutputPath = `${path.resolve(__dirname, '..')}/dist/primitives.json`;
207193
const internalOutputPath = path.resolve(
208194
__dirname,
209195
'..',
210196
'src',
211197
'PrimitiveCatalog.ts'
212198
);
213-
fs.writeFileSync(JSONoutputPath, jsonString, { flag: 'w' });
199+
214200
fs.writeFileSync(internalOutputPath, exportString, { flag: 'w' });

0 commit comments

Comments
 (0)