Skip to content

Commit

Permalink
add extensions to custom output paths for css
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Mar 29, 2021
1 parent 4774f8b commit 20e603a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
16 changes: 6 additions & 10 deletions internal/bundler/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,8 @@ func (c *linkerContext) pathRelativeToOutbase(
if outPath := c.entryPoints[entryPointBit].outputPath; outPath != "" {
// Use the configured output path if present
absPath = outPath
if !c.fs.IsAbs(outPath) {
absPath = c.fs.Join(c.options.AbsOutputBase, outPath)
if !c.fs.IsAbs(absPath) {
absPath = c.fs.Join(c.options.AbsOutputBase, absPath)
}
isCustomOutputPath = true
} else if file.source.KeyPath.Namespace != "file" {
Expand Down Expand Up @@ -898,14 +898,10 @@ func (c *linkerContext) pathRelativeToOutbase(
relDir = "/" + relDir
}

// Strip the file extension
ext := c.fs.Ext(baseName)
baseName = baseName[:len(baseName)-len(ext)]

// Only use this file extension if this is a custom output path. Otherwise
// use the standard one for this file type.
if isCustomOutputPath && ext != "" {
baseExt = ext
// Strip the file extension if the output path is an input file
if !isCustomOutputPath {
ext := c.fs.Ext(baseName)
baseName = baseName[:len(baseName)-len(ext)]
}
return
}
Expand Down
38 changes: 36 additions & 2 deletions scripts/js-api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,40 @@ console.log("success");
new Function(outputFiles[0].text)()
},

async automaticEntryPointOutputPathsWithDot({ esbuild, testDir }) {
const input = path.join(testDir, 'in.file.ts')
const css = path.join(testDir, 'file.css')
await writeFileAsync(input, `import './file.css'; console.log('test')`)
await writeFileAsync(css, `body { color: red }`)
var { outputFiles } = await esbuild.build({
entryPoints: [input],
outdir: testDir,
bundle: true,
write: false,
})
assert.strictEqual(outputFiles.length, 2)
assert.strictEqual(outputFiles[0].path, path.join(testDir, 'in.file.js'))
assert.strictEqual(outputFiles[1].path, path.join(testDir, 'in.file.css'))
},

async customEntryPointOutputPathsWithDot({ esbuild, testDir }) {
const input = path.join(testDir, 'in.file.ts')
const css = path.join(testDir, 'file.css')
await writeFileAsync(input, `import './file.css'; console.log('test')`)
await writeFileAsync(css, `body { color: red }`)
var { outputFiles } = await esbuild.build({
entryPoints: {
'out.test': input,
},
outdir: testDir,
bundle: true,
write: false,
})
assert.strictEqual(outputFiles.length, 2)
assert.strictEqual(outputFiles[0].path, path.join(testDir, 'out.test.js'))
assert.strictEqual(outputFiles[1].path, path.join(testDir, 'out.test.css'))
},

async customEntryPointOutputPathsRel({ esbuild, testDir }) {
const input1 = path.join(testDir, 'in1.js')
const input2 = path.join(testDir, 'in2.js')
Expand All @@ -2163,8 +2197,8 @@ console.log("success");
write: false,
})
assert.strictEqual(outputFiles.length, 2)
assert.strictEqual(outputFiles[0].path, path.join(testDir, 'entry', 'out', '5DNZWSYZ-1.cjs'))
assert.strictEqual(outputFiles[1].path, path.join(testDir, 'entry', 'out', 'ONX3RUSG-2.mjs'))
assert.strictEqual(outputFiles[0].path, path.join(testDir, 'entry', 'out', '55DD6UTG-1.cjs.js'))
assert.strictEqual(outputFiles[1].path, path.join(testDir, 'entry', 'out', 'PBNYN6W7-2.mjs.js'))
},

async customEntryPointOutputPathsAbs({ esbuild, testDir }) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugin-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ let pluginTests = {
assert.strictEqual(result.outputFiles[0].path, path.join(testDir, '1.js'))
assert.strictEqual(result.outputFiles[1].path, path.join(testDir, '2.js'))
assert.strictEqual(result.outputFiles[2].path, path.join(testDir, 'a_b.js'))
assert.strictEqual(result.outputFiles[3].path, path.join(testDir, 'a/b/c.d'))
assert.strictEqual(result.outputFiles[3].path, path.join(testDir, 'a/b/c.d.js'))
assert.strictEqual(result.outputFiles[0].text, `// virtual-ns:input 1\nconsole.log("input 1");\n`)
assert.strictEqual(result.outputFiles[1].text, `// virtual-ns:input 2\nconsole.log("input 2");\n`)
assert.strictEqual(result.outputFiles[2].text, `// virtual-ns:input a<>:"|?*b\nconsole.log('input a<>:"|?*b');\n`)
Expand Down

0 comments on commit 20e603a

Please sign in to comment.