Skip to content

Commit

Permalink
use copy instead of rename if temp directory is on a different device
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanwood committed Jul 27, 2023
1 parent b1a3830 commit 7a9a180
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
20 changes: 18 additions & 2 deletions create-project.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { randomUUID } from 'crypto';
import { createWriteStream, existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'fs'
import fsExtra from 'fs-extra'
import { createRequire } from 'module'
import { tmpdir } from 'os'
import { isAbsolute, join, resolve } from 'path'
import { isAbsolute, join, resolve, parse } from 'path'
import https from 'https'
import tiny from 'tiny-json-http'
import tar from 'tar'

const { copySync } = fsExtra;

const require = createRequire(import.meta.url)

export async function createProject ({ dest, path, name }) {
Expand Down Expand Up @@ -43,8 +46,21 @@ export async function createProject ({ dest, path, name }) {

// Extract starter project
tar.x({ C: temp, file: starterProjectArchive, sync: true })

// Move starter project to final destination
renameSync(join(temp, 'package'), projectDir)

// Check if the temp and projectDir are on the same file system
const tempRoot = parse(temp).root;
const projectRoot = parse(projectDir).root;
const isSameFileSystemRoot = tempRoot === projectRoot;

if (!isSameFileSystemRoot) {
// if not, we need to copy the files instead of moving them
copySync(join(temp, 'package'), projectDir)
} else {
renameSync(join(temp, 'package'), projectDir)
}

// Clean up download
unlinkSync(starterProjectArchive)

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"tape": "^5.6.3"
},
"dependencies": {
"fs-extra": "^11.1.1",
"tar": "^6.1.14",
"tiny-json-http": "^7.5.1"
},
Expand Down

0 comments on commit 7a9a180

Please sign in to comment.