dl-git-repo-safe 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/index.js +10 -43
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
6
 
7
+ ## [1.0.3] - 2026-04-01
8
+
9
+ ### Fixed
10
+ - Fixed shallow clone logic: when caller passes `opts.checkout` different from repo default, shallow is now based on the effective checkout (`opts.checkout || repo.checkout`) instead of always using `repo.checkout`
11
+ - Fixed `addProtocol` to recognize already-protocol-prefixed origins (`ssh://`, `git://`, `git@`, etc.) so they are not incorrectly rewritten with `https://` or `git@` prefixes
12
+
7
13
  ## [1.0.2] - 2026-04-01
8
14
 
9
15
  ### Fixed
package/index.js CHANGED
@@ -2,21 +2,8 @@ var downloadUrl = require('download')
2
2
  var gitclone = require('git-clone-safe')
3
3
  var rm = require('rimraf').sync
4
4
 
5
- /**
6
- * Expose `download`.
7
- */
8
-
9
5
  module.exports = download
10
6
 
11
- /**
12
- * Download `repo` to `dest` and callback `fn(err)`.
13
- *
14
- * @param {String} repo
15
- * @param {String} dest
16
- * @param {Object} opts
17
- * @param {Function} fn
18
- */
19
-
20
7
  function download (repo, dest, opts, fn) {
21
8
  if (typeof opts === 'function') {
22
9
  fn = opts
@@ -30,9 +17,10 @@ function download (repo, dest, opts, fn) {
30
17
  var url = repo.url || getUrl(repo, clone)
31
18
 
32
19
  if (clone) {
20
+ var finalCheckout = opts.checkout || repo.checkout
33
21
  var cloneOptions = {
34
22
  checkout: repo.checkout,
35
- shallow: repo.checkout === 'master',
23
+ shallow: finalCheckout === 'master',
36
24
  ...opts
37
25
  }
38
26
  gitclone(url, dest, cloneOptions, function (err) {
@@ -64,13 +52,6 @@ function download (repo, dest, opts, fn) {
64
52
  }
65
53
  }
66
54
 
67
- /**
68
- * Normalize a repo string.
69
- *
70
- * @param {String} repo
71
- * @return {Object}
72
- */
73
-
74
55
  function normalize (repo) {
75
56
  var regex = /^(?:(direct):([^#]+)(?:#(.+))?)$/
76
57
  var match = regex.exec(repo)
@@ -113,36 +94,23 @@ function normalize (repo) {
113
94
  }
114
95
  }
115
96
 
116
- /**
117
- * Adds protocol to url in none specified
118
- *
119
- * @param {String} url
120
- * @return {String}
121
- */
122
-
123
97
  function addProtocol (origin, clone) {
124
- if (!/^(f|ht)tps?:\/\//i.test(origin)) {
125
- if (clone) {
126
- origin = 'git@' + origin
127
- } else {
128
- origin = 'https://' + origin
129
- }
98
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(origin) || /^git@/i.test(origin)) {
99
+ return origin
100
+ }
101
+
102
+ if (clone) {
103
+ origin = 'git@' + origin
104
+ } else {
105
+ origin = 'https://' + origin
130
106
  }
131
107
 
132
108
  return origin
133
109
  }
134
110
 
135
- /**
136
- * Return a zip or git url for a given `repo`.
137
- *
138
- * @param {Object} repo
139
- * @return {String}
140
- */
141
-
142
111
  function getUrl (repo, clone) {
143
112
  var url
144
113
 
145
- // Get origin with protocol and add trailing slash or colon (for ssh)
146
114
  var origin = addProtocol(repo.origin, clone)
147
115
  if (/^git@/i.test(origin)) {
148
116
  origin = origin + ':'
@@ -150,7 +118,6 @@ function getUrl (repo, clone) {
150
118
  origin = origin + '/'
151
119
  }
152
120
 
153
- // Build url
154
121
  if (clone) {
155
122
  url = origin + repo.owner + '/' + repo.name + '.git'
156
123
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dl-git-repo-safe",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",