Skip to content

Commit 2c62266

Browse files
committed
1 parent cc0516b commit 2c62266

Some content is hidden

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

106 files changed

+11802
-60
lines changed

DEPENDENCIES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,21 @@ graph LR;
275275
bin-links-->write-file-atomic;
276276
brace-expansion-->balanced-match;
277277
builtins-->semver;
278+
cacache-->chownr;
278279
cacache-->fs-minipass;
279280
cacache-->glob;
281+
cacache-->infer-owner;
280282
cacache-->lru-cache;
281283
cacache-->minipass-collect;
282284
cacache-->minipass-flush;
283285
cacache-->minipass-pipeline;
284286
cacache-->minipass;
287+
cacache-->mkdirp;
285288
cacache-->npmcli-fs["@npmcli/fs"];
289+
cacache-->npmcli-move-file["@npmcli/move-file"];
286290
cacache-->p-map;
291+
cacache-->promise-inflight;
292+
cacache-->rimraf;
287293
cacache-->ssri;
288294
cacache-->tar;
289295
cacache-->unique-filename;
@@ -458,6 +464,7 @@ graph LR;
458464
make-fetch-happen-->https-proxy-agent;
459465
make-fetch-happen-->is-lambda;
460466
make-fetch-happen-->lru-cache;
467+
make-fetch-happen-->minipass-collect;
461468
make-fetch-happen-->minipass-fetch;
462469
make-fetch-happen-->minipass-flush;
463470
make-fetch-happen-->minipass-pipeline;
@@ -706,6 +713,8 @@ graph LR;
706713
npmcli-mock-registry-->npmcli-template-oss["@npmcli/template-oss"];
707714
npmcli-mock-registry-->pacote;
708715
npmcli-mock-registry-->tap;
716+
npmcli-move-file-->mkdirp;
717+
npmcli-move-file-->rimraf;
709718
npmcli-package-json-->glob;
710719
npmcli-package-json-->hosted-git-info;
711720
npmcli-package-json-->json-parse-even-better-errors;

node_modules/.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
!/@colors/
77
/@colors/*
88
!/@colors/colors
9+
!/@gar/
10+
/@gar/*
11+
!/@gar/promisify
912
!/@isaacs/
1013
/@isaacs/*
1114
!/@isaacs/cliui
@@ -24,6 +27,7 @@
2427
!/@npmcli/installed-package-contents
2528
!/@npmcli/map-workspaces
2629
!/@npmcli/metavuln-calculator
30+
!/@npmcli/move-file
2731
!/@npmcli/name-from-folder
2832
!/@npmcli/node-gyp
2933
!/@npmcli/package-json
@@ -121,6 +125,7 @@
121125
!/ignore-walk
122126
!/imurmurhash
123127
!/indent-string
128+
!/infer-owner
124129
!/inflight
125130
!/inherits
126131
!/ini
@@ -180,16 +185,32 @@
180185
!/node-gyp
181186
!/node-gyp/node_modules/
182187
/node-gyp/node_modules/*
188+
!/node-gyp/node_modules/@npmcli/
189+
/node-gyp/node_modules/@npmcli/*
190+
!/node-gyp/node_modules/@npmcli/fs
183191
!/node-gyp/node_modules/abbrev
184192
!/node-gyp/node_modules/are-we-there-yet
185193
!/node-gyp/node_modules/brace-expansion
194+
!/node-gyp/node_modules/cacache
195+
!/node-gyp/node_modules/cacache/node_modules/
196+
/node-gyp/node_modules/cacache/node_modules/*
197+
!/node-gyp/node_modules/cacache/node_modules/brace-expansion
198+
!/node-gyp/node_modules/cacache/node_modules/glob
199+
!/node-gyp/node_modules/cacache/node_modules/minimatch
200+
!/node-gyp/node_modules/fs-minipass
186201
!/node-gyp/node_modules/gauge
187202
!/node-gyp/node_modules/glob
203+
!/node-gyp/node_modules/make-fetch-happen
188204
!/node-gyp/node_modules/minimatch
205+
!/node-gyp/node_modules/minipass-fetch
206+
!/node-gyp/node_modules/minipass
189207
!/node-gyp/node_modules/nopt
190208
!/node-gyp/node_modules/npmlog
191209
!/node-gyp/node_modules/readable-stream
192210
!/node-gyp/node_modules/signal-exit
211+
!/node-gyp/node_modules/ssri
212+
!/node-gyp/node_modules/unique-filename
213+
!/node-gyp/node_modules/unique-slug
193214
!/node-gyp/node_modules/which
194215
!/nopt
195216
!/normalize-package-data
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
The MIT License (MIT)
2+
3+
Copyright © 2020-2022 Michael Garvin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict'
2+
3+
const { promisify } = require('util')
4+
5+
const handler = {
6+
get: function (target, prop, receiver) {
7+
if (typeof target[prop] !== 'function') {
8+
return target[prop]
9+
}
10+
if (target[prop][promisify.custom]) {
11+
return function () {
12+
return Reflect.get(target, prop, receiver)[promisify.custom].apply(target, arguments)
13+
}
14+
}
15+
return function () {
16+
return new Promise((resolve, reject) => {
17+
Reflect.get(target, prop, receiver).apply(target, [...arguments, function (err, result) {
18+
if (err) {
19+
return reject(err)
20+
}
21+
resolve(result)
22+
}])
23+
})
24+
}
25+
}
26+
}
27+
28+
module.exports = function (thingToPromisify) {
29+
if (typeof thingToPromisify === 'function') {
30+
return promisify(thingToPromisify)
31+
}
32+
if (typeof thingToPromisify === 'object') {
33+
return new Proxy(thingToPromisify, handler)
34+
}
35+
throw new TypeError('Can only promisify functions or objects')
36+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@gar/promisify",
3+
"version": "1.1.3",
4+
"description": "Promisify an entire class or object",
5+
"main": "index.js",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/wraithgar/gar-promisify.git"
9+
},
10+
"scripts": {
11+
"lint": "standard",
12+
"lint:fix": "standard --fix",
13+
"test": "lab -a @hapi/code -t 100",
14+
"posttest": "npm run lint"
15+
},
16+
"files": [
17+
"index.js"
18+
],
19+
"keywords": [
20+
"promisify",
21+
"all",
22+
"class",
23+
"object"
24+
],
25+
"author": "Gar <[email protected]>",
26+
"license": "MIT",
27+
"devDependencies": {
28+
"@hapi/code": "^8.0.1",
29+
"@hapi/lab": "^24.1.0",
30+
"standard": "^16.0.3"
31+
}
32+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
4+
Copyright (c) npm, Inc.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a
7+
copy of this software and associated documentation files (the "Software"),
8+
to deal in the Software without restriction, including without limitation
9+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
and/or sell copies of the Software, and to permit persons to whom the
11+
Software is furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
DEALINGS IN THE SOFTWARE.
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
const { dirname, join, resolve, relative, isAbsolute } = require('path')
2+
const rimraf_ = require('rimraf')
3+
const { promisify } = require('util')
4+
const {
5+
access: access_,
6+
accessSync,
7+
copyFile: copyFile_,
8+
copyFileSync,
9+
readdir: readdir_,
10+
readdirSync,
11+
rename: rename_,
12+
renameSync,
13+
stat: stat_,
14+
statSync,
15+
lstat: lstat_,
16+
lstatSync,
17+
symlink: symlink_,
18+
symlinkSync,
19+
readlink: readlink_,
20+
readlinkSync,
21+
} = require('fs')
22+
23+
const access = promisify(access_)
24+
const copyFile = promisify(copyFile_)
25+
const readdir = promisify(readdir_)
26+
const rename = promisify(rename_)
27+
const stat = promisify(stat_)
28+
const lstat = promisify(lstat_)
29+
const symlink = promisify(symlink_)
30+
const readlink = promisify(readlink_)
31+
const rimraf = promisify(rimraf_)
32+
const rimrafSync = rimraf_.sync
33+
34+
const mkdirp = require('mkdirp')
35+
36+
const pathExists = async path => {
37+
try {
38+
await access(path)
39+
return true
40+
} catch (er) {
41+
return er.code !== 'ENOENT'
42+
}
43+
}
44+
45+
const pathExistsSync = path => {
46+
try {
47+
accessSync(path)
48+
return true
49+
} catch (er) {
50+
return er.code !== 'ENOENT'
51+
}
52+
}
53+
54+
const moveFile = async (source, destination, options = {}, root = true, symlinks = []) => {
55+
if (!source || !destination) {
56+
throw new TypeError('`source` and `destination` file required')
57+
}
58+
59+
options = {
60+
overwrite: true,
61+
...options,
62+
}
63+
64+
if (!options.overwrite && await pathExists(destination)) {
65+
throw new Error(`The destination file exists: ${destination}`)
66+
}
67+
68+
await mkdirp(dirname(destination))
69+
70+
try {
71+
await rename(source, destination)
72+
} catch (error) {
73+
if (error.code === 'EXDEV' || error.code === 'EPERM') {
74+
const sourceStat = await lstat(source)
75+
if (sourceStat.isDirectory()) {
76+
const files = await readdir(source)
77+
await Promise.all(files.map((file) =>
78+
moveFile(join(source, file), join(destination, file), options, false, symlinks)
79+
))
80+
} else if (sourceStat.isSymbolicLink()) {
81+
symlinks.push({ source, destination })
82+
} else {
83+
await copyFile(source, destination)
84+
}
85+
} else {
86+
throw error
87+
}
88+
}
89+
90+
if (root) {
91+
await Promise.all(symlinks.map(async ({ source: symSource, destination: symDestination }) => {
92+
let target = await readlink(symSource)
93+
// junction symlinks in windows will be absolute paths, so we need to
94+
// make sure they point to the symlink destination
95+
if (isAbsolute(target)) {
96+
target = resolve(symDestination, relative(symSource, target))
97+
}
98+
// try to determine what the actual file is so we can create the correct
99+
// type of symlink in windows
100+
let targetStat = 'file'
101+
try {
102+
targetStat = await stat(resolve(dirname(symSource), target))
103+
if (targetStat.isDirectory()) {
104+
targetStat = 'junction'
105+
}
106+
} catch {
107+
// targetStat remains 'file'
108+
}
109+
await symlink(
110+
target,
111+
symDestination,
112+
targetStat
113+
)
114+
}))
115+
await rimraf(source)
116+
}
117+
}
118+
119+
const moveFileSync = (source, destination, options = {}, root = true, symlinks = []) => {
120+
if (!source || !destination) {
121+
throw new TypeError('`source` and `destination` file required')
122+
}
123+
124+
options = {
125+
overwrite: true,
126+
...options,
127+
}
128+
129+
if (!options.overwrite && pathExistsSync(destination)) {
130+
throw new Error(`The destination file exists: ${destination}`)
131+
}
132+
133+
mkdirp.sync(dirname(destination))
134+
135+
try {
136+
renameSync(source, destination)
137+
} catch (error) {
138+
if (error.code === 'EXDEV' || error.code === 'EPERM') {
139+
const sourceStat = lstatSync(source)
140+
if (sourceStat.isDirectory()) {
141+
const files = readdirSync(source)
142+
for (const file of files) {
143+
moveFileSync(join(source, file), join(destination, file), options, false, symlinks)
144+
}
145+
} else if (sourceStat.isSymbolicLink()) {
146+
symlinks.push({ source, destination })
147+
} else {
148+
copyFileSync(source, destination)
149+
}
150+
} else {
151+
throw error
152+
}
153+
}
154+
155+
if (root) {
156+
for (const { source: symSource, destination: symDestination } of symlinks) {
157+
let target = readlinkSync(symSource)
158+
// junction symlinks in windows will be absolute paths, so we need to
159+
// make sure they point to the symlink destination
160+
if (isAbsolute(target)) {
161+
target = resolve(symDestination, relative(symSource, target))
162+
}
163+
// try to determine what the actual file is so we can create the correct
164+
// type of symlink in windows
165+
let targetStat = 'file'
166+
try {
167+
targetStat = statSync(resolve(dirname(symSource), target))
168+
if (targetStat.isDirectory()) {
169+
targetStat = 'junction'
170+
}
171+
} catch {
172+
// targetStat remains 'file'
173+
}
174+
symlinkSync(
175+
target,
176+
symDestination,
177+
targetStat
178+
)
179+
}
180+
rimrafSync(source)
181+
}
182+
}
183+
184+
module.exports = moveFile
185+
module.exports.sync = moveFileSync

0 commit comments

Comments
 (0)