Skip to content

Commit 39a7db2

Browse files
committed
refactor: use upath instead of path || path.posix
because the latter does not pass treeshakeability test
1 parent 98c4689 commit 39a7db2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+390
-259
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
"pify": "^4.0.1",
6262
"readable-stream": "^3.4.0",
6363
"sha.js": "^2.4.9",
64-
"simple-get": "^4.0.1"
64+
"simple-get": "^4.0.1",
65+
"upath": "^2.0.1"
6566
},
6667
"devDependencies": {
6768
"@babel/core": "7.6.0",

src/api/abortMerge.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// @ts-check
22
import '../typedefs.js'
33

4+
import { joinSafe } from 'upath'
5+
46
import { STAGE } from '../commands/STAGE.js'
57
import { TREE } from '../commands/TREE.js'
68
import { WORKDIR } from '../commands/WORKDIR.js'
@@ -10,7 +12,6 @@ import { GitIndexManager } from '../managers/GitIndexManager.js'
1012
import { FileSystem } from '../models/FileSystem.js'
1113
import { assertParameter } from '../utils/assertParameter.js'
1214
import { modified } from '../utils/modified.js'
13-
import { join } from '../utils/path.js'
1415

1516
/**
1617
* Abort a merge in progress.
@@ -29,7 +30,7 @@ import { join } from '../utils/path.js'
2930
* @param {object} args
3031
* @param {FsClient} args.fs - a file system implementation
3132
* @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path
32-
* @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
33+
* @param {string} [args.gitdir=joinSafe(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
3334
* @param {string} [args.commit='HEAD'] - commit to reset the index and worktree to, defaults to HEAD
3435
* @param {object} [args.cache] - a [cache](cache.md) object
3536
*
@@ -39,7 +40,7 @@ import { join } from '../utils/path.js'
3940
export async function abortMerge({
4041
fs: _fs,
4142
dir,
42-
gitdir = join(dir, '.git'),
43+
gitdir = joinSafe(dir, '.git'),
4344
commit = 'HEAD',
4445
cache = {},
4546
}) {

src/api/add.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// @ts-check
22
import '../typedefs.js'
33

4+
import { joinSafe } from 'upath'
5+
46
import { MultipleGitError } from '../errors/MultipleGitError'
57
import { NotFoundError } from '../errors/NotFoundError.js'
68
import { GitIgnoreManager } from '../managers/GitIgnoreManager.js'
79
import { GitIndexManager } from '../managers/GitIndexManager.js'
810
import { FileSystem } from '../models/FileSystem.js'
911
import { _writeObject } from '../storage/writeObject.js'
1012
import { assertParameter } from '../utils/assertParameter.js'
11-
import { join } from '../utils/path.js'
1213
import { posixifyPathBuffer } from '../utils/posixifyPathBuffer.js'
1314

1415
/**
@@ -17,7 +18,7 @@ import { posixifyPathBuffer } from '../utils/posixifyPathBuffer.js'
1718
* @param {object} args
1819
* @param {FsClient} args.fs - a file system implementation
1920
* @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path
20-
* @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
21+
* @param {string} [args.gitdir=joinSafe(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
2122
* @param {string|string[]} args.filepath - The path to the file to add to the index
2223
* @param {object} [args.cache] - a [cache](cache.md) object
2324
* @param {boolean} [args.force=false] - add to index even if matches gitignore. Think `git add --force`
@@ -34,7 +35,7 @@ import { posixifyPathBuffer } from '../utils/posixifyPathBuffer.js'
3435
export async function add({
3536
fs: _fs,
3637
dir,
37-
gitdir = join(dir, '.git'),
38+
gitdir = joinSafe(dir, '.git'),
3839
filepath,
3940
cache = {},
4041
force = false,
@@ -85,18 +86,18 @@ async function addToIndex({
8586
})
8687
if (ignored) return
8788
}
88-
const stats = await fs.lstat(join(dir, currentFilepath))
89+
const stats = await fs.lstat(joinSafe(dir, currentFilepath))
8990
if (!stats) throw new NotFoundError(currentFilepath)
9091

9192
if (stats.isDirectory()) {
92-
const children = await fs.readdir(join(dir, currentFilepath))
93+
const children = await fs.readdir(joinSafe(dir, currentFilepath))
9394
if (parallel) {
9495
const promises = children.map(child =>
9596
addToIndex({
9697
dir,
9798
gitdir,
9899
fs,
99-
filepath: [join(currentFilepath, child)],
100+
filepath: [joinSafe(currentFilepath, child)],
100101
index,
101102
force,
102103
parallel,
@@ -109,7 +110,7 @@ async function addToIndex({
109110
dir,
110111
gitdir,
111112
fs,
112-
filepath: [join(currentFilepath, child)],
113+
filepath: [joinSafe(currentFilepath, child)],
113114
index,
114115
force,
115116
parallel,
@@ -118,8 +119,10 @@ async function addToIndex({
118119
}
119120
} else {
120121
const object = stats.isSymbolicLink()
121-
? await fs.readlink(join(dir, currentFilepath)).then(posixifyPathBuffer)
122-
: await fs.read(join(dir, currentFilepath))
122+
? await fs
123+
.readlink(joinSafe(dir, currentFilepath))
124+
.then(posixifyPathBuffer)
125+
: await fs.read(joinSafe(dir, currentFilepath))
123126
if (object === null) throw new NotFoundError(currentFilepath)
124127
const oid = await _writeObject({ fs, gitdir, type: 'blob', object })
125128
index.insert({ filepath: currentFilepath, stats, oid })

src/api/addNote.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// @ts-check
22
import '../typedefs.js'
33

4+
import { joinSafe } from 'upath'
5+
46
import { _addNote } from '../commands/addNote.js'
57
import { MissingNameError } from '../errors/MissingNameError.js'
68
import { FileSystem } from '../models/FileSystem.js'
79
import { assertParameter } from '../utils/assertParameter.js'
810
import { normalizeAuthorObject } from '../utils/normalizeAuthorObject.js'
911
import { normalizeCommitterObject } from '../utils/normalizeCommitterObject.js'
10-
import { join } from '../utils/path.js'
1112

1213
/**
1314
* Add or update an object note
@@ -16,7 +17,7 @@ import { join } from '../utils/path.js'
1617
* @param {FsClient} args.fs - a file system implementation
1718
* @param {SignCallback} [args.onSign] - a PGP signing implementation
1819
* @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
19-
* @param {string} [args.gitdir=join(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
20+
* @param {string} [args.gitdir=joinSafe(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
2021
* @param {string} [args.ref] - The notes ref to look under
2122
* @param {string} args.oid - The SHA-1 object id of the object to add the note to.
2223
* @param {string|Uint8Array} args.note - The note to add
@@ -41,7 +42,7 @@ export async function addNote({
4142
fs: _fs,
4243
onSign,
4344
dir,
44-
gitdir = join(dir, '.git'),
45+
gitdir = joinSafe(dir, '.git'),
4546
ref = 'refs/notes/commits',
4647
oid,
4748
note,

src/api/addRemote.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// @ts-check
22
import '../typedefs.js'
33

4+
import { joinSafe } from 'upath'
5+
46
import { _addRemote } from '../commands/addRemote.js'
57
import { FileSystem } from '../models/FileSystem.js'
68
import { assertParameter } from '../utils/assertParameter.js'
7-
import { join } from '../utils/path.js'
89

910
/**
1011
* Add or update a remote
@@ -32,7 +33,7 @@ import { join } from '../utils/path.js'
3233
export async function addRemote({
3334
fs,
3435
dir,
35-
gitdir = join(dir, '.git'),
36+
gitdir = joinSafe(dir, '.git'),
3637
remote,
3738
url,
3839
force = false,

src/api/annotatedTag.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// @ts-check
22
import '../typedefs.js'
33

4+
import { joinSafe } from 'upath'
5+
46
import { _annotatedTag } from '../commands/annotatedTag.js'
57
import { MissingNameError } from '../errors/MissingNameError.js'
68
import { FileSystem } from '../models/FileSystem.js'
79
import { assertParameter } from '../utils/assertParameter.js'
810
import { normalizeAuthorObject } from '../utils/normalizeAuthorObject.js'
9-
import { join } from '../utils/path.js'
1011

1112
/**
1213
* Create an annotated tag.
@@ -15,7 +16,7 @@ import { join } from '../utils/path.js'
1516
* @param {FsClient} args.fs - a file system implementation
1617
* @param {SignCallback} [args.onSign] - a PGP signing implementation
1718
* @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
18-
* @param {string} [args.gitdir=join(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
19+
* @param {string} [args.gitdir=joinSafe(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
1920
* @param {string} args.ref - What to name the tag
2021
* @param {string} [args.message = ref] - The tag message to use.
2122
* @param {string} [args.object = 'HEAD'] - The SHA-1 object id the tag points to. (Will resolve to a SHA-1 object id if value is a ref.) By default, the commit object which is referred by the current `HEAD` is used.
@@ -49,7 +50,7 @@ export async function annotatedTag({
4950
fs: _fs,
5051
onSign,
5152
dir,
52-
gitdir = join(dir, '.git'),
53+
gitdir = joinSafe(dir, '.git'),
5354
ref,
5455
tagger: _tagger,
5556
message = ref,

src/api/branch.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
// @ts-check
22
import '../typedefs.js'
33

4+
import { joinSafe } from 'upath'
5+
46
import { _branch } from '../commands/branch.js'
57
import { FileSystem } from '../models/FileSystem.js'
68
import { assertParameter } from '../utils/assertParameter.js'
7-
import { join } from '../utils/path.js'
89

910
/**
1011
* Create a branch
1112
*
1213
* @param {object} args
1314
* @param {FsClient} args.fs - a file system implementation
1415
* @param {string} [args.dir] - The [working tree](dir-vs-gitdir.md) directory path
15-
* @param {string} [args.gitdir=join(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
16+
* @param {string} [args.gitdir=joinSafe(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
1617
* @param {string} args.ref - What to name the branch
1718
* @param {string} [args.object = 'HEAD'] - What oid to use as the start point. Accepts a symbolic ref.
1819
* @param {boolean} [args.checkout = false] - Update `HEAD` to point at the newly created branch
@@ -28,7 +29,7 @@ import { join } from '../utils/path.js'
2829
export async function branch({
2930
fs,
3031
dir,
31-
gitdir = join(dir, '.git'),
32+
gitdir = joinSafe(dir, '.git'),
3233
ref,
3334
object,
3435
checkout = false,

src/api/checkout.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// @ts-check
22
import '../typedefs.js'
33

4+
import { joinSafe } from 'upath'
5+
46
import { _checkout } from '../commands/checkout.js'
57
import { FileSystem } from '../models/FileSystem.js'
68
import { assertParameter } from '../utils/assertParameter.js'
7-
import { join } from '../utils/path.js'
89

910
/**
1011
* Checkout a branch
@@ -15,7 +16,7 @@ import { join } from '../utils/path.js'
1516
* @param {FsClient} args.fs - a file system implementation
1617
* @param {ProgressCallback} [args.onProgress] - optional progress event callback
1718
* @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path
18-
* @param {string} [args.gitdir=join(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
19+
* @param {string} [args.gitdir=joinSafe(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
1920
* @param {string} [args.ref = 'HEAD'] - Source to checkout files from
2021
* @param {string[]} [args.filepaths] - Limit the checkout to the given files and directories
2122
* @param {string} [args.remote = 'origin'] - Which remote repository to use
@@ -63,7 +64,7 @@ export async function checkout({
6364
fs,
6465
onProgress,
6566
dir,
66-
gitdir = join(dir, '.git'),
67+
gitdir = joinSafe(dir, '.git'),
6768
remote = 'origin',
6869
ref: _ref,
6970
filepaths,

src/api/clone.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// @ts-check
22
import '../typedefs.js'
33

4+
import { joinSafe } from 'upath'
5+
46
import { _clone } from '../commands/clone.js'
57
import { FileSystem } from '../models/FileSystem.js'
68
import { assertParameter } from '../utils/assertParameter.js'
7-
import { join } from '../utils/path.js'
89

910
/**
1011
* Clone a repository
@@ -18,7 +19,7 @@ import { join } from '../utils/path.js'
1819
* @param {AuthFailureCallback} [args.onAuthFailure] - optional auth rejected callback
1920
* @param {AuthSuccessCallback} [args.onAuthSuccess] - optional auth approved callback
2021
* @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path
21-
* @param {string} [args.gitdir=join(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
22+
* @param {string} [args.gitdir=joinSafe(dir,'.git')] - [required] The [git directory](dir-vs-gitdir.md) path
2223
* @param {string} args.url - The URL of the remote repository
2324
* @param {string} [args.corsProxy] - Optional [CORS proxy](https://www.npmjs.com/%40isomorphic-git/cors-proxy). Value is stored in the git config file for that repo.
2425
* @param {string} [args.ref] - Which branch to checkout. By default this is the designated "main branch" of the repository.
@@ -57,7 +58,7 @@ export async function clone({
5758
onAuthSuccess,
5859
onAuthFailure,
5960
dir,
60-
gitdir = join(dir, '.git'),
61+
gitdir = joinSafe(dir, '.git'),
6162
url,
6263
corsProxy = undefined,
6364
ref = undefined,

0 commit comments

Comments
 (0)