diff --git a/LICENSE.md b/LICENSE.md index 9f1eeef1d01..5cc0382e517 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -150,13 +150,13 @@ Repository: jonschlinkert/fill-range ## hash.js License: MIT By: Fedor Indutny -Repository: git@github.com:indutny/hash.js +Repository: git+ssh://git@github.com/indutny/hash.js.git --------------------------------------- ## inherits License: ISC -Repository: git://github.com/isaacs/inherits +Repository: git://github.com/isaacs/inherits.git > The ISC License > @@ -265,7 +265,7 @@ Repository: micromatch/micromatch ## minimalistic-assert License: ISC -Repository: https://github.com/calvinmetcalf/minimalistic-assert.git +Repository: git+https://github.com/calvinmetcalf/minimalistic-assert.git > Copyright 2015 Calvin Metcalf > diff --git a/browser/crypto.ts b/browser/crypto.ts new file mode 100644 index 00000000000..294dc57ff80 --- /dev/null +++ b/browser/crypto.ts @@ -0,0 +1,3 @@ +import sha256 from 'hash.js/lib/hash/sha/256'; + +export const createHash = () => sha256(); diff --git a/package-lock.json b/package-lock.json index ad5d9b94a83..1c7e5a1f9ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -314,6 +314,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz", "integrity": "sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==", + "dev": true, "requires": { "es6-promisify": "^5.0.0" } @@ -1437,12 +1438,14 @@ "es6-promise": { "version": "4.2.8", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", - "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==" + "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", + "dev": true }, "es6-promisify": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", + "dev": true, "requires": { "es6-promise": "^4.0.3" } @@ -2578,31 +2581,6 @@ "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", "dev": true }, - "https-proxy-agent": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-3.0.0.tgz", - "integrity": "sha512-y4jAxNEihqvBI5F3SaO2rtsjIOnnNA8sEbuiP+UhJZJHeM2NRm6c09ax2tgqme+SgUUvjao2fJXF4h3D6Cb2HQ==", - "dev": true, - "requires": { - "agent-base": "^4.3.0", - "debug": "^3.1.0" - }, - "dependencies": { - "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", - "requires": { - "ms": "^2.1.1" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - } - } - }, "human-signals": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-1.1.1.tgz", @@ -6044,7 +6022,7 @@ "integrity": "sha512-CKncqSF7sH6p4rzCgkb/z/Pcos5efl0DmolzvlqRQUNcpRIruOhY9+T1FsIlyEbfWd7MsFpodROOwHYh2BaXzw==", "dev": true, "requires": { - "https-proxy-agent": "^3.0.0", + "https-proxy-agent": "^2.2.1", "node-fetch": "^2.2.0", "uuid": "^3.3.2" }, @@ -6058,6 +6036,16 @@ "ms": "^2.1.1" } }, + "https-proxy-agent": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz", + "integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==", + "dev": true, + "requires": { + "agent-base": "^4.3.0", + "debug": "^3.1.0" + } + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", diff --git a/rollup.config.js b/rollup.config.js index 16171315e91..74cc004878c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -171,7 +171,7 @@ export default command => { !command.configTest && license({ thirdParty: generateLicenseFile }) ], // acorn needs to be external as some plugins rely on a shared acorn instance - external: ['acorn', 'assert', 'events', 'fs', 'module', 'path', 'util'], + external: ['acorn', 'assert', 'crypto', 'events', 'fs', 'module', 'path', 'util'], treeshake, output: { banner, @@ -205,6 +205,7 @@ export default command => { json(), { load: id => { + if (~id.indexOf('crypto.ts')) return fs.readFileSync('browser/crypto.ts', 'utf-8'); if (~id.indexOf('fs.ts')) return fs.readFileSync('browser/fs.ts', 'utf-8'); if (~id.indexOf('path.ts')) return fs.readFileSync('browser/path.ts', 'utf-8'); } diff --git a/src/Chunk.ts b/src/Chunk.ts index beb66769f48..e5b69e17544 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -1,5 +1,5 @@ -import sha256 from 'hash.js/lib/hash/sha/256'; import MagicString, { Bundle as MagicStringBundle, SourceMap } from 'magic-string'; +import { createHash } from '../browser/crypto'; import { relative } from '../browser/path'; import { createInclusionContext } from './ast/ExecutionContext'; import ExportDefaultDeclaration from './ast/nodes/ExportDefaultDeclaration'; @@ -366,7 +366,7 @@ export default class Chunk { getRenderedHash(): string { if (this.renderedHash) return this.renderedHash; if (!this.renderedSource) return ''; - const hash = sha256(); + const hash = createHash(); const hashAugmentation = this.calculateHashAugmentation(); hash.update(hashAugmentation); hash.update(this.renderedSource.toString()); @@ -860,11 +860,11 @@ export default class Chunk { options: OutputOptions, existingNames: Record ): string { - const hash = sha256(); + const hash = createHash(); hash.update( [addons.intro, addons.outro, addons.banner, addons.footer].map(addon => addon || '').join(':') ); - hash.update(options.format); + hash.update(options.format as string); this.visitDependencies(dep => { if (dep instanceof ExternalModule) { hash.update(':' + dep.renderPath); diff --git a/src/utils/FileEmitter.ts b/src/utils/FileEmitter.ts index c6196285fc0..5ddb3b14e78 100644 --- a/src/utils/FileEmitter.ts +++ b/src/utils/FileEmitter.ts @@ -1,9 +1,9 @@ -import sha256 from 'hash.js/lib/hash/sha/256'; import Chunk from '../Chunk'; import Graph from '../Graph'; import Module from '../Module'; import { FilePlaceholder, OutputBundleWithPlaceholders } from '../rollup/types'; import { BuildPhase } from './buildPhase'; +import { createHash } from './crypto'; import { errAssetNotFinalisedForFileName, errAssetReferenceIdNotFoundForSetSource, @@ -33,7 +33,7 @@ function generateAssetFileName( return makeUnique( renderNamePattern(output.assetFileNames, 'output.assetFileNames', { hash() { - const hash = sha256(); + const hash = createHash(); hash.update(emittedName); hash.update(':'); hash.update(source); @@ -290,7 +290,7 @@ export class FileEmitter { private assignReferenceId(file: ConsumedFile, idBase: string): string { let referenceId: string | undefined; do { - const hash = sha256(); + const hash = createHash(); if (referenceId) { hash.update(referenceId); } else { diff --git a/src/utils/crypto.ts b/src/utils/crypto.ts new file mode 100644 index 00000000000..310c9a9922e --- /dev/null +++ b/src/utils/crypto.ts @@ -0,0 +1,3 @@ +import { createHash as cryptoCreateHash } from 'crypto'; + +export const createHash = () => cryptoCreateHash('sha256'); diff --git a/typings/Chunk.d.ts b/typings/hash.js.d.ts similarity index 100% rename from typings/Chunk.d.ts rename to typings/hash.js.d.ts index 5928d560977..1b6c018d494 100644 --- a/typings/Chunk.d.ts +++ b/typings/hash.js.d.ts @@ -1,6 +1,6 @@ declare module 'hash.js/lib/hash/sha/256' { export default function sha256(): { - update: (data: any) => void; digest: (format: string) => string; + update: (data: any) => void; }; }