feat(publish): auto-localize Leaflet CDN to platform assets
Memind CI / Test, build, and release guards (push) Failing after 3m57s
Memind CI / Test, build, and release guards (push) Failing after 3m57s
Ship Leaflet 1.9.4 under public/assets/leaflet and rewrite common CDN script/stylesheet URLs during publish and public HTML delivery, matching the existing Chart.js guard pattern. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,7 +3,9 @@ import test from 'node:test';
|
||||
import {
|
||||
findExternalScriptSources,
|
||||
isExternalScriptSrc,
|
||||
rewriteKnownCdnAssetSources,
|
||||
rewriteKnownCdnScriptSources,
|
||||
rewriteKnownCdnStylesheetSources,
|
||||
} from './mindspace-published-script-localize.mjs';
|
||||
|
||||
test('isExternalScriptSrc detects http and protocol-relative urls', () => {
|
||||
@@ -36,3 +38,41 @@ test('findExternalScriptSources lists unresolved external scripts only', () => {
|
||||
const rewritten = rewriteKnownCdnScriptSources(source).html;
|
||||
assert.deepEqual(findExternalScriptSources(rewritten), ['https://cdn.example.com/app.js']);
|
||||
});
|
||||
|
||||
test('rewriteKnownCdnStylesheetSources rewrites leaflet css cdn urls to platform asset', () => {
|
||||
const source = `<!doctype html><html><head>
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
|
||||
<link href="//cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="/assets/local.css">
|
||||
</head><body></body></html>`;
|
||||
const result = rewriteKnownCdnStylesheetSources(source);
|
||||
assert.equal(result.rewrittenCount, 2);
|
||||
assert.match(result.html, /href="\/assets\/leaflet\/leaflet\.css"/g);
|
||||
assert.doesNotMatch(result.html, /unpkg\.com\/leaflet/);
|
||||
assert.doesNotMatch(result.html, /cdn\.jsdelivr\.net\/npm\/leaflet/);
|
||||
assert.match(result.html, /href="\/assets\/local\.css"/);
|
||||
});
|
||||
|
||||
test('rewriteKnownCdnScriptSources rewrites leaflet js cdn urls to platform asset', () => {
|
||||
const source = `<!doctype html><html><body>
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
</body></html>`;
|
||||
const result = rewriteKnownCdnScriptSources(source);
|
||||
assert.equal(result.rewrittenCount, 2);
|
||||
assert.match(result.html, /src="\/assets\/leaflet\/leaflet\.js"/g);
|
||||
assert.doesNotMatch(result.html, /unpkg\.com\/leaflet/);
|
||||
});
|
||||
|
||||
test('rewriteKnownCdnAssetSources rewrites leaflet css and js together', () => {
|
||||
const source = `<!doctype html><html><head>
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
|
||||
</head><body>
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
</body></html>`;
|
||||
const result = rewriteKnownCdnAssetSources(source);
|
||||
assert.equal(result.rewrittenCount, 2);
|
||||
assert.match(result.html, /href="\/assets\/leaflet\/leaflet\.css"/);
|
||||
assert.match(result.html, /src="\/assets\/leaflet\/leaflet\.js"/);
|
||||
assert.deepEqual(findExternalScriptSources(result.html), []);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user