@vixoniccom/module-packager 2.12.0-dev.3 → 2.12.0-dev.5

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 CHANGED
@@ -8,11 +8,11 @@ const __filename = fileURLToPath(import.meta.url);
8
8
  const __dirname = path.dirname(__filename);
9
9
  const optionDefinitions = [
10
10
  { name: 'externals', type: String, defaultValue: [], multiple: true },
11
- { name: 'src', type: String, defaultValue: path.join(__dirname, './src') },
12
- { name: 'build', type: String, defaultValue: path.join(__dirname, './build') },
11
+ { name: 'src', type: String, defaultValue: path.join(__dirname, 'src') },
12
+ { name: 'build', type: String, defaultValue: path.join(__dirname, 'build') },
13
13
  { name: 'config', type: String, defaultValue: './webpack.config.js' },
14
14
  { name: 'port', type: Number, defaultValue: 8080 },
15
- { name: 'mode', type: String, defaultValue: 'run' }
15
+ { name: 'mode', type: String, defaultValue: 'build' }
16
16
  ];
17
17
  const options = commandLineArgs(optionDefinitions);
18
18
  if (options.mode === 'watch') {
@@ -55,7 +55,4 @@ app.whenReady().then(() => {
55
55
  }
56
56
  });
57
57
  });
58
- app.on('window-all-closed', () => {
59
- if (process.platform !== 'darwin')
60
- app.quit();
61
- });
58
+ app.on('window-all-closed', () => app.quit());
@@ -7,11 +7,11 @@
7
7
  </head>
8
8
 
9
9
  <body style="width: 100%; height: 100%; margin: 0; padding: 0;">
10
- <webview id="webview" style="width: 100%; height: 100%;" partition="persist:webview"></webview>
10
+ <!-- Remover el webview del HTML -->
11
+ <div id="webview-container" style="width: 100%; height: 100%;"></div>
11
12
 
12
13
  <script>
13
14
  const path = require('path')
14
- const { pathToFileURL } = require('url')
15
15
  let ModuleController;
16
16
  try {
17
17
  const moduleControllerModule = require('@vixoniccom/module-controller');
@@ -23,11 +23,17 @@
23
23
  const remote = require('@electron/remote')
24
24
 
25
25
  ipcRenderer.on('init', (event, options) => {
26
- const webview = document.getElementById('webview')
27
- const win = remote.getCurrentWindow()
28
-
26
+ // Crear el webview dinámicamente
27
+ const webview = document.createElement('webview')
28
+ webview.id = 'webview'
29
+ webview.style.width = '100%'
30
+ webview.style.height = '100%'
31
+ webview.setAttribute('partition', 'persist:webview')
32
+
29
33
  webview.setAttribute('nodeintegration', '')
30
34
  webview.setAttribute('webpreferences', 'webSecurity=false, allowRunningInsecureContent=true, nodeIntegration=yes, contextIsolation=no')
35
+
36
+ const win = remote.getCurrentWindow()
31
37
 
32
38
  webview.addEventListener('did-finish-load', () => {
33
39
  win.show()
@@ -40,27 +46,29 @@
40
46
 
41
47
  webview.src = resolvedSrc
42
48
 
49
+ // Añadir el webview al DOM después de configurarlo
50
+ document.getElementById('webview-container').appendChild(webview)
51
+
43
52
  function getData() {
44
53
  const data = {}
45
54
 
46
55
  try {
47
- data.parameters = require(path.join(options.src, '/test/parameters.json')).parameters
56
+ data.parameters = require(path.join(options.src, 'test', 'parameters.json')).parameters
48
57
  } catch (err) {
49
58
  console.log('No parameters:', err.message)
50
59
  }
51
60
 
52
- const downloadsDir = path.join(
53
- options.mode === 'watch' ? options.src : options.build,
54
- 'test',
55
- 'downloads'
56
- )
61
+ let escaped = path.join(options.mode === 'watch' ? options.src : options.build, 'test', 'downloads')
62
+
63
+ // Add file:// to watch because in this mode the app will be in a localhost hosted environment.
64
+ if (options.mode === 'watch') escaped = `file://${escaped}`
65
+ escaped = escaped.replace(/\\/g, '/')
66
+
67
+ data.downloadsPath = escaped
57
68
 
58
- data.downloadsPath = options.mode === 'watch'
59
- ? pathToFileURL(downloadsDir).href
60
- : downloadsDir.replace(/\\/g, '/')
61
69
 
62
70
  try {
63
- data.services = require(path.join(options.src, '/test/services.json')).services
71
+ data.services = require(path.join(options.src, 'test','services.json')).services
64
72
  } catch (err) {
65
73
  console.log('No services:', err.message)
66
74
  }
package/dist/main.js CHANGED
@@ -16,7 +16,14 @@ import which from 'which';
16
16
  const __filename = fileURLToPath(import.meta.url);
17
17
  const __dirname = path.dirname(__filename);
18
18
  const electronPath = path.join(__dirname, 'electron.js');
19
- const npxPath = which.sync('npx');
19
+ let npxPath;
20
+ try {
21
+ npxPath = which.sync('npx');
22
+ }
23
+ catch (error) {
24
+ console.log(error);
25
+ console.error('Error: npx is not installed or not found in PATH.');
26
+ }
20
27
  const optionDefinitions = [
21
28
  { name: 'externals', type: String, defaultValue: [], multiple: true },
22
29
  { name: 'target', type: String, defaultValue: 'web' },
@@ -47,12 +54,11 @@ function validateOptions(options) {
47
54
  }
48
55
  // Función para sanitizar rutas
49
56
  function sanitizePath(inputPath) {
50
- const resolved = path.resolve(inputPath);
51
- const projectRoot = path.resolve('.');
52
- if (!resolved.startsWith(projectRoot + path.sep) && !resolved.startsWith(projectRoot)) {
53
- throw new Error(`Invalid path outside project scope: ${inputPath}`);
57
+ // Prevenir path traversal
58
+ if (inputPath.includes('..') || inputPath.includes('~')) {
59
+ throw new Error('Invalid path: path traversal detected');
54
60
  }
55
- return resolved;
61
+ return path.resolve(inputPath);
56
62
  }
57
63
  // Función centralizada para crear argumentos de Electron
58
64
  function createElectronArgs(mode) {
@@ -63,9 +69,10 @@ function createElectronArgs(mode) {
63
69
  '--port', String(options.port),
64
70
  '--mode', mode,
65
71
  '--config', options.config,
66
- '--externals', Array.isArray(options.externals) ? options.externals.join(',') : ''
72
+ ...options.externals.flatMap((pkg) => ['--externals', pkg])
67
73
  ];
68
74
  }
75
+ // Función centralizada para manejar procesos Electron
69
76
  function spawnElectronProcess(mode) {
70
77
  const args = createElectronArgs(mode);
71
78
  const nodeEnv = mode === 'run' ? 'production' : 'development';
@@ -77,28 +84,10 @@ function spawnElectronProcess(mode) {
77
84
  ELECTRON_DISABLE_SECURITY_WARNINGS: 'true',
78
85
  NODE_NO_WARNINGS: '1'
79
86
  },
80
- stdio: 'inherit'
81
- });
82
- const signals = ['SIGINT', 'SIGTERM'];
83
- signals.forEach((sig) => {
84
- process.once(sig, () => {
85
- console.log(clc.yellow(`Received ${sig}, terminating Electron process...`));
86
- child.kill(sig);
87
- });
87
+ stdio: ['inherit', 'pipe', 'pipe']
88
88
  });
89
+ // Manejo centralizado de logs
89
90
  setupChildProcessLogging(child);
90
- child.on('exit', (code) => {
91
- if (code !== 0) {
92
- console.error(clc.red(`Electron exited with code ${code}`));
93
- }
94
- if (mode === 'watch') {
95
- process.exit(code ?? 0);
96
- }
97
- });
98
- child.on('error', (err) => {
99
- console.error(clc.red(`Failed to start Electron: ${err.message}`));
100
- process.exit(1);
101
- });
102
91
  return child;
103
92
  }
104
93
  // Función para manejar logging de procesos hijo
@@ -116,16 +105,16 @@ function setupChildProcessLogging(child) {
116
105
  }
117
106
  });
118
107
  }
108
+ // Función centralizada para compilar webpack
119
109
  async function compileWebpack() {
110
+ // CORREGIDO: Usar __dirname para el webpack.config.js del module-packager
120
111
  const cfgPath = path.resolve(__dirname, 'webpack.config.js');
121
112
  const webpackConfigFactory = (await import(cfgPath)).default;
122
113
  const compiler = webpack(webpackConfigFactory(options));
123
114
  return new Promise((resolve, reject) => {
124
115
  compiler.run((err, stats) => {
125
- if (err) {
126
- compiler.close(() => { });
116
+ if (err)
127
117
  return reject(err);
128
- }
129
118
  if (stats?.hasErrors()) {
130
119
  return reject(new Error(stats.toString({ all: false, errors: true, colors: true })));
131
120
  }
@@ -210,7 +199,7 @@ async function pack(callback) {
210
199
  function installExternals(callback) {
211
200
  let externals = options.externals.map((x) => {
212
201
  // Validar nombre del paquete
213
- if (!/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(x)) {
202
+ if (!/^[@a-z0-9-_./]+$/i.test(x)) {
214
203
  throw new Error(`Invalid package name: ${x}`);
215
204
  }
216
205
  const packageJsonPath = sanitizePath(path.resolve(options.src, '..', 'node_modules', x, 'package.json'));
@@ -240,6 +229,7 @@ function zip() {
240
229
  console.log(clc.blue('Cleaning build...'));
241
230
  const buildPath = sanitizePath(options.build);
242
231
  const zipPath = path.resolve(buildPath, '../', 'build.zip');
232
+ console.log("[DEBUG] Cleaning build folder", zipPath);
243
233
  let output = fs.createWriteStream(zipPath);
244
234
  let archive = archiver('zip');
245
235
  archive.pipe(output);
@@ -13,7 +13,9 @@ export default (env = {}, argv = {}) => {
13
13
  port: env.port ?? 8080,
14
14
  mode: argv.mode ?? 'production',
15
15
  };
16
- const isDev = options.mode === 'watch';
16
+ const isDev = options.mode === 'development' ||
17
+ argv.watch === true ||
18
+ process.env.NODE_ENV === 'development';
17
19
  const buildPath = path.resolve(options.build);
18
20
  const controllerHtmlPath = path.resolve(options.src, 'index.html');
19
21
  const controllerStaticPath = path.resolve(path.dirname(controllerHtmlPath), '../static');
@@ -21,7 +23,7 @@ export default (env = {}, argv = {}) => {
21
23
  const controllerTestPath = path.resolve(options.src, 'test');
22
24
  return {
23
25
  mode: isDev ? 'development' : 'production',
24
- target: 'electron-renderer',
26
+ target: options.target,
25
27
  entry: isDev ? [
26
28
  `webpack-dev-server/client?http://localhost:${options.port}/`,
27
29
  'webpack/hot/dev-server',
@@ -30,7 +32,7 @@ export default (env = {}, argv = {}) => {
30
32
  output: {
31
33
  path: buildPath,
32
34
  filename: '[name].js',
33
- publicPath: isDev ? '/' : ''
35
+ publicPath: isDev ? '/' : './'
34
36
  },
35
37
  externals: {
36
38
  electron: 'commonjs electron',
@@ -76,7 +78,7 @@ export default (env = {}, argv = {}) => {
76
78
  test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|mp4)$/,
77
79
  type: 'asset/resource',
78
80
  generator: {
79
- filename: isDev ? '[name][ext]' : '[name].[contenthash:8][ext]'
81
+ filename: '[name][ext]'
80
82
  }
81
83
  },
82
84
  {
@@ -112,7 +114,7 @@ export default (env = {}, argv = {}) => {
112
114
  ]
113
115
  })
114
116
  ],
115
- optimization: isDev ? undefined : {
117
+ optimization: {
116
118
  minimize: !isDev,
117
119
  minimizer: [
118
120
  new TerserPlugin({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vixoniccom/module-packager",
3
- "version": "2.12.0-dev.3",
3
+ "version": "2.12.0-dev.5",
4
4
  "type": "module",
5
5
  "license": "ISC",
6
6
  "bin": {
@@ -9,13 +9,13 @@
9
9
  "files": [
10
10
  "dist"
11
11
  ],
12
- "main": "./dist/main.js",
12
+ "main": "dist/main.js",
13
13
  "scripts": {
14
14
  "start": "electron dist/electron.js --mode run --build ./dist/build",
15
15
  "clean": "rimraf dist",
16
16
  "build:main": "tsc -p tsconfig.json --outDir dist",
17
17
  "build:renderer": "webpack --config webpack.config.js --env src=./ --env build=./dist/build --mode production",
18
- "copy:launcher": "cp launcher.html dist/launcher.html",
18
+ "copy:launcher": "cpy launcher.html dist",
19
19
  "build": "npm run clean && npm-run-all -p build:renderer build:main && npm run copy:launcher",
20
20
  "prerelease-dev": "standard-version --prerelease dev",
21
21
  "prerelease-rc": "standard-version --prerelease rc",
@@ -31,18 +31,19 @@
31
31
  "clean-webpack-plugin": "^4.0.0",
32
32
  "cli-color": "^1.2.0",
33
33
  "command-line-args": "^3.0.1",
34
- "copy-webpack-plugin": "^12.0.2",
34
+ "copy-webpack-plugin": "^13.0.0",
35
+ "cpy-cli": "^5.0.0",
35
36
  "css-loader": "^7.1.2",
36
37
  "electron": "^36.1.0",
37
38
  "electron-debug": "^3.2.0",
38
39
  "global": "^4.4.0",
39
40
  "html-loader": "^5.1.0",
40
- "html-webpack-plugin": "^5.6.0",
41
+ "html-webpack-plugin": "^4.5.2",
41
42
  "lodash": "^4.17.21",
42
43
  "process": "^0.11.10",
43
- "raw-loader": "^0.5.1",
44
+ "raw-loader": "^4.0.2",
45
+ "rimraf": "^6.0.1",
44
46
  "style-loader": "^4.0.0",
45
- "terser-webpack-plugin": "^5.3.10",
46
47
  "ts-loader": "^9.5.0",
47
48
  "ts-node": "^10.9.1",
48
49
  "typescript": "^5.8.3",