@yuneta/gobj-ui 7.27.33 → 7.28.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/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-2021 Niyamaka
4
+ Copyright (c) 2024-2026, ArtGins
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+
24
+ Most icons of src/yui_icons.css are paths of Font Awesome Free, under the
25
+ CC BY 4.0 License: see THIRD-PARTY-NOTICES.
package/README.md CHANGED
@@ -3367,7 +3367,10 @@ in every other answer. Then a read asked BEFORE a set and answered after it
3367
3367
  does not unlock what the set locked: without it, a card's own read answered
3368
3368
  after a tick showed the levels before the set, enabled, for one round trip. A
3369
3369
  host that leaves `set_id` out of its answers keeps working as before: the view
3370
- matches an answer by its gclass.
3370
+ matches an answer by its gclass. A host that echoes it is expected to REPLACE
3371
+ the pending read of a gclass with the read of a newer set of that gclass (as
3372
+ gui_agent does), so a newer set of the gclass an open viewer waits for moves
3373
+ the viewer's wait to the newer number (7.27.34): the older answer never comes.
3371
3374
 
3372
3375
  ```js
3373
3376
  /* the host, after the last command of a set: */
@@ -3376,7 +3379,9 @@ gobj_send_event(priv.view.tree, "EV_TRACE_INFO",
3376
3379
  /* a plain read (a card was opened): */
3377
3380
  gobj_send_event(priv.view.tree, "EV_TRACE_INFO",
3378
3381
  Object.assign({gclass: "C_TCP", set_id: null}, the_four_answers), gobj);
3379
- ``` Ask `view-gobj-tree` for the fields the view reads,
3382
+ ```
3383
+
3384
+ Ask `view-gobj-tree` for the fields the view reads,
3380
3385
  by name (`options=[...]`): its default leaves out `gclass` and `fullname`, and
3381
3386
  `play_methods` is what keeps a gobj with nothing to play from reading paused.
3382
3387
 
@@ -4473,6 +4478,48 @@ export default { plugins: [ yunetaHtmlPlugin({ defaultTitle: "My App" }) ] };
4473
4478
  sorted names of the bundle's files, source maps excluded. `<version>` is the
4474
4479
  app's `package.json` version. `C_YUI_UPDATE_WATCH` reads it.
4475
4480
 
4481
+ ### `licenses.txt`: the notices of what the bundle carries
4482
+
4483
+ The bundle of an app carries code of others (gobj-js, this library, G6,
4484
+ Tabulator, i18next, Bulma ...), and every browser that loads it receives a
4485
+ copy. Their licenses ask for their notices to go with it, and Vite's
4486
+ minifier drops them all, `/*!` comments included. The vite plugin
4487
+ `yunetaLicensesPlugin` (`vite-plugin-yuneta-licenses.js`, 7.28.0) writes them
4488
+ beside the bundle at build time: `dist/licenses.txt`, served at
4489
+ `/licenses.txt`.
4490
+
4491
+ ```js
4492
+ // vite.config.js
4493
+ import { yunetaHtmlPlugin } from "@yuneta/gobj-ui/vite-plugin-yuneta-html.js";
4494
+ import { yunetaLicensesPlugin } from "@yuneta/gobj-ui/vite-plugin-yuneta-licenses.js";
4495
+ export default {
4496
+ plugins: [
4497
+ yunetaHtmlPlugin({ defaultTitle: "My App" }),
4498
+ yunetaLicensesPlugin()
4499
+ ]
4500
+ };
4501
+ ```
4502
+
4503
+ - **What is listed:** every package with a module that renders code in an
4504
+ emitted chunk, and every package whose stylesheet the bundle imports. A
4505
+ module tree-shaken to nothing is not in the bundle, so its package is not
4506
+ listed. The app's own sources are not listed. Code a package ships inside
4507
+ its own files (`@antv/layout` carries d3-force in `lib/node_modules/`) is
4508
+ listed as that package.
4509
+ - **What of each:** name, version, the license its `package.json` declares,
4510
+ its source url, and every `LICENSE` / `LICENCE` / `COPYING` / `NOTICE` /
4511
+ `THIRD-PARTY-NOTICES` file at its root. That last one is how the notice of
4512
+ `sprintf.js` (gobj-js) and the attribution of the Font Awesome icons of
4513
+ `yui_icons.css` (this library) reach the app. A package with no license
4514
+ file is listed with its declared license, and the build warns about it.
4515
+ - **Code of others that is no package** (vendored into the app's `src/`)
4516
+ goes in with `extra`:
4517
+ `yunetaLicensesPlugin({extra: [{name: "x.js (from ...)", license: "MIT", text: "..."}]})`.
4518
+ `fileName` changes the name of the file.
4519
+ - Link it from the app's "About" so a user can find it. The obligations of a
4520
+ closed app built with Yuneta are written in `OBLIGACIONES-LICENCIA.md` of
4521
+ each app.
4522
+
4476
4523
  ### Releasing
4477
4524
 
4478
4525
  `npm run build && npm test`, then `npm publish`. A published version reaches
@@ -0,0 +1,17 @@
1
+ THIRD-PARTY NOTICES
2
+ ===================
3
+
4
+ @yuneta/gobj-ui is under the MIT License of LICENSE. It carries the work of
5
+ others below, under its own license.
6
+
7
+ ------------------------------------------------------------------------------
8
+ Font Awesome Free (icons)
9
+ ------------------------------------------------------------------------------
10
+ Most icons of src/yui_icons.css are the SVG paths of Font Awesome Free (6.x
11
+ and 7.x, solid style), drawn as CSS masks; some are adjusted to their box.
12
+
13
+ Font Awesome Free by Fonticons, Inc. - https://fontawesome.com
14
+ Copyright (c) Fonticons, Inc.
15
+ The icons are licensed under the Creative Commons Attribution 4.0
16
+ International License (CC BY 4.0): https://creativecommons.org/licenses/by/4.0/
17
+ Font Awesome Free license: https://fontawesome.com/license/free
@@ -55176,6 +55176,7 @@ function set_trace_levels(gobj, target, scope, levels, set) {
55176
55176
  if (viewer) {
55177
55177
  let shown = (0, _yuneta_gobj_js.gobj_read_str_attr)(viewer, "gclass_name");
55178
55178
  if (lock_viewer_for_set(gobj, shown, priv.set_in_flight)) (0, _yuneta_gobj_js.gobj_send_event)(viewer, "EV_SET_TRACES", viewer_traces(gobj, shown), gobj);
55179
+ else if (priv.viewer_awaits && priv.viewer_awaits === target.gclass) priv.viewer_awaits_set = set_id;
55179
55180
  }
55180
55181
  (0, _yuneta_gobj_js.gobj_publish_event)(gobj, "EV_SET_TRACE_LEVEL", {
55181
55182
  scope,
@@ -55171,6 +55171,7 @@ function set_trace_levels(gobj, target, scope, levels, set) {
55171
55171
  if (viewer) {
55172
55172
  let shown = gobj_read_str_attr(viewer, "gclass_name");
55173
55173
  if (lock_viewer_for_set(gobj, shown, priv.set_in_flight)) gobj_send_event(viewer, "EV_SET_TRACES", viewer_traces(gobj, shown), gobj);
55174
+ else if (priv.viewer_awaits && priv.viewer_awaits === target.gclass) priv.viewer_awaits_set = set_id;
55174
55175
  }
55175
55176
  gobj_publish_event(gobj, "EV_SET_TRACE_LEVEL", {
55176
55177
  scope,
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.27.33",
3
+ "version": "7.28.0",
4
+ "license": "MIT",
4
5
  "type": "module",
5
6
  "main": "dist/gobj-ui.cjs.js",
6
7
  "module": "dist/gobj-ui.es.js",
@@ -11,14 +12,17 @@
11
12
  },
12
13
  "./index.js": "./index.js",
13
14
  "./vite-plugin-yuneta-html.js": "./vite-plugin-yuneta-html.js",
15
+ "./vite-plugin-yuneta-licenses.js": "./vite-plugin-yuneta-licenses.js",
14
16
  "./src/*": "./src/*"
15
17
  },
16
18
  "files": [
19
+ "THIRD-PARTY-NOTICES",
17
20
  "dist/gobj-ui.es.js",
18
21
  "dist/gobj-ui.cjs.js",
19
22
  "index.js",
20
23
  "src/",
21
24
  "vite-plugin-yuneta-html.js",
25
+ "vite-plugin-yuneta-licenses.js",
22
26
  "scripts/check-markup-strings.mjs",
23
27
  "scripts/validate-locales.mjs"
24
28
  ],
@@ -43,7 +47,7 @@
43
47
  "devDependencies": {
44
48
  "@rollup/plugin-terser": "^1.0.2",
45
49
  "@vitest/coverage-v8": "^5.0.5",
46
- "@yuneta/gobj-js": "^7.27.0",
50
+ "@yuneta/gobj-js": "^7.28.0",
47
51
  "jsdom": "^30.1.3",
48
52
  "vite": "^8.3.5",
49
53
  "vitest": "^5.0.5"
@@ -3910,6 +3910,11 @@ function set_trace_levels(gobj, target, scope, levels, set)
3910
3910
  let shown = gobj_read_str_attr(viewer, "gclass_name");
3911
3911
  if(lock_viewer_for_set(gobj, shown, priv.set_in_flight)) {
3912
3912
  gobj_send_event(viewer, "EV_SET_TRACES", viewer_traces(gobj, shown), gobj);
3913
+ } else if(priv.viewer_awaits && priv.viewer_awaits === target.gclass) {
3914
+ /* The host replaces the pending read of a gclass with the one
3915
+ * of this newer set: the answer the viewer waited for will
3916
+ * come under this set's number, not the older one's. */
3917
+ priv.viewer_awaits_set = set_id;
3913
3918
  }
3914
3919
  }
3915
3920
 
@@ -689,4 +689,42 @@ describe("C_YUI_GOBJ_TREE_JS, source remote: a host that says which set it answe
689
689
  expect(viewer_box(viewer, "traffic").disabled).toBe(false);
690
690
  expect(problems()).toEqual([]);
691
691
  });
692
+
693
+ /* REV-CLOUD V41.2.1: the host REPLACES the pending read of a gclass
694
+ * with the one of a newer set of that gclass, so the read the
695
+ * viewer waits for (the yuno's, of an older set) never comes. */
696
+ test("a newer set of the gclass the viewer waits for: it waits for the newer one", async () => {
697
+ const {view, viewer} = await open_tcp_viewer();
698
+ gobj_read_attr(view, "$container").querySelector(".GOBJ_TREE_YUNO_TRACES_BUTTON").click();
699
+ gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, YUNO_INFO, {set_id: null}), host);
700
+
701
+ /* S1: a set of the yuno's scope; the viewer of C_TCP waits for C_YUNO */
702
+ const ev_kw = row_of(view, "ev_kw");
703
+ ev_kw.$global.checked = true;
704
+ ev_kw.$global.dispatchEvent(fake_event("change"));
705
+ const s1 = last_set_id();
706
+ expect(viewer_box(viewer, "traffic").disabled).toBe(true);
707
+ gobj_send_event(view, "EV_LOAD_TREE", {tree: TREE, set_id: s1}, host);
708
+
709
+ /* S2: a gobj set on the root's card, before the C_YUNO read of S1 */
710
+ gobj_send_event(view, "EV_NODE_CLICK",
711
+ {id: node_id_of(view, "C_YUNO^gate"), client_x: 10, client_y: 10}, view);
712
+ const {$gobj} = row_of(view, "machine");
713
+ $gobj.checked = true;
714
+ $gobj.dispatchEvent(fake_event("change"));
715
+ const s2 = last_set_id();
716
+ expect(s2).not.toBe(s1);
717
+ wanted.length = 0;
718
+
719
+ /* the host sends only the C_YUNO read of S2: S1's was replaced */
720
+ gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, YUNO_INFO,
721
+ {global_on: ["machine", "ev_kw"], set_id: s2}), host);
722
+ expect(wanted.map((w) => [w.event, w.kw.gclass, w.kw.set_id]))
723
+ .toEqual([["EV_TRACE_INFO_WANTED", "C_TCP", s2]]);
724
+ gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO,
725
+ {global_levels: YUNO_INFO.global_levels,
726
+ gclass_on: ["connections", "ev_kw"], global_on: ["ev_kw"], set_id: s2}), host);
727
+ expect(viewer_box(viewer, "traffic").disabled).toBe(false);
728
+ expect(problems()).toEqual([]);
729
+ });
692
730
  });
package/src/yui_icons.css CHANGED
@@ -3,6 +3,11 @@
3
3
  * Custom icon set — replaces FontAwesome for this app.
4
4
  * Usage: <i class="yi-bars"> (same pattern as FA, without style prefix class)
5
5
  * Color: inherits currentColor from parent via CSS mask.
6
+ *
7
+ * Most icons are the SVG paths of Font Awesome Free (6.x and 7.x, solid),
8
+ * some adjusted to their box: Font Awesome Free by Fonticons, Inc.,
9
+ * https://fontawesome.com, icons under the CC BY 4.0 License
10
+ * (https://creativecommons.org/licenses/by/4.0/). See THIRD-PARTY-NOTICES.
6
11
  */
7
12
 
8
13
  [class^="yi-"]::before,
@@ -0,0 +1,264 @@
1
+ /***********************************************************************
2
+ * vite-plugin-yuneta-licenses.js
3
+ *
4
+ * Vite plugin for Yuneta GUI projects: at build time it writes
5
+ * `licenses.txt` beside the bundle, with the license of every
6
+ * package whose code is IN the bundle.
7
+ *
8
+ * An app is closed or open, but the code of others inside its
9
+ * bundle is distributed to every browser that loads it, and its
10
+ * licenses (MIT, BSD, ISC, Apache-2.0, CC BY ...) ask for their
11
+ * notices to go with it. A minifier drops most of them (the
12
+ * attribution of the Font Awesome icons of yui_icons.css never
13
+ * reached a bundle; Vite 8 drops even the /*! comments), so the
14
+ * notices are gathered here instead,
15
+ * from the packages themselves.
16
+ *
17
+ * Which packages: the modules of the emitted chunks that render
18
+ * some code (a module tree-shaken to nothing is not in the
19
+ * bundle, and neither is its license), plus the stylesheets
20
+ * they import. Each module is mapped to the package that holds
21
+ * it under node_modules/; the app's own sources are not listed.
22
+ *
23
+ * What of each package: its name, version, declared license
24
+ * and source url, and the text of every LICENSE / LICENCE / COPYING /
25
+ * NOTICE / THIRD-PARTY-NOTICES file at its root -- which is how
26
+ * the notices that a package carries for code of others inside
27
+ * it (sprintf.js in gobj-js, Font Awesome in gobj-ui) come along.
28
+ * A package with no license file is listed with what its
29
+ * package.json declares, and warned about.
30
+ *
31
+ * Usage in vite.config.js:
32
+ * import {yunetaLicensesPlugin} from "@yuneta/gobj-ui/vite-plugin-yuneta-licenses.js";
33
+ * plugins: [yunetaHtmlPlugin({...}), yunetaLicensesPlugin()]
34
+ *
35
+ * Options:
36
+ * fileName: the name of the file in the bundle ("licenses.txt")
37
+ * extra: [{name, license, text}] for code of others that is
38
+ * not a package (vendored into the app's sources)
39
+ *
40
+ * Copyright (c) 2026, ArtGins.
41
+ * All Rights Reserved.
42
+ ***********************************************************************/
43
+ import fs from "fs";
44
+ import path from "path";
45
+
46
+ const LICENSE_FILE_RE = /^(licen[cs]e|copying|notice|third[-_]party[-_]notices?)([._-].*)?$/i;
47
+ const STYLESHEET_RE = /\.(css|scss|sass|less|styl)$/i;
48
+ const RULE = "-".repeat(78);
49
+
50
+ /*
51
+ * The root of the package that holds `id`, or null when it is not under
52
+ * node_modules/ (the app's own code). The LAST node_modules/ of the path
53
+ * is the one that holds it, and a scoped package takes two segments.
54
+ */
55
+ export function package_root_of(id)
56
+ {
57
+ let file = String(id).replace(/^\0/, "").split("?")[0];
58
+ let marker = `${path.sep}node_modules${path.sep}`;
59
+ let at = file.lastIndexOf(marker);
60
+ if(at < 0) {
61
+ return null;
62
+ }
63
+ let rest = file.slice(at + marker.length).split(path.sep);
64
+ let segments = rest[0].startsWith("@")? 2 : 1;
65
+ if(rest.length <= segments) {
66
+ return null;
67
+ }
68
+ return file.slice(0, at + marker.length) + rest.slice(0, segments).join(path.sep);
69
+ }
70
+
71
+ /*
72
+ * The license a package.json declares, as text: "MIT", the SPDX
73
+ * expression, or the old {type} / [{type}] forms joined with OR
74
+ */
75
+ export function declared_license(pkg)
76
+ {
77
+ let lic = pkg.license || pkg.licenses;
78
+ if(!lic) {
79
+ return "(none declared)";
80
+ }
81
+ if(typeof lic === "string") {
82
+ return lic;
83
+ }
84
+ if(Array.isArray(lic)) {
85
+ return lic.map(l => (typeof l === "string")? l : (l.type || "?")).join(" OR ");
86
+ }
87
+ return lic.type || "?";
88
+ }
89
+
90
+ /*
91
+ * Where the source of a package is: its repository, else its homepage,
92
+ * as an https url when it is one in disguise ("git+https://...git",
93
+ * "github:owner/repo"). Empty when the package says neither.
94
+ */
95
+ export function source_url(pkg)
96
+ {
97
+ let repo = pkg.repository;
98
+ let url = (typeof repo === "string")? repo : (repo && repo.url) || pkg.homepage || "";
99
+ url = String(url).trim()
100
+ .replace(/^git\+/, "")
101
+ .replace(/^git:\/\//, "https://")
102
+ .replace(/^git@github\.com:/, "https://github.com/")
103
+ .replace(/\.git$/, "");
104
+ let short = url.match(/^(github|gitlab|bitbucket):(.+)$/);
105
+ if(short) {
106
+ url = `https://${short[1]}.${short[1] === "bitbucket"? "org" : "com"}/${short[2]}`;
107
+ } else if(/^[\w.-]+\/[\w.-]+$/.test(url)) {
108
+ url = `https://github.com/${url}`;
109
+ }
110
+ return url;
111
+ }
112
+
113
+ /*
114
+ * The ids of the modules that put something in the bundle
115
+ */
116
+ export function bundled_module_ids(bundle)
117
+ {
118
+ let ids = new Set();
119
+ for(const out of Object.values(bundle)) {
120
+ if(out.type !== "chunk") {
121
+ continue;
122
+ }
123
+ let modules = out.modules || {};
124
+ let module_ids = out.moduleIds || Object.keys(modules);
125
+ for(const id of module_ids) {
126
+ let clean = String(id).split("?")[0];
127
+ let rendered = modules[id]? modules[id].renderedLength : 1;
128
+ if(rendered > 0 || STYLESHEET_RE.test(clean)) {
129
+ ids.add(id);
130
+ }
131
+ }
132
+ }
133
+ return ids;
134
+ }
135
+
136
+ /*
137
+ * The text of licenses.txt for the packages of `ids`. `warn` is told of
138
+ * a package with no license file.
139
+ */
140
+ export function build_licenses_text(ids, app, extra = [], warn = console.warn)
141
+ {
142
+ let roots = new Set();
143
+ for(const id of ids) {
144
+ let root = package_root_of(id);
145
+ if(root) {
146
+ roots.add(root);
147
+ }
148
+ }
149
+
150
+ let packages = new Map();
151
+ for(const start of roots) {
152
+ /*
153
+ * A directory under node_modules/ with no package.json is code a
154
+ * package ships inside its own files (@antv/layout carries d3-force
155
+ * and others in lib/node_modules/): it is listed as that package.
156
+ */
157
+ let root = start;
158
+ while(root && !fs.existsSync(path.join(root, "package.json"))) {
159
+ let marker = `${path.sep}node_modules${path.sep}`;
160
+ root = package_root_of(root.slice(0, root.lastIndexOf(marker)));
161
+ }
162
+ if(!root) {
163
+ warn(`yuneta-licenses: no package.json for ${start}, not listed`);
164
+ continue;
165
+ }
166
+ let pkg_path = path.join(root, "package.json");
167
+ let pkg = JSON.parse(fs.readFileSync(pkg_path, "utf-8"));
168
+ let key = `${pkg.name}@${pkg.version}`;
169
+ if(packages.has(key)) {
170
+ continue;
171
+ }
172
+ let files = fs.readdirSync(root)
173
+ .filter(name => LICENSE_FILE_RE.test(name) && fs.statSync(path.join(root, name)).isFile())
174
+ .sort((a, b) => {
175
+ let rank = (n) => /^licen[cs]e|^copying/i.test(n)? 0 : 1;
176
+ return (rank(a) - rank(b)) || a.localeCompare(b);
177
+ });
178
+ if(files.length === 0) {
179
+ warn(`yuneta-licenses: ${key} carries no license file; listed with its declared license only`);
180
+ }
181
+ packages.set(key, {
182
+ name: pkg.name,
183
+ version: pkg.version,
184
+ license: declared_license(pkg),
185
+ source: source_url(pkg),
186
+ texts: files.map(name => fs.readFileSync(path.join(root, name), "utf-8").trimEnd())
187
+ });
188
+ }
189
+
190
+ let sorted = [...packages.values()].sort((a, b) => a.name.localeCompare(b.name));
191
+
192
+ let out = [];
193
+ out.push("Licenses of the software in this application");
194
+ out.push("=".repeat(44));
195
+ out.push("");
196
+ out.push(`${app.name || "This application"}${app.version? " " + app.version : ""} includes the software ` +
197
+ "below, each part under its own license.");
198
+ out.push("This file is written at build time from the code that is in the bundle.");
199
+ out.push("");
200
+
201
+ for(const p of sorted) {
202
+ out.push(RULE);
203
+ out.push(`${p.name} ${p.version}`);
204
+ out.push(`License: ${p.license}`);
205
+ if(p.source) {
206
+ out.push(`Source: ${p.source}`);
207
+ }
208
+ out.push(RULE);
209
+ if(p.texts.length === 0) {
210
+ out.push("(The package carries no license file.)");
211
+ }
212
+ for(const text of p.texts) {
213
+ out.push(text);
214
+ out.push("");
215
+ }
216
+ out.push("");
217
+ }
218
+ for(const e of extra) {
219
+ out.push(RULE);
220
+ out.push(e.name);
221
+ out.push(`License: ${e.license || "?"}`);
222
+ out.push(RULE);
223
+ out.push(String(e.text || "").trimEnd());
224
+ out.push("");
225
+ out.push("");
226
+ }
227
+ return out.join("\n");
228
+ }
229
+
230
+ /**
231
+ * @param {object} [options]
232
+ * @param {string} [options.fileName] - The file in the bundle (default licenses.txt)
233
+ * @param {Array} [options.extra] - [{name, license, text}] not from a package
234
+ */
235
+ export function yunetaLicensesPlugin(options = {})
236
+ {
237
+ const fileName = options.fileName || "licenses.txt";
238
+ const extra = options.extra || [];
239
+
240
+ return {
241
+ name: "yuneta-licenses",
242
+ apply: "build",
243
+ generateBundle: {
244
+ order: "post",
245
+ handler(output_options, bundle) {
246
+ let app = {};
247
+ let pkg_path = path.resolve(process.cwd(), "package.json");
248
+ if(fs.existsSync(pkg_path)) {
249
+ app = JSON.parse(fs.readFileSync(pkg_path, "utf-8"));
250
+ }
251
+ let ids = bundled_module_ids(bundle);
252
+ if(ids.size === 0) {
253
+ console.error("❌ yuneta-licenses: no module in the bundle, no licenses file written");
254
+ return;
255
+ }
256
+ this.emitFile({
257
+ type: "asset",
258
+ fileName: fileName,
259
+ source: build_licenses_text(ids, app, extra)
260
+ });
261
+ }
262
+ }
263
+ };
264
+ }