@astryxdesign/cli 0.7.4 → 0.7.5-canary.0418c47
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 +20 -20
- 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/tokenizer-showcase.test.mjs +47 -0
- package/api/template/unknown-name.test.mjs +63 -0
- package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
- package/api/theme/build/build.icon-variants.test.mjs +105 -0
- package/api/theme/build/build.mjs +36 -7
- package/api/theme/build/build.test.mjs +27 -0
- 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__/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/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/next/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-codeblock-tokenizer-to-language.mjs +315 -0
- 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/__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/discover/official-packages.json +4 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/icons.doc.mjs +71 -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/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/docs/tree/template-styles.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +145 -1
- package/assets/docs/tree/tokens.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/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/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 +22 -14
- 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/dashboard-alert-rail/page.tsx +3 -3
- package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
- package/assets/templates/pages/library/page.tsx +1 -2
- package/assets/templates/pages/table-comparison/page.tsx +12 -3
- package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
- package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
- 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 +18 -5
- package/authoring/codemod/type.ts +10 -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/build-theme.adaptations.test.mjs +110 -0
- 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 +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/clients/cli/index.mjs +1 -0
- package/foundation/agent-docs/agent-docs.mjs +1 -0
- package/foundation/agent-docs/agent-docs.test.mjs +5 -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 +39 -2
- 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 +15 -9
|
@@ -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
|
+
});
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
runCodeCodemod,
|
|
25
25
|
runConfigCodemod,
|
|
26
26
|
} from './run-codemod.mjs';
|
|
27
|
+
import {withoutProtected} from './runner.mjs';
|
|
27
28
|
import {createFileProtectionResolver} from '../../foundation/fs/file-protection.mjs';
|
|
28
29
|
|
|
29
30
|
/**
|
|
@@ -44,7 +45,7 @@ import {createFileProtectionResolver} from '../../foundation/fs/file-protection.
|
|
|
44
45
|
* @param {string} [options.root]
|
|
45
46
|
* @param {Map<string, string>} [options.contents] staged bytes from earlier dry-run phases
|
|
46
47
|
* @param {{root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}} [options.protection]
|
|
47
|
-
* @returns {{totalFilesChanged: number, totalTransformsApplied: number, changedFiles: string[], writtenFiles: string[], stagedContents: Map<string, string>, protectedFiles: import('../../authoring/codemod/type').CodemodRunResult['protectedFiles'], errors: Array<{file: string, codemod: string, error: string}>, skippedOptional: Array<import('../../authoring/codemod/type').CodemodEntry>}}
|
|
48
|
+
* @returns {{totalFilesChanged: number, totalTransformsApplied: number, changedFiles: string[], writtenFiles: string[], stagedContents: Map<string, string>, protectedFiles: import('../../authoring/codemod/type').CodemodRunResult['protectedFiles'], declinedCandidates: NonNullable<import('../../authoring/codemod/type').CodemodRunResult['declinedCandidates']>, errors: Array<{file: string, codemod: string, error: string}>, skippedOptional: Array<import('../../authoring/codemod/type').CodemodEntry>}}
|
|
48
49
|
*/
|
|
49
50
|
export function runIntegrationCodemods(
|
|
50
51
|
versionGroups,
|
|
@@ -74,6 +75,8 @@ export function runIntegrationCodemods(
|
|
|
74
75
|
const writtenFiles = [];
|
|
75
76
|
/** @type {import('../../authoring/codemod/type').CodemodRunResult['protectedFiles']} */
|
|
76
77
|
const protectedFiles = [];
|
|
78
|
+
/** @type {NonNullable<import('../../authoring/codemod/type').CodemodRunResult['declinedCandidates']>} */
|
|
79
|
+
const declinedCandidates = [];
|
|
77
80
|
/** @type {Array<{file: string, codemod: string, error: string}>} */
|
|
78
81
|
const errors = [];
|
|
79
82
|
/** @type {Array<import('../../authoring/codemod/type').CodemodEntry>} */
|
|
@@ -125,7 +128,7 @@ export function runIntegrationCodemods(
|
|
|
125
128
|
if (codeEntries.length > 0) {
|
|
126
129
|
const resolvedPath = path.resolve(srcPath);
|
|
127
130
|
const files = fs.existsSync(resolvedPath)
|
|
128
|
-
? findSourceFiles(resolvedPath)
|
|
131
|
+
? findSourceFiles(resolvedPath, path.resolve(root))
|
|
129
132
|
: [];
|
|
130
133
|
for (const entry of codeEntries) {
|
|
131
134
|
if (apply && writtenFiles.length !== protectionWriteCount) {
|
|
@@ -147,9 +150,11 @@ export function runIntegrationCodemods(
|
|
|
147
150
|
changedFiles.push(...r.changedFiles);
|
|
148
151
|
writtenFiles.push(...r.writtenFiles);
|
|
149
152
|
protectedFiles.push(...r.protectedFiles);
|
|
153
|
+
declinedCandidates.push(...(r.declinedCandidates ?? []));
|
|
150
154
|
errors.push(...r.errors);
|
|
151
155
|
}
|
|
152
156
|
}
|
|
157
|
+
const reportedDeclined = withoutProtected(declinedCandidates, protectedFiles);
|
|
153
158
|
|
|
154
159
|
// A file several codemods changed is one file; transforms count each change.
|
|
155
160
|
const totalFilesChanged = new Set(changedFiles).size;
|
|
@@ -161,6 +166,7 @@ export function runIntegrationCodemods(
|
|
|
161
166
|
writtenFiles,
|
|
162
167
|
stagedContents: virtualContents,
|
|
163
168
|
protectedFiles,
|
|
169
|
+
declinedCandidates: reportedDeclined,
|
|
164
170
|
errors,
|
|
165
171
|
skippedOptional,
|
|
166
172
|
};
|
|
@@ -150,4 +150,57 @@ describe('integration codemod file protection', () => {
|
|
|
150
150
|
}),
|
|
151
151
|
]);
|
|
152
152
|
});
|
|
153
|
+
|
|
154
|
+
it('declines a protected file that does not parse, as the core runner does', async () => {
|
|
155
|
+
write('.gitattributes', 'src/vendor/** linguist-vendored\n');
|
|
156
|
+
write('src/owned.js', "export const value = 'old';\n");
|
|
157
|
+
write('src/vendor/bundle.js', 'export const value = {;\n');
|
|
158
|
+
write('src/broken.js', 'export const value = {;\n');
|
|
159
|
+
|
|
160
|
+
const groups = [
|
|
161
|
+
{
|
|
162
|
+
version: '1.0.0',
|
|
163
|
+
codemods: [
|
|
164
|
+
{
|
|
165
|
+
id: 'code',
|
|
166
|
+
type: 'code',
|
|
167
|
+
package: '@acme/integration',
|
|
168
|
+
codemod: {
|
|
169
|
+
title: 'code',
|
|
170
|
+
fileExtensions: ['.js'],
|
|
171
|
+
transform: (file, {jscodeshift: j}) => {
|
|
172
|
+
const ast = j(file.source);
|
|
173
|
+
ast.find(j.Identifier, {name: 'value'}).forEach(p => {
|
|
174
|
+
p.node.name = 'renamed';
|
|
175
|
+
});
|
|
176
|
+
return ast.toSource();
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
184
|
+
const result = runIntegrationCodemods(groups, {
|
|
185
|
+
apply: true,
|
|
186
|
+
path: path.join(root, 'src'),
|
|
187
|
+
root,
|
|
188
|
+
jscodeshift,
|
|
189
|
+
silent: true,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(fs.readFileSync(path.join(root, 'src/owned.js'), 'utf8')).toContain(
|
|
193
|
+
'renamed',
|
|
194
|
+
);
|
|
195
|
+
expect(result.declinedCandidates).toEqual([
|
|
196
|
+
expect.objectContaining({
|
|
197
|
+
file: path.join('src', 'vendor', 'bundle.js'),
|
|
198
|
+
codemod: '@acme/integration:code',
|
|
199
|
+
location: '1:23',
|
|
200
|
+
}),
|
|
201
|
+
]);
|
|
202
|
+
expect(result.errors).toEqual([
|
|
203
|
+
expect.objectContaining({file: path.join('src', 'broken.js')}),
|
|
204
|
+
]);
|
|
205
|
+
});
|
|
153
206
|
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Codemod outcomes that are not failures.
|
|
5
|
+
*
|
|
6
|
+
* A core transform throws one of these, instead of a plain Error, when a file
|
|
7
|
+
* needs a change the codemod cannot make itself:
|
|
8
|
+
*
|
|
9
|
+
* - `ManualMigrationRequired`: a person must migrate the code (the codemod can
|
|
10
|
+
* identify it but has no safe rewrite). Reported in the upgrade receipt's
|
|
11
|
+
* `declinedCandidates`; it does not fail the run.
|
|
12
|
+
* - `RegenerationRequired`: a generated file is out of date and its generator
|
|
13
|
+
* must rebuild it. Reported in `regenerate` with the command that does; the
|
|
14
|
+
* run is incomplete until it is rebuilt.
|
|
15
|
+
*
|
|
16
|
+
* Anything else a transform throws is still a codemod failure. The upgrade
|
|
17
|
+
* leaf (`api/upgrade/_adapter.mjs` `withCodemodOutcomes`) catches these around
|
|
18
|
+
* each core transform, so the codemod runners never see them.
|
|
19
|
+
*
|
|
20
|
+
* @input A message, and the source line or regeneration commands
|
|
21
|
+
* @output Error subclasses tagged with a stable outcome kind
|
|
22
|
+
* @position Shared by core codemod transforms and the upgrade leaf
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const OUTCOME = Symbol.for('astryx.codemod.outcome');
|
|
26
|
+
|
|
27
|
+
/** A person must migrate this code; the codemod has no safe rewrite. */
|
|
28
|
+
export class ManualMigrationRequired extends Error {
|
|
29
|
+
/**
|
|
30
|
+
* @param {string} message What to change, and how.
|
|
31
|
+
* @param {{line?: number | null}} [options] 1-based source line, when known.
|
|
32
|
+
*/
|
|
33
|
+
constructor(message, {line} = {}) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = 'ManualMigrationRequired';
|
|
36
|
+
/** @type {number | undefined} */
|
|
37
|
+
this.line = typeof line === 'number' ? line : undefined;
|
|
38
|
+
Object.defineProperty(this, OUTCOME, {value: 'manual'});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** A generated file is out of date; its generator must rebuild it. */
|
|
43
|
+
export class RegenerationRequired extends Error {
|
|
44
|
+
/**
|
|
45
|
+
* @param {string} message Why the file is out of date.
|
|
46
|
+
* @param {{commands: string[]}} options Commands that rebuild it.
|
|
47
|
+
*/
|
|
48
|
+
constructor(message, {commands}) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.name = 'RegenerationRequired';
|
|
51
|
+
/** @type {string[]} */
|
|
52
|
+
this.commands = [...commands];
|
|
53
|
+
Object.defineProperty(this, OUTCOME, {value: 'regenerate'});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The outcome a thrown value reports, or null for an ordinary failure.
|
|
59
|
+
* @param {unknown} err
|
|
60
|
+
* @returns {{kind: 'manual', message: string, line?: number} | {kind: 'regenerate', message: string, commands: string[]} | null}
|
|
61
|
+
*/
|
|
62
|
+
export function codemodOutcome(err) {
|
|
63
|
+
if (!err || typeof err !== 'object') return null;
|
|
64
|
+
const kind = /** @type {any} */ (err)[OUTCOME];
|
|
65
|
+
const message = /** @type {Error} */ (err).message;
|
|
66
|
+
if (kind === 'manual') {
|
|
67
|
+
const line = /** @type {ManualMigrationRequired} */ (err).line;
|
|
68
|
+
return {kind, message, ...(typeof line === 'number' ? {line} : {})};
|
|
69
|
+
}
|
|
70
|
+
if (kind === 'regenerate') {
|
|
71
|
+
const commands = /** @type {RegenerationRequired} */ (err).commands;
|
|
72
|
+
return {
|
|
73
|
+
kind,
|
|
74
|
+
message,
|
|
75
|
+
commands: Array.isArray(commands) ? [...commands] : [],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import {
|
|
5
|
+
ManualMigrationRequired,
|
|
6
|
+
RegenerationRequired,
|
|
7
|
+
codemodOutcome,
|
|
8
|
+
} from './outcome.mjs';
|
|
9
|
+
|
|
10
|
+
describe('codemodOutcome', () => {
|
|
11
|
+
it('reads a manual migration with and without its line', () => {
|
|
12
|
+
expect(codemodOutcome(new ManualMigrationRequired('m', {line: 3}))).toEqual(
|
|
13
|
+
{kind: 'manual', message: 'm', line: 3},
|
|
14
|
+
);
|
|
15
|
+
expect(codemodOutcome(new ManualMigrationRequired('m'))).toEqual({
|
|
16
|
+
kind: 'manual',
|
|
17
|
+
message: 'm',
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('reads a regeneration with its commands', () => {
|
|
22
|
+
expect(
|
|
23
|
+
codemodOutcome(new RegenerationRequired('r', {commands: ['gen']})),
|
|
24
|
+
).toEqual({kind: 'regenerate', message: 'r', commands: ['gen']});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('treats anything else as an ordinary failure', () => {
|
|
28
|
+
expect(codemodOutcome(new Error('boom'))).toBeNull();
|
|
29
|
+
expect(
|
|
30
|
+
codemodOutcome(Object.assign(new Error('x'), {kind: 'manual'})),
|
|
31
|
+
).toBeNull();
|
|
32
|
+
expect(codemodOutcome('boom')).toBeNull();
|
|
33
|
+
expect(codemodOutcome(undefined)).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('stays an Error, so a runner without the wrapper still reports it', () => {
|
|
37
|
+
expect(new ManualMigrationRequired('m')).toBeInstanceOf(Error);
|
|
38
|
+
expect(new RegenerationRequired('r', {commands: []})).toBeInstanceOf(Error);
|
|
39
|
+
});
|
|
40
|
+
});
|