Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added extension host process that launches from main process #29

Merged
merged 15 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions .erb/configs/webpack.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import TsconfigPathsPlugins from 'tsconfig-paths-webpack-plugin';
import webpackPaths from './webpack.paths';
import { dependencies as externals } from '../../release/app/package.json';

const isRenderer =
process.env.npm_lifecycle_script?.includes('webpack.config.renderer') ??
false;
let processType: string;
if (process.env.npm_lifecycle_script?.includes('webpack.config.renderer'))
processType = 'renderer';
else if (
process.env.npm_lifecycle_script?.includes('webpack.config.extension-host')
)
processType = 'extension-host';
else processType = 'main';

const configuration: webpack.Configuration = {
externals: [...Object.keys(externals || {})],
Expand Down Expand Up @@ -61,16 +66,39 @@ const configuration: webpack.Configuration = {
new webpack.IgnorePlugin({
checkResource(resource, context) {
// Don't include stuff from the main folder or @main... in renderer and renderer folder in main folder
const exclude = isRenderer
? resource.startsWith('@main') || resource.includes('main/')
: resource.startsWith('@renderer') || /renderer\//.test(resource);
let exclude = false;
switch (processType) {
case 'renderer':
exclude =
resource.startsWith('@main') ||
resource.includes('main/') ||
resource.startsWith('@extension-host') ||
resource.includes('extension-host/') ||
resource.startsWith('@node') ||
resource.includes('node/');
break;
case 'extension-host':
exclude =
resource.startsWith('@main') ||
resource.includes('main/') ||
resource.startsWith('@renderer') ||
resource.includes('renderer/');
break;
default: // main
exclude =
resource.startsWith('@renderer') ||
/renderer\//.test(resource) ||
resource.startsWith('@extension-host') ||
resource.includes('extension-host/') ||
resource.startsWith('@client') ||
resource.includes('client/');
break;
}

// Log if a file is excluded just fyi
if (!context.includes('node_modules') && exclude)
console.log(
`${
isRenderer ? 'Renderer' : 'Main'
}: Resource ${resource}\n\tat context ${context}: ${
`${processType}: Resource ${resource}\n\tat context ${context}: ${
exclude ? 'excluded' : 'included'
}`,
);
Expand Down
34 changes: 34 additions & 0 deletions .erb/configs/webpack.config.extension-host.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Webpack config for production extension-host process
*/

import path from 'path';
import webpack from 'webpack';
import merge, { mergeWithCustomize } from 'webpack-merge';
import mainConfig from './webpack.config.main.prod';
import webpackPaths from './webpack.paths';
import checkNodeEnv from '../scripts/check-node-env';
import deleteSourceMaps from '../scripts/delete-source-maps';

checkNodeEnv('production');
deleteSourceMaps();

const configuration: webpack.Configuration = {
entry: {
'extension-host': path.join(
webpackPaths.srcExtensionHostPath,
'extension-host.ts',
),
},

output: {
path: webpackPaths.distExtensionHostPath,
},
};

export default mergeWithCustomize({
customizeObject(a, b, key) {
if (key === 'entry') return b;
return merge(a, b);
},
})(mainConfig, configuration);
4 changes: 4 additions & 0 deletions .erb/configs/webpack.paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const dllPath = path.join(__dirname, '../dll');

const srcPath = path.join(rootPath, 'src');
const srcMainPath = path.join(srcPath, 'main');
const srcExtensionHostPath = path.join(srcPath, 'extension-host');
const srcRendererPath = path.join(srcPath, 'renderer');
const srcSharedPath = path.join(srcPath, 'shared');

Expand All @@ -17,6 +18,7 @@ const srcNodeModulesPath = path.join(srcPath, 'node_modules');

const distPath = path.join(appPath, 'dist');
const distMainPath = path.join(distPath, 'main');
const distExtensionHostPath = path.join(distPath, 'extension-host');
const distRendererPath = path.join(distPath, 'renderer');

const buildPath = path.join(releasePath, 'build');
Expand All @@ -26,6 +28,7 @@ export default {
dllPath,
srcPath,
srcMainPath,
srcExtensionHostPath,
srcRendererPath,
srcSharedPath,
releasePath,
Expand All @@ -35,6 +38,7 @@ export default {
srcNodeModulesPath,
distPath,
distMainPath,
distExtensionHostPath,
distRendererPath,
buildPath,
};
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ npm-debug.log.*

# Extra VS Code workspaces
*.code-workspace

# Test node localStorage files
local-storage
18 changes: 16 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "start"],
"env": {
"MAIN_ARGS": "--inspect=5858 --remote-debugging-port=9223"
}
"MAIN_ARGS": "--inspect=5858 --remote-debugging-port=9223",
"IN_VSCODE": "true"
},
"autoAttachChildProcesses": true
irahopkinson marked this conversation as resolved.
Show resolved Hide resolved
},
{
"name": "Electron: Renderer",
Expand All @@ -41,6 +43,18 @@
"port": 9223,
"webRoot": "${workspaceFolder}",
"timeout": 15000
},
{
"name": "Extension Host",
"type": "node",
"request": "launch",
"protocol": "inspector",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "start:extension-host"],
"env": {
"IN_VSCODE": "true"
},
"autoAttachChildProcesses": true
}
],
"compounds": [
Expand Down
Loading