44
55// prettier-ignore
66export const packages = [
7- {
8- name : "@types/web" ,
9- description : "Types for the DOM, and other web technologies in browsers" ,
10- readme : "./readmes/web.md" ,
11- files : [
12- { from : "../generated/dom.generated.d.ts" , to : "index.d.ts" } ,
13- { from : "../generated/dom.iterable.generated.d.ts" , to : "index.iterable.d.ts" }
14- ] ,
15- } ,
16- ] ;
7+ {
8+ name : "@types/web" ,
9+ description : "Types for the DOM, and other web technologies in browsers" ,
10+ readme : "./readmes/web.md" ,
11+ files : [
12+ { from : "../generated/dom.generated.d.ts" , to : "index.d.ts" } ,
13+ { from : "../generated/dom.iterable.generated.d.ts" , to : "index.iterable.d.ts" }
14+ ] ,
15+ } ,
16+ ] ;
1717
1818// Note: You can add 'version: "1.0.0"' to a package above
1919// to set the major or minor, otherwise it will always bump
2020// the patch.
2121
22- import { join , dirname } from "path" ;
2322import fs from "fs" ;
2423import fetch from "node-fetch" ;
2524import { fileURLToPath } from "url" ;
@@ -28,51 +27,48 @@ import pkg from "prettier";
2827const { format } = pkg ;
2928import { execSync } from "child_process" ;
3029
31- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
32- // @ts -ignore
33- const __filename = fileURLToPath ( import . meta. url ) ;
34- const __dirname = dirname ( __filename ) ;
35-
3630const go = async ( ) => {
3731 const gitSha = execSync ( "git rev-parse HEAD" ) . toString ( ) . trim ( ) . slice ( 0 , 7 ) ;
3832
39- const generatedDir = join ( __dirname , "generated" ) ;
40- const templateDir = join ( __dirname , "template" ) ;
33+ const generatedDir = new URL ( "generated/" , import . meta . url ) ;
34+ const templateDir = new URL ( "template/" , import . meta . url ) ;
4135
4236 for ( const pkg of packages ) {
4337 const folderName = pkg . name . replace ( "@" , "" ) . replace ( "/" , "-" ) ;
44- const packagePath = join ( generatedDir , folderName ) ;
38+ const packagePath = new URL ( ` ${ folderName } /` , generatedDir ) ;
4539
46- if ( fs . existsSync ( packagePath ) ) fs . rmSync ( packagePath , { recursive : true } ) ;
40+ if ( fs . existsSync ( packagePath ) ) {
41+ await fs . promises . rm ( packagePath , { recursive : true } ) ;
42+ }
4743 fs . mkdirSync ( packagePath , { recursive : true } ) ;
4844
4945 // Migrate in the template files
5046 for ( const templateFile of fs . readdirSync ( templateDir ) ) {
5147 if ( templateFile . startsWith ( "." ) ) continue ;
5248
53- const templatedFile = join ( templateDir , templateFile ) ;
54- fs . copyFileSync ( templatedFile , join ( packagePath , templateFile ) ) ;
49+ const templatedFile = new URL ( templateFile , templateDir ) ;
50+ fs . copyFileSync ( templatedFile , new URL ( templateFile , packagePath ) ) ;
5551 }
5652
5753 // Add the reference files in the config above
5854 pkg . files . forEach ( ( fileRef ) => {
5955 fs . copyFileSync (
60- join ( __filename , ".." , fileRef . from ) ,
61- join ( packagePath , fileRef . to )
56+ new URL ( fileRef . from , import . meta . url ) ,
57+ new URL ( fileRef . to , packagePath )
6258 ) ;
6359 } ) ;
6460
6561 // Setup the files in the repo
6662 const newPkgJSON = await updatePackageJSON ( packagePath , pkg , gitSha ) ;
67- copyREADME ( pkg , newPkgJSON , join ( packagePath , "README.md" ) ) ;
63+ copyREADME ( pkg , newPkgJSON , new URL ( "README.md" , packagePath ) ) ;
6864
6965 // Done
7066 console . log ( "Built:" , pkg . name ) ;
7167 }
7268} ;
7369
7470async function updatePackageJSON ( packagePath , pkg , gitSha ) {
75- const pkgJSONPath = join ( packagePath , "package.json" ) ;
71+ const pkgJSONPath = new URL ( "package.json" , packagePath ) ;
7672 const packageText = fs . readFileSync ( pkgJSONPath , "utf8" ) ;
7773 const packageJSON = JSON . parse ( packageText ) ;
7874 packageJSON . name = pkg . name ;
@@ -107,15 +103,17 @@ async function updatePackageJSON(packagePath, pkg, gitSha) {
107103
108104 fs . writeFileSync (
109105 pkgJSONPath ,
110- format ( JSON . stringify ( packageJSON ) , { filepath : pkgJSONPath } )
106+ format ( JSON . stringify ( packageJSON ) , {
107+ filepath : fileURLToPath ( pkgJSONPath ) ,
108+ } )
111109 ) ;
112110
113111 return packageJSON ;
114112}
115113
116114// Copies the README and adds some rudimentary templating to the file.
117115function copyREADME ( pkg , pkgJSON , writePath ) {
118- let readme = fs . readFileSync ( join ( __filename , ".." , pkg . readme ) , "utf-8" ) ;
116+ let readme = fs . readFileSync ( new URL ( pkg . readme , import . meta . url ) , "utf-8" ) ;
119117
120118 const htmlEncodedTag =
121119 encodeURIComponent ( pkgJSON . name ) + "%40" + pkgJSON . version ;
0 commit comments