@barefootjs/vite 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/child-marker.d.ts +62 -0
- package/dist/child-marker.d.ts.map +1 -0
- package/dist/compile-cache.d.ts +19 -0
- package/dist/compile-cache.d.ts.map +1 -0
- package/dist/component-manifest.d.ts +69 -0
- package/dist/component-manifest.d.ts.map +1 -0
- package/dist/corpus-program.d.ts +41 -0
- package/dist/corpus-program.d.ts.map +1 -0
- package/dist/debounced-serial-runner.d.ts +27 -0
- package/dist/debounced-serial-runner.d.ts.map +1 -0
- package/dist/dev-server.d.ts +99 -0
- package/dist/dev-server.d.ts.map +1 -0
- package/dist/discover.d.ts +117 -0
- package/dist/discover.d.ts.map +1 -0
- package/dist/emit.d.ts +9 -0
- package/dist/emit.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24626 -0
- package/dist/manifest.d.ts +39 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/paths.d.ts +57 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/plugin.d.ts +5 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/resolve-client-js.d.ts +6 -0
- package/dist/resolve-client-js.d.ts.map +1 -0
- package/dist/types.d.ts +141 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +55 -0
- package/src/__tests__/child-marker.test.ts +24 -0
- package/src/__tests__/compile-cache.test.ts +73 -0
- package/src/__tests__/component-dir-entry.test.ts +239 -0
- package/src/__tests__/component-manifest.test.ts +124 -0
- package/src/__tests__/corpus-program.test.ts +244 -0
- package/src/__tests__/debounced-serial-runner.test.ts +131 -0
- package/src/__tests__/dev-server.test.ts +138 -0
- package/src/__tests__/discover.test.ts +148 -0
- package/src/__tests__/e2e-vite-build.test.ts +191 -0
- package/src/__tests__/e2e-vite-dev.test.ts +478 -0
- package/src/__tests__/emit.test.ts +73 -0
- package/src/__tests__/manifest.test.ts +146 -0
- package/src/__tests__/paths.test.ts +93 -0
- package/src/__tests__/plugin.test.ts +417 -0
- package/src/__tests__/relative-import-rewrite.test.ts +79 -0
- package/src/__tests__/resolve-client-js.test.ts +55 -0
- package/src/__tests__/templates-optional.test.ts +139 -0
- package/src/child-marker.ts +67 -0
- package/src/compile-cache.ts +63 -0
- package/src/component-manifest.ts +139 -0
- package/src/corpus-program.ts +125 -0
- package/src/debounced-serial-runner.ts +67 -0
- package/src/dev-server.ts +184 -0
- package/src/discover.ts +230 -0
- package/src/emit.ts +66 -0
- package/src/index.ts +25 -0
- package/src/manifest.ts +89 -0
- package/src/paths.ts +114 -0
- package/src/plugin.ts +792 -0
- package/src/resolve-client-js.ts +34 -0
- package/src/types.ts +144 -0
package/src/paths.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path helpers for mirroring a component's position under a configured
|
|
3
|
+
* `components` source dir into the `templates` output dir.
|
|
4
|
+
*
|
|
5
|
+
* Implemented standalone rather than by importing from `@barefootjs/cli`:
|
|
6
|
+
* that package's only published entry point is the `bf` binary, so
|
|
7
|
+
* importing it would pull in the whole CLI as a side effect.
|
|
8
|
+
*/
|
|
9
|
+
import { basename, dirname, relative, resolve, sep } from 'node:path'
|
|
10
|
+
|
|
11
|
+
/** Posix-normalized path of `absPath` relative to `root` (manifest keys and
|
|
12
|
+
* Rollup `input` specifiers both want forward slashes regardless of OS). */
|
|
13
|
+
export function toPosixRelative(root: string, absPath: string): string {
|
|
14
|
+
return relative(root, absPath).split(sep).join('/')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A `rollupOptions.input` OBJECT KEY safe for `absPath`, given the Vite
|
|
19
|
+
* project root — NOT the same thing as a manifest lookup key (Vite's own
|
|
20
|
+
* manifest is keyed by the source file's root-relative path regardless of
|
|
21
|
+
* what name you give an entry here; see `manifest.ts` / `writeBundle` in
|
|
22
|
+
* `plugin.ts`, which never call this and must not start).
|
|
23
|
+
*
|
|
24
|
+
* Rollup uses an object-form `input`'s key AS THE CHUNK NAME (the `[name]`
|
|
25
|
+
* substitution in `output.entryFileNames`), and REJECTS a name that is
|
|
26
|
+
* itself an absolute or parent-relative path outright
|
|
27
|
+
* (`Invalid substitution "…" for placeholder "[name]"`) — which
|
|
28
|
+
* `toPosixRelative(root, absPath)` produces whenever `absPath` is OUTSIDE
|
|
29
|
+
* `root`, exactly the common case this monorepo's real layouts hit (a
|
|
30
|
+
* `components` dir that's a SIBLING of, not a descendant of, the app's
|
|
31
|
+
* Vite root — see `plugin.ts`'s `configureServer` docstring for the same
|
|
32
|
+
* layout fact from the dev side). Falls back to `absPath`'s position under
|
|
33
|
+
* whichever configured `componentDirs` entry contains it (the same
|
|
34
|
+
* mirroring `relativeUnderComponentDir` already does for emitted template
|
|
35
|
+
* paths) — short and readable (`blog/LikeButton`), unlike falling all the
|
|
36
|
+
* way back to the bare filesystem-rooted absolute path, which would work
|
|
37
|
+
* (no `..` possible once `path.resolve()`-normalized) but bakes the
|
|
38
|
+
* building machine's own directory structure into every output filename.
|
|
39
|
+
*/
|
|
40
|
+
export function safeRollupEntryName(root: string, absPath: string, componentDirs: readonly string[]): string {
|
|
41
|
+
const rel = toPosixRelative(root, absPath)
|
|
42
|
+
if (!rel.startsWith('..')) return rel
|
|
43
|
+
return relativeUnderComponentDir(absPath, componentDirs)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* `absPath`'s position relative to whichever `componentDirs` entry
|
|
48
|
+
* contains it (POSIX, WITH extension) — e.g. `ui/button/index.tsx` for
|
|
49
|
+
* `<componentDir>/ui/button/index.tsx`. Falls back to the bare basename
|
|
50
|
+
* when the file isn't under any configured dir (shouldn't happen for
|
|
51
|
+
* discovered files, but keeps this total).
|
|
52
|
+
*/
|
|
53
|
+
export function relativeUnderComponentDir(absPath: string, componentDirs: readonly string[]): string {
|
|
54
|
+
for (const dir of componentDirs) {
|
|
55
|
+
if (absPath === dir) continue
|
|
56
|
+
if (absPath.startsWith(dir + sep)) {
|
|
57
|
+
return absPath.slice(dir.length + 1).split(sep).join('/')
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return basename(absPath)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Swap `.tsx`/`.ts` for `newExtension` (e.g. adapter.extension, or
|
|
64
|
+
* `.ssr-defaults.json`) on a POSIX relative path. */
|
|
65
|
+
export function withExtension(relPath: string, newExtension: string): string {
|
|
66
|
+
return relPath.replace(/\.tsx?$/, newExtension)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Output path (relative to `templatesDir`, still POSIX) for a
|
|
71
|
+
* `templatesPerComponent` adapter's per-component file — same directory as
|
|
72
|
+
* the source file's mirror, named after the exported component instead of
|
|
73
|
+
* the source basename (Mojolicious-style template lookup by component
|
|
74
|
+
* name).
|
|
75
|
+
*/
|
|
76
|
+
export function perComponentRelPath(relUnderComponentDir: string, componentName: string, extension: string): string {
|
|
77
|
+
const dir = dirname(relUnderComponentDir)
|
|
78
|
+
return dir === '.' ? `${componentName}${extension}` : `${dir}/${componentName}${extension}`
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Build a `rewriteRelativeImport` function for `compileJSX` — re-anchors a
|
|
83
|
+
* relative specifier written in `sourcePath` so it still resolves once the
|
|
84
|
+
* template is emitted to `outputPath` under `templatesDir` instead of
|
|
85
|
+
* living beside its source. Implemented standalone for the reason in this
|
|
86
|
+
* file's header comment. Only exercised by adapters whose templates carry
|
|
87
|
+
* real `import` statements (Hono-shaped JS-runtime adapters) — Go/Mojo/etc.
|
|
88
|
+
* templates have no import syntax and never call this.
|
|
89
|
+
*/
|
|
90
|
+
export function buildRelativeImportRewriter(
|
|
91
|
+
sourcePath: string,
|
|
92
|
+
outputPath: string,
|
|
93
|
+
componentDirs: readonly string[],
|
|
94
|
+
templatesDir: string,
|
|
95
|
+
): (importPath: string) => string {
|
|
96
|
+
const sourceDir = dirname(sourcePath)
|
|
97
|
+
const outputDir = dirname(outputPath)
|
|
98
|
+
|
|
99
|
+
return (importPath: string): string => {
|
|
100
|
+
const srcAbs = resolve(sourceDir, importPath)
|
|
101
|
+
let targetAbs = srcAbs
|
|
102
|
+
for (const componentDir of componentDirs) {
|
|
103
|
+
if (srcAbs === componentDir || srcAbs.startsWith(componentDir + sep)) {
|
|
104
|
+
const relUnderComponentDir = srcAbs === componentDir ? '' : srcAbs.slice(componentDir.length + 1)
|
|
105
|
+
targetAbs = relUnderComponentDir ? resolve(templatesDir, relUnderComponentDir) : templatesDir
|
|
106
|
+
break
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
let rewritten = relative(outputDir, targetAbs)
|
|
110
|
+
if (rewritten === '') rewritten = '.'
|
|
111
|
+
if (!rewritten.startsWith('.')) rewritten = './' + rewritten
|
|
112
|
+
return rewritten
|
|
113
|
+
}
|
|
114
|
+
}
|