Skip to content

Commit

Permalink
fix: more meaningful chunk filename (#381)
Browse files Browse the repository at this point in the history
<!-- Thank you for contributing! -->

### Description

Closes #49.

<!-- Please insert your description here and provide especially info about the "what" this PR is solving -->

### Test Plan

<!-- e.g. is there anything you'd like reviewers to focus on? -->

---
  • Loading branch information
hyf0 authored Dec 4, 2023
1 parent 6067e74 commit 47b4b6d
Show file tree
Hide file tree
Showing 26 changed files with 253 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ impl RuntimeNormalModuleTask {
builder.id = Some(self.module_id);
builder.ast = Some(ast);
builder.repr_name = Some(repr_name);
builder.path = Some(ResourceId::new(
"TODO: Runtime module should not have FilePath as source id".to_string().into(),
));
// TODO: Runtime module should not have FilePath as source id
builder.path = Some(ResourceId::new("runtime".to_string().into()));
builder.named_imports = Some(named_imports);
builder.named_exports = Some(named_exports);
builder.stmt_infos = Some(stmt_infos);
Expand Down
4 changes: 1 addition & 3 deletions crates/rolldown/src/bundler/stages/bundle_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,7 @@ impl<'a> BundleStage<'a> {
chunks[chunk_id].modules.push(module.id());
module_to_chunk[module.id()] = Some(chunk_id);
} else {
let len = bits_to_chunk.len();
// FIXME: https://github.com/rolldown-rs/rolldown/issues/49
let chunk = Chunk::new(Some(len.to_string()), None, bits.clone(), vec![module.id()]);
let chunk = Chunk::new(None, None, bits.clone(), vec![module.id()]);
let chunk_id = chunks.push(chunk);
module_to_chunk[module.id()] = Some(chunk_id);
bits_to_chunk.insert(bits.clone(), chunk_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ input_file: crates/rolldown/tests/esbuild/default/duplicate_entry_point
---
# Assets

## 2.mjs
## entry_js.mjs

```js
// entry.js
console.log(123)
```
## entry_js.mjs

```js
```
## entry_js.mjs
## runtime.mjs

```js
// entry.js
console.log(123)
```
10 changes: 5 additions & 5 deletions crates/rolldown/tests/esbuild/default/outbase/artifacts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ input_file: crates/rolldown/tests/esbuild/default/outbase
---
# Assets

## 2.mjs

```js
```
## c_js.mjs

```js
Expand All @@ -22,3 +17,8 @@ console.log('c')
// d.js
console.log('d')
```
## runtime.mjs

```js
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ input_file: crates/rolldown/tests/esbuild/default/var_relocating_bundle
---
# Assets

## 5.mjs

```js
```
## function-nested_js.mjs

```js
Expand Down Expand Up @@ -76,6 +71,11 @@ if (true) {
for (var { j, x: [k] } in {});
function l() {}
}
```
## runtime.mjs
```js

```
## top-level_js.mjs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@ input_file: crates/rolldown/tests/esbuild/splitting/assign-to-local
---
# Assets

## 2.mjs

```js
// shared.js
let foo
function setFoo(value) {
foo = value
}
export { foo, setFoo };
```
## a.mjs

```js
import { foo, setFoo } from "./2.mjs";
import { foo, setFoo } from "./runtime.mjs";
// a.js
Expand All @@ -28,9 +18,19 @@ console.log(foo)
## b.mjs

```js
import { foo } from "./2.mjs";
import { foo } from "./runtime.mjs";
// b.js
console.log(foo)
```
## runtime.mjs

```js
// shared.js
let foo
function setFoo(value) {
foo = value
}
export { foo, setFoo };
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@ input_file: crates/rolldown/tests/esbuild/splitting/cross_chunk_assignment_depen
---
# Assets

## 2.mjs
## a.mjs

```js
import { setValue } from "./runtime.mjs";
// a.js
setValue(123)
```
## b.mjs

```js
// b.js
```
## runtime.mjs

```js
// shared.js
Expand All @@ -24,17 +38,3 @@ function setValue(next) {
sideEffects(getValue);
export { setValue };
```
## a.mjs

```js
import { setValue } from "./2.mjs";
// a.js
setValue(123)
```
## b.mjs

```js
// b.js
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@ input_file: crates/rolldown/tests/esbuild/splitting/duplicate_chunk_collision
---
# Assets

## 4.mjs
## a.mjs

```js
// a.js
```
## 5.mjs
## ab_js.mjs

```js
// cd.js
// ab.js
console.log(123)
// d.js
```
## 6.mjs
## b.mjs

```js
// ab.js
console.log(123)
// b.js
```
## a.mjs
## cd_js.mjs

```js
// a.js
// cd.js
console.log(123)
// d.js
```
## b.mjs
## d.mjs

```js
// b.js
```
## d.mjs

```js
```
## d.mjs
## runtime.mjs

```js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,10 @@ input_file: crates/rolldown/tests/esbuild/splitting/dynamic-commonjs-into-es6
---
# Assets

## 2.mjs

```js
// <runtime>
var __getOwnPropNames = Object.getOwnPropertyNames
var __commonJS = (cb, mod) => function () {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports
}
export { __commonJS };
```
## foo_js.mjs

```js
import { __commonJS } from "./2.mjs";
import { __commonJS } from "./runtime.mjs";
// foo.js
var require_foo = __commonJS({
Expand All @@ -36,3 +24,15 @@ export default require_foo();
// main.js
import('./foo_js.mjs').then(({bar}) => console.log(bar))
```
## runtime.mjs

```js
// <runtime>
var __getOwnPropNames = Object.getOwnPropertyNames
var __commonJS = (cb, mod) => function () {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports
}
export { __commonJS };
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ input_file: crates/rolldown/tests/esbuild/splitting/dynamic-es6-into-es6
---
# Assets

## 2.mjs

```js
```
## foo_js.mjs

```js
Expand All @@ -23,3 +18,8 @@ export { bar };
// main.js
import('./foo_js.mjs').then(({bar}) => console.log(bar))
```
## runtime.mjs

```js
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ input_file: crates/rolldown/tests/esbuild/splitting/dynamic_and_not_dynamic_es6_
---
# Assets

## 2.mjs

```js
// foo.js
let bar = 123
export { bar };
```
## foo_js.mjs

```js
import { bar } from "./2.mjs";
import { bar } from "./runtime.mjs";
export { bar };
```
## main.mjs

```js
import { bar } from "./2.mjs";
import { bar } from "./runtime.mjs";
// main.js
import('./2.mjs').then(({bar: b}) => console.log(bar, b))
import('./runtime.mjs').then(({bar: b}) => console.log(bar, b))
```
## runtime.mjs

```js
// foo.js
let bar = 123
export { bar };
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ input_file: crates/rolldown/tests/esbuild/splitting/dynamic_import_issue_272
---
# Assets

## 2.mjs

```js
```
## a.mjs

```js
Expand All @@ -23,3 +18,8 @@ import('./b.mjs')
var b_default = 1
export { b_default as default };
```
## runtime.mjs

```js
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@ input_file: crates/rolldown/tests/esbuild/splitting/hybrid_esm_and_cjs_issue617
---
# Assets

## 2.mjs
## a.mjs

```js
import { foo } from "./runtime.mjs";
export { foo };
```
## b.mjs

```js
import { __toCommonJS, a_ns, init_a } from "./runtime.mjs";
// b.js
let bar = (init_a(), __toCommonJS(a_ns))
export { bar };
```
## runtime.mjs

```js
// <runtime>
Expand Down Expand Up @@ -40,19 +56,3 @@ var init_a = __esm({
});
export { __toCommonJS, a_ns, foo, init_a };
```
## a.mjs
```js
import { foo } from "./2.mjs";
export { foo };
```
## b.mjs
```js
import { __toCommonJS, a_ns, init_a } from "./2.mjs";
// b.js
let bar = (init_a(), __toCommonJS(a_ns))
export { bar };
```
Loading

0 comments on commit 47b4b6d

Please sign in to comment.