@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.
@@ -0,0 +1,65 @@
1
+ import type { Component } from '@teambit/component';
2
+ import { Dependency, DependencyResolverMain } from '@teambit/dependency-resolver';
3
+ import { Edge, Graph, Node } from '@teambit/graph.cleargraph';
4
+ import { ComponentID } from '@teambit/component-id';
5
+ import { normalize } from 'path';
6
+ import { Capsule } from './capsule';
7
+
8
+ export default class CapsuleList extends Array<Capsule> {
9
+ getCapsule(id: ComponentID): Capsule | undefined {
10
+ return this.find((capsule) => capsule.component.id.isEqual(id));
11
+ }
12
+ getCapsuleByLegacyId(id: ComponentID): Capsule | undefined {
13
+ return this.find((capsule) => capsule.component.id.isEqual(id));
14
+ }
15
+ getCapsuleIgnoreVersion(id: ComponentID): Capsule | undefined {
16
+ return this.find((capsule) => capsule.component.id.isEqual(id, { ignoreVersion: true }));
17
+ }
18
+ getAllCapsuleDirs(): string[] {
19
+ return this.map((capsule) => capsule.path);
20
+ }
21
+ getIdByPathInCapsule(pathInCapsule: string): ComponentID | null {
22
+ const normalizedPathInCapsule = normalize(pathInCapsule);
23
+ const found = this.find((capsule) => normalizedPathInCapsule === normalize(capsule.path));
24
+ return found ? found.component.id : null;
25
+ }
26
+ getAllComponents(): Component[] {
27
+ return this.map((c) => c.component);
28
+ }
29
+ // Sort the capsules by their dependencies. The capsules with no dependencies will be first. Returns a new array.
30
+ async toposort(depResolver: DependencyResolverMain): Promise<CapsuleList> {
31
+ const components = this.getAllComponents();
32
+ const graph = new Graph<Component, string>();
33
+
34
+ // Build a graph with all the components from the current capsule list
35
+ components.forEach((comp: Component) => graph.setNode(new Node(depResolver.getPackageName(comp), comp)));
36
+
37
+ // Add edges between the components according to their interdependencies
38
+ for (const node of graph.nodes) {
39
+ // eslint-disable-next-line no-await-in-loop
40
+ const deps = await depResolver.getDependencies(node.attr);
41
+ deps.forEach((dep: Dependency) => {
42
+ const depPkgName = dep.getPackageName?.();
43
+ if (depPkgName && graph.hasNode(depPkgName)) {
44
+ graph.setEdge(new Edge(node.id, depPkgName, dep.lifecycle));
45
+ }
46
+ });
47
+ }
48
+
49
+ const sortedSeeders = graph.toposort(true);
50
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
51
+ const sortedCapsules: Capsule[] = sortedSeeders.map((node: Node<Component>) => this.getCapsule(node.attr.id)!);
52
+ return CapsuleList.fromArray(sortedCapsules);
53
+ }
54
+ static fromArray(capsules: Capsule[]) {
55
+ return new CapsuleList(...capsules);
56
+ }
57
+ /**
58
+ * determines whether or not a capsule can theoretically use the dists saved in the last snap, rather than re-compile them.
59
+ * practically, this optimization is used for components that have typescript as their compiler.
60
+ */
61
+ static async capsuleUsePreviouslySavedDists(component: Component): Promise<boolean> {
62
+ const isModified = await component.isModified();
63
+ return component.buildStatus === 'succeed' && !isModified;
64
+ }
65
+ }
@@ -76,7 +76,6 @@ class FsContainer {
76
76
  return _fsExtra().default.ensureSymlink(srcPath, destPath);
77
77
  }
78
78
  async exec(execOptions, exec = new (_containerExec().default)()) {
79
- var _subprocessP$stderr, _subprocessP$stdout;
80
79
  const cwd = execOptions.cwd ? this.composePath(execOptions.cwd) : this.getPath();
81
80
  debug(`executing the following command: ${execOptions.command.join(' ')}, on cwd: ${cwd}`);
82
81
  const subprocessP = _execa().default.command(execOptions.command.join(' '), {
@@ -91,8 +90,8 @@ class FsContainer {
91
90
  exec.emit('message', msg);
92
91
  });
93
92
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
94
- (_subprocessP$stderr = subprocessP.stderr) === null || _subprocessP$stderr === void 0 || _subprocessP$stderr.pipe(exec.stderr);
95
- (_subprocessP$stdout = subprocessP.stdout) === null || _subprocessP$stdout === void 0 || _subprocessP$stdout.pipe(exec.stdout);
93
+ subprocessP.stderr?.pipe(exec.stderr);
94
+ subprocessP.stdout?.pipe(exec.stdout);
96
95
  ['close', 'exit'].forEach(function (eventName) {
97
96
  // @TODO: FIX! This probably causes errors ad the promise is not handled properly!
98
97
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
@@ -1 +1 @@
1
- {"version":3,"names":["_anyFs","data","require","_execa","_interopRequireDefault","_fsExtra","path","_interopRequireWildcard","_containerExec","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","_defineProperty","key","value","_toPropertyKey","enumerable","configurable","writable","_toPrimitive","String","Symbol","toPrimitive","TypeError","Number","debug","FsContainer","constructor","wrkDir","NodeFS","getPath","composePath","pathToCompose","join","outputFile","file","options","filePath","fs","removePath","dir","pathToRemove","remove","symlink","src","dest","srcPath","destPath","ensureDir","dirname","ensureSymlink","exec","execOptions","ContainerExec","_subprocessP$stderr","_subprocessP$stdout","cwd","command","subprocessP","execa","shell","stdio","on","msg","emit","stderr","pipe","stdout","forEach","eventName","statusCode","setStatus","execP","hasError","Promise","resolve","reject","getContents","size","toString","terminal","process","env","SHELL","start","inspect","pause","resume","stop","ttl","destroy","log","Error","event","fn","exports"],"sources":["container.ts"],"sourcesContent":["import { AnyFS, NodeFS } from '@teambit/any-fs';\nimport { Container, ContainerFactoryOptions, ContainerStatus, Exec, ExecOptions } from '@teambit/capsule';\nimport execa from 'execa';\nimport fs from 'fs-extra';\nimport * as path from 'path';\nimport { Stream } from 'stream';\n\nimport ContainerExec from './container-exec';\n\nconst debug = require('debug')('fs-container');\n\nexport interface BitExecOption extends ExecOptions {\n cwd: string;\n stdio?: 'pipe' | 'ipc' | 'ignore' | 'inherit' | Stream | number | undefined;\n}\nexport interface BitContainerConfig extends ContainerFactoryOptions {\n other?: string;\n}\n\nexport default class FsContainer implements Container<Exec, AnyFS> {\n id = 'FS Container';\n\n fs: NodeFS = new NodeFS(this.wrkDir);\n\n constructor(readonly wrkDir: string) {}\n\n // TODO: do we need this?\n public getPath() {\n return this.wrkDir;\n }\n\n private composePath(pathToCompose) {\n return path.join(this.getPath(), pathToCompose);\n }\n\n outputFile(file, data, options) {\n const filePath = this.composePath(file);\n debug(`writing file on ${filePath}`);\n return fs.outputFile(filePath, data, options);\n }\n\n removePath(dir: string): Promise<any> {\n const pathToRemove = this.composePath(dir);\n return fs.remove(pathToRemove);\n }\n\n async symlink(src: string, dest: string): Promise<any> {\n const srcPath = this.composePath(src);\n const destPath = this.composePath(dest);\n await fs.ensureDir(path.dirname(destPath));\n return fs.ensureSymlink(srcPath, destPath);\n }\n\n async exec(execOptions: BitExecOption, exec = new ContainerExec()): Promise<ContainerExec> {\n const cwd = execOptions.cwd ? this.composePath(execOptions.cwd) : this.getPath();\n debug(`executing the following command: ${execOptions.command.join(' ')}, on cwd: ${cwd}`);\n const subprocessP = execa.command(execOptions.command.join(' '), {\n shell: true,\n cwd,\n stdio: ['ipc'],\n });\n\n // @TODO: FIX! This probably causes errors ad the promise is not handled properly!\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n subprocessP.on('message', function (msg: any) {\n exec.emit('message', msg);\n });\n /* eslint-disable @typescript-eslint/no-non-null-assertion */\n subprocessP.stderr?.pipe(exec.stderr);\n subprocessP.stdout?.pipe(exec.stdout);\n ['close', 'exit'].forEach(function (eventName: string) {\n // @TODO: FIX! This probably causes errors ad the promise is not handled properly!\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n subprocessP.on(eventName, function (statusCode) {\n exec.setStatus(statusCode);\n });\n });\n\n return exec;\n }\n\n async execP(execOptions: BitExecOption): Promise<string> {\n let hasError = false;\n const exec = await this.exec(execOptions);\n return new Promise((resolve, reject) => {\n exec.stdout.on('error', () => {\n hasError = true;\n });\n exec.on('close', () => {\n if (hasError) reject(exec.stderr.getContents!(exec.stderr.size).toString());\n resolve(exec.stdout.getContents!(exec.stdout.size).toString());\n });\n });\n }\n\n async terminal() {\n const cwd = this.getPath();\n return execa.command(process.env.SHELL || '/bin/zsh', { cwd, stdio: 'inherit' });\n }\n\n start(): Promise<void> {\n return fs.ensureDir(this.wrkDir);\n }\n // @ts-ignore\n async inspect(): Promise<ContainerStatus> {\n // todo: probably not needed for this container\n }\n async pause(): Promise<void> {\n // do nothing\n }\n async resume(): Promise<void> {\n // do nothing\n }\n // eslint-disable-next-line\n stop(ttl?: number | undefined): Promise<void> {\n return fs.remove(this.wrkDir);\n }\n async destroy(): Promise<void> {\n await this.stop();\n }\n log(): Promise<Exec> {\n throw new Error('Method not implemented.');\n }\n on(event: string, fn: (data: any) => void): void {\n return fn(event);\n // throw new Error('Method not implemented.');\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,OAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,MAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAG,QAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,KAAA;EAAA,MAAAL,IAAA,GAAAM,uBAAA,CAAAL,OAAA;EAAAI,IAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAO,eAAA;EAAA,MAAAP,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAM,cAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA6C,SAAAQ,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAA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AEA,MAAMC,QAAQA,CAAA,EAAG;IACf,MAAMxB,GAAG,GAAG,IAAI,CAAC1B,OAAO,CAAC,CAAC;IAC1B,OAAO6B,gBAAK,CAACF,OAAO,CAACwB,OAAO,CAACC,GAAG,CAACC,KAAK,IAAI,UAAU,EAAE;MAAE3B,GAAG;MAAEK,KAAK,EAAE;IAAU,CAAC,CAAC;EAClF;EAEAuB,KAAKA,CAAA,EAAkB;IACrB,OAAO9C,kBAAE,CAACU,SAAS,CAAC,IAAI,CAACpB,MAAM,CAAC;EAClC;EACA;EACA,MAAMyD,OAAOA,CAAA,EAA6B;IACxC;EAAA;EAEF,MAAMC,KAAKA,CAAA,EAAkB;IAC3B;EAAA;EAEF,MAAMC,MAAMA,CAAA,EAAkB;IAC5B;EAAA;EAEF;EACAC,IAAIA,CAACC,GAAwB,EAAiB;IAC5C,OAAOnD,kBAAE,CAACI,MAAM,CAAC,IAAI,CAACd,MAAM,CAAC;EAC/B;EACA,MAAM8D,OAAOA,CAAA,EAAkB;IAC7B,MAAM,IAAI,CAACF,IAAI,CAAC,CAAC;EACnB;EACAG,GAAGA,CAAA,EAAkB;IACnB,MAAM,IAAIC,KAAK,CAAC,yBAAyB,CAAC;EAC5C;EACA9B,EAAEA,CAAC+B,KAAa,EAAEC,EAAuB,EAAQ;IAC/C,OAAOA,EAAE,CAACD,KAAK,CAAC;IAChB;EACF;AACF;AAACE,OAAA,CAAAnG,OAAA,GAAA8B,WAAA"}
1
+ {"version":3,"names":["_anyFs","data","require","_execa","_interopRequireDefault","_fsExtra","path","_interopRequireWildcard","_containerExec","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","_defineProperty","key","value","_toPropertyKey","enumerable","configurable","writable","_toPrimitive","String","Symbol","toPrimitive","TypeError","Number","debug","FsContainer","constructor","wrkDir","NodeFS","getPath","composePath","pathToCompose","join","outputFile","file","options","filePath","fs","removePath","dir","pathToRemove","remove","symlink","src","dest","srcPath","destPath","ensureDir","dirname","ensureSymlink","exec","execOptions","ContainerExec","cwd","command","subprocessP","execa","shell","stdio","on","msg","emit","stderr","pipe","stdout","forEach","eventName","statusCode","setStatus","execP","hasError","Promise","resolve","reject","getContents","size","toString","terminal","process","env","SHELL","start","inspect","pause","resume","stop","ttl","destroy","log","Error","event","fn","exports"],"sources":["container.ts"],"sourcesContent":["import { AnyFS, NodeFS } from '@teambit/any-fs';\nimport { Container, ContainerFactoryOptions, ContainerStatus, Exec, ExecOptions } from '@teambit/capsule';\nimport execa from 'execa';\nimport fs from 'fs-extra';\nimport * as path from 'path';\nimport { Stream } from 'stream';\n\nimport ContainerExec from './container-exec';\n\nconst debug = require('debug')('fs-container');\n\nexport interface BitExecOption extends ExecOptions {\n cwd: string;\n stdio?: 'pipe' | 'ipc' | 'ignore' | 'inherit' | Stream | number | undefined;\n}\nexport interface BitContainerConfig extends ContainerFactoryOptions {\n other?: string;\n}\n\nexport default class FsContainer implements Container<Exec, AnyFS> {\n id = 'FS Container';\n\n fs: NodeFS = new NodeFS(this.wrkDir);\n\n constructor(readonly wrkDir: string) {}\n\n // TODO: do we need this?\n public getPath() {\n return this.wrkDir;\n }\n\n private composePath(pathToCompose) {\n return path.join(this.getPath(), pathToCompose);\n }\n\n outputFile(file, data, options) {\n const filePath = this.composePath(file);\n debug(`writing file on ${filePath}`);\n return fs.outputFile(filePath, data, options);\n }\n\n removePath(dir: string): Promise<any> {\n const pathToRemove = this.composePath(dir);\n return fs.remove(pathToRemove);\n }\n\n async symlink(src: string, dest: string): Promise<any> {\n const srcPath = this.composePath(src);\n const destPath = this.composePath(dest);\n await fs.ensureDir(path.dirname(destPath));\n return fs.ensureSymlink(srcPath, destPath);\n }\n\n async exec(execOptions: BitExecOption, exec = new ContainerExec()): Promise<ContainerExec> {\n const cwd = execOptions.cwd ? this.composePath(execOptions.cwd) : this.getPath();\n debug(`executing the following command: ${execOptions.command.join(' ')}, on cwd: ${cwd}`);\n const subprocessP = execa.command(execOptions.command.join(' '), {\n shell: true,\n cwd,\n stdio: ['ipc'],\n });\n\n // @TODO: FIX! This probably causes errors ad the promise is not handled properly!\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n subprocessP.on('message', function (msg: any) {\n exec.emit('message', msg);\n });\n /* eslint-disable @typescript-eslint/no-non-null-assertion */\n subprocessP.stderr?.pipe(exec.stderr);\n subprocessP.stdout?.pipe(exec.stdout);\n ['close', 'exit'].forEach(function (eventName: string) {\n // @TODO: FIX! This probably causes errors ad the promise is not handled properly!\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n subprocessP.on(eventName, function (statusCode) {\n exec.setStatus(statusCode);\n });\n });\n\n return exec;\n }\n\n async execP(execOptions: BitExecOption): Promise<string> {\n let hasError = false;\n const exec = await this.exec(execOptions);\n return new Promise((resolve, reject) => {\n exec.stdout.on('error', () => {\n hasError = true;\n });\n exec.on('close', () => {\n if (hasError) reject(exec.stderr.getContents!(exec.stderr.size).toString());\n resolve(exec.stdout.getContents!(exec.stdout.size).toString());\n });\n });\n }\n\n async terminal() {\n const cwd = this.getPath();\n return execa.command(process.env.SHELL || '/bin/zsh', { cwd, stdio: 'inherit' });\n }\n\n start(): Promise<void> {\n return fs.ensureDir(this.wrkDir);\n }\n // @ts-ignore\n async inspect(): Promise<ContainerStatus> {\n // todo: probably not needed for this container\n }\n async pause(): Promise<void> {\n // do nothing\n }\n async resume(): Promise<void> {\n // do nothing\n }\n // eslint-disable-next-line\n stop(ttl?: number | undefined): Promise<void> {\n return fs.remove(this.wrkDir);\n }\n async destroy(): Promise<void> {\n await this.stop();\n }\n log(): Promise<Exec> {\n throw new Error('Method not implemented.');\n }\n on(event: string, fn: (data: any) => void): void {\n return fn(event);\n // throw new Error('Method not implemented.');\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC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D,OAAOA,CAAA,EAAkB;IAC7B,MAAM,IAAI,CAACF,IAAI,CAAC,CAAC;EACnB;EACAG,GAAGA,CAAA,EAAkB;IACnB,MAAM,IAAIC,KAAK,CAAC,yBAAyB,CAAC;EAC5C;EACA9B,EAAEA,CAAC+B,KAAa,EAAEC,EAAuB,EAAQ;IAC/C,OAAOA,EAAE,CAACD,KAAK,CAAC;IAChB;EACF;AACF;AAACE,OAAA,CAAAjG,OAAA,GAAA8B,WAAA"}
@@ -54,8 +54,7 @@ class CapsuleList extends Array {
54
54
  // eslint-disable-next-line no-await-in-loop
55
55
  const deps = await depResolver.getDependencies(node.attr);
56
56
  deps.forEach(dep => {
57
- var _dep$getPackageName;
58
- const depPkgName = (_dep$getPackageName = dep.getPackageName) === null || _dep$getPackageName === void 0 ? void 0 : _dep$getPackageName.call(dep);
57
+ const depPkgName = dep.getPackageName?.();
59
58
  if (depPkgName && graph.hasNode(depPkgName)) {
60
59
  graph.setEdge(new (_graph().Edge)(node.id, depPkgName, dep.lifecycle));
61
60
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_graph","data","require","_path","CapsuleList","Array","getCapsule","id","find","capsule","component","isEqual","getCapsuleByLegacyId","getCapsuleIgnoreVersion","ignoreVersion","getAllCapsuleDirs","map","path","getIdByPathInCapsule","pathInCapsule","normalizedPathInCapsule","normalize","found","getAllComponents","c","toposort","depResolver","components","graph","Graph","forEach","comp","setNode","Node","getPackageName","node","nodes","deps","getDependencies","attr","dep","_dep$getPackageName","depPkgName","call","hasNode","setEdge","Edge","lifecycle","sortedSeeders","sortedCapsules","fromArray","capsules","capsuleUsePreviouslySavedDists","isModified","buildStatus","exports","default"],"sources":["capsule-list.ts"],"sourcesContent":["import type { Component } from '@teambit/component';\nimport { Dependency, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { Edge, Graph, Node } from '@teambit/graph.cleargraph';\nimport { ComponentID } from '@teambit/component-id';\nimport { normalize } from 'path';\nimport { Capsule } from './capsule';\n\nexport default class CapsuleList extends Array<Capsule> {\n getCapsule(id: ComponentID): Capsule | undefined {\n return this.find((capsule) => capsule.component.id.isEqual(id));\n }\n getCapsuleByLegacyId(id: ComponentID): Capsule | undefined {\n return this.find((capsule) => capsule.component.id.isEqual(id));\n }\n getCapsuleIgnoreVersion(id: ComponentID): Capsule | undefined {\n return this.find((capsule) => capsule.component.id.isEqual(id, { ignoreVersion: true }));\n }\n getAllCapsuleDirs(): string[] {\n return this.map((capsule) => capsule.path);\n }\n getIdByPathInCapsule(pathInCapsule: string): ComponentID | null {\n const normalizedPathInCapsule = normalize(pathInCapsule);\n const found = this.find((capsule) => normalizedPathInCapsule === normalize(capsule.path));\n return found ? found.component.id : null;\n }\n getAllComponents(): Component[] {\n return this.map((c) => c.component);\n }\n // Sort the capsules by their dependencies. The capsules with no dependencies will be first. Returns a new array.\n async toposort(depResolver: DependencyResolverMain): Promise<CapsuleList> {\n const components = this.getAllComponents();\n const graph = new Graph<Component, string>();\n\n // Build a graph with all the components from the current capsule list\n components.forEach((comp: Component) => graph.setNode(new Node(depResolver.getPackageName(comp), comp)));\n\n // Add edges between the components according to their interdependencies\n for (const node of graph.nodes) {\n // eslint-disable-next-line no-await-in-loop\n const deps = await depResolver.getDependencies(node.attr);\n deps.forEach((dep: Dependency) => {\n const depPkgName = dep.getPackageName?.();\n if (depPkgName && graph.hasNode(depPkgName)) {\n graph.setEdge(new Edge(node.id, depPkgName, dep.lifecycle));\n }\n });\n }\n\n const sortedSeeders = graph.toposort(true);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const sortedCapsules: Capsule[] = sortedSeeders.map((node: Node<Component>) => this.getCapsule(node.attr.id)!);\n return CapsuleList.fromArray(sortedCapsules);\n }\n static fromArray(capsules: Capsule[]) {\n return new CapsuleList(...capsules);\n }\n /**\n * determines whether or not a capsule can theoretically use the dists saved in the last snap, rather than re-compile them.\n * practically, this optimization is used for components that have typescript as their compiler.\n */\n static async capsuleUsePreviouslySavedDists(component: Component): Promise<boolean> {\n const isModified = await component.isModified();\n return component.buildStatus === 'succeed' && !isModified;\n }\n}\n"],"mappings":";;;;;;AAEA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,MAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,KAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGe,MAAMG,WAAW,SAASC,KAAK,CAAU;EACtDC,UAAUA,CAACC,EAAe,EAAuB;IAC/C,OAAO,IAAI,CAACC,IAAI,CAAEC,OAAO,IAAKA,OAAO,CAACC,SAAS,CAACH,EAAE,CAACI,OAAO,CAACJ,EAAE,CAAC,CAAC;EACjE;EACAK,oBAAoBA,CAACL,EAAe,EAAuB;IACzD,OAAO,IAAI,CAACC,IAAI,CAAEC,OAAO,IAAKA,OAAO,CAACC,SAAS,CAACH,EAAE,CAACI,OAAO,CAACJ,EAAE,CAAC,CAAC;EACjE;EACAM,uBAAuBA,CAACN,EAAe,EAAuB;IAC5D,OAAO,IAAI,CAACC,IAAI,CAAEC,OAAO,IAAKA,OAAO,CAACC,SAAS,CAACH,EAAE,CAACI,OAAO,CAACJ,EAAE,EAAE;MAAEO,aAAa,EAAE;IAAK,CAAC,CAAC,CAAC;EAC1F;EACAC,iBAAiBA,CAAA,EAAa;IAC5B,OAAO,IAAI,CAACC,GAAG,CAAEP,OAAO,IAAKA,OAAO,CAACQ,IAAI,CAAC;EAC5C;EACAC,oBAAoBA,CAACC,aAAqB,EAAsB;IAC9D,MAAMC,uBAAuB,GAAG,IAAAC,iBAAS,EAACF,aAAa,CAAC;IACxD,MAAMG,KAAK,GAAG,IAAI,CAACd,IAAI,CAAEC,OAAO,IAAKW,uBAAuB,KAAK,IAAAC,iBAAS,EAACZ,OAAO,CAACQ,IAAI,CAAC,CAAC;IACzF,O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AC6B,IAAI,CAACI,IAAI,CAAChC,EAAE,CAAE,CAAC;IAC9G,OAAOH,WAAW,CAAC8C,SAAS,CAACD,cAAc,CAAC;EAC9C;EACA,OAAOC,SAASA,CAACC,QAAmB,EAAE;IACpC,OAAO,IAAI/C,WAAW,CAAC,GAAG+C,QAAQ,CAAC;EACrC;EACA;AACF;AACA;AACA;EACE,aAAaC,8BAA8BA,CAAC1C,SAAoB,EAAoB;IAClF,MAAM2C,UAAU,GAAG,MAAM3C,SAAS,CAAC2C,UAAU,CAAC,CAAC;IAC/C,OAAO3C,SAAS,CAAC4C,WAAW,KAAK,SAAS,IAAI,CAACD,UAAU;EAC3D;AACF;AAACE,OAAA,CAAAC,OAAA,GAAApD,WAAA"}
1
+ {"version":3,"names":["_graph","data","require","_path","CapsuleList","Array","getCapsule","id","find","capsule","component","isEqual","getCapsuleByLegacyId","getCapsuleIgnoreVersion","ignoreVersion","getAllCapsuleDirs","map","path","getIdByPathInCapsule","pathInCapsule","normalizedPathInCapsule","normalize","found","getAllComponents","c","toposort","depResolver","components","graph","Graph","forEach","comp","setNode","Node","getPackageName","node","nodes","deps","getDependencies","attr","dep","depPkgName","hasNode","setEdge","Edge","lifecycle","sortedSeeders","sortedCapsules","fromArray","capsules","capsuleUsePreviouslySavedDists","isModified","buildStatus","exports","default"],"sources":["capsule-list.ts"],"sourcesContent":["import type { Component } from '@teambit/component';\nimport { Dependency, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { Edge, Graph, Node } from '@teambit/graph.cleargraph';\nimport { ComponentID } from '@teambit/component-id';\nimport { normalize } from 'path';\nimport { Capsule } from './capsule';\n\nexport default class CapsuleList extends Array<Capsule> {\n getCapsule(id: ComponentID): Capsule | undefined {\n return this.find((capsule) => capsule.component.id.isEqual(id));\n }\n getCapsuleByLegacyId(id: ComponentID): Capsule | undefined {\n return this.find((capsule) => capsule.component.id.isEqual(id));\n }\n getCapsuleIgnoreVersion(id: ComponentID): Capsule | undefined {\n return this.find((capsule) => capsule.component.id.isEqual(id, { ignoreVersion: true }));\n }\n getAllCapsuleDirs(): string[] {\n return this.map((capsule) => capsule.path);\n }\n getIdByPathInCapsule(pathInCapsule: string): ComponentID | null {\n const normalizedPathInCapsule = normalize(pathInCapsule);\n const found = this.find((capsule) => normalizedPathInCapsule === normalize(capsule.path));\n return found ? found.component.id : null;\n }\n getAllComponents(): Component[] {\n return this.map((c) => c.component);\n }\n // Sort the capsules by their dependencies. The capsules with no dependencies will be first. Returns a new array.\n async toposort(depResolver: DependencyResolverMain): Promise<CapsuleList> {\n const components = this.getAllComponents();\n const graph = new Graph<Component, string>();\n\n // Build a graph with all the components from the current capsule list\n components.forEach((comp: Component) => graph.setNode(new Node(depResolver.getPackageName(comp), comp)));\n\n // Add edges between the components according to their interdependencies\n for (const node of graph.nodes) {\n // eslint-disable-next-line no-await-in-loop\n const deps = await depResolver.getDependencies(node.attr);\n deps.forEach((dep: Dependency) => {\n const depPkgName = dep.getPackageName?.();\n if (depPkgName && graph.hasNode(depPkgName)) {\n graph.setEdge(new Edge(node.id, depPkgName, dep.lifecycle));\n }\n });\n }\n\n const sortedSeeders = graph.toposort(true);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const sortedCapsules: Capsule[] = sortedSeeders.map((node: Node<Component>) => this.getCapsule(node.attr.id)!);\n return CapsuleList.fromArray(sortedCapsules);\n }\n static fromArray(capsules: Capsule[]) {\n return new CapsuleList(...capsules);\n }\n /**\n * determines whether or not a capsule can theoretically use the dists saved in the last snap, rather than re-compile them.\n * practically, this optimization is used for components that have typescript as their compiler.\n */\n static async capsuleUsePreviouslySavedDists(component: Component): Promise<boolean> {\n const isModified = await component.isModified();\n return component.buildStatus === 'succeed' && !isModified;\n }\n}\n"],"mappings":";;;;;;AAEA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,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SAAS,CAACyC,UAAU,CAAC,CAAC;IAC/C,OAAOzC,SAAS,CAAC0C,WAAW,KAAK,SAAS,IAAI,CAACD,UAAU;EAC3D;AACF;AAACE,OAAA,CAAAC,OAAA,GAAAlD,WAAA"}
@@ -1,2 +1,2 @@
1
- import React from 'react';
2
- export declare const Logo: () => React.JSX.Element;
1
+ /// <reference types="react" />
2
+ export declare const Logo: () => JSX.Element;
@@ -14,15 +14,15 @@ import { Scope } from '@teambit/legacy/dist/scope';
14
14
  import DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';
15
15
  import { Capsule } from './capsule';
16
16
  import { Network } from './network';
17
- export declare type ListResults = {
17
+ export type ListResults = {
18
18
  capsules: string[];
19
19
  };
20
- export declare type CapsuleTransferFn = (sourceDir: string, targetDir: string) => Promise<void>;
21
- export declare type CapsuleTransferSlot = SlotRegistry<CapsuleTransferFn>;
20
+ export type CapsuleTransferFn = (sourceDir: string, targetDir: string) => Promise<void>;
21
+ export type CapsuleTransferSlot = SlotRegistry<CapsuleTransferFn>;
22
22
  /**
23
23
  * Context for the isolation process
24
24
  */
25
- export declare type IsolationContext = {
25
+ export type IsolationContext = {
26
26
  /**
27
27
  * Whether the isolation done for aspects (as opposed to regular components)
28
28
  */
@@ -32,7 +32,7 @@ export declare type IsolationContext = {
32
32
  */
33
33
  workspaceName?: string;
34
34
  };
35
- export declare type IsolateComponentsInstallOptions = {
35
+ export type IsolateComponentsInstallOptions = {
36
36
  installPackages?: boolean;
37
37
  dedupe?: boolean;
38
38
  copyPeerToRuntimeOnComponents?: boolean;
@@ -42,7 +42,7 @@ export declare type IsolateComponentsInstallOptions = {
42
42
  packageManagerConfigRootDir?: string;
43
43
  useNesting?: boolean;
44
44
  };
45
- declare type CreateGraphOptions = {
45
+ type CreateGraphOptions = {
46
46
  /**
47
47
  * include components that exists in nested hosts. for example include components that exist in scope but not in the workspace
48
48
  */
@@ -52,7 +52,7 @@ declare type CreateGraphOptions = {
52
52
  */
53
53
  host?: ComponentFactory;
54
54
  };
55
- export declare type IsolateComponentsOptions = CreateGraphOptions & {
55
+ export type IsolateComponentsOptions = CreateGraphOptions & {
56
56
  name?: string;
57
57
  /**
58
58
  * absolute path to put all the capsules dirs inside.
@@ -151,7 +151,7 @@ export declare type IsolateComponentsOptions = CreateGraphOptions & {
151
151
  */
152
152
  cacheCapsulesDir?: string;
153
153
  };
154
- declare type GetCapsuleDirOpts = Pick<IsolateComponentsOptions, 'datedDirId' | 'useHash' | 'rootBaseDir' | 'useDatedDirs' | 'cacheLockFileOnly'> & {
154
+ type GetCapsuleDirOpts = Pick<IsolateComponentsOptions, 'datedDirId' | 'useHash' | 'rootBaseDir' | 'useDatedDirs' | 'cacheLockFileOnly'> & {
155
155
  baseDir: string;
156
156
  };
157
157
  /**
@@ -300,10 +300,9 @@ class IsolatorMain {
300
300
  // TODO: the legacy scope used for the component writer, which then decide if it need to write the artifacts and dists
301
301
  // TODO: we should think of another way to provide it (maybe a new opts) then take the scope internally from the host
302
302
  async isolateComponents(seeders, opts, legacyScope) {
303
- var _opts$host;
304
303
  const host = opts.host || this.componentAspect.getHost();
305
304
  this.logger.debug(`isolateComponents, ${seeders.join(', ')}. opts: ${JSON.stringify(Object.assign({}, opts, {
306
- host: (_opts$host = opts.host) === null || _opts$host === void 0 ? void 0 : _opts$host.name
305
+ host: opts.host?.name
307
306
  }))}`);
308
307
  const createGraphOpts = (0, _lodash().pick)(opts, ['includeFromNestedHosts', 'host']);
309
308
  const componentsToIsolate = opts.seedersOnly ? await host.getMany(seeders) : await this.createGraph(seeders, createGraphOpts);
@@ -499,7 +498,6 @@ class IsolatorMain {
499
498
  });
500
499
  }
501
500
  shouldUseDatedDirs(componentsToIsolate, opts) {
502
- var _opts$installOptions;
503
501
  if (!opts.useDatedDirs) return false;
504
502
  // No need to use the dated dirs in case we anyway create new capsule for each one
505
503
  if (opts.alwaysNew) return false;
@@ -508,7 +506,7 @@ class IsolatorMain {
508
506
  if (opts.getExistingAsIs) return false;
509
507
  // Do not use the dated dirs in case we don't use nesting, as the capsules
510
508
  // will not work after moving to the real dir
511
- if (!((_opts$installOptions = opts.installOptions) !== null && _opts$installOptions !== void 0 && _opts$installOptions.useNesting)) return false;
509
+ if (!opts.installOptions?.useNesting) return false;
512
510
  // Getting the real capsule dir to check if all capsules exists
513
511
  const realCapsulesDir = this.getCapsulesRootDir(_objectSpread(_objectSpread({}, opts), {}, {
514
512
  useDatedDirs: false,
@@ -552,16 +550,14 @@ class IsolatorMain {
552
550
  * @param legacyScope
553
551
  */
554
552
  async createCapsules(components, capsulesDir, opts, legacyScope) {
555
- var _opts$context, _opts$installOptions2;
556
553
  this.logger.debug(`createCapsules, ${components.length} components`);
557
554
  let longProcessLogger;
558
- if ((_opts$context = opts.context) !== null && _opts$context !== void 0 && _opts$context.aspects) {
559
- var _opts$host2;
555
+ if (opts.context?.aspects) {
560
556
  // const wsPath = opts.host?.path || 'unknown';
561
- const wsPath = opts.context.workspaceName || ((_opts$host2 = opts.host) === null || _opts$host2 === void 0 ? void 0 : _opts$host2.path) || opts.name || 'unknown';
557
+ const wsPath = opts.context.workspaceName || opts.host?.path || opts.name || 'unknown';
562
558
  longProcessLogger = this.logger.createLongProcessLogger(`ensuring ${_chalk().default.cyan(components.length.toString())} capsule(s) for all envs and aspects for ${_chalk().default.bold(wsPath)} at ${_chalk().default.bold(capsulesDir)}`);
563
559
  }
564
- const useNesting = this.dependencyResolver.isolatedCapsules() && ((_opts$installOptions2 = opts.installOptions) === null || _opts$installOptions2 === void 0 ? void 0 : _opts$installOptions2.useNesting);
560
+ const useNesting = this.dependencyResolver.isolatedCapsules() && opts.installOptions?.useNesting;
565
561
  const installOptions = _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_ISOLATE_INSTALL_OPTIONS), opts.installOptions), {}, {
566
562
  useNesting
567
563
  });
@@ -593,12 +589,11 @@ class IsolatorMain {
593
589
  await this.writeComponentsInCapsules(components, capsuleList, legacyScope, opts);
594
590
  await this.updateWithCurrentPackageJsonData(capsulesWithPackagesData, capsuleList);
595
591
  if (installOptions.installPackages) {
596
- var _opts$context2;
597
592
  const cachePackagesOnCapsulesRoot = opts.cachePackagesOnCapsulesRoot ?? false;
598
593
  const linkingOptions = opts.linkingOptions ?? {};
599
594
  let installLongProcessLogger;
600
595
  // Only show the log message in case we are going to install something
601
- if (capsuleList && capsuleList.length && !((_opts$context2 = opts.context) !== null && _opts$context2 !== void 0 && _opts$context2.aspects)) {
596
+ if (capsuleList && capsuleList.length && !opts.context?.aspects) {
602
597
  installLongProcessLogger = this.logger.createLongProcessLogger(`install packages in ${capsuleList.length} capsules`);
603
598
  }
604
599
  const rootLinks = await this.linkInCapsulesRoot(capsulesDir, capsuleList, linkingOptions);
@@ -800,7 +795,7 @@ class IsolatorMain {
800
795
  await Promise.all(components.map(async component => {
801
796
  const capsule = capsuleList.getCapsule(component.id);
802
797
  if (!capsule) return;
803
- const scope = (await _capsuleList().default.capsuleUsePreviouslySavedDists(component)) || opts !== null && opts !== void 0 && opts.populateArtifactsFrom ? legacyScope : undefined;
798
+ const scope = (await _capsuleList().default.capsuleUsePreviouslySavedDists(component)) || opts?.populateArtifactsFrom ? legacyScope : undefined;
804
799
  const dataToPersist = await this.populateComponentsFilesToWriteForCapsule(component, allIds, scope, opts);
805
800
  await dataToPersist.persistAllToCapsule(capsule, {
806
801
  keepExistingCapsule: true
@@ -955,7 +950,7 @@ class IsolatorMain {
955
950
  const depCapsule = capsules.getCapsule(dep.componentId);
956
951
  let version = dep.version;
957
952
  if (depCapsule) {
958
- version = (0, _componentPackageVersion().getComponentPackageVersion)(depCapsule === null || depCapsule === void 0 ? void 0 : depCapsule.component);
953
+ version = (0, _componentPackageVersion().getComponentPackageVersion)(depCapsule?.component);
959
954
  } else {
960
955
  version = (0, _componentPackageVersion().snapToSemver)(version);
961
956
  }
@@ -1003,7 +998,7 @@ class IsolatorMain {
1003
998
  const valuesToMerge = legacyComp.overrides.componentOverridesPackageJsonData;
1004
999
  packageJson.mergePackageJsonObject(valuesToMerge);
1005
1000
  dataToPersist.addFile(packageJson.toVinylFile());
1006
- const artifacts = await this.getArtifacts(component, legacyScope, opts === null || opts === void 0 ? void 0 : opts.populateArtifactsFrom);
1001
+ const artifacts = await this.getArtifacts(component, legacyScope, opts?.populateArtifactsFrom);
1007
1002
  dataToPersist.addManyFiles(artifacts);
1008
1003
  return dataToPersist;
1009
1004
  }