UNPKG

sheetxl

Version:

SheetXL - Command line tool

249 lines (248 loc) 14 kB
/** * @license sheetxl - SheetXL - Command line tool - v0.7.26 * * (C) 2025-present SheetXL Inc. & Michael T. Ford * License: The license can be found at https://www.sheetxl.com/license. */ import { a as e, e as t } from "../cli.js"; import "chalk"; import "fs"; import "path"; import "commander"; let n = null, r = null; const i = { compilerOptions: { target: "esnext" } }; const a = async () => "\n interface FirstTest {\n isTrue?: boolean;\n }\n", o = /* @__PURE__ */ new Map([["IReferenceRange", "r"], ["IRange", "l"]]), l = /* @__PURE__ */ new Map([["IWorkbook", "workbook"], ["ISheet", "sheet"], ["ICellRanges", "ranges"], ["ICellRange", "range"], ["IFormulaContext", "context"]]), s = (e2, t2) => { Array.from(t2.keys()).forEach((n2) => { const r2 = t2.get(n2); t2.set(`${e2}.${n2}`, r2); }); }, c = /* @__PURE__ */ new Map([["Scalar", "*"], ["FormulaError.Known", t.Error], ["Date", "Date"], ["JSON", "JSON"]]), d = /* @__PURE__ */ new Map([]), p = "SheetXL"; s(p, o), s(p, l), s(p, d); const u = /* @__PURE__ */ new Map([["Promise", () => ({ async: true })], ["Observable", () => ({ stream: true })]]); let m = null; async function f() { if (m) return m; try { return await (await import("./B8cIzTFZLJDxi4HN.js")).initialize(); } catch (e2) { throw m = null, e2; } finally { m = null; } } async function y(s2) { const d2 = s2?.source ?? null; if (!d2) return null; const p2 = (s2.disableBundle || s2.declarationsOnly) ?? false, m2 = [a(), f()], y2 = await Promise.all(m2), g = y2[0], h = y2[1]; let x = "", w = null; const b = [], T = { allowJs: true, declaration: false, sourceMap: false, inlineSourceMap: false, inlineSources: false, isolatedModules: true, preserveConstEnums: false, module: 99, noResolve: true, emitDeclarationOnly: false, target: h.ScriptTarget.ES2020 }, S = "script", k = `${S}.ts`, E = "lib.d.ts", K = "global.d.ts", $ = { [k]: d2, [E]: "\n/**\n * Represents the completion of an asynchronous operation\n */\ninterface Promise<T> {\n /**\n * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The\n * resolved value cannot be modified from the callback.\n * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).\n * @returns A Promise for the completion of the callback.\n */\n finally(onfinally?: (() => void) | undefined | null): Promise<T>;\n}\n", [K]: g }, v = { getSourceFile: (e2, t2, n2, r2) => h.createSourceFile(e2, $[e2], h.ScriptTarget.Latest, true), fileExists: (e2) => void 0 !== $[e2], readFile: (e2) => $[e2], writeFile: (e2, t2) => { $[e2] = t2; }, getCurrentDirectory: () => "./", getCanonicalFileName: (e2) => e2, useCaseSensitiveFileNames: () => true, getDefaultLibFileName: (e2) => E, getNewLine: () => "\n" }, F = h.createProgram([k, K], T, v), z = F.getTypeChecker(), C = F.getSourceFile(k), D = F.emit(); D.diagnostics.length > 0 && console.warn(D.diagnostics), x = $[`${S}.js`]; const N = (e2, n2, r2, i2) => { if (e2) { if (e2.kind === h.SyntaxKind.NumberKeyword) n2.scalar = t.Number; else if (e2.kind === h.SyntaxKind.StringKeyword) n2.scalar = t.String; else if (e2.kind === h.SyntaxKind.BooleanKeyword) n2.scalar = t.Boolean; else if (e2.kind === h.SyntaxKind.UndefinedKeyword || e2.kind === h.SyntaxKind.NullKeyword || e2.kind === h.SyntaxKind.VoidKeyword) { if (i2) return void R(e2, new Error(`'undefined' is not a valid type for input: '${e2?.parent?.name?.escapedText}'.`)); n2.scalar = t.Null; } else if (e2.kind === h.SyntaxKind.BigIntKeyword) n2.scalar = t.Number; else if (e2.kind === h.SyntaxKind.AnyKeyword) n2.scalar = t.Null; else if (e2.kind === h.SyntaxKind.ArrayType) { const t2 = e2.elementType; if (!t2) return void R(e2, new Error(`'Array' must be typed: '${e2?.parent?.name?.escapedText}'.`)); n2.arrayDepth = (n2.arrayDepth ?? 0) + 1, N(t2, n2, r2, i2); } else if (e2.kind !== h.SyntaxKind.TupleType && e2.kind === h.SyntaxKind.TypeReference) { const t2 = e2.typeName?.getText?.() ?? null, a2 = o.get(t2); let s3 = false; a2 && (n2.range = a2, s3 = true); const d3 = c.get(t2); if (d3 && (n2.scalar = d3), void 0 !== d3 && (s3 = true), i2) { const e3 = l.get(t2); if (e3) return e3; } else { const r3 = u.get(t2); if (r3) { const i3 = { ...n2, ...r3() }; let a3 = 0; if (i3.async && a3++, i3.stream && a3++, a3 > 1) return void R(e2, new Error(`'${t2}' cannot have multiple modifiers: '${e2?.parent?.name?.escapedText}'.`)); n2 = i3, s3 = true; } } if (!s3) return void R("node", new Error(`'${t2}' is not a valid type: '${e2?.parent?.name?.escapedText}'.`)); const p3 = e2.typeArguments; if (p3) { if (1 !== p3.length) return void R(e2, new Error(`'${t2}' must be typed with exactly 1 type: '${e2?.parent?.name?.escapedText}'.`)); N(p3[0], n2, r2, i2); } } } else R(e2, new Error(`Type is not defined for '${n2?.name ?? "return"}'.`)); }, L = [], R = (e2, t2) => { L.push(t2); }; if (h.forEachChild(C, (e2) => { if (n2 = e2, 0 !== (h.getCombinedModifierFlags(n2) & h.ModifierFlags.Export) && h.isFunctionDeclaration(e2)) { const n3 = {}, r2 = { parameters: {} }, i2 = e2?.name?.getText(); try { n3.name = i2; const a2 = z.getSymbolAtLocation(e2.name).getDocumentationComment(z); if (a2 && a2.length > 0 && a2[0].text) { let e3 = a2[0].text; e3 = e3.replace(/[\r\n]+/g, "\\n").trim(), r2.summary = e3; } const o2 = {}; N(e2.type, o2, n3, false), n3.returnType = o2; const l2 = {}; t2 = e2, 0 !== (h.getCombinedModifierFlags(t2) & h.ModifierFlags.Default) && (l2.default = true, w = i2), Object.keys(l2).length > 0 && (n3.behavior = l2), n3.parameters = []; const s3 = /* @__PURE__ */ new Map(); for (let t3 = 0; t3 < e2.parameters.length; t3++) { const i3 = e2.parameters[t3], a3 = {}; a3.name = i3.name?.getText(); const o3 = N(i3.type, a3, n3, true); if (o3) { if (0 !== n3.parameters.length) { const t4 = e2?.parent, r3 = t4?.name?.getText(); return void R(e2, new Error(`'${n3.name}' contexts must be the first parameter: '${r3}'.`)); } n3.context = o3; continue; } let l3; if ((void 0 !== i3.initializer && null !== i3.initializer || void 0 !== i3.questionToken && null !== i3.questionToken) && (a3.optional = true, i3.initializer)) try { l3 = i3.initializer.kind === h.SyntaxKind.StringLiteral ? i3.initializer.text : i3.initializer.kind === h.SyntaxKind.NumericLiteral ? parseFloat(i3.initializer.text) : i3.initializer.kind === h.SyntaxKind.TrueKeyword || i3.initializer.kind === h.SyntaxKind.FalseKeyword ? i3.initializer.kind === h.SyntaxKind.TrueKeyword : i3.initializer.kind === h.SyntaxKind.NullKeyword ? null : i3.initializer.kind === h.SyntaxKind.ObjectLiteralExpression || i3.initializer.kind === h.SyntaxKind.ArrayLiteralExpression ? i3.initializer.getText() : i3.initializer.getText?.(); } catch (e3) { console.warn(`Couldn't extract default value for parameter '${a3.name}'`, e3); } i3.dotDotDotToken && (a3.rest = true), n3.parameters.push(a3); const c2 = { description: "" }; r2.parameters[a3.name] = c2; const d3 = z.getSymbolAtLocation(i3.name).getDocumentationComment(z); d3 && d3.length > 0 && d3[0].text && (c2.description = d3[0].text), void 0 !== l3 && (c2.defaultValue = l3), s3.set(a3.name, a3); } if (e2.jsDoc && e2.jsDoc.length > 0) { const t3 = e2.jsDoc, a3 = t3.length; for (let e3 = 0; e3 < a3; e3++) { const a4 = t3[e3]?.tags; if (!a4) continue; const o3 = a4.length; for (let e4 = 0; e4 < o3; e4++) { const t4 = a4[e4]; let o4 = t4?.tagName?.text; if (!o4) continue; o4 = o4.toLowerCase(); let l3 = t4.comment; const c2 = "hidden" === o4; if (("string" == typeof l3 || c2) && ("string" == typeof l3 && (l3 = l3.replace(/[\r\n]+/g, "\\n").trim()), c2 || !l3 || (l3 = l3.split(/\\n/)[0], l3 && 0 !== l3.length))) { if (l3 && "string" == typeof l3) { const e5 = /\{@link(code|plain)?\s+([^}|]+)(?:\s*\|\s*([^}]+))?\}/g; let t5, n4 = l3, i3 = []; for (; null !== (t5 = e5.exec(l3)); ) { const [e6, n5, r3, i4] = t5, a5 = [r3.trim()]; i4 && a5.push(i4.trim()); } l3 = n4, i3.length > 0 && "see" === o4 && (r2.links || (r2.links = []), r2.links.push(...i3)); } if ("name" === o4) { const e5 = l3; e5 !== i2 && (r2.name = e5); } else if ("description" !== o4) { if ("summary" === o4) { const e5 = l3; e5 && (r2.summary = e5); } else if ("param" === o4) { const e5 = t4.name?.text, n4 = s3.get(e5); if (!n4) { L.push(new Error(`Parameter '${e5}' not found in function '${i2}'.`)); continue; } if (t4.typeExpression && t4.typeExpression.type) try { const e6 = t4.typeExpression.type; if (e6.kind === h.SyntaxKind.UnionType) { const t5 = []; n4.enums = t5, e6.types.forEach((e7) => { if (e7.kind === h.SyntaxKind.LiteralType) { const n5 = e7.literal.text; n5 && t5.push(n5); } }); } } catch (e6) { console.warn("Error parsing JSDoc type expression:", e6); } } else if ("returns" === o4 || "return" === o4) n3.returnType.description = l3; else if ("category" === o4) r2.category = l3; else if ("hidden" === o4) { let e5 = true; const t5 = l3?.toLowerCase(); "false" === t5 ? e5 = false : "true" !== t5 && (e5 = l3), false !== e5 && (r2.hidden = e5 ?? true); } } } } } } 0 === Object.keys(n3.returnType).length && delete n3.returnType, b.push([n3, r2]); } catch (t3) { R(e2, new Error(`'${i2}': ${t3.message}`)); } } var t2, n2; }), L.length > 0) throw console.warn(L), new Error("There were compilation errors.", { cause: L }); if (0 === b.length) throw new Error("No exported functions."); const j = `${e.uuidV4()}-script`; try { p2 || 0 !== L.length || (x = await (async function(e2, t2, a2 = "/script.js", o2 = "__SHEETXL") { try { const e3 = await (async function() { if (n) return n; if (r) { if (await r, !n) throw new Error("ESBuild initialization promise resolved, but instance is not available."); return n; } let e4, t3; r = new Promise((n2, r2) => { e4 = n2, t3 = r2; }); try { const { initialize: t4 } = await import("./91_-DGaTnfcVu2iY.js"); return n = await t4(), e4(), n; } catch (e5) { throw console.error("Failed to import or initialize esbuild:", e5), r = null, t3(e5), e5; } })(), l2 = "@sheetxl/primitives", s3 = ` export const FormulaContext = globalThis.${o2}?.FormulaContext; export const ScalarType = globalThis.${o2}?.ScalarType; export const Observable = globalThis.${o2}?.Observable; export const IRange = globalThis.${o2}?.IRange; export const FormulaError = globalThis.${o2}?.FormulaError; // Add more exports as needed `, c2 = { name: "sheetxl-esbuild-in-memory", setup(e4) { const n2 = "sheetxl-" + (/* @__PURE__ */ new Date()).getTime(); e4.onResolve({ filter: new RegExp(`^(${a2.replace("/", "\\/")}|${l2})$`) }, (e5) => ({ path: e5.path, namespace: n2 })), e4.onResolve({ filter: /.*/ }, (e5) => { if (e5.namespace !== n2) return console.warn(`esbuild: Treating import "${e5.path}" as external.`), { path: e5.path, external: true }; }), e4.onLoad({ filter: /.*/, namespace: n2 }, (e5) => { let r2; if (e5.path === a2) r2 = t2; else { if (e5.path !== l2) return { errors: [{ text: `Cannot load unknown path in ${n2}: ${e5.path}` }] }; r2 = s3; } return { contents: r2, loader: "ts" }; }); } }, d3 = await e3.build({ entryPoints: [a2], bundle: true, write: false, format: "esm", plugins: [c2], sourcemap: "inline", tsconfigRaw: i, minify: true, platform: "neutral" }); if (d3.outputFiles && d3.outputFiles.length > 0) return d3.outputFiles[0].text; throw d3.errors && d3.errors.length > 0 ? new Error(`esbuild bundling failed: ${d3.errors.map((e4) => e4.text).join("\n")}`) : new Error("esbuild did not produce an output file."); } catch (e3) { throw console.error("esbuild bundling process failed:", e3), e3; } })(0, x, S)); } catch { console.warn("Error bundling script"); } const M = { functions: b, commitId: j, source: d2, name: "Script", language: "typescript", compiled: x }; return w && (M.autoRun = w), M; } export { y as compileModule };