|
| 1 | +// ***************************************************************************** |
| 2 | +// Copyright (C) 2026 STMicroelectronics and others. |
| 3 | +// |
| 4 | +// This program and the accompanying materials are made available under the |
| 5 | +// terms of the Eclipse Public License v. 2.0 which is available at |
| 6 | +// http://www.eclipse.org/legal/epl-2.0. |
| 7 | +// |
| 8 | +// This Source Code may also be made available under the following Secondary |
| 9 | +// Licenses when the conditions for such availability set forth in the Eclipse |
| 10 | +// Public License v. 2.0 are satisfied: GNU General Public License, version 2 |
| 11 | +// with the GNU Classpath Exception which is available at |
| 12 | +// https://www.gnu.org/software/classpath/license.html. |
| 13 | +// |
| 14 | +// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 |
| 15 | +// ***************************************************************************** |
| 16 | + |
| 17 | +// ESM loader hooks to handle non-JS file extensions (e.g. .css) that |
| 18 | +// are imported by ESM dependencies such as @theia/monaco-editor-core. |
| 19 | +// Without this, Node's ESM resolver throws ERR_UNKNOWN_FILE_EXTENSION |
| 20 | +// which causes mocha's import-then-require fallback to partially execute |
| 21 | +// test files before retrying, leading to duplicate side effects. |
| 22 | + |
| 23 | +const STYLE_EXTENSIONS = ['.css', '.scss', '.sass', '.less']; |
| 24 | + |
| 25 | +export function resolve(specifier, context, nextResolve) { |
| 26 | + return nextResolve(specifier, context); |
| 27 | +} |
| 28 | + |
| 29 | +export function load(url, context, nextLoad) { |
| 30 | + if (STYLE_EXTENSIONS.some(ext => url.endsWith(ext))) { |
| 31 | + return { format: 'module', source: 'export default {};', shortCircuit: true }; |
| 32 | + } |
| 33 | + return nextLoad(url, context); |
| 34 | +} |
0 commit comments