1
0
mirror of https://github.com/Stirling-Tools/Stirling-PDF.git synced 2024-06-03 06:10:11 +02:00

Cleanup to help me debug build errors

This commit is contained in:
Felix Kaspar 2024-02-27 21:51:03 +01:00
parent 13bfa0b0d0
commit 2fc152e96f
15 changed files with 93 additions and 27 deletions

68
package-lock.json generated
View File

@ -5382,7 +5382,6 @@
"version": "11.1.0", "version": "11.1.0",
"resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz",
"integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==",
"dev": true,
"dependencies": { "dependencies": {
"array-union": "^2.1.0", "array-union": "^2.1.0",
"dir-glob": "^3.0.1", "dir-glob": "^3.0.1",
@ -7938,6 +7937,66 @@
"node": "*" "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": { "node_modules/run-parallel": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz",
@ -8246,6 +8305,12 @@
"source-map": "^0.6.0" "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": { "node_modules/spawn-command": {
"version": "0.0.2", "version": "0.0.2",
"resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2.tgz", "resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2.tgz",
@ -9756,6 +9821,7 @@
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
"pdf-lib": "^1.17.1", "pdf-lib": "^1.17.1",
"rollup-plugin-copy": "^3.5.0", "rollup-plugin-copy": "^3.5.0",
"rollup-plugin-dynamic-import-variables": "^1.1.0",
"tsconfig-paths": "^4.2.0", "tsconfig-paths": "^4.2.0",
"vite-plugin-compile-time": "^0.2.1", "vite-plugin-compile-time": "^0.2.1",
"vite-plugin-dynamic-import": "^1.5.0", "vite-plugin-dynamic-import": "^1.5.0",

View File

@ -35,6 +35,7 @@
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
"pdf-lib": "^1.17.1", "pdf-lib": "^1.17.1",
"rollup-plugin-copy": "^3.5.0", "rollup-plugin-copy": "^3.5.0",
"rollup-plugin-dynamic-import-variables": "^1.1.0",
"tsconfig-paths": "^4.2.0", "tsconfig-paths": "^4.2.0",
"vite-plugin-compile-time": "^0.2.1", "vite-plugin-compile-time": "^0.2.1",
"vite-plugin-dynamic-import": "^1.5.0", "vite-plugin-dynamic-import": "^1.5.0",

View File

@ -12,15 +12,16 @@ export default {
output: { output: {
dir: "dist/", dir: "dist/",
format: "es", format: "es",
strict: false,
}, },
watch: { watch: {
include: [ './src/**', '../shared-operations/src/**' ] include: [ './src/**', '../shared-operations/src/**' ]
}, },
plugins: [ plugins: [
compileTime(),
json(), json(),
typescript(), typescript(),
dynamicImportVars(), dynamicImportVars({errorWhenNoFilesFound: true, warnOnError: true}),
compileTime(),
copy({ copy({
targets: [ targets: [
{ src: '../shared-operations/public', dest: 'dist' }, { src: '../shared-operations/public', dest: 'dist' },

View File

@ -4,9 +4,12 @@ import express from "express";
const app = express(); const app = express();
const PORT = 8000; const PORT = 8000;
import { listOperatorNames } from "@stirling-pdf/shared-operations/src/workflow/operatorAccessor";
console.log("Available Modules: ", listOperatorNames())
// server-node: backend api // server-node: backend api
import api from "./routes/api/api-controller"; import api from "./routes/api/api-controller";
import { listOperatorNames } from "@stirling-pdf/shared-operations/src/workflow/operatorAccessor";
app.use("/api", api); app.use("/api", api);
// serve // serve
@ -17,5 +20,3 @@ app.listen(PORT, () => {
process.on('unhandledRejection', (reason, promise) => { process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason); console.error('Unhandled Rejection at:', promise, 'reason:', reason);
}); });
console.log("Available Modules: ", listOperatorNames())

View File

@ -44,7 +44,6 @@ async function handleEndpoint(req: Request, res: Response) {
else { else {
action.values = validationResults.value.values; action.values = validationResults.value.values;
const operation = new operator(action); const operation = new operator(action);
operation.run(validationResults.value.input, (progress) => {}).then(pdfFiles => { operation.run(validationResults.value.input, (progress) => {}).then(pdfFiles => {
respondWithPdfFiles(res, pdfFiles, req.params.func + "_result"); respondWithPdfFiles(res, pdfFiles, req.params.func + "_result");
}); });

View File

@ -48,7 +48,7 @@ router.post("/:workflowUuid?", [
res.status(400).json({error: "PDF validation failed", details: validationResults.error.message}); res.status(400).json({error: "PDF validation failed", details: validationResults.error.message});
return; return;
} }
const inputs: PdfFile[] = validationResults.value; const inputs: PdfFile[] = validationResults;
// Allow option to do it synchronously and just make a long request // Allow option to do it synchronously and just make a long request
if(req.body.async === "false") { if(req.body.async === "false") {

View File

@ -112,8 +112,8 @@
}, },
"include": [ "include": [
"src", "src",
"declarations/*.d.ts", "./declarations/",
"../shared-operations/src/wasm/pdfcpu/PdfcpuWrapper.d.ts" "../shared-operations/declarations/"
], ],
"ts-node": { "ts-node": {
"experimentalSpecifierResolution": "node", "experimentalSpecifierResolution": "node",

View File

@ -1,4 +1,4 @@
import { PdfFile } from "wrappers/PdfFile"; import { PdfFile } from "../wrappers/PdfFile";
import { Action } from "../../declarations/Action"; import { Action } from "../../declarations/Action";
import Joi from "@stirling-tools/joi"; import Joi from "@stirling-tools/joi";

View File

@ -2,7 +2,7 @@ import i18next from "i18next";
import resourcesToBackend from "i18next-resources-to-backend"; import resourcesToBackend from "i18next-resources-to-backend";
i18next 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" }, assert: { type: "json" },
}))) })))
.init({ .init({

View File

@ -61,16 +61,13 @@ async function loadFileAsync(data) {
`/input.pdf`, `/input.pdf`,
]); ]);
console.log("Exit Code: " + exitcode);
if (exitcode !== 0) if (exitcode !== 0)
throw new Error("There was an error validating your PDFs"); throw new Error("There was an error validating your PDFs");
console.log(`File is Valid`); console.log(`File is Valid`);
} }
export async function impose(snapshot, nup, format) {
};
export async function oneToOne(wasmArray, snapshot) { export async function oneToOne(wasmArray, snapshot) {
await loadFileAsync(Buffer.from(snapshot)); await loadFileAsync(Buffer.from(snapshot));

View File

@ -9,11 +9,11 @@ const wasmfs = new WasmFs();
// TODO: This can later be defered to load asynchronously // TODO: This can later be defered to load asynchronously
(async () => { (async () => {
configureFs();
await loadWasm(); await loadWasm();
await configureFs();
})(); })();
async function configureFs() { function configureFs() {
// Can't use BrowserFS: https://github.com/jvilk/BrowserFS/issues/271 // Can't use BrowserFS: https://github.com/jvilk/BrowserFS/issues/271
fs = wasmfs.fs; fs = wasmfs.fs;
global.fs = fs; global.fs = fs;
@ -43,6 +43,9 @@ const runWasm = async (param) => {
async function loadFileAsync(data) { async function loadFileAsync(data) {
console.log(`Writing file to Disk`); 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); fs.writeFileSync(`input.pdf`, data);
console.log(`Write done. Validating...`); console.log(`Write done. Validating...`);
let exitcode = await runWasm([ let exitcode = await runWasm([

View File

@ -1,20 +1,19 @@
import { Operator } from "../functions"; import { Operator } from "../functions";
import i18next from "i18next"; import i18next from "i18next";
function getCompileTimeOperatorList(): string[] { const compileTimeOperatorList: string[] = ["impose"]; import.meta.compileTime("./listOperatorsInDir.ts"); // The will compile to ["impose", "extractPages", etc...]
return import.meta.compileTime("./listOperatorsInDir.ts"); // The will compile to ["impose", "extractPages", etc...]
}
export async function getOperatorByName(name: string): Promise<typeof Operator | undefined> { export async function getOperatorByName(name: string): Promise<typeof Operator | undefined> {
// Check if exists // Check if exists
if(!getCompileTimeOperatorList().includes(name)) return; if(!compileTimeOperatorList.includes(name)) return;
i18next.loadNamespaces(name, (err, t) => { if (err) throw err; }); 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[] { export function listOperatorNames(): string[] {
const availableOperators = getCompileTimeOperatorList(); const availableOperators = compileTimeOperatorList;
// TODO: Implement this // TODO: Implement this
return availableOperators; return availableOperators;
} }

View File

@ -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<void> { async function nextOperation(actions: Action[] | undefined, input: PdfFile[], progressCallback: (state: Progress) => void): Promise<void> {
if(!actions || (Array.isArray(actions) && actions.length == 0)) { // isEmpty if(!actions || (Array.isArray(actions) && actions.length == 0)) { // isEmpty
if(input && Array.isArray(input)) { 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); results = results.concat(input);
} }
return; return;
} }
for (let i = 0; i < actions.length; i++) { 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 await computeOperation(actions[i], Object.assign([], input), progressCallback); // structuredClone-like for ts TODO: test if this really works
} }

View File

@ -6,6 +6,6 @@
"baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */ "baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */
"paths": { "paths": {
"#pdfcpu": ["../../shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.server"], "#pdfcpu": ["../../shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.server"],
} }
} /* Specify a set of entries that re-map imports to additional lookup locations. */ } /* Specify a set of entries that re-map imports to additional lookup locations. */
} }