Skip to content

Commit

Permalink
fix #617
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Jun 17, 2024
1 parent 944c579 commit dafadcc
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Go to the `v1` branch to see the changelog of Lume 1.

## [2.2.2] - Unreleased
### Fixed
- esbuild plugin: Fixed `basename` support [#617].
- Apply `mergedKeys` configuration in layouts [#618].
- Extended Preact types with Lume's custom attributes [#619].
- Hot reload: Ensure sockets are open before send updates [#614], [#615].
Expand Down Expand Up @@ -411,6 +412,7 @@ Go to the `v1` branch to see the changelog of Lume 1.
[#610]: https://github.com/lumeland/lume/issues/610
[#614]: https://github.com/lumeland/lume/issues/614
[#615]: https://github.com/lumeland/lume/issues/615
[#617]: https://github.com/lumeland/lume/issues/617
[#618]: https://github.com/lumeland/lume/issues/618
[#619]: https://github.com/lumeland/lume/issues/619

Expand Down
9 changes: 7 additions & 2 deletions plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,13 @@ export default function (userOptions?: Options) {
const url = normalizePath(
normalizePath(file.path).replace(basePath, ""),
);

const urlWithoutExt = pathWithoutExtension(url);
const entryPoint = pages.find((page) => {
const outdir = posix.join(
"/",
options.options.outdir || ".",
pathWithoutExtension(page.data.url),
pathWithoutExtension(page.sourcePath),
);

return outdir === urlWithoutExt;
Expand All @@ -263,7 +264,11 @@ export default function (userOptions?: Options) {

// The page is an entry point
if (entryPoint) {
entryPoint.data.url = url; // Update the url to .js extension
entryPoint.data.url = posix.join(
"/",
options.options.outdir || ".",
replaceExtension(entryPoint.data.url, ".js"),
);
saveAsset(site, entryPoint, content, map?.text);
} else {
// The page is a chunk
Expand Down
2 changes: 1 addition & 1 deletion plugins/source_maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function prepareAsset(site: Site, page: Page): PrepareResult {
? page.data.sourceMap as SourceMap | undefined
: undefined;
const filename = page.src.path
? site.src(page.src.path + page.src.ext)
? site.src(page.sourcePath)
: site.src(page.outputPath);
return { content, sourceMap, filename, enableSourceMap };
}
Expand Down
60 changes: 60 additions & 0 deletions tests/__snapshots__/esbuild.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ snapshot[`esbuild plugin 1`] = `
"/main.vto",
"/modules",
"/modules/to_uppercase.ts",
"/other",
"/other.ts",
"/other/_data.yml",
"/other/script.ts",
],
}
`;
Expand Down Expand Up @@ -240,6 +243,33 @@ document.querySelectorAll(".other")?.forEach((el) => {
remote: undefined,
},
},
{
content: 'console.log("Hello from script.ts!");
',
data: {
basename: "script",
content: 'console.log("Hello from script.ts!")',
date: [],
mergedKeys: [
"tags",
],
page: [
"src",
"data",
"asset",
],
paginate: "paginate",
search: [],
tags: "Array(0)",
url: "/foo/bar/script.js",
},
src: {
asset: true,
ext: ".ts",
path: "/other/script",
remote: undefined,
},
},
]
`;

Expand Down Expand Up @@ -358,7 +388,10 @@ snapshot[`esbuild plugin with splitting as true 1`] = `
"/main.vto",
"/modules",
"/modules/to_uppercase.ts",
"/other",
"/other.ts",
"/other/_data.yml",
"/other/script.ts",
],
}
`;
Expand Down Expand Up @@ -502,6 +535,33 @@ document.querySelectorAll(".other")?.forEach((el) => {
remote: undefined,
},
},
{
content: 'console.log("Hello from script.ts!");
',
data: {
basename: "script",
content: 'console.log("Hello from script.ts!")',
date: [],
mergedKeys: [
"tags",
],
page: [
"src",
"data",
"asset",
],
paginate: "paginate",
search: [],
tags: "Array(0)",
url: "/foo/foo/bar/script.js",
},
src: {
asset: true,
ext: ".ts",
path: "/other/script",
remote: undefined,
},
},
]
`;

Expand Down
1 change: 1 addition & 0 deletions tests/assets/esbuild/other/_data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
basename: "/foo/bar"
1 change: 1 addition & 0 deletions tests/assets/esbuild/other/script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello from script.ts!");

0 comments on commit dafadcc

Please sign in to comment.