6
6
// ones which have changed.
7
7
8
8
import * as fs from "fs" ;
9
- import { basename } from "path" ;
10
9
import { spawnSync } from "child_process" ;
11
10
import { Octokit } from "@octokit/rest" ;
12
11
import printDiff from "print-diff" ;
13
- import { gitShowFile , generateChangelogFrom } from "../lib/changelog.js" ;
12
+ import { generateChangelogFrom } from "../lib/changelog.js" ;
14
13
import { packages } from "./createTypesPackages.js" ;
15
14
import { fileURLToPath } from "node:url" ;
15
+ import fetch from "node-fetch" ;
16
16
17
17
verify ( ) ;
18
18
@@ -22,12 +22,18 @@ const uploaded = [];
22
22
// .d.ts files from the version available on npm.
23
23
const generatedDir = new URL ( "generated/" , import . meta. url ) ;
24
24
for ( const dirName of fs . readdirSync ( generatedDir ) ) {
25
- console . log ( `Looking at ${ dirName } ` ) ;
26
25
const packageDir = new URL ( `${ dirName } /` , generatedDir ) ;
27
26
const localPackageJSONPath = new URL ( "package.json" , packageDir ) ;
28
27
const newTSConfig = fs . readFileSync ( localPackageJSONPath , "utf-8" ) ;
29
28
const pkgJSON = JSON . parse ( newTSConfig ) ;
30
29
30
+ // This assumes we'll only _ever_ ship patches, which may change in the
31
+ // future someday.
32
+ const [ maj , min , patch ] = pkgJSON . version . split ( "." ) ;
33
+ const olderVersion = `${ maj } .${ min } .${ patch - 1 } ` ;
34
+
35
+ console . log ( `\nLooking at ${ dirName } vs ${ olderVersion } ` ) ;
36
+
31
37
// We'll need to map back from the filename in the npm package to the
32
38
// generated file in baselines inside the git tag
33
39
const thisPackageMeta = packages . find ( ( p ) => p . name === pkgJSON . name ) ;
@@ -49,23 +55,17 @@ for (const dirName of fs.readdirSync(generatedDir)) {
49
55
if ( ! filemap ) {
50
56
throw new Error ( `Couldn't find ${ file } from ${ pkgJSON . name } ` ) ;
51
57
}
52
- const originalFilename = basename ( filemap . from ) ;
53
58
54
59
const generatedDTSPath = new URL ( file , packageDir ) ;
55
60
const generatedDTSContent = fs . readFileSync ( generatedDTSPath , "utf8" ) ;
56
61
57
- // This assumes we'll only _ever_ ship patches, which may change in the
58
- // future someday.
59
- const [ maj , min , patch ] = pkgJSON . version . split ( "." ) ;
60
- const olderVersion = `${ maj } .${ min } .${ patch - 1 } ` ;
61
-
62
62
try {
63
- const oldFile = gitShowFile (
64
- `${ pkgJSON . name } @${ olderVersion } ` ,
65
- `baselines/${ originalFilename } `
63
+ const oldFile = await getFileFromUnpkg (
64
+ `${ pkgJSON . name } @${ olderVersion } /${ filemap . to } `
66
65
) ;
67
- console . log ( `Comparing ${ file } from ${ olderVersion } , to now:` ) ;
68
- printDiff ( oldFile , generatedDTSContent ) ;
66
+ console . log ( ` - ${ file } ` ) ;
67
+ if ( oldFile !== generatedDTSContent )
68
+ printDiff ( oldFile , generatedDTSContent ) ;
69
69
70
70
const title = `\n## \`${ file } \`\n\n` ;
71
71
const notes = generateChangelogFrom ( oldFile , generatedDTSContent ) ;
@@ -78,6 +78,7 @@ for (const dirName of fs.readdirSync(generatedDir)) {
78
78
console . log ( `
79
79
Could not get the file ${ file } inside the npm package ${ pkgJSON . name } from tag ${ olderVersion } .
80
80
Assuming that this means we need to upload this package.` ) ;
81
+ console . error ( error ) ;
81
82
upload = true ;
82
83
}
83
84
}
@@ -107,11 +108,13 @@ Assuming that this means we need to upload this package.`);
107
108
}
108
109
109
110
uploaded . push ( dirName ) ;
110
- }
111
111
112
- console . log ( "\n# Release notes:" ) ;
113
- console . log ( releaseNotes , "\n\n" ) ;
112
+ console . log ( "\n# Release notes:" ) ;
113
+ console . log ( releaseNotes , "\n\n" ) ;
114
+ }
114
115
}
116
+ console . log ( "" ) ;
117
+
115
118
// Warn if we did a dry run.
116
119
if ( ! process . env . NODE_AUTH_TOKEN ) {
117
120
console . log ( "Did a dry run because process.env.NODE_AUTH_TOKEN is not set." ) ;
@@ -120,7 +123,7 @@ if (!process.env.NODE_AUTH_TOKEN) {
120
123
if ( uploaded . length ) {
121
124
console . log ( "Uploaded: " , uploaded . join ( ", " ) ) ;
122
125
} else {
123
- console . log ( "No uploads " ) ;
126
+ console . log ( "Nothing to upload " ) ;
124
127
}
125
128
126
129
/**
@@ -154,3 +157,8 @@ function verify() {
154
157
"There isn't an ENV var set up for creating a GitHub release, expected GITHUB_TOKEN."
155
158
) ;
156
159
}
160
+
161
+ /** @param {string } filepath */
162
+ function getFileFromUnpkg ( filepath ) {
163
+ return fetch ( `https://unpkg.com/${ filepath } ` ) . then ( ( r ) => r . text ( ) ) ;
164
+ }
0 commit comments