symlink-dir 1.0.3 → 1.1.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.
- package/LICENSE +2 -2
- package/README.md +21 -4
- package/dist/cli.d.ts +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +15 -9
- package/dist/index.js.map +1 -1
- package/package.json +11 -10
- package/dist/forceSymlink.d.ts +0 -6
- package/dist/forceSymlink.js +0 -34
- package/dist/forceSymlink.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2016 Zoltan Kochan
|
|
3
|
+
Copyright (c) 2016-2018 Zoltan Kochan
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<!--/@-->
|
|
8
8
|
|
|
9
9
|
Always uses "junctions" on Windows. Even though support for "symbolic links" was added in Vista+, users by default
|
|
10
|
-
lack permission to create them
|
|
10
|
+
lack permission to create them
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -31,12 +31,29 @@ symlink-dir . node_modules/my-package
|
|
|
31
31
|
'use strict'
|
|
32
32
|
const symlinkDir = require('symlink-dir')
|
|
33
33
|
const path = require('path')
|
|
34
|
-
const cwd = process.cwd()
|
|
35
34
|
|
|
36
|
-
symlinkDir(
|
|
35
|
+
symlinkDir('src', 'node_modules/src')
|
|
36
|
+
.then(result => {
|
|
37
|
+
console.log(result)
|
|
38
|
+
//> { reused: false }
|
|
39
|
+
|
|
40
|
+
return symlinkDir('src', 'node_modules/src')
|
|
41
|
+
})
|
|
42
|
+
.then(result => {
|
|
43
|
+
console.log(result)
|
|
44
|
+
//> { reused: true }
|
|
45
|
+
})
|
|
46
|
+
.catch(err => console.error(err))
|
|
37
47
|
```
|
|
38
48
|
<!--/@-->
|
|
39
49
|
|
|
50
|
+
## API
|
|
51
|
+
|
|
52
|
+
### `symlinkDir(src, dest): Promise<{reused: boolean}>`
|
|
53
|
+
|
|
54
|
+
Creates a symlink in `dest` that points to `src`. Returns an object that contains a boolean property called `reused`.
|
|
55
|
+
`reused` is `true` if the symlink already existed pointing to the `src`.
|
|
56
|
+
|
|
40
57
|
## License
|
|
41
58
|
|
|
42
|
-
[MIT](./LICENSE) © [Zoltan Kochan](
|
|
59
|
+
[MIT](./LICENSE) © [Zoltan Kochan](https://www.kochan.io)
|
package/dist/cli.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -11,23 +11,28 @@ const fs = require("mz/fs");
|
|
|
11
11
|
const path = require("path");
|
|
12
12
|
const mkdirp = require("mkdirp-promise");
|
|
13
13
|
const isWindows = require("is-windows");
|
|
14
|
+
const IS_WINDOWS = isWindows();
|
|
14
15
|
// Always use "junctions" on Windows. Even though support for "symbolic links" was added in Vista+, users by default
|
|
15
16
|
// lack permission to create them
|
|
16
|
-
const symlinkType =
|
|
17
|
+
const symlinkType = IS_WINDOWS ? 'junction' : 'dir';
|
|
18
|
+
const resolveSrc = IS_WINDOWS ? resolveSrcOnWin : resolveSrcOnNonWin;
|
|
19
|
+
function resolveSrcOnWin(src, dest) {
|
|
20
|
+
return `${path.resolve(src)}\\`;
|
|
21
|
+
}
|
|
22
|
+
function resolveSrcOnNonWin(src, dest) {
|
|
23
|
+
return path.relative(path.dirname(dest), path.resolve(src));
|
|
24
|
+
}
|
|
17
25
|
function symlinkDir(src, dest) {
|
|
18
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
src = path.resolve(src);
|
|
20
27
|
dest = path.resolve(dest);
|
|
21
|
-
|
|
22
|
-
const rel = symlinkType !== 'junction' ? path.relative(path.dirname(dest), src) : src;
|
|
28
|
+
src = resolveSrc(src, dest);
|
|
23
29
|
try {
|
|
24
|
-
yield forceSymlink(
|
|
30
|
+
return yield forceSymlink(src, dest);
|
|
25
31
|
}
|
|
26
32
|
catch (err) {
|
|
27
33
|
if (err.code === 'ENOENT') {
|
|
28
34
|
yield mkdirp(path.dirname(dest));
|
|
29
|
-
yield forceSymlink(
|
|
30
|
-
return;
|
|
35
|
+
return yield forceSymlink(src, dest);
|
|
31
36
|
}
|
|
32
37
|
throw err;
|
|
33
38
|
}
|
|
@@ -41,16 +46,17 @@ function forceSymlink(src, dest) {
|
|
|
41
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
47
|
try {
|
|
43
48
|
yield fs.symlink(src, dest, symlinkType);
|
|
49
|
+
return { reused: false };
|
|
44
50
|
}
|
|
45
51
|
catch (err) {
|
|
46
52
|
if (err.code !== 'EEXIST')
|
|
47
53
|
throw err;
|
|
48
54
|
const linkString = yield fs.readlink(dest);
|
|
49
55
|
if (src === linkString) {
|
|
50
|
-
return;
|
|
56
|
+
return { reused: true };
|
|
51
57
|
}
|
|
52
58
|
yield fs.unlink(dest);
|
|
53
|
-
yield forceSymlink(src, dest);
|
|
59
|
+
return yield forceSymlink(src, dest);
|
|
54
60
|
}
|
|
55
61
|
});
|
|
56
62
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/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,IAAI,CAAC,CAAA;aACrC;YACD,MAAM,GAAG,CAAA;SACV;IACH,CAAC;CAAA;AAED;;;GAGG;AACH,sBAA6B,GAAW,EAAE,IAAY;;QACpD,IAAI;YACF,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,WAAW,CAAC,CAAA;YACxC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAA;SACzB;QAAC,OAAO,GAAG,EAAE;YACZ,IAA4B,GAAI,CAAC,IAAI,KAAK,QAAQ;gBAAE,MAAM,GAAG,CAAA;YAE7D,MAAM,UAAU,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;YAC1C,IAAI,GAAG,KAAK,UAAU,EAAE;gBACtB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;aACxB;YACD,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YACrB,OAAO,MAAM,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;SACrC;IACH,CAAC;CAAA;AAED,6BAA6B;AAC7B,UAAU,CAAC,SAAS,CAAC,GAAG,UAAU,CAAA;AAElC,iBAAS,UAAU,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "symlink-dir",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Cross-platform directory symlinking",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -17,10 +17,12 @@
|
|
|
17
17
|
"folder"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
+
"pretest": "rimraf node_modules/src",
|
|
20
21
|
"test": "npm run tsc && mos t",
|
|
22
|
+
"premd": "rimraf node_modules/src && npm run tsc",
|
|
21
23
|
"md": "mos",
|
|
22
|
-
"tsc": "
|
|
23
|
-
"
|
|
24
|
+
"tsc": "rimraf dist && tsc",
|
|
25
|
+
"prepublishOnly": "npm run tsc"
|
|
24
26
|
},
|
|
25
27
|
"repository": {
|
|
26
28
|
"type": "git",
|
|
@@ -28,8 +30,8 @@
|
|
|
28
30
|
},
|
|
29
31
|
"author": {
|
|
30
32
|
"name": "Zoltan Kochan",
|
|
31
|
-
"email": "
|
|
32
|
-
"url": "
|
|
33
|
+
"email": "z@kochan.io",
|
|
34
|
+
"url": "https://www.kochan.io"
|
|
33
35
|
},
|
|
34
36
|
"license": "MIT",
|
|
35
37
|
"bugs": {
|
|
@@ -37,17 +39,16 @@
|
|
|
37
39
|
},
|
|
38
40
|
"homepage": "https://github.com/zkochan/symlink-dir#readme",
|
|
39
41
|
"devDependencies": {
|
|
40
|
-
"
|
|
41
|
-
"mos": "^1.3.1",
|
|
42
|
+
"mos": "^2.0.0-alpha.3",
|
|
42
43
|
"mos-plugin-readme": "^1.0.4",
|
|
44
|
+
"rimraf": "^2.6.1",
|
|
43
45
|
"typescript": "^2.0.3"
|
|
44
46
|
},
|
|
45
47
|
"dependencies": {
|
|
46
|
-
"@types/mz": "0.0.
|
|
47
|
-
"@types/node": "^
|
|
48
|
+
"@types/mz": "0.0.32",
|
|
49
|
+
"@types/node": "^10.0.8",
|
|
48
50
|
"graceful-fs": "^4.1.11",
|
|
49
51
|
"is-windows": "^1.0.0",
|
|
50
|
-
"mkdirp": "^0.5.1",
|
|
51
52
|
"mkdirp-promise": "^5.0.0",
|
|
52
53
|
"mz": "^2.4.0"
|
|
53
54
|
},
|
package/dist/forceSymlink.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare type SymlinkType = 'junction' | 'dir';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a symlink. Re-link if a symlink already exists at the supplied
|
|
4
|
-
* srcPath. API compatible with [`fs#symlink`](https://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback).
|
|
5
|
-
*/
|
|
6
|
-
export default function forceSymlink(srcPath: string, dstPath: string, type: SymlinkType): Promise<void>;
|
package/dist/forceSymlink.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
const fs = require("mz/fs");
|
|
11
|
-
/**
|
|
12
|
-
* Creates a symlink. Re-link if a symlink already exists at the supplied
|
|
13
|
-
* srcPath. API compatible with [`fs#symlink`](https://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback).
|
|
14
|
-
*/
|
|
15
|
-
function forceSymlink(srcPath, dstPath, type) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
try {
|
|
18
|
-
yield fs.symlink(srcPath, dstPath, type);
|
|
19
|
-
}
|
|
20
|
-
catch (err) {
|
|
21
|
-
if (err.code !== 'EEXIST')
|
|
22
|
-
throw err;
|
|
23
|
-
const linkString = yield fs.readlink(dstPath);
|
|
24
|
-
if (srcPath === linkString) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
yield fs.unlink(dstPath);
|
|
28
|
-
yield forceSymlink(srcPath, dstPath, type);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
-
exports.default = forceSymlink;
|
|
34
|
-
//# sourceMappingURL=forceSymlink.js.map
|
package/dist/forceSymlink.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forceSymlink.js","sourceRoot":"","sources":["../src/forceSymlink.ts"],"names":[],"mappings":";;;;;;;;;AAAA,4BAA4B;AAI5B;;;GAGG;AACH,sBAA4C,OAAe,EAAE,OAAe,EAAE,IAAiB;;QAC7F,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;QAC1C,CAAC;QAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACb,EAAE,CAAC,CAAyB,GAAI,CAAC,IAAI,KAAK,QAAQ,CAAC;gBAAC,MAAM,GAAG,CAAA;YAE7D,MAAM,UAAU,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;YAC7C,EAAE,CAAC,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC;gBAC3B,MAAM,CAAA;YACR,CAAC;YACD,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;YACxB,MAAM,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;CAAA;;AAbD,+BAaC"}
|