@vttforge/cli 0.18.10 → 0.18.11

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @vttforge/cli
2
2
 
3
+ ## 0.18.11
4
+
5
+ ### Patch Changes
6
+
7
+ - ce029bd: `vttforge migrate` no longer breaks a file where `CONFIG.statusEffects = [...]` has no semicolon. It looked for the next `;` and took the following statement into the loop it wrote.
8
+
3
9
  ## 0.18.10
4
10
 
5
11
  ### Patch Changes
package/dist/bin.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCittyPlugin, defineCommand, runMain } from "citty";
3
- import { a as runDev, b as maskComments, g as definesName, h as bareUsePattern, i as runInit, m as LEGACY_GLOBALS, n as runLintCommand, p as REMOVED_UTILS, r as ScaffoldError, s as runBuild, t as VTTFORGE_CLI_VERSION, u as runAuditCommand, v as _internal, x as runReleaseRules } from "./src-kJwlrLLX.mjs";
3
+ import { a as runDev, b as maskComments, g as definesName, h as bareUsePattern, i as runInit, m as LEGACY_GLOBALS, n as runLintCommand, p as REMOVED_UTILS, r as ScaffoldError, s as runBuild, t as VTTFORGE_CLI_VERSION, u as runAuditCommand, v as _internal, x as runReleaseRules } from "./src-cI5dX2-l.mjs";
4
4
  import { dirname, join, relative, resolve } from "node:path";
5
5
  import { existsSync } from "node:fs";
6
6
  import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
@@ -2033,7 +2033,7 @@ const statusEffectsAssignment = (source) => {
2033
2033
  const start = match.index ?? 0;
2034
2034
  if (code[start] === "\0") continue;
2035
2035
  const valueStart = start + match[0].length;
2036
- const end = scanStatementEnd(source, valueStart);
2036
+ const end = scanStatementEnd(code, valueStart);
2037
2037
  if (end === -1) continue;
2038
2038
  const after = `for (const effect of ${source.slice(valueStart, end).trim()}) CONFIG.statusEffects[effect.id] = effect;`;
2039
2039
  notes.push({
@@ -2042,7 +2042,7 @@ const statusEffectsAssignment = (source) => {
2042
2042
  message: "The old assignment replaced the whole palette. This loop adds entries and keeps the core conditions. If the array left a core condition out on purpose, delete it by id: `delete CONFIG.statusEffects.<id>`. Entries use `name` and `img`; rename any `label` and `icon`."
2043
2043
  });
2044
2044
  output += source.slice(cursor, start) + after;
2045
- cursor = end + 1;
2045
+ cursor = source[end] === ";" ? end + 1 : end;
2046
2046
  changes.push({
2047
2047
  line: lineAt(source, start),
2048
2048
  before: source.slice(start, cursor).trim(),
@@ -2057,23 +2057,41 @@ const statusEffectsAssignment = (source) => {
2057
2057
  notes
2058
2058
  };
2059
2059
  };
2060
- /** Index of the `;` that ends a statement starting at `from`, brackets balanced. */
2061
- function scanStatementEnd(source, from) {
2060
+ /** What the end of a line can hold when the expression goes on, and the start of the next. */
2061
+ const GOES_ON_AFTER = /(?:[=*/%&|^<?:,.([{]|=>|(?<!\+)\+|(?<!-)-)$/;
2062
+ const GOES_ON_WITH = /^(?:[.?:*/%,([`&|^<>=]|!=|\+(?!\+)|-(?!-)|(?:in|instanceof|as|satisfies)\b)/;
2063
+ /**
2064
+ * Index where the expression at `from` ends: its `;`, the `}` of the block
2065
+ * around it, or the last character before the line break that ends it in code
2066
+ * without semicolons. -1 when it is not a statement. `code` has its comments masked.
2067
+ */
2068
+ function scanStatementEnd(code, from) {
2062
2069
  let depth = 0;
2063
2070
  let quote = null;
2064
- for (let i = from; i < source.length; i += 1) {
2065
- const ch = source[i] ?? "";
2071
+ let end = from;
2072
+ for (let i = from; i < code.length; i += 1) {
2073
+ const ch = code[i] ?? "";
2066
2074
  if (quote) {
2067
2075
  if (ch === "\\") i += 1;
2068
2076
  else if (ch === quote) quote = null;
2077
+ end = i + 1;
2069
2078
  continue;
2070
2079
  }
2080
+ if (ch === "\n" && depth === 0 && end > from) {
2081
+ const next = code.slice(i).replace(/^[\s\0]+/, "");
2082
+ if (!(GOES_ON_AFTER.test(code.slice(from, end)) || GOES_ON_WITH.test(next))) return end;
2083
+ }
2084
+ if (ch === "\0" || /\s/.test(ch)) continue;
2085
+ if (ch === ";" && depth === 0) return i;
2071
2086
  if (ch === "\"" || ch === "'" || ch === "`") quote = ch;
2072
2087
  else if (ch === "{" || ch === "[" || ch === "(") depth += 1;
2073
- else if (ch === "}" || ch === "]" || ch === ")") depth -= 1;
2074
- else if (ch === ";" && depth === 0) return i;
2088
+ else if (ch === "}" || ch === "]" || ch === ")") {
2089
+ if (depth === 0) return ch === "}" ? end : -1;
2090
+ depth -= 1;
2091
+ }
2092
+ end = i + 1;
2075
2093
  }
2076
- return -1;
2094
+ return depth === 0 && !quote && end > from ? end : -1;
2077
2095
  }
2078
2096
  const EFFECT_MODES = {
2079
2097
  CUSTOM: "custom",