neo.mjs 9.9.0 → 9.10.1
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 +80 -29
- 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/worker/Canvas.mjs +6 -3
- package/src/worker/Task.mjs +6 -3
package/ServiceWorker.mjs
CHANGED
@@ -2,17 +2,52 @@ import fs from 'fs-extra';
|
|
2
2
|
import path from 'path';
|
3
3
|
import {minify as minifyJs} from 'terser';
|
4
4
|
import {minifyHtml} from './util/minifyHtml.mjs';
|
5
|
-
import {fileURLToPath} from 'url';
|
6
5
|
|
7
6
|
const
|
8
|
-
|
9
|
-
__dirname = path.dirname(__filename),
|
10
|
-
inputDirectories = ['apps', 'docs', 'examples', 'src'],
|
11
|
-
outputBasePath = '../dist/esm/',
|
7
|
+
outputBasePath = 'dist/esm/',
|
12
8
|
// Regex to find import statements with 'node_modules' in the path
|
13
9
|
// It captures the entire import statement (excluding the leading 'import') and the path itself.
|
14
|
-
regexImport = /(import(
|
10
|
+
regexImport = /(import(?:\s*(?:[\w*{}\n\r\t, ]+from\s*)?|\s*\(\s*)?)(["'`])((?:(?!\2).)*node_modules(?:(?!\2).)*)\2/g,
|
11
|
+
root = path.resolve(),
|
12
|
+
requireJson = path => JSON.parse(fs.readFileSync(path, 'utf-8')),
|
13
|
+
packageJson = requireJson(path.join(root, 'package.json')),
|
14
|
+
insideNeo = packageJson.name.includes('neo.mjs'),
|
15
|
+
startDate = new Date();
|
16
|
+
|
17
|
+
let inputDirectories;
|
18
|
+
|
19
|
+
if (insideNeo) {
|
20
|
+
inputDirectories = ['apps', 'docs', 'examples', 'src']
|
21
|
+
} else {
|
22
|
+
inputDirectories = ['apps', 'docs', 'node_modules/neo.mjs/src', 'src']
|
23
|
+
}
|
24
|
+
|
25
|
+
/**
|
26
|
+
* @param {String} match
|
27
|
+
* @param {String} p1 will be "import {marked} from " (or similar, including the 'import' keyword and everything up to the first quote)
|
28
|
+
* @param {String} p2 will be the quote character (', ", or `)
|
29
|
+
* @param {String} p3 will be the original path string (e.g., '../../../../node_modules/marked/lib/marked.esm.js')
|
30
|
+
* @returns {String}
|
31
|
+
*/
|
32
|
+
function adjustImportPathHandler(match, p1, p2, p3) {
|
33
|
+
let newPath;
|
34
|
+
|
35
|
+
if (p3.includes('/node_modules/neo.mjs/')) {
|
36
|
+
newPath = p3.replace('/node_modules/neo.mjs/', '/')
|
37
|
+
} else {
|
38
|
+
newPath = '../../' + p3; // Prepend 2 levels up
|
39
|
+
}
|
40
|
+
|
41
|
+
// Reconstruct the import statement with the new path
|
42
|
+
return p1 + p2 + newPath + p2
|
43
|
+
}
|
15
44
|
|
45
|
+
/**
|
46
|
+
*
|
47
|
+
* @param {String} inputDir
|
48
|
+
* @param {String} outputDir
|
49
|
+
* @returns {Promise<void>}
|
50
|
+
*/
|
16
51
|
async function minifyDirectory(inputDir, outputDir) {
|
17
52
|
if (fs.existsSync(inputDir)) {
|
18
53
|
fs.mkdirSync(outputDir, {recursive: true});
|
@@ -20,6 +55,11 @@ async function minifyDirectory(inputDir, outputDir) {
|
|
20
55
|
const dirents = fs.readdirSync(inputDir, {recursive: true, withFileTypes: true});
|
21
56
|
|
22
57
|
for (const dirent of dirents) {
|
58
|
+
// Intended to skip the docs/output folder, since the content is already minified
|
59
|
+
if (dirent.path.includes('/docs/output/')) {
|
60
|
+
continue
|
61
|
+
}
|
62
|
+
|
23
63
|
if (dirent.isFile()) {
|
24
64
|
const
|
25
65
|
inputPath = path.join(dirent.path, dirent.name),
|
@@ -27,7 +67,7 @@ async function minifyDirectory(inputDir, outputDir) {
|
|
27
67
|
outputPath = path.join(outputDir, relativePath),
|
28
68
|
content = fs.readFileSync(inputPath, 'utf8');
|
29
69
|
|
30
|
-
await minifyFile(content, outputPath)
|
70
|
+
await minifyFile(content, outputPath)
|
31
71
|
}
|
32
72
|
// Copy resources folders
|
33
73
|
else if (dirent.name === 'resources') {
|
@@ -50,7 +90,7 @@ async function minifyDirectory(inputDir, outputDir) {
|
|
50
90
|
resourcePath = path.join(resource.path, resource.name),
|
51
91
|
content = fs.readFileSync(resourcePath, 'utf8');
|
52
92
|
|
53
|
-
fs.writeFileSync(resourcePath, JSON.stringify(JSON.parse(content)))
|
93
|
+
fs.writeFileSync(resourcePath, JSON.stringify(JSON.parse(content)))
|
54
94
|
}
|
55
95
|
}
|
56
96
|
}
|
@@ -59,6 +99,11 @@ async function minifyDirectory(inputDir, outputDir) {
|
|
59
99
|
}
|
60
100
|
}
|
61
101
|
|
102
|
+
/**
|
103
|
+
* @param {String} content
|
104
|
+
* @param {String} outputPath
|
105
|
+
* @returns {Promise<void>}
|
106
|
+
*/
|
62
107
|
async function minifyFile(content, outputPath) {
|
63
108
|
fs.mkdirSync(path.dirname(outputPath), {recursive: true});
|
64
109
|
|
@@ -71,32 +116,28 @@ async function minifyFile(content, outputPath) {
|
|
71
116
|
Object.assign(jsonContent, {
|
72
117
|
basePath : '../../' + jsonContent.basePath,
|
73
118
|
environment : 'dist/esm',
|
119
|
+
mainPath : './Main.mjs',
|
74
120
|
workerBasePath: jsonContent.basePath + 'src/worker/'
|
75
|
-
})
|
121
|
+
});
|
122
|
+
|
123
|
+
if (!insideNeo) {
|
124
|
+
jsonContent.appPath = jsonContent.appPath.substring(6)
|
125
|
+
}
|
76
126
|
}
|
77
127
|
|
78
128
|
fs.writeFileSync(outputPath, JSON.stringify(jsonContent));
|
79
|
-
console.log(`Minified JSON: ${outputPath}`)
|
129
|
+
console.log(`Minified JSON: ${outputPath}`)
|
80
130
|
}
|
81
131
|
// Minify HTML files
|
82
132
|
else if (outputPath.endsWith('.html')) {
|
83
133
|
const minifiedContent = await minifyHtml(content);
|
84
134
|
|
85
135
|
fs.writeFileSync(outputPath, minifiedContent);
|
86
|
-
console.log(`Minified HTML: ${outputPath}`)
|
136
|
+
console.log(`Minified HTML: ${outputPath}`)
|
87
137
|
}
|
88
138
|
// Minify JS files
|
89
139
|
else if (outputPath.endsWith('.mjs')) {
|
90
|
-
let adjustedContent = content.replace(regexImport,
|
91
|
-
// p1 will be "import {marked} from " (or similar, including the 'import' keyword and everything up to the first quote)
|
92
|
-
// p2 will be the quote character (', ", or `)
|
93
|
-
// p3 will be the original path string (e.g., '../../../../node_modules/marked/lib/marked.esm.js')
|
94
|
-
|
95
|
-
const newPath = '../../' + p3; // Prepend 2 levels up
|
96
|
-
|
97
|
-
// Reconstruct the import statement with the new path
|
98
|
-
return p1 + p2 + newPath + p2;
|
99
|
-
});
|
140
|
+
let adjustedContent = content.replace(regexImport, adjustImportPathHandler);
|
100
141
|
|
101
142
|
const result = await minifyJs(adjustedContent, {
|
102
143
|
module: true,
|
@@ -109,28 +150,38 @@ async function minifyFile(content, outputPath) {
|
|
109
150
|
});
|
110
151
|
|
111
152
|
fs.writeFileSync(outputPath, result.code);
|
112
|
-
console.log(`Minified JS: ${outputPath}`)
|
153
|
+
console.log(`Minified JS: ${outputPath}`)
|
113
154
|
}
|
114
155
|
} catch (e) {
|
115
|
-
console.error(`Error minifying ${outputPath}:`, e)
|
156
|
+
console.error(`Error minifying ${outputPath}:`, e)
|
116
157
|
}
|
117
158
|
}
|
118
159
|
|
119
160
|
const
|
120
|
-
swContent = fs.readFileSync(path.resolve(
|
121
|
-
promises = [minifyFile(swContent, path.resolve(
|
161
|
+
swContent = fs.readFileSync(path.resolve(root, 'ServiceWorker.mjs'), 'utf8'),
|
162
|
+
promises = [minifyFile(swContent, path.resolve(root, outputBasePath, 'ServiceWorker.mjs'))];
|
122
163
|
|
123
164
|
// Execute the minification
|
124
165
|
inputDirectories.forEach(folder => {
|
125
|
-
|
166
|
+
const outputPath = path.resolve(root, outputBasePath, folder.replace('node_modules/neo.mjs/', ''));
|
167
|
+
|
168
|
+
promises.push(minifyDirectory(path.resolve(root, folder), outputPath)
|
126
169
|
.catch(err => {
|
127
170
|
console.error('dist/esm Minification failed:', err);
|
128
171
|
process.exit(1) // Exit with error code
|
129
172
|
})
|
130
|
-
)
|
173
|
+
)
|
131
174
|
});
|
132
175
|
|
133
176
|
Promise.all(promises).then(() => {
|
134
|
-
|
177
|
+
// Copying the already skipped and minified docs/output folder
|
178
|
+
const docsOutputPath = path.resolve(root, 'docs/output');
|
179
|
+
|
180
|
+
if (fs.existsSync(docsOutputPath)) {
|
181
|
+
fs.copySync(docsOutputPath, path.resolve(root, outputBasePath, 'docs/output'))
|
182
|
+
}
|
183
|
+
|
184
|
+
const processTime = (Math.round((new Date - startDate) * 100) / 100000).toFixed(2);
|
185
|
+
console.log(`\nTotal time for dist/esm: ${processTime}s`);
|
135
186
|
process.exit()
|
136
|
-
})
|
187
|
+
})
|
@@ -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.1'
|
268
268
|
* @memberOf! module:Neo
|
269
269
|
* @name config.version
|
270
270
|
* @type String
|
271
271
|
*/
|
272
|
-
version: '9.
|
272
|
+
version: '9.10.1'
|
273
273
|
};
|
274
274
|
|
275
275
|
Object.assign(DefaultConfig, {
|
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 => {
|