build-strap 4.0.0-dev.2 → 4.0.0-dev.3
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 +8 -0
- package/npm.js +21 -11
- package/package.json +1 -1
- package/yarn.d.ts +18 -0
- package/yarn.js +87 -1
package/npm.d.ts
CHANGED
|
@@ -11,8 +11,16 @@ export declare type NpmConfig = {
|
|
|
11
11
|
registry?: string;
|
|
12
12
|
};
|
|
13
13
|
export declare function getNpmConfig(): NpmConfig;
|
|
14
|
+
export declare const envNpmCreds: null | NpmCreds;
|
|
14
15
|
export declare function npmExec(args: string[], npmPath?: string): Promise<string>;
|
|
15
16
|
export declare function npmGetVersions(packageName: string, npmPath?: string): Promise<string[]>;
|
|
17
|
+
interface NpmWriteRcOptions {
|
|
18
|
+
authToken?: string;
|
|
19
|
+
creds?: NpmCreds | null;
|
|
20
|
+
outPath: string;
|
|
21
|
+
registry?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function npmWriteRc({ authToken, creds, outPath, registry, }: NpmWriteRcOptions): Promise<void>;
|
|
16
24
|
export interface NpmPublishOptions {
|
|
17
25
|
npmAuthToken?: string;
|
|
18
26
|
npmConfig?: NpmConfig;
|
package/npm.js
CHANGED
|
@@ -8,7 +8,7 @@ import { getDevBranch, getVersion } from './version.js';
|
|
|
8
8
|
export function getNpmConfig() {
|
|
9
9
|
return getCfg().npm || {};
|
|
10
10
|
}
|
|
11
|
-
const envNpmCreds = (process.env.NPM_CREDS && JSON.parse(process.env.NPM_CREDS)) || null;
|
|
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
13
|
export async function npmExec(args, npmPath) {
|
|
14
14
|
return (await exec(`${npmExe(npmPath)} ${args.join(' ')}`)).stdout.toString();
|
|
@@ -22,6 +22,19 @@ export async function npmGetVersions(packageName, npmPath) {
|
|
|
22
22
|
return [];
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
export async function npmWriteRc({ authToken, creds, outPath, registry, }) {
|
|
26
|
+
// Write out .npmrc with credentials
|
|
27
|
+
const theRegistry = registry || 'https://registry.npmjs.org/';
|
|
28
|
+
const [, host] = /^(?:http(?:s)?:\/\/)?(.+)$/.exec(theRegistry) || [];
|
|
29
|
+
await fs.mkdirp(path.dirname(outPath));
|
|
30
|
+
await fs.writeFile(outPath, `registry=${theRegistry}
|
|
31
|
+
${authToken ? `//${host}:_authToken=${authToken}` : ''}
|
|
32
|
+
${creds
|
|
33
|
+
? `_auth=${Buffer.from(`${creds.username}:${creds.password}`).toString('base64')}
|
|
34
|
+
always-auth=true
|
|
35
|
+
email=${creds.email}`
|
|
36
|
+
: ''}`);
|
|
37
|
+
}
|
|
25
38
|
export async function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, publishPath = '.', skipExisting = false, tag, workDir: passedWorkDir, } = {}) {
|
|
26
39
|
const creds = npmCreds || envNpmCreds;
|
|
27
40
|
const authToken = npmAuthToken || process.env.NPM_TOKEN;
|
|
@@ -42,16 +55,12 @@ export async function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, p
|
|
|
42
55
|
}
|
|
43
56
|
if (creds || registry || authToken) {
|
|
44
57
|
// Write out .npmrc with credentials
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
? `_auth=${Buffer.from(`${creds.username}:${creds.password}`).toString('base64')}
|
|
52
|
-
always-auth=true
|
|
53
|
-
email=${creds.email}`
|
|
54
|
-
: ''}`);
|
|
58
|
+
await npmWriteRc({
|
|
59
|
+
authToken: authToken ? `\${NPM_TOKEN}` : undefined,
|
|
60
|
+
creds,
|
|
61
|
+
outPath: path.join(workDir, '.npmrc'),
|
|
62
|
+
registry,
|
|
63
|
+
});
|
|
55
64
|
}
|
|
56
65
|
const existing = await npmGetVersions(name, npmPath);
|
|
57
66
|
const { branch, isRelease, npm: npmVersion } = await getVersion();
|
|
@@ -81,6 +90,7 @@ email=${creds.email}`
|
|
|
81
90
|
...process.env,
|
|
82
91
|
NPM_TOKEN: authToken,
|
|
83
92
|
},
|
|
93
|
+
shell: true,
|
|
84
94
|
stdio: 'inherit',
|
|
85
95
|
});
|
|
86
96
|
return true;
|
package/package.json
CHANGED
package/yarn.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SpawnOptions, SpawnResult } from './cp.js';
|
|
2
|
+
import { NpmConfig, NpmCreds } from './npm.js';
|
|
2
3
|
export interface YarnOptions {
|
|
3
4
|
args?: string[];
|
|
4
5
|
spawnOptions?: SpawnOptions;
|
|
@@ -24,3 +25,20 @@ export interface YarnUpgradeOptions {
|
|
|
24
25
|
outdated?: boolean;
|
|
25
26
|
}
|
|
26
27
|
export declare function yarnUpgrade({ all, outdated, }?: YarnUpgradeOptions): Promise<void>;
|
|
28
|
+
export interface YarnPublishOptions {
|
|
29
|
+
npmAuthToken?: string;
|
|
30
|
+
npmConfig?: NpmConfig;
|
|
31
|
+
npmCreds?: NpmCreds;
|
|
32
|
+
npmPath?: string;
|
|
33
|
+
publishPath?: string;
|
|
34
|
+
skipExisting?: boolean;
|
|
35
|
+
tag?: string;
|
|
36
|
+
workDir?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare function yarnPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, publishPath, skipExisting, tag, workDir: passedWorkDir, }?: YarnPublishOptions): Promise<boolean>;
|
|
39
|
+
interface YarnPackOptions {
|
|
40
|
+
destination?: string;
|
|
41
|
+
workDir?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function yarnPack({ destination, workDir, }: YarnPackOptions): Promise<string>;
|
|
44
|
+
export {};
|
package/yarn.js
CHANGED
|
@@ -2,9 +2,11 @@ import fs from 'fs-extra';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { spawn } from './cp.js';
|
|
4
4
|
import { readDir } from './fs.js';
|
|
5
|
-
import {
|
|
5
|
+
import { envNpmCreds, getNpmConfig, npmGetVersions, npmWriteRc, } from './npm.js';
|
|
6
|
+
import { getPkg, getPkgName } from './pkg.js';
|
|
6
7
|
import { buildLog } from './run.js';
|
|
7
8
|
import { generateFileHash } from './tgz.js';
|
|
9
|
+
import { getDevBranch, getVersion } from './version.js';
|
|
8
10
|
export async function yarn({ args = [], spawnOptions, } = {}) {
|
|
9
11
|
const localYarn = path.join(path.dirname(process.execPath), '/node_modules/yarn/bin/yarn.js');
|
|
10
12
|
const spawnOpts = {
|
|
@@ -73,3 +75,87 @@ export async function yarnUpgrade({ all = false, outdated = false, } = {}) {
|
|
|
73
75
|
}
|
|
74
76
|
await yarn({ args: ['upgrade'] });
|
|
75
77
|
}
|
|
78
|
+
export async function yarnPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, publishPath = '.', skipExisting = false, tag, workDir: passedWorkDir, } = {}) {
|
|
79
|
+
const creds = npmCreds || envNpmCreds;
|
|
80
|
+
const authToken = npmAuthToken || process.env.NPM_TOKEN;
|
|
81
|
+
const name = getPkgName();
|
|
82
|
+
const { access, publish, registry } = npmConfig || getNpmConfig();
|
|
83
|
+
if (!publish) {
|
|
84
|
+
buildLog('npm publish info missing from package.json, skipping npm publish');
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
const resolvedPath = path.resolve(publishPath);
|
|
88
|
+
const workDir = passedWorkDir ||
|
|
89
|
+
((await fs.stat(resolvedPath)).isDirectory()
|
|
90
|
+
? resolvedPath
|
|
91
|
+
: path.dirname(resolvedPath));
|
|
92
|
+
if (!(await fs.pathExists(path.join(workDir, 'package.json')))) {
|
|
93
|
+
buildLog(`warning: no package.json found in ${workDir}, skipping npm publish`);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (creds || registry || authToken) {
|
|
97
|
+
// Write out .npmrc with credentials
|
|
98
|
+
await npmWriteRc({
|
|
99
|
+
authToken: authToken ? `\${NPM_TOKEN}` : undefined,
|
|
100
|
+
creds,
|
|
101
|
+
outPath: path.join(workDir, '.npmrc'),
|
|
102
|
+
registry,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const existing = await npmGetVersions(name, npmPath);
|
|
106
|
+
const { branch, isRelease, npm: npmVersion } = await getVersion();
|
|
107
|
+
if (existing.includes(npmVersion)) {
|
|
108
|
+
if (skipExisting) {
|
|
109
|
+
buildLog('npm package with this same version already exists. Skipping publish...');
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
throw new Error('Failed to publish npm package, this version already exists!');
|
|
113
|
+
}
|
|
114
|
+
await yarn({
|
|
115
|
+
args: [
|
|
116
|
+
'publish',
|
|
117
|
+
resolvedPath,
|
|
118
|
+
'--tag',
|
|
119
|
+
tag ||
|
|
120
|
+
(isRelease
|
|
121
|
+
? 'latest'
|
|
122
|
+
: branch === (await getDevBranch())
|
|
123
|
+
? 'next'
|
|
124
|
+
: 'branch'),
|
|
125
|
+
...(access ? ['--access', access] : []),
|
|
126
|
+
],
|
|
127
|
+
spawnOptions: {
|
|
128
|
+
cwd: workDir,
|
|
129
|
+
env: {
|
|
130
|
+
...process.env,
|
|
131
|
+
FORCE_COLOR: 'true',
|
|
132
|
+
NPM_TOKEN: authToken,
|
|
133
|
+
},
|
|
134
|
+
shell: true,
|
|
135
|
+
stdio: 'inherit',
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
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
|
+
],
|
|
149
|
+
spawnOptions: {
|
|
150
|
+
captureOutput: true,
|
|
151
|
+
cwd: path.resolve(workDir),
|
|
152
|
+
env: {
|
|
153
|
+
...process.env,
|
|
154
|
+
FORCE_COLOR: 'true',
|
|
155
|
+
},
|
|
156
|
+
pipeOutput: true,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
console.log({ stdout });
|
|
160
|
+
return path.resolve(destination || '.', stdout.trim());
|
|
161
|
+
}
|