From 2fc152e96fe2ab4b67aad27b99b509ebd91567bc Mon Sep 17 00:00:00 2001 From: Felix Kaspar Date: Tue, 27 Feb 2024 21:51:03 +0100 Subject: [PATCH] Cleanup to help me debug build errors --- .../public}/browserfs.min.js | 0 package-lock.json | 68 ++++++++++++++++++- server-node/package.json | 1 + server-node/rollup.config.js | 5 +- server-node/src/index.ts | 7 +- .../api/dynamic-operations-controller.ts | 1 - .../src/routes/api/workflow-controller.ts | 2 +- server-node/tsconfig.json | 4 +- shared-operations/src/functions/index.ts | 2 +- shared-operations/src/i18next.config.ts | 2 +- .../src/wasm/pdfcpu/pdfcpu-wrapper.client.js | 5 +- .../src/wasm/pdfcpu/pdfcpu-wrapper.server.js | 7 +- .../src/workflow/operatorAccessor.ts | 11 ++- .../src/workflow/traverseOperations.ts | 3 +- shared-operations/tsconfig.json | 2 +- 15 files changed, 93 insertions(+), 27 deletions(-) rename {shared-operations/src/wasm => client-tauri/public}/browserfs.min.js (100%) diff --git a/shared-operations/src/wasm/browserfs.min.js b/client-tauri/public/browserfs.min.js similarity index 100% rename from shared-operations/src/wasm/browserfs.min.js rename to client-tauri/public/browserfs.min.js diff --git a/package-lock.json b/package-lock.json index 65aab4b7d..9c27934f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5382,7 +5382,6 @@ "version": "11.1.0", "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", - "dev": true, "dependencies": { "array-union": "^2.1.0", "dir-glob": "^3.0.1", @@ -7938,6 +7937,66 @@ "node": "*" } }, + "node_modules/rollup-plugin-dynamic-import-variables": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-dynamic-import-variables/-/rollup-plugin-dynamic-import-variables-1.1.0.tgz", + "integrity": "sha512-C1avEmnXC8cC4aAQ5dB63O9oQf7IrhEHc98bQw9Qd6H36FxtZooLCvVfcO4SNYrqaNrzH3ErucQt/zdFSLPHNw==", + "dependencies": { + "@rollup/pluginutils": "^3.0.9", + "estree-walker": "^2.0.1", + "globby": "^11.0.0", + "magic-string": "^0.25.7" + } + }, + "node_modules/rollup-plugin-dynamic-import-variables/node_modules/@rollup/pluginutils": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", + "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", + "dependencies": { + "@types/estree": "0.0.39", + "estree-walker": "^1.0.1", + "picomatch": "^2.2.2" + }, + "engines": { + "node": ">= 8.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0" + } + }, + "node_modules/rollup-plugin-dynamic-import-variables/node_modules/@rollup/pluginutils/node_modules/estree-walker": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==" + }, + "node_modules/rollup-plugin-dynamic-import-variables/node_modules/@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==" + }, + "node_modules/rollup-plugin-dynamic-import-variables/node_modules/magic-string": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", + "integrity": "sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==", + "dependencies": { + "sourcemap-codec": "^1.4.8" + } + }, + "node_modules/rollup-plugin-dynamic-import-variables/node_modules/rollup": { + "version": "2.79.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz", + "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==", + "peer": true, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=10.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -8246,6 +8305,12 @@ "source-map": "^0.6.0" } }, + "node_modules/sourcemap-codec": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", + "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", + "deprecated": "Please use @jridgewell/sourcemap-codec instead" + }, "node_modules/spawn-command": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2.tgz", @@ -9756,6 +9821,7 @@ "multer": "^1.4.5-lts.1", "pdf-lib": "^1.17.1", "rollup-plugin-copy": "^3.5.0", + "rollup-plugin-dynamic-import-variables": "^1.1.0", "tsconfig-paths": "^4.2.0", "vite-plugin-compile-time": "^0.2.1", "vite-plugin-dynamic-import": "^1.5.0", diff --git a/server-node/package.json b/server-node/package.json index 42733ddf0..f563490dc 100644 --- a/server-node/package.json +++ b/server-node/package.json @@ -35,6 +35,7 @@ "multer": "^1.4.5-lts.1", "pdf-lib": "^1.17.1", "rollup-plugin-copy": "^3.5.0", + "rollup-plugin-dynamic-import-variables": "^1.1.0", "tsconfig-paths": "^4.2.0", "vite-plugin-compile-time": "^0.2.1", "vite-plugin-dynamic-import": "^1.5.0", diff --git a/server-node/rollup.config.js b/server-node/rollup.config.js index 1ae3f5144..5c00455b6 100644 --- a/server-node/rollup.config.js +++ b/server-node/rollup.config.js @@ -12,15 +12,16 @@ export default { output: { dir: "dist/", format: "es", + strict: false, }, watch: { include: [ './src/**', '../shared-operations/src/**' ] }, plugins: [ + compileTime(), json(), typescript(), - dynamicImportVars(), - compileTime(), + dynamicImportVars({errorWhenNoFilesFound: true, warnOnError: true}), copy({ targets: [ { src: '../shared-operations/public', dest: 'dist' }, diff --git a/server-node/src/index.ts b/server-node/src/index.ts index 6fc4b44dc..7bce6a6ce 100644 --- a/server-node/src/index.ts +++ b/server-node/src/index.ts @@ -4,9 +4,12 @@ import express from "express"; const app = express(); const PORT = 8000; + +import { listOperatorNames } from "@stirling-pdf/shared-operations/src/workflow/operatorAccessor"; +console.log("Available Modules: ", listOperatorNames()) + // server-node: backend api import api from "./routes/api/api-controller"; -import { listOperatorNames } from "@stirling-pdf/shared-operations/src/workflow/operatorAccessor"; app.use("/api", api); // serve @@ -17,5 +20,3 @@ app.listen(PORT, () => { process.on('unhandledRejection', (reason, promise) => { console.error('Unhandled Rejection at:', promise, 'reason:', reason); }); - -console.log("Available Modules: ", listOperatorNames()) \ No newline at end of file diff --git a/server-node/src/routes/api/dynamic-operations-controller.ts b/server-node/src/routes/api/dynamic-operations-controller.ts index cb92a3211..293934c02 100644 --- a/server-node/src/routes/api/dynamic-operations-controller.ts +++ b/server-node/src/routes/api/dynamic-operations-controller.ts @@ -44,7 +44,6 @@ async function handleEndpoint(req: Request, res: Response) { else { action.values = validationResults.value.values; const operation = new operator(action); - operation.run(validationResults.value.input, (progress) => {}).then(pdfFiles => { respondWithPdfFiles(res, pdfFiles, req.params.func + "_result"); }); diff --git a/server-node/src/routes/api/workflow-controller.ts b/server-node/src/routes/api/workflow-controller.ts index 8f1b5b164..efb9c150d 100644 --- a/server-node/src/routes/api/workflow-controller.ts +++ b/server-node/src/routes/api/workflow-controller.ts @@ -48,7 +48,7 @@ router.post("/:workflowUuid?", [ res.status(400).json({error: "PDF validation failed", details: validationResults.error.message}); return; } - const inputs: PdfFile[] = validationResults.value; + const inputs: PdfFile[] = validationResults; // Allow option to do it synchronously and just make a long request if(req.body.async === "false") { diff --git a/server-node/tsconfig.json b/server-node/tsconfig.json index 86d3a8845..2e23dffaf 100644 --- a/server-node/tsconfig.json +++ b/server-node/tsconfig.json @@ -112,8 +112,8 @@ }, "include": [ "src", - "declarations/*.d.ts", - "../shared-operations/src/wasm/pdfcpu/PdfcpuWrapper.d.ts" + "./declarations/", + "../shared-operations/declarations/" ], "ts-node": { "experimentalSpecifierResolution": "node", diff --git a/shared-operations/src/functions/index.ts b/shared-operations/src/functions/index.ts index f82e383bc..4fa729848 100644 --- a/shared-operations/src/functions/index.ts +++ b/shared-operations/src/functions/index.ts @@ -1,4 +1,4 @@ -import { PdfFile } from "wrappers/PdfFile"; +import { PdfFile } from "../wrappers/PdfFile"; import { Action } from "../../declarations/Action"; import Joi from "@stirling-tools/joi"; diff --git a/shared-operations/src/i18next.config.ts b/shared-operations/src/i18next.config.ts index ef0f9a911..53beaca1a 100644 --- a/shared-operations/src/i18next.config.ts +++ b/shared-operations/src/i18next.config.ts @@ -2,7 +2,7 @@ import i18next from "i18next"; import resourcesToBackend from "i18next-resources-to-backend"; i18next - .use(resourcesToBackend((language, namespace) => import(`./public/locales/${namespace}/${language}.json`, { + .use(resourcesToBackend((language: string, namespace: string) => import(`../public/locales/${namespace}/${language}.json`, { assert: { type: "json" }, }))) .init({ diff --git a/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.client.js b/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.client.js index cbc1627fd..104eb58d5 100644 --- a/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.client.js +++ b/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.client.js @@ -61,16 +61,13 @@ async function loadFileAsync(data) { `/input.pdf`, ]); + console.log("Exit Code: " + exitcode); if (exitcode !== 0) throw new Error("There was an error validating your PDFs"); console.log(`File is Valid`); } -export async function impose(snapshot, nup, format) { - -}; - export async function oneToOne(wasmArray, snapshot) { await loadFileAsync(Buffer.from(snapshot)); diff --git a/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.server.js b/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.server.js index e3539ae68..e37414612 100644 --- a/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.server.js +++ b/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.server.js @@ -9,11 +9,11 @@ const wasmfs = new WasmFs(); // TODO: This can later be defered to load asynchronously (async () => { + configureFs(); await loadWasm(); - await configureFs(); })(); -async function configureFs() { +function configureFs() { // Can't use BrowserFS: https://github.com/jvilk/BrowserFS/issues/271 fs = wasmfs.fs; global.fs = fs; @@ -43,6 +43,9 @@ const runWasm = async (param) => { async function loadFileAsync(data) { console.log(`Writing file to Disk`); + if(fs === undefined) { + throw new Error("FS hasn't loaded, this should never happen.") + } fs.writeFileSync(`input.pdf`, data); console.log(`Write done. Validating...`); let exitcode = await runWasm([ diff --git a/shared-operations/src/workflow/operatorAccessor.ts b/shared-operations/src/workflow/operatorAccessor.ts index a957821e8..deca03279 100644 --- a/shared-operations/src/workflow/operatorAccessor.ts +++ b/shared-operations/src/workflow/operatorAccessor.ts @@ -1,20 +1,19 @@ import { Operator } from "../functions"; import i18next from "i18next"; -function getCompileTimeOperatorList(): string[] { - return import.meta.compileTime("./listOperatorsInDir.ts"); // The will compile to ["impose", "extractPages", etc...] -} +const compileTimeOperatorList: string[] = ["impose"]; import.meta.compileTime("./listOperatorsInDir.ts"); // The will compile to ["impose", "extractPages", etc...] export async function getOperatorByName(name: string): Promise { // Check if exists - if(!getCompileTimeOperatorList().includes(name)) return; + if(!compileTimeOperatorList.includes(name)) return; i18next.loadNamespaces(name, (err, t) => { if (err) throw err; }); - return (await import("../functions/" + name + ".ts"))[capitalizeFirstLetter(name)]; + const loadedModule = await import("../functions/" + name + ".ts"); + return loadedModule[capitalizeFirstLetter(name)]; } export function listOperatorNames(): string[] { - const availableOperators = getCompileTimeOperatorList(); + const availableOperators = compileTimeOperatorList; // TODO: Implement this return availableOperators; } diff --git a/shared-operations/src/workflow/traverseOperations.ts b/shared-operations/src/workflow/traverseOperations.ts index d8e7ab7bd..fe1b14293 100644 --- a/shared-operations/src/workflow/traverseOperations.ts +++ b/shared-operations/src/workflow/traverseOperations.ts @@ -20,12 +20,11 @@ export async function traverseOperations(operations: Action[], input: PdfFile[], async function nextOperation(actions: Action[] | undefined, input: PdfFile[], progressCallback: (state: Progress) => void): Promise { if(!actions || (Array.isArray(actions) && actions.length == 0)) { // isEmpty if(input && Array.isArray(input)) { - console.log("operation done: " + input[0].filename + (input.length > 1 ? "+" : "")); + console.log("operation done: " + input.map(file => file.filename) + (input.length > 1 ? "+" : "")); results = results.concat(input); } return; } - for (let i = 0; i < actions.length; i++) { await computeOperation(actions[i], Object.assign([], input), progressCallback); // structuredClone-like for ts TODO: test if this really works } diff --git a/shared-operations/tsconfig.json b/shared-operations/tsconfig.json index ec0eab812..8b8510660 100644 --- a/shared-operations/tsconfig.json +++ b/shared-operations/tsconfig.json @@ -6,6 +6,6 @@ "baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */ "paths": { "#pdfcpu": ["../../shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.server"], - } + } } /* Specify a set of entries that re-map imports to additional lookup locations. */ } \ No newline at end of file