| author | |
| committer | |
| log | e41ee359a2b3a22fe11104311555852d3f661d41 |
| tree | cbea9c0801f4eceedaf4a3690ef1a162f68d4ca1 |
| parent | 692bc30864b34cdc3fe5297a7186605fbc73337f |
| signature | Commit is signed but in an unrecognized format. |
10 files changed, 59 insertions(+), 250 deletions(-)
lib/bytes.ts+1-1| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | export function eql<T extends ArrayBufferView & { [n: number]: number }>( |
| 2 | 2 | a: T, |
| 3 | 3 | b: T, |
| 4 | ) { | |
| 4 | ): boolean { | |
| 5 | 5 | const l = a.byteLength; |
| 6 | 6 | if (l !== b.byteLength) return false; |
| 7 | 7 | for (let i = 0; i < l; i++) if (a[i] !== b[i]) return false; |
lib/deno.json+5-2| ... | ... | @@ -6,9 +6,10 @@ |
| 6 | 6 | "exports": { |
| 7 | 7 | "./assert.ts": "./assert.ts", |
| 8 | 8 | "./async.ts": "./async.ts", |
| 9 | "./bytes.ts": "./bytes.ts", | |
| 9 | 10 | "./error.ts": "./error.ts", |
| 11 | "./Events.ts": "./Events.ts", | |
| 10 | 12 | "./log.ts": "./log.ts", |
| 11 | "./log/headless.ts": "./log/headless.ts", | |
| 12 | 13 | "./log/stack.ts": "./log/stack.ts", |
| 13 | 14 | "./Lru.ts": "./Lru.ts", |
| 14 | 15 | "./mime.ts": "./mime.ts", |
| ... | ... | @@ -18,10 +19,12 @@ |
| 18 | 19 | "./render.ts": "./render.ts", |
| 19 | 20 | "./render/jsx-runtime.ts": "./render/jsx-runtime.ts", |
| 20 | 21 | "./render/meta.ts": "./render/meta.ts", |
| 22 | "./stream.ts": "./stream.ts", | |
| 21 | 23 | "./string.ts": "./string.ts", |
| 22 | 24 | "./string/ansi.ts": "./string/ansi.ts", |
| 23 | 25 | "./subprocess.ts": "./subprocess.ts", |
| 24 | 26 | "./subprocess/ffmpeg.ts": "./subprocess/ffmpeg.ts", |
| 27 | "./testing.ts": "./testing.ts", | |
| 25 | 28 | "./ts.ts": "./ts.ts" |
| 26 | 29 | }, |
| 27 | 30 | "compilerOptions": { |
| ... | ... | @@ -36,4 +39,4 @@ |
| 36 | 39 | "readme.npm.md", |
| 37 | 40 | "deno.lock" |
| 38 | 41 | ] |
| 39 | } | |
| 42 | } | |
| \ No newline at end of file |
lib/log.ts+4-4| ... | ... | @@ -140,7 +140,7 @@ export function replaceGlobalFormatFunction( |
| 140 | 140 | globalMessageFormatFunction = format; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | export function formatMessage(msg: Message, colors: boolean) { | |
| 143 | export function formatMessage(msg: Message, colors: boolean): string { | |
| 144 | 144 | return globalMessageFormatFunction(msg, colors); |
| 145 | 145 | } |
| 146 | 146 | |
| ... | ... | @@ -187,7 +187,7 @@ export function getDrawLock(): ts.Dispose { |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | export function headlessScope(dispatch: DispatchFunction): Scope { |
| 190 | return new Scope(dispatch); | |
| 190 | return new ScopeImpl(dispatch); | |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** see {@linkcode startWidget} */ |
| ... | ... | @@ -500,7 +500,7 @@ let withinDispatch = false; |
| 500 | 500 | let withinStackCapture = false; |
| 501 | 501 | |
| 502 | 502 | /** this class is an implementation detail */ |
| 503 | const Scope = class Scope implements Scope { | |
| 503 | const ScopeImpl = class Scope implements Scope { | |
| 504 | 504 | name: string | undefined; |
| 505 | 505 | // TODO: this abstraction implementation has low performance. making every |
| 506 | 506 | // scope define it's own dispatch is needed to correctly implement `tee`. |
| ... | ... | @@ -669,7 +669,7 @@ const globalLog = /* @__PURE__ */ (() => { |
| 669 | 669 | } |
| 670 | 670 | console[level](...args); |
| 671 | 671 | }; |
| 672 | return new Scope(globalOutputFunction); | |
| 672 | return new ScopeImpl(globalOutputFunction); | |
| 673 | 673 | })(); |
| 674 | 674 | |
| 675 | 675 | export type DispatchFunction = (message: Message) => void; |
lib/progress.ts+18-8| ... | ... | @@ -182,17 +182,21 @@ export interface StartOptions { |
| 182 | 182 | * specify how `value` and `total` is formed into text. |
| 183 | 183 | * this has some discoverable presets on `StartOptions.units`. |
| 184 | 184 | */ |
| 185 | valueFormatter?: (value: number, total: number | null) => string; | |
| 185 | valueFormatter?: ValueFormatter; | |
| 186 | 186 | /** pre-fill the list of log messages */ |
| 187 | 187 | messages?: log.Message[]; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | export type ValueFormatter = (value: number, total: number | null) => string; | |
| 191 | ||
| 190 | 192 | /** |
| 191 | 193 | * creates a function to use as a `Node.valueFormatter` by using a single |
| 192 | 194 | * number formatter, and then joining the node's value and total with a "/", |
| 193 | 195 | * but leaving it out if there is no total. |
| 194 | 196 | */ |
| 195 | export function slashValueFormatter(fmtNumber: (value: number) => string) { | |
| 197 | export function slashValueFormatter( | |
| 198 | fmtNumber: (value: number) => string, | |
| 199 | ): ValueFormatter { | |
| 196 | 200 | return (value: number, total: number | null) => |
| 197 | 201 | value > 0 |
| 198 | 202 | ? fmtNumber(value) + |
| ... | ... | @@ -201,15 +205,18 @@ export function slashValueFormatter(fmtNumber: (value: number) => string) { |
| 201 | 205 | } |
| 202 | 206 | |
| 203 | 207 | /** the formatter used when passing `units: "count"` to {@linkcode start} */ |
| 204 | export const defaultValueFormatter = /* @__PURE__ */ | |
| 208 | export const defaultValueFormatter: ValueFormatter = /* @__PURE__ */ | |
| 205 | 209 | slashValueFormatter(String); |
| 206 | 210 | |
| 207 | 211 | /** the formatter used when passing `units: "bytes"` to {@linkcode start} */ |
| 208 | export const bytesValueFormatter = /* @__PURE__ */ | |
| 212 | export const bytesValueFormatter: ValueFormatter = /* @__PURE__ */ | |
| 209 | 213 | slashValueFormatter(string.formatByteSize); |
| 210 | 214 | |
| 211 | 215 | /** the formatter used when passing `units: "percent"` to {@linkcode start} */ |
| 212 | export function percentValueFormatter(value: number, total: number | null) { | |
| 216 | export function percentValueFormatter( | |
| 217 | value: number, | |
| 218 | total: number | null, | |
| 219 | ): string { | |
| 213 | 220 | if (total != null && total > 0) { |
| 214 | 221 | value /= total; |
| 215 | 222 | } |
| ... | ... | @@ -1724,14 +1731,17 @@ export const global: Ref = |
| 1724 | 1731 | * for testing. not covered by semver |
| 1725 | 1732 | * @internal |
| 1726 | 1733 | */ |
| 1727 | const uncastInternals = /** @__PURE__ */ (() => ({ | |
| 1734 | export const internals: { | |
| 1735 | readStreamEvent: typeof readStreamEvent; | |
| 1736 | writeStreamEvent: typeof writeStreamEvent; | |
| 1737 | kNode: symbol; | |
| 1738 | EncodedKey: EncodedKey; | |
| 1739 | } = /** @__PURE__ */ (() => ({ | |
| 1728 | 1740 | readStreamEvent, |
| 1729 | 1741 | writeStreamEvent, |
| 1730 | 1742 | kNode: kNode as unknown as symbol, |
| 1731 | newNode, | |
| 1732 | 1743 | EncodedKey: 0 as EncodedKey, |
| 1733 | 1744 | }))(); |
| 1734 | export const internals: typeof uncastInternals = uncastInternals; | |
| 1735 | 1745 | |
| 1736 | 1746 | import * as ansi from "./string/ansi.ts"; |
| 1737 | 1747 | import * as async from "./async.ts"; |
lib/stream.ts+16-25| ... | ... | @@ -244,7 +244,7 @@ export class BufferedReader implements Disposable { |
| 244 | 244 | this.#reader = reader; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | get available() { | |
| 247 | get available(): number { | |
| 248 | 248 | return this.#available; |
| 249 | 249 | } |
| 250 | 250 | |
| ... | ... | @@ -352,68 +352,68 @@ export class BufferedReader implements Disposable { |
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | async u8() { | |
| 355 | async u8(): Promise<number> { | |
| 356 | 356 | const int = await this.peekU8(); |
| 357 | 357 | this.#shiftOffset(1); |
| 358 | 358 | return int; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | async peekU8() { | |
| 361 | async peekU8(): Promise<number> { | |
| 362 | 362 | await this.ensureAvailable(1); |
| 363 | 363 | return UNWRAP(UNWRAP(this.#buffer[0])[this.#offset]); |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | async i8() { | |
| 366 | async i8(): Promise<number> { | |
| 367 | 367 | await this.ensureAvailable(2); |
| 368 | 368 | return this.#collectLimitedView(1).getInt8(0); |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | async u16() { | |
| 371 | async u16(): Promise<number> { | |
| 372 | 372 | await this.ensureAvailable(2); |
| 373 | 373 | return this.#collectLimitedView(2).getUint16(0, true); |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | async i16() { | |
| 376 | async i16(): Promise<number> { | |
| 377 | 377 | await this.ensureAvailable(2); |
| 378 | 378 | return this.#collectLimitedView(2).getInt16(0, true); |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | async u32() { | |
| 381 | async u32(): Promise<number> { | |
| 382 | 382 | await this.ensureAvailable(4); |
| 383 | 383 | return this.#collectLimitedView(4).getUint32(0, true); |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | async i32() { | |
| 386 | async i32(): Promise<number> { | |
| 387 | 387 | await this.ensureAvailable(4); |
| 388 | 388 | return this.#collectLimitedView(4).getInt32(0, true); |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | async u64() { | |
| 391 | async u64(): Promise<bigint> { | |
| 392 | 392 | await this.ensureAvailable(8); |
| 393 | 393 | return this.#collectLimitedView(8).getBigUint64(0, true); |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | async i64() { | |
| 396 | async i64(): Promise<bigint> { | |
| 397 | 397 | await this.ensureAvailable(8); |
| 398 | 398 | return this.#collectLimitedView(8).getBigInt64(0, true); |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | async f16() { | |
| 401 | async f16(): Promise<number> { | |
| 402 | 402 | await this.ensureAvailable(2); |
| 403 | 403 | return this.#collectLimitedView(2).getFloat16(0, true); |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | async f32() { | |
| 406 | async f32(): Promise<number> { | |
| 407 | 407 | await this.ensureAvailable(4); |
| 408 | 408 | return this.#collectLimitedView(4).getFloat32(0, true); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | async f64() { | |
| 411 | async f64(): Promise<number> { | |
| 412 | 412 | await this.ensureAvailable(8); |
| 413 | 413 | return this.#collectLimitedView(8).getFloat64(0, true); |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | async varUint() { | |
| 416 | async varUint(): Promise<number> { | |
| 417 | 417 | let result = 0; |
| 418 | 418 | let shift = 1; |
| 419 | 419 | let byte; |
| ... | ... | @@ -425,7 +425,7 @@ export class BufferedReader implements Disposable { |
| 425 | 425 | return result; |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | async stringWithLength() { | |
| 428 | async stringWithLength(): Promise<string> { | |
| 429 | 429 | const len = await this.varUint(); |
| 430 | 430 | return string.decodeUtf8(await this.readExactly(len)); |
| 431 | 431 | } |
| ... | ... | @@ -441,7 +441,7 @@ export class BufferedReader implements Disposable { |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | [Symbol.dispose]() { |
| 444 | return this.releaseLock(); | |
| 444 | this.releaseLock(); | |
| 445 | 445 | } |
| 446 | 446 | } |
| 447 | 447 | |
| ... | ... | @@ -472,14 +472,5 @@ export function readWritePair(): [ |
| 472 | 472 | return [reader, unbuffered]; |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | export function fromChunks<T>(chunks: T[]) { | |
| 476 | return new ReadableStream<T>({ | |
| 477 | start(c) { | |
| 478 | for (const chunk of chunks) c.enqueue(chunk); | |
| 479 | c.close(); | |
| 480 | }, | |
| 481 | }); | |
| 482 | } | |
| 483 | ||
| 484 | 475 | import * as string from "./string.ts"; |
| 485 | 476 | import { ASSERT, UNWRAP } from "./assert.ts"; |
lib/string.ts+3-3| ... | ... | @@ -43,7 +43,7 @@ export function decodeUtf8(input: Uint8Array): string { |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | const byteUnits = "kMGTPEZYRQ"; // kilo, mega, giga, etc |
| 46 | export function formatByteSize(bytes: number) { | |
| 46 | export function formatByteSize(bytes: number): string { | |
| 47 | 47 | if (!Number.isFinite(bytes)) return bytes.toString(); |
| 48 | 48 | let prefix = ""; |
| 49 | 49 | if (bytes < 0) bytes = -bytes, prefix = "-"; |
| ... | ... | @@ -60,7 +60,7 @@ export function formatByteSize(bytes: number) { |
| 60 | 60 | byteUnits.charAt(unit - 1) + "B"; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | export function formatBinaryByteSize(bytes: number) { | |
| 63 | export function formatBinaryByteSize(bytes: number): string { | |
| 64 | 64 | let prefix = ""; |
| 65 | 65 | if (bytes < 0) bytes = -bytes, prefix = "-"; |
| 66 | 66 | if (bytes < 1024) return (Math.round(bytes * 100) / 100) + "B"; |
| ... | ... | @@ -74,7 +74,7 @@ export function formatBinaryByteSize(bytes: number) { |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // TODO: |
| 77 | export function formatDurationLetters(seconds: number) { | |
| 77 | export function formatDurationLetters(seconds: number): string { | |
| 78 | 78 | const minutes = Math.floor(seconds / 60); |
| 79 | 79 | const remainingSeconds = seconds % 60; |
| 80 | 80 | if (minutes < 1) return `${remainingSeconds}s`; |
lib/string/ansi.ts+2-1| ... | ... | @@ -322,7 +322,8 @@ const leadingNonPrintingRegex = |
| 322 | 322 | /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Mark}\p{Surrogate}]+/v; |
| 323 | 323 | const rgiEmojiRegex = /^\p{RGI_Emoji}$/v; |
| 324 | 324 | |
| 325 | export function strip(text: string) { | |
| 325 | /** remove all ansi escape sequences */ | |
| 326 | export function strip(text: string): string { | |
| 326 | 327 | return text.replace(ansiEscapes, ""); |
| 327 | 328 | } |
| 328 | 329 |
lib/subprocess/ffmpeg.ts+1-1| ... | ... | @@ -191,10 +191,10 @@ export class Parse { |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | import * as child_process from "node:child_process"; |
| 194 | import * as subprocess from "lib/subprocess.ts"; | |
| 195 | 194 | import * as readline from "node:readline"; |
| 196 | 195 | import * as process from "node:process"; |
| 197 | 196 | import events from "node:events"; |
| 198 | 197 | import * as path from "node:path"; |
| 198 | import * as subprocess from "../subprocess.ts"; | |
| 199 | 199 | import type * as progress from "../progress.ts"; |
| 200 | 200 | import * as string from "../string.ts"; |
lib/testing.ts+7-7| ... | ... | @@ -118,7 +118,7 @@ export class FakeTimers { |
| 118 | 118 | }> = []; |
| 119 | 119 | waitTime = 0; |
| 120 | 120 | |
| 121 | now = () => { | |
| 121 | now: () => number = () => { | |
| 122 | 122 | return this.time; |
| 123 | 123 | }; |
| 124 | 124 | delay: typeof async.delay = (ms) => { |
| ... | ... | @@ -174,7 +174,7 @@ export class MockScreen implements Disposable, log.HeadlessWidgetHost { |
| 174 | 174 | delay: log.HeadlessWidgetHost["delay"]; |
| 175 | 175 | now: log.HeadlessWidgetHost["now"]; |
| 176 | 176 | |
| 177 | static sync(text: string[]) { | |
| 177 | static sync(text: string[]): string { | |
| 178 | 178 | return ansi.syncStart + text.join("") + ansi.syncEnd; |
| 179 | 179 | } |
| 180 | 180 | |
| ... | ... | @@ -271,8 +271,8 @@ export class MockScreen implements Disposable, log.HeadlessWidgetHost { |
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | import * as ansi from "lib/string/ansi.ts"; | |
| 275 | import { ASSERT, UNWRAP } from "lib/assert.ts"; | |
| 276 | import * as log from "lib/log.ts"; | |
| 277 | import * as async from "lib/async.ts"; | |
| 278 | import * as stack from "lib/log/stack.ts"; | |
| 274 | import * as ansi from "./string/ansi.ts"; | |
| 275 | import { ASSERT, UNWRAP } from "./assert.ts"; | |
| 276 | import * as log from "./log.ts"; | |
| 277 | import * as async from "./async.ts"; | |
| 278 | import * as stack from "./log/stack.ts"; |
src/bin/package-lib.ts+2-198| ... | ... | @@ -20,207 +20,11 @@ export async function updateJsrPackageExportsToAll( |
| 20 | 20 | await fs.writeFile(manifestPath, JSON.stringify(deno, null, 2)); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | export async function transpileForNpm( | |
| 24 | absPath: string, | |
| 25 | p: progress.Ref, | |
| 26 | packageJson: Record<string, unknown>, | |
| 27 | ) { | |
| 28 | using node = p.start("transpile into js for npm"); | |
| 29 | const manifestPath = path.join(absPath, "deno.json"); | |
| 30 | const deno = JSON.parse( | |
| 31 | await fs.readFile(manifestPath, "utf-8"), | |
| 32 | ); | |
| 33 | const distPath = path.join(absPath, "dist-npm"); | |
| 34 | await fs.rm(distPath, { recursive: true, force: true }); | |
| 35 | await fs.mkdir(distPath, { recursive: true }); | |
| 36 | ||
| 37 | const files: string[] = []; | |
| 38 | const exports: Record<string, string> = {}; | |
| 39 | for (const subPath of await fs.readdir(absPath, { recursive: true })) { | |
| 40 | if (!subPath.match(/\.tsx?$/)) continue; | |
| 41 | if (subPath.startsWith("dist")) continue; | |
| 42 | files.push(subPath); | |
| 43 | } | |
| 44 | const tsFiles: string[] = []; | |
| 45 | for (const subPath of files) { | |
| 46 | using _ = node.start(subPath); | |
| 47 | const targetSubPath = subPath.replace(/\.tsx?$/, ".js"); | |
| 48 | if (!subPath.match(/\.(test|sample)\.tsx?$/)) { | |
| 49 | exports["./" + subPath] = "./" + targetSubPath; | |
| 50 | } | |
| 51 | const out = path.join(distPath, subPath); | |
| 52 | await fs.mkdir(path.dirname(out), { recursive: true }); | |
| 53 | tsFiles.push(out); | |
| 54 | ||
| 55 | let code = await fs.readFile(path.join(absPath, subPath), "utf-8"); | |
| 56 | code = code.replace( | |
| 57 | / from "lib\/([^"]+)"/g, | |
| 58 | (_, src) => { | |
| 59 | return ' from "./' + path.relative( | |
| 60 | path.dirname(subPath), | |
| 61 | src.replace(/\.tsx?$/, ".js"), | |
| 62 | ) + '"'; | |
| 63 | }, | |
| 64 | ); | |
| 65 | await fs.writeFile(out, code); | |
| 66 | } | |
| 67 | await subprocess.spawnAndWait({ | |
| 68 | cmd: [ | |
| 69 | "npx", | |
| 70 | "tsc", | |
| 71 | "--outdir", | |
| 72 | distPath, | |
| 73 | "--sourceMap", | |
| 74 | "--declarationMap", | |
| 75 | "--declaration", | |
| 76 | "--module", | |
| 77 | "nodenext", | |
| 78 | "--lib", | |
| 79 | "esnext", | |
| 80 | "--skipLibCheck", | |
| 81 | "--jsx", | |
| 82 | "react-jsx", | |
| 83 | "--jsxImportSource", | |
| 84 | "./lib/dist-npm/render", | |
| 85 | "--target", | |
| 86 | "esnext", | |
| 87 | "--isolatedModules", | |
| 88 | "--verbatimModuleSyntax", | |
| 89 | "--allowSyntheticDefaultImports", | |
| 90 | "--moduleResolution", | |
| 91 | "nodenext", | |
| 92 | ...tsFiles, | |
| 93 | ], | |
| 94 | }); | |
| 95 | await fs.writeFile( | |
| 96 | path.join(distPath, "readme.md"), | |
| 97 | (await fs.readFile(path.join(absPath, "readme.md"), "utf-8")).replace( | |
| 98 | "<!--%npm%-->\n", | |
| 99 | await fs.readFile(path.join(absPath, "readme.npm.md"), "utf-8"), | |
| 100 | ), | |
| 101 | ).catch((e) => { | |
| 102 | if (e.code !== "ENOENT") throw e; | |
| 103 | }); | |
| 104 | await fs.cp( | |
| 105 | path.join(absPath, "readme.changes.md"), | |
| 106 | path.join(distPath, "readme.changes.md"), | |
| 107 | ).catch((e) => { | |
| 108 | if (e.code !== "ENOENT") throw e; | |
| 109 | }); | |
| 110 | const { name, description, ...rest } = packageJson; | |
| 111 | await fs.writeFile( | |
| 112 | path.join(distPath, "package.json"), | |
| 113 | JSON.stringify( | |
| 114 | { | |
| 115 | name, | |
| 116 | description, | |
| 117 | version: deno.version, | |
| 118 | type: "module", | |
| 119 | exports, | |
| 120 | ...rest, | |
| 121 | }, | |
| 122 | null, | |
| 123 | 2, | |
| 124 | ), | |
| 125 | ); | |
| 126 | } | |
| 127 | ||
| 128 | // TODO: failed experiment | |
| 129 | // | |
| 130 | // export async function transpileForNpm( | |
| 131 | // absPath: string, | |
| 132 | // p: progress.Ref, | |
| 133 | // packageJson: Record<string, unknown>, | |
| 134 | // ) { | |
| 135 | // const { transpileFile } = await import("ts-to-jsdoc") as TsToJsdoc; | |
| 136 | // | |
| 137 | // using node = p.start("transpile into jsdoc for npm"); | |
| 138 | // const manifestPath = path.join(absPath, "deno.json"); | |
| 139 | // const deno = JSON.parse( | |
| 140 | // await fs.readFile(manifestPath, "utf-8"), | |
| 141 | // ); | |
| 142 | // const distPath = path.join(absPath, "dist-npm"); | |
| 143 | // await fs.rm(distPath, { recursive: true, force: true }); | |
| 144 | // await fs.mkdir(distPath, { recursive: true }); | |
| 145 | // | |
| 146 | // const files: string[] = []; | |
| 147 | // const exports: Record<string, string> = {}; | |
| 148 | // for (const subPath of await fs.readdir(absPath, { recursive: true })) { | |
| 149 | // if (!subPath.match(/\.tsx?$/)) continue; | |
| 150 | // if (subPath.startsWith("dist")) continue; | |
| 151 | // files.push(subPath); | |
| 152 | // } | |
| 153 | // node.estimate = Object.keys(exports).length; | |
| 154 | // for (const subPath of files) { | |
| 155 | // using _ = node.start(subPath); | |
| 156 | // const targetSubPath = subPath.replace(/\.tsx?$/, ".js"); | |
| 157 | // if (!subPath.match(/\.(test|sample)\.tsx?$/)) { | |
| 158 | // exports["./" + subPath] = "./" + targetSubPath; | |
| 159 | // } | |
| 160 | // | |
| 161 | // let code = transpileFile({ | |
| 162 | // code: await fs.readFile(path.join(absPath, subPath), "utf-8"), | |
| 163 | // }); | |
| 164 | // code = code.replace( | |
| 165 | // / from "lib\/([^"]+)"/g, | |
| 166 | // (_, src) => { | |
| 167 | // return ' from "./' + path.relative( | |
| 168 | // path.dirname(subPath), | |
| 169 | // src.replace(/\.tsx?$/, ".js"), | |
| 170 | // ) + '"'; | |
| 171 | // }, | |
| 172 | // ); | |
| 173 | // if (packageJson.homepage) { | |
| 174 | // code = | |
| 175 | // "// This file is transpiled from TypeScript from paper clover's sitegen\n" + | |
| 176 | // "// " + packageJson.homepage + "/" + subPath + "\n" + | |
| 177 | // code; | |
| 178 | // } | |
| 179 | // const out = path.join(distPath, targetSubPath); | |
| 180 | // await fs.mkdir(path.dirname(out), { recursive: true }); | |
| 181 | // await fs.writeFile(out, code); | |
| 182 | // node.value += 1; | |
| 183 | // } | |
| 184 | // await fs.cp( | |
| 185 | // path.join(absPath, "readme.npm.md"), | |
| 186 | // path.join(distPath, "readme.md"), | |
| 187 | // ).catch((e) => { | |
| 188 | // if (e.code !== "ENOENT") throw e; | |
| 189 | // }); | |
| 190 | // await fs.cp( | |
| 191 | // path.join(absPath, "readme.changes.md"), | |
| 192 | // path.join(distPath, "readme.changes.md"), | |
| 193 | // ).catch((e) => { | |
| 194 | // if (e.code !== "ENOENT") throw e; | |
| 195 | // }); | |
| 196 | // const { name, description, ...rest } = packageJson; | |
| 197 | // await fs.writeFile( | |
| 198 | // path.join(distPath, "package.json"), | |
| 199 | // JSON.stringify({ | |
| 200 | // name, | |
| 201 | // description, | |
| 202 | // version: deno.version, | |
| 203 | // type: "module", | |
| 204 | // ...rest, | |
| 205 | // }), | |
| 206 | // ); | |
| 207 | // } | |
| 208 | // | |
| 209 | export function main() { | |
| 23 | export async function main() { | |
| 210 | 24 | const main = path.resolve("lib"); |
| 211 | updateJsrPackageExportsToAll(main, progress) | |
| 212 | .then(() => | |
| 213 | transpileForNpm(main, progress, { | |
| 214 | name: "@paperclover/lib", | |
| 215 | description: "high quality typescript libraries", | |
| 216 | homepage: | |
| 217 | "https://git.paperclover.net/clo/sitegen/src/branch/master/lib", | |
| 218 | }) | |
| 219 | ); | |
| 25 | await updateJsrPackageExportsToAll(main, progress); | |
| 220 | 26 | } |
| 221 | 27 | |
| 222 | 28 | import * as progress from "lib/progress.ts"; |
| 223 | 29 | import * as path from "node:path"; |
| 224 | 30 | import * as fs from "node:fs/promises"; |
| 225 | import * as subprocess from "lib/subprocess.ts"; | |
| 226 | import { UNWRAP } from "lib/assert.ts"; |