Socket
Socket
Sign inDemoInstall

unimported

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unimported - npm Package Compare versions

Comparing version 1.1.0 to 1.3.0

9

dist/config.d.ts
import { ProcessedResult } from './process';
import { Context } from './index';
export interface UnimportedConfig {
ignore_unresolved: string[];
ignore_unimported: string[];
ignore_unused: string[];
flow?: boolean;
ignorePatterns?: string[];
ignoreUnresolved: string[];
ignoreUnimported: string[];
ignoreUnused: string[];
}
export declare function getConfig(): Promise<UnimportedConfig>;
export declare function writeConfig(config: Partial<UnimportedConfig>, context: Context): Promise<void>;
export declare function updateAllowLists(files: ProcessedResult, context: Context): Promise<void>;

@@ -17,5 +17,5 @@ "use strict";

return Object.assign({
ignore_unresolved: [],
ignore_unimported: [],
ignore_unused: [],
ignoreUnresolved: [],
ignoreUnimported: [],
ignoreUnused: [],
}, json);

@@ -30,8 +30,22 @@ });

}
function updateAllowLists(files, context) {
function merge(left, right) {
return sort(Array.from(new Set([...left, ...right])));
}
function writeConfig(config, context) {
return __awaiter(this, void 0, void 0, function* () {
const cfg = Object.assign(Object.assign({}, context.config), { ignore_unresolved: sort(files.unresolved), ignore_unused: sort(files.unused), ignore_unimported: sort(files.unimported) });
const cfg = Object.assign({}, context.config, config);
yield fs_1.writeJson('.unimportedrc.json', cfg);
});
}
exports.writeConfig = writeConfig;
function updateAllowLists(files, context) {
return __awaiter(this, void 0, void 0, function* () {
const cfg = context.config;
yield writeConfig({
ignoreUnresolved: merge(cfg.ignoreUnresolved, files.unresolved),
ignoreUnused: merge(cfg.ignoreUnused, files.unused),
ignoreUnimported: merge(cfg.ignoreUnimported, files.unimported),
}, context);
});
}
exports.updateAllowLists = updateAllowLists;

@@ -34,2 +34,3 @@ "use strict";

function main(args) {
var _a;
return __awaiter(this, void 0, void 0, function* () {

@@ -40,2 +41,3 @@ const spinner = ora_1.default('initializing').start();

const config = yield config_1.getConfig();
args.flow = (_a = config.flow) !== null && _a !== void 0 ? _a : args.flow;
const [aliases, dependencies, peerDependencies, type] = yield Promise.all([

@@ -56,15 +58,21 @@ meta.getAliases(cwd),

type, extensions: ['.js', '.jsx', '.ts', '.tsx'], ignore: [], entry: [], config }, args);
context.ignore = [
'**/node_modules/**',
'**/*.stories.{js,jsx,ts,tsx}',
'**/*.tests.{js,jsx,ts,tsx}',
'**/*.test.{js,jsx,ts,tsx}',
'**/*.spec.{js,jsx,ts,tsx}',
'**/tests/**',
'**/__tests__/**',
'**/*.d.ts',
context.type === 'meteor' && 'packages/**',
].filter(Boolean);
if (context.type === 'meteor') {
context.ignore.push('public/**', 'private/**', 'tests/**');
context.ignore =
config.ignorePatterns ||
[
'**/node_modules/**',
'**/*.stories.{js,jsx,ts,tsx}',
'**/*.tests.{js,jsx,ts,tsx}',
'**/*.test.{js,jsx,ts,tsx}',
'**/*.spec.{js,jsx,ts,tsx}',
'**/tests/**',
'**/__tests__/**',
'**/*.d.ts',
...(context.type === 'meteor'
? ['packages/**', 'public/**', 'private/**', 'tests/**']
: []),
].filter(Boolean);
if (args.init) {
yield config_1.writeConfig({ ignorePatterns: context.ignore }, context);
spinner.stop();
process.exit(0);
}

@@ -112,2 +120,7 @@ // traverse all source files and get import data

.command('*', 'scan your project for dead files', (yargs) => {
yargs.option('init', {
alias: 'i',
type: 'boolean',
describe: 'dump default settings to .unimportedrc.json',
});
yargs.option('flow', {

@@ -124,4 +137,8 @@ alias: 'f',

}, function (argv) {
return main({ flow: argv.flow, update: argv.update });
return main({
init: argv.init,
update: argv.update,
flow: argv.flow,
});
})
.help().argv;

@@ -66,3 +66,4 @@ "use strict";

}
console.log(`\n Inspect the results and run ${chalk_1.default.greenBright('npx unimported -u')} to update ignore lists`);
}
exports.printResults = printResults;

@@ -20,5 +20,5 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
const ignoreUnresolvedIdx = index(context.config.ignore_unresolved);
const ignoreUnusedIdx = index(context.config.ignore_unused);
const ignoreUnimportedIdx = index(context.config.ignore_unimported);
const ignoreUnresolvedIdx = index(context.config.ignoreUnresolved);
const ignoreUnusedIdx = index(context.config.ignoreUnused);
const ignoreUnimportedIdx = index(context.config.ignoreUnimported);
const unresolved = Array.from(traverseResult.unresolved).filter((x) => !ignoreUnresolvedIdx[x]);

@@ -25,0 +25,0 @@ const unused = Object.keys(context.dependencies).filter((x) => !traverseResult.modules.has(x) &&

{
"name": "unimported",
"version": "1.1.0",
"version": "1.3.0",
"description": "Scans your nodejs project folder and shows obsolete files and modules",

@@ -5,0 +5,0 @@ "main": "./dist/unimported.js",

@@ -21,2 +21,47 @@ # unimported

## Options
Output all options in your terminal:
```shell
npx unimported --help
```
### Init
This option will write the default ignore patterns to the `.unimportedrc.json` settings files. This will enable you to easily adjust them to your needs.
```shell
npx unimported --init
```
### Update
Update, will write the current results to the ignore lists in `.unimportedrc.json`. You want to use this option **after running and verifying** a full scan. Ignore lists are used to ignore certain false positives that could not be resolved properly. This is especially useful when running `unimported` on a regular basis, or for example as part of a CI pipeline.
```shell
npx unimported --update
```
### Flow Type
If your project is using flow type for typing, you might need this flag.
```shell
npx unimported --flow
```
### Example Config File
Save the file as `.unimportedrc.json` in the root of your project (next to `package.json`)
```json
{
"ignoreUnresolved": ["some-npm-dependency"],
"ignoreUnimported": ["src/i18n/locales/en.ts", "src/i18n/locales/nl.ts"],
"ignoreUnused": ["bcrypt", "create-emotion"],
"ignorePatterns": ["**/node_modules/**", "private/**"]
}
```
## Report

@@ -34,2 +79,4 @@

To ignore specific results, add them to `.unimportedrc.json#ignoreUnresolved`.
### unused dependencies

@@ -41,2 +88,4 @@

To ignore specific results, add them to `.unimportedrc.json#ignoreUnused`.
### unimported files

@@ -48,2 +97,4 @@

To ignore specific results, add them to `.unimportedrc.json#ignoreUnimported`.
### example

@@ -50,0 +101,0 @@

@@ -1,2 +0,1 @@

/* eslint-disable @typescript-eslint/camelcase */
import { ProcessedResult } from './process';

@@ -7,5 +6,7 @@ import { readJson, writeJson } from './fs';

export interface UnimportedConfig {
ignore_unresolved: string[];
ignore_unimported: string[];
ignore_unused: string[];
flow?: boolean;
ignorePatterns?: string[];
ignoreUnresolved: string[];
ignoreUnimported: string[];
ignoreUnused: string[];
}

@@ -19,5 +20,5 @@

{
ignore_unresolved: [],
ignore_unimported: [],
ignore_unused: [],
ignoreUnresolved: [],
ignoreUnimported: [],
ignoreUnused: [],
},

@@ -34,2 +35,14 @@ json,

function merge(left, right) {
return sort(Array.from(new Set([...left, ...right])));
}
export async function writeConfig(
config: Partial<UnimportedConfig>,
context: Context,
) {
const cfg = Object.assign({}, context.config, config);
await writeJson('.unimportedrc.json', cfg);
}
export async function updateAllowLists(

@@ -39,10 +52,12 @@ files: ProcessedResult,

) {
const cfg = {
...context.config,
ignore_unresolved: sort(files.unresolved),
ignore_unused: sort(files.unused),
ignore_unimported: sort(files.unimported),
};
const cfg = context.config;
await writeJson('.unimportedrc.json', cfg);
await writeConfig(
{
ignoreUnresolved: merge(cfg.ignoreUnresolved, files.unresolved),
ignoreUnused: merge(cfg.ignoreUnused, files.unused),
ignoreUnimported: merge(cfg.ignoreUnimported, files.unimported),
},
context,
);
}

@@ -13,3 +13,8 @@ import * as fs from './fs';

import { processResults } from './process';
import { getConfig, UnimportedConfig, updateAllowLists } from './config';
import {
getConfig,
UnimportedConfig,
updateAllowLists,
writeConfig,
} from './config';

@@ -61,2 +66,3 @@ export interface TsConfig {

const config = await getConfig();
args.flow = config.flow ?? args.flow;

@@ -93,16 +99,22 @@ const [aliases, dependencies, peerDependencies, type] = await Promise.all([

context.ignore = [
'**/node_modules/**',
'**/*.stories.{js,jsx,ts,tsx}',
'**/*.tests.{js,jsx,ts,tsx}',
'**/*.test.{js,jsx,ts,tsx}',
'**/*.spec.{js,jsx,ts,tsx}',
'**/tests/**',
'**/__tests__/**',
'**/*.d.ts',
context.type === 'meteor' && 'packages/**',
].filter(Boolean) as string[];
context.ignore =
config.ignorePatterns ||
([
'**/node_modules/**',
'**/*.stories.{js,jsx,ts,tsx}',
'**/*.tests.{js,jsx,ts,tsx}',
'**/*.test.{js,jsx,ts,tsx}',
'**/*.spec.{js,jsx,ts,tsx}',
'**/tests/**',
'**/__tests__/**',
'**/*.d.ts',
...(context.type === 'meteor'
? ['packages/**', 'public/**', 'private/**', 'tests/**']
: []),
].filter(Boolean) as string[]);
if (context.type === 'meteor') {
context.ignore.push('public/**', 'private/**', 'tests/**');
if (args.init) {
await writeConfig({ ignorePatterns: context.ignore }, context);
spinner.stop();
process.exit(0);
}

@@ -153,2 +165,3 @@

update: boolean;
init: boolean;
}

@@ -163,2 +176,8 @@

(yargs) => {
yargs.option('init', {
alias: 'i',
type: 'boolean',
describe: 'dump default settings to .unimportedrc.json',
});
yargs.option('flow', {

@@ -177,5 +196,9 @@ alias: 'f',

function (argv: Arguments<CliArguments>) {
return main({ flow: argv.flow, update: argv.update });
return main({
init: argv.init,
update: argv.update,
flow: argv.flow,
});
},
)
.help().argv;

@@ -108,2 +108,8 @@ import termSize from 'term-size';

}
console.log(
`\n Inspect the results and run ${chalk.greenBright(
'npx unimported -u',
)} to update ignore lists`,
);
}

@@ -23,5 +23,5 @@ import { TraverseResult } from './traverse';

): Promise<ProcessedResult> {
const ignoreUnresolvedIdx = index(context.config.ignore_unresolved);
const ignoreUnusedIdx = index(context.config.ignore_unused);
const ignoreUnimportedIdx = index(context.config.ignore_unimported);
const ignoreUnresolvedIdx = index(context.config.ignoreUnresolved);
const ignoreUnusedIdx = index(context.config.ignoreUnused);
const ignoreUnimportedIdx = index(context.config.ignoreUnimported);

@@ -28,0 +28,0 @@ const unresolved = Array.from(traverseResult.unresolved).filter(

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