1.0.3 • Published 4 years ago
@melodyn/dynamicimport v1.0.3
DynamicImport
Automatically load your modules from subdirectories.
Motivation
The voices in my head made me do this. More details: https://habr.com/ru/post/478974/
Problem
Dynamic import V8 do not support regexp, so we make such decisions:
$ tree
.
├── modules
│ ├── a
│ │ └── index.ts
│ ├── b
│ │ └── index.ts
│ └── c
│ └── bobule.ts
├── index.ts
└── package.json
// some index.ts
import a from './modules/a';
import b from './modules/b';
import c from './modules/c/bobule.ts';
export default {
module: a,
dopule: b,
bobule: c
};
So we lift up the index.ts import from ./modules/index.ts from ./moduleName/index.ts...
How this can be solved
npm i @melodyn/dynamicimport
const myModules = dynamicimport(projectRoot, ['path', 'to', '*', '*', 'index.js|ts'], moduleName)
This function will return an array of loaded modules, as in the documentation.
To hell with chatter, see the code.
Local development
Requirements:
- Node: >=12.13 or Docker
Docker commands see in Makefile
npm ci
ormake expand
for install dependenciesnpm run test
ormake test
for run tests