mirror: Blazing fast w3c Trace Contexts for any JS runtime
0

Configure Feed

Select the types of activity you want to include in your feed.

chore: conform build scripts

Marais Rossouw (Jun 26, 2026, 1:23 PM +1000) 0225a21e 61de5fbb

+85 -35
+1 -2
.gitignore
··· 1 1 .DS_Store 2 2 node_modules 3 3 /coverage 4 - /npm/* 5 - !/npm/package.json 4 + /npm
+5 -1
deno.json
··· 14 14 "@std/path": "jsr:@std/path@^1", 15 15 "@lukeed/csprng": "npm:@lukeed/csprng@^1" 16 16 }, 17 + "nodeModulesDir": "auto", 18 + "minimumDependencyAge": "P3D", 17 19 "lock": false, 18 20 "lint": { 19 21 "rules": { ··· 21 23 "no-var", 22 24 "prefer-const", 23 25 "no-cond-assign", 24 - "no-inner-declarations" 26 + "no-inner-declarations", 27 + "no-explicit-any", 28 + "no-fallthrough" 25 29 ] 26 30 } 27 31 },
+9 -6
npm/package.json package.json
··· 1 1 { 2 2 "name": "tctx", 3 3 "version": "0.2.5", 4 - "repository": "maraisr/tctx", 5 4 "description": "W3C Trace Contexts made simple", 5 + "repository": { 6 + "type": "git", 7 + "url": "git+https://github.com/maraisr/tctx.git" 8 + }, 6 9 "license": "MIT", 7 10 "author": "Marais Rossouw <me@marais.dev> (https://marais.io)", 11 + "type": "module", 8 12 "keywords": [ 9 13 "tracecontext", 10 14 "traceparent", ··· 12 16 "tracing", 13 17 "w3c" 14 18 ], 15 - "type": "module", 16 19 "sideEffects": false, 17 20 "exports": { 18 21 "./traceparent": { 19 - "types": "./traceparent.d.mts", 20 - "default": "./traceparent.mjs" 22 + "types": "./traceparent.d.ts", 23 + "default": "./traceparent.js" 21 24 }, 22 25 "./tracestate": { 23 - "types": "./tracestate.d.mts", 24 - "default": "./tracestate.mjs" 26 + "types": "./tracestate.d.ts", 27 + "default": "./tracestate.js" 25 28 }, 26 29 "./package.json": "./package.json" 27 30 },
+70 -26
scripts/build.ts
··· 10 10 // $ git push origin main --tags 11 11 // #-> CI builds w/ publish 12 12 13 - import oxc from 'npm:oxc-transform@^0.30'; 14 - import { join, resolve } from '@std/path'; 13 + import { transform } from 'npm:oxc-transform@0.137.0'; 14 + import { minify } from 'npm:oxc-minify@0.137.0'; 15 + import { dirname, join, relative, resolve } from '@std/path'; 15 16 16 17 import denoJson from '../deno.json' with { type: 'json' }; 17 18 18 - const outdir = resolve('npm'); 19 + const root = resolve('.'); 20 + const output = resolve('npm'); 21 + 22 + const Encoder = new TextEncoder(); 23 + 24 + if (exists(output)) { 25 + await Deno.remove(output, { recursive: true }); 26 + } 19 27 20 28 let Inputs; 21 29 if (typeof denoJson.exports === 'string') Inputs = { '.': denoJson.exports }; 22 30 else Inputs = denoJson.exports; 23 31 24 - async function transform(name: string, filename: string) { 32 + async function write(file: string, raw: string, compress?: boolean) { 33 + let dir = dirname(file); 34 + await Deno.mkdir(dir, { 35 + recursive: true, 36 + }); 37 + 38 + await Deno.writeTextFile(file, raw); 39 + 40 + let gz: number; 41 + file = relative(root, file); 42 + console.log('> writing "%s" file', file); 43 + 44 + if (compress) { 45 + let c = await minify(file, raw, { compress: true, mangle: true }); 46 + gz = await gzip(Encoder.encode(c.code)); 47 + } else { 48 + gz = await gzip(Encoder.encode(raw)); 49 + } 50 + 51 + console.log('::notice::%s (%d B)', file, gz); 52 + } 53 + 54 + async function compile(name: string, file: string) { 55 + let raw = await Deno.readTextFile(file); 25 56 if (name === '.') name = 'index'; 26 57 name = name.replace(/^\.\//, ''); 27 58 28 - let entry = resolve(filename); 29 - let source = await Deno.readTextFile(entry); 30 - 31 - let xform = oxc.transform(entry, source, { 59 + let xform = await transform(file, raw, { 60 + target: 'esnext', 61 + sourceType: 'module', 32 62 typescript: { 33 - onlyRemoveTypeImports: true, 63 + rewriteImportExtensions: 'rewrite', 34 64 declaration: { 65 + sourcemap: false, 35 66 stripInternal: true, 36 67 }, 37 68 }, 38 69 }); 39 70 40 - if (xform.errors.length > 0) bail('transform', xform.errors); 71 + if (xform.errors.length > 0) bail('transform', xform.errors.map((err: any) => err.message)); 41 72 42 - let outfile = `${outdir}/${name}.d.mts`; 43 - console.log('> writing "%s" file', outfile); 44 - await Deno.writeTextFile(outfile, xform.declaration!); 73 + file = `${output}/${name}.js`; 74 + await write(file, xform.code, true); 45 75 46 - outfile = `${outdir}/${name}.mjs`; 47 - console.log('> writing "%s" file', outfile); 48 - await Deno.writeTextFile(outfile, xform.code); 76 + if (xform.declaration) { 77 + file = `${output}/${name}.d.ts`; 78 + await write(file, xform.declaration); 79 + } 49 80 } 50 81 51 - console.log('! cleaning "npm" directory'); 52 - await new Deno.Command('git', { 53 - args: ['clean', '-xfd', outdir], 54 - stderr: 'inherit', 55 - }).output(); 56 - 57 - for (let [name, filename] of Object.entries(Inputs)) await transform(name, filename); 82 + for (let [name, src] of Object.entries(Inputs)) await compile(name, src); 58 83 84 + await copy('package.json'); 59 85 await copy('readme.md'); 60 86 await copy('license'); 61 87 62 88 // --- 63 89 64 - function bail(label: string, errors: string[]): never { 90 + function bail(label: string, errors: string[]) { 65 91 console.error('[%s] error(s)\n', label, errors.join('')); 66 92 Deno.exit(1); 67 93 } ··· 77 103 78 104 function copy(file: string) { 79 105 if (exists(file)) { 80 - let outfile = join(outdir, file); 81 - console.log('> writing "%s" file', outfile); 106 + let outfile = join(output, file); 107 + console.log('> writing "%s" file', relative(root, outfile)); 82 108 return Deno.copyFile(file, outfile); 83 109 } 84 110 } 111 + 112 + async function gzip(input: Uint8Array) { 113 + let size = 0; 114 + let stream = new ReadableStream({ 115 + start(ctrl) { 116 + ctrl.enqueue(input); 117 + ctrl.close(); 118 + }, 119 + }).pipeThrough(new CompressionStream('gzip')); 120 + 121 + let reader = stream.getReader(); 122 + 123 + while (true) { 124 + let tmp = await reader.read(); 125 + if (tmp.value) size += tmp.value.length; 126 + if (tmp.done) return size; 127 + } 128 + }