neo.mjs 9.6.0 → 9.7.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/{apps/ServiceWorker.mjs → ServiceWorker.mjs} +5 -5
- package/apps/portal/view/home/FooterContainer.mjs +1 -1
- package/apps/portal/view/learn/MainContainerStateProvider.mjs +2 -2
- package/buildScripts/buildESModules.mjs +21 -3
- package/buildScripts/injectPackageVersion.mjs +19 -28
- package/buildScripts/webpack/development/webpack.config.worker.mjs +1 -1
- package/buildScripts/webpack/json/build.json +1 -1
- package/package.json +1 -1
- package/src/DefaultConfig.mjs +4 -3
- package/src/Main.mjs +10 -9
- package/src/main/addon/ServiceWorker.mjs +9 -6
- package/src/main/addon/Stylesheet.mjs +1 -13
- package/src/worker/Manager.mjs +1 -7
- package/src/worker/ServiceBase.mjs +1 -0
- package/examples/ServiceWorker.mjs +0 -35
@@ -1,6 +1,6 @@
|
|
1
|
-
import Neo from '
|
2
|
-
import * as core from '
|
3
|
-
import ServiceBase from '
|
1
|
+
import Neo from './src/Neo.mjs';
|
2
|
+
import * as core from './src/core/_export.mjs';
|
3
|
+
import ServiceBase from './src/worker/ServiceBase.mjs';
|
4
4
|
|
5
5
|
/**
|
6
6
|
* @class Neo.ServiceWorker
|
@@ -20,9 +20,9 @@ class ServiceWorker extends ServiceBase {
|
|
20
20
|
*/
|
21
21
|
singleton: true,
|
22
22
|
/**
|
23
|
-
* @member {String} version='9.
|
23
|
+
* @member {String} version='9.7.0'
|
24
24
|
*/
|
25
|
-
version: '9.
|
25
|
+
version: '9.7.0'
|
26
26
|
}
|
27
27
|
|
28
28
|
/**
|
@@ -14,9 +14,9 @@ class MainContainerStateProvider extends StateProvider {
|
|
14
14
|
*/
|
15
15
|
className: 'Portal.view.learn.MainContainerStateProvider',
|
16
16
|
/**
|
17
|
-
* @member {String} contentBasePath='
|
17
|
+
* @member {String} contentBasePath=Neo.config.basePath+'resources/data/deck/'
|
18
18
|
*/
|
19
|
-
contentBasePath: '
|
19
|
+
contentBasePath: Neo.config.basePath + 'resources/data/deck/',
|
20
20
|
/**
|
21
21
|
* @member {Object} data
|
22
22
|
*/
|
@@ -8,7 +8,10 @@ const
|
|
8
8
|
__filename = fileURLToPath(import.meta.url),
|
9
9
|
__dirname = path.dirname(__filename),
|
10
10
|
inputDirectories = ['apps', 'docs', 'examples', 'src'],
|
11
|
-
outputBasePath = '../dist/esm/'
|
11
|
+
outputBasePath = '../dist/esm/',
|
12
|
+
// Regex to find import statements with 'node_modules' in the path
|
13
|
+
// 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;
|
12
15
|
|
13
16
|
async function minifyDirectory(inputDir, outputDir) {
|
14
17
|
if (fs.existsSync(inputDir)) {
|
@@ -32,7 +35,11 @@ async function minifyDirectory(inputDir, outputDir) {
|
|
32
35
|
const jsonContent = JSON.parse(content);
|
33
36
|
|
34
37
|
if (dirent.name === 'neo-config.json') {
|
35
|
-
jsonContent
|
38
|
+
Object.assign(jsonContent, {
|
39
|
+
basePath : '../../' + jsonContent.basePath,
|
40
|
+
environment : 'dist/esm',
|
41
|
+
workerBasePath: jsonContent.basePath + 'src/worker/'
|
42
|
+
})
|
36
43
|
}
|
37
44
|
|
38
45
|
fs.writeFileSync(outputPath, JSON.stringify(jsonContent));
|
@@ -47,7 +54,18 @@ async function minifyDirectory(inputDir, outputDir) {
|
|
47
54
|
}
|
48
55
|
// Minify JS files
|
49
56
|
else if (dirent.name.endsWith('.mjs')) {
|
50
|
-
|
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, {
|
51
69
|
module: true,
|
52
70
|
compress: {
|
53
71
|
dead_code: true
|
@@ -15,20 +15,13 @@ const
|
|
15
15
|
neoPath = insideNeo ? './' : './node_modules/neo.mjs/',
|
16
16
|
programName = `${packageJson.name} inject-package-version`;
|
17
17
|
|
18
|
-
let startDate
|
19
|
-
configPath
|
20
|
-
contentArray
|
21
|
-
i
|
22
|
-
len
|
23
|
-
|
24
|
-
|
25
|
-
serviceContentArray, serviceWorkerPath
|
26
|
-
|
27
|
-
if (!insideNeo) {
|
28
|
-
// todo
|
29
|
-
} else {
|
30
|
-
serviceWorkerFolders.push('examples');
|
31
|
-
}
|
18
|
+
let startDate = new Date(),
|
19
|
+
configPath = path.join(__dirname, 'src/DefaultConfig.mjs'),
|
20
|
+
contentArray = fs.readFileSync(configPath).toString().split(os.EOL),
|
21
|
+
i = 0,
|
22
|
+
len = contentArray.length,
|
23
|
+
versionString = `'${packageJson.version}'`,
|
24
|
+
serviceContentArray, serviceWorkerPath;
|
32
25
|
|
33
26
|
for (; i < len; i++) {
|
34
27
|
if (contentArray[i].includes('version:')) {
|
@@ -41,24 +34,22 @@ for (; i < len; i++) {
|
|
41
34
|
|
42
35
|
fs.writeFileSync(configPath, contentArray.join(os.EOL));
|
43
36
|
|
44
|
-
|
45
|
-
|
46
|
-
serviceContentArray = fs.readFileSync(serviceWorkerPath).toString().split(os.EOL);
|
37
|
+
serviceWorkerPath = path.join(__dirname, 'ServiceWorker.mjs');
|
38
|
+
serviceContentArray = fs.readFileSync(serviceWorkerPath, 'utf-8').toString().split(os.EOL);
|
47
39
|
|
48
|
-
|
49
|
-
|
40
|
+
i = 0;
|
41
|
+
len = serviceContentArray.length;
|
50
42
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
}
|
43
|
+
for (; i < len; i++) {
|
44
|
+
if (serviceContentArray[i].includes('version:')) {
|
45
|
+
// we want to update the comment inside ServiceWorker.mjs as well
|
46
|
+
serviceContentArray[i - 2] = serviceContentArray[i - 2].replace(/'\d.+'/, versionString);
|
47
|
+
serviceContentArray[i] = serviceContentArray[i] .replace(/'\d.+'/, versionString);
|
48
|
+
break;
|
58
49
|
}
|
50
|
+
}
|
59
51
|
|
60
|
-
|
61
|
-
});
|
52
|
+
fs.writeFileSync(serviceWorkerPath, serviceContentArray.join(os.EOL));
|
62
53
|
|
63
54
|
// Update the version inside the Portal App Footer
|
64
55
|
if (insideNeo) {
|
@@ -15,7 +15,7 @@ export default env => {
|
|
15
15
|
|
16
16
|
if (filenameConfig.workers) {
|
17
17
|
Object.entries(filenameConfig.workers).forEach(([key, value]) => {
|
18
|
-
// Inside a neo workspace, we want to use the SW inside the top level
|
18
|
+
// Inside a neo workspace, we want to use the SW inside the top level folder,
|
19
19
|
// to allow overriding its logic
|
20
20
|
if (key === env.worker) {
|
21
21
|
entry[key] = path.resolve(key === 'service' && !insideNeo ? cwd : neoPath, value.input);
|
package/package.json
CHANGED
package/src/DefaultConfig.mjs
CHANGED
@@ -229,7 +229,8 @@ const DefaultConfig = {
|
|
229
229
|
* True will add the ServiceWorker main thread addon to support caching of assets (PWA)
|
230
230
|
* See: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
|
231
231
|
*
|
232
|
-
* You can also use a string to specify the target environment => 'dist/production'
|
232
|
+
* You can also use a string to specify the target environment => 'dist/production'.
|
233
|
+
* Using 'dist/production' will also use the service worker for 'dist/esm'
|
233
234
|
* @default false
|
234
235
|
* @memberOf! module:Neo
|
235
236
|
* @name config.useServiceWorker
|
@@ -263,12 +264,12 @@ const DefaultConfig = {
|
|
263
264
|
useVdomWorker: true,
|
264
265
|
/**
|
265
266
|
* buildScripts/injectPackageVersion.mjs will update this value
|
266
|
-
* @default '9.
|
267
|
+
* @default '9.7.0'
|
267
268
|
* @memberOf! module:Neo
|
268
269
|
* @name config.version
|
269
270
|
* @type String
|
270
271
|
*/
|
271
|
-
version: '9.
|
272
|
+
version: '9.7.0'
|
272
273
|
};
|
273
274
|
|
274
275
|
Object.assign(DefaultConfig, {
|
package/src/Main.mjs
CHANGED
@@ -243,28 +243,29 @@ class Main extends core.Base {
|
|
243
243
|
*
|
244
244
|
*/
|
245
245
|
async onDomContentLoaded() {
|
246
|
-
let me
|
247
|
-
{config}
|
248
|
-
|
249
|
-
|
246
|
+
let me = this,
|
247
|
+
{config} = Neo,
|
248
|
+
imports = [],
|
249
|
+
{environment, mainThreadAddons, useServiceWorker} = config,
|
250
250
|
modules;
|
251
251
|
|
252
252
|
DomAccess.onDomContentLoaded();
|
253
253
|
|
254
|
-
//
|
254
|
+
// We need different publicPath values for the main thread inside the webpack based dist envs,
|
255
255
|
// depending on the hierarchy level of the app entry point
|
256
|
-
if (
|
256
|
+
if (environment === 'dist/development' || environment === 'dist/production') {
|
257
257
|
__webpack_require__.p = config.basePath.substring(6)
|
258
258
|
}
|
259
259
|
|
260
|
-
//
|
260
|
+
// Intended for the online examples where we need an easy way to add GA to every generated app
|
261
261
|
if (config.useGoogleAnalytics && !mainThreadAddons.includes('AnalyticsByGoogle')) {
|
262
262
|
mainThreadAddons.push('AnalyticsByGoogle')
|
263
263
|
}
|
264
264
|
|
265
265
|
if ((
|
266
|
-
|
267
|
-
|
266
|
+
useServiceWorker === true ||
|
267
|
+
useServiceWorker === environment ||
|
268
|
+
(useServiceWorker === 'dist/production' && environment === 'dist/esm')
|
268
269
|
) &&
|
269
270
|
!mainThreadAddons.includes('ServiceWorker')
|
270
271
|
) {
|
@@ -30,13 +30,16 @@ class ServiceWorker extends Base {
|
|
30
30
|
if ('serviceWorker' in navigator) {
|
31
31
|
let me = this,
|
32
32
|
{config} = Neo,
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
{environment} = config,
|
34
|
+
devMode = environment === 'development',
|
35
|
+
hasJsModules = devMode || environment === 'dist/esm',
|
36
|
+
fileName = hasJsModules ? 'ServiceWorker.mjs' : 'serviceworker.js',
|
37
|
+
opts = hasJsModules ? {type: 'module'} : {},
|
38
|
+
path = (hasJsModules ? config.basePath : config.workerBasePath) + fileName,
|
38
39
|
{serviceWorker} = navigator,
|
39
|
-
registration
|
40
|
+
registration;
|
41
|
+
|
42
|
+
registration = await serviceWorker.register(path, opts);
|
40
43
|
|
41
44
|
window.addEventListener('beforeunload', me.onBeforeUnload.bind(me));
|
42
45
|
|
@@ -48,11 +48,7 @@ class Stylesheet extends Base {
|
|
48
48
|
|
49
49
|
if (neoConfig.useFontAwesome) {
|
50
50
|
if (env === 'development' || env === 'dist/esm') {
|
51
|
-
faPath = neoConfig.basePath + 'node_modules/@fortawesome/fontawesome-free/css/all.min.css'
|
52
|
-
|
53
|
-
if (env === 'dist/esm') {
|
54
|
-
faPath = '../../' + faPath
|
55
|
-
}
|
51
|
+
faPath = neoConfig.basePath + 'node_modules/@fortawesome/fontawesome-free/css/all.min.css'
|
56
52
|
} else {
|
57
53
|
faPath = neoConfig.basePath.substring(6) + 'resources/fontawesome-free/css/all.min.css'
|
58
54
|
}
|
@@ -78,10 +74,6 @@ class Stylesheet extends Base {
|
|
78
74
|
|
79
75
|
document.body.classList.add(themes[0]);
|
80
76
|
|
81
|
-
if (env === 'dist/esm') {
|
82
|
-
path = '../../' + path;
|
83
|
-
}
|
84
|
-
|
85
77
|
folders.forEach(folder => {
|
86
78
|
if (folder.startsWith('neo-')) {
|
87
79
|
folder = folder.substring(4)
|
@@ -109,10 +101,6 @@ class Stylesheet extends Base {
|
|
109
101
|
promises = [],
|
110
102
|
rootPath = config.basePath.substring(6);
|
111
103
|
|
112
|
-
if (env === 'dist/esm') {
|
113
|
-
path = '../../' + path;
|
114
|
-
}
|
115
|
-
|
116
104
|
if (className.startsWith('Neo.')) {
|
117
105
|
className = className.substring(4)
|
118
106
|
}
|
package/src/worker/Manager.mjs
CHANGED
@@ -42,12 +42,6 @@ class Manager extends Base {
|
|
42
42
|
* @protected
|
43
43
|
*/
|
44
44
|
appNames: [],
|
45
|
-
/**
|
46
|
-
* The base path for the worker file URLs, can e.g. get set inside the index.html.
|
47
|
-
* @member {String|null} basePath=Neo.config.workerBasePath || 'worker/'
|
48
|
-
* @protected
|
49
|
-
*/
|
50
|
-
basePath: NeoConfig.workerBasePath || 'worker/',
|
51
45
|
/**
|
52
46
|
* @member {Number} constructedThreads=0
|
53
47
|
* @protected
|
@@ -164,7 +158,7 @@ class Manager extends Base {
|
|
164
158
|
createWorker(opts) {
|
165
159
|
let me = this,
|
166
160
|
{fileName} = opts,
|
167
|
-
filePath = (opts.basePath ||
|
161
|
+
filePath = (opts.basePath || Neo.config.workerBasePath) + fileName,
|
168
162
|
name = `neomjs-${fileName.substring(0, fileName.indexOf('.')).toLowerCase()}-worker`,
|
169
163
|
isShared = me.sharedWorkersEnabled && NeoConfig.useSharedWorkers,
|
170
164
|
cls = isShared ? SharedWorker : Worker,
|
@@ -1,35 +0,0 @@
|
|
1
|
-
import Neo from '../src/Neo.mjs';
|
2
|
-
import * as core from '../src/core/_export.mjs';
|
3
|
-
import ServiceBase from '../src/worker/ServiceBase.mjs';
|
4
|
-
|
5
|
-
/**
|
6
|
-
* @class Neo.ServiceWorker
|
7
|
-
* @extends Neo.worker.ServiceBase
|
8
|
-
* @singleton
|
9
|
-
*/
|
10
|
-
class ServiceWorker extends ServiceBase {
|
11
|
-
static config = {
|
12
|
-
/**
|
13
|
-
* @member {String} className='Neo.ServiceWorker'
|
14
|
-
* @protected
|
15
|
-
*/
|
16
|
-
className: 'Neo.ServiceWorker',
|
17
|
-
/**
|
18
|
-
* @member {Boolean} singleton=true
|
19
|
-
* @protected
|
20
|
-
*/
|
21
|
-
singleton: true,
|
22
|
-
/**
|
23
|
-
* @member {String} version='9.6.0'
|
24
|
-
*/
|
25
|
-
version: '9.6.0'
|
26
|
-
}
|
27
|
-
|
28
|
-
/**
|
29
|
-
* @member {String} workerId='service'
|
30
|
-
* @protected
|
31
|
-
*/
|
32
|
-
workerId = 'service'
|
33
|
-
}
|
34
|
-
|
35
|
-
export default Neo.setupClass(ServiceWorker);
|