New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

copy-config

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

copy-config - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

73

dist/run.js

@@ -39,23 +39,41 @@ "use strict";

const run = async ({ fs = realFs, cwd = process.cwd(), argv = process.argv.slice(2), logger = console, } = {}) => {
const args = (0, arg_1.default)({
const argSpec = {
'--help': Boolean,
'--repo': String,
'--ref': String,
'--path': String,
'--output': String,
'--config': String,
'--ref': String,
'--filter': String,
'--purge': Boolean,
'--aggressive': Boolean,
}, { argv });
let repo = args['--repo'];
assert.ok(repo, `--repo must be defined`);
if (!repo.includes('://'))
repo = `https://github.com/${repo}`;
assert.ok(!/\s/.test(repo), `Invalid repo: ${repo}`);
const tmpParent = '/tmp/copy-config/' + repo.split('://')[1];
fs.mkdirSync(tmpParent, { recursive: true });
const tempDir = fs.mkdtempSync(tmpParent + '/');
cp.execSync(`git clone ${repo}`, { cwd: tempDir });
const tempRepoDir = path.join(tempDir, fs.readdirSync(tempDir)[0]);
};
const args = (0, arg_1.default)(argSpec, { argv });
if (args['--help']) {
const options = Object.entries(argSpec).map(([k, v]) => `${k}: ${v.name}`);
logger.info(`Available options: ${options.join(', ')}`);
}
const outputPath = path.resolve(cwd, args['--output'] || '.');
const getTempRepoDir = () => {
let repo = args['--repo'];
assert.ok(repo, `--repo must be defined`);
if (!repo.includes('://'))
repo = `https://github.com/${repo}`;
assert.ok(!/\s/.test(repo), `Invalid repo: ${repo}`);
const tmpParent = '/tmp/copy-config/' + repo.split('://')[1];
fs.mkdirSync(tmpParent, { recursive: true });
const tempDir = fs.mkdtempSync(tmpParent + '/');
cp.execSync(`git clone ${repo}`, { cwd: tempDir });
const tempRepoDir = path.join(tempDir, fs.readdirSync(tempDir)[0]);
return tempRepoDir;
};
const getLocalDir = () => {
const inputPath = args['--path'];
assert.ok(inputPath, '--path must be defined');
return path.resolve(cwd, inputPath);
};
const copyFrom = args['--path'] ? getLocalDir() : getTempRepoDir();
if (args['--ref']) {
cp.execSync(`git fetch`, { cwd: tempRepoDir });
cp.execSync(`git -c advice.detachedHead=false checkout ${args['--ref']}`, { cwd: tempRepoDir });
cp.execSync(`git fetch`, { cwd: copyFrom });
cp.execSync(`git -c advice.detachedHead=false checkout ${args['--ref']}`, { cwd: copyFrom });
}

@@ -73,6 +91,6 @@ const config = args['--config']

.forEach(rule => {
const files = globSync(rule.pattern, { cwd: tempRepoDir });
const filtered = args['--filter'] ? (0, lodash_1.intersection)(files, globSync(args['--filter'], { cwd: tempRepoDir })) : files;
const files = globSync(rule.pattern, { cwd: copyFrom });
const filtered = args['--filter'] ? (0, lodash_1.intersection)(files, globSync(args['--filter'], { cwd: copyFrom })) : files;
filtered.forEach(relPath => {
const absPath = path.join(cwd, relPath);
const absPath = path.join(outputPath, relPath);
if (handled.has(absPath)) {

@@ -82,3 +100,3 @@ logger.info(`skipping ${relPath} for pattern ${rule.pattern}, already handled`);

}
const remoteContent = fs.readFileSync(path.join(tempRepoDir, relPath)).toString();
const remoteContent = fs.readFileSync(path.join(copyFrom, relPath)).toString();
const localContent = fs.existsSync(absPath) ? fs.readFileSync(absPath).toString() : undefined;

@@ -88,3 +106,3 @@ const newContent = rule.merge({

localContent,
meta: { filepath: relPath, localCwd: cwd, remoteCwd: tempRepoDir },
meta: { filepath: relPath, localCwd: outputPath, remoteCwd: copyFrom },
});

@@ -100,2 +118,5 @@ if (newContent) {

if (args['--purge']) {
if (args['--path']) {
throw new Error(`Can't purge if specifying local path`);
}
config.rules

@@ -105,9 +126,11 @@ .slice()

.forEach(rule => {
const localFiles = globSync(rule.pattern, { cwd });
const filtered = args['--filter'] ? (0, lodash_1.intersection)(localFiles, globSync(args['--filter'], { cwd })) : localFiles;
const localFiles = globSync(rule.pattern, { cwd: outputPath });
const filtered = args['--filter']
? (0, lodash_1.intersection)(localFiles, globSync(args['--filter'], { cwd: outputPath }))
: localFiles;
filtered.forEach(relPath => {
const remoteFile = path.join(tempRepoDir, relPath);
const absPath = path.join(cwd, relPath);
const remoteFile = path.join(copyFrom, relPath);
const absPath = path.join(outputPath, relPath);
if (!fs.existsSync(remoteFile)) {
logger.info(`Removing ${relPath} because it doesn't exist in ${repo}`);
logger.info(`Removing ${relPath} because it doesn't exist in ${args['--repo']}`);
fs.unlinkSync(absPath);

@@ -114,0 +137,0 @@ }

{
"name": "copy-config",
"version": "0.1.0",
"version": "0.1.1",
"description": "Copies another repo's configuration",
"main": "dist/index.js",
"bin": "dist/bin.js",
"homepage": "https://github.com/mmkal/copy-config",
"repository": {
"type": "git",
"url": "git+https://github.com/mmkal/copy-config.git"
},
"scripts": {

@@ -11,3 +16,3 @@ "copy-config": "node dist/bin --repo mmkal/eslint-plugin-codegen",

"lint": "tsc && eslint .",
"build": "tsc -p tsconfig.lib.json",
"build": "rm -rf dist && tsc -p tsconfig.lib.json",
"test": "jest"

@@ -20,3 +25,3 @@ },

"arg": "^5.0.2",
"glob": "^9.0.0",
"glob": "^10.0.0",
"lodash": "^4.17.21",

@@ -28,3 +33,3 @@ "type-fest": "^3.5.0"

"@types/jest": "29.5.0",
"@types/lodash": "4.14.192",
"@types/lodash": "4.14.194",
"eslint": "8.38.0",

@@ -31,0 +36,0 @@ "eslint-plugin-mmkal": "0.0.1-2",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc