wix-jsdoc-babel
Advanced tools
Comparing version 1.3.3 to 1.3.4
'use strict'; | ||
var jsdocBabel = require('jsdoc-babel'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.handlers = undefined; | ||
exports.setExtensions = function (value) { | ||
global.env.conf.babel.extensions = value; | ||
var _lodash = require('lodash'); | ||
var _babelCore = require('babel-core'); | ||
var _jsdocRegex = require('jsdoc-regex'); | ||
var _jsdocRegex2 = _interopRequireDefault(_jsdocRegex); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// jsdoc with requizzle loads the modules twice - so the only way to move config between the two runs is using global | ||
if (!global.wixJsdocBabelExtensions) global.wixJsdocBabelExtensions = ['js']; | ||
function shouldProcessFile(filename, _ref) { | ||
var extensions = _ref.extensions; | ||
return (0, _lodash.includes)(extensions, (0, _lodash.last)(filename.split('.'))); | ||
} | ||
function countCharInRange(source, from, to, char) { | ||
var cnt = 0; | ||
for (var i = from; i < to; i += 1) { | ||
if (source[i] === char) { | ||
cnt += 1; | ||
} | ||
} | ||
return cnt; | ||
} | ||
function stripWhitespace(text) { | ||
return text.replace(/ /g, ''); | ||
} | ||
function processFile(source, options, doclets) { | ||
var regex = (0, _jsdocRegex2.default)(); | ||
var lastIndex = 0; | ||
var linesCount = 1; | ||
var match = regex.exec(source); | ||
while (match !== null) { | ||
var _match = match, | ||
index = _match.index; | ||
linesCount += countCharInRange(source, lastIndex, index, '\n'); | ||
var key = stripWhitespace(match[0]); | ||
// eslint-disable-next-line no-param-reassign | ||
doclets[key] = linesCount; | ||
lastIndex = index; | ||
match = regex.exec(source); | ||
} | ||
return (0, _babelCore.transform)(source, (0, _lodash.omit)(options, 'extensions')).code; | ||
} | ||
var doclets = {}; | ||
// eslint-disable-next-line import/prefer-default-export | ||
var handlers = exports.handlers = { | ||
beforeParse: function beforeParse(event) { | ||
doclets = {}; | ||
var options = { | ||
extensions: global.wixJsdocBabelExtensions, | ||
filename: event.filename | ||
}; | ||
if (shouldProcessFile(event.filename, options)) { | ||
// eslint-disable-next-line no-param-reassign | ||
event.source = processFile(event.source, options, doclets); | ||
} | ||
}, | ||
newDoclet: function newDoclet(e) { | ||
if (e) { | ||
if (doclets[stripWhitespace(e.doclet.comment)]) { | ||
e.doclet.meta.lineno = doclets[stripWhitespace(e.doclet.comment)]; | ||
} | ||
} | ||
} | ||
}; | ||
exports.init = function (param) { | ||
exports.setExtensions(param.split(',')); | ||
}; | ||
exports.handlers = jsdocBabel.handlers; | ||
global.wixJsdocBabelExtensions = param.split(','); | ||
}; |
{ | ||
"name": "wix-jsdoc-babel", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "", | ||
@@ -14,4 +14,8 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"jsdoc-babel": "wix/jsdoc-babel" | ||
"jsdoc-regex": "^1.0.1", | ||
"lodash": "^4.13.1" | ||
}, | ||
"peerDependencies": { | ||
"babel-core": ">6.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -18,0 +22,0 @@ "babel-cli": "^6.26.0", |
@@ -1,12 +0,71 @@ | ||
let jsdocBabel = require('jsdoc-babel'); | ||
import { assign, includes, get, last, omit } from 'lodash'; | ||
import { transform } from 'babel-core'; | ||
import jsdocRegex from 'jsdoc-regex'; | ||
exports.setExtensions = function(value) { | ||
global.env.conf.babel.extensions = value; | ||
// jsdoc with requizzle loads the modules twice - so the only way to move config between the two runs is using global | ||
if (!global.wixJsdocBabelExtensions) | ||
global.wixJsdocBabelExtensions =['js']; | ||
function shouldProcessFile(filename, { extensions }) { | ||
return includes(extensions, last(filename.split('.'))); | ||
} | ||
function countCharInRange(source, from, to, char) { | ||
let cnt = 0; | ||
for (let i = from; i < to; i += 1) { | ||
if (source[i] === char) { | ||
cnt += 1; | ||
} | ||
} | ||
return cnt; | ||
} | ||
function stripWhitespace(text) { | ||
return text.replace(/ /g, ''); | ||
} | ||
function processFile(source, options, doclets) { | ||
const regex = jsdocRegex(); | ||
let lastIndex = 0; | ||
let linesCount = 1; | ||
let match = regex.exec(source); | ||
while (match !== null) { | ||
const { index } = match; | ||
linesCount += countCharInRange(source, lastIndex, index, '\n'); | ||
const key = stripWhitespace(match[0]); | ||
// eslint-disable-next-line no-param-reassign | ||
doclets[key] = linesCount; | ||
lastIndex = index; | ||
match = regex.exec(source); | ||
} | ||
return transform(source, omit(options, 'extensions')).code; | ||
} | ||
let doclets = {}; | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const handlers = { | ||
beforeParse: (event) => { | ||
doclets = {}; | ||
const options = { | ||
extensions: global.wixJsdocBabelExtensions, | ||
filename: event.filename, | ||
}; | ||
if (shouldProcessFile(event.filename, options)) { | ||
// eslint-disable-next-line no-param-reassign | ||
event.source = processFile(event.source, options, doclets); | ||
} | ||
}, | ||
newDoclet: (e) => { | ||
if (e) { | ||
if (doclets[stripWhitespace(e.doclet.comment)]) { | ||
e.doclet.meta.lineno = doclets[stripWhitespace(e.doclet.comment)]; | ||
} | ||
} | ||
}, | ||
}; | ||
exports.init = function(param) { | ||
exports.setExtensions(param.split(',')); | ||
global.wixJsdocBabelExtensions = param.split(','); | ||
}; | ||
exports.handlers = jsdocBabel.handlers; |
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
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
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
7511
205
0
0
3
+ Addedjsdoc-regex@^1.0.1
+ Addedlodash@^4.13.1
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedbabel-code-frame@6.26.0(transitive)
+ Addedbabel-core@6.26.3(transitive)
+ Addedbabel-generator@6.26.1(transitive)
+ Addedbabel-helpers@6.24.1(transitive)
+ Addedbabel-messages@6.23.0(transitive)
+ Addedbabel-register@6.26.0(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbabel-template@6.26.0(transitive)
+ Addedbabel-traverse@6.26.0(transitive)
+ Addedbabel-types@6.26.0(transitive)
+ Addedbabylon@6.18.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconvert-source-map@1.9.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddetect-indent@4.0.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedglobals@9.18.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhome-or-tmp@2.0.0(transitive)
+ Addedinvariant@2.2.4(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedjs-tokens@3.0.2(transitive)
+ Addedjsdoc-regex@1.0.1(transitive)
+ Addedjsesc@1.3.0(transitive)
+ Addedjson5@0.5.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedms@2.0.0(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedprivate@0.1.8(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedslash@1.0.0(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedsource-map-support@0.4.18(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedto-fast-properties@1.0.3(transitive)
+ Addedtrim-right@1.0.1(transitive)
- Removedjsdoc-babel@wix/jsdoc-babel