|
1 | 1 | import fs from 'fs'; |
2 | 2 | import { TargetWorld } from '../lib/wit_tools.js'; |
3 | 3 | import path from 'path'; |
| 4 | +import { resolve } from 'node:path'; |
| 5 | +import { platform } from 'node:process'; |
| 6 | +const isWindows = platform === 'win32'; |
| 7 | + |
| 8 | +function maybeWindowsPath(path: string): string { |
| 9 | + if (!path) return path; |
| 10 | + const resolvedPath = resolve(path); |
| 11 | + if (!isWindows) return resolvedPath; |
| 12 | + |
| 13 | + // Strip any existing UNC prefix check both the format we add as well as what |
| 14 | + // the windows API returns when using path.resolve |
| 15 | + let cleanPath = resolvedPath; |
| 16 | + while (cleanPath.startsWith('\\\\?\\') || cleanPath.startsWith('//?/')) { |
| 17 | + cleanPath = cleanPath.substring(4); |
| 18 | + } |
| 19 | + |
| 20 | + return '//?/' + cleanPath.replace(/\\/g, '/'); |
| 21 | +} |
4 | 22 |
|
5 | 23 | // Define the structure of a package.json file |
6 | 24 | // Includes dependencies and an optional config section for 'knitwit' |
@@ -62,7 +80,7 @@ function absolutizeWitPath( |
62 | 80 | if (depPackageJson.config?.witDependencies) { |
63 | 81 | depPackageJson.config.witDependencies.forEach(witDep => { |
64 | 82 | if (!path.isAbsolute(witDep.witPath)) { |
65 | | - witDep.witPath = path.resolve(depPackageJsonPath, witDep.witPath); |
| 83 | + witDep.witPath = maybeWindowsPath(path.resolve(depPackageJsonPath, witDep.witPath)); |
66 | 84 | } |
67 | 85 | }); |
68 | 86 | } |
|
0 commit comments