@astryxdesign/cli 0.7.0-canary.693da50 → 0.7.0-canary.9eb7c76
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/README.md +2 -3
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.test.mjs +28 -0
- package/api/doctor/theme-checks.mjs +10 -10
- package/api/doctor/theme-checks.test.mjs +5 -4
- package/api/gap-report/gap-report.test.mjs +1 -1
- package/api/init/init.doc.mjs +5 -1
- package/api/init/init.type.d.mts +4 -1
- package/api/init/init.type.mjs +1 -1
- package/api/init/remove/remove.mjs +8 -3
- package/api/init/remove/remove.test.mjs +12 -0
- package/api/init/run/run.d.mts +1 -1
- package/api/init/run/run.mjs +3 -3
- package/api/search/search.doc.mjs +1 -1
- package/api/search/search.mjs +1 -1
- package/api/search/search.test.mjs +1 -1
- package/api/search/search.type.d.mts +1 -1
- package/api/search/search.type.mjs +1 -1
- package/api/theme/_adapter.mjs +3 -3
- package/api/theme/add/add.d.mts +11 -5
- package/api/theme/add/add.mjs +19 -192
- package/api/theme/add/add.test.mjs +68 -258
- package/api/theme/add/add.types.test.mjs +0 -1
- package/api/theme/build/build.d.mts +3 -3
- package/api/theme/build/build.mjs +22 -36
- package/api/theme/build/build.test.mjs +11 -24
- package/api/theme/eject/eject.copy-compat.test.mjs +168 -0
- package/api/theme/integration-themes.test.mjs +3 -3
- package/api/theme/remove/remove.test.mjs +1 -1
- package/api/theme/targets/targets.test.mjs +0 -4
- package/api/theme/template/template.mjs +1 -1
- package/api/theme/theme.type.d.mts +1 -30
- package/api/theme/theme.type.mjs +3 -13
- package/api/theme/themeAdd.doc.mjs +19 -27
- package/api/theme/themeTargets.doc.mjs +3 -4
- package/api/theme/themeTemplate.doc.mjs +1 -1
- package/api/theme/use/use.test.mjs +1 -1
- package/assets/codemods/transforms/next/__tests__/migrate-deprecated-theme-surface.test.mjs +322 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-deprecated-theme-surface-v0.6-data.mjs +229 -0
- package/assets/codemods/transforms/next/migrate-deprecated-theme-surface.mjs +624 -0
- package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +38 -18
- package/assets/docs/author-a-theme.doc.mjs +1 -1
- package/assets/docs/getting-started.doc.mjs +2 -2
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +2 -2
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +2 -2
- package/assets/docs/tree/fonts-and-assets.doc.mjs +3 -3
- package/assets/docs/tree/styling-advanced.doc.mjs +21 -14
- package/assets/docs/tree/themes.doc.mjs +1 -1
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +2 -2
- package/assets/docs/tree/versioning.doc.mjs +1 -4
- package/assets/docs/use-a-theme.doc.mjs +16 -16
- package/authoring/debug/type.ts +2 -2
- package/authoring/doctypes/base/type.ts +0 -9
- package/authoring/integration/integration.doc.mjs +1 -1
- package/clients/cli/commands/build-theme.adaptations.test.mjs +4 -0
- package/clients/cli/commands/build-theme.ascii-output.test.mjs +35 -8
- package/clients/cli/commands/build-theme.mjs +31 -67
- package/clients/cli/commands/build-theme.registry.test.mjs +0 -10
- package/clients/cli/commands/discover.mjs +2 -1
- package/clients/cli/commands/empty-argument.test.mjs +16 -0
- package/clients/cli/commands/init.next-steps.test.mjs +1 -1
- package/clients/cli/commands/search.test.mjs +1 -1
- package/clients/cli/commands/swizzle.mjs +4 -1
- package/clients/cli/commands/template.mjs +7 -1
- package/clients/cli/commands/theme-add-lifecycle.test.mjs +142 -49
- package/clients/cli/commands/theme-add.doc.mjs +10 -17
- package/clients/cli/commands/theme-list.behavior.test.mjs +2 -1
- package/clients/cli/commands/theme-targets.behavior.test.mjs +8 -6
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.doc.mjs +2 -2
- package/clients/cli/lib/cli-error.mjs +19 -0
- package/clients/cli/lib/component-format.mjs +111 -57
- package/clients/cli/lib/component-format.test.mjs +28 -39
- package/clients/cli/lib/doc-text-ascii.test.mjs +5 -2
- package/foundation/agent-docs/agent-docs.d.mts +2 -1
- package/foundation/agent-docs/agent-docs.mjs +6 -1
- package/foundation/agent-docs/app-theme-workflow.test.mjs +3 -0
- package/foundation/config/theme-state.mjs +3 -3
- package/foundation/debug/debug-fields.test.mjs +13 -35
- package/foundation/debug/event.mjs +13 -78
- package/foundation/debug/privacy-contract.test.mjs +20 -12
- package/foundation/debug/redact.d.mts +2 -2
- package/foundation/debug/redact.mjs +2 -2
- package/foundation/discovery/theme-imports.mjs +1 -1
- package/foundation/discovery/theming-targets.d.mts +1 -20
- package/foundation/discovery/theming-targets.mjs +1 -38
- package/foundation/discovery/theming-targets.test.mjs +9 -175
- package/foundation/response/response-types.doc.mjs +10 -13
- package/foundation/response/response-types.doc.test.mjs +36 -14
- package/package.json +9 -9
- package/api/theme/add/add.binary.test.mjs +0 -157
- package/api/theme/add/add.rollback.test.mjs +0 -158
- package/api/theme/add/add.staging.test.mjs +0 -83
package/api/theme/add/add.mjs
CHANGED
|
@@ -1,210 +1,37 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file `astryx theme add` —
|
|
4
|
+
* @file `astryx theme add` — add built theme output to the app.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Plain `theme add` and the compatibility `--import` spelling both record the
|
|
7
|
+
* built theme in the generated app module. Source copying belongs only to
|
|
8
|
+
* `theme eject`.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
|
-
import
|
|
11
|
-
import * as path from 'node:path';
|
|
12
|
-
import {addThemeToApp, findTheme, listAvailableThemes} from '../_adapter.mjs';
|
|
13
|
-
import {
|
|
14
|
-
assertWithin,
|
|
15
|
-
PathSafetyError,
|
|
16
|
-
} from '../../../foundation/fs/path-safety.mjs';
|
|
11
|
+
import {addThemeToApp} from '../_adapter.mjs';
|
|
17
12
|
import {AstryxError} from '../../error.mjs';
|
|
18
13
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
19
|
-
import {applyWrites} from '../../integration/add-helpers.mjs';
|
|
20
|
-
import {stripCopyrightHeader} from '../../../foundation/text/copyright-header.mjs';
|
|
21
|
-
|
|
22
|
-
const COPY_DEPRECATION = Object.freeze({
|
|
23
|
-
id: 'DEP-0005',
|
|
24
|
-
replacements: ['theme eject', 'theme add --import'],
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
/** @param {string} slug */
|
|
28
|
-
function defaultTargetDir(slug) {
|
|
29
|
-
return path.join('src', 'themes', slug);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Strip repository boilerplate from UTF-8 text while preserving binary bytes.
|
|
34
|
-
* @param {Buffer} bytes
|
|
35
|
-
* @returns {Buffer|string}
|
|
36
|
-
*/
|
|
37
|
-
function scaffoldContents(bytes) {
|
|
38
|
-
const text = bytes.toString('utf-8');
|
|
39
|
-
return Buffer.from(text, 'utf-8').equals(bytes)
|
|
40
|
-
? stripCopyrightHeader(text)
|
|
41
|
-
: bytes;
|
|
42
|
-
}
|
|
43
14
|
|
|
44
15
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
16
|
+
* Add one available built theme to the generated app module. `import` remains
|
|
17
|
+
* accepted as a no-op so callers that opted in before the cleanup keep working.
|
|
18
|
+
*
|
|
19
|
+
* Removed source-copy options are rejected before discovery or any write, and
|
|
20
|
+
* name the function that now owns them. `overwrite: false` remains an accepted
|
|
21
|
+
* compatibility no-op.
|
|
50
22
|
*
|
|
51
23
|
* @param {string} slug
|
|
52
|
-
* @param {{targetPath?: string, overwrite?: boolean, cwd?: string, package?: string}} options
|
|
53
|
-
* @returns {Promise<import('../theme.type.mjs').
|
|
54
|
-
*/
|
|
55
|
-
async function copyThemeSource(slug, options) {
|
|
56
|
-
const {
|
|
57
|
-
targetPath,
|
|
58
|
-
overwrite = false,
|
|
59
|
-
cwd = process.cwd(),
|
|
60
|
-
package: packageName,
|
|
61
|
-
} = options;
|
|
62
|
-
|
|
63
|
-
const match = await findTheme(slug, {
|
|
64
|
-
cwd,
|
|
65
|
-
package: packageName,
|
|
66
|
-
includeLocal: false,
|
|
67
|
-
});
|
|
68
|
-
if (!match) {
|
|
69
|
-
const available = await listAvailableThemes(cwd, {includeLocal: false});
|
|
70
|
-
throw new AstryxError(
|
|
71
|
-
`Unknown theme "${slug}"${packageName ? ` in package "${packageName}"` : ''}`,
|
|
72
|
-
available.map(theme => ({
|
|
73
|
-
name: `${theme.slug} --package ${theme.package}`,
|
|
74
|
-
reason:
|
|
75
|
-
theme.source === 'bundled'
|
|
76
|
-
? 'bundled theme'
|
|
77
|
-
: `provided by ${theme.package}`,
|
|
78
|
-
})),
|
|
79
|
-
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const rawTarget = targetPath || defaultTargetDir(match.slug);
|
|
84
|
-
let resolvedDir;
|
|
85
|
-
try {
|
|
86
|
-
resolvedDir = assertWithin(rawTarget, cwd, {label: 'theme target path'});
|
|
87
|
-
} catch (error) {
|
|
88
|
-
if (error instanceof PathSafetyError) {
|
|
89
|
-
throw new AstryxError(
|
|
90
|
-
error.message,
|
|
91
|
-
undefined,
|
|
92
|
-
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const descriptor = path
|
|
99
|
-
.relative(match.sourceDir, match.docPath)
|
|
100
|
-
.split(path.sep)
|
|
101
|
-
.join('/');
|
|
102
|
-
const copyFiles = match.bundled
|
|
103
|
-
? match.files.filter(name => name !== descriptor)
|
|
104
|
-
: [match.entry, ...match.files.filter(name => name !== match.entry).sort()];
|
|
105
|
-
let writes;
|
|
106
|
-
try {
|
|
107
|
-
writes = copyFiles.map(name => ({
|
|
108
|
-
name,
|
|
109
|
-
src: path.join(match.sourceDir, name),
|
|
110
|
-
dest: assertWithin(name, resolvedDir, {
|
|
111
|
-
label: `theme destination for ${name}`,
|
|
112
|
-
}),
|
|
113
|
-
}));
|
|
114
|
-
} catch (error) {
|
|
115
|
-
if (error instanceof PathSafetyError) {
|
|
116
|
-
throw new AstryxError(
|
|
117
|
-
error.message,
|
|
118
|
-
undefined,
|
|
119
|
-
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
for (const write of writes) {
|
|
126
|
-
if (!fs.existsSync(write.src)) {
|
|
127
|
-
throw new AstryxError(
|
|
128
|
-
`Theme "${match.slug}" is missing bundled file "${write.name}". ` +
|
|
129
|
-
'Re-run `node scripts/generate-cli-themes.mjs` to rebuild the bundle.',
|
|
130
|
-
undefined,
|
|
131
|
-
ERROR_CODES.ERR_NO_SOURCE,
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (!overwrite) {
|
|
137
|
-
const existing = writes.find(write => fs.existsSync(write.dest));
|
|
138
|
-
if (existing) {
|
|
139
|
-
const rel = path.relative(cwd, existing.dest) || existing.dest;
|
|
140
|
-
throw new AstryxError(
|
|
141
|
-
`Refusing to overwrite existing file ${rel}. ` +
|
|
142
|
-
'Re-run with --overwrite (or -f) to replace it.',
|
|
143
|
-
undefined,
|
|
144
|
-
ERROR_CODES.ERR_FILE_EXISTS,
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
fs.mkdirSync(resolvedDir, {recursive: true});
|
|
151
|
-
const plans = writes.map(write => {
|
|
152
|
-
fs.mkdirSync(path.dirname(write.dest), {recursive: true});
|
|
153
|
-
const dest = assertWithin(write.name, resolvedDir, {
|
|
154
|
-
label: `theme destination for ${write.name}`,
|
|
155
|
-
});
|
|
156
|
-
return {
|
|
157
|
-
path: dest,
|
|
158
|
-
contents: scaffoldContents(fs.readFileSync(write.src)),
|
|
159
|
-
createOnly: !overwrite,
|
|
160
|
-
};
|
|
161
|
-
});
|
|
162
|
-
applyWrites(plans);
|
|
163
|
-
} catch (error) {
|
|
164
|
-
if (error instanceof AstryxError) throw error;
|
|
165
|
-
if (error instanceof PathSafetyError) {
|
|
166
|
-
throw new AstryxError(
|
|
167
|
-
error.message,
|
|
168
|
-
undefined,
|
|
169
|
-
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
173
|
-
throw new AstryxError(
|
|
174
|
-
`Failed to write theme files: ${message}`,
|
|
175
|
-
undefined,
|
|
176
|
-
ERROR_CODES.ERR_WRITE_FAILED,
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
type: 'theme.add',
|
|
182
|
-
data: {
|
|
183
|
-
slug: match.slug,
|
|
184
|
-
displayName: match.displayName,
|
|
185
|
-
maintained: match.maintained,
|
|
186
|
-
package: match.package,
|
|
187
|
-
outputDir: path.relative(cwd, resolvedDir) || '.',
|
|
188
|
-
entry: match.entry,
|
|
189
|
-
exportName: match.exportName,
|
|
190
|
-
files: copyFiles,
|
|
191
|
-
},
|
|
192
|
-
meta: {deprecations: [COPY_DEPRECATION]},
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Copy one available source theme, or import its built output with `import`.
|
|
198
|
-
* @param {string} slug
|
|
199
|
-
* @param {{targetPath?: string, overwrite?: boolean, cwd?: string, package?: string, import?: boolean}} [options]
|
|
200
|
-
* @returns {Promise<import('../theme.type.mjs').ThemeAddResponse | import('../theme.type.mjs').ThemeAppResponse>}
|
|
24
|
+
* @param {{targetPath?: string, overwrite?: boolean, import?: boolean, cwd?: string, package?: string}} [options]
|
|
25
|
+
* @returns {Promise<import('../theme.type.mjs').ThemeAppResponse>}
|
|
201
26
|
*/
|
|
202
27
|
export async function themeAdd(slug, options = {}) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
28
|
+
const legacy = /** @type {{targetPath?: unknown, overwrite?: unknown}} */ (
|
|
29
|
+
options
|
|
30
|
+
);
|
|
31
|
+
if (legacy.targetPath != null || legacy.overwrite === true) {
|
|
206
32
|
throw new AstryxError(
|
|
207
|
-
'`
|
|
33
|
+
'`themeAdd` no longer copies source or accepts targetPath or overwrite: true. ' +
|
|
34
|
+
'Call `themeEject` with the same slug and copy options to fork source.',
|
|
208
35
|
undefined,
|
|
209
36
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
210
37
|
);
|
|
@@ -124,224 +124,7 @@ afterEach(() => {
|
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
describe('themeAdd', () => {
|
|
127
|
-
it('
|
|
128
|
-
installTheme('ocean', '@acme/themes', {missingBuilt: true});
|
|
129
|
-
|
|
130
|
-
const result = await themeAdd('ocean', {
|
|
131
|
-
cwd: tmpDir,
|
|
132
|
-
package: '@acme/themes',
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
expect(result).toMatchObject({
|
|
136
|
-
type: 'theme.add',
|
|
137
|
-
data: {
|
|
138
|
-
slug: 'ocean',
|
|
139
|
-
displayName: 'ocean',
|
|
140
|
-
maintained: true,
|
|
141
|
-
package: '@acme/themes',
|
|
142
|
-
outputDir: 'src/themes/ocean',
|
|
143
|
-
entry: 'oceanTheme.ts',
|
|
144
|
-
exportName: 'oceanTheme',
|
|
145
|
-
files: ['oceanTheme.ts', 'oceanTheme.doc.mjs'],
|
|
146
|
-
},
|
|
147
|
-
meta: {
|
|
148
|
-
deprecations: [
|
|
149
|
-
{
|
|
150
|
-
id: 'DEP-0005',
|
|
151
|
-
replacements: ['theme eject', 'theme add --import'],
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
expect(
|
|
157
|
-
fs.readFileSync(
|
|
158
|
-
path.join(tmpDir, 'src/themes/ocean/oceanTheme.ts'),
|
|
159
|
-
'utf-8',
|
|
160
|
-
),
|
|
161
|
-
).toContain('export const oceanTheme');
|
|
162
|
-
expect(
|
|
163
|
-
fs.readFileSync(
|
|
164
|
-
path.join(tmpDir, 'src/themes/ocean/oceanTheme.doc.mjs'),
|
|
165
|
-
'utf-8',
|
|
166
|
-
),
|
|
167
|
-
).toContain("name: 'ocean'");
|
|
168
|
-
expect(fs.existsSync(path.join(tmpDir, 'src/astryx-themes.ts'))).toBe(
|
|
169
|
-
false,
|
|
170
|
-
);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('keeps every released bundled copy receipt field and file', async () => {
|
|
174
|
-
const result = await themeAdd('neutral', {cwd: tmpDir});
|
|
175
|
-
|
|
176
|
-
expect(result.data).toEqual({
|
|
177
|
-
slug: 'neutral',
|
|
178
|
-
displayName: 'Neutral',
|
|
179
|
-
maintained: true,
|
|
180
|
-
package: '@astryxdesign/cli',
|
|
181
|
-
outputDir: path.join('src', 'themes', 'neutral'),
|
|
182
|
-
entry: 'neutralTheme.ts',
|
|
183
|
-
exportName: 'neutralTheme',
|
|
184
|
-
files: [
|
|
185
|
-
'neutralTheme.ts',
|
|
186
|
-
'icons.tsx',
|
|
187
|
-
'neutralPalettes.ts',
|
|
188
|
-
'neutralPalettes.generated.ts',
|
|
189
|
-
'neutralPaletteRefs.generated.ts',
|
|
190
|
-
'neutralPalettes.generated.receipt.json',
|
|
191
|
-
'palette.config.json',
|
|
192
|
-
],
|
|
193
|
-
});
|
|
194
|
-
expect(
|
|
195
|
-
fs.readdirSync(path.join(tmpDir, 'src/themes/neutral')).sort(),
|
|
196
|
-
).toEqual([...result.data.files].sort());
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('keeps every relative import required by a copied theme', async () => {
|
|
200
|
-
const result = await themeAdd('neutral', {cwd: tmpDir});
|
|
201
|
-
const outputDir = path.join(tmpDir, result.data.outputDir);
|
|
202
|
-
const relativeImports = /from\s+['"](\.\.?\/[^'"]+)['"]/gu;
|
|
203
|
-
|
|
204
|
-
for (const file of result.data.files) {
|
|
205
|
-
if (!/\.(?:ts|tsx|mjs)$/u.test(file)) continue;
|
|
206
|
-
const source = fs.readFileSync(path.join(outputDir, file), 'utf-8');
|
|
207
|
-
for (const [, specifier] of source.matchAll(relativeImports)) {
|
|
208
|
-
const imported = path.resolve(outputDir, path.dirname(file), specifier);
|
|
209
|
-
expect(
|
|
210
|
-
fs.existsSync(imported) ||
|
|
211
|
-
fs.existsSync(`${imported}.ts`) ||
|
|
212
|
-
fs.existsSync(`${imported}.tsx`) ||
|
|
213
|
-
fs.existsSync(`${imported}.mjs`),
|
|
214
|
-
).toBe(true);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('strips the repository copyright header from copied text', async () => {
|
|
220
|
-
const result = await themeAdd('neutral', {cwd: tmpDir});
|
|
221
|
-
const first = path.join(
|
|
222
|
-
tmpDir,
|
|
223
|
-
result.data.outputDir,
|
|
224
|
-
result.data.files[0],
|
|
225
|
-
);
|
|
226
|
-
expect(fs.readFileSync(first, 'utf-8')).not.toMatch(
|
|
227
|
-
/Copyright \(c\) Meta Platforms/u,
|
|
228
|
-
);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('keeps case-insensitive copy lookup', async () => {
|
|
232
|
-
const result = await themeAdd('Neutral', {cwd: tmpDir});
|
|
233
|
-
expect(result.data.slug).toBe('neutral');
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it('keeps an explicit copy target path', async () => {
|
|
237
|
-
const result = await themeAdd('neutral', {
|
|
238
|
-
cwd: tmpDir,
|
|
239
|
-
targetPath: 'themes/mine',
|
|
240
|
-
});
|
|
241
|
-
expect(result.data.outputDir).toBe(path.join('themes', 'mine'));
|
|
242
|
-
expect(
|
|
243
|
-
fs.existsSync(path.join(tmpDir, 'themes', 'mine', result.data.files[0])),
|
|
244
|
-
).toBe(true);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it('keeps unknown-theme errors on the copy path', async () => {
|
|
248
|
-
await expect(
|
|
249
|
-
themeAdd('does-not-exist', {cwd: tmpDir}),
|
|
250
|
-
).rejects.toMatchObject({code: 'ERR_UNKNOWN_THEME'});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it('keeps the copy overwrite guard and explicit replacement', async () => {
|
|
254
|
-
await themeAdd('neutral', {cwd: tmpDir});
|
|
255
|
-
await expect(themeAdd('neutral', {cwd: tmpDir})).rejects.toMatchObject({
|
|
256
|
-
code: 'ERR_FILE_EXISTS',
|
|
257
|
-
});
|
|
258
|
-
await expect(
|
|
259
|
-
themeAdd('neutral', {cwd: tmpDir, overwrite: true}),
|
|
260
|
-
).resolves.toMatchObject({type: 'theme.add'});
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it('keeps copy path traversal protection', async () => {
|
|
264
|
-
await expect(
|
|
265
|
-
themeAdd('neutral', {cwd: tmpDir, targetPath: '../escape'}),
|
|
266
|
-
).rejects.toMatchObject({code: 'ERR_PATH_TRAVERSAL'});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it('keeps stable write errors when a copy target is a file', async () => {
|
|
270
|
-
fs.writeFileSync(path.join(tmpDir, 'blocker'), 'x');
|
|
271
|
-
await expect(
|
|
272
|
-
themeAdd('neutral', {cwd: tmpDir, targetPath: 'blocker'}),
|
|
273
|
-
).rejects.toMatchObject({code: 'ERR_WRITE_FAILED'});
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it('keeps stable write errors when the default copy ancestor is a file', async () => {
|
|
277
|
-
fs.rmSync(path.join(tmpDir, 'src'), {recursive: true, force: true});
|
|
278
|
-
fs.writeFileSync(path.join(tmpDir, 'src'), 'x');
|
|
279
|
-
await expect(themeAdd('neutral', {cwd: tmpDir})).rejects.toMatchObject({
|
|
280
|
-
code: 'ERR_WRITE_FAILED',
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
it('keeps copying into an existing empty target directory', async () => {
|
|
285
|
-
fs.mkdirSync(path.join(tmpDir, 'mydir'));
|
|
286
|
-
const result = await themeAdd('neutral', {
|
|
287
|
-
cwd: tmpDir,
|
|
288
|
-
targetPath: 'mydir',
|
|
289
|
-
});
|
|
290
|
-
expect(result.data.outputDir).toBe('mydir');
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it('excludes local themes from the copying lookup', async () => {
|
|
294
|
-
installTheme();
|
|
295
|
-
const localDir = path.join(tmpDir, 'src', 'themes', 'ocean');
|
|
296
|
-
fs.mkdirSync(localDir, {recursive: true});
|
|
297
|
-
fs.writeFileSync(
|
|
298
|
-
path.join(localDir, 'oceanTheme.doc.mjs'),
|
|
299
|
-
"/** @type {import('@astryxdesign/cli/authoring').ThemeDoc} */\nexport default {type: 'theme', name: 'ocean', displayName: 'Local ocean', description: 'Local.', maintained: false};\n",
|
|
300
|
-
);
|
|
301
|
-
fs.writeFileSync(
|
|
302
|
-
path.join(localDir, 'oceanTheme.ts'),
|
|
303
|
-
'export const oceanTheme = {source: "local"};\n',
|
|
304
|
-
);
|
|
305
|
-
|
|
306
|
-
const result = await themeAdd('ocean', {
|
|
307
|
-
cwd: tmpDir,
|
|
308
|
-
targetPath: 'src/copied-ocean',
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
expect(result.type).toBe('theme.add');
|
|
312
|
-
expect(result.data.package).toBe('@acme/themes');
|
|
313
|
-
expect(
|
|
314
|
-
fs.readFileSync(
|
|
315
|
-
path.join(tmpDir, 'src', 'copied-ocean', 'oceanTheme.ts'),
|
|
316
|
-
'utf-8',
|
|
317
|
-
),
|
|
318
|
-
).not.toContain('source: "local"');
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it.each([
|
|
322
|
-
['a target path', {targetPath: 'src/brand'}],
|
|
323
|
-
['overwrite', {overwrite: true}],
|
|
324
|
-
])('rejects --import with %s before writing', async (_label, copyOption) => {
|
|
325
|
-
installTheme();
|
|
326
|
-
|
|
327
|
-
await expect(
|
|
328
|
-
themeAdd('ocean', {
|
|
329
|
-
cwd: tmpDir,
|
|
330
|
-
import: true,
|
|
331
|
-
package: '@acme/themes',
|
|
332
|
-
...copyOption,
|
|
333
|
-
}),
|
|
334
|
-
).rejects.toMatchObject({
|
|
335
|
-
code: 'ERR_THEME_INVALID',
|
|
336
|
-
message: expect.stringContaining('cannot be combined'),
|
|
337
|
-
});
|
|
338
|
-
expect(fs.existsSync(path.join(tmpDir, 'src/astryx-themes.ts'))).toBe(
|
|
339
|
-
false,
|
|
340
|
-
);
|
|
341
|
-
expect(fs.existsSync(path.join(tmpDir, 'src/brand'))).toBe(false);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it('records and imports a built package theme without copying source', async () => {
|
|
127
|
+
it('records and imports a built package theme by default without copying source', async () => {
|
|
345
128
|
installTheme();
|
|
346
129
|
const packageBefore = fs.readFileSync(
|
|
347
130
|
path.join(tmpDir, 'package.json'),
|
|
@@ -350,7 +133,6 @@ describe('themeAdd', () => {
|
|
|
350
133
|
|
|
351
134
|
const result = await themeAdd('ocean', {
|
|
352
135
|
cwd: tmpDir,
|
|
353
|
-
import: true,
|
|
354
136
|
package: '@acme/themes',
|
|
355
137
|
});
|
|
356
138
|
|
|
@@ -388,11 +170,73 @@ describe('themeAdd', () => {
|
|
|
388
170
|
});
|
|
389
171
|
});
|
|
390
172
|
|
|
173
|
+
it('accepts import as a no-op and preserves the same theme.app behavior', async () => {
|
|
174
|
+
installTheme();
|
|
175
|
+
|
|
176
|
+
const first = await themeAdd('ocean', {
|
|
177
|
+
cwd: tmpDir,
|
|
178
|
+
import: true,
|
|
179
|
+
package: '@acme/themes',
|
|
180
|
+
});
|
|
181
|
+
expect(first.type).toBe('theme.app');
|
|
182
|
+
expect(first.data.change).toMatchObject({action: 'add', changed: true});
|
|
183
|
+
|
|
184
|
+
const moduleFile = path.join(tmpDir, 'src/astryx-themes.ts');
|
|
185
|
+
fs.appendFileSync(moduleFile, '\n// hand edit\n');
|
|
186
|
+
const repeated = await themeAdd('ocean', {
|
|
187
|
+
cwd: tmpDir,
|
|
188
|
+
package: '@acme/themes',
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
expect(repeated.type).toBe('theme.app');
|
|
192
|
+
expect(repeated.data.change.changed).toBe(false);
|
|
193
|
+
expect(fs.readFileSync(moduleFile, 'utf-8')).not.toContain('hand edit');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it.each([
|
|
197
|
+
['a target path', {targetPath: 'src/brand'}],
|
|
198
|
+
['overwrite true', {overwrite: true}],
|
|
199
|
+
])(
|
|
200
|
+
'rejects removed copy option %s before writing',
|
|
201
|
+
async (_label, copyOption) => {
|
|
202
|
+
installTheme();
|
|
203
|
+
|
|
204
|
+
await expect(
|
|
205
|
+
themeAdd('ocean', {
|
|
206
|
+
cwd: tmpDir,
|
|
207
|
+
package: '@acme/themes',
|
|
208
|
+
...copyOption,
|
|
209
|
+
}),
|
|
210
|
+
).rejects.toMatchObject({
|
|
211
|
+
code: 'ERR_THEME_INVALID',
|
|
212
|
+
message: expect.stringContaining('themeEject'),
|
|
213
|
+
});
|
|
214
|
+
expect(fs.existsSync(path.join(tmpDir, 'src/astryx-themes.ts'))).toBe(
|
|
215
|
+
false,
|
|
216
|
+
);
|
|
217
|
+
expect(fs.existsSync(path.join(tmpDir, 'src/brand'))).toBe(false);
|
|
218
|
+
},
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
it('accepts overwrite false as a compatibility no-op', async () => {
|
|
222
|
+
installTheme();
|
|
223
|
+
|
|
224
|
+
const result = await themeAdd('ocean', {
|
|
225
|
+
cwd: tmpDir,
|
|
226
|
+
package: '@acme/themes',
|
|
227
|
+
overwrite: false,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
expect(result.type).toBe('theme.app');
|
|
231
|
+
expect(result.data.change).toMatchObject({action: 'add', changed: true});
|
|
232
|
+
expect(fs.existsSync(path.join(tmpDir, 'src/astryx-themes.ts'))).toBe(true);
|
|
233
|
+
expect(fs.existsSync(path.join(tmpDir, 'src/themes/ocean'))).toBe(false);
|
|
234
|
+
});
|
|
235
|
+
|
|
391
236
|
it('keeps the released CLI selector while recording the import package', async () => {
|
|
392
237
|
installBuiltThemePackage('neutral');
|
|
393
238
|
const result = await themeAdd('neutral', {
|
|
394
239
|
cwd: tmpDir,
|
|
395
|
-
import: true,
|
|
396
240
|
package: '@astryxdesign/cli',
|
|
397
241
|
});
|
|
398
242
|
|
|
@@ -415,37 +259,13 @@ describe('themeAdd', () => {
|
|
|
415
259
|
});
|
|
416
260
|
});
|
|
417
261
|
|
|
418
|
-
it('regenerates an already-added theme and reports no state change', async () => {
|
|
419
|
-
installTheme();
|
|
420
|
-
await themeAdd('ocean', {
|
|
421
|
-
cwd: tmpDir,
|
|
422
|
-
import: true,
|
|
423
|
-
package: '@acme/themes',
|
|
424
|
-
});
|
|
425
|
-
const moduleFile = path.join(tmpDir, 'src/astryx-themes.ts');
|
|
426
|
-
fs.appendFileSync(moduleFile, '\n// hand edit\n');
|
|
427
|
-
|
|
428
|
-
const result = await themeAdd('ocean', {
|
|
429
|
-
cwd: tmpDir,
|
|
430
|
-
import: true,
|
|
431
|
-
package: '@acme/themes',
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
expect(result.data.change.changed).toBe(false);
|
|
435
|
-
expect(fs.readFileSync(moduleFile, 'utf-8')).not.toContain('hand edit');
|
|
436
|
-
});
|
|
437
|
-
|
|
438
262
|
it('fails before writing when the selected module path is authored', async () => {
|
|
439
263
|
installTheme();
|
|
440
264
|
const moduleFile = path.join(tmpDir, 'src/astryx-themes.ts');
|
|
441
265
|
fs.writeFileSync(moduleFile, 'export const mine = true;\n');
|
|
442
266
|
|
|
443
267
|
await expect(
|
|
444
|
-
themeAdd('ocean', {
|
|
445
|
-
cwd: tmpDir,
|
|
446
|
-
import: true,
|
|
447
|
-
package: '@acme/themes',
|
|
448
|
-
}),
|
|
268
|
+
themeAdd('ocean', {cwd: tmpDir, package: '@acme/themes'}),
|
|
449
269
|
).rejects.toMatchObject({code: 'ERR_FILE_EXISTS'});
|
|
450
270
|
expect(fs.readFileSync(moduleFile, 'utf-8')).toBe(
|
|
451
271
|
'export const mine = true;\n',
|
|
@@ -459,7 +279,6 @@ describe('themeAdd', () => {
|
|
|
459
279
|
|
|
460
280
|
const result = await themeAdd('ocean', {
|
|
461
281
|
cwd: tmpDir,
|
|
462
|
-
import: true,
|
|
463
282
|
package: '@acme/themes',
|
|
464
283
|
});
|
|
465
284
|
|
|
@@ -469,11 +288,7 @@ describe('themeAdd', () => {
|
|
|
469
288
|
|
|
470
289
|
it('prefers a built local theme and switches the recorded owner', async () => {
|
|
471
290
|
installTheme();
|
|
472
|
-
await themeAdd('ocean', {
|
|
473
|
-
cwd: tmpDir,
|
|
474
|
-
import: true,
|
|
475
|
-
package: '@acme/themes',
|
|
476
|
-
});
|
|
291
|
+
await themeAdd('ocean', {cwd: tmpDir, package: '@acme/themes'});
|
|
477
292
|
await themeEject('ocean', {cwd: tmpDir, package: '@acme/themes'});
|
|
478
293
|
const localDir = path.join(tmpDir, 'src', 'themes', 'ocean');
|
|
479
294
|
fs.writeFileSync(
|
|
@@ -482,7 +297,7 @@ describe('themeAdd', () => {
|
|
|
482
297
|
);
|
|
483
298
|
fs.writeFileSync(path.join(localDir, 'ocean.css'), '/* local css */\n');
|
|
484
299
|
|
|
485
|
-
const result = await themeAdd('ocean', {cwd: tmpDir
|
|
300
|
+
const result = await themeAdd('ocean', {cwd: tmpDir});
|
|
486
301
|
|
|
487
302
|
expect(result).toMatchObject({
|
|
488
303
|
type: 'theme.app',
|
|
@@ -518,7 +333,6 @@ describe('themeAdd', () => {
|
|
|
518
333
|
|
|
519
334
|
const result = await themeAdd('ocean', {
|
|
520
335
|
cwd: tmpDir,
|
|
521
|
-
import: true,
|
|
522
336
|
package: '@acme/themes',
|
|
523
337
|
});
|
|
524
338
|
|
|
@@ -535,11 +349,7 @@ describe('themeAdd', () => {
|
|
|
535
349
|
installTheme('ocean', '@acme/themes', {missingBuilt: true});
|
|
536
350
|
|
|
537
351
|
await expect(
|
|
538
|
-
themeAdd('ocean', {
|
|
539
|
-
cwd: tmpDir,
|
|
540
|
-
import: true,
|
|
541
|
-
package: '@acme/themes',
|
|
542
|
-
}),
|
|
352
|
+
themeAdd('ocean', {cwd: tmpDir, package: '@acme/themes'}),
|
|
543
353
|
).rejects.toMatchObject({
|
|
544
354
|
code: 'ERR_THEME_INVALID',
|
|
545
355
|
message: expect.stringMatching(
|
|
@@ -50,7 +50,7 @@ export function validateThemePrivateInputs(file: string, { cwd }?: {
|
|
|
50
50
|
* Validate component overrides against one discovered target registry.
|
|
51
51
|
*
|
|
52
52
|
* @param {{components?: Record<string, Record<string, unknown>>, onDark?: {components?: Record<string, Record<string, unknown>>}, onLight?: {components?: Record<string, Record<string, unknown>>}, __onDark?: {components?: Record<string, Record<string, unknown>>}, __onLight?: {components?: Record<string, Record<string, unknown>>}}} themeDef
|
|
53
|
-
* @param {{propsByKey: Record<string, string[]
|
|
53
|
+
* @param {{propsByKey: Record<string, string[]>}} knownComponents
|
|
54
54
|
* @returns {string[]}
|
|
55
55
|
*/
|
|
56
56
|
export function validateComponentOverridesAgainstRegistry(themeDef: {
|
|
@@ -69,7 +69,6 @@ export function validateComponentOverridesAgainstRegistry(themeDef: {
|
|
|
69
69
|
};
|
|
70
70
|
}, knownComponents: {
|
|
71
71
|
propsByKey: Record<string, string[]>;
|
|
72
|
-
deprecatedByKey: Record<string, string>;
|
|
73
72
|
}): string[];
|
|
74
73
|
/**
|
|
75
74
|
* Print the install snippet and font guidance once for a batch: the first
|
|
@@ -119,11 +118,12 @@ export function themeBuild(file: string, options?: {
|
|
|
119
118
|
}, ctx?: {
|
|
120
119
|
cwd?: string;
|
|
121
120
|
}): Promise<import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null>;
|
|
122
|
-
/** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string}} options @param {{cwd?: string}} [ctx] */
|
|
121
|
+
/** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void}} options @param {{cwd?: string}} [ctx] */
|
|
123
122
|
export function themeBuildFamily(files: string[], options: {
|
|
124
123
|
familyKey: string;
|
|
125
124
|
check?: boolean;
|
|
126
125
|
iconsSpecifier?: string;
|
|
126
|
+
__onPrivateVarError?: () => void;
|
|
127
127
|
}, { cwd }?: {
|
|
128
128
|
cwd?: string;
|
|
129
129
|
}): Promise<{
|