@astryxdesign/cli 0.7.5-canary.d4f09c2 → 0.7.5-canary.d695efb
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 +1 -1
- package/api/upgrade/_adapter.d.mts +2 -0
- package/api/upgrade/run/failure-receipt.test.mjs +212 -0
- package/api/upgrade/run/run.mjs +251 -10
- package/api/upgrade/upgrade.doc.mjs +4 -4
- package/api/upgrade/upgrade.mjs +19 -4
- package/api/upgrade/upgrade.type.d.mts +12 -1
- package/api/upgrade/upgrade.type.mjs +17 -4
- package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
- package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
- package/assets/codemods/integration-runner.mjs +8 -2
- package/assets/codemods/integration-runner.protection.test.mjs +53 -0
- package/assets/codemods/parse.mjs +94 -0
- package/assets/codemods/run-codemod.mjs +109 -5
- package/assets/codemods/runner.mjs +108 -10
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
- package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
- package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
- package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
- package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
- package/assets/templates/pages/library/page.tsx +1 -2
- package/authoring/codemod/type.ts +10 -0
- package/clients/cli/commands/upgrade.doc.mjs +27 -0
- package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
- package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
- package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
- package/clients/cli/commands/upgrade.mjs +9 -2
- package/foundation/response/base.d.ts +7 -0
- package/foundation/response/error-codes.doc.mjs +3 -2
- package/foundation/response/error-codes.mjs +1 -1
- package/foundation/response/json.d.mts +10 -3
- package/foundation/response/json.mjs +16 -4
- package/package.json +10 -9
|
@@ -131,17 +131,30 @@
|
|
|
131
131
|
* @property {AgentDocsSummary} data.agentDocs
|
|
132
132
|
* @property {boolean} data.sourcePathFound Whether the resolved source directory (`path`, default `./src`) exists. False means no source file was read, so a zero `filesChanged` says nothing about the project being migrated.
|
|
133
133
|
* @property {RegistryCompositionSummary} [data.registryCompositions]
|
|
134
|
-
* @property {boolean} [data.complete] False when protected required changes remain.
|
|
135
|
-
* @property {
|
|
134
|
+
* @property {boolean} [data.complete] False when protected required changes remain. Also false on the receipt a failed run's error carries (`UpgradeFailureReceipt`).
|
|
135
|
+
* @property {string} [data.errorCode] Stable incomplete-result code when complete is false: `ERR_CODEMOD_PROTECTED` on a returned receipt; on the receipt a failed run's error carries, the error's own code.
|
|
136
136
|
* @property {number} [data.filesChanged] Distinct files changed across core + integration codemods (apply mode). One file that four codemods each changed counts once.
|
|
137
137
|
* @property {string[]} [data.modifiedFiles] Files changed or previewed, relative to the folder the command ran in.
|
|
138
138
|
* @property {ProtectedCodemodFile[]} [data.protectedFiles] Protected files that still require a codemod change after regeneration.
|
|
139
|
-
* @property {Array<{file: string, location?: string, reason: string}>} [data.declinedCandidates] Candidates left unchanged because proof was insufficient. Each `file` is relative to the folder the command ran in.
|
|
139
|
+
* @property {Array<{file: string, location?: string, reason: string}>} [data.declinedCandidates] Candidates left unchanged because proof was insufficient, one row per file, for manual review. A protected file whose own source does not parse is listed here, with the parse error's `line:column` as `location` and a `reason` that starts with `unparseable protected file`, instead of failing the run. Declined candidates do not make the run incomplete. Each `file` is relative to the folder the command ran in.
|
|
140
140
|
* @property {number} [data.transformsApplied] Total codemod changes. A code or config codemod counts once for each file it changed, so one file changed by four of them counts four times; a project codemod counts once, however many files it writes.
|
|
141
|
-
* @property {Array<{file: string, codemod: string, error: string}>} [data.errors] Per-codemod errors, when any codemod failed. Each `file` is relative to the folder the command ran in.
|
|
141
|
+
* @property {Array<{file: string, codemod: string, error: string}>} [data.errors] Per-codemod errors, when any codemod failed. On the receipt a failed run's error carries, also a post-codemod hook failure (`codemod: 'post-codemod-hook'`) or the error that stopped the run after codemods wrote files. Each `file` is relative to the folder the command ran in.
|
|
142
142
|
* @property {CliBehindCore} [data.cliBehindCore] Present only when the installed Core is newer than this CLI: codemods for the releases after `cliBehindCore.cliVersion` did not run.
|
|
143
143
|
*/
|
|
144
144
|
|
|
145
|
+
/**
|
|
146
|
+
* What a failed upgrade had already done. When a run fails after its codemods
|
|
147
|
+
* ran (a codemod or post-codemod hook failed, or an error stopped it after
|
|
148
|
+
* codemods wrote files), the failure keeps its usual shape: the --json error
|
|
149
|
+
* envelope `{apiVersion, error, code}` and a rejected `upgrade()` with that
|
|
150
|
+
* `code`. The envelope adds `receipt`, and the thrown AstryxError a `receipt`
|
|
151
|
+
* property: the same `upgrade.run` data a completed run returns, with
|
|
152
|
+
* `complete: false` and `errorCode` equal to the error's `code`. Files in
|
|
153
|
+
* `modifiedFiles` stay changed.
|
|
154
|
+
*
|
|
155
|
+
* @typedef {UpgradeRunResponse['data']} UpgradeFailureReceipt
|
|
156
|
+
*/
|
|
157
|
+
|
|
145
158
|
/**
|
|
146
159
|
* astryx --json upgrade — short-circuit status results.
|
|
147
160
|
*
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The codemod walkers never follow a symbolic link into installed
|
|
5
|
+
* dependencies, a package store or version-control metadata; other linked
|
|
6
|
+
* folders are still scanned, read-only.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
10
|
+
import * as fs from 'node:fs';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import {runCodemods} from '../runner.mjs';
|
|
13
|
+
import {findSourceFiles as findIntegrationSourceFiles} from '../run-codemod.mjs';
|
|
14
|
+
|
|
15
|
+
let tmpDir;
|
|
16
|
+
let originalCwd;
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
originalCwd = process.cwd();
|
|
20
|
+
tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-runner-test-'));
|
|
21
|
+
process.chdir(tmpDir);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
process.chdir(originalCwd);
|
|
26
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('findSourceFiles — symbolic links into dependency trees', () => {
|
|
30
|
+
const manifests = [
|
|
31
|
+
{
|
|
32
|
+
version: '0.1.3',
|
|
33
|
+
transforms: [
|
|
34
|
+
{
|
|
35
|
+
name: 'p',
|
|
36
|
+
meta: {title: 'p'},
|
|
37
|
+
transform: f => f.source.replace(/foo/g, 'bar'),
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
// A tree a symlinked dependency folder points at: a package store outside
|
|
44
|
+
// the project, holding a file the transform would change.
|
|
45
|
+
function seedStore() {
|
|
46
|
+
const store = path.join(tmpDir, 'store', 'node_modules', 'pkg');
|
|
47
|
+
fs.mkdirSync(store, {recursive: true});
|
|
48
|
+
fs.writeFileSync(path.join(store, 'index.ts'), 'const foo = 1;\n');
|
|
49
|
+
fs.mkdirSync(path.join(tmpDir, 'src'), {recursive: true});
|
|
50
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'real.ts'), 'const foo = 2;\n');
|
|
51
|
+
return store;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
it('does not descend a symlinked node_modules', async () => {
|
|
55
|
+
const store = seedStore();
|
|
56
|
+
fs.symlinkSync(
|
|
57
|
+
path.dirname(store),
|
|
58
|
+
path.join(tmpDir, 'src', 'node_modules'),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const r = await runCodemods(manifests, {
|
|
62
|
+
apply: true,
|
|
63
|
+
path: './src',
|
|
64
|
+
root: tmpDir,
|
|
65
|
+
silent: true,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
expect(r.writtenFiles.map(f => path.basename(f))).toEqual(['real.ts']);
|
|
69
|
+
expect(r.protectedFiles).toEqual([]);
|
|
70
|
+
expect(
|
|
71
|
+
findIntegrationSourceFiles(path.join(tmpDir, 'src')).map(f =>
|
|
72
|
+
path.relative(tmpDir, f),
|
|
73
|
+
),
|
|
74
|
+
).toEqual([path.join('src', 'real.ts')]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('does not descend a link whose target is inside a dependency tree', async () => {
|
|
78
|
+
const store = seedStore();
|
|
79
|
+
fs.symlinkSync(store, path.join(tmpDir, 'src', 'pkg'));
|
|
80
|
+
|
|
81
|
+
const r = await runCodemods(manifests, {
|
|
82
|
+
apply: true,
|
|
83
|
+
path: './src',
|
|
84
|
+
root: tmpDir,
|
|
85
|
+
silent: true,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(r.writtenFiles.map(f => path.basename(f))).toEqual(['real.ts']);
|
|
89
|
+
expect(r.protectedFiles).toEqual([]);
|
|
90
|
+
expect(
|
|
91
|
+
findIntegrationSourceFiles(path.join(tmpDir, 'src')).map(f =>
|
|
92
|
+
path.relative(tmpDir, f),
|
|
93
|
+
),
|
|
94
|
+
).toEqual([path.join('src', 'real.ts')]);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('does not descend a link into a Yarn cache folder', async () => {
|
|
98
|
+
const cached = path.join(tmpDir, '.yarn', 'cache', 'pkg');
|
|
99
|
+
fs.mkdirSync(cached, {recursive: true});
|
|
100
|
+
fs.writeFileSync(path.join(cached, 'index.ts'), 'const foo = 1;\n');
|
|
101
|
+
fs.mkdirSync(path.join(tmpDir, 'src'), {recursive: true});
|
|
102
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'real.ts'), 'const foo = 2;\n');
|
|
103
|
+
fs.symlinkSync(cached, path.join(tmpDir, 'src', 'pkg'));
|
|
104
|
+
|
|
105
|
+
const r = await runCodemods(manifests, {
|
|
106
|
+
apply: true,
|
|
107
|
+
path: '.',
|
|
108
|
+
root: tmpDir,
|
|
109
|
+
silent: true,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
expect(r.writtenFiles.map(f => path.basename(f))).toEqual(['real.ts']);
|
|
113
|
+
expect(r.protectedFiles).toEqual([]);
|
|
114
|
+
expect(
|
|
115
|
+
findIntegrationSourceFiles(tmpDir).map(f => path.relative(tmpDir, f)),
|
|
116
|
+
).toEqual([path.join('src', 'real.ts')]);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('still descends ordinary symlinked directories in a project below a node_modules folder', async () => {
|
|
120
|
+
const project = path.join(tmpDir, 'node_modules', 'consumer');
|
|
121
|
+
const shared = path.join(project, 'shared');
|
|
122
|
+
fs.mkdirSync(path.join(project, 'src'), {recursive: true});
|
|
123
|
+
fs.mkdirSync(shared, {recursive: true});
|
|
124
|
+
fs.writeFileSync(path.join(shared, 'nested.ts'), 'const foo = 1;\n');
|
|
125
|
+
fs.symlinkSync(shared, path.join(project, 'src', 'linked'));
|
|
126
|
+
|
|
127
|
+
const r = await runCodemods(manifests, {
|
|
128
|
+
apply: true,
|
|
129
|
+
path: path.join(project, 'src'),
|
|
130
|
+
root: project,
|
|
131
|
+
silent: true,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
expect(r.protectedFiles).toEqual([
|
|
135
|
+
expect.objectContaining({
|
|
136
|
+
file: 'src/linked/nested.ts',
|
|
137
|
+
reason: 'symlink',
|
|
138
|
+
}),
|
|
139
|
+
]);
|
|
140
|
+
expect(
|
|
141
|
+
findIntegrationSourceFiles(path.join(project, 'src'), project).map(f =>
|
|
142
|
+
path.relative(project, f),
|
|
143
|
+
),
|
|
144
|
+
).toEqual([path.join('src', 'linked', 'nested.ts')]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('does not descend a link into a Yarn cache outside the project', async () => {
|
|
148
|
+
const project = path.join(tmpDir, 'project');
|
|
149
|
+
const cached = path.join(tmpDir, 'other-project', '.yarn', 'cache', 'pkg');
|
|
150
|
+
fs.mkdirSync(cached, {recursive: true});
|
|
151
|
+
fs.writeFileSync(path.join(cached, 'index.ts'), 'const foo = 1;\n');
|
|
152
|
+
fs.mkdirSync(path.join(project, 'src'), {recursive: true});
|
|
153
|
+
fs.writeFileSync(path.join(project, 'src', 'real.ts'), 'const foo = 2;\n');
|
|
154
|
+
fs.symlinkSync(
|
|
155
|
+
path.join('..', '..', 'other-project', '.yarn', 'cache', 'pkg'),
|
|
156
|
+
path.join(project, 'src', 'pkg'),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const r = await runCodemods(manifests, {
|
|
160
|
+
apply: true,
|
|
161
|
+
path: path.join(project, 'src'),
|
|
162
|
+
root: project,
|
|
163
|
+
silent: true,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
expect(r.writtenFiles.map(f => path.basename(f))).toEqual(['real.ts']);
|
|
167
|
+
expect(r.protectedFiles).toEqual([]);
|
|
168
|
+
expect(
|
|
169
|
+
findIntegrationSourceFiles(path.join(project, 'src')).map(f =>
|
|
170
|
+
path.relative(project, f),
|
|
171
|
+
),
|
|
172
|
+
).toEqual([path.join('src', 'real.ts')]);
|
|
173
|
+
expect(fs.readFileSync(path.join(cached, 'index.ts'), 'utf-8')).toBe(
|
|
174
|
+
'const foo = 1;\n',
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('does not descend a link from a project below node_modules to a sibling dependency', async () => {
|
|
179
|
+
const project = path.join(tmpDir, 'node_modules', 'consumer');
|
|
180
|
+
const sibling = path.join(tmpDir, 'node_modules', 'dep');
|
|
181
|
+
fs.mkdirSync(path.join(project, 'src'), {recursive: true});
|
|
182
|
+
fs.mkdirSync(sibling, {recursive: true});
|
|
183
|
+
fs.writeFileSync(path.join(sibling, 'index.ts'), 'const foo = 1;\n');
|
|
184
|
+
fs.writeFileSync(path.join(project, 'src', 'real.ts'), 'const foo = 2;\n');
|
|
185
|
+
fs.symlinkSync(sibling, path.join(project, 'src', 'dep'));
|
|
186
|
+
|
|
187
|
+
const r = await runCodemods(manifests, {
|
|
188
|
+
apply: true,
|
|
189
|
+
path: path.join(project, 'src'),
|
|
190
|
+
root: project,
|
|
191
|
+
silent: true,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
expect(r.writtenFiles.map(f => path.basename(f))).toEqual(['real.ts']);
|
|
195
|
+
expect(r.protectedFiles).toEqual([]);
|
|
196
|
+
expect(
|
|
197
|
+
findIntegrationSourceFiles(path.join(project, 'src'), project).map(f =>
|
|
198
|
+
path.relative(project, f),
|
|
199
|
+
),
|
|
200
|
+
).toEqual([path.join('src', 'real.ts')]);
|
|
201
|
+
expect(fs.readFileSync(path.join(sibling, 'index.ts'), 'utf-8')).toBe(
|
|
202
|
+
'const foo = 1;\n',
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file A protected file a codemod cannot parse is declined for manual review
|
|
5
|
+
* instead of failing the run; every other codemod error still fails it.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
9
|
+
import * as fs from 'node:fs';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import {runCodemods} from '../runner.mjs';
|
|
12
|
+
import {parseCss, processSelector} from '../parse.mjs';
|
|
13
|
+
import validateDataTokenOwnership, {
|
|
14
|
+
meta as validateDataTokenOwnershipMeta,
|
|
15
|
+
} from '../transforms/v0.7.0/validate-data-token-ownership.mjs';
|
|
16
|
+
import migrateThemeSelectors, {
|
|
17
|
+
meta as migrateThemeSelectorsMeta,
|
|
18
|
+
} from '../transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs';
|
|
19
|
+
import migrateDeprecatedThemeSurface, {
|
|
20
|
+
meta as migrateDeprecatedThemeSurfaceMeta,
|
|
21
|
+
} from '../transforms/v0.7.0/migrate-deprecated-theme-surface.mjs';
|
|
22
|
+
|
|
23
|
+
let tmpDir;
|
|
24
|
+
let originalCwd;
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
originalCwd = process.cwd();
|
|
28
|
+
tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-runner-test-'));
|
|
29
|
+
process.chdir(tmpDir);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
process.chdir(originalCwd);
|
|
34
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('runCodemods — protected files that do not parse', () => {
|
|
38
|
+
// A transform that parses every file it is handed, like real codemods do.
|
|
39
|
+
const manifests = [
|
|
40
|
+
{
|
|
41
|
+
version: '0.1.3',
|
|
42
|
+
transforms: [
|
|
43
|
+
{
|
|
44
|
+
name: 'rename-foo',
|
|
45
|
+
meta: {title: 'rename foo'},
|
|
46
|
+
transform: (file, {jscodeshift: j}) => {
|
|
47
|
+
const root = j(file.source);
|
|
48
|
+
root.find(j.Identifier, {name: 'foo'}).forEach(p => {
|
|
49
|
+
p.node.name = 'bar';
|
|
50
|
+
});
|
|
51
|
+
return root.toSource();
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
const BROKEN = 'export const foo = {;\n';
|
|
58
|
+
|
|
59
|
+
function seedVendored() {
|
|
60
|
+
fs.mkdirSync(path.join(tmpDir, 'src'), {recursive: true});
|
|
61
|
+
fs.mkdirSync(path.join(tmpDir, 'vendor'), {recursive: true});
|
|
62
|
+
fs.writeFileSync(
|
|
63
|
+
path.join(tmpDir, '.gitattributes'),
|
|
64
|
+
'vendor/** linguist-vendored\n',
|
|
65
|
+
);
|
|
66
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'owned.ts'), 'const foo = 1;\n');
|
|
67
|
+
fs.writeFileSync(path.join(tmpDir, 'vendor', 'bundle.js'), BROKEN);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
it('declines a vendored file that does not parse and completes the owned edits', async () => {
|
|
71
|
+
seedVendored();
|
|
72
|
+
|
|
73
|
+
const r = await runCodemods(manifests, {
|
|
74
|
+
apply: true,
|
|
75
|
+
path: '.',
|
|
76
|
+
silent: true,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
expect(r.errors).toEqual([]);
|
|
80
|
+
expect(r.protectedFiles).toEqual([]);
|
|
81
|
+
expect(r.declinedCandidates).toEqual([
|
|
82
|
+
{
|
|
83
|
+
file: path.join('vendor', 'bundle.js'),
|
|
84
|
+
codemod: 'core:rename-foo',
|
|
85
|
+
location: '1:21',
|
|
86
|
+
reason: expect.stringMatching(
|
|
87
|
+
/^unparseable protected file \(vendored\): /,
|
|
88
|
+
),
|
|
89
|
+
},
|
|
90
|
+
]);
|
|
91
|
+
expect(fs.readFileSync(path.join(tmpDir, 'src', 'owned.ts'), 'utf-8')).toBe(
|
|
92
|
+
'const bar = 1;\n',
|
|
93
|
+
);
|
|
94
|
+
expect(
|
|
95
|
+
fs.readFileSync(path.join(tmpDir, 'vendor', 'bundle.js'), 'utf-8'),
|
|
96
|
+
).toBe(BROKEN);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('declines the same file in a dry run', async () => {
|
|
100
|
+
seedVendored();
|
|
101
|
+
|
|
102
|
+
const r = await runCodemods(manifests, {
|
|
103
|
+
apply: false,
|
|
104
|
+
path: '.',
|
|
105
|
+
silent: true,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(r.errors).toEqual([]);
|
|
109
|
+
expect(r.declinedCandidates.map(item => item.file)).toEqual([
|
|
110
|
+
path.join('vendor', 'bundle.js'),
|
|
111
|
+
]);
|
|
112
|
+
expect(r.changedFiles.map(f => path.basename(f))).toEqual(['owned.ts']);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('declines an unparseable file under an ignore rule or a generated marker', async () => {
|
|
116
|
+
fs.mkdirSync(path.join(tmpDir, 'src'), {recursive: true});
|
|
117
|
+
fs.writeFileSync(path.join(tmpDir, '.gitignore'), 'ignored/\n');
|
|
118
|
+
fs.mkdirSync(path.join(tmpDir, 'ignored'), {recursive: true});
|
|
119
|
+
fs.writeFileSync(path.join(tmpDir, 'ignored', 'a.js'), BROKEN);
|
|
120
|
+
fs.writeFileSync(
|
|
121
|
+
path.join(tmpDir, 'src', 'gen.js'),
|
|
122
|
+
`// @generated\n${BROKEN}`,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const r = await runCodemods(manifests, {
|
|
126
|
+
apply: true,
|
|
127
|
+
path: '.',
|
|
128
|
+
silent: true,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
expect(r.errors).toEqual([]);
|
|
132
|
+
expect(r.declinedCandidates.map(item => item.file).sort()).toEqual([
|
|
133
|
+
path.join('ignored', 'a.js'),
|
|
134
|
+
path.join('src', 'gen.js'),
|
|
135
|
+
]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('still analyses a protected file that parses and reports its required change', async () => {
|
|
139
|
+
seedVendored();
|
|
140
|
+
fs.writeFileSync(
|
|
141
|
+
path.join(tmpDir, 'vendor', 'parsed.js'),
|
|
142
|
+
'export const foo = 1;\n',
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const r = await runCodemods(manifests, {
|
|
146
|
+
apply: true,
|
|
147
|
+
path: '.',
|
|
148
|
+
silent: true,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
expect(r.protectedFiles).toEqual([
|
|
152
|
+
expect.objectContaining({
|
|
153
|
+
file: path.join('vendor', 'parsed.js'),
|
|
154
|
+
reason: 'vendored',
|
|
155
|
+
}),
|
|
156
|
+
]);
|
|
157
|
+
expect(r.declinedCandidates.map(item => item.file)).toEqual([
|
|
158
|
+
path.join('vendor', 'bundle.js'),
|
|
159
|
+
]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('still fails on owned source that does not parse', async () => {
|
|
163
|
+
fs.mkdirSync(path.join(tmpDir, 'src'), {recursive: true});
|
|
164
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'broken.js'), BROKEN);
|
|
165
|
+
|
|
166
|
+
const r = await runCodemods(manifests, {
|
|
167
|
+
apply: true,
|
|
168
|
+
path: '.',
|
|
169
|
+
silent: true,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
expect(r.declinedCandidates).toEqual([]);
|
|
173
|
+
expect(r.errors).toEqual([
|
|
174
|
+
expect.objectContaining({
|
|
175
|
+
file: path.join('src', 'broken.js'),
|
|
176
|
+
codemod: 'core:rename-foo',
|
|
177
|
+
}),
|
|
178
|
+
]);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('still fails when a transform throws on a protected file that parses', async () => {
|
|
182
|
+
seedVendored();
|
|
183
|
+
fs.writeFileSync(
|
|
184
|
+
path.join(tmpDir, 'vendor', 'bundle.js'),
|
|
185
|
+
'const x = 1;\n',
|
|
186
|
+
);
|
|
187
|
+
const throwing = [
|
|
188
|
+
{
|
|
189
|
+
version: '0.1.3',
|
|
190
|
+
transforms: [
|
|
191
|
+
{
|
|
192
|
+
name: 'throws',
|
|
193
|
+
meta: {title: 'throws'},
|
|
194
|
+
transform: file => {
|
|
195
|
+
if (file.path.endsWith('bundle.js')) throw new Error('boom');
|
|
196
|
+
return null;
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
const r = await runCodemods(throwing, {
|
|
204
|
+
apply: true,
|
|
205
|
+
path: '.',
|
|
206
|
+
silent: true,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
expect(r.declinedCandidates).toEqual([]);
|
|
210
|
+
expect(r.errors).toEqual([
|
|
211
|
+
{
|
|
212
|
+
file: path.join('vendor', 'bundle.js'),
|
|
213
|
+
codemod: 'core:throws',
|
|
214
|
+
error: 'boom',
|
|
215
|
+
},
|
|
216
|
+
]);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('keeps a CSS codemod error on a generated stylesheet that parses', async () => {
|
|
220
|
+
fs.mkdirSync(path.join(tmpDir, 'src'), {recursive: true});
|
|
221
|
+
const theme =
|
|
222
|
+
'/* @generated by `astryx theme build` */\n' +
|
|
223
|
+
':root {\n --color-data-1: #000;\n}\n';
|
|
224
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'theme.css'), theme);
|
|
225
|
+
|
|
226
|
+
const r = await runCodemods(
|
|
227
|
+
[
|
|
228
|
+
{
|
|
229
|
+
version: '0.7.0',
|
|
230
|
+
transforms: [
|
|
231
|
+
{
|
|
232
|
+
name: 'validate-data-token-ownership',
|
|
233
|
+
transform: validateDataTokenOwnership,
|
|
234
|
+
meta: validateDataTokenOwnershipMeta,
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
{apply: true, path: '.', silent: true},
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
expect(r.declinedCandidates).toEqual([]);
|
|
243
|
+
expect(r.errors).toEqual([
|
|
244
|
+
{
|
|
245
|
+
file: path.join('src', 'theme.css'),
|
|
246
|
+
codemod: 'core:validate-data-token-ownership',
|
|
247
|
+
error: expect.stringContaining('astryx theme build'),
|
|
248
|
+
},
|
|
249
|
+
]);
|
|
250
|
+
expect(
|
|
251
|
+
fs.readFileSync(path.join(tmpDir, 'src', 'theme.css'), 'utf-8'),
|
|
252
|
+
).toBe(theme);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('declines a protected stylesheet that does not parse as CSS', async () => {
|
|
256
|
+
fs.mkdirSync(path.join(tmpDir, 'vendor'), {recursive: true});
|
|
257
|
+
fs.writeFileSync(
|
|
258
|
+
path.join(tmpDir, '.gitattributes'),
|
|
259
|
+
'vendor/** linguist-vendored\n',
|
|
260
|
+
);
|
|
261
|
+
fs.writeFileSync(path.join(tmpDir, 'vendor', 'broken.css'), 'a {\n');
|
|
262
|
+
|
|
263
|
+
const r = await runCodemods(
|
|
264
|
+
[
|
|
265
|
+
{
|
|
266
|
+
version: '0.1.3',
|
|
267
|
+
transforms: [
|
|
268
|
+
{
|
|
269
|
+
name: 'css',
|
|
270
|
+
meta: {title: 'css', fileExtensions: ['.css']},
|
|
271
|
+
transform: file => parseCss(file.source).toString(),
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
{apply: true, path: '.', silent: true},
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
expect(r.errors).toEqual([]);
|
|
280
|
+
expect(r.declinedCandidates).toEqual([
|
|
281
|
+
{
|
|
282
|
+
file: path.join('vendor', 'broken.css'),
|
|
283
|
+
codemod: 'core:css',
|
|
284
|
+
location: '1:1',
|
|
285
|
+
reason: 'unparseable protected file (vendored): Unclosed block',
|
|
286
|
+
},
|
|
287
|
+
]);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('declines a vendored stylesheet whose selector the real theme codemod cannot parse', async () => {
|
|
291
|
+
fs.mkdirSync(path.join(tmpDir, 'vendor'), {recursive: true});
|
|
292
|
+
fs.writeFileSync(
|
|
293
|
+
path.join(tmpDir, '.gitattributes'),
|
|
294
|
+
'vendor/** linguist-vendored\n',
|
|
295
|
+
);
|
|
296
|
+
const bundle = 'a:: { color: red; }\n';
|
|
297
|
+
fs.writeFileSync(path.join(tmpDir, 'vendor', 'bundle.css'), bundle);
|
|
298
|
+
|
|
299
|
+
const r = await runCodemods(
|
|
300
|
+
[
|
|
301
|
+
{
|
|
302
|
+
version: '0.7.0',
|
|
303
|
+
transforms: [
|
|
304
|
+
{
|
|
305
|
+
name: 'migrate-deprecated-theme-surface',
|
|
306
|
+
transform: migrateDeprecatedThemeSurface,
|
|
307
|
+
meta: migrateDeprecatedThemeSurfaceMeta,
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
{apply: true, path: '.', silent: true},
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
expect(r.errors).toEqual([]);
|
|
316
|
+
expect(r.protectedFiles).toEqual([]);
|
|
317
|
+
expect(r.declinedCandidates).toEqual([
|
|
318
|
+
{
|
|
319
|
+
file: path.join('vendor', 'bundle.css'),
|
|
320
|
+
codemod: 'core:migrate-deprecated-theme-surface',
|
|
321
|
+
location: '1:3',
|
|
322
|
+
reason:
|
|
323
|
+
'unparseable protected file (vendored): Expected a pseudo-class or pseudo-element.',
|
|
324
|
+
},
|
|
325
|
+
]);
|
|
326
|
+
expect(
|
|
327
|
+
fs.readFileSync(path.join(tmpDir, 'vendor', 'bundle.css'), 'utf-8'),
|
|
328
|
+
).toBe(bundle);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it('keeps an error a transform throws after the file parses', async () => {
|
|
332
|
+
fs.mkdirSync(path.join(tmpDir, 'vendor'), {recursive: true});
|
|
333
|
+
fs.writeFileSync(
|
|
334
|
+
path.join(tmpDir, '.gitattributes'),
|
|
335
|
+
'vendor/** linguist-vendored\n',
|
|
336
|
+
);
|
|
337
|
+
fs.writeFileSync(
|
|
338
|
+
path.join(tmpDir, 'vendor', 'a.css'),
|
|
339
|
+
'a { color: red; }\n',
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
const r = await runCodemods(
|
|
343
|
+
[
|
|
344
|
+
{
|
|
345
|
+
version: '0.1.3',
|
|
346
|
+
transforms: [
|
|
347
|
+
{
|
|
348
|
+
name: 'walks',
|
|
349
|
+
meta: {title: 'walks', fileExtensions: ['.css']},
|
|
350
|
+
transform: file => {
|
|
351
|
+
parseCss(file.source).walkRules(rule =>
|
|
352
|
+
processSelector(rule.selector, () => {
|
|
353
|
+
throw new Error('callback failed');
|
|
354
|
+
}),
|
|
355
|
+
);
|
|
356
|
+
return null;
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
],
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
{apply: true, path: '.', silent: true},
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
expect(r.declinedCandidates).toEqual([]);
|
|
366
|
+
expect(r.errors).toEqual([
|
|
367
|
+
{
|
|
368
|
+
file: path.join('vendor', 'a.css'),
|
|
369
|
+
codemod: 'core:walks',
|
|
370
|
+
error: 'callback failed',
|
|
371
|
+
},
|
|
372
|
+
]);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('lists a file another codemod still needs to change under protectedFiles only', async () => {
|
|
376
|
+
fs.mkdirSync(path.join(tmpDir, 'vendor'), {recursive: true});
|
|
377
|
+
fs.writeFileSync(
|
|
378
|
+
path.join(tmpDir, '.gitattributes'),
|
|
379
|
+
'vendor/** linguist-vendored\n',
|
|
380
|
+
);
|
|
381
|
+
fs.writeFileSync(
|
|
382
|
+
path.join(tmpDir, 'vendor', 'bundle.css'),
|
|
383
|
+
'a:: { color: red; }\n',
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
const r = await runCodemods(
|
|
387
|
+
[
|
|
388
|
+
{
|
|
389
|
+
version: '0.6.0',
|
|
390
|
+
transforms: [
|
|
391
|
+
{
|
|
392
|
+
name: 'migrate-astryx-theme-selectors-to-data-attrs',
|
|
393
|
+
transform: migrateThemeSelectors,
|
|
394
|
+
meta: migrateThemeSelectorsMeta,
|
|
395
|
+
},
|
|
396
|
+
],
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
version: '0.7.0',
|
|
400
|
+
transforms: [
|
|
401
|
+
{
|
|
402
|
+
name: 'migrate-deprecated-theme-surface',
|
|
403
|
+
transform: migrateDeprecatedThemeSurface,
|
|
404
|
+
meta: migrateDeprecatedThemeSurfaceMeta,
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
{apply: true, path: '.', silent: true},
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
expect(r.errors).toEqual([]);
|
|
413
|
+
expect(r.protectedFiles.map(item => item.file)).toEqual([
|
|
414
|
+
'vendor/bundle.css',
|
|
415
|
+
]);
|
|
416
|
+
expect(r.declinedCandidates).toEqual([]);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it('gives a rejected @scope prelude its position in the stylesheet', async () => {
|
|
420
|
+
fs.mkdirSync(path.join(tmpDir, 'vendor'), {recursive: true});
|
|
421
|
+
fs.writeFileSync(
|
|
422
|
+
path.join(tmpDir, '.gitattributes'),
|
|
423
|
+
'vendor/** linguist-vendored\n',
|
|
424
|
+
);
|
|
425
|
+
fs.writeFileSync(
|
|
426
|
+
path.join(tmpDir, 'vendor', 'bundle.css'),
|
|
427
|
+
'.x { color: blue; }\n\n@scope (a::) {\n b { color: red; }\n}\n',
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
const r = await runCodemods(
|
|
431
|
+
[
|
|
432
|
+
{
|
|
433
|
+
version: '0.7.0',
|
|
434
|
+
transforms: [
|
|
435
|
+
{
|
|
436
|
+
name: 'migrate-deprecated-theme-surface',
|
|
437
|
+
transform: migrateDeprecatedThemeSurface,
|
|
438
|
+
meta: migrateDeprecatedThemeSurfaceMeta,
|
|
439
|
+
},
|
|
440
|
+
],
|
|
441
|
+
},
|
|
442
|
+
],
|
|
443
|
+
{apply: true, path: '.', silent: true},
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
expect(r.errors).toEqual([]);
|
|
447
|
+
expect(r.declinedCandidates).toEqual([
|
|
448
|
+
{
|
|
449
|
+
file: path.join('vendor', 'bundle.css'),
|
|
450
|
+
codemod: 'core:migrate-deprecated-theme-surface',
|
|
451
|
+
location: '3:9',
|
|
452
|
+
reason:
|
|
453
|
+
'unparseable protected file (vendored): Expected a pseudo-class or pseudo-element.',
|
|
454
|
+
},
|
|
455
|
+
]);
|
|
456
|
+
});
|
|
457
|
+
});
|