@observablehq/notebook-kit 1.3.0 → 1.4.0

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/observablehq/notebook-kit.git"
7
7
  },
8
- "version": "1.3.0",
8
+ "version": "1.4.0",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -61,6 +61,7 @@
61
61
  "jsdom": "^26.1.0",
62
62
  "markdown-it": "^14.1.0",
63
63
  "markdown-it-anchor": "^9.2.0",
64
+ "typescript": "^5.8.3",
64
65
  "vite": "^7.0.0"
65
66
  },
66
67
  "devDependencies": {
@@ -77,7 +78,6 @@
77
78
  "postgres": "^3.4.7",
78
79
  "snowflake-sdk": "^2.1.3",
79
80
  "tsx": "^4.20.3",
80
- "typescript": "^5.8.3",
81
81
  "typescript-eslint": "^8.35.0",
82
82
  "vitest": "^3.2.4"
83
83
  },
@@ -9,7 +9,7 @@ export async function getInterpreterCachePath(sourcePath, interpreter, format, i
9
9
  export function getInterpreterCommand(interpreter) {
10
10
  switch (interpreter) {
11
11
  case "node":
12
- return ["node", ["--input-type=module", "--permission", "--allow-fs-read=."]];
12
+ return ["node", ["--input-type=module-typescript", "--permission", "--allow-fs-read=."]];
13
13
  case "python":
14
14
  return ["python3", []];
15
15
  default:
@@ -1,3 +1,4 @@
1
+ import { ScriptTarget, transpile as transpileTypeScript } from "typescript";
1
2
  import { toCell } from "../lib/notebook.js";
2
3
  import { rewriteFileExpressions } from "./files.js";
3
4
  import { hasImportDeclaration } from "./imports.js";
@@ -18,16 +19,18 @@ export function transpile(input, mode, options) {
18
19
  cell = input;
19
20
  input = cell.value;
20
21
  }
21
- const transpiled = mode === "ojs"
22
- ? transpileObservable(input, options)
23
- : mode !== "js"
24
- ? transpileJavaScript(transpileTemplate(cell), options)
25
- : transpileJavaScript(input, options);
22
+ const transpiled = mode === "ts"
23
+ ? transpileJavaScript(transpileTypeScript(input, { target: ScriptTarget.ESNext }), options)
24
+ : mode === "ojs"
25
+ ? transpileObservable(input, options)
26
+ : mode !== "js"
27
+ ? transpileJavaScript(transpileTemplate(cell), options)
28
+ : transpileJavaScript(input, options);
26
29
  if (transpiled.output === undefined)
27
30
  transpiled.output = cell.output;
28
31
  if (cell.hidden)
29
32
  transpiled.autodisplay = false;
30
- else if (mode !== "js" && mode !== "ojs") {
33
+ else if (mode !== "js" && mode !== "ts" && mode !== "ojs") {
31
34
  transpiled.autodisplay = !!input;
32
35
  transpiled.autoview = mode === "sql" && transpiled.autodisplay && !!transpiled.output;
33
36
  if (transpiled.autoview)
@@ -21,7 +21,7 @@ export interface CellSpec {
21
21
  /** the committed cell value; defaults to empty */
22
22
  value?: string;
23
23
  /** the mode; affects how the value is evaluated; defaults to js */
24
- mode?: "js" | "ojs" | "md" | "html" | "tex" | "dot" | "sql" | "node" | "python";
24
+ mode?: "js" | "ts" | "ojs" | "md" | "html" | "tex" | "dot" | "sql" | "node" | "python";
25
25
  /** if true, the editor will stay open when not focused; defaults to false */
26
26
  pinned?: boolean;
27
27
  /** if true, implicit display will be suppressed; defaults to false */
@@ -24,5 +24,5 @@ function asDate(date) {
24
24
  return date instanceof Date ? date : new Date(date);
25
25
  }
26
26
  export function defaultPinned(mode) {
27
- return mode === "js" || mode === "sql" || isInterpreter(mode) || mode === "ojs";
27
+ return mode === "js" || mode === "ts" || mode === "sql" || isInterpreter(mode) || mode === "ojs";
28
28
  }
@@ -74,6 +74,8 @@ function serializeMode(mode) {
74
74
  return "text/x-python";
75
75
  case "ojs":
76
76
  return "application/vnd.observable.javascript";
77
+ case "ts":
78
+ return "text/x-typescript";
77
79
  default:
78
80
  return "module";
79
81
  }
@@ -96,6 +98,8 @@ function deserializeMode(mode) {
96
98
  return "python";
97
99
  case "application/vnd.observable.javascript":
98
100
  return "ojs";
101
+ case "text/x-typescript":
102
+ return "ts";
99
103
  default:
100
104
  return "js";
101
105
  }
@@ -47,6 +47,11 @@ export async function highlight(code) {
47
47
  highlightCode(text, tree, highlighter, emit, emitBreak);
48
48
  }
49
49
  async function getParser(language) {
50
+ switch (language) {
51
+ case "node":
52
+ language = "ts";
53
+ break;
54
+ }
50
55
  switch (language) {
51
56
  case "js":
52
57
  case "ts":
@@ -68,7 +73,6 @@ function getLanguage(code) {
68
73
  ?.slice("language-".length)
69
74
  ?.toLowerCase();
70
75
  switch (language) {
71
- case "node":
72
76
  case "javascript":
73
77
  return "js";
74
78
  case "typescript":
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/observablehq/notebook-kit.git"
7
7
  },
8
- "version": "1.3.0",
8
+ "version": "1.4.0",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "test": "vitest",
@@ -61,6 +61,7 @@
61
61
  "jsdom": "^26.1.0",
62
62
  "markdown-it": "^14.1.0",
63
63
  "markdown-it-anchor": "^9.2.0",
64
+ "typescript": "^5.8.3",
64
65
  "vite": "^7.0.0"
65
66
  },
66
67
  "devDependencies": {
@@ -77,7 +78,6 @@
77
78
  "postgres": "^3.4.7",
78
79
  "snowflake-sdk": "^2.1.3",
79
80
  "tsx": "^4.20.3",
80
- "typescript": "^5.8.3",
81
81
  "typescript-eslint": "^8.35.0",
82
82
  "vitest": "^3.2.4"
83
83
  },