File tree 3 files changed +48
-2
lines changed
test/integration/create-next-app
3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import { install } from './helpers/install'
19
19
import { isFolderEmpty } from './helpers/is-folder-empty'
20
20
import { getOnline } from './helpers/is-online'
21
21
import { shouldUseYarn } from './helpers/should-use-yarn'
22
+ import { isWriteable } from './helpers/is-writeable'
22
23
23
24
export class DownloadError extends Error { }
24
25
@@ -93,6 +94,17 @@ export async function createApp({
93
94
}
94
95
95
96
const root = path . resolve ( appPath )
97
+
98
+ if ( ! ( await isWriteable ( path . dirname ( root ) ) ) ) {
99
+ console . error (
100
+ 'The application path is not writable, please check folder permissions and try again.'
101
+ )
102
+ console . error (
103
+ 'It is likely you do not have write permissions for this folder.'
104
+ )
105
+ process . exit ( 1 )
106
+ }
107
+
96
108
const appName = path . basename ( root )
97
109
98
110
await makeDir ( root )
Original file line number Diff line number Diff line change
1
+ import fs from 'fs'
2
+
3
+ export async function isWriteable ( directory : string ) : Promise < boolean > {
4
+ try {
5
+ await fs . promises . access ( directory , ( fs . constants || fs ) . W_OK )
6
+ return true
7
+ } catch ( err ) {
8
+ return false
9
+ }
10
+ }
Original file line number Diff line number Diff line change @@ -23,9 +23,9 @@ const runStarter = (cwd, ...args) => {
23
23
return res
24
24
}
25
25
26
- async function usingTempDir ( fn ) {
26
+ async function usingTempDir ( fn , options ) {
27
27
const folder = path . join ( os . tmpdir ( ) , Math . random ( ) . toString ( 36 ) . substring ( 2 ) )
28
- await fs . mkdirp ( folder )
28
+ await fs . mkdirp ( folder , options )
29
29
try {
30
30
return await fn ( folder )
31
31
} finally {
@@ -251,4 +251,28 @@ describe('create next app', () => {
251
251
}
252
252
} )
253
253
} )
254
+
255
+ it ( 'should exit if the folder is not writable' , async ( ) => {
256
+ await usingTempDir ( async ( cwd ) => {
257
+ const projectName = 'not-writable'
258
+ expect . assertions ( 2 )
259
+ try {
260
+ const res = await runStarter ( cwd , projectName )
261
+
262
+ if ( process . platform === 'win32' ) {
263
+ expect ( res . exitCode ) . toBe ( 0 )
264
+ expect (
265
+ fs . existsSync ( path . join ( cwd , projectName , 'package.json' ) )
266
+ ) . toBeTruthy ( )
267
+ }
268
+ } catch ( e ) {
269
+ // eslint-disable-next-line jest/no-try-expect
270
+ expect ( e . exitCode ) . toBe ( 1 )
271
+ // eslint-disable-next-line jest/no-try-expect
272
+ expect ( e . stderr ) . toMatch (
273
+ / y o u d o n o t h a v e w r i t e p e r m i s s i o n s f o r t h i s f o l d e r /
274
+ )
275
+ }
276
+ } , 0o500 )
277
+ } )
254
278
} )
You can’t perform that action at this time.
0 commit comments