@open-xchange/vite-plugin-project-meta 1.2.0 → 1.3.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/CHANGELOG.md +9 -0
- package/README.md +1 -1
- package/dist/index.d.mts +27 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +60 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +13 -11
- package/dist/index.d.ts +0 -22
- package/dist/index.js +0 -56
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## `1.3.1` – 2026-Apr-13
|
|
4
|
+
|
|
5
|
+
- chore: use rolldown hook filters for better build performance
|
|
6
|
+
- chore: bump dependencies
|
|
7
|
+
|
|
8
|
+
## `1.3.0` – 2026-Apr-09
|
|
9
|
+
|
|
10
|
+
- chore: switch to `tsdown` for building packages
|
|
11
|
+
|
|
3
12
|
## `1.2.0` – 2026-Mar-13
|
|
4
13
|
|
|
5
14
|
- added: support for Vite 8
|
package/README.md
CHANGED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the plugin '@open-xchange/vite-plugin-project-meta'.
|
|
6
|
+
*/
|
|
7
|
+
interface VitePluginProjectMetaOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The display name of the project.
|
|
10
|
+
*/
|
|
11
|
+
projectName: string;
|
|
12
|
+
}
|
|
13
|
+
declare const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
|
|
14
|
+
/**
|
|
15
|
+
* Vite plugin that provides a virtual module 'virtual:metadata' exporting a
|
|
16
|
+
* metadata object with project build information (timestamp, commit ID, etc.).
|
|
17
|
+
*
|
|
18
|
+
* @param options
|
|
19
|
+
* Plugin configuration.
|
|
20
|
+
*
|
|
21
|
+
* @returns
|
|
22
|
+
* The Vite plugin object.
|
|
23
|
+
*/
|
|
24
|
+
declare function vitePluginProjectMeta(options: VitePluginProjectMetaOptions): Plugin;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { PROJECT_NAME, VitePluginProjectMetaOptions, vitePluginProjectMeta as default };
|
|
27
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;AAeA;UAAiB,4BAAA;;;;EAKf,WAAA;AAAA;AAAA,cAKW,YAAA;;;AAAuD;;;;;;;;iBAc5C,qBAAA,CAAsB,OAAA,EAAS,4BAAA,GAA+B,MAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { createJsonModule, exactRegex } from "@open-xchange/rolldown-utils";
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
|
|
7
|
+
/**
|
|
8
|
+
* Vite plugin that provides a virtual module 'virtual:metadata' exporting a
|
|
9
|
+
* metadata object with project build information (timestamp, commit ID, etc.).
|
|
10
|
+
*
|
|
11
|
+
* @param options
|
|
12
|
+
* Plugin configuration.
|
|
13
|
+
*
|
|
14
|
+
* @returns
|
|
15
|
+
* The Vite plugin object.
|
|
16
|
+
*/
|
|
17
|
+
function vitePluginProjectMeta(options) {
|
|
18
|
+
const MODULE_NAME = "virtual:metadata";
|
|
19
|
+
const MODULE_ID = `\0${PROJECT_NAME}/${MODULE_NAME}`;
|
|
20
|
+
let metadata;
|
|
21
|
+
return {
|
|
22
|
+
name: PROJECT_NAME,
|
|
23
|
+
configResolved(config) {
|
|
24
|
+
const pkg = JSON.parse(readFileSync(join(config.root, "package.json"), { encoding: "utf8" }));
|
|
25
|
+
metadata = {
|
|
26
|
+
id: pkg.name,
|
|
27
|
+
name: options.projectName,
|
|
28
|
+
version: pkg.version,
|
|
29
|
+
builddate: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30
|
+
commitsha: process.env.CI_COMMIT_SHA
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
resolveId: {
|
|
34
|
+
filter: { id: exactRegex(MODULE_NAME) },
|
|
35
|
+
handler: () => MODULE_ID
|
|
36
|
+
},
|
|
37
|
+
load: {
|
|
38
|
+
filter: { id: exactRegex(MODULE_ID) },
|
|
39
|
+
handler: () => createJsonModule(metadata)
|
|
40
|
+
},
|
|
41
|
+
transformIndexHtml(_html, context) {
|
|
42
|
+
if (!context.bundle) return;
|
|
43
|
+
const hash = createHash("md5").update(metadata.builddate).digest("hex");
|
|
44
|
+
const len = Number.parseInt(hash.slice(0, 4), 16) % 99 + 42;
|
|
45
|
+
const count = Math.ceil(len / hash.length);
|
|
46
|
+
return [{
|
|
47
|
+
tag: "meta",
|
|
48
|
+
attrs: {
|
|
49
|
+
name: "etag-fix",
|
|
50
|
+
content: hash.repeat(count).slice(0, len)
|
|
51
|
+
},
|
|
52
|
+
injectTo: "head"
|
|
53
|
+
}];
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { PROJECT_NAME, vitePluginProjectMeta as default };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["\nimport { join } from 'node:path'\nimport { readFileSync } from 'node:fs'\nimport { createHash } from 'node:crypto'\n\nimport type { Plugin } from 'vite'\nimport { exactRegex, createJsonModule } from '@open-xchange/rolldown-utils'\n\nimport type { VirtualProjectMetadata } from 'virtual:metadata'\n\n// types ======================================================================\n\n/**\n * Configuration options for the plugin '@open-xchange/vite-plugin-project-meta'.\n */\nexport interface VitePluginProjectMetaOptions {\n\n /**\n * The display name of the project.\n */\n projectName: string\n}\n\n// constants ==================================================================\n\nexport const PROJECT_NAME = '@open-xchange/vite-plugin-project-meta'\n\n// plugin =====================================================================\n\n/**\n * Vite plugin that provides a virtual module 'virtual:metadata' exporting a\n * metadata object with project build information (timestamp, commit ID, etc.).\n *\n * @param options\n * Plugin configuration.\n *\n * @returns\n * The Vite plugin object.\n */\nexport default function vitePluginProjectMeta(options: VitePluginProjectMetaOptions): Plugin {\n\n const MODULE_NAME = 'virtual:metadata'\n const MODULE_ID = `\\0${PROJECT_NAME}/${MODULE_NAME}`\n\n let metadata: VirtualProjectMetadata\n\n return {\n name: PROJECT_NAME,\n\n configResolved(config) {\n /** @ignore */\n interface Package {\n name: string\n version: string\n }\n const pkg = JSON.parse(readFileSync(join(config.root, 'package.json'), { encoding: 'utf8' })) as Package\n metadata = {\n id: pkg.name,\n name: options.projectName,\n version: pkg.version,\n builddate: new Date().toISOString(),\n commitsha: process.env.CI_COMMIT_SHA,\n }\n },\n\n resolveId: {\n filter: { id: exactRegex(MODULE_NAME) },\n handler: () => MODULE_ID,\n },\n\n load: {\n filter: { id: exactRegex(MODULE_ID) },\n handler: () => createJsonModule(metadata),\n },\n\n transformIndexHtml(_html, context) {\n if (!context.bundle) return\n const hash = createHash('md5').update(metadata.builddate).digest('hex')\n const len = Number.parseInt(hash.slice(0, 4), 16) % 99 + 42\n const count = Math.ceil(len / hash.length)\n const content = hash.repeat(count).slice(0, len)\n const attrs = { name: 'etag-fix', content }\n // inject a <meta> element into the <head>\n return [{ tag: 'meta', attrs, injectTo: 'head' }]\n },\n }\n}\n"],"mappings":";;;;;AAyBA,MAAa,eAAe;;;;;;;;;;;AAc5B,SAAwB,sBAAsB,SAA+C;CAE3F,MAAM,cAAc;CACpB,MAAM,YAAY,KAAK,aAAa,GAAG;CAEvC,IAAI;AAEJ,QAAO;EACL,MAAM;EAEN,eAAe,QAAQ;GAMrB,MAAM,MAAM,KAAK,MAAM,aAAa,KAAK,OAAO,MAAM,eAAe,EAAE,EAAE,UAAU,QAAQ,CAAC,CAAC;AAC7F,cAAW;IACT,IAAI,IAAI;IACR,MAAM,QAAQ;IACd,SAAS,IAAI;IACb,4BAAW,IAAI,MAAM,EAAC,aAAa;IACnC,WAAW,QAAQ,IAAI;IACxB;;EAGH,WAAW;GACT,QAAQ,EAAE,IAAI,WAAW,YAAY,EAAE;GACvC,eAAe;GAChB;EAED,MAAM;GACJ,QAAQ,EAAE,IAAI,WAAW,UAAU,EAAE;GACrC,eAAe,iBAAiB,SAAS;GAC1C;EAED,mBAAmB,OAAO,SAAS;AACjC,OAAI,CAAC,QAAQ,OAAQ;GACrB,MAAM,OAAO,WAAW,MAAM,CAAC,OAAO,SAAS,UAAU,CAAC,OAAO,MAAM;GACvE,MAAM,MAAM,OAAO,SAAS,KAAK,MAAM,GAAG,EAAE,EAAE,GAAG,GAAG,KAAK;GACzD,MAAM,QAAQ,KAAK,KAAK,MAAM,KAAK,OAAO;AAI1C,UAAO,CAAC;IAAE,KAAK;IAAQ,OAFT;KAAE,MAAM;KAAY,SADlB,KAAK,OAAO,MAAM,CAAC,MAAM,GAAG,IAAI;KACL;IAEb,UAAU;IAAQ,CAAC;;EAEpD"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xchange/vite-plugin-project-meta",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Vite plugin providing a virtual import for project metadata",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://gitlab.open-xchange.com/fspd/commons/plugins",
|
|
7
|
+
"url": "git+https://gitlab.open-xchange.com/fspd/commons/plugins.git",
|
|
8
8
|
"directory": "packages/vite-plugin-project-meta"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
@@ -13,10 +13,8 @@
|
|
|
13
13
|
},
|
|
14
14
|
"type": "module",
|
|
15
15
|
"exports": {
|
|
16
|
-
".":
|
|
17
|
-
|
|
18
|
-
"default": "./dist/index.js"
|
|
19
|
-
},
|
|
16
|
+
".": "./dist/index.mjs",
|
|
17
|
+
"./package.json": "./package.json",
|
|
20
18
|
"./virtual": {
|
|
21
19
|
"types": "./dist/virtual.d.ts"
|
|
22
20
|
}
|
|
@@ -25,16 +23,20 @@
|
|
|
25
23
|
"dist",
|
|
26
24
|
"CHANGELOG.*"
|
|
27
25
|
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@open-xchange/rolldown-utils": "^1.0.0"
|
|
28
|
+
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"vite": "^8.0.
|
|
30
|
-
"@open-xchange/linter-presets": "^1.
|
|
30
|
+
"vite": "^8.0.8",
|
|
31
|
+
"@open-xchange/linter-presets": "^1.22.0",
|
|
32
|
+
"@open-xchange/tsconfig": "^0.0.3"
|
|
31
33
|
},
|
|
32
34
|
"peerDependencies": {
|
|
33
35
|
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
34
36
|
},
|
|
35
37
|
"scripts": {
|
|
36
|
-
"build": "
|
|
37
|
-
"
|
|
38
|
-
"
|
|
38
|
+
"build": "tsdown",
|
|
39
|
+
"lint": "tsc && tsc --project src && eslint .",
|
|
40
|
+
"verify": "pnpm build && pnpm lint"
|
|
39
41
|
}
|
|
40
42
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
|
-
/**
|
|
3
|
-
* Configuration options for the plugin '@open-xchange/vite-plugin-project-meta'.
|
|
4
|
-
*/
|
|
5
|
-
export interface VitePluginProjectMetaOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The display name of the project.
|
|
8
|
-
*/
|
|
9
|
-
projectName: string;
|
|
10
|
-
}
|
|
11
|
-
export declare const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
|
|
12
|
-
/**
|
|
13
|
-
* Vite plugin that provides a virtual module 'virtual:metadata' exporting a
|
|
14
|
-
* metadata object with project build information (timestamp, commit ID, etc.).
|
|
15
|
-
*
|
|
16
|
-
* @param options
|
|
17
|
-
* Plugin configuration.
|
|
18
|
-
*
|
|
19
|
-
* @returns
|
|
20
|
-
* The Vite plugin object.
|
|
21
|
-
*/
|
|
22
|
-
export default function vitePluginProjectMeta(options: VitePluginProjectMetaOptions): Plugin;
|
package/dist/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { createHash } from 'node:crypto';
|
|
4
|
-
// constants ==================================================================
|
|
5
|
-
export const PROJECT_NAME = '@open-xchange/vite-plugin-project-meta';
|
|
6
|
-
// plugin =====================================================================
|
|
7
|
-
/**
|
|
8
|
-
* Vite plugin that provides a virtual module 'virtual:metadata' exporting a
|
|
9
|
-
* metadata object with project build information (timestamp, commit ID, etc.).
|
|
10
|
-
*
|
|
11
|
-
* @param options
|
|
12
|
-
* Plugin configuration.
|
|
13
|
-
*
|
|
14
|
-
* @returns
|
|
15
|
-
* The Vite plugin object.
|
|
16
|
-
*/
|
|
17
|
-
export default function vitePluginProjectMeta(options) {
|
|
18
|
-
const MODULE_NAME = 'virtual:metadata';
|
|
19
|
-
const MODULE_ID = `\0${PROJECT_NAME}/${MODULE_NAME}`;
|
|
20
|
-
let metadata;
|
|
21
|
-
return {
|
|
22
|
-
name: PROJECT_NAME,
|
|
23
|
-
configResolved(config) {
|
|
24
|
-
const pkg = JSON.parse(readFileSync(join(config.root, 'package.json'), { encoding: 'utf8' }));
|
|
25
|
-
metadata = {
|
|
26
|
-
id: pkg.name,
|
|
27
|
-
name: options.projectName,
|
|
28
|
-
version: pkg.version,
|
|
29
|
-
builddate: new Date().toISOString(),
|
|
30
|
-
commitsha: process.env.CI_COMMIT_SHA,
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
resolveId(source) {
|
|
34
|
-
return (source === MODULE_NAME) ? MODULE_ID : null;
|
|
35
|
-
},
|
|
36
|
-
load(id) {
|
|
37
|
-
if (id !== MODULE_ID) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
const code = `export default ${JSON.stringify(metadata)};`;
|
|
41
|
-
return { code, map: { mappings: '' } };
|
|
42
|
-
},
|
|
43
|
-
transformIndexHtml(_html, context) {
|
|
44
|
-
if (!context.bundle) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const hash = createHash('md5').update(metadata.builddate).digest('hex');
|
|
48
|
-
const len = Number.parseInt(hash.slice(0, 4), 16) % 99 + 42;
|
|
49
|
-
const count = Math.ceil(len / hash.length);
|
|
50
|
-
const content = hash.repeat(count).slice(0, len);
|
|
51
|
-
const attrs = { name: 'etag-fix', content };
|
|
52
|
-
// inject a <meta> element into the <head>
|
|
53
|
-
return [{ tag: 'meta', attrs, injectTo: 'head' }];
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
}
|