From 0bef181d59a365ea9814046da43d79f1ac6a53b7 Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Sun, 24 Nov 2024 16:58:42 +0800 Subject: [PATCH] refactor: from @tiddlygit/tiddlywiki to tiddlywiki , because there is no prerelease feature that I need now --- docs/Development.md | 2 +- package.json | 4 ++-- scripts/afterPack.js | 15 ++++++++------- scripts/compilePlugins.mjs | 6 +++--- src/constants/paths.ts | 2 +- src/services/wiki/plugin/zxPlugin/index.ts | 4 ++-- src/services/wiki/wikiWorker/htmlWiki.ts | 2 +- src/services/wiki/wikiWorker/index.ts | 2 -- src/services/wiki/wikiWorker/startNodeJSWiki.ts | 2 +- src/type.d.ts | 4 ---- webpack.main.config.js | 4 ++-- webpack.plugins.js | 3 ++- 12 files changed, 23 insertions(+), 27 deletions(-) diff --git a/docs/Development.md b/docs/Development.md index d4c72464..61490f3c 100644 --- a/docs/Development.md +++ b/docs/Development.md @@ -63,7 +63,7 @@ For example: `tiddlywiki` 1. `npm i tiddlywiki` 1. Add `ExternalsPlugin` in webpack.plugins.js (maybe optional for some deps, tiddlywiki needs this because its custom `require` can't require things that is bundled by webpack. `dugite` don't need this step) -1. Add a `await fs.copy(path.join(projectRoot, 'node_modules/@tiddlygit/tiddlywiki')` in `scripts/afterPack.js` , to copy things to resource folder, that is outside of asar, so it can be used by the worker_thread in electron +1. Add a `await fs.copy(path.join(projectRoot, 'node_modules/tiddlywiki')` in `scripts/afterPack.js` , to copy things to resource folder, that is outside of asar, so it can be used by the worker_thread in electron ## How to add plugin that only execute inside TidGi diff --git a/package.json b/package.json index f0480b49..58148d66 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "start": "pnpm run clean && pnpm run init:git-submodule && pnpm run start:without-clean", "start:without-clean": "pnpm run build:plugin && cross-env NODE_ENV=development electron-forge start", - "clean": "rimraf -- ./out ./userData-dev ./node_modules/@tiddlygit/tiddlywiki/plugins/linonetwo && cross-env NODE_ENV=development npx ts-node scripts/developmentMkdir.ts", + "clean": "rimraf -- ./out ./userData-dev ./node_modules/tiddlywiki/plugins/linonetwo && cross-env NODE_ENV=development npx ts-node scripts/developmentMkdir.ts", "clean:cache": "rimraf -- ./.webpack ./node_modules/.cache", "start:without-clean:debug-worker": "pnpm run build:plugin && cross-env NODE_ENV=development DEBUG_WORKER=true electron-forge start", "start:without-clean:debug-main": "pnpm run build:plugin && cross-env NODE_ENV=development DEBUG_MAIN=true electron-forge start", @@ -31,7 +31,7 @@ "author": "Lin Onetwo , Quang Lam ", "main": ".webpack/main", "dependencies": { - "@tiddlygit/tiddlywiki": "5.3.5", + "tiddlywiki": "5.3.6", "ansi-to-html": "^0.7.2", "app-path": "^4.0.0", "best-effort-json-parser": "1.1.2", diff --git a/scripts/afterPack.js b/scripts/afterPack.js index ad3f09ad..19eac11c 100644 --- a/scripts/afterPack.js +++ b/scripts/afterPack.js @@ -83,13 +83,14 @@ exports.default = async ( // shell, // }); const packagePathsToCopyDereferenced = [ - ['@tiddlygit', 'tiddlywiki', 'package.json'], - ['@tiddlygit', 'tiddlywiki', 'boot'], - ['@tiddlygit', 'tiddlywiki', 'core'], - ['@tiddlygit', 'tiddlywiki', 'plugins'], - ['@tiddlygit', 'tiddlywiki', 'themes'], - ['@tiddlygit', 'tiddlywiki', 'languages'], - ['@tiddlygit', 'tiddlywiki', 'tiddlywiki.js'], + ['tiddlywiki', 'package.json'], + ['tiddlywiki', 'boot'], + ['tiddlywiki', 'core'], + // only copy plugins that is used in src/services/wiki/wikiWorker/startNodeJSWiki.ts , other plugins can be installed via JSON from online plugin library + ['tiddlywiki', 'plugins', 'linonetwo'], + ['tiddlywiki', 'plugins', 'tiddlywiki', 'filesystem'], + ['tiddlywiki', 'plugins', 'tiddlywiki', 'tiddlyweb'], + ['tiddlywiki', 'tiddlywiki.js'], // we only need its `main` binary, no need its dependency and code, because we already copy it to src/services/native/externalApp ['app-path', 'main'], ]; diff --git a/scripts/compilePlugins.mjs b/scripts/compilePlugins.mjs index 68b8dc82..19afc396 100644 --- a/scripts/compilePlugins.mjs +++ b/scripts/compilePlugins.mjs @@ -5,10 +5,10 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-call */ import esbuild from 'esbuild'; -import { rimraf } from 'rimraf' +import { rimraf } from 'rimraf'; // put it here, so it can be loaded via `'+plugins/linonetwo/tidgi'` in cli, and get copied in scripts/afterPack.js when copying tiddlywiki (no need to copy this plugin again) -const tidgiIpcSyncadaptorOutDir = path.join(__dirname, '../node_modules/@tiddlygit/tiddlywiki/plugins/linonetwo/tidgi-ipc-syncadaptor'); +const tidgiIpcSyncadaptorOutDir = path.join(__dirname, '../node_modules/tiddlywiki/plugins/linonetwo/tidgi-ipc-syncadaptor'); // delete if exist await rimraf(tidgiIpcSyncadaptorOutDir); await fs.mkdirp(tidgiIpcSyncadaptorOutDir); @@ -44,7 +44,7 @@ const filterFunc = (src) => { await fs.copy(path.join(__dirname, tidgiIpcSyncadaptorSourceFolder), tidgiIpcSyncadaptorOutDir, { filter: filterFunc }); const tidgiIpcSyncadaptorUISourceFolder = '../src/services/wiki/plugin/ipcSyncAdaptorUI'; -const tidgiIpcSyncadaptorUIOutDir = path.join(__dirname, '../node_modules/@tiddlygit/tiddlywiki/plugins/linonetwo/tidgi-ipc-syncadaptor-ui'); +const tidgiIpcSyncadaptorUIOutDir = path.join(__dirname, '../node_modules/tiddlywiki/plugins/linonetwo/tidgi-ipc-syncadaptor-ui'); // delete if exist await rimraf(tidgiIpcSyncadaptorUIOutDir); await fs.mkdirp(tidgiIpcSyncadaptorUIOutDir); diff --git a/src/constants/paths.ts b/src/constants/paths.ts index 39d1c7aa..95e09a1b 100644 --- a/src/constants/paths.ts +++ b/src/constants/paths.ts @@ -25,7 +25,7 @@ export const PACKAGE_PATH_BASE = isDevelopmentOrTest ? path.resolve(__dirname, '..', '..', 'node_modules') : path.resolve(process.resourcesPath, 'node_modules'); export const ZX_FOLDER = path.resolve(PACKAGE_PATH_BASE, 'zx', 'build', 'cli.js'); -export const TIDDLYWIKI_PACKAGE_FOLDER = path.resolve(PACKAGE_PATH_BASE, '@tiddlygit', 'tiddlywiki', 'boot'); +export const TIDDLYWIKI_PACKAGE_FOLDER = path.resolve(PACKAGE_PATH_BASE, 'tiddlywiki', 'boot'); export const LOCALIZATION_FOLDER = isDevelopmentOrTest ? path.resolve(sourcePath, '..', localizationFolderName) diff --git a/src/services/wiki/plugin/zxPlugin/index.ts b/src/services/wiki/plugin/zxPlugin/index.ts index 7a2967c9..0dcb8155 100644 --- a/src/services/wiki/plugin/zxPlugin/index.ts +++ b/src/services/wiki/plugin/zxPlugin/index.ts @@ -1,13 +1,13 @@ /** * Can't use logger in this file, because it runs in the worker. */ -import type { ITiddlyWiki } from '@tiddlygit/tiddlywiki'; +import AnsiToHtml from 'ansi-to-html'; import { fork } from 'child_process'; import { writeFile } from 'fs-extra'; import _ from 'lodash'; import type { Subscriber } from 'rxjs'; +import type { ITiddlyWiki } from 'tiddlywiki'; import vm, { Context } from 'vm'; -import AnsiToHtml from 'ansi-to-html'; import { IZxWorkerMessage, ZxWorkerControlActions } from '../../interface'; import { fixZxPath } from './fixZxPath'; import { diff --git a/src/services/wiki/wikiWorker/htmlWiki.ts b/src/services/wiki/wikiWorker/htmlWiki.ts index dcbfe22f..a507f606 100644 --- a/src/services/wiki/wikiWorker/htmlWiki.ts +++ b/src/services/wiki/wikiWorker/htmlWiki.ts @@ -1,6 +1,6 @@ import { isHtmlWiki } from '@/constants/fileNames'; -import { TiddlyWiki } from '@tiddlygit/tiddlywiki'; import { remove } from 'fs-extra'; +import { TiddlyWiki } from 'tiddlywiki'; export async function extractWikiHTML(htmlWikiPath: string, saveWikiFolderPath: string, constants: { TIDDLYWIKI_PACKAGE_FOLDER: string }): Promise { // tiddlywiki --load ./mywiki.html --savewikifolder ./mywikifolder diff --git a/src/services/wiki/wikiWorker/index.ts b/src/services/wiki/wikiWorker/index.ts index 7aed5cad..18f82bda 100644 --- a/src/services/wiki/wikiWorker/index.ts +++ b/src/services/wiki/wikiWorker/index.ts @@ -3,8 +3,6 @@ * Worker environment is not part of electron environment, so don't import "@/constants/paths" here, as its process.resourcesPath will become undefined and throw Errors. * * Don't use i18n and logger in worker thread. For example, 12b93020, will throw error "Electron failed to install correctly, please delete node_modules/electron and try installing again ...worker.js..." - * - * Import tw related things and typing from `@tiddlygit/tiddlywiki` instead of `tiddlywiki`, otherwise you will get `Unhandled Error ReferenceError: self is not defined at $:/boot/bootprefix.js:40749:36` because tiddlywiki */ import { uninstall } from '@/helpers/installV8Cache'; import './preload'; diff --git a/src/services/wiki/wikiWorker/startNodeJSWiki.ts b/src/services/wiki/wikiWorker/startNodeJSWiki.ts index 1e02825d..f3c24bb6 100644 --- a/src/services/wiki/wikiWorker/startNodeJSWiki.ts +++ b/src/services/wiki/wikiWorker/startNodeJSWiki.ts @@ -1,11 +1,11 @@ import { getTidGiAuthHeaderWithToken } from '@/constants/auth'; import { defaultServerIP } from '@/constants/urls'; -import { TiddlyWiki } from '@tiddlygit/tiddlywiki'; import intercept from 'intercept-stdout'; import { nanoid } from 'nanoid'; import inspector from 'node:inspector'; import path from 'path'; import { Observable } from 'rxjs'; +import { TiddlyWiki } from 'tiddlywiki'; import { IWikiMessage, WikiControlActions } from '../interface'; import { wikiOperationsInWikiWorker } from '../wikiOperations/executor/wikiOperationInServer'; import { IStartNodeJSWikiConfigs } from '.'; diff --git a/src/type.d.ts b/src/type.d.ts index 3393ce52..fb1bd1dd 100644 --- a/src/type.d.ts +++ b/src/type.d.ts @@ -5,10 +5,6 @@ declare module 'errio' { export function register(error: ErrorConstructor): void; } -declare module '@tiddlygit/tiddlywiki' { - export * from 'tiddlywiki'; -} - declare module 'espree' { // https://github.com/eslint/espree#options export interface Options { diff --git a/webpack.main.config.js b/webpack.main.config.js index 7f4ae8ad..ee4538b2 100644 --- a/webpack.main.config.js +++ b/webpack.main.config.js @@ -50,10 +50,10 @@ module.exports = { externals: [ // simply external all things will make require can't find things. Only exclude what we copied in scripts/afterPack.js // nodeExternals({ - // additionalModuleDirs: ['@tiddlygit/tiddlywiki'], + // additionalModuleDirs: ['tiddlywiki'], // allowlist: [/(threads-plugin)/], // }), - '@tiddlygit/tiddlywiki', + 'tiddlywiki', 'dugite', 'zx', ...(process.platform === 'win32' ? [] : ['registry-js']), diff --git a/webpack.plugins.js b/webpack.plugins.js index ad3ce8c9..8599c19c 100644 --- a/webpack.plugins.js +++ b/webpack.plugins.js @@ -39,7 +39,8 @@ exports.main = _.compact([ new ExternalsPlugin({ type: 'commonjs', // use regex works. - include: /@tiddlygit\+tiddlywiki@(.+)|dugite(.+)/, + // include: /@tiddlygit\+tiddlywiki@(.+)|dugite(.+)/, + include: /tiddlywiki(.+)|dugite(.+)/, // when using npm, we can use this. But with pnpm, this won't work ↓ // include: path.join(__dirname, 'node_modules', '.pnpm', '@tiddlygit', 'tiddlywiki'), }),