@zipadee/dev-server 0.0.18

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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2024 Justin Fagnani
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @zipadee/dev-server
2
+
3
+ A simple dev-server CLI.
4
+
5
+ ## Overview
6
+
7
+ zpd is a web development server built with Zipadee. It serves JavaScript files
8
+ and rewrites npm-style module specifiers to be browser-compatible by resolving them to
9
+ on-disk paths.
10
+
11
+ ## Usage
12
+
13
+ ```
14
+ zpd [options]
15
+ ```
16
+
17
+ Options:
18
+
19
+ - `--port`, `-p` The port to listen on. (default: 8080)
20
+ - `--root`, `-r` Root directory to serve files from. (default: Current working directory)
21
+ - `--base`, `-b` Base directory to resolve paths and imports from, as a relative path
22
+ from the root directory. (default: '')
23
+ - `--css-modules` Whether to transform CSS modules to JavaScript.
24
+
25
+ If true, CSS imports - imports with a `type: 'css'` import attribute - will be transformed to remove the `type: 'css'` attribute and add a `?type=css--module` query parameter to the URL.
26
+
27
+ Requests for these URLs will be served as JavaScript modules that export the CSS as a CSSStyleSheet object. (default: false)
28
+ - `--help` Show the help message (default: false)
29
+
30
+ zpd serves files from the specified root directory (default: cwd).
31
+
32
+ Absolute paths and JavaScript module specifiers are resolved relative to the
33
+ base directory if set, otherwise to the root directory. If a module specifier
34
+ resolves to a path outside of the base directory, it is rewritten to be relative
35
+ to the root directory by prefixing it with the a special root path prefix.
36
+
37
+ Example:
38
+
39
+ If you have a monorepo with packages at `packages/foo` and `packages/bar`
40
+ and you want to serve content from the package `foo`, you should set the root
41
+ to the monorepo root and base to `packages/foo`.
42
+
43
+ `import 'bar'` from within the `foo` package will be rewritten to `import
44
+ '/__root__/packages/bar/index.js'`, and the server will serve the file from
45
+ `packages/bar/index.js`.
package/bin/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export declare const run: () => Promise<void>;
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/bin/cli.ts"],"names":[],"mappings":";AA+HA,eAAO,MAAM,GAAG,qBAiBf,CAAC"}
package/bin/cli.js ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env node
2
+ import { startServer } from '../index.js';
3
+ import { parseArgs, } from 'node:util';
4
+ import dedent from 'dedent';
5
+ const parseArgsConfig = {
6
+ options: {
7
+ port: {
8
+ type: 'string',
9
+ short: 'p',
10
+ help: 'The port to listen on.',
11
+ default: '8080',
12
+ },
13
+ root: {
14
+ type: 'string',
15
+ short: 'r',
16
+ default: process.cwd(),
17
+ help: 'Root directory to serve files from.',
18
+ defaultDescription: 'Current working directory',
19
+ },
20
+ base: {
21
+ type: 'string',
22
+ short: 'b',
23
+ help: dedent `
24
+ Base directory to resolve paths and imports from, as a relative path
25
+ from the root directory.`,
26
+ default: '',
27
+ defaultDescription: "''",
28
+ },
29
+ ['css-modules']: {
30
+ type: 'boolean',
31
+ help: dedent `
32
+ Whether to transform CSS modules to JavaScript. If true, CSS imports -
33
+ imports with a \`type: 'css'\` import attribute - will be transformed to
34
+ remove the \`type: 'css'\` attribute and add a \`?type=css--module\` query
35
+ parameter to the URL. Requests for these URLs will be served as JavaScript
36
+ modules that export the CSS as a CSSStyleSheet object.`,
37
+ default: false,
38
+ },
39
+ help: {
40
+ type: 'boolean',
41
+ default: false,
42
+ help: 'Show this help message',
43
+ },
44
+ },
45
+ };
46
+ const generateHelp = (config) => {
47
+ return dedent `
48
+ zpd - Zipadee Dev Server
49
+
50
+ Usage: zpd [options]
51
+
52
+ Options:
53
+ ${Object.entries(config.options)
54
+ .map(([key, descriptor]) => {
55
+ const { help } = descriptor;
56
+ const args = getArgs(key, descriptor);
57
+ const helpText = help + getDefault(descriptor);
58
+ const indent = ' '.repeat(16 - args.length);
59
+ const helpLines = helpText.split('\n');
60
+ return `${args}${indent}${helpLines.join(`\n${' '.repeat(22)}`)}`;
61
+ })
62
+ .join('\n ')}
63
+
64
+ zpd is a web development server built with Zipadee. It serves JavaScript
65
+ files and rewrites module specifiers to be browser-compatible by resolving
66
+ them to on-disk paths.
67
+
68
+ zpd serves files from the specified root directory (default: cwd).
69
+
70
+ Absolute paths and JavaScript module specifiers are resolved relative to
71
+ the base directory if set, otherwise to the root directory. If a module
72
+ specifier resolves to a path outside of the base directory, it is rewritten
73
+ to be relative to the root directory by prefixing it with the a special root
74
+ path prefix.
75
+
76
+ Example:
77
+
78
+ If you have a monorepo with packages at \`packages/foo\` and \`packages/bar\`
79
+ and you want to serve content from the package \`foo\`, you should set the
80
+ root to the monorepo root and base to \`packages/foo\`.
81
+
82
+ An import \`bar\` from within the \`foo\` package will be rewritten to
83
+ \`import '/__root__/packages/bar/index.js'\`, and the server will serve
84
+ the file from \`packages/bar/index.js\`.
85
+ `;
86
+ };
87
+ const getArgs = (key, descriptor) => {
88
+ let result = `--${key}`;
89
+ if (descriptor.short) {
90
+ result += `, -${descriptor.short}`;
91
+ }
92
+ return result;
93
+ };
94
+ const getDefault = (descriptor) => {
95
+ const defaultValue = descriptor.defaultDescription ?? descriptor.default;
96
+ if (defaultValue === undefined) {
97
+ return '';
98
+ }
99
+ return ` (default: ${defaultValue})`;
100
+ };
101
+ export const run = async () => {
102
+ const args = parseArgs(parseArgsConfig);
103
+ if (args.values.help) {
104
+ console.log(generateHelp(parseArgsConfig));
105
+ return;
106
+ }
107
+ const port = parseInt(args.values.port);
108
+ console.log('css-modules:', args.values['css-modules']);
109
+ await startServer({
110
+ port,
111
+ rootDir: args.values.root,
112
+ baseDir: args.values.base,
113
+ cssModules: args.values['css-modules'],
114
+ });
115
+ };
116
+ await run();
117
+ //# sourceMappingURL=cli.js.map
package/bin/cli.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/bin/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,SAAS,GAGV,MAAM,WAAW,CAAC;AAEnB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAe5B,MAAM,eAAe,GAAG;IACtB,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,wBAAwB;YAC9B,OAAO,EAAE,MAAM;SAChB;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;YACtB,IAAI,EAAE,qCAAqC;YAC3C,kBAAkB,EAAE,2BAA2B;SAChD;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,MAAM,CAAA;;iCAEe;YAC3B,OAAO,EAAE,EAAE;YACX,kBAAkB,EAAE,IAAI;SACzB;QACD,CAAC,aAAa,CAAC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AC;AAChB,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,UAA6C,EAAE,EAAE;IACnE,MAAM,YAAY,GAAG,UAAU,CAAC,kBAAkB,IAAI,UAAU,CAAC,OAAO,CAAC;IACzE,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,cAAc,YAAY,GAAG,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,IAAI,EAAE;IAC5B,MAAM,IAAI,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC;IAExC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC;QAC3C,OAAO;IACT,CAAC;IACD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAExC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;IAExD,MAAM,WAAW,CAAC;QAChB,IAAI;QACJ,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;QACzB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;QACzB,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;KACvC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,GAAG,EAAE,CAAC"}
package/index.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Options for the Zipadee dev server.
3
+ */
4
+ export interface Options {
5
+ /**
6
+ * The port to listen on.
7
+ */
8
+ port: number;
9
+ /**
10
+ * The root directory to serve files from. The dev server will not serve files
11
+ * outside this directory.
12
+ */
13
+ rootDir: string;
14
+ /**
15
+ * The base directory to serve from, as a relative path from the root
16
+ * directory. Absolute paths will be resolved relative to this directory.
17
+ *
18
+ * If a JavaScript modules specifier resolves to outside of this directory, it
19
+ * will be rewritten to be relative to the root directory.
20
+ */
21
+ baseDir?: string;
22
+ /**
23
+ * Whether to transform CSS modules to JavaScript. If true, CSS imports -
24
+ * imports with a `type: 'css'` import attribute - will be transformed to
25
+ * remove the `type: 'css'` attribute and add a `?type=css--module` query
26
+ * parameter to the URL. Requests for these URLs will be served as JavaScript
27
+ * modules that export the CSS as a CSSStyleSheet object.
28
+ */
29
+ cssModules?: boolean;
30
+ }
31
+ /**
32
+ * Starts the Zipadee dev server.
33
+ */
34
+ export declare const startServer: ({ port, rootDir, baseDir, cssModules, }: Options) => Promise<void>;
35
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,GAAU,yCAK/B,OAAO,kBAoBT,CAAC"}
package/index.js ADDED
@@ -0,0 +1,23 @@
1
+ import { App } from '@zipadee/core';
2
+ import { serve as serveJs } from '@zipadee/javascript';
3
+ import { serve } from '@zipadee/static';
4
+ import path from 'node:path';
5
+ /**
6
+ * Starts the Zipadee dev server.
7
+ */
8
+ export const startServer = async ({ port, rootDir, baseDir, cssModules, }) => {
9
+ const app = new App();
10
+ app.use(serveJs({
11
+ root: rootDir,
12
+ base: baseDir,
13
+ conditions: ['browser', 'development', 'import'],
14
+ cssModules,
15
+ }));
16
+ const resolvedBaseDir = path.resolve(rootDir, baseDir ?? '');
17
+ app.use(serve(resolvedBaseDir, { index: 'index.html' }));
18
+ await app.listen(port);
19
+ console.log(`Zipadee dev server is running on port ${port}`);
20
+ console.log(`Serving files from ${resolvedBaseDir}`);
21
+ console.log(`Press Ctrl+C to stop the server.`);
22
+ };
23
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,eAAe,CAAC;AAClC,OAAO,EAAC,KAAK,IAAI,OAAO,EAAC,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAC,KAAK,EAAC,MAAM,iBAAiB,CAAC;AACtC,OAAO,IAAI,MAAM,WAAW,CAAC;AAoC7B;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,EAChC,IAAI,EACJ,OAAO,EACP,OAAO,EACP,UAAU,GACF,EAAE,EAAE;IACZ,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;IAEtB,GAAG,CAAC,GAAG,CACL,OAAO,CAAC;QACN,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,CAAC;QAChD,UAAU;KACX,CAAC,CACH,CAAC;IAEF,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IAC7D,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,EAAE,EAAC,KAAK,EAAE,YAAY,EAAC,CAAC,CAAC,CAAC;IAEvD,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAEvB,OAAO,CAAC,GAAG,CAAC,yCAAyC,IAAI,EAAE,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,CAAC,sBAAsB,eAAe,EAAE,CAAC,CAAC;IACrD,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;AAClD,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@zipadee/dev-server",
3
+ "description": "A lightweight development server for modern web apps.",
4
+ "version": "0.0.18",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "scripts": {
8
+ "build": "wireit",
9
+ "test": "wireit",
10
+ "start": "wireit"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "homepage": "https://github.com/justinfagnani/zipadee#readme",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/justinfagnani/zipadee.git",
18
+ "directory": "packages/dev-server"
19
+ },
20
+ "license": "MIT",
21
+ "bin": {
22
+ "zpd": "./bin/cli.js"
23
+ },
24
+ "files": [
25
+ "/index.{d.ts.map,d.ts,js.map,js}",
26
+ "/bin/"
27
+ ],
28
+ "wireit": {
29
+ "build": {
30
+ "command": "tsc",
31
+ "dependencies": [
32
+ "../core:build",
33
+ "../cors:build",
34
+ "../javascript:build",
35
+ "../router:build",
36
+ "../static:build"
37
+ ],
38
+ "files": [
39
+ "src/**/*.ts",
40
+ "tsconfig.json"
41
+ ],
42
+ "output": [
43
+ "index.{js,js.map,d.ts,d.ts.map}",
44
+ ".tsbuildinfo",
45
+ "lib"
46
+ ],
47
+ "clean": "if-file-deleted"
48
+ },
49
+ "test": {
50
+ "command": "node --enable-source-maps --test --test-reporter=spec \"test/**/*_test.js\"",
51
+ "dependencies": [
52
+ "build"
53
+ ],
54
+ "files": []
55
+ },
56
+ "start": {
57
+ "command": "node --enable-source-maps index.js",
58
+ "dependencies": [
59
+ "build"
60
+ ]
61
+ }
62
+ },
63
+ "dependencies": {
64
+ "@zipadee/core": "^0.0.17",
65
+ "@zipadee/cors": "^0.0.17",
66
+ "@zipadee/javascript": "^0.0.17",
67
+ "@zipadee/router": "^0.0.17",
68
+ "@zipadee/static": "^0.0.17"
69
+ },
70
+ "devDependencies": {
71
+ "@types/node": "^22.15.17",
72
+ "dedent": "^1.6.0"
73
+ }
74
+ }