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

allow load plugin result with empty loader to have null contents #3532

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions internal/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,11 +1035,12 @@ func runOnLoadPlugins(
}

// Otherwise, continue on to the next loader if this loader didn't succeed
if result.Contents == nil {
if result.Contents != nil {
source.Contents = *result.Contents
} else if result.Loader != config.LoaderEmpty {
continue
}

source.Contents = *result.Contents
loader := result.Loader
if loader == config.LoaderNone {
loader = config.LoaderJS
Expand Down
22 changes: 22 additions & 0 deletions scripts/plugin-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,28 @@ let pluginTests = {
assert.strictEqual(result.outputFiles[3].text, `// virtual-ns:input a/b/c.d.e\nconsole.log("input a/b/c.d.e");\n`)
},

async emptyLoaderNoContents({ esbuild, testDir }) {
const input = path.join(testDir, 'in.js')
const output = path.join(testDir, 'out.js')
await writeFileAsync(input, 'export default 123')
await esbuild.build({
entryPoints: [input],
bundle: true,
outfile: output,
format: 'cjs',
plugins: [{
name: 'name',
setup(build) {
build.onLoad({ filter: /\.js$/ }, args => {
return { loader: 'empty' }
})
},
}],
})
const result = await readFileAsync(output, 'utf-8')
assert.doesNotMatch(result, /123/);
},

async entryPointFileNamespace({ esbuild, testDir }) {
const input = path.join(testDir, 'in.js')
let worked = false
Expand Down