Skip to content

Commit e8fe39e

Browse files
committed
Inline isWindows check to getLocationAttr;
Remove `"@solid-primitives/platform"` dependency.
1 parent 0f2fe4e commit e8fe39e

File tree

5 files changed

+20
-48
lines changed

5 files changed

+20
-48
lines changed

.changeset/slick-glasses-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solid-devtools/debugger": patch
3+
---
4+
5+
Inline `isWindows` check to `getLocationAttr` and remove `"@solid-primitives/platform"` dependency.

packages/debugger/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"@solid-primitives/bounds": "^0.1.1",
5555
"@solid-primitives/event-listener": "^2.4.1",
5656
"@solid-primitives/keyboard": "^1.3.1",
57-
"@solid-primitives/platform": "^0.2.1",
5857
"@solid-primitives/rootless": "^1.5.1",
5958
"@solid-primitives/scheduled": "^1.5.1",
6059
"@solid-primitives/static-store": "^0.1.1",

packages/debugger/src/locator/index.test.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
1-
let mockIsWindows = true
1+
import * as v from 'vitest'
2+
import {parseLocationString} from './locator.ts'
23

3-
import {beforeEach, describe, expect, test, vi} from 'vitest'
4+
v.describe('locator attribute pasting', () => {
45

5-
vi.mock('@solid-primitives/platform', () => ({
6-
get isWindows() {
7-
return mockIsWindows
8-
},
9-
}))
10-
11-
const fetchFunction = async () => (await import('./locator.ts')).parseLocationString
12-
13-
describe('locator attribute pasting', () => {
14-
beforeEach(() => {
15-
vi.resetModules()
16-
})
17-
18-
test('windows', async () => {
19-
mockIsWindows = true
20-
const getLocationFromAttribute = await fetchFunction()
21-
22-
expect(getLocationFromAttribute(`Users\\user\\Desktop\\test\\test.tsx:1:0`)).toEqual({
6+
v.test('windows', () => {
7+
v.expect(parseLocationString(`Users\\user\\Desktop\\test\\test.tsx:1:0`)).toEqual({
238
file: 'Users\\user\\Desktop\\test\\test.tsx',
249
line: 1,
2510
column: 0,
2611
})
2712
})
2813

29-
test('unix', async () => {
30-
mockIsWindows = false
31-
const getLocationFromAttribute = await fetchFunction()
32-
33-
expect(getLocationFromAttribute(`/home/username/project/src/App.tsx:10:5`)).toEqual({
14+
v.test('unix', () => {
15+
v.expect(parseLocationString(`/home/username/project/src/App.tsx:10:5`)).toEqual({
3416
file: '/home/username/project/src/App.tsx',
3517
line: 10,
3618
column: 5,

packages/debugger/src/locator/locator.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type {KbdKey} from '@solid-primitives/keyboard'
2-
import {isWindows} from '@solid-primitives/platform'
32
import type {ToDyscriminatedUnion} from '@solid-devtools/shared/utils'
43
import {type NodeID, type SourceLocation} from '../main/types.ts'
54

@@ -14,13 +13,13 @@ export type LocatorOptions = {
1413
}
1514

1615
export type HighlightElementPayload = ToDyscriminatedUnion<{
17-
node: {id: NodeID}
16+
node: {id: NodeID}
1817
element: {id: NodeID}
1918
}> | null
2019

2120
// used by the transform
2221
export const WINDOW_PROJECTPATH_PROPERTY = '$sdt_projectPath'
23-
export const LOCATION_ATTRIBUTE_NAME = 'data-source-loc'
22+
export const LOCATION_ATTRIBUTE_NAME = 'data-source-loc'
2423

2524
export type LocationAttr = `${string}:${number}:${number}`
2625

@@ -32,16 +31,15 @@ export type SourceCodeData = SourceLocation & {
3231

3332
export type TargetURLFunction = (data: SourceCodeData) => string | void
3433

35-
const LOC_ATTR_REGEX_WIN = /^((?:\\?[^\s][^/\\:\"\?\*<>\|]+)+):([0-9]+):([0-9]+)$/
36-
const LOC_ATTR_REGEX_UNIX =
37-
/^((?:(?:\.\/|\.\.\/|\/)?(?:\.?\w+\/)*)(?:\.?\w+\.?\w+)):([0-9]+):([0-9]+)$/
38-
39-
export const LOC_ATTR_REGEX = isWindows ? LOC_ATTR_REGEX_WIN : LOC_ATTR_REGEX_UNIX
34+
const LOC_ATTR_REGEX_WIN = /^((?:\\?[^\s][^/\\:\"\?\*<>\|]+)+):([0-9]+):([0-9]+)$/
35+
const LOC_ATTR_REGEX_UNIX = /^((?:(?:\.\/|\.\.\/|\/)?(?:\.?\w+\/)*)(?:\.?\w+\.?\w+)):([0-9]+):([0-9]+)$/
4036

4137
export function getLocationAttr(element: Element): LocationAttr | null {
4238
let attr = element.getAttribute(LOCATION_ATTRIBUTE_NAME)
43-
if (!attr || !LOC_ATTR_REGEX.test(attr)) return null
44-
return attr as LocationAttr
39+
if (!attr) return null
40+
let is_windows = /(win32|win64|windows|wince)/i.test(navigator.userAgent)
41+
let regex = is_windows ? LOC_ATTR_REGEX_WIN : LOC_ATTR_REGEX_UNIX
42+
return regex.test(attr) ? attr as LocationAttr : null
4543
}
4644

4745
const targetIDEMap: Record<TargetIDE, (data: SourceCodeData) => string> = {

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)