@ripple-ts/vite-plugin 0.3.61 → 0.3.62
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 +13 -0
- package/package.json +3 -3
- package/src/index.js +9 -9
- package/tests/transform-source-maps.test.js +96 -0
- package/types/index.d.ts +10 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ripple-ts/vite-plugin
|
|
2
2
|
|
|
3
|
+
## 0.3.62
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1148](https://github.com/Ripple-TS/ripple/pull/1148)
|
|
8
|
+
[`78d766a`](https://github.com/Ripple-TS/ripple/commit/78d766ad263152cd7a8decf64979d33be52a0124)
|
|
9
|
+
Thanks [@aleclarson](https://github.com/aleclarson)! - Chain TSRX compiler
|
|
10
|
+
source maps through the Vite JSX transform so browser devtools show original
|
|
11
|
+
`.tsrx` sources instead of generated TSX.
|
|
12
|
+
|
|
13
|
+
- Updated dependencies []:
|
|
14
|
+
- @ripple-ts/adapter@0.3.62
|
|
15
|
+
|
|
3
16
|
## 0.3.61
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Vite plugin for Ripple",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.3.
|
|
6
|
+
"version": "0.3.62",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"module": "src/index.js",
|
|
9
9
|
"main": "src/index.js",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"url": "https://github.com/Ripple-TS/ripple/issues"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@ripple-ts/adapter": "0.3.
|
|
35
|
+
"@ripple-ts/adapter": "0.3.62",
|
|
36
36
|
"@tsrx/ripple": "0.1.11"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^24.3.0",
|
|
40
40
|
"type-fest": "^5.6.0",
|
|
41
41
|
"vite": "^8.0.12",
|
|
42
|
-
"ripple": "0.3.
|
|
42
|
+
"ripple": "0.3.62"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @import {PackageJson} from 'type-fest' */
|
|
2
2
|
/** @import {Plugin, ResolvedConfig, ViteDevServer} from 'vite' */
|
|
3
|
-
/** @import {RipplePluginOptions, RippleConfigOptions, ResolvedRippleConfig, Route, RenderRoute} from '@ripple-ts/vite-plugin' */
|
|
3
|
+
/** @import {RipplePlugin, RipplePluginOptions, RippleConfigOptions, ResolvedRippleConfig, Route, RenderRoute} from '@ripple-ts/vite-plugin' */
|
|
4
4
|
|
|
5
5
|
/// <reference types="@tsrx/ripple/types/rpc" />
|
|
6
6
|
|
|
@@ -413,7 +413,7 @@ export function ripple(inlineOptions = {}) {
|
|
|
413
413
|
return loadedRippleConfig;
|
|
414
414
|
}
|
|
415
415
|
|
|
416
|
-
/** @type {Plugin[]} */
|
|
416
|
+
/** @type {[RipplePlugin, ...Plugin[]]} */
|
|
417
417
|
const plugins = [
|
|
418
418
|
{
|
|
419
419
|
name: 'vite-plugin-ripple',
|
|
@@ -1248,14 +1248,14 @@ import { hydrate, mount } from 'ripple';
|
|
|
1248
1248
|
transform: {
|
|
1249
1249
|
filter: { id: RIPPLE_EXTENSION_PATTERN },
|
|
1250
1250
|
|
|
1251
|
-
async handler(
|
|
1251
|
+
async handler(source_code, id, opts) {
|
|
1252
1252
|
const filename = id.replace(root, '');
|
|
1253
1253
|
const ssr = opts?.ssr === true || this.environment.config.consumer === 'server';
|
|
1254
1254
|
|
|
1255
1255
|
const is_dev = config?.command === 'serve';
|
|
1256
1256
|
const current_ripple_config = await get_current_ripple_config();
|
|
1257
1257
|
|
|
1258
|
-
|
|
1258
|
+
let { code, css, map } = await compile(source_code, filename, {
|
|
1259
1259
|
mode: ssr ? 'server' : 'client',
|
|
1260
1260
|
dev: is_dev,
|
|
1261
1261
|
hmr: is_dev && !ssr,
|
|
@@ -1266,17 +1266,17 @@ import { hydrate, mount } from 'ripple';
|
|
|
1266
1266
|
});
|
|
1267
1267
|
|
|
1268
1268
|
// Track modules with `module server` declarations for RPC (client build only)
|
|
1269
|
-
if (isBuild && !ssr &&
|
|
1269
|
+
if (isBuild && !ssr && code.includes('_$_.rpc(')) {
|
|
1270
1270
|
serverModuleModules.add(filename);
|
|
1271
1271
|
}
|
|
1272
1272
|
|
|
1273
|
-
if (
|
|
1273
|
+
if (css) {
|
|
1274
1274
|
const cssId = createVirtualImportId(filename, root, 'style');
|
|
1275
|
-
cssCache.set(cssId,
|
|
1276
|
-
|
|
1275
|
+
cssCache.set(cssId, css);
|
|
1276
|
+
code += `\nimport ${JSON.stringify(cssId)};\n`;
|
|
1277
1277
|
}
|
|
1278
1278
|
|
|
1279
|
-
return { code
|
|
1279
|
+
return { code, map };
|
|
1280
1280
|
},
|
|
1281
1281
|
},
|
|
1282
1282
|
},
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/** @import {RipplePlugin} from '@ripple-ts/vite-plugin' */
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect } from 'vitest';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { ripple } from '@ripple-ts/vite-plugin';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Pull the core ripple plugin out of the plugin array. The narrowed
|
|
9
|
+
* `name: 'vite-plugin-ripple'` on {@link import('../types/index.js').RipplePlugin}
|
|
10
|
+
* lets `find` produce a typed result with no cast.
|
|
11
|
+
*
|
|
12
|
+
* @returns {RipplePlugin}
|
|
13
|
+
*/
|
|
14
|
+
function get_ripple_plugin() {
|
|
15
|
+
const [plugin] = ripple({ excludeRippleExternalModules: true });
|
|
16
|
+
return plugin;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {RipplePlugin} plugin
|
|
21
|
+
* @param {string} root
|
|
22
|
+
*/
|
|
23
|
+
async function init_plugin(plugin, root) {
|
|
24
|
+
const hook =
|
|
25
|
+
typeof plugin.configResolved === 'function'
|
|
26
|
+
? plugin.configResolved
|
|
27
|
+
: plugin.configResolved?.handler;
|
|
28
|
+
if (!hook) return;
|
|
29
|
+
// Bind a stub `this` so we don't trip Vite's hook `this:` constraint.
|
|
30
|
+
await hook.call(/** @type {any} */ ({}), /** @type {any} */ ({ root, command: 'serve' }));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {RipplePlugin} plugin
|
|
35
|
+
* @param {string} source
|
|
36
|
+
* @param {string} id
|
|
37
|
+
*/
|
|
38
|
+
async function call_transform(plugin, source, id) {
|
|
39
|
+
const transform = plugin.transform;
|
|
40
|
+
if (!transform) throw new Error('plugin has no transform hook');
|
|
41
|
+
const handler = typeof transform === 'function' ? transform : transform.handler;
|
|
42
|
+
const ctx = /** @type {any} */ ({
|
|
43
|
+
environment: { config: { consumer: 'client' } },
|
|
44
|
+
});
|
|
45
|
+
return handler.call(ctx, source, id, undefined);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('vite-plugin-ripple source maps', () => {
|
|
49
|
+
it('returns a map that points back to the original .tsrx source', async () => {
|
|
50
|
+
const plugin = get_ripple_plugin();
|
|
51
|
+
const root = '/virtual-root';
|
|
52
|
+
await init_plugin(plugin, root);
|
|
53
|
+
|
|
54
|
+
const id = `${root}/App.tsrx`;
|
|
55
|
+
const source = `export component App() {
|
|
56
|
+
let message = 'Hello world';
|
|
57
|
+
<div>{message}</div>
|
|
58
|
+
}`;
|
|
59
|
+
|
|
60
|
+
const result = await call_transform(plugin, source, id);
|
|
61
|
+
|
|
62
|
+
expect(result).toBeTruthy();
|
|
63
|
+
const map = /** @type {any} */ (result).map;
|
|
64
|
+
// `@tsrx/ripple`'s esrap call uses `path.basename` for `sourceMapSource`,
|
|
65
|
+
// so `sources` is the bare filename rather than the full id.
|
|
66
|
+
expect(map.sources).toEqual([path.basename(id)]);
|
|
67
|
+
expect(map.sourcesContent).toEqual([source]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('keeps the map valid when a <style> block triggers a virtual css import', async () => {
|
|
71
|
+
const plugin = get_ripple_plugin();
|
|
72
|
+
const root = '/virtual-root';
|
|
73
|
+
await init_plugin(plugin, root);
|
|
74
|
+
|
|
75
|
+
const id = `${root}/Styled.tsrx`;
|
|
76
|
+
const source = `export component Styled() {
|
|
77
|
+
<div>{'Hello world'}</div>
|
|
78
|
+
|
|
79
|
+
<style>
|
|
80
|
+
.div {
|
|
81
|
+
color: red;
|
|
82
|
+
}
|
|
83
|
+
</style>
|
|
84
|
+
}`;
|
|
85
|
+
|
|
86
|
+
const result = await call_transform(plugin, source, id);
|
|
87
|
+
|
|
88
|
+
expect(result).toBeTruthy();
|
|
89
|
+
const code = /** @type {any} */ (result).code;
|
|
90
|
+
const map = /** @type {any} */ (result).map;
|
|
91
|
+
// CSS import is appended (not prepended), so existing mappings stay
|
|
92
|
+
// aligned and `sourcesContent` still carries the original source.
|
|
93
|
+
expect(code).toContain('?ripple&type=style&lang.css');
|
|
94
|
+
expect(map.sourcesContent).toEqual([source]);
|
|
95
|
+
});
|
|
96
|
+
});
|
package/types/index.d.ts
CHANGED
|
@@ -5,7 +5,16 @@ import type { RuntimePrimitives } from '@ripple-ts/adapter';
|
|
|
5
5
|
// Plugin exports
|
|
6
6
|
// ============================================================================
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The core `vite-plugin-ripple` plugin produced by {@link ripple}. The `name`
|
|
10
|
+
* is narrowed so consumers (and tests) can locate it via `find` without an
|
|
11
|
+
* `as` cast.
|
|
12
|
+
*/
|
|
13
|
+
export interface RipplePlugin extends Plugin {
|
|
14
|
+
readonly name: 'vite-plugin-ripple';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function ripple(options?: RipplePluginOptions): [RipplePlugin, ...Plugin[]];
|
|
9
18
|
export function defineConfig(options: RippleConfigOptions): RippleConfigOptions;
|
|
10
19
|
export function resolveRippleConfig(
|
|
11
20
|
raw: RippleConfigOptions,
|