diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1ac7afc97..3a3de53a4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -72,7 +72,7 @@ jobs: npm config set //npm.nordicsemi.no/:_authToken $(WAYLAND_NPM_TOKEN_INTERNAL) npm ci npm run check - npm run build + npm run build:prod npm test condition: and(eq(variables['INTERNAL'], 'true'), contains(variables['IMAGE_NAME'], 'ubuntu')) displayName: 'Build with internal release [Linux]' @@ -85,7 +85,7 @@ jobs: npm config set //npm.nordicsemi.no/:_authToken $(WAYLAND_NPM_TOKEN_INTERNAL) npm ci npm run check - npm run build + npm run build:prod npm test condition: and(eq(variables['INTERNAL'], 'true'), contains(variables['IMAGE_NAME'], 'mac')) displayName: 'Build with internal release [macOS]' @@ -115,7 +115,7 @@ jobs: - script: | npm ci npm run check - npm run build + npm run build:prod npm test env: { ENABLE_DRAFT_TEST: true, @@ -131,7 +131,7 @@ jobs: set -o errexit -o pipefail npm ci npm run check - npm run build + npm run build:prod npm test condition: and(ne(variables['INTERNAL'], 'true'), not(contains(variables['IMAGE_NAME'], 'win'))) displayName: 'Build on not windows' @@ -142,7 +142,7 @@ jobs: npm config set node_gyp "C:\npm\prefix\node_modules\node-gyp\bin\node-gyp.js" npm ci npm run check - npm run build + npm run build:prod npm test condition: and(ne(variables['INTERNAL'], 'true'), contains(variables['IMAGE_NAME'], 'win')) displayName: 'Build on windows' diff --git a/esbuild.js b/esbuild.js new file mode 100644 index 000000000..9510c67e8 --- /dev/null +++ b/esbuild.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause + */ + +require('esbuild') + .build({ + bundle: true, + color: true, + entryPoints: ['src/main/index.js'], + external: ['electron', './node_modules/*'], + logLevel: 'info', + outfile: 'dist/main.js', + platform: 'node', + sourcemap: true, + watch: process.argv.includes('--watch'), + minify: process.argv.includes('--prod'), + }) + .catch(() => process.exit(1)); diff --git a/package-lock.json b/package-lock.json index 3fdd7e984..13ecc62bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12187,6 +12187,174 @@ "ext": "^1.1.2" } }, + "esbuild": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.14.49.tgz", + "integrity": "sha512-/TlVHhOaq7Yz8N1OJrjqM3Auzo5wjvHFLk+T8pIue+fhnhIMpfAzsG6PLVMbFveVxqD2WOp3QHei+52IMUNmCw==", + "dev": true, + "requires": { + "esbuild-android-64": "0.14.49", + "esbuild-android-arm64": "0.14.49", + "esbuild-darwin-64": "0.14.49", + "esbuild-darwin-arm64": "0.14.49", + "esbuild-freebsd-64": "0.14.49", + "esbuild-freebsd-arm64": "0.14.49", + "esbuild-linux-32": "0.14.49", + "esbuild-linux-64": "0.14.49", + "esbuild-linux-arm": "0.14.49", + "esbuild-linux-arm64": "0.14.49", + "esbuild-linux-mips64le": "0.14.49", + "esbuild-linux-ppc64le": "0.14.49", + "esbuild-linux-riscv64": "0.14.49", + "esbuild-linux-s390x": "0.14.49", + "esbuild-netbsd-64": "0.14.49", + "esbuild-openbsd-64": "0.14.49", + "esbuild-sunos-64": "0.14.49", + "esbuild-windows-32": "0.14.49", + "esbuild-windows-64": "0.14.49", + "esbuild-windows-arm64": "0.14.49" + } + }, + "esbuild-android-64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-android-64/-/esbuild-android-64-0.14.49.tgz", + "integrity": "sha512-vYsdOTD+yi+kquhBiFWl3tyxnj2qZJsl4tAqwhT90ktUdnyTizgle7TjNx6Ar1bN7wcwWqZ9QInfdk2WVagSww==", + "dev": true, + "optional": true + }, + "esbuild-android-arm64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.14.49.tgz", + "integrity": "sha512-g2HGr/hjOXCgSsvQZ1nK4nW/ei8JUx04Li74qub9qWrStlysaVmadRyTVuW32FGIpLQyc5sUjjZopj49eGGM2g==", + "dev": true, + "optional": true + }, + "esbuild-darwin-64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.49.tgz", + "integrity": "sha512-3rvqnBCtX9ywso5fCHixt2GBCUsogNp9DjGmvbBohh31Ces34BVzFltMSxJpacNki96+WIcX5s/vum+ckXiLYg==", + "dev": true, + "optional": true + }, + "esbuild-darwin-arm64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.49.tgz", + "integrity": "sha512-XMaqDxO846srnGlUSJnwbijV29MTKUATmOLyQSfswbK/2X5Uv28M9tTLUJcKKxzoo9lnkYPsx2o8EJcTYwCs/A==", + "dev": true, + "optional": true + }, + "esbuild-freebsd-64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.49.tgz", + "integrity": "sha512-NJ5Q6AjV879mOHFri+5lZLTp5XsO2hQ+KSJYLbfY9DgCu8s6/Zl2prWXVANYTeCDLlrIlNNYw8y34xqyLDKOmQ==", + "dev": true, + "optional": true + }, + "esbuild-freebsd-arm64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.49.tgz", + "integrity": "sha512-lFLtgXnAc3eXYqj5koPlBZvEbBSOSUbWO3gyY/0+4lBdRqELyz4bAuamHvmvHW5swJYL7kngzIZw6kdu25KGOA==", + "dev": true, + "optional": true + }, + "esbuild-linux-32": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.14.49.tgz", + "integrity": "sha512-zTTH4gr2Kb8u4QcOpTDVn7Z8q7QEIvFl/+vHrI3cF6XOJS7iEI1FWslTo3uofB2+mn6sIJEQD9PrNZKoAAMDiA==", + "dev": true, + "optional": true + }, + "esbuild-linux-64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.49.tgz", + "integrity": "sha512-hYmzRIDzFfLrB5c1SknkxzM8LdEUOusp6M2TnuQZJLRtxTgyPnZZVtyMeCLki0wKgYPXkFsAVhi8vzo2mBNeTg==", + "dev": true, + "optional": true + }, + "esbuild-linux-arm": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.14.49.tgz", + "integrity": "sha512-iE3e+ZVv1Qz1Sy0gifIsarJMQ89Rpm9mtLSRtG3AH0FPgAzQ5Z5oU6vYzhc/3gSPi2UxdCOfRhw2onXuFw/0lg==", + "dev": true, + "optional": true + }, + "esbuild-linux-arm64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.49.tgz", + "integrity": "sha512-KLQ+WpeuY+7bxukxLz5VgkAAVQxUv67Ft4DmHIPIW+2w3ObBPQhqNoeQUHxopoW/aiOn3m99NSmSV+bs4BSsdA==", + "dev": true, + "optional": true + }, + "esbuild-linux-mips64le": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.49.tgz", + "integrity": "sha512-n+rGODfm8RSum5pFIqFQVQpYBw+AztL8s6o9kfx7tjfK0yIGF6tm5HlG6aRjodiiKkH2xAiIM+U4xtQVZYU4rA==", + "dev": true, + "optional": true + }, + "esbuild-linux-ppc64le": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.49.tgz", + "integrity": "sha512-WP9zR4HX6iCBmMFH+XHHng2LmdoIeUmBpL4aL2TR8ruzXyT4dWrJ5BSbT8iNo6THN8lod6GOmYDLq/dgZLalGw==", + "dev": true, + "optional": true + }, + "esbuild-linux-riscv64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.14.49.tgz", + "integrity": "sha512-h66ORBz+Dg+1KgLvzTVQEA1LX4XBd1SK0Fgbhhw4akpG/YkN8pS6OzYI/7SGENiN6ao5hETRDSkVcvU9NRtkMQ==", + "dev": true, + "optional": true + }, + "esbuild-linux-s390x": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.49.tgz", + "integrity": "sha512-DhrUoFVWD+XmKO1y7e4kNCqQHPs6twz6VV6Uezl/XHYGzM60rBewBF5jlZjG0nCk5W/Xy6y1xWeopkrhFFM0sQ==", + "dev": true, + "optional": true + }, + "esbuild-netbsd-64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.49.tgz", + "integrity": "sha512-BXaUwFOfCy2T+hABtiPUIpWjAeWK9P8O41gR4Pg73hpzoygVGnj0nI3YK4SJhe52ELgtdgWP/ckIkbn2XaTxjQ==", + "dev": true, + "optional": true + }, + "esbuild-openbsd-64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.49.tgz", + "integrity": "sha512-lP06UQeLDGmVPw9Rg437Btu6J9/BmyhdoefnQ4gDEJTtJvKtQaUcOQrhjTq455ouZN4EHFH1h28WOJVANK41kA==", + "dev": true, + "optional": true + }, + "esbuild-sunos-64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.14.49.tgz", + "integrity": "sha512-4c8Zowp+V3zIWje329BeLbGh6XI9c/rqARNaj5yPHdC61pHI9UNdDxT3rePPJeWcEZVKjkiAS6AP6kiITp7FSw==", + "dev": true, + "optional": true + }, + "esbuild-windows-32": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.14.49.tgz", + "integrity": "sha512-q7Rb+J9yHTeKr9QTPDYkqfkEj8/kcKz9lOabDuvEXpXuIcosWCJgo5Z7h/L4r7rbtTH4a8U2FGKb6s1eeOHmJA==", + "dev": true, + "optional": true + }, + "esbuild-windows-64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.49.tgz", + "integrity": "sha512-+Cme7Ongv0UIUTniPqfTX6mJ8Deo7VXw9xN0yJEN1lQMHDppTNmKwAM3oGbD/Vqff+07K2gN0WfNkMohmG+dVw==", + "dev": true, + "optional": true + }, + "esbuild-windows-arm64": { + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.49.tgz", + "integrity": "sha512-v+HYNAXzuANrCbbLFJ5nmO3m5y2PGZWLe3uloAkLt87aXiO2mZr3BTmacZdjwNkNEHuH3bNtN8cak+mzVjVPfA==", + "dev": true, + "optional": true + }, "escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", diff --git a/package.json b/package.json index 18c5300ab..350c6e7bc 100644 --- a/package.json +++ b/package.json @@ -6,20 +6,26 @@ "type": "git", "url": "https://github.com/NordicSemiconductor/pc-nrfconnect-launcher.git" }, - "main": "src/main", + "main": "dist/main.js", "scripts": { "postinstall": "node getJlink.js", - "app": "electron .", - "dev": "webpack watch --mode development", - "webpack": "webpack build --mode development", - "build": "webpack build", - "test": "jest src/", + "app": "NODE_OPTIONS=--enable-source-maps electron .", + "watch": "run-p --silent --continue-on-error --print-label watch:*", + "watch:main": "node esbuild.js --watch", + "watch:renderer": "webpack watch --mode development --color", + "build:dev": "run-p --silent --continue-on-error --print-label build:dev:*", + "build:dev:renderer": "webpack build --mode development --color", + "build:dev:main": "node esbuild.js", + "build:prod": "run-p --silent --continue-on-error --print-label build:prod:*", + "build:prod:renderer": "webpack build --color", + "build:prod:main": "node esbuild.js --prod", "check": "run-p --silent --continue-on-error --print-label check:*", "check:lint": "eslint --color .", "check:types": "check-for-typescript tsc --noEmit --pretty", "check:license": "nrfconnect-license check", + "test": "jest src/", "test-e2e": "xvfb-maybe npx playwright test test-e2e/", - "pack": "npm run build && electron-builder -p never", + "pack": "npm run build:prod && electron-builder -p never", "release": "electron-builder -p always", "install-devtools": "electron . --install-devtools", "remove-devtools": "electron . --remove-devtools" @@ -35,7 +41,6 @@ ], "files": [ "dist/", - "src/main/", "node_modules/", "resources/*.html", "resources/*.png", @@ -88,6 +93,7 @@ "electron-builder": "^22.14.13", "electron-devtools-installer": "3.2.0", "electron-notarize": "0.3.0", + "esbuild": "0.14.49", "mini-css-extract-plugin": "0.9.0", "pc-nrfconnect-shared": "git+https://github.com/NordicSemiconductor/pc-nrfconnect-shared.git#v6.5.5", "playwright": "^1.16.3", diff --git a/src/main/index.js b/src/main/index.js index 60be016b5..17cc374b4 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -7,17 +7,11 @@ // eslint-disable-next-line strict,lines-around-directive -- because we are not inside a module, using strict is helpful here 'use strict'; -// Run this as soon as possible, so that the user data folder is not already initialised by Electron -require('./setUserDataDir'); +// Run this as soon as possible, so it is set up for the other modules to be loaded afterwards +require('./init'); require('@electron/remote/main').initialize(); -const { argv } = require('yargs'); -// eslint-disable-next-line import/order -- The config needs to be loaded and initialised early, because it is used in other modules, sometimes while loading them -const config = require('./config'); - -config.init(argv); - const { Menu, ipcMain, @@ -27,6 +21,7 @@ const { } = require('electron'); const { join } = require('path'); +const config = require('./config'); const windows = require('./windows'); const apps = require('./apps'); const { createMenu } = require('./menu'); diff --git a/src/main/init.js b/src/main/init.js new file mode 100644 index 000000000..fab642814 --- /dev/null +++ b/src/main/init.js @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause + */ + +require('./setUserDataDir'); + +const { argv } = require('yargs'); +const config = require('./config'); + +config.init(argv);