@astryxdesign/cli 0.6.5-canary.eb58bba → 0.6.5-canary.f261d2f
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 +11 -12
- package/api/error.d.mts +0 -22
- package/api/error.mjs +0 -42
- package/api/integration/authoring-checks.mjs +7 -10
- package/api/integration/authoring-checks.type.d.mts +0 -8
- package/api/integration/authoring-checks.type.mjs +3 -7
- package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
- package/api/integration/validate-integration.d.mts +2 -4
- package/api/integration/validate-integration.mjs +2 -7
- package/api/integration/validate-integration.test.mjs +0 -55
- package/api/integration/validate-integration.type.d.mts +0 -5
- package/api/integration/validate-integration.type.mjs +1 -5
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/swizzle/copy/copy.mjs +3 -66
- package/api/swizzle/swizzle.doc.mjs +0 -4
- package/api/template/copy/copy.mjs +5 -9
- package/api/template/show/show.mjs +4 -15
- package/api/template/template.doc.mjs +1 -5
- package/api/template/template.type.d.mts +0 -1
- package/api/template/template.type.mjs +0 -1
- package/api/upgrade/run/run.mjs +3 -20
- package/api/upgrade/run/run.test.mjs +1 -45
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +0 -1
- package/api/upgrade/upgrade.type.mjs +0 -1
- package/clients/cli/commands/doctor.mjs +4 -4
- package/clients/cli/commands/template.mjs +2 -11
- package/clients/cli/commands/upgrade.ascii-output.test.mjs +0 -14
- package/clients/cli/lib/manifest.mjs +165 -44
- package/clients/cli/lib/manifest.test.mjs +7 -98
- package/foundation/discovery/template-adapter.d.mts +0 -13
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +1 -37
- package/foundation/discovery/template-adapter.mjs +1 -16
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +11 -11
- package/package.json +9 -9
- package/api/template/show/show.test.mjs +0 -76
- package/clients/cli/commands/template.show-media.test.mjs +0 -62
- package/clients/cli/commands/write-failure.test.mjs +0 -175
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file A write that fails on the filesystem reports ERR_WRITE_FAILED.
|
|
5
|
-
*
|
|
6
|
-
* An unwritable target produced `{"error": "EACCES: permission denied, open
|
|
7
|
-
* '/abs/host/path/readonly/x.tsx'", "code": "ERR_UNKNOWN"}` — the raw Node
|
|
8
|
-
* errno error, with the wrong code and an absolute host path in the message.
|
|
9
|
-
* ERR_WRITE_FAILED is in the frozen registry for exactly this case, and every
|
|
10
|
-
* other Astryx message names its target relative to the project.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
|
|
14
|
-
import * as fs from 'node:fs';
|
|
15
|
-
import * as os from 'node:os';
|
|
16
|
-
import * as path from 'node:path';
|
|
17
|
-
import {fileURLToPath} from 'node:url';
|
|
18
|
-
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
19
|
-
|
|
20
|
-
const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../..');
|
|
21
|
-
|
|
22
|
-
// chmod means nothing to root, so the unwritable directory would be writable
|
|
23
|
-
// and the command would succeed. Skip rather than assert something false.
|
|
24
|
-
const asRoot = typeof process.getuid === 'function' && process.getuid() === 0;
|
|
25
|
-
|
|
26
|
-
let dir;
|
|
27
|
-
let readonlyDir;
|
|
28
|
-
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-write-fail-'));
|
|
31
|
-
fs.writeFileSync(
|
|
32
|
-
path.join(dir, 'package.json'),
|
|
33
|
-
JSON.stringify({
|
|
34
|
-
name: 'scratch',
|
|
35
|
-
version: '1.0.0',
|
|
36
|
-
dependencies: {'@astryxdesign/core': '0.6.3'},
|
|
37
|
-
}),
|
|
38
|
-
);
|
|
39
|
-
fs.mkdirSync(path.join(dir, 'node_modules', '@astryxdesign'), {recursive: true});
|
|
40
|
-
fs.symlinkSync(
|
|
41
|
-
path.join(REPO, 'packages', 'core'),
|
|
42
|
-
path.join(dir, 'node_modules', '@astryxdesign', 'core'),
|
|
43
|
-
'dir',
|
|
44
|
-
);
|
|
45
|
-
readonlyDir = path.join(dir, 'readonly');
|
|
46
|
-
fs.mkdirSync(readonlyDir);
|
|
47
|
-
fs.chmodSync(readonlyDir, 0o500);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
afterEach(() => {
|
|
51
|
-
try {
|
|
52
|
-
fs.chmodSync(readonlyDir, 0o700);
|
|
53
|
-
} catch {
|
|
54
|
-
// already gone
|
|
55
|
-
}
|
|
56
|
-
fs.rmSync(dir, {recursive: true, force: true});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
/** @param {string[]} args */
|
|
60
|
-
const json = async args => {
|
|
61
|
-
const {status, stdout} = await runCli(['--json', ...args], {cwd: dir});
|
|
62
|
-
return {status, body: JSON.parse(stdout)};
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
describe.skipIf(asRoot)('a failed write reports ERR_WRITE_FAILED', () => {
|
|
66
|
-
it('template into an unwritable directory', async () => {
|
|
67
|
-
const {status, body} = await json(['template', 'ai-chat', 'readonly/x.tsx']);
|
|
68
|
-
|
|
69
|
-
expect(status).toBe(1);
|
|
70
|
-
expect(body.code).toBe('ERR_WRITE_FAILED');
|
|
71
|
-
expect(body.error).toContain('readonly/x.tsx');
|
|
72
|
-
expect(body.error).toContain('EACCES');
|
|
73
|
-
// The whole point of the relative form: no absolute host path escapes.
|
|
74
|
-
expect(body.error).not.toContain(dir);
|
|
75
|
-
expect(fs.existsSync(path.join(readonlyDir, 'x.tsx'))).toBe(false);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('swizzle into an unwritable directory', async () => {
|
|
79
|
-
const {status, body} = await json([
|
|
80
|
-
'swizzle',
|
|
81
|
-
'Button',
|
|
82
|
-
'--output',
|
|
83
|
-
'readonly/sub',
|
|
84
|
-
]);
|
|
85
|
-
|
|
86
|
-
expect(status).toBe(1);
|
|
87
|
-
expect(body.code).toBe('ERR_WRITE_FAILED');
|
|
88
|
-
expect(body.error).toContain('readonly/sub');
|
|
89
|
-
expect(body.error).not.toContain(dir);
|
|
90
|
-
expect(fs.existsSync(path.join(readonlyDir, 'sub'))).toBe(false);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('still writes normally into a writable directory', async () => {
|
|
94
|
-
const {status, body} = await json(['template', 'ai-chat', 'src/page.tsx']);
|
|
95
|
-
|
|
96
|
-
expect(status, JSON.stringify(body).slice(0, 200)).toBe(0);
|
|
97
|
-
expect(body.type).toBe('template.copy');
|
|
98
|
-
expect(fs.existsSync(path.join(dir, 'src', 'page.tsx'))).toBe(true);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe.skipIf(asRoot)('a swizzle that fails part-way undoes what it wrote', () => {
|
|
103
|
-
it('restores replaced files, removes created ones, and says nothing was written', async () => {
|
|
104
|
-
// Learn the component's files, in copy order, from a successful swizzle.
|
|
105
|
-
const probe = await json(['swizzle', 'Button', '--output', 'probe']);
|
|
106
|
-
expect(probe.status, JSON.stringify(probe.body).slice(0, 200)).toBe(0);
|
|
107
|
-
const files = probe.body.data.files;
|
|
108
|
-
expect(files.length).toBeGreaterThan(1);
|
|
109
|
-
const outDir = path.join(dir, 'out', path.basename(probe.body.data.outputDir));
|
|
110
|
-
|
|
111
|
-
// The first file exists (replaceable), the middle ones do not, and the
|
|
112
|
-
// last one is read-only, so --overwrite fails after writing the others.
|
|
113
|
-
const first = files[0];
|
|
114
|
-
const middle = files.slice(1, -1);
|
|
115
|
-
const last = files[files.length - 1];
|
|
116
|
-
fs.mkdirSync(outDir, {recursive: true});
|
|
117
|
-
fs.writeFileSync(path.join(outDir, first), 'before first\n');
|
|
118
|
-
fs.writeFileSync(path.join(outDir, last), 'before last\n');
|
|
119
|
-
fs.chmodSync(path.join(outDir, last), 0o444);
|
|
120
|
-
|
|
121
|
-
const {status, body} = await json([
|
|
122
|
-
'swizzle',
|
|
123
|
-
'Button',
|
|
124
|
-
'--output',
|
|
125
|
-
'out',
|
|
126
|
-
'--overwrite',
|
|
127
|
-
]);
|
|
128
|
-
fs.chmodSync(path.join(outDir, last), 0o644);
|
|
129
|
-
|
|
130
|
-
expect(status).toBe(1);
|
|
131
|
-
expect(body.code).toBe('ERR_WRITE_FAILED');
|
|
132
|
-
expect(body.error).toContain(last);
|
|
133
|
-
expect(body.error).toContain('Nothing was written.');
|
|
134
|
-
expect(body.error).not.toContain(dir);
|
|
135
|
-
expect(fs.readFileSync(path.join(outDir, first), 'utf8')).toBe('before first\n');
|
|
136
|
-
expect(fs.readFileSync(path.join(outDir, last), 'utf8')).toBe('before last\n');
|
|
137
|
-
for (const file of middle) {
|
|
138
|
-
expect(fs.existsSync(path.join(outDir, file))).toBe(false);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('undoes the copy when a destination cannot be read back', async () => {
|
|
143
|
-
const probe = await json(['swizzle', 'Button', '--output', 'probe']);
|
|
144
|
-
expect(probe.status, JSON.stringify(probe.body).slice(0, 200)).toBe(0);
|
|
145
|
-
const files = probe.body.data.files;
|
|
146
|
-
const outDir = path.join(dir, 'out', path.basename(probe.body.data.outputDir));
|
|
147
|
-
|
|
148
|
-
// A directory where the last file goes: the rollback snapshot cannot read
|
|
149
|
-
// it, and the earlier files are already written when the copy reaches it.
|
|
150
|
-
const first = files[0];
|
|
151
|
-
const middle = files.slice(1, -1);
|
|
152
|
-
const last = files[files.length - 1];
|
|
153
|
-
fs.mkdirSync(path.join(outDir, last), {recursive: true});
|
|
154
|
-
fs.writeFileSync(path.join(outDir, first), 'before first\n');
|
|
155
|
-
|
|
156
|
-
const {status, body} = await json([
|
|
157
|
-
'swizzle',
|
|
158
|
-
'Button',
|
|
159
|
-
'--output',
|
|
160
|
-
'out',
|
|
161
|
-
'--overwrite',
|
|
162
|
-
]);
|
|
163
|
-
|
|
164
|
-
expect(status).toBe(1);
|
|
165
|
-
expect(body.code).toBe('ERR_WRITE_FAILED');
|
|
166
|
-
expect(body.error).toContain(last);
|
|
167
|
-
expect(body.error).toContain('Nothing was written.');
|
|
168
|
-
expect(body.error).not.toContain(dir);
|
|
169
|
-
expect(fs.readFileSync(path.join(outDir, first), 'utf8')).toBe('before first\n');
|
|
170
|
-
expect(fs.statSync(path.join(outDir, last)).isDirectory()).toBe(true);
|
|
171
|
-
for (const file of middle) {
|
|
172
|
-
expect(fs.existsSync(path.join(outDir, file))).toBe(false);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
});
|