@vanillabp/bc-module-kit 0.0.0-stage → 0.1.0-snapshot.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,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
package/NOTICE ADDED
@@ -0,0 +1,17 @@
1
+ NOTICE file corresponding to the section 4 (d) of the Apache License, Version 2.0.
2
+
3
+ The software components provided as part of the "VanillaBP Business Cockpit Module Kit"
4
+ were developed by Phactum Softwareentwicklung GmbH (https://www.phactum.at/).
5
+
6
+ Please read the LICENSE file present in this source distribution.
7
+
8
+ You may not use files provided except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # @vanillabp/bc-module-kit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The module's side of the contract between a
4
+ [VanillaBP Business Cockpit](https://github.com/vanillabp/business-cockpit) and a workflow module:
5
+ `bc-manifest.json`, the build check `bc-check-entries`, the event protocol, `defineBcElement` and the
6
+ names of the entries. Plain JavaScript, no dependencies.
7
+
8
+ How to use it is in the
9
+ [README of the repository](https://github.com/vanillabp/business-cockpit-module-kit#readme).
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+ // Checks the entries of a workflow module's bc-manifest.json after its build.
3
+ // Run `bc-check-entries --help` for the options.
4
+
5
+ import { parseArgs } from 'node:util';
6
+ import { checkEntries, DEFAULT_LIMIT_BYTES } from '../src/check.js';
7
+
8
+ const usage = `Usage: bc-check-entries <path to bc-manifest.json> [options]
9
+
10
+ Fails when an entry of the manifest has no file, or when a data entry, with
11
+ every file it imports, is larger than the limit, imports a bare name or
12
+ contains framework code.
13
+
14
+ Options:
15
+ --limit <size> the limit of a data entry, like 32kb (default ${DEFAULT_LIMIT_BYTES / 1024}kb)
16
+ --data-entry <name> one more data entry, for example Header; may be given again
17
+ --metafile <path> esbuild's metafile, to find framework packages by their inputs
18
+ --help shows this text
19
+ `;
20
+
21
+ let parsed;
22
+ try {
23
+ parsed = parseArgs({
24
+ allowPositionals: true,
25
+ options: {
26
+ limit: { type: 'string' },
27
+ 'data-entry': { type: 'string', multiple: true },
28
+ metafile: { type: 'string' },
29
+ help: { type: 'boolean' },
30
+ },
31
+ });
32
+ } catch (error) {
33
+ process.stderr.write(`${error.message}\n\n${usage}`);
34
+ process.exit(2);
35
+ }
36
+
37
+ const { values, positionals } = parsed;
38
+ if (values.help) {
39
+ process.stdout.write(usage);
40
+ process.exit(0);
41
+ }
42
+ if (positionals.length !== 1) {
43
+ process.stderr.write(usage);
44
+ process.exit(2);
45
+ }
46
+
47
+ let result;
48
+ try {
49
+ result = checkEntries(positionals[0], {
50
+ limit: values.limit,
51
+ dataEntries: values['data-entry'],
52
+ metafile: values.metafile,
53
+ });
54
+ } catch (error) {
55
+ process.stderr.write(`bc-check-entries: ${error.message}\n`);
56
+ process.exit(2);
57
+ }
58
+
59
+ for (const { entry, files, bytes } of result.dataEntries) {
60
+ process.stdout.write(`${entry}: ${bytes} bytes in ${files.length} file(s)\n`);
61
+ }
62
+ if (result.problems.length > 0) {
63
+ process.stderr.write(`bc-check-entries found ${result.problems.length} problem(s):\n`);
64
+ for (const problem of result.problems) process.stderr.write(`- ${problem}\n`);
65
+ process.exit(1);
66
+ }
67
+ process.stdout.write('bc-check-entries: every entry is fine\n');
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@vanillabp/bc-module-kit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-snapshot.0",
4
+ "description": "The module's side of the contract between a VanillaBP Business Cockpit and a workflow module: bc-manifest.json, bc-check-entries, the event protocol and the names of the entries.",
5
+ "license": "Apache-2.0",
6
+ "author": "Phactum Softwareentwicklung GmbH (https://www.phactum.at/)",
7
+ "homepage": "https://www.vanillabp.io",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/vanillabp/business-cockpit-module-kit.git",
11
+ "directory": "packages/bc-module-kit"
12
+ },
13
+ "keywords": [
14
+ "vanillabp",
15
+ "business-cockpit",
16
+ "workflow",
17
+ "web-components"
18
+ ],
19
+ "type": "module",
20
+ "sideEffects": false,
21
+ "engines": {
22
+ "node": ">=24"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "types": "./src/index.d.ts",
27
+ "default": "./src/index.js"
28
+ },
29
+ "./check": {
30
+ "types": "./src/check.d.ts",
31
+ "default": "./src/check.js"
32
+ },
33
+ "./schema/bc-manifest.schema.json": "./schema/bc-manifest.schema.json",
34
+ "./package.json": "./package.json"
35
+ },
36
+ "types": "./src/index.d.ts",
37
+ "bin": {
38
+ "bc-check-entries": "bin/bc-check-entries.js"
39
+ },
40
+ "files": [
41
+ "src",
42
+ "bin",
43
+ "schema",
44
+ "NOTICE"
45
+ ],
46
+ "scripts": {
47
+ "test": "node --test \"test/**/*.test.js\""
48
+ }
49
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/vanillabp/business-cockpit-module-kit/blob/main/packages/bc-module-kit/schema/bc-manifest.schema.json",
4
+ "title": "bc-manifest.json",
5
+ "description": "The entries a workflow module offers to a VanillaBP Business Cockpit, and the files they are in.",
6
+ "type": "object",
7
+ "required": ["manifestVersion", "entries"],
8
+ "properties": {
9
+ "manifestVersion": {
10
+ "description": "The version of this format. A cockpit refuses a higher one it does not know.",
11
+ "const": 1
12
+ },
13
+ "buildVersion": {
14
+ "description": "The version of the module's build, shown in a details view, if at all.",
15
+ "type": "string"
16
+ },
17
+ "buildTimestamp": {
18
+ "description": "When the module was built, also only for a details view.",
19
+ "type": "string",
20
+ "format": "date-time"
21
+ },
22
+ "entries": {
23
+ "description": "Entry name to file. The file is relative to the manifest.",
24
+ "type": "object",
25
+ "propertyNames": {
26
+ "minLength": 1,
27
+ "not": { "pattern": "^\\./" }
28
+ },
29
+ "additionalProperties": {
30
+ "type": "string",
31
+ "minLength": 1,
32
+ "not": {
33
+ "anyOf": [
34
+ { "pattern": "^[A-Za-z][A-Za-z0-9+.-]*:" },
35
+ { "pattern": "^/" },
36
+ { "pattern": "(^|/)\\.\\.(/|$|[?#])" }
37
+ ]
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
package/src/check.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare const DEFAULT_LIMIT_BYTES: number;
2
+ export declare const FRAMEWORK_PACKAGES: readonly string[];
3
+ export declare const FRAMEWORK_MARKERS: ReadonlyArray<{ framework: string; marker: string }>;
4
+ export declare function parseLimit(value: string | number): number;
5
+ export declare function findFrameworkCode(source: string): string[];
6
+ export declare function importsOf(source: string): string[];
7
+ export declare function checkEntries(
8
+ manifestPath: string,
9
+ options?: { limit?: number | string; dataEntries?: string[]; metafile?: string },
10
+ ): { problems: string[]; dataEntries: Array<{ entry: string; files: string[]; bytes: number }> };
package/src/check.js ADDED
@@ -0,0 +1,194 @@
1
+ /**
2
+ * The checks of `bc-check-entries`, for a module's build. Plain Node.js without dependencies.
3
+ *
4
+ * @module @vanillabp/bc-module-kit/check
5
+ */
6
+
7
+ import { existsSync, readFileSync, statSync } from 'node:fs';
8
+ import { dirname, resolve, sep } from 'node:path';
9
+ import { DATA_ENTRIES } from './entries.js';
10
+ import { readManifest } from './manifest.js';
11
+
12
+ /** The limit of a data entry with every file it imports: 32 KB before compression. */
13
+ export const DEFAULT_LIMIT_BYTES = 32 * 1024;
14
+
15
+ /**
16
+ * The packages whose code must not be in a data entry. The check finds them through the inputs
17
+ * of a bundler's metafile.
18
+ */
19
+ export const FRAMEWORK_PACKAGES = Object.freeze([
20
+ 'react', 'react-dom', 'scheduler', 'vue', '@vue/', '@angular/', 'zone.js',
21
+ 'preact', 'svelte', 'solid-js', 'lit', 'lit-html', 'lit-element', '@lit/',
22
+ ]);
23
+
24
+ /**
25
+ * Markers that framework packages leave in a bundle, also when it is minified. The check finds a
26
+ * framework by them when there is no metafile.
27
+ */
28
+ export const FRAMEWORK_MARKERS = Object.freeze([
29
+ { framework: 'react', marker: '@license React' },
30
+ { framework: 'react', marker: 'react.transitional.element' },
31
+ { framework: 'react', marker: '__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE' },
32
+ { framework: 'react', marker: '__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' },
33
+ { framework: 'vue', marker: '__vue_app__' },
34
+ { framework: 'vue', marker: '__v_isRef' },
35
+ { framework: 'angular', marker: '@license Angular' },
36
+ { framework: 'angular', marker: 'ɵɵdefineComponent' },
37
+ { framework: 'zone.js', marker: '__zone_symbol__' },
38
+ { framework: 'lit', marker: 'litHtmlVersions' },
39
+ ]);
40
+
41
+ /**
42
+ * Reads a size like `32kb`, `0.5mb` or `32768`. A kilobyte is 1024 bytes.
43
+ *
44
+ * @param {string | number} value
45
+ * @returns {number} bytes
46
+ */
47
+ export function parseLimit(value) {
48
+ if (typeof value === 'number') return value;
49
+ const match = /^\s*(\d+(?:\.\d+)?)\s*(b|kb|k|mb|m)?\s*$/i.exec(value);
50
+ if (!match) throw new Error(`"${value}" is no size; write it like 32kb or 32768`);
51
+ const factor = { b: 1, k: 1024, kb: 1024, m: 1024 * 1024, mb: 1024 * 1024 }[(match[2] ?? 'b').toLowerCase()];
52
+ return Math.round(Number(match[1]) * factor);
53
+ }
54
+
55
+ /**
56
+ * Lists the frameworks whose markers are in a source.
57
+ *
58
+ * @param {string} source
59
+ * @returns {string[]}
60
+ */
61
+ export function findFrameworkCode(source) {
62
+ const found = new Set();
63
+ for (const { framework, marker } of FRAMEWORK_MARKERS) {
64
+ if (source.includes(marker)) found.add(framework);
65
+ }
66
+ return [...found];
67
+ }
68
+
69
+ const STATIC_IMPORT = /(?:^|[^.\w$])(?:import|export)\s*(?:[\w$*{}\s,]*?\s*from\s*)?["']([^"'\n]+)["']/g;
70
+ const DYNAMIC_IMPORT = /(?:^|[^.\w$])import\s*\(\s*["']([^"'\n]+)["']\s*\)/g;
71
+
72
+ /**
73
+ * Lists the specifiers a file imports, static and dynamic ones with a fixed string.
74
+ *
75
+ * @param {string} source
76
+ * @returns {string[]}
77
+ */
78
+ export function importsOf(source) {
79
+ const specifiers = new Set();
80
+ for (const pattern of [STATIC_IMPORT, DYNAMIC_IMPORT]) {
81
+ for (const match of source.matchAll(pattern)) specifiers.add(match[1]);
82
+ }
83
+ return [...specifiers];
84
+ }
85
+
86
+ /**
87
+ * The file part of a manifest entry, without `?v=...` and without `#...`.
88
+ *
89
+ * @param {string} file
90
+ */
91
+ function pathOf(file) {
92
+ return file.split(/[?#]/, 1)[0];
93
+ }
94
+
95
+ /**
96
+ * Reads the inputs per output file from an esbuild metafile.
97
+ *
98
+ * @param {string} metafilePath
99
+ * @returns {(file: string) => string[] | undefined} the inputs of an output file, by its absolute path
100
+ */
101
+ function readMetafile(metafilePath) {
102
+ const metafile = JSON.parse(readFileSync(metafilePath, 'utf8'));
103
+ const outputs = Object.entries(metafile.outputs ?? {}).map(([output, { inputs }]) => ({
104
+ suffix: sep + output.split('/').join(sep).replace(/^(\.\.?[\\/])+/, ''),
105
+ inputs: Object.keys(inputs ?? {}),
106
+ }));
107
+ return (file) => outputs.find(({ suffix }) => file.endsWith(suffix))?.inputs;
108
+ }
109
+
110
+ /**
111
+ * Says whether an input of a bundle comes from a framework package.
112
+ *
113
+ * @param {string} input
114
+ * @returns {string | undefined} the package
115
+ */
116
+ function frameworkOfInput(input) {
117
+ const parts = input.split(/[\\/]node_modules[\\/]|^node_modules[\\/]/);
118
+ if (parts.length < 2) return undefined;
119
+ const path = parts[parts.length - 1];
120
+ return FRAMEWORK_PACKAGES.find((name) => (name.endsWith('/') ? path.startsWith(name) : path === name || path.startsWith(`${name}/`)));
121
+ }
122
+
123
+ /**
124
+ * Checks the entries of a manifest. Every entry must have a file. Every data entry, with every
125
+ * file it imports, must stay below the limit, must import nothing by a bare name, and must hold no
126
+ * framework code.
127
+ *
128
+ * @param {string} manifestPath
129
+ * @param {{ limit?: number | string, dataEntries?: string[], metafile?: string }} [options]
130
+ * @returns {{ problems: string[], dataEntries: Array<{ entry: string, files: string[], bytes: number }> }}
131
+ */
132
+ export function checkEntries(manifestPath, options = {}) {
133
+ const limit = parseLimit(options.limit ?? DEFAULT_LIMIT_BYTES);
134
+ const dataEntryNames = new Set([...DATA_ENTRIES, ...(options.dataEntries ?? [])]);
135
+ const inputsOf = options.metafile ? readMetafile(resolve(options.metafile)) : () => undefined;
136
+ const base = dirname(resolve(manifestPath));
137
+ const problems = [];
138
+ const dataEntries = [];
139
+
140
+ let manifest;
141
+ try {
142
+ manifest = readManifest(readFileSync(manifestPath, 'utf8'));
143
+ } catch (error) {
144
+ return { problems: [/** @type {Error} */ (error).message], dataEntries };
145
+ }
146
+
147
+ for (const [entry, file] of Object.entries(manifest.entries)) {
148
+ const path = resolve(base, pathOf(file));
149
+ if (!existsSync(path) || !statSync(path).isFile()) {
150
+ problems.push(`${entry}: the file ${file} does not exist`);
151
+ continue;
152
+ }
153
+ if (!dataEntryNames.has(entry)) continue;
154
+
155
+ const files = [];
156
+ const seen = new Set();
157
+ const queue = [path];
158
+ while (queue.length > 0) {
159
+ const current = /** @type {string} */ (queue.shift());
160
+ if (seen.has(current)) continue;
161
+ seen.add(current);
162
+ files.push(current);
163
+ const source = readFileSync(current, 'utf8');
164
+ const shown = current.slice(base.length + 1);
165
+ for (const framework of findFrameworkCode(source)) {
166
+ problems.push(`${entry}: ${shown} contains code of ${framework}; a data entry carries no framework`);
167
+ }
168
+ for (const input of inputsOf(current) ?? []) {
169
+ const framework = frameworkOfInput(input);
170
+ if (framework) problems.push(`${entry}: ${shown} was built from ${input} of the package ${framework}; a data entry carries no framework`);
171
+ }
172
+ for (const specifier of importsOf(source)) {
173
+ if (!specifier.startsWith('./') && !specifier.startsWith('../')) {
174
+ problems.push(`${entry}: ${shown} imports "${specifier}"; an entry imports only files of its own module, by relative paths`);
175
+ continue;
176
+ }
177
+ const imported = resolve(dirname(current), pathOf(specifier));
178
+ if (!imported.startsWith(base + sep)) {
179
+ problems.push(`${entry}: ${shown} imports ${specifier}, which lies outside the folder of the manifest`);
180
+ } else if (!existsSync(imported)) {
181
+ problems.push(`${entry}: ${shown} imports ${specifier}, which does not exist`);
182
+ } else {
183
+ queue.push(imported);
184
+ }
185
+ }
186
+ }
187
+ const bytes = files.reduce((sum, current) => sum + statSync(current).size, 0);
188
+ if (bytes > limit) {
189
+ problems.push(`${entry}: ${bytes} bytes with the files it imports, more than the limit of ${limit} bytes`);
190
+ }
191
+ dataEntries.push({ entry, files: files.map((current) => current.slice(base.length + 1)), bytes });
192
+ }
193
+ return { problems: [...new Set(problems)], dataEntries };
194
+ }