neo.mjs 9.8.0 → 9.10.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/ServiceWorker.mjs +2 -2
- package/apps/portal/view/home/FooterContainer.mjs +1 -1
- package/buildScripts/buildESModules.mjs +98 -66
- package/buildScripts/webpack/buildThreads.mjs +6 -2
- package/buildScripts/webpack/json/build.json +11 -6
- package/package.json +1 -1
- package/src/DefaultConfig.mjs +2 -2
- package/src/main/addon/ServiceWorker.mjs +6 -1
- package/src/worker/Canvas.mjs +6 -3
- package/src/worker/Task.mjs +6 -3
package/ServiceWorker.mjs
CHANGED
@@ -5,13 +5,23 @@ import {minifyHtml} from './util/minifyHtml.mjs';
|
|
5
5
|
import {fileURLToPath} from 'url';
|
6
6
|
|
7
7
|
const
|
8
|
-
|
9
|
-
__dirname = path.dirname(__filename),
|
10
|
-
inputDirectories = ['apps', 'docs', 'examples', 'src'],
|
11
|
-
outputBasePath = '../dist/esm/',
|
8
|
+
outputBasePath = 'dist/esm/',
|
12
9
|
// Regex to find import statements with 'node_modules' in the path
|
13
10
|
// It captures the entire import statement (excluding the leading 'import') and the path itself.
|
14
|
-
regexImport = /(import(?:["'\s]*(?:[\w*{}\n\r\t, ]+)from\s*)?)(["'`])((?:(?!\2).)*node_modules(?:(?!\2).)*)\2/g
|
11
|
+
regexImport = /(import(?:["'\s]*(?:[\w*{}\n\r\t, ]+)from\s*)?)(["'`])((?:(?!\2).)*node_modules(?:(?!\2).)*)\2/g,
|
12
|
+
root = path.resolve(),
|
13
|
+
requireJson = path => JSON.parse(fs.readFileSync(path, 'utf-8')),
|
14
|
+
packageJson = requireJson(path.join(root, 'package.json')),
|
15
|
+
insideNeo = packageJson.name.includes('neo.mjs'),
|
16
|
+
startDate = new Date();
|
17
|
+
|
18
|
+
let inputDirectories;
|
19
|
+
|
20
|
+
if (insideNeo) {
|
21
|
+
inputDirectories = ['apps', 'docs', 'examples', 'src']
|
22
|
+
} else {
|
23
|
+
inputDirectories = ['apps', 'docs', 'node_modules/neo.mjs/src', 'src']
|
24
|
+
}
|
15
25
|
|
16
26
|
async function minifyDirectory(inputDir, outputDir) {
|
17
27
|
if (fs.existsSync(inputDir)) {
|
@@ -20,6 +30,11 @@ async function minifyDirectory(inputDir, outputDir) {
|
|
20
30
|
const dirents = fs.readdirSync(inputDir, {recursive: true, withFileTypes: true});
|
21
31
|
|
22
32
|
for (const dirent of dirents) {
|
33
|
+
// Intended to skip the docs/output folder, since the content is already minified
|
34
|
+
if (dirent.path.includes('/docs/output/')) {
|
35
|
+
continue
|
36
|
+
}
|
37
|
+
|
23
38
|
if (dirent.isFile()) {
|
24
39
|
const
|
25
40
|
inputPath = path.join(dirent.path, dirent.name),
|
@@ -27,60 +42,7 @@ async function minifyDirectory(inputDir, outputDir) {
|
|
27
42
|
outputPath = path.join(outputDir, relativePath),
|
28
43
|
content = fs.readFileSync(inputPath, 'utf8');
|
29
44
|
|
30
|
-
|
31
|
-
|
32
|
-
try {
|
33
|
-
// Minify JSON files
|
34
|
-
if (dirent.name.endsWith('.json')) {
|
35
|
-
const jsonContent = JSON.parse(content);
|
36
|
-
|
37
|
-
if (dirent.name === 'neo-config.json') {
|
38
|
-
Object.assign(jsonContent, {
|
39
|
-
basePath : '../../' + jsonContent.basePath,
|
40
|
-
environment : 'dist/esm',
|
41
|
-
workerBasePath: jsonContent.basePath + 'src/worker/'
|
42
|
-
})
|
43
|
-
}
|
44
|
-
|
45
|
-
fs.writeFileSync(outputPath, JSON.stringify(jsonContent));
|
46
|
-
console.log(`Minified JSON: ${inputPath} -> ${outputPath}`);
|
47
|
-
}
|
48
|
-
// Minify HTML files
|
49
|
-
else if (dirent.name.endsWith('.html')) {
|
50
|
-
const minifiedContent = await minifyHtml(content);
|
51
|
-
|
52
|
-
fs.writeFileSync(outputPath, minifiedContent);
|
53
|
-
console.log(`Minified HTML: ${inputPath} -> ${outputPath}`);
|
54
|
-
}
|
55
|
-
// Minify JS files
|
56
|
-
else if (dirent.name.endsWith('.mjs')) {
|
57
|
-
let adjustedContent = content.replace(regexImport, (match, p1, p2, p3) => {
|
58
|
-
// p1 will be "import {marked} from " (or similar, including the 'import' keyword and everything up to the first quote)
|
59
|
-
// p2 will be the quote character (', ", or `)
|
60
|
-
// p3 will be the original path string (e.g., '../../../../node_modules/marked/lib/marked.esm.js')
|
61
|
-
|
62
|
-
const newPath = '../../' + p3; // Prepend 2 levels up
|
63
|
-
|
64
|
-
// Reconstruct the import statement with the new path
|
65
|
-
return p1 + p2 + newPath + p2;
|
66
|
-
});
|
67
|
-
|
68
|
-
const result = await minifyJs(adjustedContent, {
|
69
|
-
module: true,
|
70
|
-
compress: {
|
71
|
-
dead_code: true
|
72
|
-
},
|
73
|
-
mangle: {
|
74
|
-
toplevel: true
|
75
|
-
}
|
76
|
-
});
|
77
|
-
|
78
|
-
fs.writeFileSync(outputPath, result.code);
|
79
|
-
console.log(`Minified JS: ${inputPath} -> ${outputPath}`);
|
80
|
-
}
|
81
|
-
} catch (e) {
|
82
|
-
console.error(`Error minifying ${inputPath}:`, e);
|
83
|
-
}
|
45
|
+
await minifyFile(content, outputPath)
|
84
46
|
}
|
85
47
|
// Copy resources folders
|
86
48
|
else if (dirent.name === 'resources') {
|
@@ -103,7 +65,7 @@ async function minifyDirectory(inputDir, outputDir) {
|
|
103
65
|
resourcePath = path.join(resource.path, resource.name),
|
104
66
|
content = fs.readFileSync(resourcePath, 'utf8');
|
105
67
|
|
106
|
-
fs.writeFileSync(resourcePath, JSON.stringify(JSON.parse(content)))
|
68
|
+
fs.writeFileSync(resourcePath, JSON.stringify(JSON.parse(content)))
|
107
69
|
}
|
108
70
|
}
|
109
71
|
}
|
@@ -112,19 +74,89 @@ async function minifyDirectory(inputDir, outputDir) {
|
|
112
74
|
}
|
113
75
|
}
|
114
76
|
|
115
|
-
|
77
|
+
async function minifyFile(content, outputPath) {
|
78
|
+
fs.mkdirSync(path.dirname(outputPath), {recursive: true});
|
79
|
+
|
80
|
+
try {
|
81
|
+
// Minify JSON files
|
82
|
+
if (outputPath.endsWith('.json')) {
|
83
|
+
const jsonContent = JSON.parse(content);
|
84
|
+
|
85
|
+
if (outputPath.endsWith('neo-config.json')) {
|
86
|
+
Object.assign(jsonContent, {
|
87
|
+
basePath : '../../' + jsonContent.basePath,
|
88
|
+
environment : 'dist/esm',
|
89
|
+
mainPath : './Main.mjs',
|
90
|
+
workerBasePath: jsonContent.basePath + 'src/worker/'
|
91
|
+
})
|
92
|
+
}
|
93
|
+
|
94
|
+
fs.writeFileSync(outputPath, JSON.stringify(jsonContent));
|
95
|
+
console.log(`Minified JSON: ${outputPath}`)
|
96
|
+
}
|
97
|
+
// Minify HTML files
|
98
|
+
else if (outputPath.endsWith('.html')) {
|
99
|
+
const minifiedContent = await minifyHtml(content);
|
100
|
+
|
101
|
+
fs.writeFileSync(outputPath, minifiedContent);
|
102
|
+
console.log(`Minified HTML: ${outputPath}`)
|
103
|
+
}
|
104
|
+
// Minify JS files
|
105
|
+
else if (outputPath.endsWith('.mjs')) {
|
106
|
+
let adjustedContent = content.replace(regexImport, (match, p1, p2, p3) => {
|
107
|
+
// p1 will be "import {marked} from " (or similar, including the 'import' keyword and everything up to the first quote)
|
108
|
+
// p2 will be the quote character (', ", or `)
|
109
|
+
// p3 will be the original path string (e.g., '../../../../node_modules/marked/lib/marked.esm.js')
|
110
|
+
|
111
|
+
const newPath = '../../' + p3; // Prepend 2 levels up
|
112
|
+
|
113
|
+
// Reconstruct the import statement with the new path
|
114
|
+
return p1 + p2 + newPath + p2
|
115
|
+
});
|
116
|
+
|
117
|
+
const result = await minifyJs(adjustedContent, {
|
118
|
+
module: true,
|
119
|
+
compress: {
|
120
|
+
dead_code: true
|
121
|
+
},
|
122
|
+
mangle: {
|
123
|
+
toplevel: true
|
124
|
+
}
|
125
|
+
});
|
126
|
+
|
127
|
+
fs.writeFileSync(outputPath, result.code);
|
128
|
+
console.log(`Minified JS: ${outputPath}`)
|
129
|
+
}
|
130
|
+
} catch (e) {
|
131
|
+
console.error(`Error minifying ${outputPath}:`, e)
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
const
|
136
|
+
swContent = fs.readFileSync(path.resolve(root, 'ServiceWorker.mjs'), 'utf8'),
|
137
|
+
promises = [minifyFile(swContent, path.resolve(root, outputBasePath, 'ServiceWorker.mjs'))];
|
116
138
|
|
117
139
|
// Execute the minification
|
118
140
|
inputDirectories.forEach(folder => {
|
119
|
-
|
141
|
+
const outputPath = path.resolve(root, outputBasePath, folder.replace('node_modules/neo.mjs/', ''));
|
142
|
+
|
143
|
+
promises.push(minifyDirectory(path.resolve(root, folder), outputPath)
|
120
144
|
.catch(err => {
|
121
|
-
console.error('Minification failed:', err);
|
145
|
+
console.error('dist/esm Minification failed:', err);
|
122
146
|
process.exit(1) // Exit with error code
|
123
147
|
})
|
124
|
-
)
|
148
|
+
)
|
125
149
|
});
|
126
150
|
|
127
151
|
Promise.all(promises).then(() => {
|
128
|
-
|
152
|
+
// Copying the already skipped and minified docs/output folder
|
153
|
+
const docsOutputPath = path.resolve(root, 'docs/output');
|
154
|
+
|
155
|
+
if (fs.existsSync(docsOutputPath)) {
|
156
|
+
fs.copySync(docsOutputPath, path.resolve(root, outputBasePath, 'docs/output'))
|
157
|
+
}
|
158
|
+
|
159
|
+
const processTime = (Math.round((new Date - startDate) * 100) / 100000).toFixed(2);
|
160
|
+
console.log(`\nTotal time for dist/esm: ${processTime}s`);
|
129
161
|
process.exit()
|
130
|
-
})
|
162
|
+
})
|
@@ -26,7 +26,7 @@ program
|
|
26
26
|
.option('-e, --env <value>', '"all", "dev", "prod"')
|
27
27
|
.option('-f, --framework')
|
28
28
|
.option('-n, --noquestions')
|
29
|
-
.option('-t, --threads <value>', '"all", "app", "data", "main", "vdom"')
|
29
|
+
.option('-t, --threads <value>', '"all", "app", "canvas", "data", "main", "service", "task", "vdom"')
|
30
30
|
.allowUnknownOption()
|
31
31
|
.on('--help', () => {
|
32
32
|
console.log('\nIn case you have any issues, please create a ticket here:');
|
@@ -61,7 +61,7 @@ if (programOpts.info) {
|
|
61
61
|
type : 'list',
|
62
62
|
name : 'threads',
|
63
63
|
message: 'Please choose the threads to build:',
|
64
|
-
choices: ['all', 'app', 'canvas', 'data', 'main', 'service', 'vdom'],
|
64
|
+
choices: ['all', 'app', 'canvas', 'data', 'main', 'service', 'task', 'vdom'],
|
65
65
|
default: 'all'
|
66
66
|
});
|
67
67
|
}
|
@@ -110,6 +110,10 @@ if (programOpts.info) {
|
|
110
110
|
childProcess = spawnSync(webpack, ['--config', `${tPath}.worker.mjs`, `--env insideNeo=${insideNeo} worker=service`], cpOpts);
|
111
111
|
childProcess.status && process.exit(childProcess.status);
|
112
112
|
}
|
113
|
+
if (threads === 'all' || threads === 'task') {
|
114
|
+
childProcess = spawnSync(webpack, ['--config', `${tPath}.worker.mjs`, `--env insideNeo=${insideNeo} worker=task`], cpOpts);
|
115
|
+
childProcess.status && process.exit(childProcess.status);
|
116
|
+
}
|
113
117
|
if (threads === 'all' || threads === 'vdom') {
|
114
118
|
childProcess = spawnSync(webpack, ['--config', `${tPath}.worker.mjs`, `--env insideNeo=${insideNeo} worker=vdom`], cpOpts);
|
115
119
|
childProcess.status && process.exit(childProcess.status);
|
@@ -1,25 +1,30 @@
|
|
1
1
|
{
|
2
|
-
"mainInput": "./src/Main.mjs",
|
2
|
+
"mainInput" : "./src/Main.mjs",
|
3
3
|
"mainOutput": "main.js",
|
4
|
+
|
4
5
|
"workers": {
|
5
6
|
"app": {
|
6
|
-
"input": "./src/worker/App.mjs",
|
7
|
+
"input" : "./src/worker/App.mjs",
|
7
8
|
"output": "appworker.js"
|
8
9
|
},
|
9
10
|
"canvas": {
|
10
|
-
"input": "./src/worker/Canvas.mjs",
|
11
|
+
"input" : "./src/worker/Canvas.mjs",
|
11
12
|
"output": "canvasworker.js"
|
12
13
|
},
|
13
14
|
"data": {
|
14
|
-
"input": "./src/worker/Data.mjs",
|
15
|
+
"input" : "./src/worker/Data.mjs",
|
15
16
|
"output": "dataworker.js"
|
16
17
|
},
|
17
18
|
"service": {
|
18
|
-
"input": "./ServiceWorker.mjs",
|
19
|
+
"input" : "./ServiceWorker.mjs",
|
19
20
|
"output": "serviceworker.js"
|
20
21
|
},
|
22
|
+
"task": {
|
23
|
+
"input" : "./src/worker/Task.mjs",
|
24
|
+
"output": "taskworker.js"
|
25
|
+
},
|
21
26
|
"vdom": {
|
22
|
-
"input": "./src/worker/VDom.mjs",
|
27
|
+
"input" : "./src/worker/VDom.mjs",
|
23
28
|
"output": "vdomworker.js"
|
24
29
|
}
|
25
30
|
}
|
package/package.json
CHANGED
package/src/DefaultConfig.mjs
CHANGED
@@ -264,12 +264,12 @@ const DefaultConfig = {
|
|
264
264
|
useVdomWorker: true,
|
265
265
|
/**
|
266
266
|
* buildScripts/injectPackageVersion.mjs will update this value
|
267
|
-
* @default '9.
|
267
|
+
* @default '9.10.0'
|
268
268
|
* @memberOf! module:Neo
|
269
269
|
* @name config.version
|
270
270
|
* @type String
|
271
271
|
*/
|
272
|
-
version: '9.
|
272
|
+
version: '9.10.0'
|
273
273
|
};
|
274
274
|
|
275
275
|
Object.assign(DefaultConfig, {
|
@@ -32,13 +32,18 @@ class ServiceWorker extends Base {
|
|
32
32
|
{config} = Neo,
|
33
33
|
{environment} = config,
|
34
34
|
devMode = environment === 'development',
|
35
|
-
|
35
|
+
distEsm = environment === 'dist/esm',
|
36
|
+
hasJsModules = devMode || distEsm,
|
36
37
|
fileName = hasJsModules ? 'ServiceWorker.mjs' : 'serviceworker.js',
|
37
38
|
opts = hasJsModules ? {type: 'module'} : {},
|
38
39
|
path = (hasJsModules ? config.basePath : config.workerBasePath) + fileName,
|
39
40
|
{serviceWorker} = navigator,
|
40
41
|
registration;
|
41
42
|
|
43
|
+
if (distEsm) {
|
44
|
+
path = path.substring(6)
|
45
|
+
}
|
46
|
+
|
42
47
|
registration = await serviceWorker.register(path, opts);
|
43
48
|
|
44
49
|
window.addEventListener('beforeunload', me.onBeforeUnload.bind(me));
|
package/src/worker/Canvas.mjs
CHANGED
@@ -67,11 +67,14 @@ class Canvas extends Base {
|
|
67
67
|
onRegisterNeoConfig(msg) {
|
68
68
|
super.onRegisterNeoConfig(msg);
|
69
69
|
|
70
|
-
let path = Neo.config.appPath
|
70
|
+
let path = Neo.config.appPath;
|
71
|
+
|
72
|
+
if (path.endsWith('.mjs')) {
|
73
|
+
path = path.slice(0, -8); // removing "/app.mjs"
|
74
|
+
}
|
71
75
|
|
72
76
|
import(
|
73
|
-
/*
|
74
|
-
/* webpackExclude: /\/node_modules/ */
|
77
|
+
/* webpackExclude: /(?:\/|\\)(dist|node_modules)/ */
|
75
78
|
/* webpackMode: "lazy" */
|
76
79
|
`../../${path}/canvas.mjs`
|
77
80
|
).then(module => {
|
package/src/worker/Task.mjs
CHANGED
@@ -49,11 +49,14 @@ class Task extends Base {
|
|
49
49
|
onRegisterNeoConfig(msg) {
|
50
50
|
super.onRegisterNeoConfig(msg);
|
51
51
|
|
52
|
-
let path = Neo.config.appPath
|
52
|
+
let path = Neo.config.appPath;
|
53
|
+
|
54
|
+
if (path.endsWith('.mjs')) {
|
55
|
+
path = path.slice(0, -8); // removing "/app.mjs"
|
56
|
+
}
|
53
57
|
|
54
58
|
import(
|
55
|
-
/*
|
56
|
-
/* webpackExclude: /\/node_modules/ */
|
59
|
+
/* webpackExclude: /(?:\/|\\)(dist|node_modules)/ */
|
57
60
|
/* webpackMode: "lazy" */
|
58
61
|
`../../${path}/task.mjs`
|
59
62
|
).then(module => {
|