init
This commit is contained in:
22
node_modules/babelify/LICENSE
generated
vendored
Normal file
22
node_modules/babelify/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2015 Sebastian McKenzie
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
221
node_modules/babelify/README.md
generated
vendored
Normal file
221
node_modules/babelify/README.md
generated
vendored
Normal file
@@ -0,0 +1,221 @@
|
||||
# babelify [](https://travis-ci.org/babel/babelify)
|
||||
|
||||
[Babel](https://github.com/babel/babel) [browserify](https://github.com/substack/node-browserify) transform.
|
||||
|
||||
As of [Babel 6.0.0](http://babeljs.io/blog/2015/10/29/6.0.0/) there are **no plugins included by default**. For babelify to be useful, you must also include some [presets](http://babeljs.io/docs/plugins/#presets) and/or [plugins](http://babeljs.io/docs/plugins/#transform).
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
# Babel 7
|
||||
$ npm install --save-dev babelify @babel/core
|
||||
|
||||
# Babel 6
|
||||
$ npm install --save-dev babelify@8 babel-core
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### CLI
|
||||
|
||||
```sh
|
||||
$ browserify script.js -o bundle.js -t [ babelify --presets [ @babel/preset-env @babel/preset-react ] --plugins [ @babel/plugin-transform-class-properties ] ]
|
||||
```
|
||||
|
||||
### Node
|
||||
|
||||
```javascript
|
||||
var fs = require("fs");
|
||||
var browserify = require("browserify");
|
||||
browserify("./script.js")
|
||||
.transform("babelify", {presets: ["@babel/preset-env", "@babel/preset-react"]})
|
||||
.bundle()
|
||||
.pipe(fs.createWriteStream("bundle.js"));
|
||||
```
|
||||
|
||||
**NOTE:** [Presets and plugins](http://babeljs.io/docs/plugins/) need to be installed as separate modules. For the above examples to work, you'd need to also install [`@babel/preset-env`](https://www.npmjs.com/package/@babel/preset-env) and [`@babel/preset-react`](https://www.npmjs.com/package/@babel/preset-react):
|
||||
|
||||
```sh
|
||||
$ npm install --save-dev @babel/preset-env @babel/preset-react
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
Selected options are discussed below. See the [babel](http://babeljs.io/) docs for the complete list of [options](http://babeljs.io/docs/usage/options/).
|
||||
|
||||
Options may be passed in via standard [browserify](https://github.com/substack/node-browserify#btransformtr-opts) ways:
|
||||
|
||||
```sh
|
||||
$ browserify -t [ babelify --presets [ @babel/preset-env @babel/preset-react ] ]
|
||||
```
|
||||
|
||||
```js
|
||||
browserify().transform("babelify", {presets: ["@babel/preset-env", "@babel/preset-react"]});
|
||||
```
|
||||
|
||||
```js
|
||||
var babelify = require("babelify");
|
||||
browserify().transform(babelify, {presets: ["@babel/preset-env", "@babel/preset-react"]});
|
||||
```
|
||||
|
||||
Or, with the `configure` method:
|
||||
|
||||
```js
|
||||
browserify().transform(babelify.configure({
|
||||
presets: ["@babel/preset-env", "@babel/preset-react"]
|
||||
}));
|
||||
```
|
||||
|
||||
#### Customizing extensions
|
||||
|
||||
By default, all files with the extensions `.js`, `.es`, `.es6` and `.jsx` are compiled. You can change this by passing an array of extensions.
|
||||
|
||||
**NOTE:** This will override the default ones so if you want to use any of them
|
||||
you have to add them back.
|
||||
|
||||
```js
|
||||
browserify().transform("babelify", {extensions: [".babel"]});
|
||||
```
|
||||
|
||||
```sh
|
||||
$ browserify -t [ babelify --extensions .babel ]
|
||||
```
|
||||
|
||||
Now you can use:
|
||||
|
||||
```js
|
||||
import NavBar from "nav-bar.babel";
|
||||
var Panels = require("panels.babel");
|
||||
```
|
||||
|
||||
**NOTE:** By default, Browserify will only lookup `.js` and `.json` files when the extension is ommited (like node's `require`). To lookup additional extensions, use browserify's [`extensions` option](https://github.com/substack/node-browserify#browserifyfiles--opts).
|
||||
|
||||
```js
|
||||
browserify({
|
||||
extensions: [".babel"]
|
||||
}).transform("babelify", {
|
||||
extensions: [".babel"]
|
||||
});
|
||||
```
|
||||
|
||||
```sh
|
||||
$ browserify --extensions=.babel -t [ babelify --extensions .babel ]
|
||||
```
|
||||
|
||||
Now you can omit the extension and compile `.babel` files:
|
||||
|
||||
```js
|
||||
import NavBar from "nav-bar";
|
||||
var Panels = require("panels");
|
||||
```
|
||||
|
||||
#### Source maps
|
||||
|
||||
By default, browserify sets the source map sources paths relative to the basedir (or to `process.cwd()` if not set). To make the sources paths absolute, set the `sourceMapsAbsolute` option on babelify:
|
||||
|
||||
```js
|
||||
browserify().transform("babelify", {
|
||||
sourceMapsAbsolute: true
|
||||
});
|
||||
```
|
||||
|
||||
```sh
|
||||
$ browserify -t [ babelify --sourceMapsAbsolute ]
|
||||
```
|
||||
|
||||
#### Additional options
|
||||
|
||||
```javascript
|
||||
browserify().transform(babelify.configure({
|
||||
// Optional ignore regex - if any filenames **do** match this regex then
|
||||
// they aren't compiled
|
||||
ignore: /regex/,
|
||||
|
||||
// Optional only regex - if any filenames **don't** match this regex
|
||||
// then they aren't compiled
|
||||
only: /my_es6_folder/
|
||||
}))
|
||||
```
|
||||
|
||||
```sh
|
||||
$ browserify -t [ babelify --ignore regex --only my_es6_folder ]
|
||||
```
|
||||
|
||||
#### Babel result (metadata and others)
|
||||
|
||||
Babelify emits a `babelify` event with Babel's full result object as the first
|
||||
argument, and the filename as the second. Browserify doesn't pass-through the
|
||||
events emitted by a transform, so it's necessary to get a reference to the
|
||||
transform instance before you can attach a listener for the event:
|
||||
|
||||
```js
|
||||
var b = browserify().transform(babelify);
|
||||
|
||||
b.on("transform", function(tr) {
|
||||
if (tr instanceof babelify) {
|
||||
tr.once("babelify", function(result, filename) {
|
||||
result; // => { code, map, ast, metadata }
|
||||
});
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## FAQ
|
||||
|
||||
### Why aren't files in `node_modules` being transformed?
|
||||
|
||||
This is the default browserify behavior.
|
||||
|
||||
A possible solution is to add:
|
||||
|
||||
```json
|
||||
{
|
||||
"browserify": {
|
||||
"transform": ["babelify"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
to the root of all your modules `package.json` that you want to be transformed. If you'd like to
|
||||
specify options then you can use:
|
||||
|
||||
```json
|
||||
{
|
||||
"browserify": {
|
||||
"transform": [["babelify", { "presets": ["@babel/preset-env"] }]]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Another solution (proceed with caution!) is to run babelify as a [global](https://github.com/substack/node-browserify#btransformtr-opts) transform. Use the babel [`ignore` option](http://babeljs.io/docs/usage/options/) to narrow the number of files transformed:
|
||||
|
||||
```js
|
||||
browserify().transform("babelify", {
|
||||
global: true,
|
||||
ignore: /\/node_modules\/(?!app\/)/
|
||||
});
|
||||
```
|
||||
|
||||
The above example will result in a transform that also includes the `app` module in `node_modules`: the `global` flag transform all files, and the `ignore` regular expression then excludes all those in the `node_modules` directory *except* those that are in `node_modules/app` (since `?!` will match if the given suffix is absent).
|
||||
|
||||
### Why am I not getting source maps?
|
||||
|
||||
To use source maps, enable them in browserify with the [`debug`](https://github.com/substack/node-browserify#browserifyfiles--opts) option:
|
||||
|
||||
```js
|
||||
browserify({debug: true}).transform("babelify");
|
||||
```
|
||||
|
||||
```sh
|
||||
$ browserify -d -t [ babelify ]
|
||||
```
|
||||
|
||||
If you want the source maps to be of the post-transpiled code, then leave `debug` on, but turn off babelify's `sourceMaps`:
|
||||
|
||||
```js
|
||||
browserify({debug: true}).transform("babelify", {sourceMaps: false});
|
||||
```
|
||||
|
||||
```sh
|
||||
$ browserify -d -t [ babelify --no-sourceMaps ]
|
||||
```
|
171
node_modules/babelify/index.js
generated
vendored
Normal file
171
node_modules/babelify/index.js
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
"use strict";
|
||||
|
||||
var stream = require("stream");
|
||||
var util = require("util");
|
||||
var path = require("path");
|
||||
|
||||
let babel;
|
||||
try {
|
||||
babel = require("@babel/core");
|
||||
} catch (err) {
|
||||
if (err.code === "MODULE_NOT_FOUND") {
|
||||
err.message +=
|
||||
"\n babelify@10 requires Babel 7.x (the package '@babel/core'). " +
|
||||
"If you'd like to use Babel 6.x ('babel-core'), you should install 'babelify@8'.";
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
// Since we've got the reverse bridge package at @babel/core@6.x, give
|
||||
// people useful feedback if they try to use it alongside babel-loader.
|
||||
if (/^6\./.test(babel.version)) {
|
||||
throw new Error(
|
||||
"\n babelify@10 will not work with the '@babel/core@6' bridge package. " +
|
||||
"If you want to use Babel 6.x, install 'babelify@8'."
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = buildTransform();
|
||||
module.exports.configure = buildTransform;
|
||||
|
||||
// Allow projects to import this module and check `foo instanceof babelify`
|
||||
// to see if the current stream they are working with is one created
|
||||
// by Babelify.
|
||||
Object.defineProperty(module.exports, Symbol.hasInstance, {
|
||||
value: function hasInstance(obj) {
|
||||
return obj instanceof BabelifyStream;
|
||||
},
|
||||
});
|
||||
|
||||
function buildTransform(opts) {
|
||||
return function (filename, transformOpts) {
|
||||
const babelOpts = normalizeOptions(opts, transformOpts, filename);
|
||||
if (babelOpts === null) {
|
||||
return stream.PassThrough();
|
||||
}
|
||||
|
||||
return new BabelifyStream(babelOpts);
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeOptions(preconfiguredOpts, transformOpts, filename) {
|
||||
const basedir = normalizeTransformBasedir(transformOpts);
|
||||
const opts = normalizeTransformOpts(transformOpts);
|
||||
|
||||
// Transform options override preconfigured options unless they are undefined.
|
||||
if (preconfiguredOpts) {
|
||||
for (const key of Object.keys(preconfiguredOpts)) {
|
||||
if (opts[key] === undefined) {
|
||||
opts[key] = preconfiguredOpts[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// babelify specific options
|
||||
var extensions = opts.extensions || babel.DEFAULT_EXTENSIONS;
|
||||
var sourceMapsAbsolute = opts.sourceMapsAbsolute;
|
||||
delete opts.sourceMapsAbsolute;
|
||||
delete opts.extensions;
|
||||
|
||||
var extname = path.extname(filename);
|
||||
if (extensions.indexOf(extname) === -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Browserify doesn't actually always normalize the filename passed
|
||||
// to transforms, so we manually ensure that the filename is relative
|
||||
const absoluteFilename = path.resolve(basedir, filename);
|
||||
|
||||
Object.assign(opts, {
|
||||
cwd: opts.cwd === undefined ? basedir : opts.cwd,
|
||||
caller: Object.assign(
|
||||
{
|
||||
name: "babelify",
|
||||
},
|
||||
opts.caller
|
||||
),
|
||||
filename: absoluteFilename,
|
||||
|
||||
sourceFileName:
|
||||
sourceMapsAbsolute
|
||||
? absoluteFilename
|
||||
: undefined,
|
||||
});
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
||||
function normalizeTransformBasedir(opts) {
|
||||
return path.resolve(opts._flags && opts._flags.basedir || ".");
|
||||
}
|
||||
|
||||
function normalizeTransformOpts(opts) {
|
||||
opts = Object.assign({}, opts);
|
||||
|
||||
// browserify cli options
|
||||
delete opts._;
|
||||
// "--opt [ a b ]" and "--opt a --opt b" are allowed:
|
||||
if (opts.ignore && opts.ignore._) opts.ignore = opts.ignore._;
|
||||
if (opts.only && opts.only._) opts.only = opts.only._;
|
||||
if (opts.plugins && opts.plugins._) opts.plugins = opts.plugins._;
|
||||
if (opts.presets && opts.presets._) opts.presets = opts.presets._;
|
||||
|
||||
// browserify specific options
|
||||
delete opts._flags;
|
||||
delete opts.basedir;
|
||||
delete opts.global;
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
||||
class BabelifyStream extends stream.Transform {
|
||||
constructor(opts) {
|
||||
super();
|
||||
this._data = [];
|
||||
this._opts = opts;
|
||||
}
|
||||
|
||||
_transform(buf, enc, callback) {
|
||||
this._data.push(buf);
|
||||
callback();
|
||||
}
|
||||
|
||||
_flush(callback) {
|
||||
// Merge the buffer pieces after all are available, instead of one at a time,
|
||||
// to avoid corrupting multibyte characters.
|
||||
const data = Buffer.concat(this._data).toString();
|
||||
|
||||
transform(data, this._opts, (err, result) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
this.emit("babelify", result, this._opts.filename);
|
||||
var code = result !== null ? result.code : data;
|
||||
|
||||
// Note: Node 8.x allows passing 'code' to the callback instead of
|
||||
// manually pushing, but we need to support Node 6.x.
|
||||
this.push(code);
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function transform(data, inputOpts, done) {
|
||||
let cfg;
|
||||
try {
|
||||
cfg = babel.loadPartialConfig(inputOpts);
|
||||
if (!cfg) return done(null, null);
|
||||
} catch (err) {
|
||||
return done(err);
|
||||
}
|
||||
const opts = cfg.options;
|
||||
|
||||
// Since Browserify can only handle inline sourcemaps, we override any other
|
||||
// values to force inline sourcemaps unless they've been disabled.
|
||||
if (opts.sourceMaps !== false) {
|
||||
opts.sourceMaps = "inline";
|
||||
}
|
||||
|
||||
babel.transform(data, opts, done);
|
||||
}
|
37
node_modules/babelify/package.json
generated
vendored
Normal file
37
node_modules/babelify/package.json
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "babelify",
|
||||
"description": "Babel browserify transform",
|
||||
"version": "10.0.0",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/babel/babelify",
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babelify.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/babel/babelify/issues"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "^7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.0.0",
|
||||
"@babel/plugin-transform-property-literals": "^7.0.0",
|
||||
"@babel/plugin-transform-react-display-name": "^7.0.0",
|
||||
"@babel/preset-env": "^7.0.0",
|
||||
"@babel/preset-flow": "^7.0.0",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"babel-plugin-transform-node-env-inline": "^0.4.3",
|
||||
"browserify": "^16.2.2",
|
||||
"convert-source-map": "^1.5.1",
|
||||
"lodash.zipobject": "^4.1.3",
|
||||
"tap": "^12.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/*.js"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user