Skip to content

Commit 63ff276

Browse files
committed
Initial commit
1 parent a50ef63 commit 63ff276

File tree

8 files changed

+18
-19
lines changed

8 files changed

+18
-19
lines changed

.github/workflows/onnxruntime.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ jobs:
110110
WASM_OPTIMIZED_DIR=$(hash_dir packages/onnxruntime-builder/scripts/wasm-optimized)
111111
WASM_OPTIMIZED_HASH=$(echo "${WASM_RELEASE_HASH}${WASM_OPTIMIZED_DIR}" | shasum -a 256 | cut -d' ' -f1)
112112
113-
# wasm-synced
113+
# wasm-synced: wasm-optimized + wasm-synced + wasm-sync-wrapper.mjs (shared infra)
114114
WASM_SYNC_DIR=$(hash_dir packages/onnxruntime-builder/scripts/wasm-synced)
115-
WASM_SYNC_HASH=$(echo "${WASM_OPTIMIZED_HASH}${WASM_SYNC_DIR}" | shasum -a 256 | cut -d' ' -f1)
115+
WASM_SYNC_WRAPPER=$(shasum -a 256 packages/build-infra/wasm-synced/wasm-sync-wrapper.mjs | cut -d' ' -f1)
116+
WASM_SYNC_HASH=$(echo "${WASM_OPTIMIZED_HASH}${WASM_SYNC_DIR}${WASM_SYNC_WRAPPER}" | shasum -a 256 | cut -d' ' -f1)
116117
117118
# wasm-finalized
118119
WASM_FINAL_DIR=$(hash_dir packages/onnxruntime-builder/scripts/wasm-finalized)

.github/workflows/yoga-layout.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ jobs:
148148
WASM_OPTIMIZED_DIR=$(hash_dir packages/yoga-layout-builder/scripts/wasm-optimized)
149149
WASM_OPTIMIZED_HASH=$(echo "${WASM_RELEASE_HASH}${WASM_OPTIMIZED_DIR}" | shasum -a 256 | cut -d' ' -f1)
150150
151-
# wasm-synced: wasm-optimized + wasm-synced
151+
# wasm-synced: wasm-optimized + wasm-synced + wasm-sync-wrapper.mjs (shared infra)
152152
WASM_SYNC_DIR=$(hash_dir packages/yoga-layout-builder/scripts/wasm-synced)
153-
WASM_SYNC_HASH=$(echo "${WASM_OPTIMIZED_HASH}${WASM_SYNC_DIR}" | shasum -a 256 | cut -d' ' -f1)
153+
WASM_SYNC_WRAPPER=$(shasum -a 256 packages/build-infra/wasm-synced/wasm-sync-wrapper.mjs | cut -d' ' -f1)
154+
WASM_SYNC_HASH=$(echo "${WASM_OPTIMIZED_HASH}${WASM_SYNC_DIR}${WASM_SYNC_WRAPPER}" | shasum -a 256 | cut -d' ' -f1)
154155
155156
# wasm-finalized: wasm-synced + wasm-finalized (most complete hash)
156157
WASM_FINAL_DIR=$(hash_dir packages/yoga-layout-builder/scripts/wasm-finalized)

packages/build-infra/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"./lib/test-helpers": "./lib/test-helpers.mjs",
2929
"./lib/tool-installer": "./lib/tool-installer.mjs",
3030
"./lib/unicode-property-escape-transform": "./lib/unicode-property-escape-transform.mjs",
31-
"./lib/wasm-sync-wrapper": "./lib/wasm-sync-wrapper.mjs"
31+
"./wasm-synced/wasm-sync-wrapper": "./wasm-synced/wasm-sync-wrapper.mjs"
3232
},
3333
"scripts": {
3434
"test": "vitest run",

packages/build-infra/test-transform.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { fileURLToPath } from 'node:url'
99

1010
import { getDefaultLogger } from '@socketsecurity/lib/logger'
1111

12-
import { generateWasmSyncWrapper } from './lib/wasm-sync-wrapper.mjs'
12+
import { generateWasmSyncWrapper } from './wasm-synced/wasm-sync-wrapper.mjs'
1313

1414
const require = createRequire(import.meta.url)
1515
const logger = getDefaultLogger()

packages/build-infra/test-wasm-sync-generation.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { fileURLToPath } from 'node:url'
99

1010
import { getDefaultLogger } from '@socketsecurity/lib/logger'
1111

12-
import { generateWasmSyncWrapper } from './lib/wasm-sync-wrapper.mjs'
12+
import { generateWasmSyncWrapper } from './wasm-synced/wasm-sync-wrapper.mjs'
1313

1414
const __filename = fileURLToPath(import.meta.url)
1515
const __dirname = path.dirname(__filename)

packages/build-infra/lib/wasm-sync-wrapper.mjs renamed to packages/build-infra/wasm-synced/wasm-sync-wrapper.mjs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function generateWasmSyncWrapper(options) {
5454
outputSyncJs,
5555
packageName,
5656
wasmFile,
57-
} = options
57+
} = { __proto__: null, ...options }
5858

5959
if (!existsSync(wasmFile)) {
6060
throw new Error(`WASM file not found: ${wasmFile}`)
@@ -116,19 +116,19 @@ export async function generateWasmSyncWrapper(options) {
116116
s = new MagicString(mjsContent)
117117

118118
// Helpers: Safe transformations for minified code (may have overlapping mods)
119-
const safeRemove = (start, end) => {
119+
const safeOverwrite = (start, end, content) => {
120120
try {
121-
s.remove(start, end)
121+
s.overwrite(start, end, content)
122122
} catch {
123-
// Minified code - skip conflicting removes, leave as dead code
123+
// Minified code - skip conflicting overwrites
124124
}
125125
}
126126

127-
const safeOverwrite = (start, end, content) => {
127+
const safeRemove = (start, end) => {
128128
try {
129-
s.overwrite(start, end, content)
129+
s.remove(start, end)
130130
} catch {
131-
// Minified code - skip conflicting overwrites
131+
// Minified code - skip conflicting removes, leave as dead code
132132
}
133133
}
134134

@@ -141,19 +141,16 @@ export async function generateWasmSyncWrapper(options) {
141141
// 5. Remove top-level statements that fetch/load WASM asynchronously
142142

143143
const topLevelStatementsToRemove = []
144-
const _variableDeclaratorsToRemove = []
145144
const requireDeclaratorsToRemove = []
146145
const returnModuleToFix = []
147146
// Track functions that need WebAssembly.instantiate replacement
148147
const functionsToGut = []
149-
let _exportDefaultFound = false
150148
let exportDefaultIndex = -1
151149

152150
traverse(ast, {
153151
// Remove ALL export statements (convert ESM to CommonJS)
154152
ExportDefaultDeclaration(path) {
155153
if (path.parent.type === 'Program') {
156-
_exportDefaultFound = true
157154
// Find the index of this export in the program body
158155
const programBody = path.parent.body
159156
exportDefaultIndex = programBody.indexOf(path.node)

packages/onnxruntime-builder/scripts/wasm-synced/shared/generate-sync.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import path from 'node:path'
1010

1111
import { getFileSize } from 'build-infra/lib/build-helpers'
1212
import { createCheckpoint, shouldRun } from 'build-infra/lib/checkpoint-manager'
13-
import { generateWasmSyncWrapper } from 'build-infra/lib/wasm-sync-wrapper'
13+
import { generateWasmSyncWrapper } from 'build-infra/wasm-synced/wasm-sync-wrapper'
1414

1515
import { getDefaultLogger } from '@socketsecurity/lib/logger'
1616
import { hasKeys, isObjectObject } from '@socketsecurity/lib/objects'

packages/yoga-layout-builder/scripts/wasm-synced/shared/generate-sync.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import path from 'node:path'
1010

1111
import { getFileSize } from 'build-infra/lib/build-helpers'
1212
import { createCheckpoint, shouldRun } from 'build-infra/lib/checkpoint-manager'
13-
import { generateWasmSyncWrapper } from 'build-infra/lib/wasm-sync-wrapper'
13+
import { generateWasmSyncWrapper } from 'build-infra/wasm-synced/wasm-sync-wrapper'
1414

1515
import { getDefaultLogger } from '@socketsecurity/lib/logger'
1616
import { hasKeys, isObjectObject } from '@socketsecurity/lib/objects'

0 commit comments

Comments
 (0)