Socket
Book a DemoInstallSign in
Socket

recast-deamdify

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

recast-deamdify

Transform AMD modules to CommonJS using recast.

latest
Source
npmnpm
Version
1.1.5
Version published
Maintainers
1
Created
Source

recast-deamdify

build status npm version npm downloads dependency status devDependency status

Transform AMD modules to CommonJS using recast.

Usage: recast-deamdify [source dir] {OPTIONS}

Options:
  --output, -o  Write the trasformed files to this dir.
                This option is required if a source dir is specified.
                If unspecified and a single source file is being transformed,
                recast-deamdify will print to stdout.

Examples:
  cat foo.js | recast-deamdify > bar.js
  recast-deamdify src/ -o dest/

Motivation

Retaining the correct format in the transformed code was important for my use case. Other modules exist but didn't quite fit the bill (e.g. require2commonjs).

Initial versions of this module used esprima then acorn plus their associated code generators, but I couldn't get the results I wanted. Hence, recast.

Installation

$ npm install -g recast-deamdify

Examples

Single file

Given a.js:

define('a', ['./foo', './bar'], function(foo, bar){

  'use strict';

  var baz = require('baz');
  var qux = require('qux');

  console.log('some line of code');

  return {
    height: foo.height,
    width: bar.width
  };

});

This:

$ cat test/fixtures/a.js | recast-deamdify > foo.js

Or this:

var recastDeamdify = require('recast-deamdify');
var fs = require('fs');

fs.createReadStream('./test/fixtures/a.js')
  .pipe(recastDeamdify())
  .pipe(fs.createWriteStream('foo.js'));

Will produce foo.js:

'use strict';

var foo = require('./foo');
var bar = require('./bar');
var baz = require('baz');
var qux = require('qux');

console.log('some line of code');

module.exports = {
  height: foo.height,
  width: bar.width
};

Multiple files

Let's say we want to transform all .js files contained in src and write them to dest, whilst maintaining src's directory structure:

$ recast-deamdify src -o dest

Or you can use the API:

var recastDeamdify = require('recast-deamdify');

recastDeamdify({
  srcDir: 'src',
  destDir: 'dest'
}, function(){
  console.log('complete!');
});

Tests

$ npm test

License

MIT

Keywords

transform

FAQs

Package last updated on 17 Feb 2016

Did you know?

Socket

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.

Install

Related posts