Experimental alternative module loader aiming to challenge the status quo
Experimental alternative module loader aiming to challenge the status quo
standard/8.0.0
) causing loopsRefactor this:
pkg/@scope/packagename/1.x.x.tgz
lib/@scope/packagename/1.x.x/*
lib/@scope/packagename/1.x.x/*/node_modules/dependencies
Into this:
@scope/packagename/1.x.x/m.tgz <-- mount m.tgz as folder m
@scope/packagename/1.x.x/m/package/* <-- (I arbitrarily chose /m/ to keep filenames shorter)
@scope/packagename/1.x.x/node_modules/dependencies <-- dependencies are ABOVE pkg folder not inside
@scope/packagename/1.x.x/package.json <-- cached metadata
I’m not happy with Node’s module management.
npm
.index.js
or server.js
… orpackage.json
… which it then reads to get the “main” entry… wait, so why is it ignoring itpackage.json
file.package.json
that actually isn’t ever require
d.Anyway, one of several ideas I’m playing with to improve Node module management is moving dependency declaration
away from package.json to the file where it is actually used. This project takes inspiration from lots of places,
notably require-install and ied.
Use it just like you would require, except include the version #.
const node_module = require('node-modules.io')
const express = node_module('express/4.14.0')
It will alert you with deprecation messages if your package.json is
out of date, or update them automatically if you add an option to your package.json
file giving it permission to do so.
Funnily enough, in order to achieve this alt-require semantics, I thought it would be a good idea to handle installing the packages organized by version number. This seems easy at first, until you realize that installing each dependency separately destroy’s Node’s module caching mechanism which is based on absolute path name (at least until Node 6…). So then you think, well that’s easy, I’ll just install the dependencies of my dependencies myself, in my fancy versioned directory structure. AND THEN…
…so anyway, now this project has detoured into creating something like ied and pnpm
Here’s what I’m thinking…
const node_module = require('node-modules.io')
const express = node_module('express', '4.14.0')
const body_parser = node_module('body-parser', '1.15.2')
Or maybe something more DRY?
const node_modules = require('node-modules.io')
const {express, body_parser} = node_modules('express/4.14.0', 'body-parser/1.15.2')
Or something that aligns with ES6 modules?
import * as _ from 'lodash/4.14.2'
That last one is probably the best option… sadly ES6 module support is lacking from Node, and I don’t really want to bring a transpiler into this project… Lemme see if somebody has an "import"ish module loader for node… nope can’t find one. I appologize for the stream-of-conciousness.
This looks interesting: register-module
and this: sweetjs
OK. FINE. I’m picking one. It must
a) not be incompatible with current Node code
b) not involve scary hacks of Module._resolveFilename
c) be forward-compatible with ES6 module syntax so we can transition to it at some point.
const node_module = require('node-modules.io')
const express = node_module('express/4.14.0')
There. Simple and sweet. No better nor worse than require
. 🤷