@open-xchange/vite-plugin-project-meta 1.1.0 → 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 +8 -0
- package/LICENSE +21 -0
- package/README.md +11 -11
- package/dist/index.d.ts +3 -3
- package/dist/index.js +11 -11
- package/dist/virtual.d.ts +29 -28
- package/package.json +9 -17
package/CHANGELOG.md
CHANGED
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
|
|
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
|
|
21
|
-
import metaPlugin from
|
|
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:
|
|
32
|
-
name:
|
|
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
|
|
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
|
|
58
|
+
import metadata from 'virtual:metadata'
|
|
59
59
|
|
|
60
|
-
console.log(metadata.id) // from package.json (
|
|
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 (
|
|
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
|
|
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
|
|
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
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
2
|
/**
|
|
3
|
-
* Configuration options for the plugin
|
|
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
|
|
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
|
|
2
|
-
import { readFileSync } from
|
|
3
|
-
import { createHash } from
|
|
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 =
|
|
5
|
+
export const PROJECT_NAME = '@open-xchange/vite-plugin-project-meta';
|
|
6
6
|
// plugin =====================================================================
|
|
7
7
|
/**
|
|
8
|
-
* Vite plugin that provides a virtual module
|
|
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 =
|
|
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,
|
|
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(
|
|
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:
|
|
51
|
+
const attrs = { name: 'etag-fix', content };
|
|
52
52
|
// inject a <meta> element into the <head>
|
|
53
|
-
return [{ tag:
|
|
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
|
|
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
|
-
*
|
|
10
|
+
* Internal identifier of the project.
|
|
5
11
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Internal identifier of the project.
|
|
10
|
-
*/
|
|
11
|
-
id: string;
|
|
12
|
+
id: string
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The display name of the project.
|
|
16
|
+
*/
|
|
17
|
+
name: string
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/**
|
|
20
|
+
* The version string of the package.
|
|
21
|
+
*/
|
|
22
|
+
version: string
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The date when the package was built (ISO timestamp).
|
|
26
|
+
*/
|
|
27
|
+
builddate: string
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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.
|
|
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.2",
|
|
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
|
-
"
|
|
37
|
-
"@
|
|
38
|
-
"cpx2": "^8.0.0",
|
|
39
|
-
"eslint": "^9.29.0",
|
|
40
|
-
"jiti": "^2.4.2",
|
|
41
|
-
"premove": "^4.0.0",
|
|
42
|
-
"typescript": "^5.8.3",
|
|
43
|
-
"vite": "^7.0.0"
|
|
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
|
}
|