diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-01-08 21:36:43 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-01-09 19:53:03 +0100 |
commit | d07e7b834831230b53860d0919a68edc2d36193d (patch) | |
tree | a1f2a021563ddff54f33341c475fc6c6eb787388 /scripts | |
parent | New configurations based on review comments (WIP) (diff) | |
download | sophie-d07e7b834831230b53860d0919a68edc2d36193d.tar.gz sophie-d07e7b834831230b53860d0919a68edc2d36193d.tar.zst sophie-d07e7b834831230b53860d0919a68edc2d36193d.zip |
build: Eslint fixes for multi-module project
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/build.js | 6 | ||||
-rw-r--r-- | scripts/update-electron-vendors.js | 14 | ||||
-rw-r--r-- | scripts/watch.js | 52 |
3 files changed, 46 insertions, 26 deletions
diff --git a/scripts/build.js b/scripts/build.js index ef2b998..1236a6c 100644 --- a/scripts/build.js +++ b/scripts/build.js | |||
@@ -1,8 +1,9 @@ | |||
1 | import { build as esbuildBuild } from 'esbuild'; | ||
2 | import { join } from 'path'; | 1 | import { join } from 'path'; |
2 | |||
3 | import { build as esbuildBuild } from 'esbuild'; | ||
3 | import { build as viteBuild } from 'vite'; | 4 | import { build as viteBuild } from 'vite'; |
4 | 5 | ||
5 | import { fileURLToDirname } from '../config/utils.js'; | 6 | import fileURLToDirname from '../config/fileURLToDirname.js'; |
6 | 7 | ||
7 | const thisDir = fileURLToDirname(import.meta.url); | 8 | const thisDir = fileURLToDirname(import.meta.url); |
8 | 9 | ||
@@ -12,6 +13,7 @@ const thisDir = fileURLToDirname(import.meta.url); | |||
12 | */ | 13 | */ |
13 | async function buildPackageEsbuild(packageName) { | 14 | async function buildPackageEsbuild(packageName) { |
14 | /** @type {{ default: import('esbuild').BuildOptions }} */ | 15 | /** @type {{ default: import('esbuild').BuildOptions }} */ |
16 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Read untyped config file. | ||
15 | const { default: config } = await import(`../packages/${packageName}/esbuild.config.js`); | 17 | const { default: config } = await import(`../packages/${packageName}/esbuild.config.js`); |
16 | return esbuildBuild(config); | 18 | return esbuildBuild(config); |
17 | } | 19 | } |
diff --git a/scripts/update-electron-vendors.js b/scripts/update-electron-vendors.js index 70d3afc..91cdb61 100644 --- a/scripts/update-electron-vendors.js +++ b/scripts/update-electron-vendors.js | |||
@@ -1,9 +1,10 @@ | |||
1 | import { execSync } from 'child_process'; | 1 | import { execSync } from 'child_process'; |
2 | import electronPath from 'electron'; | ||
3 | import { writeFile } from 'fs/promises'; | 2 | import { writeFile } from 'fs/promises'; |
4 | import { join } from 'path'; | 3 | import { join } from 'path'; |
5 | 4 | ||
6 | import { fileURLToDirname } from '../config/utils.js'; | 5 | import electronPath from 'electron'; |
6 | |||
7 | import fileURLToDirname from '../config/fileURLToDirname.js'; | ||
7 | 8 | ||
8 | const thisDir = fileURLToDirname(import.meta.url); | 9 | const thisDir = fileURLToDirname(import.meta.url); |
9 | 10 | ||
@@ -15,11 +16,12 @@ const thisDir = fileURLToDirname(import.meta.url); | |||
15 | * @returns {NodeJS.ProcessVersions} | 16 | * @returns {NodeJS.ProcessVersions} |
16 | */ | 17 | */ |
17 | function getVendors() { | 18 | function getVendors() { |
18 | const output = execSync(`${electronPath} -p "JSON.stringify(process.versions)"`, { | 19 | const output = execSync(`${electronPath.toString()} -p "JSON.stringify(process.versions)"`, { |
19 | env: { 'ELECTRON_RUN_AS_NODE': '1' }, | 20 | env: { ELECTRON_RUN_AS_NODE: '1' }, |
20 | encoding: 'utf-8', | 21 | encoding: 'utf-8', |
21 | }); | 22 | }); |
22 | 23 | ||
24 | // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- Read untyped output. | ||
23 | return JSON.parse(output); | 25 | return JSON.parse(output); |
24 | } | 26 | } |
25 | 27 | ||
@@ -39,10 +41,10 @@ function updateVendors() { | |||
39 | return Promise.all([ | 41 | return Promise.all([ |
40 | writeFile( | 42 | writeFile( |
41 | join(thisDir, '../.electron-vendors.cache.json'), | 43 | join(thisDir, '../.electron-vendors.cache.json'), |
42 | JSON.stringify({ | 44 | `${JSON.stringify({ |
43 | chrome: chromeMajorVersion, | 45 | chrome: chromeMajorVersion, |
44 | node: nodeMajorVersion, | 46 | node: nodeMajorVersion, |
45 | }, null, 2) + '\n', | 47 | }, null, 2)}\n`, |
46 | ), | 48 | ), |
47 | 49 | ||
48 | writeFile(browserslistrcPath, `Chrome ${chromeMajorVersion}\n`, 'utf8'), | 50 | writeFile(browserslistrcPath, `Chrome ${chromeMajorVersion}\n`, 'utf8'), |
diff --git a/scripts/watch.js b/scripts/watch.js index a61d3c8..1345a0f 100644 --- a/scripts/watch.js +++ b/scripts/watch.js | |||
@@ -1,11 +1,12 @@ | |||
1 | import { build as esbuildBuild } from 'esbuild'; | ||
2 | import { spawn } from 'child_process'; | 1 | import { spawn } from 'child_process'; |
2 | import { join } from 'path'; | ||
3 | |||
3 | import { watch } from 'chokidar'; | 4 | import { watch } from 'chokidar'; |
4 | import electronPath from 'electron'; | 5 | import electronPath from 'electron'; |
5 | import { join } from 'path'; | 6 | import { build as esbuildBuild } from 'esbuild'; |
6 | import { createServer } from 'vite'; | 7 | import { createServer } from 'vite'; |
7 | 8 | ||
8 | import { fileURLToDirname } from '../config/utils.js'; | 9 | import fileURLToDirname from '../config/fileURLToDirname.js'; |
9 | 10 | ||
10 | /** @type {string} */ | 11 | /** @type {string} */ |
11 | const thisDir = fileURLToDirname(import.meta.url); | 12 | const thisDir = fileURLToDirname(import.meta.url); |
@@ -35,6 +36,7 @@ const stderrIgnorePatterns = [ | |||
35 | */ | 36 | */ |
36 | async function setupEsbuildWatcher(packageName, extraPaths, callback) { | 37 | async function setupEsbuildWatcher(packageName, extraPaths, callback) { |
37 | /** @type {{ default: import('esbuild').BuildOptions }} */ | 38 | /** @type {{ default: import('esbuild').BuildOptions }} */ |
39 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Read untyped config file. | ||
38 | const { default: config } = await import(`../packages/${packageName}/esbuild.config.js`); | 40 | const { default: config } = await import(`../packages/${packageName}/esbuild.config.js`); |
39 | config.logLevel = 'info'; | 41 | config.logLevel = 'info'; |
40 | config.incremental = true; | 42 | config.incremental = true; |
@@ -45,7 +47,7 @@ async function setupEsbuildWatcher(packageName, extraPaths, callback) { | |||
45 | ...(extraPaths || []), | 47 | ...(extraPaths || []), |
46 | ]; | 48 | ]; |
47 | const watcher = watch(paths, { | 49 | const watcher = watch(paths, { |
48 | ignored: /(^|[\/\\])\.|__(tests|mocks)__|\.(spec|test)\.[jt]sx?$/, | 50 | ignored: /(^|[/\\])\.|__(tests|mocks)__|\.(spec|test)\.[jt]sx?$/, |
49 | ignoreInitial: true, | 51 | ignoreInitial: true, |
50 | persistent: true, | 52 | persistent: true, |
51 | }); | 53 | }); |
@@ -59,13 +61,26 @@ async function setupEsbuildWatcher(packageName, extraPaths, callback) { | |||
59 | callback(); | 61 | callback(); |
60 | } | 62 | } |
61 | }).catch((err) => { | 63 | }).catch((err) => { |
62 | const errCount = err.errors.length; | 64 | if (typeof err === 'object' && 'errors' in err) { |
65 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- We just checked. | ||
66 | const { errors } = err; | ||
67 | if (Array.isArray(errors)) { | ||
68 | const errCount = errors.length; | ||
69 | console.error( | ||
70 | '\ud83d\udd25', | ||
71 | errCount, | ||
72 | errCount > 1 ? 'errors' : 'error', | ||
73 | 'while rebuilding package', | ||
74 | packageName, | ||
75 | ); | ||
76 | return; | ||
77 | } | ||
78 | } | ||
63 | console.error( | 79 | console.error( |
64 | '\ud83d\udd25', | 80 | '\ud83d\udd25', |
65 | errCount, | 81 | 'error while rebuilding package', |
66 | errCount > 1 ? 'errors' : 'error', | ||
67 | 'while rebuilding package', | ||
68 | packageName, | 82 | packageName, |
83 | err, | ||
69 | ); | 84 | ); |
70 | }); | 85 | }); |
71 | }); | 86 | }); |
@@ -121,13 +136,14 @@ function setupServicePackageWatcher(packageName, sendEvent) { | |||
121 | */ | 136 | */ |
122 | function setupMainPackageWatcher(viteDevServer) { | 137 | function setupMainPackageWatcher(viteDevServer) { |
123 | // Write a value to an environment variable to pass it to the main process. | 138 | // Write a value to an environment variable to pass it to the main process. |
124 | const protocol = `http${viteDevServer.config.server.https ? 's' : ''}:`; | 139 | const { config: { server: { port, https, host } } } = viteDevServer; |
125 | const host = viteDevServer.config.server.host || 'localhost'; | 140 | const protocol = `http${https ? 's' : ''}:`; |
126 | const port = viteDevServer.config.server.port; | 141 | const hostOrDefault = typeof host === 'string' ? host : 'localhost'; |
127 | const path = '/'; | 142 | const portOrDefault = port || 3000; |
128 | process.env.VITE_DEV_SERVER_URL = `${protocol}//${host}:${port}${path}`; | 143 | process.env.VITE_DEV_SERVER_URL = `${protocol}//${hostOrDefault}:${portOrDefault}/`; |
129 | 144 | ||
130 | /** @type {import('child_process').ChildProcessByStdio<null, null, import('stream').Readable> | null} */ | 145 | /** @type {import('child_process').ChildProcessByStdio<null, null, import('stream').Readable> |
146 | | null} */ | ||
131 | let spawnProcess = null; | 147 | let spawnProcess = null; |
132 | 148 | ||
133 | return setupEsbuildWatcher( | 149 | return setupEsbuildWatcher( |
@@ -146,8 +162,8 @@ function setupMainPackageWatcher(viteDevServer) { | |||
146 | stdio: ['inherit', 'inherit', 'pipe'], | 162 | stdio: ['inherit', 'inherit', 'pipe'], |
147 | }); | 163 | }); |
148 | 164 | ||
149 | spawnProcess.stderr.on('data', (data) => { | 165 | spawnProcess.stderr.on('data', (/** @type {Buffer} */ data) => { |
150 | const stderrString = data.toString('utf-8').trimRight(); | 166 | const stderrString = data.toString('utf-8').trimEnd(); |
151 | if (!stderrIgnorePatterns.some((r) => r.test(stderrString))) { | 167 | if (!stderrIgnorePatterns.some((r) => r.test(stderrString))) { |
152 | console.error(stderrString); | 168 | console.error(stderrString); |
153 | } | 169 | } |
@@ -193,7 +209,7 @@ async function setupDevEnvironment() { | |||
193 | } | 209 | } |
194 | 210 | ||
195 | console.log('\ud83c\udf80 Sophie is starting up'); | 211 | console.log('\ud83c\udf80 Sophie is starting up'); |
196 | return setupMainPackageWatcher(viteDevServer); | 212 | await setupMainPackageWatcher(viteDevServer); |
197 | } | 213 | } |
198 | 214 | ||
199 | setupDevEnvironment().catch((err) => { | 215 | setupDevEnvironment().catch((err) => { |