Skip to content

Commit 2f01acf

Browse files
authored
Remove slash dependency and copy inline (#1120)
1 parent 2409437 commit 2f01acf

6 files changed

Lines changed: 44 additions & 6 deletions

File tree

.changeset/ripe-carrots-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@react-docgen/cli': patch
3+
---
4+
5+
Remove slash dependency

packages/react-docgen-cli/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
"commander": "15.0.0",
3939
"debug": "4.4.3",
4040
"fast-glob": "3.3.3",
41-
"react-docgen": "workspace:8.0.3",
42-
"slash": "5.1.0"
41+
"react-docgen": "workspace:8.0.3"
4342
},
4443
"devDependencies": {
4544
"@types/debug": "4.1.13"

packages/react-docgen-cli/src/commands/parse/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import outputResult from './output/outputResult.js';
88
import loadOptions from './options/loadOptions.js';
99
import outputError from './output/outputError.js';
1010
import { resolve } from 'path';
11-
import slash from 'slash';
11+
import slash from '../../utils/slash.js';
1212
import type { Documentation } from 'react-docgen';
1313
import { ResolverConfigs } from './options/loadResolvers.js';
1414

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Based on npm slash package: https://www.npmjs.com/package/slash
3+
Licensed under MIT License
4+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
5+
*/
6+
7+
import { describe, expect, test } from 'vitest';
8+
import slash from '../slash';
9+
10+
describe('slash', () => {
11+
test('convert backwards-slash paths to forward slash paths', () => {
12+
expect(slash('c:/aaaa\\bbbb')).toBe('c:/aaaa/bbbb');
13+
expect(slash('c:\\aaaa\\bbbb')).toBe('c:/aaaa/bbbb');
14+
expect(slash('c:\\aaaa\\bbbb\\★')).toBe('c:/aaaa/bbbb/★');
15+
});
16+
17+
test('not convert extended-length paths', () => {
18+
const path = '\\\\?\\c:\\aaaa\\bbbb';
19+
20+
expect(slash(path)).toBe(path);
21+
});
22+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Based on npm slash package: https://www.npmjs.com/package/slash
3+
Licensed under MIT License
4+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
5+
*/
6+
7+
export default function slash(path: string): string {
8+
const isExtendedLengthPath = path.startsWith('\\\\?\\');
9+
10+
if (isExtendedLengthPath) {
11+
return path;
12+
}
13+
14+
return path.replace(/\\/g, '/');
15+
}

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)