@azure-tools/typespec-ts 0.55.0-dev.2 → 0.55.0-dev.4
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/README.md +96 -24
- package/dist/src/framework/hooks/binder.d.ts.map +1 -1
- package/dist/src/framework/hooks/binder.js +3 -4
- package/dist/src/framework/hooks/binder.js.map +1 -1
- package/dist/src/framework/load-static-helpers.d.ts +4 -1
- package/dist/src/framework/load-static-helpers.d.ts.map +1 -1
- package/dist/src/framework/load-static-helpers.js +19 -15
- package/dist/src/framework/load-static-helpers.js.map +1 -1
- package/dist/src/framework/sample.js +1 -1
- package/dist/src/framework/sample.js.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +47 -28
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.js +30 -31
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/build-project-files.d.ts.map +1 -1
- package/dist/src/modular/build-project-files.js +4 -4
- package/dist/src/modular/build-project-files.js.map +1 -1
- package/dist/src/modular/build-restore-poller.js +2 -2
- package/dist/src/modular/build-restore-poller.js.map +1 -1
- package/dist/src/modular/build-root-index.d.ts.map +1 -1
- package/dist/src/modular/build-root-index.js +5 -6
- package/dist/src/modular/build-root-index.js.map +1 -1
- package/dist/src/modular/build-subpath-index.d.ts.map +1 -1
- package/dist/src/modular/build-subpath-index.js +4 -4
- package/dist/src/modular/build-subpath-index.js.map +1 -1
- package/dist/src/modular/emit-models-options.js +2 -2
- package/dist/src/modular/emit-models-options.js.map +1 -1
- package/dist/src/modular/emit-models.d.ts.map +1 -1
- package/dist/src/modular/emit-models.js +2 -3
- package/dist/src/modular/emit-models.js.map +1 -1
- package/dist/src/modular/emit-samples.d.ts.map +1 -1
- package/dist/src/modular/emit-samples.js +3 -4
- package/dist/src/modular/emit-samples.js.map +1 -1
- package/dist/src/modular/emit-tests.d.ts +2 -1
- package/dist/src/modular/emit-tests.d.ts.map +1 -1
- package/dist/src/modular/emit-tests.js +21 -11
- package/dist/src/modular/emit-tests.js.map +1 -1
- package/dist/src/modular/helpers/example-value-helpers.js +4 -4
- package/dist/src/modular/helpers/example-value-helpers.js.map +1 -1
- package/dist/src/rlc-common/build-client-definitions.js +3 -3
- package/dist/src/rlc-common/build-client-definitions.js.map +1 -1
- package/dist/src/rlc-common/build-client.js +4 -4
- package/dist/src/rlc-common/build-client.js.map +1 -1
- package/dist/src/rlc-common/build-index-file.js +3 -3
- package/dist/src/rlc-common/build-index-file.js.map +1 -1
- package/dist/src/rlc-common/build-is-unexpected-helper.js +3 -3
- package/dist/src/rlc-common/build-is-unexpected-helper.js.map +1 -1
- package/dist/src/rlc-common/build-logger.js +3 -3
- package/dist/src/rlc-common/build-logger.js.map +1 -1
- package/dist/src/rlc-common/build-paginate-helper.js +2 -2
- package/dist/src/rlc-common/build-paginate-helper.js.map +1 -1
- package/dist/src/rlc-common/build-parameter-types.js +3 -3
- package/dist/src/rlc-common/build-parameter-types.js.map +1 -1
- package/dist/src/rlc-common/build-polling-helper.js +2 -2
- package/dist/src/rlc-common/build-polling-helper.js.map +1 -1
- package/dist/src/rlc-common/build-response-types.js +3 -3
- package/dist/src/rlc-common/build-response-types.js.map +1 -1
- package/dist/src/rlc-common/build-samples.js +2 -2
- package/dist/src/rlc-common/build-samples.js.map +1 -1
- package/dist/src/rlc-common/build-schema-type.js +4 -4
- package/dist/src/rlc-common/build-schema-type.js.map +1 -1
- package/dist/src/rlc-common/build-serialize-helper.js +2 -2
- package/dist/src/rlc-common/build-serialize-helper.js.map +1 -1
- package/dist/src/rlc-common/build-top-level-index-file.js +3 -3
- package/dist/src/rlc-common/build-top-level-index-file.js.map +1 -1
- package/dist/src/rlc-common/helpers/path-utils.d.ts.map +1 -1
- package/dist/src/rlc-common/helpers/path-utils.js +1 -2
- package/dist/src/rlc-common/helpers/path-utils.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-api-extractor-config.js +1 -1
- package/dist/src/rlc-common/metadata/build-api-extractor-config.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-es-lint-config.js +1 -1
- package/dist/src/rlc-common/metadata/build-es-lint-config.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-package-file.js +1 -1
- package/dist/src/rlc-common/metadata/build-package-file.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-readme-file.d.ts +2 -2
- package/dist/src/rlc-common/metadata/build-readme-file.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-readme-file.js +11 -14
- package/dist/src/rlc-common/metadata/build-readme-file.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-rollup-config.js +1 -1
- package/dist/src/rlc-common/metadata/build-rollup-config.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-ts-config.js +1 -1
- package/dist/src/rlc-common/metadata/build-ts-config.js.map +1 -1
- package/dist/src/transform/transform.d.ts.map +1 -1
- package/dist/src/transform/transform.js +2 -3
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/utils/emit-util.d.ts.map +1 -1
- package/dist/src/utils/emit-util.js +10 -5
- package/dist/src/utils/emit-util.js.map +1 -1
- package/dist/src/utils/file-system-utils.d.ts +4 -4
- package/dist/src/utils/file-system-utils.d.ts.map +1 -1
- package/dist/src/utils/file-system-utils.js +14 -16
- package/dist/src/utils/file-system-utils.js.map +1 -1
- package/dist/src/utils/import-helper.js +3 -3
- package/dist/src/utils/import-helper.js.map +1 -1
- package/dist/src/utils/resolve-project-root.d.ts +6 -4
- package/dist/src/utils/resolve-project-root.d.ts.map +1 -1
- package/dist/src/utils/resolve-project-root.js +11 -18
- package/dist/src/utils/resolve-project-root.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -26
- package/src/framework/hooks/binder.ts +3 -4
- package/src/framework/load-static-helpers.ts +29 -18
- package/src/framework/sample.ts +1 -1
- package/src/index.ts +61 -28
- package/src/lib.ts +31 -31
- package/src/modular/build-project-files.ts +11 -4
- package/src/modular/build-restore-poller.ts +2 -2
- package/src/modular/build-root-index.ts +5 -6
- package/src/modular/build-subpath-index.ts +4 -4
- package/src/modular/emit-models-options.ts +2 -2
- package/src/modular/emit-models.ts +2 -3
- package/src/modular/emit-samples.ts +3 -4
- package/src/modular/emit-tests.ts +28 -11
- package/src/modular/helpers/example-value-helpers.ts +4 -4
- package/src/rlc-common/build-client-definitions.ts +3 -3
- package/src/rlc-common/build-client.ts +4 -4
- package/src/rlc-common/build-index-file.ts +3 -3
- package/src/rlc-common/build-is-unexpected-helper.ts +3 -3
- package/src/rlc-common/build-logger.ts +3 -3
- package/src/rlc-common/build-paginate-helper.ts +2 -2
- package/src/rlc-common/build-parameter-types.ts +3 -3
- package/src/rlc-common/build-polling-helper.ts +2 -2
- package/src/rlc-common/build-response-types.ts +3 -3
- package/src/rlc-common/build-samples.ts +2 -2
- package/src/rlc-common/build-schema-type.ts +4 -4
- package/src/rlc-common/build-serialize-helper.ts +2 -2
- package/src/rlc-common/build-top-level-index-file.ts +3 -3
- package/src/rlc-common/helpers/path-utils.ts +1 -3
- package/src/rlc-common/metadata/build-api-extractor-config.ts +1 -1
- package/src/rlc-common/metadata/build-es-lint-config.ts +1 -1
- package/src/rlc-common/metadata/build-package-file.ts +1 -1
- package/src/rlc-common/metadata/build-readme-file.ts +12 -15
- package/src/rlc-common/metadata/build-rollup-config.ts +1 -1
- package/src/rlc-common/metadata/build-ts-config.ts +1 -1
- package/src/transform/transform.ts +2 -3
- package/src/utils/emit-util.ts +10 -8
- package/src/utils/file-system-utils.ts +14 -15
- package/src/utils/import-helper.ts +3 -3
- package/src/utils/resolve-project-root.ts +11 -24
- package/dist/src/utils/dirname.d.ts +0 -9
- package/dist/src/utils/dirname.d.ts.map +0 -1
- package/dist/src/utils/dirname.js +0 -12
- package/dist/src/utils/dirname.js.map +0 -1
- package/src/utils/dirname.ts +0 -12
package/src/utils/emit-util.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { CompilerHost, NoTarget, Program } from "@typespec/compiler";
|
|
2
|
-
import { dirname, join } from "path";
|
|
1
|
+
import { CompilerHost, getDirectoryPath, joinPaths, NoTarget, Program } from "@typespec/compiler";
|
|
3
2
|
import { format } from "prettier";
|
|
3
|
+
import prettierPluginBabel from "prettier/plugins/babel";
|
|
4
|
+
import prettierPluginEstree from "prettier/plugins/estree";
|
|
5
|
+
import prettierPluginTypescript from "prettier/plugins/typescript";
|
|
4
6
|
import { prettierJSONOptions, prettierTypeScriptOptions, reportDiagnostic } from "../lib.js";
|
|
5
7
|
import {
|
|
6
8
|
buildSchemaTypes,
|
|
@@ -58,7 +60,7 @@ async function emitFile(
|
|
|
58
60
|
return;
|
|
59
61
|
}
|
|
60
62
|
const host: CompilerHost = program.host;
|
|
61
|
-
const filePath =
|
|
63
|
+
const filePath = joinPaths(emitterOutputDir ?? "", file.path);
|
|
62
64
|
const isJson = /\.json$/gi.test(filePath);
|
|
63
65
|
const isSourceCode = /\.(ts|js)$/gi.test(filePath);
|
|
64
66
|
const microsoftHeader = isAzureFlavor ? `// Copyright (c) Microsoft Corporation.\n` : "";
|
|
@@ -71,10 +73,10 @@ async function emitFile(
|
|
|
71
73
|
// Format the contents if necessary
|
|
72
74
|
if (isJson || isSourceCode) {
|
|
73
75
|
try {
|
|
74
|
-
prettierFileContent = await format(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
);
|
|
76
|
+
prettierFileContent = await format(prettierFileContent, {
|
|
77
|
+
...(isJson ? prettierJSONOptions : prettierTypeScriptOptions),
|
|
78
|
+
plugins: [prettierPluginTypescript, prettierPluginEstree, prettierPluginBabel],
|
|
79
|
+
});
|
|
78
80
|
} catch (e) {
|
|
79
81
|
reportDiagnostic(program, {
|
|
80
82
|
code: "file-formatting-error",
|
|
@@ -87,6 +89,6 @@ async function emitFile(
|
|
|
87
89
|
// Continue with unformatted content rather than crashing
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
|
-
await host.mkdirp(
|
|
92
|
+
await host.mkdirp(getDirectoryPath(filePath));
|
|
91
93
|
await host.writeFile(filePath, prettierFileContent);
|
|
92
94
|
}
|
|
@@ -1,49 +1,48 @@
|
|
|
1
|
-
import { NoTarget, Program } from "@typespec/compiler";
|
|
2
|
-
import { mkdir, readdir, rm, stat } from "fs/promises";
|
|
3
|
-
import { resolve } from "path";
|
|
1
|
+
import { NoTarget, Program, resolvePath, type CompilerHost } from "@typespec/compiler";
|
|
4
2
|
import { reportDiagnostic } from "../lib.js";
|
|
5
3
|
|
|
6
|
-
export async function pathExists(targetPath: string): Promise<boolean> {
|
|
4
|
+
export async function pathExists(host: CompilerHost, targetPath: string): Promise<boolean> {
|
|
7
5
|
try {
|
|
8
|
-
await stat(targetPath);
|
|
6
|
+
await host.stat(targetPath);
|
|
9
7
|
return true;
|
|
10
8
|
} catch {
|
|
11
9
|
return false;
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
export async function emptyDir(dirPath: string): Promise<void> {
|
|
13
|
+
export async function emptyDir(host: CompilerHost, dirPath: string): Promise<void> {
|
|
16
14
|
let entries: string[];
|
|
17
15
|
try {
|
|
18
|
-
entries = await
|
|
16
|
+
entries = await host.readDir(dirPath);
|
|
19
17
|
} catch {
|
|
20
|
-
await
|
|
18
|
+
await host.mkdirp(dirPath);
|
|
21
19
|
return;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
await Promise.all(
|
|
25
|
-
entries.map((entry) => rm(
|
|
23
|
+
entries.map((entry) => host.rm(resolvePath(dirPath, entry), { recursive: true })),
|
|
26
24
|
);
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
export async function clearDirectory(
|
|
28
|
+
host: CompilerHost,
|
|
30
29
|
dirPath: string,
|
|
31
30
|
excludeNames: string[] = [],
|
|
32
31
|
program?: Program,
|
|
33
32
|
): Promise<void> {
|
|
34
|
-
if (!(await pathExists(dirPath))) {
|
|
33
|
+
if (!(await pathExists(host, dirPath))) {
|
|
35
34
|
return;
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
// If no exclude names, just use regular emptyDir for efficiency
|
|
39
38
|
if (excludeNames.length === 0) {
|
|
40
|
-
await emptyDir(dirPath);
|
|
39
|
+
await emptyDir(host, dirPath);
|
|
41
40
|
return;
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
try {
|
|
45
44
|
// Get all subdirectories and files
|
|
46
|
-
const entries = await
|
|
45
|
+
const entries = await host.readDir(dirPath);
|
|
47
46
|
|
|
48
47
|
// Filter entries to exclude those that should be preserved
|
|
49
48
|
const filteredEntries = entries.filter((entry) => {
|
|
@@ -52,8 +51,8 @@ export async function clearDirectory(
|
|
|
52
51
|
|
|
53
52
|
// Process each entry
|
|
54
53
|
for (const entry of filteredEntries) {
|
|
55
|
-
const entryPath =
|
|
56
|
-
await rm(entryPath, { recursive: true
|
|
54
|
+
const entryPath = resolvePath(dirPath, entry);
|
|
55
|
+
await host.rm(entryPath, { recursive: true });
|
|
57
56
|
}
|
|
58
57
|
} catch (error) {
|
|
59
58
|
// If there's an error, fall back to regular emptyDir
|
|
@@ -64,6 +63,6 @@ export async function clearDirectory(
|
|
|
64
63
|
target: NoTarget,
|
|
65
64
|
});
|
|
66
65
|
}
|
|
67
|
-
await emptyDir(dirPath);
|
|
66
|
+
await emptyDir(host, dirPath);
|
|
68
67
|
}
|
|
69
68
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDirectoryPath, getRelativePathFromDirectory, resolvePath } from "@typespec/compiler";
|
|
2
2
|
import { SourceFile } from "ts-morph";
|
|
3
3
|
import { useContext } from "../context-manager.js";
|
|
4
4
|
|
|
@@ -20,7 +20,7 @@ export function addImportBySymbol(symbol: string, currentFile: SourceFile) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// Resolve absolute path and compute a relative path from the current file to the module.
|
|
23
|
-
const moduleAbsolutePath =
|
|
23
|
+
const moduleAbsolutePath = resolvePath(modulePath);
|
|
24
24
|
const relativeImportPath = getRelativeImportPath(currentFile.getFilePath(), moduleAbsolutePath)
|
|
25
25
|
.replace(/\\/g, "/")
|
|
26
26
|
.replace(/\.ts$/, ".js");
|
|
@@ -53,7 +53,7 @@ export function addImportBySymbol(symbol: string, currentFile: SourceFile) {
|
|
|
53
53
|
* @returns {string} The relative path adjusted for import syntax.
|
|
54
54
|
*/
|
|
55
55
|
function getRelativeImportPath(from: string, to: string) {
|
|
56
|
-
const relativePath =
|
|
56
|
+
const relativePath = getRelativePathFromDirectory(getDirectoryPath(from), to, false);
|
|
57
57
|
// Adjust the path format to TypeScript module syntax
|
|
58
58
|
return relativePath.startsWith(".") ? relativePath : "./" + relativePath;
|
|
59
59
|
}
|
|
@@ -1,28 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, resolve } from "path";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
1
|
+
import { resolvePath } from "@typespec/compiler";
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Returns the package root directory for the emitter.
|
|
5
|
+
*
|
|
6
|
+
* The compiled output lives at `dist/src/utils/resolve-project-root.js`,
|
|
7
|
+
* so the package root is 3 levels up. This avoids filesystem access,
|
|
8
|
+
* making it compatible with virtual file systems (e.g., the playground).
|
|
9
9
|
*/
|
|
10
|
-
export function resolveProjectRoot(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (existsSync(packageJsonPath)) {
|
|
16
|
-
return currentDir; // Return the directory containing the package.json
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const parentDir = resolve(currentDir, "..");
|
|
20
|
-
|
|
21
|
-
if (parentDir === currentDir) {
|
|
22
|
-
// If we've reached the root directory and haven't found package.json
|
|
23
|
-
throw new Error("Could not find package.json");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Recursively search the parent directory
|
|
27
|
-
return resolveProjectRoot(parentDir);
|
|
10
|
+
export function resolveProjectRoot(): string {
|
|
11
|
+
// Use the global URL constructor (works in both Node.js and browsers)
|
|
12
|
+
const currentDir = new URL(".", import.meta.url).pathname;
|
|
13
|
+
// From dist/src/utils/ -> package root (3 levels: utils -> src -> dist -> root)
|
|
14
|
+
return resolvePath(currentDir, "../../..");
|
|
28
15
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dirname.d.ts","sourceRoot":"","sources":["../../../src/utils/dirname.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM;;;EAIzC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { fileURLToPath } from "url";
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param metaUrl usually import.meta.url
|
|
6
|
-
*/
|
|
7
|
-
export function getDirname(metaUrl) {
|
|
8
|
-
const __filename = fileURLToPath(metaUrl);
|
|
9
|
-
const __dirname = path.dirname(__filename);
|
|
10
|
-
return { __dirname, __filename };
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=dirname.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dirname.js","sourceRoot":"","sources":["../../../src/utils/dirname.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC3C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AACnC,CAAC"}
|
package/src/utils/dirname.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { fileURLToPath } from "url";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param metaUrl usually import.meta.url
|
|
7
|
-
*/
|
|
8
|
-
export function getDirname(metaUrl: string) {
|
|
9
|
-
const __filename = fileURLToPath(metaUrl);
|
|
10
|
-
const __dirname = path.dirname(__filename);
|
|
11
|
-
return { __dirname, __filename };
|
|
12
|
-
}
|