@eve-online-tools/eve-resfile 0.0.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 +109 -0
- package/dist/chunk-D665R74X.js +63 -0
- package/dist/chunk-IX5WVBZL.js +65 -0
- package/dist/chunk-RP7V25VC.js +229 -0
- package/dist/chunk-YCJ3SYSF.js +203 -0
- package/dist/index.cjs +256 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +34 -0
- package/dist/rollup/index.cjs +322 -0
- package/dist/rollup/index.d.cts +6 -0
- package/dist/rollup/index.d.ts +6 -0
- package/dist/rollup/index.js +64 -0
- package/dist/types-DUuyxUdh.d.cts +28 -0
- package/dist/types-DUuyxUdh.d.ts +28 -0
- package/dist/vite/client.d.ts +4 -0
- package/dist/vite/index.cjs +416 -0
- package/dist/vite/index.d.cts +6 -0
- package/dist/vite/index.d.ts +6 -0
- package/dist/vite/index.js +154 -0
- package/package.json +80 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isVirtualResId,
|
|
3
|
+
loadResfileAssetModule,
|
|
4
|
+
lookupOrThrow,
|
|
5
|
+
resPathFromVirtualId,
|
|
6
|
+
resolveEveResfileOptions,
|
|
7
|
+
resolveResfileId
|
|
8
|
+
} from "../chunk-IX5WVBZL.js";
|
|
9
|
+
import {
|
|
10
|
+
DEFAULT_ASSET_ORIGIN,
|
|
11
|
+
DEV_PROXY_PREFIX,
|
|
12
|
+
__async,
|
|
13
|
+
fetchBuffer,
|
|
14
|
+
loadResfileIndexData,
|
|
15
|
+
resPathFromDevProxyUrl
|
|
16
|
+
} from "../chunk-RP7V25VC.js";
|
|
17
|
+
|
|
18
|
+
// src/content-type.ts
|
|
19
|
+
import { extname } from "path";
|
|
20
|
+
var CONTENT_TYPES = {
|
|
21
|
+
".png": "image/png",
|
|
22
|
+
".jpg": "image/jpeg",
|
|
23
|
+
".jpeg": "image/jpeg",
|
|
24
|
+
".gif": "image/gif",
|
|
25
|
+
".webp": "image/webp",
|
|
26
|
+
".svg": "image/svg+xml",
|
|
27
|
+
".ico": "image/x-icon",
|
|
28
|
+
".dds": "image/vnd-ms.dds",
|
|
29
|
+
".mp3": "audio/mpeg",
|
|
30
|
+
".ogg": "audio/ogg",
|
|
31
|
+
".wav": "audio/wav",
|
|
32
|
+
".webm": "video/webm",
|
|
33
|
+
".mp4": "video/mp4",
|
|
34
|
+
".woff": "font/woff",
|
|
35
|
+
".woff2": "font/woff2",
|
|
36
|
+
".ttf": "font/ttf",
|
|
37
|
+
".json": "application/json",
|
|
38
|
+
".txt": "text/plain"
|
|
39
|
+
};
|
|
40
|
+
var contentTypeForPath = (resPath) => {
|
|
41
|
+
var _a;
|
|
42
|
+
return (_a = CONTENT_TYPES[extname(resPath).toLowerCase()]) != null ? _a : "application/octet-stream";
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/vite/plugin.ts
|
|
46
|
+
var createDevProxyMiddleware = (ensureIndex, assetOrigin) => {
|
|
47
|
+
return (req, res, next) => __async(null, null, function* () {
|
|
48
|
+
if (!req.url || req.method !== "GET") {
|
|
49
|
+
next();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const pathname = new URL(req.url, "http://localhost").pathname;
|
|
53
|
+
if (!pathname.startsWith(DEV_PROXY_PREFIX)) {
|
|
54
|
+
next();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const resPath = resPathFromDevProxyUrl(pathname);
|
|
58
|
+
if (!resPath) {
|
|
59
|
+
res.statusCode = 400;
|
|
60
|
+
res.end("Invalid resfile proxy path.");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
let cdnPath;
|
|
64
|
+
try {
|
|
65
|
+
const index = yield ensureIndex();
|
|
66
|
+
cdnPath = lookupOrThrow(index, resPath);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
res.statusCode = 404;
|
|
69
|
+
res.end(error instanceof Error ? error.message : "Resfile not found.");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const buffer = yield fetchBuffer(`${assetOrigin}/${cdnPath}`);
|
|
74
|
+
res.statusCode = 200;
|
|
75
|
+
res.setHeader("Content-Type", contentTypeForPath(resPath));
|
|
76
|
+
res.setHeader("Cache-Control", "public, max-age=86400");
|
|
77
|
+
res.end(buffer);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
res.statusCode = 502;
|
|
80
|
+
res.end(error instanceof Error ? error.message : "Failed to fetch resfile from CDN.");
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
var eveResfile = (options = {}) => {
|
|
85
|
+
let resolvedOptions = null;
|
|
86
|
+
let indexPromise = null;
|
|
87
|
+
let loadedIndex = null;
|
|
88
|
+
const ensureIndex = () => {
|
|
89
|
+
if (!resolvedOptions) {
|
|
90
|
+
throw new Error("@eve-online-tools/eve-resfile/vite: configResolved has not run yet.");
|
|
91
|
+
}
|
|
92
|
+
indexPromise != null ? indexPromise : indexPromise = loadResfileIndexData(resolvedOptions).then((index) => {
|
|
93
|
+
loadedIndex = index;
|
|
94
|
+
return index;
|
|
95
|
+
});
|
|
96
|
+
return indexPromise;
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
name: "eve-resfile-vite",
|
|
100
|
+
enforce: "pre",
|
|
101
|
+
configResolved(config) {
|
|
102
|
+
resolvedOptions = resolveEveResfileOptions(options, config.root);
|
|
103
|
+
},
|
|
104
|
+
buildStart() {
|
|
105
|
+
return __async(this, null, function* () {
|
|
106
|
+
const index = yield ensureIndex();
|
|
107
|
+
this.info(
|
|
108
|
+
`Loaded EVE resfileindex (build ${index.buildNumber}, ${index.resPathToCdnPath.size} entries).`
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
configureServer: {
|
|
113
|
+
order: "pre",
|
|
114
|
+
handler(server) {
|
|
115
|
+
var _a2;
|
|
116
|
+
server.middlewares.use(
|
|
117
|
+
createDevProxyMiddleware(
|
|
118
|
+
ensureIndex,
|
|
119
|
+
(_a2 = resolvedOptions == null ? void 0 : resolvedOptions.assetOrigin) != null ? _a2 : DEFAULT_ASSET_ORIGIN
|
|
120
|
+
)
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
resolveId(source) {
|
|
125
|
+
return resolveResfileId(source);
|
|
126
|
+
},
|
|
127
|
+
load(id) {
|
|
128
|
+
return __async(this, null, function* () {
|
|
129
|
+
if (!isVirtualResId(id)) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
if (!resolvedOptions) {
|
|
133
|
+
throw new Error("@eve-online-tools/eve-resfile/vite: configResolved has not run yet.");
|
|
134
|
+
}
|
|
135
|
+
const resPath = resPathFromVirtualId(id);
|
|
136
|
+
const index = loadedIndex != null ? loadedIndex : yield ensureIndex();
|
|
137
|
+
return loadResfileAssetModule({
|
|
138
|
+
watchMode: this.meta.watchMode,
|
|
139
|
+
assetOrigin: resolvedOptions.assetOrigin,
|
|
140
|
+
index,
|
|
141
|
+
resPath,
|
|
142
|
+
emitAsset: (name, source) => this.emitFile({
|
|
143
|
+
type: "asset",
|
|
144
|
+
name,
|
|
145
|
+
source
|
|
146
|
+
})
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
export {
|
|
153
|
+
eveResfile
|
|
154
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eve-online-tools/eve-resfile",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "EVE Online resfile index loader with Vite and Rollup plugins",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/eve-online-tools/node-packages.git",
|
|
12
|
+
"directory": "packages/eve-resfile"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"./vite": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/vite/index.d.ts",
|
|
32
|
+
"default": "./dist/vite/index.js"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/vite/index.d.ts",
|
|
36
|
+
"default": "./dist/vite/index.cjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./rollup": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/rollup/index.d.ts",
|
|
42
|
+
"default": "./dist/rollup/index.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/rollup/index.d.ts",
|
|
46
|
+
"default": "./dist/rollup/index.cjs"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"./client": {
|
|
50
|
+
"types": "./dist/vite/client.d.ts"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist",
|
|
55
|
+
"README.md"
|
|
56
|
+
],
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"rollup": "^4.0.0",
|
|
59
|
+
"vite": "^6.0.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"rollup": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"vite": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@types/node": "^22.15.24",
|
|
71
|
+
"rollup": "^4.41.1",
|
|
72
|
+
"typescript": "6.0.2",
|
|
73
|
+
"vite": "^6.3.5"
|
|
74
|
+
},
|
|
75
|
+
"scripts": {
|
|
76
|
+
"build": "tsup src/index.ts src/vite/index.ts src/rollup/index.ts --format cjs,esm --dts --external vite --external rollup && mkdir -p dist/vite && cp src/vite/client.d.ts dist/vite/client.d.ts",
|
|
77
|
+
"typecheck": "tsc --noEmit",
|
|
78
|
+
"test": "pnpm --workspace-root vitest run packages/eve-resfile"
|
|
79
|
+
}
|
|
80
|
+
}
|