@inkandswitch/patchwork 0.7.1 → 0.7.2
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/CHANGELOG.md +17 -0
- package/dist/vite/static-plugin.d.ts +2 -1
- package/dist/vite/static-plugin.js +14 -3
- package/package.json +3 -3
- package/src/vite/static-plugin.ts +22 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @inkandswitch/patchwork
|
|
2
2
|
|
|
3
|
+
## 0.7.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e1374ad: Serve the `/packages/…` builtin URLs in dev. Import maps don't apply to worker
|
|
8
|
+
scripts, so code that starts one — `@automerge/automerge-repo`'s shared
|
|
9
|
+
subduction websocket worker, for instance — asks for the `/packages/…` path the
|
|
10
|
+
build emits. Nothing served those in dev, and the worker failed to fetch; the
|
|
11
|
+
dev server now redirects them to the same optimized dep the page's import map
|
|
12
|
+
points at.
|
|
13
|
+
- e1374ad: Say what's actually wrong when a `static` package declares a directory that
|
|
14
|
+
isn't there. The package resolved fine — its `"patchwork": {"static": …}` field
|
|
15
|
+
is what's wrong — and "static source not found" named neither the field nor the
|
|
16
|
+
path it pointed at. The error now quotes the declaration, gives the full path
|
|
17
|
+
that's missing, and says that a package publishing its static tree as the root
|
|
18
|
+
of its own tarball shouldn't set the field at all.
|
|
19
|
+
|
|
3
20
|
## 0.7.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -7,7 +7,8 @@ import type { PatchworkVitePluginOptions } from "./patchwork-plugin.js";
|
|
|
7
7
|
* `from` is either a package specifier or a path relative to the site root. A
|
|
8
8
|
* package says where its static tree lives with a `"patchwork": {"static":
|
|
9
9
|
* "static-dist"}` field in its own package.json; without one, the whole
|
|
10
|
-
* package directory is mounted
|
|
10
|
+
* package directory is mounted — which is what a package that publishes its
|
|
11
|
+
* static tree as the root of its own tarball wants.
|
|
11
12
|
*/
|
|
12
13
|
export interface PatchworkStaticSource {
|
|
13
14
|
from: string;
|
|
@@ -34,17 +34,28 @@ function packageDirectory(name, root) {
|
|
|
34
34
|
throw new Error(`[patchwork] can't find the package "${name}" — a static source has to be a dependency of the site`);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
/** A package's static tree: the directory it declares, or its root. */
|
|
38
|
+
function staticDirectory(name, directory) {
|
|
39
|
+
const declared = JSON.parse(readFileSync(join(directory, "package.json"), "utf8")).patchwork?.static;
|
|
40
|
+
if (!declared)
|
|
41
|
+
return directory;
|
|
42
|
+
const path = join(directory, declared);
|
|
43
|
+
if (!existsSync(path)) {
|
|
44
|
+
throw new Error(`[patchwork] ${name} declares "patchwork": {"static": ${JSON.stringify(declared)}}, but ${path} doesn't exist. ` +
|
|
45
|
+
`The field is a path inside the installed package — a package that publishes its static tree as the tarball's own root shouldn't set it at all.`);
|
|
46
|
+
}
|
|
47
|
+
return path;
|
|
48
|
+
}
|
|
37
49
|
export function resolveStatic(options, root) {
|
|
38
50
|
return (options.static ?? []).map((source) => {
|
|
39
51
|
const entry = typeof source === "string" ? { from: source } : source;
|
|
40
52
|
const isPath = entry.from.startsWith(".") || isAbsolute(entry.from);
|
|
41
53
|
const directory = isPath ? undefined : packageDirectory(entry.from, root);
|
|
42
54
|
const path = directory
|
|
43
|
-
?
|
|
44
|
-
.patchwork?.static ?? ".")
|
|
55
|
+
? staticDirectory(entry.from, directory)
|
|
45
56
|
: resolve(root, entry.from);
|
|
46
57
|
if (!existsSync(path)) {
|
|
47
|
-
throw new Error(`[patchwork] static source not found: ${entry.from}`);
|
|
58
|
+
throw new Error(`[patchwork] static source not found: ${entry.from} (${path})`);
|
|
48
59
|
}
|
|
49
60
|
const file = statSync(path).isFile();
|
|
50
61
|
const to = entry.to ?? "/";
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"url": "git+https://github.com/inkandswitch/patchwork-system.git",
|
|
6
6
|
"directory": "core/patchwork"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.7.
|
|
8
|
+
"version": "0.7.2",
|
|
9
9
|
"author": "Ink & Switch",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"license": "MIT",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"sharp": "^0.35.3",
|
|
45
45
|
"vite-plugin-wasm": "^3.6.0",
|
|
46
46
|
"@inkandswitch/patchwork-bootloader": "^0.6.2",
|
|
47
|
+
"@inkandswitch/patchwork-elements": "^6.0.0",
|
|
47
48
|
"@inkandswitch/patchwork-filesystem": "^0.2.5",
|
|
48
49
|
"@inkandswitch/patchwork-providers": "^0.5.0",
|
|
49
|
-
"@inkandswitch/patchwork-plugins": "^1.2.0"
|
|
50
|
-
"@inkandswitch/patchwork-elements": "^6.0.0"
|
|
50
|
+
"@inkandswitch/patchwork-plugins": "^1.2.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"rollup": "^4.61.1",
|
|
@@ -22,7 +22,8 @@ import type { PatchworkVitePluginOptions } from "./patchwork-plugin.js";
|
|
|
22
22
|
* `from` is either a package specifier or a path relative to the site root. A
|
|
23
23
|
* package says where its static tree lives with a `"patchwork": {"static":
|
|
24
24
|
* "static-dist"}` field in its own package.json; without one, the whole
|
|
25
|
-
* package directory is mounted
|
|
25
|
+
* package directory is mounted — which is what a package that publishes its
|
|
26
|
+
* static tree as the root of its own tarball wants.
|
|
26
27
|
*/
|
|
27
28
|
export interface PatchworkStaticSource {
|
|
28
29
|
from: string;
|
|
@@ -87,6 +88,22 @@ function packageDirectory(name: string, root: string) {
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
/** A package's static tree: the directory it declares, or its root. */
|
|
92
|
+
function staticDirectory(name: string, directory: string) {
|
|
93
|
+
const declared = JSON.parse(
|
|
94
|
+
readFileSync(join(directory, "package.json"), "utf8")
|
|
95
|
+
).patchwork?.static;
|
|
96
|
+
if (!declared) return directory;
|
|
97
|
+
const path = join(directory, declared);
|
|
98
|
+
if (!existsSync(path)) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`[patchwork] ${name} declares "patchwork": {"static": ${JSON.stringify(declared)}}, but ${path} doesn't exist. ` +
|
|
101
|
+
`The field is a path inside the installed package — a package that publishes its static tree as the tarball's own root shouldn't set it at all.`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return path;
|
|
105
|
+
}
|
|
106
|
+
|
|
90
107
|
export function resolveStatic(
|
|
91
108
|
options: PatchworkVitePluginOptions,
|
|
92
109
|
root: string
|
|
@@ -96,14 +113,12 @@ export function resolveStatic(
|
|
|
96
113
|
const isPath = entry.from.startsWith(".") || isAbsolute(entry.from);
|
|
97
114
|
const directory = isPath ? undefined : packageDirectory(entry.from, root);
|
|
98
115
|
const path = directory
|
|
99
|
-
?
|
|
100
|
-
directory,
|
|
101
|
-
JSON.parse(readFileSync(join(directory, "package.json"), "utf8"))
|
|
102
|
-
.patchwork?.static ?? "."
|
|
103
|
-
)
|
|
116
|
+
? staticDirectory(entry.from, directory)
|
|
104
117
|
: resolve(root, entry.from);
|
|
105
118
|
if (!existsSync(path)) {
|
|
106
|
-
throw new Error(
|
|
119
|
+
throw new Error(
|
|
120
|
+
`[patchwork] static source not found: ${entry.from} (${path})`
|
|
121
|
+
);
|
|
107
122
|
}
|
|
108
123
|
const file = statSync(path).isFile();
|
|
109
124
|
const to = entry.to ?? "/";
|