@web-remarq/unplugin 0.0.1 → 0.0.3
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/README.md +154 -0
- package/dist/{chunk-PRGGVU7P.cjs → chunk-LXJOI4H7.cjs} +5 -2
- package/dist/{chunk-CRVREGZW.js → chunk-XB3NQOJG.js} +5 -2
- package/dist/esbuild.cjs +2 -2
- package/dist/esbuild.d.cts +1 -0
- package/dist/esbuild.d.ts +1 -0
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/rollup.cjs +2 -2
- package/dist/rollup.d.cts +1 -0
- package/dist/rollup.d.ts +1 -0
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +2 -2
- package/dist/rspack.d.cts +1 -0
- package/dist/rspack.d.ts +1 -0
- package/dist/rspack.js +1 -1
- package/dist/vite.cjs +2 -2
- package/dist/vite.d.cts +1 -0
- package/dist/vite.d.ts +1 -0
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +2 -2
- package/dist/webpack.d.cts +1 -0
- package/dist/webpack.d.ts +1 -0
- package/dist/webpack.js +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# @web-remarq/unplugin
|
|
2
|
+
|
|
3
|
+
Universal build plugin that injects source location attributes into JSX and Vue template elements for [web-remarq](https://www.npmjs.com/package/web-remarq).
|
|
4
|
+
|
|
5
|
+
Works with Vite, webpack, Rollup, esbuild, and Rspack. Supports JSX/TSX and Vue SFC templates.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -D @web-remarq/unplugin
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
### Vite
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
// vite.config.js
|
|
19
|
+
import remarq from '@web-remarq/unplugin/vite'
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
plugins: [remarq()]
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### webpack
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
// webpack.config.js
|
|
30
|
+
const remarq = require('@web-remarq/unplugin/webpack').default
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
plugins: [remarq()]
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Rollup
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
// rollup.config.js
|
|
41
|
+
import remarq from '@web-remarq/unplugin/rollup'
|
|
42
|
+
|
|
43
|
+
export default {
|
|
44
|
+
plugins: [remarq()]
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### esbuild
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import remarq from '@web-remarq/unplugin/esbuild'
|
|
52
|
+
import { build } from 'esbuild'
|
|
53
|
+
|
|
54
|
+
build({
|
|
55
|
+
plugins: [remarq()]
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Rspack
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
// rspack.config.js
|
|
63
|
+
const remarq = require('@web-remarq/unplugin/rspack').default
|
|
64
|
+
|
|
65
|
+
module.exports = {
|
|
66
|
+
plugins: [remarq()]
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## What it does
|
|
71
|
+
|
|
72
|
+
Transforms this:
|
|
73
|
+
|
|
74
|
+
```jsx
|
|
75
|
+
function LoginForm() {
|
|
76
|
+
return <button className="submit">Log in</button>
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Into this:
|
|
81
|
+
|
|
82
|
+
```jsx
|
|
83
|
+
function LoginForm() {
|
|
84
|
+
return <button className="submit"
|
|
85
|
+
data-remarq-source="src/components/LoginForm.tsx:3:9"
|
|
86
|
+
data-remarq-component="LoginForm">Log in</button>
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Vue SFC templates are also transformed:
|
|
91
|
+
|
|
92
|
+
```vue
|
|
93
|
+
<template>
|
|
94
|
+
<div class="wrapper">
|
|
95
|
+
<button>Save</button>
|
|
96
|
+
</div>
|
|
97
|
+
</template>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Becomes:
|
|
101
|
+
|
|
102
|
+
```vue
|
|
103
|
+
<template>
|
|
104
|
+
<div class="wrapper"
|
|
105
|
+
data-remarq-source="src/components/SavePanel.vue:2:4"
|
|
106
|
+
data-remarq-component="SavePanel">
|
|
107
|
+
<button
|
|
108
|
+
data-remarq-source="src/components/SavePanel.vue:3:8"
|
|
109
|
+
data-remarq-component="SavePanel">Save</button>
|
|
110
|
+
</div>
|
|
111
|
+
</template>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Options
|
|
115
|
+
|
|
116
|
+
| Option | Type | Default | Description |
|
|
117
|
+
|--------|------|---------|-------------|
|
|
118
|
+
| `include` | `string[]` | `['**/*.jsx', '**/*.tsx', '**/*.vue']` | Glob patterns for files to transform |
|
|
119
|
+
| `exclude` | `string[]` | `['node_modules/**']` | Glob patterns to skip |
|
|
120
|
+
| `production` | `boolean` | `false` | Enable in production builds |
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
remarq({
|
|
124
|
+
include: ['src/**/*.tsx', 'src/**/*.vue'],
|
|
125
|
+
exclude: ['node_modules/**', '**/*.test.*'],
|
|
126
|
+
production: false,
|
|
127
|
+
})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Security note:** `production: true` exposes source file paths in the DOM. Use only for internal/staging environments.
|
|
131
|
+
|
|
132
|
+
## JSX/TSX
|
|
133
|
+
|
|
134
|
+
Uses `@babel/parser` for AST-based transformation. Handles TypeScript, decorators, and all JSX patterns. Component name is detected from the nearest function/class declaration.
|
|
135
|
+
|
|
136
|
+
## Vue SFC
|
|
137
|
+
|
|
138
|
+
Parses `<template>` blocks and injects attributes on HTML elements. Vue built-in tags (`template`, `slot`, `component`, `transition`, `keep-alive`, `teleport`, `suspense`) are skipped. Component name is derived from the filename.
|
|
139
|
+
|
|
140
|
+
## How it differs from `@web-remarq/babel-plugin`
|
|
141
|
+
|
|
142
|
+
| | `@web-remarq/babel-plugin` | `@web-remarq/unplugin` |
|
|
143
|
+
|-|---|---|
|
|
144
|
+
| **Use when** | Project uses Babel | Project uses Vite/SWC/esbuild without Babel |
|
|
145
|
+
| **Bundlers** | Babel only | Vite, webpack, Rollup, esbuild, Rspack |
|
|
146
|
+
| **JSX** | Yes | Yes |
|
|
147
|
+
| **Vue SFC** | No | Yes |
|
|
148
|
+
| **Parsing** | Babel AST (native) | `@babel/parser` (bundled) |
|
|
149
|
+
|
|
150
|
+
If your project already uses Babel, prefer `@web-remarq/babel-plugin` — it's lighter and integrates natively.
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT
|
|
@@ -15,7 +15,7 @@ function findComponentName(ast, jsxStart) {
|
|
|
15
15
|
}
|
|
16
16
|
if (node.type === "ExportDefaultDeclaration") {
|
|
17
17
|
const decl = node.declaration;
|
|
18
|
-
if (decl.type === "FunctionDeclaration" && decl.id && typeof decl.id.name === "string") {
|
|
18
|
+
if ((decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") && decl.id && typeof decl.id.name === "string") {
|
|
19
19
|
return decl.id.name;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -39,6 +39,9 @@ function findComponentName(ast, jsxStart) {
|
|
|
39
39
|
if (decl.type === "FunctionDeclaration" && decl.id && containsPosition(decl, jsxStart)) {
|
|
40
40
|
return decl.id.name;
|
|
41
41
|
}
|
|
42
|
+
if (decl.type === "ClassDeclaration" && decl.id && containsPosition(decl, jsxStart)) {
|
|
43
|
+
return decl.id.name;
|
|
44
|
+
}
|
|
42
45
|
}
|
|
43
46
|
if (node.type === "ClassDeclaration" && node.id && containsPosition(node, jsxStart)) {
|
|
44
47
|
return node.id.name;
|
|
@@ -162,7 +165,7 @@ var DEFAULT_INCLUDE = ["**/*.jsx", "**/*.tsx", "**/*.vue"];
|
|
|
162
165
|
var DEFAULT_EXCLUDE = ["node_modules/**"];
|
|
163
166
|
function createFilter(include, exclude) {
|
|
164
167
|
function toRegex(glob) {
|
|
165
|
-
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\xA7GLOBSTAR\xA7").replace(/\*/g, "[^/]*").replace(/§GLOBSTAR§/g, ".*").replace(/\?/g, "[^/]");
|
|
168
|
+
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\xA7GLOBSTAR\xA7").replace(/\*/g, "[^/]*").replace(/\/§GLOBSTAR§\//g, "\xA7OPTPATH\xA7").replace(/§GLOBSTAR§/g, ".*").replace(/\?/g, "[^/]").replace(/§OPTPATH§/g, "/(?:.*/)?");
|
|
166
169
|
return new RegExp(`(?:^|/)${escaped}$`);
|
|
167
170
|
}
|
|
168
171
|
const includePatterns = include.map(toRegex);
|
|
@@ -15,7 +15,7 @@ function findComponentName(ast, jsxStart) {
|
|
|
15
15
|
}
|
|
16
16
|
if (node.type === "ExportDefaultDeclaration") {
|
|
17
17
|
const decl = node.declaration;
|
|
18
|
-
if (decl.type === "FunctionDeclaration" && decl.id && typeof decl.id.name === "string") {
|
|
18
|
+
if ((decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") && decl.id && typeof decl.id.name === "string") {
|
|
19
19
|
return decl.id.name;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -39,6 +39,9 @@ function findComponentName(ast, jsxStart) {
|
|
|
39
39
|
if (decl.type === "FunctionDeclaration" && decl.id && containsPosition(decl, jsxStart)) {
|
|
40
40
|
return decl.id.name;
|
|
41
41
|
}
|
|
42
|
+
if (decl.type === "ClassDeclaration" && decl.id && containsPosition(decl, jsxStart)) {
|
|
43
|
+
return decl.id.name;
|
|
44
|
+
}
|
|
42
45
|
}
|
|
43
46
|
if (node.type === "ClassDeclaration" && node.id && containsPosition(node, jsxStart)) {
|
|
44
47
|
return node.id.name;
|
|
@@ -162,7 +165,7 @@ var DEFAULT_INCLUDE = ["**/*.jsx", "**/*.tsx", "**/*.vue"];
|
|
|
162
165
|
var DEFAULT_EXCLUDE = ["node_modules/**"];
|
|
163
166
|
function createFilter(include, exclude) {
|
|
164
167
|
function toRegex(glob) {
|
|
165
|
-
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\xA7GLOBSTAR\xA7").replace(/\*/g, "[^/]*").replace(/§GLOBSTAR§/g, ".*").replace(/\?/g, "[^/]");
|
|
168
|
+
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\xA7GLOBSTAR\xA7").replace(/\*/g, "[^/]*").replace(/\/§GLOBSTAR§\//g, "\xA7OPTPATH\xA7").replace(/§GLOBSTAR§/g, ".*").replace(/\?/g, "[^/]").replace(/§OPTPATH§/g, "/(?:.*/)?");
|
|
166
169
|
return new RegExp(`(?:^|/)${escaped}$`);
|
|
167
170
|
}
|
|
168
171
|
const includePatterns = include.map(toRegex);
|
package/dist/esbuild.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkLXJOI4H7cjs = require('./chunk-LXJOI4H7.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = _chunkLXJOI4H7cjs.esbuildPlugin;
|
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.d.ts
CHANGED
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkLXJOI4H7cjs = require('./chunk-LXJOI4H7.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
@@ -13,4 +13,4 @@ var _chunkPRGGVU7Pcjs = require('./chunk-PRGGVU7P.cjs');
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
exports.default =
|
|
16
|
+
exports.default = _chunkLXJOI4H7cjs.index_default; exports.esbuildPlugin = _chunkLXJOI4H7cjs.esbuildPlugin; exports.rollupPlugin = _chunkLXJOI4H7cjs.rollupPlugin; exports.rspackPlugin = _chunkLXJOI4H7cjs.rspackPlugin; exports.vitePlugin = _chunkLXJOI4H7cjs.vitePlugin; exports.webpackPlugin = _chunkLXJOI4H7cjs.webpackPlugin;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as esbuild from 'esbuild';
|
|
2
2
|
import * as rollup from 'rollup';
|
|
3
|
+
import * as vite from 'vite';
|
|
3
4
|
import * as _unplugin from 'unplugin';
|
|
4
5
|
|
|
5
6
|
interface Options {
|
|
@@ -12,7 +13,7 @@ interface Options {
|
|
|
12
13
|
}
|
|
13
14
|
declare const unplugin: _unplugin.UnpluginInstance<Options, boolean>;
|
|
14
15
|
|
|
15
|
-
declare const vitePlugin: (options: Options) => any;
|
|
16
|
+
declare const vitePlugin: (options: Options) => vite.Plugin<any> | vite.Plugin<any>[];
|
|
16
17
|
declare const rollupPlugin: (options: Options) => rollup.Plugin<any> | rollup.Plugin<any>[];
|
|
17
18
|
declare const webpackPlugin: (options: Options) => WebpackPluginInstance;
|
|
18
19
|
declare const esbuildPlugin: (options: Options) => esbuild.Plugin;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as esbuild from 'esbuild';
|
|
2
2
|
import * as rollup from 'rollup';
|
|
3
|
+
import * as vite from 'vite';
|
|
3
4
|
import * as _unplugin from 'unplugin';
|
|
4
5
|
|
|
5
6
|
interface Options {
|
|
@@ -12,7 +13,7 @@ interface Options {
|
|
|
12
13
|
}
|
|
13
14
|
declare const unplugin: _unplugin.UnpluginInstance<Options, boolean>;
|
|
14
15
|
|
|
15
|
-
declare const vitePlugin: (options: Options) => any;
|
|
16
|
+
declare const vitePlugin: (options: Options) => vite.Plugin<any> | vite.Plugin<any>[];
|
|
16
17
|
declare const rollupPlugin: (options: Options) => rollup.Plugin<any> | rollup.Plugin<any>[];
|
|
17
18
|
declare const webpackPlugin: (options: Options) => WebpackPluginInstance;
|
|
18
19
|
declare const esbuildPlugin: (options: Options) => esbuild.Plugin;
|
package/dist/index.js
CHANGED
package/dist/rollup.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkLXJOI4H7cjs = require('./chunk-LXJOI4H7.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = _chunkLXJOI4H7cjs.rollupPlugin;
|
package/dist/rollup.d.cts
CHANGED
package/dist/rollup.d.ts
CHANGED
package/dist/rollup.js
CHANGED
package/dist/rspack.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkLXJOI4H7cjs = require('./chunk-LXJOI4H7.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = _chunkLXJOI4H7cjs.rspackPlugin;
|
package/dist/rspack.d.cts
CHANGED
package/dist/rspack.d.ts
CHANGED
package/dist/rspack.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkLXJOI4H7cjs = require('./chunk-LXJOI4H7.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = _chunkLXJOI4H7cjs.vitePlugin;
|
package/dist/vite.d.cts
CHANGED
package/dist/vite.d.ts
CHANGED
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkLXJOI4H7cjs = require('./chunk-LXJOI4H7.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = _chunkLXJOI4H7cjs.webpackPlugin;
|
package/dist/webpack.d.cts
CHANGED
package/dist/webpack.d.ts
CHANGED
package/dist/webpack.js
CHANGED