nextapps-de / flexsearch

Next-Generation full text search library for Browser and Node.js
Apache License 2.0
12.54k stars 492 forks source link

How to avoid eval? #394

Closed zhe-he closed 10 months ago

zhe-he commented 1 year ago

node_modules/@blocksuite/blocks/dist/databaseUse of eval in "node_modules/flexsearch/dist/flexsearch.bundle.js" is strongly discouraged as it poses security risks and may cause issues with minification

image

https://github.com/nextapps-de/flexsearch/blob/9abb781357f04e7db8529654c6941009771f4bf1/src/worker/index.js#L138

https://rollupjs.org/troubleshooting/#avoiding-eval

zhe-he commented 1 year ago

Is it possible to output two versions, one for browser and one for nodejs

source:

/** index.js */
import { test }  from "./platform";
console.log(test)
/** platform-node.js */
module.exports.test = 1;
/** platform-browser.js */
export const test = 2;
/** config.js */
alias: {
    platform: process.env.isNode ? './platform-node' : './platform-browser'
}

output:

index.browser.js 
index.node.js
zhe-he commented 1 year ago

Or automatically replace node variables at the end of compilation source:

const t1 = import.meta.env.isNode;
const t2 = process.env.isNode;
const test = import.meta.env.isNode ? 'a' : 'b';
const test2 = process.env.isNode ? 'c' : 'd';
const test3 = t1 ? 'e' : 'f';

output:

/** nodejs */
const t1 = true;
const t2 = true;
const test = 'a'
const test2 = 'c'
const test3 = 'e'
/** browser */
const t1 = false;
const t2 = false;
const test = 'b'
const test2 = 'd'
const test3 = 'f'
DanielleConstell commented 11 months ago

I am also running into this issue any updates?

zhe-he commented 11 months ago

@DanielleConstell This project hasn't been updated for 1.5 years. Currently, my approach is to ignore this kind of error, and the detailed configuration is as follows.

rollupOptions: {
    onwarn(warning, rollupWarn) {
        if (warning.code == "EVAL" && warning.id?.includes("flexsearch")) return;
        rollupWarn(warning);
    }
}
DanielleConstell commented 11 months ago

@zhe-he Thanks, that also works 😄

ts-thomas commented 10 months ago

Thanks for the hint, the eval will be removed in v0.8