@githubnext/vitale
Advanced tools
Comparing version
102
dist/cli.js
@@ -7,3 +7,3 @@ #!/usr/bin/env node | ||
// package.json | ||
var version = "0.0.13"; | ||
var version = "0.0.14"; | ||
@@ -24,4 +24,4 @@ // src/server.ts | ||
import * as babelTypes from "@babel/types"; | ||
var babelGenerator = _babelGenerator.default; | ||
var babelTraverse = _babelTraverse.default; | ||
var babelGenerator = typeof _babelGenerator === "function" ? _babelGenerator : _babelGenerator.default; | ||
var babelTraverse = typeof _babelTraverse === "function" ? _babelTraverse : _babelTraverse.default; | ||
var reactImports = babelParser.parse( | ||
@@ -36,9 +36,12 @@ ` | ||
` | ||
ReactDOM.createRoot( | ||
document.getElementById(__vitale_cell_output_root_id__) | ||
).render( | ||
<React.StrictMode> | ||
{__vitale_jsx_expression__} | ||
</React.StrictMode> | ||
); | ||
const __vitale_cell_output_element = document.getElementById(__vitale_cell_output_root_id__); | ||
if (__vitale_cell_output_element) { | ||
ReactDOM.createRoot( | ||
__vitale_cell_output_element | ||
).render( | ||
<React.StrictMode> | ||
{__vitale_jsx_expression__} | ||
</React.StrictMode> | ||
); | ||
} | ||
`, | ||
@@ -150,3 +153,8 @@ { sourceType: "module", plugins: ["jsx"] } | ||
}); | ||
const autoImports = []; | ||
const autoImports = [ | ||
babelTypes.importDeclaration( | ||
[babelTypes.importNamespaceSpecifier(babelTypes.identifier("Vitale"))], | ||
babelTypes.stringLiteral("@githubnext/vitale") | ||
) | ||
]; | ||
next: | ||
@@ -205,6 +213,10 @@ for (const name of unbound) { | ||
} | ||
const generatorResult = babelGenerator(ast); | ||
const generatorResult = babelGenerator( | ||
ast, | ||
{ sourceMaps: true, sourceFileName: id }, | ||
code | ||
); | ||
return { | ||
ast, | ||
code: generatorResult.code, | ||
map: generatorResult.map, | ||
type, | ||
@@ -380,2 +392,18 @@ autoExports | ||
// src/server.ts | ||
import * as Domain from "node:domain"; | ||
var originalStdoutWrite = process.stdout.write.bind(process.stdout); | ||
var originalStderrWrite = process.stderr.write.bind(process.stderr); | ||
var processWithDomain = process; | ||
process.stdout.write = (chunk, ...args) => { | ||
if (processWithDomain.domain && processWithDomain.domain.stdoutWrite) { | ||
processWithDomain.domain.stdoutWrite(Buffer.from(chunk)); | ||
} | ||
return originalStdoutWrite(chunk, ...args); | ||
}; | ||
process.stderr.write = (chunk, ...args) => { | ||
if (processWithDomain.domain && processWithDomain.domain.stderrWrite) { | ||
processWithDomain.domain.stderrWrite(Buffer.from(chunk)); | ||
} | ||
return originalStderrWrite(chunk, ...args); | ||
}; | ||
var trailingSeparatorRE = /[?&]$/; | ||
@@ -477,2 +505,13 @@ var timestampRE = /\bt=\d{13}&?\b/; | ||
} | ||
function rewriteStack(stack) { | ||
if (!stack) { | ||
return stack; | ||
} | ||
const i = stack.indexOf("\n at ESModulesRunner.runViteModule"); | ||
if (i !== -1) { | ||
return stack.substring(0, i); | ||
} else { | ||
return stack; | ||
} | ||
} | ||
var VitaleDevServer = class _VitaleDevServer { | ||
@@ -519,3 +558,3 @@ static async construct(options) { | ||
} | ||
return cell.sourceDescription.code; | ||
return cell.sourceDescription; | ||
}, | ||
@@ -602,2 +641,4 @@ configureServer(server) { | ||
let mime; | ||
const stdoutChunks = []; | ||
const stderrChunks = []; | ||
try { | ||
@@ -625,3 +666,12 @@ const cell = getCellById(this.cellsByPath, id); | ||
} else { | ||
let { default: result } = await this.viteRuntime.executeUrl(id); | ||
const domain = Domain.create(); | ||
domain.stdoutWrite = (chunk) => { | ||
stdoutChunks.push(chunk); | ||
}; | ||
domain.stderrWrite = (chunk) => { | ||
stderrChunks.push(chunk); | ||
}; | ||
let { default: result } = await domain.run( | ||
async () => await this.viteRuntime.executeUrl(id) | ||
); | ||
if (result instanceof Promise) | ||
@@ -651,3 +701,3 @@ result = await result; | ||
message: err.message, | ||
stack: err.stack | ||
stack: rewriteStack(err.stack) | ||
}; | ||
@@ -657,5 +707,19 @@ data = JSON.stringify(obj, void 0, " "); | ||
} | ||
const cellOutput = { | ||
items: data === void 0 ? [] : [{ data: [...Buffer.from(data, "utf8").values()], mime }] | ||
}; | ||
const items = []; | ||
if (data !== void 0) { | ||
items.push({ data: [...Buffer.from(data, "utf8").values()], mime }); | ||
} | ||
if (stdoutChunks.length > 0) { | ||
items.push({ | ||
data: [...Buffer.concat(stdoutChunks).values()], | ||
mime: "application/vnd.code.notebook.stdout" | ||
}); | ||
} | ||
if (stderrChunks.length > 0) { | ||
items.push({ | ||
data: [...Buffer.concat(stderrChunks).values()], | ||
mime: "application/vnd.code.notebook.stderr" | ||
}); | ||
} | ||
const cellOutput = { items }; | ||
await Promise.all( | ||
@@ -662,0 +726,0 @@ Array.from(this.clients.values()).map( |
@@ -1,3 +0,1 @@ | ||
import * as babelTypes from '@babel/types'; | ||
interface CellOutputItem { | ||
@@ -32,18 +30,32 @@ data: number[]; | ||
}; | ||
type SourceDescription = { | ||
code: string; | ||
ast: babelTypes.File; | ||
type: "server" | "client"; | ||
autoExports: babelTypes.ImportDeclaration[]; | ||
declare function text(data: string): { | ||
data: string; | ||
mime: string; | ||
}; | ||
type Cell = { | ||
cellId: string; | ||
code: string; | ||
language: string; | ||
sourceDescription?: SourceDescription; | ||
declare function markdown(data: string): { | ||
data: string; | ||
mime: string; | ||
}; | ||
type Options = { | ||
port: number; | ||
declare function html(html: string | { | ||
outerHTML: string; | ||
}): { | ||
data: string; | ||
mime: string; | ||
}; | ||
declare function svg(html: string | { | ||
outerHTML: string; | ||
}): { | ||
data: string; | ||
mime: string; | ||
}; | ||
declare function json(obj: object): { | ||
data: string; | ||
mime: string; | ||
}; | ||
declare function jsonView(obj: object): { | ||
data: string; | ||
mime: string; | ||
}; | ||
export type { Cell, CellOutput, CellOutputItem, ClientFunctions, Options, ServerFunctions, SourceDescription }; | ||
export { type CellOutput, type CellOutputItem, type ClientFunctions, type ServerFunctions, html, json, jsonView, markdown, svg, text }; |
@@ -0,1 +1,30 @@ | ||
// src/index.ts | ||
function text(data) { | ||
return { data, mime: "text/plain" }; | ||
} | ||
function markdown(data) { | ||
return { data, mime: "text/markdown" }; | ||
} | ||
function html(html2) { | ||
const data = typeof html2 === "object" ? html2.outerHTML : html2; | ||
return { data, mime: "text/html" }; | ||
} | ||
function svg(html2) { | ||
const data = typeof html2 === "object" ? html2.outerHTML : html2; | ||
return { data, mime: "image/svg+xml" }; | ||
} | ||
function json(obj) { | ||
return { data: JSON.stringify(obj), mime: "application/json" }; | ||
} | ||
function jsonView(obj) { | ||
return { data: JSON.stringify(obj), mime: "application/x-json-view" }; | ||
} | ||
export { | ||
html, | ||
json, | ||
jsonView, | ||
markdown, | ||
svg, | ||
text | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@githubnext/vitale", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "", | ||
@@ -8,2 +8,3 @@ "license": "MIT", | ||
"types": "dist/index.d.ts", | ||
"module": "dist/index.js", | ||
"files": [ | ||
@@ -10,0 +11,0 @@ "dist/cli.js", |
30035
11.2%941
12.56%