lecodes-cli 2.0.10 → 2.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -52,7 +52,7 @@ var package_default;
52
52
  var init_package = __esm(() => {
53
53
  package_default = {
54
54
  name: "lecodes-cli",
55
- version: "2.0.10",
55
+ version: "2.0.12",
56
56
  dependencies: {
57
57
  "@letary/chisel": "^0.13.0",
58
58
  jimp: "^1.6.1",
@@ -76,7 +76,7 @@ var init_package = __esm(() => {
76
76
  },
77
77
  peerDependencies: {
78
78
  "lecodes-design": "^0.11.0",
79
- "lecodes-headless": "^2.0.10",
79
+ "lecodes-headless": "^2.0.12",
80
80
  "lecodes-3d-editor": "^0.9.0",
81
81
  "lecodes-assets": "^0.2.1",
82
82
  "heic-decode": "^2.1.0",
@@ -146,7 +146,7 @@ var init_package = __esm(() => {
146
146
  });
147
147
 
148
148
  // ../../sdk/src/version.ts
149
- var SDK_VERSION = "2.0.10", sdkMajor = (version) => {
149
+ var SDK_VERSION = "2.0.12", sdkMajor = (version) => {
150
150
  const m = version?.match(/^(\d+)\.\d+\.\d+/);
151
151
  return m ? Number(m[1]) : null;
152
152
  }, bundleSdkVersion = (head) => head.slice(0, 2000).match(/^\/\/ sdk: (\d+\.\d+\.\d+\S*)/m)?.[1] ?? null, bundleRunsOn = (bundleVersion, hostVersion) => sdkMajor(bundleVersion) !== null && sdkMajor(bundleVersion) === sdkMajor(hostVersion);
@@ -169992,7 +169992,7 @@ var normalizePath2 = (path) => {
169992
169992
  parts.push(part);
169993
169993
  }
169994
169994
  return "/" + parts.join("/");
169995
- }, EndpointTypeError, SyncEndpointError, WrongSideGlobalError, injectNames = (ts, source) => {
169995
+ }, EndpointTypeError, ServerHelperImportError, WrongSideGlobalError, injectNames = (ts, source) => {
169996
169996
  const out = new Set;
169997
169997
  const sf = ts.createSourceFile("inject.ts", source, ts.ScriptTarget.ESNext, false);
169998
169998
  for (const st of sf.statements) {
@@ -170034,7 +170034,40 @@ var normalizePath2 = (path) => {
170034
170034
  visit(sf);
170035
170035
  }
170036
170036
  return out;
170037
- }, FILE_TYPE_PATH = "/__lecodes/file.d.ts", deriveEndpointParams = async (entries, modules, typescript) => {
170037
+ }, FILE_TYPE_PATH = "/__lecodes/file.d.ts", helperImports = (ts, program, checker, modules, projectFiles) => {
170038
+ const kinds = new Map(Object.entries(modules).map(([path, exports]) => [normalizePath2(path), new Map(exports.map((e) => [e.name, e.kind]))]));
170039
+ const out = [];
170040
+ for (const sf of program.getSourceFiles()) {
170041
+ if (!projectFiles.has(sf.fileName) || sf.isDeclarationFile || isServerPath(sf.fileName))
170042
+ continue;
170043
+ const file = serverModuleId(sf.fileName);
170044
+ for (const statement of sf.statements) {
170045
+ if (!ts.isImportDeclaration(statement) || !statement.importClause?.namedBindings || !ts.isNamedImports(statement.importClause.namedBindings))
170046
+ continue;
170047
+ if (statement.importClause.isTypeOnly)
170048
+ continue;
170049
+ for (const spec of statement.importClause.namedBindings.elements) {
170050
+ if (spec.isTypeOnly)
170051
+ continue;
170052
+ let symbol = checker.getSymbolAtLocation(spec.name);
170053
+ if (symbol && symbol.flags & ts.SymbolFlags.Alias)
170054
+ symbol = checker.getAliasedSymbol(symbol);
170055
+ const decl = symbol?.valueDeclaration ?? symbol?.declarations?.[0];
170056
+ if (!symbol || !decl)
170057
+ continue;
170058
+ const target = normalizePath2(decl.getSourceFile().fileName);
170059
+ const name = (spec.propertyName ?? spec.name).text;
170060
+ if (kinds.get(target)?.get(name) !== "other")
170061
+ continue;
170062
+ if (checker.getTypeOfSymbolAtLocation(symbol, decl).getCallSignatures().length === 0)
170063
+ continue;
170064
+ const { line } = sf.getLineAndCharacterOfPosition(spec.getStart(sf));
170065
+ out.push(`${file}:${line + 1}: ${name} of ${serverModuleId(target)}`);
170066
+ }
170067
+ }
170068
+ }
170069
+ return out;
170070
+ }, deriveEndpointParams = async (entries, modules, typescript) => {
170038
170071
  let ts;
170039
170072
  if (typescript)
170040
170073
  ts = typescript;
@@ -170091,8 +170124,6 @@ var normalizePath2 = (path) => {
170091
170124
  const params = {};
170092
170125
  const warnings = [];
170093
170126
  const problems = [];
170094
- const sync2 = [];
170095
- const awaitable = (type) => !!(type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) || (type.flags & ts.TypeFlags.Union ? type.types.every(awaitable) : !!type.getProperty("then"));
170096
170127
  for (const [path, exports] of Object.entries(modules)) {
170097
170128
  const sf = program.getSourceFile(normalizePath2(path));
170098
170129
  if (!sf) {
@@ -170137,10 +170168,6 @@ var normalizePath2 = (path) => {
170137
170168
  warnings.push(`${where}: not callable — unvalidated`);
170138
170169
  continue;
170139
170170
  }
170140
- if (ex.kind === "fn" && !awaitable(checker.getReturnTypeOfSignature(sig))) {
170141
- const { line } = sf.getLineAndCharacterOfPosition(decl.getStart(sf));
170142
- sync2.push(`${serverModuleId(path)}:${line + 1}: ${ex.name} — write \`async\` before it`);
170143
- }
170144
170171
  const list = [];
170145
170172
  for (const p of sig.getParameters()) {
170146
170173
  const pd = p.valueDeclaration;
@@ -170164,11 +170191,12 @@ var normalizePath2 = (path) => {
170164
170191
  }
170165
170192
  if (problems.length)
170166
170193
  throw new EndpointTypeError(problems);
170167
- if (sync2.length)
170168
- throw new SyncEndpointError(sync2);
170169
170194
  const wrongSide = wrongSideGlobals(ts, program, checker, new Set(files.keys()));
170170
170195
  if (wrongSide.length)
170171
170196
  throw new WrongSideGlobalError(wrongSide);
170197
+ const helpers = helperImports(ts, program, checker, modules, new Set(files.keys()));
170198
+ if (helpers.length)
170199
+ throw new ServerHelperImportError(helpers);
170172
170200
  const unawaited = [];
170173
170201
  for (const path of Object.keys(modules)) {
170174
170202
  const sf = program.getSourceFile(normalizePath2(path));
@@ -170341,13 +170369,13 @@ var init_serverTypes = __esm(() => {
170341
170369
  this.problems = problems;
170342
170370
  }
170343
170371
  };
170344
- SyncEndpointError = class SyncEndpointError extends Error {
170372
+ ServerHelperImportError = class ServerHelperImportError extends Error {
170345
170373
  problems;
170346
170374
  constructor(problems) {
170347
- super(`an endpoint is called over the network, so in the app its result is a promise — declare it async:
170375
+ super(`a function of a server file that is not async is a helper of the server, for server files only — the app calls endpoints, which are \`export async function\`:
170348
170376
  ${problems.join(`
170349
170377
  `)}`);
170350
- this.name = "SyncEndpointError";
170378
+ this.name = "ServerHelperImportError";
170351
170379
  this.problems = problems;
170352
170380
  }
170353
170381
  };
@@ -170428,24 +170456,10 @@ var SERVER_FILE, isServerPath = (path) => SERVER_FILE.test(path), serverModuleId
170428
170456
  const s = init.trimStart();
170429
170457
  if (/^channel\s*[<(]/.test(s))
170430
170458
  return "channel";
170431
- if (/^(async\s+)?function\b/.test(s))
170459
+ if (/^async\s+function\b/.test(s))
170432
170460
  return "fn";
170433
170461
  if (/^async\b/.test(s))
170434
170462
  return "fn";
170435
- if (new RegExp(`^${IDENT}\\s*=>`).test(s))
170436
- return "fn";
170437
- if (/^\(/.test(s)) {
170438
- let depth = 0;
170439
- for (let i = 0;i < s.length; i++) {
170440
- if (s[i] === "(")
170441
- depth++;
170442
- else if (s[i] === ")") {
170443
- depth--;
170444
- if (depth === 0)
170445
- return /^\s*(:[^=]*)?=>/.test(s.slice(i + 1)) ? "fn" : "other";
170446
- }
170447
- }
170448
- }
170449
170463
  return "other";
170450
170464
  }, scanServerExports = (source, path = "<server module>") => {
170451
170465
  const src = blankCommentsAndStrings(source);
@@ -170461,7 +170475,7 @@ var SERVER_FILE, isServerPath = (path) => SERVER_FILE.test(path), serverModuleId
170461
170475
  found.push({ at, name, kind });
170462
170476
  };
170463
170477
  for (const m of src.matchAll(new RegExp(`(^|\\n)\\s*export\\s+(async\\s+)?function\\s*\\*?\\s*(${IDENT})`, "g")))
170464
- add(m.index, m[3], "fn");
170478
+ add(m.index, m[3], m[2] ? "fn" : "other");
170465
170479
  for (const m of src.matchAll(new RegExp(`(^|\\n)\\s*export\\s+(?:const|let|var)\\s+(${IDENT})\\s*(?::[^=]*?)?=\\s*([^\\n]*)`, "g"))) {
170466
170480
  add(m.index, m[2], classifyInit(m[3]));
170467
170481
  }
@@ -170474,7 +170488,7 @@ var SERVER_FILE, isServerPath = (path) => SERVER_FILE.test(path), serverModuleId
170474
170488
  continue;
170475
170489
  const name = exported ?? local;
170476
170490
  let kind = "other";
170477
- if (new RegExp(`(^|\\n)\\s*(async\\s+)?function\\s*\\*?\\s*${local}\\b`).test(src))
170491
+ if (new RegExp(`(^|\\n)\\s*async\\s+function\\s*\\*?\\s*${local}\\b`).test(src))
170478
170492
  kind = "fn";
170479
170493
  else {
170480
170494
  const decl = src.match(new RegExp(`(^|\\n)\\s*(?:const|let|var)\\s+${local}\\s*(?::[^=]*?)?=\\s*([^\\n]*)`));
@@ -172209,7 +172223,7 @@ __export(exports_compile, {
172209
172223
  WrongSideGlobalError: () => WrongSideGlobalError,
172210
172224
  UnawaitedUserQueryError: () => UnawaitedUserQueryError,
172211
172225
  TARGET_MATRIX_GENERATION: () => TARGET_MATRIX_GENERATION,
172212
- SyncEndpointError: () => SyncEndpointError,
172226
+ ServerHelperImportError: () => ServerHelperImportError,
172213
172227
  SERVER_INJECT: () => SERVER_INJECT,
172214
172228
  SERVER_ENTRY_PATH: () => SERVER_ENTRY_PATH,
172215
172229
  SDK_VERSION: () => SDK_VERSION,
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "lecodes-cli",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "dependencies": {
5
5
  "@letary/chisel": "^0.13.0",
6
6
  "jimp": "^1.6.1",
7
- "lecodes-sdk": "2.0.10"
7
+ "lecodes-sdk": "2.0.12"
8
8
  },
9
9
  "devDependencies": {
10
10
  "lecodes-design": "https://storage.yandexcloud.net/le-codes/releases/packages/lecodes-design/lecodes-design-0.11.0.tgz",
11
- "lecodes-headless": "2.0.10",
11
+ "lecodes-headless": "2.0.12",
12
12
  "qrcode-terminal": "^0.12.0",
13
13
  "lecodes-3d-editor": "https://storage.yandexcloud.net/le-codes/releases/packages/lecodes-3d-editor/lecodes-3d-editor-0.9.0.tgz",
14
14
  "lecodes-assets": "0.2.1",
15
15
  "lecodes-creator-nav": "0.19.0",
16
- "lecodes-gl-lite": "2.0.10",
17
- "lecodes-web-frame": "2.0.10",
18
- "lecodes-web-player": "2.0.10",
19
- "lecodes-web-shared": "2.0.10",
16
+ "lecodes-gl-lite": "2.0.12",
17
+ "lecodes-web-frame": "2.0.12",
18
+ "lecodes-web-player": "2.0.12",
19
+ "lecodes-web-shared": "2.0.12",
20
20
  "lecodes-web-lite": "2.0.2",
21
21
  "heic-decode": "^2.1.0",
22
22
  "marcidb-embedded": "^0.14.1",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "peerDependencies": {
26
26
  "lecodes-design": "^0.11.0",
27
- "lecodes-headless": "^2.0.10",
27
+ "lecodes-headless": "^2.0.12",
28
28
  "lecodes-3d-editor": "^0.9.0",
29
29
  "lecodes-assets": "^0.2.1",
30
30
  "heic-decode": "^2.1.0",