Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Adds support for large assets (> 100 MB) #3194

Merged
merged 6 commits into from Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions LICENSE.md
Expand Up @@ -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
>
Expand Down Expand Up @@ -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
>
Expand Down
3 changes: 3 additions & 0 deletions browser/crypto.ts
@@ -0,0 +1,3 @@
import sha256 from 'hash.js/lib/hash/sha/256';

export const createHash = () => sha256();
42 changes: 15 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rollup.config.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
}
Expand Down
8 changes: 4 additions & 4 deletions 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';
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -860,11 +860,11 @@ export default class Chunk {
options: OutputOptions,
existingNames: Record<string, any>
): 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);
sebiniemann marked this conversation as resolved.
Show resolved Hide resolved
this.visitDependencies(dep => {
if (dep instanceof ExternalModule) {
hash.update(':' + dep.renderPath);
Expand Down
6 changes: 3 additions & 3 deletions 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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/crypto.ts
@@ -0,0 +1,3 @@
import { createHash as cryptoCreateHash } from 'crypto';

export const createHash = () => cryptoCreateHash('sha256');
2 changes: 1 addition & 1 deletion typings/Chunk.d.ts → 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;
};
}