-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from dpikt/no-head
Refactor + update injection logic
- Loading branch information
Showing
12 changed files
with
87 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<body> | ||
<h1>Hello, world!</h1> | ||
</body> | ||
<script type="module"> | ||
import { hello } from './absolute-dep.js'; | ||
</script> | ||
|
||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { link } from '../src/inject.js'; | ||
import { describe, it } from 'node:test'; | ||
import fs from 'node:fs'; | ||
import assert from 'node:assert'; | ||
|
||
describe('link', () => { | ||
it('injects dependencies into HTML', async () => { | ||
const htmlUrl = new URL('./fixtures/link/index.html', import.meta.url) | ||
const result = await link(htmlUrl, { noFetch: true }) | ||
const expected = await fs.promises.readFile(new URL('./snapshots/link/index.snapshot.html', import.meta.url), 'utf8') | ||
assert.strictEqual(result, expected) | ||
}) | ||
it('injects dependencies to top of <html> if there is no <head> tag', async () => { | ||
const htmlUrl = new URL('./fixtures/link/no-head.html', import.meta.url) | ||
const result = await link(htmlUrl, { noFetch: true }) | ||
const expected = await fs.promises.readFile(new URL('./snapshots/link/no-head.snapshot.html', import.meta.url), 'utf8') | ||
assert.strictEqual(result, expected) | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>My HTML File</title> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"jquery": "https://cdn.skypack.dev/jquery" | ||
} | ||
} | ||
</script> | ||
<link rel="modulepreload" href="/js/dep.js" /> | ||
<link rel="modulepreload" href="/js/secondary-dep.js" /> | ||
<link rel="modulepreload" href="/absolute-dep.js" /> | ||
<link rel="modulepreload" href="https://cdn.skypack.dev/jquery" /> | ||
</head> | ||
|
||
<body> | ||
<h1>Hello, world!</h1> | ||
</body> | ||
<script type="module"> | ||
import { hello } from './js/dep.js'; | ||
</script> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<link rel="modulepreload" href="/absolute-dep.js" /> | ||
|
||
|
||
<body> | ||
<h1>Hello, world!</h1> | ||
</body> | ||
<script type="module"> | ||
import { hello } from './absolute-dep.js'; | ||
</script> | ||
|
||
</html> |