@vixoniccom/module-packager 2.12.0 → 2.13.0-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 CHANGED
@@ -40,7 +40,6 @@ function createWindow() {
40
40
  const launcherPath = path.join(__dirname, 'launcher.html');
41
41
  const launcherURL = `file://${launcherPath}`;
42
42
  mainWindow.loadURL(launcherURL);
43
- // mainWindow.webContents.openDevTools({ mode: 'detach' })
44
43
  mainWindow.webContents.once('did-finish-load', () => {
45
44
  mainWindow?.show();
46
45
  mainWindow?.webContents.send('init', options);
@@ -7,7 +7,6 @@
7
7
  </head>
8
8
 
9
9
  <body style="width: 100%; height: 100%; margin: 0; padding: 0;">
10
- <!-- Remover el webview del HTML -->
11
10
  <div id="webview-container" style="width: 100%; height: 100%;"></div>
12
11
 
13
12
  <script>
@@ -23,7 +22,6 @@
23
22
  const remote = require('@electron/remote')
24
23
 
25
24
  ipcRenderer.on('init', (event, options) => {
26
- // Crear el webview dinámicamente
27
25
  const webview = document.createElement('webview')
28
26
  webview.id = 'webview'
29
27
  webview.style.width = '100%'
@@ -46,7 +44,6 @@
46
44
 
47
45
  webview.src = resolvedSrc
48
46
 
49
- // Añadir el webview al DOM después de configurarlo
50
47
  document.getElementById('webview-container').appendChild(webview)
51
48
 
52
49
  function getData() {
@@ -60,7 +57,6 @@
60
57
 
61
58
  let escaped = path.join(options.mode === 'watch' ? options.src : options.build, 'test', 'downloads')
62
59
 
63
- // Add file:// to watch because in this mode the app will be in a localhost hosted environment.
64
60
  if (options.mode === 'watch') escaped = `file://${escaped}`
65
61
  escaped = escaped.replace(/\\/g, '/')
66
62
 
package/dist/main.js CHANGED
@@ -13,6 +13,7 @@ import { Configuration } from '@vixoniccom/modules';
13
13
  import tsNode from 'ts-node';
14
14
  import { createRequire } from 'module';
15
15
  import which from 'which';
16
+ import 'dotenv/config';
16
17
  const __filename = fileURLToPath(import.meta.url);
17
18
  const __dirname = path.dirname(__filename);
18
19
  const electronPath = path.join(__dirname, 'electron.js');
@@ -37,30 +38,24 @@ const optionDefinitions = [
37
38
  { name: 'tsOverride', type: Boolean }
38
39
  ];
39
40
  const options = commandLineArgs(optionDefinitions);
40
- // Validación de entrada mejorada
41
41
  function validateOptions(options) {
42
42
  if (options.target !== 'electron-renderer' && options.externals.length > 0) {
43
43
  throw new Error(`Can't use external dependencies if target is not electron-renderer.`);
44
44
  }
45
- // Validar puerto
46
45
  if (options.port < 1 || options.port > 65535) {
47
46
  throw new Error('Port must be between 1 and 65535');
48
47
  }
49
- // Validar modo
50
48
  const validModes = ['build', 'watch', 'run', 'generate-configuration', 'validate-configuration'];
51
49
  if (!validModes.includes(options.mode)) {
52
50
  throw new Error(`Invalid mode. Must be one of: ${validModes.join(', ')}`);
53
51
  }
54
52
  }
55
- // Función para sanitizar rutas
56
53
  function sanitizePath(inputPath) {
57
- // Prevenir path traversal
58
54
  if (inputPath.includes('..') || inputPath.includes('~')) {
59
55
  throw new Error('Invalid path: path traversal detected');
60
56
  }
61
57
  return path.resolve(inputPath);
62
58
  }
63
- // Función centralizada para crear argumentos de Electron
64
59
  function createElectronArgs(mode) {
65
60
  return [
66
61
  electronPath,
@@ -72,7 +67,6 @@ function createElectronArgs(mode) {
72
67
  ...options.externals.flatMap((pkg) => ['--externals', pkg])
73
68
  ];
74
69
  }
75
- // Función centralizada para manejar procesos Electron
76
70
  function spawnElectronProcess(mode) {
77
71
  const args = createElectronArgs(mode);
78
72
  const nodeEnv = mode === 'run' ? 'production' : 'development';
@@ -86,11 +80,9 @@ function spawnElectronProcess(mode) {
86
80
  },
87
81
  stdio: ['inherit', 'pipe', 'pipe']
88
82
  });
89
- // Manejo centralizado de logs
90
83
  setupChildProcessLogging(child);
91
84
  return child;
92
85
  }
93
- // Función para manejar logging de procesos hijo
94
86
  function setupChildProcessLogging(child) {
95
87
  child.stdout?.on('data', (data) => {
96
88
  const output = data.toString();
@@ -105,20 +97,19 @@ function setupChildProcessLogging(child) {
105
97
  }
106
98
  });
107
99
  }
108
- // Función centralizada para compilar webpack
109
100
  async function compileWebpack() {
110
- // CORREGIDO: Usar __dirname para el webpack.config.js del module-packager
111
101
  const cfgPath = path.resolve(__dirname, 'webpack.config.js');
112
102
  const webpackConfigFactory = (await import(cfgPath)).default;
113
103
  const compiler = webpack(webpackConfigFactory(options));
114
104
  return new Promise((resolve, reject) => {
115
- compiler.run((err, stats) => {
105
+ compiler?.run((err, stats) => {
116
106
  if (err)
117
- return reject(err);
107
+ return reject(new Error(`Webpack compilation error: ${err.message}`));
118
108
  if (stats?.hasErrors()) {
119
- return reject(new Error(stats.toString({ all: false, errors: true, colors: true })));
109
+ const errorMessage = stats.toString({ all: false, errors: true, colors: true });
110
+ return reject(new Error(`Webpack compilation failed: ${errorMessage}`));
120
111
  }
121
- compiler.close(closeErr => (closeErr ? reject(closeErr) : resolve()));
112
+ compiler.close(closeErr => (closeErr ? reject(new Error(`Webpack compilation error: ${closeErr}`)) : resolve()));
122
113
  });
123
114
  });
124
115
  }
@@ -175,7 +166,11 @@ async function pack(callback) {
175
166
  else {
176
167
  console.error(clc.red(JSON.stringify(info, null, 2)));
177
168
  }
178
- callback?.(stats);
169
+ // CORREGIDO: Pasar un objeto Error en lugar de stats
170
+ const errorMessage = info.errors?.length
171
+ ? info.errors.map((e) => typeof e === 'object' ? JSON.stringify(e) : e).join('\n')
172
+ : 'Webpack compilation failed with errors';
173
+ callback?.(new Error(errorMessage));
179
174
  }
180
175
  else {
181
176
  console.log(clc.green('Build OK.'));
@@ -244,7 +239,6 @@ function zip() {
244
239
  clc.move(-2, 0);
245
240
  }
246
241
  async function watch() {
247
- // CORREGIDO: Usar __dirname para el webpack.config.js del module-packager
248
242
  const cfgPath = path.resolve(__dirname, 'webpack.config.js');
249
243
  const webpackConfigFactory = (await import(cfgPath)).default;
250
244
  const compiler = webpack(webpackConfigFactory(options));
@@ -13,9 +13,7 @@ export default (env = {}, argv = {}) => {
13
13
  port: env.port ?? 8080,
14
14
  mode: argv.mode ?? 'production',
15
15
  };
16
- const isDev = options.mode === 'development' ||
17
- argv.watch === true ||
18
- process.env.NODE_ENV === 'development';
16
+ const isDev = options.mode === 'development' || argv.watch === true || process.env.NODE_ENV === 'development';
19
17
  const buildPath = path.resolve(options.build);
20
18
  const controllerHtmlPath = path.resolve(options.src, 'index.html');
21
19
  const controllerStaticPath = path.resolve(path.dirname(controllerHtmlPath), '../static');
@@ -24,20 +22,22 @@ export default (env = {}, argv = {}) => {
24
22
  return {
25
23
  mode: isDev ? 'development' : 'production',
26
24
  target: options.target ?? 'electron-renderer',
27
- entry: isDev ? [
28
- `webpack-dev-server/client?http://localhost:${options.port}/`,
29
- 'webpack/hot/dev-server',
30
- path.resolve(options.src, 'main.ts')
31
- ] : path.resolve(options.src, 'main.ts'),
25
+ entry: isDev
26
+ ? [
27
+ `webpack-dev-server/client?http://localhost:${options.port}/`,
28
+ 'webpack/hot/dev-server',
29
+ path.resolve(options.src, 'main.ts'),
30
+ ]
31
+ : path.resolve(options.src, 'main.ts'),
32
32
  output: {
33
33
  path: buildPath,
34
34
  filename: '[name].js',
35
- publicPath: isDev ? '/' : './'
35
+ publicPath: isDev ? '/' : './',
36
36
  },
37
37
  performance: {
38
38
  maxAssetSize: 2000000, //2MB
39
39
  maxEntrypointSize: 2000000,
40
- hints: isDev ? false : 'warning'
40
+ hints: isDev ? false : 'warning',
41
41
  },
42
42
  externals: {
43
43
  electron: 'commonjs electron',
@@ -46,7 +46,7 @@ export default (env = {}, argv = {}) => {
46
46
  'terser-webpack-plugin': 'commonjs terser-webpack-plugin',
47
47
  esbuild: 'commonjs esbuild',
48
48
  '@swc/core': 'commonjs @swc/core',
49
- '@swc/wasm': 'commonjs @swc/wasm'
49
+ '@swc/wasm': 'commonjs @swc/wasm',
50
50
  },
51
51
  resolve: {
52
52
  extensions: ['.tsx', '.ts', '.js', '.jsx', '.mjs'],
@@ -54,9 +54,9 @@ export default (env = {}, argv = {}) => {
54
54
  fullySpecified: false,
55
55
  fallback: {
56
56
  process: require.resolve('process/browser.js'),
57
- global: require.resolve('global')
57
+ global: require.resolve('global'),
58
58
  },
59
- modules: ['node_modules', 'src', 'static']
59
+ modules: ['node_modules', 'src', 'static'],
60
60
  },
61
61
  module: {
62
62
  rules: [
@@ -66,25 +66,25 @@ export default (env = {}, argv = {}) => {
66
66
  use: {
67
67
  loader: 'ts-loader',
68
68
  options: {
69
- transpileOnly: true
70
- }
71
- }
69
+ transpileOnly: true,
70
+ },
71
+ },
72
72
  },
73
73
  {
74
74
  test: /\.s[ac]ss$/,
75
- use: ['style-loader', 'css-loader', 'sass-loader']
75
+ use: ['style-loader', 'css-loader', 'sass-loader'],
76
76
  },
77
77
  {
78
78
  test: /\.css$/,
79
79
  use: ['style-loader', 'css-loader'],
80
- exclude: /node_modules/
80
+ exclude: /node_modules/,
81
81
  },
82
82
  {
83
83
  test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|mp4)$/,
84
84
  type: 'asset/resource',
85
85
  generator: {
86
- filename: '[name][ext]'
87
- }
86
+ filename: '[name][ext]',
87
+ },
88
88
  },
89
89
  {
90
90
  test: /\.html$/,
@@ -92,32 +92,38 @@ export default (env = {}, argv = {}) => {
92
92
  loader: 'html-loader',
93
93
  options: {
94
94
  sources: false,
95
- }
96
- }
97
- }
98
- ]
95
+ },
96
+ },
97
+ },
98
+ ],
99
99
  },
100
100
  plugins: [
101
101
  new webpack.DefinePlugin({
102
- global: 'globalThis'
102
+ global: 'globalThis',
103
+ // env variables
104
+ 'process.env.AQI_TOKEN': JSON.stringify(process.env.AQI_TOKEN || ''),
105
+ 'process.env.PTS_CLIENT_ID': JSON.stringify(process.env.PTS_CLIENT_ID || ''),
106
+ 'process.env.PTS_CLIENT_SECRET': JSON.stringify(process.env.PTS_CLIENT_SECRET || ''),
107
+ 'process.env.FS_API_KEY': JSON.stringify(process.env.FS_API_KEY || ''),
108
+ 'process.env.FS_API_HOST': JSON.stringify(process.env.FS_API_HOST || ''),
103
109
  }),
104
110
  new webpack.ProvidePlugin({
105
- process: 'process/browser.js'
111
+ process: 'process/browser.js',
106
112
  }),
107
113
  new CleanWebpackPlugin(),
108
114
  new HtmlWebpackPlugin({
109
115
  template: controllerHtmlPath,
110
116
  filename: 'index.html',
111
117
  inject: 'body',
112
- chunks: ['main']
118
+ chunks: ['main'],
113
119
  }),
114
120
  new CopyWebpackPlugin({
115
121
  patterns: [
116
122
  { from: controllerStaticPath, to: 'static', noErrorOnMissing: true },
117
123
  { from: controllerFontsPath, to: 'fonts', noErrorOnMissing: true },
118
- { from: controllerTestPath, to: 'test', noErrorOnMissing: true }
119
- ]
120
- })
124
+ { from: controllerTestPath, to: 'test', noErrorOnMissing: true },
125
+ ],
126
+ }),
121
127
  ],
122
128
  optimization: {
123
129
  minimize: !isDev,
@@ -128,31 +134,33 @@ export default (env = {}, argv = {}) => {
128
134
  ecma: 2020,
129
135
  compress: true,
130
136
  mangle: true,
131
- format: { comments: false }
132
- }
133
- })
134
- ]
137
+ format: { comments: false },
138
+ },
139
+ }),
140
+ ],
135
141
  },
136
142
  devtool: isDev ? 'source-map' : false,
137
- devServer: isDev ? {
138
- static: [
139
- {
140
- directory: path.resolve(options.src, 'test'),
141
- publicPath: '/test',
142
- watch: true,
143
- }
144
- ],
145
- open: false,
146
- client: {
147
- overlay: true
148
- },
149
- port: options.port || 8080,
150
- hot: true,
151
- historyApiFallback: true,
152
- devMiddleware: {
153
- publicPath: '/',
154
- writeToDisk: false
143
+ devServer: isDev
144
+ ? {
145
+ static: [
146
+ {
147
+ directory: path.resolve(options.src, 'test'),
148
+ publicPath: '/test',
149
+ watch: true,
150
+ },
151
+ ],
152
+ open: false,
153
+ client: {
154
+ overlay: true,
155
+ },
156
+ port: options.port || 8080,
157
+ hot: true,
158
+ historyApiFallback: true,
159
+ devMiddleware: {
160
+ publicPath: '/',
161
+ writeToDisk: false,
162
+ },
155
163
  }
156
- } : undefined
164
+ : undefined,
157
165
  };
158
166
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vixoniccom/module-packager",
3
- "version": "2.12.0",
3
+ "version": "2.13.0-dev.0",
4
4
  "type": "module",
5
5
  "license": "ISC",
6
6
  "bin": {
@@ -34,6 +34,7 @@
34
34
  "copy-webpack-plugin": "^13.0.0",
35
35
  "cpy-cli": "^5.0.0",
36
36
  "css-loader": "^7.1.2",
37
+ "dotenv": "^17.2.1",
37
38
  "electron": "^36.1.0",
38
39
  "electron-debug": "^3.2.0",
39
40
  "global": "^4.4.0",