@teambit/workspace 0.0.531 → 0.0.535

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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/workspace",
3
- "version": "0.0.531",
3
+ "version": "0.0.535",
4
4
  "homepage": "https://bit.dev/teambit/workspace/workspace",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.workspace",
8
8
  "name": "workspace",
9
- "version": "0.0.531"
9
+ "version": "0.0.535"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
@@ -33,53 +33,53 @@
33
33
  "@teambit/base-ui.surfaces.split-pane.split-pane": "1.0.0",
34
34
  "@teambit/base-ui.graph.tree.recursive-tree": "1.0.0",
35
35
  "@teambit/cli": "0.0.380",
36
- "@teambit/isolator": "0.0.531",
36
+ "@teambit/isolator": "0.0.535",
37
37
  "@teambit/component-tree": "0.0.366",
38
- "@teambit/component.ui.component-status-resolver": "0.0.453",
39
- "@teambit/harmony.modules.resolved-component": "0.0.447",
40
- "@teambit/dependency-resolver": "0.0.531",
41
- "@teambit/logger": "0.0.455",
42
- "@teambit/compiler": "0.0.531",
43
- "@teambit/component": "0.0.531",
44
- "@teambit/graphql": "0.0.531",
45
- "@teambit/aspect-loader": "0.0.531",
46
- "@teambit/bundler": "0.0.531",
47
- "@teambit/envs": "0.0.531",
48
- "@teambit/pubsub": "0.0.531",
49
- "@teambit/scope": "0.0.531",
50
- "@teambit/ui": "0.0.531",
51
- "@teambit/variants": "0.0.457",
38
+ "@teambit/component.ui.component-status-resolver": "0.0.455",
39
+ "@teambit/harmony.modules.resolved-component": "0.0.449",
40
+ "@teambit/dependency-resolver": "0.0.535",
41
+ "@teambit/logger": "0.0.457",
42
+ "@teambit/compiler": "0.0.535",
43
+ "@teambit/component": "0.0.535",
44
+ "@teambit/graphql": "0.0.535",
45
+ "@teambit/aspect-loader": "0.0.535",
46
+ "@teambit/bundler": "0.0.535",
47
+ "@teambit/envs": "0.0.535",
48
+ "@teambit/pubsub": "0.0.535",
49
+ "@teambit/scope": "0.0.535",
50
+ "@teambit/ui": "0.0.535",
51
+ "@teambit/variants": "0.0.459",
52
52
  "@teambit/legacy-bit-id": "0.0.369",
53
53
  "@teambit/bit-error": "0.0.366",
54
54
  "@teambit/component-issues": "0.0.15",
55
55
  "@teambit/config": "0.0.391",
56
- "@teambit/harmony.modules.requireable-component": "0.0.447",
57
- "@teambit/workspace.modules.match-pattern": "0.0.449",
58
- "@teambit/command-bar": "0.0.531",
56
+ "@teambit/harmony.modules.requireable-component": "0.0.449",
57
+ "@teambit/workspace.modules.match-pattern": "0.0.451",
58
+ "@teambit/command-bar": "0.0.535",
59
59
  "@teambit/design.ui.surfaces.menu.link-item": "0.0.374",
60
- "@teambit/graph": "0.0.531",
61
- "@teambit/react-router": "0.0.531",
62
- "@teambit/sidebar": "0.0.531",
63
- "@teambit/ui-foundation.ui.main-dropdown": "0.0.449",
64
- "@teambit/ui-foundation.ui.menu": "0.0.449",
65
- "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.451",
66
- "@teambit/toolbox.time.time-format": "0.0.446",
60
+ "@teambit/graph": "0.0.535",
61
+ "@teambit/react-router": "0.0.535",
62
+ "@teambit/sidebar": "0.0.535",
63
+ "@teambit/ui-foundation.ui.main-dropdown": "0.0.451",
64
+ "@teambit/ui-foundation.ui.menu": "0.0.451",
65
+ "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.453",
66
+ "@teambit/toolbox.time.time-format": "0.0.448",
67
67
  "@teambit/component-id": "0.0.370",
68
- "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.450",
69
- "@teambit/deprecation": "0.0.531",
70
- "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.449",
71
- "@teambit/ui-foundation.ui.buttons.collapser": "0.0.154",
72
- "@teambit/ui-foundation.ui.corner": "0.0.456",
73
- "@teambit/ui-foundation.ui.notifications.notification-context": "0.0.450",
74
- "@teambit/ui-foundation.ui.top-bar": "0.0.451",
68
+ "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.452",
69
+ "@teambit/deprecation": "0.0.535",
70
+ "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.451",
71
+ "@teambit/ui-foundation.ui.buttons.collapser": "0.0.156",
72
+ "@teambit/ui-foundation.ui.corner": "0.0.458",
73
+ "@teambit/ui-foundation.ui.notifications.notification-context": "0.0.452",
74
+ "@teambit/ui-foundation.ui.top-bar": "0.0.453",
75
75
  "@teambit/design.ui.styles.ellipsis": "0.0.346",
76
76
  "@teambit/design.ui.styles.muted-italic": "0.0.35",
77
- "@teambit/ui-foundation.ui.full-loader": "0.0.449",
78
- "@teambit/ui-foundation.ui.side-bar": "0.0.453",
79
- "@teambit/ui-foundation.ui.tree.drawer": "0.0.449",
80
- "@teambit/explorer.ui.gallery.component-grid": "0.0.449",
81
- "@teambit/workspace.ui.empty-workspace": "0.0.451",
82
- "@teambit/workspace.ui.workspace-component-card": "0.0.452"
77
+ "@teambit/ui-foundation.ui.full-loader": "0.0.451",
78
+ "@teambit/ui-foundation.ui.side-bar": "0.0.455",
79
+ "@teambit/ui-foundation.ui.tree.drawer": "0.0.451",
80
+ "@teambit/explorer.ui.gallery.component-grid": "0.0.451",
81
+ "@teambit/workspace.ui.empty-workspace": "0.0.453",
82
+ "@teambit/workspace.ui.workspace-component-card": "0.0.454"
83
83
  },
84
84
  "devDependencies": {
85
85
  "@types/react": "^17.0.8",
@@ -0,0 +1,5 @@
1
+ export enum CheckTypes {
2
+ None, // keep this. it equals zero. this way we can do "if checkTypes() ... "
3
+ EntireProject,
4
+ ChangedFile,
5
+ }
@@ -1,6 +1,5 @@
1
1
  import chalk from 'chalk';
2
2
  import moment from 'moment';
3
-
4
3
  import { Command, CommandOptions } from '@teambit/cli';
5
4
  import type { Logger } from '@teambit/logger';
6
5
  import type { BitBaseEvent, PubsubMain } from '@teambit/pubsub';
@@ -11,14 +10,20 @@ import { CompilerAspect, CompilerErrorEvent } from '@teambit/compiler';
11
10
  import { Watcher, WatchOptions } from './watcher';
12
11
  import { formatCompileResults, formatWatchPathsSortByComponent } from './output-formatter';
13
12
  import { OnComponentEventResult } from '../on-component-events';
13
+ import { CheckTypes } from './check-types';
14
+
15
+ export type WatchCmdOpts = {
16
+ verbose?: boolean;
17
+ skipPreCompilation?: boolean;
18
+ checkTypes?: string | boolean;
19
+ };
14
20
 
15
21
  export class WatchCommand implements Command {
16
22
  msgs = {
17
23
  onAll: (event, path) => this.logger.console(`Event: "${event}". Path: ${path}`),
18
24
  onStart: () => {},
19
25
  onReady: (workspace, watchPathsSortByComponent, verbose) => {
20
- // eslint-disable-next-line no-console
21
- console.clear();
26
+ clearOutdatedData();
22
27
  if (verbose) {
23
28
  this.logger.console(formatWatchPathsSortByComponent(watchPathsSortByComponent));
24
29
  }
@@ -29,8 +34,7 @@ export class WatchCommand implements Command {
29
34
  );
30
35
  },
31
36
  onChange: (filePath: string, buildResults: OnComponentEventResult[], verbose: boolean, duration) => {
32
- // eslint-disable-next-line no-console
33
- console.clear();
37
+ clearOutdatedData();
34
38
  if (!buildResults.length) {
35
39
  this.logger.console(`The file ${filePath} has been changed, but nothing to compile.\n\n`);
36
40
  return;
@@ -41,8 +45,7 @@ export class WatchCommand implements Command {
41
45
  this.logger.console(chalk.yellow(`Watching for component changes (${moment().format('HH:mm:ss')})...`));
42
46
  },
43
47
  onAdd: (filePath: string, buildResults: OnComponentEventResult[], verbose: boolean, duration) => {
44
- // eslint-disable-next-line no-console
45
- console.clear();
48
+ clearOutdatedData();
46
49
  this.logger.console(`The file ${filePath} has been added.\n\n`);
47
50
  this.logger.console(formatCompileResults(buildResults, verbose));
48
51
  this.logger.console(`Finished. (${duration}ms)`);
@@ -64,7 +67,11 @@ export class WatchCommand implements Command {
64
67
  options = [
65
68
  ['v', 'verbose', 'showing npm verbose output for inspection and prints stack trace'],
66
69
  ['', 'skip-pre-compilation', 'skip the compilation step before starting to watch'],
67
- ['t', 'check-types', 'EXPERIMENTAL. for typescript files, load an tsserver instance to check types'],
70
+ [
71
+ 't',
72
+ 'check-types [string]',
73
+ 'EXPERIMENTAL. show errors/warnings for types. options are [file, project] to investigate only changed file or entire project. defaults to project',
74
+ ],
68
75
  ] as CommandOptions;
69
76
 
70
77
  constructor(
@@ -99,8 +106,37 @@ export class WatchCommand implements Command {
99
106
  }
100
107
  };
101
108
 
102
- async report(cliArgs: [], watchOpts: WatchOptions) {
103
- await this.watcher.watch({ msgs: this.msgs, ...watchOpts });
109
+ async report(cliArgs: [], watchCmdOpts: WatchCmdOpts) {
110
+ const { verbose, checkTypes } = watchCmdOpts;
111
+ const getCheckTypesEnum = () => {
112
+ switch (checkTypes) {
113
+ case undefined:
114
+ case false:
115
+ return CheckTypes.None;
116
+ case 'project':
117
+ case true: // project is the default
118
+ return CheckTypes.EntireProject;
119
+ case 'file':
120
+ return CheckTypes.ChangedFile;
121
+ default:
122
+ throw new Error(`check-types can be either "file" or "project". got "${checkTypes}"`);
123
+ }
124
+ };
125
+ const watchOpts: WatchOptions = {
126
+ msgs: this.msgs,
127
+ verbose,
128
+ preCompile: !watchCmdOpts.skipPreCompilation,
129
+ spawnTSServer: Boolean(checkTypes), // if check-types is enabled, it must spawn the tsserver.
130
+ checkTypes: getCheckTypesEnum(),
131
+ };
132
+ await this.watcher.watchAll(watchOpts);
104
133
  return 'watcher terminated';
105
134
  }
106
135
  }
136
+
137
+ /**
138
+ * with console.clear() all history is deleted from the console. this function preserver the history.
139
+ */
140
+ function clearOutdatedData() {
141
+ process.stdout.write('\x1Bc');
142
+ }
package/watch/watcher.ts CHANGED
@@ -19,10 +19,18 @@ import { WorkspaceAspect } from '../';
19
19
  import { OnComponentChangeEvent, OnComponentAddEvent, OnComponentRemovedEvent } from '../events';
20
20
  import { Workspace } from '../workspace';
21
21
  import { OnComponentEventResult } from '../on-component-events';
22
+ import { CheckTypes } from './check-types';
22
23
 
23
24
  export type WatcherProcessData = { watchProcess: ChildProcess; compilerId: BitId; componentIds: BitId[] };
24
25
 
25
- export type WatchOptions = { verbose?: boolean; checkTypes?: boolean; skipPreCompilation?: boolean };
26
+ export type WatchOptions = {
27
+ msgs?: any;
28
+ initiator?: CompilationInitiator;
29
+ verbose?: boolean; // print watch events to the console. (also ts-server events if spawnTSServer is true)
30
+ spawnTSServer?: boolean; // needed for check types and extract API/docs.
31
+ checkTypes?: CheckTypes; // if enabled, the spawnTSServer becomes true.
32
+ preCompile?: boolean; // whether compile all components before start watching
33
+ };
26
34
 
27
35
  export class Watcher {
28
36
  private fsWatcher: FSWatcher;
@@ -34,16 +42,11 @@ export class Watcher {
34
42
  private multipleWatchers: WatcherProcessData[] = []
35
43
  ) {}
36
44
 
37
- async watch(opts: { msgs } & WatchOptions) {
38
- this.verbose = Boolean(opts.verbose);
39
- await this.watchAll(opts);
40
- }
41
-
42
45
  get consumer(): Consumer {
43
46
  return this.workspace.consumer;
44
47
  }
45
48
 
46
- async watchAll(opts: { msgs; initiator?: CompilationInitiator } & WatchOptions) {
49
+ async watchAll(opts: WatchOptions) {
47
50
  const { msgs, ...watchOpts } = opts;
48
51
  // TODO: run build in the beginning of process (it's work like this in other envs)
49
52
  const pathsToWatch = await this.getPathsToWatch();
package/workspace.ts CHANGED
@@ -631,7 +631,7 @@ export class Workspace implements ComponentFactory {
631
631
  const addResults = await addComponent.add();
632
632
  // @todo: the legacy commands have `consumer.onDestroy()` on command completion, it writes the
633
633
  // .bitmap file. workspace needs a similar mechanism. once done, remove the next line.
634
- await this.consumer.bitMap.write(this.consumer.componentFsCache);
634
+ await this.writeBitMap();
635
635
  return addResults;
636
636
  }
637
637
 
@@ -1287,17 +1287,15 @@ your workspace.jsonc has this component-id set. you might want to remove/change
1287
1287
  verbose: false,
1288
1288
  merge: false,
1289
1289
  objectsOnly: true,
1290
- withEnvironments: false,
1291
1290
  override: false,
1292
1291
  writeDists: false,
1293
1292
  writeConfig: false,
1294
1293
  installNpmPackages: false,
1295
- writePackageJson: false,
1296
1294
  importDependenciesDirectly: false,
1297
1295
  importDependents: false,
1298
1296
  };
1299
1297
  try {
1300
- const res = await importAction({ tester: false, compiler: false }, importOptions, []);
1298
+ const res = await importAction(importOptions, []);
1301
1299
  return res;
1302
1300
  } catch (err: any) {
1303
1301
  // TODO: this is a hack since the legacy throw an error, we should provide a way to not throw this error from the legacy