Skip to content

Commit

Permalink
filename hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Mar 16, 2024
1 parent 154e06f commit 5f726b0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
27 changes: 11 additions & 16 deletions packages/cli/src/plugins/resource/plugin-standard-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,18 @@ function bundleCss(body, url, compilation) {
const hash = hashString(fs.readFileSync(new URL(`./${root}`, userWorkspace), 'utf-8'));
const ext = root.split('.').pop();
const hashedRoot = root.replace(`.${ext}`, `.${hash}.${ext}`);
const location = new URL(`./${root}`, userWorkspace);

if (url.href.startsWith(userWorkspace.href)) {
const location = new URL(`./${root}`, userWorkspace);
console.log({ location });
fs.mkdirSync(normalizePathnameForWindows(new URL(`./${path.dirname(root)}/`, outputDir)), {
recursive: true
});

fs.promises.copyFile(
location,
new URL(`./${hashedRoot}`, outputDir)
);

optimizedCss += `url('${basePath}${hashedRoot}')`;
} else {
// TODO
}
fs.mkdirSync(normalizePathnameForWindows(new URL(`./${path.dirname(root)}/`, outputDir)), {
recursive: true
});

fs.promises.copyFile(
location,
new URL(`./${hashedRoot}`, outputDir)
);

optimizedCss += `url('${basePath}${hashedRoot}')`;
}
} else if (type === 'Atrule' && name !== 'import') {
optimizedCss += `@${name} `;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,25 @@ describe('Build Greenwood With: ', function() {
expect(contents).to.contain(`body{background-color:green;background-image:url('/${imagePath}');}`);
});
});

describe('inline scratch dir workspace reference', () => {
const imagePath = 'images/link.1200825667.png';

it('should have the expected background image from the user\'s workspace the output directory', async function() {
expect(await glob.promise(path.join(this.context.publicDir, imagePath))).to.have.lengthOf(1);
});

it('should have the expected background-image url file bundle path in the referenced <style> tag in index.html', async function() {
const styleTag = Array.from(dom.window.document.querySelectorAll('head style'));

expect(styleTag[0].textContent).to.contain(`html{background-image:url('/${imagePath}')}`);
});
});
});
});
});

after(function() {
// runner.teardown(getOutputTeardownFiles(outputPath));
runner.teardown(getOutputTeardownFiles(outputPath));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('Serve Greenwood With: ', function() {
});

it('should return the correct response body', function(done) {
expect(body).to.contain('*{color:blue;background-image:url(\'/my-path/images/webcomponents.jpg\');}');
expect(body).to.contain('*{color:blue;background-image:url(\'/my-path/images/webcomponents.1079385342.jpg\');}');
done();
});
});
Expand Down

0 comments on commit 5f726b0

Please sign in to comment.