@ripple-ts/vite-plugin 0.2.153

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Dominic Gannaway
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/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@ripple-ts/vite-plugin",
3
+ "description": "Vite plugin for Ripple",
4
+ "license": "MIT",
5
+ "author": "Dominic Gannaway",
6
+ "version": "0.2.153",
7
+ "type": "module",
8
+ "module": "src/index.js",
9
+ "main": "src/index.js",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./types/index.d.ts",
13
+ "import": "./src/index.js",
14
+ "default": "./src/index.js"
15
+ }
16
+ },
17
+ "homepage": "https://ripple-ts.com",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/Ripple-TS/ripple.git",
21
+ "directory": "packages/vite-plugin"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/Ripple-TS/ripple/issues"
25
+ },
26
+ "devDependencies": {
27
+ "vite": "^7.1.9",
28
+ "ripple": "0.2.153"
29
+ }
30
+ }
package/src/index.js ADDED
@@ -0,0 +1,78 @@
1
+ import { compile } from 'ripple/compiler';
2
+ import fs from 'node:fs';
3
+
4
+ const VITE_FS_PREFIX = '/@fs/';
5
+ const IS_WINDOWS = process.platform === 'win32';
6
+
7
+ function existsInRoot(filename, root) {
8
+ if (filename.startsWith(VITE_FS_PREFIX)) {
9
+ return false; // vite already tagged it as out of root
10
+ }
11
+ return fs.existsSync(root + filename);
12
+ }
13
+
14
+ function createVirtualImportId(filename, root, type) {
15
+ const parts = ['ripple', `type=${type}`];
16
+ if (type === 'style') {
17
+ parts.push('lang.css');
18
+ }
19
+ if (existsInRoot(filename, root)) {
20
+ filename = root + filename;
21
+ } else if (filename.startsWith(VITE_FS_PREFIX)) {
22
+ filename = IS_WINDOWS
23
+ ? filename.slice(VITE_FS_PREFIX.length) // remove /@fs/ from /@fs/C:/...
24
+ : filename.slice(VITE_FS_PREFIX.length - 1); // remove /@fs from /@fs/home/user
25
+ }
26
+ // return same virtual id format as vite-plugin-vue eg ...App.ripple?ripple&type=style&lang.css
27
+ return `${filename}?${parts.join('&')}`;
28
+ }
29
+
30
+ export function ripple(inlineOptions) {
31
+ const api = {};
32
+
33
+ let root;
34
+
35
+ const cssCache = new Map();
36
+
37
+ const plugins = [
38
+ {
39
+ name: 'vite-plugin',
40
+ // make sure our resolver runs before vite internal resolver to resolve ripple field correctly
41
+ enforce: 'pre',
42
+ api,
43
+
44
+ async configResolved(config) {
45
+ root = config.root;
46
+ },
47
+
48
+ async load(id, opts) {
49
+ if (cssCache.has(id)) {
50
+ return cssCache.get(id);
51
+ }
52
+ },
53
+
54
+ transform: {
55
+ filter: { id: /\.ripple$/ },
56
+
57
+ async handler(code, id, opts) {
58
+ const filename = id.replace(root, '');
59
+ const ssr = this.environment.config.consumer === 'server';
60
+
61
+ const { js, css } = await compile(code, filename, {
62
+ mode: ssr ? 'server' : 'client',
63
+ });
64
+
65
+ if (css !== '') {
66
+ const cssId = createVirtualImportId(filename, root, 'style');
67
+ cssCache.set(cssId, css);
68
+ js.code += `\nimport ${JSON.stringify(cssId)};\n`;
69
+ }
70
+
71
+ return js;
72
+ },
73
+ },
74
+ },
75
+ ];
76
+
77
+ return plugins;
78
+ }
@@ -0,0 +1,3 @@
1
+ declare module 'vite-plugin' {
2
+ export function ripple(): any
3
+ }