char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
f4a0f5b
main
1import { execFileSync } from "node:child_process" ; 2import { mkdtemp , readFile , rm } from "node:fs/promises" ; 3import { createRequire } from "node:module" ; 4import { tmpdir } from "node:os" ; 5import path from "node:path" ; 6import { pathToFileURL } from "node:url" ; 7 8const vendor = import . meta. dirname ; 9const source = await mkdtemp ( path . join ( tmpdir (), "avril-webstreams-build-" )); 10const commit = "12b4fedec6c01503a137d837204ca0b85992461e" ; 11const run = ( command , args ) => 12execFileSync ( command , args , { cwd :source , stdio :"inherit" }); 13const previousDirectory = process . cwd (); 14 15try { 16run ( "git" , [ "init" , "-q" ]); 17run ( "git" , [ 18"fetch" , 19"--depth=1" , 20"https://github.com/MattiasBuelens/web-streams-polyfill.git" , 21commit , 22]); 23run ( "git" , [ "checkout" , "--detach" , "-q" , "FETCH_HEAD" ]); 24run ( "git" , [ "apply" , path . join ( vendor , "avril.patch" )]); 25run ( "npm" , [ 26"ci" , 27"--include=dev" , 28"--ignore-scripts" , 29"--no-audit" , 30"--no-fund" , 31]); 32 33process . chdir ( source ); 34const { default :configs } = await import ( 35pathToFileURL ( path . join ( source , "rollup.config.mjs" )) 36); 37const config = configs . find (( config ) => 38config . input === "src/polyfill.ts" && 39config . output [ 0 ]. file === "dist/polyfill.js" 40); 41if ( ! config ) throw new Error ( "Upstream polyfill build configuration changed" ); 42const original = await readFile ( path . join ( vendor , "polyfill.js" ), "utf8" ); 43const banner = original . match ( / ^\/\*\* [ \s\S ] * ?\*\/ / )?.[ 0 ]; 44if ( ! banner ) throw new Error ( "Missing upstream license banner" ); 45 46const { rollup} = createRequire ( path . join ( source , "package.json" ))( "rollup" ); 47const { output, ...input } = config ; 48const bundle = await rollup ( input ); 49try { 50await bundle . write ({ 51 ...output [ 0 ], 52 banner, 53file :path . join ( vendor , "polyfill.avril.js" ), 54}); 55} finally { 56await bundle . close (); 57} 58} finally { 59process . chdir ( previousDirectory ); 60await rm ( source , { recursive :true , force :true }); 61}