Skip to content

Commit

Permalink
feat: initial release of @noahnu/unused-files (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahnu authored Jan 15, 2024
1 parent 05b3fbc commit 2e19087
Show file tree
Hide file tree
Showing 25 changed files with 1,011 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ insert_final_newline = true
end_of_line = lf
max_line_length = off

[*.yml]
[*.{yml,yaml}]
indent_size = 2

[{CHANGELOG.md,package.json,yarn.lock}]
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
name: CI

on:
pull_request:
push:
branches: [main]

jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: noahnu/.github/.github/actions/setup-node@main

lint:
name: Lint
runs-on: ubuntu-latest
needs: [prepare]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: noahnu/.github/.github/actions/setup-node@main

- name: Run Lint
run: |
yarn lint:ci
build:
name: Build
runs-on: ubuntu-latest
needs: [prepare]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: noahnu/.github/.github/actions/setup-node@main

- name: Run Build
run: |
yarn build
test:
name: Test
runs-on: ubuntu-latest
needs: [prepare]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: noahnu/.github/.github/actions/setup-node@main

- name: Run Test
run: |
yarn test
preview:
name: Preview
runs-on: ubuntu-latest
needs: [prepare]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
permissions:
contents: read
pull-requests: write
steps:
- uses: noahnu/.github/.github/actions/setup-node@main

- name: Post Monodeploy Preview
uses: noahnu/.github/.github/actions/post-monodeploy-preview@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
26 changes: 26 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Release

on:
workflow_dispatch:

permissions:
contents: write
packages: write

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: noahnu/.github/.github/actions/setup-node@main
with:
fetch-depth: 0

- name: Publish
if: github.ref == 'refs/heads/main'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_PUBLISH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
run: |
yarn release
2 changes: 1 addition & 1 deletion .yarn/sdks/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript",
"version": "5.2.2-sdk",
"version": "5.3.3-sdk",
"main": "./lib/typescript.js",
"type": "commonjs",
"bin": {
Expand Down
3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
---
nodeLinker: pnp
npmRegistries:
//registry.npmjs.org/:
npmAuthToken: "${NPM_PUBLISH_TOKEN:-invalid}"
18 changes: 3 additions & 15 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,14 @@ const config = {
collectCoverage: true,
}),
transform: {
'^.+\\.tsx?$': require.resolve('ts-jest'),
'^.+\\.ts$': require.resolve('ts-jest'),
},
setupFiles: ['<rootDir>/testUtils/setup.ts'],
coverageReporters: CI ? ['json'] : ['text', 'json'],
coverageDirectory: 'raw-coverage/jest/',
collectCoverageFrom: ['packages/**/src/**/*.ts', '.yarn/__virtual__/**/packages/**/*.ts'],
coveragePathIgnorePatterns: ['/node_modules/', '/__mocks__/', '\\.test.ts$', '\\.mock.ts$'],
watchPathIgnorePatterns: [
'<rootDir>/example-monorepo',
'<rootDir>/artifacts',
'<rootDir>/packages/.*/lib',
'<rootDir>/packages/.*/.*\\.js',
],
testPathIgnorePatterns: [
'/node_modules/',
'/.yarn/',
'<rootDir>/.*\\.js',
'<rootDir>/.*/lib/',
'<rootDir>/packages',
],
watchPathIgnorePatterns: ['<rootDir>/packages/.*/lib', '<rootDir>/packages/.*/.*\\.js'],
testPathIgnorePatterns: ['/node_modules/', '/.yarn/', '<rootDir>/.*\\.js', '<rootDir>/.*/lib/'],
haste: {
throwOnModuleCollision: true,
},
Expand Down
19 changes: 19 additions & 0 deletions monodeploy.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @ts-check

/** @type {import('@monodeploy/types').RecursivePartial<import('@monodeploy/types').MonodeployConfiguration>} */
const config = {
conventionalChangelogConfig: '@tophat/conventional-changelog-config',
maxConcurrentWrites: 1,
changelogFilename: '<packageDir>/CHANGELOG.md',
autoCommit: true,
autoCommitMessage: 'chore: release [skip ci]',
git: {
push: true,
tag: true,
},
persistVersions: true,
changesetIgnorePatterns: ['**/*.test.ts'],
commitIgnorePatterns: ['\\[skip-ci\\]'],
}

module.exports = config
18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"devDependencies": {
"@jest/types": "^29.6.3",
"@monodeploy/plugin-github": "^2.0.1",
"@monodeploy/types": "^5.0.1",
"@tophat/commitizen-adapter": "^1.0.2",
"@tophat/commitlint-config": "^1.0.2",
"@tophat/conventional-changelog-config": "^1.0.1",
Expand All @@ -30,9 +31,11 @@
"@tophat/jest-resolver": "^0.1.0",
"@types/jest": "^29.5.8",
"@types/node": "^20",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@yarnpkg/core": "^4.0.2",
"@yarnpkg/sdks": "^3.1.0",
"@yarnpkg/types": "^4.0.0",
"commitizen": "^4.3.0",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
Expand All @@ -46,21 +49,26 @@
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"lint-staged": "^15.1.0",
"monodeploy": "^5.0.1",
"prettier": "^3.1.0",
"ts-jest": "^29.1.1",
"typescript": "5.2.2"
"ts-node": "^10.9.1",
"typescript": "5.3.3"
},
"scripts": {
"clean": "rm -rf ${ARTIFACT_DIR:-artifacts} && yarn workspaces foreach -vpi --worktree run clean",
"clean": "rm -rf reports && yarn workspaces foreach -vpi --worktree run clean",
"build": "yarn workspaces foreach -vpi --worktree --topological-dev run prepack",
"lint:ci": "eslint . --format junit --output-file reports/eslint.junit.xml",
"lint:fix": "eslint . --fix",
"lint": "eslint .",
"test:ci": "CI=1 run test --ci --runInBand",
"test:watch": "run test --watch",
"test": "jest --config=jest.config.js",
"types:watch": "tsc --noEmit --emitDeclarationOnly false --pretty --watch"
"types:watch": "tsc --noEmit --emitDeclarationOnly false --pretty --watch",
"workspace:build": "rm -rf $0/lib $0/.tmp && tsc -p $0/tsconfig.build.json",
"workspace:clean": "rm -rf $0/lib $0/.tmp && find $0/src -name '*.js' -type f -delete",
"release": "monodeploy --config-file monodeploy.config.ts --log-level 0 --plugins @monodeploy/plugin-github"
}
}
Empty file removed packages/.gitkeep
Empty file.
20 changes: 20 additions & 0 deletions packages/internal-test-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@noahnu/internal-test-utils",
"private": true,
"version": "0.0.0",
"repository": {
"type": "git",
"url": "https://github.com/noahnu/nodejs-tools.git",
"directory": "packages/internal-test-utils"
},
"license": "MIT",
"author": {
"name": "noahnu",
"email": "[email protected]",
"url": "https://noahnu.com"
},
"main": "./src/index.ts",
"devDependencies": {
"@types/node": "^20.9.0"
}
}
31 changes: 31 additions & 0 deletions packages/internal-test-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
Symbol.asyncDispose ??= Symbol.for('asyncDispose')

export type TempDirContext = {
dir: string
writeFile: (name: string, contents: string) => Promise<string>
}

export async function createTempDir(): Promise<TempDirContext & AsyncDisposable> {
const dir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'nodejs-tools-'))

return {
dir,
async writeFile(name: string, contents: string) {
const filename = path.join(dir, name)
await fs.promises.mkdir(path.dirname(filename), { recursive: true })
await fs.promises.writeFile(filename, contents, { encoding: 'utf-8' })
return filename
},
async [Symbol.asyncDispose]() {
try {
await fs.promises.rm(dir, { recursive: true })
} catch {}
},
}
}
8 changes: 8 additions & 0 deletions packages/internal-test-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"declarationDir": "./lib",
"outDir": "./lib"
},
"include": ["./src"],
}
7 changes: 7 additions & 0 deletions packages/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": false
}
}
33 changes: 33 additions & 0 deletions packages/unused-files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# @noahnu/unused-files

## Usage

```sh
DEBUG=unused-files yarn dlx @noahnu/unused-files --entry src/index.ts --ignore '**/node_modules' --ignore '**/dist' --deppth 10 ./src
```

Or use the Node API:

```ts
import { findUnusedFiles } from '@noahnu/unused-files'

const result = await findUnusedFiles({
entryFiles: ['src/index.ts'],

// optional
sourceDirectories: [process.cwd()],
ignorePatterns: ['**/node_modules'],
aliases: {
'@my/alias': 'path/to/file/index.ts',
},
depth: 10,
})

console.log(result.unusedFiles.join('\n'))
```

## Development

```sh
yarn workspace @noahnu/unused-files run-local
```
45 changes: 45 additions & 0 deletions packages/unused-files/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "@noahnu/unused-files",
"version": "0.0.0",
"repository": {
"type": "git",
"url": "https://github.com/noahnu/nodejs-tools.git",
"directory": "packages/unused-files"
},
"license": "MIT",
"author": {
"name": "noahnu",
"email": "[email protected]",
"url": "https://noahnu.com"
},
"scripts": {
"clean": "run workspace:clean \"$(pwd)\"",
"prepack": "run workspace:build \"$(pwd)\"",
"run-local": "run -T ts-node --transpileOnly ./src/bin.ts"
},
"bin": "./src/bin.ts",
"main": "./src/api/index.ts",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public",
"bin": "./lib/bin.js",
"main": "./lib/api/index.js",
"types": "./lib/api/index.d.ts"
},
"files": [
"lib"
],
"dependencies": {
"@types/debug": "^4.1.12",
"@typescript-eslint/typescript-estree": "^6.18.1",
"clipanion": "4.0.0-rc.2",
"debug": "^4.3.4",
"fast-glob": "^3.3.2",
"typanion": "^3.14.0"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@noahnu/internal-test-utils": "workspace:*",
"@types/node": "^20.9.0"
}
}
Loading

0 comments on commit 2e19087

Please sign in to comment.