Skip to content

Commit

Permalink
chore: Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Dec 30, 2024
1 parent 95327c0 commit 4b34c4c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
11 changes: 5 additions & 6 deletions src/plugins/prerender-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
config.build.rollupOptions.output ??= {};
config.build.rollupOptions.output.manualChunks = (id) => {
if (id.includes(prerenderScript) || id.includes(preloadPolyfillId)) {
return "index";
return 'index';
}
};

Expand Down Expand Up @@ -240,10 +240,7 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere

// Create a tmp dir to allow importing & consuming the built modules,
// before Rollup writes them to the disk
const tmpDir = path.join(
viteConfig.root,
tmpDirRelative,
);
const tmpDir = path.join(viteConfig.root, tmpDirRelative);
try {
await fs.rm(tmpDir, { recursive: true });
} catch (e) {
Expand Down Expand Up @@ -300,7 +297,9 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
}
`.replace(/^\t{5}/gm, '');

const stack = StackTraceParse(e).find((s) => s.getFileName().includes(tmpDirRelative));
const stack = StackTraceParse(e).find((s) =>
s.getFileName().includes(tmpDirRelative),
);

const sourceMapContent = prerenderEntry.map;
if (stack && sourceMapContent) {
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/features/local-fetch/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export async function prerender() {
const res = await fetch('/local-fetch-test.txt')
const res = await fetch('/local-fetch-test.txt');
return await res.text();
}
6 changes: 3 additions & 3 deletions tests/fixtures/source-maps/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if (typeof window !== "undefined") {
const worker = new Worker(new URL("./worker.js", import.meta.url));
if (typeof window !== 'undefined') {
const worker = new Worker(new URL('./worker.js', import.meta.url));

worker.postMessage({ type: "init" });
worker.postMessage({ type: 'init' });
}

export async function prerender() {
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/source-maps/src/worker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addEventListener('message', (e) => {
postMessage({ type: 'init' });
})
});
5 changes: 4 additions & 1 deletion tests/prerender-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ test('Should stringify returned `data` object', async () => {
await viteBuild(env.tmp.path);

const prerenderedHtml = await getOutputFile(env.tmp.path, 'index.html');
assert.match(prerenderedHtml, '<script type="application/json" id="prerender-data">{"foo":"bar"}</script>');
assert.match(
prerenderedHtml,
'<script type="application/json" id="prerender-data">{"foo":"bar"}</script>',
);
});

test('Should support `head.lang` property', async () => {
Expand Down
18 changes: 11 additions & 7 deletions tests/source-maps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ test('Should strip sourcemaps by default', async () => {

assert.not.ok(outDirAssets.find((f) => f.endsWith('.map')));


const outputChunk = path.join(outDir, outDirAssets.find((f) => /^index-.*\.js$/.test(f)));
const outputChunk = path.join(
outDir,
outDirAssets.find((f) => /^index-.*\.js$/.test(f)),
);
const outputChunkCode = await fs.readFile(outputChunk, 'utf-8');
assert.is(outputChunkCode.match(/\/\/#\ssourceMappingURL=(.*)/), null)
assert.is(outputChunkCode.match(/\/\/#\ssourceMappingURL=(.*)/), null);

const outputAsset = path.join(outDir, outDirAssets.find((f) => /^worker-.*\.js$/.test(f)));
const outputAsset = path.join(
outDir,
outDirAssets.find((f) => /^worker-.*\.js$/.test(f)),
);
const outputAssetSource = await fs.readFile(outputAsset, 'utf-8');
assert.is(outputAssetSource.match(/\/\/#\ssourceMappingURL=(.*)/), null)
assert.is(outputAssetSource.match(/\/\/#\ssourceMappingURL=(.*)/), null);
});

test('Should preserve sourcemaps if user has enabled them', async () => {
Expand Down Expand Up @@ -68,7 +73,7 @@ test('Should use sourcemaps to display error positioning when possible', async (
document.createElement('div');
export async function prerender() {
return '<h1>Simple Test Result</h1>';
}`
}`,
);

let message = '';
Expand All @@ -83,4 +88,3 @@ test('Should use sourcemaps to display error positioning when possible', async (
});

test.run();

0 comments on commit 4b34c4c

Please sign in to comment.