import * as path from "https://deno.land/std@0.134.0/path/mod.ts";
const cwd = path.resolve(path.fromFileUrl(import.meta.url), "..");
async function rewrite(x: { path: string; prepend?: string; replacements: [string, string][];}) { const basename = path.basename(x.path); console.log(">> Rewriting", basename);
let content = ( x.prepend ? `${x.prepend}\n` : "" ) + await Deno.readTextFile(x.path);
for (const r of x.replacements) { content = content.replace(r[0], r[1]); } await Deno.writeTextFile(x.path, content);}
rewrite({ path: path.resolve(cwd, "../dist/hooks.d.ts"), replacements: [ [ `import { PreactContext, Ref as PreactRef } from '../..';`, `import { PreactContext, Ref as PreactRef } from "./preact.d.ts";`, ], ],});
rewrite({ path: path.resolve(cwd, "../dist/hooks.module.js"), prepend: `/// <reference types="./hooks.d.ts" />`, replacements: [ [ `import{options as n}from"preact"`, `import{options as n}from"./preact.module.js"`, ], ],});
rewrite({ path: path.resolve(cwd, "../dist/jsx.d.ts"), replacements: [ [ `import {\n\tClassAttributes,\n\tComponent,\n\tPreactDOMAttributes,\n\tVNode\n} from './index';`, `import {\n\tClassAttributes,\n\tComponent,\n\tPreactDOMAttributes,\n\tVNode\n} from './preact.d.ts';`, ], ],});
rewrite({ path: path.resolve(cwd, "../dist/jsxRuntime.d.ts"), replacements: [ [ `export { Fragment } from '../../';`, `export { Fragment } from './preact.d.ts';`, ], [ `import {\n\tComponentType,\n\tComponentChild,\n\tComponentChildren,\n\tVNode,\n\tAttributes\n} from '../../';`, `import {\n\tComponentType,\n\tComponentChild,\n\tComponentChildren,\n\tVNode,\n\tAttributes\n} from './preact.d.ts';`, ], [ `import { JSXInternal } from '../../src/jsx';`, `import { JSXInternal } from './jsx.d.ts';`, ], ],});
rewrite({ path: path.resolve(cwd, "../dist/jsxRuntime.module.js"), prepend: `/// <reference types="./jsxRuntime.d.ts" />`, replacements: [ [ `import{options as r,Fragment as _}from"preact";export{Fragment}from"preact";`, `import{options as r,Fragment as _}from"./preact.module.js";export{Fragment}from"./preact.module.js";`, ], ],});
rewrite({ path: path.resolve(cwd, "../dist/preact.d.ts"), replacements: [ [ `import { JSXInternal } from './jsx';`, `import { JSXInternal } from './jsx.d.ts';`, ], ],});
rewrite({ path: path.resolve(cwd, "../dist/preact.module.js"), replacements: [], prepend: `/// <reference types="./preact.d.ts" />`,});
rewrite({ path: path.resolve(cwd, "../dist/LICENSE"), replacements: [ [ `, 2022 Connor Logan`, ``, ], ],});
console.log(">> Done: rewrite.ts");