![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
amdextract
Advanced tools
Uses AST to extract AMD modules, their parts and an optimized output without unused dependencies while keeping the original format.
Uses AST to extract AMD modules, their parts and an optimized output without unused dependencies while keeping the original format.
source.js
define('module1', ['p1', 'p2'], function (a, b) {
/**
* b is not used in this scope.
*/
return (function(b) {
return b;
})(a);
});
define('module2', ['p1', 'p2', 'p3', 'p4'], function (a, b, c) {
return b;
});
example.js
var fs = require('fs');
var amdextract = require('amdextract');
var content = fs.readFileSync('source.js');
var result = amdextract.parse(content);
console.log(result.results.length + ' modules detected.');
result.results.forEach(function (r) {
console.log('Unused paths: ' + r.unusedPaths.join(', '));
});
console.log('\nOptimized output:');
console.log(result.optimizedContent);
output
2 modules detected.
Unused paths: p2
Unused paths: p1, p3, p4
Optimized output:
define('module1', ['p1'], function (a) {
/**
* b is not used in this scope.
*/
return (function(b) {
return b;
})(a);
});
define('module2', ['p2'], function (b) {
return b;
});
Type: string JavaScript source for parsing.
Type: Array Default value: []
An array of strings or RegExps that represent dependency names that should not take into account.
Type: Array Default value: []
An array of strings or RegExps that represent dependency paths that should not take into account.
NOTE: exceptsPaths
can also be declared before each module definition as a comment of strings of module paths separated by commas. This only applies on the underlying module definition.
source.js
/* exceptsPaths: p3 */
define(['p1', 'p2', 'p3'], function (a, b, c) {
return b;
});
optimized-source.js
/* exceptsPaths: p3 */
define(['p2', 'p3'], function (b, c) {
return b;
});
Type: Boolean Default value: false
Removes unused dependencies from content
and returns optimized content as optimizedContent
property of result.
Returns an object with the following properties:
Type: Array
An array of hash objects witch have this properties for each AMD module detected in content
:
moduleId
paths
dependencies
unusedPaths
unusedDependencies
Type: String
Optimized content
(original content without unused dependencies).
This property is available when the value of option removeUnusedDependencies
is true.
FAQs
Uses AST to extract AMD modules, their parts and an optimized output without unused dependencies while keeping the original format.
The npm package amdextract receives a total of 34 weekly downloads. As such, amdextract popularity was classified as not popular.
We found that amdextract demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.