@teambit/workspace 1.0.493 → 1.0.495
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/preview/teambit_workspace_workspace-preview.js +1 -1
- package/artifacts/schema.json +2480 -2208
- package/dist/{preview-1734020193676.js → preview-1734279612846.js} +2 -2
- package/dist/workspace-component/workspace-component-loader.js +18 -4
- package/dist/workspace-component/workspace-component-loader.js.map +1 -1
- package/dist/workspace.d.ts +8 -4
- package/dist/workspace.js +96 -17
- package/dist/workspace.js.map +1 -1
- package/dist/workspace.main.runtime.js +2 -0
- package/dist/workspace.main.runtime.js.map +1 -1
- package/package.json +37 -36
- package/workspace-component/workspace-component-loader.ts +25 -4
package/dist/workspace.js
CHANGED
|
@@ -11,6 +11,13 @@ function _memoizee() {
|
|
|
11
11
|
};
|
|
12
12
|
return data;
|
|
13
13
|
}
|
|
14
|
+
function _commentJson() {
|
|
15
|
+
const data = require("comment-json");
|
|
16
|
+
_commentJson = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
14
21
|
function _pMapSeries() {
|
|
15
22
|
const data = _interopRequireDefault(require("p-map-series"));
|
|
16
23
|
_pMapSeries = function () {
|
|
@@ -912,8 +919,8 @@ it's possible that the version ${component.id.version} belong to ${idStr.split('
|
|
|
912
919
|
});
|
|
913
920
|
return results;
|
|
914
921
|
}
|
|
915
|
-
async triggerOnComponentAdd(id, watchOpts) {
|
|
916
|
-
const component = await this.get(id);
|
|
922
|
+
async triggerOnComponentAdd(id, watchOpts, loadOptions) {
|
|
923
|
+
const component = await this.get(id, undefined, undefined, undefined, loadOptions);
|
|
917
924
|
const onAddEntries = this.onComponentAddSlot.toArray(); // e.g. [ [ 'teambit.bit/compiler', [Function: bound onComponentChange] ] ]
|
|
918
925
|
const results = [];
|
|
919
926
|
const files = component.state.filesystem.files.map(file => file.path);
|
|
@@ -1704,20 +1711,40 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
|
|
|
1704
1711
|
throw new Error(`findComponentIdFromPackageName supports only packages that start with @, got ${packageName}`);
|
|
1705
1712
|
}
|
|
1706
1713
|
const errMsgPrefix = `unable to resolve a component-id from the package-name ${packageName}, `;
|
|
1707
|
-
const
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1714
|
+
const fromPackageJson = await this.resolveComponentIdFromPackageJsonInNM(packageName, errMsgPrefix);
|
|
1715
|
+
if (fromPackageJson) return fromPackageJson;
|
|
1716
|
+
const fromRegistryManifest = await this.resolveComponentIdFromRegistryManifest(packageName, errMsgPrefix);
|
|
1717
|
+
if (fromRegistryManifest) return fromRegistryManifest;
|
|
1718
|
+
const fromWsComponents = await this.resolveComponentIdFromWsComponents(packageName);
|
|
1719
|
+
if (fromWsComponents) return fromWsComponents;
|
|
1720
|
+
throw new (_bitError().BitError)(errMsgPrefix);
|
|
1721
|
+
}
|
|
1722
|
+
async resolveComponentIdFromWsComponents(packageName) {
|
|
1723
|
+
const ids = this.consumer.bitMap.getAllIdsAvailableOnLane();
|
|
1724
|
+
const [, name] = packageName.split('/');
|
|
1725
|
+
const foundByName = ids.filter(id => id.fullName.includes(name));
|
|
1726
|
+
const idsToSearch = foundByName;
|
|
1727
|
+
if (!idsToSearch.length) {
|
|
1728
|
+
return undefined;
|
|
1713
1729
|
}
|
|
1714
|
-
if (
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1730
|
+
// if (!foundByName.length) {
|
|
1731
|
+
// const foundByScope = ids.filter(id => id.toString().includes(scope.replace('@', '')));
|
|
1732
|
+
// idsToSearch = foundByScope;
|
|
1733
|
+
// }
|
|
1734
|
+
const comps = await this.getMany(idsToSearch, {
|
|
1735
|
+
loadExtensions: false,
|
|
1736
|
+
storeInCache: false,
|
|
1737
|
+
loadSeedersAsAspects: false
|
|
1738
|
+
});
|
|
1739
|
+
const found = comps.find(comp => {
|
|
1740
|
+
const currPackageName = this.dependencyResolver.getPackageName(comp);
|
|
1741
|
+
return currPackageName === packageName;
|
|
1742
|
+
});
|
|
1743
|
+
if (found) {
|
|
1744
|
+
return found.id;
|
|
1720
1745
|
}
|
|
1746
|
+
}
|
|
1747
|
+
async resolveComponentIdFromRegistryManifest(packageName, errMsgPrefix) {
|
|
1721
1748
|
const url = `https://node-registry.bit.cloud/${packageName}`;
|
|
1722
1749
|
const token = await this.globalConfig.get(_legacy5().CFG_USER_TOKEN_KEY);
|
|
1723
1750
|
const headers = token ? (0, _scope2().getAuthHeader)(token) : {};
|
|
@@ -1725,7 +1752,7 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
|
|
|
1725
1752
|
headers
|
|
1726
1753
|
});
|
|
1727
1754
|
if (!res.ok) {
|
|
1728
|
-
|
|
1755
|
+
return undefined;
|
|
1729
1756
|
}
|
|
1730
1757
|
const data = await res.json();
|
|
1731
1758
|
const latest = data['dist-tags'].latest;
|
|
@@ -1736,6 +1763,22 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
|
|
|
1736
1763
|
if (!compId) throw new (_bitError().BitError)(`${errMsgPrefix}the package.json of version "${latest}" has no componentId field, it's probably not a component`);
|
|
1737
1764
|
return _componentId().ComponentID.fromObject(compId).changeVersion(undefined);
|
|
1738
1765
|
}
|
|
1766
|
+
async resolveComponentIdFromPackageJsonInNM(packageName, errMsgPrefix) {
|
|
1767
|
+
const pkgJsonPath = _path().default.join(this.path, 'node_modules', packageName, 'package.json');
|
|
1768
|
+
let pkgJson;
|
|
1769
|
+
try {
|
|
1770
|
+
pkgJson = await _fsExtra().default.readJson(pkgJsonPath);
|
|
1771
|
+
if (!pkgJson) return undefined;
|
|
1772
|
+
const compId = pkgJson.componentId;
|
|
1773
|
+
if (!compId) {
|
|
1774
|
+
throw new (_bitError().BitError)(`${errMsgPrefix}the package.json file has no componentId field, it's probably not a component`);
|
|
1775
|
+
}
|
|
1776
|
+
return _componentId().ComponentID.fromObject(compId);
|
|
1777
|
+
} catch {
|
|
1778
|
+
// never mind the reason. probably it's not there.
|
|
1779
|
+
return undefined;
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1739
1782
|
|
|
1740
1783
|
/**
|
|
1741
1784
|
* Transform the id to ComponentId and get the exact id as appear in bitmap
|
|
@@ -1952,6 +1995,42 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
|
|
|
1952
1995
|
if (!comp) throw new (_bitError().BitError)(`unable to find ${envId.toString()} in the workspace or in the remote`);
|
|
1953
1996
|
return comp.id.toString();
|
|
1954
1997
|
}
|
|
1998
|
+
async resolveEnvManifest(envId, envExtendsDeps = []) {
|
|
1999
|
+
if (this.aspectLoader.isCoreEnv(envId)) return {};
|
|
2000
|
+
const splitted = envId.split('@');
|
|
2001
|
+
const envIdWithVersion = envId.startsWith('@') ? `@${splitted[1]}` : splitted[0];
|
|
2002
|
+
const foundEnv = envExtendsDeps.find(dep => dep.id.toStringWithoutVersion() === envIdWithVersion || dep.packageName === envIdWithVersion);
|
|
2003
|
+
let id = envId;
|
|
2004
|
+
if (foundEnv?.id) {
|
|
2005
|
+
if (foundEnv.id.version.includes('-new')) {
|
|
2006
|
+
id = foundEnv.id.toStringWithoutVersion();
|
|
2007
|
+
} else {
|
|
2008
|
+
id = foundEnv.id.toString();
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
const resolvedEnvComponentId = await this.resolveComponentId(id);
|
|
2012
|
+
|
|
2013
|
+
// We need to load the env component with the slot and extensions to get the env manifest of the parent
|
|
2014
|
+
// already resolved
|
|
2015
|
+
const envComponent = await this.get(resolvedEnvComponentId, undefined, true, true, {
|
|
2016
|
+
executeLoadSlot: true,
|
|
2017
|
+
loadExtensions: true
|
|
2018
|
+
});
|
|
2019
|
+
|
|
2020
|
+
// TODO: caching this
|
|
2021
|
+
const alreadyResolved = this.envs.getEnvManifest(envComponent);
|
|
2022
|
+
if (alreadyResolved) return alreadyResolved;
|
|
2023
|
+
|
|
2024
|
+
// TODO: caching this
|
|
2025
|
+
const envJson = envComponent.filesystem.files.find(file => {
|
|
2026
|
+
return file.relative === 'env.jsonc' || file.relative === 'env.json';
|
|
2027
|
+
});
|
|
2028
|
+
if (!envJson) {
|
|
2029
|
+
throw new (_bitError().BitError)(`unable to find env.jsonc file in ${envId}`);
|
|
2030
|
+
}
|
|
2031
|
+
const envManifest = (0, _commentJson().parse)(envJson.contents.toString('utf8'), undefined, true);
|
|
2032
|
+
return envManifest;
|
|
2033
|
+
}
|
|
1955
2034
|
|
|
1956
2035
|
/**
|
|
1957
2036
|
* remove env configuration from the .bitmap file, so then other configuration, such as "variants" will take place
|
|
@@ -2073,8 +2152,8 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
|
|
|
2073
2152
|
});
|
|
2074
2153
|
return this.dependencyResolver.getInjectedDirs(this.path, relativeCompDir, this.dependencyResolver.getPackageName(component));
|
|
2075
2154
|
}
|
|
2076
|
-
async getAutoDetectOverrides(configuredExtensions, id, legacyFiles) {
|
|
2077
|
-
let policy = await this.dependencyResolver.mergeVariantPolicies(configuredExtensions, id, legacyFiles);
|
|
2155
|
+
async getAutoDetectOverrides(configuredExtensions, id, legacyFiles, envExtendedDeps) {
|
|
2156
|
+
let policy = await this.dependencyResolver.mergeVariantPolicies(configuredExtensions, id, legacyFiles, envExtendedDeps);
|
|
2078
2157
|
// this is needed for "bit install" to install the dependencies from the merge config (see https://github.com/teambit/bit/pull/6849)
|
|
2079
2158
|
const depsDataOfMergeConfig = this.getDepsDataOfMergeConfig(id);
|
|
2080
2159
|
if (depsDataOfMergeConfig) {
|