dOrgTech / DAOcreator

dApp for creating and interacting with DAOs
https://dorg.tech
MIT License
35 stars 18 forks source link

Please, don't use dynamic require imports #525

Open Razzwan opened 3 years ago

Razzwan commented 3 years ago

Instead of such syntax:

const partOfLibName = 'part1';
const myLib = require(partOfLibName + 'LibName');

Please, use such one:

cosnt myLib1 = require('part1LibName');
cosnt myLib2 = require('part2LibName');

// and later
let res;
if (/* some condition here */) {
  res = myLib1.method();
} else {
    res = myLib2.method();
}

Or with dynamic imports:

cosnt myLib1 = import('part1LibName');
cosnt myLib2 = import('part2LibName');

// and later
let res;
if (/* some condition here */) {
  myLib1.then(res => {
    // user res here
  });
} else {
  myLib2.then(res => {
    // user res here
  });
}
roienatan commented 3 years ago

Also you can use the new JavaScript 2020 native dynamic import with await, something like this:

let module = await import('/modules/my-module.js');

This can be written inside an if statement.

dOrgJelli commented 3 years ago

Hey @Razzwan, I'm assuming you're referring to these two usages: https://github.com/dOrgTech/DAOcreator/blob/09db2fdb239c69f8c12ad58fd0a84c3789335484/packages/lib/src/dependency/arc/src/migrate-dao.js#L703 and https://github.com/dOrgTech/DAOcreator/blob/09db2fdb239c69f8c12ad58fd0a84c3789335484/packages/lib/src/dependency/arc/src/utils.js#L21-L28

Both of these source files come from this repo: https://github.com/daostack/migration

They're copied into the DAOcreator here: https://github.com/dOrgTech/DAOcreator/blob/master/packages/lib/scripts/prepArc.js

The reason this manual copying is done is to:

If you'd like this code changed, I'd suggest making an issue here: https://github.com/daostack/migration

orenyodfat commented 3 years ago

ok. will try to update migration https://github.com/daostack/migration/issues/373