@textmode/tsconfig 0.1.0 → 0.2.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/README.md +70 -0
- package/base.json +2 -14
- package/browser-library.json +3 -0
- package/browser.json +16 -0
- package/dist.json +1 -1
- package/node-tooling.json +8 -0
- package/node.json +13 -0
- package/package.json +36 -5
- package/src/cli/textmode-types.mjs +99 -0
- package/src/internal/project.mjs +266 -0
- package/strict.json +12 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @textmode/tsconfig
|
|
2
|
+
|
|
3
|
+
Shared TypeScript policy and task orchestration for textmode.js libraries and
|
|
4
|
+
Node tooling.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install -D @textmode/tsconfig typescript
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Capability presets
|
|
13
|
+
|
|
14
|
+
| Preset | Use |
|
|
15
|
+
| ----------------------------------------- | ----------------------------------------- |
|
|
16
|
+
| `@textmode/tsconfig/strict.json` | Environment-independent strictness |
|
|
17
|
+
| `@textmode/tsconfig/browser.json` | Browser and bundler projects |
|
|
18
|
+
| `@textmode/tsconfig/browser-library.json` | Published textmode.js browser libraries |
|
|
19
|
+
| `@textmode/tsconfig/node.json` | TypeScript running under Node |
|
|
20
|
+
| `@textmode/tsconfig/node-tooling.json` | Checked JavaScript and TypeScript tooling |
|
|
21
|
+
|
|
22
|
+
`base.json`, `typecheck.json`, `build.json`, and `dist.json` remain as
|
|
23
|
+
compatibility exports for the 0.x migration and should not be used by new
|
|
24
|
+
projects.
|
|
25
|
+
|
|
26
|
+
## Library usage
|
|
27
|
+
|
|
28
|
+
A library owns one authoring config containing its complete editor and test
|
|
29
|
+
scope:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"extends": "@textmode/tsconfig/browser-library.json",
|
|
34
|
+
"include": ["src", "tests", "vite.config.ts", "vitest.config.ts"]
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Task-specific programs are owned by the command:
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
textmode-types check
|
|
42
|
+
textmode-types build
|
|
43
|
+
textmode-types verify
|
|
44
|
+
textmode-types show-config
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- `check` rejects authored TypeScript files that are not claimed by the local
|
|
48
|
+
config, then runs a no-emit project check.
|
|
49
|
+
- `build` emits production declarations from `src` to `dist/types`, excludes
|
|
50
|
+
co-located tests, and disables declaration maps and ambient type packages.
|
|
51
|
+
- `verify` resolves every package export from an isolated consumer with
|
|
52
|
+
`skipLibCheck: false`.
|
|
53
|
+
- `show-config` reports the complete authoring and declaration programs.
|
|
54
|
+
|
|
55
|
+
The command uses the project's installed TypeScript compiler. Paths and aliases
|
|
56
|
+
remain local project data; declaration policy and task scopes are shared.
|
|
57
|
+
|
|
58
|
+
Packages that intentionally annotate implementation exports with `@internal`
|
|
59
|
+
can opt into stripping those declarations without another config file:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"textmodeTypes": {
|
|
64
|
+
"stripInternal": true
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Internal declarations are preserved by default, matching TypeScript's default
|
|
70
|
+
and avoiding accidental API removal in packages that historically emitted them.
|
package/base.json
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"extends": "./browser.json",
|
|
2
3
|
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
4
|
"types": ["vite/client", "node"],
|
|
8
|
-
"
|
|
9
|
-
"allowImportingTsExtensions": true,
|
|
10
|
-
"resolveJsonModule": true,
|
|
11
|
-
"isolatedModules": true,
|
|
12
|
-
"moduleDetection": "force",
|
|
13
|
-
"strict": true,
|
|
14
|
-
"noUnusedLocals": true,
|
|
15
|
-
"noUnusedParameters": true,
|
|
16
|
-
"noFallthroughCasesInSwitch": true,
|
|
17
|
-
"noUncheckedSideEffectImports": true
|
|
5
|
+
"noEmit": false
|
|
18
6
|
}
|
|
19
7
|
}
|
package/browser.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./strict.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"useDefineForClassFields": true,
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
8
|
+
"types": [],
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"moduleDetection": "force",
|
|
14
|
+
"noEmit": true
|
|
15
|
+
}
|
|
16
|
+
}
|
package/dist.json
CHANGED
package/node.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./strict.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"module": "NodeNext",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"moduleResolution": "NodeNext",
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"moduleDetection": "force",
|
|
11
|
+
"noEmit": true
|
|
12
|
+
}
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@textmode/tsconfig",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=20.8.1"
|
|
7
|
+
},
|
|
5
8
|
"exports": {
|
|
9
|
+
"./strict.json": "./strict.json",
|
|
10
|
+
"./browser.json": "./browser.json",
|
|
11
|
+
"./browser-library.json": "./browser-library.json",
|
|
12
|
+
"./node.json": "./node.json",
|
|
13
|
+
"./node-tooling.json": "./node-tooling.json",
|
|
6
14
|
"./base.json": "./base.json",
|
|
7
15
|
"./typecheck.json": "./typecheck.json",
|
|
8
16
|
"./build.json": "./build.json",
|
|
9
17
|
"./dist.json": "./dist.json"
|
|
10
18
|
},
|
|
11
|
-
"
|
|
19
|
+
"bin": {
|
|
20
|
+
"textmode-types": "src/cli/textmode-types.mjs"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"strict.json",
|
|
24
|
+
"browser.json",
|
|
25
|
+
"browser-library.json",
|
|
26
|
+
"node.json",
|
|
27
|
+
"node-tooling.json",
|
|
28
|
+
"base.json",
|
|
29
|
+
"typecheck.json",
|
|
30
|
+
"build.json",
|
|
31
|
+
"dist.json",
|
|
32
|
+
"src",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
12
35
|
"peerDependencies": {
|
|
13
|
-
"typescript": ">=
|
|
36
|
+
"typescript": ">=6 <7"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^26.1.1",
|
|
40
|
+
"typescript": "^6.0.3",
|
|
41
|
+
"vitest": "^4.1.10"
|
|
14
42
|
},
|
|
15
43
|
"scripts": {
|
|
16
|
-
"check": "
|
|
17
|
-
"
|
|
44
|
+
"check": "pnpm run check:format && pnpm run lint && pnpm run test && pnpm run check:package",
|
|
45
|
+
"check:format": "prettier --check .",
|
|
46
|
+
"check:package": "node scripts/check-package.mjs",
|
|
47
|
+
"lint": "node --check src/cli/textmode-types.mjs && node --check src/internal/project.mjs && node --check scripts/check-package.mjs",
|
|
48
|
+
"test": "vitest run"
|
|
18
49
|
}
|
|
19
50
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
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));
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
|
|
7
|
+
const SOURCE_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts']);
|
|
8
|
+
const DISCOVERED_DIRECTORIES = ['src', 'tests', 'typedoc-entrypoints', 'vite-plugins'];
|
|
9
|
+
const ROOT_CONFIG_PATTERN = /^(?:vite|vitest)\.config\.(?:ts|mts|cts)$/;
|
|
10
|
+
|
|
11
|
+
export class ProjectError extends Error {}
|
|
12
|
+
|
|
13
|
+
function readJson(filePath, label) {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
16
|
+
} catch (error) {
|
|
17
|
+
throw new ProjectError(`Could not read ${label} at ${filePath}.`, { cause: error });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function requireFile(filePath, label) {
|
|
22
|
+
if (!fs.existsSync(filePath)) {
|
|
23
|
+
throw new ProjectError(`Missing ${label}: ${filePath}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function resolveProject({ cwd = process.cwd(), project = 'tsconfig.json' } = {}) {
|
|
28
|
+
const root = path.resolve(cwd);
|
|
29
|
+
const manifestPath = path.join(root, 'package.json');
|
|
30
|
+
const configPath = path.resolve(root, project);
|
|
31
|
+
requireFile(manifestPath, 'package.json');
|
|
32
|
+
requireFile(configPath, 'TypeScript config');
|
|
33
|
+
const manifest = readJson(manifestPath, 'package.json');
|
|
34
|
+
if (typeof manifest.name !== 'string' || manifest.name.length === 0) {
|
|
35
|
+
throw new ProjectError(`package.json#name must be a non-empty string in ${manifestPath}.`);
|
|
36
|
+
}
|
|
37
|
+
const textmodeTypes = manifest.textmodeTypes ?? {};
|
|
38
|
+
if (typeof textmodeTypes !== 'object' || Array.isArray(textmodeTypes)) {
|
|
39
|
+
throw new ProjectError(`package.json#textmodeTypes must be an object in ${manifestPath}.`);
|
|
40
|
+
}
|
|
41
|
+
if (textmodeTypes.stripInternal !== undefined && typeof textmodeTypes.stripInternal !== 'boolean') {
|
|
42
|
+
throw new ProjectError(`package.json#textmodeTypes.stripInternal must be a boolean in ${manifestPath}.`);
|
|
43
|
+
}
|
|
44
|
+
const sourceDir = path.join(root, 'src');
|
|
45
|
+
requireFile(sourceDir, 'source directory');
|
|
46
|
+
return {
|
|
47
|
+
root,
|
|
48
|
+
manifest,
|
|
49
|
+
manifestPath,
|
|
50
|
+
configPath,
|
|
51
|
+
sourceDir,
|
|
52
|
+
declarationDir: path.join(root, 'dist', 'types'),
|
|
53
|
+
declarationOptions: {
|
|
54
|
+
stripInternal: textmodeTypes.stripInternal ?? false,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function resolveTypeScript(project) {
|
|
60
|
+
try {
|
|
61
|
+
const require = createRequire(project.manifestPath);
|
|
62
|
+
return require.resolve('typescript/bin/tsc');
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new ProjectError(`Could not resolve TypeScript from ${project.root}.`, { cause: error });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function runTypeScript(project, args, { capture = false } = {}) {
|
|
69
|
+
const result = spawnSync(process.execPath, [resolveTypeScript(project), ...args], {
|
|
70
|
+
cwd: project.root,
|
|
71
|
+
encoding: 'utf8',
|
|
72
|
+
stdio: capture ? 'pipe' : 'inherit',
|
|
73
|
+
});
|
|
74
|
+
if (result.error) {
|
|
75
|
+
throw new ProjectError(`Could not start TypeScript: ${result.error.message}`, { cause: result.error });
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function visitTypeScriptFiles(directory, output) {
|
|
81
|
+
if (!fs.existsSync(directory)) return;
|
|
82
|
+
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
83
|
+
if (entry.isSymbolicLink()) continue;
|
|
84
|
+
const filePath = path.join(directory, entry.name);
|
|
85
|
+
if (entry.isDirectory()) {
|
|
86
|
+
visitTypeScriptFiles(filePath, output);
|
|
87
|
+
} else if (SOURCE_EXTENSIONS.has(path.extname(entry.name))) {
|
|
88
|
+
output.add(path.resolve(filePath));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function discoverAuthoredFiles(project) {
|
|
94
|
+
const files = new Set();
|
|
95
|
+
for (const directory of DISCOVERED_DIRECTORIES) {
|
|
96
|
+
visitTypeScriptFiles(path.join(project.root, directory), files);
|
|
97
|
+
}
|
|
98
|
+
for (const entry of fs.readdirSync(project.root, { withFileTypes: true })) {
|
|
99
|
+
if (entry.isFile() && ROOT_CONFIG_PATTERN.test(entry.name)) {
|
|
100
|
+
files.add(path.join(project.root, entry.name));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return files;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function readEffectiveConfig(project) {
|
|
107
|
+
const result = runTypeScript(project, ['--showConfig', '-p', project.configPath], { capture: true });
|
|
108
|
+
if (result.status !== 0) {
|
|
109
|
+
throw new ProjectError(
|
|
110
|
+
result.stderr.trim() || result.stdout.trim() || 'TypeScript could not resolve the config.'
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
return JSON.parse(result.stdout);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
throw new ProjectError('TypeScript returned invalid JSON from --showConfig.', { cause: error });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function findUnclaimedFiles(project, effectiveConfig = readEffectiveConfig(project)) {
|
|
121
|
+
const claimed = new Set((effectiveConfig.files ?? []).map((file) => path.resolve(project.root, file)));
|
|
122
|
+
return [...discoverAuthoredFiles(project)].filter((file) => !claimed.has(file)).sort();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function checkProject(project) {
|
|
126
|
+
const effectiveConfig = readEffectiveConfig(project);
|
|
127
|
+
const unclaimed = findUnclaimedFiles(project, effectiveConfig);
|
|
128
|
+
if (unclaimed.length > 0) {
|
|
129
|
+
console.error('TypeScript config does not claim every authored TypeScript file:');
|
|
130
|
+
for (const file of unclaimed) {
|
|
131
|
+
console.error(`- ${path.relative(project.root, file)}`);
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
const result = runTypeScript(project, ['--noEmit', '-p', project.configPath]);
|
|
136
|
+
if (result.status === 0) {
|
|
137
|
+
console.log(`TypeScript check passed (${effectiveConfig.files.length} files).`);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function withTemporaryConfig(config, callback) {
|
|
144
|
+
const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'textmode-types-'));
|
|
145
|
+
const configPath = path.join(temporaryDirectory, 'tsconfig.json');
|
|
146
|
+
try {
|
|
147
|
+
fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
148
|
+
return callback(configPath);
|
|
149
|
+
} finally {
|
|
150
|
+
fs.rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function declarationConfig(project) {
|
|
155
|
+
return {
|
|
156
|
+
extends: project.configPath,
|
|
157
|
+
compilerOptions: {
|
|
158
|
+
noEmit: false,
|
|
159
|
+
declaration: true,
|
|
160
|
+
declarationMap: false,
|
|
161
|
+
emitDeclarationOnly: true,
|
|
162
|
+
stripInternal: project.declarationOptions.stripInternal,
|
|
163
|
+
rootDir: project.sourceDir,
|
|
164
|
+
declarationDir: project.declarationDir,
|
|
165
|
+
noEmitOnError: true,
|
|
166
|
+
types: [],
|
|
167
|
+
},
|
|
168
|
+
include: [path.join(project.sourceDir, '**/*')],
|
|
169
|
+
exclude: [
|
|
170
|
+
path.join(project.sourceDir, '**/*.test.ts'),
|
|
171
|
+
path.join(project.sourceDir, '**/*.test.tsx'),
|
|
172
|
+
path.join(project.sourceDir, '**/*.spec.ts'),
|
|
173
|
+
path.join(project.sourceDir, '**/*.spec.tsx'),
|
|
174
|
+
],
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function buildDeclarations(project) {
|
|
179
|
+
const config = declarationConfig(project);
|
|
180
|
+
fs.rmSync(project.declarationDir, { recursive: true, force: true });
|
|
181
|
+
const result = withTemporaryConfig(config, (configPath) => runTypeScript(project, ['-p', configPath]));
|
|
182
|
+
if (result.status === 0) {
|
|
183
|
+
console.log(`Declarations written to ${path.relative(project.root, project.declarationDir)}.`);
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function exportedSpecifiers(manifest) {
|
|
190
|
+
if (!manifest.exports || typeof manifest.exports !== 'object') return [manifest.name];
|
|
191
|
+
return Object.keys(manifest.exports)
|
|
192
|
+
.filter((key) => key === '.' || key.startsWith('./'))
|
|
193
|
+
.map((key) => (key === '.' ? manifest.name : `${manifest.name}/${key.slice(2)}`));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function linkPackage(project, consumerRoot) {
|
|
197
|
+
const packagePath = path.join(consumerRoot, 'node_modules', ...project.manifest.name.split('/'));
|
|
198
|
+
fs.mkdirSync(path.dirname(packagePath), { recursive: true });
|
|
199
|
+
fs.symlinkSync(project.root, packagePath, 'dir');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function verifyDeclarations(project) {
|
|
203
|
+
requireFile(project.declarationDir, 'built declaration directory');
|
|
204
|
+
const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'textmode-types-consumer-'));
|
|
205
|
+
try {
|
|
206
|
+
linkPackage(project, temporaryDirectory);
|
|
207
|
+
const imports = exportedSpecifiers(project.manifest)
|
|
208
|
+
.map((specifier) => `import '${specifier}';`)
|
|
209
|
+
.join('\n');
|
|
210
|
+
fs.writeFileSync(path.join(temporaryDirectory, 'consumer.ts'), `${imports}\n`);
|
|
211
|
+
fs.writeFileSync(
|
|
212
|
+
path.join(temporaryDirectory, 'tsconfig.json'),
|
|
213
|
+
`${JSON.stringify(
|
|
214
|
+
{
|
|
215
|
+
compilerOptions: {
|
|
216
|
+
target: 'ES2022',
|
|
217
|
+
module: 'ESNext',
|
|
218
|
+
lib: ['ES2022', 'DOM', 'DOM.Iterable'],
|
|
219
|
+
moduleResolution: 'bundler',
|
|
220
|
+
strict: true,
|
|
221
|
+
noEmit: true,
|
|
222
|
+
types: [],
|
|
223
|
+
skipLibCheck: false,
|
|
224
|
+
},
|
|
225
|
+
files: ['consumer.ts'],
|
|
226
|
+
},
|
|
227
|
+
null,
|
|
228
|
+
2
|
|
229
|
+
)}\n`
|
|
230
|
+
);
|
|
231
|
+
const consumerProject = {
|
|
232
|
+
...project,
|
|
233
|
+
root: temporaryDirectory,
|
|
234
|
+
manifestPath: project.manifestPath,
|
|
235
|
+
configPath: path.join(temporaryDirectory, 'tsconfig.json'),
|
|
236
|
+
};
|
|
237
|
+
const result = runTypeScript(consumerProject, ['-p', consumerProject.configPath]);
|
|
238
|
+
if (result.status === 0) {
|
|
239
|
+
console.log(`Published declarations resolve for ${exportedSpecifiers(project.manifest).length} export(s).`);
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
return false;
|
|
243
|
+
} finally {
|
|
244
|
+
fs.rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function describeProject(project) {
|
|
249
|
+
const effectiveConfig = readEffectiveConfig(project);
|
|
250
|
+
return {
|
|
251
|
+
projectRoot: project.root,
|
|
252
|
+
packageName: project.manifest.name,
|
|
253
|
+
config: path.relative(project.root, project.configPath),
|
|
254
|
+
files: effectiveConfig.files.map((file) => path.relative(project.root, path.resolve(project.root, file))),
|
|
255
|
+
unclaimedFiles: findUnclaimedFiles(project, effectiveConfig).map((file) => path.relative(project.root, file)),
|
|
256
|
+
compilerOptions: effectiveConfig.compilerOptions,
|
|
257
|
+
declarations: {
|
|
258
|
+
sourceDir: path.relative(project.root, project.sourceDir),
|
|
259
|
+
declarationDir: path.relative(project.root, project.declarationDir),
|
|
260
|
+
excludedTests: true,
|
|
261
|
+
declarationMap: false,
|
|
262
|
+
stripInternal: project.declarationOptions.stripInternal,
|
|
263
|
+
types: [],
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
}
|
package/strict.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"strict": true,
|
|
4
|
+
"noUnusedLocals": true,
|
|
5
|
+
"noUnusedParameters": true,
|
|
6
|
+
"noFallthroughCasesInSwitch": true,
|
|
7
|
+
"noUncheckedSideEffectImports": true,
|
|
8
|
+
"noImplicitOverride": true,
|
|
9
|
+
"verbatimModuleSyntax": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true
|
|
11
|
+
}
|
|
12
|
+
}
|