Skip to content

Commit 6d98cd0

Browse files
Merge --config hotfix back into main (microsoft#2289)
Co-authored-by: Mingzhe Huang <archerzz@users.noreply.github.com>
1 parent 1b8b27e commit 6d98cd0

File tree

27 files changed

+129
-63
lines changed

27 files changed

+129
-63
lines changed

common/config/rush/pnpm-lock.yaml

+20-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/best-practices/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939
"!dist/test/**"
4040
],
4141
"peerDependencies": {
42-
"@typespec/compiler": "workspace:~0.47.0"
42+
"@typespec/compiler": "workspace:~0.47.1"
4343
},
4444
"devDependencies": {
4545
"@types/mocha": "~10.0.1",
4646
"@types/node": "~18.11.9",
47-
"@typespec/compiler": "workspace:~0.47.0",
47+
"@typespec/compiler": "workspace:~0.47.1",
4848
"@typespec/eslint-config-typespec": "workspace:~0.47.0",
4949
"@typespec/eslint-plugin": "workspace:~0.47.0",
5050
"eslint": "^8.42.0",

packages/bundler/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"!dist/test/**"
3939
],
4040
"dependencies": {
41-
"@typespec/compiler": "workspace:~0.47.0",
41+
"@typespec/compiler": "workspace:~0.47.1",
4242
"@rollup/plugin-virtual": "~3.0.1",
4343
"@rollup/plugin-commonjs": "~25.0.0",
4444
"@rollup/plugin-json": "~6.0.0",

packages/compiler/CHANGELOG.json

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
{
22
"name": "@typespec/compiler",
33
"entries": [
4+
{
5+
"version": "0.47.1",
6+
"tag": "@typespec/compiler_v0.47.1",
7+
"date": "Thu, 10 Aug 2023 20:18:00 GMT",
8+
"comments": {
9+
"patch": [
10+
{
11+
"comment": "**Fix**: `--config` flag was being ignored."
12+
}
13+
]
14+
}
15+
},
416
{
517
"version": "0.47.0",
618
"tag": "@typespec/compiler_v0.47.0",

packages/compiler/CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Change Log - @typespec/compiler
22

3-
This log was last generated on Tue, 08 Aug 2023 22:32:10 GMT and should not be manually modified.
3+
This log was last generated on Thu, 10 Aug 2023 20:18:00 GMT and should not be manually modified.
4+
5+
## 0.47.1
6+
Thu, 10 Aug 2023 20:18:00 GMT
7+
8+
### Patches
9+
10+
- **Fix**: `--config` flag was being ignored.
411

512
## 0.47.0
613
Tue, 08 Aug 2023 22:32:10 GMT

packages/compiler/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typespec/compiler",
3-
"version": "0.47.0",
3+
"version": "0.47.1",
44
"description": "TypeSpec Compiler Preview",
55
"author": "Microsoft Corporation",
66
"license": "MIT",

packages/compiler/src/config/config-to-options.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createDiagnosticCollector, getDirectoryPath, normalizePath } from "../core/index.js";
22
import { CompilerOptions } from "../core/options.js";
33
import { CompilerHost, Diagnostic } from "../core/types.js";
4-
import { deepClone, omitUndefined } from "../core/util.js";
4+
import { deepClone, doIO, omitUndefined } from "../core/util.js";
55
import { expandConfigVariables } from "./config-interpolation.js";
66
import { loadTypeSpecConfigForPath, validateConfigPathsAbsolute } from "./config-loader.js";
77
import { EmitterOptions, TypeSpecConfig } from "./types.js";
@@ -45,11 +45,10 @@ export async function resolveCompilerOptions(
4545
const cwd = normalizePath(options.cwd ?? process.cwd());
4646
const diagnostics = createDiagnosticCollector();
4747

48-
const entrypointStat = await host.stat(options.entrypoint);
48+
const entrypointStat = await doIO(host.stat, options.entrypoint, (diag) => diagnostics.add(diag));
4949
const configPath =
50-
options.configPath ?? entrypointStat.isDirectory()
51-
? options.entrypoint
52-
: getDirectoryPath(options.entrypoint);
50+
options.configPath ??
51+
(entrypointStat?.isDirectory() ? options.entrypoint : getDirectoryPath(options.entrypoint));
5352
const config = await loadTypeSpecConfigForPath(host, configPath);
5453
config.diagnostics.forEach((x) => diagnostics.add(x));
5554

packages/compiler/test/config/config.test.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { deepStrictEqual, strictEqual } from "assert";
2-
import { dirname, join, resolve } from "path";
2+
import { dirname, join } from "path";
33
import { fileURLToPath } from "url";
44
import { TypeSpecConfigJsonSchema } from "../../src/config/config-schema.js";
55
import { TypeSpecRawConfig, loadTypeSpecConfigForPath } from "../../src/config/index.js";
66
import { createSourceFile } from "../../src/core/diagnostics.js";
77
import { NodeHost } from "../../src/core/node-host.js";
88
import { createJSONSchemaValidator } from "../../src/core/schema-validator.js";
9+
import { resolvePath } from "../../src/index.js";
910

10-
const __dirname = dirname(fileURLToPath(import.meta.url));
11+
const scenarioRoot = resolvePath(
12+
dirname(fileURLToPath(import.meta.url)),
13+
"../../../test/config/scenarios"
14+
);
1115

1216
describe("compiler: config file loading", () => {
1317
describe("file discovery", () => {
14-
const scenarioRoot = resolve(__dirname, "../../../test/config/scenarios");
1518
const loadTestConfig = async (path: string, errorIfNotFound: boolean = true) => {
1619
const fullPath = join(scenarioRoot, path);
1720
const { filename, projectRoot, ...config } = await loadTypeSpecConfigForPath(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { deepStrictEqual } from "assert";
2+
import { dirname } from "path";
3+
import { fileURLToPath } from "url";
4+
import { resolveCompilerOptions } from "../../src/config/index.js";
5+
import { NodeHost } from "../../src/core/node-host.js";
6+
import { resolvePath } from "../../src/index.js";
7+
import { expectDiagnosticEmpty, expectDiagnostics } from "../../src/testing/expect.js";
8+
9+
const scenarioRoot = resolvePath(
10+
dirname(fileURLToPath(import.meta.url)),
11+
"../../../test/config/scenarios"
12+
);
13+
14+
describe("compiler: resolve compiler options", () => {
15+
const tspOutputPath = resolvePath(`${process.cwd()}/tsp-output`);
16+
describe("specifying explicit config file", () => {
17+
const resolveOptions = async (path: string) => {
18+
const fullPath = resolvePath(scenarioRoot, path);
19+
return await resolveCompilerOptions(NodeHost, {
20+
entrypoint: fullPath, // not really used here
21+
configPath: fullPath,
22+
});
23+
};
24+
25+
it("loads config at the given path", async () => {
26+
const [options, diagnostics] = await resolveOptions("custom/myConfig.yaml");
27+
expectDiagnosticEmpty(diagnostics);
28+
29+
deepStrictEqual(options, {
30+
config: resolvePath(scenarioRoot, "custom/myConfig.yaml"),
31+
emit: ["openapi"],
32+
options: {},
33+
outputDir: tspOutputPath,
34+
});
35+
});
36+
37+
it("emit diagnostics", async () => {
38+
const [_, diagnostics] = await resolveOptions("not-found.yaml");
39+
expectDiagnostics(diagnostics, {
40+
code: "file-not-found",
41+
message: `File ${resolvePath(scenarioRoot, "not-found.yaml")} not found.`,
42+
});
43+
});
44+
});
45+
});

packages/html-program-viewer/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"!dist/test/**"
5252
],
5353
"peerDependencies": {
54-
"@typespec/compiler": "workspace:~0.47.0"
54+
"@typespec/compiler": "workspace:~0.47.1"
5555
},
5656
"dependencies": {
5757
"prettier": "~3.0.1",
@@ -65,7 +65,7 @@
6565
"@types/node": "~18.11.9",
6666
"@types/react": "~18.2.9",
6767
"@types/react-dom": "~18.2.4",
68-
"@typespec/compiler": "workspace:~0.47.0",
68+
"@typespec/compiler": "workspace:~0.47.1",
6969
"@typespec/eslint-config-typespec": "workspace:~0.47.0",
7070
"@babel/core": "^7.0.0",
7171
"eslint": "^8.42.0",

packages/http/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
"!dist/test/**"
5454
],
5555
"peerDependencies": {
56-
"@typespec/compiler": "workspace:~0.47.0"
56+
"@typespec/compiler": "workspace:~0.47.1"
5757
},
5858
"devDependencies": {
5959
"@types/mocha": "~10.0.1",
6060
"@types/node": "~18.11.9",
61-
"@typespec/compiler": "workspace:~0.47.0",
61+
"@typespec/compiler": "workspace:~0.47.1",
6262
"@typespec/eslint-config-typespec": "workspace:~0.47.0",
6363
"@typespec/library-linter": "workspace:~0.47.0",
6464
"@typespec/eslint-plugin": "workspace:~0.47.0",

packages/json-schema/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
"!dist/test/**"
4444
],
4545
"peerDependencies": {
46-
"@typespec/compiler": "workspace:~0.47.0"
46+
"@typespec/compiler": "workspace:~0.47.1"
4747
},
4848
"devDependencies": {
4949
"@types/mocha": "~10.0.1",
5050
"@types/node": "~18.11.9",
51-
"@typespec/compiler": "workspace:~0.47.0",
51+
"@typespec/compiler": "workspace:~0.47.1",
5252
"@typespec/library-linter": "workspace:~0.47.0",
5353
"@typespec/eslint-plugin": "workspace:~0.47.0",
5454
"@typespec/eslint-config-typespec": "workspace:~0.47.0",

0 commit comments

Comments
 (0)