@swipt/cli 0.1.0-nightly.88 → 0.1.0-nightly.90

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.
Files changed (71) hide show
  1. package/dist/availability.js +86 -5
  2. package/dist/availability.js.map +1 -1
  3. package/dist/cli/commands/project/develop.js +1 -1
  4. package/dist/cli/commands/project/develop.js.map +1 -1
  5. package/dist/cli/commands/project/source.js +3 -1
  6. package/dist/cli/commands/project/source.js.map +1 -1
  7. package/dist/cli/commands/swiplet/call.js +2 -1
  8. package/dist/cli/commands/swiplet/call.js.map +1 -1
  9. package/dist/cli/commands/swiplet/show.js +1 -7
  10. package/dist/cli/commands/swiplet/show.js.map +1 -1
  11. package/dist/client.js +4 -1
  12. package/dist/client.js.map +1 -1
  13. package/dist/connection.js +3 -8
  14. package/dist/connection.js.map +1 -1
  15. package/dist/project.js +6 -2
  16. package/dist/project.js.map +1 -1
  17. package/dist/proto/swiplets_pb.js +1 -1
  18. package/dist/proto/swiplets_pb.js.map +1 -1
  19. package/dist/sideload.js +2 -0
  20. package/dist/sideload.js.map +1 -1
  21. package/locales/ar.json +3 -7
  22. package/locales/bg.json +3 -7
  23. package/locales/bn.json +3 -7
  24. package/locales/ca.json +3 -7
  25. package/locales/cs.json +3 -7
  26. package/locales/da.json +3 -7
  27. package/locales/de.json +3 -7
  28. package/locales/el.json +3 -7
  29. package/locales/es-419.json +3 -7
  30. package/locales/es.json +3 -7
  31. package/locales/fi.json +3 -7
  32. package/locales/fr-CA.json +3 -7
  33. package/locales/fr.json +3 -7
  34. package/locales/gu.json +3 -7
  35. package/locales/he.json +3 -7
  36. package/locales/hi.json +3 -7
  37. package/locales/hr.json +3 -7
  38. package/locales/hu.json +3 -7
  39. package/locales/id.json +3 -7
  40. package/locales/it.json +3 -7
  41. package/locales/ja.json +3 -7
  42. package/locales/kk.json +3 -7
  43. package/locales/kn.json +3 -7
  44. package/locales/ko.json +3 -7
  45. package/locales/lt.json +3 -7
  46. package/locales/ml.json +3 -7
  47. package/locales/mr.json +3 -7
  48. package/locales/ms.json +3 -7
  49. package/locales/nb.json +3 -7
  50. package/locales/nl.json +3 -7
  51. package/locales/or.json +3 -7
  52. package/locales/pa.json +3 -7
  53. package/locales/pl.json +3 -7
  54. package/locales/pt-BR.json +3 -7
  55. package/locales/pt-PT.json +3 -7
  56. package/locales/ro.json +3 -7
  57. package/locales/ru.json +3 -7
  58. package/locales/sk.json +3 -7
  59. package/locales/sl.json +3 -7
  60. package/locales/sv.json +3 -7
  61. package/locales/ta.json +3 -7
  62. package/locales/te.json +3 -7
  63. package/locales/th.json +3 -7
  64. package/locales/tr.json +3 -7
  65. package/locales/uk.json +3 -7
  66. package/locales/ur.json +3 -7
  67. package/locales/vi.json +3 -7
  68. package/locales/zh-HK.json +3 -7
  69. package/locales/zh-Hans.json +3 -7
  70. package/locales/zh-Hant.json +3 -7
  71. package/package.json +4 -4
@@ -67,6 +67,21 @@ const objectMembers = /* @__PURE__ */ new Set([
67
67
  SyntaxKind.GetAccessor,
68
68
  SyntaxKind.SetAccessor
69
69
  ]);
70
+ const literals = /* @__PURE__ */ new Set([
71
+ SyntaxKind.ObjectLiteralExpression,
72
+ SyntaxKind.ArrayLiteralExpression,
73
+ SyntaxKind.ArrowFunction,
74
+ SyntaxKind.FunctionExpression,
75
+ SyntaxKind.StringLiteral,
76
+ SyntaxKind.NumericLiteral,
77
+ SyntaxKind.NoSubstitutionTemplateLiteral,
78
+ SyntaxKind.TemplateExpression,
79
+ SyntaxKind.TrueKeyword,
80
+ SyntaxKind.FalseKeyword,
81
+ SyntaxKind.NullKeyword,
82
+ SyntaxKind.SpreadElement
83
+ ]);
84
+ const names = /* @__PURE__ */ new Set([SyntaxKind.StringLiteral, SyntaxKind.NoSubstitutionTemplateLiteral]);
70
85
  const inert = /* @__PURE__ */ new Set([
71
86
  SyntaxKind.ImportDeclaration,
72
87
  SyntaxKind.ExportDeclaration,
@@ -118,10 +133,12 @@ var Checker = class {
118
133
  #entries;
119
134
  #available;
120
135
  #symbols = /* @__PURE__ */ new Map();
136
+ #imports = /* @__PURE__ */ new Set();
121
137
  #requirements = /* @__PURE__ */ new Map();
122
138
  #annotations = /* @__PURE__ */ new Map();
123
139
  #facts = [/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()];
124
140
  #types = /* @__PURE__ */ new Map();
141
+ #annotated = /* @__PURE__ */ new Map();
125
142
  constructor(typescript, project, files, problems) {
126
143
  this.#project = typescript;
127
144
  this.#checker = typescript.checker;
@@ -138,10 +155,20 @@ var Checker = class {
138
155
  check(files) {
139
156
  for (const file of files) {
140
157
  const source = this.#project.program.getSourceFile(file);
141
- const { identifiers, properties } = this.#collect(source);
158
+ const { identifiers, properties, values } = this.#collect(source);
142
159
  const symbols = this.#checker.getSymbolAtLocation(identifiers);
143
160
  for (const [index, node] of identifiers.entries()) this.#use(node, node.parent.kind === SyntaxKind.ShorthandPropertyAssignment ? this.#checker.getShorthandAssignmentValueSymbol(node.parent) : symbols[index]);
144
161
  for (const node of properties) this.#use(node, this.#propertySymbol(node));
162
+ for (const node of values) this.#useValue(node);
163
+ for (const statement of source.statements) {
164
+ if (statement.kind !== SyntaxKind.ExportDeclaration || statement.isTypeOnly) continue;
165
+ const exported = (statement.exportClause?.elements ?? []).filter((specifier) => !specifier.isTypeOnly);
166
+ if (statement.moduleSpecifier === void 0) for (const specifier of exported) {
167
+ const local = this.#checker.getExportSpecifierLocalTargetSymbol(specifier);
168
+ if (local !== void 0) this.#useImport(local);
169
+ }
170
+ else if (exported.length > 0 || statement.exportClause?.elements === void 0) this.#importModule(statement);
171
+ }
145
172
  if (this.#entries.has(file)) {
146
173
  for (const statement of source.statements) if (statement.name !== void 0 && hasModifier(statement, SyntaxKind.DefaultKeyword)) this.#useEntry(statement.name);
147
174
  }
@@ -150,37 +177,90 @@ var Checker = class {
150
177
  #collect(source) {
151
178
  const identifiers = [];
152
179
  const properties = [];
180
+ const values = [];
153
181
  const visit = (node, checked) => {
154
182
  for (const tag of annotationTags(node)) this.#parse(tagText(tag), tag);
155
183
  const extended = node.kind === SyntaxKind.ExpressionWithTypeArguments && node.parent.token === SyntaxKind.ExtendsKeyword && classes.has(node.parent.parent.kind);
156
184
  if (inert.has(node.kind) || isTypeNode(node) && !extended) checked = false;
185
+ if (checked) {
186
+ if (node.kind === SyntaxKind.CallExpression || node.kind === SyntaxKind.NewExpression) values.push(...(node.arguments ?? []).filter((argument) => !literals.has(argument.kind)));
187
+ else if (node.kind === SyntaxKind.SpreadAssignment || node.kind === SyntaxKind.JsxSpreadAttribute) values.push(node.expression);
188
+ }
157
189
  if (checked && node.kind === SyntaxKind.Identifier) {
158
190
  const { parent } = node;
159
191
  const property = parent.kind === SyntaxKind.JsxAttribute || objectMembers.has(parent.kind) && parent.parent.kind === SyntaxKind.ObjectLiteralExpression && parent.name === node || parent.kind === SyntaxKind.BindingElement && parent.parent.kind === SyntaxKind.ObjectBindingPattern && (parent.propertyName ?? parent.name) === node;
160
192
  if (property) properties.push(node);
161
193
  if (parent.kind === SyntaxKind.ShorthandPropertyAssignment || !property && parent.propertyName !== node && (parent.name !== node || parent.kind === SyntaxKind.PropertyAccessExpression)) identifiers.push(node);
162
194
  }
195
+ if (checked && (node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NoSubstitutionTemplateLiteral)) {
196
+ const { parent } = node;
197
+ const member = parent.kind === SyntaxKind.ComputedPropertyName ? parent.parent : parent;
198
+ if (objectMembers.has(member.kind) && member.parent.kind === SyntaxKind.ObjectLiteralExpression && (member.name === node || member.name === parent) || member.kind === SyntaxKind.BindingElement && member.parent.kind === SyntaxKind.ObjectBindingPattern && (member.propertyName === node || member.propertyName === parent)) properties.push(node);
199
+ else if (parent.kind === SyntaxKind.ElementAccessExpression && parent.argumentExpression === node) identifiers.push(node);
200
+ }
201
+ if (checked && node.kind === SyntaxKind.ObjectLiteralExpression && node.properties.some((member) => member.name?.kind === SyntaxKind.ComputedPropertyName && !names.has(member.name.expression.kind))) values.push(node);
163
202
  node.forEachChild((child) => visit(child, checked));
164
203
  };
165
204
  source.forEachChild((child) => visit(child, true));
166
205
  return {
167
206
  identifiers,
168
- properties
207
+ properties,
208
+ values
169
209
  };
170
210
  }
171
- #use(node, symbol) {
211
+ #useValue(node) {
212
+ const expected = this.#checker.getContextualType(node);
213
+ if (expected === void 0) return;
214
+ if (!this.#annotated.has(expected.id)) {
215
+ const annotated = /* @__PURE__ */ new Map();
216
+ for (const candidate of [expected, ...expected.getTypes?.() ?? []]) for (const property of this.#checker.getPropertiesOfType(candidate)) if (Object.keys(this.#requirementOf(property)).length > 0) annotated.set(property.name, property);
217
+ this.#annotated.set(expected.id, [...annotated.values()]);
218
+ }
219
+ const annotated = this.#annotated.get(expected.id);
220
+ const type = annotated.length > 0 ? this.#checker.getTypeAtLocation(node) : void 0;
221
+ if (type === void 0) return;
222
+ const named = new Set((node.kind === SyntaxKind.ObjectLiteralExpression ? node.properties : []).map((member) => member.name?.kind === SyntaxKind.ComputedPropertyName ? member.name.expression.text : member.name?.text));
223
+ for (const property of annotated) if (!named.has(property.name) && this.#checker.getPropertyOfType(type, property.name) !== void 0) this.#use(node, property, property.name);
224
+ }
225
+ #use(node, symbol, name = node.text) {
172
226
  if (symbol === void 0) return;
227
+ this.#useImport(symbol);
173
228
  const needed = this.#requirementOf(symbol);
174
229
  const missing = Object.keys(needed).filter((name) => !this.#covered(name, needed[name], node));
175
230
  if (missing.length > 0) {
176
231
  this.#problems.guarding = true;
177
232
  this.#problems.lines.add(tr("{location}: {name} needs {requirement}.", {
178
233
  location: this.#location(node),
179
- name: node.text,
234
+ name,
180
235
  requirement: describe(needed, missing)
181
236
  }));
182
237
  }
183
238
  }
239
+ #useImport(symbol) {
240
+ let declaration = symbol.flags & SymbolFlags.Alias ? symbol.declarations?.[0]?.resolve(this.#project) : void 0;
241
+ while (declaration !== void 0 && declaration.kind !== SyntaxKind.ImportDeclaration) declaration = declaration.parent;
242
+ if (declaration !== void 0) this.#importModule(declaration);
243
+ }
244
+ #importModule(declaration) {
245
+ if (this.#imports.has(declaration)) return;
246
+ this.#imports.add(declaration);
247
+ const name = declaration.moduleSpecifier;
248
+ const module = this.#checker.getSymbolAtLocation(name)?.declarations?.[0]?.resolve(this.#project);
249
+ if (module?.kind !== SyntaxKind.SourceFile || this.#files.has(module.fileName)) return;
250
+ const needed = this.#moduleRequirement(module);
251
+ const missing = Object.keys(needed).filter((kind) => !requirements[kind].covers(this.#minimum[kind], needed[kind]));
252
+ if (missing.length > 0) this.#problems.lines.add(tr("{location}: importing {name} needs {requirement}; raise \"swiplet.minimumAPILevel\" or \"swiplet.minimumIOSVersion\" in package.json.", {
253
+ location: this.#location(name),
254
+ name: name.text,
255
+ requirement: describe(needed, missing)
256
+ }));
257
+ }
258
+ #moduleRequirement(source) {
259
+ const requirement = {};
260
+ const [first] = source.statements;
261
+ if (first?.kind === SyntaxKind.ImportDeclaration) for (const tag of annotationTags(first)) merge(requirement, this.#parse(tagText(tag), tag));
262
+ return requirement;
263
+ }
184
264
  #useEntry(name) {
185
265
  const symbol = this.#checker.getSymbolAtLocation(name);
186
266
  const needed = symbol === void 0 ? {} : this.#requirementOf(symbol);
@@ -225,6 +305,7 @@ var Checker = class {
225
305
  const declaration = (target.valueDeclaration ?? target.declarations[0])?.resolve(this.#project);
226
306
  const external = declaration !== void 0 && !this.#files.has(sourceFileOf(declaration).fileName);
227
307
  for (const tag of this.#checker.getJsDocTagsOfSymbol(target)) if (tag.name === "available") merge(requirement, external ? this.#parse(tag.text ?? "", declaration) : parseAnnotation(tag.text ?? "").requirement);
308
+ if (external) merge(requirement, this.#moduleRequirement(sourceFileOf(declaration)));
228
309
  this.#requirements.set(target.id, requirement);
229
310
  }
230
311
  return this.#requirements.get(target.id);
@@ -240,7 +321,7 @@ var Checker = class {
240
321
  return this.#annotations.get(node);
241
322
  }
242
323
  #propertySymbol(name) {
243
- const member = name.parent;
324
+ const member = name.parent.kind === SyntaxKind.ComputedPropertyName ? name.parent.parent : name.parent;
244
325
  const container = member.parent;
245
326
  if (!this.#types.has(container)) this.#types.set(container, member.kind === SyntaxKind.BindingElement ? this.#checker.getTypeAtLocation(container) : this.#checker.getContextualType(container));
246
327
  const type = this.#types.get(container);
@@ -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 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 #requirements = new Map();\n #annotations = new Map();\n #facts = [new Map(), new Map()];\n #types = 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 } = 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 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 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 && 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 node.forEachChild((child) => visit(child, checked));\n };\n source.forEachChild((child) => visit(child, true));\n return { identifiers, properties };\n }\n\n #use(node, symbol) {\n if (symbol === undefined) {\n return;\n }\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: node.text,\n requirement: describe(needed, missing),\n }),\n );\n }\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 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 = 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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AW,0BACjD,SAAS,aACT,CAAC,GAAG;GACN,MAAM,QACJ,SAAS,SAAS,WAAW,sBAC7B,OAAO,OAAO,cAAc,SAAS,KAAK,IAAI,IAC1C,KAAK,UAAU,SAAS,WAAW,IACnC,KAAA;GACN,IAAI,OAAO,SAAS,WAAW,gBAAgB;IAC7C,MAAM,SAAS,aAAa,SAAS,KAAK,KAAK,CAAC,MAC9C,OAAO,OAAO,MAAM,IAAI,CAAC,CAC3B;IACA,IAAI,WAAW,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 { 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,MA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OACJ,KAAK,SAAS,WAAW,2BAA2B,KAAK,OAAO;EAClE,OACE,KAAK,eAAe,KAAA,KACpB,KAAK,SAAS,WAAW,cACzB,KAAK,UAAU,IAAI,CAAC,EAAE,OAAO,KAAK;CAEtC;CAEA,gBAAgB,UAAU;EACxB,MAAM,SAAS,CAAC;EAChB,KAAK,MAAM,YAAY,UAAU,SAAS,WAAW,0BACjD,SAAS,aACT,CAAC,GAAG;GACN,MAAM,QACJ,SAAS,SAAS,WAAW,sBAC7B,OAAO,OAAO,cAAc,SAAS,KAAK,IAAI,IAC1C,KAAK,UAAU,SAAS,WAAW,IACnC,KAAA;GACN,IAAI,OAAO,SAAS,WAAW,gBAAgB;IAC7C,MAAM,SAAS,aAAa,SAAS,KAAK,KAAK,CAAC,MAC9C,OAAO,OAAO,MAAM,IAAI,CAAC,CAC3B;IACA,IAAI,WAAW,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"}
@@ -76,7 +76,7 @@ async function developProject(context) {
76
76
  return;
77
77
  }
78
78
  if (built.digest === deployed) {
79
- console.error(tr("built in {elapsed}; it came out as deployed, so nothing was deployed", { elapsed: elapsed(started) }));
79
+ console.error(tr("built in {elapsed}; nothing changed", { elapsed: elapsed(started) }));
80
80
  return;
81
81
  }
82
82
  let result;
@@ -1 +1 @@
1
- {"version":3,"file":"develop.js","names":["sleep"],"sources":["../../../../src/cli/commands/project/develop.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { setTimeout as sleep } from \"node:timers/promises\";\n\nimport { AvailabilityChecker } from \"../../../availability\";\nimport { unauthenticated } from \"../../../client\";\nimport { attach } from \"../../../connection\";\nimport { tr } from \"../../../i18n\";\nimport { Ignorer, relativePath } from \"../../../ignore\";\nimport { printLog, serviceText } from \"../../../output\";\nimport { buildProject, loadProject } from \"../../../project\";\nimport { ServiceStatus } from \"../../../proto/swiplets_pb\";\nimport { defineCommand } from \"../../command\";\nimport { deploy, printDeployed } from \"../../deploy\";\nimport { deviceOption } from \"../flags\";\n\nconst rebuildDelay = 300;\nconst logReconnect = 2000;\n\nfunction elapsed(since) {\n const ms = Date.now() - since;\n if (ms < 1000) {\n return `${ms}ms`;\n }\n const seconds = ms / 1000;\n if (seconds < 60) {\n return `${Number(seconds.toFixed(3))}s`;\n }\n return `${Math.floor(seconds / 60)}m${Number((seconds % 60).toFixed(3))}s`;\n}\n\nasync function follow(signal, fatal, run) {\n let reported;\n while (!signal.aborted) {\n try {\n await run();\n } catch (error) {\n if (unauthenticated(error)) {\n fatal(error);\n return;\n }\n if (!signal.aborted && error.message !== reported) {\n reported = error.message;\n console.error(tr(\"error: {message}\", { message: error.message }));\n }\n }\n try {\n await sleep(logReconnect, undefined, { signal });\n } catch {\n return;\n }\n }\n}\n\nasync function developProject(context) {\n const { signal, printError } = context;\n const project = loadProject(path.resolve(context.args[0] ?? \".\"));\n const root = project.root;\n const client = await attach(context);\n const controller = new AbortController();\n const inner = AbortSignal.any([signal, controller.signal]);\n let fatalReject;\n const fatal = new Promise((_, reject) => {\n fatalReject = reject;\n });\n follow(inner, fatalReject, async () => {\n for await (const response of client.swiplets.watchServices(\n {},\n { signal: inner },\n )) {\n if (\n response.swipletId === project.config.id &&\n response.service?.status === ServiceStatus.FAILED\n ) {\n console.error(\n `${response.swipletId}: ${serviceText(response.swipletId, response.service)}`,\n );\n }\n }\n });\n if (!context.options[\"no-logs\"]) {\n follow(inner, fatalReject, async () => {\n for await (const response of client.logs.readLogs(\n { swipletId: project.config.id, follow: true },\n { signal: inner },\n )) {\n printLog(response.entry, false);\n }\n });\n }\n let deployed = \"\";\n const checker = new AvailabilityChecker();\n const cycle = async () => {\n const started = Date.now();\n let built;\n try {\n built = await buildProject(root, checker);\n } catch (error) {\n if (!inner.aborted) {\n console.error(tr(\"error: {message}\", { message: error.message }));\n }\n return;\n }\n if (built.digest === deployed) {\n console.error(\n tr(\n \"built in {elapsed}; it came out as deployed, so nothing was deployed\",\n { elapsed: elapsed(started) },\n ),\n );\n return;\n }\n let result;\n try {\n result = await deploy(client, built.archive, inner);\n } catch (error) {\n if (unauthenticated(error)) {\n throw error;\n }\n if (!inner.aborted) {\n printError(error, \"deploy\");\n }\n return;\n }\n deployed = built.digest;\n printDeployed(result, false);\n console.error(\n tr(\"built and deployed in {elapsed}; watching {directory}\", {\n elapsed: elapsed(started),\n directory: root,\n }),\n );\n };\n const watch = () =>\n new Promise<void>((resolve, reject) => {\n if (inner.aborted) {\n resolve();\n return;\n }\n let ignore = new Ignorer(root);\n let timer;\n const watcher = fs.watch(root, { recursive: true }, (_, filename) => {\n if (filename === null) {\n return;\n }\n const name = path.join(root, filename);\n if (path.basename(name) === \".gitignore\") {\n ignore = new Ignorer(root);\n }\n let isDirectory = false;\n try {\n isDirectory = fs.statSync(name).isDirectory();\n } catch {\n isDirectory = false;\n }\n const relative = relativePath(root, name);\n if (relative === \"\" || ignore.ignored(relative, isDirectory)) {\n return;\n }\n clearTimeout(timer);\n timer = setTimeout(() => cycle().catch(reject), rebuildDelay);\n });\n watcher.on(\"error\", (error) => printError(error, \"watch the project\"));\n inner.addEventListener(\n \"abort\",\n () => {\n clearTimeout(timer);\n watcher.close();\n resolve();\n },\n { once: true },\n );\n });\n try {\n await Promise.race([cycle().then(watch), fatal]);\n } finally {\n controller.abort();\n checker.close();\n }\n}\n\nexport const develop = defineCommand({\n name: \"develop\",\n use: \"develop [PROJECT]\",\n short: tr(\"Build, install and follow a swiplet project as it changes\"),\n args: [0, 1],\n options: {\n ...deviceOption,\n \"no-logs\": { type: \"boolean\", help: tr(\"without logs\") },\n },\n run: developProject,\n});\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAM,eAAe;AACrB,MAAM,eAAe;AAErB,SAAS,QAAQ,OAAO;CACtB,MAAM,KAAK,KAAK,IAAI,IAAI;CACxB,IAAI,KAAK,KACP,OAAO,GAAG,GAAG;CAEf,MAAM,UAAU,KAAK;CACrB,IAAI,UAAU,IACZ,OAAO,GAAG,OAAO,QAAQ,QAAQ,CAAC,CAAC,EAAE;CAEvC,OAAO,GAAG,KAAK,MAAM,UAAU,EAAE,EAAE,GAAG,QAAQ,UAAU,GAAA,CAAI,QAAQ,CAAC,CAAC,EAAE;AAC1E;AAEA,eAAe,OAAO,QAAQ,OAAO,KAAK;CACxC,IAAI;CACJ,OAAO,CAAC,OAAO,SAAS;EACtB,IAAI;GACF,MAAM,IAAI;EACZ,SAAS,OAAO;GACd,IAAI,gBAAgB,KAAK,GAAG;IAC1B,MAAM,KAAK;IACX;GACF;GACA,IAAI,CAAC,OAAO,WAAW,MAAM,YAAY,UAAU;IACjD,WAAW,MAAM;IACjB,QAAQ,MAAM,GAAG,oBAAoB,EAAE,SAAS,MAAM,QAAQ,CAAC,CAAC;GAClE;EACF;EACA,IAAI;GACF,MAAMA,aAAM,cAAc,KAAA,GAAW,EAAE,OAAO,CAAC;EACjD,QAAQ;GACN;EACF;CACF;AACF;AAEA,eAAe,eAAe,SAAS;CACrC,MAAM,EAAE,QAAQ,eAAe;CAC/B,MAAM,UAAU,YAAY,KAAK,QAAQ,QAAQ,KAAK,MAAM,GAAG,CAAC;CAChE,MAAM,OAAO,QAAQ;CACrB,MAAM,SAAS,MAAM,OAAO,OAAO;CACnC,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,QAAQ,YAAY,IAAI,CAAC,QA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C"}
1
+ {"version":3,"file":"develop.js","names":["sleep"],"sources":["../../../../src/cli/commands/project/develop.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { setTimeout as sleep } from \"node:timers/promises\";\n\nimport { AvailabilityChecker } from \"../../../availability\";\nimport { unauthenticated } from \"../../../client\";\nimport { attach } from \"../../../connection\";\nimport { tr } from \"../../../i18n\";\nimport { Ignorer, relativePath } from \"../../../ignore\";\nimport { printLog, serviceText } from \"../../../output\";\nimport { buildProject, loadProject } from \"../../../project\";\nimport { ServiceStatus } from \"../../../proto/swiplets_pb\";\nimport { defineCommand } from \"../../command\";\nimport { deploy, printDeployed } from \"../../deploy\";\nimport { deviceOption } from \"../flags\";\n\nconst rebuildDelay = 300;\nconst logReconnect = 2000;\n\nfunction elapsed(since) {\n const ms = Date.now() - since;\n if (ms < 1000) {\n return `${ms}ms`;\n }\n const seconds = ms / 1000;\n if (seconds < 60) {\n return `${Number(seconds.toFixed(3))}s`;\n }\n return `${Math.floor(seconds / 60)}m${Number((seconds % 60).toFixed(3))}s`;\n}\n\nasync function follow(signal, fatal, run) {\n let reported;\n while (!signal.aborted) {\n try {\n await run();\n } catch (error) {\n if (unauthenticated(error)) {\n fatal(error);\n return;\n }\n if (!signal.aborted && error.message !== reported) {\n reported = error.message;\n console.error(tr(\"error: {message}\", { message: error.message }));\n }\n }\n try {\n await sleep(logReconnect, undefined, { signal });\n } catch {\n return;\n }\n }\n}\n\nasync function developProject(context) {\n const { signal, printError } = context;\n const project = loadProject(path.resolve(context.args[0] ?? \".\"));\n const root = project.root;\n const client = await attach(context);\n const controller = new AbortController();\n const inner = AbortSignal.any([signal, controller.signal]);\n let fatalReject;\n const fatal = new Promise((_, reject) => {\n fatalReject = reject;\n });\n follow(inner, fatalReject, async () => {\n for await (const response of client.swiplets.watchServices(\n {},\n { signal: inner },\n )) {\n if (\n response.swipletId === project.config.id &&\n response.service?.status === ServiceStatus.FAILED\n ) {\n console.error(\n `${response.swipletId}: ${serviceText(response.swipletId, response.service)}`,\n );\n }\n }\n });\n if (!context.options[\"no-logs\"]) {\n follow(inner, fatalReject, async () => {\n for await (const response of client.logs.readLogs(\n { swipletId: project.config.id, follow: true },\n { signal: inner },\n )) {\n printLog(response.entry, false);\n }\n });\n }\n let deployed = \"\";\n const checker = new AvailabilityChecker();\n const cycle = async () => {\n const started = Date.now();\n let built;\n try {\n built = await buildProject(root, checker);\n } catch (error) {\n if (!inner.aborted) {\n console.error(tr(\"error: {message}\", { message: error.message }));\n }\n return;\n }\n if (built.digest === deployed) {\n console.error(\n tr(\"built in {elapsed}; nothing changed\", {\n elapsed: elapsed(started),\n }),\n );\n return;\n }\n let result;\n try {\n result = await deploy(client, built.archive, inner);\n } catch (error) {\n if (unauthenticated(error)) {\n throw error;\n }\n if (!inner.aborted) {\n printError(error, \"deploy\");\n }\n return;\n }\n deployed = built.digest;\n printDeployed(result, false);\n console.error(\n tr(\"built and deployed in {elapsed}; watching {directory}\", {\n elapsed: elapsed(started),\n directory: root,\n }),\n );\n };\n const watch = () =>\n new Promise<void>((resolve, reject) => {\n if (inner.aborted) {\n resolve();\n return;\n }\n let ignore = new Ignorer(root);\n let timer;\n const watcher = fs.watch(root, { recursive: true }, (_, filename) => {\n if (filename === null) {\n return;\n }\n const name = path.join(root, filename);\n if (path.basename(name) === \".gitignore\") {\n ignore = new Ignorer(root);\n }\n let isDirectory = false;\n try {\n isDirectory = fs.statSync(name).isDirectory();\n } catch {\n isDirectory = false;\n }\n const relative = relativePath(root, name);\n if (relative === \"\" || ignore.ignored(relative, isDirectory)) {\n return;\n }\n clearTimeout(timer);\n timer = setTimeout(() => cycle().catch(reject), rebuildDelay);\n });\n watcher.on(\"error\", (error) => printError(error, \"watch the project\"));\n inner.addEventListener(\n \"abort\",\n () => {\n clearTimeout(timer);\n watcher.close();\n resolve();\n },\n { once: true },\n );\n });\n try {\n await Promise.race([cycle().then(watch), fatal]);\n } finally {\n controller.abort();\n checker.close();\n }\n}\n\nexport const develop = defineCommand({\n name: \"develop\",\n use: \"develop [PROJECT]\",\n short: tr(\"Build, install and follow a swiplet project as it changes\"),\n args: [0, 1],\n options: {\n ...deviceOption,\n \"no-logs\": { type: \"boolean\", help: tr(\"without logs\") },\n },\n run: developProject,\n});\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAM,eAAe;AACrB,MAAM,eAAe;AAErB,SAAS,QAAQ,OAAO;CACtB,MAAM,KAAK,KAAK,IAAI,IAAI;CACxB,IAAI,KAAK,KACP,OAAO,GAAG,GAAG;CAEf,MAAM,UAAU,KAAK;CACrB,IAAI,UAAU,IACZ,OAAO,GAAG,OAAO,QAAQ,QAAQ,CAAC,CAAC,EAAE;CAEvC,OAAO,GAAG,KAAK,MAAM,UAAU,EAAE,EAAE,GAAG,QAAQ,UAAU,GAAA,CAAI,QAAQ,CAAC,CAAC,EAAE;AAC1E;AAEA,eAAe,OAAO,QAAQ,OAAO,KAAK;CACxC,IAAI;CACJ,OAAO,CAAC,OAAO,SAAS;EACtB,IAAI;GACF,MAAM,IAAI;EACZ,SAAS,OAAO;GACd,IAAI,gBAAgB,KAAK,GAAG;IAC1B,MAAM,KAAK;IACX;GACF;GACA,IAAI,CAAC,OAAO,WAAW,MAAM,YAAY,UAAU;IACjD,WAAW,MAAM;IACjB,QAAQ,MAAM,GAAG,oBAAoB,EAAE,SAAS,MAAM,QAAQ,CAAC,CAAC;GAClE;EACF;EACA,IAAI;GACF,MAAMA,aAAM,cAAc,KAAA,GAAW,EAAE,OAAO,CAAC;EACjD,QAAQ;GACN;EACF;CACF;AACF;AAEA,eAAe,eAAe,SAAS;CACrC,MAAM,EAAE,QAAQ,eAAe;CAC/B,MAAM,UAAU,YAAY,KAAK,QAAQ,QAAQ,KAAK,MAAM,GAAG,CAAC;CAChE,MAAM,OAAO,QAAQ;CACrB,MAAM,SAAS,MAAM,OAAO,OAAO;CACnC,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,QAAQ,YAAY,IAAI,CAAC,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P,CAAC"}
@@ -18,6 +18,7 @@ function loadSource(root) {
18
18
  const localizedNames = config.localizedNames ?? {};
19
19
  if (localizedNames === null || typeof localizedNames !== "object" || !Object.values(localizedNames).every((name) => typeof name === "string")) throw new Error(tr("\"source.localizedNames\" in package.json must map languages to names."));
20
20
  if (config.icon !== void 0 && (typeof config.icon?.symbol !== "string" || config.icon.color !== void 0 && typeof config.icon.color !== "string")) throw new Error(tr("\"source.icon\" in package.json must have a symbol and may have a color."));
21
+ if (config.icon?.symbolColor !== void 0 && typeof config.icon.symbolColor !== "string") throw new Error(tr("\"{field}\" in package.json must be a string.", { field: "source.icon.symbolColor" }));
21
22
  let prefix;
22
23
  if (config.url !== void 0) try {
23
24
  prefix = new URL(config.url.endsWith("/") ? config.url : `${config.url}/`);
@@ -106,7 +107,8 @@ function sourceCommand(root, given) {
106
107
  ...Object.keys(source.localizedNames).length > 0 ? { localizedNames: source.localizedNames } : {},
107
108
  ...source.config.icon ? { icon: {
108
109
  symbol: source.config.icon.symbol,
109
- ...source.config.icon.color ? { color: source.config.icon.color } : {}
110
+ ...source.config.icon.color ? { color: source.config.icon.color } : {},
111
+ ...source.config.icon.symbolColor ? { symbolColor: source.config.icon.symbolColor } : {}
110
112
  } } : {},
111
113
  ...image ? { image: located(image.name) } : {},
112
114
  swiplets: entries
@@ -1 +1 @@
1
- {"version":3,"file":"source.js","names":[],"sources":["../../../../src/cli/commands/project/source.ts"],"sourcesContent":["import { execFileSync } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport { tr } from \"../../../i18n\";\nimport { idPattern } from \"../../../project\";\nimport { defineCommand } from \"../../command\";\n\nconst manifestEntry = /^(?:[^/]+\\/)?manifest\\.json$/;\n\nfunction loadSource(root) {\n const manifest = JSON.parse(\n fs.readFileSync(path.join(root, \"package.json\"), \"utf8\"),\n );\n const config = manifest.source ?? {};\n for (const field of [\"name\", \"image\", \"url\"]) {\n if (config[field] !== undefined && typeof config[field] !== \"string\") {\n throw new Error(\n tr('\"{field}\" in package.json must be a string.', {\n field: `source.${field}`,\n }),\n );\n }\n }\n const localizedNames = config.localizedNames ?? {};\n if (\n localizedNames === null ||\n typeof localizedNames !== \"object\" ||\n !Object.values(localizedNames).every((name) => typeof name === \"string\")\n ) {\n throw new Error(\n tr(\n '\"source.localizedNames\" in package.json must map languages to names.',\n ),\n );\n }\n if (\n config.icon !== undefined &&\n (typeof config.icon?.symbol !== \"string\" ||\n (config.icon.color !== undefined &&\n typeof config.icon.color !== \"string\"))\n ) {\n throw new Error(\n tr(\n '\"source.icon\" in package.json must have a symbol and may have a color.',\n ),\n );\n }\n let prefix;\n if (config.url !== undefined) {\n try {\n prefix = new URL(\n config.url.endsWith(\"/\") ? config.url : `${config.url}/`,\n );\n } catch {\n throw new Error(\n tr('\"source.url\" in package.json isn\\'t an absolute URL.'),\n );\n }\n }\n const workspaces = Array.isArray(manifest.workspaces)\n ? manifest.workspaces\n : (manifest.workspaces?.packages ?? []);\n return { root, config, localizedNames, prefix, workspaces };\n}\n\nfunction workspaceSwiplets(source) {\n const files = [];\n for (const pattern of source.workspaces) {\n for (const directory of fs.globSync(pattern, { cwd: source.root }).sort()) {\n const project = path.join(source.root, directory, \"package.json\");\n if (!fs.existsSync(project)) {\n continue;\n }\n const id = JSON.parse(fs.readFileSync(project, \"utf8\")).swiplet?.id;\n if (typeof id !== \"string\") {\n continue;\n }\n const built = path.join(source.root, directory, \"dist\", `${id}.swiplet`);\n if (!fs.existsSync(built)) {\n throw new Error(\n tr(\"{file} is missing; build {directory} first.\", {\n file: path.relative(source.root, built),\n directory,\n }),\n );\n }\n files.push(built);\n }\n }\n return files;\n}\n\nfunction readSwiplet(file) {\n const entry = execFileSync(\"unzip\", [\"-Z1\", file], { encoding: \"utf8\" })\n .split(\"\\n\")\n .filter((name) => manifestEntry.test(name))\n .sort((a, b) => a.length - b.length)[0];\n if (entry === undefined) {\n throw new Error(`${file} has no manifest.json`);\n }\n const manifest = JSON.parse(\n execFileSync(\"unzip\", [\"-p\", file, entry], { encoding: \"utf8\" }),\n );\n if (typeof manifest.id !== \"string\" || !idPattern.test(manifest.id)) {\n throw new Error(`${file} has no valid swiplet id in its manifest`);\n }\n return { file, manifest, data: fs.readFileSync(file) };\n}\n\nfunction sourceCommand(root, given) {\n const source = loadSource(root);\n const files =\n given.length > 0\n ? given.map((file) => path.resolve(file))\n : workspaceSwiplets(source);\n if (files.length === 0) {\n throw new Error(\n tr(\n \"package.json lists no workspaces with swiplets; name the swiplets to list.\",\n ),\n );\n }\n const swiplets = new Map();\n for (const read of files.map(readSwiplet)) {\n const { id } = read.manifest;\n if (swiplets.has(id)) {\n throw new Error(\n tr(\"{id} is both {first} and {second}\", {\n id,\n first: swiplets.get(id).file,\n second: read.file,\n }),\n );\n }\n swiplets.set(id, read);\n }\n const image =\n source.config.image === undefined\n ? undefined\n : {\n name: path.basename(source.config.image),\n data: fs.readFileSync(path.resolve(root, source.config.image)),\n };\n const located = (name) =>\n source.prefix ? new URL(name, source.prefix).href : name;\n const dist = path.join(root, \"dist\");\n fs.rmSync(dist, { recursive: true, force: true });\n fs.mkdirSync(dist, { recursive: true });\n const entries = [...swiplets.keys()].map((id) => {\n const { manifest, data } = swiplets.get(id);\n const name = `${id}.swiplet`;\n fs.writeFileSync(path.join(dist, name), data);\n return {\n ...manifest,\n url: located(name),\n size: data.length,\n sha256: createHash(\"sha256\").update(data).digest(\"hex\"),\n };\n });\n if (image) {\n fs.writeFileSync(path.join(dist, image.name), image.data);\n }\n const index = {\n ...(source.config.name ? { name: source.config.name } : {}),\n ...(Object.keys(source.localizedNames).length > 0\n ? { localizedNames: source.localizedNames }\n : {}),\n ...(source.config.icon\n ? {\n icon: {\n symbol: source.config.icon.symbol,\n ...(source.config.icon.color\n ? { color: source.config.icon.color }\n : {}),\n },\n }\n : {}),\n ...(image ? { image: located(image.name) } : {}),\n swiplets: entries,\n };\n fs.writeFileSync(\n path.join(dist, \"swiplets.json\"),\n `${JSON.stringify(index, null, 2)}\\n`,\n );\n console.log(path.relative(process.cwd(), path.join(dist, \"swiplets.json\")));\n}\n\nexport const source = defineCommand({\n name: \"source\",\n use: \"source [SWIPLET...]\",\n short: tr(\"Collect the built swiplets into dist/ with a swiplets.json\"),\n args: [0, Infinity],\n run: ({ args }) => sourceCommand(process.cwd(), args),\n});\n"],"mappings":";;;;;;;;AASA,MAAM,gBAAgB;AAEtB,SAAS,WAAW,MAAM;CACxB,MAAM,WAAW,KAAK,MACpB,GAAG,aAAa,KAAK,KAAK,MAAM,cAAc,GAAG,MAAM,CACzD;CACA,MAAM,SAAS,SAAS,UAAU,CAAC;CACnC,KAAK,MAAM,SAAS;EAAC;EAAQ;EAAS;CAAK,GACzC,IAAI,OAAO,WAAW,KAAA,KAAa,OAAO,OAAO,WAAW,UAC1D,MAAM,IAAI,MACR,GAAG,iDAA+C,EAChD,OAAO,UAAU,QACnB,CAAC,CACH;CAGJ,MAAM,iBAAiB,OAAO,kBAAkB,CAAC;CACjD,IACE,mBAAmB,QACnB,OAAO,mBAAmB,YAC1B,CAAC,OAAO,OAAO,cAAc,CAAC,CAAC,OAAO,SAAS,OAAO,SAAS,QAAQ,GAEvE,MAAM,IAAI,MACR,GACE,wEACF,CACF;CAEF,IACE,OAAO,SAAS,KAAA,MACf,OAAO,OAAO,MAAM,WAAW,YAC7B,OAAO,KAAK,UAAU,KAAA,KACrB,OAAO,OAAO,KAAK,UAAU,WAEjC,MAAM,IAAI,MACR,GACE,0EACF,CACF;CAEF,IAAI;CACJ,IAAI,OAAO,QAAQ,KAAA,GACjB,IAAI;EACF,SAAS,IAAI,IACX,OAAO,IAAI,SAAS,GAAG,IAAI,OAAO,MAAM,GAAG,OAAO,IAAI,EACxD;CACF,QAAQ;EACN,MAAM,IAAI,MACR,GAAG,uDAAsD,CAC3D;CACF;CAEF,MAAM,aAAa,MAAM,QAAQ,SAAS,UAAU,IAChD,SAAS,aACR,SAAS,YAAY,YAAY,CAAC;CACv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IAAI;GACjB,MAAM,KAAK;GACX,QAAQ,WAAW,QAAQ,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK;EACxD;CACF,CAAC;CACD,IAAI,OACF,GAAG,cAAc,KAAK,KAAK,MAAM,MAAM,IAAI,GAAG,MAAM,IAAI;CAE1D,MAAM,QAAQ;EACZ,GAAI,OAAO,OAAO,OAAO,EAAE,MAAM,OAAO,OAAO,KAAK,IAAI,CAAC;EACzD,GAAI,OAAO,KAAK,OAAO,cAAc,CAAC,CAAC,SAAS,IAC5C,EAAE,gBAAgB,OAAO,eAAe,IACxC,CAAC;EACL,GAAI,OAAO,OAAO,OACd,EACE,MAAM;GACJ,QAAQ,OAAO,OAAO,KAAK;GAC3B,GAAI,OAAO,OAAO,KAAK,QACnB,EAAE,OAAO,OAAO,OAAO,KAAK,MAAM,IAClC,CAAC;EACP,EACF,IACA,CAAC;EACL,GAAI,QAAQ,EAAE,OAAO,QAAQ,MAAM,IAAI,EAAE,IAAI,CAAC;EAC9C,UAAU;CACZ;CACA,GAAG,cACD,KAAK,KAAK,MAAM,eAAe,GAC/B,GAAG,KAAK,UAAU,OAAO,MAAM,CAAC,EAAE,GACpC;CACA,QAAQ,IAAI,KAAK,SAAS,QAAQ,IAAI,GAAG,KAAK,KAAK,MAAM,eAAe,CAAC,CAAC;AAC5E;AAEA,MAAa,SAAS,cAAc;CAClC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,4DAA4D;CACtE,MAAM,CAAC,GAAG,QAAQ;CAClB,MAAM,EAAE,WAAW,cAAc,QAAQ,IAAI,GAAG,IAAI;AACtD,CAAC"}
1
+ {"version":3,"file":"source.js","names":[],"sources":["../../../../src/cli/commands/project/source.ts"],"sourcesContent":["import { execFileSync } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport { tr } from \"../../../i18n\";\nimport { idPattern } from \"../../../project\";\nimport { defineCommand } from \"../../command\";\n\nconst manifestEntry = /^(?:[^/]+\\/)?manifest\\.json$/;\n\nfunction loadSource(root) {\n const manifest = JSON.parse(\n fs.readFileSync(path.join(root, \"package.json\"), \"utf8\"),\n );\n const config = manifest.source ?? {};\n for (const field of [\"name\", \"image\", \"url\"]) {\n if (config[field] !== undefined && typeof config[field] !== \"string\") {\n throw new Error(\n tr('\"{field}\" in package.json must be a string.', {\n field: `source.${field}`,\n }),\n );\n }\n }\n const localizedNames = config.localizedNames ?? {};\n if (\n localizedNames === null ||\n typeof localizedNames !== \"object\" ||\n !Object.values(localizedNames).every((name) => typeof name === \"string\")\n ) {\n throw new Error(\n tr(\n '\"source.localizedNames\" in package.json must map languages to names.',\n ),\n );\n }\n if (\n config.icon !== undefined &&\n (typeof config.icon?.symbol !== \"string\" ||\n (config.icon.color !== undefined &&\n typeof config.icon.color !== \"string\"))\n ) {\n throw new Error(\n tr(\n '\"source.icon\" in package.json must have a symbol and may have a color.',\n ),\n );\n }\n if (\n config.icon?.symbolColor !== undefined &&\n typeof config.icon.symbolColor !== \"string\"\n ) {\n throw new Error(\n tr('\"{field}\" in package.json must be a string.', {\n field: \"source.icon.symbolColor\",\n }),\n );\n }\n let prefix;\n if (config.url !== undefined) {\n try {\n prefix = new URL(\n config.url.endsWith(\"/\") ? config.url : `${config.url}/`,\n );\n } catch {\n throw new Error(\n tr('\"source.url\" in package.json isn\\'t an absolute URL.'),\n );\n }\n }\n const workspaces = Array.isArray(manifest.workspaces)\n ? manifest.workspaces\n : (manifest.workspaces?.packages ?? []);\n return { root, config, localizedNames, prefix, workspaces };\n}\n\nfunction workspaceSwiplets(source) {\n const files = [];\n for (const pattern of source.workspaces) {\n for (const directory of fs.globSync(pattern, { cwd: source.root }).sort()) {\n const project = path.join(source.root, directory, \"package.json\");\n if (!fs.existsSync(project)) {\n continue;\n }\n const id = JSON.parse(fs.readFileSync(project, \"utf8\")).swiplet?.id;\n if (typeof id !== \"string\") {\n continue;\n }\n const built = path.join(source.root, directory, \"dist\", `${id}.swiplet`);\n if (!fs.existsSync(built)) {\n throw new Error(\n tr(\"{file} is missing; build {directory} first.\", {\n file: path.relative(source.root, built),\n directory,\n }),\n );\n }\n files.push(built);\n }\n }\n return files;\n}\n\nfunction readSwiplet(file) {\n const entry = execFileSync(\"unzip\", [\"-Z1\", file], { encoding: \"utf8\" })\n .split(\"\\n\")\n .filter((name) => manifestEntry.test(name))\n .sort((a, b) => a.length - b.length)[0];\n if (entry === undefined) {\n throw new Error(`${file} has no manifest.json`);\n }\n const manifest = JSON.parse(\n execFileSync(\"unzip\", [\"-p\", file, entry], { encoding: \"utf8\" }),\n );\n if (typeof manifest.id !== \"string\" || !idPattern.test(manifest.id)) {\n throw new Error(`${file} has no valid swiplet id in its manifest`);\n }\n return { file, manifest, data: fs.readFileSync(file) };\n}\n\nfunction sourceCommand(root, given) {\n const source = loadSource(root);\n const files =\n given.length > 0\n ? given.map((file) => path.resolve(file))\n : workspaceSwiplets(source);\n if (files.length === 0) {\n throw new Error(\n tr(\n \"package.json lists no workspaces with swiplets; name the swiplets to list.\",\n ),\n );\n }\n const swiplets = new Map();\n for (const read of files.map(readSwiplet)) {\n const { id } = read.manifest;\n if (swiplets.has(id)) {\n throw new Error(\n tr(\"{id} is both {first} and {second}\", {\n id,\n first: swiplets.get(id).file,\n second: read.file,\n }),\n );\n }\n swiplets.set(id, read);\n }\n const image =\n source.config.image === undefined\n ? undefined\n : {\n name: path.basename(source.config.image),\n data: fs.readFileSync(path.resolve(root, source.config.image)),\n };\n const located = (name) =>\n source.prefix ? new URL(name, source.prefix).href : name;\n const dist = path.join(root, \"dist\");\n fs.rmSync(dist, { recursive: true, force: true });\n fs.mkdirSync(dist, { recursive: true });\n const entries = [...swiplets.keys()].map((id) => {\n const { manifest, data } = swiplets.get(id);\n const name = `${id}.swiplet`;\n fs.writeFileSync(path.join(dist, name), data);\n return {\n ...manifest,\n url: located(name),\n size: data.length,\n sha256: createHash(\"sha256\").update(data).digest(\"hex\"),\n };\n });\n if (image) {\n fs.writeFileSync(path.join(dist, image.name), image.data);\n }\n const index = {\n ...(source.config.name ? { name: source.config.name } : {}),\n ...(Object.keys(source.localizedNames).length > 0\n ? { localizedNames: source.localizedNames }\n : {}),\n ...(source.config.icon\n ? {\n icon: {\n symbol: source.config.icon.symbol,\n ...(source.config.icon.color\n ? { color: source.config.icon.color }\n : {}),\n ...(source.config.icon.symbolColor\n ? { symbolColor: source.config.icon.symbolColor }\n : {}),\n },\n }\n : {}),\n ...(image ? { image: located(image.name) } : {}),\n swiplets: entries,\n };\n fs.writeFileSync(\n path.join(dist, \"swiplets.json\"),\n `${JSON.stringify(index, null, 2)}\\n`,\n );\n console.log(path.relative(process.cwd(), path.join(dist, \"swiplets.json\")));\n}\n\nexport const source = defineCommand({\n name: \"source\",\n use: \"source [SWIPLET...]\",\n short: tr(\"Collect the built swiplets into dist/ with a swiplets.json\"),\n args: [0, Infinity],\n run: ({ args }) => sourceCommand(process.cwd(), args),\n});\n"],"mappings":";;;;;;;;AASA,MAAM,gBAAgB;AAEtB,SAAS,WAAW,MAAM;CACxB,MAAM,WAAW,KAAK,MACpB,GAAG,aAAa,KAAK,KAAK,MAAM,cAAc,GAAG,MAAM,CACzD;CACA,MAAM,SAAS,SAAS,UAAU,CAAC;CACnC,KAAK,MAAM,SAAS;EAAC;EAAQ;EAAS;CAAK,GACzC,IAAI,OAAO,WAAW,KAAA,KAAa,OAAO,OAAO,WAAW,UAC1D,MAAM,IAAI,MACR,GAAG,iDAA+C,EAChD,OAAO,UAAU,QACnB,CAAC,CACH;CAGJ,MAAM,iBAAiB,OAAO,kBAAkB,CAAC;CACjD,IACE,mBAAmB,QACnB,OAAO,mBAAmB,YAC1B,CAAC,OAAO,OAAO,cAAc,CAAC,CAAC,OAAO,SAAS,OAAO,SAAS,QAAQ,GAEvE,MAAM,IAAI,MACR,GACE,wEACF,CACF;CAEF,IACE,OAAO,SAAS,KAAA,MACf,OAAO,OAAO,MAAM,WAAW,YAC7B,OAAO,KAAK,UAAU,K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;CACA,GAAG,cACD,KAAK,KAAK,MAAM,eAAe,GAC/B,GAAG,KAAK,UAAU,OAAO,MAAM,CAAC,EAAE,GACpC;CACA,QAAQ,IAAI,KAAK,SAAS,QAAQ,IAAI,GAAG,KAAK,KAAK,MAAM,eAAe,CAAC,CAAC;AAC5E;AAEA,MAAa,SAAS,cAAc;CAClC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,4DAA4D;CACtE,MAAM,CAAC,GAAG,QAAQ;CAClB,MAAM,EAAE,WAAW,cAAc,QAAQ,IAAI,GAAG,IAAI;AACtD,CAAC"}
@@ -32,13 +32,14 @@ const callAction = (context) => session(context, async (client) => {
32
32
  action,
33
33
  input
34
34
  }, { signal: context.signal })) if (response.part.case === "log") printLog(response.part.value, false);
35
+ else if (response.part.case === "value") console.log(JSON.stringify(toJson(ValueSchema, response.part.value)));
35
36
  else if (response.part.case === "result") result = response.part.value;
36
37
  if (result?.outcome.case === "output") {
37
38
  console.log(JSON.stringify(toJson(ValueSchema, result.outcome.value), null, 2));
38
39
  return;
39
40
  }
40
41
  if (result?.outcome.case === "error") throw printScriptError(result.outcome.value);
41
- throw new Error("the server sent no result");
42
+ if (result === void 0) throw new Error("the server sent no result");
42
43
  });
43
44
  const call = defineCommand({
44
45
  name: "call",
@@ -1 +1 @@
1
- {"version":3,"file":"call.js","names":[],"sources":["../../../../src/cli/commands/swiplet/call.ts"],"sourcesContent":["import fs from \"node:fs\";\n\nimport { fromJson, toJson } from \"@bufbuild/protobuf\";\nimport { ValueSchema } from \"@bufbuild/protobuf/wkt\";\n\nimport { UsageError } from \"../../../client\";\nimport { tr } from \"../../../i18n\";\nimport { printLog, printScriptError } from \"../../../output\";\nimport { defineCommand } from \"../../command\";\nimport { readStdin } from \"../../io\";\nimport { session } from \"../../session\";\n\nfunction readInput(value) {\n if (value === undefined || value === \"\") {\n return undefined;\n }\n let data = value;\n try {\n if (value === \"-\") {\n data = readStdin().toString();\n } else if (value.startsWith(\"@\")) {\n data = fs.readFileSync(value.slice(1), \"utf8\");\n }\n } catch (error) {\n throw new Error(`read --input: ${error.message}`);\n }\n try {\n return fromJson(ValueSchema, JSON.parse(data));\n } catch (error) {\n throw new UsageError(\n tr(\"--input isn't JSON: {error}\", { error: error.message }),\n );\n }\n}\n\nconst callAction = (context) =>\n session(context, async (client) => {\n const [id, action] = context.args;\n const input = readInput(context.options.input);\n let result;\n for await (const response of client.swiplets.callAction(\n { swipletId: id, action, input },\n { signal: context.signal },\n )) {\n if (response.part.case === \"log\") {\n printLog(response.part.value, false);\n } else if (response.part.case === \"result\") {\n result = response.part.value;\n }\n }\n if (result?.outcome.case === \"output\") {\n console.log(\n JSON.stringify(toJson(ValueSchema, result.outcome.value), null, 2),\n );\n return;\n }\n if (result?.outcome.case === \"error\") {\n throw printScriptError(result.outcome.value);\n }\n throw new Error(\"the server sent no result\");\n });\n\nexport const call = defineCommand({\n name: \"call\",\n use: \"call ID ACTION\",\n short: tr(\"Call a swiplet action\"),\n args: [2, 2],\n options: {\n input: {\n type: \"string\",\n value: \"JSON\",\n help: tr(\"input JSON, @FILE or -\"),\n },\n },\n run: callAction,\n});\n"],"mappings":";;;;;;;;;;AAYA,SAAS,UAAU,OAAO;CACxB,IAAI,UAAU,KAAA,KAAa,UAAU,IACnC;CAEF,IAAI,OAAO;CACX,IAAI;EACF,IAAI,UAAU,KACZ,OAAO,UAAU,CAAC,CAAC,SAAS;OACvB,IAAI,MAAM,WAAW,GAAG,GAC7B,OAAO,GAAG,aAAa,MAAM,MAAM,CAAC,GAAG,MAAM;CAEjD,SAAS,OAAO;EACd,MAAM,IAAI,MAAM,iBAAiB,MAAM,SAAS;CAClD;CACA,IAAI;EACF,OAAO,SAAS,aAAa,KAAK,MAAM,IAAI,CAAC;CAC/C,SAAS,OAAO;EACd,MAAM,IAAI,WACR,GAAG,+BAA+B,EAAE,OAAO,MAAM,QAAQ,CAAC,CAC5D;CACF;AACF;AAEA,MAAM,cAAc,YAClB,QAAQ,SAAS,OAAO,WAAW;CACjC,MAAM,CAAC,IAAI,UAAU,QAAQ;CAC7B,MAAM,QAAQ,UAAU,QAAQ,QAAQ,KAAK;CAC7C,IAAI;CACJ,WAAW,MAAM,YAAY,OAAO,SAAS,WAC3C;EAAE,WAAW;EAAI;EAAQ;CAAM,GAC/B,EAAE,QAAQ,QAAQ,OAAO,CAC3B,GACE,IAAI,SAAS,KAAK,SAAS,OACzB,SAAS,SAAS,KAAK,OAAO,KAAK;MAC9B,IAAI,SAAS,KAAK,SAAS,UAChC,SAAS,SAAS,KAAK;CAG3B,IAAI,QAAQ,QAAQ,SAAS,UAAU;EACrC,QAAQ,IACN,KAAK,UAAU,OAAO,aAAa,OAAO,QAAQ,KAAK,GAAG,MAAM,CAAC,CACnE;EACA;CACF;CACA,IAAI,QAAQ,QAAQ,SAAS,SAC3B,MAAM,iBAAiB,OAAO,QAAQ,KAAK;CAE7C,MAAM,IAAI,MAAM,2BAA2B;AAC7C,CAAC;AAEH,MAAa,OAAO,cAAc;CAChC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,uBAAuB;CACjC,MAAM,CAAC,GAAG,CAAC;CACX,SAAS,EACP,OAAO;EACL,MAAM;EACN,OAAO;EACP,MAAM,GAAG,wBAAwB;CACnC,EACF;CACA,KAAK;AACP,CAAC"}
1
+ {"version":3,"file":"call.js","names":[],"sources":["../../../../src/cli/commands/swiplet/call.ts"],"sourcesContent":["import fs from \"node:fs\";\n\nimport { fromJson, toJson } from \"@bufbuild/protobuf\";\nimport { ValueSchema } from \"@bufbuild/protobuf/wkt\";\n\nimport { UsageError } from \"../../../client\";\nimport { tr } from \"../../../i18n\";\nimport { printLog, printScriptError } from \"../../../output\";\nimport { defineCommand } from \"../../command\";\nimport { readStdin } from \"../../io\";\nimport { session } from \"../../session\";\n\nfunction readInput(value) {\n if (value === undefined || value === \"\") {\n return undefined;\n }\n let data = value;\n try {\n if (value === \"-\") {\n data = readStdin().toString();\n } else if (value.startsWith(\"@\")) {\n data = fs.readFileSync(value.slice(1), \"utf8\");\n }\n } catch (error) {\n throw new Error(`read --input: ${error.message}`);\n }\n try {\n return fromJson(ValueSchema, JSON.parse(data));\n } catch (error) {\n throw new UsageError(\n tr(\"--input isn't JSON: {error}\", { error: error.message }),\n );\n }\n}\n\nconst callAction = (context) =>\n session(context, async (client) => {\n const [id, action] = context.args;\n const input = readInput(context.options.input);\n let result;\n for await (const response of client.swiplets.callAction(\n { swipletId: id, action, input },\n { signal: context.signal },\n )) {\n if (response.part.case === \"log\") {\n printLog(response.part.value, false);\n } else if (response.part.case === \"value\") {\n console.log(JSON.stringify(toJson(ValueSchema, response.part.value)));\n } else if (response.part.case === \"result\") {\n result = response.part.value;\n }\n }\n if (result?.outcome.case === \"output\") {\n console.log(\n JSON.stringify(toJson(ValueSchema, result.outcome.value), null, 2),\n );\n return;\n }\n if (result?.outcome.case === \"error\") {\n throw printScriptError(result.outcome.value);\n }\n if (result === undefined) {\n throw new Error(\"the server sent no result\");\n }\n });\n\nexport const call = defineCommand({\n name: \"call\",\n use: \"call ID ACTION\",\n short: tr(\"Call a swiplet action\"),\n args: [2, 2],\n options: {\n input: {\n type: \"string\",\n value: \"JSON\",\n help: tr(\"input JSON, @FILE or -\"),\n },\n },\n run: callAction,\n});\n"],"mappings":";;;;;;;;;;AAYA,SAAS,UAAU,OAAO;CACxB,IAAI,UAAU,KAAA,KAAa,UAAU,IACnC;CAEF,IAAI,OAAO;CACX,IAAI;EACF,IAAI,UAAU,KACZ,OAAO,UAAU,CAAC,CAAC,SAAS;OACvB,IAAI,MAAM,WAAW,GAAG,GAC7B,OAAO,GAAG,aAAa,MAAM,MAAM,CAAC,GAAG,MAAM;CAEjD,SAAS,OAAO;EACd,MAAM,IAAI,MAAM,iBAAiB,MAAM,SAAS;CAClD;CACA,IAAI;EACF,OAAO,SAAS,aAAa,KAAK,MAAM,IAAI,CAAC;CAC/C,SAAS,OAAO;EACd,MAAM,IAAI,WACR,GAAG,+BAA+B,EAAE,OAAO,MAAM,QAAQ,CAAC,CAC5D;CACF;AACF;AAEA,MAAM,cAAc,YAClB,QAAQ,SAAS,OAAO,WAAW;CACjC,MAAM,CAAC,IAAI,UAAU,QAAQ;CAC7B,MAAM,QAAQ,UAAU,QAAQ,QAAQ,KAAK;CAC7C,IAAI;CACJ,WAAW,MAAM,YAAY,OAAO,SAAS,WAC3C;EAAE,WAAW;EAAI;EAAQ;CAAM,GAC/B,EAAE,QAAQ,QAAQ,OAAO,CAC3B,GACE,IAAI,SAAS,KAAK,SAAS,OACzB,SAAS,SAAS,KAAK,OAAO,KAAK;MAC9B,IAAI,SAAS,KAAK,SAAS,SAChC,QAAQ,IAAI,KAAK,UAAU,OAAO,aAAa,SAAS,KAAK,KAAK,CAAC,CAAC;MAC/D,IAAI,SAAS,KAAK,SAAS,UAChC,SAAS,SAAS,KAAK;CAG3B,IAAI,QAAQ,QAAQ,SAAS,UAAU;EACrC,QAAQ,IACN,KAAK,UAAU,OAAO,aAAa,OAAO,QAAQ,KAAK,GAAG,MAAM,CAAC,CACnE;EACA;CACF;CACA,IAAI,QAAQ,QAAQ,SAAS,SAC3B,MAAM,iBAAiB,OAAO,QAAQ,KAAK;CAE7C,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,MAAM,2BAA2B;AAE/C,CAAC;AAEH,MAAa,OAAO,cAAc;CAChC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,uBAAuB;CACjC,MAAM,CAAC,GAAG,CAAC;CACX,SAAS,EACP,OAAO;EACL,MAAM;EACN,OAAO;EACP,MAAM,GAAG,wBAAwB;CACnC,EACF;CACA,KAAK;AACP,CAAC"}
@@ -13,13 +13,7 @@ const showSwiplet = (context) => session(context, async (client) => {
13
13
  if (swiplet.service) console.log(tr("service: {status}", { status: serviceText(swiplet.id, swiplet.service) }));
14
14
  for (const action of swiplet.actions) {
15
15
  console.log();
16
- console.log(action.exposedToShortcuts ? tr("action {name} {title} (Shortcuts)", {
17
- name: action.name,
18
- title: JSON.stringify(action.title)
19
- }) : tr("action {name} {title}", {
20
- name: action.name,
21
- title: JSON.stringify(action.title)
22
- }));
16
+ console.log(action.name, JSON.stringify(action.title));
23
17
  if (action.description !== "") console.log(` ${action.description}`);
24
18
  if (action.inputSchema) console.log(` ${tr("input: {schema}", { schema: indented(action.inputSchema) })}`);
25
19
  if (action.outputSchema) console.log(` ${tr("output: {schema}", { schema: indented(action.outputSchema) })}`);
@@ -1 +1 @@
1
- {"version":3,"file":"show.js","names":[],"sources":["../../../../src/cli/commands/swiplet/show.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport { serviceText } from \"../../../output\";\nimport { defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\n\nconst indented = (value) =>\n JSON.stringify(value, null, 2).replaceAll(\"\\n\", \"\\n \");\n\nconst notInstalled = (id) =>\n new Error(tr(\"There is no swiplet {id}.\", { id: JSON.stringify(id) }));\n\nconst showSwiplet = (context) =>\n session(context, async (client) => {\n const { swiplets } = await client.swiplets.listSwiplets(\n {},\n { signal: context.signal },\n );\n const swiplet = swiplets.find((it) => it.id === context.args[0]);\n if (!swiplet) {\n throw notInstalled(context.args[0]);\n }\n console.log(swiplet.id, JSON.stringify(swiplet.title), swiplet.version);\n if (swiplet.service) {\n console.log(\n tr(\"service: {status}\", {\n status: serviceText(swiplet.id, swiplet.service),\n }),\n );\n }\n for (const action of swiplet.actions) {\n console.log();\n console.log(\n action.exposedToShortcuts\n ? tr(\"action {name} {title} (Shortcuts)\", {\n name: action.name,\n title: JSON.stringify(action.title),\n })\n : tr(\"action {name} {title}\", {\n name: action.name,\n title: JSON.stringify(action.title),\n }),\n );\n if (action.description !== \"\") {\n console.log(` ${action.description}`);\n }\n if (action.inputSchema) {\n console.log(\n ` ${tr(\"input: {schema}\", { schema: indented(action.inputSchema) })}`,\n );\n }\n if (action.outputSchema) {\n console.log(\n ` ${tr(\"output: {schema}\", { schema: indented(action.outputSchema) })}`,\n );\n }\n }\n });\n\nexport const show = defineCommand({\n name: \"show\",\n use: \"show ID\",\n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ACvE;CAEJ;AACF,CAAC;AAEH,MAAa,OAAO,cAAc;CAChC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,gBAAgB;CAC1B,MAAM,CAAC,GAAG,CAAC;CACX,KAAK;AACP,CAAC"}
1
+ {"version":3,"file":"show.js","names":[],"sources":["../../../../src/cli/commands/swiplet/show.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport { serviceText } from \"../../../output\";\nimport { defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\n\nconst indented = (value) =>\n JSON.stringify(value, null, 2).replaceAll(\"\\n\", \"\\n \");\n\nconst notInstalled = (id) =>\n new Error(tr(\"There is no swiplet {id}.\", { id: JSON.stringify(id) }));\n\nconst showSwiplet = (context) =>\n session(context, async (client) => {\n const { swiplets } = await client.swiplets.listSwiplets(\n {},\n { signal: context.signal },\n );\n const swiplet = swiplets.find((it) => it.id === context.args[0]);\n if (!swiplet) {\n throw notInstalled(context.args[0]);\n }\n console.log(swiplet.id, JSON.stringify(swiplet.title), swiplet.version);\n if (swiplet.service) {\n console.log(\n tr(\"service: {status}\", {\n status: serviceText(swiplet.id, swiplet.service),\n }),\n );\n }\n for (const action of swiplet.actions) {\n console.log();\n console.log(action.name, JSON.stringify(action.title));\n if (action.description !== \"\") {\n console.log(` ${action.description}`);\n }\n if (action.inputSchema) {\n console.log(\n ` ${tr(\"input: {schema}\", { schema: indented(action.inputSchema) })}`,\n );\n }\n if (action.outputSchema) {\n console.log(\n ` ${tr(\"output: {schema}\", { schema: indented(action.outputSchema) })}`,\n );\n }\n }\n });\n\nexport const show = defineCommand({\n name: \"show\",\n use: \"show ID\",\n short: tr(\"Show a swiplet\"),\n args: [1, 1],\n run: showSwiplet,\n});\n"],"mappings":";;;;;AAKA,MAAM,YAAY,UAChB,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC,CAAC,WAAW,MAAM,MAAM;AAExD,MAAM,gBAAgB,OACpB,IAAI,MAAM,GAAG,6BAA6B,EAAE,IAAI,KAAK,UAAU,EAAE,EAAE,CAAC,CAAC;AAEvE,MAAM,eAAe,YACnB,QAAQ,SAAS,OAAO,WAAW;CACjC,MAAM,EAAE,aAAa,MAAM,OAAO,SAAS,aACzC,CAAC,GACD,EAAE,QAAQ,QAAQ,OAAO,CAC3B;CACA,MAAM,UAAU,SAAS,MAAM,OAAO,GAAG,OAAO,QAAQ,KAAK,EAAE;CAC/D,IAAI,CAAC,SACH,MAAM,aAAa,QAAQ,KAAK,EAAE;CAEpC,QAAQ,IAAI,QAAQ,IAAI,KAAK,UAAU,QAAQ,KAAK,GAAG,QAAQ,OAAO;CACtE,IAAI,QAAQ,SACV,QAAQ,IACN,GAAG,qBAAqB,EACtB,QAAQ,YAAY,QAAQ,IAAI,QAAQ,OAAO,EACjD,CAAC,CACH;CAEF,KAAK,MAAM,UAAU,QAAQ,SAAS;EACpC,QAAQ,IAAI;EACZ,QAAQ,IAAI,OAAO,MAAM,KAAK,UAAU,OAAO,KAAK,CAAC;EACrD,IAAI,OAAO,gBAAgB,IACzB,QAAQ,IAAI,KAAK,OAAO,aAAa;EAEvC,IAAI,OAAO,aACT,QAAQ,IACN,KAAK,GAAG,mBAAmB,EAAE,QAAQ,SAAS,OAAO,WAAW,EAAE,CAAC,GACrE;EAEF,IAAI,OAAO,cACT,QAAQ,IACN,KAAK,GAAG,oBAAoB,EAAE,QAAQ,SAAS,OAAO,YAAY,EAAE,CAAC,GACvE;CAEJ;AACF,CAAC;AAEH,MAAa,OAAO,cAAc;CAChC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,gBAAgB;CAC1B,MAAM,CAAC,GAAG,CAAC;CACX,KAAK;AACP,CAAC"}
package/dist/client.js CHANGED
@@ -2,12 +2,14 @@ import { LogService } from "./proto/logs_pb.js";
2
2
  import { REPLService } from "./proto/repl_pb.js";
3
3
  import { SwipletService } from "./proto/swiplets_pb.js";
4
4
  import { SystemService } from "./proto/system_pb.js";
5
+ import { createRequire } from "node:module";
5
6
  import dns from "node:dns";
6
7
  import { create, fromBinary, toBinary } from "@bufbuild/protobuf";
7
8
  // src/client.ts
8
9
  const largestMessage = 128 << 20;
9
10
  const contentType = "application/grpc-web+proto";
10
11
  const webSocketSubprotocol = "grpc-websockets";
12
+ const { apiLevel } = createRequire(import.meta.url)("@swipt/api/package.json");
11
13
  dns.setDefaultResultOrder("ipv4first");
12
14
  const Code = {
13
15
  Canceled: 1,
@@ -95,7 +97,8 @@ function checkStatus(headers) {
95
97
  function requestHeaders(connection) {
96
98
  const headers = {
97
99
  "content-type": contentType,
98
- "x-grpc-web": "1"
100
+ "x-grpc-web": "1",
101
+ "swipt-api-level": String(apiLevel)
99
102
  };
100
103
  if (connection.token !== "") headers.authorization = `Bearer ${connection.token}`;
101
104
  return headers;