Skip to content

Commit b4a70df

Browse files
Make yarn tasks imply yarn install where appropriate (#11394)
* made sure that yarn install gets called before compile * Add some nice messages * better detection * cleaned up more * more tweaks * remove old checks * let unit tests run without binaries * turn off scenario tests until binaries can be installed * add another rule
1 parent efa5c22 commit b4a70df

File tree

10 files changed

+156
-49
lines changed

10 files changed

+156
-49
lines changed

.github/workflows/ci_linux.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ jobs:
3434
run: yarn test
3535
working-directory: Extension
3636

37-
- name: Run simple vscode unit tests
38-
uses: GabrielBB/[email protected]
39-
with:
40-
run: yarn test --scenario=SingleRootProject
41-
working-directory: Extension
37+
# # NOTE : We can't run the test that require the native binary files
38+
# # yet -- there will be an update soon that allows the tester to
39+
# # acquire them on-the-fly
40+
# - name: Run simple vscode unit tests
41+
# uses: GabrielBB/[email protected]
42+
# with:
43+
# run: yarn test --scenario=SingleRootProject
44+
# working-directory: Extension
4245

4346
# - name: Run languageServer integration tests
4447
# uses: GabrielBB/[email protected]

.github/workflows/ci_mac.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ jobs:
3434
run: yarn test
3535
working-directory: Extension
3636

37-
- name: Run simple vscode unit tests
38-
uses: GabrielBB/[email protected]
39-
with:
40-
run: yarn test --scenario=SingleRootProject
41-
working-directory: Extension
37+
# # NOTE : We can't run the test that require the native binary files
38+
# # yet -- there will be an update soon that allows the tester to
39+
# # acquire them on-the-fly
40+
# - name: Run simple vscode unit tests
41+
# uses: GabrielBB/[email protected]
42+
# with:
43+
# run: yarn test --scenario=SingleRootProject
44+
# working-directory: Extension
4245

4346
# - name: Run languageServer integration tests
4447
# uses: GabrielBB/[email protected]

.github/workflows/ci_windows.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ jobs:
3434
run: yarn test
3535
working-directory: Extension
3636

37-
- name: Run simple vscode unit tests
38-
run: yarn test --scenario=SingleRootProject
39-
working-directory: Extension
37+
# # NOTE : We can't run the test that require the native binary files
38+
# # yet -- there will be an update soon that allows the tester to
39+
# # acquire them on-the-fly
40+
# - name: Run simple vscode unit tests
41+
# run: yarn test --scenario=SingleRootProject
42+
# working-directory: Extension
4043

4144
# - name: Run languageServer integration tests
4245
# run: yarn run integrationTests

Extension/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ module.exports = {
129129
"no-unsafe-finally": "error",
130130
"no-unused-expressions": "error",
131131
"no-unused-labels": "error",
132+
"space-before-blocks": "error",
132133
"no-var": "error",
133134
"one-var": [
134135
"error",

Extension/.scripts/code.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { spawnSync } from 'child_process';
77
import { verbose } from '../src/Utility/Text/streams';
8-
import { $args, $root, $scenario, brightGreen, checkFile, gray, green, pwd } from './common';
8+
import { $args, $root, $scenario, assertAnyFile, brightGreen, gray, green, pwd } from './common';
99

1010
import { resolve } from 'path';
1111
import { getTestInfo } from '../test/common/selectTests';
@@ -25,7 +25,7 @@ export async function main() {
2525
// we found it
2626
$args.unshift(ti.workspace);
2727
}
28-
await checkFile('dist/src/main.js', `The extension entry point '${$root}/dist/src/main.js is missing. You should run ${brightGreen("yarn compile")}\n\n`);
28+
await assertAnyFile('dist/src/main.js', `The extension entry point '${$root}/dist/src/main.js is missing. You should run ${brightGreen("yarn compile")}\n\n`);
2929

3030
const { cli, args } = await install();
3131

Extension/.scripts/common.ts

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export let $cmd = 'main';
2222
export let $scenario = '';
2323

2424
// loop through the args and pick out --scenario=... and remove it from the $args and set $scenario
25-
export const $args = process.argv.slice(2).filter(each => !(each.startsWith('--scenario=') && ($scenario = each.substring('--scenario='.length))));
25+
process.argv.slice(2).filter(each => !(each.startsWith('--scenario=') && ($scenario = each.substring('--scenario='.length))));
26+
export const $args = process.argv.slice(2).filter(each => !each.startsWith('--'));
27+
export const $switches = process.argv.slice(2).filter(each => each.startsWith('--'));
2628

2729
/** enqueue the call to the callback function to happen on the next available tick, and return a promise to the result */
2830
export function then<T>(callback: () => Promise<T> | T): Promise<T> {
@@ -166,10 +168,12 @@ export async function writeJson(filename: string, object: CommentJSONValue) {
166168

167169
export function error(text: string) {
168170
console.error(`\n${red('ERROR')}: ${text}`);
171+
return true;
169172
}
170173

171174
export function warn(text: string) {
172175
console.error(`\n${yellow('WARNING')}: ${text}`);
176+
return true;
173177
}
174178

175179
export function note(text: string) {
@@ -254,37 +258,86 @@ export function position(text: string) {
254258
return gray(`${text}`);
255259
}
256260

257-
export async function checkFolder(folder: string | string[], errMsg: string){
258-
for (const each of is.array(folder) ? folder : [folder]) {
261+
export async function assertAnyFolder(oneOrMoreFolders: string | string[], errorMessage?: string): Promise<string> {
262+
oneOrMoreFolders = is.array(oneOrMoreFolders) ? oneOrMoreFolders : [oneOrMoreFolders];
263+
for (const each of oneOrMoreFolders) {
259264
const result = await filepath.isFolder(each, $root);
260265
if (result) {
266+
verbose(`Folder ${brightGreen(each)} exists.`);
261267
return result;
262268
}
263269
}
264-
error(errMsg);
265-
process.exit(1);
270+
if (errorMessage) {
271+
if (!$switches.includes('--quiet')) {
272+
error(errorMessage);
273+
}
274+
process.exit(1);
275+
}
266276
}
267277

268-
export async function checkFile(file: string | string[], errMsg: string){
269-
for (const each of is.array(file) ? file : [file]) {
278+
export async function assertAnyFile(oneOrMoreFiles: string | string[], errorMessage?: string): Promise<string> {
279+
oneOrMoreFiles = is.array(oneOrMoreFiles) ? oneOrMoreFiles : [oneOrMoreFiles];
280+
for (const each of oneOrMoreFiles) {
270281
const result = await filepath.isFile(each, $root);
271282
if (result) {
283+
verbose(`Folder ${brightGreen(each)} exists.`);
272284
return result;
273285
}
274286
}
275-
error(errMsg);
276-
process.exit(1);
287+
if (errorMessage) {
288+
if (!$switches.includes('--quiet')) {
289+
error(errorMessage);
290+
}
291+
process.exit(1);
292+
}
277293
}
278294

295+
const quiet = process.argv.includes('--quiet');
296+
279297
export async function checkPrep() {
280-
await checkFolder('dist/walkthrough', `The walkthrough files are not in place. You should run ${brightGreen("yarn prep")}\n\n`);
281-
await checkFolder('dist/html', `The html files are not in place. You should run ${brightGreen("yarn prep")}\n\n`);
282-
await checkFolder('dist/schema', `The html files are not in place. You should run ${brightGreen("yarn prep")}\n\n`);
283-
await checkFile('dist/nls.metadata.json', `The extension translation file '${$root}/dist/nls.metadata.json is missing. You should run ${brightGreen("yarn prep")}\n\n`);
284-
verbose('Prep files appear to be in place.');
298+
let failing = false;
299+
300+
failing = !await assertAnyFolder('dist/test') && (quiet || warn(`The compiled test files are not in place.`)) || failing;
301+
failing = !await assertAnyFolder('dist/walkthrough') && (quiet || warn(`The walkthrough files are not in place.`)) || failing;
302+
failing = !await assertAnyFolder('dist/html') && (quiet || warn(`The html files are not in place.`)) || failing;
303+
failing = !await assertAnyFolder('dist/schema') && (quiet || warn(`The schema files are not in place.`)) || failing;
304+
failing = !await assertAnyFile('dist/nls.metadata.json') && (quiet || warn(`The extension translation file '${$root}/dist/nls.metadata.json is missing.`)) || failing;
305+
failing = await checkDTS() || failing;
306+
307+
if (!failing) {
308+
verbose('Prep files appear to be in place.');
309+
}
310+
return failing;
285311
}
286312

287313
export async function checkCompiled() {
288-
await checkFile('dist/src/main.js', `The extension entry point '${$root}/dist/src/main.js is missing. You should run ${brightGreen("yarn compile")}\n\n`);
289-
verbose('Compiled files appear to be in place.');
314+
let failing = false;
315+
failing = await checkDTS() || failing;
316+
failing = !await assertAnyFile('dist/src/main.js') && (quiet || warn(`The extension entry point '${$root}/dist/src/main.js is missing.`)) || failing;
317+
318+
if (!failing) {
319+
verbose('Compiled files appear to be in place.');
320+
}
321+
return failing;
322+
}
323+
324+
export async function checkDTS() {
325+
let failing = false;
326+
failing = !await assertAnyFile('vscode.d.ts') && (quiet || warn(`The VSCode import file '${$root}/dist/src/vscode.d.ts is missing.`)) || failing;
327+
failing = !await assertAnyFile('vscode.proposed.terminalDataWriteEvent.d.ts') && (quiet || warn(`The VSCode import file '${$root}/dist/src/vscode.proposed.terminalDataWriteEvent.d.ts is missing.`)) || failing;
328+
329+
if (!failing) {
330+
verbose('VSCode d.ts files appear to be in place.');
331+
}
332+
return failing;
333+
}
334+
335+
export async function checkBinaries() {
336+
let failing = false;
337+
failing = !await assertAnyFile(['bin/cpptools.exe', 'bin/cpptools']) && (quiet || warn(`The native binary files are not present. You should either build or install the native binaries\n\n.`)) || failing;
338+
339+
if (!failing) {
340+
verbose('Native binary files appear to be in place.');
341+
}
342+
return failing;
290343
}

Extension/.scripts/test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { filepath } from '../src/Utility/Filesystem/filepath';
1414
import { is } from '../src/Utility/System/guards';
1515
import { verbose } from '../src/Utility/Text/streams';
1616
import { getTestInfo } from '../test/common/selectTests';
17-
import { $args, $root, $scenario, brightGreen, checkFile, checkFolder, cmdSwitch, cyan, error, gray, green, readJson, red, writeJson } from './common';
17+
import { $args, $root, $scenario, assertAnyFile, assertAnyFolder, brightGreen, checkBinaries, cmdSwitch, cyan, error, gray, green, readJson, red, writeJson } from './common';
1818
import { install, isolated, options } from './vscode';
1919

2020
export { install, reset } from './vscode';
@@ -73,14 +73,17 @@ function filterStdio() {
7373
filterStdio();
7474

7575
async function unitTests() {
76-
await checkFolder('dist/test/unit', `The folder '${$root}/dist/test/unit is missing. You should run ${brightGreen("yarn compile")}\n\n`);
77-
const mocha = await checkFile(["node_modules/.bin/mocha.cmd", "node_modules/.bin/mocha"], `Can't find the mocha testrunner. You might need to run ${brightGreen("yarn install")}\n\n`);
76+
await assertAnyFolder('dist/test/unit', `The folder '${$root}/dist/test/unit is missing. You should run ${brightGreen("yarn compile")}\n\n`);
77+
const mocha = await assertAnyFile(["node_modules/.bin/mocha.cmd", "node_modules/.bin/mocha"], `Can't find the mocha testrunner. You might need to run ${brightGreen("yarn install")}\n\n`);
7878
const result = spawnSync(mocha, [`${$root}/dist/test/unit/**/*.test.js`, '--timeout', '30000'], { stdio:'inherit'});
7979
verbose(`\n${green("NOTE:")} If you want to run a scenario test (end-to-end) use ${cmdSwitch('scenario=<NAME>')} \n\n`);
8080
return result.status;
8181
}
8282

8383
async function scenarioTests(assets: string, name: string, workspace: string) {
84+
if (await checkBinaries()) {
85+
process.exit(1);
86+
}
8487
return runTests({
8588
...options,
8689
extensionDevelopmentPath: $root,
@@ -93,7 +96,7 @@ async function scenarioTests(assets: string, name: string, workspace: string) {
9396
}
9497

9598
export async function main() {
96-
await checkFolder('dist/test/', `The folder '${$root}/dist/test is missing. You should run ${brightGreen("yarn compile")}\n\n`);
99+
await assertAnyFolder('dist/test/', `The folder '${$root}/dist/test is missing. You should run ${brightGreen("yarn compile")}\n\n`);
97100
const arg = $args.find(each => !each.startsWith("--"));
98101
const specifiedScenario = $scenario || env.SCENARIO || await getScenarioFolder(arg);
99102
const testInfo = await getTestInfo(specifiedScenario);
@@ -114,6 +117,9 @@ export async function main() {
114117
}
115118

116119
export async function all() {
120+
if (await checkBinaries()) {
121+
process.exit(1);
122+
}
117123
const finished: string[] = [];
118124

119125
if (await unitTests() !== 0) {

Extension/.scripts/verify.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,50 @@
33
* See 'LICENSE' in the project root for license information.
44
* ------------------------------------------------------------------------------------------ */
55

6-
import { checkCompiled, checkPrep } from './common';
6+
import { checkBinaries, checkCompiled, checkDTS, checkPrep, error, green } from './common';
7+
const quiet = process.argv.includes('--quiet');
78

89
export async function main() {
9-
await checkPrep();
10-
await checkCompiled();
10+
let failing = await checkPrep() && (quiet || error(`Files are not up to date. Run ${green('yarn prep')} to fix it.`));
11+
failing = (await checkCompiled() && (quiet || error(`Compiled files are not present. Run ${green('yarn compile')} to fix it.`))) || failing;
12+
failing = (await checkBinaries() && (quiet || error(`The native binary files are not present. You should either build or install the native binaries\n\n.`))) || failing;
13+
if (failing) {
14+
process.exit(1);
15+
}
16+
}
17+
18+
export async function compiled() {
19+
let failing = false;
20+
failing = (await checkCompiled() && (quiet || error(`Compiled files are not present. Run ${green('yarn compile')} to fix it.`))) || failing;
21+
22+
if (failing) {
23+
process.exit(1);
24+
}
25+
}
26+
27+
export async function binaries() {
28+
let failing = false;
29+
failing = (await checkBinaries() && (quiet || error(`The native binary files are not present. You should either build or install the native binaries\n\n.`))) || failing;
30+
31+
if (failing) {
32+
process.exit(1);
33+
}
1134
}
1235

1336
export async function prep() {
14-
await checkPrep();
37+
let failing = false;
38+
failing = (await checkPrep() && (quiet || error(`Files are not up to date. Run ${green('yarn prep')} to fix it.`))) || failing;
39+
40+
if (failing) {
41+
process.exit(1);
42+
}
43+
}
44+
45+
export async function dts() {
46+
let failing = false;
47+
failing = (await checkDTS() && (quiet || error(`VSCode import files are not present. Run ${green('yarn prep')} to fix it.`))) || failing;
48+
49+
if (failing) {
50+
process.exit(1);
51+
}
1552
}

Extension/package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6121,24 +6121,25 @@
61216121
"scripts": "ts-node -T .scripts/scripts.ts",
61226122
"show": "ts-node -T .scripts/clean.ts show",
61236123
"clean": "ts-node -T .scripts/clean.ts",
6124-
"test": "ts-node -T .scripts/test.ts",
6125-
"code": "ts-node -T .scripts/code.ts",
6124+
"test": "yarn install && (yarn verify prep --quiet || yarn prep) && (yarn verify compiled --quiet || yarn build) && ts-node -T .scripts/test.ts",
6125+
"code": "yarn install && (yarn verify compiled --quiet || yarn build) && yarn verify binaries && ts-node -T .scripts/code.ts",
61266126
"verify": "ts-node -T .scripts/verify.ts",
6127-
"prep": "yarn copy-walkthrough-media && yarn generate-native-strings && yarn translations-generate",
6128-
"lint": "eslint -c .eslintrc.js --report-unused-disable-directives src test ui .scripts",
6129-
"compile": "(yarn verify prep || yarn prep) && tsc --build tsconfig.json",
6130-
"watch": "(yarn verify prep || yarn prep )&& tsc --build tsconfig.json --watch",
6131-
"rebuild": "yarn clean && yarn prep && yarn compile",
6127+
"prep": "yarn prep:dts && yarn copy-walkthrough-media && yarn generate-native-strings && yarn translations-generate",
6128+
"lint": "yarn install && eslint -c .eslintrc.js --report-unused-disable-directives src test ui .scripts",
6129+
"compile": "yarn install && (yarn verify prep --quiet || yarn prep) && yarn build",
6130+
"watch": "yarn install && (yarn verify prep --quiet || yarn prep) && tsc --build tsconfig.json --watch",
6131+
"rebuild": "yarn install && yarn clean && yarn prep && yarn build",
61326132
"vscode:prepublish": "yarn clean && yarn webpack",
6133-
"webpack": "yarn prep && tsc --build ui.tsconfig.json && webpack --mode production --env vscode_nls",
6133+
"webpack": "yarn install && (yarn verify prep --quiet || yarn prep) && tsc --build ui.tsconfig.json && webpack --mode production --env vscode_nls",
61346134
"generate-native-strings": "ts-node -T ./.scripts/generateNativeStrings.ts",
61356135
"generate-options-schema": "ts-node -T ./.scripts/generateOptionsSchema.ts",
61366136
"copy-walkthrough-media": "ts-node -T ./.scripts/copyWalkthruMedia.ts",
61376137
"translations-export": "yarn generate-native-strings && gulp translations-export",
61386138
"translations-generate": "set NODE_OPTIONS=--no-experimental-fetch && gulp translations-generate",
61396139
"translations-import": "gulp translations-import",
61406140
"import-edge-strings": "ts-node -T ./.scripts/import_edge_strings.ts",
6141-
"postinstall": "npx vscode-dts dev && npx vscode-dts main && yarn prep"
6141+
"prep:dts": "yarn verify dts --quiet || (npx vscode-dts dev && npx vscode-dts main)",
6142+
"build": "yarn prep:dts && echo [Building TypeScript code] && tsc --build tsconfig.json"
61426143
},
61436144
"devDependencies": {
61446145
"@octokit/rest": "^18.12.0",

Extension/test/unit/commandLineParsing.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function marker() {
1717
try {
1818
throw new Error('Test Marker');
1919
} catch (E) {
20-
if (is.error(E)){
20+
if (is.error(E)) {
2121
return E.stack?.split('\n').filter(each => each.includes('.ts') && each.includes('<anonymous>')).join('\n');
2222
}
2323
}

0 commit comments

Comments
 (0)