vivth 1.5.9 → 1.5.11

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/README.md CHANGED
@@ -770,7 +770,11 @@ body {
770
770
  - files extention:
771
771
  > - `js`/`ts` files will be compiled with `vivth/node.EsWathcer`, using `option.esbuild` as argument;
772
772
  > - `sass`/`scss` it will be compiled to `css` first;
773
+ > - `html` will be checked for `script`;
774
+ > > - has `[type="module]"`: will be processed as `esm`;
775
+ > > - has `[minify="true"]`: will be minified;
773
776
  > - other than those files, they will be just copied to `targetPaths`;
777
+ - avoid forbidden filename characters and problematic one such as curly/square/normal-braces, that might be used for file pointing cli;
774
778
  - for runtime example see file `/dev/auto/` on source code;
775
779
 
776
780
  ```js
@@ -31,7 +31,11 @@
31
31
  * - files extention:
32
32
  * >- `js`/`ts` files will be compiled with `vivth/node.EsWathcer`, using `option.esbuild` as argument;
33
33
  * >- `sass`/`scss` it will be compiled to `css` first;
34
+ * >- `html` will be checked for `script`;
35
+ * >>- has `[type="module]"`: will be processed as `esm`;
36
+ * >>- has `[minify="true"]`: will be minified;
34
37
  * >- other than those files, they will be just copied to `targetPaths`;
38
+ * - avoid forbidden filename characters and problematic one such as curly/square/normal-braces, that might be used for file pointing cli;
35
39
  * - for runtime example see file `/dev/auto/` on source code;
36
40
  * @implements {VivthCleanup}
37
41
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vivth",
3
- "version": "1.5.9",
3
+ "version": "1.5.11",
4
4
  "description": "library primitives",
5
5
  "devDependencies": {
6
6
  "@types/bun": "^1.3.3",
@@ -59,7 +59,11 @@ import { LazyFactory } from '../function/LazyFactory.mjs';
59
59
  * - files extention:
60
60
  * >- `js`/`ts` files will be compiled with `vivth/node.EsWathcer`, using `option.esbuild` as argument;
61
61
  * >- `sass`/`scss` it will be compiled to `css` first;
62
+ * >- `html` will be checked for `script`;
63
+ * >>- has `[type="module]"`: will be processed as `esm`;
64
+ * >>- has `[minify="true"]`: will be minified;
62
65
  * >- other than those files, they will be just copied to `targetPaths`;
66
+ * - avoid forbidden filename characters and problematic one such as curly/square/normal-braces, that might be used for file pointing cli;
63
67
  * - for runtime example see file `/dev/auto/` on source code;
64
68
  * @implements {VivthCleanup}
65
69
  */
@@ -206,15 +210,14 @@ export class FileSelfMapper {
206
210
  const { content: originalContent, targetPaths } = await FileSelfMapper.#getTargetPath(path);
207
211
  let newContent = originalContent;
208
212
  const resDocument = createDocument(originalContent);
209
- const fileSelfMapperAttribute = 'vivth-file-self-mapper';
210
- const handledScripts = resDocument.querySelectorAll(`script[${fileSelfMapperAttribute}]`);
213
+ const handledScripts = Array.from(resDocument.querySelectorAll(`script`));
211
214
  await Promise.all(
212
215
  ForOfSync(handledScripts, async (scriptElement) => {
213
- const directionsString = scriptElement.getAttribute(fileSelfMapperAttribute);
214
- scriptElement.removeAttribute(fileSelfMapperAttribute);
215
- if (!directionsString) return;
216
- const directions = new Set(directionsString.split(';'));
217
- const hasMin = directions.has('min');
216
+ const hasMinifyTrue = (scriptElement.getAttribute('minify') ?? '') === 'true';
217
+ const hasTypeModule = (scriptElement.getAttribute('type') ?? '') === 'module';
218
+ if (!hasMinifyTrue && !hasTypeModule) {
219
+ return;
220
+ }
218
221
  const inner = scriptElement.innerHTML;
219
222
  const res = await build({
220
223
  write: false,
@@ -225,12 +228,8 @@ export class FileSelfMapper {
225
228
  },
226
229
  bundle: false,
227
230
  logLevel: 'silent',
228
- minify: hasMin,
229
- format: directions.has('iife')
230
- ? 'iife'
231
- : scriptElement.getAttribute('type') === 'module'
232
- ? 'esm'
233
- : undefined,
231
+ minify: hasMinifyTrue,
232
+ format: hasTypeModule ? 'esm' : undefined,
234
233
  });
235
234
  if (res.errors.length) {
236
235
  Console.error({
@@ -241,8 +240,7 @@ export class FileSelfMapper {
241
240
  });
242
241
  return;
243
242
  }
244
-
245
- const minified = res.outputFiles[0]?.text;
243
+ const minified = res.outputFiles[0]?.text.trim();
246
244
  newContent = newContent.replace(
247
245
  inner,
248
246
  // @ts-expect-error
@@ -259,7 +257,7 @@ export class FileSelfMapper {
259
257
  const [, errorWriteHTML] = await FileSafe.write(
260
258
  target,
261
259
  (!!processedContent ? processedContent : newContent).replace(
262
- /\s*vivth-file-self-mapper\="[\s\S]*?"\s*/g,
260
+ /\s*minify\="[\s\S]*?"\s*/g,
263
261
  '',
264
262
  ),
265
263
  {
@@ -270,7 +268,7 @@ export class FileSelfMapper {
270
268
  Console.error({ errorWriteHTML }, { now: true });
271
269
  return;
272
270
  }
273
- Console.info(`✅ Successfully map:'${path}' to:'${target}'`, { now: true });
271
+ Console.info(`✅ Successfully map:'${path}' 👉:'${target}'`, { now: true });
274
272
  })[0],
275
273
  );
276
274
  };
@@ -546,15 +544,20 @@ export class FileSelfMapper {
546
544
  if (!group) {
547
545
  break;
548
546
  }
549
- const candidate = group.trim();
550
- if (!/^(?:[A-Za-z]:[\\/]|[\\/]|\.{1,2}[\\/])?[A-Za-z0-9._\\/-]+$/g.test(candidate)) {
551
- break;
552
- }
553
- if (!candidate) {
547
+ const pathCandidate = group.trim();
548
+ if (
549
+ !pathCandidate ||
550
+ !/^(?:[A-Za-z]:[\\/]|[\\/]|\.{1,2}[\\/])?[A-Za-z0-9._\\/-]+$/g.test(pathCandidate)
551
+ ) {
552
+ Console.error({
553
+ pathCandidate,
554
+ message: 'pathCandidate invalid for testRegex',
555
+ testRegex: /^(?:[A-Za-z]:[\\/]|[\\/]|\.{1,2}[\\/])?[A-Za-z0-9._\\/-]+$/g,
556
+ });
554
557
  break;
555
558
  }
556
559
  perLinesCode[i] = '';
557
- targetPaths.add(Paths.normalize(candidate));
560
+ targetPaths.add(Paths.normalize(pathCandidate));
558
561
  }
559
562
 
560
563
  return {