|
1 |
| -// Used for JS files by rollup.config.js |
2 |
| -// Used for CSS files by Gruntfile.js via preprocess() |
| 1 | +// Helper used for JS files by rollup.config.js, |
| 2 | +// and for CSS files by Gruntfile.js via preprocess() |
| 3 | + |
| 4 | +const distVersion = require( "../package.json" ).version; |
| 5 | + |
| 6 | +let distEpoch; |
| 7 | +let distDate; |
| 8 | +if ( /pre/.test( distVersion ) ) { |
| 9 | + |
| 10 | + // During development, insert a detailed timestamp. |
| 11 | + // |
| 12 | + // Format as 0000-00-00T00:00Z |
| 13 | + distDate = ( new Date() ).toISOString().replace( /:\d+\.\d+Z$/, "Z" ); |
| 14 | +} else { |
| 15 | + |
| 16 | + // Release builds should be deterministic and reproducible. |
| 17 | + // Use the date of the release prep commit via an environment variable |
| 18 | + // See RELEASE.md and <https://reproducible-builds.org/docs/source-date-epoch/>. |
| 19 | + // |
| 20 | + // Format as 0000-00-00 |
| 21 | + distEpoch = process.env.SOURCE_DATE_EPOCH; |
| 22 | + if ( !/^\d{7,}$/.test( distEpoch ) ) { |
| 23 | + throw new Error( "SOURCE_DATE_EPOCH must be set to a UNIX timestamp" ); |
| 24 | + } |
| 25 | + distDate = ( new Date( distEpoch * 1000 ) ).toISOString().replace( /T.+$/, "" ); |
| 26 | +} |
| 27 | + |
3 | 28 | const replacements = {
|
4 | 29 |
|
5 | 30 | // Embed version
|
6 |
| - "@VERSION": require( "../package.json" ).version, |
| 31 | + "@VERSION": distVersion, |
7 | 32 |
|
8 |
| - // Embed date (yyyy-mm-ddThh:mmZ) |
9 |
| - "@DATE": ( new Date() ).toISOString().replace( /:\d+\.\d+Z$/, "Z" ) |
| 33 | + // Embed date |
| 34 | + "@DATE": distDate |
10 | 35 | };
|
11 | 36 |
|
12 | 37 | function preprocess( code ) {
|
|
0 commit comments