Skip to content

Commit

Permalink
fix-windows-env-issue-in-model-namespace-hierarchy (#3008)
Browse files Browse the repository at this point in the history
* fix-windows-env-issue-in-model-namespace-hierarchy

* fix ci

* Update packages/typespec-ts/src/modular/emitModels.ts
  • Loading branch information
qiaozha authored Jan 17, 2025
1 parent 36273e0 commit 5724011
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .scripts/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ stages:
vmImage: $[coalesce(variables['OSVmImage'], '')]
steps:
- template: build.yml
- script: node $(Build.SourcesDirectory)/common/scripts/install-run-rushx.js smoke-test:contoso
- script: node $(Build.SourcesDirectory)/common/scripts/install-run-rushx.js smoke-test:contoso && node $(Build.SourcesDirectory)/common/scripts/install-run-rushx.js smoke-test:todo
workingDirectory: $(Build.SourcesDirectory)/packages/typespec-test
displayName: "Generate Contoso Code From TypeSpec"

Expand Down
Empty file modified .vscode/launch.json
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions packages/typespec-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"scripts": {
"smoke-test": "node --max-old-space-size=4096 ./eng/smoke-test.js",
"smoke-test:contoso": "node --max-old-space-size=4096 ./eng/smoke-test.js -- contoso",
"smoke-test:todo": "node --max-old-space-size=4096 ./eng/smoke-test.js -- todo_non_branded",
"smoke-test:workers": "node ./eng/smoke-test-main.js",
"build": "echo skip",
"format": "echo skipped",
Expand Down
12 changes: 9 additions & 3 deletions packages/typespec-ts/src/modular/buildProjectFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,22 @@ export function getModuleExports(
function getModelSubpaths(emitterOptions: ModularEmitterOptions) {
const outputProject = useContext("outputProject");
const modelFiles = outputProject.getSourceFiles(
path.join(emitterOptions.modularOptions.sourceRoot, `models/**/*.ts`)
path.join(
emitterOptions.modularOptions.sourceRoot.replace(/\\/g, "/"),
`models/**/*.ts`
)
);
const subpath = new Set<string>();
for (const modelFile of modelFiles) {
const filepath = modelFile.getFilePath();
const filepath = modelFile.getFilePath().replace(/\\/g, "/");
if (!filepath.endsWith("index.ts")) {
continue;
}
subpath.add(
path.relative(emitterOptions.modularOptions.sourceRoot, filepath)
path.relative(
emitterOptions.modularOptions.sourceRoot.replace(/\\/g, "/"),
filepath
)
);
}
return Array.from(subpath);
Expand Down
14 changes: 9 additions & 5 deletions packages/typespec-ts/src/modular/buildRootIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,21 @@ function exportModules(
folders = project
.getDirectories()
.filter((dir) => {
const targetPath = join(srcPath, subfolder, moduleName);
return dir.getPath().replace(/\\/g, "/").startsWith(targetPath);
const formattedDir = dir.getPath().replace(/\\/g, "/");
const targetPath = join(srcPath, subfolder, moduleName).replace(
/\\/g,
"/"
);
return formattedDir.startsWith(targetPath);
})
.map((dir) => {
return dir.getPath();
return dir.getPath().replace(/\\/g, "/");
});
} else {
folders = [join(srcPath, subfolder, moduleName)];
folders = [join(srcPath, subfolder, moduleName).replace(/\\/g, "/")];
}
for (const folder of folders) {
const apiFilePattern = join(folder, "index.ts");
const apiFilePattern = join(folder, "index.ts").replace(/\\/g, "/");
const modelsFile = project.getSourceFile(apiFilePattern);
if (!modelsFile) {
continue;
Expand Down
14 changes: 9 additions & 5 deletions packages/typespec-ts/src/modular/buildSubpathIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ export function buildSubpathIndexFile(
folders = emitterOptions.project
.getDirectories()
.filter((dir) => {
const targetPath = join(srcPath, subfolder, subpath);
const formattedDir = dir.getPath().replace(/\\/g, "/");
const targetPath = join(srcPath, subfolder, subpath).replace(
/\\/g,
"/"
);
return (
dir.getPath().replace(/\\/g, "/").startsWith(targetPath) &&
!emitterOptions.project.getSourceFile(`${dir}/index.ts`)
formattedDir.startsWith(targetPath) &&
!emitterOptions.project.getSourceFile(`${formattedDir}/index.ts`)
);
})
.map((dir) => {
return dir.getPath();
return dir.getPath().replace(/\\/g, "/");
});
} else {
folders = [join(srcPath, subfolder, subpath)];
folders = [join(srcPath, subfolder, subpath).replace(/\\/g, "/")];
}
for (const folder of folders) {
const apiFilePattern =
Expand Down
3 changes: 2 additions & 1 deletion packages/typespec-ts/src/modular/emitModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ export function getModelNamespaces(
) {
if (
model.clientNamespace.startsWith("Azure.ResourceManager") ||
model.clientNamespace.startsWith("Azure.Core")
model.clientNamespace.startsWith("Azure.Core") ||
model.crossLanguageDefinitionId === "TypeSpec.Http.File" // filter out the TypeSpec.Http.File model similar like what java does here https://github.com/microsoft/typespec/blob/main/packages/http-client-java/emitter/src/code-model-builder.ts#L2589
) {
return [];
}
Expand Down

0 comments on commit 5724011

Please sign in to comment.