@marko/run 0.0.1-beta1

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.
Files changed (43) hide show
  1. package/README.md +267 -0
  2. package/dist/adapter/default-entry.mjs +18 -0
  3. package/dist/adapter/dev-server.d.ts +4 -0
  4. package/dist/adapter/index.cjs +159 -0
  5. package/dist/adapter/index.d.ts +4 -0
  6. package/dist/adapter/index.js +126 -0
  7. package/dist/adapter/server-old.d.ts +3 -0
  8. package/dist/adapter/server.d.ts +6 -0
  9. package/dist/adapters/node/index.d.ts +5 -0
  10. package/dist/adapters/node/server.d.ts +3 -0
  11. package/dist/adapters/static/crawler.d.ts +9 -0
  12. package/dist/adapters/static/default-entry.mjs +1 -0
  13. package/dist/adapters/static/index.cjs +371 -0
  14. package/dist/adapters/static/index.d.ts +5 -0
  15. package/dist/adapters/static/index.js +341 -0
  16. package/dist/adapters/static/server.d.ts +3 -0
  17. package/dist/cli/default.config.mjs +7 -0
  18. package/dist/cli/index.mjs +223 -0
  19. package/dist/runtime/index.cjs +34 -0
  20. package/dist/runtime/index.d.ts +2 -0
  21. package/dist/runtime/index.js +7 -0
  22. package/dist/runtime/request.d.ts +4 -0
  23. package/dist/runtime/router.cjs +39 -0
  24. package/dist/runtime/router.d.ts +4 -0
  25. package/dist/runtime/router.js +12 -0
  26. package/dist/runtime/types.d.ts +22 -0
  27. package/dist/vite/codegen/index.d.ts +5 -0
  28. package/dist/vite/codegen/writer.d.ts +20 -0
  29. package/dist/vite/constants.d.ts +19 -0
  30. package/dist/vite/index.cjs +1394 -0
  31. package/dist/vite/index.d.ts +3 -0
  32. package/dist/vite/index.js +1359 -0
  33. package/dist/vite/plugin.d.ts +3 -0
  34. package/dist/vite/routes/builder.d.ts +7 -0
  35. package/dist/vite/routes/routeTrie.d.ts +2 -0
  36. package/dist/vite/routes/walk.d.ts +14 -0
  37. package/dist/vite/types.d.ts +62 -0
  38. package/dist/vite/utils/ast.d.ts +1 -0
  39. package/dist/vite/utils/config.d.ts +3 -0
  40. package/dist/vite/utils/log.d.ts +3 -0
  41. package/dist/vite/utils/route.d.ts +3 -0
  42. package/dist/vite/utils/server.d.ts +7 -0
  43. package/package.json +93 -0
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "vite";
2
+ import type { Options } from "./types";
3
+ export default function markoServe(opts?: Options): Plugin[];
@@ -0,0 +1,7 @@
1
+ import type { BuiltRoutes, RoutableFileType, SpecialRoutes } from "../types";
2
+ import type { Walker } from "./walk";
3
+ export declare function isRoutableFile(filename: string): boolean;
4
+ export declare function matchRoutableFile(filename: string): RoutableFileType | null;
5
+ export declare function scorePath(path: string, index: number): number;
6
+ export declare function isSpecialType(type: RoutableFileType): type is keyof SpecialRoutes;
7
+ export declare function buildRoutes(walk: Walker, basePath?: string): Promise<BuiltRoutes>;
@@ -0,0 +1,2 @@
1
+ import type { Route, RouteTrie } from "../types";
2
+ export declare function createRouteTrie(routes: Route[]): RouteTrie;
@@ -0,0 +1,14 @@
1
+ export interface WalkEntry {
2
+ name: string;
3
+ path: string;
4
+ }
5
+ export interface WalkOptions {
6
+ onFile?: (file: WalkEntry) => void;
7
+ onDir?: (dir: string) => (() => void) | false | void;
8
+ onEnter?: (dir: WalkEntry) => (() => void) | false | void;
9
+ maxDepth?: number;
10
+ }
11
+ export declare type Walker = (options: WalkOptions) => Promise<void>;
12
+ export declare function createFSWalker(dir: string): Walker;
13
+ export declare type TestFileTree = [string, (string | TestFileTree)[]];
14
+ export declare function createTestWalker(dir: TestFileTree): Walker;
@@ -0,0 +1,62 @@
1
+ import type { RoutableFileType, HttpVerb, RoutableFileTypes } from "./constants";
2
+ import type { Options as MarkoViteOptions } from "@marko/vite";
3
+ import type { ResolvedConfig, UserConfig } from "vite";
4
+ export type { RoutableFileType, HttpVerb };
5
+ export declare type StartServer = (port?: number) => Promise<void>;
6
+ export interface Adapter {
7
+ readonly name: string;
8
+ pluginOptions?(options: Options): Promise<Options> | Options | undefined;
9
+ viteConfig?(config: UserConfig): Promise<UserConfig> | UserConfig | undefined;
10
+ getEntryFile?(): Promise<string> | string;
11
+ startDev?(configFile: string, port: number): Promise<void> | void;
12
+ startPreview?(dir: string, entry?: string, port?: number): Promise<void> | void;
13
+ buildEnd?(config: ResolvedConfig, routes: Route[], builtEntries: string[], sourceEntries: string[]): Promise<void> | void;
14
+ }
15
+ export interface MarkoServeOptions {
16
+ routesDir?: string;
17
+ emitRoutes?(routes: Route[]): void | Promise<void>;
18
+ adapter?: Adapter;
19
+ codegen?: CodegenOptions;
20
+ }
21
+ export interface CodegenOptions {
22
+ trailingSlashes: 'Ignore' | 'RedirectWithout' | 'RedirectWith' | 'RewriteWithout' | 'RewriteWith';
23
+ }
24
+ export declare type Options = MarkoServeOptions & MarkoViteOptions;
25
+ export interface Route {
26
+ key: string;
27
+ index: number;
28
+ path: string;
29
+ params?: ParamInfo[];
30
+ layouts: RoutableFile[];
31
+ middleware: RoutableFile[];
32
+ meta?: RoutableFile;
33
+ handler?: RoutableFile;
34
+ page?: RoutableFile;
35
+ score: number;
36
+ }
37
+ export interface ParamInfo {
38
+ name: string;
39
+ index: number;
40
+ }
41
+ export interface SpecialRoutes {
42
+ [RoutableFileTypes.NotFound]?: Route;
43
+ [RoutableFileTypes.Error]?: Route;
44
+ }
45
+ export interface RoutableFile {
46
+ name: string;
47
+ type: RoutableFileType;
48
+ filePath: string;
49
+ importPath: string;
50
+ verbs?: HttpVerb[];
51
+ }
52
+ export interface RouteTrie {
53
+ key: string;
54
+ route?: Route;
55
+ catchAll?: Route;
56
+ static?: Map<string, RouteTrie>;
57
+ dynamic?: RouteTrie;
58
+ }
59
+ export interface BuiltRoutes {
60
+ list: Route[];
61
+ special: SpecialRoutes;
62
+ }
@@ -0,0 +1 @@
1
+ export declare function getExportIdentifiers(astProgramNode: any): string[];
@@ -0,0 +1,3 @@
1
+ import type { Options } from '../types';
2
+ export declare function getMarkoServeOptions<T extends Record<string, any>>(viteConfig: T): Readonly<Options> | undefined;
3
+ export declare function setMarkoServeOptions<T extends Record<string, any>>(viteConfig: T, options: Options): T;
@@ -0,0 +1,3 @@
1
+ import type { OutputBundle } from "rollup";
2
+ import type { BuiltRoutes } from "../types";
3
+ export declare function logRoutesTable(routes: BuiltRoutes, bundle: OutputBundle): void;
@@ -0,0 +1,3 @@
1
+ import type { HttpVerb, Route } from "../types";
2
+ export declare function getVerbs(route: Route): ("get" | "post" | "put" | "delete")[];
3
+ export declare function hasVerb(route: Route, verb: HttpVerb): boolean | import("../types").RoutableFile | undefined;
@@ -0,0 +1,7 @@
1
+ export interface SpawnedServer {
2
+ port: number;
3
+ close(): void;
4
+ }
5
+ export declare function spawnServer(cmd: string, port?: number, cwd?: string, wait?: number): Promise<SpawnedServer>;
6
+ export declare function isPortInUse(port: number): Promise<boolean>;
7
+ export declare function getAvailablePort(): Promise<number>;
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@marko/run",
3
+ "version": "0.0.1-beta1",
4
+ "description": "File-based routing for Marko based on Vite",
5
+ "keywords": [],
6
+ "author": "Ryan Turnquist <rturnq@gmail.com>",
7
+ "license": "MIT",
8
+ "type": "module",
9
+ "bin": {
10
+ "marko-run": "./dist/cli/index.mjs"
11
+ },
12
+ "scripts": {
13
+ "mocha": "cross-env NODE_ENV=test mocha \"./src/**/__tests__/*.test.ts\"",
14
+ "test": "npm run mocha",
15
+ "test:watch": "npm run mocha -- --watch",
16
+ "test:inspect": "npm test -- --inspect",
17
+ "test:update": "npm run mocha -- --update",
18
+ "build": "tsc -b && tsx scripts/build.ts"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/runtime/index.d.ts",
23
+ "import": "./dist/runtime/index.js",
24
+ "require": "./dist/runtime/index.cjs"
25
+ },
26
+ "./router": {
27
+ "types": "./dist/runtime/router.d.ts",
28
+ "import": "./dist/runtime/router.js",
29
+ "require": "./dist/runtime/router.cjs"
30
+ },
31
+ "./vite": {
32
+ "types": "./dist/vite/index.d.ts",
33
+ "import": "./dist/vite/index.js",
34
+ "require": "./dist/vite/index.cjs"
35
+ },
36
+ "./adapter": {
37
+ "types": "./dist/adapter/index.d.ts",
38
+ "import": "./dist/adapter/index.js",
39
+ "require": "./dist/adapter/index.cjs"
40
+ }
41
+ },
42
+ "typesVersions": {
43
+ "*": {
44
+ "*": [
45
+ "./src/runtime/index.ts"
46
+ ],
47
+ "router": [
48
+ "./src/runtime/router.ts"
49
+ ],
50
+ "vite": [
51
+ "./src/vite/index.ts"
52
+ ],
53
+ "adapter": [
54
+ "./src/adapter/index.ts"
55
+ ]
56
+ }
57
+ },
58
+ "types": "./dist/runtime/index.d.ts",
59
+ "main": "./src/runtime/index.ts",
60
+ "files": [
61
+ "dist"
62
+ ],
63
+ "peerDependencies": {
64
+ "@marko/vite": "^2.3.9"
65
+ },
66
+ "devDependencies": {
67
+ "@babel/types": "^7.19.0",
68
+ "@marko/compiler": "^5.22.6",
69
+ "@types/mocha": "^9.1.1",
70
+ "@types/node": "^18.7.6",
71
+ "acorn": "^8.8.0",
72
+ "cross-env": "^7.0.3",
73
+ "esbuild": "^0.15.7",
74
+ "marko": "^5.21.9",
75
+ "mocha": "^10.0.0",
76
+ "mocha-snap": "^4.3.0",
77
+ "prettier": "^2.7.1",
78
+ "tsx": "^3.9.0",
79
+ "typescript": "^4.7.4"
80
+ },
81
+ "dependencies": {
82
+ "@hattip/adapter-node": "^0.0.24",
83
+ "@hattip/core": "^0.0.24",
84
+ "@marko/vite": "^2.3.11",
85
+ "cli-table3": "^0.6.3",
86
+ "gzip-size": "^7.0.0",
87
+ "kleur": "^4.1.5",
88
+ "pretty-bytes": "^6.0.0",
89
+ "sade": "^1.8.1",
90
+ "serve-static": "^1.15.0",
91
+ "vite": "^3.0.8"
92
+ }
93
+ }