Skip to content

Commit

Permalink
Merge branch 'master' into watch-on-build
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Aug 28, 2019
2 parents ec973d1 + 071f5e3 commit e2e0a27
Show file tree
Hide file tree
Showing 122 changed files with 740 additions and 248 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,17 @@
# rollup changelog

## 1.20.3
*2019-08-28*

### Bug Fixes
* Make sure file hashes change when a change of the naming pattern leads to a file name change of a dependency (#3083)
* Fix several issues where reexporting an external "default" export could lead to invalid or incorrect code (#3084)

### Pull Requests
* [#3078](https://github.com/rollup/rollup/pull/3078): Add github actions workflow config for windows (@shellscape)
* [#3083](https://github.com/rollup/rollup/pull/3083): Properly reflect dependency file names in hash (@lukastaegert)
* [#3084](https://github.com/rollup/rollup/pull/3084): Fix "default" reexport issues in non ESM/System formats (@lukastaegert)

## 1.20.2
*2019-08-25*

Expand Down
2 changes: 1 addition & 1 deletion docs/999-big-list-of-options.md
Expand Up @@ -397,7 +397,7 @@ Default: `"[name]-[hash].js"`
The pattern to use for naming shared chunks created when code-splitting. Pattern supports the following placeholders:
* `[format]`: The rendering format defined in the output options, e.g. `esm` or `cjs`.
* `[hash]`: A hash based on the content of the chunk and the content of all its dependencies.
* `[name]`: The name of the chunk. This will be `chunk` unless the chunk was created via the [`manualChunks`](guide/en/#manualchunks) options.
* `[name]`: The name of the chunk. This can be explicitly set via the [`manualChunks`](guide/en/#manualchunks) option or when the chunk is created by a plugin via [`this.emitFile`](guide/en/#thisemitfileemittedfile-emittedchunk--emittedasset--string). Otherwise it will be derived from the chunk contents.

Forward slashes `/` can be used to place files in sub-directories. See also [`output.assetFileNames`](guide/en/#outputassetfilenames), [`output.entryFileNames`](guide/en/#outputentryfilenames).

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "rollup",
"version": "1.20.2",
"version": "1.20.3",
"description": "Next-generation ES module bundler",
"main": "dist/rollup.js",
"module": "dist/rollup.es.js",
Expand Down
28 changes: 21 additions & 7 deletions src/Chunk.ts
Expand Up @@ -250,19 +250,25 @@ export default class Chunk {
}

generateId(
pattern: string,
patternName: string,
addons: Addons,
options: OutputOptions,
existingNames: Record<string, any>
existingNames: Record<string, any>,
includeHash: boolean
): string {
if (this.fileName !== null) {
return this.fileName;
}
const [pattern, patternName] =
this.facadeModule && this.facadeModule.isUserDefinedEntryPoint
? [options.entryFileNames || '[name].js', 'output.entryFileNames']
: [options.chunkFileNames || '[name]-[hash].js', 'output.chunkFileNames'];
return makeUnique(
renderNamePattern(pattern, patternName, {
format: () => (options.format === 'es' ? 'esm' : (options.format as string)),
hash: () => this.computeContentHashWithDependencies(addons, options),
hash: () =>
includeHash
? this.computeContentHashWithDependencies(addons, options, existingNames)
: '[hash]',
name: () => this.getChunkName()
}),
existingNames
Expand Down Expand Up @@ -831,15 +837,23 @@ export default class Chunk {
return hashAugmentation;
}

private computeContentHashWithDependencies(addons: Addons, options: OutputOptions): string {
private computeContentHashWithDependencies(
addons: Addons,
options: OutputOptions,
existingNames: Record<string, any>
): string {
const hash = sha256();
hash.update(
[addons.intro, addons.outro, addons.banner, addons.footer].map(addon => addon || '').join(':')
);
hash.update(options.format);
this.visitDependencies(dep => {
if (dep instanceof ExternalModule) hash.update(':' + dep.renderPath);
else hash.update(dep.getRenderedHash());
if (dep instanceof ExternalModule) {
hash.update(':' + dep.renderPath);
} else {
hash.update(dep.getRenderedHash());
hash.update(dep.generateId(addons, options, existingNames, false));
}
});

return hash.digest('hex').substr(0, 8);
Expand Down
125 changes: 59 additions & 66 deletions src/finalisers/shared/getExportBlock.ts
Expand Up @@ -11,28 +11,20 @@ export default function getExportBlock(
) {
const _ = compact ? '' : ' ';
const n = compact ? '' : '\n';

if (!namedExportsMode) {
let local;
exports.some(expt => {
if (expt.exported === 'default') {
local = expt.local;
return true;
if (exports.length > 0) {
local = exports[0].local;
} else {
for (const dep of dependencies) {
if (dep.reexports) {
const expt = dep.reexports[0];
local =
dep.namedExportsMode && expt.imported !== '*' && expt.imported !== 'default'
? `${dep.name}.${expt.imported}`
: dep.name;
}
}
return false;
});
// search for reexported default otherwise
if (!local) {
dependencies.some(dep => {
if (!dep.reexports) return false;
return dep.reexports.some(expt => {
if (expt.reexported === 'default') {
local = dep.namedExportsMode && expt.imported !== '*' ? `${dep.name}.${expt.imported}` : dep.name;
return true;
}
return false;
});
});
}
return `${mechanism}${local};`;
}
Expand All @@ -44,7 +36,7 @@ export default function getExportBlock(
if (reexports && namedExportsMode) {
reexports.forEach(specifier => {
if (specifier.reexported === '*') {
if (!compact && exportBlock) exportBlock += '\n';
if (exportBlock) exportBlock += n;
if (specifier.needsLiveBinding) {
exportBlock +=
`Object.keys(${name}).forEach(function${_}(k)${_}{${n}` +
Expand All @@ -63,60 +55,61 @@ export default function getExportBlock(
}
});

dependencies.forEach(
({ name, imports, reexports, isChunk, namedExportsMode: depNamedExportsMode }) => {
if (reexports && namedExportsMode) {
reexports.forEach(specifier => {
if (specifier.imported === 'default' && !isChunk) {
const exportsNamesOrNamespace =
(imports && imports.some(specifier => specifier.imported !== 'default')) ||
(reexports &&
reexports.some(
specifier => specifier.imported !== 'default' && specifier.imported !== '*'
));

const reexportsDefaultAsDefault =
reexports &&
reexports.some(
specifier => specifier.imported === 'default' && specifier.reexported === 'default'
);

if (exportBlock && !compact) exportBlock += '\n';
if (exportsNamesOrNamespace || reexportsDefaultAsDefault)
exportBlock += `exports.${specifier.reexported}${_}=${_}${name}${
interop !== false ? '__default' : '.default'
};`;
else exportBlock += `exports.${specifier.reexported}${_}=${_}${name};`;
} else if (specifier.imported !== '*') {
if (exportBlock && !compact) exportBlock += '\n';
const importName =
specifier.imported === 'default' && !depNamedExportsMode
? name
: `${name}.${specifier.imported}`;
exportBlock += specifier.needsLiveBinding
? `Object.defineProperty(exports,${_}'${specifier.reexported}',${_}{${n}` +
`${t}enumerable:${_}true,${n}` +
`${t}get:${_}function${_}()${_}{${n}` +
`${t}${t}return ${importName};${n}${t}}${n}});`
: `exports.${specifier.reexported}${_}=${_}${importName};`;
} else if (specifier.reexported !== '*') {
if (exportBlock && !compact) exportBlock += '\n';
for (const {
name,
imports,
reexports,
isChunk,
namedExportsMode: depNamedExportsMode,
exportsNames
} of dependencies) {
if (reexports && namedExportsMode) {
for (const specifier of reexports) {
if (specifier.imported === 'default' && !isChunk) {
if (exportBlock) exportBlock += n;
if (
exportsNames &&
(reexports.some(specifier =>
specifier.imported === 'default'
? specifier.reexported === 'default'
: specifier.imported !== '*'
) ||
(imports && imports.some(specifier => specifier.imported !== 'default')))
) {
exportBlock += `exports.${specifier.reexported}${_}=${_}${name}${
interop !== false ? '__default' : '.default'
};`;
} else {
exportBlock += `exports.${specifier.reexported}${_}=${_}${name};`;
}
});
} else if (specifier.imported !== '*') {
if (exportBlock) exportBlock += n;
const importName =
specifier.imported === 'default' && !depNamedExportsMode
? name
: `${name}.${specifier.imported}`;
exportBlock += specifier.needsLiveBinding
? `Object.defineProperty(exports,${_}'${specifier.reexported}',${_}{${n}` +
`${t}enumerable:${_}true,${n}` +
`${t}get:${_}function${_}()${_}{${n}` +
`${t}${t}return ${importName};${n}${t}}${n}});`
: `exports.${specifier.reexported}${_}=${_}${importName};`;
} else if (specifier.reexported !== '*') {
if (exportBlock) exportBlock += n;
exportBlock += `exports.${specifier.reexported}${_}=${_}${name};`;
}
}
}
);
}

exports.forEach(expt => {
for (const expt of exports) {
const lhs = `exports.${expt.exported}`;
const rhs = expt.local;
if (lhs === rhs) {
return;
if (lhs !== rhs) {
if (exportBlock) exportBlock += n;
exportBlock += `${lhs}${_}=${_}${rhs};`;
}
if (exportBlock && !compact) exportBlock += '\n';
exportBlock += `${lhs}${_}=${_}${rhs};`;
});
}

return exportBlock;
}
20 changes: 11 additions & 9 deletions src/finalisers/shared/getInteropBlock.ts
Expand Up @@ -6,21 +6,23 @@ export default function getInteropBlock(
options: OutputOptions,
varOrConst: string
) {
const _ = options.compact ? '' : ' ';

return dependencies
.map(({ name, exportsNames, exportsDefault, namedExportsMode }) => {
if (!namedExportsMode) return;

if (!exportsDefault || options.interop === false) return null;
if (!namedExportsMode || !exportsDefault || options.interop === false) return null;

if (exportsNames) {
if (options.compact)
return `${varOrConst} ${name}__default='default'in ${name}?${name}['default']:${name};`;
return `${varOrConst} ${name}__default = 'default' in ${name} ? ${name}['default'] : ${name};`;
return (
`${varOrConst} ${name}__default${_}=${_}'default'${_}in ${name}${_}?` +
`${_}${name}['default']${_}:${_}${name};`
);
}

if (options.compact)
return `${name}=${name}&&${name}.hasOwnProperty('default')?${name}['default']:${name};`;
return `${name} = ${name} && ${name}.hasOwnProperty('default') ? ${name}['default'] : ${name};`;
return (
`${name}${_}=${_}${name}${_}&&${_}${name}.hasOwnProperty('default')${_}?` +
`${_}${name}['default']${_}:${_}${name};`
);
})
.filter(Boolean)
.join(options.compact ? '' : '\n');
Expand Down
11 changes: 1 addition & 10 deletions src/utils/assignChunkIds.ts
Expand Up @@ -24,21 +24,12 @@ export function assignChunkIds(
// make sure entry chunk names take precedence with regard to deconflicting
const chunksForNaming: Chunk[] = entryChunks.concat(otherChunks);
for (const chunk of chunksForNaming) {
const facadeModule = chunk.facadeModule;
if (outputOptions.file) {
chunk.id = basename(outputOptions.file);
} else if (inputOptions.preserveModules) {
chunk.id = chunk.generateIdPreserveModules(inputBase, bundle);
} else {
let pattern, patternName;
if (facadeModule && facadeModule.isUserDefinedEntryPoint) {
pattern = outputOptions.entryFileNames || '[name].js';
patternName = 'output.entryFileNames';
} else {
pattern = outputOptions.chunkFileNames || '[name]-[hash].js';
patternName = 'output.chunkFileNames';
}
chunk.id = chunk.generateId(pattern, patternName, addons, outputOptions, bundle);
chunk.id = chunk.generateId(addons, outputOptions, bundle, true);
}
bundle[chunk.id] = FILE_PLACEHOLDER;
}
Expand Down

This file was deleted.

@@ -0,0 +1,5 @@
define(['./chunk-main2-6a714ad3-amd'], function (main2) { 'use strict';

main2.log(main2.dep);

});
@@ -0,0 +1,7 @@
define(['./chunk-main2-6a714ad3-amd'], function (main2) { 'use strict';



return main2.log;

});

This file was deleted.

@@ -0,0 +1,5 @@
'use strict';

var main2 = require('./chunk-main2-397efa8f-cjs.js');

main2.log(main2.dep);

This file was deleted.

This file was deleted.

@@ -0,0 +1,7 @@
'use strict';

var main2 = require('./chunk-main2-397efa8f-cjs.js');



module.exports = main2.log;

This file was deleted.

@@ -0,0 +1,3 @@
import { l as log, d as dep } from './chunk-main2-5251e7d2-esm.js';

log(dep);
@@ -0,0 +1 @@
export { l as default } from './chunk-main2-5251e7d2-esm.js';

This file was deleted.

@@ -1,4 +1,4 @@
System.register(['./chunk-main2-63744fb4-system.js'], function () {
System.register(['./chunk-main2-97f5caac-system.js'], function () {
'use strict';
var log, dep;
return {
Expand Down
@@ -1,4 +1,4 @@
System.register(['./chunk-main2-63744fb4-system.js'], function (exports) {
System.register(['./chunk-main2-97f5caac-system.js'], function (exports) {
'use strict';
return {
setters: [function (module) {
Expand Down

0 comments on commit e2e0a27

Please sign in to comment.