Skip to content

fix!: migrate to ESM #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
changelog:
exclude:
labels:
- 'Type: Meta'
- 'Type: Question'
- 'Type: Release'

categories:
- title: Security Fixes
labels: ['Type: Security']
- title: Breaking Changes
labels: ['Type: Breaking Change']
- title: Features
labels: ['Type: Feature']
- title: Bug Fixes
labels: ['Type: Bug']
- title: Documentation
labels: ['Type: Documentation']
- title: Refactoring
labels: ['Type: Refactoring']
- title: Testing
labels: ['Type: Testing']
- title: Maintenance
labels: ['Type: Maintenance']
- title: CI
labels: ['Type: CI']
- title: Dependency Updates
labels: ['Type: Dependencies', "dependencies"]
- title: Other Changes
labels: ['*']
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ on: [push, pull_request]
jobs:
test:
name: "Test on Node.js ${{ matrix.node-version }}"
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14]
node-version: [16, 18]
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install
Expand Down
10 changes: 6 additions & 4 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"require": [
"ts-node-test-register"
]
}
"$schema": "https://json.schemastore.org/mocharc",
"loader": "ts-node/esm",
"spec": [
"test/*.test.ts"
]
}
5 changes: 3 additions & 2 deletions bin/cmd.cjs → bin/cmd.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
require("../lib/cli")
.run()
import { run } from "../lib/cli"

run()
.then(
({ exitStatus, stderr, stdout }) => {
if (stdout) {
Expand Down
80 changes: 43 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"name": "express-router-dependency-graph",
"version": "1.1.3",
"description": "Create dependency graph for express routing.",
"keywords": [
"node",
"express",
"dependency-graph",
"visualize",
"tool"
],
"homepage": "https://github.com/azu/express-router-dependency-graph",
"bugs": {
"url": "https://github.com/azu/express-router-dependency-graph/issues"
Expand All @@ -13,38 +20,37 @@
"license": "MIT",
"author": "azu",
"sideEffects": false,
"keywords": [
"node",
"express",
"dependency-graph",
"visualize",
"tool"
],
"main": "lib/index.js",
"type": "module",
"exports": {
".": {
"import": {
"types": "./module/index.d.ts",
"default": "./module/index.js"
},
"default": "./module/index.js"
},
"./package.json": "./package.json"
},
"main": "./module/index.js",
"module": "module/index.js",
"types": "lib/index.d.ts",
"types": "./module/index.d.ts",
"bin": {
"express-router-dependency-graph": "bin/cmd.cjs"
},
"directories": {
"lib": "lib",
"test": "test"
"express-router-dependency-graph": "bin/cmd.mjs"
},
"files": [
"bin/",
"lib/",
"module/",
"src/"
],
"scripts": {
"build": "tsc --build",
"clean": "tsc --build --clean",
"main": "ts-node-transpile-only src/index.ts",
"build": "tsc -p . && tsc -p ./tsconfig.module.json",
"clean": "rimraf lib/ module/",
"prepare": "git config --local core.hooksPath .githooks",
"prepublishOnly": "npm run clean && npm run build",
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
"test": "mocha \"test/**/*.test.ts\"",
"watch": "tsc -p . --watch"
"test": "mocha",
"watch": "tsc --build --watch"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,css}": [
Expand All @@ -57,25 +63,25 @@
"tabWidth": 4,
"trailingComma": "none"
},
"dependencies": {
"@babel/parser": "^7.21.4",
"dependency-cruiser": "^12.11.1",
"esquery": "^1.5.0",
"markdown-table": "^3.0.3",
"meow": "^11.0.0"
},
"devDependencies": {
"@types/esquery": "^1.0.1",
"@types/express": "^4.17.11",
"@types/mocha": "^9.1.1",
"@types/node": "^18.0.0",
"express": "^4.18.1",
"lint-staged": "^13.0.3",
"mocha": "^10.0.0",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"ts-node": "^10.8.1",
"ts-node-test-register": "^10.0.0",
"typescript": "^4.7.4"
"@types/express": "^4.17.17",
"@types/mocha": "^10.0.1",
"@types/node": "^18.15.11",
"express": "^4.18.2",
"lint-staged": "^13.2.1",
"mocha": "^10.2.0",
"prettier": "^2.8.7",
"rimraf": "^5.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
"dependencies": {
"@babel/parser": "^7.18.6",
"dependency-cruiser": "^11.11.0",
"esquery": "^1.4.0",
"markdown-table": "^2.0.0",
"meow": "^9.0.0"
}
"packageManager": "yarn@1.22.19"
}
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import meow from "meow";
import * as path from "path";
import { analyzeDependency } from "./index";
import * as path from "node:path";
import { analyzeDependency } from "./index.js";

export const cli = meow(
`
Expand Down
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { cruise, IReporterOutput } from "dependency-cruiser";
import { IDependency, IModule } from "dependency-cruiser/types/cruise-result";
import { cruise } from "dependency-cruiser";
import type { IDependency, IModule, IReporterOutput } from "dependency-cruiser";
import { parse } from "@babel/parser";
import path from "path";
import fs from "fs/promises";
import path from "node:path";
import fs from "node:fs/promises";
import query from "esquery";
// @ts-ignore
import markdownTable from "markdown-table";
import { markdownTable } from "markdown-table";

const findRouting = async (filePath: string) => {
try {
Expand Down
10 changes: 5 additions & 5 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "path";
import { analyzeDependency } from "../src";
import assert from "assert";

import path from "node:path";
import assert from "node:assert";
import { analyzeDependency } from "../src/index.js";
const __dirname = path.dirname(new URL(import.meta.url).pathname);
const pathReplacer = (dirPath: string) => {
return function replacer(key: string, value: any) {
if (key === "filePath") {
Expand All @@ -10,7 +10,7 @@ const pathReplacer = (dirPath: string) => {
return value;
};
};
const normalize = (o: object, rootDir: string) => {
const normalize = (o: object | string, rootDir: string) => {
return JSON.parse(JSON.stringify(o, pathReplacer(rootDir)));
};

Expand Down
11 changes: 0 additions & 11 deletions test/tsconfig.json

This file was deleted.

30 changes: 17 additions & 13 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
{
"compilerOptions": {
/* Basic Options */
"module": "commonjs",
"moduleResolution": "node",
"module": "ESNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"newLine": "LF",
"outDir": "./lib/",
"target": "ES2018",
"outDir": "./module/",
"target": "ES2020",
"sourceMap": true,
"declaration": true,
"skipLibCheck": true,
"declarationMap": true,
"jsx": "preserve",
"lib": [
"esnext",
"dom"
],
/* Strict Type-Checking Options */
"strict": true,
/* Additional Checks */
/* Report errors on unused locals. */
"skipLibCheck": true,
"noUnusedLocals": true,
/* Report errors on unused parameters. */
"noUnusedParameters": true,
/* Report error when not all code paths in function return a value. */
"noImplicitReturns": true,
/* Report errors for fallthrough cases in switch statement. */
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
},
"include": [
"src/**/*"
],
"exclude": [
".git",
"node_modules"
]
],
"ts-node": {
"compilerOptions": {
"noEmit": true
},
"include": [
"./src/**/*",
"./test/*"
]
}
}
7 changes: 0 additions & 7 deletions tsconfig.module.json

This file was deleted.

Loading