diff --git a/ts/util/context.ts b/ts/util/context.ts index a18295ba3..8179b590b 100644 --- a/ts/util/context.ts +++ b/ts/util/context.ts @@ -22,12 +22,18 @@ */ declare const process: { platform: string }; +declare const exports: object; /** * True if there is a window object */ export const hasWindow = typeof window !== 'undefined'; +/** + * True if used from the cjs directory, false for mjs directory + */ +export const isCJS = typeof exports !== 'undefined'; + /** * The browsers window and document objects, if any */ @@ -75,6 +81,6 @@ export const context = { if (context.os === 'Windows') { context.path = (file: string) => file.match(/^[/\\]?[a-zA-Z]:[/\\]/) - ? 'file://' + file.replace(/\\/g, '/').replace(/^\//, '') + ? (isCJS ? '' : 'file://') + file.replace(/\\/g, '/').replace(/^\//, '') : file.replace(/^\//, 'file:///'); }