babel-plugin-open-source
Advanced tools
Comparing version 1.2.4 to 1.3.0
62
babel.js
@@ -1,10 +0,11 @@ | ||
const fs = require('fs'); | ||
const ini = require('ini'); | ||
const path = require('path'); | ||
const { declare } = require('@babel/helper-plugin-utils'); | ||
const { types: t } = require('@babel/core'); | ||
const dotenv = require('dotenv'); | ||
const getGitHubUrl = require('./github-url.js'); | ||
const scriptLocation = 'babel-plugin-open-source/script.js'; | ||
// picks root directory's .env file | ||
const dotenvConfig = dotenv.config(); | ||
module.exports = declare((api) => { | ||
@@ -17,2 +18,11 @@ api.assertVersion(7); | ||
state.file.set('hasJSX', false); | ||
let editor = state.opts && state.opts.editor ? state.opts.editor.toLowerCase() : 'vscode'; | ||
const editorInENV = dotenvConfig && dotenvConfig.parsed && dotenvConfig.parsed.BABEL_OPEN_SOURCE_EDITOR; | ||
if (editorInENV) editor = editorInENV; | ||
state.file.set('editor', editor); | ||
if (process.env.NODE_ENV === 'development' || editor === 'github'); | ||
else state.file.set('skip', true); | ||
}, | ||
@@ -32,8 +42,7 @@ exit: (path, state) => { | ||
JSXOpeningElement(path, state) { | ||
if (state.file.get('skip')) return; | ||
const location = path.container.openingElement.loc; | ||
let url = null; | ||
let editor = state.opts && state.opts.editor ? state.opts.editor.toLowerCase() : 'vscode'; | ||
if (editor !== 'github' && process.env.NODE_ENV !== 'development') return; | ||
// the element was generated and doesn't have location information | ||
@@ -57,8 +66,3 @@ if (!location) return; | ||
// picks root directory's .env file | ||
const dotenvConfig = dotenv.config(); | ||
const editorInENV = dotenvConfig && dotenvConfig.parsed && dotenvConfig.parsed.BABEL_OPEN_SOURCE_EDITOR; | ||
if (editorInENV) { | ||
editor = editorInENV; | ||
} | ||
const editor = state.file.get('editor'); | ||
@@ -95,35 +99,1 @@ if (editor === 'sublime') { | ||
}); | ||
const getGitHubUrl = (localFilePath, lineNumber) => { | ||
const findGitRoot = require('find-git-root'); | ||
const repo = getRepositoryPath(); | ||
const gitRoot = findGitRoot(localFilePath).replace('.git', ''); | ||
const filePath = localFilePath.replace(gitRoot, ''); | ||
const branchName = process.env.GITHUB_HEAD_REF || 'main'; | ||
return `https://github.com/${repo}/blob/${branchName}/${filePath}#L${lineNumber}`; | ||
}; | ||
function findGit() { | ||
var directory = path.resolve('./', '.git', 'config'); | ||
const exists = fs.existsSync(directory); | ||
if (exists) return directory; | ||
if ('./' === path.resolve('./', '..')) return false; | ||
findGit(); | ||
} | ||
const getRepositoryPath = () => { | ||
const gitPath = findGit(); | ||
if (!gitPath) { | ||
console.log('Could not find .git'); | ||
return; | ||
} | ||
const result = fs.readFileSync(gitPath, 'utf8'); | ||
const config = ini.parse(result); | ||
return config['remote "origin"'].url.replace('git@github.com:', '').replace('.git', ''); | ||
}; |
{ | ||
"name": "babel-plugin-open-source", | ||
"version": "1.2.4", | ||
"version": "1.3.0", | ||
"description": "Alt + Click on rendered JSX to open it's source code in VSCode", | ||
@@ -5,0 +5,0 @@ "main": "babel.js", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
7582
5
150
8