es6-module-transpiler
Advanced tools
Comparing version 0.4.0 to 0.5.1
{ | ||
"name": "es6-module-transpiler", | ||
"version": "0.4.0", | ||
"description": "es6-module-transpiler is an experimental compiler that allows you to write your JavaScript using a subset of the current ES6 module syntax, and compile it into AMD, CommonJS, and globals styles.", | ||
"version": "0.5.1", | ||
"description": "es6-module-transpiler is an experimental compiler that allows you to write your JavaScript using a subset of the current ES6 module syntax, and compile it into various formats.", | ||
"homepage": "http://square.github.com/es6-module-transpiler", | ||
@@ -17,6 +17,13 @@ "keywords": [ | ||
}, | ||
"files": [ | ||
"bin", | ||
"lib", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"directories": { | ||
"lib": "./lib" | ||
"lib": "./lib", | ||
"test": "test" | ||
}, | ||
"main": "./dist/es6-module-transpiler", | ||
"main": "lib/index.js", | ||
"repository": { | ||
@@ -26,26 +33,19 @@ "type": "git", | ||
}, | ||
"scripts": { | ||
"test": "npm run test-bundle && npm run test-commonjs", | ||
"test-bundle": "node test/runner.js -f bundle", | ||
"test-commonjs": "node test/runner.js -f commonjs" | ||
}, | ||
"author": "Square, Inc.", | ||
"license": "Apache 2", | ||
"dependencies": { | ||
"optimist": "~0.3.5", | ||
"through": "~2.3.4" | ||
"recast": "^0.5.17", | ||
"esprima": "git://github.com/thomasboyt/esprima#4be906f1abcbb", | ||
"ast-util": "^0.1.2", | ||
"mkdirp": "^0.5.0", | ||
"posix-getopt": "^1.0.0" | ||
}, | ||
"scripts": { | ||
"test": "grunt build && grunt test", | ||
"prepublish": "grunt build && grunt test" | ||
}, | ||
"devDependencies": { | ||
"es6ify": "~0.2.0", | ||
"esprima": "git://github.com/thomasboyt/esprima#4be906f1abcbb", | ||
"grunt": "~0.4.1", | ||
"grunt-browserify": "~1.2.0", | ||
"grunt-contrib-clean": "~0.5.0", | ||
"grunt-contrib-concat": "~0.3.0", | ||
"grunt-contrib-uglify": "~0.2.2", | ||
"grunt-es6-module-transpiler": "~0.4.1", | ||
"grunt-simple-mocha": "~0.4.0", | ||
"matchdep": "~0.1.2", | ||
"mocha": "~1.12.0", | ||
"qunit-mocha-ui": "0.0.4", | ||
"uglify-js": "~2.2.4", | ||
"grunt-contrib-jshint": "~0.6.2" | ||
"example-runner": "^0.1.0" | ||
} | ||
} | ||
} |
193
README.md
@@ -24,9 +24,10 @@ # ES6 Module Transpiler [![Build Status](https://travis-ci.org/square/es6-module-transpiler.png)](https://travis-ci.org/square/es6-module-transpiler) | ||
The easiest way to use the transpiler is from an existing build tool. There several plugins developed for different build tools: | ||
The easiest way to use the transpiler is from an existing build tool. There | ||
several plugins developed for different build tools: | ||
* **Grunt:** [grunt-es6-module-transpiler](https://github.com/joefiorini/grunt-es6-module-transpiler), maintained by @joefiorini | ||
* **Gulp:** [gulp-es6-module-transpiler](https://github.com/ryanseddon/gulp-es6-module-transpiler), maintained by @ryanseddon | ||
* **Brunch:** [es6-module-transpiler-brunch](https://github.com/gcollazo/es6-module-transpiler-brunch), maintained by @gcollazo *(CommonJS only)* | ||
* **Broccoli:** [broccoli-es6-concatenator](https://github.com/joliss/broccoli-es6-concatenator), maintained by @joliss | ||
* **Mimosa:** [mimosa-es6-module-transpiler](https://github.com/dbashford/mimosa-es6-module-transpiler), maintained by @dbashford | ||
* **Grunt:** [grunt-es6-module-transpiler](https://github.com/joefiorini/grunt-es6-module-transpiler), maintained by @joefiorini (not yet compatible with v0.5.x) | ||
* **Gulp:** [gulp-es6-module-transpiler](https://github.com/ryanseddon/gulp-es6-module-transpiler), maintained by @ryanseddon (not yet compatible with v0.5.x) | ||
* **Brunch:** [es6-module-transpiler-brunch](https://github.com/gcollazo/es6-module-transpiler-brunch), maintained by @gcollazo *(CommonJS only)* (not yet compatible with v0.5.x) | ||
* **Broccoli:** [broccoli-es6-concatenator](https://github.com/joliss/broccoli-es6-concatenator), maintained by @joliss (not yet compatible with v0.5.x) | ||
* **Mimosa:** [mimosa-es6-module-transpiler](https://github.com/dbashford/mimosa-es6-module-transpiler), maintained by @dbashford (not yet compatible with v0.5.x) | ||
@@ -39,3 +40,3 @@ ### Executable | ||
$ npm install -g es6-module-transpiler | ||
$ compile-modules foo.js --to compiled | ||
$ compile-modules convert < foo.js | ||
``` | ||
@@ -46,38 +47,3 @@ | ||
``` | ||
compile-modules FILE [FILE…] --to OUTPUT [--type=TYPE] | ||
[--infer-name] [--module-name=NAME] | ||
[--global=GLOBAL] [--imports=IMPORTS] | ||
FILE | ||
An input file relative to the current directory to process. | ||
OUTPUT | ||
An output directory relative to the current directory. If it does not exist, | ||
it will be created. | ||
TYPE | ||
One of `amd` (for AMD output), `cjs` (for CommonJS output), `yui` (for YUI | ||
output). | ||
INFER-NAME | ||
If you use the --infer-name flag with the AMD or YUI type, the transpiler will | ||
generate a name for the module from its file path. The default is to output | ||
anonymous modules. | ||
NAME | ||
You can supply a name to use as the module name. By default, the transpiler | ||
will use the name of the file (without the ending `.js`) as the module name. | ||
You may not use this option if you provided multiple FILEs. | ||
GLOBAL | ||
This option is only supported when the type is `globals`. By default, the | ||
`globals` option will attach all of the exports to `window`. This option will | ||
attach the exports to a single named variable on `window` instead. | ||
IMPORTS | ||
This option is only supported when the type is | ||
`globals`. It is a hash option. If your module | ||
includes imports, you must use this option to | ||
map the import names onto globals. For example, | ||
`--imports ember:Ember underscore:_` | ||
compile-modules convert -I lib -o out FILE [FILE…] | ||
``` | ||
@@ -90,29 +56,16 @@ | ||
```javascript | ||
var Compiler = require("es6-module-transpiler").Compiler; | ||
var transpiler = require('es6-module-transpiler'); | ||
var Container = transpiler.Container; | ||
var FileResolver = transpiler.FileResolver; | ||
var BundleFormatter = transpiler.formatters.bundle; | ||
var compiler = new Compiler(inputString, moduleName); | ||
var output = compiler.toAMD(); // AMD output as a string | ||
``` | ||
var container = new Container({ | ||
resolvers: [new FileResolver(['lib/'])], | ||
formatter: new BundleFormatter() | ||
}); | ||
If you want to emit globals output, and your module has imports, you must | ||
supply an `imports` hash. You can also use the `global` option to specify that | ||
exports should be added to a single global instead of `window`. | ||
```javascript | ||
var Compiler = require("es6-module-transpiler").Compiler; | ||
var imports = { underscore: "_", ember: "Ember" }; | ||
var options = { imports: imports, global: "RSVP" }; | ||
var compiler = new Compiler(string, name, options); | ||
compiler.toGlobals() // window global output | ||
container.getModule('index'); | ||
container.write('out/mylib.js'); | ||
``` | ||
The `string` parameter is a string of JavaScript written using the declarative | ||
module syntax. | ||
The `name` parameter is an optional name that should be used as the name of the | ||
module if appropriate (for AMD, this maps onto the first parameter to the | ||
`define` function). | ||
## Supported ES6 Module Syntax | ||
@@ -129,3 +82,3 @@ | ||
// foobar.js | ||
var foo = "foo", bar = "bar"; | ||
var foo = 'foo', bar = 'bar'; | ||
@@ -141,4 +94,4 @@ export { foo, bar }; | ||
// foobar.js | ||
export var foo = "foo"; | ||
export var bar = "bar"; | ||
export var foo = 'foo'; | ||
export var bar = 'bar'; | ||
``` | ||
@@ -149,5 +102,5 @@ | ||
```js | ||
import { foo, bar } from "foobar"; | ||
import { foo, bar } from 'foobar'; | ||
console.log(foo); // "foo" | ||
console.log(foo); // 'foo' | ||
``` | ||
@@ -168,3 +121,3 @@ | ||
export default = jQuery; | ||
export default jQuery; | ||
``` | ||
@@ -175,3 +128,3 @@ | ||
```javascript | ||
import $ from "jquery"; | ||
import $ from 'jquery'; | ||
``` | ||
@@ -198,3 +151,4 @@ | ||
In ES6, this created object is *read-only*, so don't treat it like a mutable | ||
namespace! | ||
namespace! **NOTE:** This syntax especially may be removed or modified before | ||
ES6 is finalized! | ||
@@ -224,93 +178,8 @@ #### `import "foo";` | ||
any outside consumer needs to be aware that it should use the `default` key and | ||
not the module itself. For example, an AMD consumer should look like this: | ||
not the module itself. For example, a CommonJS consumer should look like this: | ||
```js | ||
define(["jquery"], | ||
function(jQuery) { | ||
var $ = jQuery['default']; | ||
}); | ||
var $ = require('jquery')['default']; | ||
``` | ||
In general, if your project wants to create a "native" module for AMD, YUI, CJS, | ||
or globals, you should wrap modules with default exports like so: | ||
```js | ||
// AMD wrapper | ||
define("jquery-amd", | ||
["jquery"], | ||
function(jQuery) { | ||
return jQuery['default']; | ||
}); | ||
// consumer | ||
define(["jquery-amd"], | ||
function($) { | ||
// $ is now bound to jQuery['default'] | ||
}); | ||
``` | ||
The reason for all of this extra boilerplate is that ES6 modules support | ||
a module having both default and named exports, whereas AMD, YUI and CJS do not. | ||
### Individual Exports | ||
This input (ember.js): | ||
```javascript | ||
var get = function(obj, key) { | ||
return obj[key]; | ||
}; | ||
var set = function(obj, key, value) { | ||
obj[key] = value; | ||
return obj; | ||
}; | ||
export { get, set }; | ||
``` | ||
will compile into this AMD output: | ||
```javascript | ||
define( | ||
["exports"], | ||
function(__exports__) { | ||
"use strict"; | ||
var get = function(obj, key) { | ||
return obj[key]; | ||
}; | ||
var set = function(obj, key, value) { | ||
obj[key] = value; | ||
return obj; | ||
}; | ||
__exports__.get = get; | ||
__exports__.set = set; | ||
}); | ||
``` | ||
The output is the same whether you use the single-line export (`export { get, | ||
set }`) or multiple export lines, as above. | ||
### Individual Imports | ||
This input: | ||
```javascript | ||
import { get, set } from "ember"; | ||
``` | ||
will compile into this AMD output: | ||
```javascript | ||
define( | ||
["ember"], | ||
function(__dependency1__) { | ||
"use strict"; | ||
var get = __dependency1__.get; | ||
var set = __dependency1__.set; | ||
}); | ||
``` | ||
## Installation | ||
@@ -324,3 +193,3 @@ | ||
$ sudo npm install -g es6-module-transpiler | ||
$ npm install -g es6-module-transpiler | ||
@@ -327,0 +196,0 @@ ## Acknowledgements |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable and can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
1
23
2
85967
5
2544
217
1
7
1
+ Addedast-util@^0.1.2
+ Addedesprima@git://github.com/thomasboyt/esprima#4be906f1abcbb
+ Addedmkdirp@^0.5.0
+ Addedposix-getopt@^1.0.0
+ Addedrecast@^0.5.17
+ Addedamdefine@1.0.1(transitive)
+ Addedast-types@0.3.38(transitive)
+ Addedast-util@0.1.2(transitive)
+ Addedcls@0.1.5(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedposix-getopt@1.2.1(transitive)
+ Addedprivate@0.1.8(transitive)
+ Addedrecast@0.5.27(transitive)
+ Addedsource-map@0.1.32(transitive)
- Removedoptimist@~0.3.5
- Removedthrough@~2.3.4
- Removedoptimist@0.3.7(transitive)
- Removedthrough@2.3.8(transitive)
- Removedwordwrap@0.0.3(transitive)