-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: normalizes bundle hash on any node version
- Loading branch information
Showing
10 changed files
with
113 additions
and
20 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,17 +1,41 @@ | ||
const npm = require('./npm') | ||
const logger = require('./logger') | ||
const { rootDir } = require('./paths') | ||
const { join } = require('path') | ||
const { join, resolve } = require('path') | ||
const { readFileSync, statSync } = require('fs') | ||
const { createHash } = require('crypto') | ||
const { sync: globIgnore } = require('glob-gitignore') | ||
|
||
// This will trigger the build as well (not using yarn since yarn pack is bugy) | ||
// Except that on npm < 4.0.0 the prepare doesn't exists | ||
|
||
module.exports = function createBundle() { | ||
function createBundle(log = logger.log.bind(logger)) { | ||
if (!npm.can.prepare()) { | ||
logger.log('building ts-jest') | ||
log('building ts-jest') | ||
npm.spawnSync(['-s', 'run', 'build'], { cwd: rootDir }) | ||
} | ||
logger.log('creating ts-jest bundle') | ||
log('creating ts-jest bundle') | ||
const res = npm.spawnSync(['-s', 'pack'], { cwd: rootDir }) | ||
return join(rootDir, res.stdout.toString().trim()) | ||
} | ||
|
||
function packageDigest() { | ||
const files = globIgnore(join(rootDir, '**'), { | ||
ignore: readFileSync(join(rootDir, '.npmignore')) | ||
.toString('utf8') | ||
.split(/\n/g) | ||
.filter(l => l && !/^(\s*#.+|\s*)$/.test(l)), | ||
}) | ||
const hash = createHash('sha1') | ||
files.sort().forEach(file => { | ||
if (statSync(file).isDirectory()) return | ||
hash.update(readFileSync(resolve(file))) | ||
hash.update('\x00') | ||
}) | ||
return hash.digest('hex') | ||
} | ||
|
||
module.exports = { | ||
createBundle, | ||
packageDigest, | ||
} |
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
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