@marko/run 0.1.16 → 0.2.1
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/README.md +98 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/adapter/index.cjs +9 -1
- package/dist/adapter/index.js +9 -1
- package/dist/adapter/middleware.cjs +69 -24
- package/dist/adapter/middleware.js +69 -24
- package/dist/cli/index.mjs +168 -1
- package/dist/vite/index.cjs +604 -305
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +606 -305
- package/dist/vite/routes/builder.d.ts +0 -1
- package/dist/vite/routes/parse.d.ts +13 -0
- package/dist/vite/routes/vdir.d.ts +19 -0
- package/dist/vite/routes/walk.d.ts +2 -2
- package/dist/vite/types.d.ts +8 -14
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
var __accessCheck = (obj, member, msg) => {
|
|
9
|
+
if (!member.has(obj))
|
|
10
|
+
throw TypeError("Cannot " + msg);
|
|
11
|
+
};
|
|
12
|
+
var __privateGet = (obj, member, getter) => {
|
|
13
|
+
__accessCheck(obj, member, "read from private field");
|
|
14
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
15
|
+
};
|
|
16
|
+
var __privateAdd = (obj, member, value) => {
|
|
17
|
+
if (member.has(obj))
|
|
18
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
19
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
20
|
+
};
|
|
21
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
22
|
+
__accessCheck(obj, member, "write to private field");
|
|
23
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
2
26
|
|
|
3
27
|
// src/cli/index.ts
|
|
4
28
|
import sade from "sade";
|
|
@@ -48,11 +72,154 @@ var RoutableFileTypes = {
|
|
|
48
72
|
Error: "500"
|
|
49
73
|
};
|
|
50
74
|
|
|
75
|
+
// src/vite/routes/vdir.ts
|
|
76
|
+
var _dirs, _pathlessDirs;
|
|
77
|
+
var _VDir = class {
|
|
78
|
+
constructor(parent, segment, source) {
|
|
79
|
+
__privateAdd(this, _dirs, void 0);
|
|
80
|
+
__privateAdd(this, _pathlessDirs, void 0);
|
|
81
|
+
__publicField(this, "parent");
|
|
82
|
+
__publicField(this, "source");
|
|
83
|
+
__publicField(this, "path");
|
|
84
|
+
__publicField(this, "fullPath");
|
|
85
|
+
__publicField(this, "segment");
|
|
86
|
+
__publicField(this, "files");
|
|
87
|
+
if (!parent || !segment) {
|
|
88
|
+
this.parent = null;
|
|
89
|
+
this.source = null;
|
|
90
|
+
this.path = "/";
|
|
91
|
+
this.fullPath = "/";
|
|
92
|
+
this.segment = {
|
|
93
|
+
raw: "",
|
|
94
|
+
name: ""
|
|
95
|
+
};
|
|
96
|
+
} else {
|
|
97
|
+
this.parent = parent;
|
|
98
|
+
this.source = source;
|
|
99
|
+
this.path = parent.path + (parent.path === "/" ? segment.name : `/${segment.name}`);
|
|
100
|
+
this.fullPath = parent.fullPath + (parent.fullPath === "/" ? segment.name : `/${segment.name}`);
|
|
101
|
+
if (segment.param) {
|
|
102
|
+
this.fullPath += segment.param;
|
|
103
|
+
}
|
|
104
|
+
this.segment = segment;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
get pathInfo() {
|
|
108
|
+
const value = {
|
|
109
|
+
id: "/",
|
|
110
|
+
path: "/",
|
|
111
|
+
segments: []
|
|
112
|
+
};
|
|
113
|
+
let sep = "";
|
|
114
|
+
for (const { segment } of this) {
|
|
115
|
+
const { type, name, param } = segment;
|
|
116
|
+
if (name && type !== "_") {
|
|
117
|
+
value.id += sep + (type || name);
|
|
118
|
+
value.path += sep + name;
|
|
119
|
+
value.isEnd = type === "$$";
|
|
120
|
+
if (param) {
|
|
121
|
+
value.path += param;
|
|
122
|
+
let index = type === "$$" ? null : value.segments.length;
|
|
123
|
+
if (!value.params) {
|
|
124
|
+
value.params = { [param]: index };
|
|
125
|
+
} else if (!(param in value.params)) {
|
|
126
|
+
value.params[param] = index;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
value.segments.push(name);
|
|
130
|
+
sep = "/";
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
Object.defineProperty(this, "pathInfo", {
|
|
134
|
+
value,
|
|
135
|
+
enumerable: true
|
|
136
|
+
});
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
addDir(path4, segment) {
|
|
140
|
+
const map = segment.type === "_" ? __privateGet(this, _pathlessDirs) ?? __privateSet(this, _pathlessDirs, /* @__PURE__ */ new Map()) : __privateGet(this, _dirs) ?? __privateSet(this, _dirs, /* @__PURE__ */ new Map());
|
|
141
|
+
if (!map.has(segment.name)) {
|
|
142
|
+
const dir = new _VDir(this, segment, path4);
|
|
143
|
+
map.set(segment.name, dir);
|
|
144
|
+
return dir;
|
|
145
|
+
}
|
|
146
|
+
return map.get(segment.name);
|
|
147
|
+
}
|
|
148
|
+
addFile(file) {
|
|
149
|
+
if (!this.files) {
|
|
150
|
+
this.files = /* @__PURE__ */ new Map();
|
|
151
|
+
this.files.set(file.type, file);
|
|
152
|
+
} else if (!this.files.has(file.type)) {
|
|
153
|
+
this.files.set(file.type, file);
|
|
154
|
+
} else {
|
|
155
|
+
const existing = this.files.get(file.type);
|
|
156
|
+
if (existing !== file) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`Duplicate file type '${file.type}' added at path '${this.path}'. File '${file.filePath}' collides with '${existing.filePath}'.`
|
|
159
|
+
);
|
|
160
|
+
} else if (file.type === RoutableFileTypes.Page || file.type === RoutableFileTypes.Handler) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
`Ambiguous path definition: route '${this.path}' is defined multiple times by ${file.filePath}`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
throw new Error(
|
|
166
|
+
`Ambiguous path definition: file '${this.path}' is included multiple times by ${file.filePath}`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
*dirs() {
|
|
171
|
+
if (__privateGet(this, _pathlessDirs)) {
|
|
172
|
+
yield* __privateGet(this, _pathlessDirs).values();
|
|
173
|
+
}
|
|
174
|
+
if (__privateGet(this, _dirs)) {
|
|
175
|
+
yield* __privateGet(this, _dirs).values();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
*[Symbol.iterator]() {
|
|
179
|
+
if (this.parent) {
|
|
180
|
+
yield* this.parent;
|
|
181
|
+
}
|
|
182
|
+
yield this;
|
|
183
|
+
}
|
|
184
|
+
static addPaths(roots, paths) {
|
|
185
|
+
const dirs = [];
|
|
186
|
+
const unique = /* @__PURE__ */ new Set();
|
|
187
|
+
for (const root of roots) {
|
|
188
|
+
for (const path4 of paths) {
|
|
189
|
+
let dir = root;
|
|
190
|
+
for (const segment of path4.segments) {
|
|
191
|
+
dir = dir.addDir(path4, segment);
|
|
192
|
+
}
|
|
193
|
+
if (unique.has(dir.path)) {
|
|
194
|
+
const sources = /* @__PURE__ */ new Set();
|
|
195
|
+
let sourcePath = "";
|
|
196
|
+
for (const { source } of dir) {
|
|
197
|
+
if (source && !sources.has(source.source)) {
|
|
198
|
+
sources.add(source.source);
|
|
199
|
+
sourcePath += source.source + "/";
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
throw new Error(
|
|
203
|
+
`Ambiguous directory structure: '${sourcePath}${path4.source}' defines '${dir.path}' multiple times.`
|
|
204
|
+
);
|
|
205
|
+
} else {
|
|
206
|
+
unique.add(dir.path);
|
|
207
|
+
dirs.push(dir);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return dirs;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
var VDir = _VDir;
|
|
215
|
+
_dirs = new WeakMap();
|
|
216
|
+
_pathlessDirs = new WeakMap();
|
|
217
|
+
|
|
51
218
|
// src/vite/routes/builder.ts
|
|
52
219
|
var markoFiles = `(${RoutableFileTypes.Layout}|${RoutableFileTypes.Page}|${RoutableFileTypes.NotFound}|${RoutableFileTypes.Error})\\.(?:.*\\.)?(marko)`;
|
|
53
220
|
var nonMarkoFiles = `(${RoutableFileTypes.Middleware}|${RoutableFileTypes.Handler}|${RoutableFileTypes.Meta})\\.(?:.*\\.)?(.+)`;
|
|
54
221
|
var routeableFileRegex = new RegExp(
|
|
55
|
-
|
|
222
|
+
`[+](?:${markoFiles}|${nonMarkoFiles})$`,
|
|
56
223
|
"i"
|
|
57
224
|
);
|
|
58
225
|
|