Skip to content

Commit e50d76f

Browse files
Copilotkazrael2119
andauthored
Fix failing CI tests: apply PR #4585 changes and update missing test expectations
Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com>
1 parent 03b28c0 commit e50d76f

28 files changed

Lines changed: 50 additions & 255 deletions

packages/typespec-ts/src/framework/hooks/binder.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,13 @@ class BinderImp implements Binder {
5050
private project: Project;
5151
private dependencies: Record<string, ReferenceableSymbol>;
5252
private staticHelpers: Map<string, StaticHelperMetadata>;
53-
private useSubpathImports: boolean;
5453

5554
constructor(project: Project, options: BinderOptions = {}) {
5655
this.project = project;
5756

5857
provideDependencies(options.dependencies);
5958
this.staticHelpers = options.staticHelpers ?? new Map();
6059
this.dependencies = useDependencies();
61-
this.useSubpathImports = options.useSubpathImports ?? false;
6260
}
6361

6462
trackDeclaration(refkey: unknown, name: string, sourceFile: SourceFile): string {
@@ -185,27 +183,6 @@ class BinderImp implements Binder {
185183
return importSpecifier;
186184
}
187185

188-
/**
189-
* Returns the #platform/ subpath import specifier for a static helper file
190-
* that has a polyfill variant (-browser.mts or -react-native.mts sibling),
191-
* or undefined if subpath imports are disabled or no variant exists.
192-
* e.g. "src/static-helpers/serialization/get-binary-response.ts"
193-
* -> "#platform/static-helpers/serialization/get-binary-response"
194-
*/
195-
private getPlatformImportSpecifier(declarationSourceFile: SourceFile): string | undefined {
196-
if (!this.useSubpathImports) return undefined;
197-
const filePath = declarationSourceFile.getFilePath();
198-
const srcIndex = filePath.indexOf("/src/");
199-
if (srcIndex === -1) return undefined;
200-
// Check if a -browser.mts or -react-native.mts sibling exists
201-
const basePath = filePath.replace(/\.ts$/, "");
202-
const hasBrowserVariant = this.project.getSourceFile(basePath + "-browser.mts");
203-
const hasReactNativeVariant = this.project.getSourceFile(basePath + "-react-native.mts");
204-
if (!hasBrowserVariant && !hasReactNativeVariant) return undefined;
205-
const relativePath = filePath.substring(srcIndex + "/src/".length);
206-
return "#platform/" + relativePath.replace(/\.ts$/, "");
207-
}
208-
209186
/**
210187
* Applies all tracked imports to their respective source files.
211188
*/
@@ -316,9 +293,7 @@ class BinderImp implements Binder {
316293

317294
if (file !== declarationSourceFile) {
318295
this.trackReference(declarationKey, file);
319-
// Use #platform/ subpath import specifier for static helpers in warp packages
320-
const platformSpecifier = this.getPlatformImportSpecifier(declarationSourceFile);
321-
const importTarget = platformSpecifier ?? declarationSourceFile;
296+
const importTarget = declarationSourceFile;
322297
const importDec = this.addImport(file, importTarget, name);
323298
name = importDec.alias ?? name;
324299
}

packages/typespec-ts/src/framework/load-static-helpers.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ModularEmitterOptions } from "../modular/interfaces.js";
1313
import { resolveProjectRoot } from "../utils/resolve-project-root.js";
1414
import { refkey } from "./refkey.js";
1515
export const SourceFileSymbol = Symbol("SourceFile");
16+
1617
export interface StaticHelperMetadata {
1718
name: string;
1819
kind: "function" | "interface" | "typeAlias" | "class" | "enum";
@@ -94,22 +95,6 @@ export async function loadStaticHelpers(
9495
const addedFile = project.createSourceFile(targetPath, contents, {
9596
overwrite: true,
9697
});
97-
addedFile.getImportDeclarations().map((i) => {
98-
// Rewrite relative platform-types imports to #platform/ specifiers
99-
// so that browser/react-native variants are resolved via subpath imports.
100-
// Only rewrite imports to the default variant (not -browser/-react-native variants
101-
// which are already platform-specific direct imports).
102-
const specifier = i.getModuleSpecifierValue();
103-
if (
104-
specifier.startsWith(".") &&
105-
specifier.includes("platform-types") &&
106-
!specifier.includes("-browser") &&
107-
!specifier.includes("-react-native")
108-
) {
109-
i.setModuleSpecifier("#platform/static-helpers/platform-types");
110-
}
111-
});
112-
11398
for (const entry of Object.values(helpers)) {
11499
if (!addedFile.getFilePath().endsWith(entry.location)) {
115100
continue;

packages/typespec-ts/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
CreateRecorderHelpers,
2424
MultipartHelpers,
2525
PagingHelpers,
26-
PlatformTypeHelpers,
2726
PollingHelpers,
2827
SerializationHelpers,
2928
SimplePollerHelpers,
@@ -139,7 +138,6 @@ export async function $onEmit(context: EmitContext) {
139138
...SimplePollerHelpers,
140139
...UrlTemplateHelpers,
141140
...MultipartHelpers,
142-
...PlatformTypeHelpers,
143141
...CloudSettingHelpers,
144142
...XmlHelpers,
145143
...(resolvedEmitterOptions.generateTest ? CreateRecorderHelpers : {}),
@@ -165,7 +163,6 @@ export async function $onEmit(context: EmitContext) {
165163
dependencies: {
166164
...extraDependencies,
167165
},
168-
useSubpathImports: true,
169166
});
170167
provideSdkTypes(dpgContext);
171168

packages/typespec-ts/src/metadata/build-package-file.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ export function updatePackageFile(
131131
// Update Core Client dependency
132132
if (needsCoreClientUpdate) {
133133
delete deps["@azure/core-client"];
134-
if (!("@azure-rest/core-client" in deps)) {
135-
deps["@azure-rest/core-client"] = "^2.3.1";
136-
}
137134
packageInfo.dependencies = deps;
138135
}
139136

@@ -161,6 +158,14 @@ export function updatePackageFile(
161158
metadata.constantPaths = [...nonUserAgentPaths, ...newUserAgentPaths];
162159
}
163160

161+
// Always update @azure/core-rest-pipeline and @azure-rest/core-client to the latest
162+
// versions because our imports rely on APIs from those latest package versions.
163+
packageInfo.dependencies = {
164+
...packageInfo.dependencies,
165+
"@azure/core-rest-pipeline": "^1.24.0",
166+
"@azure-rest/core-client": "^2.7.0",
167+
};
168+
164169
return {
165170
path: "package.json",
166171
content: JSON.stringify(packageInfo, null, 2),

packages/typespec-ts/src/metadata/package-json/build-azure-monorepo-package.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ export function getAzureMonorepoDependencies(config: AzureMonorepoInfoConfig) {
3232
// revert this change after sdk repo update.
3333
const runtimeDeps = {
3434
...dependencies,
35-
"@azure-rest/core-client": "^2.3.1",
35+
"@azure-rest/core-client": "^2.7.0",
3636
...(hasLro && {
3737
"@azure/abort-controller": "^2.1.2",
3838
}),
3939
"@azure/core-auth": "^1.9.0",
4040
...(hasLro && {
4141
"@azure/core-lro": "^3.1.0",
4242
}),
43-
"@azure/core-rest-pipeline": "^1.20.0",
43+
"@azure/core-rest-pipeline": "^1.24.0",
4444
"@azure/core-util": "^1.12.0",
4545
"@azure/logger": "^1.2.0",
4646
tslib: "catalog:",

packages/typespec-ts/src/metadata/package-json/package-common.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,11 @@ function getEntryPointInformation(config: PackageCommonInfoConfig) {
4545
module: "./dist/esm/index.js",
4646
types: "./dist/commonjs/index.d.ts",
4747
browser: "./dist/browser/index.js",
48-
imports: {
49-
"#platform/*": {
50-
browser: "./src/*-browser.mts",
51-
default: "./src/*.ts",
52-
} as Record<string, string>,
53-
},
5448
exports: resolveWarpExports(config.exports, config.generateReactNativeTarget),
5549
};
5650

5751
if (config.generateReactNativeTarget) {
5852
result["react-native"] = "./dist/react-native/index.js";
59-
(result["imports"]["#platform/*"] as Record<string, string>)["react-native"] =
60-
"./src/*-react-native.mts";
61-
// Reorder so react-native comes before default
62-
const importsEntry = result["imports"]["#platform/*"] as Record<string, string>;
63-
result["imports"]["#platform/*"] = {
64-
browser: importsEntry["browser"],
65-
"react-native": importsEntry["react-native"],
66-
default: importsEntry["default"],
67-
};
6853
}
6954

7055
return result;

packages/typespec-ts/src/modular/build-root-index.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ import { SdkContext } from "../utils/interfaces.js";
1616
import { NameType, normalizeName } from "../utils/name-utils.js";
1717
import { getMethodHierarchiesMap } from "../utils/operation-util.js";
1818
import { partitionAndEmitExports } from "./build-subpath-index.js";
19+
import { AzureCoreDependencies } from "./external-dependencies.js";
1920
import { getClassicalClientName } from "./helpers/naming-helpers.js";
2021
import { isLroOnlyOperation } from "./helpers/operation-helpers.js";
2122
import { ModularEmitterOptions } from "./interfaces.js";
22-
import {
23-
CloudSettingHelpers,
24-
MultipartHelpers,
25-
PagingHelpers,
26-
PlatformTypeHelpers,
27-
} from "./static-helpers-metadata.js";
23+
import { CloudSettingHelpers, MultipartHelpers, PagingHelpers } from "./static-helpers-metadata.js";
2824

2925
export function buildRootIndex(
3026
context: SdkContext,
@@ -179,7 +175,7 @@ function exportFileContentsType(context: SdkContext, rootIndexFile: SourceFile)
179175
rootIndexFile,
180176
[
181177
resolveReference(MultipartHelpers.FileContents),
182-
resolveReference(PlatformTypeHelpers.NodeReadableStream),
178+
resolveReference(AzureCoreDependencies["NodeReadableStream"]),
183179
],
184180
true,
185181
);

packages/typespec-ts/src/modular/external-dependencies.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ export const AzureCoreDependencies: CoreDependencies = {
207207
name: "ErrorResponse",
208208
module: "@azure-rest/core-client",
209209
},
210+
getBinaryStreamResponse: {
211+
kind: "externalDependency",
212+
module: "@azure-rest/core-client",
213+
name: "getBinaryStreamResponse",
214+
},
215+
NodeReadableStream: {
216+
kind: "externalDependency",
217+
module: "@azure/core-rest-pipeline",
218+
name: "NodeReadableStream",
219+
},
210220
};
211221

212222
export const AzureIdentityDependencies = {

packages/typespec-ts/src/modular/helpers/operation-helpers.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import {
4848
KnownCollectionFormat,
4949
ServiceOperation,
5050
} from "../../utils/operation-util.js";
51-
import { AzurePollingDependencies } from "../external-dependencies.js";
51+
import { AzureCoreDependencies, AzurePollingDependencies } from "../external-dependencies.js";
5252
import {
5353
buildModelDeserializer,
5454
buildPropertyDeserializer,
@@ -70,7 +70,6 @@ import {
7070
} from "../serialization/serialize-utils.js";
7171
import {
7272
PagingHelpers,
73-
PlatformTypeHelpers,
7473
PollingHelpers,
7574
SerializationHelpers,
7675
StorageCompatHelpers,
@@ -1043,7 +1042,7 @@ export function getOperationFunction(
10431042
statements.push(`const ${streamableMethodVarName} = _${name}Send(${sendParameterList});`);
10441043
const binaryHelper =
10451044
wrapReturn && wrapReturnIsBinary
1046-
? SerializationHelpers.getBinaryStreamResponse
1045+
? AzureCoreDependencies["getBinaryStreamResponse"]
10471046
: SerializationHelpers.getBinaryResponse;
10481047
statements.push(
10491048
`const ${resultVarName} = await ${resolveReference(binaryHelper)}(${streamableMethodVarName});`,
@@ -3003,7 +3002,7 @@ export function buildNonModelResponseTypeDeclaration(
30033002
let typeBody: string;
30043003

30053004
if (isBinary) {
3006-
const nodeReadableStreamRef = resolveReference(PlatformTypeHelpers.NodeReadableStream);
3005+
const nodeReadableStreamRef = resolveReference(AzureCoreDependencies["NodeReadableStream"]);
30073006
typeBody = `{
30083007
/**
30093008
* BROWSER ONLY

packages/typespec-ts/src/modular/static-helpers-metadata.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ export const SerializationHelpers = {
5959
name: "getBinaryResponse",
6060
location: "serialization/get-binary-response.ts",
6161
},
62-
getBinaryStreamResponse: {
63-
kind: "function",
64-
name: "getBinaryStreamResponse",
65-
location: "serialization/get-binary-stream-response.ts",
66-
},
6762
areAllPropsUndefined: {
6863
kind: "function",
6964
name: "areAllPropsUndefined",
@@ -150,14 +145,6 @@ export const MultipartHelpers = {
150145
},
151146
} as const;
152147

153-
export const PlatformTypeHelpers = {
154-
NodeReadableStream: {
155-
kind: "typeAlias",
156-
name: "NodeReadableStream",
157-
location: "platform-types.ts",
158-
},
159-
} as const;
160-
161148
export const CloudSettingHelpers = {
162149
AzureClouds: {
163150
kind: "enum",

0 commit comments

Comments
 (0)