Skip to content

Commit

Permalink
fix: correctly replace path sep with forward slash
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardocavazza committed Oct 29, 2022
1 parent e7fdd77 commit 921dd67
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-html/lib/collectAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function collectAsset($, element, attribute, options, helpers) {

const entryPoint = resolvedFile.path;
const file = await helpers.emitFile(entryPoint);
element.attr(attribute, file.path.replace(path.sep, '/'));
element.attr(attribute, file.path.split(path.sep).join('/'));

return {
...file,
Expand Down
4 changes: 2 additions & 2 deletions packages/esbuild-plugin-html/lib/collectIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ export async function collectIcon($, element, icon, rel, shortcut, options, help
if (icon.size === 196 && shortcut) {
const link = $('<link>');
link.attr('rel', 'shortcut icon');
link.attr('href', file.path.replace(path.sep, '/'));
link.attr('href', file.path.split(path.sep).join('/'));
link.insertBefore(element);
}

const link = $('<link>');
link.attr('rel', rel);
link.attr('sizes', `${icon.size}x${icon.size}`);
link.attr('href', file.path.replace(path.sep, '/'));
link.attr('href', file.path.split(path.sep).join('/'));
link.insertBefore(element);

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-html/lib/collectScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function collectScreen($, element, screen, options, helpers) {
const link = $('<link>');
link.attr('rel', 'apple-touch-startup-image');
link.attr('media', screen.query);
link.attr('href', file.path.replace(path.sep, '/'));
link.attr('href', file.path.split(path.sep).join('/'));
link.insertBefore(element);

return {
Expand Down
6 changes: 3 additions & 3 deletions packages/esbuild-plugin-html/lib/collectScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ async function innerCollect($, dom, elements, target, format, type, attrs = {},
const relativeOutName = path.relative(options.entryDir, fullOutName);

if ($(element).attr('src')) {
$(element).attr('src', relativeOutName.replace(path.sep, '/'));
$(element).attr('src', relativeOutName.split(path.sep).join('/'));
$(element).html('');
} else {
$(element).html(`import './${relativeOutName.replace(path.sep, '/')}'`);
$(element).html(`import './${relativeOutName.split(path.sep).join('/')}'`);
}
$(element).removeAttr('type').attr('type', type);
for (const attrName in attrs) {
Expand All @@ -109,7 +109,7 @@ function loadStyle(url) {
${styleFiles.map((outName) => {
const fullOutFile = path.join(options.workingDir, outName);
const relativeOutFile = path.relative(options.entryDir, fullOutFile);
return `loadStyle('${relativeOutFile.replace(path.sep, '/')}');`;
return `loadStyle('${relativeOutFile.split(path.sep).join('/')}');`;
}).join('\n')}
}());`);
dom.find('head').append(script);
Expand Down
4 changes: 2 additions & 2 deletions packages/esbuild-plugin-html/lib/collectStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export async function collectStyles($, dom, options, helpers) {
const relativeOutName = path.relative(options.entryDir, fullOutName);

if ($(element).is('link')) {
$(element).attr('href', relativeOutName.replace(path.sep, '/'));
$(element).attr('href', relativeOutName.split(path.sep).join('/'));
} else {
$(element).html(`@import '${relativeOutName.replace(path.sep, '/')}'`);
$(element).html(`@import '${relativeOutName.split(path.sep).join('/')}'`);
}
});

Expand Down
4 changes: 2 additions & 2 deletions packages/esbuild-plugin-html/lib/collectWebManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export async function collectWebManifest($, dom, options, helpers) {
const contents = await generateIcon(image, size, 0, { r: 255, g: 255, b: 255, a: 1 });
const result = await helpers.emitFile(name, contents);
return {
src: path.relative(manifestOutputDir, result.filePath).replace(path.sep, '/'),
src: path.relative(manifestOutputDir, result.filePath).split(path.sep).join('/'),
sizes: `${size}x${size}`,
type: 'image/png',
};
Expand All @@ -131,7 +131,7 @@ export async function collectWebManifest($, dom, options, helpers) {

const file = await helpers.emitFile(entryPoint, JSON.stringify(json, null, 2));

$(element).attr('href', file.path.replace(path.sep, '/'));
$(element).attr('href', file.path.split(path.sep).join('/'));

return [{
...file,
Expand Down
18 changes: 9 additions & 9 deletions packages/esbuild-plugin-html/test/test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ html {

expect(outputFiles).to.have.lengthOf(17);

expect(index.path).endsWith('/out/index.manifest.html');
expect(index.path).endsWith(path.join(path.sep, 'out', 'index.manifest.html'));
expect(index.text).to.be.equal(`<!DOCTYPE html>
<html lang="en">
Expand All @@ -806,12 +806,12 @@ html {
</html>`);

expect(icons).to.have.lengthOf(9);
expect(icons[0].path).endsWith('/out/assets/android-chrome-36x36.png');
expect(icons[0].path).endsWith(path.join(path.sep, 'out', 'assets', 'android-chrome-36x36.png'));
expect(icons[0].contents.byteLength).to.be.equal(1135);
expect(icons[8].path).endsWith('/out/assets/android-chrome-512x512.png');
expect(icons[8].path).endsWith(path.join(path.sep, 'out', 'assets', 'android-chrome-512x512.png'));
expect(icons[8].contents.byteLength).to.be.equal(24012);

expect(manifest.path).endsWith('/out/assets/manifest.webmanifest');
expect(manifest.path).endsWith(path.join(path.sep, 'out', 'assets', 'manifest.webmanifest'));
expect(manifest.text).to.be.equal(`{
"name": "Document",
"short_name": "Document",
Expand Down Expand Up @@ -893,7 +893,7 @@ html {
const css = files.find((file) => file.path.endsWith('.css'));

expect(outputFiles).to.have.lengthOf(3);
expect(index.path).endsWith('/out/fixture/index.iife.html');
expect(index.path).endsWith(path.join(path.sep, 'out', 'fixture', 'index.iife.html'));
expect(index.text).to.be.equal(`<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -921,8 +921,8 @@ html {
</html>`);

expect(js.path).endsWith('/out/index.js');
expect(css.path).endsWith('/out/index.css');
expect(js.path).endsWith(path.join(path.sep, 'out', 'index.js'));
expect(css.path).endsWith(path.join(path.sep, 'out', 'index.css'));
});

it('should bundle webapp with [dir] without outbase', async () => {
Expand Down Expand Up @@ -974,7 +974,7 @@ html {
</html>`);

expect(js.path).endsWith('/out/index.js');
expect(css.path).endsWith('/out/index.css');
expect(js.path).endsWith(path.join(path.sep, 'out', 'index.js'));
expect(css.path).endsWith(path.join(path.sep, 'out', 'index.css'));
});
});

0 comments on commit 921dd67

Please sign in to comment.