juisy 2.0.0-beta.12 → 2.0.0-beta.13

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/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * juisy v2.0.0-beta.12
2
+ * juisy v2.0.0-beta.13
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * juisy v2.0.0-beta.12
2
+ * juisy v2.0.0-beta.13
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * juisy v2.0.0-beta.12
2
+ * juisy v2.0.0-beta.13
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * juisy v2.0.0-beta.12
2
+ * juisy v2.0.0-beta.13
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
@@ -0,0 +1,18 @@
1
+ import { Plugin } from 'vite';
2
+ export type Options = {
3
+ /**
4
+ * The virtual module ID
5
+ */
6
+ moduleId?: string;
7
+ /**
8
+ * The project globals path (relative form root folder)
9
+ */
10
+ filePath?: string;
11
+ };
12
+ /**
13
+ * Inject project globals via a virtual module
14
+ * @param opts - The plugin options or an array of options
15
+ * @returns {Plugin} The vite plugin function
16
+ */
17
+ export declare function injectProjectGlobals(options?: Options): Plugin;
18
+ export default injectProjectGlobals;
@@ -0,0 +1,36 @@
1
+ /*!
2
+ * juisy v2.0.0-beta.13
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import { getProjectGlobals } from 'juisy';
7
+
8
+ function injectProjectGlobals(options = {}) {
9
+ let moduleId = "virtual:project.globals.js";
10
+ if (options.moduleId) {
11
+ if (options.moduleId.trim().length === 0) {
12
+ throw new Error("Please provide a non-empty module ID for juisy/vite-plugin-inject-project-globals");
13
+ }
14
+ moduleId = options.moduleId;
15
+ }
16
+ return {
17
+ name: "vite-plugin-inject-project-globals",
18
+ enforce: "pre",
19
+ resolveId(id) {
20
+ if (id !== moduleId) {
21
+ return;
22
+ } else {
23
+ return "\0" + moduleId;
24
+ }
25
+ },
26
+ async load(id) {
27
+ if (!id.startsWith("\0") || id.slice(1) !== moduleId) {
28
+ return;
29
+ }
30
+ const PROJECT_GLOBALS = await getProjectGlobals(options.filePath);
31
+ return "export default " + JSON.stringify(PROJECT_GLOBALS);
32
+ }
33
+ };
34
+ }
35
+
36
+ export { injectProjectGlobals as default, injectProjectGlobals };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "juisy",
3
- "version": "2.0.0-beta.12",
3
+ "version": "2.0.0-beta.13",
4
4
  "description": "Make you JavaScript (and/or TypeScript) project juicy!",
5
5
  "type": "module",
6
6
  "files": [
@@ -40,6 +40,10 @@
40
40
  "./vite-plugin-inject-css-variables": {
41
41
  "types": "./dist/vite/plugins/inject-css-variables/index.d.ts",
42
42
  "import": "./dist/vite/plugins/inject-css-variables/index.js"
43
+ },
44
+ "./vite-plugin-inject-project-globals": {
45
+ "types": "./dist/vite/plugins/inject-project-globals/index.d.ts",
46
+ "import": "./dist/vite/plugins/inject-project-globals/index.js"
43
47
  }
44
48
  },
45
49
  "publishConfig": {