@teambit/isolator 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.
- package/capsule-list.ts +65 -0
- package/dist/capsule/container.js +2 -3
- package/dist/capsule/container.js.map +1 -1
- package/dist/capsule-list.js +1 -2
- package/dist/capsule-list.js.map +1 -1
- package/dist/isolator.composition.d.ts +2 -2
- package/dist/isolator.main.runtime.d.ts +8 -8
- package/dist/isolator.main.runtime.js +9 -14
- package/dist/isolator.main.runtime.js.map +1 -1
- package/dist/{preview-1703590665075.js → preview-1703647408454.js} +2 -2
- package/index.ts +6 -0
- package/isolator.aspect.ts +7 -0
- package/isolator.main.runtime.ts +1244 -0
- package/network.ts +103 -0
- package/package.json +20 -27
- package/symlink-dependencies-to-capsules.ts +68 -0
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
package/network.ts
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
import { ComponentID } from '@teambit/component';
|
2
|
+
import { PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
|
3
|
+
import { compact } from 'lodash';
|
4
|
+
import CapsuleList from './capsule-list';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* collection of isolated components (capsules).
|
8
|
+
* normally, "seeders" are the components that this network was created for.
|
9
|
+
* "graphCapsules" is the graph created from the seeders and it includes also the dependencies.
|
10
|
+
*
|
11
|
+
* however, during "bit build"/"bit tag"/"bit snap", things are more complex because there is one more variable in the
|
12
|
+
* picture, which is the "env". the Network is created per env.
|
13
|
+
* in practice, for "build-task", a task is called per env, and the network passed to the task is relevant to that env.
|
14
|
+
* the "originalSeeders" are the ones the network was created for, but only for this env.
|
15
|
+
* the "seeders" are similar to the "graphCapsules" above, which contains also the dependencies, but only for this env.
|
16
|
+
* the "graphCapsules" is the entire graph, including capsules from other envs.
|
17
|
+
*
|
18
|
+
* for example:
|
19
|
+
* comp1 depends on comp2. comp1 env is "react". comp2 env is "aspect".
|
20
|
+
*
|
21
|
+
* when the user is running "bit build comp1", two `Network` instances will be created with the following:
|
22
|
+
* Network for "react" env: originalSeeders: ['comp1'], seeders: ['comp1'], graphCapsules: ['comp1', 'comp2'].
|
23
|
+
* Network for "aspect" env: originalSeeders: [], seeders: ['comp2'], graphCapsules: ['comp2'].
|
24
|
+
*
|
25
|
+
* on the other hand, when the user is running "bit capsule create comp1", only one `Network` instance is created:
|
26
|
+
* Network: originalSeeders: ['comp1'], seeders: ['comp1'], graphCapsules: ['comp1', 'comp2'].
|
27
|
+
*
|
28
|
+
* (as a side note, another implementation was attempt to have the "seeders" as the original-seeders for build,
|
29
|
+
* however, it's failed. see https://github.com/teambit/bit/pull/5407 for more details).
|
30
|
+
*/
|
31
|
+
export class Network {
|
32
|
+
_originalSeeders: ComponentID[] | undefined;
|
33
|
+
constructor(
|
34
|
+
private _graphCapsules: CapsuleList,
|
35
|
+
private seedersIds: ComponentID[],
|
36
|
+
private _capsulesRootDir: string
|
37
|
+
) {}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* for build-tasks (during bit build/tag/snap), this includes the component graph of the current env only.
|
41
|
+
* otherwise, this includes the original components the network was created for.
|
42
|
+
*/
|
43
|
+
get seedersCapsules(): CapsuleList {
|
44
|
+
const capsules = this.seedersIds.map((seederId) => {
|
45
|
+
const capsule = this.graphCapsules.getCapsule(seederId);
|
46
|
+
if (!capsule) throw new Error(`unable to find ${seederId.toString()} in the capsule list`);
|
47
|
+
return capsule;
|
48
|
+
});
|
49
|
+
return CapsuleList.fromArray(capsules);
|
50
|
+
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* for build-tasks (during bit build/tag/snap), this includes the original components of the current env.
|
54
|
+
* otherwise, this is the same as `this.seedersCapsules()`.
|
55
|
+
*/
|
56
|
+
get originalSeedersCapsules(): CapsuleList {
|
57
|
+
const capsules = this.getOriginalSeeders().map((seederId) => {
|
58
|
+
const capsule = this.graphCapsules.getCapsule(seederId);
|
59
|
+
if (!capsule) throw new Error(`unable to find ${seederId.toString()} in the capsule list`);
|
60
|
+
return capsule;
|
61
|
+
});
|
62
|
+
return CapsuleList.fromArray(capsules);
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* some of the capsules (non-modified) are written already with the dists files, so no need to re-compile them.
|
67
|
+
* this method helps optimizing compilers that are running on the capsules.
|
68
|
+
*/
|
69
|
+
async getCapsulesToCompile() {
|
70
|
+
const originalSeedersCapsules = this.originalSeedersCapsules;
|
71
|
+
const capsules = await Promise.all(
|
72
|
+
this.seedersCapsules.map(async (seederCapsule) => {
|
73
|
+
if (originalSeedersCapsules.getCapsule(seederCapsule.component.id)) {
|
74
|
+
return seederCapsule;
|
75
|
+
}
|
76
|
+
const capsuleUsePreviouslySavedDists = await CapsuleList.capsuleUsePreviouslySavedDists(
|
77
|
+
seederCapsule.component
|
78
|
+
);
|
79
|
+
return capsuleUsePreviouslySavedDists ? null : seederCapsule;
|
80
|
+
})
|
81
|
+
);
|
82
|
+
return CapsuleList.fromArray(compact(capsules));
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* originalSeeders are not always set (currently, only during build process), so if they're missing, just provide the
|
87
|
+
* seeders, which are probably the original-seeders
|
88
|
+
*/
|
89
|
+
private getOriginalSeeders(): ComponentID[] {
|
90
|
+
return this._originalSeeders || this.seedersIds;
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* all capsules, including the dependencies of the seeders. (even when they belong to another env)
|
95
|
+
*/
|
96
|
+
get graphCapsules(): CapsuleList {
|
97
|
+
return this._graphCapsules;
|
98
|
+
}
|
99
|
+
|
100
|
+
get capsulesRootDir(): PathOsBasedAbsolute {
|
101
|
+
return this._capsulesRootDir;
|
102
|
+
}
|
103
|
+
}
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/isolator",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.108",
|
4
4
|
"homepage": "https://bit.cloud/teambit/component/isolator",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.component",
|
8
8
|
"name": "isolator",
|
9
|
-
"version": "1.0.
|
9
|
+
"version": "1.0.108"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"chalk": "2.4.2",
|
@@ -24,39 +24,35 @@
|
|
24
24
|
"glob": "7.1.6",
|
25
25
|
"debug": "4.3.4",
|
26
26
|
"execa": "2.1.0",
|
27
|
-
"core-js": "^3.0.0",
|
28
|
-
"@babel/runtime": "7.20.0",
|
29
27
|
"@teambit/component-id": "1.2.0",
|
30
28
|
"@teambit/graph.cleargraph": "0.0.1",
|
31
29
|
"@teambit/harmony": "0.4.6",
|
32
|
-
"@teambit/component": "1.0.
|
33
|
-
"@teambit/dependency-resolver": "1.0.
|
34
|
-
"@teambit/aspect-loader": "1.0.
|
35
|
-
"@teambit/cli": "0.0.
|
36
|
-
"@teambit/component-package-version": "0.0.
|
30
|
+
"@teambit/component": "1.0.108",
|
31
|
+
"@teambit/dependency-resolver": "1.0.108",
|
32
|
+
"@teambit/aspect-loader": "1.0.108",
|
33
|
+
"@teambit/cli": "0.0.840",
|
34
|
+
"@teambit/component-package-version": "0.0.431",
|
37
35
|
"@teambit/dependencies.fs.linked-dependencies": "0.0.6",
|
38
|
-
"@teambit/global-config": "0.0.
|
39
|
-
"@teambit/graph": "1.0.
|
40
|
-
"@teambit/logger": "0.0.
|
41
|
-
"@teambit/workspace.modules.node-modules-linker": "0.0.
|
36
|
+
"@teambit/global-config": "0.0.842",
|
37
|
+
"@teambit/graph": "1.0.108",
|
38
|
+
"@teambit/logger": "0.0.933",
|
39
|
+
"@teambit/workspace.modules.node-modules-linker": "0.0.158"
|
42
40
|
},
|
43
41
|
"devDependencies": {
|
44
|
-
"@types/react": "^17.0.8",
|
45
42
|
"@types/fs-extra": "9.0.7",
|
46
43
|
"@types/lodash": "4.14.165",
|
47
44
|
"@types/object-hash": "1.3.4",
|
48
45
|
"@types/semver": "7.3.4",
|
49
46
|
"@types/uuid": "8.3.4",
|
50
47
|
"@types/mocha": "9.1.0",
|
51
|
-
"@types/
|
52
|
-
"@types/
|
53
|
-
"@
|
54
|
-
"@types/testing-library__jest-dom": "5.9.5"
|
48
|
+
"@types/jest": "^29.2.2",
|
49
|
+
"@types/testing-library__jest-dom": "^5.9.5",
|
50
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.13"
|
55
51
|
},
|
56
52
|
"peerDependencies": {
|
57
|
-
"
|
58
|
-
"react": "^
|
59
|
-
"
|
53
|
+
"react": "^17.0.0 || ^18.0.0",
|
54
|
+
"@types/react": "^18.2.12",
|
55
|
+
"@teambit/legacy": "1.0.624"
|
60
56
|
},
|
61
57
|
"license": "Apache-2.0",
|
62
58
|
"optionalDependencies": {},
|
@@ -70,7 +66,7 @@
|
|
70
66
|
},
|
71
67
|
"private": false,
|
72
68
|
"engines": {
|
73
|
-
"node": ">=
|
69
|
+
"node": ">=16.0.0"
|
74
70
|
},
|
75
71
|
"repository": {
|
76
72
|
"type": "git",
|
@@ -79,12 +75,9 @@
|
|
79
75
|
"keywords": [
|
80
76
|
"bit",
|
81
77
|
"bit-aspect",
|
78
|
+
"bit-core-aspect",
|
82
79
|
"components",
|
83
80
|
"collaboration",
|
84
|
-
"web"
|
85
|
-
"react",
|
86
|
-
"react-components",
|
87
|
-
"angular",
|
88
|
-
"angular-components"
|
81
|
+
"web"
|
89
82
|
]
|
90
83
|
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import { LinkDetail } from '@teambit/dependency-resolver';
|
2
|
+
import { Logger } from '@teambit/logger';
|
3
|
+
import { ComponentID } from '@teambit/component-id';
|
4
|
+
import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
|
5
|
+
import componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';
|
6
|
+
import path from 'path';
|
7
|
+
|
8
|
+
import { Capsule } from './capsule';
|
9
|
+
import CapsuleList from './capsule-list';
|
10
|
+
|
11
|
+
export async function symlinkDependenciesToCapsules(
|
12
|
+
capsules: Capsule[],
|
13
|
+
capsuleList: CapsuleList,
|
14
|
+
logger: Logger
|
15
|
+
): Promise<Record<string, Record<string, string>>> {
|
16
|
+
logger.debug(`symlinkDependenciesToCapsules, ${capsules.length} capsules`);
|
17
|
+
return Object.fromEntries(
|
18
|
+
await Promise.all(
|
19
|
+
capsules.map((capsule) => {
|
20
|
+
return symlinkComponent(capsule.component.state._consumer, capsuleList, logger);
|
21
|
+
})
|
22
|
+
)
|
23
|
+
);
|
24
|
+
}
|
25
|
+
|
26
|
+
export async function symlinkOnCapsuleRoot(
|
27
|
+
capsuleList: CapsuleList,
|
28
|
+
logger: Logger,
|
29
|
+
capsuleRoot: string
|
30
|
+
): Promise<LinkDetail[]> {
|
31
|
+
const modulesPath = path.join(capsuleRoot, 'node_modules');
|
32
|
+
return capsuleList.map((capsule) => {
|
33
|
+
const packageName = componentIdToPackageName(capsule.component.state._consumer);
|
34
|
+
const dest = path.join(modulesPath, packageName);
|
35
|
+
return {
|
36
|
+
from: capsule.path,
|
37
|
+
to: dest,
|
38
|
+
packageName,
|
39
|
+
};
|
40
|
+
});
|
41
|
+
}
|
42
|
+
|
43
|
+
async function symlinkComponent(
|
44
|
+
component: ConsumerComponent,
|
45
|
+
capsuleList: CapsuleList,
|
46
|
+
logger: Logger
|
47
|
+
): Promise<[string, Record<string, string>]> {
|
48
|
+
const componentCapsule = capsuleList.getCapsuleIgnoreVersion(component.id);
|
49
|
+
if (!componentCapsule) throw new Error(`unable to find the capsule for ${component.id.toString()}`);
|
50
|
+
const allDeps = component.getAllDependenciesIds();
|
51
|
+
const linkResults = allDeps.reduce((acc, depId: ComponentID) => {
|
52
|
+
// TODO: this is dangerous - we might have 2 capsules for the same component with different version, then we might link to the wrong place
|
53
|
+
const devCapsule = capsuleList.getCapsuleIgnoreVersion(depId);
|
54
|
+
if (!devCapsule) {
|
55
|
+
// happens when a dependency is not in the workspace. (it gets installed via the package manager)
|
56
|
+
logger.debug(
|
57
|
+
`symlinkComponentToCapsule: unable to find the capsule for ${depId.toStringWithoutVersion()}. skipping`
|
58
|
+
);
|
59
|
+
return acc;
|
60
|
+
}
|
61
|
+
const packageName = componentIdToPackageName(devCapsule.component.state._consumer);
|
62
|
+
const devCapsulePath = devCapsule.path;
|
63
|
+
acc[packageName] = `link:${devCapsulePath}`;
|
64
|
+
return acc;
|
65
|
+
}, {});
|
66
|
+
|
67
|
+
return [componentCapsule.path, linkResults];
|
68
|
+
}
|
package/tsconfig.json
CHANGED
@@ -1,38 +1,33 @@
|
|
1
1
|
{
|
2
2
|
"compilerOptions": {
|
3
3
|
"lib": [
|
4
|
-
"
|
5
|
-
"
|
6
|
-
"
|
7
|
-
"DOM.Iterable",
|
8
|
-
"ScriptHost"
|
4
|
+
"esnext",
|
5
|
+
"dom",
|
6
|
+
"dom.Iterable"
|
9
7
|
],
|
10
|
-
"target": "
|
11
|
-
"module": "
|
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
|
-
"
|
14
|
+
"skipLibCheck": true,
|
20
15
|
"moduleResolution": "node",
|
21
16
|
"esModuleInterop": true,
|
22
|
-
"rootDir": ".",
|
23
17
|
"resolveJsonModule": true,
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
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
|
-
"
|
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<
|
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
|
+
}
|