neo.mjs 9.8.0 → 9.9.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 CHANGED
@@ -20,9 +20,9 @@ class ServiceWorker extends ServiceBase {
20
20
  */
21
21
  singleton: true,
22
22
  /**
23
- * @member {String} version='9.8.0'
23
+ * @member {String} version='9.9.0'
24
24
  */
25
- version: '9.8.0'
25
+ version: '9.9.0'
26
26
  }
27
27
 
28
28
  /**
@@ -107,7 +107,7 @@ class FooterContainer extends Container {
107
107
  }, {
108
108
  module: Component,
109
109
  cls : ['neo-version'],
110
- html : 'v9.8.0'
110
+ html : 'v9.9.0'
111
111
  }]
112
112
  }],
113
113
  /**
@@ -27,60 +27,7 @@ async function minifyDirectory(inputDir, outputDir) {
27
27
  outputPath = path.join(outputDir, relativePath),
28
28
  content = fs.readFileSync(inputPath, 'utf8');
29
29
 
30
- fs.mkdirSync(path.dirname(outputPath), {recursive: true});
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
- }
30
+ await minifyFile(content, outputPath);
84
31
  }
85
32
  // Copy resources folders
86
33
  else if (dirent.name === 'resources') {
@@ -112,19 +59,78 @@ async function minifyDirectory(inputDir, outputDir) {
112
59
  }
113
60
  }
114
61
 
115
- const promises = [];
62
+ async function minifyFile(content, outputPath) {
63
+ fs.mkdirSync(path.dirname(outputPath), {recursive: true});
64
+
65
+ try {
66
+ // Minify JSON files
67
+ if (outputPath.endsWith('.json')) {
68
+ const jsonContent = JSON.parse(content);
69
+
70
+ if (outputPath.endsWith('neo-config.json')) {
71
+ Object.assign(jsonContent, {
72
+ basePath : '../../' + jsonContent.basePath,
73
+ environment : 'dist/esm',
74
+ workerBasePath: jsonContent.basePath + 'src/worker/'
75
+ })
76
+ }
77
+
78
+ fs.writeFileSync(outputPath, JSON.stringify(jsonContent));
79
+ console.log(`Minified JSON: ${outputPath}`);
80
+ }
81
+ // Minify HTML files
82
+ else if (outputPath.endsWith('.html')) {
83
+ const minifiedContent = await minifyHtml(content);
84
+
85
+ fs.writeFileSync(outputPath, minifiedContent);
86
+ console.log(`Minified HTML: ${outputPath}`);
87
+ }
88
+ // Minify JS files
89
+ else if (outputPath.endsWith('.mjs')) {
90
+ let adjustedContent = content.replace(regexImport, (match, p1, p2, p3) => {
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
+ });
100
+
101
+ const result = await minifyJs(adjustedContent, {
102
+ module: true,
103
+ compress: {
104
+ dead_code: true
105
+ },
106
+ mangle: {
107
+ toplevel: true
108
+ }
109
+ });
110
+
111
+ fs.writeFileSync(outputPath, result.code);
112
+ console.log(`Minified JS: ${outputPath}`);
113
+ }
114
+ } catch (e) {
115
+ console.error(`Error minifying ${outputPath}:`, e);
116
+ }
117
+ }
118
+
119
+ const
120
+ swContent = fs.readFileSync(path.resolve(__dirname, '../ServiceWorker.mjs'), 'utf8'),
121
+ promises = [minifyFile(swContent, path.resolve(__dirname, outputBasePath, 'ServiceWorker.mjs'))];
116
122
 
117
123
  // Execute the minification
118
124
  inputDirectories.forEach(folder => {
119
125
  promises.push(minifyDirectory(path.resolve(__dirname, '../' + folder), path.resolve(__dirname, outputBasePath, folder))
120
126
  .catch(err => {
121
- console.error('Minification failed:', err);
127
+ console.error('dist/esm Minification failed:', err);
122
128
  process.exit(1) // Exit with error code
123
129
  })
124
130
  );
125
131
  });
126
132
 
127
133
  Promise.all(promises).then(() => {
128
- console.log('Minification complete.');
134
+ console.log('dist/esm Minification complete.');
129
135
  process.exit()
130
136
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name" : "neo.mjs",
3
- "version" : "9.8.0",
3
+ "version" : "9.9.0",
4
4
  "description" : "The webworkers driven UI framework",
5
5
  "type" : "module",
6
6
  "repository" : {
@@ -264,12 +264,12 @@ const DefaultConfig = {
264
264
  useVdomWorker: true,
265
265
  /**
266
266
  * buildScripts/injectPackageVersion.mjs will update this value
267
- * @default '9.8.0'
267
+ * @default '9.9.0'
268
268
  * @memberOf! module:Neo
269
269
  * @name config.version
270
270
  * @type String
271
271
  */
272
- version: '9.8.0'
272
+ version: '9.9.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
- hasJsModules = devMode || environment === 'dist/esm',
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));