@teambit/bvm.link 1.1.5 → 1.2.0
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/bitx-link.spec.ts +50 -0
- package/bitx-link.ts +64 -0
- package/dist/bitx-link.d.ts +23 -0
- package/dist/bitx-link.js +64 -0
- package/dist/bitx-link.js.map +1 -0
- package/dist/bitx-link.spec.d.ts +1 -0
- package/dist/bitx-link.spec.js +48 -0
- package/dist/bitx-link.spec.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/link.d.ts +19 -0
- package/dist/link.docs.md +5 -0
- package/dist/link.js +97 -9
- package/dist/link.js.map +1 -1
- package/dist/{preview-1793888985211.js → preview-1795425000766.js} +1 -1
- package/index.ts +9 -1
- package/link.docs.md +5 -0
- package/link.ts +111 -12
- package/package.json +4 -4
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { getBitxLinkSource, readBitxMetadata, validateBitxLinkName, BITX_METADATA_FILE } from './bitx-link';
|
|
5
|
+
|
|
6
|
+
describe('bitx link helpers', () => {
|
|
7
|
+
let root: string;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
root = fs.mkdtempSync(path.join(os.tmpdir(), 'bvm-bitx-link-'));
|
|
10
|
+
});
|
|
11
|
+
afterEach(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
12
|
+
|
|
13
|
+
describe('getBitxLinkSource', () => {
|
|
14
|
+
it('selects bin/bitx on Unix', () => {
|
|
15
|
+
fs.mkdirSync(path.join(root, 'bin'));
|
|
16
|
+
fs.writeFileSync(path.join(root, 'bin/bitx'), 'native fixture', { mode: 0o755 });
|
|
17
|
+
expect(getBitxLinkSource(root, 'linux')).toEqual(path.join('bin', 'bitx'));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('selects bin/bitx.exe on Windows', () => {
|
|
21
|
+
fs.mkdirSync(path.join(root, 'bin'));
|
|
22
|
+
fs.writeFileSync(path.join(root, 'bin/bitx.exe'), 'native fixture');
|
|
23
|
+
expect(getBitxLinkSource(root, 'win32')).toEqual(path.join('bin', 'bitx.exe'));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('fails with a reinstall hint when the executable is missing', () => {
|
|
27
|
+
expect(() => getBitxLinkSource(root, 'linux')).toThrow('bvm install --next --override');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('reads the metadata file and treats a missing one as not installed', () => {
|
|
32
|
+
expect(readBitxMetadata(root)).toBeUndefined();
|
|
33
|
+
fs.writeFileSync(path.join(root, BITX_METADATA_FILE), JSON.stringify({ version: '0.1.0', node: '22.23.4' }));
|
|
34
|
+
expect(readBitxMetadata(root)).toEqual({ version: '0.1.0', node: '22.23.4' });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('validateBitxLinkName', () => {
|
|
38
|
+
it('accepts a name that Bit does not use', () => {
|
|
39
|
+
expect(() => validateBitxLinkName('bitx', 'bit', { bit: '2.2.164' })).not.toThrow();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('refuses the default Bit link name', () => {
|
|
43
|
+
expect(() => validateBitxLinkName('bit', 'bit', {})).toThrow('is used by Bit');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('refuses a name that a Bit version is linked with', () => {
|
|
47
|
+
expect(() => validateBitxLinkName('bit2', 'bit', { bit2: '2.0.0' })).toThrow('is used by Bit');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
package/bitx-link.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { BvmError } from '@teambit/bvm.error';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Written to the root of every installed bitx version once its installation completes.
|
|
7
|
+
* A bitx version directory without it is an interrupted installation.
|
|
8
|
+
*/
|
|
9
|
+
export const BITX_METADATA_FILE = 'bvm-bitx.json';
|
|
10
|
+
|
|
11
|
+
export type BitxMetadata = {
|
|
12
|
+
version: string,
|
|
13
|
+
// the npm package the version was installed from, and the platform package that holds the executable
|
|
14
|
+
package: string,
|
|
15
|
+
platformPackage: string,
|
|
16
|
+
// the Node.js version installed for this bitx version (undefined when the system Node.js is used)
|
|
17
|
+
node?: string,
|
|
18
|
+
installedAt: string,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function getBitxExecutableName(platform = process.platform): string {
|
|
22
|
+
return platform === 'win32' ? 'bitx.exe' : 'bitx';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function readBitxMetadata(versionDir: string): BitxMetadata | undefined {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(fs.readFileSync(path.join(versionDir, BITX_METADATA_FILE), 'utf8'));
|
|
28
|
+
} catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The bitx executable inside an installed bitx version, relative to the version directory.
|
|
35
|
+
*/
|
|
36
|
+
export function getBitxLinkSource(versionDir: string, platform = process.platform): string {
|
|
37
|
+
const source = path.join('bin', getBitxExecutableName(platform));
|
|
38
|
+
const filename = path.join(versionDir, source);
|
|
39
|
+
let stat: fs.Stats;
|
|
40
|
+
try {
|
|
41
|
+
stat = fs.statSync(filename);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
44
|
+
throw new BvmError(`the bitx executable is missing at ${filename}. reinstall bitx with "bvm install --next --override"`);
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
if (!stat.isFile()) throw new BvmError(`the bitx executable is not a regular file: ${filename}`);
|
|
49
|
+
if (platform !== 'win32') fs.accessSync(filename, fs.constants.X_OK);
|
|
50
|
+
return source;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* bitx and Bit share the links directory and the bin directory, so a bitx link
|
|
55
|
+
* must not take a name that a Bit version is linked with.
|
|
56
|
+
*/
|
|
57
|
+
export function validateBitxLinkName(linkName: string, defaultLinkName: string, bitLinks: Record<string, string>) {
|
|
58
|
+
if (!linkName) {
|
|
59
|
+
throw new BvmError('bitx link name is empty');
|
|
60
|
+
}
|
|
61
|
+
if (linkName === defaultLinkName || bitLinks[linkName]) {
|
|
62
|
+
throw new BvmError(`the link name "${linkName}" is used by Bit. bitx must be linked with another name (see "bvm config set BITX_LINK <name>")`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Written to the root of every installed bitx version once its installation completes.
|
|
3
|
+
* A bitx version directory without it is an interrupted installation.
|
|
4
|
+
*/
|
|
5
|
+
export declare const BITX_METADATA_FILE = "bvm-bitx.json";
|
|
6
|
+
export type BitxMetadata = {
|
|
7
|
+
version: string;
|
|
8
|
+
package: string;
|
|
9
|
+
platformPackage: string;
|
|
10
|
+
node?: string;
|
|
11
|
+
installedAt: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function getBitxExecutableName(platform?: NodeJS.Platform): string;
|
|
14
|
+
export declare function readBitxMetadata(versionDir: string): BitxMetadata | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The bitx executable inside an installed bitx version, relative to the version directory.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getBitxLinkSource(versionDir: string, platform?: NodeJS.Platform): string;
|
|
19
|
+
/**
|
|
20
|
+
* bitx and Bit share the links directory and the bin directory, so a bitx link
|
|
21
|
+
* must not take a name that a Bit version is linked with.
|
|
22
|
+
*/
|
|
23
|
+
export declare function validateBitxLinkName(linkName: string, defaultLinkName: string, bitLinks: Record<string, string>): void;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BITX_METADATA_FILE = void 0;
|
|
7
|
+
exports.getBitxExecutableName = getBitxExecutableName;
|
|
8
|
+
exports.readBitxMetadata = readBitxMetadata;
|
|
9
|
+
exports.getBitxLinkSource = getBitxLinkSource;
|
|
10
|
+
exports.validateBitxLinkName = validateBitxLinkName;
|
|
11
|
+
const fs_1 = __importDefault(require("fs"));
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const bvm_error_1 = require("@teambit/bvm.error");
|
|
14
|
+
/**
|
|
15
|
+
* Written to the root of every installed bitx version once its installation completes.
|
|
16
|
+
* A bitx version directory without it is an interrupted installation.
|
|
17
|
+
*/
|
|
18
|
+
exports.BITX_METADATA_FILE = 'bvm-bitx.json';
|
|
19
|
+
function getBitxExecutableName(platform = process.platform) {
|
|
20
|
+
return platform === 'win32' ? 'bitx.exe' : 'bitx';
|
|
21
|
+
}
|
|
22
|
+
function readBitxMetadata(versionDir) {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(fs_1.default.readFileSync(path_1.default.join(versionDir, exports.BITX_METADATA_FILE), 'utf8'));
|
|
25
|
+
}
|
|
26
|
+
catch (_a) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The bitx executable inside an installed bitx version, relative to the version directory.
|
|
32
|
+
*/
|
|
33
|
+
function getBitxLinkSource(versionDir, platform = process.platform) {
|
|
34
|
+
const source = path_1.default.join('bin', getBitxExecutableName(platform));
|
|
35
|
+
const filename = path_1.default.join(versionDir, source);
|
|
36
|
+
let stat;
|
|
37
|
+
try {
|
|
38
|
+
stat = fs_1.default.statSync(filename);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error.code === 'ENOENT') {
|
|
42
|
+
throw new bvm_error_1.BvmError(`the bitx executable is missing at ${filename}. reinstall bitx with "bvm install --next --override"`);
|
|
43
|
+
}
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
if (!stat.isFile())
|
|
47
|
+
throw new bvm_error_1.BvmError(`the bitx executable is not a regular file: ${filename}`);
|
|
48
|
+
if (platform !== 'win32')
|
|
49
|
+
fs_1.default.accessSync(filename, fs_1.default.constants.X_OK);
|
|
50
|
+
return source;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* bitx and Bit share the links directory and the bin directory, so a bitx link
|
|
54
|
+
* must not take a name that a Bit version is linked with.
|
|
55
|
+
*/
|
|
56
|
+
function validateBitxLinkName(linkName, defaultLinkName, bitLinks) {
|
|
57
|
+
if (!linkName) {
|
|
58
|
+
throw new bvm_error_1.BvmError('bitx link name is empty');
|
|
59
|
+
}
|
|
60
|
+
if (linkName === defaultLinkName || bitLinks[linkName]) {
|
|
61
|
+
throw new bvm_error_1.BvmError(`the link name "${linkName}" is used by Bit. bitx must be linked with another name (see "bvm config set BITX_LINK <name>")`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=bitx-link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitx-link.js","sourceRoot":"","sources":["../bitx-link.ts"],"names":[],"mappings":";;;;;;AAoBA,sDAEC;AAED,4CAMC;AAKD,8CAeC;AAMD,oDAOC;AA/DD,4CAAoB;AACpB,gDAAwB;AACxB,kDAA8C;AAE9C;;;GAGG;AACU,QAAA,kBAAkB,GAAG,eAAe,CAAC;AAYlD,SAAgB,qBAAqB,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ;IAC/D,OAAO,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC;AACpD,CAAC;AAED,SAAgB,gBAAgB,CAAC,UAAkB;IACjD,IAAI,CAA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AAC;IACD,IAAI,QAAQ,KAAK,eAAe,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,oBAAQ,CAAC,kBAAkB,QAAQ,iGAAiG,CAAC,CAAC;IAClJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const bitx_link_1 = require("./bitx-link");
|
|
10
|
+
describe('bitx link helpers', () => {
|
|
11
|
+
let root;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
root = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'bvm-bitx-link-'));
|
|
14
|
+
});
|
|
15
|
+
afterEach(() => fs_1.default.rmSync(root, { recursive: true, force: true }));
|
|
16
|
+
describe('getBitxLinkSource', () => {
|
|
17
|
+
it('selects bin/bitx on Unix', () => {
|
|
18
|
+
fs_1.default.mkdirSync(path_1.default.join(root, 'bin'));
|
|
19
|
+
fs_1.default.writeFileSync(path_1.default.join(root, 'bin/bitx'), 'native fixture', { mode: 0o755 });
|
|
20
|
+
expect((0, bitx_link_1.getBitxLinkSource)(root, 'linux')).toEqual(path_1.default.join('bin', 'bitx'));
|
|
21
|
+
});
|
|
22
|
+
it('selects bin/bitx.exe on Windows', () => {
|
|
23
|
+
fs_1.default.mkdirSync(path_1.default.join(root, 'bin'));
|
|
24
|
+
fs_1.default.writeFileSync(path_1.default.join(root, 'bin/bitx.exe'), 'native fixture');
|
|
25
|
+
expect((0, bitx_link_1.getBitxLinkSource)(root, 'win32')).toEqual(path_1.default.join('bin', 'bitx.exe'));
|
|
26
|
+
});
|
|
27
|
+
it('fails with a reinstall hint when the executable is missing', () => {
|
|
28
|
+
expect(() => (0, bitx_link_1.getBitxLinkSource)(root, 'linux')).toThrow('bvm install --next --override');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
it('reads the metadata file and treats a missing one as not installed', () => {
|
|
32
|
+
expect((0, bitx_link_1.readBitxMetadata)(root)).toBeUndefined();
|
|
33
|
+
fs_1.default.writeFileSync(path_1.default.join(root, bitx_link_1.BITX_METADATA_FILE), JSON.stringify({ version: '0.1.0', node: '22.23.4' }));
|
|
34
|
+
expect((0, bitx_link_1.readBitxMetadata)(root)).toEqual({ version: '0.1.0', node: '22.23.4' });
|
|
35
|
+
});
|
|
36
|
+
describe('validateBitxLinkName', () => {
|
|
37
|
+
it('accepts a name that Bit does not use', () => {
|
|
38
|
+
expect(() => (0, bitx_link_1.validateBitxLinkName)('bitx', 'bit', { bit: '2.2.164' })).not.toThrow();
|
|
39
|
+
});
|
|
40
|
+
it('refuses the default Bit link name', () => {
|
|
41
|
+
expect(() => (0, bitx_link_1.validateBitxLinkName)('bit', 'bit', {})).toThrow('is used by Bit');
|
|
42
|
+
});
|
|
43
|
+
it('refuses a name that a Bit version is linked with', () => {
|
|
44
|
+
expect(() => (0, bitx_link_1.validateBitxLinkName)('bit2', 'bit', { bit2: '2.0.0' })).toThrow('is used by Bit');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=bitx-link.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitx-link.spec.js","sourceRoot":"","sources":["../bitx-link.spec.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,4CAAoB;AACpB,gDAAwB;AACxB,2CAA4G;AAE5G,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,IAAI,IAAY,CAAC;IACjB,U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AE,CAAC,IAAA,gCAAoB,EAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACjG,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,5 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.validateBitxLinkName = exports.readBitxMetadata = exports.getBitxLinkSource = exports.getBitxExecutableName = exports.BITX_METADATA_FILE = void 0;
|
|
17
18
|
__exportStar(require("./link"), exports);
|
|
19
|
+
var bitx_link_1 = require("./bitx-link");
|
|
20
|
+
Object.defineProperty(exports, "BITX_METADATA_FILE", { enumerable: true, get: function () { return bitx_link_1.BITX_METADATA_FILE; } });
|
|
21
|
+
Object.defineProperty(exports, "getBitxExecutableName", { enumerable: true, get: function () { return bitx_link_1.getBitxExecutableName; } });
|
|
22
|
+
Object.defineProperty(exports, "getBitxLinkSource", { enumerable: true, get: function () { return bitx_link_1.getBitxLinkSource; } });
|
|
23
|
+
Object.defineProperty(exports, "readBitxMetadata", { enumerable: true, get: function () { return bitx_link_1.readBitxMetadata; } });
|
|
24
|
+
Object.defineProperty(exports, "validateBitxLinkName", { enumerable: true, get: function () { return bitx_link_1.validateBitxLinkName; } });
|
|
18
25
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,yCAOqB;AANnB,+GAAA,kBAAkB,OAAA;AAElB,kHAAA,qBAAqB,OAAA;AACrB,8GAAA,iBAAiB,OAAA;AACjB,6GAAA,gBAAgB,OAAA;AAChB,iHAAA,oBAAoB,OAAA"}
|
package/dist/link.d.ts
CHANGED
|
@@ -23,3 +23,22 @@ export interface LinkOptions {
|
|
|
23
23
|
}
|
|
24
24
|
export declare function linkDefault(version: string | undefined, opts?: LinkOptions): Promise<LinkResult>;
|
|
25
25
|
export declare function linkOne(linkName: string, version: string | undefined, opts?: LinkOptions): Promise<LinkResult>;
|
|
26
|
+
export type BitxLinkOptions = {
|
|
27
|
+
addToConfig?: boolean;
|
|
28
|
+
addToPathIfMissing?: boolean;
|
|
29
|
+
useSystemNode?: boolean;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Links an installed bitx (the next Bit) version.
|
|
33
|
+
* bitx is a native executable, so the shim runs it directly. Unless `useSystemNode` is set,
|
|
34
|
+
* the shim puts the Node.js that was installed for this bitx version first on the PATH,
|
|
35
|
+
* since bitx runs Node.js for env-related work (compile, test, build, start...).
|
|
36
|
+
*/
|
|
37
|
+
export declare function linkBitx(linkName: string | undefined, version: string, opts?: BitxLinkOptions): Promise<LinkResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Relinks every bitx link that is saved in the config.
|
|
40
|
+
*/
|
|
41
|
+
export declare function linkAllBitx(opts: {
|
|
42
|
+
addToPathIfMissing?: boolean;
|
|
43
|
+
useSystemNode?: boolean;
|
|
44
|
+
}): Promise<LinkResult[]>;
|
package/dist/link.docs.md
CHANGED
|
@@ -9,3 +9,8 @@ Packaged releases may include a native entry at `bin/bit` (`bin/bit.exe` on Wind
|
|
|
9
9
|
Links select that executable when present. Releases without it retain the Node CLI entry.
|
|
10
10
|
The packaged Node CLI and its Node.js runtime remain available for delegated commands.
|
|
11
11
|
An invalid native entry fails linking with a filesystem error.
|
|
12
|
+
|
|
13
|
+
`linkBitx()` links an installed bitx (the next Bit CLI) version from `<bvm dir>/bitx/versions/<version>`.
|
|
14
|
+
The shim runs the native `bin/bitx` directly and puts the Node.js installed for that version first on the `PATH`.
|
|
15
|
+
bitx links are saved under `bitx_links` in the config, and a bitx link can't take the name of a Bit link (or the
|
|
16
|
+
other way around), since both share the links and bin directories.
|
package/dist/link.js
CHANGED
|
@@ -15,6 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.linkAll = linkAll;
|
|
16
16
|
exports.linkDefault = linkDefault;
|
|
17
17
|
exports.linkOne = linkOne;
|
|
18
|
+
exports.linkBitx = linkBitx;
|
|
19
|
+
exports.linkAllBitx = linkAllBitx;
|
|
18
20
|
const os_env_path_extender_1 = require("@pnpm/os.env.path-extender");
|
|
19
21
|
const bvm_config_1 = require("@teambit/bvm.config");
|
|
20
22
|
const bvm_list_1 = require("@teambit/bvm.list");
|
|
@@ -26,6 +28,7 @@ const bvm_error_1 = require("@teambit/bvm.error");
|
|
|
26
28
|
const os_1 = __importDefault(require("os"));
|
|
27
29
|
const semver_1 = __importDefault(require("semver"));
|
|
28
30
|
const link_source_1 = require("./link-source");
|
|
31
|
+
const bitx_link_1 = require("./bitx-link");
|
|
29
32
|
const IS_WINDOWS = os_1.default.platform() === 'win32';
|
|
30
33
|
const DOCS_BASE_URL = 'https://bit.dev/docs';
|
|
31
34
|
const DOCS_REFERENCE_BASE_URL = 'https://bit.dev/reference';
|
|
@@ -79,6 +82,9 @@ function linkOne(linkName_1, version_1) {
|
|
|
79
82
|
if (!exists) {
|
|
80
83
|
throw new bvm_error_1.BvmError(`version ${concreteVersion} is not installed`);
|
|
81
84
|
}
|
|
85
|
+
if (config.getBitxLinks()[linkName]) {
|
|
86
|
+
throw new bvm_error_1.BvmError(`the link name "${linkName}" is used by bitx (the next Bit). choose another link name for Bit`);
|
|
87
|
+
}
|
|
82
88
|
const source = (0, link_source_1.getLinkSource)(versionDir);
|
|
83
89
|
let nodeExecPath;
|
|
84
90
|
const wantedNodeVersion = config.getWantedNodeVersion(versionDir);
|
|
@@ -95,6 +101,37 @@ function linkOne(linkName_1, version_1) {
|
|
|
95
101
|
else if (semver_1.default.lt(process.version, wantedNodeVersion)) {
|
|
96
102
|
warnings.push(`The system Node.js is ${process.version} while Bit CLI requires at least Node.js ${wantedNodeVersion}!`);
|
|
97
103
|
}
|
|
104
|
+
const generatedLink = yield createShim({
|
|
105
|
+
linkName,
|
|
106
|
+
versionDir,
|
|
107
|
+
source,
|
|
108
|
+
nodeExecPath,
|
|
109
|
+
prependToPath: nodeExecPath ? path_1.default.dirname(nodeExecPath) : undefined,
|
|
110
|
+
});
|
|
111
|
+
let previousLinkVersion;
|
|
112
|
+
if (opts.addToConfig) {
|
|
113
|
+
previousLinkVersion = config.setLink(linkName, concreteVersion);
|
|
114
|
+
}
|
|
115
|
+
const { pathExtenderReport, warning } = yield validateBinDirInPath(getBinDir(), opts);
|
|
116
|
+
if (warning) {
|
|
117
|
+
warnings.push(warning);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
linkName,
|
|
121
|
+
previousLinkVersion,
|
|
122
|
+
version: concreteVersion,
|
|
123
|
+
generatedLink,
|
|
124
|
+
pathExtenderReport,
|
|
125
|
+
warnings,
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Points `<bvm dir>/links/<linkName>` at the version directory and writes the
|
|
131
|
+
* `<linkName>` shim (in ~/bin, or in the bvm directory on Windows) that runs `source` from it.
|
|
132
|
+
*/
|
|
133
|
+
function createShim(_a) {
|
|
134
|
+
return __awaiter(this, arguments, void 0, function* ({ linkName, versionDir, source, nodeExecPath, prependToPath }) {
|
|
98
135
|
const pkg = {
|
|
99
136
|
bin: {
|
|
100
137
|
[linkName]: source
|
|
@@ -119,30 +156,81 @@ function linkOne(linkName_1, version_1) {
|
|
|
119
156
|
// so it is better to not use them.
|
|
120
157
|
createPwshFile: false,
|
|
121
158
|
nodeExecPath,
|
|
122
|
-
prependToPath
|
|
159
|
+
prependToPath,
|
|
160
|
+
});
|
|
161
|
+
return generatedLink;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function getBinDir() {
|
|
165
|
+
if (IS_WINDOWS) {
|
|
166
|
+
return config.getBvmDirectory();
|
|
167
|
+
}
|
|
168
|
+
return path_1.default.join(os_1.default.homedir(), 'bin');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Links an installed bitx (the next Bit) version.
|
|
172
|
+
* bitx is a native executable, so the shim runs it directly. Unless `useSystemNode` is set,
|
|
173
|
+
* the shim puts the Node.js that was installed for this bitx version first on the PATH,
|
|
174
|
+
* since bitx runs Node.js for env-related work (compile, test, build, start...).
|
|
175
|
+
*/
|
|
176
|
+
function linkBitx(linkName_1, version_1) {
|
|
177
|
+
return __awaiter(this, arguments, void 0, function* (linkName, version, opts = {}) {
|
|
178
|
+
const concreteLinkName = linkName || config.getBitxLinkName();
|
|
179
|
+
(0, bitx_link_1.validateBitxLinkName)(concreteLinkName, config.getDefaultLinkName(), config.getLinks());
|
|
180
|
+
const { versionDir } = config.getSpecificBitxVersionDir(version);
|
|
181
|
+
const metadata = (0, bitx_link_1.readBitxMetadata)(versionDir);
|
|
182
|
+
if (!metadata) {
|
|
183
|
+
throw new bvm_error_1.BvmError(`bitx version ${version} is not installed`);
|
|
184
|
+
}
|
|
185
|
+
const source = (0, bitx_link_1.getBitxLinkSource)(versionDir);
|
|
186
|
+
const warnings = [];
|
|
187
|
+
let prependToPath;
|
|
188
|
+
if (!opts.useSystemNode && metadata.node) {
|
|
189
|
+
const node = config.getSpecificNodeVersionDir(metadata.node);
|
|
190
|
+
if (!node.exists) {
|
|
191
|
+
throw new bvm_error_1.BvmError(`Node.js version ${metadata.node} is not installed. Try to reinstall bitx with "bvm install --next ${version} --override"`);
|
|
192
|
+
}
|
|
193
|
+
prependToPath = IS_WINDOWS ? node.versionDir : path_1.default.join(node.versionDir, 'bin');
|
|
194
|
+
}
|
|
195
|
+
const generatedLink = yield createShim({
|
|
196
|
+
linkName: concreteLinkName,
|
|
197
|
+
versionDir,
|
|
198
|
+
source,
|
|
199
|
+
prependToPath,
|
|
123
200
|
});
|
|
124
201
|
let previousLinkVersion;
|
|
125
202
|
if (opts.addToConfig) {
|
|
126
|
-
previousLinkVersion = config.
|
|
127
|
-
}
|
|
128
|
-
let binDir = path_1.default.join(os_1.default.homedir(), 'bin');
|
|
129
|
-
if (IS_WINDOWS) {
|
|
130
|
-
binDir = config.getBvmDirectory();
|
|
203
|
+
previousLinkVersion = config.setBitxLink(concreteLinkName, version);
|
|
131
204
|
}
|
|
132
|
-
const { pathExtenderReport, warning } = yield validateBinDirInPath(
|
|
205
|
+
const { pathExtenderReport, warning } = yield validateBinDirInPath(getBinDir(), opts);
|
|
133
206
|
if (warning) {
|
|
134
207
|
warnings.push(warning);
|
|
135
208
|
}
|
|
136
209
|
return {
|
|
137
|
-
linkName,
|
|
210
|
+
linkName: concreteLinkName,
|
|
138
211
|
previousLinkVersion,
|
|
139
|
-
version
|
|
212
|
+
version,
|
|
140
213
|
generatedLink,
|
|
141
214
|
pathExtenderReport,
|
|
142
215
|
warnings,
|
|
143
216
|
};
|
|
144
217
|
});
|
|
145
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Relinks every bitx link that is saved in the config.
|
|
221
|
+
*/
|
|
222
|
+
function linkAllBitx(opts) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
const links = config.getBitxLinks();
|
|
225
|
+
return Promise.all(Object.entries(links).map(([linkName, version]) => {
|
|
226
|
+
return linkBitx(linkName, version, {
|
|
227
|
+
addToConfig: false,
|
|
228
|
+
addToPathIfMissing: opts.addToPathIfMissing,
|
|
229
|
+
useSystemNode: opts.useSystemNode,
|
|
230
|
+
});
|
|
231
|
+
}));
|
|
232
|
+
});
|
|
233
|
+
}
|
|
146
234
|
function validateBinDirInPath(binDir_1) {
|
|
147
235
|
return __awaiter(this, arguments, void 0, function* (binDir, opts = { addToPathIfMissing: true }) {
|
|
148
236
|
const osPaths = (process.env.PATH || process.env.Path || process.env.path).split(path_1.default.delimiter);
|
package/dist/link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sourceRoot":"","sources":["../link.ts"],"names":[],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"link.js","sourceRoot":"","sources":["../link.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAqCA,0BAoBC;AAQD,kCASC;AAED,0BA4DC;AAgED,4BAwCC;AAKD,kCASC;AA9PD,qEAAqH;AACrH,oDAA2C;AAC3C,gDAA4C;AAC5C,iEAAwC;AACxC,gDAAwB;AACxB,8DAAqC;AACrC,0DAAiC;AACjC,kDAA8C;AAC9C,4CAAoB;AACpB,oDAA4B;AAC5B,+CAA8C;AAC9C,2CAAwF;AAExF,MAAM,UAAU,GAAG,YAAE,CAAC,QAAQ,EAAE,KAAK,OAAO,CAAC;AAC7C,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAC7C,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAC5D,MAAM,wCAAwC,GAAG,GAAG,uBAAuB,sCAAsC,CAAC;AAClH,MAAM,0CAA0C,GAAG,GAAG,uBAAuB,sCAAsC,CAAC;AAEpH,MAAM,MAAM,GAAG,mBAAM,CAAC,IAAI,EAAE,CAAC;AAkB7B,SAAsB,OAAO,CAAC,IAA+D;;QAC3F,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAChC,MAAM,kBAAkB,GAAG,MAAM,CAAC,qBAAqB,EAAE,CAAC;QAC1D,MAAM,WAAW,GAAG,CAAC,MAAM,IAAA,oBAAS,GAAE,CAAC,CAAC,MAAM,EAAE,CAAC;QACjD,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAA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AK;oBACf,iBAAiB,EAAE,KAAK;iBACzB,CAAC,CAAC;gBACH,OAAO,EAAE,kBAAkB,EAAE,CAAC;YAChC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,GAAG,CAAC,IAAI,KAAK,wBAAwB,EAAE,CAAC;oBAC1C,OAAO;wBACL,OAAO,EAAE;;KAEd,kBAAkB,CAAC,MAAM,CAAC,EAAE;qBACxB,CAAC;gBACJ,CAAC;gBACD,OAAO;oBACL,OAAO,EAAE,oCAAoC,GAAG,CAAC,OAAO;EAC9D,kBAAkB,CAAC,MAAM,CAAC,EAAE;iBACvB,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;CAAA;AAED,SAAS,kBAAkB,CAAC,MAAc;IACxC,IAAI,UAAU,EAAE,CAAC;QACf,OAAO;oBACS,MAAM;mCACS,wCAAwC,EAAE,CAAC;IAC5E,CAAC;IACD,OAAO;;mCAE0B,0CAA0C,EAAE,CAAC;AAChF,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
;
|
|
2
|
-
import * as overview_0 from '/home/runner/Library/Caches/Bit/capsules/22984e0a6/teambit.bvm_link@1.
|
|
2
|
+
import * as overview_0 from '/home/runner/Library/Caches/Bit/capsules/22984e0a6/teambit.bvm_link@1.2.0/dist/link.docs.md';
|
|
3
3
|
|
|
4
4
|
export const compositions = [];
|
|
5
5
|
export const overview = [overview_0];
|
package/index.ts
CHANGED
package/link.docs.md
CHANGED
|
@@ -9,3 +9,8 @@ Packaged releases may include a native entry at `bin/bit` (`bin/bit.exe` on Wind
|
|
|
9
9
|
Links select that executable when present. Releases without it retain the Node CLI entry.
|
|
10
10
|
The packaged Node CLI and its Node.js runtime remain available for delegated commands.
|
|
11
11
|
An invalid native entry fails linking with a filesystem error.
|
|
12
|
+
|
|
13
|
+
`linkBitx()` links an installed bitx (the next Bit CLI) version from `<bvm dir>/bitx/versions/<version>`.
|
|
14
|
+
The shim runs the native `bin/bitx` directly and puts the Node.js installed for that version first on the `PATH`.
|
|
15
|
+
bitx links are saved under `bitx_links` in the config, and a bitx link can't take the name of a Bit link (or the
|
|
16
|
+
other way around), since both share the links and bin directories.
|
package/link.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { BvmError } from '@teambit/bvm.error';
|
|
|
9
9
|
import os from 'os';
|
|
10
10
|
import semver from 'semver';
|
|
11
11
|
import { getLinkSource } from './link-source';
|
|
12
|
+
import { getBitxLinkSource, readBitxMetadata, validateBitxLinkName } from './bitx-link';
|
|
12
13
|
|
|
13
14
|
const IS_WINDOWS = os.platform() === 'win32';
|
|
14
15
|
const DOCS_BASE_URL = 'https://bit.dev/docs';
|
|
@@ -90,6 +91,9 @@ export async function linkOne(linkName: string, version: string | undefined, opt
|
|
|
90
91
|
if (!exists){
|
|
91
92
|
throw new BvmError(`version ${concreteVersion} is not installed`);
|
|
92
93
|
}
|
|
94
|
+
if (config.getBitxLinks()[linkName]) {
|
|
95
|
+
throw new BvmError(`the link name "${linkName}" is used by bitx (the next Bit). choose another link name for Bit`);
|
|
96
|
+
}
|
|
93
97
|
const source = getLinkSource(versionDir);
|
|
94
98
|
let nodeExecPath: string;
|
|
95
99
|
const wantedNodeVersion = config.getWantedNodeVersion(versionDir);
|
|
@@ -105,6 +109,47 @@ export async function linkOne(linkName: string, version: string | undefined, opt
|
|
|
105
109
|
} else if (semver.lt(process.version, wantedNodeVersion)) {
|
|
106
110
|
warnings.push(`The system Node.js is ${process.version} while Bit CLI requires at least Node.js ${wantedNodeVersion}!`)
|
|
107
111
|
}
|
|
112
|
+
const generatedLink = await createShim({
|
|
113
|
+
linkName,
|
|
114
|
+
versionDir,
|
|
115
|
+
source,
|
|
116
|
+
nodeExecPath,
|
|
117
|
+
prependToPath: nodeExecPath ? path.dirname(nodeExecPath) : undefined,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
let previousLinkVersion;
|
|
121
|
+
if (opts.addToConfig){
|
|
122
|
+
previousLinkVersion = config.setLink(linkName, concreteVersion);
|
|
123
|
+
}
|
|
124
|
+
const { pathExtenderReport, warning } = await validateBinDirInPath(getBinDir(), opts);
|
|
125
|
+
if (warning) {
|
|
126
|
+
warnings.push(warning);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
linkName,
|
|
131
|
+
previousLinkVersion,
|
|
132
|
+
version: concreteVersion,
|
|
133
|
+
generatedLink,
|
|
134
|
+
pathExtenderReport,
|
|
135
|
+
warnings,
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
type CreateShimOpts = {
|
|
140
|
+
linkName: string,
|
|
141
|
+
versionDir: string,
|
|
142
|
+
// relative to versionDir
|
|
143
|
+
source: string,
|
|
144
|
+
nodeExecPath?: string,
|
|
145
|
+
prependToPath?: string,
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Points `<bvm dir>/links/<linkName>` at the version directory and writes the
|
|
150
|
+
* `<linkName>` shim (in ~/bin, or in the bvm directory on Windows) that runs `source` from it.
|
|
151
|
+
*/
|
|
152
|
+
async function createShim({ linkName, versionDir, source, nodeExecPath, prependToPath }: CreateShimOpts): Promise<GeneratedLink> {
|
|
108
153
|
const pkg = {
|
|
109
154
|
bin: {
|
|
110
155
|
[linkName]: source
|
|
@@ -129,30 +174,84 @@ export async function linkOne(linkName: string, version: string | undefined, opt
|
|
|
129
174
|
// so it is better to not use them.
|
|
130
175
|
createPwshFile: false,
|
|
131
176
|
nodeExecPath,
|
|
132
|
-
prependToPath
|
|
177
|
+
prependToPath,
|
|
133
178
|
});
|
|
179
|
+
return generatedLink;
|
|
180
|
+
}
|
|
134
181
|
|
|
135
|
-
|
|
136
|
-
if (opts.addToConfig){
|
|
137
|
-
previousLinkVersion = config.setLink(linkName, concreteVersion);
|
|
138
|
-
}
|
|
139
|
-
let binDir = path.join(os.homedir(), 'bin');
|
|
182
|
+
function getBinDir(): string {
|
|
140
183
|
if (IS_WINDOWS){
|
|
141
|
-
|
|
184
|
+
return config.getBvmDirectory();
|
|
185
|
+
}
|
|
186
|
+
return path.join(os.homedir(), 'bin');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export type BitxLinkOptions = {
|
|
190
|
+
addToConfig?: boolean
|
|
191
|
+
addToPathIfMissing?: boolean
|
|
192
|
+
useSystemNode?: boolean
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Links an installed bitx (the next Bit) version.
|
|
197
|
+
* bitx is a native executable, so the shim runs it directly. Unless `useSystemNode` is set,
|
|
198
|
+
* the shim puts the Node.js that was installed for this bitx version first on the PATH,
|
|
199
|
+
* since bitx runs Node.js for env-related work (compile, test, build, start...).
|
|
200
|
+
*/
|
|
201
|
+
export async function linkBitx(linkName: string | undefined, version: string, opts: BitxLinkOptions = {}): Promise<LinkResult> {
|
|
202
|
+
const concreteLinkName = linkName || config.getBitxLinkName();
|
|
203
|
+
validateBitxLinkName(concreteLinkName, config.getDefaultLinkName(), config.getLinks());
|
|
204
|
+
const { versionDir } = config.getSpecificBitxVersionDir(version);
|
|
205
|
+
const metadata = readBitxMetadata(versionDir);
|
|
206
|
+
if (!metadata) {
|
|
207
|
+
throw new BvmError(`bitx version ${version} is not installed`);
|
|
208
|
+
}
|
|
209
|
+
const source = getBitxLinkSource(versionDir);
|
|
210
|
+
const warnings: string[] = [];
|
|
211
|
+
let prependToPath: string | undefined;
|
|
212
|
+
if (!opts.useSystemNode && metadata.node) {
|
|
213
|
+
const node = config.getSpecificNodeVersionDir(metadata.node);
|
|
214
|
+
if (!node.exists) {
|
|
215
|
+
throw new BvmError(`Node.js version ${metadata.node} is not installed. Try to reinstall bitx with "bvm install --next ${version} --override"`);
|
|
216
|
+
}
|
|
217
|
+
prependToPath = IS_WINDOWS ? node.versionDir : path.join(node.versionDir, 'bin');
|
|
142
218
|
}
|
|
143
|
-
const
|
|
219
|
+
const generatedLink = await createShim({
|
|
220
|
+
linkName: concreteLinkName,
|
|
221
|
+
versionDir,
|
|
222
|
+
source,
|
|
223
|
+
prependToPath,
|
|
224
|
+
});
|
|
225
|
+
let previousLinkVersion;
|
|
226
|
+
if (opts.addToConfig) {
|
|
227
|
+
previousLinkVersion = config.setBitxLink(concreteLinkName, version);
|
|
228
|
+
}
|
|
229
|
+
const { pathExtenderReport, warning } = await validateBinDirInPath(getBinDir(), opts);
|
|
144
230
|
if (warning) {
|
|
145
231
|
warnings.push(warning);
|
|
146
232
|
}
|
|
147
|
-
|
|
148
233
|
return {
|
|
149
|
-
linkName,
|
|
234
|
+
linkName: concreteLinkName,
|
|
150
235
|
previousLinkVersion,
|
|
151
|
-
version
|
|
236
|
+
version,
|
|
152
237
|
generatedLink,
|
|
153
238
|
pathExtenderReport,
|
|
154
239
|
warnings,
|
|
155
|
-
}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Relinks every bitx link that is saved in the config.
|
|
245
|
+
*/
|
|
246
|
+
export async function linkAllBitx(opts: { addToPathIfMissing?: boolean, useSystemNode?: boolean }): Promise<LinkResult[]> {
|
|
247
|
+
const links = config.getBitxLinks();
|
|
248
|
+
return Promise.all(Object.entries(links).map(([linkName, version]) => {
|
|
249
|
+
return linkBitx(linkName, version, {
|
|
250
|
+
addToConfig: false,
|
|
251
|
+
addToPathIfMissing: opts.addToPathIfMissing,
|
|
252
|
+
useSystemNode: opts.useSystemNode,
|
|
253
|
+
});
|
|
254
|
+
}));
|
|
156
255
|
}
|
|
157
256
|
|
|
158
257
|
async function validateBinDirInPath(binDir: string, opts: { addToPathIfMissing?: boolean } = { addToPathIfMissing: true }): Promise<{ pathExtenderReport?: PathExtenderReport | undefined, warning?: string }> {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/bvm.link",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/bvm/link",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.bvm",
|
|
8
8
|
"name": "link",
|
|
9
|
-
"version": "1.
|
|
9
|
+
"version": "1.2.0"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"fs-extra": "9.1.0",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"symlink-dir": "^5.1.1",
|
|
17
17
|
"@teambit/bvm.error": "1.0.0",
|
|
18
18
|
"@pnpm/os.env.path-extender": "2.0.3",
|
|
19
|
-
"@teambit/bvm.config": "1.0
|
|
20
|
-
"@teambit/bvm.list": "1.1.
|
|
19
|
+
"@teambit/bvm.config": "1.1.0",
|
|
20
|
+
"@teambit/bvm.list": "1.1.5"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/fs-extra": "9.0.7",
|