Skip to content

Commit

Permalink
fixes for the "entryPoint" property feature (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Feb 23, 2021
1 parent b6f8b82 commit 8ab143a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
In this release, esbuild will now validate absolute paths in the resolver. So invalid paths will now fail in the resolver and retry without the parameter suffix instead of failing in the loader, which correctly handles a parameter suffix on absolute paths. In addition, this release now handles implicit file extensions on absolute paths. This makes esbuild a more accurate copy of [node's module resolution algorithm](https://nodejs.org/api/modules.html#modules_all_together), which does this as well.
* Output files in `metafile` now have `entryPoint` ([#711](https://github.com/evanw/esbuild/issues/711))
There is now an optional `entryPoint` property on each output file in the JSON metadata file generated with the `--metafile=` flag. It is only present for output files that are the bundled results of entry point files, and contains the path name of the corresponding input entry point file. This property is not present on other kinds of output files (e.g. code splitting chunks). This feature was contributed by [@remorses](https://github.com/remorses).
## 0.8.50
* Using direct `eval` now pulls in `module` and `exports`
Expand Down
16 changes: 15 additions & 1 deletion internal/bundler/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4159,7 +4159,21 @@ func (repr *chunkReprCSS) generate(c *linkerContext, chunk *chunkInfo) func(gene
if !isFirstMeta {
jMeta.AddString("\n ")
}
jMeta.AddString("],\n \"inputs\": {")
if chunk.isEntryPoint {
file := &c.files[chunk.sourceIndex]

// Do not generate "entryPoint" for CSS files that are the result of
// importing CSS into JavaScript. We want this to be a 1:1 relationship
// and there is already an output file for the JavaScript entry point.
if _, ok := file.repr.(*reprCSS); ok {
jMeta.AddString(fmt.Sprintf("],\n \"entryPoint\": %s,\n \"inputs\": {",
js_printer.QuoteForJSON(file.source.PrettyPath, c.options.ASCIIOnly)))
} else {
jMeta.AddString("],\n \"inputs\": {")
}
} else {
jMeta.AddString("],\n \"inputs\": {")
}
}
isFirstMeta := true

Expand Down
20 changes: 12 additions & 8 deletions scripts/js-api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ body {
const imported = path.join(testDir, 'imported.js')
const text = path.join(testDir, 'text.txt')
const css = path.join(testDir, 'example.css')
const output = path.join(testDir, 'out.js')
const outputJS = path.join(testDir, 'out.js')
const outputCSS = path.join(testDir, 'out.css')
const meta = path.join(testDir, 'meta.json')
await writeFileAsync(entry, `
import x from "./imported"
Expand All @@ -528,7 +529,7 @@ body {
await esbuild.build({
entryPoints: [entry],
bundle: true,
outfile: output,
outfile: outputJS,
metafile: meta,
sourcemap: true,
loader: { '.txt': 'file' },
Expand All @@ -555,14 +556,16 @@ body {
assert.deepStrictEqual(json.inputs[makePath(css)].imports, [])

// Check outputs
assert.strictEqual(typeof json.outputs[makePath(output)].bytes, 'number')
assert.strictEqual(typeof json.outputs[makePath(output) + '.map'].bytes, 'number')
assert.deepStrictEqual(json.outputs[makePath(output) + '.map'].imports, [])
assert.deepStrictEqual(json.outputs[makePath(output) + '.map'].exports, [])
assert.deepStrictEqual(json.outputs[makePath(output) + '.map'].inputs, {})
assert.strictEqual(typeof json.outputs[makePath(outputJS)].bytes, 'number')
assert.strictEqual(typeof json.outputs[makePath(outputJS) + '.map'].bytes, 'number')
assert.strictEqual(json.outputs[makePath(outputJS)].entryPoint, makePath(entry))
assert.strictEqual(json.outputs[makePath(outputCSS)].entryPoint, undefined) // This is deliberately undefined
assert.deepStrictEqual(json.outputs[makePath(outputJS) + '.map'].imports, [])
assert.deepStrictEqual(json.outputs[makePath(outputJS) + '.map'].exports, [])
assert.deepStrictEqual(json.outputs[makePath(outputJS) + '.map'].inputs, {})

// Check inputs for main output
const outputInputs = json.outputs[makePath(output)].inputs
const outputInputs = json.outputs[makePath(outputJS)].inputs
assert.strictEqual(Object.keys(outputInputs).length, 4)
assert.strictEqual(typeof outputInputs[makePath(entry)].bytesInOutput, 'number')
assert.strictEqual(typeof outputInputs[makePath(imported)].bytesInOutput, 'number')
Expand Down Expand Up @@ -990,6 +993,7 @@ body {
outputs: {
[makePath(output)]: {
bytes: 227,
entryPoint: makePath(entry),
imports: [],
inputs: {
[makePath(entry)]: { bytesInOutput: 62 },
Expand Down

0 comments on commit 8ab143a

Please sign in to comment.