@open-xchange/vite-plugin-project-meta 1.1.1 → 1.2.0

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## `1.2.0` – 2026-Mar-13
4
+
5
+ - added: support for Vite 8
6
+
3
7
  ## `1.1.1` – 2025-Sep-09
4
8
 
5
9
  - chore: bump dependencies
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Open-Xchange GmbH, Germany <info@open-xchange.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -5,7 +5,7 @@ A Vite plugin providing a virtual import for project metadata with build informa
5
5
  The metadata object can simply be imported in source code as following:
6
6
 
7
7
  ```js
8
- import metadata from "virtual:metadata"
8
+ import metadata from 'virtual:metadata'
9
9
  ```
10
10
 
11
11
  Additionally, while bundling the project, the plugin will insert a `<meta>` element into all HTML entry files containing a string with random length and contents. This is needed to workaround sticky browser cache when the HTML entry files are being served with weak e-tags that depend on the file size only but not on the file contents.
@@ -17,8 +17,8 @@ Add the plugin to your Vite configuration:
17
17
  ```ts
18
18
  // vite.config.ts
19
19
 
20
- import { defineConfig } from "vite" // or "vitest/config"
21
- import metaPlugin from "@open-xchange/vite-plugin-project-meta"
20
+ import { defineConfig } from 'vite' // or 'vitest/config'
21
+ import metaPlugin from '@open-xchange/vite-plugin-project-meta'
22
22
 
23
23
  export default defineConfig(() => {
24
24
 
@@ -28,14 +28,14 @@ export default defineConfig(() => {
28
28
  // ...
29
29
 
30
30
  metaPlugin({
31
- id: "my-project-ui"
32
- name: "My Project UI",
31
+ id: 'my-project-ui'
32
+ name: 'My Project UI',
33
33
  }),
34
34
  ],
35
35
  })
36
36
  ```
37
37
 
38
- Register TypeScript type definitions for the "virtual:metadata" module import:
38
+ Register TypeScript type definitions for the 'virtual:metadata' module import:
39
39
 
40
40
  ```json
41
41
  // src/tsconfig.json
@@ -55,17 +55,17 @@ Use the virtual module in your code:
55
55
  ```ts
56
56
  // src/path/to/some/module.ts
57
57
 
58
- import metadata from "virtual:metadata"
58
+ import metadata from 'virtual:metadata'
59
59
 
60
- console.log(metadata.id) // from package.json ("name")
60
+ console.log(metadata.id) // from package.json ('name')
61
61
  console.log(metadata.name) // from `options.projectName`
62
- console.log(metadata.version) // from package.json ("version")
62
+ console.log(metadata.version) // from package.json ('version')
63
63
  console.log(metadata.builddate) // plugin execution timestamp
64
- console.log(metadata.commitsha) // from env variable "CI_COMMIT_SHA"
64
+ console.log(metadata.commitsha) // from env variable 'CI_COMMIT_SHA'
65
65
  ```
66
66
 
67
67
  ### Options
68
68
 
69
69
  | Name | Type | Default | Description |
70
70
  | - | - | - | - |
71
- | `projectName` | `string` | _required_ | Display name of the project, for metadata property "name". |
71
+ | `projectName` | `string` | _required_ | Display name of the project, for metadata property 'name'. |
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { Plugin } from "vite";
1
+ import type { Plugin } from 'vite';
2
2
  /**
3
- * Configuration options for the plugin "@open-xchange/vite-plugin-project-meta".
3
+ * Configuration options for the plugin '@open-xchange/vite-plugin-project-meta'.
4
4
  */
5
5
  export interface VitePluginProjectMetaOptions {
6
6
  /**
@@ -10,7 +10,7 @@ export interface VitePluginProjectMetaOptions {
10
10
  }
11
11
  export declare const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
12
12
  /**
13
- * Vite plugin that provides a virtual module "virtual:metadata" exporting a
13
+ * Vite plugin that provides a virtual module 'virtual:metadata' exporting a
14
14
  * metadata object with project build information (timestamp, commit ID, etc.).
15
15
  *
16
16
  * @param options
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { join } from "node:path";
2
- import { readFileSync } from "node:fs";
3
- import { createHash } from "node:crypto";
1
+ import { join } from 'node:path';
2
+ import { readFileSync } from 'node:fs';
3
+ import { createHash } from 'node:crypto';
4
4
  // constants ==================================================================
5
- export const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
5
+ export const PROJECT_NAME = '@open-xchange/vite-plugin-project-meta';
6
6
  // plugin =====================================================================
7
7
  /**
8
- * Vite plugin that provides a virtual module "virtual:metadata" exporting a
8
+ * Vite plugin that provides a virtual module 'virtual:metadata' exporting a
9
9
  * metadata object with project build information (timestamp, commit ID, etc.).
10
10
  *
11
11
  * @param options
@@ -15,13 +15,13 @@ export const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
15
15
  * The Vite plugin object.
16
16
  */
17
17
  export default function vitePluginProjectMeta(options) {
18
- const MODULE_NAME = "virtual:metadata";
18
+ const MODULE_NAME = 'virtual:metadata';
19
19
  const MODULE_ID = `\0${PROJECT_NAME}/${MODULE_NAME}`;
20
20
  let metadata;
21
21
  return {
22
22
  name: PROJECT_NAME,
23
23
  configResolved(config) {
24
- const pkg = JSON.parse(readFileSync(join(config.root, "package.json"), { encoding: "utf8" }));
24
+ const pkg = JSON.parse(readFileSync(join(config.root, 'package.json'), { encoding: 'utf8' }));
25
25
  metadata = {
26
26
  id: pkg.name,
27
27
  name: options.projectName,
@@ -38,19 +38,19 @@ export default function vitePluginProjectMeta(options) {
38
38
  return null;
39
39
  }
40
40
  const code = `export default ${JSON.stringify(metadata)};`;
41
- return { code, map: { mappings: "" } };
41
+ return { code, map: { mappings: '' } };
42
42
  },
43
43
  transformIndexHtml(_html, context) {
44
44
  if (!context.bundle) {
45
45
  return;
46
46
  }
47
- const hash = createHash("md5").update(metadata.builddate).digest("hex");
47
+ const hash = createHash('md5').update(metadata.builddate).digest('hex');
48
48
  const len = Number.parseInt(hash.slice(0, 4), 16) % 99 + 42;
49
49
  const count = Math.ceil(len / hash.length);
50
50
  const content = hash.repeat(count).slice(0, len);
51
- const attrs = { name: "etag-fix", content };
51
+ const attrs = { name: 'etag-fix', content };
52
52
  // inject a <meta> element into the <head>
53
- return [{ tag: "meta", attrs, injectTo: "head" }];
53
+ return [{ tag: 'meta', attrs, injectTo: 'head' }];
54
54
  },
55
55
  };
56
56
  }
package/dist/virtual.d.ts CHANGED
@@ -1,37 +1,38 @@
1
- declare module "virtual:metadata" {
1
+ declare module 'virtual:metadata' {
2
+
3
+ /**
4
+ * Shape of the metadata object provided by the virtual module
5
+ * 'virtual:metadata'.
6
+ */
7
+ export interface VirtualProjectMetadata {
2
8
 
3
9
  /**
4
- * Shape of the metadata object provided by the virtual module "virtual:metadata".
10
+ * Internal identifier of the project.
5
11
  */
6
- export interface VirtualProjectMetadata {
7
-
8
- /**
9
- * Internal identifier of the project.
10
- */
11
- id: string;
12
+ id: string
12
13
 
13
- /**
14
- * The display name of the project.
15
- */
16
- name: string;
14
+ /**
15
+ * The display name of the project.
16
+ */
17
+ name: string
17
18
 
18
- /**
19
- * The version string of the package.
20
- */
21
- version: string;
19
+ /**
20
+ * The version string of the package.
21
+ */
22
+ version: string
22
23
 
23
- /**
24
- * The date when the package was built (ISO timestamp).
25
- */
26
- builddate: string;
24
+ /**
25
+ * The date when the package was built (ISO timestamp).
26
+ */
27
+ builddate: string
27
28
 
28
- /**
29
- * The identifier of the last GIT commit the package has been built on.
30
- * Will be picked from the environment variable "CI_COMMIT_SHA".
31
- */
32
- commitsha: string | undefined;
33
- }
29
+ /**
30
+ * The identifier of the last GIT commit the package has been built on.
31
+ * Will be picked from the environment variable 'CI_COMMIT_SHA'.
32
+ */
33
+ commitsha: string | undefined
34
+ }
34
35
 
35
- const metadata: VirtualProjectMetadata;
36
- export default metadata;
36
+ const metadata: VirtualProjectMetadata
37
+ export default metadata
37
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/vite-plugin-project-meta",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Vite plugin providing a virtual import for project metadata",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,7 +11,6 @@
11
11
  "engines": {
12
12
  "node": ">=20.18"
13
13
  },
14
- "packageManager": "yarn@4.9.4",
15
14
  "type": "module",
16
15
  "exports": {
17
16
  ".": {
@@ -26,23 +25,16 @@
26
25
  "dist",
27
26
  "CHANGELOG.*"
28
27
  ],
29
- "scripts": {
30
- "prepack": "yarn build && yarn lint",
31
- "clean": "premove dist",
32
- "build": "yarn clean && tsc --project src/tsconfig.json && cpx src/virtual.d.ts dist/",
33
- "lint": "tsc && tsc --project src/tsconfig.json --noEmit && eslint ."
34
- },
35
28
  "devDependencies": {
36
- "@open-xchange/linter-presets": "^1.9.0",
37
- "@types/node": "^24.3.1",
38
- "cpx2": "^8.0.0",
39
- "eslint": "^9.35.0",
40
- "jiti": "^2.5.1",
41
- "premove": "^4.0.0",
42
- "typescript": "^5.9.2",
43
- "vite": "^7.1.5"
29
+ "vite": "^8.0.0",
30
+ "@open-xchange/linter-presets": "^1.18.3"
44
31
  },
45
32
  "peerDependencies": {
46
- "vite": "^6.0.0 || ^7.0.0"
33
+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
34
+ },
35
+ "scripts": {
36
+ "build": "pnpm clean && tsc --project src/tsconfig.json && cpx src/virtual.d.ts dist/",
37
+ "clean": "premove dist",
38
+ "lint": "tsc && tsc --project src/tsconfig.json --noEmit && eslint ."
47
39
  }
48
40
  }