Gathering detailed insights and metrics for dumber-module-loader
Gathering detailed insights and metrics for dumber-module-loader
Gathering detailed insights and metrics for dumber-module-loader
Gathering detailed insights and metrics for dumber-module-loader
npm install dumber-module-loader
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2 Stars
250 Commits
3 Watching
2 Branches
1 Contributors
Updated on 26 Jan 2022
Minified
Minified + Gzipped
JavaScript (97.56%)
HTML (2.22%)
CSS (0.22%)
Cumulative downloads
Total Downloads
Last day
120%
11
Compared to previous day
Last week
-6%
47
Compared to previous week
Last month
-22.4%
239
Compared to previous month
Last year
-16.8%
3,779
Compared to previous year
A modern AMD module loader, used by dumber bundler internally.
dumber-module-loader is a loose AMD implementation, does not strictly follow the AMD spec.
For users of dumber bundler, you only need to know that the internal module loader is an AMD loader, similar to requirejs. The good old AMD gives dumber bundler intuitive code splitting, and flexible runtime composition.
define('../package.json', ...)
. We allow it. This is to support dependency '../package.json'
that could be required by src/app.js
. We say module id '../package.json'
is above surface.load()
function, doesn't support normalize()
function, doesn't support load.fromText()
function (not in spec, but some requirejs plugins use it). Note there is built-in support of traditional text!
and json!
plugins out of the box.1requirejs([/\.spec$/], function() { 2});
Mimic Node.js module resolving behaviour so dumber bundler can do less work.
require('foo/bar')
could load module foo/bar
, foo/bar.js
, foo/bar.json
, foo/bar/index.js
, or foo/bar/index.json
.package.json
file in folder foo/bar/
, it can load file foo/bar/resolved/main.js
, dumber will build an alias foo/bar/index
to foo/bar/resolved/main.js
.Two module spaces: user
(default, for local source file) and package
(for npm packages and local packages).
user
space can acquire user
or package
modules.package
space can only acquire package
modules.user
and package
space can contain module with the same id. This is designed to avoid local src/util.js
over-shadowing Node.js core module util
.Full support of Node.js circular dependencies (for packages like yallist, note yallist 3.0.3 has removed circular dependency).
Besides normal plugin, we support ext plugin which targets ext name.
text!
, json!
, and raw!
.text!some.fie
will resolve to the text content of the file, at runtime it uses fetch API reponse.text()
to get the content.json!some.fie
will resolve to the parsed json, at runtime it uses fetch API reponse.json()
to parse the content.raw!some.fie
will resolve to fetch API reponse
, note the result is a promise, not final value.1define('ext:html', {load: function(name, req, load) { 2 req(['text!' + name], text => load(text)); 3}});
'ext:css'
plugin to support style sheet injection.baseUrl
, paths
, and bundles
.data-main
attribute on script tag doesn't affect baseUrl
, data-main
is purely a module id.paths
support is simplified.
"foo": "/foo"
"foo": "common/foo"
, resolve foo/bar/lo
to common/foo/bar/lo
. Note we treat common/foo/bar/lo
as the real module id, it could result to an existing known module, otherwise go through remote fetch."foo": ["common/foo", "shared/foo"]
the fail-over array.1define('common/foo', ['./bar'], function (bar) { /* ... */ }); 2requirejs.config({paths: {'foo': 'common/foo'}}); 3requirejs(['foo'], function (foo) { 4 // requirejs resolves './bar' to 'bar', 5 // we resolves './bar' to 'common/bar'. 6});
bundles
config is different, it needs two arrays, 'user'
and 'package'
for the two module spaces.
{"a-bundle": {"user": ['a', 'b'], "package": ["lodash", "jquery"]}}
.package
space, it can be written in requirejs compatible format, {"a-bundle": ['a', 'b']}
.require([...], callback, errback)
doesn't support optional config, errback only gets one error object.package
or map
config.There globals, define
, requirejs
(same as require
).
define(id? :string, deps?: string[], callback: function | any)
Ref: https://github.com/amdjs/amdjs-api/blob/master/AMD.md
When id
is absent, it defines an anonymous module. Anonymous module is only for runtime dynamically module loading.
requirejs(deps: string[], callback?: function, errback?: function)
Ref: https://github.com/amdjs/amdjs-api/blob/master/require.md
When errback
is called, it only gets one error object (an instance of Error
);
define.switchToUserSpace()
Switch to user module space, define()
call after this will define module in user space.
User module space is the default module space.
define.switchToPackageSpace()
Switch to package module space, define()
call after this will define module in package space.
define.currentSpace()
Returns "user"
if current space is user space, or "package"
if current space is packaeg space. Current space only affects define()
call, it doesn't affect requirejs()
call.
define.nameAnonymous(id)
Provide a module id for the last anonymous module defined like define([deps], function() {})
. The new module id is defined on current space (either user space or package space).
When there is no anonymous module defined, this method will do nothing.
define.reset()
Reset all config, remove all registered and defined modules, switch to default user space.
requirejs.config(options)
Options supports:
baseUrl
The default baseUrl is empty string ""
, the behaviour is same as requirejs
default baseUrl "./"
.
When dumber-module-loader tries to load a missing module 'foo/bar' at runtime, it will call fetch API fetch("foo/bar.js")
.
The real url is relative to app's current route.
If there is <base href="/some/folder/">
in html head, the real url is relative to "/some/folder/"
, note the ending "/"
is significant.
If you set baseUrl
to some/folder
, the resulting fetch call fetch("some/folder/foo/bar.js")
is still relative to current route or <base>
tag.
To ignore app's current route and <base>
tag, set baseUrl
to an absolute value like /some/folder
, the resulting fetch call fetch("/some/folder/foo/bar.js")
hits absolute URL.
paths
Similar to requirejs
paths, but simplified, see above.
bundles
Tells dumber-module-loader what remote bundle file contains certain missing module. Note user and package space modules are listed separately.
nameSpace
is optional, it's designed to load foreign bundle file at runtime.
When nameSpace
is in use, all modules in user module space will be prefixed with optional-name-space/
. For instance, app
module is name spaced as optional-name-space/app
. Note all modules in package module space are not affected, for instance, lodash
will still be lodash
.
1bundles: { 2 'app-bundle': { 3 nameSpace: 'optional-name-space', 4 user: ['app', 'app.html', 'util', 'common/index'], 5 package: ['lodash', 'lodash/map', 'util'] 6 } 7}
for bundles only contain user space modules, a simplified config can be used.
1bundles: { 2 'app-bundle': ['app', 'app.html', 'util', 'common/index'] 3}
requirejs.definedValues()
Return all defined module values {"id": val, "id2": val2}
, excluding registered but not evaluated. This is to match existing behaviour of requirejs
and webpack
. Note if there is duplicated module id in user and package space, the user space module value will show up.
requirejs.defined(id: string)
Check whether a module id is defined, excluding registered but not evaluated. This is to match existing behaviour of requirejs
.
requirejs.specified(id: string)
Check whether a module id is defined or registered but not evaluated. This is to match existing behaviour of requirejs
.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
binaries present in source code
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More