@tooltify/integration-rspack 0.1.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.
@@ -0,0 +1,10 @@
1
+ import * as react from 'react';
2
+ export { Fragment } from 'react/jsx-runtime';
3
+
4
+ declare function jsxDEV(type: any, props: any, key: any, isStaticChildren: boolean, source?: {
5
+ fileName?: string;
6
+ lineNumber?: number;
7
+ columnNumber?: number;
8
+ }): react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
9
+
10
+ export { jsxDEV };
@@ -0,0 +1,19 @@
1
+ // ../helpers/react-transform-source.ts
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment } from "react/jsx-runtime";
3
+ function jsxDEV(type, props, key, isStaticChildren, source) {
4
+ if (typeof type === "string" && source?.fileName) {
5
+ const filePath = source.fileName;
6
+ const line = source.lineNumber || 0;
7
+ const idx = filePath.indexOf(__TOOLTIFY_PACKAGES_DIR__);
8
+ if (idx >= 0) {
9
+ const relative = filePath.slice(idx + __TOOLTIFY_PACKAGES_DIR__.length);
10
+ props = { ...props, "data-source": `${relative}:${line}` };
11
+ }
12
+ }
13
+ const fn = isStaticChildren ? _jsxs : _jsx;
14
+ return fn(type, props, key);
15
+ }
16
+ export {
17
+ Fragment,
18
+ jsxDEV
19
+ };
@@ -0,0 +1,5 @@
1
+ import { RspackPluginInstance } from '@rspack/core';
2
+
3
+ declare function rspackTooltify(): RspackPluginInstance;
4
+
5
+ export { rspackTooltify };
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ // index.ts
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ import { startServer } from "@tooltify/core";
5
+ var __dirname = path.dirname(fileURLToPath(import.meta.url));
6
+ var CUSTOM_JSX_RUNTIME = path.resolve(__dirname, "./helpers/react-transform-source");
7
+ function rspackTooltify() {
8
+ return {
9
+ apply(compiler) {
10
+ const { config, port, buildTracker, cleanDeps } = startServer();
11
+ new compiler.rspack.NormalModuleReplacementPlugin(
12
+ /^react\/jsx-dev-runtime$/,
13
+ CUSTOM_JSX_RUNTIME
14
+ ).apply(compiler);
15
+ new compiler.rspack.DefinePlugin({
16
+ __TOOLTIFY_PACKAGES_DIR__: JSON.stringify(config.packagesDir)
17
+ }).apply(compiler);
18
+ compiler.hooks.compilation.tap("tooltify", (compilation) => {
19
+ compilation.hooks.processAssets.tap(
20
+ { name: "tooltify", stage: compiler.rspack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE },
21
+ (assets) => {
22
+ for (const name of Object.keys(assets)) {
23
+ if (name !== "index.html") continue;
24
+ const html = assets[name].source().toString();
25
+ const injected = html.replace(
26
+ "</head>",
27
+ `<script>window.__TOOLTIFY_URL__="http://localhost:${port}"</script>
28
+ <script src="http://localhost:${port}/tooltify.js" defer></script>
29
+ </head>`
30
+ );
31
+ compilation.updateAsset(
32
+ name,
33
+ new compiler.rspack.sources.RawSource(injected)
34
+ );
35
+ }
36
+ }
37
+ );
38
+ });
39
+ compiler.hooks.shutdown.tap("tooltify", () => cleanDeps());
40
+ compiler.hooks.watchRun.tap("tooltify", (comp) => {
41
+ const changed = comp.modifiedFiles ? [...comp.modifiedFiles] : [];
42
+ if (changed.length === 0) return;
43
+ buildTracker.onFilesChanged(changed);
44
+ });
45
+ compiler.hooks.done.tap("tooltify", (stats) => {
46
+ const hash = stats.hash || Date.now().toString(36);
47
+ const errors = stats.hasErrors() ? stats.compilation.errors.map((e) => e.message) : [];
48
+ buildTracker.onBuildDone(hash, stats.hasErrors(), errors);
49
+ });
50
+ }
51
+ };
52
+ }
53
+ export {
54
+ rspackTooltify
55
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@tooltify/integration-rspack",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "scripts": {
14
+ "build:lib": "tsup",
15
+ "build": "npm run build:lib",
16
+ "prepublishOnly": "npm run build"
17
+ },
18
+ "peerDependencies": {
19
+ "@rspack/core": "^1.7.8",
20
+ "@tooltify/core": "^0.1.0"
21
+ },
22
+ "devDependencies": {
23
+ "@tooltify/core": "*"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "keywords": [
29
+ "devtools",
30
+ "rspack",
31
+ "tooltify",
32
+ "integration"
33
+ ],
34
+ "author": "Franco Werner",
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/franwerner/tooltify.git",
39
+ "directory": "integrations/rspack"
40
+ }
41
+ }