build-strap 4.0.0-dev.3 → 4.0.0-dev.4

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/npm.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { SpawnOptions, SpawnResult } from './cp.js';
1
2
  export declare type NpmCreds = {
2
3
  email?: string;
3
4
  password?: string;
@@ -12,7 +13,12 @@ export declare type NpmConfig = {
12
13
  };
13
14
  export declare function getNpmConfig(): NpmConfig;
14
15
  export declare const envNpmCreds: null | NpmCreds;
15
- export declare function npmExec(args: string[], npmPath?: string): Promise<string>;
16
+ export interface NpmOptions {
17
+ args?: string[];
18
+ npmPath?: string;
19
+ spawnOptions?: SpawnOptions;
20
+ }
21
+ export declare function npm({ args, spawnOptions, npmPath, }?: NpmOptions): Promise<SpawnResult>;
16
22
  export declare function npmGetVersions(packageName: string, npmPath?: string): Promise<string[]>;
17
23
  interface NpmWriteRcOptions {
18
24
  authToken?: string;
package/npm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs-extra';
2
2
  import { platform } from 'os';
3
3
  import path from 'path';
4
- import { exec, spawn } from './cp.js';
4
+ import { spawn } from './cp.js';
5
5
  import { getCfg, getPkgName } from './pkg.js';
6
6
  import { buildLog } from './run.js';
7
7
  import { getDevBranch, getVersion } from './version.js';
@@ -10,12 +10,32 @@ export function getNpmConfig() {
10
10
  }
11
11
  export const envNpmCreds = (process.env.NPM_CREDS && JSON.parse(process.env.NPM_CREDS)) || null;
12
12
  const npmExe = (npmPath) => npmPath || (platform() === 'win32' ? 'npm.cmd' : 'npm');
13
- export async function npmExec(args, npmPath) {
14
- return (await exec(`${npmExe(npmPath)} ${args.join(' ')}`)).stdout.toString();
13
+ export async function npm({ args = [], spawnOptions, npmPath, } = {}) {
14
+ const localNpm = path.join(path.dirname(process.execPath), 'lib/node_modules/npm/bin/npm-cli.js');
15
+ const spawnOpts = {
16
+ env: process.env,
17
+ shell: true,
18
+ stdio: 'inherit',
19
+ ...spawnOptions,
20
+ };
21
+ return npmPath
22
+ ? spawn(npmPath, args, spawnOpts)
23
+ : (await fs.pathExists(localNpm))
24
+ ? // prefer to use local copy of npm
25
+ spawn(process.execPath, [localNpm, ...args], spawnOpts)
26
+ : // fall back to globally installed npm
27
+ spawn(npmExe(), args, spawnOpts);
15
28
  }
16
29
  export async function npmGetVersions(packageName, npmPath) {
17
30
  try {
18
- return JSON.parse((await npmExec(['show', packageName, 'versions', '--json'], npmPath)).trim());
31
+ return JSON.parse((await npm({
32
+ args: ['show', packageName, 'versions', '--json'],
33
+ npmPath,
34
+ spawnOptions: {
35
+ captureOutput: true,
36
+ stdio: 'pipe',
37
+ },
38
+ })).stdout.trim());
19
39
  }
20
40
  catch (err) {
21
41
  buildLog(`warning: failed to find existing package for ${packageName} in npm registry: ${err.message}`);
@@ -71,27 +91,31 @@ export async function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, p
71
91
  }
72
92
  throw new Error('Failed to publish npm package, this version already exists!');
73
93
  }
74
- await spawn(npmExe(npmPath), [
75
- 'publish',
76
- resolvedPath,
77
- '--tag',
78
- tag ||
79
- (isRelease
80
- ? 'latest'
81
- : branch === (await getDevBranch())
82
- ? 'next'
83
- : 'branch'),
84
- ...(access ? ['--access', access] : []),
85
- ...(dryRun ? ['--dry-run'] : []),
86
- '--color=always',
87
- ], {
88
- cwd: workDir,
89
- env: {
90
- ...process.env,
91
- NPM_TOKEN: authToken,
94
+ await npm({
95
+ args: [
96
+ 'publish',
97
+ resolvedPath,
98
+ '--tag',
99
+ tag ||
100
+ (isRelease
101
+ ? 'latest'
102
+ : branch === (await getDevBranch())
103
+ ? 'next'
104
+ : 'branch'),
105
+ ...(access ? ['--access', access] : []),
106
+ ...(dryRun ? ['--dry-run'] : []),
107
+ '--color=always',
108
+ ],
109
+ npmPath,
110
+ spawnOptions: {
111
+ cwd: workDir,
112
+ env: {
113
+ ...process.env,
114
+ NPM_TOKEN: authToken,
115
+ },
116
+ shell: true,
117
+ stdio: 'inherit',
92
118
  },
93
- shell: true,
94
- stdio: 'inherit',
95
119
  });
96
120
  return true;
97
121
  }
@@ -100,15 +124,20 @@ export async function npmPack({ destination, npmConfig, npmPath, workDir = '.',
100
124
  if (destination) {
101
125
  await fs.ensureDir(destination);
102
126
  }
103
- const { stdout } = await spawn(npmExe(npmPath), [
104
- 'pack',
105
- ...(dryRun ? ['--dry-run'] : []),
106
- ...(destination ? ['--pack-destination', path.resolve(destination)] : []),
107
- '--color=always',
108
- ], {
109
- captureOutput: true,
110
- cwd: path.resolve(workDir),
111
- pipeOutput: true,
127
+ const { stdout } = await npm({
128
+ args: [
129
+ 'pack',
130
+ ...(dryRun ? ['--dry-run'] : []),
131
+ ...(destination ? ['--pack-destination', path.resolve(destination)] : []),
132
+ '--color=always',
133
+ ],
134
+ npmPath,
135
+ spawnOptions: {
136
+ captureOutput: true,
137
+ cwd: path.resolve(workDir),
138
+ pipeOutput: true,
139
+ stdio: 'pipe',
140
+ },
112
141
  });
113
142
  return path.resolve(destination || '.', stdout.trim());
114
143
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "build-strap",
3
- "version": "4.0.0-dev.3",
3
+ "version": "4.0.0-dev.4",
4
4
  "description": "Node scripts for building things",
5
5
  "license": "MIT",
6
6
  "authors": [
package/yarn.d.ts CHANGED
@@ -37,7 +37,7 @@ export interface YarnPublishOptions {
37
37
  }
38
38
  export declare function yarnPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, publishPath, skipExisting, tag, workDir: passedWorkDir, }?: YarnPublishOptions): Promise<boolean>;
39
39
  interface YarnPackOptions {
40
- destination?: string;
40
+ destination: string;
41
41
  workDir?: string;
42
42
  }
43
43
  export declare function yarnPack({ destination, workDir, }: YarnPackOptions): Promise<string>;
package/yarn.js CHANGED
@@ -115,6 +115,8 @@ export async function yarnPublish({ npmAuthToken, npmConfig, npmCreds, npmPath,
115
115
  args: [
116
116
  'publish',
117
117
  resolvedPath,
118
+ '--new-version',
119
+ npmVersion,
118
120
  '--tag',
119
121
  tag ||
120
122
  (isRelease
@@ -138,24 +140,16 @@ export async function yarnPublish({ npmAuthToken, npmConfig, npmCreds, npmPath,
138
140
  return true;
139
141
  }
140
142
  export async function yarnPack({ destination, workDir = '.', }) {
141
- if (destination) {
142
- await fs.ensureDir(destination);
143
- }
144
- const { stdout } = await yarn({
145
- args: [
146
- 'pack',
147
- ...(destination ? ['--filename', path.resolve(destination)] : []),
148
- ],
143
+ await fs.ensureDir(destination);
144
+ const version = await getVersion();
145
+ const name = getPkgName();
146
+ const filename = path.resolve(destination, `${name}-${version.npm}.tgz`);
147
+ await yarn({
148
+ args: ['pack', ...(destination ? ['--filename', filename] : [])],
149
149
  spawnOptions: {
150
- captureOutput: true,
151
150
  cwd: path.resolve(workDir),
152
- env: {
153
- ...process.env,
154
- FORCE_COLOR: 'true',
155
- },
156
151
  pipeOutput: true,
157
152
  },
158
153
  });
159
- console.log({ stdout });
160
- return path.resolve(destination || '.', stdout.trim());
154
+ return filename;
161
155
  }