aglinxinyuan commented on code in PR #4997:
URL: https://github.com/apache/texera/pull/4997#discussion_r3231683951


##########
frontend/src/jsdom-svg-polyfill.ts:
##########
@@ -17,128 +17,169 @@
  * under the License.
  */
 
-/**
- * jsdom doesn't implement the SVG geometry APIs 
(`SVGSVGElement#createSVGMatrix`,
- * `createSVGPoint`, `createSVGTransform`, `getScreenCTM`, `getCTM`,
- * `getBBox`). jointjs reaches into these during graph layout and crashes
- * the spec build with `TypeError: svgDocument.createSVGMatrix is not a
- * function` etc.
- *
- * The stubs below return identity-ish geometry: matrices/points behave like
- * the identity, bounding boxes report zero dimensions. That's enough for
- * jointjs construction code to not throw; specs that actually depend on
- * accurate geometry should run under Vitest browser mode rather than
- * jsdom (tracked in #4861), but the bulk of the texera specs only need
- * jointjs to instantiate cleanly.
- */
+// Test-environment polyfills + setup hooks for jsdom + the Angular
+// `@angular/build:unit-test` builder. Pulled in via `setupFiles` in
+// `angular.json`. Each block below patches one specific gap that surfaces
+// when the codingame monaco-vscode-* v25 stack or jointjs runs under jsdom.
+
+// Node ESM loader hook so every transitive `.css` import resolves to an empty
+// module. The unit-test builder pre-bundles spec files with `externalPackages:
+// true`, so imports like `monaco-languageclient` reach Node's native ESM
+// loader instead of Vite's transform pipeline — without the hook, every spec
+// that transitively loads the codingame v25 stack crashes with
+// `Unknown file extension ".css"`. Inline as a `data:` URL so we don't carry
+// a sidecar `.mjs`. Vitest re-evaluates this setup file once per spec file,
+// so we gate the registration with a `globalThis` flag — `module.register`
+// chains every call, and we don't want N hooks doing identical work for N
+// specs. Must run before any spec body imports the affected packages;
+// `module.register` needs Node 20.6+ (project pins Node ≥ 24).
+import { register as registerLoader } from "node:module";
+
+const CSS_HOOK_FLAG = Symbol.for("texera.cssLoaderHookRegistered");
+const flagHolder = globalThis as Record<symbol, boolean | undefined>;
+if (!flagHolder[CSS_HOOK_FLAG]) {
+  const cssLoaderHookSource = `
+export function resolve(specifier, context, nextResolve) {
+  if (specifier.endsWith(".css") || /\\.css(\\?|$)/.test(specifier)) {
+    return { url: "data:text/javascript,export%20default%20%7B%7D%3B", 
shortCircuit: true, format: "module" };
+  }
+  return nextResolve(specifier, context);
+}
+`;

Review Comment:
   Good point — hardened in 67bcc5b863 (now 29cbba5a1c after rebase).
   
   Switched the CSS stub from `export default {}` to a `CSSStyleSheet`-shaped 
object mirroring our `InertCSSStyleSheet` polyfill:
   
   ```js
   const s = { cssRules: [] };
   s.replaceSync = () => {};
   s.replace = () => Promise.resolve();
   s.insertRule = () => 0;
   s.deleteRule = () => {};
   export default s;
   ```
   
   So if any transitive consumer in the codingame v25 `css-style-sheet` export 
form reads `.replaceSync` / `.cssRules` / `.replace` off the imported value, it 
now gets the methods that the polyfill exposes everywhere else in the test env.



##########
frontend/LICENSE-binary:
##########
@@ -290,11 +301,10 @@ Angular / npm packages:
   - [email protected]
   - [email protected]
   - [email protected]
-  - [email protected]
+  - [email protected]

Review Comment:
   False positive — `[email protected]` is in `yarn.lock` because it's the direct 
dep declared in `package.json`, but the production bundle only includes 
`[email protected]` (transitively, via `[email protected]`'s peer-pin). Confirmed 
by:
   
   \`\`\`
   $ node -e 
"console.log(require('./dist/3rdpartylicenses.json').filter(p=>p.name==='marked').map(p=>p.name+'@'+p.version))"
   [ '[email protected]' ]
   \`\`\`
   
   `LICENSE-binary` is intentionally aligned with what `license-webpack-plugin` 
records — i.e., what actually ships in `dist/`. 
`bin/licensing/check_binary_deps.py` flags drift between these two precisely so 
we don't list unbundled deps. So `[email protected]` shouldn't be in 
`LICENSE-binary`; it isn't bundled at runtime.
   
   If we want both versions reflected (e.g., a future code path imports the new 
one), the right fix is to reach into the source for an explicit use site so 
webpack pulls it in — not to amend `LICENSE-binary` ahead of that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to