• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

skmtc / skmtc / 27309662378

10 Jun 2026 10:11PM UTC coverage: 81.05% (-1.1%) from 82.119%
27309662378

push

github

web-flow
Merge pull request #1 from skmtc/spike/option2-base-param

Promote the development line to main: lang seam, GraphQL, lang-kotlin, CLI 0.5.1 (auth decommission + login/logout)

4608 of 5363 branches covered (85.92%)

Branch coverage included in aggregate %.

9793 of 13156 new or added lines in 247 files covered. (74.44%)

91 existing lines in 18 files now uncovered.

18446 of 23081 relevant lines covered (79.92%)

66.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/deno/lang-typescript/src/normalizeModuleName.ts
1
import type { ModulePackage } from '@skmtc/core'
2

3
/**
4
 * Arguments for the {@link normalizeModuleName} function.
5
 */
6
export type NormalizeModuleNameArgs = {
7
  /** The path of the file that will contain the import/export */
8
  destinationPath: string
9
  /** The original path being imported/exported from */
10
  exportPath: string
11
  /** Package configuration for path resolution */
12
  packages: ModulePackage[] | undefined
13
}
14

15
/**
16
 * Normalizes module import/export paths based on package configuration.
17
 *
18
 * This function handles path resolution for complex project structures with
19
 * multiple packages. It converts file system paths to appropriate module
20
 * names based on:
21
 * - Whether the destination and export paths are in the same package
22
 * - Package-specific module naming conventions
23
 * - Root path truncation for intra-package imports
24
 *
25
 * @throws {Error} When a matching package is found but has no moduleName configured
26
 *
27
 * @example Cross-package import
28
 * ```typescript
29
 * const normalized = normalizeModuleName({
30
 *   destinationPath: './packages/client/src/api.ts',
31
 *   exportPath: './packages/types/models/User.ts',
32
 *   packages: [
33
 *     { rootPath: './packages/types', moduleName: '@company/types' },
34
 *     { rootPath: './packages/client', moduleName: '@company/client' }
35
 *   ]
36
 * });
37
 * console.log(normalized); // '@company/types'
38
 * ```
39
 *
40
 * @example Intra-package import (same package)
41
 * ```typescript
42
 * const normalized = normalizeModuleName({
43
 *   destinationPath: './packages/types/src/index.ts',
44
 *   exportPath: './packages/types/models/User.ts',
45
 *   packages: [
46
 *     { rootPath: './packages/types', moduleName: '@company/types' }
47
 *   ]
48
 * });
49
 * console.log(normalized); // '@/models/User.ts' (truncates root path)
50
 * ```
51
 *
52
 * @example No package match (returns original path)
53
 * ```typescript
54
 * const normalized = normalizeModuleName({
55
 *   destinationPath: './src/index.ts',
56
 *   exportPath: './src/utils.ts',
57
 *   packages: []
58
 * });
59
 * console.log(normalized); // './src/utils.ts'
60
 * ```
61
 */
62
export const normalizeModuleName = ({
23✔
63
  destinationPath,
23✔
64
  exportPath,
23✔
65
  packages = []
23✔
66
}: NormalizeModuleNameArgs): string => {
23✔
67
  const matchingModule = packages.find(packageModule => {
5✔
68
    return exportPath.startsWith(packageModule.rootPath)
1✔
69
  })
5✔
70

71
  if (!matchingModule) {
5✔
72
    return exportPath
4✔
73
  }
4✔
74

75
  const { rootPath, moduleName } = matchingModule
1✔
76

77
  // When importing from within same package, truncate the root path and denote root with '@'
NEW
78
  if (destinationPath.startsWith(rootPath)) {
×
NEW
79
    return exportPath.replace(rootPath, '@')
×
NEW
80
  }
✔
81

NEW
82
  if (!moduleName) {
×
NEW
83
    throw new Error(`Module name is not set for ${rootPath}`)
×
NEW
84
  }
✔
85

86
  return moduleName
1✔
87
}
23✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc