@swipt/cli 0.1.0-nightly.98 → 0.1.0-nightly.99
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/dist/availability.d.ts +3 -1
- package/dist/availability.js +173 -151
- package/dist/availability.js.map +1 -1
- package/dist/cli/cli.js +52 -66
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/command.d.ts +9 -0
- package/dist/cli/command.js.map +1 -1
- package/dist/cli/commands/data/clear.js +2 -2
- package/dist/cli/commands/data/clear.js.map +1 -1
- package/dist/cli/commands/data/data.js +2 -2
- package/dist/cli/commands/data/data.js.map +1 -1
- package/dist/cli/commands/data/list.js +3 -3
- package/dist/cli/commands/data/list.js.map +1 -1
- package/dist/cli/commands/data/operand.js.map +1 -1
- package/dist/cli/commands/data/read.js +4 -7
- package/dist/cli/commands/data/read.js.map +1 -1
- package/dist/cli/commands/data/remove.js +3 -3
- package/dist/cli/commands/data/remove.js.map +1 -1
- package/dist/cli/commands/data/write.js +2 -2
- package/dist/cli/commands/data/write.js.map +1 -1
- package/dist/cli/commands/device/add.js +2 -2
- package/dist/cli/commands/device/add.js.map +1 -1
- package/dist/cli/commands/device/device.js +2 -2
- package/dist/cli/commands/device/device.js.map +1 -1
- package/dist/cli/commands/device/list.js +2 -2
- package/dist/cli/commands/device/list.js.map +1 -1
- package/dist/cli/commands/device/logs.js +44 -46
- package/dist/cli/commands/device/logs.js.map +1 -1
- package/dist/cli/commands/device/remove.js +2 -2
- package/dist/cli/commands/device/remove.js.map +1 -1
- package/dist/cli/commands/device/stop.js +3 -3
- package/dist/cli/commands/device/stop.js.map +1 -1
- package/dist/cli/commands/driver/driver.js +6 -6
- package/dist/cli/commands/driver/driver.js.map +1 -1
- package/dist/cli/commands/flags.js +9 -9
- package/dist/cli/commands/flags.js.map +1 -1
- package/dist/cli/commands/index.js +2 -2
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/project/build.js +2 -2
- package/dist/cli/commands/project/build.js.map +1 -1
- package/dist/cli/commands/project/create.js +3 -3
- package/dist/cli/commands/project/create.js.map +1 -1
- package/dist/cli/commands/project/deploy.js +2 -2
- package/dist/cli/commands/project/deploy.js.map +1 -1
- package/dist/cli/commands/project/develop.js +19 -19
- package/dist/cli/commands/project/develop.js.map +1 -1
- package/dist/cli/commands/project/project.js +2 -2
- package/dist/cli/commands/project/project.js.map +1 -1
- package/dist/cli/commands/project/source.js +62 -37
- package/dist/cli/commands/project/source.js.map +1 -1
- package/dist/cli/commands/repl/api.js +2 -2
- package/dist/cli/commands/repl/api.js.map +1 -1
- package/dist/cli/commands/repl/repl.js +4 -4
- package/dist/cli/commands/repl/repl.js.map +1 -1
- package/dist/cli/commands/repl/reset.js +2 -2
- package/dist/cli/commands/repl/reset.js.map +1 -1
- package/dist/cli/commands/repl/run.js +5 -5
- package/dist/cli/commands/repl/run.js.map +1 -1
- package/dist/cli/commands/sideload/install.js +4 -4
- package/dist/cli/commands/sideload/install.js.map +1 -1
- package/dist/cli/commands/sideload/setup.js +3 -3
- package/dist/cli/commands/sideload/setup.js.map +1 -1
- package/dist/cli/commands/sideload/sideload.js +2 -2
- package/dist/cli/commands/sideload/sideload.js.map +1 -1
- package/dist/cli/commands/sideload/uninstall.js +2 -2
- package/dist/cli/commands/sideload/uninstall.js.map +1 -1
- package/dist/cli/commands/sideload/update.js +3 -3
- package/dist/cli/commands/sideload/update.js.map +1 -1
- package/dist/cli/commands/swiplet/call.js +6 -6
- package/dist/cli/commands/swiplet/call.js.map +1 -1
- package/dist/cli/commands/swiplet/install.js +3 -3
- package/dist/cli/commands/swiplet/install.js.map +1 -1
- package/dist/cli/commands/swiplet/list.js +8 -8
- package/dist/cli/commands/swiplet/list.js.map +1 -1
- package/dist/cli/commands/swiplet/remove.js +3 -3
- package/dist/cli/commands/swiplet/remove.js.map +1 -1
- package/dist/cli/commands/swiplet/service/disable.js +3 -3
- package/dist/cli/commands/swiplet/service/disable.js.map +1 -1
- package/dist/cli/commands/swiplet/service/enable.js +3 -3
- package/dist/cli/commands/swiplet/service/enable.js.map +1 -1
- package/dist/cli/commands/swiplet/service/service.js +2 -2
- package/dist/cli/commands/swiplet/service/service.js.map +1 -1
- package/dist/cli/commands/swiplet/service/services.js +2 -2
- package/dist/cli/commands/swiplet/service/services.js.map +1 -1
- package/dist/cli/commands/swiplet/service/watch.js +2 -2
- package/dist/cli/commands/swiplet/service/watch.js.map +1 -1
- package/dist/cli/commands/swiplet/show.js +6 -6
- package/dist/cli/commands/swiplet/show.js.map +1 -1
- package/dist/cli/commands/swiplet/swiplet.js +4 -4
- package/dist/cli/commands/swiplet/swiplet.js.map +1 -1
- package/dist/cli/commands/version/version.js +2 -2
- package/dist/cli/commands/version/version.js.map +1 -1
- package/dist/cli/deploy.js +9 -7
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/session.js.map +1 -1
- package/dist/client.d.ts +145 -7
- package/dist/client.js +20 -22
- package/dist/client.js.map +1 -1
- package/dist/connection.d.ts +292 -25
- package/dist/connection.js +36 -35
- package/dist/connection.js.map +1 -1
- package/dist/driver.d.ts +62 -23
- package/dist/driver.js +29 -33
- package/dist/driver.js.map +1 -1
- package/dist/i18n.d.ts +2 -5
- package/dist/i18n.js +15 -13
- package/dist/i18n.js.map +1 -1
- package/dist/i18next.d.ts +7 -0
- package/dist/ignore.d.ts +14 -7
- package/dist/ignore.js +13 -14
- package/dist/ignore.js.map +1 -1
- package/dist/mdns.d.ts +2 -2
- package/dist/mdns.js +1 -1
- package/dist/mdns.js.map +1 -1
- package/dist/metro.d.ts +19 -5
- package/dist/metro.js +61 -63
- package/dist/metro.js.map +1 -1
- package/dist/output.d.ts +29 -14
- package/dist/output.js +17 -15
- package/dist/output.js.map +1 -1
- package/dist/passcode.d.ts +12 -8
- package/dist/passcode.js +18 -18
- package/dist/passcode.js.map +1 -1
- package/dist/project.d.ts +20 -10
- package/dist/project.js +72 -49
- package/dist/project.js.map +1 -1
- package/dist/proto/common_pb.d.ts +240 -0
- package/dist/proto/common_pb.js +7 -2
- package/dist/proto/common_pb.js.map +1 -1
- package/dist/proto/logs_pb.d.ts +38 -0
- package/dist/proto/repl_pb.d.ts +96 -0
- package/dist/proto/swiplets_pb.d.ts +361 -0
- package/dist/proto/swiplets_pb.js +7 -2
- package/dist/proto/swiplets_pb.js.map +1 -1
- package/dist/proto/system_pb.d.ts +33 -0
- package/dist/resources.d.ts +400 -0
- package/dist/serve.d.ts +9 -1
- package/dist/serve.js +17 -16
- package/dist/serve.js.map +1 -1
- package/dist/sideload.d.ts +27 -14
- package/dist/sideload.js +102 -89
- package/dist/sideload.js.map +1 -1
- package/dist/swipt-app.d.ts +19 -9
- package/dist/swipt-app.js +1 -1
- package/dist/swipt-app.js.map +1 -1
- package/locales/ar/translation.json +413 -0
- package/locales/bg/translation.json +397 -0
- package/locales/bn/translation.json +397 -0
- package/locales/ca/translation.json +401 -0
- package/locales/cs/translation.json +405 -0
- package/locales/da/translation.json +397 -0
- package/locales/de/translation.json +397 -0
- package/locales/el/translation.json +397 -0
- package/locales/en/translation.json +397 -0
- package/locales/es/translation.json +401 -0
- package/locales/es-419/translation.json +401 -0
- package/locales/fi/translation.json +397 -0
- package/locales/fr/translation.json +401 -0
- package/locales/fr-CA/translation.json +401 -0
- package/locales/gu/translation.json +397 -0
- package/locales/he/translation.json +401 -0
- package/locales/hi/translation.json +397 -0
- package/locales/hr/translation.json +401 -0
- package/locales/hu/translation.json +397 -0
- package/locales/id/translation.json +393 -0
- package/locales/it/translation.json +401 -0
- package/locales/ja/translation.json +393 -0
- package/locales/kk/translation.json +397 -0
- package/locales/kn/translation.json +397 -0
- package/locales/ko/translation.json +393 -0
- package/locales/lt/translation.json +405 -0
- package/locales/ml/translation.json +397 -0
- package/locales/mr/translation.json +397 -0
- package/locales/ms/translation.json +393 -0
- package/locales/nb/translation.json +397 -0
- package/locales/nl/translation.json +397 -0
- package/locales/or/translation.json +397 -0
- package/locales/pa/translation.json +397 -0
- package/locales/pl/translation.json +405 -0
- package/locales/pt-BR/translation.json +401 -0
- package/locales/pt-PT/translation.json +401 -0
- package/locales/ro/translation.json +401 -0
- package/locales/ru/translation.json +405 -0
- package/locales/sk/translation.json +405 -0
- package/locales/sl/translation.json +405 -0
- package/locales/sv/translation.json +397 -0
- package/locales/ta/translation.json +397 -0
- package/locales/te/translation.json +397 -0
- package/locales/th/translation.json +393 -0
- package/locales/tr/translation.json +397 -0
- package/locales/uk/translation.json +405 -0
- package/locales/ur/translation.json +397 -0
- package/locales/vi/translation.json +397 -0
- package/locales/zh-HK/translation.json +393 -0
- package/locales/zh-Hans/translation.json +393 -0
- package/locales/zh-Hant/translation.json +393 -0
- package/package.json +14 -9
- package/locales/ar.json +0 -311
- package/locales/bg.json +0 -295
- package/locales/bn.json +0 -295
- package/locales/ca.json +0 -299
- package/locales/cs.json +0 -303
- package/locales/da.json +0 -295
- package/locales/de.json +0 -295
- package/locales/el.json +0 -295
- package/locales/es-419.json +0 -299
- package/locales/es.json +0 -299
- package/locales/fi.json +0 -295
- package/locales/fr-CA.json +0 -299
- package/locales/fr.json +0 -299
- package/locales/gu.json +0 -295
- package/locales/he.json +0 -299
- package/locales/hi.json +0 -295
- package/locales/hr.json +0 -299
- package/locales/hu.json +0 -295
- package/locales/id.json +0 -283
- package/locales/it.json +0 -299
- package/locales/ja.json +0 -283
- package/locales/kk.json +0 -295
- package/locales/kn.json +0 -295
- package/locales/ko.json +0 -283
- package/locales/lt.json +0 -303
- package/locales/ml.json +0 -295
- package/locales/mr.json +0 -295
- package/locales/ms.json +0 -283
- package/locales/nb.json +0 -295
- package/locales/nl.json +0 -295
- package/locales/or.json +0 -295
- package/locales/pa.json +0 -295
- package/locales/pl.json +0 -303
- package/locales/pt-BR.json +0 -299
- package/locales/pt-PT.json +0 -299
- package/locales/ro.json +0 -299
- package/locales/ru.json +0 -303
- package/locales/sk.json +0 -303
- package/locales/sl.json +0 -303
- package/locales/sv.json +0 -295
- package/locales/ta.json +0 -295
- package/locales/te.json +0 -295
- package/locales/th.json +0 -283
- package/locales/tr.json +0 -295
- package/locales/uk.json +0 -303
- package/locales/ur.json +0 -295
- package/locales/vi.json +0 -295
- package/locales/zh-HK.json +0 -283
- package/locales/zh-Hans.json +0 -283
- package/locales/zh-Hant.json +0 -283
package/dist/availability.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"availability.js","names":[],"sources":["../src/availability.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport { NodeFlags, SyntaxKind } from \"typescript/unstable/ast\";\nimport { isTypeNode } from \"typescript/unstable/ast/is\";\nimport { API, SymbolFlags } from \"typescript/unstable/sync\";\n\nimport { language, tr } from \"./i18n\";\nimport { parseVersion, versionAtLeast } from \"./version\";\n\nconst requirements = {\n apiLevel: {\n parse: (text) => (/^[1-9]\\d*$/.test(text) ? Number(text) : undefined),\n covers: (level, needed) => level >= needed,\n describe: (level) => tr(\"API level {level}\", { level }),\n },\n iOS: {\n parse: parseVersion,\n covers: versionAtLeast,\n describe: (version) => `iOS ${version.join(\".\")}`,\n },\n};\n\nconst lists = new Intl.ListFormat(language, { type: \"conjunction\" });\n\nconst merge = (into, from) => {\n for (const [name, needed] of Object.entries(from)) {\n if (\n into[name] === undefined ||\n !requirements[name].covers(into[name], needed)\n ) {\n into[name] = needed;\n }\n }\n return into;\n};\n\nconst describe = (needed, missing) =>\n lists.format(\n missing.map((name) => requirements[name].describe(needed[name])),\n );\n\nfunction parseAnnotation(text) {\n const requirement = {};\n for (const entry of text.split(\",\").map((part) => part.trim())) {\n const [kind, value, ...rest] = entry.split(/\\s+/);\n const parsed =\n rest.length === 0 && Object.hasOwn(requirements, kind)\n ? requirements[kind].parse(value ?? \"\")\n : undefined;\n if (parsed === undefined) {\n return { requirement, invalid: entry };\n }\n if (requirement[kind] !== undefined) {\n return { requirement, repeated: kind };\n }\n requirement[kind] = parsed;\n }\n return { requirement };\n}\n\nconst tagText = (tag) =>\n typeof tag.comment === \"string\"\n ? tag.comment\n : (tag.comment ?? []).map((part) => part.text).join(\"\");\n\nconst annotationTags = (node) =>\n (node.jsDoc ?? []).flatMap((comment) =>\n (comment.tags ?? []).filter((tag) => tag.tagName.text === \"available\"),\n );\n\nconst exits = (statement) =>\n statement.kind === SyntaxKind.ReturnStatement ||\n statement.kind === SyntaxKind.ThrowStatement ||\n statement.kind === SyntaxKind.BreakStatement ||\n statement.kind === SyntaxKind.ContinueStatement ||\n (statement.kind === SyntaxKind.Block &&\n statement.statements.length > 0 &&\n exits(statement.statements.at(-1)));\n\nconst hasModifier = (node, kind) =>\n node.modifiers?.some((modifier) => modifier.kind === kind) ?? false;\n\nconst functions = new Set([\n SyntaxKind.FunctionDeclaration,\n SyntaxKind.FunctionExpression,\n SyntaxKind.ArrowFunction,\n SyntaxKind.MethodDeclaration,\n SyntaxKind.GetAccessor,\n SyntaxKind.SetAccessor,\n SyntaxKind.Constructor,\n]);\n\nconst classes = new Set([\n SyntaxKind.ClassDeclaration,\n SyntaxKind.ClassExpression,\n]);\n\nconst valueHolders = new Set([\n SyntaxKind.VariableDeclaration,\n SyntaxKind.PropertyDeclaration,\n SyntaxKind.PropertyAssignment,\n]);\n\nconst objectMembers = new Set([\n SyntaxKind.PropertyAssignment,\n SyntaxKind.ShorthandPropertyAssignment,\n SyntaxKind.MethodDeclaration,\n SyntaxKind.GetAccessor,\n SyntaxKind.SetAccessor,\n]);\n\nconst literals = new Set([\n SyntaxKind.ObjectLiteralExpression,\n SyntaxKind.ArrayLiteralExpression,\n SyntaxKind.ArrowFunction,\n SyntaxKind.FunctionExpression,\n SyntaxKind.StringLiteral,\n SyntaxKind.NumericLiteral,\n SyntaxKind.NoSubstitutionTemplateLiteral,\n SyntaxKind.TemplateExpression,\n SyntaxKind.TrueKeyword,\n SyntaxKind.FalseKeyword,\n SyntaxKind.NullKeyword,\n SyntaxKind.SpreadElement,\n]);\n\nconst names = new Set([\n SyntaxKind.StringLiteral,\n SyntaxKind.NoSubstitutionTemplateLiteral,\n]);\n\nconst inert = new Set([\n SyntaxKind.ImportDeclaration,\n SyntaxKind.ExportDeclaration,\n SyntaxKind.InterfaceDeclaration,\n SyntaxKind.TypeAliasDeclaration,\n SyntaxKind.JsxClosingElement,\n]);\n\nfunction sourceFilesOf(root, metafiles) {\n const files = new Set();\n for (const metafile of metafiles) {\n for (const input of Object.keys(metafile.inputs)) {\n const file = path.resolve(input);\n if (\n !/^[a-z][\\w-]+:/.test(input) &&\n /\\.[cm]?[jt]sx?$/.test(file) &&\n !path.relative(root, file).startsWith(\"..\") &&\n !file.split(path.sep).includes(\"node_modules\")\n ) {\n files.add(fs.realpathSync(file));\n }\n }\n }\n return [...files];\n}\n\nexport class AvailabilityChecker {\n #api;\n #open = new Set();\n\n check(project, metafiles) {\n const files = sourceFilesOf(project.root, metafiles);\n if (files.length === 0 && this.#open.size === 0) {\n return;\n }\n this.#api ??= new API({ cwd: project.root });\n // An open file keeps the content it was opened with, whatever fileChanges says\n // (typescript 7.0.2).\n if (this.#open.size > 0) {\n this.#api.updateSnapshot({ closeFiles: [...this.#open] });\n }\n const snapshot = this.#api.updateSnapshot({\n openFiles: files,\n fileChanges: { invalidateAll: true },\n });\n this.#open = new Set(files);\n if (files.length === 0) {\n return;\n }\n const problems = { lines: new Set(), guarding: false };\n const groups = Map.groupBy(files, (file) =>\n snapshot.getDefaultProjectForFile(file),\n );\n for (const [typescript, owned] of groups) {\n new Checker(typescript, project, files, problems).check(owned);\n }\n if (problems.lines.size > 0) {\n throw new Error(\n [\n ...problems.lines,\n ...(problems.guarding\n ? [\n tr(\n 'Check these with available(), mark the code that uses them with @available, or raise \"swiplet.minimumAPILevel\" or \"swiplet.minimumIOSVersion\" in package.json.',\n ),\n ]\n : []),\n ].join(\"\\n\"),\n );\n }\n }\n\n close() {\n this.#api?.close();\n }\n}\n\nclass Checker {\n #project;\n #checker;\n #root;\n #files;\n #problems;\n #minimum;\n #entries;\n #available;\n #symbols = new Map();\n #imports = new Set();\n #requirements = new Map();\n #annotations = new Map();\n #facts = [new Map(), new Map()];\n #types = new Map();\n #annotated = new Map();\n\n constructor(typescript, project, files, problems) {\n this.#project = typescript;\n this.#checker = typescript.checker;\n this.#root = project.root;\n this.#files = new Set(files);\n this.#problems = problems;\n this.#minimum = {\n apiLevel: project.config.minimumAPILevel ?? project.apiLevel,\n iOS: parseVersion(\n project.config.minimumIOSVersion ?? project.minimumIOSVersion,\n ),\n };\n this.#entries = new Set(\n [project.app, project.extension]\n .filter(Boolean)\n .map((entry) => fs.realpathSync(entry)),\n );\n this.#available = this.#availableSymbol(project.apiDirectory);\n }\n\n check(files) {\n for (const file of files) {\n const source = this.#project.program.getSourceFile(file);\n const { identifiers, properties, values } = this.#collect(source);\n const symbols = this.#checker.getSymbolAtLocation(identifiers);\n for (const [index, node] of identifiers.entries()) {\n this.#use(\n node,\n node.parent.kind === SyntaxKind.ShorthandPropertyAssignment\n ? this.#checker.getShorthandAssignmentValueSymbol(node.parent)\n : symbols[index],\n );\n }\n for (const node of properties) {\n this.#use(node, this.#propertySymbol(node));\n }\n for (const node of values) {\n this.#useValue(node);\n }\n for (const statement of source.statements) {\n if (\n statement.kind !== SyntaxKind.ExportDeclaration ||\n statement.isTypeOnly\n ) {\n continue;\n }\n const exported = (statement.exportClause?.elements ?? []).filter(\n (specifier) => !specifier.isTypeOnly,\n );\n if (statement.moduleSpecifier === undefined) {\n for (const specifier of exported) {\n const local =\n this.#checker.getExportSpecifierLocalTargetSymbol(specifier);\n if (local !== undefined) {\n this.#useImport(local);\n }\n }\n } else if (\n exported.length > 0 ||\n statement.exportClause?.elements === undefined\n ) {\n this.#importModule(statement);\n }\n }\n if (this.#entries.has(file)) {\n for (const statement of source.statements) {\n if (\n statement.name !== undefined &&\n hasModifier(statement, SyntaxKind.DefaultKeyword)\n ) {\n this.#useEntry(statement.name);\n }\n }\n }\n }\n }\n\n #collect(source) {\n const identifiers = [];\n const properties = [];\n const values = [];\n const visit = (node, checked) => {\n for (const tag of annotationTags(node)) {\n this.#parse(tagText(tag), tag);\n }\n const extended =\n node.kind === SyntaxKind.ExpressionWithTypeArguments &&\n node.parent.token === SyntaxKind.ExtendsKeyword &&\n classes.has(node.parent.parent.kind);\n if (inert.has(node.kind) || (isTypeNode(node) && !extended)) {\n checked = false;\n }\n if (checked) {\n if (\n node.kind === SyntaxKind.CallExpression ||\n node.kind === SyntaxKind.NewExpression\n ) {\n values.push(\n ...(node.arguments ?? []).filter(\n (argument) => !literals.has(argument.kind),\n ),\n );\n } else if (\n node.kind === SyntaxKind.SpreadAssignment ||\n node.kind === SyntaxKind.JsxSpreadAttribute\n ) {\n values.push(node.expression);\n }\n }\n if (checked && node.kind === SyntaxKind.Identifier) {\n const { parent } = node;\n const property =\n parent.kind === SyntaxKind.JsxAttribute ||\n (objectMembers.has(parent.kind) &&\n parent.parent.kind === SyntaxKind.ObjectLiteralExpression &&\n parent.name === node) ||\n (parent.kind === SyntaxKind.BindingElement &&\n parent.parent.kind === SyntaxKind.ObjectBindingPattern &&\n (parent.propertyName ?? parent.name) === node);\n if (property) {\n properties.push(node);\n }\n if (\n parent.kind === SyntaxKind.ShorthandPropertyAssignment ||\n (!property &&\n parent.propertyName !== node &&\n (parent.name !== node ||\n parent.kind === SyntaxKind.PropertyAccessExpression))\n ) {\n identifiers.push(node);\n }\n }\n if (\n checked &&\n (node.kind === SyntaxKind.StringLiteral ||\n node.kind === SyntaxKind.NoSubstitutionTemplateLiteral)\n ) {\n const { parent } = node;\n const member =\n parent.kind === SyntaxKind.ComputedPropertyName\n ? parent.parent\n : parent;\n if (\n (objectMembers.has(member.kind) &&\n member.parent.kind === SyntaxKind.ObjectLiteralExpression &&\n (member.name === node || member.name === parent)) ||\n (member.kind === SyntaxKind.BindingElement &&\n member.parent.kind === SyntaxKind.ObjectBindingPattern &&\n (member.propertyName === node || member.propertyName === parent))\n ) {\n properties.push(node);\n } else if (\n parent.kind === SyntaxKind.ElementAccessExpression &&\n parent.argumentExpression === node\n ) {\n identifiers.push(node);\n }\n }\n if (\n checked &&\n node.kind === SyntaxKind.ObjectLiteralExpression &&\n node.properties.some(\n (member) =>\n member.name?.kind === SyntaxKind.ComputedPropertyName &&\n !names.has(member.name.expression.kind),\n )\n ) {\n values.push(node);\n }\n node.forEachChild((child) => visit(child, checked));\n };\n source.forEachChild((child) => visit(child, true));\n return { identifiers, properties, values };\n }\n\n #useValue(node) {\n const expected = this.#checker.getContextualType(node);\n if (expected === undefined) {\n return;\n }\n if (!this.#annotated.has(expected.id)) {\n const annotated = new Map();\n for (const candidate of [expected, ...(expected.getTypes?.() ?? [])]) {\n for (const property of this.#checker.getPropertiesOfType(candidate)) {\n if (Object.keys(this.#requirementOf(property)).length > 0) {\n annotated.set(property.name, property);\n }\n }\n }\n this.#annotated.set(expected.id, [...annotated.values()]);\n }\n const annotated = this.#annotated.get(expected.id);\n const type =\n annotated.length > 0 ? this.#checker.getTypeAtLocation(node) : undefined;\n if (type === undefined) {\n return;\n }\n const named = new Set(\n (node.kind === SyntaxKind.ObjectLiteralExpression\n ? node.properties\n : []\n ).map((member) =>\n member.name?.kind === SyntaxKind.ComputedPropertyName\n ? member.name.expression.text\n : member.name?.text,\n ),\n );\n for (const property of annotated) {\n if (\n !named.has(property.name) &&\n this.#checker.getPropertyOfType(type, property.name) !== undefined\n ) {\n this.#use(node, property, property.name);\n }\n }\n }\n\n #use(node, symbol, name = node.text) {\n if (symbol === undefined) {\n return;\n }\n this.#useImport(symbol);\n const needed = this.#requirementOf(symbol);\n const missing = Object.keys(needed).filter(\n (name) => !this.#covered(name, needed[name], node),\n );\n if (missing.length > 0) {\n this.#problems.guarding = true;\n this.#problems.lines.add(\n tr(\"{location}: {name} needs {requirement}.\", {\n location: this.#location(node),\n name,\n requirement: describe(needed, missing),\n }),\n );\n }\n }\n\n #useImport(symbol) {\n let declaration =\n symbol.flags & SymbolFlags.Alias\n ? symbol.declarations?.[0]?.resolve(this.#project)\n : undefined;\n while (\n declaration !== undefined &&\n declaration.kind !== SyntaxKind.ImportDeclaration\n ) {\n declaration = declaration.parent;\n }\n if (declaration !== undefined) {\n this.#importModule(declaration);\n }\n }\n\n #importModule(declaration) {\n if (this.#imports.has(declaration)) {\n return;\n }\n this.#imports.add(declaration);\n const name = declaration.moduleSpecifier;\n const module = this.#checker\n .getSymbolAtLocation(name)\n ?.declarations?.[0]?.resolve(this.#project);\n if (\n module?.kind !== SyntaxKind.SourceFile ||\n this.#files.has(module.fileName)\n ) {\n return;\n }\n const needed = this.#moduleRequirement(module);\n const missing = Object.keys(needed).filter(\n (kind) => !requirements[kind].covers(this.#minimum[kind], needed[kind]),\n );\n if (missing.length > 0) {\n this.#problems.lines.add(\n tr(\n '{location}: importing {name} needs {requirement}; raise \"swiplet.minimumAPILevel\" or \"swiplet.minimumIOSVersion\" in package.json.',\n {\n location: this.#location(name),\n name: name.text,\n requirement: describe(needed, missing),\n },\n ),\n );\n }\n }\n\n #moduleRequirement(source) {\n const requirement = {};\n const [first] = source.statements;\n if (first?.kind === SyntaxKind.ImportDeclaration) {\n for (const tag of annotationTags(first)) {\n merge(requirement, this.#parse(tagText(tag), tag));\n }\n }\n return requirement;\n }\n\n #useEntry(name) {\n const symbol = this.#checker.getSymbolAtLocation(name);\n const needed = symbol === undefined ? {} : this.#requirementOf(symbol);\n const missing = Object.keys(needed).filter(\n (kind) => !requirements[kind].covers(this.#minimum[kind], needed[kind]),\n );\n if (missing.length > 0) {\n this.#problems.lines.add(\n tr(\n '{location}: {name} is an entry of the swiplet and needs {requirement}; raise \"swiplet.minimumAPILevel\" or \"swiplet.minimumIOSVersion\" in package.json.',\n {\n location: this.#location(name),\n name: name.text,\n requirement: describe(needed, missing),\n },\n ),\n );\n }\n }\n\n #location(node) {\n const source = sourceFileOf(node);\n const { line, character } = source.getLineAndCharacterOfPosition(\n node.getStart(source),\n );\n return `${path.relative(this.#root, source.fileName)}:${line + 1}:${character + 1}`;\n }\n\n #parse(text, node) {\n const { requirement, invalid, repeated } = parseAnnotation(text);\n if (invalid !== undefined) {\n this.#problems.lines.add(\n tr(\n '{location}: @available has \"{entry}\"; it takes \"apiLevel <level>\" and \"iOS <version>\", separated by commas.',\n { location: this.#location(node), entry: invalid },\n ),\n );\n } else if (repeated !== undefined) {\n this.#problems.lines.add(\n tr(\"{location}: @available names {kind} twice.\", {\n location: this.#location(node),\n kind: repeated,\n }),\n );\n }\n return requirement;\n }\n\n #target(symbol) {\n return symbol.flags & SymbolFlags.Alias\n ? this.#checker.getAliasedSymbol(symbol)\n : symbol;\n }\n\n #symbolOf(node) {\n if (!this.#symbols.has(node)) {\n const symbol = this.#checker.getSymbolAtLocation(node);\n this.#symbols.set(\n node,\n symbol === undefined ? undefined : this.#target(symbol),\n );\n }\n return this.#symbols.get(node);\n }\n\n #requirementOf(symbol) {\n const target = this.#target(symbol);\n if (!this.#requirements.has(target.id)) {\n const requirement = {};\n const declaration = (\n target.valueDeclaration ?? target.declarations[0]\n )?.resolve(this.#project);\n const external =\n declaration !== undefined &&\n !this.#files.has(sourceFileOf(declaration).fileName);\n for (const tag of this.#checker.getJsDocTagsOfSymbol(target)) {\n if (tag.name === \"available\") {\n merge(\n requirement,\n external\n ? this.#parse(tag.text ?? \"\", declaration)\n : parseAnnotation(tag.text ?? \"\").requirement,\n );\n }\n }\n if (external) {\n merge(requirement, this.#moduleRequirement(sourceFileOf(declaration)));\n }\n this.#requirements.set(target.id, requirement);\n }\n return this.#requirements.get(target.id);\n }\n\n #annotationOf(node) {\n if (!this.#annotations.has(node)) {\n const requirement = {};\n const symbol =\n node.name?.kind === SyntaxKind.Identifier\n ? this.#checker.getSymbolAtLocation(node.name)\n : undefined;\n if (symbol !== undefined) {\n merge(requirement, this.#requirementOf(symbol));\n }\n for (const tag of annotationTags(node)) {\n merge(requirement, parseAnnotation(tagText(tag)).requirement);\n }\n this.#annotations.set(node, requirement);\n }\n return this.#annotations.get(node);\n }\n\n #propertySymbol(name) {\n const member =\n name.parent.kind === SyntaxKind.ComputedPropertyName\n ? name.parent.parent\n : name.parent;\n const container = member.parent;\n if (!this.#types.has(container)) {\n this.#types.set(\n container,\n member.kind === SyntaxKind.BindingElement\n ? this.#checker.getTypeAtLocation(container)\n : this.#checker.getContextualType(container),\n );\n }\n const type = this.#types.get(container);\n if (type === undefined) {\n return undefined;\n }\n for (const candidate of [type, ...(type.getTypes?.() ?? [])]) {\n const property = this.#checker.getPropertyOfType(candidate, name.text);\n if (property !== undefined) {\n return property;\n }\n }\n return undefined;\n }\n\n #covered(name, needed, reference) {\n const { covers } = requirements[name];\n if (covers(this.#minimum[name], needed)) {\n return true;\n }\n let crossed = false;\n for (\n let child = reference, parent = reference.parent;\n parent;\n child = parent, parent = parent.parent\n ) {\n const proven = this.#provenBy(parent, child, crossed)[name];\n if (proven !== undefined && covers(proven, needed)) {\n return true;\n }\n crossed ||= functions.has(parent.kind);\n }\n return false;\n }\n\n #provenBy(parent, child, crossed) {\n const proven = {};\n switch (parent.kind) {\n case SyntaxKind.IfStatement:\n if (child === parent.thenStatement) {\n merge(proven, this.#factsOf(parent.expression, true));\n } else if (child === parent.elseStatement) {\n merge(proven, this.#factsOf(parent.expression, false));\n }\n break;\n case SyntaxKind.ConditionalExpression:\n if (child === parent.whenTrue) {\n merge(proven, this.#factsOf(parent.condition, true));\n } else if (child === parent.whenFalse) {\n merge(proven, this.#factsOf(parent.condition, false));\n }\n break;\n case SyntaxKind.BinaryExpression:\n if (child === parent.right) {\n const operator = parent.operatorToken.kind;\n if (operator === SyntaxKind.AmpersandAmpersandToken) {\n merge(proven, this.#factsOf(parent.left, true));\n } else if (operator === SyntaxKind.BarBarToken) {\n merge(proven, this.#factsOf(parent.left, false));\n }\n }\n break;\n }\n for (const statement of parent.statements ?? []) {\n if (statement === child) {\n break;\n }\n if (\n statement.kind === SyntaxKind.IfStatement &&\n statement.elseStatement === undefined &&\n exits(statement.thenStatement)\n ) {\n merge(proven, this.#factsOf(statement.expression, false));\n }\n }\n if (\n functions.has(parent.kind) ||\n (classes.has(parent.kind) &&\n (crossed ||\n (child.kind === SyntaxKind.PropertyDeclaration &&\n !hasModifier(child, SyntaxKind.StaticKeyword)))) ||\n (valueHolders.has(parent.kind) && crossed && child === parent.initializer)\n ) {\n merge(proven, this.#annotationOf(parent));\n }\n return proven;\n }\n\n #factsOf(node, outcome) {\n const cache = this.#facts[Number(outcome)];\n if (!cache.has(node)) {\n cache.set(node, {});\n cache.set(node, this.#computeFacts(node, outcome));\n }\n return cache.get(node);\n }\n\n #computeFacts(node, outcome) {\n switch (node.kind) {\n case SyntaxKind.Identifier: {\n const value = this.#constant(node);\n return value === node ? {} : this.#factsOf(value, outcome);\n }\n case SyntaxKind.ParenthesizedExpression:\n return this.#factsOf(node.expression, outcome);\n case SyntaxKind.PrefixUnaryExpression:\n return node.operator === SyntaxKind.ExclamationToken\n ? this.#factsOf(node.operand, !outcome)\n : {};\n case SyntaxKind.CallExpression:\n return outcome && this.#isAvailable(node.expression)\n ? this.#requirementsOf(node.arguments[0])\n : {};\n case SyntaxKind.BinaryExpression: {\n const operator = node.operatorToken.kind;\n if (operator === SyntaxKind.AmpersandAmpersandToken) {\n return outcome\n ? merge(\n merge({}, this.#factsOf(node.left, true)),\n this.#factsOf(node.right, true),\n )\n : {};\n }\n if (operator === SyntaxKind.BarBarToken) {\n return outcome\n ? {}\n : merge(\n merge({}, this.#factsOf(node.left, false)),\n this.#factsOf(node.right, false),\n );\n }\n return {};\n }\n }\n return {};\n }\n\n #constant(node) {\n for (const seen = new Set(); node.kind === SyntaxKind.Identifier;) {\n const declaration = this.#symbolOf(node)?.valueDeclaration?.resolve(\n this.#project,\n );\n if (\n declaration?.kind !== SyntaxKind.VariableDeclaration ||\n declaration.initializer === undefined ||\n !(declaration.parent.flags & NodeFlags.Const) ||\n seen.has(declaration)\n ) {\n break;\n }\n seen.add(declaration);\n node = declaration.initializer;\n }\n return node;\n }\n\n #isAvailable(node) {\n const name =\n node.kind === SyntaxKind.PropertyAccessExpression ? node.name : node;\n return (\n this.#available !== undefined &&\n name.kind === SyntaxKind.Identifier &&\n this.#symbolOf(name)?.id === this.#available\n );\n }\n\n #requirementsOf(argument) {\n const proven = {};\n for (const property of argument?.kind === SyntaxKind.ObjectLiteralExpression\n ? argument.properties\n : []) {\n const value =\n property.kind === SyntaxKind.PropertyAssignment &&\n Object.hasOwn(requirements, property.name.text)\n ? this.#constant(property.initializer)\n : undefined;\n if (value?.kind === SyntaxKind.NumericLiteral) {\n const parsed = requirements[property.name.text].parse(\n String(Number(value.text)),\n );\n if (parsed !== undefined) {\n proven[property.name.text] = parsed;\n }\n }\n }\n return proven;\n }\n\n #availableSymbol(apiDirectory) {\n const source = this.#project.program.getSourceFile(\n fs.realpathSync(path.join(apiDirectory, \"index.d.ts\")),\n );\n const declaration = source?.statements.find(\n (statement) =>\n statement.kind === SyntaxKind.FunctionDeclaration &&\n statement.name?.text === \"available\",\n );\n return declaration === undefined\n ? undefined\n : this.#checker.getSymbolAtLocation(declaration.name)?.id;\n }\n}\n\nfunction sourceFileOf(node) {\n while (node.kind !== SyntaxKind.SourceFile) {\n node = node.parent;\n }\n return node;\n}\n"],"mappings":";;;;;;;;AAUA,MAAM,eAAe;CACnB,UAAU;EACR,QAAQ,SAAU,aAAa,KAAK,IAAI,IAAI,OAAO,IAAI,IAAI,KAAA;EAC3D,SAAS,OAAO,WAAW,SAAS;EACpC,WAAW,UAAU,GAAG,qBAAqB,EAAE,MAAM,CAAC;CACxD;CACA,KAAK;EACH,OAAO;EACP,QAAQ;EACR,WAAW,YAAY,OAAO,QAAQ,KAAK,GAAG;CAChD;AACF;AAEA,MAAM,QAAQ,IAAI,KAAK,WAAW,UAAU,EAAE,MAAM,cAAc,CAAC;AAEnE,MAAM,SAAS,MAAM,SAAS;CAC5B,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,IAAI,GAC9C,IACE,KAAK,UAAU,KAAA,KACf,CAAC,aAAa,KAAK,CAAC,OAAO,KAAK,OAAO,MAAM,GAE7C,KAAK,QAAQ;CAGjB,OAAO;A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AAW,KAAA,GACb,OAAO,SAAS,KAAK,QAAQ;GAEjC;EACF;EACA,OAAO;CACT;CAEA,iBAAiB,cAAc;EAI7B,MAAM,cAHS,KAAK,SAAS,QAAQ,cACnC,GAAG,aAAa,KAAK,KAAK,cAAc,YAAY,CAAC,CAE9B,CAAC,EAAE,WAAW,MACpC,cACC,UAAU,SAAS,WAAW,uBAC9B,UAAU,MAAM,SAAS,WAC7B;EACA,OAAO,gBAAgB,KAAA,IACnB,KAAA,IACA,KAAK,SAAS,oBAAoB,YAAY,IAAI,CAAC,EAAE;CAC3D;AACF;AAEA,SAAS,aAAa,MAAM;CAC1B,OAAO,KAAK,SAAS,WAAW,YAC9B,OAAO,KAAK;CAEd,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"availability.js","names":[],"sources":["../src/availability.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport type { Metafile } from \"esbuild\";\nimport {\n type ClassLikeDeclaration,\n type ExportDeclaration,\n type Expression,\n type FunctionLikeDeclaration,\n type Identifier,\n type ImportDeclaration,\n type JSDocTag,\n type ModifiersBase,\n type Node,\n NodeFlags,\n type ObjectLiteralElementLike,\n type PropertyAssignment,\n type PropertyDeclaration,\n type SourceFile,\n type Statement,\n type StringLiteralLikeNode,\n SyntaxKind,\n type VariableDeclaration,\n} from \"typescript/unstable/ast\";\nimport {\n isAccessorDeclaration,\n isArrowFunction,\n isBinaryExpression,\n isBindingElement,\n isBlock,\n isBreakOrContinueStatement,\n isCallExpression,\n isCallOrNewExpression,\n isCaseClause,\n isClassDeclaration,\n isClassLikeDeclaration,\n isComputedPropertyName,\n isConditionalExpression,\n isConstructorDeclaration,\n isDefaultClause,\n isElementAccessExpression,\n isExportDeclaration,\n isExpressionWithTypeArguments,\n isFunctionDeclaration,\n isFunctionLikeDeclaration,\n isHeritageClause,\n isIdentifier,\n isIfStatement,\n isImportDeclaration,\n isInterfaceDeclaration,\n isJSDoc,\n isJsxAttribute,\n isJsxAttributes,\n isJsxSpreadAttribute,\n isMethodDeclaration,\n isModuleBlock,\n isNamedExports,\n isNumericLiteral,\n isNumericOrStringLikeLiteral,\n isObjectBindingPattern,\n isObjectLiteralExpression,\n isParenthesizedExpression,\n isPrefixUnaryExpression,\n isPropertyAccessExpression,\n isPropertyAssignment,\n isPropertyDeclaration,\n isReturnStatement,\n isShorthandPropertyAssignment,\n isSourceFile,\n isSpreadAssignment,\n isStringLiteralLikeNode,\n isThrowStatement,\n isTypeNode,\n isVariableDeclaration,\n} from \"typescript/unstable/ast/is\";\nimport {\n API,\n SymbolFlags,\n type Checker as TypeScriptChecker,\n type Project as TypeScriptProject,\n type Symbol as TypeScriptSymbol,\n type Type,\n} from \"typescript/unstable/sync\";\n\nimport { language, t } from \"./i18n\";\nimport type { Project } from \"./project\";\nimport { parseVersion, versionAtLeast } from \"./version\";\ninterface Requirements {\n apiLevel: number;\n iOS: readonly number[];\n}\n\ntype Kind = keyof Requirements;\n\ntype Requirement = Partial<Requirements>;\n\ninterface Rule<Value> {\n readonly parse: (text: string) => Value | undefined;\n readonly covers: (value: Value, needed: Value) => boolean;\n readonly describe: (value: Value) => string;\n}\n\nconst requirements: { readonly [K in Kind]: Rule<Requirements[K]> } = {\n apiLevel: {\n parse: (text) => (/^[1-9]\\d*$/.test(text) ? Number(text) : undefined),\n covers: (level, needed) => level >= needed,\n describe: (level) => t(\"availability.apiLevel\", { level }),\n },\n iOS: {\n parse: parseVersion,\n covers: versionAtLeast,\n describe: (version) => `iOS ${version.join(\".\")}`,\n },\n};\n\nconst isKind = (name: string): name is Kind =>\n Object.hasOwn(requirements, name);\n\nconst kindsOf = (requirement: Requirement) =>\n Object.keys(requirement).filter(isKind);\n\nconst parseKind = <K extends Kind>(\n kind: K,\n text: string,\n): Requirement | undefined => {\n const value = requirements[kind].parse(text);\n if (value === undefined) {\n return undefined;\n }\n const requirement: Requirement = {};\n requirement[kind] = value;\n return requirement;\n};\n\nconst lists = new Intl.ListFormat(language, { type: \"conjunction\" });\n\nconst mergeKind = <K extends Kind>(\n into: Requirement,\n from: Requirement,\n kind: K,\n) => {\n const needed = from[kind];\n const current = into[kind];\n if (\n needed !== undefined &&\n (current === undefined || !requirements[kind].covers(current, needed))\n ) {\n into[kind] = needed;\n }\n};\n\nconst merge = (into: Requirement, from: Requirement) => {\n for (const kind of kindsOf(from)) {\n mergeKind(into, from, kind);\n }\n return into;\n};\n\ntype Coverage = <K extends Kind>(kind: K, needed: Requirements[K]) => boolean;\n\nconst unmet = (needed: Requirement, covered: Coverage) => {\n const missing = kindsOf(needed).flatMap(<K extends Kind>(kind: K) => {\n const value = needed[kind];\n return value === undefined || covered(kind, value)\n ? []\n : [requirements[kind].describe(value)];\n });\n return missing.length > 0 ? lists.format(missing) : undefined;\n};\n\ninterface Annotation {\n readonly requirement: Requirement;\n readonly invalid?: string;\n readonly repeated?: Kind;\n}\n\nfunction parseAnnotation(text: string): Annotation {\n const requirement: Requirement = {};\n for (const entry of text.split(\",\").map((part) => part.trim())) {\n const [kind = \"\", value = \"\", ...rest] = entry.split(/\\s+/);\n const parsed =\n rest.length === 0 && isKind(kind) ? parseKind(kind, value) : undefined;\n if (parsed === undefined) {\n return { requirement, invalid: entry };\n }\n const repeated = kindsOf(parsed).find(\n (name) => requirement[name] !== undefined,\n );\n if (repeated !== undefined) {\n return { requirement, repeated };\n }\n Object.assign(requirement, parsed);\n }\n return { requirement };\n}\n\nconst tagText = (tag: JSDocTag) =>\n (tag.comment ?? []).map((part) => part.text).join(\"\");\n\nconst annotationTags = (node: Node) =>\n (node.jsDoc ?? [])\n .filter(isJSDoc)\n .flatMap((comment) =>\n (comment.tags ?? []).filter((tag) => tag.tagName.text === \"available\"),\n );\n\nconst exits = (statement: Statement): boolean => {\n if (\n isReturnStatement(statement) ||\n isThrowStatement(statement) ||\n isBreakOrContinueStatement(statement)\n ) {\n return true;\n }\n const last = isBlock(statement) ? statement.statements.at(-1) : undefined;\n return last !== undefined && exits(last);\n};\n\nconst hasModifier = (node: ModifiersBase, kind: SyntaxKind) =>\n node.modifiers?.some((modifier) => modifier.kind === kind) ?? false;\n\nconst statementsOf = (node: Node): readonly Statement[] =>\n isBlock(node) ||\n isSourceFile(node) ||\n isModuleBlock(node) ||\n isCaseClause(node) ||\n isDefaultClause(node)\n ? node.statements\n : [];\n\nconst isNameOf = (node: Node) =>\n \"name\" in node.parent && node.parent.name === node;\n\nconst isPropertyNameOf = (node: Node) =>\n \"propertyName\" in node.parent && node.parent.propertyName === node;\n\nconst isObjectMember = (node: Node) =>\n isPropertyAssignment(node) ||\n isShorthandPropertyAssignment(node) ||\n isMethodDeclaration(node) ||\n isAccessorDeclaration(node);\n\nconst isValueHolder = (node: Node) =>\n isVariableDeclaration(node) ||\n isPropertyDeclaration(node) ||\n isPropertyAssignment(node);\n\ntype Annotated =\n | FunctionLikeDeclaration\n | ClassLikeDeclaration\n | VariableDeclaration\n | PropertyDeclaration\n | PropertyAssignment;\n\nconst writtenName = (member: ObjectLiteralElementLike) => {\n if (isSpreadAssignment(member)) {\n return undefined;\n }\n const { name } = member;\n if (isComputedPropertyName(name)) {\n return isNumericOrStringLikeLiteral(name.expression)\n ? name.expression.text\n : undefined;\n }\n return name.text;\n};\n\nconst constituentsOf = (type: Type) =>\n type.isUnionType() ||\n type.isIntersectionType() ||\n type.isTemplateLiteralType()\n ? type.getTypes()\n : [];\n\nconst literals = new Set([\n SyntaxKind.ObjectLiteralExpression,\n SyntaxKind.ArrayLiteralExpression,\n SyntaxKind.ArrowFunction,\n SyntaxKind.FunctionExpression,\n SyntaxKind.StringLiteral,\n SyntaxKind.NumericLiteral,\n SyntaxKind.NoSubstitutionTemplateLiteral,\n SyntaxKind.TemplateExpression,\n SyntaxKind.TrueKeyword,\n SyntaxKind.FalseKeyword,\n SyntaxKind.NullKeyword,\n SyntaxKind.SpreadElement,\n]);\n\nconst inert = new Set([\n SyntaxKind.ImportDeclaration,\n SyntaxKind.ExportDeclaration,\n SyntaxKind.InterfaceDeclaration,\n SyntaxKind.TypeAliasDeclaration,\n SyntaxKind.JsxClosingElement,\n]);\n\nfunction sourceFilesOf(root: string, metafiles: readonly Metafile[]) {\n const files = new Set<string>();\n for (const metafile of metafiles) {\n for (const input of Object.keys(metafile.inputs)) {\n const file = path.resolve(input);\n if (\n !/^[a-z][\\w-]+:/.test(input) &&\n /\\.[cm]?[jt]sx?$/.test(file) &&\n !path.relative(root, file).startsWith(\"..\") &&\n !file.split(path.sep).includes(\"node_modules\")\n ) {\n files.add(fs.realpathSync(file));\n }\n }\n }\n return [...files];\n}\n\ninterface Problems {\n readonly lines: Set<string>;\n guarding: boolean;\n}\n\nexport class AvailabilityChecker {\n #api: API | undefined;\n #open = new Set<string>();\n\n check(project: Project, metafiles: readonly Metafile[]) {\n const files = sourceFilesOf(project.root, metafiles);\n if (files.length === 0 && this.#open.size === 0) {\n return;\n }\n this.#api ??= new API({ cwd: project.root });\n // An open file keeps the content it was opened with, whatever fileChanges says\n // (typescript 7.0.2).\n if (this.#open.size > 0) {\n this.#api.updateSnapshot({ closeFiles: [...this.#open] });\n }\n const snapshot = this.#api.updateSnapshot({\n openFiles: files,\n fileChanges: { invalidateAll: true },\n });\n this.#open = new Set(files);\n if (files.length === 0) {\n return;\n }\n const problems: Problems = { lines: new Set(), guarding: false };\n const groups = Map.groupBy(files, (file) => {\n const typescript = snapshot.getDefaultProjectForFile(file);\n if (typescript === undefined) {\n throw new Error(`no TypeScript project contains ${file}`);\n }\n return typescript;\n });\n for (const [typescript, owned] of groups) {\n new Checker(typescript, project, files, problems).check(owned);\n }\n if (problems.lines.size > 0) {\n throw new Error(\n [\n ...problems.lines,\n ...(problems.guarding ? [t(\"availability.advice\")] : []),\n ].join(\"\\n\"),\n );\n }\n }\n\n close() {\n this.#api?.close();\n }\n}\n\nclass Checker {\n #project: TypeScriptProject;\n #checker: TypeScriptChecker;\n #root: string;\n #files: Set<string>;\n #problems: Problems;\n #minimum: Requirement;\n #entries: Set<string>;\n #available: number | undefined;\n #symbols = new Map<Node, TypeScriptSymbol | undefined>();\n #imports = new Set<Node>();\n #requirements = new Map<number, Requirement>();\n #annotations = new Map<Node, Requirement>();\n #facts: [Map<Node, Requirement>, Map<Node, Requirement>] = [\n new Map(),\n new Map(),\n ];\n #types = new Map<Node, Type | undefined>();\n #annotated = new Map<number, TypeScriptSymbol[]>();\n\n constructor(\n typescript: TypeScriptProject,\n project: Project,\n files: readonly string[],\n problems: Problems,\n ) {\n this.#project = typescript;\n this.#checker = typescript.checker;\n this.#root = project.root;\n this.#files = new Set(files);\n this.#problems = problems;\n this.#minimum = {\n apiLevel: project.config.minimumAPILevel ?? project.apiLevel,\n iOS: parseVersion(\n project.config.minimumIOSVersion ?? project.minimumIOSVersion,\n ),\n };\n this.#entries = new Set(\n [project.app, project.extension]\n .filter((entry) => entry !== undefined)\n .map((entry) => fs.realpathSync(entry)),\n );\n this.#available = this.#availableSymbol(project.apiDirectory);\n }\n\n check(files: readonly string[]) {\n for (const file of files) {\n const source = this.#project.program.getSourceFile(file);\n if (source === undefined) {\n throw new Error(`the TypeScript program has no ${file}`);\n }\n const { identifiers, properties, values } = this.#collect(source);\n const symbols = this.#checker.getSymbolAtLocation(identifiers);\n for (const [index, node] of identifiers.entries()) {\n this.#use(\n node,\n isShorthandPropertyAssignment(node.parent)\n ? this.#checker.getShorthandAssignmentValueSymbol(node.parent)\n : symbols[index],\n node.text,\n );\n }\n for (const node of properties) {\n this.#use(node, this.#propertySymbol(node), node.text);\n }\n for (const node of values) {\n this.#useValue(node);\n }\n for (const statement of source.statements) {\n if (!isExportDeclaration(statement) || statement.isTypeOnly) {\n continue;\n }\n const { exportClause } = statement;\n const elements =\n exportClause !== undefined && isNamedExports(exportClause)\n ? exportClause.elements\n : undefined;\n const exported = (elements ?? []).filter(\n (specifier) => !specifier.isTypeOnly,\n );\n if (statement.moduleSpecifier === undefined) {\n for (const specifier of exported) {\n const local =\n this.#checker.getExportSpecifierLocalTargetSymbol(specifier);\n if (local !== undefined) {\n this.#useImport(local);\n }\n }\n } else if (exported.length > 0 || elements === undefined) {\n this.#importModule(statement);\n }\n }\n if (this.#entries.has(file)) {\n for (const statement of source.statements) {\n if (\n (isFunctionDeclaration(statement) ||\n isClassDeclaration(statement) ||\n isInterfaceDeclaration(statement)) &&\n statement.name !== undefined &&\n hasModifier(statement, SyntaxKind.DefaultKeyword)\n ) {\n this.#useEntry(statement.name);\n }\n }\n }\n }\n }\n\n #collect(source: SourceFile) {\n const identifiers: (Identifier | StringLiteralLikeNode)[] = [];\n const properties: (Identifier | StringLiteralLikeNode)[] = [];\n const values: Expression[] = [];\n const visit = (node: Node, checked: boolean) => {\n for (const tag of annotationTags(node)) {\n this.#parse(tagText(tag), tag);\n }\n const extended =\n isExpressionWithTypeArguments(node) &&\n isHeritageClause(node.parent) &&\n node.parent.token === SyntaxKind.ExtendsKeyword &&\n isClassLikeDeclaration(node.parent.parent);\n if (inert.has(node.kind) || (isTypeNode(node) && !extended)) {\n checked = false;\n }\n if (checked) {\n if (isCallOrNewExpression(node)) {\n values.push(\n ...(node.arguments ?? []).filter(\n (argument) => !literals.has(argument.kind),\n ),\n );\n } else if (isSpreadAssignment(node) || isJsxSpreadAttribute(node)) {\n values.push(node.expression);\n }\n }\n if (checked && isIdentifier(node)) {\n const { parent } = node;\n const property =\n isJsxAttribute(parent) ||\n (isObjectMember(parent) &&\n isObjectLiteralExpression(parent.parent) &&\n parent.name === node) ||\n (isBindingElement(parent) &&\n isObjectBindingPattern(parent.parent) &&\n (parent.propertyName ?? parent.name) === node);\n if (property) {\n properties.push(node);\n }\n if (\n isShorthandPropertyAssignment(parent) ||\n (!property &&\n !isPropertyNameOf(node) &&\n (!isNameOf(node) || isPropertyAccessExpression(parent)))\n ) {\n identifiers.push(node);\n }\n }\n if (checked && isStringLiteralLikeNode(node)) {\n const { parent } = node;\n const member = isComputedPropertyName(parent) ? parent.parent : parent;\n if (\n (isObjectMember(member) &&\n isObjectLiteralExpression(member.parent) &&\n (member.name === node || member.name === parent)) ||\n (isBindingElement(member) &&\n isObjectBindingPattern(member.parent) &&\n (member.propertyName === node || member.propertyName === parent))\n ) {\n properties.push(node);\n } else if (\n isElementAccessExpression(parent) &&\n parent.argumentExpression === node\n ) {\n identifiers.push(node);\n }\n }\n if (\n checked &&\n isObjectLiteralExpression(node) &&\n node.properties.some(\n (member) =>\n !isSpreadAssignment(member) &&\n isComputedPropertyName(member.name) &&\n !isStringLiteralLikeNode(member.name.expression),\n )\n ) {\n values.push(node);\n }\n node.forEachChild((child) => visit(child, checked));\n };\n source.forEachChild((child) => visit(child, true));\n return { identifiers, properties, values };\n }\n\n #useValue(node: Expression) {\n const expected = this.#checker.getContextualType(node);\n if (expected === undefined) {\n return;\n }\n let annotated = this.#annotated.get(expected.id);\n if (annotated === undefined) {\n const found = new Map<string, TypeScriptSymbol>();\n for (const candidate of [expected, ...constituentsOf(expected)]) {\n for (const property of this.#checker.getPropertiesOfType(candidate)) {\n if (Object.keys(this.#requirementOf(property)).length > 0) {\n found.set(property.name, property);\n }\n }\n }\n annotated = [...found.values()];\n this.#annotated.set(expected.id, annotated);\n }\n const type =\n annotated.length > 0 ? this.#checker.getTypeAtLocation(node) : undefined;\n if (type === undefined) {\n return;\n }\n const named = new Set(\n (isObjectLiteralExpression(node) ? node.properties : []).map(writtenName),\n );\n for (const property of annotated) {\n if (\n !named.has(property.name) &&\n this.#checker.getPropertyOfType(type, property.name) !== undefined\n ) {\n this.#use(node, property, property.name);\n }\n }\n }\n\n #use(node: Node, symbol: TypeScriptSymbol | undefined, name: string) {\n if (symbol === undefined) {\n return;\n }\n this.#useImport(symbol);\n const requirement = unmet(this.#requirementOf(symbol), (kind, needed) =>\n this.#covered(kind, needed, node),\n );\n if (requirement !== undefined) {\n this.#problems.guarding = true;\n this.#problems.lines.add(\n t(\"availability.needs\", {\n location: this.#location(node),\n name,\n requirement,\n }),\n );\n }\n }\n\n #useImport(symbol: TypeScriptSymbol) {\n let declaration =\n symbol.flags & SymbolFlags.Alias\n ? symbol.declarations.at(0)?.resolve(this.#project)\n : undefined;\n while (declaration !== undefined && !isImportDeclaration(declaration)) {\n declaration = isSourceFile(declaration) ? undefined : declaration.parent;\n }\n if (declaration !== undefined) {\n this.#importModule(declaration);\n }\n }\n\n #importModule(declaration: ImportDeclaration | ExportDeclaration) {\n const name = declaration.moduleSpecifier;\n if (\n this.#imports.has(declaration) ||\n name === undefined ||\n !isStringLiteralLikeNode(name)\n ) {\n return;\n }\n this.#imports.add(declaration);\n const module = this.#checker\n .getSymbolAtLocation(name)\n ?.declarations.at(0)\n ?.resolve(this.#project);\n if (\n module === undefined ||\n !isSourceFile(module) ||\n this.#files.has(module.fileName)\n ) {\n return;\n }\n const requirement = unmet(this.#moduleRequirement(module), (kind, needed) =>\n this.#meetsMinimum(kind, needed),\n );\n if (requirement !== undefined) {\n this.#problems.lines.add(\n t(\"availability.importNeeds\", {\n location: this.#location(name),\n name: name.text,\n requirement,\n }),\n );\n }\n }\n\n #moduleRequirement(source: SourceFile) {\n const requirement: Requirement = {};\n const first = source.statements.at(0);\n if (first !== undefined && isImportDeclaration(first)) {\n for (const tag of annotationTags(first)) {\n merge(requirement, this.#parse(tagText(tag), tag));\n }\n }\n return requirement;\n }\n\n #useEntry(name: Identifier) {\n const symbol = this.#checker.getSymbolAtLocation(name);\n const requirement = unmet(\n symbol === undefined ? {} : this.#requirementOf(symbol),\n (kind, needed) => this.#meetsMinimum(kind, needed),\n );\n if (requirement !== undefined) {\n this.#problems.lines.add(\n t(\"availability.entryNeeds\", {\n location: this.#location(name),\n name: name.text,\n requirement,\n }),\n );\n }\n }\n\n #location(node: Node) {\n const source = sourceFileOf(node);\n const { line, character } = source.getLineAndCharacterOfPosition(\n node.getStart(source),\n );\n return `${path.relative(this.#root, source.fileName)}:${line + 1}:${character + 1}`;\n }\n\n #parse(text: string, node: Node) {\n const { requirement, invalid, repeated } = parseAnnotation(text);\n if (invalid !== undefined) {\n this.#problems.lines.add(\n t(\"availability.invalidEntry\", {\n location: this.#location(node),\n entry: invalid,\n }),\n );\n } else if (repeated !== undefined) {\n this.#problems.lines.add(\n t(\"availability.repeatedEntry\", {\n location: this.#location(node),\n kind: repeated,\n }),\n );\n }\n return requirement;\n }\n\n #target(symbol: TypeScriptSymbol) {\n return symbol.flags & SymbolFlags.Alias\n ? this.#checker.getAliasedSymbol(symbol)\n : symbol;\n }\n\n #symbolOf(node: Node) {\n if (!this.#symbols.has(node)) {\n const symbol = this.#checker.getSymbolAtLocation(node);\n this.#symbols.set(\n node,\n symbol === undefined ? undefined : this.#target(symbol),\n );\n }\n return this.#symbols.get(node);\n }\n\n #requirementOf(symbol: TypeScriptSymbol) {\n const target = this.#target(symbol);\n let requirement = this.#requirements.get(target.id);\n if (requirement === undefined) {\n requirement = {};\n const declaration = (\n target.valueDeclaration ?? target.declarations.at(0)\n )?.resolve(this.#project);\n const external =\n declaration !== undefined &&\n !this.#files.has(sourceFileOf(declaration).fileName);\n for (const tag of this.#checker.getJsDocTagsOfSymbol(target)) {\n if (tag.name === \"available\") {\n merge(\n requirement,\n external\n ? this.#parse(tag.text ?? \"\", declaration)\n : parseAnnotation(tag.text ?? \"\").requirement,\n );\n }\n }\n if (external) {\n merge(requirement, this.#moduleRequirement(sourceFileOf(declaration)));\n }\n this.#requirements.set(target.id, requirement);\n }\n return requirement;\n }\n\n #annotationOf(node: Annotated) {\n let requirement = this.#annotations.get(node);\n if (requirement === undefined) {\n requirement = {};\n const name =\n isArrowFunction(node) || isConstructorDeclaration(node)\n ? undefined\n : node.name;\n const symbol =\n name !== undefined && isIdentifier(name)\n ? this.#checker.getSymbolAtLocation(name)\n : undefined;\n if (symbol !== undefined) {\n merge(requirement, this.#requirementOf(symbol));\n }\n for (const tag of annotationTags(node)) {\n merge(requirement, parseAnnotation(tagText(tag)).requirement);\n }\n this.#annotations.set(node, requirement);\n }\n return requirement;\n }\n\n #propertySymbol(name: Identifier | StringLiteralLikeNode) {\n const member = isComputedPropertyName(name.parent)\n ? name.parent.parent\n : name.parent;\n const container = member.parent;\n if (!this.#types.has(container)) {\n this.#types.set(\n container,\n isObjectBindingPattern(container)\n ? this.#checker.getTypeAtLocation(container)\n : isObjectLiteralExpression(container) || isJsxAttributes(container)\n ? this.#checker.getContextualType(container)\n : undefined,\n );\n }\n const type = this.#types.get(container);\n if (type === undefined) {\n return undefined;\n }\n for (const candidate of [type, ...constituentsOf(type)]) {\n const property = this.#checker.getPropertyOfType(candidate, name.text);\n if (property !== undefined) {\n return property;\n }\n }\n return undefined;\n }\n\n #meetsMinimum<K extends Kind>(kind: K, needed: Requirements[K]) {\n const minimum = this.#minimum[kind];\n return minimum !== undefined && requirements[kind].covers(minimum, needed);\n }\n\n #covered<K extends Kind>(kind: K, needed: Requirements[K], reference: Node) {\n if (this.#meetsMinimum(kind, needed)) {\n return true;\n }\n const { covers } = requirements[kind];\n let crossed = false;\n for (let child = reference; !isSourceFile(child); child = child.parent) {\n const { parent } = child;\n const proven = this.#provenBy(parent, child, crossed)[kind];\n if (proven !== undefined && covers(proven, needed)) {\n return true;\n }\n crossed ||= isFunctionLikeDeclaration(parent);\n }\n return false;\n }\n\n #provenBy(parent: Node, child: Node, crossed: boolean) {\n const proven: Requirement = {};\n if (isIfStatement(parent)) {\n if (child === parent.thenStatement) {\n merge(proven, this.#factsOf(parent.expression, true));\n } else if (child === parent.elseStatement) {\n merge(proven, this.#factsOf(parent.expression, false));\n }\n } else if (isConditionalExpression(parent)) {\n if (child === parent.whenTrue) {\n merge(proven, this.#factsOf(parent.condition, true));\n } else if (child === parent.whenFalse) {\n merge(proven, this.#factsOf(parent.condition, false));\n }\n } else if (isBinaryExpression(parent) && child === parent.right) {\n const operator = parent.operatorToken.kind;\n if (operator === SyntaxKind.AmpersandAmpersandToken) {\n merge(proven, this.#factsOf(parent.left, true));\n } else if (operator === SyntaxKind.BarBarToken) {\n merge(proven, this.#factsOf(parent.left, false));\n }\n }\n for (const statement of statementsOf(parent)) {\n if (statement === child) {\n break;\n }\n if (\n isIfStatement(statement) &&\n statement.elseStatement === undefined &&\n exits(statement.thenStatement)\n ) {\n merge(proven, this.#factsOf(statement.expression, false));\n }\n }\n if (\n isFunctionLikeDeclaration(parent) ||\n (isClassLikeDeclaration(parent) &&\n (crossed ||\n (isPropertyDeclaration(child) &&\n !hasModifier(child, SyntaxKind.StaticKeyword)))) ||\n (isValueHolder(parent) && crossed && child === parent.initializer)\n ) {\n merge(proven, this.#annotationOf(parent));\n }\n return proven;\n }\n\n #factsOf(node: Expression, outcome: boolean) {\n const cache = this.#facts[Number(outcome)];\n let facts = cache.get(node);\n if (facts === undefined) {\n cache.set(node, {});\n facts = this.#computeFacts(node, outcome);\n cache.set(node, facts);\n }\n return facts;\n }\n\n #computeFacts(node: Expression, outcome: boolean): Requirement {\n if (isIdentifier(node)) {\n const value = this.#constant(node);\n return value === node ? {} : this.#factsOf(value, outcome);\n }\n if (isParenthesizedExpression(node)) {\n return this.#factsOf(node.expression, outcome);\n }\n if (isPrefixUnaryExpression(node)) {\n return node.operator === SyntaxKind.ExclamationToken\n ? this.#factsOf(node.operand, !outcome)\n : {};\n }\n if (isCallExpression(node)) {\n return outcome && this.#isAvailable(node.expression)\n ? this.#requirementsOf(node.arguments.at(0))\n : {};\n }\n if (isBinaryExpression(node)) {\n const operator = node.operatorToken.kind;\n if (operator === SyntaxKind.AmpersandAmpersandToken) {\n return outcome\n ? merge(\n merge({}, this.#factsOf(node.left, true)),\n this.#factsOf(node.right, true),\n )\n : {};\n }\n if (operator === SyntaxKind.BarBarToken) {\n return outcome\n ? {}\n : merge(\n merge({}, this.#factsOf(node.left, false)),\n this.#factsOf(node.right, false),\n );\n }\n }\n return {};\n }\n\n #constant(node: Expression) {\n for (const seen = new Set<Node>(); isIdentifier(node);) {\n const declaration = this.#symbolOf(node)?.valueDeclaration?.resolve(\n this.#project,\n );\n if (\n declaration === undefined ||\n !isVariableDeclaration(declaration) ||\n declaration.initializer === undefined ||\n !(declaration.parent.flags & NodeFlags.Const) ||\n seen.has(declaration)\n ) {\n break;\n }\n seen.add(declaration);\n node = declaration.initializer;\n }\n return node;\n }\n\n #isAvailable(node: Expression) {\n const name = isPropertyAccessExpression(node) ? node.name : node;\n return (\n this.#available !== undefined &&\n isIdentifier(name) &&\n this.#symbolOf(name)?.id === this.#available\n );\n }\n\n #requirementsOf(argument: Expression | undefined) {\n const proven: Requirement = {};\n for (const property of argument !== undefined &&\n isObjectLiteralExpression(argument)\n ? argument.properties\n : []) {\n if (\n !isPropertyAssignment(property) ||\n isComputedPropertyName(property.name)\n ) {\n continue;\n }\n const kind = property.name.text;\n if (!isKind(kind)) {\n continue;\n }\n const value = this.#constant(property.initializer);\n const parsed = isNumericLiteral(value)\n ? parseKind(kind, String(Number(value.text)))\n : undefined;\n if (parsed !== undefined) {\n Object.assign(proven, parsed);\n }\n }\n return proven;\n }\n\n #availableSymbol(apiDirectory: string) {\n const source = this.#project.program.getSourceFile(\n fs.realpathSync(path.join(apiDirectory, \"index.d.ts\")),\n );\n const name = source?.statements\n .filter(isFunctionDeclaration)\n .map((statement) => statement.name)\n .find((name) => name?.text === \"available\");\n return name === undefined\n ? undefined\n : this.#checker.getSymbolAtLocation(name)?.id;\n }\n}\n\nfunction sourceFileOf(node: Node) {\n while (!isSourceFile(node)) {\n node = node.parent;\n }\n return node;\n}\n"],"mappings":";;;;;;;;AAsGA,MAAM,eAAgE;CACpE,UAAU;EACR,QAAQ,SAAU,aAAa,KAAK,IAAI,IAAI,OAAO,IAAI,IAAI,KAAA;EAC3D,SAAS,OAAO,WAAW,SAAS;EACpC,WAAW,UAAU,EAAE,yBAAyB,EAAE,MAAM,CAAC;CAC3D;CACA,KAAK;EACH,OAAO;EACP,QAAQ;EACR,WAAW,YAAY,OAAO,QAAQ,KAAK,GAAG;CAChD;AACF;AAEA,MAAM,UAAU,SACd,OAAO,OAAO,cAAc,IAAI;AAElC,MAAM,WAAW,gBACf,OAAO,KAAK,WAAW,CAAC,CAAC,OAAO,MAAM;AAExC,MAAM,aACJ,MACA,SAC4B;CAC5B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O,SAAS,KAAK;GAC3B,IAAI,CAAC,OAAO,IAAI,GACd;GAEF,MAAM,QAAQ,KAAK,UAAU,SAAS,WAAW;GACjD,MAAM,SAAS,iBAAiB,KAAK,IACjC,UAAU,MAAM,OAAO,OAAO,MAAM,IAAI,CAAC,CAAC,IAC1C,KAAA;GACJ,IAAI,WAAW,KAAA,GACb,OAAO,OAAO,QAAQ,MAAM;EAEhC;EACA,OAAO;CACT;CAEA,iBAAiB,cAAsB;EAIrC,MAAM,OAHS,KAAK,SAAS,QAAQ,cACnC,GAAG,aAAa,KAAK,KAAK,cAAc,YAAY,CAAC,CAErC,CAAC,EAAE,WAClB,OAAO,qBAAqB,CAAC,CAC7B,KAAK,cAAc,UAAU,IAAI,CAAC,CAClC,MAAM,SAAS,MAAM,SAAS,WAAW;EAC5C,OAAO,SAAS,KAAA,IACZ,KAAA,IACA,KAAK,SAAS,oBAAoB,IAAI,CAAC,EAAE;CAC/C;AACF;AAEA,SAAS,aAAa,MAAY;CAChC,OAAO,CAAC,aAAa,IAAI,GACvB,OAAO,KAAK;CAEd,OAAO;AACT"}
|
package/dist/cli/cli.js
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
import { Code, RpcError, UsageError } from "../client.js";
|
|
2
2
|
import { withToken } from "../connection.js";
|
|
3
|
-
import {
|
|
4
|
-
import { FalseResult } from "../output.js";
|
|
3
|
+
import { t } from "../i18n.js";
|
|
4
|
+
import { FalseResult, errorMessage } from "../output.js";
|
|
5
5
|
import { root } from "./commands/index.js";
|
|
6
6
|
import { parseArgs } from "node:util";
|
|
7
7
|
// src/cli/cli.ts
|
|
8
8
|
const globalOptions = { help: {
|
|
9
9
|
type: "boolean",
|
|
10
10
|
short: "h",
|
|
11
|
-
help:
|
|
11
|
+
help: t("cli.help")
|
|
12
12
|
} };
|
|
13
|
-
const parseOptions = (options) => Object.fromEntries(Object.entries(options
|
|
13
|
+
const parseOptions = (options = {}) => Object.fromEntries(Object.entries(options).map(([name, option]) => [name, {
|
|
14
14
|
type: option.type,
|
|
15
15
|
...option.short ? { short: option.short } : {}
|
|
16
16
|
}]));
|
|
17
|
-
function allOptions(command
|
|
18
|
-
Object.assign(
|
|
19
|
-
for (const child of command.commands ?? []) allOptions(child, collected);
|
|
20
|
-
return collected;
|
|
17
|
+
function allOptions(command) {
|
|
18
|
+
return Object.assign(parseOptions(command.options), ..."commands" in command ? command.commands.map(allOptions) : []);
|
|
21
19
|
}
|
|
22
20
|
function usage(trail) {
|
|
23
|
-
const command = trail.
|
|
21
|
+
const command = trail[trail.length - 1];
|
|
24
22
|
const name = trail.map((it) => it.name).join(" ");
|
|
25
23
|
const lines = [command.short, ""];
|
|
26
|
-
if (command
|
|
27
|
-
lines.push(
|
|
24
|
+
if ("commands" in command) {
|
|
25
|
+
lines.push(t("cli.usage", { usage: `${name} COMMAND` }), "", t("cli.commands"));
|
|
28
26
|
lines.push(...columns(command.commands.map((child) => [` ${child.use ?? child.name}`, child.short])).split("\n"));
|
|
29
|
-
} else lines.push(
|
|
27
|
+
} else lines.push(t("cli.usage", { usage: `${trail.slice(0, -1).map((it) => it.name).join(" ")} ${command.use ?? command.name}`.replace(/ +/g, " ") }));
|
|
30
28
|
if (command.description) lines.push("", ...command.description);
|
|
31
29
|
const options = {
|
|
32
30
|
...trail.reduce((found, it) => ({
|
|
@@ -35,7 +33,7 @@ function usage(trail) {
|
|
|
35
33
|
}), {}),
|
|
36
34
|
...globalOptions
|
|
37
35
|
};
|
|
38
|
-
lines.push("",
|
|
36
|
+
lines.push("", t("cli.options"));
|
|
39
37
|
lines.push(...columns(Object.entries(options).map(([option, it]) => [` ${it.short ? `-${it.short}, ` : ""}--${option}${it.value ? ` ${it.value}` : ""}`, it.help])).split("\n"));
|
|
40
38
|
return lines.join("\n");
|
|
41
39
|
}
|
|
@@ -56,28 +54,26 @@ function resolve(argv) {
|
|
|
56
54
|
});
|
|
57
55
|
const positionals = loose.tokens.filter((token) => token.kind === "positional");
|
|
58
56
|
const trail = [root];
|
|
57
|
+
let current = root;
|
|
59
58
|
let consumed = 0;
|
|
60
59
|
let help = positionals[0]?.value === "help";
|
|
61
60
|
if (help) consumed++;
|
|
62
|
-
while (
|
|
63
|
-
const current = trail.at(-1);
|
|
61
|
+
while ("commands" in current) {
|
|
64
62
|
const word = positionals[consumed]?.value;
|
|
65
63
|
if (word === void 0) {
|
|
66
|
-
if (help || loose.values.help || current !== root || argv.length === 0) return {
|
|
67
|
-
|
|
68
|
-
help: true
|
|
69
|
-
};
|
|
70
|
-
throw new UsageError(tr("A command is missing."));
|
|
64
|
+
if (help || loose.values.help || current !== root || argv.length === 0) return { trail };
|
|
65
|
+
throw new UsageError(t("cli.missingCommand"));
|
|
71
66
|
}
|
|
72
67
|
const found = current.commands.find((it) => it.name === word);
|
|
73
|
-
if (!found) throw new UsageError(
|
|
68
|
+
if (!found) throw new UsageError(t("cli.unknownCommand", {
|
|
74
69
|
name: JSON.stringify(word),
|
|
75
70
|
parent: JSON.stringify(trail.map((it) => it.name).join(" "))
|
|
76
71
|
}));
|
|
77
72
|
trail.push(found);
|
|
73
|
+
current = found;
|
|
78
74
|
consumed++;
|
|
79
75
|
}
|
|
80
|
-
const command =
|
|
76
|
+
const command = current;
|
|
81
77
|
const options = trail.reduce((found, it) => ({
|
|
82
78
|
...found,
|
|
83
79
|
...it.options
|
|
@@ -96,66 +92,58 @@ function resolve(argv) {
|
|
|
96
92
|
strict: true
|
|
97
93
|
});
|
|
98
94
|
} catch (error) {
|
|
99
|
-
const
|
|
100
|
-
|
|
95
|
+
const message = errorMessage(error);
|
|
96
|
+
const option = message.match(/^Unknown option '(-[^']*)'/)?.[1];
|
|
97
|
+
throw new UsageError(option === void 0 ? message : t("cli.unknownOption", {
|
|
101
98
|
option,
|
|
102
99
|
command: JSON.stringify(trail.map((it) => it.name).join(" "))
|
|
103
100
|
}));
|
|
104
101
|
}
|
|
105
|
-
if (parsed.values.help)
|
|
102
|
+
if (help || parsed.values.help) return { trail };
|
|
106
103
|
const args = [...parsed.positionals.slice(consumed), ...argv.slice(verbatim)];
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
count: least,
|
|
120
|
-
received: args.length
|
|
121
|
-
}) : tr({
|
|
122
|
-
one: "accepts between {least} and {count} arg, received {received}",
|
|
123
|
-
other: "accepts between {least} and {count} args, received {received}"
|
|
124
|
-
}, {
|
|
125
|
-
least,
|
|
126
|
-
count: most,
|
|
127
|
-
received: args.length
|
|
128
|
-
}));
|
|
129
|
-
}
|
|
104
|
+
const [least, most] = command.args;
|
|
105
|
+
if (args.length < least || args.length > most) throw new UsageError(least === most ? t("cli.exactArgs", {
|
|
106
|
+
count: least,
|
|
107
|
+
received: args.length
|
|
108
|
+
}) : most === Infinity ? t("cli.minimumArgs", {
|
|
109
|
+
count: least,
|
|
110
|
+
received: args.length
|
|
111
|
+
}) : t("cli.rangeArgs", {
|
|
112
|
+
least,
|
|
113
|
+
count: most,
|
|
114
|
+
received: args.length
|
|
115
|
+
}));
|
|
130
116
|
return {
|
|
131
117
|
trail,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
118
|
+
invocation: {
|
|
119
|
+
command,
|
|
120
|
+
args,
|
|
121
|
+
options: parsed.values
|
|
122
|
+
}
|
|
135
123
|
};
|
|
136
124
|
}
|
|
137
125
|
function printError(error, target, operation) {
|
|
138
126
|
let exit = 1;
|
|
139
|
-
let message = error
|
|
127
|
+
let message = errorMessage(error);
|
|
140
128
|
if (error instanceof UsageError) exit = 2;
|
|
141
129
|
else if (error instanceof RpcError) switch (error.code) {
|
|
142
130
|
case Code.Unavailable:
|
|
143
131
|
exit = 5;
|
|
144
|
-
message =
|
|
132
|
+
message = t("cli.unreachable", {
|
|
145
133
|
url: target.url,
|
|
146
134
|
message
|
|
147
135
|
});
|
|
148
136
|
break;
|
|
149
137
|
case Code.Unauthenticated:
|
|
150
|
-
message =
|
|
138
|
+
message = t("cli.unauthenticated", {
|
|
151
139
|
message,
|
|
152
140
|
url: withToken(target.url)
|
|
153
141
|
});
|
|
154
142
|
break;
|
|
155
|
-
case Code.Unimplemented: message =
|
|
143
|
+
case Code.Unimplemented: message = t("cli.unimplemented", { url: target.url });
|
|
156
144
|
}
|
|
157
|
-
console.error(
|
|
158
|
-
if (exit === 2) console.error(
|
|
145
|
+
console.error(t("error", { message: operation === void 0 ? message : `${operation}: ${message}` }));
|
|
146
|
+
if (exit === 2) console.error(t("cli.helpHint"));
|
|
159
147
|
return exit;
|
|
160
148
|
}
|
|
161
149
|
async function main() {
|
|
@@ -165,23 +153,21 @@ async function main() {
|
|
|
165
153
|
process.once("SIGTERM", interrupted);
|
|
166
154
|
const target = { url: "" };
|
|
167
155
|
try {
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
170
|
-
console.log(usage(
|
|
156
|
+
const { trail, invocation } = resolve(process.argv.slice(2));
|
|
157
|
+
if (!invocation) {
|
|
158
|
+
console.log(usage(trail));
|
|
171
159
|
return;
|
|
172
160
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
args: resolved.args,
|
|
177
|
-
options: values,
|
|
161
|
+
await invocation.command.run({
|
|
162
|
+
args: invocation.args,
|
|
163
|
+
options: invocation.options,
|
|
178
164
|
target,
|
|
179
165
|
signal: interrupt.signal,
|
|
180
166
|
printError: (error, operation) => printError(error, target, operation)
|
|
181
167
|
});
|
|
182
168
|
} catch (error) {
|
|
183
169
|
if (error instanceof FalseResult) process.exitCode = 1;
|
|
184
|
-
else if (interrupt.signal.aborted || error.name === "ExitPromptError") process.exitCode = 130;
|
|
170
|
+
else if (interrupt.signal.aborted || error instanceof Error && error.name === "ExitPromptError") process.exitCode = 130;
|
|
185
171
|
else process.exitCode = printError(error, target);
|
|
186
172
|
} finally {
|
|
187
173
|
process.off("SIGINT", interrupted);
|
package/dist/cli/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":["connection.withToken"],"sources":["../../src/cli/cli.ts"],"sourcesContent":["import { parseArgs } from \"node:util\";\n\nimport { Code, RpcError, UsageError } from \"../client\";\nimport * as connection from \"../connection\";\nimport { tr } from \"../i18n\";\nimport { FalseResult } from \"../output\";\nimport type { Command, Options } from \"./command\";\nimport { root } from \"./commands\";\n\nconst globalOptions: Options = {\n help: { type: \"boolean\", short: \"h\", help: tr(\"help\") },\n};\n\nconst parseOptions = (options: Options) =>\n Object.fromEntries(\n Object.entries(options ?? {}).map(([name, option]) => [\n name,\n { type: option.type, ...(option.short ? { short: option.short } : {}) },\n ]),\n );\n\nfunction allOptions(command: Command, collected = {}) {\n Object.assign(collected, parseOptions(command.options));\n for (const child of command.commands ?? []) {\n allOptions(child, collected);\n }\n return collected;\n}\n\nfunction usage(trail: Command[]) {\n const command = trail.at(-1);\n const name = trail.map((it) => it.name).join(\" \");\n const lines = [command.short, \"\"];\n if (command.commands) {\n lines.push(\n tr(\"usage: {usage}\", { usage: `${name} COMMAND` }),\n \"\",\n tr(\"commands:\"),\n );\n lines.push(\n ...columns(\n command.commands.map((child) => [\n ` ${child.use ?? child.name}`,\n child.short,\n ]),\n ).split(\"\\n\"),\n );\n } else {\n lines.push(\n tr(\"usage: {usage}\", {\n usage: `${trail\n .slice(0, -1)\n .map((it) => it.name)\n .join(\" \")} ${command.use ?? command.name}`.replace(/ +/g, \" \"),\n }),\n );\n }\n if (command.description) {\n lines.push(\"\", ...command.description);\n }\n const options: Options = {\n ...trail.reduce((found, it) => ({ ...found, ...it.options }), {}),\n ...globalOptions,\n };\n lines.push(\"\", tr(\"options:\"));\n lines.push(\n ...columns(\n Object.entries(options).map(([option, it]) => [\n ` ${it.short ? `-${it.short}, ` : \"\"}--${option}${it.value ? ` ${it.value}` : \"\"}`,\n it.help,\n ]),\n ).split(\"\\n\"),\n );\n return lines.join(\"\\n\");\n}\n\nfunction columns(rows) {\n const width = Math.max(...rows.map((row) => row[0].length));\n return rows.map((row) => `${row[0].padEnd(width + 2)}${row[1]}`).join(\"\\n\");\n}\n\nfunction resolve(argv) {\n const loose = parseArgs({\n args: argv,\n options: { ...parseOptions(globalOptions), ...allOptions(root) },\n allowPositionals: true,\n strict: false,\n tokens: true,\n });\n const positionals = loose.tokens.filter(\n (token) => token.kind === \"positional\",\n );\n const trail = [root];\n let consumed = 0;\n let help = positionals[0]?.value === \"help\";\n if (help) {\n consumed++;\n }\n while (trail.at(-1).commands) {\n const current = trail.at(-1);\n const word = positionals[consumed]?.value;\n if (word === undefined) {\n if (help || loose.values.help || current !== root || argv.length === 0) {\n return { trail, help: true };\n }\n throw new UsageError(tr(\"A command is missing.\"));\n }\n const found = current.commands.find((it) => it.name === word);\n if (!found) {\n throw new UsageError(\n tr(\"unknown command {name} for {parent}\", {\n name: JSON.stringify(word),\n parent: JSON.stringify(trail.map((it) => it.name).join(\" \")),\n }),\n );\n }\n trail.push(found);\n consumed++;\n }\n const command = trail.at(-1);\n const options: Options = trail.reduce(\n (found, it) => ({ ...found, ...it.options }),\n {},\n );\n const first = positionals[consumed];\n const verbatim =\n first !== undefined && command.passthrough?.(first.value)\n ? first.index + 1\n : argv.length;\n let parsed;\n try {\n parsed = parseArgs({\n args: argv.slice(0, verbatim),\n options: { ...parseOptions(globalOptions), ...parseOptions(options) },\n allowPositionals: true,\n strict: true,\n });\n } catch (error) {\n const option = error.message.match(/^Unknown option '(-[^']*)'/)?.[1];\n throw new UsageError(\n option === undefined\n ? error.message\n : tr(\"{option} isn't an option of {command}.\", {\n option,\n command: JSON.stringify(trail.map((it) => it.name).join(\" \")),\n }),\n );\n }\n if (parsed.values.help) {\n help = true;\n }\n const args = [...parsed.positionals.slice(consumed), ...argv.slice(verbatim)];\n if (\n !help &&\n (args.length < command.args[0] || args.length > command.args[1])\n ) {\n const [least, most] = command.args;\n throw new UsageError(\n least === most\n ? tr(\n {\n one: \"accepts {count} arg, received {received}\",\n other: \"accepts {count} args, received {received}\",\n },\n {\n count: least,\n received: args.length,\n },\n )\n : most === Infinity\n ? tr(\n {\n one: \"accepts at least {count} arg, received {received}\",\n other: \"accepts at least {count} args, received {received}\",\n },\n {\n count: least,\n received: args.length,\n },\n )\n : tr(\n {\n one: \"accepts between {least} and {count} arg, received {received}\",\n other:\n \"accepts between {least} and {count} args, received {received}\",\n },\n { least, count: most, received: args.length },\n ),\n );\n }\n return { trail, help, args, values: parsed.values };\n}\n\nfunction printError(error, target, operation?) {\n let exit = 1;\n let message = error.message;\n if (error instanceof UsageError) {\n exit = 2;\n } else if (error instanceof RpcError) {\n switch (error.code) {\n case Code.Unavailable:\n exit = 5;\n message = tr(\"Swipt at {url} is unreachable: {message}\", {\n url: target.url,\n message,\n });\n break;\n case Code.Unauthenticated:\n message = tr(\n '{message}; connect with the URL that Swipt › Developer or \"swipt driver\" shows: swipt device add {url}',\n { message, url: connection.withToken(target.url) },\n );\n break;\n case Code.Unimplemented:\n message = tr(\n \"Swipt at {url} doesn't have this command; update Swipt.\",\n { url: target.url },\n );\n break;\n }\n }\n console.error(\n tr(\"error: {message}\", {\n message: operation === undefined ? message : `${operation}: ${message}`,\n }),\n );\n if (exit === 2) {\n console.error(tr('Run \"swipt help\" for usage.'));\n }\n return exit;\n}\n\nexport async function main() {\n const interrupt = new AbortController();\n const interrupted = () => interrupt.abort();\n process.once(\"SIGINT\", interrupted);\n process.once(\"SIGTERM\", interrupted);\n const target = { url: \"\" };\n try {\n const resolved = resolve(process.argv.slice(2));\n if (resolved.help) {\n console.log(usage(resolved.trail));\n return;\n }\n const command = resolved.trail.at(-1);\n const values = command.parse\n ? command.parse(resolved.values)\n : resolved.values;\n await command.run({\n args: resolved.args,\n options: values,\n target,\n signal: interrupt.signal,\n printError: (error, operation) => printError(error, target, operation),\n });\n } catch (error) {\n if (error instanceof FalseResult) {\n process.exitCode = 1;\n } else if (interrupt.signal.aborted || error.name === \"ExitPromptError\") {\n process.exitCode = 130;\n } else {\n process.exitCode = printError(error, target);\n }\n } finally {\n process.off(\"SIGINT\", interrupted);\n process.off(\"SIGTERM\", interrupted);\n }\n}\n"],"mappings":";;;;;;;AASA,MAAM,gBAAyB,EAC7B,MAAM;CAAE,MAAM;CAAW,OAAO;CAAK,MAAM,GAAG,MAAM;AAAE,EACxD;AAEA,MAAM,gBAAgB,YACpB,OAAO,YACL,OAAO,QAAQ,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,YAAY,CACpD,MACA;CAAE,MAAM,OAAO;CAAM,GAAI,OAAO,QAAQ,EAAE,OAAO,OAAO,MAAM,IAAI,CAAC;AAAG,CACxE,CAAC,CACH;AAEF,SAAS,WAAW,SAAkB,YAAY,CAAC,GAAG;CACpD,OAAO,OAAO,WAAW,aAAa,QAAQ,OAAO,CAAC;CACtD,KAAK,MAAM,SAAS,QAAQ,YAAY,CAAC,GACvC,WAAW,OAAO,SAAS;CAE7B,OAAO;AACT;AAEA,SAAS,MAAM,OAAkB;CAC/B,MAAM,UAAU,MAAM,GAAG,EAAE;CAC3B,MAAM,OAAO,MAAM,KAAK,OAAO,GAAG,IAAI,CAAC,CAAC,KAAK,GAAG;CAChD,MAAM,QAAQ,CAAC,QAAQ,OAAO,EAAE;CAChC,IAAI,QAAQ,UAAU;EACpB,MAAM,KACJ,GAAG,kBAAkB,EAAE,OAAO,GAAG,KAAK,UAAU,CAAC,GACjD,IACA,GAAG,WAAW,CAChB;EACA,MAAM,KACJ,GAAG,QACD,QAAQ,SAAS,KAAK,UAAU,CAC9B,KAAK,MAAM,OAAO,MAAM,QACxB,MAAM,KACR,CAAC,CACH,CAAC,CAAC,MAAM,IAAI,CACd;CACF,OACE,MAAM,KACJ,GAAG,kBAAkB,EACnB,OAAO,GAAG,MACP,MAAM,GAAG,EAAE,CAAC,CACZ,KAAK,OAAO,GAAG,IAAI,CAAC,CACpB,KAAK,GAAG,EAAE,GAAG,QAAQ,OAAO,QAAQ,OAAO,QAAQ,OAA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1C,QAAQ,KAAK,UAAU,WAAW;CAClC,QAAQ,KAAK,WAAW,WAAW;CACnC,MAAM,SAAS,EAAE,KAAK,GAAG;CACzB,IAAI;EACF,MAAM,WAAW,QAAQ,QAAQ,KAAK,MAAM,CAAC,CAAC;EAC9C,IAAI,SAAS,MAAM;GACjB,QAAQ,IAAI,MAAM,SAAS,KAAK,CAAC;GACjC;EACF;EACA,MAAM,UAAU,SAAS,MAAM,GAAG,EAAE;EACpC,MAAM,SAAS,QAAQ,QACnB,QAAQ,MAAM,SAAS,MAAM,IAC7B,SAAS;EACb,MAAM,QAAQ,IAAI;GAChB,MAAM,SAAS;GACf,SAAS;GACT;GACA,QAAQ,UAAU;GAClB,aAAa,OAAO,cAAc,WAAW,OAAO,QAAQ,SAAS;EACvE,CAAC;CACH,SAAS,OAAO;EACd,IAAI,iBAAiB,aACnB,QAAQ,WAAW;OACd,IAAI,UAAU,OAAO,WAAW,MAAM,SAAS,mBACpD,QAAQ,WAAW;OAEnB,QAAQ,WAAW,WAAW,OAAO,MAAM;CAE/C,UAAU;EACR,QAAQ,IAAI,UAAU,WAAW;EACjC,QAAQ,IAAI,WAAW,WAAW;CACpC;AACF"}
|
|
1
|
+
{"version":3,"file":"cli.js","names":["connection.withToken"],"sources":["../../src/cli/cli.ts"],"sourcesContent":["import { parseArgs } from \"node:util\";\n\nimport { Code, RpcError, UsageError } from \"../client\";\nimport * as connection from \"../connection\";\nimport { t } from \"../i18n\";\nimport { FalseResult, errorMessage } from \"../output\";\nimport type { Command, Options } from \"./command\";\nimport { root } from \"./commands\";\n\nconst globalOptions: Options = {\n help: { type: \"boolean\", short: \"h\", help: t(\"cli.help\") },\n};\n\nconst parseOptions = (options: Options = {}) =>\n Object.fromEntries(\n Object.entries(options).map(([name, option]) => [\n name,\n { type: option.type, ...(option.short ? { short: option.short } : {}) },\n ]),\n );\n\nfunction allOptions(command: Command): ReturnType<typeof parseOptions> {\n return Object.assign(\n parseOptions(command.options),\n ...(\"commands\" in command ? command.commands.map(allOptions) : []),\n );\n}\n\nfunction usage(trail: Command[]) {\n const command = trail[trail.length - 1];\n const name = trail.map((it) => it.name).join(\" \");\n const lines = [command.short, \"\"];\n if (\"commands\" in command) {\n lines.push(\n t(\"cli.usage\", { usage: `${name} COMMAND` }),\n \"\",\n t(\"cli.commands\"),\n );\n lines.push(\n ...columns(\n command.commands.map((child) => [\n ` ${child.use ?? child.name}`,\n child.short,\n ]),\n ).split(\"\\n\"),\n );\n } else {\n lines.push(\n t(\"cli.usage\", {\n usage: `${trail\n .slice(0, -1)\n .map((it) => it.name)\n .join(\" \")} ${command.use ?? command.name}`.replace(/ +/g, \" \"),\n }),\n );\n }\n if (command.description) {\n lines.push(\"\", ...command.description);\n }\n const options: Options = {\n ...trail.reduce((found, it) => ({ ...found, ...it.options }), {}),\n ...globalOptions,\n };\n lines.push(\"\", t(\"cli.options\"));\n lines.push(\n ...columns(\n Object.entries(options).map(([option, it]) => [\n ` ${it.short ? `-${it.short}, ` : \"\"}--${option}${it.value ? ` ${it.value}` : \"\"}`,\n it.help,\n ]),\n ).split(\"\\n\"),\n );\n return lines.join(\"\\n\");\n}\n\nfunction columns(rows: [string, string][]) {\n const width = Math.max(...rows.map((row) => row[0].length));\n return rows.map((row) => `${row[0].padEnd(width + 2)}${row[1]}`).join(\"\\n\");\n}\n\nfunction resolve(argv: string[]) {\n const loose = parseArgs({\n args: argv,\n options: { ...parseOptions(globalOptions), ...allOptions(root) },\n allowPositionals: true,\n strict: false,\n tokens: true,\n });\n const positionals = loose.tokens.filter(\n (token) => token.kind === \"positional\",\n );\n const trail: Command[] = [root];\n let current: Command = root;\n let consumed = 0;\n let help = positionals[0]?.value === \"help\";\n if (help) {\n consumed++;\n }\n while (\"commands\" in current) {\n const word = positionals[consumed]?.value;\n if (word === undefined) {\n if (help || loose.values.help || current !== root || argv.length === 0) {\n return { trail };\n }\n throw new UsageError(t(\"cli.missingCommand\"));\n }\n const found: Command | undefined = current.commands.find(\n (it) => it.name === word,\n );\n if (!found) {\n throw new UsageError(\n t(\"cli.unknownCommand\", {\n name: JSON.stringify(word),\n parent: JSON.stringify(trail.map((it) => it.name).join(\" \")),\n }),\n );\n }\n trail.push(found);\n current = found;\n consumed++;\n }\n const command = current;\n const options: Options = trail.reduce(\n (found, it) => ({ ...found, ...it.options }),\n {},\n );\n const first = positionals[consumed];\n const verbatim =\n first !== undefined && command.passthrough?.(first.value)\n ? first.index + 1\n : argv.length;\n let parsed;\n try {\n parsed = parseArgs({\n args: argv.slice(0, verbatim),\n options: { ...parseOptions(globalOptions), ...parseOptions(options) },\n allowPositionals: true,\n strict: true,\n });\n } catch (error) {\n const message = errorMessage(error);\n const option = message.match(/^Unknown option '(-[^']*)'/)?.[1];\n throw new UsageError(\n option === undefined\n ? message\n : t(\"cli.unknownOption\", {\n option,\n command: JSON.stringify(trail.map((it) => it.name).join(\" \")),\n }),\n );\n }\n if (help || parsed.values.help) {\n return { trail };\n }\n const args = [...parsed.positionals.slice(consumed), ...argv.slice(verbatim)];\n const [least, most] = command.args;\n if (args.length < least || args.length > most) {\n throw new UsageError(\n least === most\n ? t(\"cli.exactArgs\", {\n count: least,\n received: args.length,\n })\n : most === Infinity\n ? t(\"cli.minimumArgs\", {\n count: least,\n received: args.length,\n })\n : t(\"cli.rangeArgs\", { least, count: most, received: args.length }),\n );\n }\n return { trail, invocation: { command, args, options: parsed.values } };\n}\n\nfunction printError(\n error: unknown,\n target: { url: string },\n operation?: string,\n) {\n let exit = 1;\n let message = errorMessage(error);\n if (error instanceof UsageError) {\n exit = 2;\n } else if (error instanceof RpcError) {\n switch (error.code) {\n case Code.Unavailable:\n exit = 5;\n message = t(\"cli.unreachable\", {\n url: target.url,\n message,\n });\n break;\n case Code.Unauthenticated:\n message = t(\"cli.unauthenticated\", {\n message,\n url: connection.withToken(target.url),\n });\n break;\n case Code.Unimplemented:\n message = t(\"cli.unimplemented\", { url: target.url });\n break;\n }\n }\n console.error(\n t(\"error\", {\n message: operation === undefined ? message : `${operation}: ${message}`,\n }),\n );\n if (exit === 2) {\n console.error(t(\"cli.helpHint\"));\n }\n return exit;\n}\n\nexport async function main() {\n const interrupt = new AbortController();\n const interrupted = () => interrupt.abort();\n process.once(\"SIGINT\", interrupted);\n process.once(\"SIGTERM\", interrupted);\n const target = { url: \"\" };\n try {\n const { trail, invocation } = resolve(process.argv.slice(2));\n if (!invocation) {\n console.log(usage(trail));\n return;\n }\n await invocation.command.run({\n args: invocation.args,\n options: invocation.options,\n target,\n signal: interrupt.signal,\n printError: (error, operation) => printError(error, target, operation),\n });\n } catch (error) {\n if (error instanceof FalseResult) {\n process.exitCode = 1;\n } else if (\n interrupt.signal.aborted ||\n (error instanceof Error && error.name === \"ExitPromptError\")\n ) {\n process.exitCode = 130;\n } else {\n process.exitCode = printError(error, target);\n }\n } finally {\n process.off(\"SIGINT\", interrupted);\n process.off(\"SIGTERM\", interrupted);\n }\n}\n"],"mappings":";;;;;;;AASA,MAAM,gBAAyB,EAC7B,MAAM;CAAE,MAAM;CAAW,OAAO;CAAK,MAAM,EAAE,UAAU;AAAE,EAC3D;AAEA,MAAM,gBAAgB,UAAmB,CAAC,MACxC,OAAO,YACL,OAAO,QAAQ,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,YAAY,CAC9C,MACA;CAAE,MAAM,OAAO;CAAM,GAAI,OAAO,QAAQ,EAAE,OAAO,OAAO,MAAM,IAAI,CAAC;AAAG,CACxE,CAAC,CACH;AAEF,SAAS,WAAW,SAAmD;CACrE,OAAO,OAAO,OACZ,aAAa,QAAQ,OAAO,GAC5B,GAAI,cAAc,UAAU,QAAQ,SAAS,IAAI,UAAU,IAAI,CAAC,CAClE;AACF;AAEA,SAAS,MAAM,OAAkB;CAC/B,MAAM,UAAU,MAAM,MAAM,SAAS;CACrC,MAAM,OAAO,MAAM,KAAK,OAAO,GAAG,IAAI,CAAC,CAAC,KAAK,GAAG;CAChD,MAAM,QAAQ,CAAC,QAAQ,OAAO,EAAE;CAChC,IAAI,cAAc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UAAU,EAAE,qBAAqB,EAAE,KAAK,OAAO,IAAI,CAAC;CAExD;CAEF,QAAQ,MACN,EAAE,SAAS,EACT,SAAS,cAAc,KAAA,IAAY,UAAU,GAAG,UAAU,IAAI,UAChE,CAAC,CACH;CACA,IAAI,SAAS,GACX,QAAQ,MAAM,EAAE,cAAc,CAAC;CAEjC,OAAO;AACT;AAEA,eAAsB,OAAO;CAC3B,MAAM,YAAY,IAAI,gBAAgB;CACtC,MAAM,oBAAoB,UAAU,MAAM;CAC1C,QAAQ,KAAK,UAAU,WAAW;CAClC,QAAQ,KAAK,WAAW,WAAW;CACnC,MAAM,SAAS,EAAE,KAAK,GAAG;CACzB,IAAI;EACF,MAAM,EAAE,OAAO,eAAe,QAAQ,QAAQ,KAAK,MAAM,CAAC,CAAC;EAC3D,IAAI,CAAC,YAAY;GACf,QAAQ,IAAI,MAAM,KAAK,CAAC;GACxB;EACF;EACA,MAAM,WAAW,QAAQ,IAAI;GAC3B,MAAM,WAAW;GACjB,SAAS,WAAW;GACpB;GACA,QAAQ,UAAU;GAClB,aAAa,OAAO,cAAc,WAAW,OAAO,QAAQ,SAAS;EACvE,CAAC;CACH,SAAS,OAAO;EACd,IAAI,iBAAiB,aACnB,QAAQ,WAAW;OACd,IACL,UAAU,OAAO,WAChB,iBAAiB,SAAS,MAAM,SAAS,mBAE1C,QAAQ,WAAW;OAEnB,QAAQ,WAAW,WAAW,OAAO,MAAM;CAE/C,UAAU;EACR,QAAQ,IAAI,UAAU,WAAW;EACjC,QAAQ,IAAI,WAAW,WAAW;CACpC;AACF"}
|
package/dist/cli/command.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","names":[],"sources":["../../src/cli/command.ts"],"sourcesContent":["export interface Option {\n type: \"string\" | \"boolean\";\n short?: string;\n value?: string;\n help: string;\n}\n\nexport type Options = Record<string, Option>;\n\nexport interface
|
|
1
|
+
{"version":3,"file":"command.js","names":[],"sources":["../../src/cli/command.ts"],"sourcesContent":["export interface Option {\n type: \"string\" | \"boolean\";\n short?: string;\n value?: string;\n help: string;\n}\n\nexport type Options = Record<string, Option>;\n\nexport interface Context<Values = {}> {\n args: string[];\n options: Values;\n target: { url: string };\n signal: AbortSignal;\n printError: (error: unknown, operation?: string) => number;\n}\n\ninterface Named {\n name: string;\n use?: string;\n short: string;\n description?: string[];\n options?: Options;\n}\n\nexport interface CommandGroup extends Named {\n commands: Command[];\n}\n\nexport interface LeafCommand extends Named {\n args: [least: number, most: number];\n passthrough?: (word: string) => boolean;\n run: (context: Context<any>) => unknown;\n}\n\nexport type Command = CommandGroup | LeafCommand;\n\nexport const defineCommand = <C extends Command>(command: C): C => command;\n"],"mappings":";AAqCA,MAAa,iBAAoC,YAAkB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t } from "../../../i18n.js";
|
|
2
2
|
import { defineCommand } from "../../command.js";
|
|
3
3
|
import { session } from "../../session.js";
|
|
4
4
|
import { operandCount } from "./operand.js";
|
|
@@ -17,7 +17,7 @@ const clear = (operand, target) => {
|
|
|
17
17
|
return defineCommand({
|
|
18
18
|
name: "clear",
|
|
19
19
|
use: `clear ${operand}`.trimEnd(),
|
|
20
|
-
short:
|
|
20
|
+
short: t("commands.data.clear.description"),
|
|
21
21
|
args: [before, before],
|
|
22
22
|
run: clearFiles(target)
|
|
23
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clear.js","names":[],"sources":["../../../../src/cli/commands/data/clear.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"clear.js","names":[],"sources":["../../../../src/cli/commands/data/clear.ts"],"sourcesContent":["import { t } from \"../../../i18n\";\nimport { type Context, defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\nimport { type ResolveTarget, operandCount } from \"./operand\";\n\nconst clearFiles =\n (target: ResolveTarget) => (context: Context<{ device?: string }>) =>\n session(context, async (client) => {\n const { id } = target(context.args);\n const { files } = await client.swiplets.listDataFiles(\n { swipletId: id },\n { signal: context.signal },\n );\n for (const file of files) {\n await client.swiplets.removeDataFile(\n { swipletId: id, path: file.path, recursive: true },\n { signal: context.signal },\n );\n }\n });\n\nexport const clear = (operand: string, target: ResolveTarget) => {\n const before = operandCount(operand);\n return defineCommand({\n name: \"clear\",\n use: `clear ${operand}`.trimEnd(),\n short: t(\"commands.data.clear.description\"),\n args: [before, before],\n run: clearFiles(target),\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,cACH,YAA2B,YAC1B,QAAQ,SAAS,OAAO,WAAW;CACjC,MAAM,EAAE,OAAO,OAAO,QAAQ,IAAI;CAClC,MAAM,EAAE,UAAU,MAAM,OAAO,SAAS,cACtC,EAAE,WAAW,GAAG,GAChB,EAAE,QAAQ,QAAQ,OAAO,CAC3B;CACA,KAAK,MAAM,QAAQ,OACjB,MAAM,OAAO,SAAS,eACpB;EAAE,WAAW;EAAI,MAAM,KAAK;EAAM,WAAW;CAAK,GAClD,EAAE,QAAQ,QAAQ,OAAO,CAC3B;AAEJ,CAAC;AAEL,MAAa,SAAS,SAAiB,WAA0B;CAC/D,MAAM,SAAS,aAAa,OAAO;CACnC,OAAO,cAAc;EACnB,MAAM;EACN,KAAK,SAAS,UAAU,QAAQ;EAChC,OAAO,EAAE,iCAAiC;EAC1C,MAAM,CAAC,QAAQ,MAAM;EACrB,KAAK,WAAW,MAAM;CACxB,CAAC;AACH"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t } from "../../../i18n.js";
|
|
2
2
|
import { defineCommand } from "../../command.js";
|
|
3
3
|
import { clear } from "./clear.js";
|
|
4
4
|
import { list } from "./list.js";
|
|
@@ -8,7 +8,7 @@ import { write } from "./write.js";
|
|
|
8
8
|
// src/cli/commands/data/data.ts
|
|
9
9
|
const data = (operand, target) => defineCommand({
|
|
10
10
|
name: "data",
|
|
11
|
-
short: operand === "" ?
|
|
11
|
+
short: operand === "" ? t("commands.data.replDescription") : t("commands.data.swipletDescription"),
|
|
12
12
|
commands: [
|
|
13
13
|
list(operand, target),
|
|
14
14
|
read(operand, target),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.js","names":[],"sources":["../../../../src/cli/commands/data/data.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"data.js","names":[],"sources":["../../../../src/cli/commands/data/data.ts"],"sourcesContent":["import { t } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { clear } from \"./clear\";\nimport { list } from \"./list\";\nimport type { ResolveTarget } from \"./operand\";\nimport { read } from \"./read\";\nimport { remove } from \"./remove\";\nimport { write } from \"./write\";\n\nexport const data = (operand: string, target: ResolveTarget) =>\n defineCommand({\n name: \"data\",\n short:\n operand === \"\"\n ? t(\"commands.data.replDescription\")\n : t(\"commands.data.swipletDescription\"),\n commands: [\n list(operand, target),\n read(operand, target),\n write(operand, target),\n remove(operand, target),\n clear(operand, target),\n ],\n });\n"],"mappings":";;;;;;;;AASA,MAAa,QAAQ,SAAiB,WACpC,cAAc;CACZ,MAAM;CACN,OACE,YAAY,KACR,EAAE,+BAA+B,IACjC,EAAE,kCAAkC;CAC1C,UAAU;EACR,KAAK,SAAS,MAAM;EACpB,KAAK,SAAS,MAAM;EACpB,MAAM,SAAS,MAAM;EACrB,OAAO,SAAS,MAAM;EACtB,MAAM,SAAS,MAAM;CACvB;AACF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t } from "../../../i18n.js";
|
|
2
2
|
import { columns, dateTime } from "../../../output.js";
|
|
3
3
|
import { defineCommand } from "../../command.js";
|
|
4
4
|
import { session } from "../../session.js";
|
|
@@ -23,11 +23,11 @@ const list = (operand, target) => {
|
|
|
23
23
|
return defineCommand({
|
|
24
24
|
name: "list",
|
|
25
25
|
use: `list ${operand}[PATH]`,
|
|
26
|
-
short:
|
|
26
|
+
short: t("commands.data.list.description"),
|
|
27
27
|
args: [before, before + 1],
|
|
28
28
|
options: { recursive: {
|
|
29
29
|
type: "boolean",
|
|
30
|
-
help:
|
|
30
|
+
help: t("commands.data.list.recursive")
|
|
31
31
|
} },
|
|
32
32
|
run: listFiles(target)
|
|
33
33
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","names":[],"sources":["../../../../src/cli/commands/data/list.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"list.js","names":[],"sources":["../../../../src/cli/commands/data/list.ts"],"sourcesContent":["import { t } from \"../../../i18n\";\nimport { columns, dateTime } from \"../../../output\";\nimport { type Context, defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\nimport { type ResolveTarget, operandCount } from \"./operand\";\n\nconst listFiles =\n (target: ResolveTarget) =>\n (context: Context<{ device?: string; recursive?: boolean }>) =>\n session(context, async (client) => {\n const {\n id,\n args: [directory = \"\"],\n } = target(context.args);\n const { files } = await client.swiplets.listDataFiles(\n {\n swipletId: id,\n path: directory,\n recursive: context.options.recursive,\n },\n { signal: context.signal },\n );\n const rows = files.map((file) => [\n file.directory ? \"-\" : String(file.size),\n dateTime(file.modified),\n file.directory ? `${file.path}/` : file.path,\n ]);\n if (rows.length > 0) {\n console.log(columns(rows));\n }\n });\n\nexport const list = (operand: string, target: ResolveTarget) => {\n const before = operandCount(operand);\n return defineCommand({\n name: \"list\",\n use: `list ${operand}[PATH]`,\n short: t(\"commands.data.list.description\"),\n args: [before, before + 1],\n options: {\n recursive: { type: \"boolean\", help: t(\"commands.data.list.recursive\") },\n },\n run: listFiles(target),\n });\n};\n"],"mappings":";;;;;;AAMA,MAAM,aACH,YACA,YACC,QAAQ,SAAS,OAAO,WAAW;CACjC,MAAM,EACJ,IACA,MAAM,CAAC,YAAY,QACjB,OAAO,QAAQ,IAAI;CACvB,MAAM,EAAE,UAAU,MAAM,OAAO,SAAS,cACtC;EACE,WAAW;EACX,MAAM;EACN,WAAW,QAAQ,QAAQ;CAC7B,GACA,EAAE,QAAQ,QAAQ,OAAO,CAC3B;CACA,MAAM,OAAO,MAAM,KAAK,SAAS;EAC/B,KAAK,YAAY,MAAM,OAAO,KAAK,IAAI;EACvC,SAAS,KAAK,QAAQ;EACtB,KAAK,YAAY,GAAG,KAAK,KAAK,KAAK,KAAK;CAC1C,CAAC;CACD,IAAI,KAAK,SAAS,GAChB,QAAQ,IAAI,QAAQ,IAAI,CAAC;AAE7B,CAAC;AAEL,MAAa,QAAQ,SAAiB,WAA0B;CAC9D,MAAM,SAAS,aAAa,OAAO;CACnC,OAAO,cAAc;EACnB,MAAM;EACN,KAAK,QAAQ,QAAQ;EACrB,OAAO,EAAE,gCAAgC;EACzC,MAAM,CAAC,QAAQ,SAAS,CAAC;EACzB,SAAS,EACP,WAAW;GAAE,MAAM;GAAW,MAAM,EAAE,8BAA8B;EAAE,EACxE;EACA,KAAK,UAAU,MAAM;CACvB,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operand.js","names":[],"sources":["../../../../src/cli/commands/data/operand.ts"],"sourcesContent":["export const operandCount = (operand) => (operand === \"\" ? 0 : 1);\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"operand.js","names":[],"sources":["../../../../src/cli/commands/data/operand.ts"],"sourcesContent":["export interface DataTarget {\n id: string;\n wholeDirectory: (name: string) => string;\n subdirectory: (name: string) => string;\n args: string[];\n}\n\nexport type ResolveTarget = (args: string[]) => DataTarget;\n\nexport const operandCount = (operand: string) => (operand === \"\" ? 0 : 1);\n"],"mappings":";AASA,MAAa,gBAAgB,YAAqB,YAAY,KAAK,IAAI"}
|