Skip to content

Commit

Permalink
Merge pull request #27 from chiefmikey/framework-support
Browse files Browse the repository at this point in the history
  • Loading branch information
chiefmikey authored Jan 27, 2025
2 parents 3d63529 + 785503e commit 5a19bc7
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"major": "npm version major; cd dist && npm version major",
"minor": "npm version minor; cd dist && npm version minor",
"ncu": "ncu -u; cd dist && ncu -u;",
"start": "npm run build && node dist/src/index.js",
"start": "npm run build && node dist/index.js",
"pretest": "npm run build",
"test": "jest --no-cache",
"test:coverage": "jest --coverage",
Expand Down
29 changes: 22 additions & 7 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,34 @@ export const CLI_STRINGS = {
EXAMPLE_TEXT: '\nExample:\n $ depsweep -v --measure-impact',
};

export const FRAMEWORK_PATTERNS = {
ANGULAR: {
CORE: '@angular/core',
PATTERNS: ['@angular/*', '@angular-*', '@webcomponents/*'],
DEV_DEPS: ['@angular-builders/*', '@angular-devkit/*', '@angular/cli'],
},
REACT: {
CORE: 'react',
PATTERNS: ['react-*', '@testing-library/react*', '@types/react*'],
DEV_DEPS: ['react-scripts', 'react-app-rewired'],
},
VUE: {
CORE: 'vue',
PATTERNS: ['vue-*', '@vue/*', '@nuxt/*'],
DEV_DEPS: ['@vue/cli-service', '@vue/cli-plugin-*'],
},
};

export const RAW_CONTENT_PATTERNS = new Map([
['webpack', ['webpack.*', 'webpack-*']],
['babel', ['babel.*', '@babel/*']],
['eslint', ['eslint.*', '@eslint/*']],
['jest', ['jest.*', '@jest/*']],
['typescript', ['ts-*', '@typescript-*']],
['rollup', ['rollup.*', 'rollup-*']],
['esbuild', ['esbuild.*', '@esbuild/*']],
['vite', ['vite.*', '@vitejs/*']],
['next', ['next.*', '@next/*']],
['vue', ['vue.*', '@vue/*', '@nuxt/*']],
['react', ['react.*', '@types/react*']],
['svelte', ['svelte.*', '@sveltejs/*']],
[
'bundler',
['rollup.*', 'rollup-*', 'esbuild.*', '@esbuild/*', 'vite.*', '@vitejs/*'],
],
]);

export const DEPENDENCY_PATTERNS = {
Expand Down
66 changes: 66 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,62 @@ interface ProgressOptions {
totalAnalysisSteps: number;
}

function getFrameworkInfo(context: DependencyContext): {
name: string;
corePackage: string;
devDependencies: string[];
} | null {
const packageJson = context.configs?.['package.json'];
if (!packageJson) return null;

const deps = packageJson.dependencies || {};
const developmentDeps = packageJson.devDependencies || {};
const allDeps = { ...deps, ...developmentDeps };

// Framework detection patterns
const frameworks = [
{
name: 'angular',
corePackage: '@angular/core',
devDependencies: [
'@angular-builders/',
'@angular-devkit/',
'@angular/cli',
'@webcomponents/custom-elements',
],
},
{
name: 'react',
corePackage: 'react',
devDependencies: [
'react-scripts',
'@testing-library/react',
'react-app-rewired',
],
},
// Add more frameworks as needed
];

for (const framework of frameworks) {
if (allDeps[framework.corePackage]) {
return framework;
}
}

return null;
}

function isFrameworkDevelopmentDependency(
dependency: string,
frameworkInfo: ReturnType<typeof getFrameworkInfo>,
): boolean {
if (!frameworkInfo) return false;

return frameworkInfo.devDependencies.some(
(prefix) => dependency.startsWith(prefix) || dependency === prefix,
);
}

export async function getDependencyInfo(
dependency: string,
context: DependencyContext,
Expand All @@ -72,6 +128,16 @@ export async function getDependencyInfo(
hasSubDependencyUsage: false,
};

// Framework-specific handling
const frameworkInfo = getFrameworkInfo(context);
if (
frameworkInfo &&
isFrameworkDevelopmentDependency(dependency, frameworkInfo)
) {
info.requiredByPackages.add(frameworkInfo.corePackage);
return info;
}

// Special handling for @types packages
if (dependency.startsWith('@types/')) {
const basePackage = normalizeTypesPackage(dependency);
Expand Down

0 comments on commit 5a19bc7

Please sign in to comment.