Commit 82ed47e

Anton Medvedev <anton@medv.io>
2022-07-01 21:35:36
Add circular dependencies check
1 parent 700bd4c
Changed files (4)
.github/workflows/check.yml
@@ -34,3 +34,10 @@ jobs:
       - run: npm i
       - run: npm run build
       - run: npm run test:types
+
+  circular:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+      - run: npm i
+      - run: npm run circular
src/core.ts
@@ -12,18 +12,19 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import { ChalkInstance } from 'chalk'
 import assert from 'node:assert'
-import { AsyncLocalStorage, createHook } from 'node:async_hooks'
 import { ChildProcess, spawn, StdioNull, StdioPipe } from 'node:child_process'
+import { AsyncLocalStorage, createHook } from 'node:async_hooks'
 import { Readable, Writable } from 'node:stream'
 import { inspect } from 'node:util'
-import { chalk, which } from './goods.js'
-import { log } from './log.js'
+import { RequestInfo, RequestInit } from 'node-fetch'
+import chalk, { ChalkInstance } from 'chalk'
+import * as which from 'which'
 import {
   Duration,
   errnoMessage,
   exitCodeInfo,
+  formatCmd,
   noop,
   parseDuration,
   psTree,
@@ -395,3 +396,60 @@ export function cd(dir: string) {
   process.chdir(dir)
   $[processCwd] = process.cwd()
 }
+
+export type LogEntry =
+  | {
+  kind: 'cmd'
+  verbose: boolean
+  cmd: string
+}
+  | {
+  kind: 'stdout' | 'stderr'
+  verbose: boolean
+  data: Buffer
+}
+  | {
+  kind: 'cd'
+  dir: string
+}
+  | {
+  kind: 'fetch'
+  url: RequestInfo
+  init?: RequestInit
+}
+  | {
+  kind: 'retry'
+  error: string
+}
+  | {
+  kind: 'custom'
+  data: any
+}
+
+export function log(entry: LogEntry) {
+  switch (entry.kind) {
+    case 'cmd':
+      if (!entry.verbose) return
+      process.stderr.write(formatCmd(entry.cmd))
+      break
+    case 'stdout':
+    case 'stderr':
+      if (!entry.verbose) return
+      process.stderr.write(entry.data)
+      break
+    case 'cd':
+      if (!$.verbose) return
+      process.stderr.write('$ ' + chalk.greenBright('cd') + ` ${entry.dir}\n`)
+      break
+    case 'fetch':
+      if (!$.verbose) return
+      const init = entry.init ? ' ' + inspect(entry.init) : ''
+      process.stderr.write(
+        '$ ' + chalk.greenBright('fetch') + ` ${entry.url}${init}\n`
+      )
+      break
+    case 'retry':
+      if (!$.verbose) return
+      process.stderr.write(entry.error + '\n')
+  }
+}
src/log.ts
@@ -1,76 +0,0 @@
-// Copyright 2022 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-import chalk from 'chalk'
-import { RequestInfo, RequestInit } from 'node-fetch'
-import { inspect } from 'node:util'
-import { $ } from './core.js'
-import { formatCmd } from './util.js'
-
-export type LogEntry =
-  | {
-      kind: 'cmd'
-      verbose: boolean
-      cmd: string
-    }
-  | {
-      kind: 'stdout' | 'stderr'
-      verbose: boolean
-      data: Buffer
-    }
-  | {
-      kind: 'cd'
-      dir: string
-    }
-  | {
-      kind: 'fetch'
-      url: RequestInfo
-      init?: RequestInit
-    }
-  | {
-      kind: 'retry'
-      error: string
-    }
-  | {
-      kind: 'custom'
-      data: any
-    }
-
-export function log(entry: LogEntry) {
-  switch (entry.kind) {
-    case 'cmd':
-      if (!entry.verbose) return
-      process.stderr.write(formatCmd(entry.cmd))
-      break
-    case 'stdout':
-    case 'stderr':
-      if (!entry.verbose) return
-      process.stderr.write(entry.data)
-      break
-    case 'cd':
-      if (!$.verbose) return
-      process.stderr.write('$ ' + chalk.greenBright('cd') + ` ${entry.dir}\n`)
-      break
-    case 'fetch':
-      if (!$.verbose) return
-      const init = entry.init ? ' ' + inspect(entry.init) : ''
-      process.stderr.write(
-        '$ ' + chalk.greenBright('fetch') + ` ${entry.url}${init}\n`
-      )
-      break
-    case 'retry':
-      if (!$.verbose) return
-      process.stderr.write(entry.error + '\n')
-  }
-}
package.json
@@ -46,7 +46,8 @@
     "test": "npm run build && PATH=$(env -i bash -c 'echo $PATH') node_modules/.bin/uvu test -i fixtures",
     "test:types": "tsd",
     "coverage": "c8 --check-coverage npm test -- -i package",
-    "mutation": "stryker run"
+    "mutation": "stryker run",
+    "circular": "madge --circular src/*"
   },
   "dependencies": {
     "@types/fs-extra": "^9.0.13",
@@ -66,6 +67,7 @@
   "devDependencies": {
     "@stryker-mutator/core": "^6.0.2",
     "c8": "^7.11.3",
+    "madge": "^5.0.1",
     "prettier": "^2.7.0",
     "tsd": "^0.21.0",
     "typescript": "^4.8.0-dev.20220529",