@lntvow/vite-plugin 0.0.2 → 0.0.4

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/dist/index.cjs CHANGED
@@ -1,11 +1,15 @@
1
1
  'use strict';
2
2
 
3
+ const path = require('node:path');
4
+ const fs = require('node:fs');
3
5
  const dayjs = require('dayjs');
4
6
  const utc = require('dayjs/plugin/utc.js');
5
7
  const timezone = require('dayjs/plugin/timezone.js');
6
8
 
7
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
8
10
 
11
+ const path__default = /*#__PURE__*/_interopDefaultCompat(path);
12
+ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
9
13
  const dayjs__default = /*#__PURE__*/_interopDefaultCompat(dayjs);
10
14
  const utc__default = /*#__PURE__*/_interopDefaultCompat(utc);
11
15
  const timezone__default = /*#__PURE__*/_interopDefaultCompat(timezone);
@@ -13,7 +17,17 @@ const timezone__default = /*#__PURE__*/_interopDefaultCompat(timezone);
13
17
  dayjs__default.extend(utc__default);
14
18
  dayjs__default.extend(timezone__default);
15
19
  function vitePluginLogs(options = {}) {
16
- const { name, version } = options;
20
+ const { name = "LNTVOW_VERSION" } = options;
21
+ let version = options.version;
22
+ if (!version) {
23
+ const packageJsonContent = fs__default.readFileSync(
24
+ path__default.resolve(process.cwd(), "package.json"),
25
+ "utf8"
26
+ );
27
+ if (!packageJsonContent)
28
+ throw new Error("version is required");
29
+ version = JSON.parse(packageJsonContent).version;
30
+ }
17
31
  return {
18
32
  name: "vite-plugin-logs",
19
33
  transform(code, id) {
@@ -26,10 +40,8 @@ function vitePluginLogs(options = {}) {
26
40
 
27
41
  ${code}
28
42
 
29
- import('../package.json').then(res => {
30
- localStorage.setItem(${name || `'LNTVOW_VERSION'`}, JSON.stringify(['${time}', ${version || "res.version"}]))
31
- log('version', '${time}', ${version || "res.version"})
32
- })
43
+ localStorage.setItem('${name}', JSON.stringify(['${time}', '${version}']))
44
+ log('version', '${time}', '${version}')
33
45
 
34
46
  `
35
47
  };
package/dist/index.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import path from 'node:path';
2
+ import fs from 'node:fs';
1
3
  import dayjs from 'dayjs';
2
4
  import utc from 'dayjs/plugin/utc.js';
3
5
  import timezone from 'dayjs/plugin/timezone.js';
@@ -5,7 +7,17 @@ import timezone from 'dayjs/plugin/timezone.js';
5
7
  dayjs.extend(utc);
6
8
  dayjs.extend(timezone);
7
9
  function vitePluginLogs(options = {}) {
8
- const { name, version } = options;
10
+ const { name = "LNTVOW_VERSION" } = options;
11
+ let version = options.version;
12
+ if (!version) {
13
+ const packageJsonContent = fs.readFileSync(
14
+ path.resolve(process.cwd(), "package.json"),
15
+ "utf8"
16
+ );
17
+ if (!packageJsonContent)
18
+ throw new Error("version is required");
19
+ version = JSON.parse(packageJsonContent).version;
20
+ }
9
21
  return {
10
22
  name: "vite-plugin-logs",
11
23
  transform(code, id) {
@@ -18,10 +30,8 @@ function vitePluginLogs(options = {}) {
18
30
 
19
31
  ${code}
20
32
 
21
- import('../package.json').then(res => {
22
- localStorage.setItem(${name || `'LNTVOW_VERSION'`}, JSON.stringify(['${time}', ${version || "res.version"}]))
23
- log('version', '${time}', ${version || "res.version"})
24
- })
33
+ localStorage.setItem('${name}', JSON.stringify(['${time}', '${version}']))
34
+ log('version', '${time}', '${version}')
25
35
 
26
36
  `
27
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lntvow/vite-plugin",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "vite插件",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -8,6 +8,9 @@
8
8
  "files": [
9
9
  "dist"
10
10
  ],
11
+ "main": "dist/index.cjs",
12
+ "module": "dist/index.mjs",
13
+ "types": "dist/index.d.ts",
11
14
  "dependencies": {
12
15
  "@lntvow/utils": "^1.8.5",
13
16
  "dayjs": "^1.11.10"