Skip to content

Commit ad19177

Browse files
authored
Fix build issues (microsoft#474)
1. Fix `rush dogfood` 2. Fix `watch-tmlanguage` 3. Fix regen-samples running in parallel 4. Be consistent about utf-8 with readFile(Sync)
1 parent 669f2c9 commit ad19177

File tree

17 files changed

+71
-27
lines changed

17 files changed

+71
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@cadl-lang/compiler",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@cadl-lang/compiler"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@cadl-lang/internal-build-utils",
5+
"comment": "Make RunOptions optional",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@cadl-lang/internal-build-utils"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "cadl-vs",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "cadl-vs"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "cadl-vscode",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "cadl-vscode"
10+
}

eng/scripts/dogfood.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import { npmForEach, run } from "./helpers.js";
2+
run("rush", ["update"]);
23
run("rush", ["build"]);
34
npmForEach("dogfood");

eng/scripts/helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { dirname, join, resolve } from "path";
44
import { fileURLToPath } from "url";
55

66
function read(filename) {
7-
const txt = readFileSync(filename, "utf8")
7+
const txt = readFileSync(filename, "utf-8")
88
.replace(/\r/gm, "")
99
.replace(/\n/gm, "«")
1010
.replace(/\/\*.*?\*\//gm, "")
@@ -24,7 +24,7 @@ export function forEachProject(onEach) {
2424
for (const each of rush.projects) {
2525
const packageName = each.packageName;
2626
const projectFolder = resolve(`${repoRoot}/${each.projectFolder}`);
27-
const project = JSON.parse(readFileSync(`${projectFolder}/package.json`));
27+
const project = JSON.parse(readFileSync(`${projectFolder}/package.json`, "utf-8"));
2828
onEach(packageName, projectFolder, project);
2929
}
3030
}

packages/cadl-vs/scripts/build.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ async function main() {
1616
}
1717

1818
const pkgRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
19-
const file = await readFile(join(pkgRoot, "package.json"));
20-
const version = JSON.parse(file.toString()).version;
19+
const file = await readFile(join(pkgRoot, "package.json"), "utf-8");
20+
const version = JSON.parse(file).version;
2121

2222
const result = await getBuildTool();
2323
if (result.type === "dotnet") {

packages/cadl-vs/scripts/restore.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ import { fileURLToPath } from "url";
55

66
const pkgRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
77

8-
runDotnetOrExit(["restore", "Microsoft.Cadl.VS.sln"], { cwd: pkgRoot });
8+
await runDotnetOrExit(["restore", "Microsoft.Cadl.VS.sln"], { cwd: pkgRoot });

packages/cadl-vscode/scripts/dogfood.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { run } from "@cadl-lang/internal-build-utils";
33
import { readFileSync } from "fs";
44

5-
const version = JSON.parse(readFileSync("package.json").toString()).version;
5+
const version = JSON.parse(readFileSync("package.json", "utf-8")).version;
66
const vsix = `cadl-vscode-${version}.vsix`;
77

88
const options = {
@@ -12,5 +12,5 @@ const options = {
1212
};
1313

1414
for (const command of ["code", "code-insiders"]) {
15-
run(command, ["--install-extension", vsix], options);
15+
await run(command, ["--install-extension", vsix], options);
1616
}

packages/cadl-vscode/scripts/watch-tmlanguage.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { runWatch } from "@cadl-lang/internal-build-utils";
22
import { createRequire } from "module";
33
import { resolve } from "path";
4-
import watch from "watch";
54

65
const require = createRequire(import.meta.url);
76
const script = resolve("dist-dev/src/tmlanguage.js");
@@ -15,7 +14,7 @@ async function regenerate() {
1514
await require(script).main();
1615
}
1716

18-
runWatch(watch, "dist-dev/src", regenerate, {
17+
runWatch("dist-dev/src", regenerate, {
1918
// This filter doesn't do as much as one might hope because tsc writes out all
2019
// the files on recompilation. So tmlanguage.js changes when other .ts files
2120
// in cadl-vscode change but tmlanguage.ts has not changed. We could check the

packages/cadl-vscode/test/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ async function createOnigLib(): Promise<IOnigLib> {
1818
const registry = new Registry({
1919
onigLib: createOnigLib(),
2020
loadGrammar: async (scopeName) => {
21-
const data = await readFile(path.resolve(__dirname, "../../dist/cadl.tmLanguage"));
22-
return parseRawGrammar(data.toString());
21+
const data = await readFile(path.resolve(__dirname, "../../dist/cadl.tmLanguage"), "utf-8");
22+
return parseRawGrammar(data);
2323
},
2424
});
2525

packages/compiler/core/formatter.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ export async function findUnformattedCadlFiles(
8585
}
8686

8787
export async function formatCadlFile(filename: string) {
88-
const content = await readFile(filename);
88+
const content = await readFile(filename, "utf-8");
8989
const prettierConfig = await prettier.resolveConfig(filename);
90-
const formattedContent = await formatCadl(content.toString(), prettierConfig ?? {});
90+
const formattedContent = await formatCadl(content, prettierConfig ?? {});
9191
await writeFile(filename, formattedContent);
9292
}
9393

@@ -96,9 +96,9 @@ export async function formatCadlFile(filename: string) {
9696
* @returns true if code is formatted correctly.
9797
*/
9898
export async function checkFormatCadlFile(filename: string): Promise<boolean> {
99-
const content = await readFile(filename);
99+
const content = await readFile(filename, "utf-8");
100100
const prettierConfig = await prettier.resolveConfig(filename);
101-
return await checkFormatCadl(content.toString(), prettierConfig ?? {});
101+
return await checkFormatCadl(content, prettierConfig ?? {});
102102
}
103103

104104
async function findFiles(include: string[], ignore: string[] = []): Promise<string[]> {

packages/compiler/scripts/dogfood.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
import { run } from "@cadl-lang/internal-build-utils";
33
import { readFileSync } from "fs";
44

5-
const version = JSON.parse(readFileSync("package.json")).version;
6-
run("npm", ["pack"]);
7-
run("npm", ["install", "-g", `cadl-lang-compiler-${version}.tgz`]);
5+
const version = JSON.parse(readFileSync("package.json", "utf-8")).version;
6+
await run("npm", ["pack"]);
7+
await run("npm", ["install", "-g", `cadl-lang-compiler-${version}.tgz`]);

packages/compiler/test/formatter/scenarios/scenarios.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const shouldUpdate = process.argv.indexOf("--update-snapshots") !== -1;
2020

2121
async function getOutput(name: string): Promise<string | undefined> {
2222
try {
23-
const output = await readFile(join(scenarioRoot, "outputs", name));
24-
return output.toString();
23+
const output = await readFile(join(scenarioRoot, "outputs", name), "utf-8");
24+
return output;
2525
} catch {
2626
return undefined;
2727
}
@@ -34,9 +34,9 @@ async function saveOutput(name: string, content: string) {
3434
}
3535

3636
async function testScenario(name: string) {
37-
const content = await readFile(join(scenarioRoot, "inputs", name));
37+
const content = await readFile(join(scenarioRoot, "inputs", name), "utf-8");
3838
const output = await getOutput(name);
39-
const formatted = format(content.toString());
39+
const formatted = format(content);
4040
if (!output) {
4141
return await saveOutput(name, formatted);
4242
}

packages/internal-build-utils/src/common.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface RunOptions extends SpawnOptions {
1313
throwOnNonZeroExit?: boolean;
1414
}
1515

16-
export async function run(command: string, args: string[], options: RunOptions) {
16+
export async function run(command: string, args: string[], options?: RunOptions) {
1717
if (!options?.silent) {
1818
// eslint-disable-next-line no-console
1919
console.log();

packages/internal-build-utils/src/generate-third-party-notice.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async function getLicense(packageRoot: string) {
119119
for (const licenseName of ["LICENSE", "LICENSE.txt", "LICENSE.md", "LICENSE-MIT"]) {
120120
const licensePath = join(packageRoot, licenseName);
121121
try {
122-
let text = (await readFile(licensePath)).toString("utf-8");
122+
let text = await readFile(licensePath, "utf-8");
123123
text = text.replace("&lt;", "<");
124124
text = text.replace("&gt;", ">");
125125
return text;

packages/samples/scripts/regen-samples.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ const excludedSamples = [
2020

2121
const rootInputPath = resolvePath("../");
2222
const rootOutputPath = resolvePath("../test/output");
23-
main();
2423

25-
function main() {
24+
main().catch((e) => {
25+
console.error(e);
26+
process.exit(1);
27+
});
28+
29+
async function main() {
2630
// clear any previous output as otherwise failing to emit anything could
2731
// escape PR validation. Also ensures we delete output for samples that
2832
// no longer exist.
@@ -33,7 +37,7 @@ function main() {
3337
const outputPath = join(rootOutputPath, folderName);
3438
mkdirp(outputPath);
3539

36-
run(process.execPath, [
40+
await run(process.execPath, [
3741
"../../packages/compiler/dist/core/cli.js",
3842
"compile",
3943
inputPath,

0 commit comments

Comments
 (0)