Skip to content

Commit

Permalink
build: test publish
Browse files Browse the repository at this point in the history
  • Loading branch information
mysteryven committed Aug 13, 2024
1 parent aa884a8 commit 10f4c63
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
restore-cache: false
tools: cargo-deny

- if: steps.filter.outputs.src == 'true'
- if: steps.filter.outpts.src == 'true'
run: cargo deny check

unused-deps:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "depcheck"
name = "depclean"
version = "0.1.0"
edition = "2021"

Expand Down
Binary file added depclean-darwin-arm64
Binary file not shown.
Binary file added npm/depclean-darwin-arm64/depclean
Binary file not shown.
1 change: 1 addition & 0 deletions npm/depclean-darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"@depclean/darwin-arm64","version":"0.0.2","author":"mysteryven","license":"MIT","homepage":"https://github.com/mysteryven/depclean","bugs":"https://github.com/mysteryven/depclean/issues","repository":{"type":"git","url":"git+https://github.com/mysteryven/depclean.git","directory":"npm"},"os":["darwin"],"cpu":["arm64"]}
30 changes: 1 addition & 29 deletions npm/depclean/package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1 @@
{
"name": "depclean",
"version": "0.7.1",
"description": "A rust version depcheck to help you find and remove unused dependencies in your package.json",
"keywords": [
"depclean",
"depcheck",
"npm",
"node",
"rust"
],
"author": "mysteryven",
"license": "MIT",
"homepage": "https://github.com/mysteryven/depclean",
"bugs": "https://github.com/mysteryven/depclean/issues",
"repository": {
"type": "git",
"url": "https://github.com/mysteryven/depclean",
"directory": "npm"
},
"bin": "bin/depclean",
"engines": {
"node": ">=14.*"
},
"files": [
"bin/depclean",
"README.md"
]
}
{"name":"depclean","version":"0.0.2","description":"A rust version depcheck to help you find and remove unused dependencies in your package.json","keywords":["depclean","depcheck","npm","node","rust"],"author":"mysteryven","license":"MIT","homepage":"https://github.com/mysteryven/depclean","bugs":"https://github.com/mysteryven/depclean/issues","repository":{"type":"git","url":"git+https://github.com/mysteryven/depclean.git","directory":"npm"},"bin":{"depclean":"bin/depclean"},"engines":{"node":">=14.*"},"files":["bin/depclean","README.md"],"optionalDependencies":{"@depclean/darwin-arm64":"0.0.2"}}
5 changes: 3 additions & 2 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ pub struct PackageJSON {
dependencies: FxHashMap<Atom, Atom>,
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Deserialize)]
pub struct DependenceContainer {
/// dependencies collect from package.json
dependencies: FxHashSet<Atom>,
#[serde(default)]
dependencies: FxHashSet<CompactStr>,
}

impl DependenceContainer {
Expand Down
17 changes: 9 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use std::{
env::current_dir,
path::Path,
sync::Arc,
};
use std::{env::current_dir, path::Path, sync::Arc};

use colorful::Colorful;
use dependencies::DependenceBuilder;
Expand Down Expand Up @@ -38,9 +34,6 @@ impl DepChecker {
/// # Panics
/// if package.json not found in the root directory
pub fn check(&mut self, root_path: &Path) -> Vec<CompactStr> {
if !root_path.join("package.json").exists() {
eprintln!("package.json not found in the root directory");
}
let paths: FxHashSet<Box<Path>> = Walk::new(root_path.to_path_buf())
.paths()
.into_iter()
Expand Down Expand Up @@ -79,7 +72,15 @@ impl DepChecker {
}

pub fn run_with_path(&mut self, path: &Path) {
if !path.join("package.json").exists() {
eprintln!("Didn't find package.json in current directory, did you run this command in the right place?");
return;
}
let unused_deps = self.check(path);
if unused_deps.is_empty() {
println!("No unused dependencies found, good!");
return;
}
let dep_text = if unused_deps.len() > 1 {
"dependencies"
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use depclean::DepChecker;

fn main() {
println!("Hello, world!");
let mut checker = DepChecker::new();
checker.run();
}
19 changes: 15 additions & 4 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
Atom,
};

const EXTENSIONS: [&str; 4] = ["js", "jsx", "mjs", "cjs", "ts", "tsx"];
const EXTENSIONS: &[&str] = &["js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx"];

pub struct DepCheckerContext<'a> {
semantic: Rc<Semantic<'a>>,
Expand Down Expand Up @@ -64,15 +64,26 @@ impl Runtime {
/// # Panics
/// if the file extension is not one of "js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx"
///
/// check js kind files, includes .js, .jsx, .ts, .tsx
/// analyze their esm and cjs dependencies
/// Analyze their esm and cjs dependencies, return the used dependencies
/// for file:
///
/// ```js
/// import A from './a.js';
/// import B from 'b/foo.mjs';
/// const C = require('c')
/// ```
///
/// We will get `["b/foo.mjs", "c"]`
pub fn check_js_files(&self, path: &Path) -> Vec<CompactStr> {
let Ok(source_type) = SourceType::from_path(path) else {
eprintln!("Unsupported file type: {:?}", path);
return vec![];
};

let source_text = fs::read_to_string(path).unwrap();
let Ok(source_text) = fs::read_to_string(path) else {
eprintln!("Failed to read file: {:?}", path);
return vec![];
};
let allocator = Allocator::default();
let ret = Parser::new(&allocator, &source_text, source_type)
.allow_return_outside_function(true)
Expand Down

0 comments on commit 10f4c63

Please sign in to comment.