Skip to content

Commit 3ec09fe

Browse files
authored
Merge pull request #159 from rollup/sync-ae1d14b7
docs(en): merge rollup/master into rollup-docs-cn/master @ ae1d14b
2 parents b10c452 + fbec424 commit 3ec09fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+208
-30
lines changed

Diff for: CHANGELOG.md

+55
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
# rollup changelog
22

3+
## 4.26.0
4+
5+
_2024-11-13_
6+
7+
### Features
8+
9+
- Allow to avoid `await bundle.close()` via explicit resource management in TypeScript (#5721)
10+
11+
### Pull Requests
12+
13+
- [#5721](https://github.com/rollup/rollup/pull/5721): feat: support `using` for `RollupBuild` (@shulaoda)
14+
15+
## 4.25.0
16+
17+
_2024-11-09_
18+
19+
### Features
20+
21+
- Add `output.sourcemapDebugIds` option to add matching debug ids to sourcemaps and code for tools like Sentry or Rollbar (#5712)
22+
23+
### Bug Fixes
24+
25+
- Make it easier to manually reproduce base16 hashes by using a more standard base16 conversion algorithm (#5719)
26+
27+
### Pull Requests
28+
29+
- [#5712](https://github.com/rollup/rollup/pull/5712): feat: Add support for injecting Debug IDs (@timfish)
30+
- [#5717](https://github.com/rollup/rollup/pull/5717): fix(deps): update swc monorepo (major) (@renovate[bot])
31+
- [#5718](https://github.com/rollup/rollup/pull/5718): chore(deps): lock file maintenance minor/patch updates (@renovate[bot])
32+
- [#5719](https://github.com/rollup/rollup/pull/5719): Use a less surprising base-16 encoding (@lukastaegert)
33+
334
## 4.24.4
435

536
_2024-11-04_
@@ -97,6 +128,30 @@ _2024-09-27_
97128
- [#5682](https://github.com/rollup/rollup/pull/5682): chore(deps): update dependency @rollup/plugin-typescript to v12 (@renovate[bot])
98129
- [#5684](https://github.com/rollup/rollup/pull/5684): chore(deps): lock file maintenance minor/patch updates (@renovate[bot])
99130

131+
## 2.79.2
132+
133+
_2024-09-26_
134+
135+
### Bug Fixes
136+
137+
- Fix a vulnerability in generated code that affects IIFE, UMD and CJS bundles when run in a browser context (#5671)
138+
139+
### Pull Requests
140+
141+
- [#5671](https://github.com/rollup/rollup/pull/5671): Fix DOM Clobbering CVE (@lukastaegert)
142+
143+
## 3.29.5
144+
145+
_2024-09-21_
146+
147+
### Bug Fixes
148+
149+
- Fix a vulnerability in generated code that affects IIFE, UMD and CJS bundles when run in a browser context (#5671)
150+
151+
### Pull Requests
152+
153+
- [#5671](https://github.com/rollup/rollup/pull/5671): Fix DOM Clobbering CVE (@lukastaegert)
154+
100155
## 4.22.4
101156

102157
_2024-09-21_

Diff for: browser/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rollup/browser",
3-
"version": "4.24.4",
3+
"version": "4.26.0",
44
"description": "Next-generation ES module bundler browser build",
55
"main": "dist/rollup.browser.js",
66
"module": "dist/es/rollup.browser.js",

Diff for: cli/help.md

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Basic options:
7171
--shimMissingExports Create shim variables for missing exports
7272
--silent Don't print warnings
7373
--sourcemapBaseUrl <url> Emit absolute sourcemap URLs with given base
74+
--sourcemapDebugIds Emit unique debug ids in source and sourcemaps
7475
--sourcemapExcludeSources Do not include source code in source maps
7576
--sourcemapFile <file> Specify bundle position for source maps
7677
--sourcemapFileNames <pattern> Name pattern for emitted sourcemaps

Diff for: cli/run/build.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default async function build(
3030
stderr(cyan(`\n${bold(inputFiles!)}${bold(files.join(', '))}...`));
3131
}
3232

33-
const bundle = await rollup(inputOptions as any);
33+
await using bundle = await rollup(inputOptions as any);
3434
if (useStdout) {
3535
const output = outputOptions[0];
3636
if (output.sourcemap && output.sourcemap !== 'inline') {
@@ -48,7 +48,6 @@ export default async function build(
4848
}
4949

5050
await Promise.all(outputOptions.map(bundle.write));
51-
await bundle.close();
5251
if (!silent) {
5352
warnings.flush();
5453
stderr(green(`created ${bold(files.join(', '))} in ${bold(ms(Date.now() - start))}`));

Diff for: docs/command-line-interface/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export default {
109109
preserveModulesRoot,
110110
sourcemap,
111111
sourcemapBaseUrl,
112+
sourcemapDebugIds,
112113
sourcemapExcludeSources,
113114
sourcemapFile,
114115
sourcemapFileNames,
@@ -439,6 +440,7 @@ export default {
439440
--shimMissingExports 为丢失的导出创建卡扣变量
440441
--silent 不打印警告
441442
--sourcemapBaseUrl <url> 使用给定的基本 URL 发出绝对源映射 URL
443+
--sourcemapDebugIds 在源代码和源映射中生成唯一的 debug ID
442444
--sourcemapExcludeSources 在源映射中不包括源代码
443445
--sourcemapFile <file> 指定源映射的包位置
444446
--sourcemapFileNames <pattern> 编译后 sourcemap 的命名模式

Diff for: docs/configuration-options/index.md

+10
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,16 @@ export default {
17441744

17451745
默认情况下,Rollup 生成的 sourcemap 使用相对 URL 路径来引用它们描述的文件。该选项可提供一个绝对基础 URL 路径,例如 `https://example.com`,sourcemap 将使用绝对 URL 路径来代替。
17461746

1747+
### output.sourcemapDebugIds
1748+
1749+
| | |
1750+
| -----: | :--------------------------------------------- |
1751+
| 类型: | `boolean` |
1752+
| CLI: | `--sourcemapDebugIds`/`--no-sourcemapDebugIds` |
1753+
| 默认: | `false` |
1754+
1755+
如果设为 `true`,将在源代码和 sourcemap 中生成唯一的 ID,这有助于在不同的构建中识别 sourcemap。有关详细信息,请参阅 [TC39 sourcemap debug ID 提案](https://github.com/tc39/source-map/blob/main/proposals/debug-id.md)
1756+
17471757
### output.sourcemapExcludeSources {#output-sourcemapexcludesources}
17481758

17491759
| | |

Diff for: docs/javascript-api/index.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ async function build() {
5353
let bundle;
5454
let buildFailed = false;
5555
try {
56-
// 启动一次打包
56+
// 新建一个 bundle。如果你使用的是 TypeScript 或支持该特性的运行时,
57+
// 你可以这样写:
58+
//
59+
// await using bundle = await rollup(inputOptions);
60+
//
61+
// 这样做就不需要在下面显式地关闭释放 bundle。
5762
bundle = await rollup(inputOptions);
5863

5964
// 一个文件名数组,表示此产物所依赖的文件
@@ -208,6 +213,7 @@ const outputOptions = {
208213
preserveModulesRoot,
209214
sourcemap,
210215
sourcemapBaseUrl,
216+
sourcemapDebugIds,
211217
sourcemapExcludeSources,
212218
sourcemapFile,
213219
sourcemapFileNames,

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rollup",
3-
"version": "4.24.4",
3+
"version": "4.26.0",
44
"description": "Next-generation ES module bundler",
55
"main": "dist/rollup.js",
66
"module": "dist/es/rollup.js",

Diff for: rust/xxhash/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const CHARACTERS_BASE64: &[u8; 64] =
66

77
const CHARACTERS_BASE36: &[u8; 36] = b"abcdefghijklmnopqrstuvwxyz0123456789";
88

9-
const CHARACTERS_BASE16: &[u8; 16] = b"abcdef0123456789";
9+
const CHARACTERS_BASE16: &[u8; 16] = b"0123456789abcdef";
1010

1111
pub fn xxhash_base64_url(input: &[u8]) -> String {
1212
to_string(&xxh3_128(input).to_le_bytes(), 64, CHARACTERS_BASE64).unwrap()

Diff for: src/rollup/rollup.ts

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ import type {
3838
RollupWatcher
3939
} from './types';
4040

41+
// @ts-expect-error TS2540: the polyfill of `asyncDispose`.
42+
Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
43+
4144
export default function rollup(rawInputOptions: RollupOptions): Promise<RollupBuild> {
4245
return rollupInternal(rawInputOptions, null);
4346
}
@@ -95,6 +98,9 @@ export async function rollupInternal(
9598
await graph.pluginDriver.hookParallel('closeBundle', []);
9699
},
97100
closed: false,
101+
async [Symbol.asyncDispose]() {
102+
await this.close();
103+
},
98104
async generate(rawOutputOptions: OutputOptions) {
99105
if (result.closed) return error(logAlreadyClosed());
100106

Diff for: src/rollup/types.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ export interface OutputOptions {
782782
sourcemapFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
783783
sourcemapIgnoreList?: boolean | SourcemapIgnoreListOption;
784784
sourcemapPathTransform?: SourcemapPathTransformOption;
785+
sourcemapDebugIds?: boolean;
785786
strict?: boolean;
786787
systemNullSetters?: boolean;
787788
validate?: boolean;
@@ -836,6 +837,7 @@ export interface NormalizedOutputOptions {
836837
sourcemapFileNames: string | ((chunkInfo: PreRenderedChunk) => string) | undefined;
837838
sourcemapIgnoreList: SourcemapIgnoreListOption;
838839
sourcemapPathTransform: SourcemapPathTransformOption | undefined;
840+
sourcemapDebugIds: boolean;
839841
strict: boolean;
840842
systemNullSetters: boolean;
841843
validate: boolean;
@@ -916,6 +918,7 @@ export interface RollupBuild {
916918
cache: RollupCache | undefined;
917919
close: () => Promise<void>;
918920
closed: boolean;
921+
[Symbol.asyncDispose](): Promise<void>;
919922
generate: (outputOptions: OutputOptions) => Promise<RollupOutput>;
920923
getTimings?: () => SerializedTimings;
921924
watchFiles: string[];

Diff for: src/utils/options/mergeOptions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ async function mergeOutputOptions(
279279
sanitizeFileName: getOption('sanitizeFileName'),
280280
sourcemap: getOption('sourcemap'),
281281
sourcemapBaseUrl: getOption('sourcemapBaseUrl'),
282+
sourcemapDebugIds: getOption('sourcemapDebugIds'),
282283
sourcemapExcludeSources: getOption('sourcemapExcludeSources'),
283284
sourcemapFile: getOption('sourcemapFile'),
284285
sourcemapFileNames: getOption('sourcemapFileNames'),

Diff for: src/utils/options/normalizeOutputOptions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export async function normalizeOutputOptions(
9494
: defaultSanitizeFileName,
9595
sourcemap: config.sourcemap || false,
9696
sourcemapBaseUrl: getSourcemapBaseUrl(config),
97+
sourcemapDebugIds: config.sourcemapDebugIds || false,
9798
sourcemapExcludeSources: config.sourcemapExcludeSources || false,
9899
sourcemapFile: config.sourcemapFile,
99100
sourcemapFileNames: getSourcemapFileNames(config, unsetOptions),

Diff for: src/utils/renderChunks.ts

+21
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ function addChunksToBundle(
347347
const finalFileName = replacePlaceholders(fileName, hashesByPlaceholder);
348348
let finalSourcemapFileName = null;
349349
if (map) {
350+
if (options.sourcemapDebugIds) {
351+
updatedCode += calculateDebugIdAndGetComment(updatedCode, map);
352+
}
350353
finalSourcemapFileName = sourcemapFileName
351354
? replacePlaceholders(sourcemapFileName, hashesByPlaceholder)
352355
: `${finalFileName}.map`;
@@ -365,6 +368,9 @@ function addChunksToBundle(
365368
hashesByPlaceholder.size > 0 ? replacePlaceholders(code, hashesByPlaceholder) : code;
366369
let finalSourcemapFileName = null;
367370
if (map) {
371+
if (options.sourcemapDebugIds) {
372+
updatedCode += calculateDebugIdAndGetComment(updatedCode, map);
373+
}
368374
finalSourcemapFileName = sourcemapFileName
369375
? replacePlaceholders(sourcemapFileName, hashesByPlaceholder)
370376
: `${fileName}.map`;
@@ -402,3 +408,18 @@ function emitSourceMapAndGetComment(
402408
}
403409
return sourcemap === 'hidden' ? '' : `//# ${SOURCEMAPPING_URL}=${url}\n`;
404410
}
411+
412+
function calculateDebugIdAndGetComment(code: string, map: SourceMap & { debugId?: string }) {
413+
const hash = hasherByType.hex(code);
414+
const debugId = [
415+
hash.slice(0, 8),
416+
hash.slice(8, 12),
417+
'4' + hash.slice(12, 15),
418+
((parseInt(hash.slice(15, 16), 16) & 3) | 8).toString(16) + hash.slice(17, 20),
419+
hash.slice(20, 32)
420+
].join('-');
421+
422+
map.debugId = debugId;
423+
424+
return '//# debugId=' + debugId + '\n';
425+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
define(['./dep-9748f597e7f841'], (function (dep) { 'use strict';
2+
3+
console.log('main1');
4+
5+
}));

Diff for: test/chunking-form/samples/hashing/base-16/_expected/amd/main1-c7c1549b.js

-5
This file was deleted.

Diff for: test/chunking-form/samples/hashing/base-16/_expected/amd/main2-b28d1351.js

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
define(['./dep-9748f597e7f841'], (function (dep) { 'use strict';
2+
3+
console.log('main2');
4+
5+
}));
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
22

3-
require('./dep-56610f0f1f4a63.js');
3+
require('./dep-8e72f6a548dc1a.js');
44

55
console.log('main1');
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
22

3-
require('./dep-56610f0f1f4a63.js');
3+
require('./dep-8e72f6a548dc1a.js');
44

55
console.log('main2');

Diff for: test/chunking-form/samples/hashing/base-16/_expected/es/main1-2ba5365c.js

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './dep-ea4271148a0859.js';
2+
3+
console.log('main1');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './dep-ea4271148a0859.js';
2+
3+
console.log('main2');

Diff for: test/chunking-form/samples/hashing/base-16/_expected/es/main2-c2fcf802.js

-3
This file was deleted.

Diff for: test/chunking-form/samples/hashing/base-16/_expected/system/main1-0b232646.js renamed to test/chunking-form/samples/hashing/base-16/_expected/system/main1-9428b54c.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
System.register(['./dep-bacfaa81397007.js'], (function () {
1+
System.register(['./dep-fc1ce55215e47e.js'], (function () {
22
'use strict';
33
return {
44
setters: [null],

Diff for: test/chunking-form/samples/hashing/base-16/_expected/system/main2-83b1318a.js renamed to test/chunking-form/samples/hashing/base-16/_expected/system/main2-bae4f47a.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
System.register(['./dep-bacfaa81397007.js'], (function () {
1+
System.register(['./dep-fc1ce55215e47e.js'], (function () {
22
'use strict';
33
return {
44
setters: [null],

Diff for: test/function/samples/output-options-hook/_config.js

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module.exports = defineTest({
5757
preserveModules: false,
5858
reexportProtoFromExternal: true,
5959
sourcemap: false,
60+
sourcemapDebugIds: false,
6061
sourcemapExcludeSources: false,
6162
strict: true,
6263
systemNullSetters: true,

Diff for: test/misc/misc.js

+14
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,18 @@ console.log(x);
318318
await bundle.generate({ format: 'iife', inlineDynamicImports: true });
319319
await bundle.generate({ format: 'es', exports: 'auto' });
320320
});
321+
322+
it('should support `Symbol.asyncDispose` of the rollup bundle and set closed state to true', async () => {
323+
const bundle = await rollup.rollup({
324+
input: 'main.js',
325+
plugins: [
326+
loader({
327+
'main.js': "console.log('hello')"
328+
})
329+
]
330+
});
331+
332+
await bundle[Symbol.asyncDispose]();
333+
assert.strictEqual(bundle.closed, true);
334+
});
321335
});

Diff for: test/misc/optionList.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)