dependency-cruiser 13.0.0-beta-5 → 13.0.0-beta-6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-cruiser",
3
- "version": "13.0.0-beta-5",
3
+ "version": "13.0.0-beta-6",
4
4
  "description": "Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.",
5
5
  "keywords": [
6
6
  "static analysis",
@@ -169,19 +169,19 @@
169
169
  "semver-try-require": "6.2.2",
170
170
  "teamcity-service-messages": "0.1.14",
171
171
  "tsconfig-paths-webpack-plugin": "4.0.1",
172
- "watskeburt": "0.10.2",
172
+ "watskeburt": "0.11.1",
173
173
  "wrap-ansi": "8.1.0"
174
174
  },
175
175
  "devDependencies": {
176
- "@babel/core": "7.21.4",
177
- "@babel/plugin-transform-modules-commonjs": "7.21.2",
178
- "@babel/preset-typescript": "7.21.4",
179
- "@swc/core": "1.3.53",
176
+ "@babel/core": "7.21.5",
177
+ "@babel/plugin-transform-modules-commonjs": "7.21.5",
178
+ "@babel/preset-typescript": "7.21.5",
179
+ "@swc/core": "1.3.55",
180
180
  "@types/lodash": "4.14.194",
181
- "@types/node": "18.16.0",
181
+ "@types/node": "18.16.3",
182
182
  "@types/prompts": "2.4.4",
183
- "@typescript-eslint/eslint-plugin": "5.59.0",
184
- "@typescript-eslint/parser": "5.59.0",
183
+ "@typescript-eslint/eslint-plugin": "5.59.1",
184
+ "@typescript-eslint/parser": "5.59.1",
185
185
  "@vue/compiler-sfc": "3.2.47",
186
186
  "c8": "7.13.0",
187
187
  "chai": "4.3.7",
@@ -199,7 +199,7 @@
199
199
  "eslint-plugin-unicorn": "^46.0.0",
200
200
  "husky": "8.0.3",
201
201
  "intercept-stdout": "0.1.2",
202
- "lint-staged": "13.2.1",
202
+ "lint-staged": "13.2.2",
203
203
  "mocha": "10.2.0",
204
204
  "normalize-newline": "4.1.0",
205
205
  "npm-run-all": "4.1.5",
@@ -1,6 +1,7 @@
1
- import { readFileSync, mkdirSync, writeFileSync } from "node:fs";
1
+ import { readFile, mkdir, writeFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { scannableExtensions } from "../extract/transpile/meta.mjs";
4
+ import { bus } from "../utl/bus.mjs";
4
5
  import { optionsAreCompatible } from "./options-compatible.mjs";
5
6
  import MetadataStrategy from "./metadata-strategy.mjs";
6
7
  import ContentStrategy from "./content-strategy.mjs";
@@ -25,10 +26,10 @@ export default class Cache {
25
26
  * @param {import("../../types/dependency-cruiser.js").IRevisionData=} pRevisionData
26
27
  * @returns {boolean}
27
28
  */
28
- canServeFromCache(pCruiseOptions, pCachedCruiseResult, pRevisionData) {
29
+ async canServeFromCache(pCruiseOptions, pCachedCruiseResult, pRevisionData) {
29
30
  this.revisionData =
30
31
  pRevisionData ??
31
- this.cacheStrategy.getRevisionData(
32
+ (await this.cacheStrategy.getRevisionData(
32
33
  ".",
33
34
  pCachedCruiseResult,
34
35
  pCruiseOptions,
@@ -37,7 +38,8 @@ export default class Cache {
37
38
  scannableExtensions.concat(pCruiseOptions.extraExtensionsToScan)
38
39
  ),
39
40
  }
40
- );
41
+ ));
42
+ bus.debug("cache: - comparing");
41
43
  return (
42
44
  this.cacheStrategy.revisionDataEqual(
43
45
  pCachedCruiseResult.revisionData,
@@ -54,10 +56,10 @@ export default class Cache {
54
56
  * @param {string} pCacheFolder
55
57
  * @returns {import("../../types/dependency-cruiser.js").ICruiseResult}
56
58
  */
57
- read(pCacheFolder) {
59
+ async read(pCacheFolder) {
58
60
  try {
59
61
  return JSON.parse(
60
- readFileSync(join(pCacheFolder, CACHE_FILE_NAME), "utf8")
62
+ await readFile(join(pCacheFolder, CACHE_FILE_NAME), "utf8")
61
63
  );
62
64
  } catch (pError) {
63
65
  return { modules: [], summary: {} };
@@ -69,11 +71,11 @@ export default class Cache {
69
71
  * @param {import("../../types/dependency-cruiser.js").ICruiseResult} pCruiseResult
70
72
  * @param {import("../../types/dependency-cruiser.js").IRevisionData=} pRevisionData
71
73
  */
72
- write(pCacheFolder, pCruiseResult, pRevisionData) {
74
+ async write(pCacheFolder, pCruiseResult, pRevisionData) {
73
75
  const lRevisionData = pRevisionData ?? this.revisionData;
74
76
 
75
- mkdirSync(pCacheFolder, { recursive: true });
76
- writeFileSync(
77
+ await mkdir(pCacheFolder, { recursive: true });
78
+ await writeFile(
77
79
  join(pCacheFolder, CACHE_FILE_NAME),
78
80
  JSON.stringify(
79
81
  this.cacheStrategy.prepareRevisionDataForSaving(
@@ -2,9 +2,8 @@ import { isDeepStrictEqual } from "node:util";
2
2
  import { join } from "node:path/posix";
3
3
  import findContentChanges from "./find-content-changes.mjs";
4
4
  import {
5
- getFileHash,
5
+ getFileHashSync,
6
6
  isInterestingChangeType,
7
- addCheckSumToChange,
8
7
  moduleIsInterestingForDiff,
9
8
  } from "./helpers.mjs";
10
9
 
@@ -17,7 +16,7 @@ function addCheckSumToModule(pBaseDirectory) {
17
16
  if (moduleIsInterestingForDiff(pModule)) {
18
17
  return {
19
18
  ...pModule,
20
- checksum: getFileHash(join(pBaseDirectory, pModule.source)),
19
+ checksum: getFileHashSync(join(pBaseDirectory, pModule.source)),
21
20
  };
22
21
  }
23
22
  return pModule;
@@ -56,7 +55,6 @@ export default class ContentStrategy {
56
55
  getRevisionData(pDirectory, pCachedCruiseResult, pCruiseOptions, pOptions) {
57
56
  const lOptions = {
58
57
  diffListFn: findContentChanges,
59
- checksumFn: addCheckSumToChange,
60
58
  baseDir: process.cwd(),
61
59
  ...pOptions,
62
60
  };
@@ -1,26 +1,23 @@
1
1
  import { join } from "node:path/posix";
2
- import bus from "../utl/bus.mjs";
3
- import busLogLevels from "../utl/bus-log-levels.mjs";
2
+ import { bus } from "../utl/bus.mjs";
4
3
  import findAllFiles from "../utl/find-all-files.mjs";
5
4
  import {
6
- getFileHash,
5
+ getFileHashSync,
7
6
  excludeFilter,
8
7
  includeOnlyFilter,
9
8
  hasInterestingExtension,
10
9
  moduleIsInterestingForDiff,
11
10
  } from "./helpers.mjs";
12
11
 
13
- const { DEBUG } = busLogLevels;
14
-
15
12
  /**
16
13
  * @param {Set<string>} pFileSet
17
- * @param {typeof getFileHash} pFileHashFunction
14
+ * @param {typeof getFileHashSync} pFileHashFunction
18
15
  * @returns {(pModule:import("../..").IModule) => import('../..').IRevisionChange}
19
16
  */
20
17
  function diffCachedModuleAgainstFileSet(
21
18
  pFileSet,
22
19
  pBaseDirectory,
23
- pFileHashFunction = getFileHash
20
+ pFileHashFunction = getFileHashSync
24
21
  ) {
25
22
  return (pModule) => {
26
23
  if (!moduleIsInterestingForDiff(pModule)) {
@@ -75,7 +72,7 @@ export default function findContentChanges(
75
72
  pCachedCruiseResult,
76
73
  pOptions
77
74
  ) {
78
- bus.emit("progress", "cache: - hauling revision data", { level: DEBUG });
75
+ bus.debug("cache: - getting revision data");
79
76
  const lFileSet = new Set(
80
77
  findAllFiles(pDirectory, {
81
78
  baseDir: pOptions.baseDir,
@@ -84,12 +81,12 @@ export default function findContentChanges(
84
81
  }).filter(hasInterestingExtension(pOptions.extensions))
85
82
  );
86
83
 
87
- bus.emit("progress", "cache: - determining cached vs new", { level: DEBUG });
84
+ bus.debug("cache: - getting (cached - new)");
88
85
  const lDiffCachedVsNew = pCachedCruiseResult.modules.map(
89
86
  diffCachedModuleAgainstFileSet(lFileSet, pOptions.baseDir)
90
87
  );
91
88
 
92
- bus.emit("progress", "cache: - determining new vs cached", { level: DEBUG });
89
+ bus.debug("cache: - getting (new - cached)");
93
90
  lDiffCachedVsNew.forEach(({ name }) => lFileSet.delete(name));
94
91
 
95
92
  const lDiffNewVsCached = [];
@@ -97,10 +94,10 @@ export default function findContentChanges(
97
94
  lDiffNewVsCached.push({
98
95
  name: lFileName,
99
96
  changeType: "added",
100
- checksum: getFileHash(join(pOptions.baseDir, lFileName)),
97
+ checksum: getFileHashSync(join(pOptions.baseDir, lFileName)),
101
98
  });
102
99
  }
103
100
 
104
- bus.emit("progress", "cache: - returning revision data", { level: DEBUG });
101
+ bus.debug("cache: - returning revision data");
105
102
  return lDiffCachedVsNew.concat(lDiffNewVsCached);
106
103
  }
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable import/exports-last */
2
2
  import { createHash } from "node:crypto";
3
3
  import { readFileSync } from "node:fs";
4
+ import { readFile } from "node:fs/promises";
4
5
  import { extname } from "node:path";
5
6
  import memoize from "lodash/memoize.js";
6
7
  import { filenameMatchesPattern } from "../graph-utl/match-facade.mjs";
@@ -13,11 +14,32 @@ function hash(pString) {
13
14
  return createHash("sha1").update(pString).digest("base64");
14
15
  }
15
16
 
17
+ /**
18
+ * @param {import("fs").PathOrFileDescriptor} pFileName
19
+ * @returns {Promise<string>}
20
+ */
21
+ async function _getFileHash(pFileName) {
22
+ try {
23
+ return hash(await readFile(pFileName, "utf8"));
24
+ } catch (pError) {
25
+ return "file not found";
26
+ }
27
+ }
28
+
29
+ export const getFileHash = memoize(_getFileHash);
30
+
31
+ export async function addCheckSumToChange(pChange) {
32
+ return {
33
+ ...pChange,
34
+ checksum: await getFileHash(pChange.name),
35
+ };
36
+ }
37
+
16
38
  /**
17
39
  * @param {import("fs").PathOrFileDescriptor} pFileName
18
40
  * @returns {string}
19
41
  */
20
- function _getFileHash(pFileName) {
42
+ function _getFileHashSync(pFileName) {
21
43
  try {
22
44
  return hash(readFileSync(pFileName, "utf8"));
23
45
  } catch (pError) {
@@ -25,16 +47,16 @@ function _getFileHash(pFileName) {
25
47
  }
26
48
  }
27
49
 
28
- export const getFileHash = memoize(_getFileHash);
50
+ export const getFileHashSync = memoize(_getFileHashSync);
29
51
 
30
52
  /**
31
53
  * @param {import("watskeburt").IChange} pChange
32
54
  * @param {import("../../types/dependency-cruiser.js").IRevisionChange}
33
55
  */
34
- export function addCheckSumToChange(pChange) {
56
+ export function addCheckSumToChangeSync(pChange) {
35
57
  return {
36
58
  ...pChange,
37
- checksum: getFileHash(pChange.name),
59
+ checksum: getFileHashSync(pChange.name),
38
60
  };
39
61
  }
40
62
 
@@ -1,8 +1,9 @@
1
1
  import { isDeepStrictEqual } from "node:util";
2
- import { getSHASync, listSync } from "watskeburt";
2
+ import { getSHA, list } from "watskeburt";
3
+ import { bus } from "../utl/bus.mjs";
3
4
  import {
4
5
  isInterestingChangeType,
5
- addCheckSumToChange,
6
+ addCheckSumToChangeSync,
6
7
  excludeFilter,
7
8
  includeOnlyFilter,
8
9
  changeHasInterestingExtension,
@@ -21,26 +22,34 @@ export default class MetaDataStrategy {
21
22
  * @param {(import("watskeburt").IChange) => import("../..").IRevisionChange} pOptions.checksumFn
22
23
  * @returns {import("../../types/dependency-cruiser.js").IRevisionData}
23
24
  */
24
- getRevisionData(pDirectory, pCachedCruiseResult, pCruiseOptions, pOptions) {
25
+ async getRevisionData(
26
+ pDirectory,
27
+ pCachedCruiseResult,
28
+ pCruiseOptions,
29
+ pOptions
30
+ ) {
25
31
  const lOptions = {
26
- shaRetrievalFn: getSHASync,
27
- diffListFn: listSync,
28
- checksumFn: addCheckSumToChange,
32
+ shaRetrievalFn: getSHA,
33
+ diffListFn: list,
34
+ checksumFn: addCheckSumToChangeSync,
29
35
  ...pOptions,
30
36
  };
31
37
  try {
32
- const lSHA = lOptions.shaRetrievalFn();
38
+ bus.debug("cache: - getting sha");
39
+ const lSHA = await lOptions.shaRetrievalFn();
40
+ bus.debug("cache: - getting diff");
41
+ const lDiff = await lOptions.diffListFn(lSHA);
42
+ const lChanges = lDiff
43
+ .filter(({ name }) => excludeFilter(pCruiseOptions.exclude)(name))
44
+ .filter(({ name }) =>
45
+ includeOnlyFilter(pCruiseOptions.includeOnly)(name)
46
+ )
47
+ .filter(changeHasInterestingExtension(lOptions.extensions))
48
+ .filter(isInterestingChangeType(lOptions.interestingChangeTypes));
49
+ bus.debug("cache: - sha-summing diff");
33
50
  return {
34
51
  SHA1: lSHA,
35
- changes: lOptions
36
- .diffListFn(lSHA)
37
- .filter(({ name }) => excludeFilter(pCruiseOptions.exclude)(name))
38
- .filter(({ name }) =>
39
- includeOnlyFilter(pCruiseOptions.includeOnly)(name)
40
- )
41
- .filter(changeHasInterestingExtension(lOptions.extensions))
42
- .filter(isInterestingChangeType(lOptions.interestingChangeTypes))
43
- .map(lOptions.checksumFn),
52
+ changes: lChanges.map(lOptions.checksumFn),
44
53
  };
45
54
  } catch (pError) {
46
55
  throw new Error(
@@ -117,8 +117,8 @@ export function optionsAreCompatible(pOldOptions, pNewOptions) {
117
117
  filterOptionIsCompatible(pOldOptions.collapse, pNewOptions.collapse) &&
118
118
  limitIsCompatible(pOldOptions.maxDepth, pNewOptions.maxDepth) &&
119
119
  optionIsCompatible(
120
- pOldOptions.knownViolations,
121
- pNewOptions.knownViolations
120
+ pOldOptions.knownViolations || [],
121
+ pNewOptions.knownViolations || []
122
122
  ) &&
123
123
  optionIsCompatible(
124
124
  pOldOptions.enhancedResolveOptions,
package/src/cli/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- /* eslint-disable import/max-dependencies */
2
1
  import { join } from "node:path";
3
2
  import { glob } from "glob";
4
3
  import cloneDeep from "lodash/cloneDeep.js";
@@ -7,9 +6,8 @@ import isInstalledGlobally from "is-installed-globally";
7
6
  import chalk from "chalk";
8
7
 
9
8
  import cruise from "../main/cruise.mjs";
10
- import bus from "../utl/bus.mjs";
9
+ import { INFO, bus } from "../utl/bus.mjs";
11
10
 
12
- import busLogLevels from "../utl/bus-log-levels.mjs";
13
11
  import validateFileExistence from "./utl/validate-file-existence.mjs";
14
12
  import normalizeCliOptions from "./normalize-cli-options.mjs";
15
13
  import { write } from "./utl/io.mjs";
@@ -97,8 +95,7 @@ function setUpListener(pCruiseOptions) {
97
95
  if (Boolean(lListenerFunction)) {
98
96
  lListenerFunction(
99
97
  bus,
100
- pCruiseOptions?.ruleSet?.options?.progress?.maximumLevel ??
101
- busLogLevels.INFO
98
+ pCruiseOptions?.ruleSet?.options?.progress?.maximumLevel ?? INFO
102
99
  );
103
100
  }
104
101
  }
@@ -132,7 +129,7 @@ async function runCruise(pFileDirectoryArray, pCruiseOptions) {
132
129
  { tsConfig, babelConfig }
133
130
  );
134
131
 
135
- bus.emit("progress", "cli: writing results", { complete: 1 });
132
+ bus.progress("cli: writing results", { complete: 1 });
136
133
  bus.emit("write-start");
137
134
  write(lCruiseOptions.outputTo, lReportingResult.output);
138
135
 
@@ -1,6 +1,6 @@
1
1
  import chalk from "chalk";
2
2
  import figures from "figures";
3
- import busLogLevels from "../../utl/bus-log-levels.mjs";
3
+ import { SUMMARY } from "../../utl/bus.mjs";
4
4
 
5
5
  const FULL_ON = 100;
6
6
 
@@ -26,7 +26,7 @@ function getPercentageBar(pPercentage, pParameters) {
26
26
  function getProgressMessageWriter(pStream, pState, pMaxLogLevel) {
27
27
  return (pMessage, pOptions) => {
28
28
  const lOptions = {
29
- level: busLogLevels.SUMMARY,
29
+ level: SUMMARY,
30
30
  complete: pState.complete,
31
31
  ...(pOptions || {}),
32
32
  };
@@ -56,7 +56,7 @@ function getStartWriter(pStream) {
56
56
 
57
57
  export default function setUpCliFeedbackListener(
58
58
  pEventEmitter,
59
- pMaxLogLevel = busLogLevels.SUMMARY,
59
+ pMaxLogLevel = SUMMARY,
60
60
  pStream = process.stderr
61
61
  ) {
62
62
  const lState = {
@@ -1,5 +1,5 @@
1
1
  import { EOL } from "node:os";
2
- import busLogLevels from "../../utl/bus-log-levels.mjs";
2
+ import { INFO, SUMMARY } from "../../utl/bus.mjs";
3
3
 
4
4
  const MICRO_SECONDS_PER_SECOND = 1000000;
5
5
 
@@ -63,7 +63,7 @@ function getProgressLine(pMessage, pState, pLevel, pMaxLevel) {
63
63
 
64
64
  function getProgressWriter(pStream, pState, pMaxLevel) {
65
65
  return (pMessage, pOptions) => {
66
- const lOptions = { level: busLogLevels.SUMMARY, ...(pOptions || {}) };
66
+ const lOptions = { level: SUMMARY, ...(pOptions || {}) };
67
67
 
68
68
  pStream.write(getProgressLine(pMessage, pState, lOptions.level, pMaxLevel));
69
69
  };
@@ -71,12 +71,12 @@ function getProgressWriter(pStream, pState, pMaxLevel) {
71
71
 
72
72
  export default function setUpNDJSONListener(
73
73
  pEventEmitter,
74
- pMaxLevel = busLogLevels.INFO,
74
+ pMaxLevel = INFO,
75
75
  pStream = process.stderr
76
76
  ) {
77
77
  let lState = {
78
78
  runStartTime: new Date(Date.now()).toISOString(),
79
- previousMessage: "start of node process",
79
+ previousMessage: "starting nodejs",
80
80
  previousTime: 0,
81
81
  previousUserUsage: 0,
82
82
  previousSystemUsage: 0,
@@ -38,13 +38,13 @@ export function formatHeader() {
38
38
  return chalk
39
39
  .bold(
40
40
  `${
41
- pad("elapsed real") +
42
- pad("user") +
43
- pad("system") +
44
41
  pad("∆ rss") +
45
42
  pad("∆ heapTotal") +
46
43
  pad("∆ heapUsed") +
47
- pad("∆ external")
44
+ pad("∆ external") +
45
+ pad("⏱ system") +
46
+ pad("⏱ user") +
47
+ pad("⏱ real")
48
48
  }after step...\n`
49
49
  )
50
50
  .concat(formatDividerLine());
@@ -73,13 +73,13 @@ export function formatPerfLine({
73
73
  message,
74
74
  }) {
75
75
  return `${
76
- formatTime(elapsedTime) +
77
- formatTime(elapsedUser, MS_PER_MICRO_SECOND) +
78
- formatTime(elapsedSystem, MS_PER_MICRO_SECOND) +
79
76
  formatMemory(deltaRss) +
80
77
  formatMemory(deltaHeapTotal) +
81
78
  formatMemory(deltaHeapUsed) +
82
79
  formatMemory(deltaExternal) +
80
+ formatTime(elapsedSystem, MS_PER_MICRO_SECOND) +
81
+ formatTime(elapsedUser, MS_PER_MICRO_SECOND) +
82
+ formatTime(elapsedTime) +
83
83
  message
84
84
  }\n`;
85
85
  }
@@ -1,12 +1,9 @@
1
- import chalk from "chalk";
2
- import busLogLevels from "../../../utl/bus-log-levels.mjs";
1
+ import { INFO, SUMMARY } from "../../../utl/bus.mjs";
3
2
  import { getHeader, getProgressLine, getEndText } from "./handlers.mjs";
4
3
 
5
- let gUnderline = false;
6
-
7
4
  function getHeaderWriter(pStream, pMaxLevel) {
8
5
  return (_pMessage, pOptions) => {
9
- const lOptions = { level: busLogLevels.SUMMARY, ...(pOptions || {}) };
6
+ const lOptions = { level: SUMMARY, ...(pOptions || {}) };
10
7
 
11
8
  pStream.write(getHeader(lOptions.level, pMaxLevel));
12
9
  };
@@ -14,22 +11,19 @@ function getHeaderWriter(pStream, pMaxLevel) {
14
11
 
15
12
  function getProgressWriter(pStream, pState, pMaxLevel) {
16
13
  return (pMessage, pOptions) => {
17
- const lOptions = { level: busLogLevels.SUMMARY, ...(pOptions || {}) };
14
+ const lOptions = { level: SUMMARY, ...(pOptions || {}) };
18
15
  const lProgressLine = getProgressLine(
19
16
  pMessage,
20
17
  pState,
21
18
  lOptions.level,
22
19
  pMaxLevel
23
20
  );
24
- pStream.write(
25
- gUnderline ? `${chalk.underline(lProgressLine)}` : lProgressLine
26
- );
27
- gUnderline = !gUnderline;
21
+ pStream.write(lProgressLine);
28
22
  };
29
23
  }
30
24
 
31
25
  function getEndWriter(pStream, pState, pMaxLevel) {
32
- return (_pMessage, pLevel = busLogLevels.SUMMARY) => {
26
+ return (_pMessage, pLevel = SUMMARY) => {
33
27
  pStream.write(getEndText(pState, pLevel, pMaxLevel));
34
28
  pStream.end();
35
29
  };
@@ -37,11 +31,11 @@ function getEndWriter(pStream, pState, pMaxLevel) {
37
31
 
38
32
  export default function setUpPerformanceLogListener(
39
33
  pEventEmitter,
40
- pMaxLevel = busLogLevels.INFO,
34
+ pMaxLevel = INFO,
41
35
  pStream = process.stderr
42
36
  ) {
43
37
  let lState = {
44
- previousMessage: "start of node process",
38
+ previousMessage: "starting nodejs",
45
39
  previousTime: 0,
46
40
  previousUserUsage: 0,
47
41
  previousSystemUsage: 0,
@@ -1,5 +1,4 @@
1
- import bus from "../utl/bus.mjs";
2
- import busLogLevels from "../utl/bus-log-levels.mjs";
1
+ import { bus } from "../utl/bus.mjs";
3
2
  import addFocus from "../graph-utl/add-focus.mjs";
4
3
  import IndexedModuleGraph from "../graph-utl/indexed-module-graph.mjs";
5
4
  import deriveCycles from "./derive/circular.mjs";
@@ -11,31 +10,27 @@ import softenKnownViolations from "./soften-known-violations.mjs";
11
10
  import deriveModuleMetrics from "./derive/metrics/index.mjs";
12
11
 
13
12
  export default function enrichModules(pModules, pOptions) {
14
- bus.emit("progress", "analyzing: cycles", { level: busLogLevels.INFO });
13
+ bus.info("analyzing: cycles");
15
14
  const lIndexedModules = new IndexedModuleGraph(pModules);
16
15
  let lModules = deriveCycles(pModules, lIndexedModules, {
17
16
  pSourceAttribute: "source",
18
17
  pDependencyName: "resolved",
19
18
  });
20
- bus.emit("progress", "analyzing: dependents", { level: busLogLevels.INFO });
19
+ bus.info("analyzing: dependents");
21
20
  lModules = addDependents(lModules);
22
- bus.emit("progress", "analyzing: orphans", { level: busLogLevels.INFO });
21
+ bus.info("analyzing: orphans");
23
22
  lModules = deriveOrphans(lModules);
24
- bus.emit("progress", "analyzing: reachables", { level: busLogLevels.INFO });
23
+ bus.info("analyzing: reachables");
25
24
  lModules = deriveReachable(lModules, pOptions.ruleSet);
26
- bus.emit("progress", "analyzing: module metrics", {
27
- level: busLogLevels.INFO,
28
- });
25
+ bus.info("analyzing: module metrics");
29
26
  lModules = deriveModuleMetrics(lModules, pOptions);
30
- bus.emit("progress", "analyzing: add focus (if any)", {
31
- level: busLogLevels.INFO,
32
- });
27
+ bus.info("analyzing: add focus (if any)");
33
28
  lModules = addFocus(lModules, pOptions.focus);
34
29
 
35
30
  // when validate === false we might want to skip the addValidations.
36
31
  // We don't at this time, however, as "valid" is a mandatory
37
32
  // attribute (to simplify reporter logic)
38
- bus.emit("progress", "analyzing: validations", { level: busLogLevels.INFO });
33
+ bus.info("analyzing: validations");
39
34
  lModules = addValidations(lModules, pOptions.ruleSet, pOptions.validate);
40
35
 
41
36
  lModules = softenKnownViolations(lModules, pOptions.knownViolations);
@@ -1,5 +1,4 @@
1
- import bus from "../utl/bus.mjs";
2
- import busLogLevels from "../utl/bus-log-levels.mjs";
1
+ import { bus } from "../utl/bus.mjs";
3
2
  import isSameViolation from "./summarize/is-same-violation.mjs";
4
3
 
5
4
  function softenModuleViolation(
@@ -118,9 +117,7 @@ export default function softenKnownViolations(
118
117
  pSoftenedSeverity = "ignore"
119
118
  ) {
120
119
  if (Boolean(pKnownViolations)) {
121
- bus.emit("progress", "analyzing: comparing against known errors", {
122
- level: busLogLevels.INFO,
123
- });
120
+ bus.info("analyzing: comparing against known errors");
124
121
  return pModules.map((pModule) =>
125
122
  softenKnownViolation(pModule, pKnownViolations, pSoftenedSeverity)
126
123
  );
@@ -1,6 +1,5 @@
1
1
  import has from "lodash/has.js";
2
- import bus from "../utl/bus.mjs";
3
- import busLogLevels from "../utl/bus-log-levels.mjs";
2
+ import { bus } from "../utl/bus.mjs";
4
3
  import getDependencies from "./get-dependencies.mjs";
5
4
  import gatherInitialSources from "./gather-initial-sources.mjs";
6
5
  import clearCaches from "./clear-caches.mjs";
@@ -62,17 +61,13 @@ function extractFileDirectoryArray(
62
61
  ) {
63
62
  let lVisited = new Set();
64
63
 
65
- bus.emit("progress", "reading files: gathering initial sources", {
66
- level: busLogLevels.INFO,
67
- });
64
+ bus.info("reading files: gathering initial sources");
68
65
  const lInitialSources = gatherInitialSources(
69
66
  pFileDirectoryArray,
70
67
  pCruiseOptions
71
68
  );
72
69
 
73
- bus.emit("progress", "reading files: visiting dependencies", {
74
- level: busLogLevels.INFO,
75
- });
70
+ bus.info("reading files: visiting dependencies");
76
71
  return lInitialSources.reduce((pDependencies, pFilename) => {
77
72
  if (!lVisited.has(pFilename)) {
78
73
  lVisited.add(pFilename);
@@ -1,7 +1,6 @@
1
1
  /* eslint-disable no-return-await */
2
2
  /* eslint-disable no-magic-numbers */
3
-
4
- import bus from "../utl/bus.mjs";
3
+ import { bus } from "../utl/bus.mjs";
5
4
  import { validateCruiseOptions } from "./options/validate.mjs";
6
5
  import { normalizeCruiseOptions } from "./options/normalize.mjs";
7
6
  import reportWrap from "./report-wrap.mjs";
@@ -20,7 +19,7 @@ export default async function cruise(
20
19
  pResolveOptions,
21
20
  pTranspileOptions
22
21
  ) {
23
- bus.emit("progress", "parsing options", c(1));
22
+ bus.summary("parsing options", c(1));
24
23
  /** @type {import("../../types/strict-options.js").IStrictCruiseOptions} */
25
24
  let lCruiseOptions = normalizeCruiseOptions(
26
25
  validateCruiseOptions(pCruiseOptions),
@@ -29,23 +28,22 @@ export default async function cruise(
29
28
  let lCache = null;
30
29
 
31
30
  if (lCruiseOptions.cache) {
32
- bus.emit(
33
- "progress",
34
- `cache: check freshness with ${lCruiseOptions.cache.strategy}`,
31
+ bus.summary(
32
+ `cache: checking freshness with ${lCruiseOptions.cache.strategy}`,
35
33
  c(2)
36
34
  );
37
35
 
38
36
  const { default: Cache } = await import("../cache/cache.mjs");
39
37
  lCache = new Cache(lCruiseOptions.cache.strategy);
40
- const lCachedResults = lCache.read(lCruiseOptions.cache.folder);
38
+ const lCachedResults = await lCache.read(lCruiseOptions.cache.folder);
41
39
 
42
- if (lCache.canServeFromCache(lCruiseOptions, lCachedResults)) {
43
- bus.emit("progress", "cache: reporting from cache", c(8));
40
+ if (await lCache.canServeFromCache(lCruiseOptions, lCachedResults)) {
41
+ bus.summary("cache: reporting from cache", c(8));
44
42
  return await reportWrap(lCachedResults, lCruiseOptions);
45
43
  }
46
44
  }
47
45
 
48
- bus.emit("progress", "importing analytical modules", c(3));
46
+ bus.summary("importing analytical modules", c(3));
49
47
  const [
50
48
  { default: normalizeRuleSet },
51
49
  { default: validateRuleSet },
@@ -65,7 +63,7 @@ export default async function cruise(
65
63
  ]);
66
64
 
67
65
  if (Boolean(lCruiseOptions.ruleSet)) {
68
- bus.emit("progress", "parsing rule set", c(4));
66
+ bus.summary("parsing rule set", c(4));
69
67
  lCruiseOptions.ruleSet = normalizeRuleSet(
70
68
  validateRuleSet(lCruiseOptions.ruleSet)
71
69
  );
@@ -75,14 +73,14 @@ export default async function cruise(
75
73
  pFileAndDirectoryArray
76
74
  );
77
75
 
78
- bus.emit("progress", "determining how to resolve", c(5));
76
+ bus.summary("determining how to resolve", c(5));
79
77
  const lNormalizedResolveOptions = await normalizeResolveOptions(
80
78
  pResolveOptions,
81
79
  lCruiseOptions,
82
80
  pTranspileOptions?.tsConfig
83
81
  );
84
82
 
85
- bus.emit("progress", "reading files", c(6));
83
+ bus.summary("reading files", c(6));
86
84
  const lExtractionResult = extract(
87
85
  lNormalizedFileAndDirectoryArray,
88
86
  lCruiseOptions,
@@ -90,7 +88,7 @@ export default async function cruise(
90
88
  pTranspileOptions
91
89
  );
92
90
 
93
- bus.emit("progress", "analyzing", c(7));
91
+ bus.summary("analyzing", c(7));
94
92
  const lCruiseResult = enrich(
95
93
  lExtractionResult,
96
94
  lCruiseOptions,
@@ -98,10 +96,10 @@ export default async function cruise(
98
96
  );
99
97
 
100
98
  if (lCruiseOptions.cache) {
101
- bus.emit("progress", "cache: save", c(8));
102
- lCache.write(lCruiseOptions.cache.folder, lCruiseResult);
99
+ bus.summary("cache: saving", c(8));
100
+ await lCache.write(lCruiseOptions.cache.folder, lCruiseResult);
103
101
  }
104
102
 
105
- bus.emit("progress", "reporting", c(9));
103
+ bus.summary("reporting", c(9));
106
104
  return await reportWrap(lCruiseResult, lCruiseOptions);
107
105
  }
package/src/meta.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* generated - don't edit */
2
2
 
3
3
  module.exports = {
4
- version: "13.0.0-beta-5",
4
+ version: "13.0.0-beta-6",
5
5
  engines: {
6
6
  node: "^16.14||>=18",
7
7
  },
package/src/utl/bus.mjs CHANGED
@@ -1,5 +1,30 @@
1
+ /* eslint-disable import/exports-last */
1
2
  import EventEmitter from "node:events";
2
3
 
3
- const gBus = new EventEmitter();
4
+ export const OFF = -1;
5
+ export const SUMMARY = 40;
6
+ export const INFO = 50;
7
+ export const DEBUG = 60;
8
+ export const TRACE = 70;
9
+ export const EXTRA_STRONG = 80;
10
+ export const ALL = 99;
4
11
 
5
- export default gBus;
12
+ class Bus extends EventEmitter {
13
+ progress(pMessage, pOptions, ...pArguments) {
14
+ this.emit("progress", pMessage, pOptions, pArguments);
15
+ }
16
+
17
+ summary(pMessage, pOptions, ...pArguments) {
18
+ this.progress(pMessage, { ...pOptions, level: SUMMARY }, pArguments);
19
+ }
20
+
21
+ info(pMessage, pOptions, ...pArguments) {
22
+ this.progress(pMessage, { ...pOptions, level: INFO }, pArguments);
23
+ }
24
+
25
+ debug(pMessage, pOptions, ...pArguments) {
26
+ this.progress(pMessage, { ...pOptions, level: DEBUG }, pArguments);
27
+ }
28
+ }
29
+
30
+ export const bus = new Bus();
@@ -1,9 +0,0 @@
1
- export default {
2
- OFF: -1,
3
- SUMMARY: 40,
4
- INFO: 50,
5
- DEBUG: 60,
6
- TRACE: 70,
7
- EXTRA_STRONG: 80,
8
- ALL: 99,
9
- };