@intellectual-frontiers/libraries 0.4.0 → 0.5.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.
Files changed (64) hide show
  1. package/LICENSE +75 -21
  2. package/dist/affected.d.ts +1 -1
  3. package/dist/dev.d.ts +2 -0
  4. package/dist/dev.js +14 -2
  5. package/dist/family.js +1 -0
  6. package/dist/generate-ontology.js +4 -0
  7. package/dist/imports/nist-sp-800-53.auto.prov.ttl +22 -0
  8. package/dist/imports/schema-org.auto.prov.ttl +22 -0
  9. package/dist/install-bun.js +19 -14
  10. package/dist/libraries.d.ts +39 -2
  11. package/dist/libraries.js +80 -9
  12. package/dist/license/PolyForm-Noncommercial-1.0.0.md +73 -0
  13. package/dist/license/standard.d.ts +46 -0
  14. package/dist/license/standard.js +43 -0
  15. package/dist/license/third-party.d.ts +25 -0
  16. package/dist/license/third-party.js +71 -0
  17. package/dist/license.d.ts +61 -0
  18. package/dist/license.js +204 -0
  19. package/dist/link.d.ts +1 -1
  20. package/dist/link.js +4 -4
  21. package/dist/metapackages.d.ts +62 -0
  22. package/dist/metapackages.js +190 -0
  23. package/dist/mod.d.ts +1 -1
  24. package/dist/mod.js +1 -1
  25. package/dist/pack-library.d.ts +9 -0
  26. package/dist/pack-library.js +46 -58
  27. package/dist/pack-metapackage.d.ts +22 -0
  28. package/dist/pack-metapackage.js +147 -0
  29. package/dist/pins.d.ts +34 -7
  30. package/dist/pins.js +36 -9
  31. package/dist/readme.d.ts +71 -0
  32. package/dist/readme.js +310 -0
  33. package/dist/releasing.d.ts +8 -1
  34. package/dist/releasing.js +44 -14
  35. package/dist/workflows/definitions.d.ts +2 -2
  36. package/dist/workflows/definitions.js +32 -114
  37. package/dist/workflows/model.d.ts +6 -0
  38. package/dist/workflows/render.js +2 -0
  39. package/dist/workflows/schema/github-workflow.schema.json +2290 -0
  40. package/package.json +39 -14
  41. package/src/affected.ts +1 -1
  42. package/src/dev.ts +13 -2
  43. package/src/family.ts +1 -0
  44. package/src/generate-ontology.ts +4 -0
  45. package/src/imports/nist-sp-800-53.auto.prov.ttl +22 -0
  46. package/src/imports/schema-org.auto.prov.ttl +22 -0
  47. package/src/install-bun.ts +16 -13
  48. package/src/libraries.ts +100 -8
  49. package/src/license/PolyForm-Noncommercial-1.0.0.md +73 -0
  50. package/src/license/standard.ts +67 -0
  51. package/src/license/third-party.ts +87 -0
  52. package/src/license.ts +222 -0
  53. package/src/link.ts +4 -4
  54. package/src/metapackages.ts +206 -0
  55. package/src/mod.ts +1 -1
  56. package/src/pack-library.ts +52 -55
  57. package/src/pack-metapackage.ts +137 -0
  58. package/src/pins.ts +55 -10
  59. package/src/readme.ts +320 -0
  60. package/src/releasing.ts +47 -16
  61. package/src/workflows/definitions.ts +36 -133
  62. package/src/workflows/model.ts +6 -0
  63. package/src/workflows/render.ts +1 -0
  64. package/src/workflows/schema/github-workflow.schema.json +2290 -0
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The license of this repository as data: the one license every library and every part of the repository is under, the one place its identifier is written, and the standard its text is taken from
3
+ * (commons 0035-licensing FR-001 to FR-004, 0018-standards-first FR-006 and FR-007). The text is the official PolyForm Noncommercial License 1.0.0, copied byte for byte into
4
+ * `PolyForm-Noncommercial-1.0.0.md` beside this file from the tag `1.0.0` of the official repository, and held to the SHA-256 recorded here.
5
+ *
6
+ * @remarks
7
+ * Read as data by `../license.ts` (which writes and checks every `LICENSE`), by the packer (the `license` of a package) and by the decoder of the manifest (its optional `license`). The identifier is a closed union:
8
+ * a license is added to {@link SPDX_IDS} together with its text, never as a free string.
9
+ *
10
+ * Spec: 0001-libraries FR-019
11
+ *
12
+ * @module
13
+ */
14
+ import { type Result } from "@intellectual-frontiers/core";
15
+ /** The SPDX identifiers of the licenses this repository can carry: each has its official text in this folder. */
16
+ export declare const SPDX_IDS: readonly ["PolyForm-Noncommercial-1.0.0"];
17
+ /** An SPDX license identifier of {@link SPDX_IDS}. */
18
+ export type SpdxId = (typeof SPDX_IDS)[number];
19
+ /** The license of every library and of the repository, unless a manifest's `license` says another of {@link SPDX_IDS}. */
20
+ export declare const DEFAULT_LICENSE: SpdxId;
21
+ /** An SPDX identifier from text, or why the text is none of the licenses this repository can carry. */
22
+ export declare function parseSpdxId(text: string): Result<SpdxId, string>;
23
+ /** A standard imported as data (0018-standards-first FR-006): its issuer, name, version, location, license and the SHA-256 of what was imported. */
24
+ export type Standard = {
25
+ readonly id: string;
26
+ readonly issuer: string;
27
+ readonly name: string;
28
+ readonly version: string;
29
+ /** Where the imported text is, at the tag that is pinned. */
30
+ readonly location: string;
31
+ /** What the text may be copied under (an SPDX identifier where there is one). */
32
+ readonly license: string;
33
+ readonly redistributable: boolean;
34
+ /** The SHA-256 of the file in this folder, line ends as they are (they are `\n`). */
35
+ readonly sha256: string;
36
+ /** The file of this folder that holds the text. */
37
+ readonly file: string;
38
+ };
39
+ /** The official text of each license, as a standard of 0018-standards-first. */
40
+ export declare const LICENSE_STANDARDS: Readonly<Record<SpdxId, Standard>>;
41
+ /** The licensor named in the `Required Notice:` line of every `LICENSE` and in `NOTICE`. */
42
+ export declare const LICENSOR = "Intellectual Frontiers LLC";
43
+ /** The repository the `Required Notice:` line names. */
44
+ export declare const REPOSITORY_URL = "https://github.com/intellectual-frontiers/.github";
45
+ /** Where a commercial license is asked for. */
46
+ export declare const COMMERCIAL_ISSUES_URL = "https://github.com/intellectual-frontiers/.github/issues";
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The license of this repository as data: the one license every library and every part of the repository is under, the one place its identifier is written, and the standard its text is taken from
3
+ * (commons 0035-licensing FR-001 to FR-004, 0018-standards-first FR-006 and FR-007). The text is the official PolyForm Noncommercial License 1.0.0, copied byte for byte into
4
+ * `PolyForm-Noncommercial-1.0.0.md` beside this file from the tag `1.0.0` of the official repository, and held to the SHA-256 recorded here.
5
+ *
6
+ * @remarks
7
+ * Read as data by `../license.ts` (which writes and checks every `LICENSE`), by the packer (the `license` of a package) and by the decoder of the manifest (its optional `license`). The identifier is a closed union:
8
+ * a license is added to {@link SPDX_IDS} together with its text, never as a free string.
9
+ *
10
+ * Spec: 0001-libraries FR-019
11
+ *
12
+ * @module
13
+ */
14
+ import { err, ok } from "@intellectual-frontiers/core";
15
+ /** The SPDX identifiers of the licenses this repository can carry: each has its official text in this folder. */
16
+ export const SPDX_IDS = ["PolyForm-Noncommercial-1.0.0"];
17
+ /** The license of every library and of the repository, unless a manifest's `license` says another of {@link SPDX_IDS}. */
18
+ export const DEFAULT_LICENSE = "PolyForm-Noncommercial-1.0.0";
19
+ /** An SPDX identifier from text, or why the text is none of the licenses this repository can carry. */
20
+ export function parseSpdxId(text) {
21
+ const found = SPDX_IDS.find((id) => id === text);
22
+ return found === undefined ? err(`${JSON.stringify(text)} is not a license of this repository (${SPDX_IDS.join(", ")})`) : ok(found);
23
+ }
24
+ /** The official text of each license, as a standard of 0018-standards-first. */
25
+ export const LICENSE_STANDARDS = {
26
+ "PolyForm-Noncommercial-1.0.0": {
27
+ id: "polyform-noncommercial-1.0.0",
28
+ issuer: "The PolyForm Project",
29
+ name: "PolyForm Noncommercial License 1.0.0",
30
+ version: "1.0.0",
31
+ location: "https://raw.githubusercontent.com/polyformproject/polyform-licenses/1.0.0/PolyForm-Noncommercial-1.0.0.md",
32
+ license: "The terms of LICENSE.md of polyformproject/polyform-licenses at tag 1.0.0: a PolyForm license is copied as it is, and a change removes the name PolyForm",
33
+ redistributable: true,
34
+ sha256: "c0ea4a896d2c8c394b29f9427589996db826cd501c512279ff0ed3ef48fabbe5",
35
+ file: "PolyForm-Noncommercial-1.0.0.md",
36
+ },
37
+ };
38
+ /** The licensor named in the `Required Notice:` line of every `LICENSE` and in `NOTICE`. */
39
+ export const LICENSOR = "Intellectual Frontiers LLC";
40
+ /** The repository the `Required Notice:` line names. */
41
+ export const REPOSITORY_URL = "https://github.com/intellectual-frontiers/.github";
42
+ /** Where a commercial license is asked for. */
43
+ export const COMMERCIAL_ISSUES_URL = "https://github.com/intellectual-frontiers/.github/issues";
@@ -0,0 +1,25 @@
1
+ /**
2
+ * What is really vendored in this repository: the files that are not ours and the license each is under, as data (commons 0035-licensing FR-008). `../license.ts` makes `THIRD_PARTY_NOTICES.md` from it, and its check names an
3
+ * item whose path is gone. Where a license was not checked against its source the item says `unverified: <what to check>` and never a guess.
4
+ *
5
+ * @remarks
6
+ * Packages installed from a registry (TypeScript, fast-check, `@types/node` and the others in `bun.lock`) are not vendored: nothing of them is in this repository, and a package's license is its own. Mermaid is
7
+ * copied into a built site and not into this repository, so its item has no path.
8
+ *
9
+ * Spec: 0001-libraries FR-019
10
+ *
11
+ * @module
12
+ */
13
+ /** One third-party item: what it is, where it came from, whose it is and the license it is under. */
14
+ export type ThirdPartyItem = {
15
+ /** The path in the repository, or `undefined` for an item that is copied only into a built output. */
16
+ readonly path: string | undefined;
17
+ readonly what: string;
18
+ readonly source: string;
19
+ readonly owner: string;
20
+ readonly license: string;
21
+ /** What was checked, or `unverified: <what to check>`. */
22
+ readonly checked: string;
23
+ };
24
+ /** The items, in the order the notices list them. */
25
+ export declare const THIRD_PARTY: readonly ThirdPartyItem[];
@@ -0,0 +1,71 @@
1
+ /**
2
+ * What is really vendored in this repository: the files that are not ours and the license each is under, as data (commons 0035-licensing FR-008). `../license.ts` makes `THIRD_PARTY_NOTICES.md` from it, and its check names an
3
+ * item whose path is gone. Where a license was not checked against its source the item says `unverified: <what to check>` and never a guess.
4
+ *
5
+ * @remarks
6
+ * Packages installed from a registry (TypeScript, fast-check, `@types/node` and the others in `bun.lock`) are not vendored: nothing of them is in this repository, and a package's license is its own. Mermaid is
7
+ * copied into a built site and not into this repository, so its item has no path.
8
+ *
9
+ * Spec: 0001-libraries FR-019
10
+ *
11
+ * @module
12
+ */
13
+ /** The items, in the order the notices list them. */
14
+ export const THIRD_PARTY = [
15
+ {
16
+ path: "commons/libraries/src/workflows/schema/github-workflow.schema.json",
17
+ what: "The JSON Schema of GitHub Actions workflows, the copy fetched on 2026-11-19, which the tests validate the generated workflows against",
18
+ source: "https://json.schemastore.org/github-workflow.json (the SchemaStore project, https://github.com/SchemaStore/schemastore)",
19
+ owner: "The SchemaStore authors",
20
+ license: "Apache-2.0",
21
+ checked: "The license is that of the SchemaStore repository (its LICENSE is the Apache License 2.0, read on 2026-11-20). unverified: whether the Apache-2.0 text must travel with this one file, which is named here by its address; ask counsel",
22
+ },
23
+ {
24
+ path: "commons/data/sql/extensions/osquery/schema/osquery-5.24.1.auto.json",
25
+ what: "The tables of osquery 5.24.1 (names, columns, types, descriptions), trimmed to the fields the importer reads",
26
+ source: "https://github.com/osquery/osquery-site, commit 055097f8d8fb45c0c33a83c9ed7c56a7df3d7b5f, path src/data/osquery_schema_versions/5.24.1.json",
27
+ owner: "The osquery authors",
28
+ license: "CC-BY-4.0, as the file's own `source.license` records for the osquery-site documentation data; the osquery project is Apache-2.0 OR GPL-2.0-only",
29
+ checked: "Taken from the record in the file itself. unverified: the license file of osquery-site at that commit (the address of a LICENSE file at the root returned 404), so check where the CC-BY-4.0 statement comes from and the attribution it asks for",
30
+ },
31
+ {
32
+ path: "commons/ontology/src/standards/nist-sp-800-53/controls.auto.ts",
33
+ what: "The titles and groups of twelve controls of NIST SP 800-53 Rev. 5.2.0, imported from the OSCAL catalog and held to its SHA-256",
34
+ source: "https://github.com/usnistgov/oscal-content, commit f0de6d8d8c059d374f15e0ae07508d82e370fc1d (import manifest commons/libraries/src/imports/nist-sp-800-53.import.ts)",
35
+ owner: "The National Institute of Standards and Technology",
36
+ license: "Public domain (a work of the United States Government, 17 U.S.C. 105)",
37
+ checked: "Taken from the import manifest, which records it with the SHA-256 of the source.",
38
+ },
39
+ {
40
+ path: "commons/ontology/src/supply-chain/packaging/schema.auto.ts",
41
+ what: "The slice of schema.org 30.1 that the packaging ontology specializes, imported and held to its SHA-256",
42
+ source: "https://schema.org/version/30.1/schemaorg-current-https.ttl (import manifest commons/libraries/src/imports/schema-org.import.ts)",
43
+ owner: "The Schema.org Community Group and contributors",
44
+ license: "CC-BY-SA-3.0",
45
+ checked: "Taken from the import manifest. unverified: whether the ShareAlike term of CC-BY-SA-3.0 reaches this generated module and what it asks of the files that use it; ask counsel",
46
+ },
47
+ {
48
+ path: "commons/ontology/src/supply-chain/packaging/managers.ts",
49
+ what: "The table of package managers, seeded from the tables of upt (the families file, `families.ts`, is seeded from the same)",
50
+ source: "https://github.com/sigoden/upt, kept as a fixture in tests/fixtures/upt/",
51
+ owner: "The authors of upt",
52
+ license: "MIT OR Apache-2.0, at the user's option",
53
+ checked: "Taken from the files' own headers and from tests/fixtures/upt/README.md. unverified: the license files of the pinned upt commit, which are not kept in this repository",
54
+ },
55
+ {
56
+ path: "commons/ontology/src/supply-chain/packaging/families.ts",
57
+ what: "The families of package managers, seeded from the tables of upt",
58
+ source: "https://github.com/sigoden/upt, kept as a fixture in tests/fixtures/upt/",
59
+ owner: "The authors of upt",
60
+ license: "MIT OR Apache-2.0, at the user's option",
61
+ checked: "Taken from the file's own header and from tests/fixtures/upt/README.md. unverified: the license files of the pinned upt commit, which are not kept in this repository",
62
+ },
63
+ {
64
+ path: undefined,
65
+ what: "Mermaid 11.17.2, the script the generated documentation site serves on a page with a diagram; it is copied into the built site from the package `mermaid` and is not in this repository",
66
+ source: "https://www.npmjs.com/package/mermaid",
67
+ owner: "Knut Sveidqvist and contributors",
68
+ license: "MIT",
69
+ checked: "The LICENSE of the installed package 11.17.2 was read on 2026-11-20: The MIT License (MIT), Copyright (c) 2014 - 2022 Knut Sveidqvist.",
70
+ },
71
+ ];
@@ -0,0 +1,61 @@
1
+ import { type Result } from "@intellectual-frontiers/core";
2
+ import { type Library } from "./libraries.js";
3
+ import { type SpdxId } from "./license/standard.js";
4
+ import { type ThirdPartyItem } from "./license/third-party.js";
5
+ /** The command that writes what the check finds wrong. */
6
+ export declare const COMMAND = "bun commons/libraries/src/license.ts";
7
+ /** The license of a library: its manifest's `license`, else the default of the repository. */
8
+ export declare function licenseOf(library: Pick<Library, "license"> | undefined): SpdxId;
9
+ /** The line every `LICENSE` begins with, as the license asks of its licensor (its section Notices). */
10
+ export declare const REQUIRED_NOTICE = "Required Notice: Copyright Intellectual Frontiers LLC (https://github.com/intellectual-frontiers/.github)";
11
+ /** The text of a `LICENSE`: the required notice, a blank line and the official text exactly as it is. */
12
+ export declare function licenseFileText(official: string): string;
13
+ /** What is wrong, one case for each sentence. */
14
+ export type Finding = {
15
+ readonly kind: "text-missing";
16
+ readonly id: SpdxId;
17
+ readonly file: string;
18
+ } | {
19
+ readonly kind: "text-changed";
20
+ readonly id: SpdxId;
21
+ readonly want: string;
22
+ readonly have: string;
23
+ } | {
24
+ readonly kind: "manifest";
25
+ readonly dir: string;
26
+ readonly problem: string;
27
+ } | {
28
+ readonly kind: "missing";
29
+ readonly path: string;
30
+ readonly why: string;
31
+ } | {
32
+ readonly kind: "stale";
33
+ readonly path: string;
34
+ } | {
35
+ readonly kind: "lacks";
36
+ readonly path: string;
37
+ readonly what: string;
38
+ } | {
39
+ readonly kind: "vendored-gone";
40
+ readonly path: string;
41
+ };
42
+ /** The one sentence of a finding. */
43
+ export declare function sentence(f: Finding): string;
44
+ /** A file this module writes: its path from the repository and its whole text. */
45
+ export type Made = {
46
+ readonly path: string;
47
+ readonly text: string;
48
+ };
49
+ /** The official text of a license, held to the SHA-256 of its standard. */
50
+ export declare function officialText(id: SpdxId, folder?: string): Promise<Result<string, Finding>>;
51
+ /** `THIRD_PARTY_NOTICES.md` made from the items. */
52
+ export declare function thirdPartyNotices(items: readonly ThirdPartyItem[]): string;
53
+ /** The result of looking at a repository: what it should hold and what is wrong. */
54
+ export type Judged = {
55
+ readonly made: readonly Made[];
56
+ readonly findings: readonly Finding[];
57
+ };
58
+ /** The files this module makes for a repository and what is wrong with the rest, read from the files and the manifests; nothing is written. */
59
+ export declare function judge(repo: string, folder?: string): Promise<Judged>;
60
+ /** The command line: 0, or 1 where a finding exists (with `--check`) or a file could not be made. Without `--check` the files are written. */
61
+ export declare function main(argv: readonly string[]): Promise<number>;
@@ -0,0 +1,204 @@
1
+ /**
2
+ * The license of the repository and of every library in it, written and checked from one place (commons 0035-licensing). One official text, the PolyForm Noncommercial License 1.0.0
3
+ * (`license/PolyForm-Noncommercial-1.0.0.md`, held to the SHA-256 of its standard), and one `Required Notice:` line for the licensor make the `LICENSE` of the root and of each library folder; the third-party
4
+ * notices are made from the record of what is vendored.
5
+ *
6
+ * bun commons/libraries/src/license.ts write every LICENSE and THIRD_PARTY_NOTICES.md again
7
+ * bun commons/libraries/src/license.ts --check write nothing and exit 1 where any file is not what the manifests and the official text make
8
+ * other flags: --repo DIR (the repository, the working folder by default)
9
+ *
10
+ * @remarks
11
+ * What is written: `LICENSE` at the root and in each `commons/<name>/` that holds a manifest (`library.ts`), and `THIRD_PARTY_NOTICES.md`. What is only checked, because a person writes it: `LICENSING.md`, `COMMERCIAL.md`,
12
+ * `NOTICE`, `CONTRIBUTING.md`, `CITATION.cff`, the License section of `README.md` and the `license` of the root `package.json`. A library with a folder and no `LICENSE` is a finding that names the command above, so a new
13
+ * library runs it once. The packer writes the same identifier into the `package.json` it publishes ({@link licenseOf}).
14
+ *
15
+ * @limits
16
+ * It does not fetch anything: the official text is the copy in `license/`, checked against the SHA-256 its standard records. It does not judge what the hand-written files say beyond the few facts named in {@link Finding}.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { licenseFileText } from "./license.ts";
21
+ * licenseFileText("TEXT\n").startsWith("Required Notice: Copyright Intellectual Frontiers LLC"); // true
22
+ * ```
23
+ *
24
+ * Spec: 0001-libraries FR-019
25
+ *
26
+ * @module
27
+ */
28
+ import process from "node:process";
29
+ import { absurd, err, ok } from "@intellectual-frontiers/core";
30
+ import { sha256 } from "@intellectual-frontiers/crypto/sha256";
31
+ import { stdio } from "@intellectual-frontiers/system";
32
+ import { existsSync, readTextFileSync, writeTextFileSync } from "@intellectual-frontiers/system/fs";
33
+ import { fromFileUrl, join, resolve } from "@intellectual-frontiers/system/path";
34
+ import { readLibraries } from "./libraries.js";
35
+ import { COMMERCIAL_ISSUES_URL, DEFAULT_LICENSE, LICENSE_STANDARDS, LICENSOR, REPOSITORY_URL } from "./license/standard.js";
36
+ import { THIRD_PARTY } from "./license/third-party.js";
37
+ /** The command that writes what the check finds wrong. */
38
+ export const COMMAND = "bun commons/libraries/src/license.ts";
39
+ /** The license of a library: its manifest's `license`, else the default of the repository. */
40
+ export function licenseOf(library) {
41
+ return library?.license ?? DEFAULT_LICENSE;
42
+ }
43
+ /** The line every `LICENSE` begins with, as the license asks of its licensor (its section Notices). */
44
+ export const REQUIRED_NOTICE = `Required Notice: Copyright ${LICENSOR} (${REPOSITORY_URL})`;
45
+ /** The text of a `LICENSE`: the required notice, a blank line and the official text exactly as it is. */
46
+ export function licenseFileText(official) {
47
+ return `${REQUIRED_NOTICE}\n\n${official}`;
48
+ }
49
+ /** The one sentence of a finding. */
50
+ export function sentence(f) {
51
+ switch (f.kind) {
52
+ case "text-missing":
53
+ return `the official text of ${f.id} is not at commons/libraries/src/license/${f.file}`;
54
+ case "text-changed":
55
+ return `commons/libraries/src/license/ is not the official text of the standard: its SHA-256 is ${f.have} and the standard records ${f.want}`;
56
+ case "manifest":
57
+ return `commons/${f.dir}/library.ts cannot be read: ${f.problem}`;
58
+ case "missing":
59
+ return `${f.path} is missing: ${f.why}`;
60
+ case "stale":
61
+ return `${f.path} is not what the official text and the manifest make; run: ${COMMAND}`;
62
+ case "lacks":
63
+ return `${f.path} does not ${f.what}`;
64
+ case "vendored-gone":
65
+ return `${f.path} is named as vendored in commons/libraries/src/license/third-party.ts and is not in the repository`;
66
+ default:
67
+ return absurd(f);
68
+ }
69
+ }
70
+ const lf = (t) => t.replaceAll("\r\n", "\n");
71
+ const here = resolve(fromFileUrl(new URL(".", import.meta.url)));
72
+ /** The official text of a license, held to the SHA-256 of its standard. */
73
+ export async function officialText(id, folder = join(here, "license")) {
74
+ const std = LICENSE_STANDARDS[id];
75
+ const file = join(folder, std.file);
76
+ if (!existsSync(file))
77
+ return err({ kind: "text-missing", id, file: std.file });
78
+ const text = lf(readTextFileSync(file));
79
+ const have = await sha256(text);
80
+ return have === std.sha256 ? ok(text) : err({ kind: "text-changed", id, want: std.sha256, have });
81
+ }
82
+ /** `THIRD_PARTY_NOTICES.md` made from the items. */
83
+ export function thirdPartyNotices(items) {
84
+ const body = items.map((i) => [
85
+ `## ${i.path === undefined ? i.what.split(",")[0] ?? i.what : `\`${i.path}\``}`,
86
+ "",
87
+ `- **What**: ${i.what}.`,
88
+ `- **Source**: ${i.source}.`,
89
+ `- **Owner**: ${i.owner}.`,
90
+ `- **License**: ${i.license}.`,
91
+ `- **Checked**: ${i.checked}`,
92
+ "",
93
+ ].join("\n"));
94
+ return [
95
+ "# Third-party notices",
96
+ "",
97
+ "<!-- Generated by `bun commons/libraries/src/license.ts` from `commons/libraries/src/license/third-party.ts`: change that file and run the command, never this one. -->",
98
+ "",
99
+ "Intellectual Frontiers LLC owns the code of this repository, which is under the PolyForm Noncommercial License 1.0.0 (see [`LICENSE`](LICENSE)). The items below are not its own: each is under the license named, which is not changed by this repository's.",
100
+ "Where an item says `unverified:` the license was recorded from a secondary source and has not been checked against the original; that is for the owner to settle, and nothing here is a statement that it is settled.",
101
+ "",
102
+ "Packages installed from a registry (listed in `bun.lock`) are not vendored: nothing of them is in this repository, and each package carries its own license.",
103
+ "",
104
+ ...body,
105
+ ].join("\n");
106
+ }
107
+ const read = (repo, path) => (existsSync(join(repo, path)) ? lf(readTextFileSync(join(repo, path))) : undefined);
108
+ const HAND_WRITTEN = [
109
+ { path: "LICENSING.md", why: "it says in plain words what is free and what needs a commercial license" },
110
+ { path: "COMMERCIAL.md", why: "it says what a commercial license covers and how it is obtained" },
111
+ { path: "NOTICE", why: "it carries the copyright of the licensor" },
112
+ { path: "CONTRIBUTING.md", why: "it carries the sign-off and the contributor's agreement" },
113
+ { path: "CITATION.cff", why: "it says how to cite the software and under what license" },
114
+ ];
115
+ /** Whether `text` contains `needle`, as a finding where it does not. */
116
+ const must = (path, text, needle, what) => text === undefined || text.includes(needle) ? [] : [{ kind: "lacks", path, what }];
117
+ /** The files this module makes for a repository and what is wrong with the rest, read from the files and the manifests; nothing is written. */
118
+ export async function judge(repo, folder) {
119
+ const root = repo.replace(/[\\/]$/, "");
120
+ const findings = [];
121
+ const made = [];
122
+ const texts = new Map();
123
+ const reported = new Set();
124
+ const textOf = async (id) => {
125
+ const have = texts.get(id);
126
+ if (have !== undefined)
127
+ return have;
128
+ const r = await officialText(id, folder);
129
+ if (r.kind === "err") {
130
+ if (!reported.has(id))
131
+ findings.push(r.error);
132
+ reported.add(id);
133
+ return undefined;
134
+ }
135
+ texts.set(id, r.value);
136
+ return r.value;
137
+ };
138
+ const rootText = await textOf(DEFAULT_LICENSE);
139
+ if (rootText !== undefined)
140
+ made.push({ path: "LICENSE", text: licenseFileText(rootText) });
141
+ for (const f of readLibraries(root)) {
142
+ if ("problem" in f) {
143
+ findings.push({ kind: "manifest", dir: f.dir, problem: f.problem });
144
+ continue;
145
+ }
146
+ const t = await textOf(licenseOf(f.library));
147
+ if (t !== undefined)
148
+ made.push({ path: `commons/${f.dir}/LICENSE`, text: licenseFileText(t) });
149
+ }
150
+ made.push({ path: "THIRD_PARTY_NOTICES.md", text: thirdPartyNotices(THIRD_PARTY) });
151
+ for (const m of made) {
152
+ const have = read(root, m.path);
153
+ if (have === undefined)
154
+ findings.push({ kind: "missing", path: m.path, why: m.path === "THIRD_PARTY_NOTICES.md" ? "it lists what is vendored and its licenses" : `it is the license of ${m.path === "LICENSE" ? "the repository" : "the library"}; run: ${COMMAND}` });
155
+ else if (have !== m.text)
156
+ findings.push({ kind: "stale", path: m.path });
157
+ }
158
+ for (const h of HAND_WRITTEN) {
159
+ const t = read(root, h.path);
160
+ if (t === undefined || t.trim() === "")
161
+ findings.push({ kind: "missing", path: h.path, why: h.why });
162
+ }
163
+ findings.push(...must("NOTICE", read(root, "NOTICE"), `Copyright ${LICENSOR}`, `name the copyright of ${LICENSOR}`));
164
+ findings.push(...must("CONTRIBUTING.md", read(root, "CONTRIBUTING.md"), "git commit -s", "ask for a sign-off with `git commit -s`"));
165
+ findings.push(...must("LICENSING.md", read(root, "LICENSING.md"), DEFAULT_LICENSE, `name ${DEFAULT_LICENSE}`));
166
+ findings.push(...must("LICENSING.md", read(root, "LICENSING.md"), COMMERCIAL_ISSUES_URL, `say where to ask for a commercial license (${COMMERCIAL_ISSUES_URL})`));
167
+ findings.push(...must("CITATION.cff", read(root, "CITATION.cff"), `license: ${DEFAULT_LICENSE}`, `carry \`license: ${DEFAULT_LICENSE}\``));
168
+ const readme = read(root, "README.md");
169
+ if (readme !== undefined) {
170
+ const at = readme.indexOf("\n## License\n");
171
+ const rest = at < 0 ? "" : readme.slice(at + 1);
172
+ const next = rest.indexOf("\n## ", 1);
173
+ const section = next < 0 ? rest : rest.slice(0, next);
174
+ if (at < 0 || !section.includes(DEFAULT_LICENSE))
175
+ findings.push({ kind: "lacks", path: "README.md", what: `have a License section that names ${DEFAULT_LICENSE}` });
176
+ }
177
+ const pkg = read(root, "package.json");
178
+ if (pkg !== undefined && !pkg.includes(`"license": "${DEFAULT_LICENSE}"`))
179
+ findings.push({ kind: "lacks", path: "package.json", what: `declare "license": "${DEFAULT_LICENSE}"` });
180
+ for (const i of THIRD_PARTY)
181
+ if (i.path !== undefined && !existsSync(join(root, i.path)))
182
+ findings.push({ kind: "vendored-gone", path: i.path });
183
+ return { made, findings };
184
+ }
185
+ /** The command line: 0, or 1 where a finding exists (with `--check`) or a file could not be made. Without `--check` the files are written. */
186
+ export async function main(argv) {
187
+ const at = argv.indexOf("--repo");
188
+ const repo = at >= 0 ? (argv[at + 1] ?? ".") : ".";
189
+ const check = argv.includes("--check");
190
+ let j = await judge(repo);
191
+ if (!check) {
192
+ for (const m of j.made) {
193
+ const have = read(repo, m.path);
194
+ if (have !== m.text)
195
+ writeTextFileSync(join(repo.replace(/[\\/]$/, ""), m.path), m.text);
196
+ }
197
+ j = await judge(repo);
198
+ }
199
+ for (const f of j.findings)
200
+ stdio.stderr.writeSync(`${sentence(f)}\n`);
201
+ return j.findings.length > 0 ? 1 : 0;
202
+ }
203
+ if (import.meta.main)
204
+ process.exitCode = await main(process.argv.slice(2));
package/dist/link.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /** The packages of commons by name and the folder of each; `commons/ts` comes first, so that it is the one that bears `@intellectual-frontiers/commons`. */
1
+ /** The packages of commons by name and the folder of each. */
2
2
  export declare function linksOf(repo: string): ReadonlyMap<string, string>;
3
3
  /** Links each package that is not linked yet, and gives how many it linked, or why it could not. */
4
4
  export declare function linkAll(repo: string): {
package/dist/link.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * bun commons/libraries/src/link.ts link what is not linked, from the repository above this folder (or --repo DIR)
7
7
  *
8
8
  * @remarks
9
- * A folder of `commons/` whose `package.json` is named `@intellectual-frontiers/<name>` is linked as that name, and `commons/ts` as `@intellectual-frontiers/commons` (`commons/docs` bears the same name and is not linked). A link
9
+ * A folder of `commons/` whose `package.json` is named `@intellectual-frontiers/<name>` is linked as that name (the metapackage `commons/commons` bears `@intellectual-frontiers/commons`). A link
10
10
  * that is there is left as it is. Only the built-ins of Node are used, so it runs on Bun and on Node 26 before anything is installed.
11
11
  *
12
12
  * @limits
@@ -15,7 +15,7 @@
15
15
  * @example
16
16
  * ```ts
17
17
  * import { linksOf } from "./link.ts";
18
- * linksOf(".").get("@intellectual-frontiers/commons"); // the path of commons/ts
18
+ * linksOf(".").get("@intellectual-frontiers/commons"); // the path of commons/commons
19
19
  * ```
20
20
  *
21
21
  * Spec: 0001-libraries FR-011
@@ -36,13 +36,13 @@ const nameOf = (file) => {
36
36
  return undefined;
37
37
  }
38
38
  };
39
- /** The packages of commons by name and the folder of each; `commons/ts` comes first, so that it is the one that bears `@intellectual-frontiers/commons`. */
39
+ /** The packages of commons by name and the folder of each. */
40
40
  export function linksOf(repo) {
41
41
  const links = new Map();
42
42
  const dirs = readdirSync(join(repo, "commons"), { withFileTypes: true })
43
43
  .filter((e) => e.isDirectory() && e.name !== "node_modules")
44
44
  .map((e) => e.name)
45
- .sort((a, b) => (a === "ts" ? -1 : b === "ts" ? 1 : a < b ? -1 : 1));
45
+ .sort((a, b) => (a < b ? -1 : 1));
46
46
  for (const d of dirs) {
47
47
  const name = nameOf(join(repo, "commons", d, "package.json"));
48
48
  if (name !== undefined && name.startsWith(SCOPE) && !links.has(name))
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The metapackages of commons (commons 0036-distribution FR-005 to FR-008): five packages with no code of their own, each a set of libraries at the exact versions of one release. `@intellectual-frontiers/commons` is every
3
+ * consumer-facing library; `foundation`, `patterns`, `programs` and `standards` are the four roles of the libraries. A repository other than `.github` installs commons by installing one of them, or a library, from a registry.
4
+ *
5
+ * @remarks
6
+ * Pure: the libraries as data give the members of a set, the exact dependencies of its package, the file that records them, the `package.json` and the README that are published. The role of a library is read from `ROLE_OF` of
7
+ * `readme.ts`, the one place that says it, and the set of a role is the role's: `foundation`, `pattern` (`patterns`), `program` (`programs`) and `standard` (`standards`). A library is consumer-facing where its distribution
8
+ * names npm and it is not a metapackage and not held back ({@link HELD_BACK}); the package of a member is the package it publishes ({@link publishedPackage}). A member whose role is not known is a problem and never a member
9
+ * of no set. The effects (writing the files, packing) are `pack-metapackage.ts`.
10
+ *
11
+ * @limits
12
+ * It reads no file and knows no registry. It does not know what is published: a release that has not published a member makes the set refer to a version npm does not hold yet, which the release's order prevents.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { dependenciesOf } from "./metapackages.js";
17
+ * dependenciesOf([{ library: "core", package: "@intellectual-frontiers/core", version: "0.1.5" }]); // { "@intellectual-frontiers/core": "0.1.5" }
18
+ * ```
19
+ *
20
+ * Spec: 0001-libraries FR-023
21
+ *
22
+ * @module
23
+ */
24
+ import { type Result } from "@intellectual-frontiers/core";
25
+ import { type BundleName, type Library } from "./libraries.js";
26
+ import { type Role } from "./readme.js";
27
+ /** The libraries that are not in any set yet, each with why: they declare npm and are not ready to be installed (commons 0036-distribution FR-006). A library leaves this list when its owner releases it. */
28
+ export declare const HELD_BACK: ReadonlyMap<string, string>;
29
+ /** The roles' sets: a role is in exactly one. */
30
+ export declare const BUNDLE_OF_ROLE: Readonly<Record<Role, Exclude<BundleName, "commons">>>;
31
+ /** A member of a set: the library, the package it publishes and the version of this release. */
32
+ export type Member = {
33
+ readonly library: string;
34
+ readonly package: string;
35
+ readonly version: string;
36
+ };
37
+ /** The exact dependencies of a package: the name of each member and its version, nothing else. */
38
+ export type Dependencies = Readonly<Record<string, string>>;
39
+ /** Whether a library is installed by a set: it names npm, it is no metapackage and it is not held back. */
40
+ export declare function isConsumerFacing(l: Pick<Library, "name" | "bundle" | "distribution" | "held">): boolean;
41
+ /** The members of a set, in the order of their packages' names; the problem where a consumer-facing library has no role in `ROLE_OF`. */
42
+ export declare function membersOf(bundle: BundleName, libraries: readonly Library[]): Result<readonly Member[], string>;
43
+ /** The exact dependencies of the package of a set: each member's package at its version, no range. */
44
+ export declare function dependenciesOf(members: readonly Member[]): Dependencies;
45
+ /** What the generated file of a set holds: the set and its exact dependencies. */
46
+ export declare function setFileText(bundle: BundleName, members: readonly Member[]): string;
47
+ /** The generated file of a set, from its folder. */
48
+ export declare const SET_FILE = "dependencies.auto.json";
49
+ /** The dependencies a generated file holds, or why its text is not one. */
50
+ export declare function readSetFile(text: string): Result<Dependencies, string>;
51
+ /** The text of a set's own `description`, which the package carries. */
52
+ export declare function descriptionOf(bundle: BundleName): string;
53
+ /** The README of a set's package: what it holds, how to install it from npm and from the GitHub package registry, and how to keep one copy of each library. */
54
+ export declare function readmeOf(bundle: BundleName, members: readonly Member[]): string;
55
+ /** The `package.json` that is published for a set: no code, one empty entry, the exact dependencies. */
56
+ export declare function publishedManifest(bundle: BundleName, version: string, dependencies: Dependencies, license: string): Readonly<Record<string, unknown>>;
57
+ /** The one file of code of a set's package, and its declaration: an empty module, so that the entry imports. */
58
+ export declare const ENTRY_JS = "export {};\n";
59
+ /** The declaration of {@link ENTRY_JS}. */
60
+ export declare const ENTRY_DTS = "export {};\n";
61
+ /** Every set, in the order the README lists them. */
62
+ export declare const ALL_BUNDLES: readonly BundleName[];