mirror of
https://github.com/dream-num/univer.git
synced 2026-10-16 15:17:56 +08:00
fix(examples): resolve dev locale imports to file URLs on Windows (#7751)
Co-authored-by: 白熱 <sonne@asaki.me>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import process from 'node:process';
|
||||
|
||||
import { resolveLocaleModuleUrl } from './locale-module-url.mts';
|
||||
|
||||
interface ILocaleModule {
|
||||
default?: unknown;
|
||||
}
|
||||
@@ -90,7 +92,12 @@ if (!isLocaleProduct(product) || !locale || !LOCALE_TAGS.has(locale)) {
|
||||
|
||||
const source = LOCALE_SOURCES[product];
|
||||
const packs = await Promise.all(source.packages.map(async (packageName) => {
|
||||
const module = await import(`${packageName}/${source.directory}/${locale}`) as ILocaleModule;
|
||||
// Import the resolved file:// URL instead of the bare specifier: on
|
||||
// Windows a bare dynamic import can degrade to a raw absolute path
|
||||
// (`C:\...`), which Node's ESM loader rejects with
|
||||
// ERR_UNSUPPORTED_ESM_URL_SCHEME.
|
||||
const moduleUrl = resolveLocaleModuleUrl(`${packageName}/${source.directory}/${locale}`);
|
||||
const module = await import(moduleUrl) as ILocaleModule;
|
||||
return unwrapDefault(module);
|
||||
}));
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Resolve a locale module specifier to a `file://` URL for dynamic import.
|
||||
*
|
||||
* The dev locale exporter used to pass the bare specifier straight to
|
||||
* `import()`. Under tsx on Windows that resolves to a raw absolute path like
|
||||
* `C:\...`, which Node's ESM loader rejects with
|
||||
* `ERR_UNSUPPORTED_ESM_URL_SCHEME` ("Received protocol 'c:'"). The failure
|
||||
* surfaces in the workbench as "Could not load <product> locale <tag>" on
|
||||
* every tab. Importing the resolved `file://` URL works on all platforms.
|
||||
*/
|
||||
export function resolveLocaleModuleUrl(specifier: string): string {
|
||||
return import.meta.resolve(specifier);
|
||||
}
|
||||
Reference in New Issue
Block a user