diff --git a/packages/cli/package.json b/packages/cli/package.json index b86c0b6bb5..33cf4706cd 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -25,13 +25,13 @@ "optionalDependencies": { "llamaindex": "0.1.21", "llm-code-highlighter": "0.0.13", - "mammoth": "^1.7.0", "pdfjs-dist": "4.0.379" }, "engines": { "node": ">=20.0.0" }, "devDependencies": { + "mammoth": "^1.7.0", "commander": "^12.0.0", "dotenv": "^16.4.5", "execa": "^8.0.1", @@ -58,7 +58,7 @@ "zx": "^7.2.3" }, "scripts": { - "compile": "esbuild src/main.ts --bundle --platform=node --target=node20 --outfile=built/genaiscript.cjs --external:pdfjs-dist --external:mammoth --external:llamaindex --external:llm-code-highlighter && echo '#!/usr/bin/env node' | cat - built/genaiscript.cjs > temp && mv temp built/genaiscript.cjs", + "compile": "esbuild src/main.ts --bundle --platform=node --target=node20 --outfile=built/genaiscript.cjs --external:pdfjs-dist --external:llamaindex --external:llm-code-highlighter && echo '#!/usr/bin/env node' | cat - built/genaiscript.cjs > temp && mv temp built/genaiscript.cjs", "postcompile": "cp built/genaiscript.cjs ../vscode/genaiscript.cjs && node built/genaiscript.cjs help-all > ../../docs/src/content/docs/reference/cli/commands.md", "go": "yarn compile && node built/genaiscript.cjs", "test": "node --import tsx --test src/**.test.ts", diff --git a/packages/core/src/docx.ts b/packages/core/src/docx.ts index a4d4e02ba1..7415d4fd5c 100644 --- a/packages/core/src/docx.ts +++ b/packages/core/src/docx.ts @@ -1,25 +1,7 @@ import { host } from "./host" import { MarkdownTrace } from "./trace" -import { installImport } from "./import" import { logError } from "./util" -import { MAMMOTH_VERSION } from "./version" - -async function tryImportMammoth(trace?: MarkdownTrace) { - try { - const mod = await import("mammoth") - return mod - } catch (e) { - trace?.error(`mammoth not found, installing ${MAMMOTH_VERSION}...`) - try { - await installImport("mammoth", MAMMOTH_VERSION, trace) - const mod = await import("mammoth") - return mod - } catch (e) { - trace?.error("mammoth failed to load") - return undefined - } - } -} +import { extractRawText } from "mammoth" /** * parses docx, require mammoth to be installed @@ -33,11 +15,10 @@ export async function DOCXTryParse( ): Promise { const { trace } = options || {} try { - const mammoth = await tryImportMammoth(trace) const path = !/^\//.test(file) ? host.path.join(host.projectFolder(), file) : file - const results = await mammoth.extractRawText({ path }) + const results = await extractRawText({ path }) return results.value } catch (error) { logError(error.message) diff --git a/packages/core/src/version.ts b/packages/core/src/version.ts index 66d92b0d76..9756f0d26e 100644 --- a/packages/core/src/version.ts +++ b/packages/core/src/version.ts @@ -11,4 +11,3 @@ export const CORE_VERSION = packageJson.version export const GITHUB_REPO = packageJson.repository.url export const PDFJS_DIST_VERSION = packageJson.optionalDependencies["pdfjs-dist"] -export const MAMMOTH_VERSION = packageJson.optionalDependencies["mammoth"] \ No newline at end of file diff --git a/packages/vscode/package.json b/packages/vscode/package.json index f1ca6676d1..61c78f9e2d 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -313,7 +313,7 @@ "scripts": { "vscode:update-dts": "npx @vscode/dts dev", "vscode:prepublish": "yarn run compile", - "compile:extension": "esbuild src/extension.ts --sourcemap --bundle --format=cjs --platform=node --target=node20 --outfile=built/extension.js --external:vscode --external:pdfjs-dist --external:mammoth --external:llamaindex", + "compile:extension": "esbuild src/extension.ts --sourcemap --bundle --format=cjs --platform=node --target=node20 --outfile=built/extension.js --external:vscode --external:pdfjs-dist --external:llamaindex", "compile": "yarn compile:extension", "lint": "eslint src --ext ts", "run-in-browser": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. ../sample", diff --git a/packages/vscode/postpackage.mjs b/packages/vscode/postpackage.mjs index 2620419804..dd4a57909a 100644 --- a/packages/vscode/postpackage.mjs +++ b/packages/vscode/postpackage.mjs @@ -1,7 +1,6 @@ import 'zx/globals' await $`rm -Rf ./node_modules/pdfjs-dist` -await $`rm -Rf ./node_modules/mammoth` const pkg = await fs.readJSON('./package.json') pkg.enabledApiProposals = pkg._enabledApiProposals diff --git a/packages/vscode/prepackage.mjs b/packages/vscode/prepackage.mjs index cd7d151a2b..817a7cb4a9 100644 --- a/packages/vscode/prepackage.mjs +++ b/packages/vscode/prepackage.mjs @@ -4,9 +4,6 @@ import 'zx/globals' await fs.copy('../../node_modules/pdfjs-dist/package.json', './node_modules/pdfjs-dist/package.json', { overwrite: true }) await $`cp -R ../../node_modules/pdfjs-dist/build ./node_modules/pdfjs-dist` -await fs.copy('../../node_modules/mammoth/package.json', './node_modules/mammoth/package.json', { overwrite: true }) -await $`cp -R ../../node_modules/mammoth/lib ./node_modules/mammoth` - const pkg = await fs.readJSON('./package.json') pkg._enabledApiProposals = pkg.enabledApiProposals pkg.displayName = "GenAIScript"