Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const fs = require( 'fs' );
const path = require( 'path' );
const glob = require( 'glob' );
const depCheck = require( 'depcheck' );
const chalk = require( 'chalk' );
const cwd = process.cwd();
const packageJson = require( path.join( cwd, 'package.json' ) );
const nonExistingCSSFiles = [];
const depCheckOptions = {
// We need to add all values manually because if we modify it, the rest is being lost.
parsers: {
'*.css': parsePostCSS,
'*.js': depCheck.parser.es6,
'*.jsx': depCheck.parser.jsx,
'*.ts': depCheck.parser.typescript,
'*.vue': depCheck.parser.vue
},
ignoreDirs: [ 'docs', 'build' ],
ignoreMatches: [ 'eslint', 'eslint-plugin-ckeditor5-rules', 'husky', 'lint-staged', 'webpack-cli' ]
};
if ( Array.isArray( packageJson.depcheckIgnore ) ) {
depCheckOptions.ignoreMatches.push( ...packageJson.depcheckIgnore );
}
console.log( 'Checking dependencies...' );
depCheck( cwd, depCheckOptions )
.then( unused => {
const path = require( 'path' );
const glob = require( 'glob' );
const depCheck = require( 'depcheck' );
const chalk = require( 'chalk' );
const cwd = process.cwd();
const packageJson = require( path.join( cwd, 'package.json' ) );
const nonExistingCSSFiles = [];
const depCheckOptions = {
// We need to add all values manually because if we modify it, the rest is being lost.
parsers: {
'*.css': parsePostCSS,
'*.js': depCheck.parser.es6,
'*.jsx': depCheck.parser.jsx,
'*.ts': depCheck.parser.typescript,
'*.vue': depCheck.parser.vue
},
ignoreDirs: [ 'docs', 'build' ],
ignoreMatches: [ 'eslint', 'eslint-plugin-ckeditor5-rules', 'husky', 'lint-staged', 'webpack-cli' ]
};
if ( Array.isArray( packageJson.depcheckIgnore ) ) {
depCheckOptions.ignoreMatches.push( ...packageJson.depcheckIgnore );
}
console.log( 'Checking dependencies...' );
depCheck( cwd, depCheckOptions )
.then( unused => {
const missingPackages = groupMissingPackages( unused.missing, packageJson.name );
const result = await new Promise(resolve => {
depCheck(projectDir, {
ignoreDirs: [
"src", "test", "docs", "typings", "docker", "certs", "templates", "vendor",
],
// ignore d.ts
parsers: {
"*.js": (depCheck as any).parser.es6,
},
}, resolve)
})
'url-loader',
'webpack-cli',
'webpack-dev-server',
'yarn',
],
// skip calculation of missing dependencies
skipMissing: true,
ignoreDirs: [
'dist',
'dll',
'release',
'src/dist',
],
// the target special parsers
specials: [
depcheck.special.babel,
depcheck.special.eslint,
depcheck.special.webpack,
],
};
depcheck(path.join(__dirname, '..'), options, (unused) => {
const unusedDependencies = _.get(unused, 'dependencies', null);
const unusedDevDependencies = _.get(unused, 'devDependencies', null);
if (!_.isEmpty(unusedDependencies)) {
console.log(chalk.yellow.bold('Unused dependencies'));
console.log(chalk.yellow(_.join(unusedDependencies, '\n')));
}
if (!_.isEmpty(unusedDevDependencies)) {
console.log(chalk.yellow.bold('Unused devDependencies'));
console.log(chalk.yellow(_.join(unusedDevDependencies, '\n')));
}
skipMissing: true,
ignoreDirs: [
'dist',
'dll',
'release',
'src/dist',
],
// the target special parsers
specials: [
depcheck.special.babel,
depcheck.special.eslint,
depcheck.special.webpack,
],
};
depcheck(path.join(__dirname, '..'), options, (unused) => {
const unusedDependencies = _.get(unused, 'dependencies', null);
const unusedDevDependencies = _.get(unused, 'devDependencies', null);
if (!_.isEmpty(unusedDependencies)) {
console.log(chalk.yellow.bold('Unused dependencies'));
console.log(chalk.yellow(_.join(unusedDependencies, '\n')));
}
if (!_.isEmpty(unusedDevDependencies)) {
console.log(chalk.yellow.bold('Unused devDependencies'));
console.log(chalk.yellow(_.join(unusedDevDependencies, '\n')));
}
});
'clean',
'lint',
'scripts',
'cover',
'test'
)(done);
});
// Examine package.json for unused deps (except for frontend and gulp)
gulp.task('depcheck', g.depcheck({
ignoreMatches : [
'babel-preset-es2015'
],
specials : [
depcheck.special['gulp-load-plugins']
]
}));
// What to do when you run `$ gulp`
gulp.task('default', done => {
g.sequence(
[ 'david', 'depcheck' ],
'build',
'watch'
)(done);
});
gulp.task('_unused-dependencies', done => {
gulpDepcheck({
ignoreDirs: configuration.exclude,
ignoreMatches: [ 'roboter-client', 'roboter-server' ],
parsers: {
'*.js': depcheck.parser.es6,
'*.jsx': depcheck.parser.jsx
},
detectors: [
depcheck.detector.requireCallExpression,
depcheck.detector.importDeclaration
],
specials: [
depcheck.special.babel,
depcheck.special.eslint,
depcheck.special.mocha,
depcheck.special.webpack
]
})().
then(done).
catch(err => {
if (
err.message.includes('You have unused dependencies') ||
err.message.includes('You have missing dependencies')
) {
gutil.log(err.message);
return done();
}
gulpDepcheck({
ignoreDirs: configuration.exclude,
ignoreMatches: [ 'roboter-client', 'roboter-server' ],
parsers: {
'*.js': depcheck.parser.es6,
'*.jsx': depcheck.parser.jsx
},
detectors: [
depcheck.detector.requireCallExpression,
depcheck.detector.importDeclaration
],
specials: [
depcheck.special.babel,
depcheck.special.eslint,
depcheck.special.mocha,
depcheck.special.webpack
]
})().
then(done).
catch(err => {
if (
err.message.includes('You have unused dependencies') ||
err.message.includes('You have missing dependencies')
) {
gutil.log(err.message);
return done();
}
done(err);
});
});
.on('data', (file) => {
options.parsers[file.path] = [
parser,
depcheck.special.babel,
depcheck.special.bin,
depcheck.special.eslint,
depcheck.special.webpack
];
})
.on('end', (err) => {
.on('data', (file: { path: string }) => {
depcheckOptions.parsers[file.path] = [
(content: string, filename: string) => {
return babylon.parse(
this.transpileService.transpile(content, filename),
{sourceType: 'module'}
);
},
depcheck.special.babel,
depcheck.special.bin,
depcheck.special.eslint,
depcheck.special.webpack
];
})
.on('end', (err: Error) => {