build-strap 6.0.0 → 6.0.1-buildlog-stderr.142
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 +25 -3
- package/package.json +2 -2
- package/src/docker.container.js +1 -1
- package/src/orbstack.d.ts +1 -1
- package/src/orbstack.js +5 -5
- package/src/run.d.ts +17 -1
- package/src/run.js +31 -2
package/README.md
CHANGED
|
@@ -32,8 +32,8 @@ By default, the build tools read project-specific configuration from your `packa
|
|
|
32
32
|
"name": "your-project-name",
|
|
33
33
|
"version": "1.2.3",
|
|
34
34
|
"buildStrap": {
|
|
35
|
-
"nodeVersion": "
|
|
36
|
-
"yarnVersion": "1.22.
|
|
35
|
+
"nodeVersion": "24.18.0",
|
|
36
|
+
"yarnVersion": "1.22.22",
|
|
37
37
|
"repoType": "git",
|
|
38
38
|
"copyright": "your company",
|
|
39
39
|
"mainBranch": "main",
|
|
@@ -120,13 +120,35 @@ publish(
|
|
|
120
120
|
```
|
|
121
121
|
|
|
122
122
|
### buildLog
|
|
123
|
-
Write out to the console in a timestamp prefixed format consistent with the rest of the build output.
|
|
123
|
+
Write out to the console in a timestamp prefixed format consistent with the rest of the build output. Output goes to `stderr` by default, so that `stdout` can be reserved for machine readable output.
|
|
124
124
|
```
|
|
125
125
|
import { buildLog } from 'build-strap';
|
|
126
126
|
|
|
127
127
|
buildLog('Hello world');
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
+
Pass a `Date` (as before) or an options object to control the timestamp and destination:
|
|
131
|
+
```
|
|
132
|
+
buildLog('Hello world', new Date());
|
|
133
|
+
buildLog('to stdout instead', { stream: 'stdout' });
|
|
134
|
+
buildLog('to any writable stream', { stream: myWriteStream });
|
|
135
|
+
buildLog('or handle it yourself', { stream: (msg) => myLogger.info(msg) });
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The default destination can be changed globally (affects `run`/`runCli` logging too):
|
|
139
|
+
```
|
|
140
|
+
import { getBuildLogStream, setBuildLogStream } from 'build-strap';
|
|
141
|
+
|
|
142
|
+
setBuildLogStream('stdout');
|
|
143
|
+
setBuildLogStream(process.stderr);
|
|
144
|
+
setBuildLogStream((msg) => myLogger.info(msg));
|
|
145
|
+
getBuildLogStream(); // current default
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
CLI flags:
|
|
149
|
+
- `--buildLog-stdout` — default to `stdout` instead of `stderr`
|
|
150
|
+
- `--silence-buildLog` — suppress all `buildLog` output
|
|
151
|
+
|
|
130
152
|
## NPM Credentials
|
|
131
153
|
In order to publish to NPM, proper credentials must be provided to the script. By default, these are read from the `NPM_CREDS` environment variable, but it is also possible to pass them as an argument to most functions. This is expected to be a JSON encoded string in the following format:
|
|
132
154
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "build-strap",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1-buildlog-stderr.142",
|
|
4
4
|
"description": "Node scripts for building things",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Justin Murray <justin@murrayju.com>",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"main": "./src/index.js",
|
|
13
13
|
"types": "./src/index.d.ts",
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
15
|
+
"node": ">=24"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"bytes": "^3.1.1",
|
package/src/docker.container.js
CHANGED
package/src/orbstack.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SpawnOptions, SpawnResult } from './cp';
|
|
1
|
+
import { SpawnOptions, SpawnResult } from './cp.js';
|
|
2
2
|
export declare const ensureOrbStackInstalled: (options?: SpawnOptions) => Promise<SpawnResult | null>;
|
|
3
3
|
export declare const ensureOrbStackRunning: (timeoutSeconds?: number) => Promise<void>;
|
|
4
4
|
export declare const ensureOrbStackConfigured: (desiredConfig?: null | Record<string, unknown>) => Promise<void>;
|
package/src/orbstack.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import os from 'os';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { brew } from './brew';
|
|
5
|
-
import { spawn } from './cp';
|
|
6
|
-
import { dockerIsRunning } from './docker';
|
|
7
|
-
import { cmdExists, isMac } from './env';
|
|
8
|
-
import { buildLog } from './run';
|
|
4
|
+
import { brew } from './brew.js';
|
|
5
|
+
import { spawn } from './cp.js';
|
|
6
|
+
import { dockerIsRunning } from './docker.js';
|
|
7
|
+
import { cmdExists, isMac } from './env.js';
|
|
8
|
+
import { buildLog } from './run.js';
|
|
9
9
|
export const ensureOrbStackInstalled = async (options) => {
|
|
10
10
|
if (!isMac()) {
|
|
11
11
|
throw new Error('OrbStack is only supported on macOS');
|
package/src/run.d.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
export declare function format(time?: Date): string;
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Where `buildLog` output should be written. Either the name of one of the
|
|
4
|
+
* standard streams, any writable stream, or a function that receives the
|
|
5
|
+
* fully formatted message.
|
|
6
|
+
*/
|
|
7
|
+
export type BuildLogStream = 'stderr' | 'stdout' | NodeJS.WritableStream | ((msg: string) => void);
|
|
8
|
+
export interface BuildLogOptions {
|
|
9
|
+
/** Override the destination for this message only. */
|
|
10
|
+
stream?: BuildLogStream;
|
|
11
|
+
/** Timestamp to prefix the message with (defaults to now). */
|
|
12
|
+
time?: Date;
|
|
13
|
+
}
|
|
14
|
+
/** Change the destination used by `buildLog` when none is specified. */
|
|
15
|
+
export declare function setBuildLogStream(stream: BuildLogStream): void;
|
|
16
|
+
/** The destination currently used by `buildLog` when none is specified. */
|
|
17
|
+
export declare function getBuildLogStream(): BuildLogStream;
|
|
18
|
+
export declare function buildLog(msg: string, timeOrOptions?: BuildLogOptions | Date): void;
|
|
3
19
|
export type RunnableModule<Args extends string[], Result> = ((...args: Args) => Promise<Result>) | {
|
|
4
20
|
default: (...args: Args) => Promise<Result>;
|
|
5
21
|
};
|
package/src/run.js
CHANGED
|
@@ -2,11 +2,40 @@ export function format(time = new Date()) {
|
|
|
2
2
|
return time.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1');
|
|
3
3
|
}
|
|
4
4
|
const silenceLogs = process.argv.includes('--silence-buildLog');
|
|
5
|
-
|
|
5
|
+
// stderr by default, so that stdout can be used for machine readable output.
|
|
6
|
+
let defaultStream = process.argv.includes('--buildLog-stdout')
|
|
7
|
+
? 'stdout'
|
|
8
|
+
: 'stderr';
|
|
9
|
+
/** Change the destination used by `buildLog` when none is specified. */
|
|
10
|
+
export function setBuildLogStream(stream) {
|
|
11
|
+
defaultStream = stream;
|
|
12
|
+
}
|
|
13
|
+
/** The destination currently used by `buildLog` when none is specified. */
|
|
14
|
+
export function getBuildLogStream() {
|
|
15
|
+
return defaultStream;
|
|
16
|
+
}
|
|
17
|
+
function writeLog(msg, stream) {
|
|
18
|
+
if (typeof stream === 'function') {
|
|
19
|
+
stream(msg);
|
|
20
|
+
}
|
|
21
|
+
else if (stream === 'stdout') {
|
|
22
|
+
process.stdout.write(`${msg}\n`);
|
|
23
|
+
}
|
|
24
|
+
else if (stream === 'stderr') {
|
|
25
|
+
process.stderr.write(`${msg}\n`);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
stream.write(`${msg}\n`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function buildLog(msg, timeOrOptions) {
|
|
6
32
|
if (silenceLogs) {
|
|
7
33
|
return;
|
|
8
34
|
}
|
|
9
|
-
|
|
35
|
+
const { stream = defaultStream, time } = timeOrOptions instanceof Date
|
|
36
|
+
? { time: timeOrOptions }
|
|
37
|
+
: (timeOrOptions ?? {});
|
|
38
|
+
writeLog(`[${format(time || new Date())}] ${msg}`, stream);
|
|
10
39
|
}
|
|
11
40
|
export async function run(fn, ...options) {
|
|
12
41
|
if (fn == null) {
|