aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/build-common.js28
-rw-r--r--config/esbuild-config.js17
2 files changed, 31 insertions, 14 deletions
diff --git a/config/build-common.js b/config/build-common.js
index aea2335..ff5a218 100644
--- a/config/build-common.js
+++ b/config/build-common.js
@@ -1,11 +1,17 @@
1// @ts-check 1import { readFileSync } from 'fs';
2import { dirname, join } from 'path';
3import { fileURLToPath } from 'url';
2 4
3// `resolveJsonModule` is disabled for this package, but vite will load the json nevertheless. 5const thisDir = fileURLToDirname(import.meta.url);
4// @ts-ignore 6
5const { chrome: chromeVersion, node: nodeVersion } = require('../.electron-vendors.cache.json'); 7// We import this from a vite config, where top-level await is not available (es2021),
8// so we have to use the synchronous filesystem API.
9const electronVendorsJson = readFileSync(join(thisDir, '../.electron-vendors.cache.json'), 'utf8');
10
11const { chrome: chromeVersion, node: nodeVersion } = JSON.parse(electronVendorsJson);
6 12
7/** @type {string} */ 13/** @type {string} */
8module.exports.banner = `/*! 14export const banner = `/*!
9 * Copyright (C) 2021-2022 Sophie contributors 15 * Copyright (C) 2021-2022 Sophie contributors
10 * 16 *
11 * This file is part of Sophie. 17 * This file is part of Sophie.
@@ -27,7 +33,15 @@ module.exports.banner = `/*!
27`; 33`;
28 34
29/** @type {string} */ 35/** @type {string} */
30module.exports.chrome = `chrome${chromeVersion}`; 36export const chrome = `chrome${chromeVersion}`;
31 37
32/** @type {string} */ 38/** @type {string} */
33module.exports.node = `node${nodeVersion}`; 39export const node = `node${nodeVersion}`;
40
41/**
42 * @param {string} url
43 * @returns {string}
44 */
45export function fileURLToDirname(url) {
46 return dirname(fileURLToPath(url));
47}
diff --git a/config/esbuild-config.js b/config/esbuild-config.js
index 9140b89..52d1a59 100644
--- a/config/esbuild-config.js
+++ b/config/esbuild-config.js
@@ -1,6 +1,4 @@
1// @ts-check 1import { banner } from './build-common.js';
2
3const { banner } = require('./build-common');
4 2
5/** @type {string} */ 3/** @type {string} */
6const mode = process.env.MODE || 'development'; 4const mode = process.env.MODE || 'development';
@@ -8,8 +6,10 @@ const mode = process.env.MODE || 'development';
8/** @type {boolean} */ 6/** @type {boolean} */
9const isDevelopment = mode === 'development'; 7const isDevelopment = mode === 'development';
10 8
9/** @type {string} */
11const modeString = JSON.stringify(mode); 10const modeString = JSON.stringify(mode);
12 11
12/** @type {Record<string, string>} */
13const defineEnv = { 13const defineEnv = {
14 'import.meta.env.DEV': JSON.stringify(isDevelopment), 14 'import.meta.env.DEV': JSON.stringify(isDevelopment),
15 'import.meta.env.MODE': modeString, 15 'import.meta.env.MODE': modeString,
@@ -20,13 +20,16 @@ const defineEnv = {
20 20
21/** 21/**
22 * @param {import('esbuild').BuildOptions} config 22 * @param {import('esbuild').BuildOptions} config
23 * @param {object | unknown} metaEnvVars 23 * @param {Record<string, string>} [metaEnvVars]
24 * @returns {import('esbuild').BuildOptions} 24 * @returns {import('esbuild').BuildOptions}
25 */ 25 */
26module.exports.getConfig = function(config, metaEnvVars) { 26export function getConfig(config, metaEnvVars) {
27 /** @type {Record<string, string>} */
27 const defineMeta = {}; 28 const defineMeta = {};
28 for (const varName in metaEnvVars) { 29 if (metaEnvVars) {
29 defineMeta[`import.meta.env.${varName}`] = JSON.stringify(metaEnvVars[varName]); 30 for (const varName in metaEnvVars) {
31 defineMeta[`import.meta.env.${varName}`] = JSON.stringify(metaEnvVars[varName]);
32 }
30 } 33 }
31 return { 34 return {
32 logLevel: 'info', 35 logLevel: 'info',