@teambit/mover 1.0.107 → 1.0.108

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.
@@ -13,7 +13,7 @@ export declare class MoveCmd implements Command {
13
13
  extendedDescription: string;
14
14
  alias: string;
15
15
  loader: boolean;
16
- options: never[];
16
+ options: any[];
17
17
  constructor(mover: MoverMain);
18
18
  report([from, to]: [string, string]): Promise<string>;
19
19
  }
@@ -11,7 +11,7 @@ export declare class MoverMain {
11
11
  to: PathOsBasedRelative;
12
12
  }): Promise<PathChangeResult[]>;
13
13
  moveExistingComponent(component: Component, oldPath: PathOsBasedAbsolute, newPath: PathOsBasedAbsolute): void;
14
- static slots: never[];
14
+ static slots: any[];
15
15
  static dependencies: import("@teambit/harmony").Aspect[];
16
16
  static runtime: import("@teambit/harmony").RuntimeDefinition;
17
17
  static provider([cli, workspace]: [CLIMain, Workspace]): Promise<MoverMain>;
package/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { MoverAspect } from './mover.aspect';
2
+
3
+ export type { MoverMain } from './mover.main.runtime';
4
+ export default MoverAspect;
5
+ export { MoverAspect };
package/move-cmd.ts ADDED
@@ -0,0 +1,40 @@
1
+ import chalk from 'chalk';
2
+ import { Command } from '@teambit/cli';
3
+ import { PathChangeResult } from '@teambit/legacy/dist/consumer/bit-map/bit-map';
4
+ import { MoverMain } from './mover.main.runtime';
5
+
6
+ export class MoveCmd implements Command {
7
+ name = 'move <current-component-dir> <new-component-dir>';
8
+ description =
9
+ "move a component to a different filesystem path (note: this does NOT affect the component's name or scope, just its location in the workspace)";
10
+ helpUrl = 'reference/workspace/moving-components';
11
+ arguments = [
12
+ {
13
+ name: 'current-component-dir',
14
+ description: "the component's current directory (relative to the workspace root)",
15
+ },
16
+ {
17
+ name: 'new-component-dir',
18
+ description: "the new directory (relative to the workspace root) to create and move the component's files to",
19
+ },
20
+ ];
21
+ group = 'development';
22
+ extendedDescription = `move files or directories of component(s)\n`;
23
+ alias = 'mv';
24
+ loader = true;
25
+ options = [];
26
+
27
+ constructor(private mover: MoverMain) {}
28
+
29
+ async report([from, to]: [string, string]) {
30
+ const componentsChanged: PathChangeResult[] = await this.mover.movePaths({ from, to });
31
+ const output = componentsChanged.map((component) => {
32
+ const title = chalk.green(`moved component ${component.id.toString()}:\n`);
33
+ const files = component.changes
34
+ .map((file) => `from ${chalk.bold(file.from)} to ${chalk.bold(file.to)}`)
35
+ .join('\n');
36
+ return title + files;
37
+ });
38
+ return output.join('\n');
39
+ }
40
+ }
@@ -0,0 +1,5 @@
1
+ import { Aspect } from '@teambit/harmony';
2
+
3
+ export const MoverAspect = Aspect.create({
4
+ id: 'teambit.component/mover',
5
+ });
@@ -0,0 +1,85 @@
1
+ import fs from 'fs-extra';
2
+ import { BitError } from '@teambit/bit-error';
3
+ import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
4
+ import WorkspaceAspect, { Workspace } from '@teambit/workspace';
5
+ import R from 'ramda';
6
+ import GeneralError from '@teambit/legacy/dist/error/general-error';
7
+ import { isDir } from '@teambit/legacy/dist/utils';
8
+ import moveSync from '@teambit/legacy/dist/utils/fs/move-sync';
9
+ import { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';
10
+ import { linkToNodeModulesByIds } from '@teambit/workspace.modules.node-modules-linker';
11
+ import { PathChangeResult } from '@teambit/legacy/dist/consumer/bit-map/bit-map';
12
+ import Component from '@teambit/legacy/dist/consumer/component/consumer-component';
13
+ import RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';
14
+ import { MoverAspect } from './mover.aspect';
15
+ import { MoveCmd } from './move-cmd';
16
+
17
+ export class MoverMain {
18
+ constructor(private workspace: Workspace) {}
19
+
20
+ async movePaths({ from, to }: { from: PathOsBasedRelative; to: PathOsBasedRelative }): Promise<PathChangeResult[]> {
21
+ const consumer = await this.workspace.consumer;
22
+ const fromExists = fs.existsSync(from);
23
+ const toExists = fs.existsSync(to);
24
+ if (fromExists && toExists) {
25
+ throw new BitError(`unable to move because both paths from (${from}) and to (${to}) already exist`);
26
+ }
27
+ if (!fromExists && !toExists) throw new GeneralError(`both paths from (${from}) and to (${to}) do not exist`);
28
+ if (!consumer.isLegacy && fromExists && !isDir(from)) {
29
+ throw new BitError(`bit move supports moving directories only, not files.
30
+ files withing a component dir are automatically tracked, no action is needed.
31
+ to change the main-file, use "bit add <component-dir> --main <new-main-file>"`);
32
+ }
33
+ const fromRelative = consumer.getPathRelativeToConsumer(from);
34
+ const toRelative = consumer.getPathRelativeToConsumer(to);
35
+ const fromAbsolute = consumer.toAbsolutePath(fromRelative);
36
+ const toAbsolute = consumer.toAbsolutePath(toRelative);
37
+ const existingPath = fromExists ? fromAbsolute : toAbsolute;
38
+ const changes = consumer.bitMap.updatePathLocation(fromRelative, toRelative, existingPath);
39
+ if (fromExists && !toExists) {
40
+ // user would like to physically move the file. Otherwise (!fromExists and toExists), user would like to only update bit.map
41
+ moveSync(fromAbsolute, toAbsolute);
42
+ }
43
+ if (!R.isEmpty(changes)) {
44
+ const componentsIds = changes.map((c) => c.id);
45
+ await linkToNodeModulesByIds(this.workspace, componentsIds);
46
+ }
47
+ await this.workspace.bitMap.write('move');
48
+ return changes;
49
+ }
50
+
51
+ moveExistingComponent(component: Component, oldPath: PathOsBasedAbsolute, newPath: PathOsBasedAbsolute) {
52
+ const consumer = this.workspace.consumer;
53
+ if (fs.existsSync(newPath)) {
54
+ throw new GeneralError(
55
+ `could not move the component ${component.id.toString()} from ${oldPath} to ${newPath} as the destination path already exists`
56
+ );
57
+ }
58
+ const componentMap = consumer.bitMap.getComponent(component.id);
59
+ const oldPathRelative = consumer.getPathRelativeToConsumer(oldPath);
60
+ const newPathRelative = consumer.getPathRelativeToConsumer(newPath);
61
+ componentMap.updateDirLocation(oldPathRelative, newPathRelative);
62
+ consumer.bitMap.markAsChanged();
63
+ component.dataToPersist.files.forEach((file) => {
64
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
65
+ const newRelative = file.relative.replace(oldPathRelative, newPathRelative);
66
+ file.updatePaths({ newRelative, newBase: newPathRelative });
67
+ });
68
+ component.dataToPersist.removePath(new RemovePath(oldPathRelative));
69
+ component.writtenPath = newPathRelative;
70
+ }
71
+
72
+ static slots = [];
73
+ static dependencies = [CLIAspect, WorkspaceAspect];
74
+ static runtime = MainRuntime;
75
+
76
+ static async provider([cli, workspace]: [CLIMain, Workspace]) {
77
+ const moverMain = new MoverMain(workspace);
78
+ cli.register(new MoveCmd(moverMain));
79
+ return moverMain;
80
+ }
81
+ }
82
+
83
+ MoverAspect.addRuntime(MoverMain);
84
+
85
+ export default MoverMain;
package/package.json CHANGED
@@ -1,38 +1,32 @@
1
1
  {
2
2
  "name": "@teambit/mover",
3
- "version": "1.0.107",
3
+ "version": "1.0.108",
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.107"
9
+ "version": "1.0.108"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
13
13
  "fs-extra": "10.0.0",
14
14
  "ramda": "0.27.1",
15
- "core-js": "^3.0.0",
16
- "@babel/runtime": "7.20.0",
17
15
  "@teambit/harmony": "0.4.6",
18
16
  "@teambit/bit-error": "0.0.404",
19
- "@teambit/cli": "0.0.839",
20
- "@teambit/workspace.modules.node-modules-linker": "0.0.157",
21
- "@teambit/workspace": "1.0.107"
17
+ "@teambit/cli": "0.0.840",
18
+ "@teambit/workspace.modules.node-modules-linker": "0.0.158",
19
+ "@teambit/workspace": "1.0.108"
22
20
  },
23
21
  "devDependencies": {
24
22
  "@types/fs-extra": "9.0.7",
25
23
  "@types/mocha": "9.1.0",
26
- "@types/node": "12.20.4",
27
- "@types/react": "^17.0.8",
28
- "@types/react-dom": "^17.0.5",
29
- "@types/jest": "^26.0.0",
30
- "@types/testing-library__jest-dom": "5.9.5"
24
+ "@types/jest": "^29.2.2",
25
+ "@types/testing-library__jest-dom": "^5.9.5",
26
+ "@teambit/harmony.envs.core-aspect-env": "0.0.13"
31
27
  },
32
28
  "peerDependencies": {
33
- "@teambit/legacy": "1.0.624",
34
- "react": "^16.8.0 || ^17.0.0",
35
- "react-dom": "^16.8.0 || ^17.0.0"
29
+ "@teambit/legacy": "1.0.624"
36
30
  },
37
31
  "license": "Apache-2.0",
38
32
  "optionalDependencies": {},
@@ -46,7 +40,7 @@
46
40
  },
47
41
  "private": false,
48
42
  "engines": {
49
- "node": ">=12.22.0"
43
+ "node": ">=16.0.0"
50
44
  },
51
45
  "repository": {
52
46
  "type": "git",
@@ -55,12 +49,9 @@
55
49
  "keywords": [
56
50
  "bit",
57
51
  "bit-aspect",
52
+ "bit-core-aspect",
58
53
  "components",
59
54
  "collaboration",
60
- "web",
61
- "react",
62
- "react-components",
63
- "angular",
64
- "angular-components"
55
+ "web"
65
56
  ]
66
57
  }
package/tsconfig.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
4
+ "esnext",
5
+ "dom",
6
+ "dom.Iterable"
9
7
  ],
10
- "target": "es2015",
11
- "module": "CommonJS",
12
- "jsx": "react",
13
- "allowJs": true,
14
- "composite": true,
8
+ "target": "es2020",
9
+ "module": "es2020",
10
+ "jsx": "react-jsx",
15
11
  "declaration": true,
16
12
  "sourceMap": true,
17
- "skipLibCheck": true,
18
13
  "experimentalDecorators": true,
19
- "outDir": "dist",
14
+ "skipLibCheck": true,
20
15
  "moduleResolution": "node",
21
16
  "esModuleInterop": true,
22
- "rootDir": ".",
23
17
  "resolveJsonModule": true,
24
- "emitDeclarationOnly": true,
25
- "emitDecoratorMetadata": true,
26
- "allowSyntheticDefaultImports": true,
27
- "strictPropertyInitialization": false,
28
- "strict": true,
29
- "noImplicitAny": false,
30
- "preserveConstEnums": true
18
+ "allowJs": true,
19
+ "outDir": "dist",
20
+ "emitDeclarationOnly": true
31
21
  },
32
22
  "exclude": [
23
+ "artifacts",
24
+ "public",
33
25
  "dist",
26
+ "node_modules",
27
+ "package.json",
34
28
  "esm.mjs",
35
- "package.json"
29
+ "**/*.cjs",
30
+ "./dist"
36
31
  ],
37
32
  "include": [
38
33
  "**/*",
package/types/asset.d.ts CHANGED
@@ -5,12 +5,12 @@ declare module '*.png' {
5
5
  declare module '*.svg' {
6
6
  import type { FunctionComponent, SVGProps } from 'react';
7
7
 
8
- export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
9
11
  const src: string;
10
12
  export default src;
11
13
  }
12
-
13
- // @TODO Gilad
14
14
  declare module '*.jpg' {
15
15
  const value: any;
16
16
  export = value;
@@ -27,3 +27,15 @@ declare module '*.bmp' {
27
27
  const value: any;
28
28
  export = value;
29
29
  }
30
+ declare module '*.otf' {
31
+ const value: any;
32
+ export = value;
33
+ }
34
+ declare module '*.woff' {
35
+ const value: any;
36
+ export = value;
37
+ }
38
+ declare module '*.woff2' {
39
+ const value: any;
40
+ export = value;
41
+ }