@astryxdesign/cli 0.7.5-canary.fccd771 → 0.7.5
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 +91 -3
- package/README.md +2 -2
- package/api/hook/detail/detail.test.mjs +11 -0
- package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
- package/api/integration/pack-check.mjs +10 -4
- package/api/integration/pack-check.test.mjs +5 -1
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/template/tokenizer-showcase.test.mjs +47 -0
- package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
- package/api/theme/build/build.icon-entry-variants.test.mjs +134 -0
- package/api/theme/build/build.icon-function-entries.test.mjs +499 -0
- package/api/theme/build/build.icon-variants.test.mjs +105 -0
- package/api/theme/build/build.mjs +371 -113
- package/api/theme/build/build.project-core.test.mjs +63 -8
- package/api/theme/build/build.test.mjs +77 -0
- package/api/theme/build/icon-imports.d.mts +12 -2
- package/api/theme/build/icon-imports.mjs +36 -11
- package/api/upgrade/_adapter.d.mts +47 -2
- package/api/upgrade/_adapter.mjs +58 -2
- package/api/upgrade/run/failure-receipt.test.mjs +212 -0
- package/api/upgrade/run/outcomes.test.mjs +646 -0
- package/api/upgrade/run/run.d.mts +36 -0
- package/api/upgrade/run/run.mjs +670 -44
- package/api/upgrade/upgrade.doc.mjs +4 -4
- package/api/upgrade/upgrade.mjs +19 -4
- package/api/upgrade/upgrade.type.d.mts +36 -1
- package/api/upgrade/upgrade.type.mjs +29 -4
- package/assets/codemods/__tests__/registry.test.mjs +1 -0
- 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/outcome.mjs +79 -0
- package/assets/codemods/outcome.test.mjs +40 -0
- package/assets/codemods/parse.mjs +94 -0
- package/assets/codemods/registry.mjs +1 -0
- package/assets/codemods/run-codemod.mjs +109 -5
- package/assets/codemods/runner.mjs +119 -13
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- package/assets/codemods/transforms/v0.1.2/rename-text-color-active-to-accent.mjs +1 -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.1.5/rename-switch-label-spacing-default-to-hug.mjs +1 -1
- package/assets/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +1 -1
- package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +1 -1
- package/assets/codemods/transforms/v0.2.0/remove-tablist-orientation.mjs +1 -1
- package/assets/codemods/transforms/v0.2.1/migrate-dialog-position-to-logical.mjs +1 -1
- 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/__tests__/validate-data-token-ownership.test.mjs +143 -70
- 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/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +23 -78
- package/assets/codemods/transforms/v0.7.5/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
- package/assets/codemods/transforms/v0.7.5/index.mjs +20 -0
- package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +315 -0
- package/assets/docs/README.md +13 -13
- package/assets/docs/author-a-theme.doc.mjs +5 -1
- package/assets/docs/getting-started.doc.mjs +5 -5
- package/assets/docs/icons.doc.mjs +82 -1
- package/assets/docs/motion.doc.mjs +1 -1
- package/assets/docs/theme.doc.dense.mjs +8 -0
- package/assets/docs/theme.doc.mjs +16 -0
- package/assets/docs/theme.doc.zh.mjs +11 -0
- package/assets/docs/tree/i18n-library-integration.doc.mjs +1 -1
- package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +145 -1
- package/assets/docs/tree/tokens-ease.doc.mjs +4 -0
- package/assets/docs/tree/tokens.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
- package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +13 -6
- package/assets/templates/pages/dashboard-alert-rail/page.tsx +3 -3
- package/assets/templates/pages/library/page.tsx +1 -2
- package/assets/templates/pages/table-comparison/page.tsx +12 -3
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
- package/assets/templates/themes/butter/butterTheme.ts +47 -44
- package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
- package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
- package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
- package/assets/templates/themes/stone/stoneTheme.ts +46 -21
- package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
- package/assets/theme.template.ts +19 -6
- package/authoring/codemod/type.ts +10 -0
- package/authoring/config/config.doc.mjs +1 -1
- package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
- package/clients/cli/commands/build-theme.outside-project.test.mjs +140 -0
- package/clients/cli/commands/swizzle.routing.test.mjs +1 -1
- package/clients/cli/commands/upgrade.doc.mjs +47 -2
- 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/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
- package/foundation/agent-docs/agent-docs.mjs +1 -0
- package/foundation/agent-docs/agent-docs.test.mjs +5 -0
- package/foundation/config/project.d.mts +1 -1
- package/foundation/config/project.mjs +1 -1
- package/foundation/debug/redact.test.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +2 -6
- 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/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +13 -12
|
@@ -128,13 +128,13 @@ export const doc = {
|
|
|
128
128
|
{
|
|
129
129
|
type: 'upgrade.run',
|
|
130
130
|
description:
|
|
131
|
-
'The terminal run receipt: from, to, codemods (count), integrations, agentDocs, agentDocsRefreshed, registryCompositions (when receipts are found), sourcePathFound (false when the resolved `path` does not exist, so nothing was scanned), filesChanged, transformsApplied, modifiedFiles, protectedFiles, declinedCandidates, errors, and complete. When a protected file still requires a change, complete is false and errorCode is ERR_CODEMOD_PROTECTED; the CLI exits nonzero while preserving the structured receipt. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run, and command runs the same upgrade with the matching CLI.',
|
|
131
|
+
'The terminal run receipt: from, to, codemods (count), integrations, agentDocs, agentDocsRefreshed, registryCompositions (when receipts are found), sourcePathFound (false when the resolved `path` does not exist, so nothing was scanned), filesChanged, transformsApplied, modifiedFiles, protectedFiles, declinedCandidates (left unchanged for manual review, including code a codemod identified but cannot migrate; never incomplete), regenerate (generated files to rebuild, with their commands), errors, and complete. When a protected file still requires a change, including a protected file in regenerate, complete is false and errorCode is ERR_CODEMOD_PROTECTED; the CLI exits nonzero while preserving the structured receipt. A run that fails after its codemods ran throws instead (see throws), and the thrown AstryxError carries the same receipt on `receipt`, with complete false and errorCode set to its code. A file in regenerate that nothing protects is such a failure: it is also in errors, and the run throws ERR_CODEMOD_FAILED. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run, and command runs the same upgrade with the matching CLI.',
|
|
132
132
|
},
|
|
133
133
|
],
|
|
134
134
|
throws: [
|
|
135
135
|
{
|
|
136
136
|
code: 'ERR_INVALID_ARGUMENT',
|
|
137
|
-
when: '`from` is missing (and neither `list` nor `registry` is set); `list` and `registry` are both set; `list` is combined with `from`, `force`, `apply`, `path` (non-default), `codemod`, `skipCodemod`, `integration` or `installDeps`; `registry` is combined with `from`, `force`, `codemod`, `skipCodemod`, `integration` or `installDeps`; an `integration` specifier is invalid or not installed; or astryx.config fails to load or validate and no pending config codemod repairs it',
|
|
137
|
+
when: '`from` is missing (and neither `list` nor `registry` is set); `list` and `registry` are both set; `list` is combined with `from`, `force`, `apply`, `path` (non-default), `codemod`, `skipCodemod`, `integration` or `installDeps`; `registry` is combined with `from`, `force`, `codemod`, `skipCodemod`, `integration` or `installDeps`; an `integration` specifier is invalid or not installed; or astryx.config fails to load or validate and no pending config codemod repairs it (when core codemods already wrote files, the error carries their receipt on `receipt`)',
|
|
138
138
|
},
|
|
139
139
|
{code: 'ERR_INVALID_VERSION', when: '`from` is not a valid semver string'},
|
|
140
140
|
{
|
|
@@ -155,11 +155,11 @@ export const doc = {
|
|
|
155
155
|
},
|
|
156
156
|
{
|
|
157
157
|
code: 'ERR_CODEMOD_FAILED',
|
|
158
|
-
when:
|
|
158
|
+
when: "one or more codemods failed (including a generated file to regenerate that nothing protects), or a post-codemod hook failed, and no protected file still needs a change (otherwise an upgrade.run receipt with complete: false is returned). The error carries the run's receipt on `receipt`: the files already changed, each failure in errors, complete: false",
|
|
159
159
|
},
|
|
160
160
|
{
|
|
161
161
|
code: 'ERR_CODEMOD_PROTECTION_SOURCE',
|
|
162
|
-
when: 'a working-tree protection declaration cannot be read or parsed before writes begin',
|
|
162
|
+
when: 'a working-tree protection declaration cannot be read or parsed before writes begin, or after post-codemod hooks rewrite it (the error then carries the receipt on `receipt`)',
|
|
163
163
|
},
|
|
164
164
|
],
|
|
165
165
|
examples: [
|
package/api/upgrade/upgrade.mjs
CHANGED
|
@@ -120,8 +120,23 @@ export async function upgrade(options = {}, {cwd = process.cwd()} = {}) {
|
|
|
120
120
|
// A run from a subfolder upgrades the project the folder belongs to, and
|
|
121
121
|
// names files relative to the folder it ran in.
|
|
122
122
|
const scoped = scopeToProject(options, cwd);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
scoped,
|
|
126
|
-
|
|
123
|
+
let result;
|
|
124
|
+
try {
|
|
125
|
+
result = await run(scoped.options, {
|
|
126
|
+
cwd: scoped.cwd,
|
|
127
|
+
origin: scoped.origin,
|
|
128
|
+
});
|
|
129
|
+
} catch (err) {
|
|
130
|
+
// A failure after codemods wrote carries their receipt; name its files
|
|
131
|
+
// from the folder the command ran in, as a returned receipt does.
|
|
132
|
+
const receipt = /** @type {any} */ (err)?.receipt;
|
|
133
|
+
if (err instanceof AstryxError && receipt) {
|
|
134
|
+
/** @type {any} */ (err).receipt = relativeToOrigin(
|
|
135
|
+
{type: 'upgrade.run', data: receipt},
|
|
136
|
+
scoped,
|
|
137
|
+
).data;
|
|
138
|
+
}
|
|
139
|
+
throw err;
|
|
140
|
+
}
|
|
141
|
+
return relativeToOrigin(result, scoped);
|
|
127
142
|
}
|
|
@@ -162,6 +162,29 @@ export type ProtectedCodemodFile = {
|
|
|
162
162
|
*/
|
|
163
163
|
commands: string[];
|
|
164
164
|
};
|
|
165
|
+
/**
|
|
166
|
+
* A generated file that must be rebuilt before the upgrade is complete: a
|
|
167
|
+
* protected generated file a codemod still needs to change (also listed in
|
|
168
|
+
* `protectedFiles`), or a generated output a codemod reported out of date.
|
|
169
|
+
*/
|
|
170
|
+
export type RegenerateFile = {
|
|
171
|
+
/**
|
|
172
|
+
* Path relative to the folder the command ran in.
|
|
173
|
+
*/
|
|
174
|
+
file: string;
|
|
175
|
+
/**
|
|
176
|
+
* Codemods that need the rebuild.
|
|
177
|
+
*/
|
|
178
|
+
codemods: string[];
|
|
179
|
+
/**
|
|
180
|
+
* Exact commands that rebuild the file, when known: the generated header's `Command:` line, or the command the codemod names (such as `astryx theme build`).
|
|
181
|
+
*/
|
|
182
|
+
commands: string[];
|
|
183
|
+
/**
|
|
184
|
+
* Why a codemod reported the file out of date; empty for a protected generated file that no codemod reported out of date, whose `protectedFiles` entry carries its declarations.
|
|
185
|
+
*/
|
|
186
|
+
messages: string[];
|
|
187
|
+
};
|
|
165
188
|
/**
|
|
166
189
|
* Present only when the installed `@astryxdesign/core` (the response's `to`) is
|
|
167
190
|
* newer than the running CLI. Core codemods ship inside the CLI, so this CLI
|
|
@@ -193,7 +216,8 @@ export type UpgradeRunResponse = {
|
|
|
193
216
|
sourcePathFound: boolean;
|
|
194
217
|
registryCompositions?: RegistryCompositionSummary | undefined;
|
|
195
218
|
complete?: boolean | undefined;
|
|
196
|
-
|
|
219
|
+
regenerate?: RegenerateFile[] | undefined;
|
|
220
|
+
errorCode?: string | undefined;
|
|
197
221
|
filesChanged?: number | undefined;
|
|
198
222
|
modifiedFiles?: string[] | undefined;
|
|
199
223
|
protectedFiles?: ProtectedCodemodFile[] | undefined;
|
|
@@ -211,6 +235,17 @@ export type UpgradeRunResponse = {
|
|
|
211
235
|
cliBehindCore?: CliBehindCore | undefined;
|
|
212
236
|
};
|
|
213
237
|
};
|
|
238
|
+
/**
|
|
239
|
+
* What a failed upgrade had already done. When a run fails after its codemods
|
|
240
|
+
* ran (a codemod or post-codemod hook failed, or an error stopped it after
|
|
241
|
+
* codemods wrote files), the failure keeps its usual shape: the --json error
|
|
242
|
+
* envelope `{apiVersion, error, code}` and a rejected `upgrade()` with that
|
|
243
|
+
* `code`. The envelope adds `receipt`, and the thrown AstryxError a `receipt`
|
|
244
|
+
* property: the same `upgrade.run` data a completed run returns, with
|
|
245
|
+
* `complete: false` and `errorCode` equal to the error's `code`. Files in
|
|
246
|
+
* `modifiedFiles` stay changed.
|
|
247
|
+
*/
|
|
248
|
+
export type UpgradeFailureReceipt = UpgradeRunResponse["data"];
|
|
214
249
|
/**
|
|
215
250
|
* astryx --json upgrade — short-circuit status results.
|
|
216
251
|
*
|
|
@@ -108,6 +108,17 @@
|
|
|
108
108
|
* @property {string[]} commands Exact regeneration commands found in generated headers, when present.
|
|
109
109
|
*/
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* A generated file that must be rebuilt before the upgrade is complete: a
|
|
113
|
+
* protected generated file a codemod still needs to change (also listed in
|
|
114
|
+
* `protectedFiles`), or a generated output a codemod reported out of date.
|
|
115
|
+
* @typedef {object} RegenerateFile
|
|
116
|
+
* @property {string} file Path relative to the folder the command ran in.
|
|
117
|
+
* @property {string[]} codemods Codemods that need the rebuild.
|
|
118
|
+
* @property {string[]} commands Exact commands that rebuild the file, when known: the generated header's `Command:` line, or the command the codemod names (such as `astryx theme build`).
|
|
119
|
+
* @property {string[]} messages Why a codemod reported the file out of date; empty for a protected generated file that no codemod reported out of date, whose `protectedFiles` entry carries its declarations.
|
|
120
|
+
*/
|
|
121
|
+
|
|
111
122
|
/**
|
|
112
123
|
* Present only when the installed `@astryxdesign/core` (the response's `to`) is
|
|
113
124
|
* newer than the running CLI. Core codemods ship inside the CLI, so this CLI
|
|
@@ -131,17 +142,31 @@
|
|
|
131
142
|
* @property {AgentDocsSummary} data.agentDocs
|
|
132
143
|
* @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
144
|
* @property {RegistryCompositionSummary} [data.registryCompositions]
|
|
134
|
-
* @property {boolean} [data.complete] False when protected required changes remain.
|
|
135
|
-
* @property {
|
|
145
|
+
* @property {boolean} [data.complete] False when protected required changes remain, including a protected file in `regenerate`. Declined candidates alone never make it false. Also false on the receipt a failed run's error carries (`UpgradeFailureReceipt`).
|
|
146
|
+
* @property {RegenerateFile[]} [data.regenerate] Generated files to rebuild, with their commands; rebuild them, then run the same upgrade again. A listed file the project protects (for example with an `@generated` header) is also in `protectedFiles`, with the declaration that protects it and the same commands, and makes the run incomplete with `ERR_CODEMOD_PROTECTED`. A listed file nothing protects is a codemod error: it is also in `errors`, and the run fails with `ERR_CODEMOD_FAILED` (`UpgradeFailureReceipt`).
|
|
147
|
+
* @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
148
|
* @property {number} [data.filesChanged] Distinct files changed across core + integration codemods (apply mode). One file that four codemods each changed counts once.
|
|
137
149
|
* @property {string[]} [data.modifiedFiles] Files changed or previewed, relative to the folder the command ran in.
|
|
138
150
|
* @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.
|
|
151
|
+
* @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. Code a codemod identified but cannot migrate safely is listed here too, with its line as `location` when known and a `reason` that starts with `manual migration needed (<codemod>):` followed by what to change. A file with several declined findings, of either kind, keeps one row: each finding keeps its own prefix, they are joined by `; `, unparseable-file findings first, then manual migrations, each in the order found, and `location` is the first finding's own location (absent when it has none). A later finding whose location differs from the row's ends with ` (at <location>)`, or ` (location unknown)` when it has none; one without a suffix is at the row's location. Declined candidates do not make the run incomplete. Each `file` is relative to the folder the command ran in.
|
|
140
152
|
* @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.
|
|
153
|
+
* @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. A returned `ERR_CODEMOD_PROTECTED` result lists them too when a protected file wins over them: a post-codemod hook failure, or an `astryx.config` that fails validation (`{file: '.', codemod: 'config', error}`). Each `file` is relative to the folder the command ran in.
|
|
142
154
|
* @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
155
|
*/
|
|
144
156
|
|
|
157
|
+
/**
|
|
158
|
+
* What a failed upgrade had already done. When a run fails after its codemods
|
|
159
|
+
* ran (a codemod or post-codemod hook failed, or an error stopped it after
|
|
160
|
+
* codemods wrote files), the failure keeps its usual shape: the --json error
|
|
161
|
+
* envelope `{apiVersion, error, code}` and a rejected `upgrade()` with that
|
|
162
|
+
* `code`. The envelope adds `receipt`, and the thrown AstryxError a `receipt`
|
|
163
|
+
* property: the same `upgrade.run` data a completed run returns, with
|
|
164
|
+
* `complete: false` and `errorCode` equal to the error's `code`. Files in
|
|
165
|
+
* `modifiedFiles` stay changed.
|
|
166
|
+
*
|
|
167
|
+
* @typedef {UpgradeRunResponse['data']} UpgradeFailureReceipt
|
|
168
|
+
*/
|
|
169
|
+
|
|
145
170
|
/**
|
|
146
171
|
* astryx --json upgrade — short-circuit status results.
|
|
147
172
|
*
|
|
@@ -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
|
+
});
|