@teambit/workspace 0.0.625 → 0.0.631
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/__preview-1643039669895.js +1 -0
- package/dist/ui/workspace-components-drawer/workspace-components-drawer.module.scss +4 -0
- package/dist/ui/workspace-components-drawer/workspace-components.drawer.d.ts +4 -0
- package/dist/ui/workspace-components-drawer/workspace-components.drawer.js +45 -4
- package/dist/ui/workspace-components-drawer/workspace-components.drawer.js.map +1 -1
- package/dist/workspace.d.ts +7 -1
- package/dist/workspace.js +168 -44
- package/dist/workspace.js.map +1 -1
- package/package-tar/teambit-workspace-0.0.631.tgz +0 -0
- package/package.json +30 -30
- package/ui/workspace-components-drawer/workspace-components-drawer.module.scss +4 -0
- package/ui/workspace-components-drawer/workspace-components.drawer.tsx +30 -7
- package/package-tar/teambit-workspace-0.0.625.tgz +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -5,5 +5,9 @@ export declare class WorkspaceComponentsDrawer implements DrawerType {
|
|
|
5
5
|
private treeNodeSlot;
|
|
6
6
|
constructor(treeNodeSlot: ComponentTreeSlot);
|
|
7
7
|
name: string;
|
|
8
|
+
widget: JSX.Element;
|
|
9
|
+
Context: ({ children }: {
|
|
10
|
+
children: any;
|
|
11
|
+
}) => JSX.Element;
|
|
8
12
|
render: () => JSX.Element;
|
|
9
13
|
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
+
require("core-js/modules/es.array.iterator.js");
|
|
6
|
+
|
|
5
7
|
Object.defineProperty(exports, "__esModule", {
|
|
6
8
|
value: true
|
|
7
9
|
});
|
|
@@ -111,12 +113,32 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
111
113
|
|
|
112
114
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
113
115
|
|
|
116
|
+
const WorkspaceTreeContext = /*#__PURE__*/(0, _react().createContext)({
|
|
117
|
+
collapsed: true,
|
|
118
|
+
setCollapsed: () => {}
|
|
119
|
+
});
|
|
120
|
+
|
|
114
121
|
class WorkspaceComponentsDrawer {
|
|
115
122
|
constructor(treeNodeSlot) {
|
|
116
123
|
this.treeNodeSlot = treeNodeSlot;
|
|
117
124
|
(0, _defineProperty2().default)(this, "name", 'COMPONENTS');
|
|
125
|
+
(0, _defineProperty2().default)(this, "widget", /*#__PURE__*/_react().default.createElement(Widget, null));
|
|
126
|
+
(0, _defineProperty2().default)(this, "Context", ({
|
|
127
|
+
children
|
|
128
|
+
}) => {
|
|
129
|
+
const [collapsed, setCollapsed] = (0, _react().useState)(true);
|
|
130
|
+
return /*#__PURE__*/_react().default.createElement(WorkspaceTreeContext.Provider, {
|
|
131
|
+
value: {
|
|
132
|
+
collapsed,
|
|
133
|
+
setCollapsed
|
|
134
|
+
}
|
|
135
|
+
}, children);
|
|
136
|
+
});
|
|
118
137
|
(0, _defineProperty2().default)(this, "render", () => {
|
|
119
138
|
const workspace = (0, _react().useContext)(_workspaceContext().WorkspaceContext);
|
|
139
|
+
const {
|
|
140
|
+
collapsed
|
|
141
|
+
} = (0, _react().useContext)(WorkspaceTreeContext);
|
|
120
142
|
const {
|
|
121
143
|
treeNodeSlot
|
|
122
144
|
} = this;
|
|
@@ -124,16 +146,22 @@ class WorkspaceComponentsDrawer {
|
|
|
124
146
|
const children = props.node.children;
|
|
125
147
|
if (!children) return /*#__PURE__*/_react().default.createElement(_uiFoundationUi2().ComponentView, (0, _extends2().default)({}, props, {
|
|
126
148
|
treeNodeSlot: treeNodeSlot
|
|
127
|
-
}));
|
|
149
|
+
})); // non collapse
|
|
150
|
+
|
|
128
151
|
if (props.node.payload instanceof _uiFoundationUi2().ScopePayload) return /*#__PURE__*/_react().default.createElement(_uiFoundationUi2().ScopeTreeNode, props);
|
|
129
152
|
return /*#__PURE__*/_react().default.createElement(_uiFoundationUi2().NamespaceTreeNode, props);
|
|
130
153
|
}, [treeNodeSlot]);
|
|
131
154
|
if (!workspace) return /*#__PURE__*/_react().default.createElement(_uiFoundationUi().FullLoader, null);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
155
|
+
|
|
156
|
+
if (workspace.components.length === 0) {
|
|
157
|
+
return /*#__PURE__*/_react().default.createElement("span", {
|
|
158
|
+
className: (0, _classnames().default)(_designUiStyles().mutedItalic, _designUiStyles2().ellipsis, _workspaceComponentsDrawerModule().default.emptyWorkspace)
|
|
159
|
+
}, "Workspace is empty");
|
|
160
|
+
}
|
|
161
|
+
|
|
135
162
|
return /*#__PURE__*/_react().default.createElement(_uiFoundationUi2().ComponentTree, {
|
|
136
163
|
components: workspace.components,
|
|
164
|
+
isCollapsed: collapsed,
|
|
137
165
|
TreeNode: TreeNodeRenderer
|
|
138
166
|
});
|
|
139
167
|
});
|
|
@@ -143,4 +171,17 @@ class WorkspaceComponentsDrawer {
|
|
|
143
171
|
|
|
144
172
|
exports.WorkspaceComponentsDrawer = WorkspaceComponentsDrawer;
|
|
145
173
|
|
|
174
|
+
function Widget() {
|
|
175
|
+
const {
|
|
176
|
+
collapsed,
|
|
177
|
+
setCollapsed
|
|
178
|
+
} = (0, _react().useContext)(WorkspaceTreeContext);
|
|
179
|
+
const icon = collapsed ? 'https://static.bit.dev/bit-icons/expand.svg' : 'https://static.bit.dev/bit-icons/collapse.svg';
|
|
180
|
+
return /*#__PURE__*/_react().default.createElement("img", {
|
|
181
|
+
src: icon,
|
|
182
|
+
className: _workspaceComponentsDrawerModule().default.collapseIcon,
|
|
183
|
+
onClick: () => setCollapsed(!collapsed)
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
146
187
|
//# sourceMappingURL=workspace-components.drawer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["workspace-components.drawer.tsx"],"names":["WorkspaceComponentsDrawer","constructor","treeNodeSlot","workspace","WorkspaceContext","TreeNodeRenderer","TreeNode","props","
|
|
1
|
+
{"version":3,"sources":["workspace-components.drawer.tsx"],"names":["WorkspaceTreeContext","collapsed","setCollapsed","WorkspaceComponentsDrawer","constructor","treeNodeSlot","children","workspace","WorkspaceContext","TreeNodeRenderer","TreeNode","props","node","payload","ScopePayload","components","length","mutedItalic","ellipsis","styles","emptyWorkspace","Widget","icon","collapseIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AASA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAEA,MAAMA,oBAAoB,gBAAG,4BAA0E;AACrGC,EAAAA,SAAS,EAAE,IAD0F;AAErGC,EAAAA,YAAY,EAAE,MAAM,CAAE;AAF+E,CAA1E,CAA7B;;AAKO,MAAMC,yBAAN,CAAsD;AAC3DC,EAAAA,WAAW,CAASC,YAAT,EAA0C;AAAA,SAAjCA,YAAiC,GAAjCA,YAAiC;AAAA,kDAE9C,YAF8C;AAAA,iEAI3C,+BAAC,MAAD,OAJ2C;AAAA,qDAM3C,CAAC;AAAEC,MAAAA;AAAF,KAAD,KAAkB;AAC1B,YAAM,CAACL,SAAD,EAAYC,YAAZ,IAA4B,uBAAS,IAAT,CAAlC;AACA,0BACE,+BAAC,oBAAD,CAAsB,QAAtB;AAA+B,QAAA,KAAK,EAAE;AAAED,UAAAA,SAAF;AAAaC,UAAAA;AAAb;AAAtC,SAAoEI,QAApE,CADF;AAGD,KAXoD;AAAA,oDAa5C,MAAM;AACb,YAAMC,SAAS,GAAG,yBAAWC,oCAAX,CAAlB;AACA,YAAM;AAAEP,QAAAA;AAAF,UAAgB,yBAAWD,oBAAX,CAAtB;AACA,YAAM;AAAEK,QAAAA;AAAF,UAAmB,IAAzB;AAEA,YAAMI,gBAAgB,GAAG,0BACvB,SAASC,QAAT,CAAkBC,KAAlB,EAAqD;AACnD,cAAML,QAAQ,GAAGK,KAAK,CAACC,IAAN,CAAWN,QAA5B;AAEA,YAAI,CAACA,QAAL,EAAe,oBAAO,+BAAC,gCAAD,+BAAmBK,KAAnB;AAA0B,UAAA,YAAY,EAAEN;AAAxC,WAAP,CAHoC,CAG6B;;AAEhF,YAAIM,KAAK,CAACC,IAAN,CAAWC,OAAX,YAA8BC,+BAAlC,EAAgD,oBAAO,+BAAC,gCAAD,EAAmBH,KAAnB,CAAP;AAEhD,4BAAO,+BAAC,oCAAD,EAAuBA,KAAvB,CAAP;AACD,OATsB,EAUvB,CAACN,YAAD,CAVuB,CAAzB;AAaA,UAAI,CAACE,SAAL,EAAgB,oBAAO,+BAAC,4BAAD,OAAP;;AAChB,UAAIA,SAAS,CAACQ,UAAV,CAAqBC,MAArB,KAAgC,CAApC,EAAuC;AACrC,4BAAO;AAAM,UAAA,SAAS,EAAE,2BAAWC,6BAAX,EAAwBC,2BAAxB,EAAkCC,2CAAOC,cAAzC;AAAjB,gCAAP;AACD;;AAED,0BAAO,+BAAC,gCAAD;AAAe,QAAA,UAAU,EAAEb,SAAS,CAACQ,UAArC;AAAiD,QAAA,WAAW,EAAEd,SAA9D;AAAyE,QAAA,QAAQ,EAAEQ;AAAnF,QAAP;AACD,KArCoD;AAAE;;AADI;;;;AAyC7D,SAASY,MAAT,GAAkB;AAChB,QAAM;AAAEpB,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA8B,yBAAWF,oBAAX,CAApC;AACA,QAAMsB,IAAI,GAAGrB,SAAS,GAClB,6CADkB,GAElB,+CAFJ;AAGA,sBAAO;AAAK,IAAA,GAAG,EAAEqB,IAAV;AAAgB,IAAA,SAAS,EAAEH,2CAAOI,YAAlC;AAAgD,IAAA,OAAO,EAAE,MAAMrB,YAAY,CAAC,CAACD,SAAF;AAA3E,IAAP;AACD","sourcesContent":["import type { DrawerType } from '@teambit/ui-foundation.ui.tree.drawer';\nimport { FullLoader } from '@teambit/ui-foundation.ui.full-loader';\nimport {\n ComponentTree,\n PayloadType,\n ComponentView,\n ScopeTreeNode,\n NamespaceTreeNode,\n ScopePayload,\n} from '@teambit/ui-foundation.ui.side-bar';\nimport { TreeNodeProps } from '@teambit/design.ui.tree';\nimport React, { useCallback, useContext, useState, createContext } from 'react';\nimport classNames from 'classnames';\nimport { ComponentTreeSlot } from '@teambit/component-tree';\nimport { mutedItalic } from '@teambit/design.ui.styles.muted-italic';\nimport { ellipsis } from '@teambit/design.ui.styles.ellipsis';\nimport { WorkspaceContext } from '../workspace/workspace-context';\nimport styles from './workspace-components-drawer.module.scss';\n\nconst WorkspaceTreeContext = createContext<{ collapsed: boolean; setCollapsed: (x: boolean) => void }>({\n collapsed: true,\n setCollapsed: () => {},\n});\n\nexport class WorkspaceComponentsDrawer implements DrawerType {\n constructor(private treeNodeSlot: ComponentTreeSlot) {}\n\n name = 'COMPONENTS';\n\n widget = (<Widget />);\n\n Context = ({ children }) => {\n const [collapsed, setCollapsed] = useState(true);\n return (\n <WorkspaceTreeContext.Provider value={{ collapsed, setCollapsed }}>{children}</WorkspaceTreeContext.Provider>\n );\n };\n\n render = () => {\n const workspace = useContext(WorkspaceContext);\n const { collapsed } = useContext(WorkspaceTreeContext);\n const { treeNodeSlot } = this;\n\n const TreeNodeRenderer = useCallback(\n function TreeNode(props: TreeNodeProps<PayloadType>) {\n const children = props.node.children;\n\n if (!children) return <ComponentView {...props} treeNodeSlot={treeNodeSlot} />; // non collapse\n\n if (props.node.payload instanceof ScopePayload) return <ScopeTreeNode {...props} />;\n\n return <NamespaceTreeNode {...props} />;\n },\n [treeNodeSlot]\n );\n\n if (!workspace) return <FullLoader />;\n if (workspace.components.length === 0) {\n return <span className={classNames(mutedItalic, ellipsis, styles.emptyWorkspace)}>Workspace is empty</span>;\n }\n\n return <ComponentTree components={workspace.components} isCollapsed={collapsed} TreeNode={TreeNodeRenderer} />;\n };\n}\n\nfunction Widget() {\n const { collapsed, setCollapsed } = useContext(WorkspaceTreeContext);\n const icon = collapsed\n ? 'https://static.bit.dev/bit-icons/expand.svg'\n : 'https://static.bit.dev/bit-icons/collapse.svg';\n return <img src={icon} className={styles.collapseIcon} onClick={() => setCollapsed(!collapsed)} />;\n}\n"]}
|
package/dist/workspace.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { PathOsBased, PathOsBasedRelative, PathOsBasedAbsolute } from '@teambit/
|
|
|
26
26
|
import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
|
|
27
27
|
import type { ComponentLog } from '@teambit/legacy/dist/scope/models/model-component';
|
|
28
28
|
import { CompilationInitiator } from '@teambit/compiler';
|
|
29
|
+
import { Lane } from '@teambit/legacy/dist/scope/models';
|
|
29
30
|
import { OnComponentAdd, OnComponentChange, OnComponentEventResult, OnComponentLoad, OnComponentRemove } from './on-component-events';
|
|
30
31
|
import { WorkspaceExtConfig } from './types';
|
|
31
32
|
import { Watcher, WatchOptions } from './watch/watcher';
|
|
@@ -123,6 +124,7 @@ export declare class Workspace implements ComponentFactory {
|
|
|
123
124
|
componentsScopeDirsMap: ComponentScopeDirMap;
|
|
124
125
|
componentLoader: WorkspaceComponentLoader;
|
|
125
126
|
bitMap: BitMap;
|
|
127
|
+
private componentLoadedSelfAsAspects;
|
|
126
128
|
constructor(
|
|
127
129
|
/**
|
|
128
130
|
* private pubsub.
|
|
@@ -264,7 +266,10 @@ export declare class Workspace implements ComponentFactory {
|
|
|
264
266
|
* if checked out to a lane and the lane exists in the remote,
|
|
265
267
|
* return the remote lane id (name+scope). otherwise, return null.
|
|
266
268
|
*/
|
|
267
|
-
getCurrentRemoteLaneId():
|
|
269
|
+
getCurrentRemoteLaneId(): Promise<{
|
|
270
|
+
laneId: RemoteLaneId;
|
|
271
|
+
lane: Lane;
|
|
272
|
+
} | null>;
|
|
268
273
|
getDefaultExtensions(): ExtensionDataList;
|
|
269
274
|
ejectConfig(id: ComponentID, options: EjectConfOptions): Promise<EjectConfResult>;
|
|
270
275
|
private resolveScopeAspectListIds;
|
|
@@ -355,6 +360,7 @@ export declare class Workspace implements ComponentFactory {
|
|
|
355
360
|
* the component.json file in the component folder
|
|
356
361
|
* matching pattern in the variants config
|
|
357
362
|
* defaults extensions from workspace config
|
|
363
|
+
* extensions from the model.
|
|
358
364
|
*/
|
|
359
365
|
componentExtensions(componentId: ComponentID, componentFromScope?: Component): Promise<ExtensionDataList>;
|
|
360
366
|
private filterEnvsFromExtensionsIfNeeded;
|
package/dist/workspace.js
CHANGED
|
@@ -229,20 +229,30 @@ function _consumer2() {
|
|
|
229
229
|
return data;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
function
|
|
233
|
-
const data = require("@teambit/legacy/dist/consumer/
|
|
232
|
+
function _addComponents() {
|
|
233
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component-ops/add-components"));
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
_addComponents = function () {
|
|
236
236
|
return data;
|
|
237
237
|
};
|
|
238
238
|
|
|
239
239
|
return data;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
function
|
|
243
|
-
const data =
|
|
242
|
+
function _inMemoryCache() {
|
|
243
|
+
const data = require("@teambit/legacy/dist/cache/in-memory-cache");
|
|
244
244
|
|
|
245
|
-
|
|
245
|
+
_inMemoryCache = function () {
|
|
246
|
+
return data;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
return data;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function _cacheFactory() {
|
|
253
|
+
const data = require("@teambit/legacy/dist/cache/cache-factory");
|
|
254
|
+
|
|
255
|
+
_cacheFactory = function () {
|
|
246
256
|
return data;
|
|
247
257
|
};
|
|
248
258
|
|
|
@@ -349,6 +359,46 @@ function _component2() {
|
|
|
349
359
|
return data;
|
|
350
360
|
}
|
|
351
361
|
|
|
362
|
+
function _scopeComponentsImporter() {
|
|
363
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/scope/component-ops/scope-components-importer"));
|
|
364
|
+
|
|
365
|
+
_scopeComponentsImporter = function () {
|
|
366
|
+
return data;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
return data;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function _loader() {
|
|
373
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/cli/loader"));
|
|
374
|
+
|
|
375
|
+
_loader = function () {
|
|
376
|
+
return data;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
return data;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function _laneNotFound() {
|
|
383
|
+
const data = require("@teambit/legacy/dist/api/scope/lib/exceptions/lane-not-found");
|
|
384
|
+
|
|
385
|
+
_laneNotFound = function () {
|
|
386
|
+
return data;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
return data;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function _scopeNotFoundOrDenied() {
|
|
393
|
+
const data = require("@teambit/legacy/dist/remotes/exceptions/scope-not-found-or-denied");
|
|
394
|
+
|
|
395
|
+
_scopeNotFoundOrDenied = function () {
|
|
396
|
+
return data;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
return data;
|
|
400
|
+
}
|
|
401
|
+
|
|
352
402
|
function _componentConfigFile() {
|
|
353
403
|
const data = require("./component-config-file");
|
|
354
404
|
|
|
@@ -429,10 +479,10 @@ function _buildGraphFromFs() {
|
|
|
429
479
|
return data;
|
|
430
480
|
}
|
|
431
481
|
|
|
432
|
-
function
|
|
482
|
+
function _bitMap() {
|
|
433
483
|
const data = require("./bit-map");
|
|
434
484
|
|
|
435
|
-
|
|
485
|
+
_bitMap = function () {
|
|
436
486
|
return data;
|
|
437
487
|
};
|
|
438
488
|
|
|
@@ -452,6 +502,7 @@ const DEFAULT_VENDOR_DIR = 'vendor';
|
|
|
452
502
|
*/
|
|
453
503
|
|
|
454
504
|
class Workspace {
|
|
505
|
+
// cache loaded components
|
|
455
506
|
constructor(
|
|
456
507
|
/**
|
|
457
508
|
* private pubsub.
|
|
@@ -511,12 +562,16 @@ class Workspace {
|
|
|
511
562
|
(0, _defineProperty2().default)(this, "componentsScopeDirsMap", void 0);
|
|
512
563
|
(0, _defineProperty2().default)(this, "componentLoader", void 0);
|
|
513
564
|
(0, _defineProperty2().default)(this, "bitMap", void 0);
|
|
565
|
+
(0, _defineProperty2().default)(this, "componentLoadedSelfAsAspects", void 0);
|
|
514
566
|
(0, _defineProperty2().default)(this, "watcher", new (_watcher().Watcher)(this, this.pubsub));
|
|
515
|
-
|
|
567
|
+
this.componentLoadedSelfAsAspects = (0, _cacheFactory().createInMemoryCache)({
|
|
568
|
+
maxSize: (0, _inMemoryCache().getMaxSizeForComponents)()
|
|
569
|
+
}); // TODO: refactor - prefer to avoid code inside the constructor.
|
|
570
|
+
|
|
516
571
|
this.owner = (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.defaultOwner;
|
|
517
572
|
this.componentLoader = new (_workspaceComponentLoader().WorkspaceComponentLoader)(this, logger, dependencyResolver, envs);
|
|
518
573
|
this.validateConfig();
|
|
519
|
-
this.bitMap = new (
|
|
574
|
+
this.bitMap = new (_bitMap().BitMap)(this.consumer.bitMap, this.consumer); // memoize this method to improve performance.
|
|
520
575
|
|
|
521
576
|
this.componentDefaultScopeFromComponentDirAndNameWithoutConfigFile = (0, _memoizee().default)(this.componentDefaultScopeFromComponentDirAndNameWithoutConfigFile.bind(this), {
|
|
522
577
|
primitive: true,
|
|
@@ -787,7 +842,33 @@ class Workspace {
|
|
|
787
842
|
|
|
788
843
|
async get(componentId, forCapsule = false, legacyComponent, useCache = true, storeInCache = true) {
|
|
789
844
|
this.logger.debug(`get ${componentId.toString()}`);
|
|
790
|
-
|
|
845
|
+
const component = await this.componentLoader.get(componentId, forCapsule, legacyComponent, useCache, storeInCache); // When loading a component if it's an env make sure to load it as aspect as well
|
|
846
|
+
// We only want to try load it as aspect if it's the first time we load the component
|
|
847
|
+
|
|
848
|
+
const tryLoadAsAspect = this.componentLoadedSelfAsAspects.get(component.id.toString()) === undefined; // const config = this.harmony.get<ConfigMain>('teambit.harmony/config');
|
|
849
|
+
// We are loading the component as aspect if it's an env, in order to be able to run the env-preview-template task which run only on envs.
|
|
850
|
+
// Without this loading we will have a problem in case the env is the only component in the workspace. in that case we will load it as component
|
|
851
|
+
// then we don't run it's provider so it doesn't register to the env slot, so we don't know it's an env.
|
|
852
|
+
|
|
853
|
+
if (tryLoadAsAspect && this.envs.isUsingEnvEnv(component) && !this.aspectLoader.isCoreAspect(component.id.toStringWithoutVersion()) && !this.aspectLoader.isAspectLoaded(component.id.toString()) && (await this.hasId(component.id)) // !config.extension(component.id.toStringWithoutVersion(), true)
|
|
854
|
+
) {
|
|
855
|
+
try {
|
|
856
|
+
this.componentLoadedSelfAsAspects.set(component.id.toString(), true);
|
|
857
|
+
this.logger.debug(`trying to load self as aspect with id ${component.id.toString()}`);
|
|
858
|
+
await this.loadAspects([component.id.toString()]); // In most cases if the load self as aspect failed we don't care about it.
|
|
859
|
+
// we only need it in specific cases to work, but this workspace.get runs on different
|
|
860
|
+
// cases where it might fail (like when importing aspect, after the import objects
|
|
861
|
+
// when we write the package.json we run the applyTransformers which get to pkg which call
|
|
862
|
+
// host.get, but the component not written yet to the fs, so it fails.)
|
|
863
|
+
} catch (e) {
|
|
864
|
+
this.logger.debug(`fail to load self as aspect with id ${component.id.toString()}`);
|
|
865
|
+
this.componentLoadedSelfAsAspects.delete(component.id.toString());
|
|
866
|
+
return component;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
this.componentLoadedSelfAsAspects.set(component.id.toString(), false);
|
|
871
|
+
return component;
|
|
791
872
|
} // TODO: @gilad we should refactor this asap into to the envs aspect.
|
|
792
873
|
|
|
793
874
|
|
|
@@ -910,7 +991,7 @@ class Workspace {
|
|
|
910
991
|
*/
|
|
911
992
|
|
|
912
993
|
|
|
913
|
-
getCurrentRemoteLaneId() {
|
|
994
|
+
async getCurrentRemoteLaneId() {
|
|
914
995
|
const currentLane = this.getCurrentLaneId();
|
|
915
996
|
|
|
916
997
|
if (currentLane.isDefault()) {
|
|
@@ -919,14 +1000,32 @@ class Workspace {
|
|
|
919
1000
|
|
|
920
1001
|
const trackData = this.scope.legacyScope.lanes.getRemoteTrackedDataByLocalLane(currentLane.name);
|
|
921
1002
|
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
if (!trackData || !remoteLane) {
|
|
1003
|
+
if (!trackData) {
|
|
925
1004
|
return null;
|
|
926
1005
|
}
|
|
927
1006
|
|
|
928
|
-
const
|
|
929
|
-
|
|
1007
|
+
const scopeComponentImporter = _scopeComponentsImporter().default.getInstance(this.consumer.scope);
|
|
1008
|
+
|
|
1009
|
+
const laneId = _laneId().RemoteLaneId.from(trackData.remoteLane, trackData.remoteScope);
|
|
1010
|
+
|
|
1011
|
+
try {
|
|
1012
|
+
const lanes = await scopeComponentImporter.importLanes([laneId]);
|
|
1013
|
+
if (!lanes || lanes.length === 0) return null;
|
|
1014
|
+
return {
|
|
1015
|
+
laneId,
|
|
1016
|
+
lane: lanes[0]
|
|
1017
|
+
};
|
|
1018
|
+
} catch (err) {
|
|
1019
|
+
if (err instanceof _legacyBitId().InvalidScopeName || err instanceof _scopeNotFoundOrDenied().ScopeNotFoundOrDenied || err instanceof _laneNotFound().LaneNotFound) {
|
|
1020
|
+
// the lane could be a local lane so no need to throw an error in such case
|
|
1021
|
+
_loader().default.stop();
|
|
1022
|
+
|
|
1023
|
+
this.logger.warn(`unable to get lane's data from a remote due to an error:\n${err.message}`);
|
|
1024
|
+
return null;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
throw err;
|
|
1028
|
+
}
|
|
930
1029
|
}
|
|
931
1030
|
|
|
932
1031
|
getDefaultExtensions() {
|
|
@@ -1243,6 +1342,7 @@ class Workspace {
|
|
|
1243
1342
|
* the component.json file in the component folder
|
|
1244
1343
|
* matching pattern in the variants config
|
|
1245
1344
|
* defaults extensions from workspace config
|
|
1345
|
+
* extensions from the model.
|
|
1246
1346
|
*/
|
|
1247
1347
|
|
|
1248
1348
|
|
|
@@ -1474,20 +1574,12 @@ class Workspace {
|
|
|
1474
1574
|
const components = await this.importAndGetAspects(componentIds);
|
|
1475
1575
|
|
|
1476
1576
|
const isAspect = async bitId => {
|
|
1477
|
-
var _component$config$ext;
|
|
1478
|
-
|
|
1479
1577
|
const id = await this.resolveComponentId(bitId);
|
|
1480
1578
|
const component = await this.get(id);
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
if (!data) {
|
|
1484
|
-
// TODO: remove this once we re-export old components used to store the data here
|
|
1485
|
-
data = component.state.aspects.get('teambit.workspace/workspace');
|
|
1486
|
-
}
|
|
1487
|
-
|
|
1488
|
-
if (!data) return false;
|
|
1579
|
+
const data = this.envs.getEnvData(component);
|
|
1580
|
+
const isUsingAspectEnv = this.envs.isUsingAspectEnv(component);
|
|
1489
1581
|
|
|
1490
|
-
if (
|
|
1582
|
+
if (!isUsingAspectEnv && idsWithoutCore.includes(component.id.toString())) {
|
|
1491
1583
|
const err = new (_incorrectEnvAspect().IncorrectEnvAspect)(component.id.toString(), data.type, data.id);
|
|
1492
1584
|
|
|
1493
1585
|
if (data.id === _envs().DEFAULT_ENV) {
|
|
@@ -1500,7 +1592,7 @@ class Workspace {
|
|
|
1500
1592
|
}
|
|
1501
1593
|
}
|
|
1502
1594
|
|
|
1503
|
-
return
|
|
1595
|
+
return isUsingAspectEnv;
|
|
1504
1596
|
};
|
|
1505
1597
|
|
|
1506
1598
|
const graph = await this.getAspectsGraphWithoutCore(components, isAspect);
|
|
@@ -2081,12 +2173,24 @@ your workspace.jsonc has this component-id set. you might want to remove/change
|
|
|
2081
2173
|
|
|
2082
2174
|
|
|
2083
2175
|
async resolveComponentId(id) {
|
|
2084
|
-
|
|
2176
|
+
const getDefaultScope = async (bitId, bitMapOptions) => {
|
|
2177
|
+
if (bitId.scope) {
|
|
2178
|
+
return bitId.scope;
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
const relativeComponentDir = this.componentDirFromLegacyId(bitId, bitMapOptions, {
|
|
2182
|
+
relative: true
|
|
2183
|
+
});
|
|
2184
|
+
const defaultScope = await this.componentDefaultScopeFromComponentDirAndName(relativeComponentDir, bitId.toStringWithoutScopeAndVersion());
|
|
2185
|
+
return defaultScope;
|
|
2186
|
+
}; // This is required in case where you have in your workspace a component with the same name as a core aspect
|
|
2085
2187
|
// let's say you have component called react-native (which is eventually my-org.my-scope/react-native)
|
|
2086
2188
|
// and you set teambit.react/react-native as your env
|
|
2087
2189
|
// bit will get here with the string teambit.react/react-native and will try to resolve it from the workspace
|
|
2088
2190
|
// during this it will find the my-org.my-scope/react-native which is incorrect as the core one doesn't exist in the
|
|
2089
2191
|
// workspace
|
|
2192
|
+
|
|
2193
|
+
|
|
2090
2194
|
if (this.aspectLoader.isCoreAspect(id.toString())) {
|
|
2091
2195
|
return _component().ComponentID.fromString(id.toString());
|
|
2092
2196
|
}
|
|
@@ -2139,11 +2243,43 @@ your workspace.jsonc has this component-id set. you might want to remove/change
|
|
|
2139
2243
|
|
|
2140
2244
|
if (_bitMapIdWithoutVersion.endsWith(idWithoutVersion) && _bitMapIdWithoutVersion !== idWithoutVersion) {
|
|
2141
2245
|
return await this.scope.resolveComponentId(_bitMapIdWithVersion);
|
|
2142
|
-
} //
|
|
2143
|
-
//
|
|
2246
|
+
} // Handle case when I tagged the component locally with a default scope which is not the local scope
|
|
2247
|
+
// but not exported it yet
|
|
2248
|
+
// now i'm trying to load it with source id contain the default scope prefix
|
|
2249
|
+
// we want to get it from the local first before assuming it's something coming from outside
|
|
2250
|
+
|
|
2251
|
+
|
|
2252
|
+
if (!_bitMapId.scope) {
|
|
2253
|
+
const defaultScopeForBitmapId = await getDefaultScope(_bitMapId, {
|
|
2254
|
+
ignoreVersion: true
|
|
2255
|
+
});
|
|
2256
|
+
|
|
2257
|
+
const getFromBitmapAddDefaultScope = () => {
|
|
2258
|
+
let _bitmapIdWithVersionForSource = _bitMapId;
|
|
2259
|
+
|
|
2260
|
+
if (version) {
|
|
2261
|
+
_bitmapIdWithVersionForSource = _bitMapId.changeVersion(version);
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
return _component().ComponentID.fromLegacy(_bitmapIdWithVersionForSource, defaultScopeForBitmapId);
|
|
2265
|
+
}; // a case when the given id contains the default scope
|
|
2266
|
+
|
|
2267
|
+
|
|
2268
|
+
if (idWithVersion.startsWith(`${defaultScopeForBitmapId}/${_bitMapIdWithoutVersion}`)) {
|
|
2269
|
+
return getFromBitmapAddDefaultScope();
|
|
2270
|
+
} // a case when the given id does not contain the default scope
|
|
2271
|
+
|
|
2144
2272
|
|
|
2273
|
+
const fromScope = await this.scope.resolveComponentId(idWithVersion);
|
|
2274
|
+
|
|
2275
|
+
if (!fromScope._legacy.hasScope()) {
|
|
2276
|
+
return getFromBitmapAddDefaultScope();
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2145
2279
|
|
|
2146
2280
|
if (idWithoutVersion.endsWith(_bitMapIdWithoutVersion) && _bitMapIdWithoutVersion !== idWithoutVersion) {
|
|
2281
|
+
// The id in the bitmap doesn't have scope, the source id has scope
|
|
2282
|
+
// Handle use case 2 and use case 1
|
|
2147
2283
|
if (id.toString().startsWith(this.scope.name)) {
|
|
2148
2284
|
// Handle use case 1 - the provided id has scope name same as the local scope name
|
|
2149
2285
|
// we want to send it as it appear in the bitmap
|
|
@@ -2163,18 +2299,6 @@ your workspace.jsonc has this component-id set. you might want to remove/change
|
|
|
2163
2299
|
}
|
|
2164
2300
|
}
|
|
2165
2301
|
|
|
2166
|
-
const getDefaultScope = async bitId => {
|
|
2167
|
-
if (bitId.scope) {
|
|
2168
|
-
return bitId.scope;
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
const relativeComponentDir = this.componentDirFromLegacyId(bitId, undefined, {
|
|
2172
|
-
relative: true
|
|
2173
|
-
});
|
|
2174
|
-
const defaultScope = await this.componentDefaultScopeFromComponentDirAndName(relativeComponentDir, bitId.toStringWithoutScopeAndVersion());
|
|
2175
|
-
return defaultScope;
|
|
2176
|
-
};
|
|
2177
|
-
|
|
2178
2302
|
const defaultScope = await getDefaultScope(legacyId);
|
|
2179
2303
|
return _component().ComponentID.fromLegacy(legacyId, defaultScope);
|
|
2180
2304
|
}
|