Skip to content

Commit

Permalink
bug loading pages before processing them
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Jan 30, 2025
1 parent bea92b6 commit e4eedaa
Show file tree
Hide file tree
Showing 7 changed files with 910 additions and 166 deletions.
10 changes: 6 additions & 4 deletions core/processors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ export default class Processors {

this.loadedExtensions.add(extension);

const toRemove: StaticFile[] = [];
for (const file of files) {
if (file.src.ext === extension) {
const page = await file.toPage();
const index = files.indexOf(file);
files.splice(index, 1);
pages.push(page);
pages.push(await file.toPage());
toRemove.push(file);
}
}
for (const file of toRemove) {
files.splice(files.indexOf(file), 1);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/source_maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function saveAsset(

// There's no source map
if (!sourceMap) {
page.content = content;
page.text = content;
return;
}

Expand Down Expand Up @@ -177,13 +177,13 @@ export function saveAsset(
sourceMap[dynamicSourcesSymbol] = sources;

if (!sources[file]) {
sources[file] = page.content as string;
sources[file] = page.text;
}
}

// Store the new content and source map
page.data.sourceMap = sourceMap;
page.content = content;
page.text = content;
}

function addSourceMap(url: string, sourceMap: string): string {
Expand Down
417 changes: 329 additions & 88 deletions tests/__snapshots__/esbuild.test.ts.snap

Large diffs are not rendered by default.

69 changes: 51 additions & 18 deletions tests/__snapshots__/lightningcss.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,7 @@ snapshot[`lightningcss plugin (only transform) 1`] = `
}
`;

snapshot[`lightningcss plugin (only transform) 2`] = `
[
{
entry: "/text.css",
flags: [],
outputPath: "/text.css",
},
]
`;
snapshot[`lightningcss plugin (only transform) 2`] = `[]`;

snapshot[`lightningcss plugin (only transform) 3`] = `
[
Expand Down Expand Up @@ -151,6 +143,30 @@ snapshot[`lightningcss plugin (only transform) 3`] = `
remote: undefined,
},
},
{
content: '@import "npm:[email protected]";.text{font-family:var(--font-family)}.text p{color:var(--color);box-shadow:0 0 .5em var(--background);backface-visibility:hidden}',
data: {
basename: "text",
mergedKeys: [
"tags",
],
page: [
"src",
"data",
"asset",
],
paginate: "paginate",
search: [],
tags: "Array(0)",
url: "/text.css",
},
src: {
asset: true,
ext: ".css",
path: "/text",
remote: undefined,
},
},
]
`;

Expand Down Expand Up @@ -269,15 +285,7 @@ snapshot[`lightningcss plugin (bundle mode) 1`] = `
}
`;

snapshot[`lightningcss plugin (bundle mode) 2`] = `
[
{
entry: "/text.css",
flags: [],
outputPath: "/text.css",
},
]
`;
snapshot[`lightningcss plugin (bundle mode) 2`] = `[]`;

snapshot[`lightningcss plugin (bundle mode) 3`] = `
[
Expand Down Expand Up @@ -306,5 +314,30 @@ snapshot[`lightningcss plugin (bundle mode) 3`] = `
remote: undefined,
},
},
{
content: "/*! modern-normalize v2.0.0 | MIT License | https://github.com/sindresorhus/modern-normalize */
*,:before,:after{box-sizing:border-box}html{-webkit-text-size-adjust:100%;tab-size:4;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Noto Sans,Ubuntu,Cantarell,Helvetica Neue,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;line-height:1.15}body{margin:0}hr{height:0;color:inherit}abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:100%;line-height:1.15}button,select{text-transform:none}button{-webkit-appearance:button}[type=button]{-webkit-appearance:button}[type=reset]{-webkit-appearance:button}[type=submit]{-webkit-appearance:button}::-moz-focus-inner{border-style:none;padding:0}:-moz-focusring{outline:1px dotted buttontext}:-moz-ui-invalid{box-shadow:none}legend{padding:0}progress{vertical-align:baseline}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}.text{font-family:var(--font-family)}.text p{color:var(--color);box-shadow:0 0 .5em var(--background);backface-visibility:hidden}",
data: {
basename: "text",
mergedKeys: [
"tags",
],
page: [
"src",
"data",
"asset",
],
paginate: "paginate",
search: [],
tags: "Array(0)",
url: "/text.css",
},
src: {
asset: true,
ext: ".css",
path: "/text",
remote: undefined,
},
},
]
`;
Loading

0 comments on commit e4eedaa

Please sign in to comment.