Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use static as the asset dir name #1586

Merged
merged 3 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"stoppable": "^1.1.0",
"type-is": "^1.6.18",
"@unleash/express-openapi": "^0.2.0",
"unleash-frontend": "4.11.0-beta.0",
"unleash-frontend": "4.11.0-beta.1",
"uuid": "^8.3.2",
"semver": "^7.3.5"
},
Expand Down
37 changes: 7 additions & 30 deletions src/lib/util/rewriteHTML.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
import fs from 'fs';
import path from 'path';
import { rewriteHTML } from './rewriteHTML';
import { publicFolder } from 'unleash-frontend';

const input = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="::faviconPrefix::/favicon.ico" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="baseUriPath" content="::baseUriPath::" />
<meta name="cdnPrefix" content="::cdnPrefix::" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="unleash" />
<title>Unleash</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Sen:wght@400;700;800&display=swap"
rel="stylesheet"
/>
<script type="module" crossorigin src="/assets/index.556ac563.js"></script>
<link rel="stylesheet" href="/assets/index.4b6b260a.css">
</head>
<body>
<div id="app"></div>

</body>
</html>
`;
const input = fs.readFileSync(path.join(publicFolder, 'index.html')).toString();

test('rewriteHTML substitutes meta tag with existing rewrite value', () => {
const result = rewriteHTML(input, '/hosted');
Expand All @@ -46,23 +23,23 @@ test('rewriteHTML substitutes asset paths correctly with baseUriPath', () => {
const result = rewriteHTML(input, '/hosted');
expect(
result.includes(
'<script type="module" crossorigin src="/hosted/assets/index',
'<script type="module" crossorigin src="/hosted/static/index',
),
).toBe(true);
});

test('rewriteHTML substitutes asset paths correctly without baseUriPath', () => {
const result = rewriteHTML(input, '');
expect(
result.includes('<script type="module" crossorigin src="/assets/index'),
result.includes('<script type="module" crossorigin src="/static/index'),
).toBe(true);
});

test('rewriteHTML substitutes asset paths correctly with cdnPrefix', () => {
const result = rewriteHTML(input, '', 'https://cdn.getunleash.io/v4.1.0');
expect(
result.includes(
'<script type="module" crossorigin src="https://cdn.getunleash.io/v4.1.0/assets/index',
'<script type="module" crossorigin src="https://cdn.getunleash.io/v4.1.0/static/index',
),
).toBe(true);
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/util/rewriteHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const rewriteHTML = (
result = result.replace(/::faviconPrefix::/gi, faviconPrefix);

result = result.replace(
/\/assets/gi,
`${cdnPrefix || rewriteValue}/assets`,
/\/static/gi,
`${cdnPrefix || rewriteValue}/static`,
);

return result;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7466,10 +7466,10 @@ universalify@^2.0.0:
resolved "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==

unleash-frontend@4.11.0-beta.0:
version "4.11.0-beta.0"
resolved "https://registry.yarnpkg.com/unleash-frontend/-/unleash-frontend-4.11.0-beta.0.tgz#1e48bf66f15a4999c8efab19d214a975858ede7d"
integrity sha512-yNKzjGXUXPZgp+ihGdYphiDgeOzxN2mAslJnvFnGh15c7B2MBYeflf1DaHihcdwJTxhJsEucxE6cRucH/2DQOA==
unleash-frontend@4.11.0-beta.1:
version "4.11.0-beta.1"
resolved "https://registry.yarnpkg.com/unleash-frontend/-/unleash-frontend-4.11.0-beta.1.tgz#b93245488b5d8a143c8e17728e27b6005b917754"
integrity sha512-CSTG+mJyxxlNEBlGPzRxP8ExwbtFjE9IyB1JGV3X7YpsWXQDOxspB2/PZLUL0yAZhUrtbcg2I2hHhbp8ehVdCQ==

unpipe@1.0.0, unpipe@~1.0.0:
version "1.0.0"
Expand Down