Improve code quality and write tests

This commit is contained in:
Shivam Mathur
2019-09-20 08:11:20 +05:30
parent db44db4b97
commit 43178a7254
3597 changed files with 255478 additions and 785554 deletions

View File

@ -0,0 +1,9 @@
{
"presets": [
"airbnb"
],
"plugins": [
"add-module-exports",
["transform-replace-object-assign", { "moduleSpecifier": "object.assign" }],
],
}

View File

@ -0,0 +1,2 @@
test/fixtures
lib/

View File

@ -0,0 +1,5 @@
{
"parser": "babel-eslint",
"extends": "airbnb-base",
"root": true
}

View File

@ -0,0 +1,42 @@
language: node_js
os:
- linux
node_js:
- "10"
- "9"
- "8"
- "7"
- "6"
- "5"
- "4"
- "iojs-v3"
- "iojs-v2"
- "iojs-v1"
- "0.12"
before_install:
- 'nvm install-latest-npm'
install:
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
script:
- 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi'
- 'if [ -n "${POSTTEST-}" ]; then npm run posttest ; fi'
- 'if [ -n "${COVERAGE-}" ]; then npm run coverage ; fi'
- 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi'
sudo: false
env:
- TEST=true
matrix:
fast_finish: true
include:
- node_js: "lts/*"
env: PRETEST=true
allow_failures:
- node_js: "9"
- node_js: "7"
- node_js: "5"
- node_js: "iojs-v3"
- node_js: "iojs-v2"
- node_js: "iojs-v1"
- os: osx
- env: TEST=true ALLOW_FAILURE=true
- env: COVERAGE=true

View File

@ -0,0 +1,52 @@
## Unreleased
## v2.3.0
- [New] expose createDynamicImportTransform and getImportSource (#75)
- [Docs] Document noInterop option (#70)
## v2.2.0
- [Refactor] remove dependency on babel-plugin-syntax-dynamic-import
- [Dev Deps] update `airbnb-js-shims`, `babel-preset-airbnb`, `eslint`
## v2.1.0
- [New] add `noInterop` option (#57)
- [Docs] Fix typo "correct" -> "correctly" in readme (#55)
- [Dev Deps] update `airbnb-js-shims`, `babel-eslint`, `babel-preset-airbnb`, `eslint`, `eslint-config-airbnb-base`, `eslint-plugin-import`, `safe-publish-latest`
## v2.0.0
- [Breaking] always return a module namespace object (#52, #47)
- [Breaking] remove `.default` on entry points (#27)
- [Docs] removed $ before npm command (#35)
- [Docs] Improve README.md with a code example (#41)
- [Dev Deps] update `airbnb-js-shims`, `babel-core`, `babel-eslint`, `eslint`, `eslint-plugin-import`
- [Tests] switch from mocha to tape, so we can support older nodes
## v1.2.0
- [New] support comments (#37)
- [Refactor] Use template and types from the babel object (#32)
- [Tests] on `node` `v9`; pin included builds to LTS
- [Dev Deps] update `eslint`, `eslint-config-airbnb-base`, `mocha`, `rimraf`
## v1.1.0
- Visit Import nodes instead of CallExpressions (#30)
- [Deps] update `babel-template`, `babel-types`
- [Dev Deps] update `airbnb-js-shims`, `babel-cli`, `babel-core`, `babel-preset-airbnb`, `babel-register`, `chai`, `eslint`, `eslint-config-airbnb-base`, `eslint-plugin-import`, `mocha`
- [Tests] on `node` `v8`
- [Tests] use `nvm install-latest-npm` so newer npm doesnt break older node
## v1.0.2
- [Fix] Ensure it works with the ES2015 preset too (#12, #16)
- [Deps] update `babel-template`, `babel-types`
- [Dev Deps] update `babel-cli`, `babel-core`, `babel-eslint`, `babel-register`, `eslint`, `eslint-config-airbnb-base`, `mocha`
## v1.0.1
- [Fix] Move `in-publish` to devDeps (#11)
- [Fix] ensure dynamic `import()` input is properly stringified (#2)
- [Fix] async timing of dynamic import to match spec (#3)
- [Fix] Remove spaces in template strings and update Babel (#10)
- [Deps] update `babel-template`, `babel-types`
- [Deps] update `babel-types` (#4, #5, #6)
- [Dev Deps] update `babel-cli`, `babel-core`, `babel-eslint`, `babel-register`, `eslint`, `eslint-config-airbnb-base`, `eslint-plugin-import`, `mocha`, `rimraf`
## v1.0.0
- Initial full release.

21
node_modules/babel-plugin-dynamic-import-node/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Airbnb
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.

View File

@ -0,0 +1,63 @@
# babel-plugin-dynamic-import-node
Babel plugin to transpile `import()` to a deferred `require()`, for node. Matches the [proposed spec](https://github.com/domenic/proposal-import-function).
**NOTE:** Babylon >= v6.12.0 is required to correctly parse dynamic imports.
## Installation
```sh
npm install babel-plugin-dynamic-import-node --save-dev
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": ["dynamic-import-node"]
}
```
#### Options
- *`noInterop`* - A boolean value, that if true will not interop the require calls. Useful to avoid using `require('module').default` on commonjs modules.
```json
{
"plugins": [
["dynamic-import-node", { "noInterop": true }]
]
}
```
### Via CLI
```sh
$ babel --plugins dynamic-import-node script.js
```
### Via Node API
```javascript
require('babel-core').transform('code', {
plugins: ['dynamic-import-node']
});
```
### Code Example
```javascript
Promise.all([
import('./lib/import1'),
import('./lib/import2')
]).then(([
Import1,
Import2
]) => {
console.log(Import1);
/* CODE HERE*/
});
```

View File

@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = function (api) {
var transformImport = (0, _utils.createDynamicImportTransform)(api);
return {
// NOTE: Once we drop support for Babel <= v6 we should
// update this to import from @babel/plugin-syntax-dynamic-import.
// https://www.npmjs.com/package/@babel/plugin-syntax-dynamic-import
manipulateOptions: function () {
function manipulateOptions(opts, parserOpts) {
parserOpts.plugins.push('dynamicImport');
}
return manipulateOptions;
}(),
visitor: {
Import: function () {
function Import(path) {
transformImport(this, path);
}
return Import;
}()
}
};
};
var _utils = require("./utils");
module.exports = exports["default"];

View File

@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getImportSource = getImportSource;
exports.createDynamicImportTransform = createDynamicImportTransform;
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function getImportSource(t, callNode) {
var importArguments = callNode.arguments;
var _importArguments = _slicedToArray(importArguments, 1),
importPath = _importArguments[0];
var isString = t.isStringLiteral(importPath) || t.isTemplateLiteral(importPath);
if (isString) {
t.removeComments(importPath);
return importPath;
}
return t.templateLiteral([t.templateElement({
raw: '',
cooked: ''
}), t.templateElement({
raw: '',
cooked: ''
}, true)], importArguments);
}
function createDynamicImportTransform(_ref) {
var template = _ref.template,
t = _ref.types;
var buildImport = template('Promise.resolve().then(() => MODULE)');
return function (context, path) {
var requireCall = t.callExpression(t.identifier('require'), [getImportSource(t, path.parent)]);
var _context$opts$noInter = context.opts.noInterop,
noInterop = _context$opts$noInter === undefined ? false : _context$opts$noInter;
var MODULE = noInterop === true ? requireCall : t.callExpression(context.addHelper('interopRequireWildcard'), [requireCall]);
var newImport = buildImport({
MODULE: MODULE
});
path.parentPath.replaceWith(newImport);
};
}

View File

@ -0,0 +1,99 @@
{
"_args": [
[
"babel-plugin-dynamic-import-node@2.3.0",
"E:\\python\\setup-php"
]
],
"_from": "babel-plugin-dynamic-import-node@2.3.0",
"_id": "babel-plugin-dynamic-import-node@2.3.0",
"_inBundle": false,
"_integrity": "sha512-o6qFkpeQEBxcqt0XYlWzAVxNCSCZdUgcR8IRlhD/8DylxjjO4foPcvTW0GGKa/cVt3rvxZ7o5ippJ+/0nvLhlQ==",
"_location": "/babel-plugin-dynamic-import-node",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "babel-plugin-dynamic-import-node@2.3.0",
"name": "babel-plugin-dynamic-import-node",
"escapedName": "babel-plugin-dynamic-import-node",
"rawSpec": "2.3.0",
"saveSpec": null,
"fetchSpec": "2.3.0"
},
"_requiredBy": [
"/@babel/plugin-transform-modules-amd",
"/@babel/plugin-transform-modules-commonjs",
"/@babel/plugin-transform-modules-systemjs"
],
"_resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.0.tgz",
"_spec": "2.3.0",
"_where": "E:\\python\\setup-php",
"author": {
"name": "Jordan Gensler",
"email": "jordan.gensler@airbnb.com"
},
"bugs": {
"url": "https://github.com/airbnb/babel-plugin-dynamic-import-node/issues"
},
"dependencies": {
"object.assign": "^4.1.0"
},
"description": "Babel plugin to transpile import() to a deferred require(), for node",
"devDependencies": {
"airbnb-js-shims": "^2.2.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^9.0.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-es2015-template-literals": "^6.22.0",
"babel-plugin-transform-replace-object-assign": "^1.0.0",
"babel-preset-airbnb": "^2.6.0",
"babel-preset-es2015": "^6.24.1",
"babel-register": "^6.26.0",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.17.3",
"in-publish": "^2.0.0",
"rimraf": "^2.6.3",
"safe-publish-latest": "^1.1.2",
"tape": "^4.10.2"
},
"directories": {
"test": "test"
},
"homepage": "https://github.com/airbnb/babel-plugin-dynamic-import-node#readme",
"keywords": [
"babel",
"plugin",
"dynamic",
"import",
"node"
],
"license": "MIT",
"main": "lib/index.js",
"name": "babel-plugin-dynamic-import-node",
"repository": {
"type": "git",
"url": "git+https://github.com/airbnb/babel-plugin-dynamic-import-node.git"
},
"scripts": {
"build": "babel src --out-dir lib",
"check-changelog": "expr $(git status --porcelain 2>/dev/null| grep \"^\\s*M.*CHANGELOG.md\" | wc -l) >/dev/null || (echo 'Please edit CHANGELOG.md' && exit 1)",
"check-only-changelog-changed": "(expr $(git status --porcelain 2>/dev/null| grep -v \"CHANGELOG.md\" | wc -l) >/dev/null && echo 'Only CHANGELOG.md may have uncommitted changes' && exit 1) || exit 0",
"clean": "rimraf lib",
"lint": "eslint .",
"postversion": "git commit package.json CHANGELOG.md -m \"v$npm_package_version\" && npm run tag && git push && git push --tags",
"prebuild": "npm run clean",
"prepublish": "not-in-publish || (safe-publish-latest && npm run build)",
"pretest": "npm run lint",
"preversion": "npm run test && npm run check-changelog && npm run check-only-changelog-changed",
"tag": "git tag v$npm_package_version",
"test": "npm run tests-only",
"tests-only": "tape --require airbnb-js-shims --require babel-register test",
"version:major": "npm --no-git-tag-version version major",
"version:minor": "npm --no-git-tag-version version minor",
"version:patch": "npm --no-git-tag-version version patch"
},
"version": "2.3.0"
}

View File

@ -0,0 +1,6 @@
// Re-export lib/utils, so that consumers can import
// babel-plugin-dynamic-import-node/utils instead of
// babel-plugin-dynamic-import-node/lib/utils
// eslint-disable-next-line import/no-unresolved
module.exports = require('./lib/utils');