@teambit/mover 1.0.185 → 1.0.187
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/artifacts/__bit_junit.xml +1 -1
- package/artifacts/schema.json +105 -1
- package/dist/mover.main.runtime.d.ts +1 -0
- package/dist/mover.main.runtime.js +22 -8
- package/dist/mover.main.runtime.js.map +1 -1
- package/package.json +4 -4
- /package/dist/{preview-1709695009203.js → preview-1709867881461.js} +0 -0
@@ -1,4 +1,4 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<testsuites tests="0" failures="0" errors="0" skipped="0">
|
3
|
-
<testsuite name="teambit.component/mover@1.0.
|
3
|
+
<testsuite name="teambit.component/mover@1.0.187" tests="0" failures="0" errors="0" skipped="0"/>
|
4
4
|
</testsuites>
|
package/artifacts/schema.json
CHANGED
@@ -892,6 +892,110 @@
|
|
892
892
|
},
|
893
893
|
"name": "MoverMain",
|
894
894
|
"type": "Identifier"
|
895
|
+
},
|
896
|
+
{
|
897
|
+
"__schema": "FunctionLikeSchema",
|
898
|
+
"location": {
|
899
|
+
"filePath": "mover.main.runtime.ts",
|
900
|
+
"line": 88,
|
901
|
+
"character": 1
|
902
|
+
},
|
903
|
+
"signature": "function moveSync(src: PathOsBasedAbsolute, dest: PathOsBasedAbsolute, options?: Record<string, any>): void",
|
904
|
+
"name": "moveSync",
|
905
|
+
"params": [
|
906
|
+
{
|
907
|
+
"__schema": "ParameterSchema",
|
908
|
+
"location": {
|
909
|
+
"filePath": "mover.main.runtime.ts",
|
910
|
+
"line": 88,
|
911
|
+
"character": 26
|
912
|
+
},
|
913
|
+
"name": "src",
|
914
|
+
"type": {
|
915
|
+
"__schema": "TypeRefSchema",
|
916
|
+
"location": {
|
917
|
+
"filePath": "mover.main.runtime.ts",
|
918
|
+
"line": 88,
|
919
|
+
"character": 31
|
920
|
+
},
|
921
|
+
"name": "PathOsBasedAbsolute"
|
922
|
+
},
|
923
|
+
"isOptional": false,
|
924
|
+
"isSpread": false
|
925
|
+
},
|
926
|
+
{
|
927
|
+
"__schema": "ParameterSchema",
|
928
|
+
"location": {
|
929
|
+
"filePath": "mover.main.runtime.ts",
|
930
|
+
"line": 88,
|
931
|
+
"character": 52
|
932
|
+
},
|
933
|
+
"name": "dest",
|
934
|
+
"type": {
|
935
|
+
"__schema": "TypeRefSchema",
|
936
|
+
"location": {
|
937
|
+
"filePath": "mover.main.runtime.ts",
|
938
|
+
"line": 88,
|
939
|
+
"character": 58
|
940
|
+
},
|
941
|
+
"name": "PathOsBasedAbsolute"
|
942
|
+
},
|
943
|
+
"isOptional": false,
|
944
|
+
"isSpread": false
|
945
|
+
},
|
946
|
+
{
|
947
|
+
"__schema": "ParameterSchema",
|
948
|
+
"location": {
|
949
|
+
"filePath": "mover.main.runtime.ts",
|
950
|
+
"line": 88,
|
951
|
+
"character": 79
|
952
|
+
},
|
953
|
+
"name": "options",
|
954
|
+
"type": {
|
955
|
+
"__schema": "TypeRefSchema",
|
956
|
+
"location": {
|
957
|
+
"filePath": "mover.main.runtime.ts",
|
958
|
+
"line": 88,
|
959
|
+
"character": 89
|
960
|
+
},
|
961
|
+
"name": "Record",
|
962
|
+
"typeArgs": [
|
963
|
+
{
|
964
|
+
"__schema": "KeywordTypeSchema",
|
965
|
+
"location": {
|
966
|
+
"filePath": "mover.main.runtime.ts",
|
967
|
+
"line": 88,
|
968
|
+
"character": 96
|
969
|
+
},
|
970
|
+
"name": "string"
|
971
|
+
},
|
972
|
+
{
|
973
|
+
"__schema": "KeywordTypeSchema",
|
974
|
+
"location": {
|
975
|
+
"filePath": "mover.main.runtime.ts",
|
976
|
+
"line": 88,
|
977
|
+
"character": 104
|
978
|
+
},
|
979
|
+
"name": "any"
|
980
|
+
}
|
981
|
+
]
|
982
|
+
},
|
983
|
+
"isOptional": true,
|
984
|
+
"isSpread": false
|
985
|
+
}
|
986
|
+
],
|
987
|
+
"returnType": {
|
988
|
+
"__schema": "InferenceTypeSchema",
|
989
|
+
"location": {
|
990
|
+
"filePath": "mover.main.runtime.ts",
|
991
|
+
"line": 88,
|
992
|
+
"character": 1
|
993
|
+
},
|
994
|
+
"type": "void"
|
995
|
+
},
|
996
|
+
"modifiers": [
|
997
|
+
"export"
|
998
|
+
]
|
895
999
|
}
|
896
1000
|
],
|
897
1001
|
"internals": [
|
@@ -948,7 +1052,7 @@
|
|
948
1052
|
"componentId": {
|
949
1053
|
"scope": "teambit.component",
|
950
1054
|
"name": "mover",
|
951
|
-
"version": "1.0.
|
1055
|
+
"version": "1.0.187"
|
952
1056
|
},
|
953
1057
|
"taggedModuleExports": []
|
954
1058
|
}
|
@@ -17,3 +17,4 @@ export declare class MoverMain {
|
|
17
17
|
static provider([cli, workspace]: [CLIMain, Workspace]): Promise<MoverMain>;
|
18
18
|
}
|
19
19
|
export default MoverMain;
|
20
|
+
export declare function moveSync(src: PathOsBasedAbsolute, dest: PathOsBasedAbsolute, options?: Record<string, any>): void;
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = exports.MoverMain = void 0;
|
7
|
+
exports.moveSync = moveSync;
|
7
8
|
function _fsExtra() {
|
8
9
|
const data = _interopRequireDefault(require("fs-extra"));
|
9
10
|
_fsExtra = function () {
|
@@ -11,6 +12,13 @@ function _fsExtra() {
|
|
11
12
|
};
|
12
13
|
return data;
|
13
14
|
}
|
15
|
+
function _path() {
|
16
|
+
const data = require("path");
|
17
|
+
_path = function () {
|
18
|
+
return data;
|
19
|
+
};
|
20
|
+
return data;
|
21
|
+
}
|
14
22
|
function _bitError() {
|
15
23
|
const data = require("@teambit/bit-error");
|
16
24
|
_bitError = function () {
|
@@ -46,13 +54,6 @@ function _utils() {
|
|
46
54
|
};
|
47
55
|
return data;
|
48
56
|
}
|
49
|
-
function _moveSync() {
|
50
|
-
const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/fs/move-sync"));
|
51
|
-
_moveSync = function () {
|
52
|
-
return data;
|
53
|
-
};
|
54
|
-
return data;
|
55
|
-
}
|
56
57
|
function _workspaceModules() {
|
57
58
|
const data = require("@teambit/workspace.modules.node-modules-linker");
|
58
59
|
_workspaceModules = function () {
|
@@ -115,7 +116,7 @@ to change the main-file, use "bit add <component-dir> --main <new-main-file>"`);
|
|
115
116
|
const changes = consumer.bitMap.updatePathLocation(fromRelative, toRelative);
|
116
117
|
if (fromExists && !toExists) {
|
117
118
|
// user would like to physically move the file. Otherwise (!fromExists and toExists), user would like to only update bit.map
|
118
|
-
(
|
119
|
+
moveSync(fromAbsolute, toAbsolute);
|
119
120
|
}
|
120
121
|
if (!(0, _lodash().isEmpty)(changes)) {
|
121
122
|
const componentsIds = changes.map(c => c.id);
|
@@ -157,5 +158,18 @@ _defineProperty(MoverMain, "dependencies", [_cli().CLIAspect, _workspace().Works
|
|
157
158
|
_defineProperty(MoverMain, "runtime", _cli().MainRuntime);
|
158
159
|
_mover().MoverAspect.addRuntime(MoverMain);
|
159
160
|
var _default = exports.default = MoverMain;
|
161
|
+
function moveSync(src, dest, options) {
|
162
|
+
if (!(0, _path().isAbsolute)(src) || !(0, _path().isAbsolute)(dest)) {
|
163
|
+
throw new Error(`moveSync, src and dest must be absolute. Got src "${src}", dest "${dest}"`);
|
164
|
+
}
|
165
|
+
try {
|
166
|
+
_fsExtra().default.moveSync(src, dest, options);
|
167
|
+
} catch (err) {
|
168
|
+
if (err.message.includes('Cannot move') && err.message.includes('into itself')) {
|
169
|
+
throw new (_bitError().BitError)(`unable to move '${src}' into itself '${dest}'`);
|
170
|
+
}
|
171
|
+
throw err;
|
172
|
+
}
|
173
|
+
}
|
160
174
|
|
161
175
|
//# sourceMappingURL=mover.main.runtime.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_bitError","_cli","_lodash","_workspace","_utils","_moveSync","_workspaceModules","_removePath","_mover","_moveCmd","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","MoverMain","constructor","workspace","movePaths","from","to","consumer","fromExists","fs","existsSync","toExists","BitError","isDir","fromRelative","getPathRelativeToConsumer","toRelative","fromAbsolute","toAbsolutePath","toAbsolute","changes","bitMap","updatePathLocation","moveSync","isEmpty","componentsIds","map","c","id","linkToNodeModulesByIds","write","moveExistingComponent","component","oldPath","newPath","toString","componentMap","getComponent","oldPathRelative","newPathRelative","updateDirLocation","markAsChanged","dataToPersist","files","forEach","file","newRelative","relative","replace","updatePaths","newBase","removePath","RemovePath","writtenPath","provider","cli","moverMain","register","MoveCmd","exports","CLIAspect","WorkspaceAspect","MainRuntime","MoverAspect","addRuntime","_default"],"sources":["mover.main.runtime.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport { BitError } from '@teambit/bit-error';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { isEmpty } from 'lodash';\nimport { WorkspaceAspect, Workspace } from '@teambit/workspace';\nimport { isDir } from '@teambit/legacy/dist/utils';\nimport moveSync from '@teambit/legacy/dist/utils/fs/move-sync';\nimport { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';\nimport { linkToNodeModulesByIds } from '@teambit/workspace.modules.node-modules-linker';\nimport { PathChangeResult } from '@teambit/legacy/dist/consumer/bit-map/bit-map';\nimport Component from '@teambit/legacy/dist/consumer/component/consumer-component';\nimport RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';\nimport { MoverAspect } from './mover.aspect';\nimport { MoveCmd } from './move-cmd';\n\nexport class MoverMain {\n constructor(private workspace: Workspace) {}\n\n async movePaths({ from, to }: { from: PathOsBasedRelative; to: PathOsBasedRelative }): Promise<PathChangeResult[]> {\n const consumer = this.workspace.consumer;\n const fromExists = fs.existsSync(from);\n const toExists = fs.existsSync(to);\n if (fromExists && toExists) {\n throw new BitError(`unable to move because both paths from (${from}) and to (${to}) already exist`);\n }\n if (!fromExists && !toExists) throw new BitError(`both paths from (${from}) and to (${to}) do not exist`);\n if (fromExists && !isDir(from)) {\n throw new BitError(`bit move supports moving directories only, not files.\nfiles withing a component dir are automatically tracked, no action is needed.\nto change the main-file, use \"bit add <component-dir> --main <new-main-file>\"`);\n }\n if (toExists && !isDir(to)) {\n throw new BitError(`unable to move because the destination path (${to}) is a file and not a directory`);\n }\n const fromRelative = consumer.getPathRelativeToConsumer(from);\n const toRelative = consumer.getPathRelativeToConsumer(to);\n const fromAbsolute = consumer.toAbsolutePath(fromRelative);\n const toAbsolute = consumer.toAbsolutePath(toRelative);\n const changes = consumer.bitMap.updatePathLocation(fromRelative, toRelative);\n if (fromExists && !toExists) {\n // user would like to physically move the file. Otherwise (!fromExists and toExists), user would like to only update bit.map\n moveSync(fromAbsolute, toAbsolute);\n }\n if (!isEmpty(changes)) {\n const componentsIds = changes.map((c) => c.id);\n await linkToNodeModulesByIds(this.workspace, componentsIds);\n }\n await this.workspace.bitMap.write('move');\n return changes;\n }\n\n moveExistingComponent(component: Component, oldPath: PathOsBasedAbsolute, newPath: PathOsBasedAbsolute) {\n const consumer = this.workspace.consumer;\n if (fs.existsSync(newPath)) {\n throw new BitError(\n `could not move the component ${component.id.toString()} from ${oldPath} to ${newPath} as the destination path already exists`\n );\n }\n const componentMap = consumer.bitMap.getComponent(component.id);\n const oldPathRelative = consumer.getPathRelativeToConsumer(oldPath);\n const newPathRelative = consumer.getPathRelativeToConsumer(newPath);\n componentMap.updateDirLocation(oldPathRelative, newPathRelative);\n consumer.bitMap.markAsChanged();\n component.dataToPersist.files.forEach((file) => {\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const newRelative = file.relative.replace(oldPathRelative, newPathRelative);\n file.updatePaths({ newRelative, newBase: newPathRelative });\n });\n component.dataToPersist.removePath(new RemovePath(oldPathRelative));\n component.writtenPath = newPathRelative;\n }\n\n static slots = [];\n static dependencies = [CLIAspect, WorkspaceAspect];\n static runtime = MainRuntime;\n\n static async provider([cli, workspace]: [CLIMain, Workspace]) {\n const moverMain = new MoverMain(workspace);\n cli.register(new MoveCmd(moverMain));\n return moverMain;\n }\n}\n\nMoverAspect.addRuntime(MoverMain);\n\nexport default MoverMain;\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,UAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,KAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,IAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,QAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,OAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,WAAA;EAAA,MAAAN,IAAA,GAAAE,OAAA;EAAAI,UAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,OAAA;EAAA,MAAAP,IAAA,GAAAE,OAAA;EAAAK,MAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAQ,UAAA;EAAA,MAAAR,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAM,SAAA,YAAAA,CAAA;IAAA,OAAAR,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAS,kBAAA;EAAA,MAAAT,IAAA,GAAAE,OAAA;EAAAO,iBAAA,YAAAA,CAAA;IAAA,OAAAT,IAAA;EAAA;EAA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AAI,CAACE,QAAQ,CAACC,OAAO,CAACV,eAAe,EAAEC,eAAe,CAAC;MAC3EM,IAAI,CAACI,WAAW,CAAC;QAAEH,WAAW;QAAEI,OAAO,EAAEX;MAAgB,CAAC,CAAC;IAC7D,CAAC,CAAC;IACFP,SAAS,CAACU,aAAa,CAACS,UAAU,CAAC,KAAIC,qBAAU,EAACd,eAAe,CAAC,CAAC;IACnEN,SAAS,CAACqB,WAAW,GAAGd,eAAe;EACzC;EAMA,aAAae,QAAQA,CAAC,CAACC,GAAG,EAAEpD,SAAS,CAAuB,EAAE;IAC5D,MAAMqD,SAAS,GAAG,IAAIvD,SAAS,CAACE,SAAS,CAAC;IAC1CoD,GAAG,CAACE,QAAQ,CAAC,KAAIC,kBAAO,EAACF,SAAS,CAAC,CAAC;IACpC,OAAOA,SAAS;EAClB;AACF;AAACG,OAAA,CAAA1D,SAAA,GAAAA,SAAA;AAAApB,eAAA,CAlEYoB,SAAS,WAyDL,EAAE;AAAApB,eAAA,CAzDNoB,SAAS,kBA0DE,CAAC2D,gBAAS,EAAEC,4BAAe,CAAC;AAAAhF,eAAA,CA1DvCoB,SAAS,aA2DH6D,kBAAW;AAS9BC,oBAAW,CAACC,UAAU,CAAC/D,SAAS,CAAC;AAAC,IAAAgE,QAAA,GAAAN,OAAA,CAAA/E,OAAA,GAEnBqB,SAAS"}
|
1
|
+
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_path","_bitError","_cli","_lodash","_workspace","_utils","_workspaceModules","_removePath","_mover","_moveCmd","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","MoverMain","constructor","workspace","movePaths","from","to","consumer","fromExists","fs","existsSync","toExists","BitError","isDir","fromRelative","getPathRelativeToConsumer","toRelative","fromAbsolute","toAbsolutePath","toAbsolute","changes","bitMap","updatePathLocation","moveSync","isEmpty","componentsIds","map","c","id","linkToNodeModulesByIds","write","moveExistingComponent","component","oldPath","newPath","toString","componentMap","getComponent","oldPathRelative","newPathRelative","updateDirLocation","markAsChanged","dataToPersist","files","forEach","file","newRelative","relative","replace","updatePaths","newBase","removePath","RemovePath","writtenPath","provider","cli","moverMain","register","MoveCmd","exports","CLIAspect","WorkspaceAspect","MainRuntime","MoverAspect","addRuntime","_default","src","dest","options","isAbsolute","Error","err","message","includes"],"sources":["mover.main.runtime.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport { isAbsolute } from 'path';\nimport { BitError } from '@teambit/bit-error';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { isEmpty } from 'lodash';\nimport { WorkspaceAspect, Workspace } from '@teambit/workspace';\nimport { isDir } from '@teambit/legacy/dist/utils';\nimport { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';\nimport { linkToNodeModulesByIds } from '@teambit/workspace.modules.node-modules-linker';\nimport { PathChangeResult } from '@teambit/legacy/dist/consumer/bit-map/bit-map';\nimport Component from '@teambit/legacy/dist/consumer/component/consumer-component';\nimport RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';\nimport { MoverAspect } from './mover.aspect';\nimport { MoveCmd } from './move-cmd';\n\nexport class MoverMain {\n constructor(private workspace: Workspace) {}\n\n async movePaths({ from, to }: { from: PathOsBasedRelative; to: PathOsBasedRelative }): Promise<PathChangeResult[]> {\n const consumer = this.workspace.consumer;\n const fromExists = fs.existsSync(from);\n const toExists = fs.existsSync(to);\n if (fromExists && toExists) {\n throw new BitError(`unable to move because both paths from (${from}) and to (${to}) already exist`);\n }\n if (!fromExists && !toExists) throw new BitError(`both paths from (${from}) and to (${to}) do not exist`);\n if (fromExists && !isDir(from)) {\n throw new BitError(`bit move supports moving directories only, not files.\nfiles withing a component dir are automatically tracked, no action is needed.\nto change the main-file, use \"bit add <component-dir> --main <new-main-file>\"`);\n }\n if (toExists && !isDir(to)) {\n throw new BitError(`unable to move because the destination path (${to}) is a file and not a directory`);\n }\n const fromRelative = consumer.getPathRelativeToConsumer(from);\n const toRelative = consumer.getPathRelativeToConsumer(to);\n const fromAbsolute = consumer.toAbsolutePath(fromRelative);\n const toAbsolute = consumer.toAbsolutePath(toRelative);\n const changes = consumer.bitMap.updatePathLocation(fromRelative, toRelative);\n if (fromExists && !toExists) {\n // user would like to physically move the file. Otherwise (!fromExists and toExists), user would like to only update bit.map\n moveSync(fromAbsolute, toAbsolute);\n }\n if (!isEmpty(changes)) {\n const componentsIds = changes.map((c) => c.id);\n await linkToNodeModulesByIds(this.workspace, componentsIds);\n }\n await this.workspace.bitMap.write('move');\n return changes;\n }\n\n moveExistingComponent(component: Component, oldPath: PathOsBasedAbsolute, newPath: PathOsBasedAbsolute) {\n const consumer = this.workspace.consumer;\n if (fs.existsSync(newPath)) {\n throw new BitError(\n `could not move the component ${component.id.toString()} from ${oldPath} to ${newPath} as the destination path already exists`\n );\n }\n const componentMap = consumer.bitMap.getComponent(component.id);\n const oldPathRelative = consumer.getPathRelativeToConsumer(oldPath);\n const newPathRelative = consumer.getPathRelativeToConsumer(newPath);\n componentMap.updateDirLocation(oldPathRelative, newPathRelative);\n consumer.bitMap.markAsChanged();\n component.dataToPersist.files.forEach((file) => {\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const newRelative = file.relative.replace(oldPathRelative, newPathRelative);\n file.updatePaths({ newRelative, newBase: newPathRelative });\n });\n component.dataToPersist.removePath(new RemovePath(oldPathRelative));\n component.writtenPath = newPathRelative;\n }\n\n static slots = [];\n static dependencies = [CLIAspect, WorkspaceAspect];\n static runtime = MainRuntime;\n\n static async provider([cli, workspace]: [CLIMain, Workspace]) {\n const moverMain = new MoverMain(workspace);\n cli.register(new MoveCmd(moverMain));\n return moverMain;\n }\n}\n\nMoverAspect.addRuntime(MoverMain);\n\nexport default MoverMain;\n\nexport function moveSync(src: PathOsBasedAbsolute, dest: PathOsBasedAbsolute, options?: Record<string, any>) {\n if (!isAbsolute(src) || !isAbsolute(dest)) {\n throw new Error(`moveSync, src and dest must be absolute. Got src \"${src}\", dest \"${dest}\"`);\n }\n try {\n fs.moveSync(src, dest, options);\n } catch (err: any) {\n if (err.message.includes('Cannot move') && err.message.includes('into itself')) {\n throw new BitError(`unable to move '${src}' into itself '${dest}'`);\n }\n throw err;\n }\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,MAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,KAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,UAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,SAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,KAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,IAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,QAAA;EAAA,MAAAN,IAAA,GAAAE,OAAA;EAAAI,OAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,WAAA;EAAA,MAAAP,IAAA,GAAAE,OAAA;EAAAK,UAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAQ,OAAA;EAAA,MAAAR,IAAA,GAAAE,OAAA;EAAAM,MAAA,YAAAA,CAAA;IAAA,OAAAR,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAS,kBAAA;EAAA,MAAAT,IAAA,GAAAE,OAAA;EAAAO,iBAAA,YAAAA,CAAA;IAAA,OAA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,IAAIA,GAAG,CAACC,OAAO,CAACC,QAAQ,CAAC,aAAa,CAAC,IAAIF,GAAG,CAACC,OAAO,CAACC,QAAQ,CAAC,aAAa,CAAC,EAAE;MAC9E,MAAM,KAAI7D,oBAAQ,EAAE,mBAAkBsD,GAAI,kBAAiBC,IAAK,GAAE,CAAC;IACrE;IACA,MAAMI,GAAG;EACX;AACF"}
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/mover",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.187",
|
4
4
|
"homepage": "https://bit.cloud/teambit/component/mover",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.component",
|
8
8
|
"name": "mover",
|
9
|
-
"version": "1.0.
|
9
|
+
"version": "1.0.187"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"chalk": "2.4.2",
|
@@ -14,9 +14,9 @@
|
|
14
14
|
"lodash": "4.17.21",
|
15
15
|
"@teambit/harmony": "0.4.6",
|
16
16
|
"@teambit/bit-error": "0.0.404",
|
17
|
-
"@teambit/cli": "0.0.
|
17
|
+
"@teambit/cli": "0.0.855",
|
18
18
|
"@teambit/workspace.modules.node-modules-linker": "0.0.165",
|
19
|
-
"@teambit/workspace": "1.0.
|
19
|
+
"@teambit/workspace": "1.0.187"
|
20
20
|
},
|
21
21
|
"devDependencies": {
|
22
22
|
"@types/fs-extra": "9.0.7",
|
File without changes
|