Skip to content

Commit e228a39

Browse files
committed
More notes.
1 parent 3c40286 commit e228a39

16 files changed

+142
-38
lines changed

main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (isDev) {
2424
})
2525
}
2626
else {
27-
generateFiles(await processSite())
27+
generateFiles(await processSite(), { parent: import.meta.dirname })
2828
}
2929

3030
async function processSite() {

package-lock.json

Lines changed: 100 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@types/markdown-it-attrs": "^4.1.3",
1313
"@types/markdown-it-container": "^2.0.10",
1414
"@types/node": "^22.15.9",
15-
"immaculata": "^2.0.1",
15+
"immaculata": "^2.2.1",
1616
"typescript": "^5.8.2"
1717
},
1818
"dependencies": {

site/public/api/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change log
22

3+
## 2.1.1
4+
5+
Fix type error.
6+
37
## 2.2.0
48

59
* Changed [new FileTree()](filetree.md#constructor) to take `meta.import.dirname` instead of `meta.import.url`

site/public/api/filetree.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
```ts
88
constructor(
99
path: string, // e.g. "site" or "."
10-
importMetaUrl: string,
10+
parentDir: string, // usually import.meta.dirname
1111
opts?: {
1212
exclude?: (path: string, stat: fs.Stats) => any,
1313
}
@@ -17,7 +17,7 @@ constructor(
1717
Loads the tree from disk into memory immediately.
1818

1919
```ts
20-
const tree = new FileTree('site', import.meta.url)
20+
const tree = new FileTree('site', import.meta.dirname)
2121
```
2222

2323

@@ -27,7 +27,7 @@ const tree = new FileTree('site', import.meta.url)
2727
public root: string
2828
```
2929

30-
The full file URL of the tree's root based on constructor's `path` and `importMetaUrl`.
30+
The full file URL of the tree's root, being constructor's `parentDir` + `path`
3131

3232
Never includes a trailing `'/'`
3333

@@ -51,7 +51,7 @@ type TreeFile = {
5151
A list of all files (recursively) at the given path.
5252
5353
```ts
54-
const tree = new FileTree('site', import.meta.url)
54+
const tree = new FileTree('site', import.meta.dirname)
5555

5656
// if cwd contains:
5757
// ./site/index.html
@@ -92,7 +92,7 @@ May be called more than once, which are no-ops that just return the same `EventE
9292
Uses `fs.watch` internally; groups multiple fs events into one via `debounce` (default `100` ms).
9393
9494
```ts
95-
const tree = new FileTree('site', import.meta.url)
95+
const tree = new FileTree('site', import.meta.dirname)
9696
tree.watch()
9797
```
9898

site/public/api/generate-files.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
```typescript
44
function generateFiles(
55
out: Map<string, Buffer | string>,
6-
dry = false,
7-
outDir = 'docs'
6+
opts: {
7+
parent: string,
8+
dry?: boolean, // default false
9+
dir?: string, // default 'docs'
10+
}
811
): void
912
```
1013

@@ -20,7 +23,7 @@ generateFiles(new Map([
2023
['/index.html', 'hello world'],
2124
['/about.html', 'about my site'],
2225
['/css/main.css', 'body{...}'],
23-
]))
26+
]), { parent: import.meta.dirname })
2427
2528
// writefile: docs/index.html
2629
// writefile: docs/about.html

site/public/api/module-hooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ are never stale modules.
7272
```ts
7373
import module from 'node:module'
7474
75-
const tree = new FileTree('site', import.meta.url)
75+
const tree = new FileTree('site', import.meta.dirname)
7676
7777
module.registerHooks(hooks.useTree(tree))
7878

site/public/api/pipeline.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ a `FileTree.files` into a map compatible with `DevServer`
1212
and `generateFiles`. You can just do this:
1313

1414
```ts
15-
const tree = new FileTree('site', import.meta.url)
15+
const tree = new FileTree('site', import.meta.dirname)
1616

1717
let files = tree.files.values().toArray()
1818

@@ -23,7 +23,7 @@ await Promise.all(files.forEach(async f => /* ... */))
2323

2424
const fileMap = new Map(files.map(f => [f.path, f.content]))
2525
server.files = fileMap
26-
generateFiles(fileMap)
26+
generateFiles(fileMap, { parent: import.meta.dirname })
2727
```
2828

2929
But that gets very inconvenient very quickly:
@@ -42,7 +42,7 @@ So the `Pipeline` class was created as a convenience.
4242
Here's the same code above with `Pipeline`:
4343

4444
```ts
45-
const tree = new FileTree('site', import.meta.url)
45+
const tree = new FileTree('site', import.meta.dirname)
4646

4747
const pipeline = Pipeline.from(tree.files)
4848

@@ -53,7 +53,7 @@ await pipeline.with(/.../).doAsync(f => /* ... */)
5353

5454
const fileMap = pipeline.results()
5555
server.files = fileMap
56-
generateFiles(fileMap)
56+
generateFiles(fileMap, { parent: import.meta.dirname })
5757
```
5858

5959
## API

site/public/blog/a-new-way-to-vendor.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ an out tree, transpiling and renaming as needed:
2020
```ts
2121
import { FileTree, generateFiles } from "immaculata"
2222

23-
const tree = new FileTree('site', import.meta.url)
23+
const tree = new FileTree('site', import.meta.dirname)
2424

2525
tree.watch().on('filesUpdated', process)
2626
process()
@@ -34,7 +34,8 @@ function process() {
3434
const out = new Map(files.map(f => [f.path, f.content]))
3535

3636
server.files = out // update dev server
37-
generateFiles(out) // or write to disk
37+
// or write to disk:
38+
generateFiles(out, { parent: import.meta.dirname })
3839
}
3940
```
4041

@@ -73,11 +74,11 @@ import { Head, Html, Main, Navbar, Sidebar } from "../template/core.tsx"
7374
import { md, type Env } from "./markdown.ts"
7475
import { tocToHtml } from './toc.ts'
7576

76-
const tree = new FileTree('site', import.meta.url)
77+
const tree = new FileTree('site', import.meta.dirname)
7778

78-
const martel = new FileTree('node_modules/@fontsource/martel', import.meta.url)
79-
const exo2 = new FileTree('node_modules/@fontsource-variable/exo-2', import.meta.url)
80-
const monda = new FileTree('node_modules/@fontsource-variable/monda', import.meta.url)
79+
const martel = new FileTree('node_modules/@fontsource/martel', import.meta.dirname)
80+
const exo2 = new FileTree('node_modules/@fontsource-variable/exo-2', import.meta.dirname)
81+
const monda = new FileTree('node_modules/@fontsource-variable/monda', import.meta.dirname)
8182

8283
export function processSite() {
8384
const files = Pipeline.from(tree.files)

site/public/blog/announcing-immaculata.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { FileTree, hooks } from 'immaculata'
1515
import { registerHooks } from 'module'
1616

1717
// keep an in-memory version of file tree under "./site"
18-
const tree = new FileTree('site', import.meta.url)
18+
const tree = new FileTree('site', import.meta.dirname)
1919

2020
// keep it up to date
2121
tree.watch().on('filesUpdated', reload)
@@ -141,7 +141,7 @@ registerHooks(hooks.mapImport('react/jsx-runtime', 'immaculata/dist/jsx-strings.
141141
registerHooks(hooks.mapImport('react/jsx-runtime', 'another-jsx-lib/jsx.js'))
142142

143143
// or bring your own impl
144-
export const tree = new FileTree('site', import.meta.url)
144+
export const tree = new FileTree('site', import.meta.dirname)
145145
registerHooks(hooks.mapImport('react/jsx-runtime', tree.root + '/myjsx.js'))
146146
```
147147

site/public/blog/hacking-nodejs-modules.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and optionally keep it updated with [tree.watch](../api/filetree.md#watch).
1616
```ts
1717
import { FileTree } from 'immaculata'
1818

19-
export const tree = new FileTree('site', import.meta.url)
19+
export const tree = new FileTree('site', import.meta.dirname)
2020

2121
// can now load files from memory rather than fs.readFileSync('site/style.css')
2222
tree.files.get('/style.css')
@@ -36,7 +36,7 @@ So I created the [useTree](../api/module-hooks.md#usetree) module hook that inva
3636
import { FileTree, hooks } from 'immaculata'
3737
import { registerHooks } from 'module'
3838

39-
export const tree = new FileTree('site', import.meta.url)
39+
export const tree = new FileTree('site', import.meta.dirname)
4040
registerHooks(hooks.useTree(tree))
4141

4242
tree.watch().on('filesUpdated', dostuff)

site/public/guides/enabling-hmr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { FileTree } from "immaculata"
2323
import { useTree } from "immaculata/hooks.js"
2424
import { registerHooks } from 'module'
2525

26-
const tree = new FileTree('site', import.meta.url)
26+
const tree = new FileTree('site', import.meta.dirname)
2727
registerHooks(useTree(tree))
2828

2929
const myModule = await import('site/myModule.js')

site/public/guides/enabling-jsx.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ To use a JSX implementatoin within a [FileTree](../api/filetree.md#filetree), pr
7373
import { FileTree, hooks } from "immaculata"
7474
import { registerHooks } from "module"
7575

76-
const tree = new FileTree('site', import.meta.url)
76+
const tree = new FileTree('site', import.meta.dirname)
7777

7878
registerHooks(hooks.mapImport('react/jsx-runtime', tree.root + '/my-jsx.ts'))
7979
~~~

site/public/guides/simple-build-tool.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { registerHooks } from 'module'
1919
import ts from 'typescript'
2020
import { fileURLToPath } from 'url'
2121

22-
const tree = new immaculata.FileTree('site', import.meta.url)
22+
const tree = new immaculata.FileTree('site', import.meta.dirname)
2323
registerHooks(hooks.useTree(tree))
2424
registerHooks(hooks.mapImport('react/jsx-runtime', 'immaculata/jsx-strings.js'))
2525
registerHooks(hooks.compileJsx(compileViaTypescript))
@@ -35,7 +35,7 @@ if (process.argv[2] === 'dev') {
3535
})
3636
}
3737
else {
38-
immaculata.generateFiles(await processSite())
38+
immaculata.generateFiles(await processSite(), { parent: import.meta.dirname })
3939
}
4040

4141
async function processSite() {

site/public/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { FileTree, hooks } from 'immaculata'
2929
import { registerHooks } from 'module'
3030

3131
// keep an in-memory version of file tree under "./src"
32-
const tree = new FileTree('src', import.meta.url)
32+
const tree = new FileTree('src', import.meta.dirname)
3333

3434
// invalidate modules under "src" when they change
3535
registerHooks(hooks.useTree(tree))

0 commit comments

Comments
 (0)