@uirouter/publish-scripts 2.6.1 → 2.6.2
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/CHANGELOG.md +10 -4
- package/actions/upgrade/Dockerfile +7 -7
- package/actions/upgrade/action.yml +24 -24
- package/actions/upgrade/entrypoint.sh +3 -3
- package/actions/upgrade/package.json +8 -8
- package/actions/upgrade/upgrade.js +59 -59
- package/artifact_tagging.js +108 -108
- package/docgen/Dockerfile +14 -14
- package/docgen/clone.sh +10 -10
- package/docgen/docgen.sh +27 -27
- package/docgen/docker_push.sh +9 -9
- package/docgen/package.json +7 -7
- package/docgen/prep_docgen.js +58 -58
- package/docgen_via_docker.sh +3 -3
- package/ensure_clean_master.js +10 -10
- package/modify_sourcemap_paths.js +28 -28
- package/package.json +1 -1
- package/publish_docs.js +46 -46
- package/publish_yalc_package.js +117 -117
- package/release.js +164 -164
- package/show_changelog.js +142 -142
- package/show_version.js +110 -110
- package/test_downstream_projects.js +303 -303
- package/util.js +50 -50
|
@@ -1,303 +1,303 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const tmp = require('tmp');
|
|
5
|
-
const shelljs = require('shelljs');
|
|
6
|
-
const _ = require('lodash');
|
|
7
|
-
const isTravis = !!process.env.TRAVIS;
|
|
8
|
-
const isGithubActions = !!process.env.GITHUB_ACTIONS;
|
|
9
|
-
|
|
10
|
-
const yargs = require('yargs')
|
|
11
|
-
.option('group', {
|
|
12
|
-
alias: 'g',
|
|
13
|
-
default: 'all',
|
|
14
|
-
description: 'the group of projects to test (from downstream_projects.json "group" key)',
|
|
15
|
-
})
|
|
16
|
-
.option('workspace', {
|
|
17
|
-
alias: 'ws',
|
|
18
|
-
description: 'use yarn workspace to save space',
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const nodeCleanup = require('node-cleanup');
|
|
22
|
-
const publishYalcPackage = require('./publish_yalc_package');
|
|
23
|
-
const foldStart = (message) => {
|
|
24
|
-
isTravis && console.log('travis_fold:start:' + message.replace(/\s+/g, '.'));
|
|
25
|
-
isGithubActions && console.log('::group::' + message);
|
|
26
|
-
console.log(message);
|
|
27
|
-
return () => {
|
|
28
|
-
isTravis && console.log('travis_fold:end:' + message.replace(/\s+/g, '.'));
|
|
29
|
-
isGithubActions && console.log(message);
|
|
30
|
-
isGithubActions && console.log('::endgroup::');
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
let foldEnd = () => null;
|
|
34
|
-
|
|
35
|
-
const util = require('./util');
|
|
36
|
-
util.packageDir();
|
|
37
|
-
const PKG_DIR = process.cwd();
|
|
38
|
-
|
|
39
|
-
const pkgjson = JSON.parse(fs.readFileSync('package.json'));
|
|
40
|
-
const DOWNSTREAM_PKGS = (process.env.DOWNSTREAM_PKGS || '').split(',').filter(x => x);
|
|
41
|
-
|
|
42
|
-
const TEMP = tmp.dirSync();
|
|
43
|
-
const TEMP_DIR = TEMP.name;
|
|
44
|
-
const TEMP_DOWNSTREAM_CACHE = path.resolve(TEMP_DIR, '.downstream_cache');
|
|
45
|
-
const DOWNSTREAM_CACHE = path.resolve(PKG_DIR, '.downstream_cache');
|
|
46
|
-
|
|
47
|
-
function parseConfig(configFilePath, limitToGroup = 'all') {
|
|
48
|
-
console.log('parsing config for ' + configFilePath);
|
|
49
|
-
const config = JSON.parse(fs.readFileSync(configFilePath).toString());
|
|
50
|
-
const configBlock = _.toPairs(config.projects || config);
|
|
51
|
-
|
|
52
|
-
// Object values are groups (nested config). string values are github url or local file path
|
|
53
|
-
const isGroup = ([key, value]) => typeof value === 'object';
|
|
54
|
-
const groupsAsPairs = configBlock.filter(pair => isGroup(pair));
|
|
55
|
-
const ungroupedProjectsAsPairs = configBlock.filter(pair => !isGroup(pair));
|
|
56
|
-
|
|
57
|
-
const allGroupedProjectPairs = _.flatten(groupsAsPairs.map(([name, groupedProjects]) => _.toPairs(groupedProjects)));
|
|
58
|
-
|
|
59
|
-
const groups = _.fromPairs(groupsAsPairs);
|
|
60
|
-
groups.all = _.fromPairs(allGroupedProjectPairs.concat(ungroupedProjectsAsPairs));
|
|
61
|
-
|
|
62
|
-
const projects = groups[limitToGroup];
|
|
63
|
-
if (!projects) {
|
|
64
|
-
throw new Error(`Attempting to run tests for a group named ${yargs.argv.group}, but no matching group was found in downstream_projects.json`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const nohoist = (config.projects && config.nohoist) || [];
|
|
68
|
-
return { projects, nohoist };
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const { projects, nohoist } = parseConfig('downstream_projects.json', yargs.argv.group);
|
|
72
|
-
|
|
73
|
-
function makeDownstreamCache() {
|
|
74
|
-
if (!fs.existsSync(DOWNSTREAM_CACHE)) {
|
|
75
|
-
console.log(' ===> making .downstream_cache working directory <===');
|
|
76
|
-
fs.mkdirSync(DOWNSTREAM_CACHE);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function localPublish(packageDir) {
|
|
81
|
-
packageDir = packageDir || PKG_DIR;
|
|
82
|
-
process.chdir(packageDir);
|
|
83
|
-
console.log(` ===> Building ${packageDir} and publishing using yalc... <===`);
|
|
84
|
-
|
|
85
|
-
// Un-yalc any deps in the package.json (after building, but before yalc publishing)
|
|
86
|
-
const packageString = fs.readFileSync('package.json');
|
|
87
|
-
const package = JSON.parse(packageString);
|
|
88
|
-
const distDir = package.distDir || '.';
|
|
89
|
-
const { resolutions = {}, dependencies = {}, devDependencies = {} } = package;
|
|
90
|
-
|
|
91
|
-
const yalcLockfile = fs.existsSync('yalc.lock') ? JSON.parse(fs.readFileSync('yalc.lock')) : {};
|
|
92
|
-
const yalcPackages = Object.keys(yalcLockfile.packages || {})
|
|
93
|
-
|
|
94
|
-
yalcPackages.forEach(pkg => {
|
|
95
|
-
delete resolutions[pkg];
|
|
96
|
-
|
|
97
|
-
if (dependencies[pkg]) {
|
|
98
|
-
dependencies[pkg] = yalcLockfile.packages[pkg].replaced;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (devDependencies[pkg]) {
|
|
102
|
-
devDependencies[pkg] = yalcLockfile.packages[pkg].replaced;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
if (yalcPackages.length) {
|
|
107
|
-
console.log(` ===> De-yalc'ed ${yalcPackages.join(', ')} from ${packageDir}/package.json using ${packageDir}/yarn.lock <===`)
|
|
108
|
-
fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (distDir !== '.' && package.scripts && package.scripts.build) {
|
|
112
|
-
util._exec('npm run build')
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
shelljs.pushd(distDir);
|
|
116
|
-
util._exec('npx yalc publish');
|
|
117
|
-
shelljs.popd();
|
|
118
|
-
|
|
119
|
-
if (yalcPackages.length) {
|
|
120
|
-
console.log(` ===> Restoring yalc'd manifest ${packageDir}/package.json <===`)
|
|
121
|
-
fs.writeFileSync('package.json', packageString);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function installUpstreamDeps(upstreamPackages) {
|
|
126
|
-
upstreamPackages.forEach(upstream => {
|
|
127
|
-
util._exec('npx yalc add ' + upstream);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
upstreamPackages.forEach(upstream => {
|
|
131
|
-
const package = JSON.parse(fs.readFileSync('package.json'));
|
|
132
|
-
const yalcDep = (package.dependencies || {})[upstream] || (package.devDependencies || {})[upstream];
|
|
133
|
-
package.resolutions = package.resolutions || {};
|
|
134
|
-
package.resolutions[upstream] = yalcDep;
|
|
135
|
-
fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// Install updated deps from the upstream
|
|
139
|
-
// If local changes point to a new version of @uirouter/core, for example
|
|
140
|
-
util._exec('npx yarn');
|
|
141
|
-
util._exec('npx check-peer-dependencies --install');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function runTests() {
|
|
145
|
-
util._exec(`npm test`);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function fetchDownstreamProjects(downstreamConfig, prefix, downstreamTreeNode) {
|
|
149
|
-
prefix = prefix || "";
|
|
150
|
-
|
|
151
|
-
Object.keys(downstreamConfig).forEach(key => {
|
|
152
|
-
const installDir = prefix ? `${prefix}.${key}` : key;
|
|
153
|
-
|
|
154
|
-
console.log(` ===> Fetching downstream project to '${installDir}' <===`);
|
|
155
|
-
const installSource = downstreamConfig[key];
|
|
156
|
-
const isFile = /^\./.exec(installSource);
|
|
157
|
-
const installSourcePath = prefix ? path.resolve(DOWNSTREAM_CACHE, prefix, installSource) : path.resolve(PKG_DIR, installSource);
|
|
158
|
-
const installSourceNormalized = isFile ? './' + path.relative(process.cwd(), installSourcePath) : installSource;
|
|
159
|
-
// Extract optional git repo branch, i.e.: https://github.com/ui-router/core.git@somebranch
|
|
160
|
-
const [orig, gitRepoOnly, branch] = /^(.*?)(?:\.git@(.*))?$/.exec(installSourceNormalized);
|
|
161
|
-
const installSourceForYalc = branch ? gitRepoOnly : orig;
|
|
162
|
-
const flags = { noBuild: true, noPublish: true, noInstall: true };
|
|
163
|
-
if (branch) {
|
|
164
|
-
flags.branch = `origin/${branch}`;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
publishYalcPackage(path.resolve(DOWNSTREAM_CACHE, installDir), installSourceForYalc, flags);
|
|
168
|
-
|
|
169
|
-
const children = {};
|
|
170
|
-
downstreamTreeNode[key] = { installDir, installSource, children };
|
|
171
|
-
|
|
172
|
-
const nestedDownstreamConfigPath = path.resolve(DOWNSTREAM_CACHE, installDir, 'downstream_projects.json');
|
|
173
|
-
if (fs.existsSync(nestedDownstreamConfigPath)) {
|
|
174
|
-
const { projects } = parseConfig(nestedDownstreamConfigPath);
|
|
175
|
-
console.log({ projects });
|
|
176
|
-
fetchDownstreamProjects(projects, installDir, children);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function getDownstreamInstallDirs(downstreamTreeNode) {
|
|
182
|
-
const children = Object.keys(downstreamTreeNode.children);
|
|
183
|
-
const childrenInstallDirs = children.map(key => getDownstreamInstallDirs(downstreamTreeNode.children[key]));
|
|
184
|
-
return [downstreamTreeNode.installDir]
|
|
185
|
-
.concat(childrenInstallDirs)
|
|
186
|
-
.reduce((acc, arr) => acc.concat(arr), [])
|
|
187
|
-
.filter(x => !!x);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function installWorkspaceDependencies(downstreamInstallDirs) {
|
|
191
|
-
const yarnWorkspacePackageJsonPath = path.resolve(DOWNSTREAM_CACHE, "package.json");
|
|
192
|
-
const yarnWorkspacePackageJson = {
|
|
193
|
-
private: true,
|
|
194
|
-
"workspaces": {
|
|
195
|
-
"packages": downstreamInstallDirs,
|
|
196
|
-
"nohoist": nohoist.concat([ "**/webpack", "**/karma-webpack", ])
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
fs.writeFileSync(yarnWorkspacePackageJsonPath, JSON.stringify(yarnWorkspacePackageJson, null, 2));
|
|
201
|
-
process.chdir(DOWNSTREAM_CACHE);
|
|
202
|
-
util._exec('yarn');
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
let runningTestsFor;
|
|
206
|
-
function runDownstreamTests(key, upstreamPackages, downstreamTreeNode, successLog) {
|
|
207
|
-
if (DOWNSTREAM_PKGS.length && DOWNSTREAM_PKGS.indexOf(key) === -1) {
|
|
208
|
-
console.log(` ===> ${key} not in DOWNSTREAM_PKGS, skipping... <===`);
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
process.chdir(TEMP_DOWNSTREAM_CACHE);
|
|
213
|
-
|
|
214
|
-
const name = downstreamTreeNode.installDir;
|
|
215
|
-
|
|
216
|
-
foldEnd = foldStart(`Running downstream tests: '${name}'`)
|
|
217
|
-
runningTestsFor = name;
|
|
218
|
-
|
|
219
|
-
console.log(` ===> '${name}': prepping tests <===`);
|
|
220
|
-
process.chdir(downstreamTreeNode.installDir);
|
|
221
|
-
|
|
222
|
-
if (!yargs.argv.workspace) {
|
|
223
|
-
console.log(` ===> '${name}': Installing dependencies <===`);
|
|
224
|
-
util._exec('yarn');
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
console.log(` ===> '${name}': Installing freshly built upstream packages <===`);
|
|
228
|
-
installUpstreamDeps(upstreamPackages);
|
|
229
|
-
|
|
230
|
-
console.log(` ===> '${name}': Running tests <===`);
|
|
231
|
-
runTests();
|
|
232
|
-
|
|
233
|
-
successLog.push(name);
|
|
234
|
-
runningTestsFor = undefined;
|
|
235
|
-
|
|
236
|
-
foldEnd();
|
|
237
|
-
|
|
238
|
-
const downstreamChildren = Object.keys(downstreamTreeNode.children || {});
|
|
239
|
-
if (downstreamChildren.length) {
|
|
240
|
-
const thisPkg = JSON.parse(fs.readFileSync('package.json')).name;
|
|
241
|
-
const upstreams = upstreamPackages.concat(thisPkg);
|
|
242
|
-
|
|
243
|
-
foldEnd = foldStart(`Local Yalc Publish: ${process.cwd().replace(/.*\//, '')}`);
|
|
244
|
-
localPublish(process.cwd());
|
|
245
|
-
foldEnd();
|
|
246
|
-
|
|
247
|
-
downstreamChildren.forEach(child => {
|
|
248
|
-
runDownstreamTests(child, upstreams, downstreamTreeNode.children[child], successLog);
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
console.log(` ===> Creating .downstream_cache working directory <===`);
|
|
254
|
-
makeDownstreamCache();
|
|
255
|
-
|
|
256
|
-
foldEnd = foldStart(`Publishing ${pkgjson.name} to yalc registry`);
|
|
257
|
-
localPublish();
|
|
258
|
-
foldEnd();
|
|
259
|
-
|
|
260
|
-
foldEnd = foldStart(`Fetching downstream projects`);
|
|
261
|
-
const tree = { children: {} };
|
|
262
|
-
fetchDownstreamProjects(projects, "", tree.children);
|
|
263
|
-
foldEnd();
|
|
264
|
-
|
|
265
|
-
if (yargs.argv.workspace) {
|
|
266
|
-
foldEnd = foldStart(`Installing downstream dependencies`);
|
|
267
|
-
const downstreamDirs = getDownstreamInstallDirs(tree);
|
|
268
|
-
installWorkspaceDependencies(downstreamDirs);
|
|
269
|
-
foldEnd();
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
console.log(` ===> Moving working directory to temp dir ${TEMP_DIR} <===`);
|
|
273
|
-
shelljs.mv(DOWNSTREAM_CACHE, TEMP_DIR);
|
|
274
|
-
|
|
275
|
-
function getAllProjectKeys(tree, keyPrefix) {
|
|
276
|
-
const children = Object.keys(tree.children || {});
|
|
277
|
-
const grandChildren = children.map(child => getAllProjectKeys(tree.children[child], child));
|
|
278
|
-
return children.concat(...grandChildren).map(key => keyPrefix ? `${keyPrefix}.${key}` : key);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const successLog = [];
|
|
282
|
-
const allProjectKeys = getAllProjectKeys(tree);
|
|
283
|
-
nodeCleanup(() => {
|
|
284
|
-
shelljs.mv(TEMP_DOWNSTREAM_CACHE, PKG_DIR);
|
|
285
|
-
console.log(` ===> Successfully ran downstream tests for: ${successLog.join(', ')} <===`);
|
|
286
|
-
if (runningTestsFor) {
|
|
287
|
-
console.log(` ===> Failed to run downstream tests for: ${runningTestsFor} <===`);
|
|
288
|
-
}
|
|
289
|
-
const skipped = _.difference(allProjectKeys, successLog.concat(runningTestsFor));
|
|
290
|
-
if (skipped.length) {
|
|
291
|
-
console.log(` ===> Did not try to run downstream tests for: ${skipped.join(', ')} <===`);
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
console.log(` ===> Running the following downstream tests <===`);
|
|
296
|
-
allProjectKeys.forEach(key => {
|
|
297
|
-
console.log(` ===> ${_.padEnd(key, 38)} <===`);
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
Object.keys(tree.children).forEach(key => {
|
|
301
|
-
runDownstreamTests(key, [pkgjson.name], tree.children[key], successLog);
|
|
302
|
-
});
|
|
303
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const tmp = require('tmp');
|
|
5
|
+
const shelljs = require('shelljs');
|
|
6
|
+
const _ = require('lodash');
|
|
7
|
+
const isTravis = !!process.env.TRAVIS;
|
|
8
|
+
const isGithubActions = !!process.env.GITHUB_ACTIONS;
|
|
9
|
+
|
|
10
|
+
const yargs = require('yargs')
|
|
11
|
+
.option('group', {
|
|
12
|
+
alias: 'g',
|
|
13
|
+
default: 'all',
|
|
14
|
+
description: 'the group of projects to test (from downstream_projects.json "group" key)',
|
|
15
|
+
})
|
|
16
|
+
.option('workspace', {
|
|
17
|
+
alias: 'ws',
|
|
18
|
+
description: 'use yarn workspace to save space',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const nodeCleanup = require('node-cleanup');
|
|
22
|
+
const publishYalcPackage = require('./publish_yalc_package');
|
|
23
|
+
const foldStart = (message) => {
|
|
24
|
+
isTravis && console.log('travis_fold:start:' + message.replace(/\s+/g, '.'));
|
|
25
|
+
isGithubActions && console.log('::group::' + message);
|
|
26
|
+
console.log(message);
|
|
27
|
+
return () => {
|
|
28
|
+
isTravis && console.log('travis_fold:end:' + message.replace(/\s+/g, '.'));
|
|
29
|
+
isGithubActions && console.log(message);
|
|
30
|
+
isGithubActions && console.log('::endgroup::');
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
let foldEnd = () => null;
|
|
34
|
+
|
|
35
|
+
const util = require('./util');
|
|
36
|
+
util.packageDir();
|
|
37
|
+
const PKG_DIR = process.cwd();
|
|
38
|
+
|
|
39
|
+
const pkgjson = JSON.parse(fs.readFileSync('package.json'));
|
|
40
|
+
const DOWNSTREAM_PKGS = (process.env.DOWNSTREAM_PKGS || '').split(',').filter(x => x);
|
|
41
|
+
|
|
42
|
+
const TEMP = tmp.dirSync();
|
|
43
|
+
const TEMP_DIR = TEMP.name;
|
|
44
|
+
const TEMP_DOWNSTREAM_CACHE = path.resolve(TEMP_DIR, '.downstream_cache');
|
|
45
|
+
const DOWNSTREAM_CACHE = path.resolve(PKG_DIR, '.downstream_cache');
|
|
46
|
+
|
|
47
|
+
function parseConfig(configFilePath, limitToGroup = 'all') {
|
|
48
|
+
console.log('parsing config for ' + configFilePath);
|
|
49
|
+
const config = JSON.parse(fs.readFileSync(configFilePath).toString());
|
|
50
|
+
const configBlock = _.toPairs(config.projects || config);
|
|
51
|
+
|
|
52
|
+
// Object values are groups (nested config). string values are github url or local file path
|
|
53
|
+
const isGroup = ([key, value]) => typeof value === 'object';
|
|
54
|
+
const groupsAsPairs = configBlock.filter(pair => isGroup(pair));
|
|
55
|
+
const ungroupedProjectsAsPairs = configBlock.filter(pair => !isGroup(pair));
|
|
56
|
+
|
|
57
|
+
const allGroupedProjectPairs = _.flatten(groupsAsPairs.map(([name, groupedProjects]) => _.toPairs(groupedProjects)));
|
|
58
|
+
|
|
59
|
+
const groups = _.fromPairs(groupsAsPairs);
|
|
60
|
+
groups.all = _.fromPairs(allGroupedProjectPairs.concat(ungroupedProjectsAsPairs));
|
|
61
|
+
|
|
62
|
+
const projects = groups[limitToGroup];
|
|
63
|
+
if (!projects) {
|
|
64
|
+
throw new Error(`Attempting to run tests for a group named ${yargs.argv.group}, but no matching group was found in downstream_projects.json`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const nohoist = (config.projects && config.nohoist) || [];
|
|
68
|
+
return { projects, nohoist };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const { projects, nohoist } = parseConfig('downstream_projects.json', yargs.argv.group);
|
|
72
|
+
|
|
73
|
+
function makeDownstreamCache() {
|
|
74
|
+
if (!fs.existsSync(DOWNSTREAM_CACHE)) {
|
|
75
|
+
console.log(' ===> making .downstream_cache working directory <===');
|
|
76
|
+
fs.mkdirSync(DOWNSTREAM_CACHE);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function localPublish(packageDir) {
|
|
81
|
+
packageDir = packageDir || PKG_DIR;
|
|
82
|
+
process.chdir(packageDir);
|
|
83
|
+
console.log(` ===> Building ${packageDir} and publishing using yalc... <===`);
|
|
84
|
+
|
|
85
|
+
// Un-yalc any deps in the package.json (after building, but before yalc publishing)
|
|
86
|
+
const packageString = fs.readFileSync('package.json');
|
|
87
|
+
const package = JSON.parse(packageString);
|
|
88
|
+
const distDir = package.distDir || '.';
|
|
89
|
+
const { resolutions = {}, dependencies = {}, devDependencies = {} } = package;
|
|
90
|
+
|
|
91
|
+
const yalcLockfile = fs.existsSync('yalc.lock') ? JSON.parse(fs.readFileSync('yalc.lock')) : {};
|
|
92
|
+
const yalcPackages = Object.keys(yalcLockfile.packages || {})
|
|
93
|
+
|
|
94
|
+
yalcPackages.forEach(pkg => {
|
|
95
|
+
delete resolutions[pkg];
|
|
96
|
+
|
|
97
|
+
if (dependencies[pkg]) {
|
|
98
|
+
dependencies[pkg] = yalcLockfile.packages[pkg].replaced;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (devDependencies[pkg]) {
|
|
102
|
+
devDependencies[pkg] = yalcLockfile.packages[pkg].replaced;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (yalcPackages.length) {
|
|
107
|
+
console.log(` ===> De-yalc'ed ${yalcPackages.join(', ')} from ${packageDir}/package.json using ${packageDir}/yarn.lock <===`)
|
|
108
|
+
fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (distDir !== '.' && package.scripts && package.scripts.build) {
|
|
112
|
+
util._exec('npm run build')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
shelljs.pushd(distDir);
|
|
116
|
+
util._exec('npx yalc publish');
|
|
117
|
+
shelljs.popd();
|
|
118
|
+
|
|
119
|
+
if (yalcPackages.length) {
|
|
120
|
+
console.log(` ===> Restoring yalc'd manifest ${packageDir}/package.json <===`)
|
|
121
|
+
fs.writeFileSync('package.json', packageString);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function installUpstreamDeps(upstreamPackages) {
|
|
126
|
+
upstreamPackages.forEach(upstream => {
|
|
127
|
+
util._exec('npx yalc add ' + upstream);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
upstreamPackages.forEach(upstream => {
|
|
131
|
+
const package = JSON.parse(fs.readFileSync('package.json'));
|
|
132
|
+
const yalcDep = (package.dependencies || {})[upstream] || (package.devDependencies || {})[upstream];
|
|
133
|
+
package.resolutions = package.resolutions || {};
|
|
134
|
+
package.resolutions[upstream] = yalcDep;
|
|
135
|
+
fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Install updated deps from the upstream
|
|
139
|
+
// If local changes point to a new version of @uirouter/core, for example
|
|
140
|
+
util._exec('npx yarn');
|
|
141
|
+
util._exec('npx check-peer-dependencies --install');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function runTests() {
|
|
145
|
+
util._exec(`npm test`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function fetchDownstreamProjects(downstreamConfig, prefix, downstreamTreeNode) {
|
|
149
|
+
prefix = prefix || "";
|
|
150
|
+
|
|
151
|
+
Object.keys(downstreamConfig).forEach(key => {
|
|
152
|
+
const installDir = prefix ? `${prefix}.${key}` : key;
|
|
153
|
+
|
|
154
|
+
console.log(` ===> Fetching downstream project to '${installDir}' <===`);
|
|
155
|
+
const installSource = downstreamConfig[key];
|
|
156
|
+
const isFile = /^\./.exec(installSource);
|
|
157
|
+
const installSourcePath = prefix ? path.resolve(DOWNSTREAM_CACHE, prefix, installSource) : path.resolve(PKG_DIR, installSource);
|
|
158
|
+
const installSourceNormalized = isFile ? './' + path.relative(process.cwd(), installSourcePath) : installSource;
|
|
159
|
+
// Extract optional git repo branch, i.e.: https://github.com/ui-router/core.git@somebranch
|
|
160
|
+
const [orig, gitRepoOnly, branch] = /^(.*?)(?:\.git@(.*))?$/.exec(installSourceNormalized);
|
|
161
|
+
const installSourceForYalc = branch ? gitRepoOnly : orig;
|
|
162
|
+
const flags = { noBuild: true, noPublish: true, noInstall: true };
|
|
163
|
+
if (branch) {
|
|
164
|
+
flags.branch = `origin/${branch}`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
publishYalcPackage(path.resolve(DOWNSTREAM_CACHE, installDir), installSourceForYalc, flags);
|
|
168
|
+
|
|
169
|
+
const children = {};
|
|
170
|
+
downstreamTreeNode[key] = { installDir, installSource, children };
|
|
171
|
+
|
|
172
|
+
const nestedDownstreamConfigPath = path.resolve(DOWNSTREAM_CACHE, installDir, 'downstream_projects.json');
|
|
173
|
+
if (fs.existsSync(nestedDownstreamConfigPath)) {
|
|
174
|
+
const { projects } = parseConfig(nestedDownstreamConfigPath);
|
|
175
|
+
console.log({ projects });
|
|
176
|
+
fetchDownstreamProjects(projects, installDir, children);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function getDownstreamInstallDirs(downstreamTreeNode) {
|
|
182
|
+
const children = Object.keys(downstreamTreeNode.children);
|
|
183
|
+
const childrenInstallDirs = children.map(key => getDownstreamInstallDirs(downstreamTreeNode.children[key]));
|
|
184
|
+
return [downstreamTreeNode.installDir]
|
|
185
|
+
.concat(childrenInstallDirs)
|
|
186
|
+
.reduce((acc, arr) => acc.concat(arr), [])
|
|
187
|
+
.filter(x => !!x);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function installWorkspaceDependencies(downstreamInstallDirs) {
|
|
191
|
+
const yarnWorkspacePackageJsonPath = path.resolve(DOWNSTREAM_CACHE, "package.json");
|
|
192
|
+
const yarnWorkspacePackageJson = {
|
|
193
|
+
private: true,
|
|
194
|
+
"workspaces": {
|
|
195
|
+
"packages": downstreamInstallDirs,
|
|
196
|
+
"nohoist": nohoist.concat([ "**/webpack", "**/karma-webpack", ])
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
fs.writeFileSync(yarnWorkspacePackageJsonPath, JSON.stringify(yarnWorkspacePackageJson, null, 2));
|
|
201
|
+
process.chdir(DOWNSTREAM_CACHE);
|
|
202
|
+
util._exec('yarn');
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
let runningTestsFor;
|
|
206
|
+
function runDownstreamTests(key, upstreamPackages, downstreamTreeNode, successLog) {
|
|
207
|
+
if (DOWNSTREAM_PKGS.length && DOWNSTREAM_PKGS.indexOf(key) === -1) {
|
|
208
|
+
console.log(` ===> ${key} not in DOWNSTREAM_PKGS, skipping... <===`);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
process.chdir(TEMP_DOWNSTREAM_CACHE);
|
|
213
|
+
|
|
214
|
+
const name = downstreamTreeNode.installDir;
|
|
215
|
+
|
|
216
|
+
foldEnd = foldStart(`Running downstream tests: '${name}'`)
|
|
217
|
+
runningTestsFor = name;
|
|
218
|
+
|
|
219
|
+
console.log(` ===> '${name}': prepping tests <===`);
|
|
220
|
+
process.chdir(downstreamTreeNode.installDir);
|
|
221
|
+
|
|
222
|
+
if (!yargs.argv.workspace) {
|
|
223
|
+
console.log(` ===> '${name}': Installing dependencies <===`);
|
|
224
|
+
util._exec('yarn');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
console.log(` ===> '${name}': Installing freshly built upstream packages <===`);
|
|
228
|
+
installUpstreamDeps(upstreamPackages);
|
|
229
|
+
|
|
230
|
+
console.log(` ===> '${name}': Running tests <===`);
|
|
231
|
+
runTests();
|
|
232
|
+
|
|
233
|
+
successLog.push(name);
|
|
234
|
+
runningTestsFor = undefined;
|
|
235
|
+
|
|
236
|
+
foldEnd();
|
|
237
|
+
|
|
238
|
+
const downstreamChildren = Object.keys(downstreamTreeNode.children || {});
|
|
239
|
+
if (downstreamChildren.length) {
|
|
240
|
+
const thisPkg = JSON.parse(fs.readFileSync('package.json')).name;
|
|
241
|
+
const upstreams = upstreamPackages.concat(thisPkg);
|
|
242
|
+
|
|
243
|
+
foldEnd = foldStart(`Local Yalc Publish: ${process.cwd().replace(/.*\//, '')}`);
|
|
244
|
+
localPublish(process.cwd());
|
|
245
|
+
foldEnd();
|
|
246
|
+
|
|
247
|
+
downstreamChildren.forEach(child => {
|
|
248
|
+
runDownstreamTests(child, upstreams, downstreamTreeNode.children[child], successLog);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
console.log(` ===> Creating .downstream_cache working directory <===`);
|
|
254
|
+
makeDownstreamCache();
|
|
255
|
+
|
|
256
|
+
foldEnd = foldStart(`Publishing ${pkgjson.name} to yalc registry`);
|
|
257
|
+
localPublish();
|
|
258
|
+
foldEnd();
|
|
259
|
+
|
|
260
|
+
foldEnd = foldStart(`Fetching downstream projects`);
|
|
261
|
+
const tree = { children: {} };
|
|
262
|
+
fetchDownstreamProjects(projects, "", tree.children);
|
|
263
|
+
foldEnd();
|
|
264
|
+
|
|
265
|
+
if (yargs.argv.workspace) {
|
|
266
|
+
foldEnd = foldStart(`Installing downstream dependencies`);
|
|
267
|
+
const downstreamDirs = getDownstreamInstallDirs(tree);
|
|
268
|
+
installWorkspaceDependencies(downstreamDirs);
|
|
269
|
+
foldEnd();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
console.log(` ===> Moving working directory to temp dir ${TEMP_DIR} <===`);
|
|
273
|
+
shelljs.mv(DOWNSTREAM_CACHE, TEMP_DIR);
|
|
274
|
+
|
|
275
|
+
function getAllProjectKeys(tree, keyPrefix) {
|
|
276
|
+
const children = Object.keys(tree.children || {});
|
|
277
|
+
const grandChildren = children.map(child => getAllProjectKeys(tree.children[child], child));
|
|
278
|
+
return children.concat(...grandChildren).map(key => keyPrefix ? `${keyPrefix}.${key}` : key);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const successLog = [];
|
|
282
|
+
const allProjectKeys = getAllProjectKeys(tree);
|
|
283
|
+
nodeCleanup(() => {
|
|
284
|
+
shelljs.mv(TEMP_DOWNSTREAM_CACHE, PKG_DIR);
|
|
285
|
+
console.log(` ===> Successfully ran downstream tests for: ${successLog.join(', ')} <===`);
|
|
286
|
+
if (runningTestsFor) {
|
|
287
|
+
console.log(` ===> Failed to run downstream tests for: ${runningTestsFor} <===`);
|
|
288
|
+
}
|
|
289
|
+
const skipped = _.difference(allProjectKeys, successLog.concat(runningTestsFor));
|
|
290
|
+
if (skipped.length) {
|
|
291
|
+
console.log(` ===> Did not try to run downstream tests for: ${skipped.join(', ')} <===`);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
console.log(` ===> Running the following downstream tests <===`);
|
|
296
|
+
allProjectKeys.forEach(key => {
|
|
297
|
+
console.log(` ===> ${_.padEnd(key, 38)} <===`);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
Object.keys(tree.children).forEach(key => {
|
|
301
|
+
runDownstreamTests(key, [pkgjson.name], tree.children[key], successLog);
|
|
302
|
+
});
|
|
303
|
+
|