Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(tooling): normalize CRLF line endings in check-contract-shapes parsers
Purushotham-Prajapati-2481dc726dc86a
diff --git a/scripts/check-contract-shapes.mjs b/scripts/check-contract-shapes.mjsindex 4aa5031f0..93e758691 100644--- a/scripts/check-contract-shapes.mjs+++ b/scripts/check-contract-shapes.mjs@@ -486,6 +486,7 @@ const JAVA_MAPPING = {// ── hand-type parsing (declarations follow the regular formatting of the two files) ──export function parseHandTypes(source) {+ source = source.replace(/\r\n/g, '\n');const types = {};const parents = {};const iface = /export interface (\w+)(?: extends (\w+))? \{([\s\S]*?)\n\}/g;@@ -728,6 +729,7 @@ export function comparePair(handName, handMembers, schemaName, schema, schemas,* TypedDict inheritance (the parent's own total flag governs its members).*/export function parsePythonTypes(source) {+ source = source.replace(/\r\n/g, '\n');// Join continuation lines inside unclosed brackets so multi-line Literal[...] aliases and// annotations parse as one token (a truncated `Literal[` is worse than no token).const joined = [];@@ -915,6 +917,7 @@ function pythonToken(text, resolve, depth = 0) {* grouped per defined type produce enum tokens.*/export function parseGoTypes(sources) {+ sources = sources.map(s => s.replace(/\r\n/g, '\n'));const structs = {};const scalarAliases = {};const constGroups = {};@@ -993,6 +996,7 @@ export function parseGoTypes(sources) {* (the client config sets compareOptionality=false).*/export function parseJavaTypes(sources) {+ sources = sources.map(s => s.replace(/\r\n/g, '\n'));const records = {};const primMap = {String: 'string',diff --git a/scripts/check-contract-shapes.spec.mjs b/scripts/check-contract-shapes.spec.mjsindex acfeb84ce..37268243d 100644--- a/scripts/check-contract-shapes.spec.mjs+++ b/scripts/check-contract-shapes.spec.mjs@@ -28,7 +28,7 @@ import {const handSource = `export interface Sample {- id: string;+ id: string; // inline comment on fieldname?: string;direction: string;count: number | null;@@ -42,6 +42,15 @@ test('parseHandTypes reads required and optional members (a required field is noassert.equal(types.Sample.name.optional, true);});+test('parsers handle Windows CRLF line endings identically to LF', () => {+ const crlfHand = handSource.replace(/\n/g, '\r\n');+ assert.deepEqual(parseHandTypes(crlfHand), parseHandTypes(handSource));++ const pySource = 'class Sample(TypedDict):\n id: str\n name: NotRequired[str]\n';+ const crlfPy = pySource.replace(/\n/g, '\r\n');+ assert.deepEqual(parsePythonTypes(crlfPy), parsePythonTypes(pySource));+});+const schemas = {SampleDto: {type: 'object',@@ -280,7 +289,11 @@ test('parseJavaTypes: a bare UNKNOWN sentinel is not a wire member, an annotatedtest('isSimpleToken-gated diffing reaches inside an array of enum members', () => {const hand = { events: { optional: false, token: 'array<enum(a,b)>' } };- const schema = { type: 'object', required: ['events'], properties: { events: { type: 'array', items: { enum: ['a', 'c'] } } } };+ const schema = {+ type: 'object',+ required: ['events'],+ properties: { events: { type: 'array', items: { enum: ['a', 'c'] } } },+ };const diffs = comparePair('Hand', hand, 'Dto', schema, {});assert.equal(diffs.length, 1, 'a vocabulary that travels as a list must still be compared');assert.match(diffs[0], /events/);