build-strap 4.1.0-dev.61 → 4.1.0-dev.62

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "build-strap",
3
- "version": "4.1.0-dev.61",
3
+ "version": "4.1.0-dev.62",
4
4
  "description": "Node scripts for building things",
5
5
  "license": "MIT",
6
6
  "authors": [
package/src/brew.js CHANGED
@@ -2,8 +2,7 @@ import fs from 'fs-extra';
2
2
  import os from 'os';
3
3
  import path from 'path';
4
4
  import { spawn } from './cp.js';
5
- import { cmdExists } from './env.js';
6
- import { appendIfMissing } from './fs.js';
5
+ import { appendToEnvProfile, cmdExists, ensureProcessPathEnvIncludes, } from './env.js';
7
6
  const brewPath = async () => {
8
7
  for (const testPath of [
9
8
  '/opt/homebrew/bin/brew',
@@ -25,12 +24,10 @@ const brewPathExists = async () => {
25
24
  return false;
26
25
  }
27
26
  };
28
- const appendBrewShellEnv = async () => {
27
+ const appendBrewShellEnv = async (opts) => {
29
28
  const brewDir = path.dirname(await brewPath());
30
- await appendIfMissing(path.join(os.homedir(), '.zprofile'), `\neval "$(${brewDir}/brew shellenv)"`);
31
- if (!process.env.PATH?.includes(brewDir)) {
32
- process.env.PATH = `${brewDir}:${process.env.PATH}`;
33
- }
29
+ await appendToEnvProfile(`\neval "$(${brewDir}/brew shellenv)"`, opts);
30
+ ensureProcessPathEnvIncludes(brewDir);
34
31
  };
35
32
  export const ensureBrewInstalled = async () => {
36
33
  if (!(await cmdExists('brew'))) {
@@ -73,14 +73,14 @@ export async function unthrottledDockerContainerLs({ all, filter, } = {}) {
73
73
  log(`<${this.name}> container stopped.`);
74
74
  }
75
75
  catch (e1) {
76
- log(`Failed to stop <${this.name}> container: ${e1.message}`);
76
+ log(`Failed to stop <${this.name}> container: ${e1 instanceof Error && e1.message}`);
77
77
  try {
78
78
  log(`Killing container: <${this.name}>...`);
79
79
  await this.kill(false);
80
80
  log(`<${this.name}> container killed.`);
81
81
  }
82
82
  catch (e2) {
83
- log(`Failed to kill <${this.name}> container: ${e2.message}`);
83
+ log(`Failed to kill <${this.name}> container: ${e2 instanceof Error && e2.message}`);
84
84
  }
85
85
  }
86
86
  }
@@ -113,7 +113,7 @@ export async function dockerContainerStop(id, ignoreErrors = true) {
113
113
  }
114
114
  catch (e) {
115
115
  if (!ignoreErrors) {
116
- throw new Error(`Failed to stop container(s): ${e.message}`);
116
+ throw new Error(`Failed to stop container(s): ${e instanceof Error && e.message}`);
117
117
  }
118
118
  }
119
119
  }
@@ -124,7 +124,7 @@ export async function dockerContainerKill(id, ignoreErrors = true) {
124
124
  }
125
125
  catch (e) {
126
126
  if (!ignoreErrors) {
127
- throw new Error(`Failed to kill container(s): ${e.message}`);
127
+ throw new Error(`Failed to kill container(s): ${e instanceof Error && e.message}`);
128
128
  }
129
129
  }
130
130
  }
@@ -134,7 +134,7 @@ export async function dockerTryStopContainer(id, name = '') {
134
134
  await dockerContainerStop(id, false);
135
135
  }
136
136
  catch (e) {
137
- buildLog(`Failed to stop ${name} container: ${e.message}`);
137
+ buildLog(`Failed to stop ${name} container: ${e instanceof Error && e.message}`);
138
138
  }
139
139
  }
140
140
  }
@@ -145,10 +145,10 @@ export async function dockerContainerRm(id, ignoreErrors = true) {
145
145
  }
146
146
  catch (e) {
147
147
  if (ignoreErrors) {
148
- buildLog(`Warning (ignored Error): Failed to remove container(s): ${e.message}`);
148
+ buildLog(`Warning (ignored Error): Failed to remove container(s): ${e instanceof Error && e.message}`);
149
149
  }
150
150
  else {
151
- throw new Error(`Failed to remove container(s): ${e.message}`);
151
+ throw new Error(`Failed to remove container(s): ${e instanceof Error && e.message}`);
152
152
  }
153
153
  }
154
154
  }
@@ -1,4 +1,4 @@
1
- declare type DockerVolumeInspectOutput = Record<string, any>;
1
+ declare type DockerVolumeInspectOutput = Record<string, unknown>;
2
2
  export interface DockerVolume {
3
3
  driver: string;
4
4
  inspect: () => Promise<null | DockerVolumeInspectOutput>;
@@ -49,7 +49,7 @@ export async function dockerVolumeRm(id, ignoreErrors = true) {
49
49
  }
50
50
  catch (e) {
51
51
  if (!ignoreErrors) {
52
- throw new Error(`Failed to remove volume(s): ${e.message}`);
52
+ throw new Error(`Failed to remove volume(s): ${e instanceof Error && e.message}`);
53
53
  }
54
54
  }
55
55
  }
@@ -8,7 +8,9 @@ import { buildLog } from './run.js';
8
8
  async function flatten(input) {
9
9
  const result = await input;
10
10
  return Array.isArray(result)
11
- ? [].concat(...(await Promise.all(result.map(flatten))))
11
+ ? [].concat(
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ ...(await Promise.all(result.map(flatten))))
12
14
  : result;
13
15
  }
14
16
  /**
package/src/env.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { StringGenFn } from './fs.js';
1
2
  export declare const isMac: () => boolean;
2
3
  export declare const isLinux: () => boolean;
3
4
  export declare const isWindows: () => boolean;
@@ -13,7 +14,13 @@ interface ReadShellEnvVarOptions {
13
14
  shell?: string;
14
15
  }
15
16
  export declare const readShellEnvVar: (name: string, { refreshEnv, envFile, shell, }?: ReadShellEnvVarOptions) => Promise<string | null>;
17
+ export interface AppendToEnvProfileOptions {
18
+ envFile?: string | null;
19
+ testContent?: string | StringGenFn;
20
+ }
21
+ export declare const appendToEnvProfile: (content: string | StringGenFn, { envFile, testContent }?: AppendToEnvProfileOptions) => Promise<void>;
16
22
  export declare const appendEnvVarToProfile: (name: string, value: string, { envFile }?: ReadShellEnvVarOptions) => Promise<void>;
17
23
  export declare const ensureEnvVarValue: (name: string, value: string, opts?: ReadShellEnvVarOptions | undefined) => Promise<void>;
18
24
  export declare const ensureEnvVarSet: (name: string, getValue: () => Promise<string>) => Promise<void>;
25
+ export declare const ensureProcessPathEnvIncludes: (binPath: string) => void;
19
26
  export {};
package/src/env.js CHANGED
@@ -37,7 +37,7 @@ export const shellEnvFile = () => cacheString('shellEnvFile', () => {
37
37
  }
38
38
  });
39
39
  export const whichCmd = async (cmd) => {
40
- const binPath = (await spawn('which', [cmd], { captureOutput: true })).output.trim();
40
+ const binPath = (await spawn('which', [cmd], { captureOutput: true })).stdout.trim();
41
41
  if (!binPath || !(await fs.pathExists(binPath))) {
42
42
  return null;
43
43
  }
@@ -57,12 +57,13 @@ export const readShellEnvVar = async (name, { refreshEnv = false, envFile = shel
57
57
  return null;
58
58
  }
59
59
  };
60
- export const appendEnvVarToProfile = async (name, value, { envFile = shellEnvFile() } = {}) => {
60
+ export const appendToEnvProfile = async (content, { envFile = shellEnvFile(), testContent } = {}) => {
61
61
  if (!envFile) {
62
62
  throw new Error('envFile must be set');
63
63
  }
64
- await appendIfMissing(path.join(os.homedir(), envFile), `\nexport ${name}=${value}`);
64
+ await appendIfMissing(envFile, content, testContent);
65
65
  };
66
+ export const appendEnvVarToProfile = async (name, value, { envFile = shellEnvFile() } = {}) => appendToEnvProfile(`\nexport ${name}=${value}`, { envFile });
66
67
  export const ensureEnvVarValue = async (name, value, opts) => {
67
68
  const currentValue = await readShellEnvVar(name, opts);
68
69
  if (currentValue !== value) {
@@ -78,3 +79,8 @@ export const ensureEnvVarSet = async (name, getValue) => {
78
79
  process.env[name] = newValue;
79
80
  }
80
81
  };
82
+ export const ensureProcessPathEnvIncludes = (binPath) => {
83
+ if (!process.env.PATH?.includes(binPath)) {
84
+ process.env.PATH = `${binPath}:${process.env.PATH}`;
85
+ }
86
+ };
package/src/fs.d.ts CHANGED
@@ -5,7 +5,6 @@ export declare const copyDir: (source: string, target: string, fileGlob?: string
5
5
  export declare const cleanDir: (pattern: string, globOptions?: false | glob.IOptions | undefined) => Promise<void>;
6
6
  export declare const producedPathExists: (producer: () => Promise<string>) => Promise<boolean>;
7
7
  export declare const copyIfMissing: (src: string, dest: string) => Promise<void>;
8
- declare type StringGenFn = () => string | Promise<string>;
8
+ export declare type StringGenFn = () => string | Promise<string>;
9
9
  export declare const writeIfMissing: (dest: string, content: string | StringGenFn) => Promise<boolean>;
10
10
  export declare const appendIfMissing: (dest: string, content: string | StringGenFn, testContent?: string | StringGenFn | undefined) => Promise<void>;
11
- export {};
package/src/maps.js CHANGED
@@ -38,4 +38,6 @@ export const filterKeys = (obj, filter = (v) => v != null) => Object.entries(obj
38
38
  * @param {Object} obj the input object
39
39
  * @returns {Object} a new object, a subset of the input
40
40
  */
41
- export const filterNullish = (obj) => filterKeys(obj);
41
+ export const filterNullish = (obj) =>
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ filterKeys(obj);
package/src/publish.d.ts CHANGED
@@ -22,6 +22,6 @@ export interface PublishConfiguration extends CreateArtifactOptions {
22
22
  npmPath?: string;
23
23
  npmSkipExisting?: boolean;
24
24
  npmTag?: string;
25
- prePublishFn?: () => any;
25
+ prePublishFn?: () => void | Promise<void>;
26
26
  }
27
27
  export declare function publish({ distDir, doPublish, fileName, npmAuthToken, npmConfig, npmCreds, npmPath, npmSkipExisting, npmTag, outDir, prePublishFn, }: PublishConfiguration): Promise<void>;