Skip to content

Commit b5d42ca

Browse files
author
Jason Kuhrt
authored
fix: glocal check stops at windows disk root (#1119)
1 parent d963813 commit b5d42ca

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

.github/workflows/pr.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ jobs:
1818
node-version: ${{ matrix.node-version }}
1919
- run: yarn --frozen-lockfile
2020
- run: yarn -s build
21-
- run: yarn -s test runtime/app runtime/schema/settings lib/build runtime/schema/index lib/nexus-schema-backing-types lib/graphql-client runtime/server runtime/schema/settings-mapper lib/plugin lib/add-to-context-extractor
21+
- run: yarn -s test runtime/app runtime/schema/settings lib/build runtime/schema/index lib/nexus-schema-backing-types lib/graphql-client runtime/server runtime/schema/settings-mapper lib/plugin lib/add-to-context-extractor lib/glocal
2222
# todo
2323
# lib/layout
24-
# lib/glocal
2524
# lib/watcher
26-
2725
unit-tests:
2826
runs-on: ubuntu-latest
2927
strategy:
@@ -38,7 +36,6 @@ jobs:
3836
- run: yarn --frozen-lockfile
3937
- run: yarn -s build
4038
- run: yarn -s test:unit
41-
4239
system-tests:
4340
runs-on: ubuntu-latest
4441
strategy:
@@ -56,7 +53,7 @@ jobs:
5653
- run: yarn -s build
5754
- name: Setup global git user
5855
run: |
59-
# For nexus create app flow which will make an init commit
56+
# For nexus create app flow which will make an init commit
6057
git config --global user.name prisma-labs
6158
git config --global user.email [email protected]
6259
- run: yarn -s test system/${{matrix.test-case}}

.github/workflows/trunk.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ jobs:
1818
node-version: ${{ matrix.node-version }}
1919
- run: yarn --frozen-lockfile
2020
- run: yarn -s build
21-
- run: yarn -s test runtime/app runtime/schema/settings lib/build runtime/schema/index lib/nexus-schema-backing-types lib/graphql-client runtime/server runtime/schema/settings-mapper lib/plugin lib/add-to-context-extractor
21+
- run: yarn -s test runtime/app runtime/schema/settings lib/build runtime/schema/index lib/nexus-schema-backing-types lib/graphql-client runtime/server runtime/schema/settings-mapper lib/plugin lib/add-to-context-extractor lib/glocal
2222
# todo
2323
# lib/layout
24-
# lib/glocal
2524
# lib/watcher
2625

2726
unit-tests:

src/lib/fs.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function findFileRecurisvelyUpwardSync(
6969
break
7070
}
7171

72-
if (currentDir === '/') {
72+
if (isRootPath(currentDir)) {
7373
break
7474
}
7575

@@ -232,3 +232,23 @@ export async function isEmptyDir(dirPath: string): Promise<boolean> {
232232
const contents = await FS.listAsync(dirPath)
233233
return contents === undefined || contents.length === 0
234234
}
235+
236+
// https://github.com/iojs/io.js/blob/5883a59b21a97e8b7339f435c977155a2c29ba8d/lib/path.js#L43
237+
const windowsPathRegex = /^(?:[a-zA-Z]:|[\\/]{2}[^\\/]+[\\/]+[^\\/]+)?[\\/]$/
238+
239+
/**
240+
* Ask whether the given path is a root path or not.
241+
*
242+
* @remarks
243+
*
244+
* Take from https://github.com/sindresorhus/is-root-path/blob/master/index.js
245+
*/
246+
export function isRootPath(path: string) {
247+
path = path.trim()
248+
249+
if (path === '') {
250+
return false
251+
}
252+
253+
return process.platform === 'win32' ? windowsPathRegex.test(path) : path === '/'
254+
}

src/lib/glocal/detect-exec-layout.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import * as path from 'path'
22
import * as TestContext from '../test-context'
3-
import { Param1, repalceInObject } from '../utils'
3+
import { normalizePathsInData, Param1 } from '../utils'
44
import { detectExecLayout } from './detect-exec-layout'
55

66
const ctx = TestContext.compose(TestContext.tmpDir(), TestContext.fs(), (ctx) => {
77
return {
88
detectExecLayout: (input?: Partial<Param1<typeof detectExecLayout>>) => {
9-
return repalceInObject(
10-
ctx.tmpDir,
11-
'/__dynamic__',
9+
return normalizePathsInData(
1210
detectExecLayout({
1311
depName: 'a',
1412
cwd: ctx.tmpDir,
1513
scriptPath: ctx.fs.path('some/other/bin/a'),
1614
...input,
17-
})
15+
}),
16+
ctx.tmpDir,
17+
'/__dynamic__'
1818
)
1919
},
2020
}
@@ -54,7 +54,6 @@ describe('node project detection', () => {
5454
})
5555
})
5656
it('if package.json not present then is not a node project', () => {
57-
expect(ctx.detectExecLayout().nodeProject).toEqual(false)
5857
expect(ctx.detectExecLayout()).toMatchObject({
5958
nodeProject: false,
6059
toolProject: false,

src/lib/glocal/detect-exec-layout.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ export function detectExecLayout(input: Input): ExecScenario {
124124

125125
let isToolProject = null
126126
try {
127+
// todo test that not using Path.posix will break on windows
127128
isToolProject =
128-
typeof require(Path.join(projectDir, 'package.json'))?.dependencies?.[input.depName] === 'string'
129+
typeof require(Path.posix.join(projectDir, 'package.json'))?.dependencies?.[input.depName] === 'string'
129130
} catch (e) {
130131
console.log(e)
131132
}

0 commit comments

Comments
 (0)