vivth 1.5.9 → 1.5.10

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,6 +770,9 @@ 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`;
774
777
  - for runtime example see file `/dev/auto/` on source code;
775
778
 
@@ -31,6 +31,9 @@
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`;
35
38
  * - for runtime example see file `/dev/auto/` on source code;
36
39
  * @implements {VivthCleanup}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vivth",
3
- "version": "1.5.9",
3
+ "version": "1.5.10",
4
4
  "description": "library primitives",
5
5
  "devDependencies": {
6
6
  "@types/bun": "^1.3.3",
@@ -59,6 +59,9 @@ 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`;
63
66
  * - for runtime example see file `/dev/auto/` on source code;
64
67
  * @implements {VivthCleanup}
@@ -206,15 +209,14 @@ export class FileSelfMapper {
206
209
  const { content: originalContent, targetPaths } = await FileSelfMapper.#getTargetPath(path);
207
210
  let newContent = originalContent;
208
211
  const resDocument = createDocument(originalContent);
209
- const fileSelfMapperAttribute = 'vivth-file-self-mapper';
210
- const handledScripts = resDocument.querySelectorAll(`script[${fileSelfMapperAttribute}]`);
212
+ const handledScripts = Array.from(resDocument.querySelectorAll(`script`));
211
213
  await Promise.all(
212
214
  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');
215
+ const hasMinifyTrue = (scriptElement.getAttribute('minify') ?? '') === 'true';
216
+ const hasTypeModule = (scriptElement.getAttribute('type') ?? '') === 'module';
217
+ if (!hasMinifyTrue && !hasTypeModule) {
218
+ return;
219
+ }
218
220
  const inner = scriptElement.innerHTML;
219
221
  const res = await build({
220
222
  write: false,
@@ -225,12 +227,8 @@ export class FileSelfMapper {
225
227
  },
226
228
  bundle: false,
227
229
  logLevel: 'silent',
228
- minify: hasMin,
229
- format: directions.has('iife')
230
- ? 'iife'
231
- : scriptElement.getAttribute('type') === 'module'
232
- ? 'esm'
233
- : undefined,
230
+ minify: hasMinifyTrue,
231
+ format: hasTypeModule ? 'esm' : undefined,
234
232
  });
235
233
  if (res.errors.length) {
236
234
  Console.error({
@@ -241,8 +239,7 @@ export class FileSelfMapper {
241
239
  });
242
240
  return;
243
241
  }
244
-
245
- const minified = res.outputFiles[0]?.text;
242
+ const minified = res.outputFiles[0]?.text.trim();
246
243
  newContent = newContent.replace(
247
244
  inner,
248
245
  // @ts-expect-error
@@ -259,7 +256,7 @@ export class FileSelfMapper {
259
256
  const [, errorWriteHTML] = await FileSafe.write(
260
257
  target,
261
258
  (!!processedContent ? processedContent : newContent).replace(
262
- /\s*vivth-file-self-mapper\="[\s\S]*?"\s*/g,
259
+ /\s*minify\="[\s\S]*?"\s*/g,
263
260
  '',
264
261
  ),
265
262
  {