diff --git a/.changeset/cyan-weeks-cheer.md b/.changeset/cyan-weeks-cheer.md new file mode 100644 index 00000000..75fdcb33 --- /dev/null +++ b/.changeset/cyan-weeks-cheer.md @@ -0,0 +1,8 @@ +--- +'thebe-react': patch +'thebe': patch +'thebe-core': patch +'thebe-lite': patch +--- + +Version numbers are printed in debug messages to aid in debugging diff --git a/.gitignore b/.gitignore index 69c112dd..cac2824f 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,6 @@ junit.xml .turbo .ipynb_checkpoints -.yalc/ \ No newline at end of file +.yalc/ + +packages/**/src/version.ts \ No newline at end of file diff --git a/packages/core/package.json b/packages/core/package.json index 7a276f59..956ed274 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -13,16 +13,17 @@ "scripts": { "clean": "rm -rf dist", "prepublish": "npm run build", + "copy:version": "echo \"const version = '\"$npm_package_version\"';\nexport default version;\" > src/version.ts", "build:css": "node ./esbuild.css.js", "build:cjs": "tsc --project ./tsconfig.json --outDir ./dist/cjs", "build:esm": "tsc --project ./tsconfig.json --module ES2020 --outDir ./dist/esm", "build:bundle:dev": "webpack --config webpack.dev.js", "build:bundle": "webpack --config webpack.prod.js", "declarations": "tsc --project ./tsconfig.json --declaration --emitDeclarationOnly --outDir dist/types", - "build:dev": "npm-run-all -l clean -p declarations build:cjs build:esm build:css build:bundle:dev", - "build": "npm-run-all -l clean -p declarations build:cjs build:esm build:css build:bundle", + "build:dev": "npm-run-all -l clean copy:version -p declarations build:cjs build:esm build:css build:bundle:dev", + "build": "npm-run-all -l clean copy:version -p declarations build:cjs build:esm build:css build:bundle", "build:watch": "concurrently 'npm run build:cjs -- -w' 'npm run copy:css' 'npm run build:bundle -- --watch'", - "dev": "npm run build:watch", + "dev": "npm run copy:version && npm run build:watch", "start": "webpack serve --open --config webpack.dev.js", "test:watch": "vitest", "test": "vitest run", diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 903fa123..5d289571 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -4,6 +4,7 @@ export { default as ThebeNotebook, CodeBlock } from './notebook'; export { default as ThebeCodeCell } from './cell'; export { default as ThebeMarkdownCell } from './markdown'; export { default as PassiveCellRenderer } from './passive'; +export { default as version } from './version'; export * from './options'; export * from './events'; @@ -14,4 +15,5 @@ export * from './manager'; export * from './rendermime'; export * from './types'; export * from './config'; + export { clearAllSavedSessions, clearSavedSession } from './sessions'; diff --git a/packages/core/src/thebe/api.ts b/packages/core/src/thebe/api.ts index 2350a6a5..dea8caf9 100644 --- a/packages/core/src/thebe/api.ts +++ b/packages/core/src/thebe/api.ts @@ -8,6 +8,7 @@ import { makeConfiguration } from '../options'; import { makeRenderMimeRegistry } from '../rendermime'; import * as coreModule from '../index'; import type { IRenderMimeRegistry } from '@jupyterlab/rendermime'; +import version from '../version'; export function connectToBinder(config: Config): ThebeServer { const server: ThebeServer = new ThebeServer(config); @@ -55,7 +56,7 @@ export function setupNotebookFromIpynb( } export function setupThebeCore() { - console.debug(`thebe:api:setupThebeCore`, { coreModule }); + console.debug(`thebe-core (v${version})`, { coreModule }); window.thebeCore = Object.assign(window.thebeCore ?? {}, { module: coreModule, api: { @@ -69,5 +70,6 @@ export function setupThebeCore() { setupNotebookFromBlocks, setupNotebookFromIpynb, }, + version, }); } diff --git a/packages/core/src/thebe/entrypoint.ts b/packages/core/src/thebe/entrypoint.ts index 33d77891..dff0e0f1 100644 --- a/packages/core/src/thebe/entrypoint.ts +++ b/packages/core/src/thebe/entrypoint.ts @@ -46,6 +46,7 @@ export type ThebeCore = typeof coreModule; export interface ThebeCoreGlobal { module: ThebeCore; api: JsApi; + version: string; } declare global { diff --git a/packages/lite/package.json b/packages/lite/package.json index 52c297f2..13d19802 100644 --- a/packages/lite/package.json +++ b/packages/lite/package.json @@ -10,12 +10,13 @@ ], "scripts": { "clean": "rm -rf ./dist", + "copy:version": "echo \"const version = '\"$npm_package_version\"';\nexport default version;\" > src/version.ts", "build:bundle": "webpack --config webpack.config.cjs", "build:post:shuffle": "./bin/shufflePyolitePaths.sh", "build:post:contents": "./bin/stubContentsApi.js", "declarations": "tsc --project ./tsconfig.json --declaration --emitDeclarationOnly --outDir dist/types", - "build": "npm-run-all -l clean -p build:bundle declarations", - "dev": "npm run build:bundle -- -w" + "build": "npm-run-all -l clean copy:version -p build:bundle declarations", + "dev": "npm run copy:version && npm run build:bundle -- -w" }, "repository": { "type": "git", diff --git a/packages/lite/src/index.ts b/packages/lite/src/index.ts index 4f995572..9f1b6c5e 100644 --- a/packages/lite/src/index.ts +++ b/packages/lite/src/index.ts @@ -1,5 +1,6 @@ import { startJupyterLiteServer } from './jlite'; import type { ThebeLiteGlobal } from './types'; +import version from './version'; declare global { interface Window { @@ -8,13 +9,13 @@ declare global { } function setupThebeLite() { - window.thebeLite = Object.assign(window.thebeLite ?? {}, { startJupyterLiteServer }); + window.thebeLite = Object.assign(window.thebeLite ?? {}, { startJupyterLiteServer, version }); } if (typeof window !== 'undefined') { console.debug('window is defined, setting up thebe-lite'); setupThebeLite(); - console.debug('window.thebeLite', window.thebeLite); + console.debug(`thebe-lite (v${window.thebeLite?.version ?? 0})`, window.thebeLite); } export * from './types'; diff --git a/packages/lite/src/types.ts b/packages/lite/src/types.ts index 5eda09b6..ff6d3ab5 100644 --- a/packages/lite/src/types.ts +++ b/packages/lite/src/types.ts @@ -20,4 +20,5 @@ export type LiteServerConfig = { export interface ThebeLiteGlobal { startJupyterLiteServer: (config?: LiteServerConfig) => Promise; + version: string; } diff --git a/packages/react/package.json b/packages/react/package.json index 91a15d8e..d3a42592 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -29,11 +29,12 @@ }, "scripts": { "clean": "rm -rf dist", + "copy:version": "echo \"const version = '\"$npm_package_version\"';\nexport default version;\" > src/version.ts", "prepublish": "npm run build", "build:cjs": "tsc --project ./tsconfig.json --outDir ./dist", "declarations": "tsc --project ./tsconfig.json --declaration --emitDeclarationOnly --outDir dist", - "build": "npm run declarations; npm run build:cjs", - "dev": "concurrently 'npm run declarations -- -w' 'npm run build:cjs -- -w'", + "build": "npm run copy:version; npm run declarations; npm run build:cjs", + "dev": "npm copy:version; concurrently 'npm run declarations -- -w' 'npm run build:cjs -- -w'", "test": "vitest run", "test:watch": "vitest" }, diff --git a/packages/react/src/ThebeLoaderProvider.tsx b/packages/react/src/ThebeLoaderProvider.tsx index 74ec6bee..b23f24c1 100644 --- a/packages/react/src/ThebeLoaderProvider.tsx +++ b/packages/react/src/ThebeLoaderProvider.tsx @@ -1,4 +1,5 @@ import React, { useEffect, useState } from 'react'; +import version from './version'; // eslint-disable-next-line @typescript-eslint/consistent-type-imports export type ThebeCore = typeof import('thebe-core'); @@ -21,10 +22,10 @@ export function ThebeLoaderProvider({ // if already loaded do nothing if (!startLoad || core) return; setLoading(true); - console.debug('importing thebe-core...'); + console.debug(`thebe-react (v${version}) importing thebe-core...`); import('thebe-core') .then((thebeCore) => { - console.debug('thebe-core loaded'); + console.debug(`thebe-core (v${thebeCore.version}) loaded`); setCore(thebeCore); setLoading(false); }) @@ -63,7 +64,7 @@ export function ThebeBundleLoaderProvider({ // if already loaded do nothing if (!startLoad || core) return; setLoading(true); - console.debug('importing thebe-core...'); + console.debug(`thebe-react (v${version}) importing thebe-core...`); if (typeof document !== 'undefined' && typeof window !== 'undefined') { try { @@ -88,8 +89,9 @@ export function ThebeBundleLoaderProvider({ if (window.thebeCore && (window.thebeLite || !loadThebeLite)) { setLoading(false); setCore((window as any).thebeCore?.module); - console.debug('thebe-core loaded'); - if (window.thebeLite) console.debug('thebe-lite loaded'); + console.debug(`thebe-core (v${(window as any).thebeCore?.version ?? '0'}) loaded`); + if (window.thebeLite) + console.debug(`thebe-lite (v${window.thebeLite?.version ?? '0'}) loaded`); clearInterval(timer); } if (attempts > (options?.attempts ?? 50)) { diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index ba8afbb0..f0a3ffd4 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -4,3 +4,4 @@ export * from './ThebeServerProvider'; export * from './ThebeSessionProvider'; export * from './ThebeRenderMimeRegistryProvider'; export * from './hooks'; +export { default as version } from './version'; diff --git a/packages/thebe/package.json b/packages/thebe/package.json index 435849a3..a20f88e7 100644 --- a/packages/thebe/package.json +++ b/packages/thebe/package.json @@ -14,19 +14,20 @@ }, "scripts": { "clean": "rm -rf ./lib", + "copy:version": "echo \"const version = '\"$npm_package_version\"';\nexport default version;\" > src/version.ts", "build:bundle:dev": "webpack --mode development --devtool inline-source-map --progress --color", "build:bundle": "webpack --mode production --devtool source-map", "build:mkdir": "mkdir -p lib", "build:css": "node ./esbuild.css.js", "build:dev": "npm-run-all -l clean -p build:css build:bundle:dev declarations", - "build": "npm-run-all -l clean -p build:css build:bundle declarations", + "build": "npm-run-all -l clean copy:version -p build:css build:bundle declarations", "declarations": "tsc --project ./tsconfig.json --declaration --emitDeclarationOnly --outDir lib/types", "build:watch": "npm run build:bundle:dev -- --watch", "build:publish": "NODE_PREPUBLISH=true npm run build", "serve": "http-server -c-1 -a 127.0.0.1 -o development/binder.html", "serve:local": "http-server -c-1 -a 127.0.0.1 -o development/local.html", "serve:examples": "http-server -c-1 -a 127.0.0.1 -o docs/_static/html_examples/index.html", - "dev": "npm run build:watch", + "dev": "npm run copy:version && npm run build:watch", "develop": "concurrently \"yarn run build:watch\" \"yarn run serve\"", "develop:local": "concurrently \"yarn run build:watch\" \"yarn run serve:local\"", "disabled-test": "jest --detectOpenHandles", diff --git a/packages/thebe/src/index.ts b/packages/thebe/src/index.ts index 9034c2fe..81562edb 100644 --- a/packages/thebe/src/index.ts +++ b/packages/thebe/src/index.ts @@ -1,5 +1,6 @@ import { ThebeEvents, setupThebeCore } from 'thebe-core'; import * as thebe from './thebe'; +import version from './version'; export * from './types'; export * from './thebe'; @@ -8,6 +9,7 @@ export function setupGlobals() { const events = new ThebeEvents(); window.thebe = Object.assign(window.thebe ?? {}, { + version, ...thebe, events, trigger: events.trigger.bind(events),