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 12 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: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = {
'react/jsx-indent-props': ['warn', 2],
'comma-dangle': ['error', 'always-multiline'],
'prettier/prettier': ['warn', { tabWidth: 2, trailingComma: 'all' }],
'no-console': 'off',
// Should always use our logger
'no-console': 'error',
'react/require-default-props': 'off',
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
'jsx-a11y/label-has-associated-control': [
Expand Down
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
30 changes: 21 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch",
"name": "Debug .NET Core",
irahopkinson marked this conversation as resolved.
Show resolved Hide resolved
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"preLaunchTask": "npm: build:data",
"program": "${workspaceFolder}/c-sharp/bin/Debug/net7.0/ParanextDataProvider",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"windows": {
"program": "${workspaceFolder}/c-sharp/bin/Debug/net7.0/ParanextDataProvider.exe"
"program": "${workspaceFolder}/c-sharp/bin/Debug/net7.0/win-x64/ParanextDataProvider.exe"
irahopkinson marked this conversation as resolved.
Show resolved Hide resolved
}
},
{
"name": ".NET Core Attach",
"name": "Attach to .NET Core",
"type": "coreclr",
"request": "attach",
"processName": "ParanextDataProvider",
Expand All @@ -24,29 +24,41 @@
}
},
{
"name": "Electron: Main",
"name": "Debug Paranext Core Backend",
"type": "node",
"request": "launch",
"protocol": "inspector",
"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"
}
},
{
"name": "Electron: Renderer",
"name": "Attach to Renderer",
"type": "chrome",
"request": "attach",
"port": 9223,
"webRoot": "${workspaceFolder}",
"timeout": 15000
},
{
"name": "Debug Extension Host",
"type": "node",
"request": "launch",
"protocol": "inspector",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "start:extension-host"],
"env": {
"IN_VSCODE": "true"
}
}
],
"compounds": [
{
"name": "Electron: All",
"configurations": ["Electron: Main", "Electron: Renderer"]
"name": "Debug Paranext Core",
"configurations": ["Debug Paranext Core Backend", "Attach to Renderer"]
}
]
}
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ cd paranext-core
npm install
```

Build the C# code:

```bash
npm run build:data
```

## Starting Development

Start the app in the `dev` environment:
Expand All @@ -70,7 +64,7 @@ Start the app in the `dev` environment:
npm start
```

After you run `npm start`, you can edit the Electron and frontend files, and they will hot reload. To edit C# files, you must stop the `npm start` process (or only close Paranext), run `npm run build:data`, and restart `npm start` (or if you only closed Paranext, make a trivial edit to `src/main/main.ts`, and save it to launch Paranext again).
After you run `npm start` (or, in VSCode, launch `Debug Paranext Core`), you can edit the code, and the relevant processes will hot reload.

## Packaging for Production

Expand Down
Loading