import-jsx
Advanced tools
Comparing version 3.1.0 to 4.0.0
39
index.js
'use strict'; | ||
const path = require('path'); | ||
const destructuringTransform = require('@babel/plugin-transform-destructuring'); | ||
const restSpreadTransform = require('@babel/plugin-proposal-object-rest-spread'); | ||
const jsxTransform = require('@babel/plugin-transform-react-jsx'); | ||
const resolveFrom = require('resolve-from'); | ||
const callerPath = require('caller-path'); | ||
const babel = require('@babel/core'); | ||
const cache = require('./cache'); | ||
const {version} = require('./package.json'); | ||
@@ -16,9 +13,8 @@ const importJsx = (moduleId, options) => { | ||
options = Object.assign({ | ||
options = { | ||
pragma: 'h', | ||
pragmaFrag: 'Fragment', | ||
cache: true, | ||
// Put on options object for easier testing. | ||
supportsDestructuring: Number(process.versions.node.split('.')[0]) >= 6 | ||
}, options); | ||
...options | ||
}; | ||
@@ -42,23 +38,11 @@ const modulePath = resolveFrom(path.dirname(callerPath()), moduleId); | ||
module._compile = source => { | ||
if (source.includes('React')) { | ||
options.pragma = 'React.createElement'; | ||
options.pragmaFrag = 'React.Fragment'; | ||
} | ||
const plugins = [ | ||
[restSpreadTransform, {useBuiltIns: true}], | ||
options.supportsDestructuring ? null : destructuringTransform, | ||
[jsxTransform, {pragma: options.pragma, pragmaFrag: options.pragmaFrag, useBuiltIns: true}] | ||
].filter(Boolean); | ||
const result = babel.transformSync(source, { | ||
plugins, | ||
filename: modulePath, | ||
sourceMaps: 'inline', | ||
babelrc: false, | ||
configFile: false | ||
const result = cache({ | ||
modulePath, | ||
options, | ||
source, | ||
version | ||
}); | ||
module._compile = oldCompile; | ||
module._compile(result.code, modulePath); | ||
module._compile(result, modulePath); | ||
}; | ||
@@ -81,2 +65,3 @@ | ||
module.exports = importJsx; | ||
module.exports.default = importJsx; | ||
@@ -83,0 +68,0 @@ module.exports.create = options => { |
{ | ||
"name": "import-jsx", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "Require and transpile JSX on the fly", | ||
@@ -13,9 +13,11 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">= 4" | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"test": "xo && nyc --check-coverage --branches=100 --lines=100 --functions=100 --statements=100 ava" | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"cache.js", | ||
"transform.js" | ||
], | ||
@@ -35,9 +37,27 @@ "keywords": [ | ||
"caller-path": "^2.0.0", | ||
"resolve-from": "^3.0.0" | ||
"find-cache-dir": "^3.2.0", | ||
"make-dir": "^3.0.2", | ||
"resolve-from": "^3.0.0", | ||
"rimraf": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.19.1", | ||
"nyc": "^13.3.0", | ||
"xo": "^0.18.2" | ||
"prettier": "^2.0.2", | ||
"xo": "^0.28.1" | ||
}, | ||
"prettier": { | ||
"tabs": true, | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"bracketSpacing": false, | ||
"arrowParens": "avoid" | ||
}, | ||
"xo": { | ||
"ignore": [ | ||
"test/fixtures" | ||
], | ||
"rules": { | ||
"node/no-deprecated-api": "off" | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# import-jsx [](https://travis-ci.org/vadimdemedes/import-jsx) | ||
# import-jsx  | ||
@@ -10,3 +10,2 @@ > Require and transpile JSX on the fly | ||
## Install | ||
@@ -18,3 +17,2 @@ | ||
## Usage | ||
@@ -30,3 +28,3 @@ | ||
**react.js** | ||
**React** | ||
@@ -36,6 +34,6 @@ ```jsx | ||
module.exports = <div/>; | ||
module.exports = <div />; | ||
``` | ||
**preact.js** | ||
**Preact** | ||
@@ -45,6 +43,6 @@ ```jsx | ||
module.exports = <div/>; | ||
module.exports = <div />; | ||
``` | ||
**custom.js** | ||
**Any JSX pragma** | ||
@@ -54,3 +52,3 @@ ```jsx | ||
module.exports = <div/>; | ||
module.exports = <div />; | ||
``` | ||
@@ -89,3 +87,3 @@ | ||
Enable or disable caching of transpiled sources. | ||
Cache transpiled source code. | ||
@@ -116,5 +114,1 @@ ### importJsx.create([options]) | ||
``` | ||
## License | ||
MIT © [Vadim Demedes](https://github.com/vadimdemedes) |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
9136
6
167
9
107
3
+ Addedfind-cache-dir@^3.2.0
+ Addedmake-dir@^3.0.2
+ Addedrimraf@^3.0.0
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcommondir@1.0.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfind-cache-dir@3.3.2(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedmake-dir@3.1.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpkg-dir@4.2.0(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)