Skip to content

Commit

Permalink
chore(cli): converts to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Apr 2, 2023
1 parent 334a3ce commit 8fd6c47
Show file tree
Hide file tree
Showing 59 changed files with 493 additions and 593 deletions.
4 changes: 2 additions & 2 deletions .c8rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"src/**/*.template.js",
"src/cli/tools/svg-in-html-snippets/script.snippet.js",
"src/cli/init-config/get-user-input.js",
"src/cli/listeners/*/index.js",
"src/cli/listeners/{cli-feedback,ndjson}.js"
"src/cli/listeners/*/index.mjs",
"src/cli/listeners/{cli-feedback,ndjson}.mjs"
],
"reporter": ["text-summary", "html", "json-summary"]
}
27 changes: 0 additions & 27 deletions .dependency-cruiser-known-violations.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,6 @@
"name": "not-unreachable-from-cli"
}
},
{
"type": "module",
"from": "src/cli/format.js",
"to": "src/cli/format.js",
"rule": {
"severity": "info",
"name": "not-reachable-from-folder-index"
}
},
{
"type": "module",
"from": "src/cli/tools/wrap-stream-in-html.js",
"to": "src/cli/tools/wrap-stream-in-html.js",
"rule": {
"severity": "info",
"name": "not-reachable-from-folder-index"
}
},
{
"type": "module",
"from": "src/cli/validate-node-environment.js",
"to": "src/cli/validate-node-environment.js",
"rule": {
"severity": "info",
"name": "not-reachable-from-folder-index"
}
},
{
"type": "module",
"from": "src/utl/array-util.js",
Expand Down
1 change: 1 addition & 0 deletions .dependency-cruiser.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"^os$",
"^fs$",
"^path$",
"^url$",
"$1",
"^src/meta.js$",
"^src/extract/transpile/meta.js$"
Expand Down
15 changes: 5 additions & 10 deletions bin/depcruise-baseline.js → bin/depcruise-baseline.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env node
const validateNodeEnvironment = require("../src/cli/validate-node-environment");
import { program } from "commander";
import validateNodeEnvironment from "../src/cli/validate-node-environment.mjs";
import meta from "../src/meta.js";
import cli from "../src/cli/index.mjs";

function formatError(pError) {
process.stderr.write(pError.message);
Expand All @@ -9,14 +12,6 @@ function formatError(pError) {
try {
validateNodeEnvironment();

// importing things only after the validateNodeEnv check so we can show an understandable
// error. Otherwise, on unsupported platforms we would show a stack trace, which is
// not so nice
/* eslint-disable node/global-require */
const program = require("commander");
const { version } = require("../src/meta.js");
const cli = require("../src/cli");

program
.description(
"Writes all known violations of rules in a .dependency-cruiser.js to a file.\n" +
Expand All @@ -29,7 +24,7 @@ try {
"file to write output to; - for stdout",
".dependency-cruiser-known-violations.json"
)
.version(version)
.version(meta.version)
.arguments("<files-or-directories>")
.parse(process.argv);

Expand Down
16 changes: 6 additions & 10 deletions bin/depcruise-fmt.js → bin/depcruise-fmt.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env node
const validateNodeEnvironment = require("../src/cli/validate-node-environment");

import { program } from "commander";
import validateNodeEnvironment from "../src/cli/validate-node-environment.mjs";
import meta from "../src/meta.js";
import format from "../src/cli/format.mjs";

function formatError(pError) {
process.stderr.write(pError.message);
Expand All @@ -9,14 +13,6 @@ function formatError(pError) {
try {
validateNodeEnvironment();

// importing things only after the validateNodeEnv check so we can show an understandable
// error. Otherwise, on unsupported platforms we would show a stack trace, which is
// not so nice
/* eslint-disable node/global-require */
const program = require("commander");
const { version } = require("../src/meta.js");
const format = require("../src/cli/format.js");

program
.description(
"Format dependency-cruiser output json.\nDetails: https://github.com/sverweij/dependency-cruiser"
Expand Down Expand Up @@ -69,7 +65,7 @@ try {
"exit with a non-zero exit code when the input json contains error level " +
"dependency violations. Works for err, err-long and teamcity output types"
)
.version(version)
.version(meta.version)
.arguments("<dependency-cruiser-json>")
.parse(process.argv);

Expand Down
13 changes: 6 additions & 7 deletions bin/dependency-cruise.js → bin/dependency-cruise.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#!/usr/bin/env node
const validateNodeEnvironment = require("../src/cli/validate-node-environment");
import { EOL } from "os";
import { program } from "commander";
import validateNodeEnvironment from "../src/cli/validate-node-environment.mjs";
import meta from "../src/meta.js";
import cli from "../src/cli/index.mjs";

try {
validateNodeEnvironment();

// importing things only after the validateNodeEnv check so we can show an understandable
// error. Otherwise, on unsupported platforms we could show a stack trace, which is
// not so nice
/* eslint-disable node/global-require */
const { EOL } = require("os");
const program = require("commander");
const { version } = require("../src/meta.js");
const cli = require("../src/cli");

program
.description(
Expand Down Expand Up @@ -168,7 +167,7 @@ try {
`${EOL}Other options:` +
`${EOL} see https://github.com/sverweij/dependency-cruiser/blob/master/doc/cli.md${EOL}`
)
.version(version)
.version(meta.version)
.arguments("[files-or-directories]")
.parse(process.argv);

Expand Down
5 changes: 0 additions & 5 deletions bin/wrap-stream-in-html.js

This file was deleted.

5 changes: 5 additions & 0 deletions bin/wrap-stream-in-html.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

import wrapStreamInHtml from "../src/cli/tools/wrap-stream-in-html.mjs";

wrapStreamInHtml(process.stdin, process.stdout);
2 changes: 1 addition & 1 deletion doc/options-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ the default theme to be replaced by flipping the `replace` attribute to `true`.

<details>
<summary>bare</summary>
<!-- bin/dependency-cruise.js -Tdot -v doc/assets/theming/bare.config.js src/main | dot -Tsvg > doc/assets/theming/bare.svg-->
<!-- bin/dependency-cruise.mjs -Tdot -v doc/assets/theming/bare.config.js src/main | dot -Tsvg > doc/assets/theming/bare.svg-->

```javascript
module.exports = {
Expand Down
8 changes: 4 additions & 4 deletions doc/real-world-samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,22 @@ them. Click for slightly more interactive versions.
To generate this yourself do this in the root of the dependency-cruiser repo:

```
node ./bin/dependency-cruise.js bin src --config --output-type archi | \
node ./bin/dependency-cruise.mjs bin src --config --output-type archi | \
# format the output with dot. For this specific graph top-down (TD)
# orientation works best
dot -T svg -Grankdir=TD | \
# save the svg
tee doc/real-world-samples/dependency-cruiser-archi-graph.svg | \
# process the svg into an interactive html graph
node bin/wrap-stream-in-html.js > docs/dependency-cruiser-archi-graph.html
node bin/wrap-stream-in-html.mjs > docs/dependency-cruiser-archi-graph.html
```

> the only repository in the world you can't use the commands `depcruise`,
> `depcruise-fmt` or `depcruise-wrap-stream-in-html` is dependency-cruiser's own -
> instead we run the JavaScript files from `bin` directly.
> If you adapt the script for your own use replace
> `node ./bin/dependency-cruise.js` with `depcruise`,
> `node ./bin/wrap-stream-in-html.js` with `depcruise-wrap-stream-in-html`.
> `node ./bin/dependency-cruise.mjs` with `depcruise`,
> `node ./bin/wrap-stream-in-html.mjs` with `depcruise-wrap-stream-in-html`.
</details>

Expand Down
56 changes: 28 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
},
"homepage": "https://github.com/sverweij/dependency-cruiser",
"bin": {
"dependency-cruiser": "bin/dependency-cruise.js",
"dependency-cruise": "bin/dependency-cruise.js",
"depcruise": "bin/dependency-cruise.js",
"depcruise-baseline": "bin/depcruise-baseline.js",
"depcruise-fmt": "bin/depcruise-fmt.js",
"depcruise-wrap-stream-in-html": "bin/wrap-stream-in-html.js"
"dependency-cruiser": "bin/dependency-cruise.mjs",
"dependency-cruise": "bin/dependency-cruise.mjs",
"depcruise": "bin/dependency-cruise.mjs",
"depcruise-baseline": "bin/depcruise-baseline.mjs",
"depcruise-fmt": "bin/depcruise-fmt.mjs",
"depcruise-wrap-stream-in-html": "bin/wrap-stream-in-html.mjs"
},
"main": "src/main/index.js",
"exports": {
Expand Down Expand Up @@ -73,30 +73,30 @@
"build:clean": "make clean",
"check": "npm-run-all build lint depcruise test:cover",
"check:full": "npm-run-all check test:glob",
"depcruise": "node ./bin/dependency-cruise.js src bin test configs types tools --config --ignore-known",
"depcruise:all": "node ./bin/dependency-cruise.js src bin test configs types tools --config",
"depcruise:baseline": "node ./bin/depcruise-baseline.js src bin test configs types tools",
"depcruise:explain": "node ./bin/dependency-cruise.js src bin test configs types tools --output-type err-long --config --progress none",
"depcruise": "node ./bin/dependency-cruise.mjs src bin test configs types tools --config --ignore-known",
"depcruise:all": "node ./bin/dependency-cruise.mjs src bin test configs types tools --config",
"depcruise:baseline": "node ./bin/depcruise-baseline.mjs src bin test configs types tools",
"depcruise:explain": "node ./bin/dependency-cruise.mjs src bin test configs types tools --output-type err-long --config --progress none",
"depcruise:graph:doc": "npm-run-all depcruise:graph:doc:json --parallel depcruise:graph:doc:fmt-* depcruise:graph:doc:samples",
"depcruise:graph:doc:json": "node ./bin/dependency-cruise.js bin src test --config --output-type json --output-to tmp_graph_deps.json --progress",
"depcruise:graph:doc:fmt-detail": "./bin/depcruise-fmt.js -T dot -f - tmp_graph_deps.json | dot -T svg | tee doc/real-world-samples/dependency-cruiser-without-node_modules.svg | node bin/wrap-stream-in-html.js > docs/dependency-cruiser-dependency-graph.html",
"depcruise:graph:doc:fmt-archi": "./bin/depcruise-fmt.js -T archi -f - tmp_graph_deps.json | dot -T svg -Gordering=in -Grankdir=TD | tee doc/real-world-samples/dependency-cruiser-archi-graph.svg | node bin/wrap-stream-in-html.js > docs/dependency-cruiser-archi-graph.html",
"depcruise:graph:doc:fmt-dir": "./bin/depcruise-fmt.js -T ddot -f - tmp_graph_deps.json | dot -T svg -Grankdir=TD | tee doc/real-world-samples/dependency-cruiser-dir-graph.svg | node bin/wrap-stream-in-html.js > docs/dependency-cruiser-dir-graph.html",
"depcruise:graph:doc:fmt-schema": "cd tools/schema && node ../../bin/dependency-cruise.js . --config --output-type dot | dot -T svg | tee ../overview.svg | node ../../bin/wrap-stream-in-html.js > ../../docs/schema-overview.html && cd -",
"depcruise:graph:doc:fmt-types": "cd types && node ../bin/dependency-cruise.js . --ts-pre-compilation-deps --config --output-type dot | dot -T svg > overview.svg && cd -",
"depcruise:graph:doc:json": "node ./bin/dependency-cruise.mjs bin src test --config --output-type json --output-to tmp_graph_deps.json --progress",
"depcruise:graph:doc:fmt-detail": "./bin/depcruise-fmt.mjs -T dot -f - tmp_graph_deps.json | dot -T svg | tee doc/real-world-samples/dependency-cruiser-without-node_modules.svg | node bin/wrap-stream-in-html.mjs > docs/dependency-cruiser-dependency-graph.html",
"depcruise:graph:doc:fmt-archi": "./bin/depcruise-fmt.mjs -T archi -f - tmp_graph_deps.json | dot -T svg -Gordering=in -Grankdir=TD | tee doc/real-world-samples/dependency-cruiser-archi-graph.svg | node bin/wrap-stream-in-html.mjs > docs/dependency-cruiser-archi-graph.html",
"depcruise:graph:doc:fmt-dir": "./bin/depcruise-fmt.mjs -T ddot -f - tmp_graph_deps.json | dot -T svg -Grankdir=TD | tee doc/real-world-samples/dependency-cruiser-dir-graph.svg | node bin/wrap-stream-in-html.mjs > docs/dependency-cruiser-dir-graph.html",
"depcruise:graph:doc:fmt-schema": "cd tools/schema && node ../../bin/dependency-cruise.mjs . --config --output-type dot | dot -T svg | tee ../overview.svg | node ../../bin/wrap-stream-in-html.mjs > ../../docs/schema-overview.html && cd -",
"depcruise:graph:doc:fmt-types": "cd types && node ../bin/dependency-cruise.mjs . --ts-pre-compilation-deps --config --output-type dot | dot -T svg > overview.svg && cd -",
"depcruise:graph:doc:samples": "sh tools/generate-samples.sh",
"depcruise:graph:mermaid": "node ./bin/dependency-cruise.js bin src --include-only ^src/ --config --collapse 2 --output-type mermaid",
"depcruise:graph:mermaid:diff": "node ./bin/dependency-cruise.js bin src test types tools --config configs/.dependency-cruiser-unlimited.json --output-type mermaid --reaches \"$(watskeburt $SHA)\"",
"depcruise:graph:view": "node ./bin/dependency-cruise.js bin src --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-show-metrics-config.json --output-type dot --progress cli-feedback --highlight \"$(watskeburt develop)\" | dot -T svg | node ./bin/wrap-stream-in-html.js | browser",
"depcruise:graph:view:diff": "node ./bin/dependency-cruise.js bin src test --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-unlimited.json --output-type dot --progress cli-feedback --reaches \"$(watskeburt develop)\" | dot -T svg | node ./bin/wrap-stream-in-html.js | browser",
"depcruise:report": "node ./bin/dependency-cruise.js src bin test configs types --output-type err-html --config configs/.dependency-cruiser-show-metrics-config.json --output-to dependency-violations.html",
"depcruise:report:view": "node ./bin/dependency-cruise.js src bin test configs types --output-type err-html --config configs/.dependency-cruiser-show-metrics-config.json --output-to - | browser",
"depcruise:focus": "node ./bin/dependency-cruise.js src bin test configs types tools --progress --config --output-type text --focus",
"depcruise:reaches": "node ./bin/dependency-cruise.js src bin test configs types tools --progress --config configs/.dependency-cruiser-unlimited.json --output-type text --reaches",
"depcruise:graph:mermaid": "node ./bin/dependency-cruise.mjs bin src --include-only ^src/ --config --collapse 2 --output-type mermaid",
"depcruise:graph:mermaid:diff": "node ./bin/dependency-cruise.mjs bin src test types tools --config configs/.dependency-cruiser-unlimited.json --output-type mermaid --reaches \"$(watskeburt $SHA)\"",
"depcruise:graph:view": "node ./bin/dependency-cruise.mjs bin src --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-show-metrics-config.json --output-type dot --progress cli-feedback --highlight \"$(watskeburt develop)\" | dot -T svg | node ./bin/wrap-stream-in-html.mjs | browser",
"depcruise:graph:view:diff": "node ./bin/dependency-cruise.mjs bin src test --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-unlimited.json --output-type dot --progress cli-feedback --reaches \"$(watskeburt develop)\" | dot -T svg | node ./bin/wrap-stream-in-html.mjs | browser",
"depcruise:report": "node ./bin/dependency-cruise.mjs src bin test configs types --output-type err-html --config configs/.dependency-cruiser-show-metrics-config.json --output-to dependency-violations.html",
"depcruise:report:view": "node ./bin/dependency-cruise.mjs src bin test configs types --output-type err-html --config configs/.dependency-cruiser-show-metrics-config.json --output-to - | browser",
"depcruise:focus": "node ./bin/dependency-cruise.mjs src bin test configs types tools --progress --config --output-type text --focus",
"depcruise:reaches": "node ./bin/dependency-cruise.mjs src bin test configs types tools --progress --config configs/.dependency-cruiser-unlimited.json --output-type text --reaches",
"format": "prettier --loglevel warn --write \"src/**/*.js\" \"configs/**/*.js\" \"tools/**/*.mjs\" \"bin/*\" \"types/*.d.ts\" \"test/**/*.spec.{cjs,js}\" \"test/**/*.{spec,utl}.mjs\"",
"format:check": "prettier --loglevel warn --check \"src/**/*.js\" \"configs/**/*.js\" \"tools/**/*.mjs\" \"bin/*\" \"types/*.d.ts\" \"test/**/*.spec.{cjs,js}\" \"test/**/*.{spec,utl}.mjs\"",
"lint": "npm-run-all --parallel --aggregate-output lint:eslint format:check lint:types",
"lint:eslint": "eslint bin/dependency-cruise.js bin src test configs tools/**/*.mjs --cache --cache-location node_modules/.cache/eslint/",
"lint:eslint": "eslint bin/dependency-cruise.mjs bin src test configs tools/**/*.mjs --cache --cache-location node_modules/.cache/eslint/",
"lint:eslint:fix": "eslint --fix bin src test configs tools/**/*.mjs --cache --cache-location node_modules/.cache/eslint/",
"lint:eslint:clear-caches": "rm -rf node_modules/.cache/eslint/",
"lint:fix": "npm-run-all lint:eslint:fix format lint:types:fix",
Expand All @@ -121,9 +121,9 @@
"test:u": "LANG=en_US.UTF-8 mocha --grep \"^\\[[U]\\]\"",
"test:e": "LANG=en_US.UTF-8 mocha --grep \"^\\[[E]\\]\"",
"test:cover": "LANG=en_US.UTF-8 c8 mocha",
"test:glob": "set -f && test \"`bin/dependency-cruise.js test/extract/__mocks__/gather-globbing/packages/**/src/**/*.js | grep \"no dependency violations found\"`\" = \"✔ no dependency violations found (6 modules, 0 dependencies cruised)\"",
"test:load": "hyperfine --warmup 3 --runs 30 \"bin/dependency-cruise.js src bin test configs types tools --ignore-known --validate --no-cache --no-progress\"",
"test:load:short": "hyperfine --warmup 1 --runs 5 \"bin/dependency-cruise.js src bin test configs types tools --ignore-known --validate --no-cache --no-progress\"",
"test:glob": "set -f && test \"`bin/dependency-cruise.mjs test/extract/__mocks__/gather-globbing/packages/**/src/**/*.js | grep \"no dependency violations found\"`\" = \"✔ no dependency violations found (6 modules, 0 dependencies cruised)\"",
"test:load": "hyperfine --warmup 3 --runs 30 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --validate --no-cache --no-progress\"",
"test:load:short": "hyperfine --warmup 1 --runs 5 \"bin/dependency-cruise.mjs src bin test configs types tools --ignore-known --validate --no-cache --no-progress\"",
"test:watch": "mocha --watch --watch-extensions=json --reporter=min test/\\*\\*/\\*.spec.js",
"update-dependencies": "npm-run-all upem:update upem:install build:clean build lint:eslint:clear-caches lint:fix depcruise test:cover",
"upem-outdated": "npm outdated --json --long | upem --dry-run",
Expand Down
17 changes: 0 additions & 17 deletions src/cli/defaults.js

This file was deleted.

16 changes: 16 additions & 0 deletions src/cli/defaults.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const OLD_DEFAULT_RULES_FILE_NAME = ".dependency-cruiser.json";
export const RULES_FILE_NAME_SEARCH_ARRAY = [
".dependency-cruiser.json",
".dependency-cruiser.js",
".dependency-cruiser.cjs",
];
export const DEFAULT_BASELINE_FILE_NAME =
".dependency-cruiser-known-violations.json";
export const DEFAULT_CONFIG_FILE_NAME = ".dependency-cruiser.js";
export const WEBPACK_CONFIG = "webpack.config.js";
export const TYPESCRIPT_CONFIG = "tsconfig.json";
export const BABEL_CONFIG = ".babelrc";
export const PACKAGE_MANIFEST = "package.json";
export const OUTPUT_TYPE = "err";
export const OUTPUT_TO = "-";
export const CACHE_FOLDER = "node_modules/.cache/dependency-cruiser";
11 changes: 6 additions & 5 deletions src/cli/format-meta-info.js → src/cli/format-meta-info.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const chalk = require("chalk");
const figures = require("figures");
const main = require("../main");
import chalk from "chalk";
import figures from "figures";

import main from "../main/index.js";

function bool2Symbol(pBool) {
return pBool ? chalk.green(figures.tick) : chalk.red(figures.cross);
Expand All @@ -26,7 +27,7 @@ function formatExtensions(pExtensions) {
);
}

module.exports = function formatMetaInfo() {
export default function formatMetaInfo() {
return `
Supported:
Expand All @@ -43,6 +44,6 @@ ${formatTranspilers()}
${formatExtensions(main.allExtensions)}
`;
};
}

/* eslint security/detect-object-injection : 0 */
Loading

0 comments on commit 8fd6c47

Please sign in to comment.