@teambit/isolator 0.0.0-0438888a7c5866eb047e91b207cdcc9b1a199754

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.
Files changed (46) hide show
  1. package/capsule/capsule.ts +138 -0
  2. package/capsule/container-exec.ts +31 -0
  3. package/capsule/container.ts +128 -0
  4. package/capsule/index.ts +3 -0
  5. package/dist/capsule/capsule.d.ts +75 -0
  6. package/dist/capsule/capsule.js +194 -0
  7. package/dist/capsule/capsule.js.map +1 -0
  8. package/dist/capsule/container-exec.d.ts +13 -0
  9. package/dist/capsule/container-exec.js +51 -0
  10. package/dist/capsule/container-exec.js.map +1 -0
  11. package/dist/capsule/container.d.ts +34 -0
  12. package/dist/capsule/container.js +153 -0
  13. package/dist/capsule/container.js.map +1 -0
  14. package/dist/capsule/index.d.ts +3 -0
  15. package/dist/capsule/index.js +47 -0
  16. package/dist/capsule/index.js.map +1 -0
  17. package/dist/capsule-list.d.ts +22 -0
  18. package/dist/capsule-list.js +100 -0
  19. package/dist/capsule-list.js.map +1 -0
  20. package/dist/esm.mjs +13 -0
  21. package/dist/index.d.ts +6 -0
  22. package/dist/index.js +85 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/isolator.aspect.d.ts +2 -0
  25. package/dist/isolator.aspect.js +20 -0
  26. package/dist/isolator.aspect.js.map +1 -0
  27. package/dist/isolator.composition.d.ts +1 -0
  28. package/dist/isolator.composition.js +29 -0
  29. package/dist/isolator.composition.js.map +1 -0
  30. package/dist/isolator.docs.md +41 -0
  31. package/dist/isolator.main.runtime.d.ts +285 -0
  32. package/dist/isolator.main.runtime.js +1225 -0
  33. package/dist/isolator.main.runtime.js.map +1 -0
  34. package/dist/network.d.ts +131 -0
  35. package/dist/network.js +191 -0
  36. package/dist/network.js.map +1 -0
  37. package/dist/preview-1752796259513.js +7 -0
  38. package/dist/symlink-dependencies-to-capsules.d.ts +6 -0
  39. package/dist/symlink-dependencies-to-capsules.js +61 -0
  40. package/dist/symlink-dependencies-to-capsules.js.map +1 -0
  41. package/esm.mjs +13 -0
  42. package/isolator.composition.tsx +7 -0
  43. package/isolator.docs.md +41 -0
  44. package/package.json +94 -0
  45. package/types/asset.d.ts +41 -0
  46. package/types/style.d.ts +42 -0
@@ -0,0 +1,285 @@
1
+ import { CLIMain } from '@teambit/cli';
2
+ import { AspectLoaderMain } from '@teambit/aspect-loader';
3
+ import type { ComponentMain, ComponentFactory } from '@teambit/component';
4
+ import { GraphMain } from '@teambit/graph';
5
+ import { SlotRegistry } from '@teambit/harmony';
6
+ import { DependencyResolverMain, LinkingOptions, NodeLinker } from '@teambit/dependency-resolver';
7
+ import { Logger, LoggerMain } from '@teambit/logger';
8
+ import { ComponentID } from '@teambit/component-id';
9
+ import { Scope as LegacyScope } from '@teambit/legacy.scope';
10
+ import { GlobalConfigMain } from '@teambit/global-config';
11
+ import { PathOsBasedAbsolute } from '@teambit/legacy.utils';
12
+ import { Capsule } from './capsule';
13
+ import { Network } from './network';
14
+ import { ConfigStoreMain } from '@teambit/config-store';
15
+ export type ListResults = {
16
+ capsules: string[];
17
+ };
18
+ export type CapsuleTransferFn = (sourceDir: string, targetDir: string) => Promise<void>;
19
+ export type CapsuleTransferSlot = SlotRegistry<CapsuleTransferFn>;
20
+ /**
21
+ * Context for the isolation process
22
+ */
23
+ export type IsolationContext = {
24
+ /**
25
+ * Whether the isolation done for aspects (as opposed to regular components)
26
+ */
27
+ aspects?: boolean;
28
+ /**
29
+ * Workspace name where the isolation starts from
30
+ */
31
+ workspaceName?: string;
32
+ };
33
+ export type IsolateComponentsInstallOptions = {
34
+ installPackages?: boolean;
35
+ dedupe?: boolean;
36
+ copyPeerToRuntimeOnComponents?: boolean;
37
+ copyPeerToRuntimeOnRoot?: boolean;
38
+ installPeersFromEnvs?: boolean;
39
+ installTeambitBit?: boolean;
40
+ packageManagerConfigRootDir?: string;
41
+ useNesting?: boolean;
42
+ };
43
+ type CreateGraphOptions = {
44
+ /**
45
+ * include components that exists in nested hosts. for example include components that exist in scope but not in the workspace
46
+ */
47
+ includeFromNestedHosts?: boolean;
48
+ /**
49
+ * Force specific host to get the component from.
50
+ */
51
+ host?: ComponentFactory;
52
+ };
53
+ export type IsolateComponentsOptions = CreateGraphOptions & {
54
+ name?: string;
55
+ /**
56
+ * absolute path to put all the capsules dirs inside.
57
+ */
58
+ rootBaseDir?: string;
59
+ /**
60
+ * the capsule root-dir based on a *hash* of this baseDir, not on the baseDir itself.
61
+ * A folder with this hash as its name will be created in the rootBaseDir
62
+ * By default this value will be the host path
63
+ */
64
+ baseDir?: string;
65
+ /**
66
+ * Whether to use hash function (of base dir) as capsules root dir name
67
+ */
68
+ useHash?: boolean;
69
+ /**
70
+ * create a new capsule with a random string attached to the path suffix
71
+ */
72
+ alwaysNew?: boolean;
73
+ /**
74
+ * If this is true -
75
+ * the isolator will check if there are missing capsules in the base dir
76
+ * if yes, it will create the capsule in a special dir inside a dir with the current date (without time)
77
+ * then inside that dir, it will create a dir with a random hash
78
+ * at the end of the process it will move missing capsules from the temp dir to the base dir so they can be used in
79
+ * the next iteration
80
+ */
81
+ useDatedDirs?: boolean;
82
+ /**
83
+ * If this is true -
84
+ * the isolator will do few things:
85
+ * 1. in the end of the process it will only move the lock file (pnpm-lock.yaml) into the capsule cache
86
+ * 2. in the beginning of the process it will check if there is a lock file in the capsule cache, if yes it will move
87
+ * it to the temp dated dir
88
+ * 3. it will write env's file into the dated dir (as it only contain the lock file)
89
+ * 4. it will run install in the dated dir (as there is no node_modules there yet)
90
+ */
91
+ cacheLockFileOnly?: boolean;
92
+ /**
93
+ * If set, along with useDatedDirs, then we will use the same hash dir for all capsules created with the same
94
+ * datedDirId
95
+ */
96
+ datedDirId?: string;
97
+ /**
98
+ * installation options
99
+ */
100
+ installOptions?: IsolateComponentsInstallOptions;
101
+ linkingOptions?: LinkingOptions;
102
+ /**
103
+ * delete the capsule rootDir first. it makes sure that the isolation process starts fresh with
104
+ * no previous capsules. for build and tag this is true.
105
+ */
106
+ emptyRootDir?: boolean;
107
+ /**
108
+ * skip the reproduction of the capsule in case it exists.
109
+ */
110
+ skipIfExists?: boolean;
111
+ /**
112
+ * get existing capsule without doing any changes, no writes, no installations.
113
+ */
114
+ getExistingAsIs?: boolean;
115
+ /**
116
+ * place the package-manager cache on the capsule-root
117
+ */
118
+ cachePackagesOnCapsulesRoot?: boolean;
119
+ /**
120
+ * do not build graph with all dependencies. isolate the seeders only.
121
+ */
122
+ seedersOnly?: boolean;
123
+ /**
124
+ * relevant for tagging from scope, where we tag an existing snap without any code-changes.
125
+ * the idea is to have all build artifacts from the previous snap and run deploy pipeline on top of it.
126
+ */
127
+ populateArtifactsFrom?: ComponentID[];
128
+ /**
129
+ * relevant when populateArtifactsFrom is set.
130
+ * by default, it uses the package.json created in the previous snap as a base and make the necessary changes.
131
+ * if this is set to true, it will ignore the package.json from the previous snap.
132
+ */
133
+ populateArtifactsIgnorePkgJson?: boolean;
134
+ /**
135
+ * Force specific host to get the component from.
136
+ */
137
+ host?: ComponentFactory;
138
+ /**
139
+ * Use specific package manager for the isolation process (override the package manager from the dep resolver config)
140
+ */
141
+ packageManager?: string;
142
+ /**
143
+ * Use specific node linker for the isolation process (override the package manager from the dep resolver config)
144
+ */
145
+ nodeLinker?: NodeLinker;
146
+ /**
147
+ * Dir where to read the package manager config from
148
+ * usually used when running package manager in the capsules dir to use the config
149
+ * from the workspace dir
150
+ */
151
+ packageManagerConfigRootDir?: string;
152
+ context?: IsolationContext;
153
+ /**
154
+ * Root dir of capsulse cache (used mostly to copy lock file if used with cache lock file only option)
155
+ */
156
+ cacheCapsulesDir?: string;
157
+ /**
158
+ * Generate a lockfile from the dependencies graph stored in the model
159
+ * and generate a dependency graph from the lockfile in the capsule.
160
+ */
161
+ useDependenciesGraph?: boolean;
162
+ };
163
+ type GetCapsuleDirOpts = Pick<IsolateComponentsOptions, 'datedDirId' | 'useHash' | 'rootBaseDir' | 'useDatedDirs' | 'cacheLockFileOnly'> & {
164
+ baseDir: string;
165
+ };
166
+ /**
167
+ * File name to indicate that the capsule is ready (all packages are installed and links are created)
168
+ */
169
+ export declare const CAPSULE_READY_FILE = ".bit-capsule-ready";
170
+ export declare class IsolatorMain {
171
+ private dependencyResolver;
172
+ private logger;
173
+ private componentAspect;
174
+ private graph;
175
+ private cli;
176
+ private globalConfig;
177
+ private aspectLoader;
178
+ private capsuleTransferSlot;
179
+ private configStore;
180
+ static runtime: import("@teambit/harmony").RuntimeDefinition;
181
+ static dependencies: import("@teambit/harmony").Aspect[];
182
+ static slots: ((registerFn: () => string) => SlotRegistry<CapsuleTransferFn>)[];
183
+ static defaultConfig: {};
184
+ _componentsPackagesVersionCache: {
185
+ [idStr: string]: string;
186
+ };
187
+ _datedHashForName: Map<string, string>;
188
+ _movedLockFiles: Set<unknown>;
189
+ static provider([dependencyResolver, loggerExtension, componentAspect, graphMain, globalConfig, aspectLoader, cli, configStore]: [
190
+ DependencyResolverMain,
191
+ LoggerMain,
192
+ ComponentMain,
193
+ GraphMain,
194
+ GlobalConfigMain,
195
+ AspectLoaderMain,
196
+ CLIMain,
197
+ ConfigStoreMain
198
+ ], _config: any, [capsuleTransferSlot]: [CapsuleTransferSlot]): Promise<IsolatorMain>;
199
+ constructor(dependencyResolver: DependencyResolverMain, logger: Logger, componentAspect: ComponentMain, graph: GraphMain, cli: CLIMain, globalConfig: GlobalConfigMain, aspectLoader: AspectLoaderMain, capsuleTransferSlot: CapsuleTransferSlot, configStore: ConfigStoreMain);
200
+ isolateComponents(seeders: ComponentID[], opts: IsolateComponentsOptions, legacyScope?: LegacyScope): Promise<Network>;
201
+ private createGraph;
202
+ private registerMoveCapsuleOnProcessExit;
203
+ private getAllCapsulesDirsFromRoot;
204
+ private moveCapsulesLockFileToTargetDir;
205
+ private moveCapsulesToTargetDir;
206
+ /**
207
+ * The function moves a directory from a source location to a target location using a temporary directory.
208
+ * This is using temp dir because sometime the source dir and target dir might be in different FS
209
+ * (for example different mounts) which means the move might take a long time
210
+ * during the time of moving, another process will see that the capsule is not ready and will try to remove then
211
+ * move it again, which lead to the first process throwing an error
212
+ * @param sourceDir - The source directory from where the files or directories will be moved.
213
+ * @param targetDir - The target directory where the source directory will be moved to.
214
+ */
215
+ private moveWithTempName;
216
+ /**
217
+ * Re-create the core aspects links in the real capsule dir
218
+ * This is required mainly for the first time when that folder is empty
219
+ */
220
+ private relinkCoreAspectsInCapsuleDir;
221
+ private shouldUseDatedDirs;
222
+ /**
223
+ *
224
+ * @param originalCapsule the capsule that contains the original component
225
+ * @param newBaseDir relative path. (it will be saved inside `this.getRootDirOfAllCapsules()`. the final path of the capsule will be getRootDirOfAllCapsules() + newBaseDir + filenameify(component.id))
226
+ * @returns a new capsule with the same content of the original capsule but with a new baseDir and all packages
227
+ * installed in the newBaseDir.
228
+ */
229
+ cloneCapsule(originalCapsule: Capsule, newBaseDir: string): Promise<Capsule>;
230
+ /**
231
+ * Create capsules for the provided components
232
+ * do not use this outside directly, use isolate components which build the entire network
233
+ * @param components
234
+ * @param opts
235
+ * @param legacyScope
236
+ */
237
+ private createCapsules;
238
+ private addDependenciesGraphToComponents;
239
+ private markCapsulesAsReady;
240
+ private markCapsuleAsReady;
241
+ private removeCapsuleReadyFileSync;
242
+ private writeCapsuleReadyFileSync;
243
+ private getCapsuleReadyFilePath;
244
+ private installInCapsules;
245
+ private linkInCapsules;
246
+ private linkInCapsulesRoot;
247
+ private toLocalLinks;
248
+ private linkDetailToLocalDepEntry;
249
+ private getCapsulesWithModifiedPackageJson;
250
+ private writeComponentsInCapsules;
251
+ private getWorkspacePeersOnlyPolicy;
252
+ private toComponentMap;
253
+ list(rootDir: string): Promise<ListResults>;
254
+ registerCapsuleTransferFn(fn: CapsuleTransferFn): void;
255
+ private getCapsuleTransferFn;
256
+ private getDefaultCapsuleTransferFn;
257
+ private getCapsuleDirHash;
258
+ /** @deprecated use the new function signature with an object parameter instead */
259
+ getCapsulesRootDir(baseDir: string, rootBaseDir?: string, useHash?: boolean): PathOsBasedAbsolute;
260
+ getCapsulesRootDir(getCapsuleDirOpts: GetCapsuleDirOpts): PathOsBasedAbsolute;
261
+ deleteCapsules(rootDir?: string): Promise<string>;
262
+ private writeRootPackageJson;
263
+ private createCapsulesFromComponents;
264
+ private getRootDirOfAllCapsules;
265
+ private wereDependenciesInPackageJsonChanged;
266
+ private getCapsulesPreviousPackageJson;
267
+ private updateWithCurrentPackageJsonData;
268
+ private getCurrentPackageJson;
269
+ private populateComponentsFilesToWriteForCapsule;
270
+ private mergePkgJsonFromLastBuild;
271
+ private getCompForArtifacts;
272
+ private preparePackageJsonToWrite;
273
+ /**
274
+ * currently, it writes all artifacts.
275
+ * later, this responsibility might move to pkg extension, which could write only artifacts
276
+ * that are set in package.json.files[], to have a similar structure of a package.
277
+ */
278
+ private getArtifacts;
279
+ /**
280
+ * Filter out unmodified exported dependencies to optimize capsule creation.
281
+ * These dependencies can be installed as packages instead of creating capsules.
282
+ */
283
+ private filterUnmodifiedExportedDependencies;
284
+ }
285
+ export {};