Skip to content

Commit 57321cc

Browse files
committed
fix(workflow-code): keep one babel major so the app image builds
The app image installs the pruned workspace with bun's hoisted linker. With apps/sim on Babel 7 and workflow-code/workspace-code on Babel 8, @babel/types 7 was hoisted beside @babel/parser 8, so the parser's types resolved to the wrong major and `bun run build` failed in packages/sim-cli (TS2322/TS2345 on Node, Program and ParseResult<File>). Local and CI installs nest the copies, so no gate caught it; the image build on staging has failed since this merged. Return workflow-code, workspace-code and the root parser to Babel 7.29 with the AST code they had before, keeping commander 15, chalk 6 and the Node floor. Moving to Babel 8 belongs in one change that moves apps/sim as well.
1 parent 0e0d09c commit 57321cc

12 files changed

Lines changed: 53 additions & 61 deletions

File tree

‎bun.lock‎

Lines changed: 6 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
"@next/swc-linux-x64-gnu": "16.4.5"
186186
},
187187
"devDependencies": {
188-
"@babel/parser": "8.1.2",
188+
"@babel/parser": "7.29.9",
189189
"@biomejs/biome": "2.0.6",
190190
"@mdx-js/mdx": "3.1.1",
191191
"@octokit/rest": "^22.0.1",

‎packages/workflow-code/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@
7777
"test:watch": "vitest"
7878
},
7979
"dependencies": {
80-
"@babel/parser": "8.1.2",
80+
"@babel/parser": "7.29.9",
8181
"@noble/hashes": "2.2.0",
8282
"@sim/utils": "workspace:*",
8383
"@sim/workflow-types": "workspace:*"
8484
},
8585
"devDependencies": {
86-
"@babel/types": "8.1.2",
86+
"@babel/types": "7.29.8",
8787
"@sim/testing": "workspace:*",
8888
"@sim/tsconfig": "workspace:*",
8989
"@xyflow/react": "12.12.1",

‎packages/workflow-code/src/babel.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* The Babel AST walk and error reading shared by the compiler and the code-file reader.
33
*/
44

5-
import type { MemberExpression, Node, OptionalMemberExpression } from '@babel/types'
5+
import type { MemberExpression, Node } from '@babel/types'
66
import { isIndexSegment, isNameSegment, type RefSegment } from './code-files/ref-path'
77

88
/** The fields a thrown or recovered Babel error may carry. */
@@ -47,14 +47,9 @@ export function childNodes(node: Node): Node[] {
4747
return children
4848
}
4949

50-
/** Whether `node` is a member access, optional or not. */
51-
export function isMemberAccess(node: Node): node is MemberExpression | OptionalMemberExpression {
52-
return node.type === 'MemberExpression' || node.type === 'OptionalMemberExpression'
53-
}
54-
5550
/** The name a member access reads: `.name` or `['name']` (optional or not); `null` otherwise. */
5651
export function memberName(node: Node): string | null {
57-
if (!isMemberAccess(node)) return null
52+
if (node.type !== 'MemberExpression' && node.type !== 'OptionalMemberExpression') return null
5853
if (!node.computed && node.property.type === 'Identifier') return node.property.name
5954
return node.property.type === 'StringLiteral' ? node.property.value : null
6055
}

‎packages/workflow-code/src/code-files/from-file.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type ParserOptions, parse } from '@babel/parser'
2-
import type { MemberExpression, Node } from '@babel/types'
2+
import type { Expression, MemberExpression, Node } from '@babel/types'
33
import { isLikelyWorkflowReferenceSegment } from '@sim/utils/workflow-references'
44
import { babelErrorShape, childNodes, memberSegment } from '../babel'
55
import { ENV_VAR_NAME, formatStoredPath, type RefSegment } from './ref-path'
@@ -106,10 +106,7 @@ function isParenthesized(node: Node): boolean {
106106
}
107107

108108
/** The members of a chain, innermost first, and its root; stops at a parenthesized object. */
109-
function flattenChain(top: MemberExpression): {
110-
root: MemberExpression['object']
111-
members: MemberExpression[]
112-
} {
109+
function flattenChain(top: MemberExpression): { root: Expression; members: MemberExpression[] } {
113110
const members: MemberExpression[] = [top]
114111
let object = top.object
115112
while (object.type === 'MemberExpression' && !isParenthesized(object)) {
@@ -136,7 +133,7 @@ function envName(member: MemberExpression): string | null {
136133
* rooted at `$ref`/`$env` or maps no member.
137134
*/
138135
function chainReplacement(
139-
root: MemberExpression['object'],
136+
root: Expression,
140137
members: MemberExpression[]
141138
): { replacement: Replacement; consumed: number } | null {
142139
if (root.type !== 'Identifier' || members.length === 0) return null

‎packages/workflow-code/src/compile/function-returns.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import { parse } from '@babel/parser'
1717
import type { Expression, Node, ObjectExpression, PatternLike } from '@babel/types'
18-
import { childNodes, isMemberAccess, memberName } from '../babel'
18+
import { childNodes, memberName } from '../babel'
1919
import { parseStoredPath } from '../code-files/ref-path'
2020
import { toCodeFile } from '../code-files/to-file'
2121
import type { BlockKey, CanonicalBlock } from '../model'
@@ -295,9 +295,8 @@ class Inference {
295295
if (BOOLEAN_FUNCTIONS.has(callee.name)) return 'boolean'
296296
return undefined
297297
}
298-
if (!isMemberAccess(callee)) return undefined
299298
const method = memberName(callee)
300-
if (method === null) return undefined
299+
if (method === null || !('object' in callee)) return undefined
301300
if (callee.object.type === 'Identifier') {
302301
if (callee.object.name === 'Math') return this.isBuiltin('Math') ? 'number' : undefined
303302
const known = STATIC_KINDS[`${callee.object.name}.${method}`]
@@ -357,9 +356,8 @@ class Inference {
357356
private isArray(node: Node, strict = false): boolean {
358357
if (node.type === 'ArrayExpression') return true
359358
if (node.type === 'CallExpression' || node.type === 'OptionalCallExpression') {
360-
if (!isMemberAccess(node.callee)) return false
361359
const method = memberName(node.callee)
362-
if (method === null) return false
360+
if (method === null || !('object' in node.callee)) return false
363361
if (node.callee.object.type === 'Identifier' && node.callee.object.name === 'Object') {
364362
return (
365363
this.isBuiltin('Object') &&

‎packages/workflow-code/src/compile/hints.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export function hintForNode(node: Node): string {
112112
case 'YieldExpression':
113113
case 'ThisExpression':
114114
case 'Super':
115+
case 'Import':
115116
case 'ImportExpression':
116117
case 'MetaProperty':
117118
return HINTS.calls

‎packages/workflow-code/src/compile/values.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {
22
ArrayExpression,
33
CallExpression,
4+
Expression,
45
MemberExpression,
56
Node,
67
ObjectExpression,
@@ -532,10 +533,7 @@ function singleStringArgument(
532533
return { text, node: argument }
533534
}
534535

535-
function flattenMembers(node: MemberExpression): {
536-
root: MemberExpression['object']
537-
members: MemberExpression[]
538-
} {
536+
function flattenMembers(node: MemberExpression): { root: Expression; members: MemberExpression[] } {
539537
const members: MemberExpression[] = [node]
540538
let object = node.object
541539
while (object.type === 'MemberExpression') {

‎packages/workspace-code/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@
5353
"test:watch": "vitest"
5454
},
5555
"dependencies": {
56-
"@babel/parser": "8.1.2",
56+
"@babel/parser": "7.29.9",
5757
"@sim/table-cells": "workspace:*",
5858
"@sim/utils": "workspace:*",
5959
"@sim/workflow-code": "workspace:*"
6060
},
6161
"devDependencies": {
62-
"@babel/types": "8.1.2",
62+
"@babel/types": "7.29.8",
6363
"@sim/testing": "workspace:*",
6464
"@sim/tsconfig": "workspace:*",
6565
"@types/js-yaml": "4.0.9",

‎scripts/check-source-conventions.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,14 @@ function isBarrel(file: string): boolean {
209209
return /(?:^|\/)index\.tsx?$/.test(file)
210210
}
211211

212-
/** The specifier of `import('x')` or `require('x')`. */
212+
/** The specifier of `import('x')` or `require('x')`, in either AST shape Babel produces. */
213213
function dynamicSpecifier(node: Node): string | undefined {
214214
if (node.type === 'ImportExpression') return stringValue(node.source)
215215
if (node.type !== 'CallExpression') return undefined
216216
const callee = node.callee as Node
217-
const isRequire = callee.type === 'Identifier' && callee.name === 'require'
218-
return isRequire ? stringValue((node.arguments as Node[])[0]) : undefined
217+
const isImportOrRequire =
218+
callee.type === 'Import' || (callee.type === 'Identifier' && callee.name === 'require')
219+
return isImportOrRequire ? stringValue((node.arguments as Node[])[0]) : undefined
219220
}
220221

221222
/** The specifier of a static `import`, `import x = require()`, or `export … from`. */
@@ -272,7 +273,9 @@ function isBarrelReExport(node: Node, specifier: string, reExported: Set<string>
272273

273274
/** The specifier of a type-position `import('./x').T`. */
274275
function importTypeSpecifier(node: Node): string | undefined {
275-
return node.type === 'TSImportType' ? stringValue(node.source) : undefined
276+
if (node.type !== 'TSImportType') return undefined
277+
const argument = node.argument as Node
278+
return stringValue(argument.type === 'TSLiteralType' ? argument.literal : argument)
276279
}
277280

278281
function findRelativeImports(file: string, program: Node): Violation[] {

0 commit comments

Comments
 (0)