@package-verse/esmpack 1.0.6 → 1.0.7
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/.vscode/launch.json +10 -7
- package/package.json +2 -2
- package/src/ProcessArgs.ts +3 -0
- package/src/parser/babel.ts +15 -4
- package/src/serve/WebServer.ts +8 -2
- package/src/serve/send/sendJS.ts +54 -11
- package/src/serve/send/sendNonJSModule.ts +39 -0
- package/src/tags.d.ts +32 -0
- package/src/test/Clock.svg +1 -0
- package/src/test/TestView.ts +9 -1
- package/src/serve/send/sendCSSJS.ts +0 -22
package/.vscode/launch.json
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": "0.2.0",
|
|
3
3
|
"configurations": [
|
|
4
|
-
{
|
|
5
|
-
"name": "Launch Edge",
|
|
6
|
-
"request": "launch",
|
|
7
|
-
"type": "pwa-msedge",
|
|
8
|
-
"url": "http://127.0.0.1:8080/uiv/$CURRENT$/dist/c8-front-end",
|
|
9
|
-
"webRoot": "${workspaceFolder}"
|
|
10
|
-
},
|
|
11
4
|
{
|
|
12
5
|
"type": "node",
|
|
13
6
|
"request": "launch",
|
|
@@ -16,6 +9,16 @@
|
|
|
16
9
|
"outFiles": [
|
|
17
10
|
"${workspaceRoot}/out/**/*.js"
|
|
18
11
|
]
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "Attach to Process",
|
|
15
|
+
"type": "node",
|
|
16
|
+
"request": "attach",
|
|
17
|
+
"port": 9229,
|
|
18
|
+
"localRoot": "${workspaceRoot}",
|
|
19
|
+
"outFiles": [
|
|
20
|
+
"${workspaceFolder}/dist/**/*.js",
|
|
21
|
+
]
|
|
19
22
|
}
|
|
20
23
|
]
|
|
21
24
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@package-verse/esmpack",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "ESM Pack Packer and Web Server with PostCSS and ESM Loader",
|
|
5
5
|
"homepage": "https://github.com/package-verse/esmpack#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"test": "exit 0",
|
|
18
18
|
"push": "git add -A && git commit -m \"dep vb\" && npm version patch",
|
|
19
19
|
"build-css-watch": "npx postcss \"./src/**/*.css\" --base src --dir dist --map --verbose -w",
|
|
20
|
-
"test-server": "node --enable-source-maps ./serve.js",
|
|
20
|
+
"test-server": "node --enable-source-maps --inspect=0.0.0.0:9229 ./serve.js",
|
|
21
21
|
"postversion": "git push --follow-tags"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
package/src/ProcessArgs.ts
CHANGED
package/src/parser/babel.ts
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { transformSync } from "@babel/core";
|
|
2
2
|
import { readFileSync } from "fs";
|
|
3
|
+
import { ProcessOptions } from "../ProcessArgs.js";
|
|
4
|
+
import { parse } from "path";
|
|
3
5
|
|
|
4
6
|
export class Babel {
|
|
5
7
|
|
|
6
|
-
static transform({ file, resolve }: { file: string, resolve: (url: string) => string }) {
|
|
8
|
+
static transform({ file, resolve }: { file: string, resolve: (url: string, sourceFile: string) => string }) {
|
|
9
|
+
|
|
10
|
+
const { base: name } = parse(file);
|
|
7
11
|
|
|
8
12
|
const presets = {
|
|
9
13
|
sourceType: "module",
|
|
10
14
|
sourceMaps: true,
|
|
11
15
|
inputSourceMap: true,
|
|
16
|
+
caller: {
|
|
17
|
+
name,
|
|
18
|
+
supportsDynamicImport: true,
|
|
19
|
+
supportsTopLevelAwait: true,
|
|
20
|
+
},
|
|
12
21
|
compact: false,
|
|
13
22
|
comments: false,
|
|
23
|
+
root: ProcessOptions.cwd,
|
|
14
24
|
getModuleId: () => "v",
|
|
15
25
|
"plugins": [
|
|
16
26
|
[
|
|
@@ -24,7 +34,8 @@ export class Babel {
|
|
|
24
34
|
if (!source) {
|
|
25
35
|
return node;
|
|
26
36
|
}
|
|
27
|
-
|
|
37
|
+
const sourceFile = node.hub?.file?.inputMap?.sourcemap?.sources?.[0];
|
|
38
|
+
source = resolve(source, sourceFile);
|
|
28
39
|
e.source.value = source;
|
|
29
40
|
return node;
|
|
30
41
|
},
|
|
@@ -38,7 +49,7 @@ export class Babel {
|
|
|
38
49
|
|
|
39
50
|
const p = { ... presets, filename: file };
|
|
40
51
|
const code = readFileSync(file, "utf8");
|
|
41
|
-
const result =
|
|
52
|
+
const result = transformSync(code, p);
|
|
42
53
|
return result.code;
|
|
43
54
|
}
|
|
44
55
|
|
package/src/serve/WebServer.ts
CHANGED
|
@@ -6,7 +6,7 @@ import sendLocalFile from "./send/sendLocalFile.js";
|
|
|
6
6
|
import { createProxyMiddleware, fixRequestBody } from "http-proxy-middleware";
|
|
7
7
|
import colors from "colors";
|
|
8
8
|
import sendJSHost from "./send/sendJSHost.js";
|
|
9
|
-
import
|
|
9
|
+
import sendNonJSModule from "./send/sendNonJSModule.js";
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
let middleware;
|
|
@@ -24,7 +24,7 @@ export default function WebServer(req: IncomingMessage, res: ServerResponse) {
|
|
|
24
24
|
|
|
25
25
|
const css = fullPath.replace(/\.js$/, "");
|
|
26
26
|
if (existsSync(css)) {
|
|
27
|
-
|
|
27
|
+
sendNonJSModule(pathname.substring(0, pathname.length - 3), req, res);
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -34,6 +34,12 @@ export default function WebServer(req: IncomingMessage, res: ServerResponse) {
|
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
// if (!fileArgument) {
|
|
38
|
+
// res.writeHead(404,{});
|
|
39
|
+
// res.end("");
|
|
40
|
+
// return;
|
|
41
|
+
// }
|
|
42
|
+
|
|
37
43
|
// proxy...
|
|
38
44
|
middleware ??= createProxyMiddleware({
|
|
39
45
|
target: fileArgument,
|
package/src/serve/send/sendJS.ts
CHANGED
|
@@ -2,33 +2,76 @@ import { IncomingMessage, ServerResponse } from "node:http";
|
|
|
2
2
|
import { Babel } from "../../parser/babel.js";
|
|
3
3
|
import path, { parse } from "node:path";
|
|
4
4
|
import { ProcessOptions } from "../../ProcessArgs.js";
|
|
5
|
-
import { readFileSync } from "node:fs";
|
|
5
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6
6
|
|
|
7
7
|
export default function sendJS(filePath: string, req: IncomingMessage, res: ServerResponse) {
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
let text = Babel.transform({ file: filePath, resolve(url) {
|
|
11
|
-
if (url.endsWith(".css")) {
|
|
12
|
-
url += ".js";
|
|
13
|
-
}
|
|
10
|
+
let text = Babel.transform({ file: filePath, resolve(url, sourceFile) {
|
|
14
11
|
// check if it has no extension...
|
|
15
12
|
const { ext } = parse(url);
|
|
16
13
|
if (!ext) {
|
|
14
|
+
|
|
15
|
+
// this is case for tslib, reflect_metadata
|
|
16
|
+
|
|
17
17
|
// fetch module...
|
|
18
18
|
const tokens = url.split("/");
|
|
19
|
-
let
|
|
19
|
+
let packageName = tokens.shift();
|
|
20
20
|
if (packageName.startsWith("@")) {
|
|
21
21
|
packageName += "/" + tokens.shift();
|
|
22
22
|
}
|
|
23
23
|
const packageJsonPath = path.resolve(ProcessOptions.cwd, "node_modules", packageName, "package.json");
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
if (existsSync(packageJsonPath)) {
|
|
25
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
26
|
+
const start = packageJson["module"] || packageJson["main"];
|
|
27
|
+
return "/node_modules/" + url + "/" + start;
|
|
28
|
+
}
|
|
29
|
+
|
|
27
30
|
}
|
|
31
|
+
|
|
32
|
+
|
|
28
33
|
if (!url.startsWith(".")) {
|
|
29
|
-
|
|
34
|
+
const resolved = path.resolve(ProcessOptions.cwd, "node_modules/" + url);
|
|
35
|
+
if (existsSync(resolved)) {
|
|
36
|
+
url = "/node_modules/" + url;
|
|
37
|
+
return url;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const tokens = url.split("/");
|
|
41
|
+
let packageName = tokens.shift();
|
|
42
|
+
if (packageName.startsWith("@")) {
|
|
43
|
+
packageName += "/" + tokens.shift();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const mainModuleFile = path.resolve(ProcessOptions.cwd, ... tokens);
|
|
47
|
+
if (existsSync(mainModuleFile)) {
|
|
48
|
+
url = tokens.join("/");
|
|
49
|
+
if (!url.endsWith(".js")) {
|
|
50
|
+
return "/" + url + ".js";
|
|
51
|
+
}
|
|
52
|
+
return "/" + url;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return "/" + url;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const jsFile = path.resolve(path.dirname(filePath), url);
|
|
59
|
+
if (existsSync(jsFile)) {
|
|
60
|
+
if (!jsFile.endsWith(".js")) {
|
|
61
|
+
url += ".js";
|
|
62
|
+
}
|
|
63
|
+
return url;
|
|
30
64
|
}
|
|
31
|
-
|
|
65
|
+
|
|
66
|
+
// is it refernced from source...
|
|
67
|
+
const absoluteSourcePath = path.join( path.dirname(filePath), sourceFile);
|
|
68
|
+
const localSourceFile = path.resolve( absoluteSourcePath, url);
|
|
69
|
+
const localFile = path.resolve(ProcessOptions.cwd, localSourceFile);
|
|
70
|
+
if (!localFile.endsWith(".js")) {
|
|
71
|
+
return "/" + localSourceFile + ".js";
|
|
72
|
+
}
|
|
73
|
+
return "/" + localSourceFile;
|
|
74
|
+
|
|
32
75
|
}});
|
|
33
76
|
|
|
34
77
|
const { base } = parse(filePath);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
export default function sendNonJSModule(path: string, req: IncomingMessage, res: ServerResponse) {
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if (path.endsWith(".css")) {
|
|
9
|
+
|
|
10
|
+
const init = fileURLToPath(import.meta.resolve("../../../init.js"));
|
|
11
|
+
const initText = readFileSync(init, "utf-8");
|
|
12
|
+
|
|
13
|
+
const text = `
|
|
14
|
+
(function (link) {
|
|
15
|
+
${initText};
|
|
16
|
+
ESMPack.installStyleSheet(link);
|
|
17
|
+
}("/${path}"))
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
res.writeHead(200, {
|
|
21
|
+
"content-type": "text/javascript",
|
|
22
|
+
"cache-control": "no-cache"
|
|
23
|
+
});
|
|
24
|
+
res.end(text);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// just send a path...
|
|
30
|
+
res.writeHead(200, {
|
|
31
|
+
"content-type": "text/javascript",
|
|
32
|
+
"cache-control": "no-cache"
|
|
33
|
+
});
|
|
34
|
+
res.end(`
|
|
35
|
+
const value = "/${path}";
|
|
36
|
+
export default value;
|
|
37
|
+
`);
|
|
38
|
+
|
|
39
|
+
}
|
package/src/tags.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare module "*.png" {
|
|
2
|
+
const value: string;
|
|
3
|
+
export default value;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module "*.jpg" {
|
|
7
|
+
const value: string;
|
|
8
|
+
export default value;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module "*.jpeg" {
|
|
12
|
+
const value: string;
|
|
13
|
+
export default value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module "*.gif" {
|
|
17
|
+
const value: string;
|
|
18
|
+
export default value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module "*.svg" {
|
|
22
|
+
const value: string;
|
|
23
|
+
export default value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare module "*.css" {
|
|
27
|
+
const value: string;
|
|
28
|
+
export default value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare module "*.json" {
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Pro v7.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2026 Fonticons, Inc.--><path opacity=".4" d="M96 352C96 402.3 112.6 448.8 140.6 486.2L105.4 521.4C92.9 533.9 92.9 554.2 105.4 566.7C117.9 579.2 138.2 579.2 150.7 566.7L185.9 531.5C223.3 559.5 269.7 576.1 320 576.1C370.3 576.1 416.8 559.5 454.2 531.5L489.4 566.7C501.9 579.2 522.2 579.2 534.7 566.7C547.2 554.2 547.2 533.9 534.7 521.4L499.5 486.2C527.5 448.8 544.1 402.4 544.1 352C544.1 228.3 443.8 128 320.1 128C196.4 128 96 228.3 96 352zM296 248C296 234.7 306.7 224 320 224C333.3 224 344 234.7 344 248L344 342.1L393 391.1C402.4 400.5 402.4 415.7 393 425C383.6 434.3 368.4 434.4 359.1 425L303.1 369C298.6 364.5 296.1 358.4 296.1 352L296.1 248z"/><path d="M543.5 196.9C550 206.3 564 207 568.4 196.5C573.3 185 576 172.4 576 159.2C576 106.6 533.4 64 480.8 64C461.5 64 443.5 69.8 428.5 79.7C418.9 86 422.2 99.6 432.6 104.3C477.4 124.7 515.7 156.9 543.6 196.9zM71.6 196.5C76.1 207 90 206.3 96.5 196.9C124.3 156.9 162.6 124.7 207.5 104.3C217.9 99.6 221.2 86 211.6 79.7C196.6 69.8 178.6 64 159.3 64C106.7 64 64.1 106.6 64.1 159.2C64.1 172.4 66.8 185 71.7 196.5zM344 248C344 234.7 333.3 224 320 224C306.7 224 296 234.7 296 248L296 352C296 358.4 298.5 364.5 303 369L359 425C368.4 434.4 383.6 434.4 392.9 425C402.2 415.6 402.3 400.4 392.9 391.1L343.9 342.1L343.9 248z"/></svg>
|
package/src/test/TestView.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import DateTime from "@web-atoms/date-time/dist/DateTime.js";
|
|
2
2
|
|
|
3
|
+
import clock from "@package-verse/esmpack/src/test/Clock.svg";
|
|
4
|
+
|
|
3
5
|
// irrespective of loading order
|
|
4
6
|
// global must be loaded first and
|
|
5
7
|
// local must override the global style
|
|
@@ -12,9 +14,15 @@ import LogDecorator from "./LogDecorator.js";
|
|
|
12
14
|
export default class DateView extends HTMLElement {
|
|
13
15
|
|
|
14
16
|
connectedCallback() {
|
|
17
|
+
|
|
18
|
+
const img = document.createElement("img");
|
|
19
|
+
img.src = clock;
|
|
20
|
+
const span = document.createElement("span");
|
|
21
|
+
this.appendChild(img);
|
|
22
|
+
this.appendChild(span);
|
|
15
23
|
setInterval(() => {
|
|
16
24
|
const now = DateTime.now;
|
|
17
|
-
|
|
25
|
+
span.textContent = now.toJSON();
|
|
18
26
|
}, 1000);
|
|
19
27
|
}
|
|
20
28
|
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { IncomingMessage, ServerResponse } from "node:http";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
5
|
-
export default function sendCSSJS(path: string, req: IncomingMessage, res: ServerResponse) {
|
|
6
|
-
|
|
7
|
-
const init = fileURLToPath(import.meta.resolve("../../../init.js"));
|
|
8
|
-
const initText = readFileSync(init, "utf-8");
|
|
9
|
-
|
|
10
|
-
const text = `
|
|
11
|
-
(function (link) {
|
|
12
|
-
${initText};
|
|
13
|
-
ESMPack.installStyleSheet(link);
|
|
14
|
-
}("/${path}"))
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
res.writeHead(200, {
|
|
18
|
-
"content-type": "text/javascript",
|
|
19
|
-
"cache-control": "no-cache"
|
|
20
|
-
});
|
|
21
|
-
res.end(text);
|
|
22
|
-
}
|