@textmode/tsconfig 0.2.2 → 0.3.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 (34) hide show
  1. package/LICENSE +21 -121
  2. package/README.md +7 -7
  3. package/dist/cli/textmode-types.d.ts +3 -0
  4. package/dist/cli/textmode-types.d.ts.map +1 -0
  5. package/dist/cli/textmode-types.js +95 -0
  6. package/dist/cli/textmode-types.js.map +1 -0
  7. package/dist/index.d.ts +11 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +11 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/internal/check-project.d.ts +52 -0
  12. package/dist/internal/check-project.d.ts.map +1 -0
  13. package/dist/internal/check-project.js +65 -0
  14. package/dist/internal/check-project.js.map +1 -0
  15. package/dist/internal/declaration-doc-tags.d.ts +45 -0
  16. package/dist/internal/declaration-doc-tags.d.ts.map +1 -0
  17. package/dist/internal/declaration-doc-tags.js +210 -0
  18. package/dist/internal/declaration-doc-tags.js.map +1 -0
  19. package/dist/internal/declarations.d.ts +20 -0
  20. package/dist/internal/declarations.d.ts.map +1 -0
  21. package/dist/internal/declarations.js +136 -0
  22. package/dist/internal/declarations.js.map +1 -0
  23. package/dist/internal/project.d.ts +68 -0
  24. package/dist/internal/project.d.ts.map +1 -0
  25. package/dist/internal/project.js +100 -0
  26. package/dist/internal/project.js.map +1 -0
  27. package/dist/internal/typescript-compiler.d.ts +25 -0
  28. package/dist/internal/typescript-compiler.d.ts.map +1 -0
  29. package/dist/internal/typescript-compiler.js +43 -0
  30. package/dist/internal/typescript-compiler.js.map +1 -0
  31. package/package.json +70 -50
  32. package/src/cli/textmode-types.mjs +0 -99
  33. package/src/internal/declaration-doc-tags.mjs +0 -202
  34. package/src/internal/project.mjs +0 -282
package/package.json CHANGED
@@ -1,51 +1,71 @@
1
1
  {
2
- "name": "@textmode/tsconfig",
3
- "version": "0.2.2",
4
- "type": "module",
5
- "license": "CC0-1.0",
6
- "engines": {
7
- "node": ">=24 <25"
8
- },
9
- "exports": {
10
- "./strict.json": "./strict.json",
11
- "./browser.json": "./browser.json",
12
- "./browser-library.json": "./browser-library.json",
13
- "./node.json": "./node.json",
14
- "./node-tooling.json": "./node-tooling.json",
15
- "./base.json": "./base.json",
16
- "./typecheck.json": "./typecheck.json",
17
- "./build.json": "./build.json",
18
- "./dist.json": "./dist.json"
19
- },
20
- "bin": {
21
- "textmode-types": "src/cli/textmode-types.mjs"
22
- },
23
- "files": [
24
- "strict.json",
25
- "browser.json",
26
- "browser-library.json",
27
- "node.json",
28
- "node-tooling.json",
29
- "base.json",
30
- "typecheck.json",
31
- "build.json",
32
- "dist.json",
33
- "src",
34
- "README.md"
35
- ],
36
- "peerDependencies": {
37
- "typescript": ">=6 <7"
38
- },
39
- "devDependencies": {
40
- "@types/node": "^26.1.2",
41
- "typescript": "^6.0.3",
42
- "vitest": "^4.1.10"
43
- },
44
- "scripts": {
45
- "check": "pnpm run check:format && pnpm run lint && pnpm run test && pnpm run check:package",
46
- "check:format": "prettier --check .",
47
- "check:package": "node scripts/check-package.mjs",
48
- "lint": "node --check src/cli/textmode-types.mjs && node --check src/internal/*.mjs && node --check scripts/check-package.mjs",
49
- "test": "vitest run"
50
- }
51
- }
2
+ "name": "@textmode/tsconfig",
3
+ "version": "0.3.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "description": "Shared TypeScript presets and declaration verification tooling for the textmode.js ecosystem.",
7
+ "keywords": [
8
+ "textmode",
9
+ "typescript",
10
+ "tsconfig",
11
+ "types",
12
+ "declarations"
13
+ ],
14
+ "author": "humanbydefinition <hello@textmode.art> (https://code.textmode.art)",
15
+ "homepage": "https://code.textmode.art",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/textmode-art/tooling.git",
19
+ "directory": "packages/tsconfig"
20
+ },
21
+ "engines": {
22
+ "node": "^24.15.0 || >=26.0.0"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./strict.json": "./strict.json",
30
+ "./browser.json": "./browser.json",
31
+ "./browser-library.json": "./browser-library.json",
32
+ "./node.json": "./node.json",
33
+ "./node-tooling.json": "./node-tooling.json",
34
+ "./base.json": "./base.json",
35
+ "./typecheck.json": "./typecheck.json",
36
+ "./build.json": "./build.json",
37
+ "./dist.json": "./dist.json",
38
+ "./package.json": "./package.json"
39
+ },
40
+ "bin": {
41
+ "textmode-types": "dist/cli/textmode-types.js"
42
+ },
43
+ "files": [
44
+ "dist",
45
+ "strict.json",
46
+ "browser.json",
47
+ "browser-library.json",
48
+ "node.json",
49
+ "node-tooling.json",
50
+ "base.json",
51
+ "typecheck.json",
52
+ "build.json",
53
+ "dist.json",
54
+ "README.md"
55
+ ],
56
+ "peerDependencies": {
57
+ "typescript": ">=6 <7"
58
+ },
59
+ "devDependencies": {
60
+ "@types/node": "^24.0.0",
61
+ "typescript": "^6.0.3",
62
+ "vitest": "^5.1.0"
63
+ },
64
+ "publishConfig": {
65
+ "access": "public"
66
+ },
67
+ "scripts": {
68
+ "build": "tsc -b",
69
+ "test": "vitest run"
70
+ }
71
+ }
@@ -1,99 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from 'node:fs';
4
- import process from 'node:process';
5
- import { parseArgs } from 'node:util';
6
-
7
- import {
8
- ProjectError,
9
- buildDeclarations,
10
- checkProject,
11
- describeProject,
12
- resolveProject,
13
- verifyDeclarations,
14
- } from '../internal/project.mjs';
15
-
16
- const PACKAGE_JSON = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
17
- const COMMANDS = new Set(['check', 'build', 'verify', 'show-config']);
18
-
19
- function printHelp() {
20
- console.log(`@textmode/tsconfig ${PACKAGE_JSON.version}`);
21
- console.log('');
22
- console.log('Usage: textmode-types <command> [options]');
23
- console.log('');
24
- console.log('Commands:');
25
- console.log(' check Type-check the authored project and reject unclaimed TypeScript files');
26
- console.log(' build Emit production declarations to dist/types');
27
- console.log(' verify Resolve every package export from an isolated declaration consumer');
28
- console.log(' show-config Print the resolved authoring and declaration programs');
29
- console.log('');
30
- console.log('Options:');
31
- console.log(' --cwd <dir> Project root containing package.json');
32
- console.log(' --project <file> TypeScript config relative to the project root');
33
- console.log(' --help, -h Show help');
34
- console.log(' --version Show version');
35
- }
36
-
37
- function parseCli(argv) {
38
- const parsed = parseArgs({
39
- args: argv,
40
- allowPositionals: true,
41
- strict: true,
42
- options: {
43
- cwd: { type: 'string' },
44
- project: { type: 'string' },
45
- help: { type: 'boolean', short: 'h' },
46
- version: { type: 'boolean' },
47
- },
48
- });
49
- if (parsed.values.version) return { action: 'version' };
50
- if (parsed.values.help && parsed.positionals.length === 0) return { action: 'help' };
51
- if (parsed.positionals.length !== 1 || !COMMANDS.has(parsed.positionals[0])) {
52
- throw new ProjectError('Expected one command: check, build, verify, or show-config.');
53
- }
54
- if (parsed.values.help) return { action: 'help' };
55
- return { action: 'run', command: parsed.positionals[0], values: parsed.values };
56
- }
57
-
58
- function run(argv) {
59
- let cli;
60
- try {
61
- cli = parseCli(argv);
62
- } catch (error) {
63
- console.error(error instanceof Error ? error.message : String(error));
64
- process.exitCode = 2;
65
- return;
66
- }
67
- if (cli.action === 'help') {
68
- printHelp();
69
- return;
70
- }
71
- if (cli.action === 'version') {
72
- console.log(PACKAGE_JSON.version);
73
- return;
74
- }
75
- try {
76
- const project = resolveProject({ cwd: cli.values.cwd, project: cli.values.project });
77
- let ok = true;
78
- switch (cli.command) {
79
- case 'check':
80
- ok = checkProject(project);
81
- break;
82
- case 'build':
83
- ok = buildDeclarations(project);
84
- break;
85
- case 'verify':
86
- ok = verifyDeclarations(project);
87
- break;
88
- case 'show-config':
89
- console.log(JSON.stringify(describeProject(project), null, 2));
90
- break;
91
- }
92
- if (!ok) process.exitCode = 1;
93
- } catch (error) {
94
- console.error(error instanceof Error ? (error.stack ?? error.message) : String(error));
95
- process.exitCode = error instanceof ProjectError ? 2 : 1;
96
- }
97
- }
98
-
99
- run(process.argv.slice(2));
@@ -1,202 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- export const STRIPPED_DECLARATION_DOC_TAGS = ['category', 'categoryDescription'];
5
-
6
- const DECLARATION_FILE_PATTERN = /\.d\.(?:ts|mts|cts)$/;
7
- const TAG_PATTERN = new RegExp(`^@(?:${STRIPPED_DECLARATION_DOC_TAGS.join('|')})(?=\\s|$)`);
8
- const ANY_TAG_PATTERN = /^@[A-Za-z][A-Za-z0-9_-]*(?=\s|$)/;
9
-
10
- function splitLines(text) {
11
- const lines = text.match(/.*(?:\r\n|\n|\r|$)/g) ?? [];
12
- return lines.filter((line) => line.length > 0);
13
- }
14
-
15
- function docLineBody(line) {
16
- const match = /^(\s*\*?[ \t]*)(.*?)(\r\n|\n|\r)?$/.exec(line);
17
- return match ? match[2] : line;
18
- }
19
-
20
- function updateFence(line, activeFence) {
21
- const match = /^(`{3,}|~{3,})(.*)$/.exec(docLineBody(line).trimStart());
22
- if (!match) return activeFence;
23
-
24
- const [marker, suffix] = match.slice(1);
25
- if (!activeFence) return { character: marker[0], length: marker.length };
26
- if (marker[0] === activeFence.character && marker.length >= activeFence.length && suffix.trim().length === 0) {
27
- return null;
28
- }
29
- return activeFence;
30
- }
31
-
32
- function categoryTag(line) {
33
- return TAG_PATTERN.test(docLineBody(line).trimStart());
34
- }
35
-
36
- function anyTag(line) {
37
- return ANY_TAG_PATTERN.test(docLineBody(line).trimStart());
38
- }
39
-
40
- function compactBlankLines(lines) {
41
- const compacted = [];
42
- let previousWasBlank = false;
43
- for (const line of lines) {
44
- const blank = docLineBody(line).trim().length === 0;
45
- if (blank && previousWasBlank) continue;
46
- compacted.push(line);
47
- previousWasBlank = blank;
48
- }
49
- return compacted;
50
- }
51
-
52
- function stripTagsFromJsDocContent(content) {
53
- const retained = [];
54
- let activeFence = null;
55
- let removingTagContent = false;
56
- let removedTags = 0;
57
-
58
- for (const line of splitLines(content)) {
59
- if (!activeFence && categoryTag(line)) {
60
- removingTagContent = true;
61
- removedTags += 1;
62
- continue;
63
- }
64
-
65
- if (removingTagContent) {
66
- if (!activeFence && anyTag(line)) {
67
- removingTagContent = false;
68
- } else {
69
- activeFence = updateFence(line, activeFence);
70
- continue;
71
- }
72
- }
73
-
74
- retained.push(line);
75
- activeFence = updateFence(line, activeFence);
76
- }
77
-
78
- if (removedTags === 0) return { content, removedTags };
79
- const normalized = compactBlankLines(retained).join('');
80
- return {
81
- content: normalized.replace(/^\s+|\s+$/g, '') === '' ? '' : normalized,
82
- removedTags,
83
- };
84
- }
85
-
86
- function transformJsDocComments(source, transform) {
87
- let output = '';
88
- let index = 0;
89
-
90
- while (index < source.length) {
91
- const character = source[index];
92
- if (character === '"' || character === "'" || character === '`') {
93
- const end = skipQuotedText(source, index, character);
94
- output += source.slice(index, end);
95
- index = end;
96
- continue;
97
- }
98
- if (source.startsWith('//', index)) {
99
- const end = findLineEnd(source, index + 2);
100
- output += source.slice(index, end);
101
- index = end;
102
- continue;
103
- }
104
- if (source.startsWith('/*', index)) {
105
- const end = findCommentEnd(source, index + 2);
106
- const comment = source.slice(index, end);
107
- output += source.startsWith('/**', index) ? transform(comment) : comment;
108
- index = end;
109
- continue;
110
- }
111
- output += character;
112
- index += 1;
113
- }
114
-
115
- return output;
116
- }
117
-
118
- function findCommentEnd(source, start) {
119
- const closingIndex = source.indexOf('*/', start);
120
- return closingIndex === -1 ? source.length : closingIndex + 2;
121
- }
122
-
123
- function findLineEnd(source, start) {
124
- const lineBreak = source.slice(start).search(/[\r\n]/);
125
- return lineBreak === -1 ? source.length : start + lineBreak;
126
- }
127
-
128
- function skipQuotedText(source, start, quote) {
129
- let index = start + 1;
130
- while (index < source.length) {
131
- if (source[index] === '\\') {
132
- index += 2;
133
- continue;
134
- }
135
- index += 1;
136
- if (source[index - 1] === quote) break;
137
- }
138
- return index;
139
- }
140
-
141
- function declarationFiles(directory, files = []) {
142
- if (!fs.existsSync(directory)) return files;
143
- for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
144
- if (entry.isSymbolicLink()) continue;
145
- const filePath = path.join(directory, entry.name);
146
- if (entry.isDirectory()) {
147
- declarationFiles(filePath, files);
148
- } else if (entry.isFile() && DECLARATION_FILE_PATTERN.test(entry.name)) {
149
- files.push(filePath);
150
- }
151
- }
152
- return files.sort();
153
- }
154
-
155
- export function stripDeclarationDocTags(source) {
156
- let removedTags = 0;
157
- const code = transformJsDocComments(source, (comment) => {
158
- const { content, removedTags: removed } = stripTagsFromJsDocContent(comment.slice(3, -2));
159
- removedTags += removed;
160
- return content === '' ? '' : `/**${content}*/`;
161
- });
162
- return { code, removedTags };
163
- }
164
-
165
- export function findDeclarationDocTags(source) {
166
- const found = [];
167
- transformJsDocComments(source, (comment) => {
168
- let activeFence = null;
169
- for (const line of splitLines(comment.slice(3, -2))) {
170
- if (!activeFence && categoryTag(line)) found.push(docLineBody(line).trimStart().split(/\s/, 1)[0]);
171
- activeFence = updateFence(line, activeFence);
172
- }
173
- return comment;
174
- });
175
- return found;
176
- }
177
-
178
- export function sanitizeDeclarationDocTags(directory) {
179
- const changedFiles = [];
180
- let removedTags = 0;
181
-
182
- for (const filePath of declarationFiles(directory)) {
183
- const source = fs.readFileSync(filePath, 'utf8');
184
- const result = stripDeclarationDocTags(source);
185
- removedTags += result.removedTags;
186
- if (result.code !== source) {
187
- fs.writeFileSync(filePath, result.code);
188
- changedFiles.push(filePath);
189
- }
190
- }
191
-
192
- const remaining = declarationFiles(directory).flatMap((filePath) => {
193
- const tags = findDeclarationDocTags(fs.readFileSync(filePath, 'utf8'));
194
- return tags.length === 0 ? [] : [{ filePath, tags }];
195
- });
196
- if (remaining.length > 0) {
197
- const details = remaining.map(({ filePath, tags }) => `${filePath}: ${tags.join(', ')}`).join('\n');
198
- throw new Error(`TypeDoc category tags remain in emitted declarations:\n${details}`);
199
- }
200
-
201
- return { changedFiles, removedTags };
202
- }