Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions packages/dts-generator/src/runCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const log = getLogger("@ui5/dts-generator/runCheck");
import esMain from "es-main";

import * as path from "path";
import { promises as fsp } from "fs";
import { promises as fsp, readdirSync, readFileSync } from "fs";
const readdir = fsp.readdir;

import {
Expand Down Expand Up @@ -48,6 +48,53 @@ async function main() {

const dtsFiles = await findFiles(dtsDir, "d.ts");

// TS6 no longer auto-includes @types packages; discover which ones are declared
// as dependencies and walk up from CWD to find where they're installed.
const declaredTypes = new Set<string>();
let dir = process.cwd();
while (true) {
try {
const pkg = JSON.parse(
readFileSync(path.join(dir, "package.json"), "utf8"),
Comment thread
akudev marked this conversation as resolved.
);
for (const deps of [pkg.dependencies, pkg.devDependencies]) {
if (deps) {
for (const name of Object.keys(deps)) {
if (name.startsWith("@types/")) {
declaredTypes.add(name.slice("@types/".length));
}
}
}
}
break;
} catch {
// no package.json at this level
}
const parent = path.dirname(dir);
if (parent === dir) break;
dir = parent;
}

const typeRoots: string[] = [];
const types = new Set<string>();
dir = process.cwd();
while (true) {
const candidate = path.join(dir, "node_modules", "@types");
try {
for (const entry of readdirSync(candidate, { withFileTypes: true })) {
if (entry.isDirectory() && declaredTypes.has(entry.name)) {
types.add(entry.name);
Comment thread
akudev marked this conversation as resolved.
}
}
typeRoots.push(candidate);
} catch {
// doesn't exist at this level
}
const parent = path.dirname(dir);
if (parent === dir) break;
dir = parent;
}

log.verbose(`Running a compile check for ${dtsFiles}`);
const success = checkCompile({
dependencyFiles: dtsFiles,
Expand All @@ -56,8 +103,9 @@ async function main() {
noImplicitAny: true,
strict: true,
target: ScriptTarget.ES2015,
module: ModuleKind.Node16,
moduleResolution: ModuleResolutionKind.Node16,
module: ModuleKind.ESNext,
moduleResolution: ModuleResolutionKind.Bundler,
...(typeRoots.length > 0 && { typeRoots, types: [...types] }),
},
});

Expand Down
3 changes: 2 additions & 1 deletion test-packages/openui5-snapshot-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"@types/qunit": "2.5.4"
},
"scripts": {
"ci": "npm-run-all test",
"ci": "npm-run-all test dts:run-check",
"test": "mocha \"./test/**/*spec.js\"",
"dts:run-check": "node ../../packages/dts-generator/dist/runCheck.js output-dts",
"re-generate": "npm-run-all sdk:* dts:*",
"sdk:download": "node ./lib/download-sdk.js",
"sdk:format": "prettier --write \"input-sdk/*.json\"",
Expand Down
Loading