1.0.3 • Published 4 years ago

@melodyn/dynamicimport v1.0.3

Weekly downloads
147
License
MIT
Repository
github
Last release
4 years ago

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 or make expand for install dependencies
  • npm run test or make test for run tests
1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago