@arcgis/node-toolkit 6.0.0-next.6 → 6.0.0-next.8

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/dist/env.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Reads the .env file and loads the environment variables.
3
+ *
4
+ * @param searchRoot Set this to `import.meta.dirname`. If no `.env` file is found, will search at `process.cwd()`.
5
+ */
6
+ export declare function readEnvFile(searchRoot: string): void;
package/dist/env.js ADDED
@@ -0,0 +1,10 @@
1
+ import { findPath } from "./file.js";
2
+ function readEnvFile(searchRoot) {
3
+ const envFile = findPath(".env", searchRoot) ?? findPath(".env");
4
+ if (envFile !== void 0) {
5
+ process.loadEnvFile(envFile);
6
+ }
7
+ }
8
+ export {
9
+ readEnvFile
10
+ };
@@ -0,0 +1,9 @@
1
+ export declare const markdownTextLimit = 65000;
2
+ /**
3
+ * Split markdown to fit into GitHub comment length limit. Splits at best available
4
+ * places: headings, code blocks and details sections, blank lines.
5
+ *
6
+ * Use cases: automated reports in issues, pull request check status comments,
7
+ * reporting public API diff inside a pr comment.
8
+ */
9
+ export declare function splitMarkdown(content: string, limit?: number): string[];
@@ -0,0 +1,102 @@
1
+ const markdownTextLimit = 65e3;
2
+ const boundaryKinds = ["heading", "block", "blank", "line", "text"];
3
+ function splitMarkdown(content, limit = markdownTextLimit) {
4
+ if (!Number.isSafeInteger(limit) || limit < 2) {
5
+ throw new Error("Markdown limit must be an integer of at least 2.");
6
+ }
7
+ const chunks = [];
8
+ let start = 0;
9
+ let blocks = [];
10
+ let prefix = "";
11
+ while (prefix.length + content.length - start > limit) {
12
+ const remaining = content.slice(start);
13
+ const split = getBoundary(remaining, limit - prefix.length, blocks, start === 0 || content[start - 1] === "\n");
14
+ chunks.push(
15
+ prefix + remaining.slice(0, split.index) + closeBlocks(split.blocks, remaining[split.index - 1] === "\n")
16
+ );
17
+ start += split.index;
18
+ blocks = split.blocks;
19
+ prefix = openBlocks(blocks);
20
+ }
21
+ chunks.push(prefix + content.slice(start));
22
+ return chunks;
23
+ }
24
+ function getBoundary(content, limit, initialBlocks, atLineStart) {
25
+ const blocks = [...initialBlocks];
26
+ let best;
27
+ let skipEnd = 0;
28
+ for (const match of content.matchAll(/[^\n]*(?:\n|$)/gu)) {
29
+ const index = match.index;
30
+ if (index > limit) {
31
+ break;
32
+ }
33
+ const line = match[0];
34
+ const end = index + line.length;
35
+ let textStart = Math.max(index, skipEnd);
36
+ if (end <= textStart) {
37
+ continue;
38
+ }
39
+ const aligned = textStart === index && (index > 0 || atLineStart);
40
+ const fence = aligned ? /^ {0,3}(`{3,}|~{3,})([^\r\n]*)/u.exec(line) : null;
41
+ const activeFence = blocks.at(-1)?.fence;
42
+ const opening = aligned && activeFence === void 0 ? /^[ \t]*<details\b[^>]*>(?:\s*<summary\b[^>]*>[\s\S]*?<\/summary\s*>)?/iu.exec(content.slice(index)) : null;
43
+ const kind = !aligned ? "text" : activeFence !== void 0 ? "line" : opening !== null || fence !== null ? "block" : /^ {0,3}#{1,6}\s/u.test(line) ? "heading" : /^\s*$/u.test(line) ? "blank" : "line";
44
+ consider(textStart, kind);
45
+ if (activeFence !== void 0) {
46
+ if (fence !== null && fence[1].startsWith(activeFence[0]) && fence[1].length >= activeFence.length && fence[2].trim() === "") {
47
+ blocks.pop();
48
+ textStart = end;
49
+ }
50
+ } else if (fence !== null) {
51
+ blocks.push({ opening: line.trimEnd(), closing: fence[1], fence: fence[1] });
52
+ textStart = end;
53
+ } else if (aligned && /^\s*<!--/u.test(line)) {
54
+ const closing = content.indexOf("-->", index);
55
+ textStart = closing === -1 ? content.length : closing + 3;
56
+ } else if (opening !== null) {
57
+ if (/<\/details\s*>/iu.test(line)) {
58
+ textStart = end;
59
+ } else {
60
+ blocks.push({ opening: opening[0], closing: "</details>" });
61
+ textStart = index + opening[0].length;
62
+ }
63
+ } else if (aligned && /^\s*<\/details\s*>/iu.test(line)) {
64
+ blocks.pop();
65
+ textStart = end;
66
+ }
67
+ skipEnd = textStart;
68
+ if (textStart <= end) {
69
+ consider(end, line.endsWith("\n") ? "line" : "text");
70
+ let exact = Math.min(end, limit - closeBlocks(blocks).length);
71
+ if (/[\uD800-\uDBFF]/u.test(content[exact - 1]) && /[\uDC00-\uDFFF]/u.test(content[exact])) {
72
+ exact--;
73
+ }
74
+ if (exact >= textStart) {
75
+ consider(exact, "text");
76
+ }
77
+ }
78
+ }
79
+ if (best === void 0) {
80
+ throw new Error("Markdown limit is too small to split the enclosing blocks.");
81
+ }
82
+ return best;
83
+ function consider(index, kind) {
84
+ if (index <= 0 || index + closeBlocks(blocks, content[index - 1] === "\n").length > limit) {
85
+ return;
86
+ }
87
+ if (best === void 0 || boundaryKinds.indexOf(kind) < boundaryKinds.indexOf(best.kind) || kind === best.kind && index > best.index) {
88
+ best = { index, kind, blocks: [...blocks] };
89
+ }
90
+ }
91
+ }
92
+ function closeBlocks(blocks, endsWithNewline = false) {
93
+ return blocks.length === 0 ? "" : `${endsWithNewline ? "" : "\n"}${blocks.toReversed().map(({ closing }) => closing).join("\n")}
94
+ `;
95
+ }
96
+ function openBlocks(blocks) {
97
+ return blocks.map(({ opening, fence }) => opening + (fence === void 0 ? "\n\n" : "\n")).join("");
98
+ }
99
+ export {
100
+ markdownTextLimit,
101
+ splitMarkdown
102
+ };
@@ -51,7 +51,7 @@ export type PackageJson = {
51
51
  /** @public */
52
52
  "css.customData"?: string[];
53
53
  /** @public */
54
- "customElements"?: string;
54
+ "customElements"?: string[] | string;
55
55
  /** @public */
56
56
  "html.customData"?: string[];
57
57
  /** @public */
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@arcgis/node-toolkit",
3
- "version": "6.0.0-next.6",
3
+ "version": "6.0.0-next.8",
4
4
  "description": "Collection of common internal build-time patterns and utilities for ArcGIS Maps SDK for JavaScript components.",
5
5
  "homepage": "https://developers.arcgis.com/javascript/latest/",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  "./codeowners": "./dist/codeowners.js",
9
+ "./env": "./dist/env.js",
9
10
  "./file": "./dist/file.js",
11
+ "./markdown": "./dist/markdown.js",
10
12
  "./shell": "./dist/shell.js",
11
13
  "./glob": "./dist/glob.js",
12
14
  "./path": "./dist/path.js",