Skip to content

Commit

Permalink
Generate typesVersions for compat, plus types and entryPoints
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderOMara committed Nov 19, 2024
1 parent afbb37d commit d8678dd
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions scripts/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ const keywords = readme.map((s) => s.match(/^\!\[(.*)\]\((.*)\)$/))
.filter((m) => m && m[2].startsWith('https://img.shields.io/badge/'))
.map((m) => m![1]);

const entryPoints = [];
let types: string | undefined;
const typed: { [s: string]: string[] } = {};
for (const [name, path] of Object.entries(denoJson.exports)) {
const d = path.replace(/^(\.\/)?(.*)(\.[^.]+)$/i, './esm/$2.d$3');
if (name === '.') {
entryPoints.unshift(path);
types = d;
} else {
entryPoints.push({ name, path });
typed[name.replace(/^\.\//, '')] = [d];
}
}

// Monkey patch for broken JSR mappings, also add version info.
const replace = new Map<string, string>();
const jsrs = Object.keys(mappings).filter((s) => s.startsWith('jsr:'));
Expand Down Expand Up @@ -77,8 +91,7 @@ await emptyDir(outDir);
await build({
test: env === 'dev',
importMap: 'deno.json',
entryPoints: Object.entries(denoJson.exports)
.map(([name, path]) => name === '.' ? path : { name, path }),
entryPoints,
outDir,
shims: {
deno: env === 'dev' ? 'dev' : false,
Expand All @@ -91,6 +104,8 @@ await build({
keywords,
license: denoJson.license,
sideEffects: false,
types,
...(typed ? { typesVersions: { '*': typed } } : {}),
...(env !== 'prod' ? { private: true } : {}),
...(GITHUB_REPOSITORY
? {
Expand Down

0 comments on commit d8678dd

Please sign in to comment.