@astryxdesign/cli 0.1.1 → 0.1.2-canary.043f3fd
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 +50 -0
- package/docs/theme.doc.mjs +2 -2
- package/docs/working-with-ai.doc.mjs +6 -6
- package/package.json +31 -8
- package/src/api/component.mjs +253 -12
- package/src/api/discover.mjs +87 -28
- package/src/api/doctor.mjs +7 -22
- package/src/api/index.mjs +1 -0
- package/src/api/layout.mjs +302 -0
- package/src/api/layout.test.mjs +241 -0
- package/src/api/template-integration.test.mjs +225 -0
- package/src/api/template.mjs +421 -122
- package/src/api/template.test.mjs +2 -0
- package/src/api/theme-add.mjs +182 -0
- package/src/api/validate-integration.mjs +370 -0
- package/src/api/validate-integration.test.mjs +222 -0
- package/src/codemod.mjs +93 -0
- package/src/codemod.test.mjs +134 -0
- package/src/codemods/__tests__/registry.test.mjs +2 -0
- package/src/codemods/__tests__/runner.test.mjs +103 -0
- package/src/codemods/integration-discovery.mjs +168 -0
- package/src/codemods/integration-discovery.test.mjs +234 -0
- package/src/codemods/integration-runner.mjs +109 -0
- package/src/codemods/registry.mjs +2 -0
- package/src/codemods/run-codemod.mjs +207 -0
- package/src/codemods/runner.mjs +73 -96
- package/src/codemods/transforms/v0.0.15/index.mjs +0 -13
- package/src/codemods/transforms/v0.1.0/__tests__/v0.1.0-ordering.test.mjs +81 -0
- package/src/codemods/transforms/{v0.0.15 → v0.1.0}/drop-xds-prefix-imports.mjs +15 -4
- package/src/codemods/transforms/v0.1.0/index.mjs +15 -6
- package/src/codemods/transforms/v0.1.2/__tests__/rename-text-color-active-to-accent.test.mjs +120 -0
- package/src/codemods/transforms/v0.1.2/index.mjs +19 -0
- package/src/codemods/transforms/v0.1.2/rename-text-color-active-to-accent.mjs +136 -0
- package/src/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +360 -0
- package/src/codemods/transforms/v0.1.3/index.mjs +19 -0
- package/src/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +260 -0
- package/src/commands/build-theme.import-path.test.mjs +22 -2
- package/src/commands/build-theme.mjs +185 -16
- package/src/commands/component/index.mjs +44 -10
- package/src/commands/component-ownership.test.mjs +227 -0
- package/src/commands/discover.mjs +5 -16
- package/src/commands/doctor.test.mjs +3 -3
- package/src/commands/init.mjs +34 -8
- package/src/commands/init.next-steps.test.mjs +46 -0
- package/src/commands/json-contract.test.mjs +0 -32
- package/src/commands/layout.mjs +139 -0
- package/src/commands/swizzle.mjs +241 -224
- package/src/commands/swizzle.path-safety.test.mjs +3 -3
- package/src/commands/swizzle.routing.test.mjs +279 -0
- package/src/commands/template.mjs +33 -37
- package/src/commands/upgrade.config-ordering.test.mjs +273 -0
- package/src/commands/upgrade.integration-policy.test.mjs +204 -0
- package/src/commands/upgrade.mjs +349 -239
- package/src/commands/validate-integration.mjs +110 -0
- package/src/commands/validate-integration.test.mjs +124 -0
- package/src/config.mjs +18 -0
- package/src/config.test.mjs +100 -0
- package/src/index.mjs +13 -3
- package/src/integration.mjs +19 -0
- package/src/lib/component-discovery.mjs +177 -0
- package/src/lib/config-cache.mjs +91 -0
- package/src/lib/config-cache.test.mjs +83 -0
- package/src/lib/config-schema.mjs +105 -0
- package/src/lib/error-codes.mjs +18 -12
- package/src/lib/integration-warnings.mjs +62 -0
- package/src/lib/integration-warnings.test.mjs +102 -0
- package/src/lib/integrations.mjs +132 -0
- package/src/lib/integrations.test.mjs +135 -0
- package/src/lib/levenshtein.mjs +29 -0
- package/src/lib/manifest.mjs +15 -2
- package/src/lib/module-loader.mjs +80 -0
- package/src/lib/module-loader.test.mjs +106 -0
- package/src/lib/package-scanner.mjs +31 -7
- package/src/lib/project.mjs +502 -0
- package/src/lib/project.test.mjs +308 -0
- package/src/lib/string-utils.mjs +5 -14
- package/src/lib/xle/browser.d.ts +100 -0
- package/src/lib/xle/browser.mjs +120 -0
- package/src/lib/xle/expand.mjs +622 -0
- package/src/lib/xle/parse.mjs +581 -0
- package/src/lib/xle/print.mjs +174 -0
- package/src/lib/xle/registry-core.mjs +170 -0
- package/src/lib/xle/registry.mjs +237 -0
- package/src/lib/xle/splice.mjs +137 -0
- package/src/lib/xle/validate.mjs +356 -0
- package/src/lib/xle/xle.test.mjs +333 -0
- package/src/template.mjs +73 -0
- package/src/template.test.mjs +127 -0
- package/src/types/api.d.ts +2 -6
- package/src/types/base.d.ts +3 -9
- package/src/types/codemod.d.ts +81 -0
- package/src/types/component.d.ts +27 -2
- package/src/types/config.d.ts +70 -0
- package/src/types/error-codes.d.ts +5 -3
- package/src/types/index.d.ts +0 -1
- package/src/types/integration.d.ts +29 -0
- package/src/types/swizzle.d.ts +9 -2
- package/src/types/template-api.d.ts +54 -0
- package/src/types/template.d.ts +10 -7
- package/src/types/upgrade.d.ts +29 -0
- package/src/types/validate-integration.d.ts +24 -0
- package/src/utils/github.mjs +0 -252
- package/src/utils/interactive.mjs +2 -2
- package/templates/blocks/components/Card/ClickableCardWithNestedButton.doc.mjs +1 -1
- package/templates/blocks/components/Card/SelectableCardMulti.doc.mjs +1 -1
- package/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerWithProgress.tsx +1 -1
- package/templates/blocks/components/ChatDictationButton/ChatDictationButtonShowcase.tsx +3 -3
- package/templates/blocks/components/CommandPaletteEmpty/CommandPaletteEmptyShowcase.doc.mjs +15 -0
- package/templates/blocks/components/CommandPaletteEmpty/CommandPaletteEmptyShowcase.tsx +26 -0
- package/templates/blocks/components/DateInput/DateInputDateRange.doc.mjs +2 -2
- package/templates/blocks/components/DateRangeInput/DateRangeInputWithPresets.doc.mjs +14 -0
- package/templates/blocks/components/DateRangeInput/DateRangeInputWithPresets.tsx +46 -0
- package/templates/blocks/components/DateRangeInput/DateRangeInputWithValidation.doc.mjs +14 -0
- package/templates/blocks/components/DateRangeInput/DateRangeInputWithValidation.tsx +52 -0
- package/templates/blocks/components/DateTimeInput/DateTimeInputWithValidation.doc.mjs +14 -0
- package/templates/blocks/components/DateTimeInput/DateTimeInputWithValidation.tsx +43 -0
- package/templates/blocks/components/FileInput/FileInputShowcase.tsx +4 -2
- package/templates/blocks/components/HoverCard/HoverCardInteractiveContent.doc.mjs +1 -1
- package/templates/blocks/components/HoverCard/HoverCardInteractiveContent.tsx +9 -4
- package/templates/blocks/components/LinkProvider/LinkProviderCustomLink.doc.mjs +14 -0
- package/templates/blocks/components/LinkProvider/LinkProviderCustomLink.tsx +43 -0
- package/templates/blocks/components/MultiSelector/MultiSelectorShowcase.tsx +6 -2
- package/templates/blocks/components/NumberInput/NumberInputShowcase.tsx +6 -2
- package/templates/blocks/components/Outline/OutlineShowcase.doc.mjs +15 -0
- package/templates/blocks/components/Outline/OutlineShowcase.tsx +22 -0
- package/templates/blocks/components/RadioList/RadioListShowcase.tsx +8 -1
- package/templates/blocks/components/SegmentedControl/SegmentedControlShowcase.tsx +3 -1
- package/templates/blocks/components/Selector/SelectorShowcase.tsx +4 -1
- package/templates/blocks/components/Slider/SliderShowcase.tsx +10 -1
- package/templates/blocks/components/Tab/TabShowcase.tsx +3 -1
- package/templates/blocks/components/Tab/TabWithSelectedIcon.doc.mjs +13 -0
- package/templates/blocks/components/Tab/TabWithSelectedIcon.tsx +39 -0
- package/templates/blocks/components/TabList/TabListShowcase.tsx +3 -1
- package/templates/blocks/components/TabMenu/TabMenuShowcase.tsx +3 -1
- package/templates/blocks/components/Table/ColumnResizeHookUsage.doc.mjs +14 -0
- package/templates/blocks/components/Table/ColumnResizeHookUsage.tsx +59 -0
- package/templates/blocks/components/Table/StickyColumnsHookUsage.doc.mjs +14 -0
- package/templates/blocks/components/Table/StickyColumnsHookUsage.tsx +104 -0
- package/templates/blocks/components/Text/TextColors.tsx +20 -5
- package/templates/blocks/components/TextArea/TextAreaShowcase.tsx +4 -2
- package/templates/blocks/components/TextInput/TextInputShowcase.tsx +4 -2
- package/templates/blocks/components/Thumbnail/ThumbnailDisabled.tsx +11 -6
- package/templates/blocks/components/Thumbnail/ThumbnailGallery.tsx +43 -7
- package/templates/blocks/components/Thumbnail/ThumbnailRemovable.tsx +40 -3
- package/templates/blocks/components/Thumbnail/ThumbnailShowcase.tsx +6 -5
- package/templates/blocks/components/Thumbnail/ThumbnailStates.tsx +11 -6
- package/templates/blocks/components/Timestamp/TimestampColors.tsx +2 -2
- package/templates/blocks/components/ToggleButton/ToggleButtonGroup.doc.mjs +1 -1
- package/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +8 -6
- package/templates/blocks/components/Toolbar/ToolbarTableFilter.doc.mjs +2 -2
- package/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +23 -14
- package/templates/blocks/components/Typeahead/TypeaheadShowcase.tsx +6 -2
- package/templates/pages/shell-nav/page.tsx +321 -0
- package/templates/pages/shell-nav/template.doc.mjs +12 -0
- package/templates/pages/shell-side-nav/page.tsx +242 -0
- package/templates/pages/shell-side-nav/template.doc.mjs +12 -0
- package/templates/pages/shell-top-nav/page.tsx +224 -0
- package/templates/pages/shell-top-nav/template.doc.mjs +12 -0
- package/templates/pages/theme-showcase/page.tsx +8 -19
- package/templates/themes/butter/butterTheme.ts +916 -0
- package/templates/themes/butter/icons.tsx +77 -0
- package/templates/themes/chocolate/chocolateTheme.ts +230 -0
- package/templates/themes/chocolate/icons.tsx +77 -0
- package/templates/themes/gothic/gothicTheme.ts +657 -0
- package/templates/themes/gothic/icons.tsx +77 -0
- package/templates/themes/manifest.json +90 -0
- package/templates/themes/matcha/icons.tsx +67 -0
- package/templates/themes/matcha/matchaTheme.ts +247 -0
- package/templates/themes/neutral/icons.tsx +77 -0
- package/templates/themes/neutral/neutralTheme.ts +603 -0
- package/templates/themes/stone/icons.tsx +77 -0
- package/templates/themes/stone/stoneTheme.ts +652 -0
- package/templates/themes/y2k/icons.tsx +67 -0
- package/templates/themes/y2k/y2kTheme.ts +617 -0
- package/src/codemods/transforms/v0.1.0/__tests__/migrate-xds-config-surfaces.test.mjs +0 -116
- package/src/codemods/transforms/v0.1.0/migrate-xds-config-surfaces.mjs +0 -230
- package/src/commands/gap-report.mjs +0 -456
- package/src/commands/gap-report.test.mjs +0 -163
- package/src/commands/swizzle-gap-safety.test.mjs +0 -273
- package/src/lib/config.mjs +0 -86
- package/src/lib/config.test.mjs +0 -42
- package/src/types/gap-report.d.ts +0 -29
- package/templates/blocks/components/MoreMenu/MoreMenuInToolbar.doc.mjs +0 -14
- package/templates/blocks/components/MoreMenu/MoreMenuInToolbar.tsx +0 -57
- /package/src/codemods/transforms/{v0.0.15 → v0.1.0}/__tests__/drop-xds-prefix-imports.test.mjs +0 -0
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
import {describe, it, expect} from 'vitest';
|
|
4
|
-
|
|
5
|
-
async function applyConfigCodemod(files) {
|
|
6
|
-
const {default: transform} =
|
|
7
|
-
await import('../migrate-xds-config-surfaces.mjs');
|
|
8
|
-
const config = {
|
|
9
|
-
packageJson: files['package.json']
|
|
10
|
-
? {path: 'package.json', source: files['package.json']}
|
|
11
|
-
: null,
|
|
12
|
-
astryxConfig: files['astryx.config.mjs']
|
|
13
|
-
? {path: 'astryx.config.mjs', source: files['astryx.config.mjs']}
|
|
14
|
-
: null,
|
|
15
|
-
xdsConfig: files['xds.config.mjs']
|
|
16
|
-
? {path: 'xds.config.mjs', source: files['xds.config.mjs']}
|
|
17
|
-
: null,
|
|
18
|
-
};
|
|
19
|
-
return transform({path: process.cwd(), source: ''}, {config});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
describe('migrate-xds-config-surfaces', () => {
|
|
23
|
-
it('extracts package.json xds config into astryx.config.mjs and removes the package key in place', async () => {
|
|
24
|
-
const input = `{
|
|
25
|
-
"dependencies": {"@xds/core":"^0.0.15"},
|
|
26
|
-
"xds" : {"theme":"neutral","docs":"./src"}
|
|
27
|
-
}
|
|
28
|
-
`;
|
|
29
|
-
|
|
30
|
-
const result = await applyConfigCodemod({'package.json': input});
|
|
31
|
-
expect(result.errors ?? []).toEqual([]);
|
|
32
|
-
expect(result.changes).toEqual([
|
|
33
|
-
{
|
|
34
|
-
path: 'package.json',
|
|
35
|
-
source: `{
|
|
36
|
-
"dependencies": {"@xds/core":"^0.0.15"}
|
|
37
|
-
}
|
|
38
|
-
`,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
path: 'astryx.config.mjs',
|
|
42
|
-
source: `export default {
|
|
43
|
-
"theme": "neutral",
|
|
44
|
-
"docs": "./src"
|
|
45
|
-
};
|
|
46
|
-
`,
|
|
47
|
-
},
|
|
48
|
-
]);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('extracts package.json astryx config into astryx.config.mjs too', async () => {
|
|
52
|
-
const result = await applyConfigCodemod({
|
|
53
|
-
'package.json': `{"astryx":{"theme":"neutral"}}\n`,
|
|
54
|
-
});
|
|
55
|
-
expect(result.changes).toEqual([
|
|
56
|
-
{path: 'package.json', source: `{}\n`},
|
|
57
|
-
{
|
|
58
|
-
path: 'astryx.config.mjs',
|
|
59
|
-
source: `export default {
|
|
60
|
-
"theme": "neutral"
|
|
61
|
-
};
|
|
62
|
-
`,
|
|
63
|
-
},
|
|
64
|
-
]);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('bails when package.json contains both xds and astryx config keys', async () => {
|
|
68
|
-
const result = await applyConfigCodemod({
|
|
69
|
-
'package.json': `{"xds":{"theme":"default"},"astryx":{"theme":"neutral"}}\n`,
|
|
70
|
-
});
|
|
71
|
-
expect(result.errors?.[0]?.error).toMatch(/both xds and astryx/);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('does not rewrite dependency keys in package.json', async () => {
|
|
75
|
-
const input = `{"dependencies":{"@xds/core":"^0.0.15"}}\n`;
|
|
76
|
-
const result = await applyConfigCodemod({'package.json': input});
|
|
77
|
-
expect(result.changes).toEqual([]);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('bails when package config and astryx.config.mjs both exist', async () => {
|
|
81
|
-
const result = await applyConfigCodemod({
|
|
82
|
-
'package.json': `{"xds":{"theme":"neutral"}}\n`,
|
|
83
|
-
'astryx.config.mjs': `export default {};\n`,
|
|
84
|
-
});
|
|
85
|
-
expect(result.errors?.[0]?.error).toMatch(/migrate the config manually/);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('bails when package config and xds.config.mjs both exist', async () => {
|
|
89
|
-
const result = await applyConfigCodemod({
|
|
90
|
-
'package.json': `{"xds":{"theme":"neutral"}}\n`,
|
|
91
|
-
'xds.config.mjs': `export default {};\n`,
|
|
92
|
-
});
|
|
93
|
-
expect(result.errors?.[0]?.error).toMatch(/migrate the config manually/);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('renames xds.config.mjs to astryx.config.mjs when no package config exists', async () => {
|
|
97
|
-
const result = await applyConfigCodemod({
|
|
98
|
-
'xds.config.mjs': "export default { theme: 'neutral' };\n",
|
|
99
|
-
});
|
|
100
|
-
expect(result.changes).toEqual([
|
|
101
|
-
{
|
|
102
|
-
path: 'astryx.config.mjs',
|
|
103
|
-
source: "export default { theme: 'neutral' };\n",
|
|
104
|
-
},
|
|
105
|
-
{path: 'xds.config.mjs', delete: true},
|
|
106
|
-
]);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('bails when xds.config.mjs and astryx.config.mjs both exist', async () => {
|
|
110
|
-
const result = await applyConfigCodemod({
|
|
111
|
-
'xds.config.mjs': `export default {};\n`,
|
|
112
|
-
'astryx.config.mjs': `export default {};\n`,
|
|
113
|
-
});
|
|
114
|
-
expect(result.errors?.[0]?.error).toMatch(/migrate the config manually/);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file Codemod: migrate XDS config surfaces to Astryx v0.1.0
|
|
5
|
-
*
|
|
6
|
-
* The v0.1.0 CLI reads astryx.config.mjs. This config codemod migrates
|
|
7
|
-
* legacy xds.config.mjs and package.json's top-level `xds` config without
|
|
8
|
-
* changing dependency names or versions.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export const meta = {
|
|
12
|
-
title: 'Migrate xds config surfaces to astryx',
|
|
13
|
-
description:
|
|
14
|
-
'Moves legacy package.json xds config into astryx.config.mjs, or renames ' +
|
|
15
|
-
'xds.config.mjs when no package.json config exists. Bails out if both exist.',
|
|
16
|
-
pr: '#3092',
|
|
17
|
-
codemodType: 'config',
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
function findTopLevelKey(source, targetKey) {
|
|
21
|
-
let depth = 0;
|
|
22
|
-
let inString = false;
|
|
23
|
-
let escaped = false;
|
|
24
|
-
let stringStart = -1;
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < source.length; i++) {
|
|
27
|
-
const ch = source[i];
|
|
28
|
-
|
|
29
|
-
if (inString) {
|
|
30
|
-
if (escaped) {
|
|
31
|
-
escaped = false;
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (ch === '\\') {
|
|
35
|
-
escaped = true;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (ch !== '"') continue;
|
|
39
|
-
|
|
40
|
-
inString = false;
|
|
41
|
-
const rawKey = source.slice(stringStart + 1, i);
|
|
42
|
-
if (depth !== 1 || rawKey !== targetKey) continue;
|
|
43
|
-
|
|
44
|
-
let j = i + 1;
|
|
45
|
-
while (/\s/.test(source[j] ?? '')) j++;
|
|
46
|
-
if (source[j] !== ':') continue;
|
|
47
|
-
|
|
48
|
-
const valueStart = j + 1;
|
|
49
|
-
const value = readJsonValue(source, valueStart);
|
|
50
|
-
if (!value) return null;
|
|
51
|
-
return {keyStart: stringStart, keyEnd: i + 1, colon: j, ...value};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (ch === '"') {
|
|
55
|
-
inString = true;
|
|
56
|
-
stringStart = i;
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (ch === '{' || ch === '[') depth++;
|
|
60
|
-
else if (ch === '}' || ch === ']') depth--;
|
|
61
|
-
}
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function readJsonValue(source, start) {
|
|
66
|
-
let i = start;
|
|
67
|
-
while (/\s/.test(source[i] ?? '')) i++;
|
|
68
|
-
const valueStart = i;
|
|
69
|
-
let inString = false;
|
|
70
|
-
let escaped = false;
|
|
71
|
-
let depth = 0;
|
|
72
|
-
|
|
73
|
-
for (; i < source.length; i++) {
|
|
74
|
-
const ch = source[i];
|
|
75
|
-
if (inString) {
|
|
76
|
-
if (escaped) {
|
|
77
|
-
escaped = false;
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
if (ch === '\\') {
|
|
81
|
-
escaped = true;
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
if (ch === '"') inString = false;
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
if (ch === '"') {
|
|
88
|
-
inString = true;
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
if (ch === '{' || ch === '[') {
|
|
92
|
-
depth++;
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
if (ch === '}' || ch === ']') {
|
|
96
|
-
if (depth === 0) break;
|
|
97
|
-
depth--;
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
if (depth === 0 && ch === ',') break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const valueEnd = i;
|
|
104
|
-
const rawValue = source.slice(valueStart, valueEnd).trim();
|
|
105
|
-
try {
|
|
106
|
-
JSON.parse(rawValue);
|
|
107
|
-
} catch {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
return {valueStart, valueEnd, rawValue, terminator: source[i]};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function removeTopLevelProperty(source, property) {
|
|
114
|
-
let removeStart = property.keyStart;
|
|
115
|
-
let removeEnd = property.valueEnd;
|
|
116
|
-
|
|
117
|
-
if (source[removeEnd] === ',') {
|
|
118
|
-
removeEnd++;
|
|
119
|
-
if (source[removeEnd] === '\n') removeEnd++;
|
|
120
|
-
return source.slice(0, removeStart) + source.slice(removeEnd);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
let i = removeStart - 1;
|
|
124
|
-
while (/\s/.test(source[i] ?? '')) i--;
|
|
125
|
-
if (source[i] === ',') {
|
|
126
|
-
const whitespaceBetweenCommaAndKey = source.slice(i + 1, removeStart);
|
|
127
|
-
const preservedWhitespace = whitespaceBetweenCommaAndKey.includes('\n')
|
|
128
|
-
? '\n'
|
|
129
|
-
: '';
|
|
130
|
-
return source.slice(0, i) + preservedWhitespace + source.slice(removeEnd);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return source.slice(0, removeStart) + source.slice(removeEnd);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function formatConfigSource(rawConfig) {
|
|
137
|
-
const parsed = JSON.parse(rawConfig);
|
|
138
|
-
return `export default ${JSON.stringify(parsed, null, 2)};\n`;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function migratePackageJsonConfig(config) {
|
|
142
|
-
if (!config.packageJson) return {changes: []};
|
|
143
|
-
|
|
144
|
-
const packageJson = config.packageJson.source;
|
|
145
|
-
const xdsConfig = findTopLevelKey(packageJson, 'xds');
|
|
146
|
-
const astryxConfig = findTopLevelKey(packageJson, 'astryx');
|
|
147
|
-
if (!xdsConfig && !astryxConfig) return {changes: []};
|
|
148
|
-
|
|
149
|
-
if (config.astryxConfig) {
|
|
150
|
-
return {
|
|
151
|
-
errors: [
|
|
152
|
-
{
|
|
153
|
-
file: 'package.json',
|
|
154
|
-
error:
|
|
155
|
-
'package.json contains xds/astryx config and astryx.config.mjs already exists; migrate the config manually.',
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (xdsConfig && astryxConfig) {
|
|
162
|
-
return {
|
|
163
|
-
errors: [
|
|
164
|
-
{
|
|
165
|
-
file: 'package.json',
|
|
166
|
-
error:
|
|
167
|
-
'package.json contains both xds and astryx config keys; migrate the config manually.',
|
|
168
|
-
},
|
|
169
|
-
],
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const configProperty = astryxConfig ?? xdsConfig;
|
|
174
|
-
const packageJsonWithoutConfig = removeTopLevelProperty(
|
|
175
|
-
packageJson,
|
|
176
|
-
configProperty,
|
|
177
|
-
);
|
|
178
|
-
return {
|
|
179
|
-
changes: [
|
|
180
|
-
{path: 'package.json', source: packageJsonWithoutConfig},
|
|
181
|
-
{
|
|
182
|
-
path: 'astryx.config.mjs',
|
|
183
|
-
source: formatConfigSource(configProperty.rawValue),
|
|
184
|
-
},
|
|
185
|
-
],
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function migrateXdsConfigFile(config) {
|
|
190
|
-
if (!config.xdsConfig) return {changes: []};
|
|
191
|
-
if (config.astryxConfig) {
|
|
192
|
-
return {
|
|
193
|
-
errors: [
|
|
194
|
-
{
|
|
195
|
-
file: 'xds.config.mjs',
|
|
196
|
-
error:
|
|
197
|
-
'xds.config.mjs and astryx.config.mjs both exist; migrate the config manually.',
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
return {
|
|
203
|
-
changes: [
|
|
204
|
-
{path: 'astryx.config.mjs', source: config.xdsConfig.source},
|
|
205
|
-
{path: 'xds.config.mjs', delete: true},
|
|
206
|
-
],
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export default function transformer(_file, api) {
|
|
211
|
-
const config = api.config ?? {};
|
|
212
|
-
const packageResult = migratePackageJsonConfig(config);
|
|
213
|
-
if (packageResult.errors?.length) return packageResult;
|
|
214
|
-
if (packageResult.changes?.length) {
|
|
215
|
-
if (config.xdsConfig) {
|
|
216
|
-
return {
|
|
217
|
-
errors: [
|
|
218
|
-
{
|
|
219
|
-
file: 'package.json',
|
|
220
|
-
error:
|
|
221
|
-
'package.json contains xds/astryx config and xds.config.mjs exists; migrate the config manually.',
|
|
222
|
-
},
|
|
223
|
-
],
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
return packageResult;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return migrateXdsConfigFile(config);
|
|
230
|
-
}
|