Skip to content

Commit f7346f2

Browse files
committed
fixes
1 parent 6f0804b commit f7346f2

17 files changed

+312
-118
lines changed

.erb/configs/getAnalyzerPlugins.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
2+
3+
export function getAnalyzerPlugins() {
4+
return process.env.ANALYZE === 'true' ? [new BundleAnalyzerPlugin({
5+
analyzerMode: 'server',
6+
analyzerPort: 8888,
7+
})] : []
8+
}

.erb/configs/webpack.config.main.dev.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,49 @@
44

55
import path from 'path';
66
import webpack from 'webpack';
7-
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
87
import { merge } from 'webpack-merge';
98
import checkNodeEnv from '../scripts/check-node-env';
109
import baseConfig from './webpack.config.base';
1110
import webpackPaths from './webpack.paths';
1211
import { devMainCopyPlugins } from './copy-plugin'
13-
import { LogContentsPlugin } from './webpack.custom-plugins'
12+
import { GenerateApiPropsPlugin } from './webpack.custom-plugins'
13+
import { getAnalyzerPlugins } from './getAnalyzerPlugins'
14+
import WatchExternalFilesPlugin from 'webpack-watch-files-plugin'
15+
import touch from 'touch';
1416

17+
18+
class WebpackForceRebuildOnEmitPlugin {
19+
apply(compiler) {
20+
compiler.hooks.emit.tapAsync('WebpackForceRebuildOnEmitPlugin', (compilation, callback) => {
21+
const outputPath = compilation.outputOptions.path;
22+
const firstAssetName = compilation.getAssets()[0].name;
23+
const assetToTouch = path.resolve(outputPath, firstAssetName);
24+
touch(assetToTouch);
25+
callback();
26+
});
27+
}
28+
}
29+
30+
31+
function getWatchingPlugins() {
32+
const IS_WATCH_MODE = process.argv?.includes('--watch');
33+
return IS_WATCH_MODE ? [
34+
// @ts-ignore
35+
new WatchExternalFilesPlugin({
36+
verbose: false,
37+
files: [
38+
'./inputs/**/*.js',
39+
]
40+
}) as any,
41+
new WebpackForceRebuildOnEmitPlugin(),
42+
] : []
43+
}
1544
// When an ESLint server is running, we can't set the NODE_ENV so we'll check if it's
1645
// at the dev webpack config is not accidentally run in a production environment
1746
if (process.env.NODE_ENV === 'production') {
1847
checkNodeEnv('development');
1948
}
49+
const generateApiProps = process.env.GENERATE_APP_PROPS === 'true';
2050
const configuration: webpack.Configuration = {
2151
devtool: 'inline-source-map',
2252

@@ -39,13 +69,11 @@ const configuration: webpack.Configuration = {
3969

4070
plugins: [
4171
...devMainCopyPlugins,
42-
new LogContentsPlugin(),
72+
...(generateApiProps ? [new GenerateApiPropsPlugin()] : []),
73+
...getWatchingPlugins(),
4374
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4475
// @ts-ignore
45-
new BundleAnalyzerPlugin({
46-
analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled',
47-
analyzerPort: 8888,
48-
}),
76+
...getAnalyzerPlugins(),
4977

5078
new webpack.DefinePlugin({
5179
'process.type': '"browser"',

.erb/configs/webpack.config.main.prod.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import path from 'path';
66
import webpack from 'webpack';
77
import { merge } from 'webpack-merge';
88
import TerserPlugin from 'terser-webpack-plugin';
9-
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
9+
import { getAnalyzerPlugins } from './getAnalyzerPlugins';
1010
import baseConfig from './webpack.config.base';
1111
import webpackPaths from './webpack.paths';
1212
import checkNodeEnv from '../scripts/check-node-env';
@@ -51,10 +51,7 @@ const configuration: webpack.Configuration = {
5151

5252
plugins: [
5353
...prodMainCopyPlugins,
54-
new BundleAnalyzerPlugin({
55-
analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled',
56-
analyzerPort: 8888,
57-
}),
54+
...getAnalyzerPlugins(),
5855

5956
/**
6057
* Create global constants which can be configured at compile time.

.erb/configs/webpack.config.preload.dev.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
22
import webpack from 'webpack';
33
import { merge } from 'webpack-merge';
4-
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
4+
import { getAnalyzerPlugins } from './getAnalyzerPlugins';
55
import baseConfig from './webpack.config.base';
66
import webpackPaths from './webpack.paths';
77
import checkNodeEnv from '../scripts/check-node-env';
@@ -30,9 +30,7 @@ const configuration: webpack.Configuration = {
3030
},
3131

3232
plugins: [
33-
new BundleAnalyzerPlugin({
34-
analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled',
35-
}),
33+
...getAnalyzerPlugins(),
3634

3735
/**
3836
* Create global constants which can be configured at compile time.

.erb/configs/webpack.config.renderer.dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ const configuration: webpack.Configuration = {
208208
.on('error', (spawnError) => console.error(spawnError));
209209

210210
console.log('Starting Main Process...');
211-
let args = ['run', 'start:main'];
211+
let args = ['run', process.env.K8S_MODE === 'master' ? 'start:main:master' : 'start:main'];
212212
if (process.env.MAIN_ARGS) {
213213
args = args.concat(
214214
['--', ...process.env.MAIN_ARGS.matchAll(/"[^"]+"|[^\s"]+/g)].flat(),

.erb/configs/webpack.config.renderer.prod.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import path from 'path';
66
import webpack from 'webpack';
77
import HtmlWebpackPlugin from 'html-webpack-plugin';
88
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
9-
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
9+
import { getAnalyzerPlugins } from './getAnalyzerPlugins';
1010
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
1111
import { merge } from 'webpack-merge';
1212
import TerserPlugin from 'terser-webpack-plugin';
@@ -50,7 +50,7 @@ const configuration: webpack.Configuration = {
5050
importLoaders: 1,
5151
},
5252
},
53-
'sass-loader',
53+
// 'sass-loader', // no need as no sass files, and throws warnings
5454
],
5555
include: /\.module\.s?(c|a)ss$/,
5656
},
@@ -59,19 +59,18 @@ const configuration: webpack.Configuration = {
5959
use: [
6060
MiniCssExtractPlugin.loader,
6161
'css-loader',
62-
'sass-loader',
6362
{
6463
loader: 'postcss-loader',
6564
options: {
66-
postcssOptions: {
67-
plugins:
68-
[
65+
postcssOptions: {
66+
plugins: [
6967
require('tailwindcss'),
7068
require('autoprefixer'),
7169
]
7270
},
7371
},
7472
},
73+
// 'sass-loader', // no need as no sass files, and throws warnings
7574
],
7675
exclude: /\.module\.s?(c|a)ss$/,
7776
},
@@ -132,10 +131,7 @@ const configuration: webpack.Configuration = {
132131
filename: 'style.css',
133132
}),
134133

135-
new BundleAnalyzerPlugin({
136-
analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled',
137-
analyzerPort: 8889,
138-
}),
134+
...getAnalyzerPlugins(),
139135

140136
new HtmlWebpackPlugin({
141137
filename: 'index.html',

.erb/configs/webpack.custom-plugins.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,64 @@
11
import { writeFile } from "botasaurus/output"
22
import { exec } from 'child_process'
33
import * as path from 'path'
4+
import * as fs from 'fs'
5+
6+
function ensureDllDirExists(): void {
7+
const dllDir = path.join(__dirname, "../dll/")
8+
if (!fs.existsSync(dllDir)) {
9+
fs.mkdirSync(dllDir, { recursive: true })
10+
}
11+
}
12+
13+
function getTempPath(): string {
14+
return path.join(__dirname, "../dll/", "temp.js")
15+
}
16+
17+
418

519
function runCode(contents) {
6-
writeFile(contents, path.join(__dirname, "../../", "temp.js"), false)
7-
// Execute temp.js using Node.js
8-
exec('node temp.js', (error, stdout, stderr) => {
20+
ensureDllDirExists()
21+
writeFile(contents, getTempPath(), false)
22+
23+
exec('node ./.erb/dll/temp.js', (error, stdout, stderr) => {
924
if (error) {
1025
console.error(`Error executing temp.js: ${error}`)
1126
return
1227
}
1328
if (stderr) {
1429
console.error(`stderr: ${stderr}`)
30+
process.exit(1)
1531
}
1632
})
1733
}
1834

19-
function getAssetNames(assets) {
20-
const ls:any[] = []
21-
for (const assetName in assets) {
22-
ls.push(assetName)
23-
}
24-
return ls
25-
}
26-
27-
export class LogContentsPlugin {
35+
export class GenerateApiPropsPlugin {
2836
apply(compiler) {
29-
compiler.hooks.emit.tapAsync('LogContentsPlugin', async (compilation, callback) => {
37+
compiler.hooks.emit.tapAsync('GenerateApiPropsPlugin', async (compilation, callback) => {
3038
const compAssets = compilation.assets
31-
// console.log(getAssetNames(compAssets))
3239
for (const assetName in compAssets) {
33-
const targetFiles = ["main.bundle.dev.js",
34-
// "main.js",
35-
]
40+
const targetFiles = ["main.bundle.dev.js"]
3641
if (targetFiles.includes( assetName ) ){
3742
const asset = compAssets[assetName]
3843
const source:string = asset.source()
39-
// make dev, and also fix resolve errors of bota server
40-
let contents = source.replace("process.env.CREATE_API_CONFIG", "true")
41-
// fix native modules imports
44+
let contents = source.replace("main() {", "main() {(0,_utils_generate_app_props__WEBPACK_IMPORTED_MODULE_1__.generateAppProps)();return;")
45+
46+
47+
// Fixes Input JS and README paths
48+
contents = contents.replaceAll('if (isElectron) {', 'if (false) {')
49+
50+
// Disable master logging
51+
contents = contents.replaceAll('static async enableKubernetes({ masterEndpoint, taskTimeout = master_executor_1.DEFAULT_TASK_TIMEOUT }) {', 'static async enableKubernetes({ masterEndpoint, taskTimeout = master_executor_1.DEFAULT_TASK_TIMEOUT }) {return;')
4252
contents = contents.replaceAll('factory(require("', 'factory(require("./release/app/node_modules/')
43-
// factory(require("
53+
// Sentry FIX
54+
contents = contents.replace('function __webpack_require__(moduleId) {', 'function __webpack_require__(moduleId) {if (moduleId.includes("sentry")){return {}};')
4455
try {
45-
// console.log("Updating index.html")
4656
runCode(contents)
4757
} catch (error) {
4858
console.error(error)
4959
}
5060
}
5161
}
52-
// console.log(JSON.stringify(ls))
5362
callback()
5463
})
5564
}

package-lock.json

Lines changed: 84 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)