@teambit/workspace 0.0.596 → 0.0.601
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/dist/bit-map.d.ts +10 -2
- package/dist/bit-map.js +38 -3
- package/dist/bit-map.js.map +1 -1
- package/dist/envs-subcommands/envs-set.cmd.d.ts +11 -0
- package/dist/envs-subcommands/envs-set.cmd.js +55 -0
- package/dist/envs-subcommands/envs-set.cmd.js.map +1 -0
- package/dist/envs-subcommands/envs-unset.cmd.d.ts +11 -0
- package/dist/envs-subcommands/envs-unset.cmd.js +46 -0
- package/dist/envs-subcommands/envs-unset.cmd.js.map +1 -0
- package/dist/workspace-component/workspace-component-loader.d.ts +1 -0
- package/dist/workspace-component/workspace-component-loader.js +15 -2
- package/dist/workspace-component/workspace-component-loader.js.map +1 -1
- package/dist/workspace.d.ts +22 -5
- package/dist/workspace.js +108 -22
- package/dist/workspace.js.map +1 -1
- package/dist/workspace.provider.js +29 -1
- package/dist/workspace.provider.js.map +1 -1
- package/envs-subcommands/envs-set.cmd.ts +20 -0
- package/envs-subcommands/envs-unset.cmd.ts +18 -0
- package/package-tar/teambit-workspace-0.0.601.tgz +0 -0
- package/package.json +40 -40
- package/workspace-component/workspace-component-loader.ts +15 -3
- package/package-tar/teambit-workspace-0.0.596.tgz +0 -0
package/dist/workspace.js
CHANGED
|
@@ -1009,6 +1009,22 @@ class Workspace {
|
|
|
1009
1009
|
return this.get(id, undefined, component);
|
|
1010
1010
|
});
|
|
1011
1011
|
}
|
|
1012
|
+
/**
|
|
1013
|
+
* don't throw an error if the component was not found, simply return undefined.
|
|
1014
|
+
*/
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
async getIfExist(componentId) {
|
|
1018
|
+
return this.componentLoader.getIfExist(componentId);
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* whether a component exists in the workspace
|
|
1022
|
+
*/
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
exists(componentId) {
|
|
1026
|
+
return Boolean(this.consumer.bitmapIdsFromCurrentLane.find(_ => _.isEqualWithoutVersion(componentId._legacy)));
|
|
1027
|
+
}
|
|
1012
1028
|
/**
|
|
1013
1029
|
* This will make sure to fetch the objects prior to load them
|
|
1014
1030
|
* do not use it if you are not sure you need it.
|
|
@@ -1107,7 +1123,7 @@ class Workspace {
|
|
|
1107
1123
|
|
|
1108
1124
|
async write(rootPath, component) {
|
|
1109
1125
|
await Promise.all(component.filesystem.files.map(async file => {
|
|
1110
|
-
const pathToWrite = _path().default.join(this.path, rootPath, file.
|
|
1126
|
+
const pathToWrite = _path().default.join(this.path, rootPath, file.relative);
|
|
1111
1127
|
|
|
1112
1128
|
await _fsExtra().default.outputFile(pathToWrite, file.contents);
|
|
1113
1129
|
}));
|
|
@@ -1210,19 +1226,15 @@ class Workspace {
|
|
|
1210
1226
|
}
|
|
1211
1227
|
/**
|
|
1212
1228
|
* Calculate the component config based on:
|
|
1229
|
+
* the config property in the .bitmap file
|
|
1213
1230
|
* the component.json file in the component folder
|
|
1214
1231
|
* matching pattern in the variants config
|
|
1215
1232
|
* defaults extensions from workspace config
|
|
1216
|
-
*
|
|
1217
|
-
* @param {ComponentID} componentId
|
|
1218
|
-
* @param {Component} [componentFromScope]
|
|
1219
|
-
* @returns {Promise<ExtensionDataList>}
|
|
1220
|
-
* @memberof Workspace
|
|
1221
1233
|
*/
|
|
1222
1234
|
|
|
1223
1235
|
|
|
1224
1236
|
async componentExtensions(componentId, componentFromScope) {
|
|
1225
|
-
var _componentFromScope$c, _componentConfigFile$, _variantConfig$propag;
|
|
1237
|
+
var _componentFromScope$c, _componentConfigFile$, _variantConfig$propag, _wsDefaultExtensions;
|
|
1226
1238
|
|
|
1227
1239
|
// TODO: consider caching this result
|
|
1228
1240
|
let configFileExtensions;
|
|
@@ -1262,54 +1274,83 @@ class Workspace {
|
|
|
1262
1274
|
|
|
1263
1275
|
|
|
1264
1276
|
const extensionsToMerge = [];
|
|
1277
|
+
let envWasFoundPreviously = false;
|
|
1278
|
+
|
|
1279
|
+
const addAndLoadExtensions = async extensions => {
|
|
1280
|
+
const extsWithoutRemoved = extensions.filterRemovedExtensions();
|
|
1281
|
+
const selfInMergedExtensions = extsWithoutRemoved.findExtension(componentId._legacy.toStringWithoutScopeAndVersion(), true, true);
|
|
1282
|
+
const extsWithoutSelf = selfInMergedExtensions !== null && selfInMergedExtensions !== void 0 && selfInMergedExtensions.extensionId ? extsWithoutRemoved.remove(selfInMergedExtensions.extensionId) : extsWithoutRemoved;
|
|
1283
|
+
await this.loadExtensions(extsWithoutSelf);
|
|
1284
|
+
const {
|
|
1285
|
+
extensionDataListFiltered,
|
|
1286
|
+
envIsCurrentlySet
|
|
1287
|
+
} = this.filterEnvsFromExtensionsIfNeeded(extsWithoutSelf, envWasFoundPreviously);
|
|
1288
|
+
if (envIsCurrentlySet) envWasFoundPreviously = true;
|
|
1289
|
+
extensionsToMerge.push(extensionDataListFiltered);
|
|
1290
|
+
};
|
|
1265
1291
|
|
|
1266
1292
|
if (bitMapExtensions) {
|
|
1267
1293
|
const extensionsDataEntries = Object.keys(bitMapExtensions).map(aspectId => new (_extensionData().ExtensionDataEntry)(aspectId, undefined, aspectId, bitMapExtensions[aspectId]));
|
|
1268
1294
|
const extensionDataList = new (_extensionData().ExtensionDataList)(...extensionsDataEntries);
|
|
1269
|
-
|
|
1295
|
+
await addAndLoadExtensions(extensionDataList);
|
|
1270
1296
|
}
|
|
1271
1297
|
|
|
1272
1298
|
if (configFileExtensions) {
|
|
1273
|
-
|
|
1299
|
+
await addAndLoadExtensions(configFileExtensions);
|
|
1274
1300
|
}
|
|
1275
1301
|
|
|
1276
1302
|
let continuePropagating = (_componentConfigFile$ = componentConfigFile === null || componentConfigFile === void 0 ? void 0 : componentConfigFile.propagate) !== null && _componentConfigFile$ !== void 0 ? _componentConfigFile$ : true;
|
|
1277
1303
|
|
|
1278
1304
|
if (variantsExtensions && continuePropagating) {
|
|
1279
1305
|
// Put it in the start to make sure the config file is stronger
|
|
1280
|
-
|
|
1306
|
+
await addAndLoadExtensions(variantsExtensions);
|
|
1281
1307
|
}
|
|
1282
1308
|
|
|
1283
1309
|
continuePropagating = continuePropagating && ((_variantConfig$propag = variantConfig === null || variantConfig === void 0 ? void 0 : variantConfig.propagate) !== null && _variantConfig$propag !== void 0 ? _variantConfig$propag : true); // Do not apply default extensions on the default extensions (it will create infinite loop when loading them)
|
|
1284
1310
|
|
|
1285
|
-
const isDefaultExtension = wsDefaultExtensions.findExtension(componentId.toString(), true, true);
|
|
1311
|
+
const isDefaultExtension = (_wsDefaultExtensions = wsDefaultExtensions) === null || _wsDefaultExtensions === void 0 ? void 0 : _wsDefaultExtensions.findExtension(componentId.toString(), true, true);
|
|
1286
1312
|
|
|
1287
1313
|
if (wsDefaultExtensions && continuePropagating && !isDefaultExtension) {
|
|
1288
1314
|
// Put it in the start to make sure the config file is stronger
|
|
1289
|
-
|
|
1315
|
+
await addAndLoadExtensions(wsDefaultExtensions);
|
|
1290
1316
|
} // It's before the scope extensions, since there is no need to resolve extensions from scope they are already resolved
|
|
1291
1317
|
// await Promise.all(extensionsToMerge.map((extensions) => this.resolveExtensionsList(extensions)));
|
|
1292
1318
|
|
|
1293
1319
|
|
|
1294
1320
|
if (mergeFromScope && continuePropagating) {
|
|
1295
|
-
|
|
1321
|
+
await addAndLoadExtensions(scopeExtensions);
|
|
1296
1322
|
} // It's important to do this resolution before the merge, otherwise we have issues with extensions
|
|
1297
1323
|
// coming from scope with local scope name, as opposed to the same extension comes from the workspace with default scope name
|
|
1298
1324
|
|
|
1299
1325
|
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
let mergedExtensions = _extensionData().ExtensionDataList.mergeConfigs(extensionsToMerge).filterRemovedExtensions(); // remove self from merged extensions
|
|
1304
|
-
|
|
1326
|
+
await Promise.all(extensionsToMerge.map(list => this.resolveExtensionListIds(list)));
|
|
1327
|
+
return _extensionData().ExtensionDataList.mergeConfigs(extensionsToMerge);
|
|
1328
|
+
}
|
|
1305
1329
|
|
|
1306
|
-
|
|
1330
|
+
filterEnvsFromExtensionsIfNeeded(extensionDataList, envWasFoundPreviously) {
|
|
1331
|
+
const envAspect = extensionDataList.findExtension(_envs().EnvsAspect.id);
|
|
1332
|
+
const envFromEnvsAspect = envAspect === null || envAspect === void 0 ? void 0 : envAspect.config.env;
|
|
1333
|
+
const [envsNotFromEnvsAspect, nonEnvs] = (0, _lodash().partition)(extensionDataList, ext => this.envs.isEnvRegistered(ext.stringId));
|
|
1334
|
+
const extensionDataListFiltered = new (_extensionData().ExtensionDataList)(...nonEnvs);
|
|
1335
|
+
const envIsCurrentlySet = envFromEnvsAspect || envsNotFromEnvsAspect.length;
|
|
1336
|
+
const shouldIgnoreCurrentEnv = envIsCurrentlySet && envWasFoundPreviously;
|
|
1307
1337
|
|
|
1308
|
-
if (
|
|
1309
|
-
|
|
1338
|
+
if (shouldIgnoreCurrentEnv) {
|
|
1339
|
+
// still, aspect env may have other data other then config.env.
|
|
1340
|
+
if (envAspect) {
|
|
1341
|
+
delete envAspect.config.env;
|
|
1342
|
+
extensionDataListFiltered.push(envAspect);
|
|
1343
|
+
}
|
|
1344
|
+
} else {
|
|
1345
|
+
// add the envs
|
|
1346
|
+
if (envAspect) extensionDataListFiltered.push(envAspect);
|
|
1347
|
+
extensionDataListFiltered.push(...envsNotFromEnvsAspect);
|
|
1310
1348
|
}
|
|
1311
1349
|
|
|
1312
|
-
return
|
|
1350
|
+
return {
|
|
1351
|
+
extensionDataListFiltered,
|
|
1352
|
+
envIsCurrentlySet
|
|
1353
|
+
};
|
|
1313
1354
|
}
|
|
1314
1355
|
|
|
1315
1356
|
async triggerOnPreWatch(componentIds, watchOpts) {
|
|
@@ -2183,6 +2224,51 @@ your workspace.jsonc has this component-id set. you might want to remove/change
|
|
|
2183
2224
|
dedupe: true
|
|
2184
2225
|
});
|
|
2185
2226
|
}
|
|
2227
|
+
/**
|
|
2228
|
+
* configure an environment to the given components in the .bitmap file, this configuration overrides other, such as
|
|
2229
|
+
* overrides in workspace.jsonc.
|
|
2230
|
+
*/
|
|
2231
|
+
|
|
2232
|
+
|
|
2233
|
+
async setEnvToComponents(envId, components) {
|
|
2234
|
+
const envIdStr = envId.toString();
|
|
2235
|
+
components.forEach(component => {
|
|
2236
|
+
this.bitMap.addComponentConfig(component.id, envIdStr);
|
|
2237
|
+
this.bitMap.addComponentConfig(component.id, _envs().EnvsAspect.id, {
|
|
2238
|
+
env: envIdStr
|
|
2239
|
+
});
|
|
2240
|
+
});
|
|
2241
|
+
await this.bitMap.write();
|
|
2242
|
+
}
|
|
2243
|
+
/**
|
|
2244
|
+
* remove env configuration from the .bitmap file, so then other configuration, such as "variants" will take place
|
|
2245
|
+
*/
|
|
2246
|
+
|
|
2247
|
+
|
|
2248
|
+
async unsetEnvFromComponents(components) {
|
|
2249
|
+
const changed = [];
|
|
2250
|
+
const unchanged = [];
|
|
2251
|
+
components.forEach(comp => {
|
|
2252
|
+
var _bitMapEntry$config, _bitMapEntry$config$E;
|
|
2253
|
+
|
|
2254
|
+
const bitMapEntry = this.bitMap.getBitmapEntry(comp.id);
|
|
2255
|
+
const currentEnv = (_bitMapEntry$config = bitMapEntry.config) === null || _bitMapEntry$config === void 0 ? void 0 : (_bitMapEntry$config$E = _bitMapEntry$config[_envs().EnvsAspect.id]) === null || _bitMapEntry$config$E === void 0 ? void 0 : _bitMapEntry$config$E.env;
|
|
2256
|
+
|
|
2257
|
+
if (!currentEnv) {
|
|
2258
|
+
unchanged.push(comp.id);
|
|
2259
|
+
return;
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
this.bitMap.removeComponentConfig(comp.id, currentEnv);
|
|
2263
|
+
this.bitMap.removeComponentConfig(comp.id, _envs().EnvsAspect.id);
|
|
2264
|
+
changed.push(comp.id);
|
|
2265
|
+
});
|
|
2266
|
+
await this.bitMap.write();
|
|
2267
|
+
return {
|
|
2268
|
+
changed,
|
|
2269
|
+
unchanged
|
|
2270
|
+
};
|
|
2271
|
+
}
|
|
2186
2272
|
|
|
2187
2273
|
}
|
|
2188
2274
|
/**
|