build-strap 5.1.0-dev.118 → 5.2.0

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": "5.1.0-dev.118",
3
+ "version": "5.2.0",
4
4
  "description": "Node scripts for building things",
5
5
  "license": "MIT",
6
6
  "authors": [
package/src/cp.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import cp from 'child_process';
3
2
  export interface SpawnOptions extends cp.SpawnOptions {
4
3
  captureOutput?: boolean;
package/src/docker.js CHANGED
@@ -73,7 +73,7 @@ export async function dockerImages(repo = getDockerRepo(), filter = null) {
73
73
  digest,
74
74
  id,
75
75
  repository,
76
- size: bytes.parse(Size),
76
+ size: bytes.parse(Size) || 0,
77
77
  tag,
78
78
  };
79
79
  })
package/src/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export * from './git.js';
19
19
  export * from './macos.js';
20
20
  export * from './maps.js';
21
21
  export * from './npm.js';
22
+ export * from './orbstack.js';
22
23
  export * from './pkg.js';
23
24
  export * from './promise.js';
24
25
  export * from './prompt.js';
package/src/index.js CHANGED
@@ -19,6 +19,7 @@ export * from './git.js';
19
19
  export * from './macos.js';
20
20
  export * from './maps.js';
21
21
  export * from './npm.js';
22
+ export * from './orbstack.js';
22
23
  export * from './pkg.js';
23
24
  export * from './promise.js';
24
25
  export * from './prompt.js';
package/src/npm.d.ts CHANGED
@@ -32,12 +32,13 @@ export interface NpmPublishOptions {
32
32
  npmConfig?: NpmConfig;
33
33
  npmCreds?: NpmCreds;
34
34
  npmPath?: string;
35
+ provenance?: boolean;
35
36
  publishPath?: string;
36
37
  skipExisting?: boolean;
37
38
  tag?: string;
38
39
  workDir?: string;
39
40
  }
40
- export declare function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, publishPath, skipExisting, tag, workDir: passedWorkDir, }?: NpmPublishOptions): Promise<boolean>;
41
+ export declare function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, provenance, publishPath, skipExisting, tag, workDir: passedWorkDir, }?: NpmPublishOptions): Promise<boolean>;
41
42
  interface NpmPackOptions {
42
43
  destination?: string;
43
44
  npmConfig?: NpmConfig;
package/src/npm.js CHANGED
@@ -48,6 +48,7 @@ export async function npmWriteRc({ authToken, creds, outPath, registry, }) {
48
48
  // Write out .npmrc with credentials
49
49
  const theRegistry = registry || 'https://registry.npmjs.org/';
50
50
  const [, host] = /^(?:http(?:s)?:\/\/)?(.+)$/.exec(theRegistry) || [];
51
+ buildLog(`Writing npmrc with registry ${theRegistry}`);
51
52
  await fs.mkdirp(path.dirname(outPath));
52
53
  await fs.writeFile(outPath, `registry=${theRegistry}
53
54
  ${authToken ? `//${host}:_authToken=${authToken}` : ''}
@@ -57,7 +58,7 @@ always-auth=true
57
58
  email=${creds.email}`
58
59
  : ''}`);
59
60
  }
60
- export async function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, publishPath = '.', skipExisting = false, tag, workDir: passedWorkDir, } = {}) {
61
+ export async function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, provenance = false, publishPath = '.', skipExisting = false, tag, workDir: passedWorkDir, } = {}) {
61
62
  const creds = npmCreds || envNpmCreds;
62
63
  const authToken = npmAuthToken || process.env.NPM_TOKEN;
63
64
  const name = getPkgName(true);
@@ -93,6 +94,9 @@ export async function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, p
93
94
  }
94
95
  throw new Error('Failed to publish npm package, this version already exists!');
95
96
  }
97
+ if (authToken) {
98
+ buildLog(`Using NPM_TOKEN for authentication`);
99
+ }
96
100
  await npm({
97
101
  args: [
98
102
  'publish',
@@ -106,6 +110,7 @@ export async function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, p
106
110
  : 'branch'),
107
111
  ...(access ? ['--access', access] : []),
108
112
  ...(dryRun ? ['--dry-run'] : []),
113
+ ...(provenance ? ['--provenance'] : []),
109
114
  '--color=always',
110
115
  ],
111
116
  npmPath,
@@ -113,7 +118,12 @@ export async function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, p
113
118
  cwd: workDir,
114
119
  env: {
115
120
  ...process.env,
116
- NPM_TOKEN: authToken,
121
+ npm_config_registry: registry || 'https://registry.npmjs.org/',
122
+ ...(authToken
123
+ ? {
124
+ NPM_TOKEN: authToken,
125
+ }
126
+ : {}),
117
127
  },
118
128
  },
119
129
  });
@@ -0,0 +1,4 @@
1
+ import { SpawnOptions, SpawnResult } from './cp';
2
+ export declare const ensureOrbStackInstalled: (options?: SpawnOptions) => Promise<SpawnResult | null>;
3
+ export declare const ensureOrbStackRunning: (timeoutSeconds?: number) => Promise<void>;
4
+ export declare const ensureOrbStackConfigured: (desiredConfig?: null | Record<string, unknown>) => Promise<void>;
@@ -0,0 +1,90 @@
1
+ import fs from 'fs-extra';
2
+ import os from 'os';
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';
9
+ export const ensureOrbStackInstalled = async (options) => {
10
+ if (!isMac()) {
11
+ throw new Error('OrbStack is only supported on macOS');
12
+ }
13
+ if (!(await cmdExists('orb'))) {
14
+ return brew(['install', 'orbstack'], options);
15
+ }
16
+ return null;
17
+ };
18
+ export const ensureOrbStackRunning = async (timeoutSeconds = 600) => {
19
+ if (!(await dockerIsRunning())) {
20
+ if (!isMac()) {
21
+ throw new Error('OrbStack is only supported on macOS');
22
+ }
23
+ buildLog('docker is not running, starting OrbStack...');
24
+ await spawn('open', ['-a', '/Applications/OrbStack.app']);
25
+ let attempts = 0;
26
+ while (!(await dockerIsRunning())) {
27
+ attempts += 1;
28
+ if (attempts % 5 === 0) {
29
+ process.stdout.write('.');
30
+ }
31
+ if (attempts > timeoutSeconds) {
32
+ throw new Error('Timeout starting OrbStack');
33
+ }
34
+ await new Promise((resolve) => {
35
+ setTimeout(resolve, 1000);
36
+ });
37
+ }
38
+ if (attempts >= 5) {
39
+ process.stdout.write('\n');
40
+ }
41
+ }
42
+ };
43
+ const defaultConfig = {
44
+ memory_mib: 16384,
45
+ };
46
+ export const ensureOrbStackConfigured = async (desiredConfig) => {
47
+ if (!desiredConfig) {
48
+ buildLog('Skipping OrbStack configuration due to empty config value');
49
+ return;
50
+ }
51
+ if (!isMac()) {
52
+ throw new Error('OrbStack is only supported on macOS');
53
+ }
54
+ const configPath = path.join(os.homedir(), '.orbstack/vmconfig.json');
55
+ await fs.ensureDir(path.dirname(configPath));
56
+ let changed = false;
57
+ if (!(await fs.pathExists(configPath))) {
58
+ buildLog('Setting OrbStack config...');
59
+ await fs.writeJson(configPath, desiredConfig, { spaces: 2 });
60
+ changed = true;
61
+ }
62
+ else {
63
+ const existingConfig = await fs.readJson(configPath);
64
+ const effectiveConfig = {
65
+ ...defaultConfig,
66
+ ...existingConfig,
67
+ };
68
+ if (!Object.entries(desiredConfig).every(([key, value]) => effectiveConfig[key] === value)) {
69
+ buildLog('Adjusting OrbStack config...');
70
+ const newConfig = {
71
+ ...existingConfig,
72
+ ...desiredConfig,
73
+ };
74
+ for (const [key, value] of Object.entries(defaultConfig)) {
75
+ if (newConfig[key] === value) {
76
+ // Don't write default values
77
+ delete newConfig[key];
78
+ }
79
+ }
80
+ await fs.writeJson(configPath, newConfig, { spaces: 2 });
81
+ changed = true;
82
+ }
83
+ }
84
+ if (changed && (await dockerIsRunning())) {
85
+ // Restart the app
86
+ buildLog('Killing OrbStack...');
87
+ await spawn('osascript', ['-e', `quit app "OrbStack"`]);
88
+ await ensureOrbStackRunning();
89
+ }
90
+ };
package/src/tgz.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- /// <reference types="node" />
2
1
  import { Readable } from 'stream';
3
- import { TarOptionsWithAliases } from 'tar/dist/commonjs/options.js';
2
+ import { TarOptionsWithAliasesNoFile } from 'tar/dist/commonjs/options.js';
4
3
  export type ArtifactInfo = {
5
4
  contentType?: string;
6
5
  md5: string;
@@ -8,6 +7,6 @@ export type ArtifactInfo = {
8
7
  sha512: string;
9
8
  size: number;
10
9
  };
11
- export declare const generateFileHash: (filePath: string, type: 'md5' | 'sha1' | 'sha512') => Promise<string>;
10
+ export declare const generateFileHash: (filePath: string, type: "md5" | "sha1" | "sha512") => Promise<string>;
12
11
  export declare function getArtifactInfo(artifact: string | Pick<Readable, 'pipe'>): Promise<ArtifactInfo>;
13
- export declare function tgzDir(srcDir: string, outPath: string, options?: TarOptionsWithAliases): Promise<ArtifactInfo>;
12
+ export declare function tgzDir(srcDir: string, outPath: string, options?: TarOptionsWithAliasesNoFile): Promise<ArtifactInfo>;