build-strap 4.0.0 → 4.0.1
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 +7 -57
- package/{dist/src → src}/ant.d.ts +0 -0
- package/{dist/src → src}/ant.js +0 -0
- package/{dist/src → src}/cert.d.ts +0 -0
- package/{dist/src → src}/cert.js +0 -0
- package/{dist/src → src}/clean.d.ts +0 -0
- package/{dist/src → src}/clean.js +0 -0
- package/{dist/src → src}/copy.d.ts +0 -0
- package/{dist/src → src}/copy.js +0 -0
- package/{dist/src → src}/cp.d.ts +0 -0
- package/{dist/src → src}/cp.js +0 -0
- package/{dist/src → src}/docker.container.d.ts +0 -0
- package/{dist/src → src}/docker.container.js +0 -0
- package/{dist/src → src}/docker.d.ts +0 -0
- package/{dist/src → src}/docker.js +0 -0
- package/{dist/src → src}/docker.network.d.ts +0 -0
- package/{dist/src → src}/docker.network.js +0 -0
- package/{dist/src → src}/docker.volume.d.ts +0 -0
- package/{dist/src → src}/docker.volume.js +0 -0
- package/{dist/src → src}/dockerCleanup.d.ts +0 -0
- package/{dist/src → src}/dockerCleanup.js +0 -0
- package/{dist/src → src}/dockerCompose.d.ts +0 -0
- package/{dist/src → src}/dockerCompose.js +0 -0
- package/{dist/src → src}/fs.d.ts +0 -0
- package/{dist/src → src}/fs.js +0 -0
- package/{dist/src → src}/git.d.ts +0 -0
- package/{dist/src → src}/git.js +0 -0
- package/{dist/src → src}/index.d.ts +0 -0
- package/{dist/src → src}/index.js +0 -0
- package/{dist/src → src}/maps.d.ts +0 -0
- package/{dist/src → src}/maps.js +0 -0
- package/{dist/src → src}/npm.d.ts +16 -3
- package/src/npm.js +141 -0
- package/{dist/src → src}/pkg.d.ts +6 -1
- package/{dist/src → src}/pkg.js +0 -0
- package/{dist/src → src}/publish.d.ts +0 -0
- package/{dist/src → src}/publish.js +0 -0
- package/{dist/src → src}/run.d.ts +0 -0
- package/{dist/src → src}/run.js +0 -0
- package/{dist/src → src}/tgz.d.ts +0 -0
- package/{dist/src → src}/tgz.js +0 -0
- package/{dist/src → src}/version.d.ts +0 -0
- package/{dist/src → src}/version.js +1 -1
- package/{dist/src → src}/yarn.d.ts +18 -0
- package/src/yarn.js +155 -0
- package/dist/src/npm.js +0 -104
- package/dist/src/yarn.js +0 -75
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "build-strap",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Node scripts for building things",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"authors": [
|
|
@@ -11,26 +11,11 @@
|
|
|
11
11
|
"url": "https://github.com/murrayju/build-strap"
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
|
-
"
|
|
15
|
-
"types": "
|
|
14
|
+
"main": "./src/index.js",
|
|
15
|
+
"types": "./src/index.d.ts",
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=16"
|
|
18
18
|
},
|
|
19
|
-
"buildStrap": {
|
|
20
|
-
"nodeVersion": "16.13.1",
|
|
21
|
-
"yarnVersion": "1.22.17",
|
|
22
|
-
"repoType": "git",
|
|
23
|
-
"copyright": "Justin Murray",
|
|
24
|
-
"releaseBranch": "master",
|
|
25
|
-
"devBranch": "dev",
|
|
26
|
-
"npm": {
|
|
27
|
-
"publish": true
|
|
28
|
-
},
|
|
29
|
-
"docker": {
|
|
30
|
-
"repository": "murrayju",
|
|
31
|
-
"registry": "ghcr.io"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
19
|
"dependencies": {
|
|
35
20
|
"bytes": "^3.1.1",
|
|
36
21
|
"chokidar": "^3.5.2",
|
|
@@ -43,43 +28,8 @@
|
|
|
43
28
|
"lodash-es": "^4.17.21",
|
|
44
29
|
"moment": "^2.29.1",
|
|
45
30
|
"node-fetch": "^3.1.0",
|
|
31
|
+
"rimraf": "^3.0.2",
|
|
46
32
|
"stream-counter": "1",
|
|
47
|
-
"tar": "^6.1.11"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"devDependencies": {
|
|
51
|
-
"@tsconfig/node16": "^1.0.2",
|
|
52
|
-
"@types/bytes": "^3.1.1",
|
|
53
|
-
"@types/cross-spawn": "^6.0.2",
|
|
54
|
-
"@types/eslint": "^8.2.1",
|
|
55
|
-
"@types/fs-extra": "^9.0.13",
|
|
56
|
-
"@types/glob": "^7.2.0",
|
|
57
|
-
"@types/js-yaml": "^4.0.5",
|
|
58
|
-
"@types/lodash-es": "^4.17.5",
|
|
59
|
-
"@types/rimraf": "^3.0.2",
|
|
60
|
-
"@types/tar": "^6.1.1",
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
|
62
|
-
"@typescript-eslint/parser": "^5.8.0",
|
|
63
|
-
"camelcase": "^6.2.0",
|
|
64
|
-
"eslint": "^8.5.0",
|
|
65
|
-
"eslint-config-airbnb-base": "^15.0.0",
|
|
66
|
-
"eslint-config-prettier": "^8.3.0",
|
|
67
|
-
"eslint-import-resolver-node": "^0.3.6",
|
|
68
|
-
"eslint-plugin-import": "^2.22.1",
|
|
69
|
-
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
70
|
-
"eslint-plugin-prettier": "^4.0.0",
|
|
71
|
-
"eslint-plugin-react": "^7.22.0",
|
|
72
|
-
"eslint-plugin-sort-destructure-keys": "^1.4.0",
|
|
73
|
-
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
74
|
-
"eslint-plugin-typescript-sort-keys": "^2.1.0",
|
|
75
|
-
"prettier": "^2.2.1",
|
|
76
|
-
"ts-node": "^10.4.0",
|
|
77
|
-
"typescript": "^4.5.4"
|
|
78
|
-
},
|
|
79
|
-
"scripts": {
|
|
80
|
-
"target": "node --loader ts-node/esm ./targets/run.ts"
|
|
81
|
-
},
|
|
82
|
-
"files": [
|
|
83
|
-
"dist/src"
|
|
84
|
-
]
|
|
85
|
-
}
|
|
33
|
+
"tar": "^6.1.11"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
File without changes
|
package/{dist/src → src}/ant.js
RENAMED
|
File without changes
|
|
File without changes
|
package/{dist/src → src}/cert.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/{dist/src → src}/copy.js
RENAMED
|
File without changes
|
package/{dist/src → src}/cp.d.ts
RENAMED
|
File without changes
|
package/{dist/src → src}/cp.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/{dist/src → src}/fs.d.ts
RENAMED
|
File without changes
|
package/{dist/src → src}/fs.js
RENAMED
|
File without changes
|
|
File without changes
|
package/{dist/src → src}/git.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/{dist/src → src}/maps.js
RENAMED
|
File without changes
|
|
@@ -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;
|
|
@@ -11,8 +12,21 @@ export declare type NpmConfig = {
|
|
|
11
12
|
registry?: string;
|
|
12
13
|
};
|
|
13
14
|
export declare function getNpmConfig(): NpmConfig;
|
|
14
|
-
export declare
|
|
15
|
+
export declare const envNpmCreds: null | NpmCreds;
|
|
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>;
|
|
15
22
|
export declare function npmGetVersions(packageName: string, npmPath?: string): Promise<string[]>;
|
|
23
|
+
interface NpmWriteRcOptions {
|
|
24
|
+
authToken?: string;
|
|
25
|
+
creds?: NpmCreds | null;
|
|
26
|
+
outPath: string;
|
|
27
|
+
registry?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function npmWriteRc({ authToken, creds, outPath, registry, }: NpmWriteRcOptions): Promise<void>;
|
|
16
30
|
export interface NpmPublishOptions {
|
|
17
31
|
npmAuthToken?: string;
|
|
18
32
|
npmConfig?: NpmConfig;
|
|
@@ -22,9 +36,8 @@ export interface NpmPublishOptions {
|
|
|
22
36
|
skipExisting?: boolean;
|
|
23
37
|
tag?: string;
|
|
24
38
|
workDir?: string;
|
|
25
|
-
writeNpmrc?: boolean;
|
|
26
39
|
}
|
|
27
|
-
export declare function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, publishPath, skipExisting, tag, workDir: passedWorkDir,
|
|
40
|
+
export declare function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, publishPath, skipExisting, tag, workDir: passedWorkDir, }?: NpmPublishOptions): Promise<boolean>;
|
|
28
41
|
interface NpmPackOptions {
|
|
29
42
|
destination?: string;
|
|
30
43
|
npmConfig?: NpmConfig;
|
package/src/npm.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import { platform } from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { spawn } from './cp.js';
|
|
5
|
+
import { getCfg, getPkgName } from './pkg.js';
|
|
6
|
+
import { buildLog } from './run.js';
|
|
7
|
+
import { getDevBranch, getVersion } from './version.js';
|
|
8
|
+
export function getNpmConfig() {
|
|
9
|
+
return getCfg().npm || {};
|
|
10
|
+
}
|
|
11
|
+
export const envNpmCreds = (process.env.NPM_CREDS && JSON.parse(process.env.NPM_CREDS)) || null;
|
|
12
|
+
const npmExe = (npmPath) => npmPath || (platform() === 'win32' ? 'npm.cmd' : 'npm');
|
|
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);
|
|
28
|
+
}
|
|
29
|
+
export async function npmGetVersions(packageName, npmPath) {
|
|
30
|
+
try {
|
|
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());
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
buildLog(`warning: failed to find existing package for ${packageName} in npm registry: ${err.message}`);
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export async function npmWriteRc({ authToken, creds, outPath, registry, }) {
|
|
46
|
+
// Write out .npmrc with credentials
|
|
47
|
+
const theRegistry = registry || 'https://registry.npmjs.org/';
|
|
48
|
+
const [, host] = /^(?:http(?:s)?:\/\/)?(.+)$/.exec(theRegistry) || [];
|
|
49
|
+
await fs.mkdirp(path.dirname(outPath));
|
|
50
|
+
await fs.writeFile(outPath, `registry=${theRegistry}
|
|
51
|
+
${authToken ? `//${host}:_authToken=${authToken}` : ''}
|
|
52
|
+
${creds
|
|
53
|
+
? `_auth=${Buffer.from(`${creds.username}:${creds.password}`).toString('base64')}
|
|
54
|
+
always-auth=true
|
|
55
|
+
email=${creds.email}`
|
|
56
|
+
: ''}`);
|
|
57
|
+
}
|
|
58
|
+
export async function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, publishPath = '.', skipExisting = false, tag, workDir: passedWorkDir, } = {}) {
|
|
59
|
+
const creds = npmCreds || envNpmCreds;
|
|
60
|
+
const authToken = npmAuthToken || process.env.NPM_TOKEN;
|
|
61
|
+
const name = getPkgName();
|
|
62
|
+
const { access, dryRun, publish, registry } = npmConfig || getNpmConfig();
|
|
63
|
+
if (!publish) {
|
|
64
|
+
buildLog('npm publish info missing from package.json, skipping npm publish');
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const resolvedPath = path.resolve(publishPath);
|
|
68
|
+
const workDir = passedWorkDir ||
|
|
69
|
+
((await fs.stat(resolvedPath)).isDirectory()
|
|
70
|
+
? resolvedPath
|
|
71
|
+
: path.dirname(resolvedPath));
|
|
72
|
+
if (!(await fs.pathExists(path.join(workDir, 'package.json')))) {
|
|
73
|
+
buildLog(`warning: no package.json found in ${workDir}, skipping npm publish`);
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if (creds || registry || authToken) {
|
|
77
|
+
// Write out .npmrc with credentials
|
|
78
|
+
await npmWriteRc({
|
|
79
|
+
authToken: authToken ? `\${NPM_TOKEN}` : undefined,
|
|
80
|
+
creds,
|
|
81
|
+
outPath: path.join(workDir, '.npmrc'),
|
|
82
|
+
registry,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const existing = await npmGetVersions(name, npmPath);
|
|
86
|
+
const { branch, isRelease, npm: npmVersion } = await getVersion();
|
|
87
|
+
if (existing.includes(npmVersion)) {
|
|
88
|
+
if (skipExisting) {
|
|
89
|
+
buildLog('npm package with this same version already exists. Skipping publish...');
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
throw new Error('Failed to publish npm package, this version already exists!');
|
|
93
|
+
}
|
|
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
|
+
},
|
|
117
|
+
});
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
export async function npmPack({ destination, npmConfig, npmPath, workDir = '.', }) {
|
|
121
|
+
const { dryRun } = npmConfig || getNpmConfig();
|
|
122
|
+
if (destination) {
|
|
123
|
+
await fs.ensureDir(destination);
|
|
124
|
+
}
|
|
125
|
+
const { stdout } = await npm({
|
|
126
|
+
args: [
|
|
127
|
+
'pack',
|
|
128
|
+
...(dryRun ? ['--dry-run'] : []),
|
|
129
|
+
...(destination ? ['--pack-destination', path.resolve(destination)] : []),
|
|
130
|
+
'--color=always',
|
|
131
|
+
],
|
|
132
|
+
npmPath,
|
|
133
|
+
spawnOptions: {
|
|
134
|
+
captureOutput: true,
|
|
135
|
+
cwd: path.resolve(workDir),
|
|
136
|
+
pipeOutput: true,
|
|
137
|
+
stdio: 'pipe',
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
return path.resolve(destination || '.', stdout.trim());
|
|
141
|
+
}
|
|
@@ -22,8 +22,13 @@ export interface PackageJson {
|
|
|
22
22
|
name: string;
|
|
23
23
|
peerDependencies?: Record<string, string>;
|
|
24
24
|
private?: boolean;
|
|
25
|
-
repository?: string
|
|
25
|
+
repository?: string | {
|
|
26
|
+
type: string;
|
|
27
|
+
url: string;
|
|
28
|
+
};
|
|
26
29
|
scripts?: Record<string, string>;
|
|
30
|
+
type?: string;
|
|
31
|
+
types?: string;
|
|
27
32
|
version: string;
|
|
28
33
|
}
|
|
29
34
|
export declare function getPkg(): PackageJson;
|
package/{dist/src → src}/pkg.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/{dist/src → src}/run.js
RENAMED
|
File without changes
|
|
File without changes
|
package/{dist/src → src}/tgz.js
RENAMED
|
File without changes
|
|
File without changes
|
|
@@ -38,7 +38,7 @@ export async function getRepoInfo() {
|
|
|
38
38
|
}
|
|
39
39
|
export async function getDevBranch() {
|
|
40
40
|
const { devBranch } = getCfg();
|
|
41
|
-
return devBranch || (await getRepoType()) === 'hg' ? 'default' : 'dev';
|
|
41
|
+
return devBranch || ((await getRepoType()) === 'hg' ? 'default' : 'dev');
|
|
42
42
|
}
|
|
43
43
|
export async function getIsRelease(passedBranch = null, releaseOverride = null) {
|
|
44
44
|
const branch = passedBranch || (await getRepoInfo()).branch;
|
|
@@ -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/src/yarn.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { spawn } from './cp.js';
|
|
4
|
+
import { readDir } from './fs.js';
|
|
5
|
+
import { envNpmCreds, getNpmConfig, npmGetVersions, npmWriteRc, } from './npm.js';
|
|
6
|
+
import { getPkg, getPkgName } from './pkg.js';
|
|
7
|
+
import { buildLog } from './run.js';
|
|
8
|
+
import { generateFileHash } from './tgz.js';
|
|
9
|
+
import { getDevBranch, getVersion } from './version.js';
|
|
10
|
+
export async function yarn({ args = [], spawnOptions, } = {}) {
|
|
11
|
+
const localYarn = path.join(path.dirname(process.execPath), '/node_modules/yarn/bin/yarn.js');
|
|
12
|
+
const spawnOpts = {
|
|
13
|
+
env: process.env,
|
|
14
|
+
shell: true,
|
|
15
|
+
stdio: 'inherit',
|
|
16
|
+
...spawnOptions,
|
|
17
|
+
};
|
|
18
|
+
return (await fs.pathExists(localYarn))
|
|
19
|
+
? // prefer to use local copy of yarn
|
|
20
|
+
spawn(process.execPath, [localYarn, ...args], spawnOpts)
|
|
21
|
+
: // fall back to globally installed yarn
|
|
22
|
+
spawn('yarn', args, spawnOpts);
|
|
23
|
+
}
|
|
24
|
+
export const yarnFiles = ['./package.json', './yarn.lock'];
|
|
25
|
+
// Smart yarn invocation, only if package changed
|
|
26
|
+
export async function yarnInstall({ force = false, hashFilePath = './download/buildHash_yarn.md5', nodeModulesPath = './node_modules', } = {}) {
|
|
27
|
+
await fs.ensureDir(nodeModulesPath);
|
|
28
|
+
const currentHash = (await Promise.all(yarnFiles.map(async (f) => generateFileHash(f, 'md5')))).join('|');
|
|
29
|
+
await fs.ensureFile(hashFilePath);
|
|
30
|
+
const prevHash = await fs.readFile(hashFilePath, 'utf8');
|
|
31
|
+
if (currentHash !== prevHash) {
|
|
32
|
+
buildLog('node package definition changed since last build, invoking yarn.');
|
|
33
|
+
}
|
|
34
|
+
else if (!(await readDir(`${nodeModulesPath}/**/*.js`)).length) {
|
|
35
|
+
buildLog('node packages missing, invoking yarn.');
|
|
36
|
+
}
|
|
37
|
+
else if (force) {
|
|
38
|
+
buildLog('node packages unchanged, but yarn forced on command line...');
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
buildLog('node packages unchanged since last build, skipping yarn.');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
await yarn();
|
|
45
|
+
await fs.writeFile(hashFilePath, currentHash);
|
|
46
|
+
}
|
|
47
|
+
export async function yarnUpgrade({ all = false, outdated = false, } = {}) {
|
|
48
|
+
if (outdated) {
|
|
49
|
+
const { code, stdout } = await yarn({
|
|
50
|
+
args: ['outdated'],
|
|
51
|
+
spawnOptions: {
|
|
52
|
+
captureOutput: true,
|
|
53
|
+
rejectOnErrorCode: false,
|
|
54
|
+
stdio: 'pipe',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
if (code === 0) {
|
|
58
|
+
buildLog('No outdated packages.');
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const { dependencies = {}, devDependencies = {} } = getPkg();
|
|
62
|
+
const packages = stdout
|
|
63
|
+
.split('\n')
|
|
64
|
+
.slice(5, -1)
|
|
65
|
+
.map((l) => l.split(/\s+/)[0])
|
|
66
|
+
.filter((p) => all || !/^\d/.test(dependencies[p] || devDependencies[p] || ''));
|
|
67
|
+
if (packages.length) {
|
|
68
|
+
await yarn({ args: ['add', ...packages] });
|
|
69
|
+
buildLog(`Upgraded: ${packages.join(', ')}`);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
buildLog('No eligible outdated packages');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
await yarn({ args: ['upgrade'] });
|
|
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
|
+
'--new-version',
|
|
119
|
+
npmVersion,
|
|
120
|
+
'--tag',
|
|
121
|
+
tag ||
|
|
122
|
+
(isRelease
|
|
123
|
+
? 'latest'
|
|
124
|
+
: branch === (await getDevBranch())
|
|
125
|
+
? 'next'
|
|
126
|
+
: 'branch'),
|
|
127
|
+
...(access ? ['--access', access] : []),
|
|
128
|
+
],
|
|
129
|
+
spawnOptions: {
|
|
130
|
+
cwd: workDir,
|
|
131
|
+
env: {
|
|
132
|
+
...process.env,
|
|
133
|
+
FORCE_COLOR: 'true',
|
|
134
|
+
NPM_TOKEN: authToken,
|
|
135
|
+
},
|
|
136
|
+
shell: true,
|
|
137
|
+
stdio: 'inherit',
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
export async function yarnPack({ destination, workDir = '.', }) {
|
|
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
|
+
spawnOptions: {
|
|
150
|
+
cwd: path.resolve(workDir),
|
|
151
|
+
pipeOutput: true,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
return filename;
|
|
155
|
+
}
|
package/dist/src/npm.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import { platform } from 'os';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { exec, spawn } from './cp.js';
|
|
5
|
-
import { getCfg, getPkgName } from './pkg.js';
|
|
6
|
-
import { buildLog } from './run.js';
|
|
7
|
-
import { getDevBranch, getVersion } from './version.js';
|
|
8
|
-
export function getNpmConfig() {
|
|
9
|
-
return getCfg().npm || {};
|
|
10
|
-
}
|
|
11
|
-
const envNpmCreds = (process.env.NPM_CREDS && JSON.parse(process.env.NPM_CREDS)) || null;
|
|
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();
|
|
15
|
-
}
|
|
16
|
-
export async function npmGetVersions(packageName, npmPath) {
|
|
17
|
-
try {
|
|
18
|
-
return JSON.parse(await npmExec(['show', packageName, 'versions'], npmPath));
|
|
19
|
-
}
|
|
20
|
-
catch (err) {
|
|
21
|
-
buildLog(`warning: failed to find existing package for ${packageName} in npm registry: ${err.message}`);
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export async function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, publishPath = '.', skipExisting = false, tag, workDir: passedWorkDir, writeNpmrc = false, } = {}) {
|
|
26
|
-
const creds = npmCreds || envNpmCreds;
|
|
27
|
-
const authToken = npmAuthToken || process.env.NPM_TOKEN;
|
|
28
|
-
const name = getPkgName();
|
|
29
|
-
const { access, dryRun, publish, registry } = npmConfig || getNpmConfig();
|
|
30
|
-
if (!publish) {
|
|
31
|
-
buildLog('npm publish info missing from package.json, skipping npm publish');
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
const resolvedPath = path.resolve(publishPath);
|
|
35
|
-
const workDir = passedWorkDir ||
|
|
36
|
-
((await fs.stat(resolvedPath)).isDirectory()
|
|
37
|
-
? resolvedPath
|
|
38
|
-
: path.dirname(resolvedPath));
|
|
39
|
-
if (!(await fs.pathExists(path.join(workDir, 'package.json')))) {
|
|
40
|
-
buildLog(`warning: no package.json found in ${workDir}, skipping npm publish`);
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
if (writeNpmrc && (creds || registry || authToken)) {
|
|
44
|
-
// Write out .npmrc with credentials
|
|
45
|
-
const theRegistry = registry || 'https://registry.npmjs.org/';
|
|
46
|
-
const [, host] = /^(?:http(?:s)?:\/\/)?(.+)$/.exec(theRegistry) || [];
|
|
47
|
-
await fs.mkdirp(workDir);
|
|
48
|
-
await fs.writeFile(path.join(workDir, '.npmrc'), `registry=${theRegistry}
|
|
49
|
-
${authToken ? `//${host}:_authToken=${authToken}` : ''}
|
|
50
|
-
${creds
|
|
51
|
-
? `_auth=${Buffer.from(`${creds.username}:${creds.password}`).toString('base64')}
|
|
52
|
-
always-auth=true
|
|
53
|
-
email=${creds.email}`
|
|
54
|
-
: ''}`);
|
|
55
|
-
}
|
|
56
|
-
const existing = await npmGetVersions(name, npmPath);
|
|
57
|
-
const { branch, isRelease, npm: npmVersion } = await getVersion();
|
|
58
|
-
if (existing.includes(npmVersion)) {
|
|
59
|
-
if (skipExisting) {
|
|
60
|
-
buildLog('npm package with this same version already exists. Skipping publish...');
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
throw new Error('Failed to publish npm package, this version already exists!');
|
|
64
|
-
}
|
|
65
|
-
await spawn(npmExe(npmPath), [
|
|
66
|
-
'publish',
|
|
67
|
-
resolvedPath,
|
|
68
|
-
'--tag',
|
|
69
|
-
tag ||
|
|
70
|
-
(isRelease
|
|
71
|
-
? 'latest'
|
|
72
|
-
: branch === (await getDevBranch())
|
|
73
|
-
? 'next'
|
|
74
|
-
: 'branch'),
|
|
75
|
-
...(access ? ['--access', access] : []),
|
|
76
|
-
...(dryRun ? ['--dry-run'] : []),
|
|
77
|
-
'--color=always',
|
|
78
|
-
], {
|
|
79
|
-
cwd: workDir,
|
|
80
|
-
env: {
|
|
81
|
-
...process.env,
|
|
82
|
-
NPM_TOKEN: authToken,
|
|
83
|
-
},
|
|
84
|
-
stdio: 'inherit',
|
|
85
|
-
});
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
export async function npmPack({ destination, npmConfig, npmPath, workDir = '.', }) {
|
|
89
|
-
const { dryRun } = npmConfig || getNpmConfig();
|
|
90
|
-
if (destination) {
|
|
91
|
-
await fs.ensureDir(destination);
|
|
92
|
-
}
|
|
93
|
-
const { stdout } = await spawn(npmExe(npmPath), [
|
|
94
|
-
'pack',
|
|
95
|
-
...(dryRun ? ['--dry-run'] : []),
|
|
96
|
-
...(destination ? ['--pack-destination', destination] : []),
|
|
97
|
-
'--color=always',
|
|
98
|
-
], {
|
|
99
|
-
captureOutput: true,
|
|
100
|
-
cwd: workDir,
|
|
101
|
-
pipeOutput: true,
|
|
102
|
-
});
|
|
103
|
-
return path.resolve(destination || '.', stdout.trim());
|
|
104
|
-
}
|
package/dist/src/yarn.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { spawn } from './cp.js';
|
|
4
|
-
import { readDir } from './fs.js';
|
|
5
|
-
import { getPkg } from './pkg.js';
|
|
6
|
-
import { buildLog } from './run.js';
|
|
7
|
-
import { generateFileHash } from './tgz.js';
|
|
8
|
-
export async function yarn({ args = [], spawnOptions, } = {}) {
|
|
9
|
-
const localYarn = path.join(path.dirname(process.execPath), '/node_modules/yarn/bin/yarn.js');
|
|
10
|
-
const spawnOpts = {
|
|
11
|
-
env: process.env,
|
|
12
|
-
shell: true,
|
|
13
|
-
stdio: 'inherit',
|
|
14
|
-
...spawnOptions,
|
|
15
|
-
};
|
|
16
|
-
return (await fs.pathExists(localYarn))
|
|
17
|
-
? // prefer to use local copy of yarn
|
|
18
|
-
spawn(process.execPath, [localYarn, ...args], spawnOpts)
|
|
19
|
-
: // fall back to globally installed yarn
|
|
20
|
-
spawn('yarn', args, spawnOpts);
|
|
21
|
-
}
|
|
22
|
-
export const yarnFiles = ['./package.json', './yarn.lock'];
|
|
23
|
-
// Smart yarn invocation, only if package changed
|
|
24
|
-
export async function yarnInstall({ force = false, hashFilePath = './download/buildHash_yarn.md5', nodeModulesPath = './node_modules', } = {}) {
|
|
25
|
-
await fs.ensureDir(nodeModulesPath);
|
|
26
|
-
const currentHash = (await Promise.all(yarnFiles.map(async (f) => generateFileHash(f, 'md5')))).join('|');
|
|
27
|
-
await fs.ensureFile(hashFilePath);
|
|
28
|
-
const prevHash = await fs.readFile(hashFilePath, 'utf8');
|
|
29
|
-
if (currentHash !== prevHash) {
|
|
30
|
-
buildLog('node package definition changed since last build, invoking yarn.');
|
|
31
|
-
}
|
|
32
|
-
else if (!(await readDir(`${nodeModulesPath}/**/*.js`)).length) {
|
|
33
|
-
buildLog('node packages missing, invoking yarn.');
|
|
34
|
-
}
|
|
35
|
-
else if (force) {
|
|
36
|
-
buildLog('node packages unchanged, but yarn forced on command line...');
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
buildLog('node packages unchanged since last build, skipping yarn.');
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
await yarn();
|
|
43
|
-
await fs.writeFile(hashFilePath, currentHash);
|
|
44
|
-
}
|
|
45
|
-
export async function yarnUpgrade({ all = false, outdated = false, } = {}) {
|
|
46
|
-
if (outdated) {
|
|
47
|
-
const { code, stdout } = await yarn({
|
|
48
|
-
args: ['outdated'],
|
|
49
|
-
spawnOptions: {
|
|
50
|
-
captureOutput: true,
|
|
51
|
-
rejectOnErrorCode: false,
|
|
52
|
-
stdio: 'pipe',
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
if (code === 0) {
|
|
56
|
-
buildLog('No outdated packages.');
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
const { dependencies = {}, devDependencies = {} } = getPkg();
|
|
60
|
-
const packages = stdout
|
|
61
|
-
.split('\n')
|
|
62
|
-
.slice(5, -1)
|
|
63
|
-
.map((l) => l.split(/\s+/)[0])
|
|
64
|
-
.filter((p) => all || !/^\d/.test(dependencies[p] || devDependencies[p] || ''));
|
|
65
|
-
if (packages.length) {
|
|
66
|
-
await yarn({ args: ['add', ...packages] });
|
|
67
|
-
buildLog(`Upgraded: ${packages.join(', ')}`);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
buildLog('No eligible outdated packages');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
await yarn({ args: ['upgrade'] });
|
|
75
|
-
}
|