@vixoniccom/module-packager 2.12.0-dev.2 → 2.12.0-dev.3
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 +6 -3
- package/dist/launcher.html +9 -7
- package/dist/main.js +28 -12
- package/dist/webpack.config.js +6 -8
- package/package.json +4 -3
package/dist/electron.js
CHANGED
|
@@ -8,8 +8,8 @@ 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
15
|
{ name: 'mode', type: String, defaultValue: 'run' }
|
|
@@ -55,4 +55,7 @@ app.whenReady().then(() => {
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
|
-
app.on('window-all-closed', () =>
|
|
58
|
+
app.on('window-all-closed', () => {
|
|
59
|
+
if (process.platform !== 'darwin')
|
|
60
|
+
app.quit();
|
|
61
|
+
});
|
package/dist/launcher.html
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
<script>
|
|
13
13
|
const path = require('path')
|
|
14
|
+
const { pathToFileURL } = require('url')
|
|
14
15
|
let ModuleController;
|
|
15
16
|
try {
|
|
16
17
|
const moduleControllerModule = require('@vixoniccom/module-controller');
|
|
@@ -48,14 +49,15 @@
|
|
|
48
49
|
console.log('No parameters:', err.message)
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
data.downloadsPath = escaped
|
|
52
|
+
const downloadsDir = path.join(
|
|
53
|
+
options.mode === 'watch' ? options.src : options.build,
|
|
54
|
+
'test',
|
|
55
|
+
'downloads'
|
|
56
|
+
)
|
|
58
57
|
|
|
58
|
+
data.downloadsPath = options.mode === 'watch'
|
|
59
|
+
? pathToFileURL(downloadsDir).href
|
|
60
|
+
: downloadsDir.replace(/\\/g, '/')
|
|
59
61
|
|
|
60
62
|
try {
|
|
61
63
|
data.services = require(path.join(options.src, '/test/services.json')).services
|
package/dist/main.js
CHANGED
|
@@ -47,11 +47,12 @@ function validateOptions(options) {
|
|
|
47
47
|
}
|
|
48
48
|
// Función para sanitizar rutas
|
|
49
49
|
function sanitizePath(inputPath) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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}`);
|
|
53
54
|
}
|
|
54
|
-
return
|
|
55
|
+
return resolved;
|
|
55
56
|
}
|
|
56
57
|
// Función centralizada para crear argumentos de Electron
|
|
57
58
|
function createElectronArgs(mode) {
|
|
@@ -65,7 +66,6 @@ function createElectronArgs(mode) {
|
|
|
65
66
|
'--externals', Array.isArray(options.externals) ? options.externals.join(',') : ''
|
|
66
67
|
];
|
|
67
68
|
}
|
|
68
|
-
// Función centralizada para manejar procesos Electron
|
|
69
69
|
function spawnElectronProcess(mode) {
|
|
70
70
|
const args = createElectronArgs(mode);
|
|
71
71
|
const nodeEnv = mode === 'run' ? 'production' : 'development';
|
|
@@ -79,8 +79,26 @@ function spawnElectronProcess(mode) {
|
|
|
79
79
|
},
|
|
80
80
|
stdio: 'inherit'
|
|
81
81
|
});
|
|
82
|
-
|
|
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
|
+
});
|
|
88
|
+
});
|
|
83
89
|
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
|
+
});
|
|
84
102
|
return child;
|
|
85
103
|
}
|
|
86
104
|
// Función para manejar logging de procesos hijo
|
|
@@ -98,16 +116,16 @@ function setupChildProcessLogging(child) {
|
|
|
98
116
|
}
|
|
99
117
|
});
|
|
100
118
|
}
|
|
101
|
-
// Función centralizada para compilar webpack
|
|
102
119
|
async function compileWebpack() {
|
|
103
|
-
// CORREGIDO: Usar __dirname para el webpack.config.js del module-packager
|
|
104
120
|
const cfgPath = path.resolve(__dirname, 'webpack.config.js');
|
|
105
121
|
const webpackConfigFactory = (await import(cfgPath)).default;
|
|
106
122
|
const compiler = webpack(webpackConfigFactory(options));
|
|
107
123
|
return new Promise((resolve, reject) => {
|
|
108
124
|
compiler.run((err, stats) => {
|
|
109
|
-
if (err)
|
|
125
|
+
if (err) {
|
|
126
|
+
compiler.close(() => { });
|
|
110
127
|
return reject(err);
|
|
128
|
+
}
|
|
111
129
|
if (stats?.hasErrors()) {
|
|
112
130
|
return reject(new Error(stats.toString({ all: false, errors: true, colors: true })));
|
|
113
131
|
}
|
|
@@ -144,7 +162,6 @@ async function pack(callback) {
|
|
|
144
162
|
console.log(clc.blue('Building module...'));
|
|
145
163
|
validateConfiguration();
|
|
146
164
|
const configPath = path.resolve(__dirname, options.config);
|
|
147
|
-
console.log("🚀 ~ pack ~ configPath:", configPath);
|
|
148
165
|
try {
|
|
149
166
|
const webpackConfig = (await import(configPath)).default(options);
|
|
150
167
|
function handleWebpackError(err) {
|
|
@@ -193,7 +210,7 @@ async function pack(callback) {
|
|
|
193
210
|
function installExternals(callback) {
|
|
194
211
|
let externals = options.externals.map((x) => {
|
|
195
212
|
// Validar nombre del paquete
|
|
196
|
-
if (!/^[
|
|
213
|
+
if (!/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(x)) {
|
|
197
214
|
throw new Error(`Invalid package name: ${x}`);
|
|
198
215
|
}
|
|
199
216
|
const packageJsonPath = sanitizePath(path.resolve(options.src, '..', 'node_modules', x, 'package.json'));
|
|
@@ -223,7 +240,6 @@ function zip() {
|
|
|
223
240
|
console.log(clc.blue('Cleaning build...'));
|
|
224
241
|
const buildPath = sanitizePath(options.build);
|
|
225
242
|
const zipPath = path.resolve(buildPath, '../', 'build.zip');
|
|
226
|
-
console.log("[DEBUG] Cleaning build folder", zipPath);
|
|
227
243
|
let output = fs.createWriteStream(zipPath);
|
|
228
244
|
let archive = archiver('zip');
|
|
229
245
|
archive.pipe(output);
|
package/dist/webpack.config.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
3
2
|
import { createRequire } from 'module';
|
|
4
3
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
5
4
|
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
|
|
6
5
|
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
|
7
6
|
import TerserPlugin from 'terser-webpack-plugin';
|
|
8
7
|
import webpack from 'webpack';
|
|
9
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = path.dirname(__filename);
|
|
11
|
-
console.log("🚀 ~ __dirname:", __dirname);
|
|
12
8
|
export default (env = {}, argv = {}) => {
|
|
13
9
|
const require = createRequire(import.meta.url);
|
|
14
10
|
const options = {
|
|
@@ -22,6 +18,7 @@ export default (env = {}, argv = {}) => {
|
|
|
22
18
|
const controllerHtmlPath = path.resolve(options.src, 'index.html');
|
|
23
19
|
const controllerStaticPath = path.resolve(path.dirname(controllerHtmlPath), '../static');
|
|
24
20
|
const controllerFontsPath = path.resolve(path.dirname(controllerHtmlPath), '../fonts');
|
|
21
|
+
const controllerTestPath = path.resolve(options.src, 'test');
|
|
25
22
|
return {
|
|
26
23
|
mode: isDev ? 'development' : 'production',
|
|
27
24
|
target: 'electron-renderer',
|
|
@@ -33,7 +30,7 @@ export default (env = {}, argv = {}) => {
|
|
|
33
30
|
output: {
|
|
34
31
|
path: buildPath,
|
|
35
32
|
filename: '[name].js',
|
|
36
|
-
publicPath: isDev ? '/' : '
|
|
33
|
+
publicPath: isDev ? '/' : ''
|
|
37
34
|
},
|
|
38
35
|
externals: {
|
|
39
36
|
electron: 'commonjs electron',
|
|
@@ -79,7 +76,7 @@ export default (env = {}, argv = {}) => {
|
|
|
79
76
|
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|mp4)$/,
|
|
80
77
|
type: 'asset/resource',
|
|
81
78
|
generator: {
|
|
82
|
-
filename: '[name][ext]'
|
|
79
|
+
filename: isDev ? '[name][ext]' : '[name].[contenthash:8][ext]'
|
|
83
80
|
}
|
|
84
81
|
},
|
|
85
82
|
{
|
|
@@ -110,12 +107,13 @@ export default (env = {}, argv = {}) => {
|
|
|
110
107
|
new CopyWebpackPlugin({
|
|
111
108
|
patterns: [
|
|
112
109
|
{ from: controllerStaticPath, to: 'static', noErrorOnMissing: true },
|
|
113
|
-
{ from: controllerFontsPath, to: 'fonts', noErrorOnMissing: true }
|
|
110
|
+
{ from: controllerFontsPath, to: 'fonts', noErrorOnMissing: true },
|
|
111
|
+
{ from: controllerTestPath, to: 'test', noErrorOnMissing: true }
|
|
114
112
|
]
|
|
115
113
|
})
|
|
116
114
|
],
|
|
117
115
|
optimization: isDev ? undefined : {
|
|
118
|
-
minimize:
|
|
116
|
+
minimize: !isDev,
|
|
119
117
|
minimizer: [
|
|
120
118
|
new TerserPlugin({
|
|
121
119
|
minify: TerserPlugin.terserMinify,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vixoniccom/module-packager",
|
|
3
|
-
"version": "2.12.0-dev.
|
|
3
|
+
"version": "2.12.0-dev.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"bin": {
|
|
@@ -31,17 +31,18 @@
|
|
|
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": "^
|
|
34
|
+
"copy-webpack-plugin": "^12.0.2",
|
|
35
35
|
"css-loader": "^7.1.2",
|
|
36
36
|
"electron": "^36.1.0",
|
|
37
37
|
"electron-debug": "^3.2.0",
|
|
38
38
|
"global": "^4.4.0",
|
|
39
39
|
"html-loader": "^5.1.0",
|
|
40
|
-
"html-webpack-plugin": "^
|
|
40
|
+
"html-webpack-plugin": "^5.6.0",
|
|
41
41
|
"lodash": "^4.17.21",
|
|
42
42
|
"process": "^0.11.10",
|
|
43
43
|
"raw-loader": "^0.5.1",
|
|
44
44
|
"style-loader": "^4.0.0",
|
|
45
|
+
"terser-webpack-plugin": "^5.3.10",
|
|
45
46
|
"ts-loader": "^9.5.0",
|
|
46
47
|
"ts-node": "^10.9.1",
|
|
47
48
|
"typescript": "^5.8.3",
|