@astryxdesign/cli 0.7.0-canary.fe57f54 → 0.7.0
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/CHANGELOG.md +167 -0
- package/api/doctor/doctor.d.mts +30 -2
- package/api/doctor/doctor.doc.mjs +2 -1
- package/api/doctor/doctor.mjs +153 -3
- package/api/doctor/doctor.test.mjs +250 -4
- package/assets/codemods/__tests__/registry.test.mjs +1 -0
- package/assets/codemods/registry.mjs +1 -0
- package/assets/codemods/transforms/next/index.mjs +1 -27
- package/assets/codemods/transforms/v0.7.0/__tests__/preserve-bottom-sheet-content-padding.test.mjs +178 -0
- package/assets/codemods/transforms/v0.7.0/__tests__/rename-empty-search-results-text.test.mjs +202 -0
- package/assets/codemods/transforms/v0.7.0/index.mjs +52 -0
- package/assets/codemods/transforms/v0.7.0/preserve-bottom-sheet-content-padding.mjs +242 -0
- package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +254 -0
- package/assets/docs/spacing.doc.mjs +2 -2
- package/assets/docs/tree/tokens-spacing.doc.mjs +15 -15
- package/assets/templates/blocks/components/BottomSheet/BottomSheetHeights.tsx +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetMobileKeyboard.tsx +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetNoScrim.tsx +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSnapPoints.tsx +1 -1
- package/assets/templates/blocks/components/Dialog/DialogAdaptivePresentation.tsx +1 -1
- package/assets/templates/pages/table-filter/page.tsx +8 -3
- package/assets/templates/pages/table-inbox/page.tsx +3 -1
- package/assets/templates/themes/butter/butterTheme.ts +12 -0
- package/assets/templates/themes/chocolate/chocolateTheme.ts +12 -0
- package/assets/templates/themes/matcha/matchaTheme.ts +14 -14
- package/assets/templates/themes/neutral/neutralTheme.ts +12 -0
- package/assets/templates/themes/stone/stoneTheme.ts +12 -0
- package/assets/templates/themes/y2k/y2kTheme.ts +10 -10
- package/assets/theme.template.ts +1 -1
- package/clients/cli/commands/doctor.doc.mjs +1 -1
- package/clients/cli/commands/doctor.test.mjs +33 -0
- package/package.json +9 -9
- /package/assets/codemods/transforms/{next → v0.7.0}/__tests__/migrate-deprecated-theme-surface.test.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.7.0}/__tests__/migrate-field-input-styling.test.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.7.0}/__tests__/validate-data-token-ownership.test.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.7.0}/migrate-deprecated-theme-surface-v0.6-data.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.7.0}/migrate-deprecated-theme-surface.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.7.0}/migrate-field-input-styling.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.7.0}/validate-data-token-ownership.mjs +0 -0
|
@@ -1042,7 +1042,7 @@ describe('doctor says why it skipped and what it checked', () => {
|
|
|
1042
1042
|
}
|
|
1043
1043
|
|
|
1044
1044
|
it(
|
|
1045
|
-
'
|
|
1045
|
+
'fails, and quotes the reason, when the CLI cannot load the project from a config that imports',
|
|
1046
1046
|
async () => {
|
|
1047
1047
|
const dir = cwdProject({
|
|
1048
1048
|
'package.json': '{"name":"app"}',
|
|
@@ -1051,7 +1051,7 @@ describe('doctor says why it skipped and what it checked', () => {
|
|
|
1051
1051
|
});
|
|
1052
1052
|
const {checks, summary} = (await doctor({cwd: dir})).data;
|
|
1053
1053
|
const by = Object.fromEntries(checks.map(c => [c.id, c]));
|
|
1054
|
-
expect(by.config.status).toBe('
|
|
1054
|
+
expect(by.config.status).toBe('fail');
|
|
1055
1055
|
expect(by.config.message).toMatch(
|
|
1056
1056
|
/^astryx\.config\.mjs loads, but the CLI could not load the project from it: .*integrations/,
|
|
1057
1057
|
);
|
|
@@ -1064,8 +1064,8 @@ describe('doctor says why it skipped and what it checked', () => {
|
|
|
1064
1064
|
expect(by['integration-issues'].message).toMatch(
|
|
1065
1065
|
/^Skipped — the project integration graph could not be loaded: .*integrations/,
|
|
1066
1066
|
);
|
|
1067
|
-
//
|
|
1068
|
-
expect(summary.fail).toBe(
|
|
1067
|
+
// The config check is the one failure; the skipped checks stay info.
|
|
1068
|
+
expect(summary.fail).toBe(1);
|
|
1069
1069
|
},
|
|
1070
1070
|
SLOW,
|
|
1071
1071
|
);
|
|
@@ -1123,6 +1123,252 @@ describe('doctor says why it skipped and what it checked', () => {
|
|
|
1123
1123
|
});
|
|
1124
1124
|
});
|
|
1125
1125
|
|
|
1126
|
+
describe('a configured integration that cannot load fails the gate', () => {
|
|
1127
|
+
const CORE_STUB = {
|
|
1128
|
+
'node_modules/@astryxdesign/core/package.json': JSON.stringify({
|
|
1129
|
+
name: '@astryxdesign/core',
|
|
1130
|
+
version: '0.6.3',
|
|
1131
|
+
}),
|
|
1132
|
+
};
|
|
1133
|
+
const WIDGETS = 'node_modules/@acme/widgets';
|
|
1134
|
+
/** @param {string} [manifest] */
|
|
1135
|
+
const widgets = (
|
|
1136
|
+
manifest = "export default {components: './components'};\n",
|
|
1137
|
+
) => ({
|
|
1138
|
+
[`${WIDGETS}/package.json`]: JSON.stringify({
|
|
1139
|
+
name: '@acme/widgets',
|
|
1140
|
+
version: '1.0.0',
|
|
1141
|
+
}),
|
|
1142
|
+
[`${WIDGETS}/astryx.integration.mjs`]: manifest,
|
|
1143
|
+
[`${WIDGETS}/components/AcmeCard.doc.mjs`]:
|
|
1144
|
+
"export default {type: 'component', name: 'AcmeCard', displayName: 'AcmeCard', description: 'Fixture.', props: []};\n",
|
|
1145
|
+
[`${WIDGETS}/components/AcmeCard.tsx`]:
|
|
1146
|
+
'export default function AcmeCard() { return null; }\n',
|
|
1147
|
+
});
|
|
1148
|
+
const APP = {
|
|
1149
|
+
'package.json': '{"name":"app"}',
|
|
1150
|
+
...CORE_STUB,
|
|
1151
|
+
'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
/** Run doctor on a project under the working directory. */
|
|
1155
|
+
async function report(files) {
|
|
1156
|
+
const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
|
|
1157
|
+
tmpDirs.push(dir);
|
|
1158
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
1159
|
+
const abs = path.join(dir, rel);
|
|
1160
|
+
fs.mkdirSync(path.dirname(abs), {recursive: true});
|
|
1161
|
+
fs.writeFileSync(abs, content);
|
|
1162
|
+
}
|
|
1163
|
+
const {checks, summary} = (await doctor({cwd: dir})).data;
|
|
1164
|
+
return {by: Object.fromEntries(checks.map(c => [c.id, c])), summary};
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
it.each([
|
|
1168
|
+
['not installed', {}, /Could not find installed integration package "@acme\/widgets"/],
|
|
1169
|
+
[
|
|
1170
|
+
'installed without a manifest',
|
|
1171
|
+
{[`${WIDGETS}/package.json`]: JSON.stringify({name: '@acme/widgets', version: '1.0.0'})},
|
|
1172
|
+
/no conventional root manifest/,
|
|
1173
|
+
],
|
|
1174
|
+
['installed with a manifest that throws', widgets('export default { not valid ((\n'), /Unexpected/],
|
|
1175
|
+
])(
|
|
1176
|
+
'fails when a configured integration is %s, and names it',
|
|
1177
|
+
async (_shape, extra, reason) => {
|
|
1178
|
+
const {by, summary} = await report({...APP, ...extra});
|
|
1179
|
+
const check = by['configured-integrations'];
|
|
1180
|
+
expect(check.status).toBe('fail');
|
|
1181
|
+
expect(check.message).toMatch(
|
|
1182
|
+
/^1 of 1 integration named in astryx\.config could not be loaded, so it contributes nothing: @acme\/widgets \(/,
|
|
1183
|
+
);
|
|
1184
|
+
expect(check.message).toMatch(reason);
|
|
1185
|
+
expect(check.fix).toContain('astryx doctor integration validate <package>');
|
|
1186
|
+
expect(summary.fail).toBe(1);
|
|
1187
|
+
},
|
|
1188
|
+
SLOW,
|
|
1189
|
+
);
|
|
1190
|
+
|
|
1191
|
+
it(
|
|
1192
|
+
'counts the package being authored when its own config names it',
|
|
1193
|
+
async () => {
|
|
1194
|
+
const {by} = await report({
|
|
1195
|
+
...CORE_STUB,
|
|
1196
|
+
'package.json': JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
|
|
1197
|
+
'astryx.integration.mjs': "export default {components: './components'};\n",
|
|
1198
|
+
'components/AcmeCard.doc.mjs':
|
|
1199
|
+
"export default {type: 'component', name: 'AcmeCard', displayName: 'AcmeCard', description: 'Fixture.', props: []};\n",
|
|
1200
|
+
'components/AcmeCard.tsx': 'export default function AcmeCard() { return null; }\n',
|
|
1201
|
+
'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
|
|
1202
|
+
});
|
|
1203
|
+
expect(by['configured-integrations'].status).toBe('pass');
|
|
1204
|
+
expect(by['configured-integrations'].message).toBe(
|
|
1205
|
+
'1 integration named in astryx.config loaded: @acme/widgets.',
|
|
1206
|
+
);
|
|
1207
|
+
},
|
|
1208
|
+
SLOW,
|
|
1209
|
+
);
|
|
1210
|
+
|
|
1211
|
+
it(
|
|
1212
|
+
'fails when the package being authored is named by its own config and its manifest throws',
|
|
1213
|
+
async () => {
|
|
1214
|
+
const {by, summary} = await report({
|
|
1215
|
+
...CORE_STUB,
|
|
1216
|
+
'package.json': JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
|
|
1217
|
+
'astryx.integration.mjs': 'export default { not valid ((\n',
|
|
1218
|
+
'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
|
|
1219
|
+
});
|
|
1220
|
+
const check = by['configured-integrations'];
|
|
1221
|
+
expect(check.status).toBe('fail');
|
|
1222
|
+
expect(check.message).toMatch(
|
|
1223
|
+
/^1 of 1 integration named in astryx\.config could not be loaded, so it contributes nothing: @acme\/widgets \(/,
|
|
1224
|
+
);
|
|
1225
|
+
expect(summary.fail).toBe(1);
|
|
1226
|
+
},
|
|
1227
|
+
SLOW,
|
|
1228
|
+
);
|
|
1229
|
+
|
|
1230
|
+
it(
|
|
1231
|
+
'fails when node_modules links the configured name back to the authored package and its manifest throws',
|
|
1232
|
+
async () => {
|
|
1233
|
+
const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
|
|
1234
|
+
tmpDirs.push(dir);
|
|
1235
|
+
const files = {
|
|
1236
|
+
...CORE_STUB,
|
|
1237
|
+
'package.json': JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
|
|
1238
|
+
'astryx.integration.mjs': 'export default { not valid ((\n',
|
|
1239
|
+
'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
|
|
1240
|
+
};
|
|
1241
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
1242
|
+
const abs = path.join(dir, rel);
|
|
1243
|
+
fs.mkdirSync(path.dirname(abs), {recursive: true});
|
|
1244
|
+
fs.writeFileSync(abs, content);
|
|
1245
|
+
}
|
|
1246
|
+
fs.mkdirSync(path.join(dir, 'node_modules/@acme'), {recursive: true});
|
|
1247
|
+
fs.symlinkSync(dir, path.join(dir, 'node_modules/@acme/widgets'), 'dir');
|
|
1248
|
+
const {checks, summary} = (await doctor({cwd: dir})).data;
|
|
1249
|
+
const by = Object.fromEntries(checks.map(c => [c.id, c]));
|
|
1250
|
+
expect(by['configured-integrations'].status).toBe('fail');
|
|
1251
|
+
expect(by['configured-integrations'].message).toMatch(
|
|
1252
|
+
/^1 of 1 integration named in astryx\.config could not be loaded/,
|
|
1253
|
+
);
|
|
1254
|
+
expect(summary.fail).toBe(1);
|
|
1255
|
+
},
|
|
1256
|
+
SLOW,
|
|
1257
|
+
);
|
|
1258
|
+
|
|
1259
|
+
it(
|
|
1260
|
+
'fails for the self-linked authored package when the working directory is itself a symlink',
|
|
1261
|
+
async () => {
|
|
1262
|
+
const real = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
|
|
1263
|
+
tmpDirs.push(real);
|
|
1264
|
+
const linkParent = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
|
|
1265
|
+
tmpDirs.push(linkParent);
|
|
1266
|
+
const cwd = path.join(linkParent, 'link');
|
|
1267
|
+
fs.symlinkSync(real, cwd, 'dir');
|
|
1268
|
+
const files = {
|
|
1269
|
+
...CORE_STUB,
|
|
1270
|
+
'package.json': JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
|
|
1271
|
+
'astryx.integration.mjs': 'export default { not valid ((\n',
|
|
1272
|
+
'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
|
|
1273
|
+
};
|
|
1274
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
1275
|
+
const abs = path.join(real, rel);
|
|
1276
|
+
fs.mkdirSync(path.dirname(abs), {recursive: true});
|
|
1277
|
+
fs.writeFileSync(abs, content);
|
|
1278
|
+
}
|
|
1279
|
+
fs.mkdirSync(path.join(real, 'node_modules/@acme'), {recursive: true});
|
|
1280
|
+
fs.symlinkSync(real, path.join(real, 'node_modules/@acme/widgets'), 'dir');
|
|
1281
|
+
const {checks, summary} = (await doctor({cwd})).data;
|
|
1282
|
+
const by = Object.fromEntries(checks.map(c => [c.id, c]));
|
|
1283
|
+
expect(by['configured-integrations'].status).toBe('fail');
|
|
1284
|
+
expect(summary.fail).toBe(1);
|
|
1285
|
+
},
|
|
1286
|
+
SLOW,
|
|
1287
|
+
);
|
|
1288
|
+
|
|
1289
|
+
it(
|
|
1290
|
+
'still counts a configured package that was set aside for a provider conflict',
|
|
1291
|
+
async () => {
|
|
1292
|
+
const CHARTS = 'node_modules/@acme/charts';
|
|
1293
|
+
const {by} = await report({
|
|
1294
|
+
...APP,
|
|
1295
|
+
'astryx.config.mjs':
|
|
1296
|
+
"export default { integrations: ['@acme/widgets', '@acme/charts'] };\n",
|
|
1297
|
+
...widgets("export default {providerId: 'acme', components: './components'};\n"),
|
|
1298
|
+
[`${CHARTS}/package.json`]: JSON.stringify({name: '@acme/charts', version: '1.0.0'}),
|
|
1299
|
+
[`${CHARTS}/astryx.integration.mjs`]:
|
|
1300
|
+
"export default {providerId: 'acme', components: './components'};\n",
|
|
1301
|
+
[`${CHARTS}/components/AcmeChart.doc.mjs`]:
|
|
1302
|
+
"export default {type: 'component', name: 'AcmeChart', displayName: 'AcmeChart', description: 'Fixture.', props: []};\n",
|
|
1303
|
+
[`${CHARTS}/components/AcmeChart.tsx`]: 'export default function AcmeChart() { return null; }\n',
|
|
1304
|
+
});
|
|
1305
|
+
expect(by['configured-integrations'].status).toBe('pass');
|
|
1306
|
+
expect(by['configured-integrations'].message).toMatch(/^2 integrations named in astryx\.config loaded: /);
|
|
1307
|
+
expect(by['configured-integrations'].message).toContain('@acme/charts');
|
|
1308
|
+
},
|
|
1309
|
+
SLOW,
|
|
1310
|
+
);
|
|
1311
|
+
|
|
1312
|
+
it(
|
|
1313
|
+
'passes, naming each one, when every configured integration loads',
|
|
1314
|
+
async () => {
|
|
1315
|
+
const {by, summary} = await report({...APP, ...widgets()});
|
|
1316
|
+
expect(by['configured-integrations']).toEqual({
|
|
1317
|
+
id: 'configured-integrations',
|
|
1318
|
+
label: 'Configured integrations',
|
|
1319
|
+
status: 'pass',
|
|
1320
|
+
message: '1 integration named in astryx.config loaded: @acme/widgets.',
|
|
1321
|
+
});
|
|
1322
|
+
expect(summary.fail).toBe(0);
|
|
1323
|
+
},
|
|
1324
|
+
SLOW,
|
|
1325
|
+
);
|
|
1326
|
+
|
|
1327
|
+
it.each([
|
|
1328
|
+
[
|
|
1329
|
+
'an invalid component doc',
|
|
1330
|
+
{[`${WIDGETS}/components/AcmeCard.doc.mjs`]: 'export default {;\n'},
|
|
1331
|
+
],
|
|
1332
|
+
[
|
|
1333
|
+
'a declared root missing on disk',
|
|
1334
|
+
{
|
|
1335
|
+
[`${WIDGETS}/astryx.integration.mjs`]:
|
|
1336
|
+
"export default {components: './components', templates: './templates'};\n",
|
|
1337
|
+
},
|
|
1338
|
+
],
|
|
1339
|
+
])(
|
|
1340
|
+
'keeps %s a warning, because the rest of the integration still loads (spec:AST-035 FR9)',
|
|
1341
|
+
async (_shape, extra) => {
|
|
1342
|
+
const {by, summary} = await report({...APP, ...widgets(), ...extra});
|
|
1343
|
+
expect(by['configured-integrations'].status).toBe('pass');
|
|
1344
|
+
expect(by['integration-issues'].status).toBe('warn');
|
|
1345
|
+
expect(summary.fail).toBe(0);
|
|
1346
|
+
},
|
|
1347
|
+
SLOW,
|
|
1348
|
+
);
|
|
1349
|
+
|
|
1350
|
+
it(
|
|
1351
|
+
'leaves an autolinked dependency that cannot load informational',
|
|
1352
|
+
async () => {
|
|
1353
|
+
const {by, summary} = await report({
|
|
1354
|
+
'package.json': JSON.stringify({
|
|
1355
|
+
name: 'app',
|
|
1356
|
+
dependencies: {'@acme/widgets': '1.0.0'},
|
|
1357
|
+
}),
|
|
1358
|
+
...CORE_STUB,
|
|
1359
|
+
...widgets('export default { not valid ((\n'),
|
|
1360
|
+
});
|
|
1361
|
+
expect(by['configured-integrations']).toMatchObject({
|
|
1362
|
+
status: 'info',
|
|
1363
|
+
message: 'No integration is named in astryx.config.',
|
|
1364
|
+
});
|
|
1365
|
+
expect(by['implicit-integrations'].status).toBe('info');
|
|
1366
|
+
expect(summary.fail).toBe(0);
|
|
1367
|
+
},
|
|
1368
|
+
SLOW,
|
|
1369
|
+
);
|
|
1370
|
+
});
|
|
1371
|
+
|
|
1126
1372
|
describe('no Astryx-owned environment variables (spec:AST-017 FR14)', () => {
|
|
1127
1373
|
it('no source file reads an ASTRYX_* env var', () => {
|
|
1128
1374
|
const cliDir = path.resolve(REPO, 'packages/cli');
|
|
@@ -31,6 +31,7 @@ const registry = new Map([
|
|
|
31
31
|
['0.6.0', () => import('./transforms/v0.6.0/index.mjs')],
|
|
32
32
|
['0.6.4', () => import('./transforms/v0.6.4/index.mjs')],
|
|
33
33
|
['0.6.7', () => import('./transforms/v0.6.7/index.mjs')],
|
|
34
|
+
['0.7.0', () => import('./transforms/v0.7.0/index.mjs')],
|
|
34
35
|
]);
|
|
35
36
|
|
|
36
37
|
// Re-export from the shared utility so registry callers and other consumers
|
|
@@ -7,30 +7,4 @@
|
|
|
7
7
|
* this file into the resolved version folder.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
meta as migrateDeprecatedThemeSurfaceMeta,
|
|
12
|
-
} from './migrate-deprecated-theme-surface.mjs';
|
|
13
|
-
import migrateFieldInputStyling, {
|
|
14
|
-
meta as migrateFieldInputStylingMeta,
|
|
15
|
-
} from './migrate-field-input-styling.mjs';
|
|
16
|
-
import validateDataTokenOwnership, {
|
|
17
|
-
meta as validateDataTokenOwnershipMeta,
|
|
18
|
-
} from './validate-data-token-ownership.mjs';
|
|
19
|
-
|
|
20
|
-
export default [
|
|
21
|
-
{
|
|
22
|
-
name: 'migrate-deprecated-theme-surface',
|
|
23
|
-
transform: migrateDeprecatedThemeSurface,
|
|
24
|
-
meta: migrateDeprecatedThemeSurfaceMeta,
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'validate-data-token-ownership',
|
|
28
|
-
transform: validateDataTokenOwnership,
|
|
29
|
-
meta: validateDataTokenOwnershipMeta,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: 'migrate-field-input-styling',
|
|
33
|
-
transform: migrateFieldInputStyling,
|
|
34
|
-
meta: migrateFieldInputStylingMeta,
|
|
35
|
-
},
|
|
36
|
-
];
|
|
10
|
+
export default [];
|
package/assets/codemods/transforms/v0.7.0/__tests__/preserve-bottom-sheet-content-padding.test.mjs
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import transform from '../preserve-bottom-sheet-content-padding.mjs';
|
|
5
|
+
|
|
6
|
+
async function applyTransform(source) {
|
|
7
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
8
|
+
const j = jscodeshift.withParser('tsx');
|
|
9
|
+
const api = {jscodeshift: j, stats: () => {}, report: () => {}};
|
|
10
|
+
return transform({source, path: 'test.tsx'}, api) ?? source;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe('preserve-bottom-sheet-content-padding', () => {
|
|
14
|
+
it('adds padding={0} to a sheet with self-padded content', async () => {
|
|
15
|
+
const output =
|
|
16
|
+
await applyTransform(`import {BottomSheet, VStack} from '@astryxdesign/core';
|
|
17
|
+
const a = (
|
|
18
|
+
<BottomSheet isOpen={isOpen} onOpenChange={setIsOpen} label="Filters">
|
|
19
|
+
<VStack gap={4} padding={4}>x</VStack>
|
|
20
|
+
</BottomSheet>
|
|
21
|
+
);`);
|
|
22
|
+
|
|
23
|
+
expect(output).toContain(
|
|
24
|
+
'<BottomSheet isOpen={isOpen} onOpenChange={setIsOpen} label="Filters" padding={0}>',
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('leaves a sheet whose only child is a core Section unchanged', async () => {
|
|
29
|
+
const source = `import {BottomSheet, Section, VStack} from '@astryxdesign/core';
|
|
30
|
+
const a = (
|
|
31
|
+
<BottomSheet isOpen onOpenChange={() => {}} label="Filters">
|
|
32
|
+
{/* filters */}
|
|
33
|
+
<Section padding={4}>
|
|
34
|
+
<VStack gap={4}>x</VStack>
|
|
35
|
+
</Section>
|
|
36
|
+
</BottomSheet>
|
|
37
|
+
);`;
|
|
38
|
+
expect(await applyTransform(source)).toBe(source);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('leaves a sheet whose only child is a core Layout unchanged', async () => {
|
|
42
|
+
const source = `import {BottomSheet, Layout, LayoutContent} from '@astryxdesign/core';
|
|
43
|
+
const a = (
|
|
44
|
+
<BottomSheet isOpen onOpenChange={() => {}} label="Message">
|
|
45
|
+
<Layout content={<LayoutContent>x</LayoutContent>} />
|
|
46
|
+
</BottomSheet>
|
|
47
|
+
);`;
|
|
48
|
+
expect(await applyTransform(source)).toBe(source);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('flags every nested Layout with a TODO, with or without its own padding', async () => {
|
|
52
|
+
const output =
|
|
53
|
+
await applyTransform(`import {BottomSheet, Layout, VStack} from '@astryxdesign/core';
|
|
54
|
+
function A() {
|
|
55
|
+
return (
|
|
56
|
+
<BottomSheet sheetId="a" label="A">
|
|
57
|
+
<VStack>
|
|
58
|
+
<Layout content={x} />
|
|
59
|
+
</VStack>
|
|
60
|
+
</BottomSheet>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function B() {
|
|
64
|
+
return (
|
|
65
|
+
<BottomSheet sheetId="b" label="B">
|
|
66
|
+
<VStack>
|
|
67
|
+
<Layout padding={4} content={x} />
|
|
68
|
+
</VStack>
|
|
69
|
+
</BottomSheet>
|
|
70
|
+
);
|
|
71
|
+
}`);
|
|
72
|
+
|
|
73
|
+
expect(output).toContain('<BottomSheet sheetId="a" label="A" padding={0}>');
|
|
74
|
+
expect(output).toContain('<BottomSheet sheetId="b" label="B" padding={0}>');
|
|
75
|
+
expect(output.match(/TODO\(astryx upgrade\)/g)).toHaveLength(2);
|
|
76
|
+
expect(output.indexOf('TODO(astryx upgrade)')).toBeLessThan(
|
|
77
|
+
output.indexOf('sheetId="a"'),
|
|
78
|
+
);
|
|
79
|
+
expect(output.indexOf('TODO(astryx upgrade)')).toBeGreaterThan(
|
|
80
|
+
output.indexOf('function A'),
|
|
81
|
+
);
|
|
82
|
+
expect(output.lastIndexOf('TODO(astryx upgrade)')).toBeGreaterThan(
|
|
83
|
+
output.indexOf('function B'),
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('does not flag a Layout from another package or a shadowed Layout binding', async () => {
|
|
88
|
+
const output =
|
|
89
|
+
await applyTransform(`import {BottomSheet} from '@astryxdesign/core';
|
|
90
|
+
import {Layout} from './my-layout';
|
|
91
|
+
export function A() {
|
|
92
|
+
return <BottomSheet isOpen><Layout content={<p>b</p>} /></BottomSheet>;
|
|
93
|
+
}
|
|
94
|
+
`);
|
|
95
|
+
expect(output).toContain('padding={0}');
|
|
96
|
+
expect(output).not.toContain('TODO');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('leaves a BottomSheet that a parameter or local binding shadows alone', async () => {
|
|
100
|
+
const source = `import {BottomSheet} from '@astryxdesign/core';
|
|
101
|
+
export function Host({BottomSheet: Sheet}) {
|
|
102
|
+
return <Sheet isOpen><p>own inset</p></Sheet>;
|
|
103
|
+
}
|
|
104
|
+
export function Local() {
|
|
105
|
+
const BottomSheet = (props) => <div {...props} />;
|
|
106
|
+
return <BottomSheet isOpen><p>own inset</p></BottomSheet>;
|
|
107
|
+
}
|
|
108
|
+
`;
|
|
109
|
+
expect(await applyTransform(source)).toBe(source);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('is idempotent: a second run changes nothing', async () => {
|
|
113
|
+
const once =
|
|
114
|
+
await applyTransform(`import {BottomSheet, Layout, VStack} from '@astryxdesign/core';
|
|
115
|
+
export function A() {
|
|
116
|
+
return <BottomSheet isOpen><VStack><p>a</p></VStack></BottomSheet>;
|
|
117
|
+
}
|
|
118
|
+
export function B() {
|
|
119
|
+
return <BottomSheet isOpen><VStack><Layout content={<p>b</p>} /></VStack></BottomSheet>;
|
|
120
|
+
}
|
|
121
|
+
`);
|
|
122
|
+
expect(await applyTransform(once)).toBe(once);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('pads a sheet when the Section has a sibling or is not from core', async () => {
|
|
126
|
+
const output =
|
|
127
|
+
await applyTransform(`import {BottomSheet} from '@astryxdesign/core';
|
|
128
|
+
import {Section} from './local';
|
|
129
|
+
import {Section as CoreSection} from '@astryxdesign/core';
|
|
130
|
+
const a = <BottomSheet sheetId="a" label="A"><Section>x</Section></BottomSheet>;
|
|
131
|
+
const b = (
|
|
132
|
+
<BottomSheet sheetId="b" label="B">
|
|
133
|
+
<CoreSection>x</CoreSection>
|
|
134
|
+
<p>after</p>
|
|
135
|
+
</BottomSheet>
|
|
136
|
+
);`);
|
|
137
|
+
|
|
138
|
+
expect(output).toContain('<BottomSheet sheetId="a" label="A" padding={0}>');
|
|
139
|
+
expect(output).toContain('<BottomSheet sheetId="b" label="B" padding={0}>');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('leaves a sheet that already sets padding unchanged', async () => {
|
|
143
|
+
const source = `import {BottomSheet} from '@astryxdesign/core';
|
|
144
|
+
const a = <BottomSheet sheetId="a" label="A" padding={2}>x</BottomSheet>;
|
|
145
|
+
const b = <BottomSheet sheetId="b" label="B" padding={value}>x</BottomSheet>;`;
|
|
146
|
+
expect(await applyTransform(source)).toBe(source);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('follows aliases, subpath default imports, and namespace imports', async () => {
|
|
150
|
+
const output =
|
|
151
|
+
await applyTransform(`import {BottomSheet as Sheet} from '@astryxdesign/core';
|
|
152
|
+
import Panel from '@astryxdesign/core/BottomSheet';
|
|
153
|
+
import * as Core from '@astryxdesign/core';
|
|
154
|
+
const a = <Sheet sheetId="a" label="A">x</Sheet>;
|
|
155
|
+
const b = <Panel sheetId="b" label="B">x</Panel>;
|
|
156
|
+
const c = <Core.BottomSheet sheetId="c" label="C">x</Core.BottomSheet>;`);
|
|
157
|
+
|
|
158
|
+
expect(output).toContain('<Sheet sheetId="a" label="A" padding={0}>');
|
|
159
|
+
expect(output).toContain('<Panel sheetId="b" label="B" padding={0}>');
|
|
160
|
+
expect(output).toContain(
|
|
161
|
+
'<Core.BottomSheet sheetId="c" label="C" padding={0}>',
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('puts padding={0} before a spread so a spread padding still wins', async () => {
|
|
166
|
+
const output =
|
|
167
|
+
await applyTransform(`import {BottomSheet} from '@astryxdesign/core';
|
|
168
|
+
const a = <BottomSheet label="A" {...args} />;`);
|
|
169
|
+
|
|
170
|
+
expect(output).toContain('<BottomSheet label="A" padding={0} {...args} />');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('ignores BottomSheet from other packages', async () => {
|
|
174
|
+
const source = `import {BottomSheet} from './prototype';
|
|
175
|
+
const a = <BottomSheet title="A">x</BottomSheet>;`;
|
|
176
|
+
expect(await applyTransform(source)).toBe(source);
|
|
177
|
+
});
|
|
178
|
+
});
|