aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/infrastructure/resources/impl
diff options
context:
space:
mode:
Diffstat (limited to 'packages/main/src/infrastructure/resources/impl')
-rw-r--r--packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.test.ts (renamed from packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.spec.ts)20
-rw-r--r--packages/main/src/infrastructure/resources/impl/getDistResources.ts6
2 files changed, 14 insertions, 12 deletions
diff --git a/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.spec.ts b/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.test.ts
index 635a6b4..c7c6e22 100644
--- a/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.spec.ts
+++ b/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.test.ts
@@ -20,10 +20,8 @@
20 20
21import os from 'node:os'; 21import os from 'node:os';
22 22
23import { each } from '@sophie/test-utils'; 23import Resources from '../../Resources.js';
24 24import getDistResources from '../getDistResources.js';
25import Resources from '../../Resources';
26import getDistResources from '../getDistResources';
27 25
28const defaultDevServerURL = 'http://localhost:3000/'; 26const defaultDevServerURL = 'http://localhost:3000/';
29 27
@@ -52,7 +50,7 @@ const [
52 50
53const fileURLs: [string, string] = [rendererIndexFileURL, rendererRootFileURL]; 51const fileURLs: [string, string] = [rendererIndexFileURL, rendererRootFileURL];
54 52
55each([ 53describe.each([
56 ['not in dev mode', false, undefined, ...fileURLs], 54 ['not in dev mode', false, undefined, ...fileURLs],
57 [ 55 [
58 'not in dev mode with VITE_DEV_SERVER_URL set', 56 'not in dev mode with VITE_DEV_SERVER_URL set',
@@ -68,12 +66,12 @@ each([
68 `${defaultDevServerURL}index.html`, 66 `${defaultDevServerURL}index.html`,
69 defaultDevServerURL, 67 defaultDevServerURL,
70 ], 68 ],
71]).describe( 69])(
72 'when %s', 70 'when %s',
73 ( 71 (
74 _description: string, 72 _description: string,
75 devMode: boolean, 73 devMode: boolean,
76 devServerURL: string, 74 devServerURL: string | undefined,
77 rendererIndexURL: string, 75 rendererIndexURL: string,
78 rendererRootURL: string, 76 rendererRootURL: string,
79 ) => { 77 ) => {
@@ -83,23 +81,23 @@ each([
83 resources = getDistResources(devMode, thisDir, devServerURL); 81 resources = getDistResources(devMode, thisDir, devServerURL);
84 }); 82 });
85 83
86 it('getPath should return the path to the requested resource', () => { 84 test('getPath returns the path to the requested resource', () => {
87 const path = resources.getPath('preload', 'index.cjs'); 85 const path = resources.getPath('preload', 'index.cjs');
88 expect(path).toBe(preloadIndexPath); 86 expect(path).toBe(preloadIndexPath);
89 }); 87 });
90 88
91 it('getFileURL should return the file URL to the requested resource', () => { 89 test('getFileURL returns the file URL to the requested resource', () => {
92 const url = resources.getFileURL('preload', 'index.cjs'); 90 const url = resources.getFileURL('preload', 'index.cjs');
93 expect(url).toBe(preloadIndexFileURL); 91 expect(url).toBe(preloadIndexFileURL);
94 }); 92 });
95 93
96 describe('getRendererURL', () => { 94 describe('getRendererURL', () => {
97 it('should return the URL to the requested resource', () => { 95 test('returns the URL to the requested resource', () => {
98 const url = resources.getRendererURL('index.html'); 96 const url = resources.getRendererURL('index.html');
99 expect(url).toBe(rendererIndexURL); 97 expect(url).toBe(rendererIndexURL);
100 }); 98 });
101 99
102 it('should return the root URL', () => { 100 test('returns the root URL', () => {
103 const url = resources.getRendererURL('/'); 101 const url = resources.getRendererURL('/');
104 expect(url).toBe(rendererRootURL); 102 expect(url).toBe(rendererRootURL);
105 }); 103 });
diff --git a/packages/main/src/infrastructure/resources/impl/getDistResources.ts b/packages/main/src/infrastructure/resources/impl/getDistResources.ts
index f3c3f7b..3b7827c 100644
--- a/packages/main/src/infrastructure/resources/impl/getDistResources.ts
+++ b/packages/main/src/infrastructure/resources/impl/getDistResources.ts
@@ -21,7 +21,7 @@
21import path from 'node:path'; 21import path from 'node:path';
22import { pathToFileURL, URL } from 'node:url'; 22import { pathToFileURL, URL } from 'node:url';
23 23
24import Resources from '../Resources'; 24import Resources from '../Resources.js';
25 25
26export default function getDistResources( 26export default function getDistResources(
27 devMode: boolean, 27 devMode: boolean,
@@ -33,6 +33,7 @@ export default function getDistResources(
33 devServerURL = import.meta.env?.VITE_DEV_SERVER_URL, 33 devServerURL = import.meta.env?.VITE_DEV_SERVER_URL,
34): Resources { 34): Resources {
35 const packagesRoot = path.join(thisDir, '..', '..'); 35 const packagesRoot = path.join(thisDir, '..', '..');
36 const localizationRoot = path.join(packagesRoot, '..', 'locales');
36 37
37 function getPath(packageName: string, relativePathInPackage: string): string { 38 function getPath(packageName: string, relativePathInPackage: string): string {
38 return path.join(packagesRoot, packageName, 'dist', relativePathInPackage); 39 return path.join(packagesRoot, packageName, 'dist', relativePathInPackage);
@@ -48,6 +49,9 @@ export default function getDistResources(
48 49
49 return { 50 return {
50 getPath, 51 getPath,
52 getLocalizationPath(language, fileName) {
53 return path.join(localizationRoot, language, fileName);
54 },
51 getFileURL, 55 getFileURL,
52 getRendererURL: 56 getRendererURL:
53 devMode && devServerURL !== undefined 57 devMode && devServerURL !== undefined