@astryxdesign/cli 0.7.4 → 0.7.5-canary.04434e7
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 +19 -19
- package/api/component/_adapter.mjs +16 -1
- package/api/component/component.test.mjs +31 -0
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +5 -2
- package/api/docs/_adapter.mjs +24 -16
- package/api/docs/docs.test.mjs +18 -0
- package/api/docs/integrationDocs.test.mjs +2 -2
- package/api/experimental.d.mts +5 -0
- package/api/experimental.mjs +15 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/icon/_adapter.d.mts +3 -2
- package/api/icon/_adapter.mjs +16 -3
- package/api/icon/_authoring.d.mts +5 -1
- package/api/icon/_authoring.mjs +478 -63
- package/api/icon/_options.d.mts +11 -0
- package/api/icon/_options.mjs +39 -4
- package/api/icon/_records.d.mts +19 -0
- package/api/icon/_records.mjs +25 -0
- package/api/icon/add/add.d.mts +3 -3
- package/api/icon/add/add.mjs +227 -14
- package/api/icon/all-or-nothing.test.mjs +283 -0
- package/api/icon/detail/detail.mjs +2 -13
- package/api/icon/error-codes.test.mjs +14 -7
- package/api/icon/icon.d.mts +2 -2
- package/api/icon/icon.doc.mjs +30 -2
- package/api/icon/icon.mjs +57 -8
- package/api/icon/icon.test.mjs +133 -1
- package/api/icon/icon.type.d.mts +126 -1
- package/api/icon/icon.type.mjs +67 -3
- package/api/icon/iconAdd.doc.mjs +22 -6
- package/api/icon/iconMap.doc.mjs +24 -8
- package/api/icon/iconNewDefinition.doc.mjs +2 -2
- package/api/icon/iconNewSet.doc.mjs +30 -2
- package/api/icon/iconUse.doc.mjs +4 -1
- package/api/icon/map/map.d.mts +4 -4
- package/api/icon/map/map.mjs +134 -9
- package/api/icon/new-definition/new-definition.mjs +6 -2
- package/api/icon/new-set/new-set.mjs +2 -2
- package/api/icon/new-set/new-set.test.mjs +60 -10
- package/api/icon/option-pairs.test.mjs +368 -0
- package/api/icon/search/search.d.mts +10 -0
- package/api/icon/search/search.mjs +55 -14
- package/api/icon/use/use.mjs +2 -13
- package/api/integration/add-helpers.d.mts +15 -1
- package/api/integration/add-helpers.mjs +1 -1
- 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/integration/validate-integration.type.d.mts +3 -2
- package/api/integration/validate-integration.type.mjs +3 -2
- package/api/render/_adapter.d.mts +28 -0
- package/api/render/_adapter.mjs +540 -0
- package/api/render/render.d.mts +15 -0
- package/api/render/render.doc.d.mts +9 -0
- package/api/render/render.doc.mjs +112 -0
- package/api/render/render.mjs +113 -0
- package/api/render/render.test.mjs +1155 -0
- package/api/render/render.type.d.mts +74 -0
- package/api/render/render.type.mjs +64 -0
- package/api/search/_adapter.test.mjs +21 -2
- package/api/search/_result.d.mts +5 -5
- package/api/search/search.d.mts +1 -1
- package/api/template/template.mjs +3 -1
- package/api/template/template.type.d.mts +2 -1
- package/api/template/template.type.mjs +1 -1
- package/api/template/unknown-name.test.mjs +63 -0
- package/api/upgrade/run/failure-receipt.test.mjs +155 -0
- package/api/upgrade/run/run.mjs +170 -8
- 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 +16 -3
- package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
- package/assets/codemods/integration-runner.mjs +1 -1
- package/assets/codemods/run-codemod.mjs +17 -3
- package/assets/codemods/runner.mjs +81 -8
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- 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 +123 -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 +200 -32
- package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +19 -77
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
- package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +50 -20
- package/assets/docs/tree/render-pages.doc.mjs +94 -0
- package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
- package/assets/icons/definitions/activity.doc.mjs +1 -1
- package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
- package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
- package/assets/icons/definitions/alignStart.doc.mjs +10 -0
- package/assets/icons/definitions/archive.doc.mjs +1 -1
- package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
- package/assets/icons/definitions/attach.doc.mjs +1 -1
- package/assets/icons/definitions/audio.doc.mjs +1 -1
- package/assets/icons/definitions/cart.doc.mjs +1 -1
- package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
- package/assets/icons/definitions/close.doc.mjs +1 -1
- package/assets/icons/definitions/collapse.doc.mjs +1 -1
- package/assets/icons/definitions/compose.doc.mjs +1 -1
- package/assets/icons/definitions/conversation.doc.mjs +1 -1
- package/assets/icons/definitions/copy.doc.mjs +1 -1
- package/assets/icons/definitions/cpu.doc.mjs +9 -0
- package/assets/icons/definitions/database.doc.mjs +1 -1
- package/assets/icons/definitions/desktop.doc.mjs +1 -1
- package/assets/icons/definitions/discount.doc.mjs +1 -1
- package/assets/icons/definitions/download.doc.mjs +1 -1
- package/assets/icons/definitions/emoji.doc.mjs +1 -1
- package/assets/icons/definitions/error.doc.mjs +1 -1
- package/assets/icons/definitions/expand.doc.mjs +1 -1
- package/assets/icons/definitions/experiment.doc.mjs +1 -1
- package/assets/icons/definitions/externalLink.doc.mjs +7 -1
- package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
- package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
- package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
- package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
- package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
- package/assets/icons/definitions/gitFork.doc.mjs +9 -0
- package/assets/icons/definitions/info.doc.mjs +1 -1
- package/assets/icons/definitions/location.doc.mjs +1 -1
- package/assets/icons/definitions/mention.doc.mjs +1 -1
- package/assets/icons/definitions/menu.doc.mjs +1 -1
- package/assets/icons/definitions/microphone.doc.mjs +1 -1
- package/assets/icons/definitions/mobile.doc.mjs +1 -1
- package/assets/icons/definitions/money.doc.mjs +1 -1
- package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
- package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
- package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
- package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
- package/assets/icons/definitions/panelRight.doc.mjs +10 -0
- package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
- package/assets/icons/definitions/redo.doc.mjs +1 -1
- package/assets/icons/definitions/refresh.doc.mjs +1 -1
- package/assets/icons/definitions/rotate.doc.mjs +9 -0
- package/assets/icons/definitions/scale.doc.mjs +10 -0
- package/assets/icons/definitions/search.doc.mjs +1 -1
- package/assets/icons/definitions/send.doc.mjs +1 -1
- package/assets/icons/definitions/settings.doc.mjs +1 -1
- package/assets/icons/definitions/star.doc.mjs +1 -1
- package/assets/icons/definitions/stop.doc.mjs +1 -1
- package/assets/icons/definitions/success.doc.mjs +1 -1
- package/assets/icons/definitions/textCase.doc.mjs +9 -0
- package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
- package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
- package/assets/icons/definitions/trendDown.doc.mjs +7 -1
- package/assets/icons/definitions/trendUp.doc.mjs +1 -1
- package/assets/icons/definitions/undo.doc.mjs +1 -1
- package/assets/icons/definitions/upload.doc.mjs +1 -1
- package/assets/icons/definitions/userAdd.doc.mjs +1 -1
- package/assets/icons/definitions/warning.doc.mjs +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +9 -8
- package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
- package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
- package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
- package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
- package/authoring/debug/parse.d.mts +2 -2
- package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
- package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
- package/authoring/doctypes/icon-set/parse.d.mts +1 -0
- package/authoring/doctypes/icon-set/parse.mjs +1 -0
- package/authoring/doctypes/icon-set/type.ts +5 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +2 -1
- package/clients/cli/commands/doctor.mjs +16 -17
- package/clients/cli/commands/experimental/icon.mjs +167 -35
- package/clients/cli/commands/experimental/index.mjs +2 -0
- package/clients/cli/commands/experimental/render.mjs +113 -0
- package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
- package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
- package/clients/cli/commands/experimental-render.doc.mjs +60 -0
- package/clients/cli/commands/experimental.doc.mjs +4 -2
- package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
- package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
- package/clients/cli/commands/icon.test.mjs +1 -1
- package/clients/cli/commands/template.mjs +4 -1
- package/clients/cli/commands/text-json-parity.test.mjs +46 -0
- package/clients/cli/commands/upgrade.doc.mjs +17 -0
- package/clients/cli/commands/upgrade.file-protection.test.mjs +29 -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/index.mjs +1 -0
- package/foundation/discovery/component-discovery.d.mts +2 -1
- package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
- package/foundation/discovery/component-discovery.mjs +13 -7
- package/foundation/discovery/icon-set-checks.d.mts +43 -9
- package/foundation/discovery/icon-set-checks.mjs +296 -21
- package/foundation/discovery/icon-set-checks.test.mjs +125 -12
- package/foundation/discovery/icon-set-writer.d.mts +192 -3
- package/foundation/discovery/icon-set-writer.mjs +608 -34
- package/foundation/discovery/icon-set-writer.test.mjs +26 -0
- package/foundation/discovery/module-exports.mjs +82 -25
- package/foundation/discovery/module-exports.test.mjs +38 -1
- package/foundation/discovery/package-exports.d.mts +13 -0
- package/foundation/discovery/package-exports.mjs +40 -1
- package/foundation/discovery/template-icons.d.mts +6 -0
- package/foundation/discovery/template-icons.mjs +98 -10
- package/foundation/discovery/template-icons.test.mjs +103 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +20 -5
- package/foundation/doc-compiler/import.mjs +81 -8
- package/foundation/doc-compiler/read.d.mts +4 -3
- package/foundation/doc-compiler/read.mjs +15 -10
- package/foundation/doc-compiler/read.test.mjs +59 -1
- package/foundation/doc-compiler/tree.mjs +3 -1
- package/foundation/fs/module-loader.d.mts +3 -2
- package/foundation/fs/module-loader.mjs +3 -2
- package/foundation/fs/publish-file-eperm-mutation.test.mjs +2 -0
- package/foundation/fs/read-record.d.mts +27 -0
- package/foundation/fs/read-record.mjs +83 -15
- package/foundation/fs/read-record.test.mjs +88 -1
- package/foundation/render/assets.d.mts +31 -0
- package/foundation/render/assets.mjs +102 -0
- package/foundation/render/component-map.d.mts +52 -0
- package/foundation/render/component-map.mjs +141 -0
- package/foundation/render/css-cut.d.mts +29 -0
- package/foundation/render/css-cut.mjs +144 -0
- package/foundation/render/embedded-files.d.mts +28 -0
- package/foundation/render/embedded-files.mjs +108 -0
- package/foundation/render/embedded-imports.d.mts +61 -0
- package/foundation/render/embedded-imports.mjs +315 -0
- package/foundation/render/html-reader.d.mts +37 -0
- package/foundation/render/html-reader.mjs +121 -0
- package/foundation/render/page-worker.d.mts +7 -0
- package/foundation/render/page-worker.mjs +519 -0
- package/foundation/render/rebuild.d.mts +19 -0
- package/foundation/render/rebuild.mjs +269 -0
- package/foundation/render/render-page.d.mts +85 -0
- package/foundation/render/render-page.mjs +612 -0
- package/foundation/render/render.test.mjs +117 -0
- package/foundation/render/source-block.d.mts +52 -0
- package/foundation/render/source-block.mjs +106 -0
- package/foundation/response/base.d.ts +7 -0
- package/foundation/response/error-codes.d.mts +10 -1
- package/foundation/response/error-codes.doc.mjs +59 -2
- package/foundation/response/error-codes.mjs +62 -1
- package/foundation/response/json.d.mts +10 -3
- package/foundation/response/json.mjs +16 -4
- package/foundation/response/response-types.doc.mjs +38 -1
- package/foundation/text/string-utils.mjs +33 -0
- package/foundation/text/string-utils.test.mjs +17 -0
- package/foundation/text/suggest-order.d.mts +17 -3
- package/foundation/text/suggest-order.mjs +58 -13
- package/foundation/text/suggest-order.test.mjs +53 -0
- package/package.json +14 -9
package/api/upgrade/run/run.mjs
CHANGED
|
@@ -109,6 +109,80 @@ function loadFileProtection(cwd) {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
/**
|
|
113
|
+
* The receipt of a run that stopped after codemods ran. Whatever the codemods
|
|
114
|
+
* already wrote stays on disk, so the error the run throws carries this
|
|
115
|
+
* receipt (`failWithReceipt`): a caller that reads only the error would
|
|
116
|
+
* report nothing changed while the files it lists remain modified
|
|
117
|
+
* (spec:AST-040 FR7).
|
|
118
|
+
*
|
|
119
|
+
* @param {{from: string, to: string, codemods: number, integrations: string[], sourcePathFound: boolean, cwd: string, changedFiles: string[], transformsApplied: number, protectedRows: Array<{file: string, codemod: string, reason: string, declaration: string, generated: boolean, command?: string}>, errors: Array<{file: string, codemod: string, error: string}>, errorCode: string, cliBehindCore?: import('../upgrade.type.mjs').CliBehindCore | null, registryCompositions?: import('../upgrade.type.mjs').RegistryCompositionSummary}} facts
|
|
120
|
+
* @returns {import('../upgrade.type.mjs').UpgradeRunResponse['data']}
|
|
121
|
+
*/
|
|
122
|
+
function stoppedReceipt({
|
|
123
|
+
from,
|
|
124
|
+
to,
|
|
125
|
+
codemods,
|
|
126
|
+
integrations,
|
|
127
|
+
sourcePathFound,
|
|
128
|
+
cwd,
|
|
129
|
+
changedFiles,
|
|
130
|
+
transformsApplied,
|
|
131
|
+
protectedRows,
|
|
132
|
+
errors,
|
|
133
|
+
errorCode,
|
|
134
|
+
cliBehindCore,
|
|
135
|
+
registryCompositions,
|
|
136
|
+
}) {
|
|
137
|
+
const modifiedFiles = uniqueFiles(changedFiles).map(file =>
|
|
138
|
+
path.relative(cwd, file).split(path.sep).join('/'),
|
|
139
|
+
);
|
|
140
|
+
return /** @type {import('../upgrade.type.mjs').UpgradeRunResponse['data']} */ ({
|
|
141
|
+
from,
|
|
142
|
+
to,
|
|
143
|
+
codemods,
|
|
144
|
+
integrations,
|
|
145
|
+
agentDocsRefreshed: false,
|
|
146
|
+
agentDocs: {
|
|
147
|
+
status: 'current',
|
|
148
|
+
installedVersion: to,
|
|
149
|
+
fromVersions: [],
|
|
150
|
+
files: [],
|
|
151
|
+
refreshed: false,
|
|
152
|
+
action: 'none',
|
|
153
|
+
},
|
|
154
|
+
sourcePathFound,
|
|
155
|
+
filesChanged: modifiedFiles.length,
|
|
156
|
+
transformsApplied,
|
|
157
|
+
modifiedFiles,
|
|
158
|
+
protectedFiles: summarizeProtectedFiles(protectedRows),
|
|
159
|
+
declinedCandidates: [],
|
|
160
|
+
complete: false,
|
|
161
|
+
errorCode,
|
|
162
|
+
errors,
|
|
163
|
+
...(registryCompositions ? {registryCompositions} : {}),
|
|
164
|
+
...(cliBehindCore ? {cliBehindCore} : {}),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The error a run throws once codemods have run: the same message and stable
|
|
170
|
+
* code as always, plus the run's receipt on `receipt`, so the JSON error
|
|
171
|
+
* envelope and a programmatic caller can still see what was written.
|
|
172
|
+
* @param {string} message
|
|
173
|
+
* @param {string} code
|
|
174
|
+
* @param {import('../upgrade.type.mjs').UpgradeRunResponse['data']} receipt
|
|
175
|
+
* @returns {AstryxError & {receipt: import('../upgrade.type.mjs').UpgradeRunResponse['data']}}
|
|
176
|
+
*/
|
|
177
|
+
function failWithReceipt(message, code, receipt) {
|
|
178
|
+
const err =
|
|
179
|
+
/** @type {AstryxError & {receipt: import('../upgrade.type.mjs').UpgradeRunResponse['data']}} */ (
|
|
180
|
+
new AstryxError(message, undefined, code)
|
|
181
|
+
);
|
|
182
|
+
err.receipt = receipt;
|
|
183
|
+
return err;
|
|
184
|
+
}
|
|
185
|
+
|
|
112
186
|
/**
|
|
113
187
|
* Run the upgrade pipeline for a validated, non-list invocation. Returns the
|
|
114
188
|
* terminal run receipt, or one of the status short-circuits; throws AstryxError
|
|
@@ -368,6 +442,32 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
368
442
|
// Genuine config error: abort.
|
|
369
443
|
logger.error(configErr.message);
|
|
370
444
|
logger.log('Aborted\n');
|
|
445
|
+
if ((coreResult?.writtenFiles.length ?? 0) > 0) {
|
|
446
|
+
// Core codemods already wrote: the error carries what they changed.
|
|
447
|
+
if (cliBehindCore) logCliBehindCore(cliBehindCore, targetVersion);
|
|
448
|
+
const stopped = stoppedReceipt({
|
|
449
|
+
from: currentVersion,
|
|
450
|
+
to: targetVersion,
|
|
451
|
+
codemods: totalTransforms,
|
|
452
|
+
integrations: [],
|
|
453
|
+
sourcePathFound,
|
|
454
|
+
cwd,
|
|
455
|
+
changedFiles: coreResult?.changedFiles ?? [],
|
|
456
|
+
transformsApplied: coreResult?.totalTransformsApplied ?? 0,
|
|
457
|
+
protectedRows: [],
|
|
458
|
+
errors: [
|
|
459
|
+
...(coreResult?.errors ?? []),
|
|
460
|
+
{file: '.', codemod: 'config', error: configErr.message},
|
|
461
|
+
],
|
|
462
|
+
errorCode: ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
463
|
+
cliBehindCore,
|
|
464
|
+
});
|
|
465
|
+
throw failWithReceipt(
|
|
466
|
+
configErr.message,
|
|
467
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
468
|
+
stopped,
|
|
469
|
+
);
|
|
470
|
+
}
|
|
371
471
|
throw new AstryxError(
|
|
372
472
|
configErr.message,
|
|
373
473
|
undefined,
|
|
@@ -561,7 +661,30 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
561
661
|
logger.error(msg);
|
|
562
662
|
if (initialProtected.length === 0) {
|
|
563
663
|
logger.log('Upgrade failed\n');
|
|
564
|
-
throw
|
|
664
|
+
throw failWithReceipt(
|
|
665
|
+
msg,
|
|
666
|
+
ERROR_CODES.ERR_CODEMOD_FAILED,
|
|
667
|
+
stoppedReceipt({
|
|
668
|
+
from: currentVersion,
|
|
669
|
+
to: targetVersion,
|
|
670
|
+
codemods: totalTransforms,
|
|
671
|
+
integrations: receipt.integrations,
|
|
672
|
+
sourcePathFound,
|
|
673
|
+
cwd,
|
|
674
|
+
changedFiles: mergedChangedFiles,
|
|
675
|
+
transformsApplied: mergedTransformsApplied,
|
|
676
|
+
protectedRows: [],
|
|
677
|
+
errors: [
|
|
678
|
+
...mergedErrors,
|
|
679
|
+
{file: '.', codemod: 'post-codemod-hook', error: msg},
|
|
680
|
+
],
|
|
681
|
+
errorCode: ERROR_CODES.ERR_CODEMOD_FAILED,
|
|
682
|
+
cliBehindCore,
|
|
683
|
+
...(registryResult
|
|
684
|
+
? {registryCompositions: registryResult.summary}
|
|
685
|
+
: {}),
|
|
686
|
+
}),
|
|
687
|
+
);
|
|
565
688
|
}
|
|
566
689
|
hookFailure = msg;
|
|
567
690
|
finalErrors = [
|
|
@@ -587,7 +710,35 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
587
710
|
// to distinguish resolved outputs from changes that remain blocked.
|
|
588
711
|
let remainingProtected = initialProtected;
|
|
589
712
|
if (apply && shouldRunHooks && !hookFailure) {
|
|
590
|
-
|
|
713
|
+
let refreshedProtection;
|
|
714
|
+
try {
|
|
715
|
+
refreshedProtection = loadFileProtection(cwd);
|
|
716
|
+
} catch (err) {
|
|
717
|
+
if (!(err instanceof AstryxError)) throw err;
|
|
718
|
+
// The hooks ran after the codemods wrote; the error carries their receipt.
|
|
719
|
+
if (cliBehindCore) logCliBehindCore(cliBehindCore, targetVersion);
|
|
720
|
+
const stopped = stoppedReceipt({
|
|
721
|
+
from: currentVersion,
|
|
722
|
+
to: targetVersion,
|
|
723
|
+
codemods: totalTransforms,
|
|
724
|
+
integrations: receipt.integrations,
|
|
725
|
+
sourcePathFound,
|
|
726
|
+
cwd,
|
|
727
|
+
changedFiles: [...mergedChangedFiles, ...hookModifiedFiles],
|
|
728
|
+
transformsApplied: mergedTransformsApplied,
|
|
729
|
+
protectedRows: initialProtected,
|
|
730
|
+
errors: [
|
|
731
|
+
...mergedErrors,
|
|
732
|
+
{file: '.', codemod: 'file-protection', error: err.message},
|
|
733
|
+
],
|
|
734
|
+
errorCode: err.code,
|
|
735
|
+
cliBehindCore,
|
|
736
|
+
...(registryResult
|
|
737
|
+
? {registryCompositions: registryResult.summary}
|
|
738
|
+
: {}),
|
|
739
|
+
});
|
|
740
|
+
throw failWithReceipt(err.message, err.code, stopped);
|
|
741
|
+
}
|
|
591
742
|
const coreCheck = await runCoreCodemods(versionManifests, {
|
|
592
743
|
apply: false,
|
|
593
744
|
path: path_,
|
|
@@ -654,9 +805,12 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
654
805
|
]).map(file => path.relative(cwd, file).split(path.sep).join('/'));
|
|
655
806
|
receipt.protectedFiles = protectedFiles;
|
|
656
807
|
receipt.declinedCandidates = [];
|
|
657
|
-
receipt.complete = protectedFiles.length === 0;
|
|
658
|
-
if (
|
|
808
|
+
receipt.complete = protectedFiles.length === 0 && finalErrors.length === 0;
|
|
809
|
+
if (protectedFiles.length > 0) {
|
|
659
810
|
receipt.errorCode = 'ERR_CODEMOD_PROTECTED';
|
|
811
|
+
} else if (finalErrors.length > 0) {
|
|
812
|
+
// Only on the receipt the thrown error carries (below).
|
|
813
|
+
receipt.errorCode = 'ERR_CODEMOD_FAILED';
|
|
660
814
|
}
|
|
661
815
|
receipt.errors = finalErrors;
|
|
662
816
|
if (registryResult) receipt.registryCompositions = registryResult.summary;
|
|
@@ -674,14 +828,22 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
|
|
|
674
828
|
}
|
|
675
829
|
}
|
|
676
830
|
|
|
677
|
-
if (
|
|
678
|
-
const msg = `Upgrade completed with ${
|
|
831
|
+
if (finalErrors.length > 0 && protectedFiles.length === 0) {
|
|
832
|
+
const msg = `Upgrade completed with ${finalErrors.length} codemod error${finalErrors.length === 1 ? '' : 's'}.`;
|
|
679
833
|
logger.log('Upgrade failed\n');
|
|
680
|
-
|
|
834
|
+
// The error carries the receipt: every file the codemods wrote before the
|
|
835
|
+
// failure stays changed, and the caller keeps or reverts them knowingly.
|
|
836
|
+
throw failWithReceipt(
|
|
837
|
+
msg,
|
|
838
|
+
ERROR_CODES.ERR_CODEMOD_FAILED,
|
|
839
|
+
/** @type {import('../upgrade.type.mjs').UpgradeRunResponse['data']} */ (
|
|
840
|
+
/** @type {unknown} */ (receipt)
|
|
841
|
+
),
|
|
842
|
+
);
|
|
681
843
|
}
|
|
682
844
|
|
|
683
845
|
// Only refresh managed docs after all required codemod changes are complete.
|
|
684
|
-
if (
|
|
846
|
+
if (receipt.complete) {
|
|
685
847
|
const agentDocsPlan = await prepareAgentDocsRefresh({
|
|
686
848
|
cwd,
|
|
687
849
|
origin,
|
|
@@ -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, 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. 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. 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, 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
|
}
|
|
@@ -193,7 +193,7 @@ export type UpgradeRunResponse = {
|
|
|
193
193
|
sourcePathFound: boolean;
|
|
194
194
|
registryCompositions?: RegistryCompositionSummary | undefined;
|
|
195
195
|
complete?: boolean | undefined;
|
|
196
|
-
errorCode?:
|
|
196
|
+
errorCode?: string | undefined;
|
|
197
197
|
filesChanged?: number | undefined;
|
|
198
198
|
modifiedFiles?: string[] | undefined;
|
|
199
199
|
protectedFiles?: ProtectedCodemodFile[] | undefined;
|
|
@@ -211,6 +211,17 @@ export type UpgradeRunResponse = {
|
|
|
211
211
|
cliBehindCore?: CliBehindCore | undefined;
|
|
212
212
|
};
|
|
213
213
|
};
|
|
214
|
+
/**
|
|
215
|
+
* What a failed upgrade had already done. When a run fails after its codemods
|
|
216
|
+
* ran (a codemod or post-codemod hook failed, or an error stopped it after
|
|
217
|
+
* codemods wrote files), the failure keeps its usual shape: the --json error
|
|
218
|
+
* envelope `{apiVersion, error, code}` and a rejected `upgrade()` with that
|
|
219
|
+
* `code`. The envelope adds `receipt`, and the thrown AstryxError a `receipt`
|
|
220
|
+
* property: the same `upgrade.run` data a completed run returns, with
|
|
221
|
+
* `complete: false` and `errorCode` equal to the error's `code`. Files in
|
|
222
|
+
* `modifiedFiles` stay changed.
|
|
223
|
+
*/
|
|
224
|
+
export type UpgradeFailureReceipt = UpgradeRunResponse["data"];
|
|
214
225
|
/**
|
|
215
226
|
* astryx --json upgrade — short-circuit status results.
|
|
216
227
|
*
|
|
@@ -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
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.
|
|
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
|
+
});
|
|
@@ -125,7 +125,7 @@ export function runIntegrationCodemods(
|
|
|
125
125
|
if (codeEntries.length > 0) {
|
|
126
126
|
const resolvedPath = path.resolve(srcPath);
|
|
127
127
|
const files = fs.existsSync(resolvedPath)
|
|
128
|
-
? findSourceFiles(resolvedPath)
|
|
128
|
+
? findSourceFiles(resolvedPath, path.resolve(root))
|
|
129
129
|
: [];
|
|
130
130
|
for (const entry of codeEntries) {
|
|
131
131
|
if (apply && writtenFiles.length !== protectionWriteCount) {
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
fixDirectiveCorruption,
|
|
36
36
|
validateOutput,
|
|
37
37
|
isIgnoredDirectory,
|
|
38
|
+
isIgnoredLinkedDirectory,
|
|
38
39
|
} from './runner.mjs';
|
|
39
40
|
import {createFileProtectionResolver} from '../../foundation/fs/file-protection.mjs';
|
|
40
41
|
|
|
@@ -86,9 +87,10 @@ function logProtected(log, protections) {
|
|
|
86
87
|
/**
|
|
87
88
|
* Recursively find candidate source files in a directory.
|
|
88
89
|
* @param {string} dir
|
|
90
|
+
* @param {string} [root] the operation's project root (default: `dir`)
|
|
89
91
|
* @returns {string[]}
|
|
90
92
|
*/
|
|
91
|
-
export function findSourceFiles(dir) {
|
|
93
|
+
export function findSourceFiles(dir, root = dir) {
|
|
92
94
|
/** @type {string[]} */
|
|
93
95
|
const results = [];
|
|
94
96
|
/** @param {string} currentDir @param {Set<string>} [ancestors] */
|
|
@@ -111,12 +113,24 @@ export function findSourceFiles(dir) {
|
|
|
111
113
|
for (const entry of entries) {
|
|
112
114
|
const fullPath = path.join(currentDir, entry.name);
|
|
113
115
|
// Symlinked files and descendants remain read-only candidates so a
|
|
114
|
-
// required change can be reported. Real-path ancestors prevent cycles
|
|
116
|
+
// required change can be reported. Real-path ancestors prevent cycles,
|
|
117
|
+
// and a link into a dependency or VCS tree is not descended.
|
|
115
118
|
if (entry.isSymbolicLink()) {
|
|
116
119
|
try {
|
|
117
120
|
const target = fs.statSync(fullPath);
|
|
118
121
|
if (target.isFile()) results.push(fullPath);
|
|
119
|
-
else if (
|
|
122
|
+
else if (
|
|
123
|
+
target.isDirectory() &&
|
|
124
|
+
!isIgnoredLinkedDirectory(
|
|
125
|
+
dir,
|
|
126
|
+
fullPath,
|
|
127
|
+
entry.name,
|
|
128
|
+
fs.realpathSync(fullPath),
|
|
129
|
+
root,
|
|
130
|
+
)
|
|
131
|
+
) {
|
|
132
|
+
walk(fullPath, nextAncestors);
|
|
133
|
+
}
|
|
120
134
|
} catch {
|
|
121
135
|
// Broken links have no source bytes to evaluate.
|
|
122
136
|
}
|