|
| 1 | +import { |
| 2 | + BuildOptions, |
| 3 | + EntryPoint, |
| 4 | +} from "https://deno.land/x/dnt@0.34.0/mod.ts"; |
| 5 | +import { expandGlobSync } from "https://deno.land/std@0.186.0/fs/expand_glob.ts"; |
| 6 | +import { |
| 7 | + fromFileUrl, |
| 8 | + join, |
| 9 | + parse, |
| 10 | + relative, |
| 11 | +} from "https://deno.land/std@0.186.0/path/mod.ts"; |
| 12 | + |
| 13 | +interface ModuleInfo { |
| 14 | + readonly name: string; |
| 15 | + readonly path: string; |
| 16 | +} |
| 17 | + |
| 18 | +function path2EntryPoint(module: ModuleInfo): EntryPoint { |
| 19 | + const entryPoint: EntryPoint = { |
| 20 | + name: toRelative(module.name), |
| 21 | + path: toRelative(module.path), |
| 22 | + }; |
| 23 | + |
| 24 | + return entryPoint; |
| 25 | +} |
| 26 | + |
| 27 | +function module2TypeVersions(modules: readonly ModuleInfo[]) { |
| 28 | + const entries = modules.map(({ name, path }) => { |
| 29 | + return [name, [join("types", toDts(path))]]; |
| 30 | + }); |
| 31 | + const map = Object.fromEntries(entries); |
| 32 | + |
| 33 | + return { "*": map }; |
| 34 | +} |
| 35 | + |
| 36 | +function toRelative(path: string): string { |
| 37 | + return path.startsWith("./") ? path : "./" + path; |
| 38 | +} |
| 39 | + |
| 40 | +function toDts(path: string): string { |
| 41 | + return path.replace(/.ts$/, ".d.ts"); |
| 42 | +} |
| 43 | + |
| 44 | +const root = fromFileUrl(import.meta.resolve("../")); |
| 45 | +const entries = expandGlobSync("!(_*|*_test.ts)*.ts", { |
| 46 | + includeDirs: false, |
| 47 | + root, |
| 48 | +}); |
| 49 | + |
| 50 | +const modules = [...entries].map(({ path }) => relative(root, path)).map( |
| 51 | + (path) => { |
| 52 | + const parsed = parse(path); |
| 53 | + const name = join(parsed.dir, parsed.name) + ".js"; |
| 54 | + |
| 55 | + return { name, path }; |
| 56 | + }, |
| 57 | +); |
| 58 | + |
| 59 | +const entryPoints = modules.map(path2EntryPoint); |
| 60 | +const typesVersions = module2TypeVersions(modules); |
| 61 | + |
| 62 | +export const makeOptions = (version: string): BuildOptions => ({ |
| 63 | + test: false, |
| 64 | + shims: {}, |
| 65 | + compilerOptions: { |
| 66 | + lib: ["esnext", "dom", "dom.iterable"], |
| 67 | + }, |
| 68 | + typeCheck: false, |
| 69 | + entryPoints, |
| 70 | + outDir: "./npm", |
| 71 | + package: { |
| 72 | + name: "@httpland/request-utils", |
| 73 | + version, |
| 74 | + description: "Request utility collection", |
| 75 | + keywords: [ |
| 76 | + "http", |
| 77 | + "request", |
| 78 | + "fetch-api", |
| 79 | + "utility", |
| 80 | + "utilities", |
| 81 | + "collection", |
| 82 | + ], |
| 83 | + license: "MIT", |
| 84 | + homepage: "https://github.com/httpland/request-utils", |
| 85 | + repository: { |
| 86 | + type: "git", |
| 87 | + url: "git+https://github.com/httpland/request-utils.git", |
| 88 | + }, |
| 89 | + bugs: { |
| 90 | + url: "https://github.com/httpland/request-utils/issues", |
| 91 | + }, |
| 92 | + main: undefined, |
| 93 | + module: undefined, |
| 94 | + types: undefined, |
| 95 | + sideEffects: false, |
| 96 | + type: "module", |
| 97 | + publishConfig: { |
| 98 | + access: "public", |
| 99 | + }, |
| 100 | + typesVersions, |
| 101 | + }, |
| 102 | + packageManager: "pnpm", |
| 103 | + mappings: { |
| 104 | + "https://deno.land/x/headers_utils@1.0.0/equal.ts": { |
| 105 | + name: "@httpland/headers-utils", |
| 106 | + version: "1.0.0", |
| 107 | + subPath: "equal.js", |
| 108 | + }, |
| 109 | + "https://deno.land/x/isx@1.3.1/is_null.ts": { |
| 110 | + name: "@miyauci/isx", |
| 111 | + version: "1.3.1", |
| 112 | + subPath: "is_null.js", |
| 113 | + }, |
| 114 | + }, |
| 115 | +}); |
0 commit comments