@vixoniccom/module-packager 2.13.0-test.6 → 2.13.1-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/electron.js +2 -6
- package/dist/launcher.html +0 -79
- package/dist/main.js +6 -2
- package/dist/scripts/preload.js +59 -0
- package/dist/scripts/webview-preload.js +13 -0
- package/dist/webpack.config.js +4 -5
- package/package.json +3 -2
package/dist/electron.js
CHANGED
|
@@ -28,12 +28,8 @@ function createWindow() {
|
|
|
28
28
|
width: 1024,
|
|
29
29
|
height: 768,
|
|
30
30
|
webPreferences: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
nodeIntegration: true,
|
|
34
|
-
contextIsolation: false,
|
|
35
|
-
webSecurity: false,
|
|
36
|
-
webviewTag: true
|
|
31
|
+
webviewTag: true,
|
|
32
|
+
preload: path.join(__dirname, 'scripts', 'preload.js'),
|
|
37
33
|
}
|
|
38
34
|
});
|
|
39
35
|
remoteMain.enable(mainWindow.webContents);
|
package/dist/launcher.html
CHANGED
|
@@ -8,85 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
<body style="width: 100%; height: 100%; margin: 0; padding: 0;">
|
|
10
10
|
<div id="webview-container" style="width: 100%; height: 100%;"></div>
|
|
11
|
-
|
|
12
|
-
<script>
|
|
13
|
-
const path = require('path')
|
|
14
|
-
let ModuleController;
|
|
15
|
-
try {
|
|
16
|
-
const moduleControllerModule = require('@vixoniccom/module-controller');
|
|
17
|
-
ModuleController = moduleControllerModule.default;
|
|
18
|
-
} catch (err) {
|
|
19
|
-
console.error('[WEBVIEW] NO se pudo cargar ModuleController', err);
|
|
20
|
-
}
|
|
21
|
-
const { ipcRenderer } = require('electron')
|
|
22
|
-
const remote = require('@electron/remote')
|
|
23
|
-
|
|
24
|
-
ipcRenderer.on('init', (event, options) => {
|
|
25
|
-
const webview = document.createElement('webview')
|
|
26
|
-
webview.id = 'webview'
|
|
27
|
-
webview.style.width = '100%'
|
|
28
|
-
webview.style.height = '100%'
|
|
29
|
-
webview.setAttribute('partition', 'persist:webview')
|
|
30
|
-
|
|
31
|
-
webview.setAttribute('nodeintegration', '')
|
|
32
|
-
webview.setAttribute('webpreferences', 'webSecurity=false, allowRunningInsecureContent=true, nodeIntegration=yes, contextIsolation=no')
|
|
33
|
-
|
|
34
|
-
const win = remote.getCurrentWindow()
|
|
35
|
-
|
|
36
|
-
webview.addEventListener('did-finish-load', () => {
|
|
37
|
-
win.show()
|
|
38
|
-
win.focus()
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
const resolvedSrc = options.mode === 'watch'
|
|
42
|
-
? `http://localhost:${options.port}/index.html`
|
|
43
|
-
: `file://${path.join(options.build, 'index.html')}`
|
|
44
|
-
|
|
45
|
-
webview.src = resolvedSrc
|
|
46
|
-
|
|
47
|
-
document.getElementById('webview-container').appendChild(webview)
|
|
48
|
-
|
|
49
|
-
function getData() {
|
|
50
|
-
const data = {}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
data.parameters = require(path.join(options.src, 'test', 'parameters.json')).parameters
|
|
54
|
-
} catch (err) {
|
|
55
|
-
console.log('No parameters:', err.message)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
let escaped = path.join(options.mode === 'watch' ? options.src : options.build, 'test', 'downloads')
|
|
59
|
-
|
|
60
|
-
if (options.mode === 'watch') escaped = `file://${escaped}`
|
|
61
|
-
escaped = escaped.replace(/\\/g, '/')
|
|
62
|
-
|
|
63
|
-
data.downloadsPath = escaped
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
data.services = require(path.join(options.src, 'test','services.json')).services
|
|
68
|
-
} catch (err) {
|
|
69
|
-
console.log('No services:', err.message)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return data
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function getSchema() {
|
|
76
|
-
try {
|
|
77
|
-
return require(path.join(options.src, '../configuration.json')).schema
|
|
78
|
-
} catch (err) {
|
|
79
|
-
console.log('No schema:', err.message)
|
|
80
|
-
return {}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const data = getData()
|
|
85
|
-
const schema = getSchema()
|
|
86
|
-
|
|
87
|
-
ModuleController.init(win, webview, data, schema, options.mode === 'watch')
|
|
88
|
-
})
|
|
89
|
-
</script>
|
|
90
11
|
</body>
|
|
91
12
|
|
|
92
13
|
</html>
|
package/dist/main.js
CHANGED
|
@@ -194,10 +194,14 @@ async function pack(callback) {
|
|
|
194
194
|
function installExternals(callback) {
|
|
195
195
|
let externals = options.externals.map((x) => {
|
|
196
196
|
// Validar nombre del paquete
|
|
197
|
-
if (!/^[
|
|
197
|
+
if (!/^(?:@[a-z0-9-_.]+\/)?[a-z0-9-_.]+$/i.test(x)) {
|
|
198
198
|
throw new Error(`Invalid package name: ${x}`);
|
|
199
199
|
}
|
|
200
|
-
const
|
|
200
|
+
const nodeModulesBase = path.resolve(options.src, '..', 'node_modules');
|
|
201
|
+
const packageJsonPath = path.resolve(nodeModulesBase, x, 'package.json');
|
|
202
|
+
if (!packageJsonPath.startsWith(nodeModulesBase + path.sep)) {
|
|
203
|
+
throw new Error(`Invalid package path: path traversal detected for package ${x}`);
|
|
204
|
+
}
|
|
201
205
|
return `${x}@${JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')).version}`;
|
|
202
206
|
});
|
|
203
207
|
if (externals.length) {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// preload.ts
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { ipcRenderer } from 'electron';
|
|
4
|
+
import remote from '@electron/remote';
|
|
5
|
+
let ModuleController;
|
|
6
|
+
try {
|
|
7
|
+
const m = require('@vixoniccom/module-controller');
|
|
8
|
+
ModuleController = m.default;
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
console.error('[PRELOAD] No se pudo cargar ModuleController', err);
|
|
12
|
+
}
|
|
13
|
+
ipcRenderer.on('init', (_event, options) => {
|
|
14
|
+
const webview = document.createElement('webview');
|
|
15
|
+
webview.id = 'webview';
|
|
16
|
+
webview.style.width = '100%';
|
|
17
|
+
webview.style.height = '100%';
|
|
18
|
+
webview.setAttribute('partition', 'persist:webview');
|
|
19
|
+
webview.setAttribute('preload', `file://${path.join(__dirname, 'webview-preload.js')}`);
|
|
20
|
+
const win = remote.getCurrentWindow();
|
|
21
|
+
webview.addEventListener('did-finish-load', () => {
|
|
22
|
+
win.show();
|
|
23
|
+
win.focus();
|
|
24
|
+
});
|
|
25
|
+
const resolvedSrc = options.mode === 'watch'
|
|
26
|
+
? `http://localhost:${options.port}/index.html`
|
|
27
|
+
: `file://${path.join(options.build, 'index.html')}`;
|
|
28
|
+
webview.src = resolvedSrc;
|
|
29
|
+
document.getElementById('webview-container')?.appendChild(webview);
|
|
30
|
+
function getData() {
|
|
31
|
+
const data = {};
|
|
32
|
+
try {
|
|
33
|
+
data.parameters = require(path.join(options.src, 'test', 'parameters.json')).parameters;
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
console.log('No parameters:', err.message);
|
|
37
|
+
}
|
|
38
|
+
let escaped = path.join(options.mode === 'watch' ? options.src : options.build, 'test', 'downloads');
|
|
39
|
+
if (options.mode === 'watch')
|
|
40
|
+
escaped = `file://${escaped}`;
|
|
41
|
+
data.downloadsPath = escaped.replace(/\\/g, '/');
|
|
42
|
+
try {
|
|
43
|
+
data.services = require(path.join(options.src, 'test', 'services.json')).services;
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
console.log('No services:', err.message);
|
|
47
|
+
}
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
function getSchema() {
|
|
51
|
+
try {
|
|
52
|
+
return require(path.join(options.src, '../configuration.json')).schema;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
ModuleController?.init(win, webview, getData(), getSchema(), options.mode === 'watch');
|
|
59
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ipcRenderer } from 'electron';
|
|
2
|
+
ipcRenderer.on('preload', (_event, data) => {
|
|
3
|
+
window.postMessage({ channel: 'preload', data }, location.origin);
|
|
4
|
+
});
|
|
5
|
+
ipcRenderer.on('start', (_event, data) => {
|
|
6
|
+
window.postMessage({ channel: 'start', data }, location.origin);
|
|
7
|
+
});
|
|
8
|
+
ipcRenderer.on('update', (_event, data) => {
|
|
9
|
+
window.postMessage({ channel: 'update', data }, location.origin);
|
|
10
|
+
});
|
|
11
|
+
ipcRenderer.on('finish', () => {
|
|
12
|
+
window.postMessage({ channel: 'finish', data: null }, location.origin);
|
|
13
|
+
});
|
package/dist/webpack.config.js
CHANGED
|
@@ -15,19 +15,18 @@ export default (env = {}, argv = {}) => {
|
|
|
15
15
|
};
|
|
16
16
|
const isDev = options.mode === 'development' || argv.watch === true || process.env.NODE_ENV === 'development';
|
|
17
17
|
const buildPath = path.resolve(options.build);
|
|
18
|
+
const controllerHtmlPath = path.resolve(options.src, 'index.html');
|
|
19
|
+
const controllerStaticPath = path.resolve(path.dirname(controllerHtmlPath), '../static');
|
|
20
|
+
const controllerFontsPath = path.resolve(path.dirname(controllerHtmlPath), '../fonts');
|
|
21
|
+
const controllerTestPath = path.resolve(options.src, 'test');
|
|
18
22
|
// Process all environment variables
|
|
19
23
|
const getEnvironmentVariables = () => {
|
|
20
24
|
const envVars = {};
|
|
21
25
|
Object.keys(process.env).forEach((key) => {
|
|
22
26
|
envVars[`process.env.${key}`] = JSON.stringify(process.env[key]);
|
|
23
27
|
});
|
|
24
|
-
console.log('Environment variables found:', Object.keys(process.env).length);
|
|
25
28
|
return envVars;
|
|
26
29
|
};
|
|
27
|
-
const controllerHtmlPath = path.resolve(options.src, 'index.html');
|
|
28
|
-
const controllerStaticPath = path.resolve(path.dirname(controllerHtmlPath), '../static');
|
|
29
|
-
const controllerFontsPath = path.resolve(path.dirname(controllerHtmlPath), '../fonts');
|
|
30
|
-
const controllerTestPath = path.resolve(options.src, 'test');
|
|
31
30
|
return {
|
|
32
31
|
mode: isDev ? 'development' : 'production',
|
|
33
32
|
target: options.target ?? 'electron-renderer',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vixoniccom/module-packager",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.1-dev.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"bin": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"start": "electron dist/electron.js --mode run --build ./dist/build",
|
|
15
15
|
"clean": "rimraf dist",
|
|
16
|
+
"prepublish": "npm run build",
|
|
16
17
|
"build:main": "tsc -p tsconfig.json --outDir dist",
|
|
17
18
|
"build:renderer": "webpack --config webpack.config.js --env src=./ --env build=./dist/build --mode production",
|
|
18
19
|
"copy:launcher": "cpy launcher.html dist",
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"@electron/remote": "^2.1.2",
|
|
27
28
|
"@types/which": "^3.0.4",
|
|
28
29
|
"@vixoniccom/module-controller": "^2.0.0",
|
|
29
|
-
"@vixoniccom/modules": "^2.
|
|
30
|
+
"@vixoniccom/modules": "^2.21.0",
|
|
30
31
|
"archiver": "^5.3.0",
|
|
31
32
|
"clean-webpack-plugin": "^4.0.0",
|
|
32
33
|
"cli-color": "^1.2.0",
|