-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inject version identifiers in module builds
- Loading branch information
1 parent
12789d7
commit 887578d
Showing
3 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Inject variables into distribution code | ||
// (this was previously handled by webpack for the bundled library) | ||
const fs = require('fs') | ||
const shell = require('shelljs') | ||
|
||
const files = [ | ||
'dist/es6/index.js', | ||
'dist/es2022/index.js' | ||
] | ||
|
||
const build_flavor = JSON.stringify('module') | ||
const build_commit = JSON.stringify( | ||
shell.exec('git rev-list -1 HEAD -- .', { silent: true }).trim(), | ||
) | ||
|
||
files.map(f => { | ||
fs.readFile(f, 'utf8', (err, data) => { | ||
if (err) { | ||
if (err.code === 'ENOENT') { | ||
console.warn('Could not patch file', f, `which doesn't seem to exist`) | ||
return | ||
} else { | ||
throw err | ||
} | ||
} | ||
|
||
let output = data.replace( | ||
/BUILD_FLAVOR/g, | ||
build_flavor | ||
) | ||
output = output.replace( | ||
/BUILD_COMMIT/g, | ||
build_commit | ||
) | ||
|
||
fs.writeFile(f, output, 'utf8', (err) => { | ||
if (err) throw err | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters