diff options
Diffstat (limited to 'config')
-rw-r--r-- | config/build-common.js | 28 | ||||
-rw-r--r-- | config/esbuild-config.js | 17 |
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 | 1 | import { readFileSync } from 'fs'; |
2 | import { dirname, join } from 'path'; | ||
3 | import { fileURLToPath } from 'url'; | ||
2 | 4 | ||
3 | // `resolveJsonModule` is disabled for this package, but vite will load the json nevertheless. | 5 | const thisDir = fileURLToDirname(import.meta.url); |
4 | // @ts-ignore | 6 | |
5 | const { 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. | ||
9 | const electronVendorsJson = readFileSync(join(thisDir, '../.electron-vendors.cache.json'), 'utf8'); | ||
10 | |||
11 | const { chrome: chromeVersion, node: nodeVersion } = JSON.parse(electronVendorsJson); | ||
6 | 12 | ||
7 | /** @type {string} */ | 13 | /** @type {string} */ |
8 | module.exports.banner = `/*! | 14 | export 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} */ |
30 | module.exports.chrome = `chrome${chromeVersion}`; | 36 | export const chrome = `chrome${chromeVersion}`; |
31 | 37 | ||
32 | /** @type {string} */ | 38 | /** @type {string} */ |
33 | module.exports.node = `node${nodeVersion}`; | 39 | export const node = `node${nodeVersion}`; |
40 | |||
41 | /** | ||
42 | * @param {string} url | ||
43 | * @returns {string} | ||
44 | */ | ||
45 | export 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 | 1 | import { banner } from './build-common.js'; |
2 | |||
3 | const { banner } = require('./build-common'); | ||
4 | 2 | ||
5 | /** @type {string} */ | 3 | /** @type {string} */ |
6 | const mode = process.env.MODE || 'development'; | 4 | const mode = process.env.MODE || 'development'; |
@@ -8,8 +6,10 @@ const mode = process.env.MODE || 'development'; | |||
8 | /** @type {boolean} */ | 6 | /** @type {boolean} */ |
9 | const isDevelopment = mode === 'development'; | 7 | const isDevelopment = mode === 'development'; |
10 | 8 | ||
9 | /** @type {string} */ | ||
11 | const modeString = JSON.stringify(mode); | 10 | const modeString = JSON.stringify(mode); |
12 | 11 | ||
12 | /** @type {Record<string, string>} */ | ||
13 | const defineEnv = { | 13 | const 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 | */ |
26 | module.exports.getConfig = function(config, metaEnvVars) { | 26 | export 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', |