Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
πŸ› Go back to fs-extra for symlinks
Browse files Browse the repository at this point in the history
Windows doesn't like nodejs's defualt symlink implementation
  • Loading branch information
trickypr committed Dec 5, 2021
1 parent 4f5885f commit b6dca82
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 29 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"cli-progress": "^3.9.1",
"commander": "^6.2.1",
"execa": "^5.1.1",
"fs-extra": "^10.0.0",
"glob": "^7.1.7",
"linus": "^0.0.6",
"listr": "^0.14.3",
Expand All @@ -50,6 +51,7 @@
},
"devDependencies": {
"@types/cli-progress": "^3.9.2",
"@types/fs-extra": "^9.0.13",
"@types/listr": "^0.14.4",
"@types/node": "^14.14.16",
"@types/prompts": "^2.0.14",
Expand Down
50 changes: 22 additions & 28 deletions src/utils/import.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { existsSync } from 'fs'
import { lstatSync, readFileSync } from 'fs'
import { ensureSymlink } from 'fs-extra'
import { resolve } from 'path'
import rimraf from 'rimraf'
import { appendToFileSync, createSymlink } from '.'
import { appendToFileSync } from '.'
import { ENGINE_DIR, SRC_DIR } from '../constants'

const getChunked = (location: string) => location.replace(/\\/g, '/').split('/')
Expand All @@ -11,35 +12,28 @@ export const copyManual = async (
name: string,
noIgnore?: boolean
): Promise<void> => {
try {
// If the file exists and is not a symlink, we want to replace it with a
// symlink to our file, so remove it
if (
existsSync(resolve(ENGINE_DIR, ...getChunked(name))) &&
!lstatSync(resolve(ENGINE_DIR, ...getChunked(name))).isSymbolicLink()
) {
rimraf.sync(resolve(ENGINE_DIR, ...getChunked(name)))
}

// Create the symlink
await createSymlink(
resolve(SRC_DIR, ...getChunked(name)),
resolve(ENGINE_DIR, ...getChunked(name))
)
// If the file exists and is not a symlink, we want to replace it with a
// symlink to our file, so remove it
if (
existsSync(resolve(ENGINE_DIR, ...getChunked(name))) &&
!lstatSync(resolve(ENGINE_DIR, ...getChunked(name))).isSymbolicLink()
) {
rimraf.sync(resolve(ENGINE_DIR, ...getChunked(name)))
}

if (!noIgnore) {
const gitignore = readFileSync(resolve(ENGINE_DIR, '.gitignore'), 'utf-8')
// Create the symlink
await ensureSymlink(
resolve(SRC_DIR, ...getChunked(name)),
resolve(ENGINE_DIR, ...getChunked(name))
)

if (!gitignore.includes(getChunked(name).join('/')))
appendToFileSync(
resolve(ENGINE_DIR, '.gitignore'),
`\n${getChunked(name).join('/')}`
)
}
if (!noIgnore) {
const gitignore = readFileSync(resolve(ENGINE_DIR, '.gitignore'), 'utf-8')

return
} catch (e) {
console.log(e)
process.exit(0)
if (!gitignore.includes(getChunked(name).join('/')))
appendToFileSync(
resolve(ENGINE_DIR, '.gitignore'),
`\n${getChunked(name).join('/')}`
)
}
}
32 changes: 31 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@
dependencies:
"@types/node" "*"

"@types/fs-extra@^9.0.13":
version "9.0.13"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.13.tgz#7594fbae04fe7f1918ce8b3d213f74ff44ac1f45"
integrity sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==
dependencies:
"@types/node" "*"

"@types/glob@*":
version "7.1.4"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.4.tgz#ea59e21d2ee5c517914cb4bc8e4153b99e566672"
Expand Down Expand Up @@ -1162,6 +1169,15 @@ fs-constants@^1.0.0:
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==

fs-extra@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -1261,7 +1277,7 @@ globby@^11.0.3:
merge2 "^1.3.0"
slash "^3.0.0"

graceful-fs@^4.1.2:
graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.8"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
integrity sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==
Expand Down Expand Up @@ -1578,6 +1594,15 @@ json5@^1.0.1:
dependencies:
minimist "^1.2.0"

jsonfile@^6.0.1:
version "6.1.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
dependencies:
universalify "^2.0.0"
optionalDependencies:
graceful-fs "^4.1.6"

"jsx-ast-utils@^2.4.1 || ^3.0.0", jsx-ast-utils@^3.1.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-3.2.1.tgz#720b97bfe7d901b927d87c3773637ae8ea48781b"
Expand Down Expand Up @@ -2660,6 +2685,11 @@ unbox-primitive@^1.0.1:
has-symbols "^1.0.2"
which-boxed-primitive "^1.0.2"

universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==

uri-js@^4.2.2:
version "4.4.1"
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e"
Expand Down

0 comments on commit b6dca82

Please sign in to comment.