@yongdall/live-server 0.6.1 → 0.6.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/cli/live-server.mjs +2 -2
- package/cli/live-server.mjs.map +1 -1
- package/index.mjs +2 -2
- package/index.mjs.map +1 -1
- package/package.json +5 -5
package/cli/live-server.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import liveServer from "live-server";
|
|
3
|
-
import
|
|
3
|
+
import { roots } from "@yongdall/root";
|
|
4
4
|
import { middleware } from "#index";
|
|
5
5
|
|
|
6
6
|
//#region cli/live-server/cli/live-server.mjs
|
|
@@ -57,7 +57,7 @@ async function live_server_default({ development, options, parameters }) {
|
|
|
57
57
|
host: process.env.IP,
|
|
58
58
|
port,
|
|
59
59
|
open,
|
|
60
|
-
mount: [["/assets", path.resolve(
|
|
60
|
+
mount: [["/assets", path.resolve(roots.project, "assets")], ["/", path.resolve(roots.project, "public")]],
|
|
61
61
|
proxy: server ? [["/api/", `${server}/api/`]] : [],
|
|
62
62
|
middleware: server ? [middleware()] : [await createHttp(development), middleware()],
|
|
63
63
|
logLevel: 2,
|
package/cli/live-server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-server.mjs","names":[],"sources":["../../../cli/live-server/cli/live-server.mjs"],"sourcesContent":["/** @import { Cli } from '@yongdall/cli-parse' */\nimport * as path from 'node:path';\n// @ts-ignore\nimport liveServer from 'live-server';\nimport
|
|
1
|
+
{"version":3,"file":"live-server.mjs","names":[],"sources":["../../../cli/live-server/cli/live-server.mjs"],"sourcesContent":["/** @import { Cli } from '@yongdall/cli-parse' */\nimport * as path from 'node:path';\n// @ts-ignore\nimport liveServer from 'live-server';\nimport {roots} from '@yongdall/root';\nimport {middleware} from '#index';\n\n\n/**\n * \n * @param {boolean} development \n */\nasync function createHttp(development) {\n\tconst { default: init } = await import('@yongdall/init');\n\tconst { default: createCallback } = await import('@yongdall/http/callback');\n\tawait init({ development });\n\treturn await createCallback({ development });\n}\n\n\n/**\n * \n * @param {Cli.Env} env \n */\nexport default async function ({ development, options, parameters }) {\n\tlet server = ``;\n\tlet port = 0;\n\tfor (const s of options.server || []) {\n\t\tif (!s) { continue; }\n\t\tlet port = 0;\n\t\tif (/^\\d(_?\\d)*$/.test(s)) {\n\t\t\tport = parseInt(s.replace(/_/g, ''));\n\t\t} else if (/^0x[a-f\\d](_?[a-f\\d]+)$/i.test(s)) {\n\t\t\tport = parseInt(s.replace(/_/g, '').slice(2), 16);\n\t\t}\n\t\tif (port > 0 && port <= 0xffff) {\n\t\t\tserver = `http://127.0.0.1:${port}`;\n\t\t\tbreak;\n\t\t}\n\t\tif (/^(\\[[:.a-f\\d]+\\]|[\\.a-z\\d-]+)(:\\d+)?$/i.test(s)) {\n\t\t\tserver = `http://${s}`;\n\t\t\tbreak;\n\t\t}\n\t\ttry {\n\t\t\tconst url = new URL(s);\n\t\t\tif (!['http:', 'https:'].includes(url.protocol.toLowerCase())) { continue; }\n\t\t\tserver = url.origin;\n\t\t\tbreak;\n\t\t} catch {}\n\t}\n\tfor (const s of options.port || []) {\n\t\tif (!s) { continue; }\n\t\tlet v = 0;\n\t\tif (/^\\d(_?\\d)*$/.test(s)) {\n\t\t\tv = parseInt(s.replace(/_/g, ''));\n\t\t} else if (/^0x[a-f\\d](_?[a-f\\d]+)$/i.test(s)) {\n\t\t\tv = parseInt(s.replace(/_/g, '').slice(2), 16);\n\t\t}\n\t\tif (v > 0 && v <= 0xffff) {\n\t\t\tport = v;\n\t\t\tbreak;\n\t\t}\n\t}\n\tconst open = Boolean(options.open?.length);\n\tliveServer.start({\n\t\thost: process.env.IP,\n\t\tport,\n\t\topen,\n\t\tmount: [['/assets', path.resolve(roots.project, 'assets')], ['/', path.resolve(roots.project, 'public')]],\n\t\t// @ts-ignore\n\t\tproxy: server ? [['/api/', `${server}/api/`]] : [],\n\t\tmiddleware: server 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Q;AACzB,UAAO;AACP;;;CAGF,MAAM,OAAO,QAAQ,QAAQ,MAAM,OAAO;AAC1C,YAAW,MAAM;EAChB,MAAM,QAAQ,IAAI;EAClB;EACA;EACA,OAAO,CAAC,CAAC,WAAW,KAAK,QAAQ,MAAM,SAAS,SAAS,CAAC,EAAE,CAAC,KAAK,KAAK,QAAQ,MAAM,SAAS,SAAS,CAAC,CAAC;EAEzG,OAAO,SAAS,CAAC,CAAC,SAAS,GAAG,OAAO,OAAO,CAAC,GAAG,EAAE;EAClD,YAAY,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,WAAW,YAAY,EAAE,YAAY,CAAC;EACnF,UAAU;EACV,MAAM;EACN,CAAC"}
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
|
-
import
|
|
2
|
+
import { roots } from "@yongdall/root";
|
|
3
3
|
import * as fs from "node:fs/promises";
|
|
4
4
|
import * as amaro from "amaro";
|
|
5
5
|
|
|
@@ -18,7 +18,7 @@ function middleware() {
|
|
|
18
18
|
const url = req.url?.split("#", 1)[0].split("?", 1)[0];
|
|
19
19
|
if (!url) return next();
|
|
20
20
|
if (!url.endsWith(".ts") && !url.endsWith(".mts")) return next();
|
|
21
|
-
const filePath = path.join(
|
|
21
|
+
const filePath = path.join(roots.project, url.startsWith("/assets/") ? "" : "public", url);
|
|
22
22
|
const rawCode = await fs.readFile(filePath, "utf-8").catch(() => null);
|
|
23
23
|
if (rawCode === null) return next();
|
|
24
24
|
try {
|
package/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../cli/live-server/index.mjs"],"sourcesContent":["/** @import { IncomingMessage, ServerResponse } from 'node:http' */\nimport * as path from 'node:path';\nimport * as fs from 'node:fs/promises';\nimport * as amaro from 'amaro';\nimport
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../cli/live-server/index.mjs"],"sourcesContent":["/** @import { IncomingMessage, ServerResponse } from 'node:http' */\nimport * as path from 'node:path';\nimport * as fs from 'node:fs/promises';\nimport * as amaro from 'amaro';\nimport { roots } from '@yongdall/root';\n\nexport function middleware() {\n\n\t/**\n\t * 一个用于 live-server 的中间件,用于处理 .ts 和 .mts 文件 \n\t * @param {IncomingMessage} req \n\t * @param {ServerResponse} res \n\t * @param {() => void} next \n\t * @returns \n\t */\n\tasync function middleware(req, res, next) {\n\t\tif (req.method !== 'GET') { return next(); }\n\n\t\tconst url = req.url?.split('#', 1)[0].split('?', 1)[0];\n\t\tif (!url) { return next(); }\n\n\t\tif (!url.endsWith('.ts') && !url.endsWith('.mts')) { return next(); }\n\n\n\t\tconst filePath = path.join(roots.project, url.startsWith('/assets/') ? '' : 'public', url);\n\n\t\tconst rawCode = await fs.readFile(filePath, 'utf-8').catch(() => null);\n\t\tif (rawCode === null) { return next(); }\n\t\ttry {\n\t\t\tconst { code } = amaro.transformSync(rawCode, { mode: 'strip-only' });\n\t\t\tres.setHeader('Content-Type', 'application/javascript');\n\n\t\t\tres.end(code);\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error processing ${url}:`, error);\n\t\t\tres.statusCode = 500;\n\t\t\tres.setHeader('Content-Type', 'text/plain');\n\t\t\t// @ts-ignore\n\t\t\tres.end(`Error processing TypeScript file: ${error.message}`);\n\t\t}\n\t}\n\treturn middleware;\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,aAAa;;;;;;;;CAS5B,eAAe,WAAW,KAAK,KAAK,MAAM;AACzC,MAAI,IAAI,WAAW,MAAS,QAAO,MAAM;EAEzC,MAAM,MAAM,IAAI,KAAK,MAAM,KAAK,EAAE,CAAC,GAAG,MAAM,KAAK,EAAE,CAAC;AACpD,MAAI,CAAC,IAAO,QAAO,MAAM;AAEzB,MAAI,CAAC,IAAI,SAAS,MAAM,IAAI,CAAC,IAAI,SAAS,OAAO,CAAI,QAAO,MAAM;EAGlE,MAAM,WAAW,KAAK,KAAK,MAAM,SAAS,IAAI,WAAW,WAAW,GAAG,KAAK,UAAU,IAAI;EAE1F,MAAM,UAAU,MAAM,GAAG,SAAS,UAAU,QAAQ,CAAC,YAAY,KAAK;AACtE,MAAI,YAAY,KAAQ,QAAO,MAAM;AACrC,MAAI;GACH,MAAM,EAAE,SAAS,MAAM,cAAc,SAAS,EAAE,MAAM,cAAc,CAAC;AACrE,OAAI,UAAU,gBAAgB,yBAAyB;AAEvD,OAAI,IAAI,KAAK;WACL,OAAO;AACf,WAAQ,MAAM,oBAAoB,IAAI,IAAI,MAAM;AAChD,OAAI,aAAa;AACjB,OAAI,UAAU,gBAAgB,aAAa;AAE3C,OAAI,IAAI,qCAAqC,MAAM,UAAU;;;AAG/D,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yongdall/live-server",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.mjs",
|
|
6
6
|
"imports": {
|
|
7
7
|
"#index": "./index.mjs"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@yongdall/http": "^0.6.
|
|
11
|
-
"@yongdall/init": "^0.6.
|
|
12
|
-
"@yongdall/root": "^0.6.
|
|
10
|
+
"@yongdall/http": "^0.6.2",
|
|
11
|
+
"@yongdall/init": "^0.6.2",
|
|
12
|
+
"@yongdall/root": "^0.6.2",
|
|
13
13
|
"amaro": "^1.1.8",
|
|
14
14
|
"live-server": "^1.2.2"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@types/live-server": "^1.2.3",
|
|
18
|
-
"@yongdall/cli-parse": "^0.6.
|
|
18
|
+
"@yongdall/cli-parse": "^0.6.2"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
".": "./index.mjs"
|