From b6f219aa82b4c934ea6817e8d4893eabbc1c55b9 Mon Sep 17 00:00:00 2001 From: linonetwo Date: Tue, 10 Sep 2024 16:13:59 +0800 Subject: [PATCH] feat: make $tw.wiki globally available --- .gitignore | 1 + core/globals.d.ts | 1 - core/modules/wiki.js | 7 +++++++ package.json | 1 + tsconfig.json | 9 +++++---- types/tw.d.ts | 7 +++++++ 6 files changed, 21 insertions(+), 5 deletions(-) delete mode 100644 core/globals.d.ts create mode 100644 types/tw.d.ts diff --git a/.gitignore b/.gitignore index 412759161..07f080e26 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ node_modules/ /playwright-report/ /playwright/.cache/ $__StoryList.tid +types/generated/ diff --git a/core/globals.d.ts b/core/globals.d.ts deleted file mode 100644 index 1c5abfbb1..000000000 --- a/core/globals.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare var $tw: any; diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 5673c9e3b..587ca8cad 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -22,6 +22,13 @@ Adds the following properties to the wiki object: /*global $tw: false */ "use strict"; +/** + * @typedef {import('$:/core/modules/widgets/widget.js').widget} Widget + */ + +/** + * @type {Widget} + */ var widget = require("$:/core/modules/widgets/widget.js"); var USER_NAME_TITLE = "$:/status/UserName", diff --git a/package.json b/package.json index 4dbd39087..5be4b5799 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "bin": { "tiddlywiki": "./tiddlywiki.js" }, + "types": "./types", "main": "./boot/boot.js", "repository": { "type": "git", diff --git a/tsconfig.json b/tsconfig.json index 378247231..0988bf8aa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,15 +11,16 @@ "allowSyntheticDefaultImports": true, "checkJs": true, "declaration": true, - "declarationDir": "types", + "declarationDir": "types/generated", "declarationMap": true, "emitDeclarationOnly": true, "lib": ["ES2020", "DOM", "DOM.Iterable"], "module": "Node16", - "outDir": "types", - "rootDir": "core", + "outDir": "types/generated", + "rootDir": ".", "skipLibCheck": true, "target": "ESNext" }, - "include": ["./core/**/*.js", "**/*.d.ts"] + "include": ["./core/**/*.js", "./core/**/*.d.ts", "types/tw.d.ts"], + "exclude": ["types/generated"] } diff --git a/types/tw.d.ts b/types/tw.d.ts new file mode 100644 index 000000000..b0477dde3 --- /dev/null +++ b/types/tw.d.ts @@ -0,0 +1,7 @@ +import * as Wiki from '../core/modules/wiki'; + +declare global { + var $tw: { + wiki: typeof Wiki; + }; +}