@proveanything/smartlinks 2.2.1 → 3.0.0-alpha.1
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 +741 -754
- package/dist/README.md +573 -573
- package/dist/adminCardsView.js +55 -55
- package/dist/api/adminCards.d.ts +8 -0
- package/dist/api/adminCards.js +9 -1
- package/dist/api/ai.d.ts +22 -11
- package/dist/api/ai.js +18 -14
- package/dist/api/analytics.d.ts +13 -0
- package/dist/api/analytics.js +13 -0
- package/dist/api/appConfiguration.d.ts +17 -14
- package/dist/api/appConfiguration.js +14 -12
- package/dist/api/appObjects.d.ts +80 -16
- package/dist/api/appObjects.js +74 -11
- package/dist/api/asset.d.ts +55 -19
- package/dist/api/asset.js +52 -32
- package/dist/api/attestation.d.ts +3 -2
- package/dist/api/attestation.js +1 -1
- package/dist/api/attestations.d.ts +22 -7
- package/dist/api/attestations.js +22 -7
- package/dist/api/authKit.d.ts +22 -5
- package/dist/api/authKit.js +21 -4
- package/dist/api/batch.d.ts +23 -16
- package/dist/api/batch.js +19 -13
- package/dist/api/bookings.d.ts +45 -9
- package/dist/api/bookings.js +39 -3
- package/dist/api/broadcasts.d.ts +26 -6
- package/dist/api/broadcasts.js +22 -2
- package/dist/api/claimSet.d.ts +48 -13
- package/dist/api/claimSet.js +43 -7
- package/dist/api/collection.d.ts +20 -6
- package/dist/api/collection.js +19 -8
- package/dist/api/comms.d.ts +43 -12
- package/dist/api/comms.js +43 -13
- package/dist/api/conditions.d.ts +12 -2
- package/dist/api/conditions.js +10 -1
- package/dist/api/config.d.ts +15 -2
- package/dist/api/config.js +12 -0
- package/dist/api/contact.d.ts +34 -13
- package/dist/api/contact.js +35 -10
- package/dist/api/containers.d.ts +41 -23
- package/dist/api/containers.js +37 -21
- package/dist/api/crate.d.ts +9 -8
- package/dist/api/crate.js +8 -8
- package/dist/api/dpp.d.ts +58 -10
- package/dist/api/dpp.js +57 -15
- package/dist/api/facets.d.ts +71 -0
- package/dist/api/facets.js +71 -0
- package/dist/api/files.d.ts +11 -5
- package/dist/api/files.js +9 -1
- package/dist/api/form.d.ts +9 -2
- package/dist/api/form.js +7 -1
- package/dist/api/index.d.ts +0 -1
- package/dist/api/index.js +0 -1
- package/dist/api/integrations.d.ts +82 -27
- package/dist/api/integrations.js +63 -7
- package/dist/api/interactions.d.ts +42 -6
- package/dist/api/interactions.js +41 -5
- package/dist/api/jobs.d.ts +9 -2
- package/dist/api/jobs.js +6 -0
- package/dist/api/journeys.d.ts +13 -2
- package/dist/api/journeys.js +10 -1
- package/dist/api/journeysAnalytics.d.ts +12 -3
- package/dist/api/journeysAnalytics.js +9 -1
- package/dist/api/knowledge.d.ts +43 -10
- package/dist/api/knowledge.js +37 -5
- package/dist/api/location.d.ts +10 -3
- package/dist/api/location.js +7 -1
- package/dist/api/lots.d.ts +40 -13
- package/dist/api/lots.js +38 -8
- package/dist/api/loyalty.d.ts +70 -12
- package/dist/api/loyalty.js +60 -3
- package/dist/api/nfc.d.ts +8 -2
- package/dist/api/nfc.js +6 -1
- package/dist/api/order.d.ts +51 -160
- package/dist/api/order.js +46 -208
- package/dist/api/partner.d.ts +41 -8
- package/dist/api/partner.js +36 -4
- package/dist/api/products.d.ts +41 -8
- package/dist/api/products.js +33 -4
- package/dist/api/proof.d.ts +50 -13
- package/dist/api/proof.js +43 -7
- package/dist/api/realtime.d.ts +1 -11
- package/dist/api/realtime.js +1 -22
- package/dist/api/secrets.d.ts +25 -5
- package/dist/api/secrets.js +21 -2
- package/dist/api/segments.d.ts +26 -6
- package/dist/api/segments.js +22 -2
- package/dist/api/serviceAccounts.d.ts +8 -1
- package/dist/api/serviceAccounts.js +8 -1
- package/dist/api/shop.d.ts +41 -13
- package/dist/api/shop.js +35 -4
- package/dist/api/subscriptions.d.ts +47 -12
- package/dist/api/subscriptions.js +40 -4
- package/dist/api/tags.d.ts +40 -19
- package/dist/api/tags.js +38 -18
- package/dist/api/template.d.ts +31 -3
- package/dist/api/template.js +27 -0
- package/dist/api/translations.d.ts +17 -2
- package/dist/api/translations.js +14 -0
- package/dist/api/userGroups.d.ts +35 -9
- package/dist/api/userGroups.js +30 -5
- package/dist/api/variant.d.ts +11 -3
- package/dist/api/variant.js +9 -2
- package/dist/api/wallet.d.ts +23 -10
- package/dist/api/wallet.js +20 -2
- package/dist/apiVersion.d.ts +1 -1
- package/dist/apiVersion.js +1 -1
- package/dist/baseline.css +194 -194
- package/dist/docs/API_SUMMARY.md +1389 -2298
- package/dist/docs/PRODUCT_FACETS_SDK.md +10 -15
- package/dist/docs/admin-cards.md +189 -189
- package/dist/docs/admin-lists-and-pickers.md +1 -1
- package/dist/docs/agent-tools.md +156 -156
- package/dist/docs/ai-tools-and-skills.md +180 -180
- package/dist/docs/ai.md +1721 -1721
- package/dist/docs/analytics.md +3 -2
- package/dist/docs/api-versions.md +85 -76
- package/dist/docs/app-data-storage.md +277 -277
- package/dist/docs/app-docs.md +73 -73
- package/dist/docs/app-manifest.md +852 -852
- package/dist/docs/app-objects.md +38 -50
- package/dist/docs/app-records-pattern.md +388 -388
- package/dist/docs/appConfig.md +550 -550
- package/dist/docs/assets.md +17 -3
- package/dist/docs/assistant-apps.md +172 -172
- package/dist/docs/assistant-context.md +119 -119
- package/dist/docs/attestations.md +5 -4
- package/dist/docs/auth-kit.md +1 -1
- package/dist/docs/bookings.md +442 -442
- package/dist/docs/comms.md +689 -686
- package/dist/docs/connectors.md +340 -340
- package/dist/docs/contact-search.md +4 -3
- package/dist/docs/container-tracking.md +7 -7
- package/dist/docs/css-baseline.md +133 -133
- package/dist/docs/customer-guide.md +70 -70
- package/dist/docs/deploying-apps.md +340 -340
- package/dist/docs/dpp.md +115 -115
- package/dist/docs/entitlements.md +90 -90
- package/dist/docs/executor.md +1 -1
- package/dist/docs/files.md +69 -69
- package/dist/docs/forms.md +1 -1
- package/dist/docs/headless-providers.md +3 -3
- package/dist/docs/host-dependency-contract.md +252 -210
- package/dist/docs/integrations.md +322 -322
- package/dist/docs/interactions.md +544 -545
- package/dist/docs/item-context.md +181 -181
- package/dist/docs/knowledge.md +105 -102
- package/dist/docs/lists.md +114 -0
- package/dist/docs/lots.md +112 -111
- package/dist/docs/loyalty.md +348 -352
- package/dist/docs/members.md +183 -183
- package/dist/docs/memberships.md +150 -149
- package/dist/docs/mobile-admin-container.md +693 -693
- package/dist/docs/operations.md +281 -281
- package/dist/docs/overview.md +485 -485
- package/dist/docs/proof-claiming-methods.md +6 -6
- package/dist/docs/proof-comms-triggers.md +142 -142
- package/dist/docs/proof-ownership-transfer.md +155 -155
- package/dist/docs/proof-product-data-scoping.md +462 -462
- package/dist/docs/proof-share-grants.md +305 -305
- package/dist/docs/realtime.md +139 -138
- package/dist/docs/records-admin-pattern.md +304 -304
- package/dist/docs/server-functions.md +2 -2
- package/dist/docs/service-accounts.md +64 -64
- package/dist/docs/shop.md +4 -2
- package/dist/docs/site-seo.md +2 -1
- package/dist/docs/standard-query.md +187 -187
- package/dist/docs/tag-codes.md +97 -97
- package/dist/docs/tag-ranges.md +106 -106
- package/dist/docs/theme-tokens.md +252 -252
- package/dist/docs/translations.md +6 -1
- package/dist/docs/upgrading-to-3.md +430 -0
- package/dist/docs/user-groups.md +4 -4
- package/dist/docs/utils.md +1 -1
- package/dist/docs/wallet-passes.md +107 -107
- package/dist/docs/websites.md +123 -123
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +2 -2
- package/dist/http.d.ts +15 -2
- package/dist/http.js +60 -2
- package/dist/index.d.ts +7 -8
- package/dist/index.js +2 -0
- package/dist/list.d.ts +24 -0
- package/dist/list.js +80 -0
- package/dist/mobile-admin/types.d.ts +0 -16
- package/dist/openapi.yaml +290 -2723
- package/dist/shared-dependencies.d.ts +3 -3
- package/dist/shared-dependencies.js +13 -5
- package/dist/site.d.ts +1 -7
- package/dist/site.js +1 -14
- package/dist/theme-boot.js +82 -82
- package/dist/theme.css +75 -75
- package/dist/types/adminCards.d.ts +6 -3
- package/dist/types/ai.d.ts +0 -6
- package/dist/types/analytics.d.ts +5 -8
- package/dist/types/appManifest.d.ts +4 -5
- package/dist/types/appObjects.d.ts +14 -18
- package/dist/types/appObjects.js +0 -1
- package/dist/types/appOptions.d.ts +18 -0
- package/dist/types/asset.d.ts +3 -22
- package/dist/types/attestations.d.ts +7 -10
- package/dist/types/batch.d.ts +6 -14
- package/dist/types/bookings.d.ts +22 -4
- package/dist/types/broadcasts.d.ts +5 -13
- package/dist/types/broadcasts.js +0 -1
- package/dist/types/claimSet.d.ts +0 -5
- package/dist/types/comms.d.ts +11 -9
- package/dist/types/contact.d.ts +5 -29
- package/dist/types/contact.js +0 -13
- package/dist/types/containers.d.ts +15 -26
- package/dist/types/crate.d.ts +4 -12
- package/dist/types/dpp.d.ts +3 -3
- package/dist/types/dpp.js +0 -1
- package/dist/types/error.d.ts +8 -5
- package/dist/types/error.js +12 -5
- package/dist/types/facets.d.ts +15 -15
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/integrations.d.ts +3 -28
- package/dist/types/interaction.d.ts +3 -9
- package/dist/types/jobs.d.ts +3 -8
- package/dist/types/jobs.js +0 -1
- package/dist/types/journeys.d.ts +3 -8
- package/dist/types/journeys.js +0 -1
- package/dist/types/journeysAnalytics.d.ts +0 -1
- package/dist/types/list.d.ts +24 -0
- package/dist/types/list.js +2 -0
- package/dist/types/location.d.ts +0 -4
- package/dist/types/lots.d.ts +0 -9
- package/dist/types/loyalty.d.ts +0 -9
- package/dist/types/order.d.ts +7 -134
- package/dist/types/product.d.ts +11 -24
- package/dist/types/proof.d.ts +16 -0
- package/dist/types/realtime.d.ts +0 -29
- package/dist/types/segments.d.ts +5 -13
- package/dist/types/segments.js +0 -1
- package/dist/types/serviceAccounts.d.ts +3 -2
- package/dist/types/serviceAccounts.js +0 -1
- package/dist/types/shop.d.ts +5 -12
- package/dist/types/shop.js +0 -4
- package/dist/types/subscriptions.d.ts +18 -0
- package/dist/types/subscriptions.js +0 -8
- package/dist/types/tags.d.ts +6 -16
- package/dist/types/tags.js +0 -7
- package/dist/types/translations.d.ts +3 -9
- package/dist/types/variant.d.ts +0 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/API_SUMMARY.md +1389 -2298
- package/docs/PRODUCT_FACETS_SDK.md +10 -15
- package/docs/admin-cards.md +189 -189
- package/docs/admin-lists-and-pickers.md +1 -1
- package/docs/agent-tools.md +156 -156
- package/docs/ai-tools-and-skills.md +180 -180
- package/docs/ai.md +1721 -1721
- package/docs/analytics.md +3 -2
- package/docs/api-versions.md +85 -76
- package/docs/app-data-storage.md +277 -277
- package/docs/app-docs.md +73 -73
- package/docs/app-manifest.md +852 -852
- package/docs/app-objects.md +38 -50
- package/docs/app-records-pattern.md +388 -388
- package/docs/appConfig.md +550 -550
- package/docs/assets.md +17 -3
- package/docs/assistant-apps.md +172 -172
- package/docs/assistant-context.md +119 -119
- package/docs/attestations.md +5 -4
- package/docs/auth-kit.md +1 -1
- package/docs/bookings.md +442 -442
- package/docs/comms.md +689 -686
- package/docs/connectors.md +340 -340
- package/docs/contact-search.md +4 -3
- package/docs/container-tracking.md +7 -7
- package/docs/css-baseline.md +133 -133
- package/docs/customer-guide.md +70 -70
- package/docs/deploying-apps.md +340 -340
- package/docs/dpp.md +115 -115
- package/docs/entitlements.md +90 -90
- package/docs/executor.md +1 -1
- package/docs/files.md +69 -69
- package/docs/forms.md +1 -1
- package/docs/headless-providers.md +3 -3
- package/docs/host-dependency-contract.md +252 -210
- package/docs/integrations.md +322 -322
- package/docs/interactions.md +544 -545
- package/docs/item-context.md +181 -181
- package/docs/knowledge.md +105 -102
- package/docs/lists.md +114 -0
- package/docs/lots.md +112 -111
- package/docs/loyalty.md +348 -352
- package/docs/members.md +183 -183
- package/docs/memberships.md +150 -149
- package/docs/mobile-admin-container.md +693 -693
- package/docs/operations.md +281 -281
- package/docs/overview.md +485 -485
- package/docs/proof-claiming-methods.md +6 -6
- package/docs/proof-comms-triggers.md +142 -142
- package/docs/proof-ownership-transfer.md +155 -155
- package/docs/proof-product-data-scoping.md +462 -462
- package/docs/proof-share-grants.md +305 -305
- package/docs/realtime.md +139 -138
- package/docs/server-functions.md +2 -2
- package/docs/service-accounts.md +64 -64
- package/docs/shop.md +4 -2
- package/docs/site-seo.md +2 -1
- package/docs/standard-query.md +187 -187
- package/docs/tag-codes.md +97 -97
- package/docs/tag-ranges.md +106 -106
- package/docs/theme-lookbook.v1.json +120 -120
- package/docs/theme-tokens.md +252 -252
- package/docs/translations.md +6 -1
- package/docs/upgrading-to-3.md +430 -0
- package/docs/user-groups.md +4 -4
- package/docs/utils.md +1 -1
- package/docs/wallet-passes.md +107 -107
- package/docs/websites.md +123 -123
- package/openapi.yaml +290 -2723
- package/package.json +8 -4
- package/scripts/headless-check.mjs +87 -87
- package/scripts/lib/bare-imports.mjs +57 -57
- package/scripts/lib/keyed-app-data.mjs +21 -21
- package/scripts/lib/upgrade.mjs +512 -0
- package/scripts/publish.mjs +272 -272
- package/scripts/register-release.mjs +91 -91
- package/scripts/upgrade.mjs +56 -0
- package/upgrade/3.json +2213 -0
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// Moving an app to a new major of the SDK: what a script can safely do, and a list of everything else.
|
|
3
|
+
//
|
|
4
|
+
// Reads upgrade/<major>.json (the same table docs/upgrading-to-<major>.md is filled from) and the app's
|
|
5
|
+
// source, and:
|
|
6
|
+
// 1. plans the MECHANICAL edits: a call that only changed name, an argument that went, the manifest's
|
|
7
|
+
// shared-dependency contract. Nothing that changes what the code means.
|
|
8
|
+
// 2. lists every other place the table says needs a person or an agent: each call to a list whose
|
|
9
|
+
// shape changed, each removed call, each option that went, each thing to check at run time.
|
|
10
|
+
//
|
|
11
|
+
// It finds SDK calls by what a name is BOUND to, not by its spelling: `product.get(…)` is only an SDK
|
|
12
|
+
// call where `product` is the SDK's export (an import, `SL.product`, or taken from one of those). A
|
|
13
|
+
// local variable that happens to be called `product` is never touched.
|
|
14
|
+
//
|
|
15
|
+
// Used by scripts/upgrade.mjs (the `smartlinks-upgrade` command) and by the SDK's tests.
|
|
16
|
+
// =============================================================================
|
|
17
|
+
|
|
18
|
+
import fs from 'node:fs'
|
|
19
|
+
import path from 'node:path'
|
|
20
|
+
import { createRequire } from 'node:module'
|
|
21
|
+
import { fileURLToPath } from 'node:url'
|
|
22
|
+
|
|
23
|
+
const here = path.dirname(fileURLToPath(import.meta.url))
|
|
24
|
+
const SDK = /^@proveanything\/smartlinks(\/.*)?$/
|
|
25
|
+
const SOURCE = /\.(ts|tsx|js|jsx|mjs|cjs|mts|cts)$/
|
|
26
|
+
const SKIP_DIRS = new Set(['node_modules', 'dist', 'build', '.git', '.next', '.output', '.vite', '.turbo', 'coverage', '.forge', '.lovable'])
|
|
27
|
+
|
|
28
|
+
/** The upgrade table for a major, from this package. */
|
|
29
|
+
export function loadTable(major = '3') {
|
|
30
|
+
return JSON.parse(fs.readFileSync(path.join(here, '..', '..', 'upgrade', `${major}.json`), 'utf8'))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** TypeScript's parser: the app's own copy if it has one, else whatever this package can reach. */
|
|
34
|
+
export function loadTypeScript(appDir) {
|
|
35
|
+
for (const from of [path.join(appDir, 'package.json'), path.join(here, 'package.json')]) {
|
|
36
|
+
try { return createRequire(from)('typescript') } catch { /* try the next place */ }
|
|
37
|
+
}
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function sourceFiles(appDir) {
|
|
42
|
+
const out = []
|
|
43
|
+
const walk = (dir, depth) => {
|
|
44
|
+
let entries = []
|
|
45
|
+
try { entries = fs.readdirSync(dir, { withFileTypes: true }) } catch { return }
|
|
46
|
+
for (const e of entries) {
|
|
47
|
+
const p = path.join(dir, e.name)
|
|
48
|
+
if (e.isDirectory()) { if (!SKIP_DIRS.has(e.name) && !e.name.startsWith('.') && depth < 12) walk(p, depth + 1) }
|
|
49
|
+
else if (SOURCE.test(e.name) && !e.name.endsWith('.d.ts')) out.push(p)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
walk(appDir, 0)
|
|
53
|
+
return out
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ── the table, indexed ───────────────────────────────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
function indexTable(table) {
|
|
59
|
+
const renames = new Map() // old full name → new full name, mechanical only
|
|
60
|
+
const removed = new Map() // name → entry (also renames a script must not do)
|
|
61
|
+
const lists = new Map()
|
|
62
|
+
const options = new Map() // name → [entries]
|
|
63
|
+
const fields = [] // entries about a field of a type: only a person or a type-check finds these
|
|
64
|
+
for (const c of table.changes) {
|
|
65
|
+
if (c.kind === 'renamed' && c.mechanical) renames.set(c.name, c.to)
|
|
66
|
+
else if (c.kind === 'renamed' || c.kind === 'removed') {
|
|
67
|
+
if (c.what === 'field') fields.push(c)
|
|
68
|
+
else removed.set(c.name, c)
|
|
69
|
+
} else if (c.kind === 'list') lists.set(c.name, c)
|
|
70
|
+
else if (c.kind === 'option') options.set(c.name, [...(options.get(c.name) || []), c])
|
|
71
|
+
}
|
|
72
|
+
const hold = new Map()
|
|
73
|
+
for (const h of table.hold || []) for (const n of h.names || []) hold.set(n, h)
|
|
74
|
+
return { renames, removed, lists, options, fields, hold, behaviour: table.changes.filter((c) => c.kind === 'behaviour') }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ── one file ─────────────────────────────────────────────────────────────────────────────────────
|
|
78
|
+
|
|
79
|
+
function analyseFile(ts, checker, sf, idx, rel) {
|
|
80
|
+
const text = sf.text
|
|
81
|
+
const edits = [] // { start, end, text }
|
|
82
|
+
const work = [] // { kind, name, line, note, ... }
|
|
83
|
+
const lineOf = (node) => sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1
|
|
84
|
+
const push = (kind, node, name, extra = {}) => work.push({ kind, file: rel, line: lineOf(node), name, ...extra })
|
|
85
|
+
|
|
86
|
+
// 1. What the SDK's names are bound to in this file.
|
|
87
|
+
const imports = new Map() // symbol → { imported, local, spec, decl }
|
|
88
|
+
const namespaces = new Set() // symbols of `import * as X` / default imports of the SDK
|
|
89
|
+
for (const st of sf.statements) {
|
|
90
|
+
if (ts.isImportDeclaration(st) && ts.isStringLiteral(st.moduleSpecifier) && SDK.test(st.moduleSpecifier.text) && st.importClause) {
|
|
91
|
+
const clause = st.importClause
|
|
92
|
+
if (clause.name) { const s = checker.getSymbolAtLocation(clause.name); if (s) namespaces.add(s) }
|
|
93
|
+
const nb = clause.namedBindings
|
|
94
|
+
if (nb && ts.isNamespaceImport(nb)) { const s = checker.getSymbolAtLocation(nb.name); if (s) namespaces.add(s) }
|
|
95
|
+
if (nb && ts.isNamedImports(nb)) {
|
|
96
|
+
for (const spec of nb.elements) {
|
|
97
|
+
const s = checker.getSymbolAtLocation(spec.name)
|
|
98
|
+
if (s) imports.set(s, { imported: (spec.propertyName || spec.name).text, local: spec.name.text, spec, decl: st })
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// export { product } from '@proveanything/smartlinks'
|
|
103
|
+
if (ts.isExportDeclaration(st) && st.moduleSpecifier && ts.isStringLiteral(st.moduleSpecifier) && SDK.test(st.moduleSpecifier.text) && st.exportClause && ts.isNamedExports(st.exportClause)) {
|
|
104
|
+
for (const spec of st.exportClause.elements) {
|
|
105
|
+
const name = (spec.propertyName || spec.name).text
|
|
106
|
+
const hit = [...idx.renames.keys(), ...idx.removed.keys()].find((n) => n === name || n.startsWith(name + '.'))
|
|
107
|
+
if (hit) push('by-hand', spec, name, { note: `Re-exported from the SDK here. \`${name}\` is ${idx.renames.has(hit) ? 'renamed' : 'gone'} in SDK 3: change the re-export, then whatever imports it from this file.` })
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const symbolOf = (id) => {
|
|
113
|
+
if (id.parent && ts.isShorthandPropertyAssignment(id.parent) && id.parent.name === id) return checker.getShorthandAssignmentValueSymbol(id.parent)
|
|
114
|
+
return checker.getSymbolAtLocation(id)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The SDK name an expression stands for (['products', 'list']), [] for the SDK itself, null for anything else. */
|
|
118
|
+
const sdkPath = (node, depth = 0) => {
|
|
119
|
+
if (!node || depth > 8) return null
|
|
120
|
+
if (ts.isParenthesizedExpression(node) || ts.isNonNullExpression(node) || ts.isAsExpression(node)) return sdkPath(node.expression, depth + 1)
|
|
121
|
+
if (ts.isIdentifier(node)) {
|
|
122
|
+
const sym = symbolOf(node)
|
|
123
|
+
if (sym && imports.has(sym)) return [imports.get(sym).imported]
|
|
124
|
+
if (sym && namespaces.has(sym)) return []
|
|
125
|
+
// const { product } = SL · const records = SL.app.records
|
|
126
|
+
const decl = sym && sym.declarations && sym.declarations[0]
|
|
127
|
+
if (decl && ts.isBindingElement(decl) && ts.isObjectBindingPattern(decl.parent) && ts.isVariableDeclaration(decl.parent.parent) && decl.parent.parent.initializer) {
|
|
128
|
+
const base = sdkPath(decl.parent.parent.initializer, depth + 1)
|
|
129
|
+
const key = decl.propertyName || decl.name
|
|
130
|
+
if (base && ts.isIdentifier(key)) return [...base, key.text]
|
|
131
|
+
}
|
|
132
|
+
if (decl && ts.isVariableDeclaration(decl) && ts.isIdentifier(decl.name) && decl.initializer && decl.initializer !== node
|
|
133
|
+
&& ts.isVariableDeclarationList(decl.parent) && (decl.parent.flags & ts.NodeFlags.Const)) {
|
|
134
|
+
const base = sdkPath(decl.initializer, depth + 1)
|
|
135
|
+
if (base) return base
|
|
136
|
+
}
|
|
137
|
+
// The SDK handed over by a host is called SL by convention (window.SL, host.SL, a prop named SL).
|
|
138
|
+
if (node.text === 'SL' || node.text === 'SL3') return []
|
|
139
|
+
return null
|
|
140
|
+
}
|
|
141
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
142
|
+
if (node.name.text === 'SL' || node.name.text === 'SL3') return []
|
|
143
|
+
const base = sdkPath(node.expression, depth + 1)
|
|
144
|
+
return base ? [...base, node.name.text] : null
|
|
145
|
+
}
|
|
146
|
+
return null
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 2. Every use of an SDK name.
|
|
150
|
+
const refs = new Map() // import symbol → [identifier]
|
|
151
|
+
const renameRefs = new Map() // import symbol → [{ id, to }]: uses a script may rename
|
|
152
|
+
const seen = new Set() // "name@pos": one entry per place
|
|
153
|
+
|
|
154
|
+
const objectKeys = (call) => {
|
|
155
|
+
const keys = new Set()
|
|
156
|
+
for (const a of call.arguments || []) if (ts.isObjectLiteralExpression(a)) for (const p of a.properties) if (p.name && (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name))) keys.add(p.name.text)
|
|
157
|
+
return keys
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const visit = (node) => {
|
|
161
|
+
if (ts.isIdentifier(node)) {
|
|
162
|
+
const sym = symbolOf(node)
|
|
163
|
+
const imp = sym && imports.get(sym)
|
|
164
|
+
if (imp && node !== imp.spec.name && node !== imp.spec.propertyName) refs.set(sym, [...(refs.get(sym) || []), node])
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const isChainTop = (ts.isPropertyAccessExpression(node) || ts.isIdentifier(node))
|
|
168
|
+
&& !(node.parent && ts.isPropertyAccessExpression(node.parent) && node.parent.name === node)
|
|
169
|
+
&& !(node.parent && (ts.isImportSpecifier(node.parent) || ts.isExportSpecifier(node.parent) || ts.isImportClause(node.parent) || ts.isNamespaceImport(node.parent)))
|
|
170
|
+
if (isChainTop) {
|
|
171
|
+
const p = sdkPath(node)
|
|
172
|
+
if (p && p.length) {
|
|
173
|
+
let name = p.join('.')
|
|
174
|
+
const call = node.parent && ts.isCallExpression(node.parent) && node.parent.expression === node ? node.parent : null
|
|
175
|
+
|
|
176
|
+
// A call that only changed name.
|
|
177
|
+
if (idx.renames.has(name)) {
|
|
178
|
+
const to = idx.renames.get(name)
|
|
179
|
+
const [fromHead, toHead] = [name.split('.')[0], to.split('.')[0]]
|
|
180
|
+
// The part that changes is the first one: `product` in product.get, or the whole of a type's name.
|
|
181
|
+
let head = node
|
|
182
|
+
for (let i = p.length; i > 1 && ts.isPropertyAccessExpression(head); i--) head = head.expression
|
|
183
|
+
while (ts.isParenthesizedExpression(head) || ts.isNonNullExpression(head) || ts.isAsExpression(head)) head = head.expression
|
|
184
|
+
if (ts.isPropertyAccessExpression(head) && head.name.text === fromHead) {
|
|
185
|
+
edits.push({ start: head.name.getStart(sf), end: head.name.getEnd(), text: toHead }) // SL.product → SL.products
|
|
186
|
+
} else if (ts.isIdentifier(head) && imports.has(symbolOf(head)) && imports.get(symbolOf(head)).imported === fromHead) {
|
|
187
|
+
const sym = symbolOf(head)
|
|
188
|
+
renameRefs.set(sym, [...(renameRefs.get(sym) || []), { id: head, to: toHead }])
|
|
189
|
+
} else {
|
|
190
|
+
push('by-hand', node, name, { to, note: `Renamed to \`${to}\`, but reached here through another name: rename it by hand.` })
|
|
191
|
+
}
|
|
192
|
+
name = to
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const key = name + '@' + node.getStart(sf)
|
|
196
|
+
if (!seen.has(key)) {
|
|
197
|
+
seen.add(key)
|
|
198
|
+
if (idx.hold.has(name)) push('hold', node, name, { note: idx.hold.get(name).why })
|
|
199
|
+
const gone = idx.removed.get(name)
|
|
200
|
+
if (gone) push('removed', node, name, { to: gone.to || null, note: gone.note || '' })
|
|
201
|
+
const list = idx.lists.get(name)
|
|
202
|
+
if (list) {
|
|
203
|
+
const keys = call ? objectKeys(call) : new Set()
|
|
204
|
+
const passes = (list.optionsRemoved || []).filter((o) => keys.has(o.split('.')[0]))
|
|
205
|
+
push('list', node, name, { before: list.before, after: list.after, paged: !!list.paged, passes, called: !!call, note: list.note || '' })
|
|
206
|
+
}
|
|
207
|
+
for (const opt of idx.options.get(name) || []) {
|
|
208
|
+
if (typeof opt.argument === 'number') {
|
|
209
|
+
// An argument that went: drop it when it is the last one passed.
|
|
210
|
+
if (call && call.arguments.length === opt.argument + 1) {
|
|
211
|
+
const arg = call.arguments[opt.argument]
|
|
212
|
+
const from = opt.argument === 0 ? arg.getFullStart() : call.arguments[opt.argument - 1].getEnd()
|
|
213
|
+
edits.push({ start: from, end: arg.getEnd(), text: '' })
|
|
214
|
+
} else if (call && call.arguments.length > opt.argument + 1) {
|
|
215
|
+
push('option', node, name, { option: opt.option, note: opt.note })
|
|
216
|
+
}
|
|
217
|
+
} else if (call && objectKeys(call).has(opt.option)) {
|
|
218
|
+
push('option', node, name, { option: opt.option, note: opt.note })
|
|
219
|
+
} else if (call && call.arguments.some((a) => !ts.isObjectLiteralExpression(a) && !ts.isStringLiteral(a) && !ts.isNumericLiteral(a) && a.kind !== ts.SyntaxKind.TrueKeyword && a.kind !== ts.SyntaxKind.FalseKeyword
|
|
220
|
+
// An id or the admin flag is not an options object: `facets.list(collectionId)` passes no options.
|
|
221
|
+
&& !(ts.isIdentifier(a) && /(Id|Ids|^id|^admin|^isAdmin)$/.test(a.text)))) {
|
|
222
|
+
// Options built somewhere else: can't see inside from here.
|
|
223
|
+
push('option-check', node, name, { option: opt.option, note: opt.note })
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
ts.forEachChild(node, visit)
|
|
230
|
+
}
|
|
231
|
+
visit(sf)
|
|
232
|
+
|
|
233
|
+
// A namespace that changed name (product → products): any use of the old one that the script couldn't
|
|
234
|
+
// rename and the table doesn't name (passed as a value, say) still has to be found by someone.
|
|
235
|
+
const goneHeads = new Map()
|
|
236
|
+
for (const [from, to] of idx.renames) if (from.includes('.') && from.split('.')[0] !== to.split('.')[0]) goneHeads.set(from.split('.')[0], to.split('.')[0])
|
|
237
|
+
for (const [sym, all] of refs) {
|
|
238
|
+
const imp = imports.get(sym)
|
|
239
|
+
if (!goneHeads.has(imp.imported)) continue
|
|
240
|
+
const renamed = new Set((renameRefs.get(sym) || []).map((u) => u.id))
|
|
241
|
+
for (const id of all) {
|
|
242
|
+
if (renamed.has(id)) continue
|
|
243
|
+
const line = lineOf(id)
|
|
244
|
+
if (work.some((w) => w.line === line && (w.kind === 'removed' || w.kind === 'by-hand'))) continue
|
|
245
|
+
push('by-hand', id, imp.imported, { to: goneHeads.get(imp.imported), note: `The \`${imp.imported}\` namespace is \`${goneHeads.get(imp.imported)}\` in SDK 3. This use isn't a plain call, so change it by hand.` })
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// 3. Imports whose uses were renamed: rename the import to match.
|
|
250
|
+
const declared = (name) => {
|
|
251
|
+
// Is `name` already something else in this file (a variable, a parameter, another import)?
|
|
252
|
+
let clash = false
|
|
253
|
+
const look = (n) => {
|
|
254
|
+
if (clash) return
|
|
255
|
+
if (ts.isIdentifier(n) && n.text === name) {
|
|
256
|
+
const isMemberName = n.parent && ((ts.isPropertyAccessExpression(n.parent) && n.parent.name === n)
|
|
257
|
+
|| ((ts.isPropertyAssignment(n.parent) || ts.isPropertySignature(n.parent) || ts.isPropertyDeclaration(n.parent) || ts.isMethodDeclaration(n.parent) || ts.isMethodSignature(n.parent)) && n.parent.name === n)
|
|
258
|
+
|| (ts.isBindingElement(n.parent) && n.parent.propertyName === n)
|
|
259
|
+
|| (ts.isJsxAttribute(n.parent) && n.parent.name === n)
|
|
260
|
+
|| ((ts.isImportSpecifier(n.parent) || ts.isExportSpecifier(n.parent)) && n.parent.propertyName === n))
|
|
261
|
+
if (!isMemberName) {
|
|
262
|
+
const sym = symbolOf(n)
|
|
263
|
+
const imp = sym && imports.get(sym)
|
|
264
|
+
if (!(imp && imp.imported === name && imp.local === name)) clash = true
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
ts.forEachChild(n, look)
|
|
268
|
+
}
|
|
269
|
+
look(sf)
|
|
270
|
+
return clash
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const specEdits = new Map() // import declaration → { remove: Set<spec>, rename: Map<spec, text>, add: Set<text> }
|
|
274
|
+
const planFor = (decl) => { if (!specEdits.has(decl)) specEdits.set(decl, { remove: new Set(), rename: new Map(), add: new Set() }); return specEdits.get(decl) }
|
|
275
|
+
|
|
276
|
+
for (const [sym, uses] of renameRefs) {
|
|
277
|
+
const imp = imports.get(sym)
|
|
278
|
+
const to = uses[0].to
|
|
279
|
+
const all = refs.get(sym) || []
|
|
280
|
+
const everyUse = all.length === uses.length
|
|
281
|
+
const already = [...imports.values()].find((i) => i.imported === to) // the new name is imported too
|
|
282
|
+
const aliased = imp.local !== imp.imported
|
|
283
|
+
|
|
284
|
+
if (aliased) {
|
|
285
|
+
// import { product as p }: the uses keep their name; only what it points at changes.
|
|
286
|
+
if (!everyUse) { for (const u of uses) push('by-hand', u.id, imp.imported, { to, note: `\`${imp.imported}\` is \`${to}\` in SDK 3, but \`${imp.local}\` is also used here for something \`${to}\` doesn't do the same way. Change the import by hand.` }); continue }
|
|
287
|
+
planFor(imp.decl).rename.set(imp.spec, `${to} as ${imp.local}`)
|
|
288
|
+
continue
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
let local = to
|
|
292
|
+
if (already) local = already.local
|
|
293
|
+
else if (declared(to)) {
|
|
294
|
+
// `const products = await product.list()` is everywhere: the SDK's name can't also be `products` here.
|
|
295
|
+
local = to + 'Api'
|
|
296
|
+
if (declared(local)) { for (const u of uses) push('by-hand', u.id, imp.imported, { to, note: `\`${imp.imported}\` is \`${to}\` in SDK 3, but both \`${to}\` and \`${local}\` already mean something else in this file. Rename by hand.` }); continue }
|
|
297
|
+
}
|
|
298
|
+
for (const u of uses) edits.push({ start: u.id.getStart(sf), end: u.id.getEnd(), text: local })
|
|
299
|
+
const plan = planFor(imp.decl)
|
|
300
|
+
if (already) { if (everyUse) plan.remove.add(imp.spec) }
|
|
301
|
+
else if (everyUse) plan.rename.set(imp.spec, local === to ? to : `${to} as ${local}`)
|
|
302
|
+
else plan.add.add(local === to ? to : `${to} as ${local}`)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Each import is changed in place, name by name, so its layout stays as the author had it.
|
|
306
|
+
for (const [decl, plan] of specEdits) {
|
|
307
|
+
const nb = decl.importClause.namedBindings
|
|
308
|
+
const els = [...nb.elements]
|
|
309
|
+
const kept = els.filter((s) => !plan.remove.has(s))
|
|
310
|
+
if (!kept.length && !plan.add.size) {
|
|
311
|
+
// Nothing left to import from this line.
|
|
312
|
+
if (decl.importClause.name) edits.push({ start: decl.importClause.name.getEnd(), end: nb.getEnd(), text: '' })
|
|
313
|
+
else { let end = decl.getEnd(); if (text.slice(end, end + 2) === '\r\n') end += 2; else if (text[end] === '\n') end += 1; edits.push({ start: decl.getStart(sf), end, text: '' }) }
|
|
314
|
+
continue
|
|
315
|
+
}
|
|
316
|
+
els.forEach((spec, i) => {
|
|
317
|
+
if (plan.remove.has(spec)) {
|
|
318
|
+
// With the comma that belongs to it: the one after, or for the last name the one before.
|
|
319
|
+
if (i < els.length - 1) edits.push({ start: spec.getStart(sf), end: els[i + 1].getStart(sf), text: '' })
|
|
320
|
+
else edits.push({ start: i > 0 ? els[i - 1].getEnd() : spec.getStart(sf), end: spec.getEnd(), text: '' })
|
|
321
|
+
} else if (plan.rename.has(spec)) {
|
|
322
|
+
edits.push({ start: spec.getStart(sf), end: spec.getEnd(), text: (spec.isTypeOnly ? 'type ' : '') + plan.rename.get(spec) })
|
|
323
|
+
}
|
|
324
|
+
})
|
|
325
|
+
const names = new Set(kept.map((s) => (plan.rename.has(s) ? plan.rename.get(s) : s.getText(sf))))
|
|
326
|
+
const extra = [...plan.add].filter((a) => !names.has(a))
|
|
327
|
+
if (extra.length) { const last = kept[kept.length - 1]; edits.push({ start: last.getEnd(), end: last.getEnd(), text: ', ' + extra.join(', ') }) }
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// 4. Things only a search can hint at.
|
|
331
|
+
const hint = (re, name, note) => {
|
|
332
|
+
let m
|
|
333
|
+
const g = new RegExp(re.source, re.flags.includes('g') ? re.flags : re.flags + 'g')
|
|
334
|
+
while ((m = g.exec(text))) work.push({ kind: 'check', file: rel, line: text.slice(0, m.index).split('\n').length, name, note })
|
|
335
|
+
}
|
|
336
|
+
// A code compared with something that isn't UPPER_SNAKE: 'segments.list.failed', 'notFound'.
|
|
337
|
+
hint(/\b(?:errorCode|details\??\.error(?:Code)?)\s*(?:===|!==|==|!=)\s*['"`](?![A-Z0-9_]+['"`])[^'"`]+['"`]/, 'error codes',
|
|
338
|
+
'Compares an error code with a dotted or camel-case string. Codes are UPPER_SNAKE in SDK 3 (`segments.list.failed` is `SEGMENTS_LIST_FAILED`); read it from `error.errorCode`.')
|
|
339
|
+
hint(/\bdetails\??\.error(?:Code)?\b(?!\s*(?:===|!==|==|!=))/, 'error codes', 'Reads the code from `details`. Use `error.errorCode`.')
|
|
340
|
+
hint(/['"]@proveanything\/smartlinks['"]\s*:\s*['"]SL['"]/, 'shared dependencies',
|
|
341
|
+
'The SDK\'s window global is written out here as `SL`. In a build for SDK 3 it is `SL3`: take the globals from `SHARED_DEPENDENCIES` so this can\'t drift.')
|
|
342
|
+
hint(/\bwindow\.SL\b(?!3)/, 'shared dependencies', 'Reads `window.SL`, which stays SDK 2. A component built on SDK 3 gets the SDK from its import (or `window.SL3`).')
|
|
343
|
+
|
|
344
|
+
return { edits, work }
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function applyEdits(text, edits) {
|
|
348
|
+
const sorted = [...edits].sort((a, b) => b.start - a.start || b.end - a.end)
|
|
349
|
+
let out = text
|
|
350
|
+
let last = Infinity
|
|
351
|
+
for (const e of sorted) {
|
|
352
|
+
if (e.end > last) continue // overlapping: keep the later one in the file, skip this
|
|
353
|
+
out = out.slice(0, e.start) + e.text + out.slice(e.end)
|
|
354
|
+
last = e.start
|
|
355
|
+
}
|
|
356
|
+
return out
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// ── the whole app ────────────────────────────────────────────────────────────────────────────────
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Plan (and with `write: true`, make) the move.
|
|
363
|
+
* Returns { table, files: [{ file, edits }], work: [...], manifest, packages, changed: [...paths] }.
|
|
364
|
+
*/
|
|
365
|
+
export function upgradeApp({ dir, major = '3', write = false, ts = null } = {}) {
|
|
366
|
+
const appDir = path.resolve(dir || process.cwd())
|
|
367
|
+
const table = loadTable(major)
|
|
368
|
+
const idx = indexTable(table)
|
|
369
|
+
ts = ts || loadTypeScript(appDir)
|
|
370
|
+
if (!ts) throw new Error('TypeScript was not found. Install it in the app (npm install -D typescript) and run again.')
|
|
371
|
+
|
|
372
|
+
const files = sourceFiles(appDir)
|
|
373
|
+
const program = ts.createProgram(files, {
|
|
374
|
+
allowJs: true, checkJs: false, noResolve: true, noLib: true, skipLibCheck: true,
|
|
375
|
+
jsx: ts.JsxEmit.Preserve, target: ts.ScriptTarget.ESNext, module: ts.ModuleKind.ESNext, types: [],
|
|
376
|
+
})
|
|
377
|
+
const checker = program.getTypeChecker()
|
|
378
|
+
|
|
379
|
+
const result = { table, dir: appDir, files: [], work: [], changed: [], manifest: null, packages: [] }
|
|
380
|
+
for (const file of files) {
|
|
381
|
+
const sf = program.getSourceFile(file)
|
|
382
|
+
if (!sf || !/smartlinks|\bSL3?\b|errorCode/.test(sf.text)) continue
|
|
383
|
+
const rel = path.relative(appDir, file).replace(/\\/g, '/')
|
|
384
|
+
const { edits, work } = analyseFile(ts, checker, sf, idx, rel)
|
|
385
|
+
result.work.push(...work)
|
|
386
|
+
if (edits.length) {
|
|
387
|
+
result.files.push({ file: rel, edits: edits.length })
|
|
388
|
+
if (write) { fs.writeFileSync(file, applyEdits(sf.text, edits)); result.changed.push(rel) }
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// The manifest says which shared-dependency contract the build is for.
|
|
393
|
+
const contract = table.sharedDependencies
|
|
394
|
+
for (const rel of ['public/app.manifest.json', 'app.manifest.json']) {
|
|
395
|
+
const p = path.join(appDir, rel)
|
|
396
|
+
if (!contract || !fs.existsSync(p)) continue
|
|
397
|
+
const raw = fs.readFileSync(p, 'utf8')
|
|
398
|
+
const m = /("sharedDependencies"\s*:\s*")([^"]+)(")/.exec(raw)
|
|
399
|
+
if (!m) break
|
|
400
|
+
result.manifest = { file: rel, from: m[2], to: contract.to }
|
|
401
|
+
if (m[2] !== contract.to && write) { fs.writeFileSync(p, raw.replace(m[0], m[1] + contract.to + m[3])); result.changed.push(rel) }
|
|
402
|
+
break
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Other SmartLinks packages that use the SDK must be versions built for this major.
|
|
406
|
+
for (const name of ['@proveanything/smartlinks-utils-ui', '@proveanything/smartlinks-auth-ui']) {
|
|
407
|
+
try {
|
|
408
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(appDir, 'node_modules', name, 'package.json'), 'utf8'))
|
|
409
|
+
const range = { ...(pkg.dependencies || {}), ...(pkg.peerDependencies || {}) }['@proveanything/smartlinks']
|
|
410
|
+
const ok = !range || range === '*' || new RegExp(`(^|[^\\d.])${major}(\\.|\\b)`).test(range) || /^>=/.test(range.trim())
|
|
411
|
+
result.packages.push({ name, version: pkg.version, range: range || null, ok })
|
|
412
|
+
} catch { /* not installed */ }
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
result.fields = idx.fields
|
|
416
|
+
result.behaviour = idx.behaviour
|
|
417
|
+
return result
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// ── the report ───────────────────────────────────────────────────────────────────────────────────
|
|
421
|
+
|
|
422
|
+
const plural = (n, one, many = one + 's') => `${n} ${n === 1 ? one : many}`
|
|
423
|
+
|
|
424
|
+
/** The plan as Markdown: what the script did (or would do), then the work left, file by file. */
|
|
425
|
+
export function formatReport(result, { write = false } = {}) {
|
|
426
|
+
const { table, work } = result
|
|
427
|
+
const out = []
|
|
428
|
+
const major = table.sdk.to
|
|
429
|
+
out.push(`# Moving to SDK ${major}`, '')
|
|
430
|
+
|
|
431
|
+
const edits = result.files.reduce((n, f) => n + f.edits, 0)
|
|
432
|
+
const manifestChange = result.manifest && result.manifest.from !== result.manifest.to
|
|
433
|
+
out.push(`## ${write ? 'Done by the script' : 'What the script will change (run again with --write)'}`, '')
|
|
434
|
+
if (!edits && !manifestChange) out.push('Nothing mechanical to change.', '')
|
|
435
|
+
for (const f of result.files) out.push(`- \`${f.file}\`: ${plural(f.edits, 'edit')} (renamed calls, dropped arguments, imports)`)
|
|
436
|
+
if (manifestChange) out.push(`- \`${result.manifest.file}\`: \`sharedDependencies\` ${result.manifest.from} → ${result.manifest.to}`)
|
|
437
|
+
if (edits || manifestChange) out.push('')
|
|
438
|
+
|
|
439
|
+
const of = (kind) => work.filter((w) => w.kind === kind)
|
|
440
|
+
const where = (w) => `\`${w.file}:${w.line}\``
|
|
441
|
+
|
|
442
|
+
const hold = of('hold')
|
|
443
|
+
if (hold.length) {
|
|
444
|
+
out.push('## Leave these as they are', '', hold[0].note, '')
|
|
445
|
+
for (const w of hold) out.push(`- ${where(w)} \`${w.name}\``)
|
|
446
|
+
out.push('')
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const bad = result.packages.filter((p) => !p.ok)
|
|
450
|
+
if (bad.length) {
|
|
451
|
+
out.push('## Packages to update first', '')
|
|
452
|
+
for (const p of bad) out.push(`- \`${p.name}\` ${p.version} is built for SDK \`${p.range}\`. Install a version built for SDK ${major}, or it will read the old shapes.`)
|
|
453
|
+
out.push('')
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const removed = [...of('removed'), ...of('by-hand')]
|
|
457
|
+
if (removed.length) {
|
|
458
|
+
out.push(`## Calls to replace (${removed.length})`, '')
|
|
459
|
+
for (const w of removed) out.push(`- ${where(w)} \`${w.name}\`${w.to ? ` → \`${w.to}\`` : ''}. ${w.note}`)
|
|
460
|
+
out.push('')
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const options = [...of('option'), ...of('option-check')]
|
|
464
|
+
if (options.length) {
|
|
465
|
+
out.push(`## Options that went (${options.length})`, '')
|
|
466
|
+
for (const w of options) out.push(`- ${where(w)} \`${w.name}\` ${w.kind === 'option' ? 'passes' : 'may pass'} \`${w.option}\`. ${w.note}`)
|
|
467
|
+
out.push('')
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const lists = of('list')
|
|
471
|
+
if (lists.length) {
|
|
472
|
+
out.push(`## Lists whose result changed (${lists.length})`, '',
|
|
473
|
+
'Each of these now returns `{ items, nextCursor, count? }`. At each place: read the list from `.items`,',
|
|
474
|
+
'a total from `.count`, "is there more" from `.nextCursor !== null`, and page with `cursor`, not `offset` or `page`.', '')
|
|
475
|
+
const byFile = new Map()
|
|
476
|
+
for (const w of lists) byFile.set(w.file, [...(byFile.get(w.file) || []), w])
|
|
477
|
+
for (const [file, items] of byFile) {
|
|
478
|
+
out.push(`### \`${file}\``, '')
|
|
479
|
+
for (const w of items) {
|
|
480
|
+
const bits = [`was \`${w.before}\``]
|
|
481
|
+
if (w.passes.length) bits.push(`**passes ${w.passes.map((p) => '`' + p + '`').join(', ')}**, which is gone`)
|
|
482
|
+
if (!w.paged) bits.push('not paged')
|
|
483
|
+
if (!w.called) bits.push('passed as a value, not called here: follow it to where the result is read')
|
|
484
|
+
if (w.note) bits.push(w.note)
|
|
485
|
+
out.push(`- line ${w.line} \`${w.name}\`: ${bits.join('; ')}`)
|
|
486
|
+
}
|
|
487
|
+
out.push('')
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const checks = of('check')
|
|
492
|
+
if (checks.length) {
|
|
493
|
+
out.push(`## Check by hand (${checks.length})`, '')
|
|
494
|
+
const seen = new Set()
|
|
495
|
+
for (const w of checks) { const k = w.file + ':' + w.line + w.note; if (seen.has(k)) continue; seen.add(k); out.push(`- ${where(w)} ${w.note}`) }
|
|
496
|
+
out.push('')
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
out.push('## What no script can see', '')
|
|
500
|
+
for (const b of result.behaviour) out.push(`- **${b.name}.** ${b.note}`)
|
|
501
|
+
for (const f of result.fields) out.push(`- **\`${f.name}\`** (a field).${f.to ? ` Use \`${f.to}\`.` : ''} ${f.note}`)
|
|
502
|
+
out.push('', `Everything above is explained in \`docs/${path.basename(table.guide)}\` in this package.`, '')
|
|
503
|
+
return out.join('\n')
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** One line for a log. */
|
|
507
|
+
export function summary(result) {
|
|
508
|
+
const n = (k) => result.work.filter((w) => w.kind === k).length
|
|
509
|
+
return `${plural(result.files.reduce((a, f) => a + f.edits, 0), 'mechanical edit')} in ${plural(result.files.length, 'file')}; `
|
|
510
|
+
+ `left to do: ${plural(n('list'), 'list call')}, ${plural(n('removed') + n('by-hand'), 'call')} to replace, ${plural(n('option') + n('option-check'), 'option')}, ${plural(n('check'), 'check')}`
|
|
511
|
+
+ (n('hold') ? `; ${plural(n('hold'), 'call')} to leave alone` : '')
|
|
512
|
+
}
|