@enspirit/emb 0.8.0 → 0.8.1

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/README.md CHANGED
@@ -14,7 +14,7 @@ $ npm install -g @enspirit/emb
14
14
  $ emb COMMAND
15
15
  running command...
16
16
  $ emb (--version)
17
- @enspirit/emb/0.8.0 darwin-x64 node-v22.18.0
17
+ @enspirit/emb/0.8.1 darwin-x64 node-v22.18.0
18
18
  $ emb --help [COMMAND]
19
19
  USAGE
20
20
  $ emb COMMAND
@@ -16,9 +16,10 @@ export type GetContainerOptions = {
16
16
  export declare const DefaultGetContainerOptions: GetContainerOptions;
17
17
  export declare class DockerComposeClient {
18
18
  protected monorepo: Monorepo;
19
- protected containers?: ComposeServices;
19
+ protected services?: ComposeServices;
20
20
  constructor(monorepo: Monorepo);
21
21
  init(): Promise<void>;
22
+ isService(component: string): boolean | undefined;
22
23
  getContainer(serviceName: string, options?: Partial<GetContainerOptions>): Promise<string>;
23
24
  private loadContainers;
24
25
  }
@@ -5,17 +5,20 @@ export const DefaultGetContainerOptions = {
5
5
  };
6
6
  export class DockerComposeClient {
7
7
  monorepo;
8
- containers;
8
+ services;
9
9
  constructor(monorepo) {
10
10
  this.monorepo = monorepo;
11
11
  }
12
12
  async init() {
13
13
  await this.loadContainers();
14
14
  }
15
+ isService(component) {
16
+ return this.services?.has(component);
17
+ }
15
18
  async getContainer(serviceName, options = DefaultGetContainerOptions) {
16
19
  const getOptions = { ...DefaultGetContainerOptions, ...options };
17
20
  await this.loadContainers();
18
- const service = this.containers?.get(serviceName);
21
+ const service = this.services?.get(serviceName);
19
22
  if (!service) {
20
23
  throw new Error(`No compose service found with name ${serviceName}`);
21
24
  }
@@ -31,25 +34,29 @@ export class DockerComposeClient {
31
34
  return containers[0].ID;
32
35
  }
33
36
  async loadContainers(force = false) {
34
- if (this.containers && !force) {
37
+ if (this.services && !force) {
35
38
  return;
36
39
  }
40
+ const { stdout: servicesOutput } = await execa({
41
+ cwd: this.monorepo.rootDir,
42
+ }) `docker compose config --services`;
43
+ const services = servicesOutput
44
+ .split('\n')
45
+ .map((l) => l.trim())
46
+ .reduce((services, name) => {
47
+ services.set(name, { name, containers: [] });
48
+ return services;
49
+ }, new Map());
37
50
  const { stdout } = await execa({
38
51
  cwd: this.monorepo.rootDir,
39
52
  }) `docker compose ps -a --format json`;
40
- this.containers = stdout
53
+ this.services = stdout
41
54
  .split('\n')
42
55
  .map((l) => JSON.parse(l))
43
56
  .reduce((services, entry) => {
44
- if (!services.has(entry.Service)) {
45
- services.set(entry.Service, {
46
- name: entry.Service,
47
- containers: [],
48
- });
49
- }
50
57
  const svc = services.get(entry.Service);
51
58
  svc?.containers.push(entry);
52
59
  return services;
53
- }, new Map());
60
+ }, services);
54
61
  }
55
62
  }
@@ -13,7 +13,7 @@ export var ExecutorType;
13
13
  })(ExecutorType || (ExecutorType = {}));
14
14
  export class RunTasksOperation {
15
15
  async run(params) {
16
- const { monorepo } = getContext();
16
+ const { monorepo, compose } = getContext();
17
17
  // First ensure the selection is valid (user can use task IDs or names)
18
18
  const collection = new EMBCollection(monorepo.tasks, {
19
19
  idField: 'id',
@@ -33,9 +33,14 @@ export class RunTasksOperation {
33
33
  }
34
34
  const vars = await monorepo.expand(task.vars || {});
35
35
  const executor = params.executor ??
36
- (task.component ? ExecutorType.container : ExecutorType.local);
37
- if (executor === ExecutorType.container && !task.component) {
38
- throw new Error('Cannot use the container executor with global tasks');
36
+ (task.component
37
+ ? compose.isService(task.component)
38
+ ? ExecutorType.container
39
+ : ExecutorType.local
40
+ : ExecutorType.local);
41
+ if (executor === ExecutorType.container &&
42
+ (!task.component || !compose.isService(task.component))) {
43
+ throw new Error('Cannot use the container executor with this task');
39
44
  }
40
45
  // Handle tasks that require confirmation
41
46
  if (task.confirm) {
@@ -853,5 +853,5 @@
853
853
  ]
854
854
  }
855
855
  },
856
- "version": "0.8.0"
856
+ "version": "0.8.1"
857
857
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@enspirit/emb",
3
3
  "type": "module",
4
- "version": "0.8.0",
4
+ "version": "0.8.1",
5
5
  "keywords": [
6
6
  "monorepo",
7
7
  "docker",