@web-remarq/unplugin 0.0.1
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/chunk-CRVREGZW.js +211 -0
- package/dist/chunk-PRGGVU7P.cjs +211 -0
- package/dist/esbuild.cjs +6 -0
- package/dist/esbuild.d.cts +4 -0
- package/dist/esbuild.d.ts +4 -0
- package/dist/esbuild.js +6 -0
- package/dist/index.cjs +16 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +16 -0
- package/dist/rollup.cjs +6 -0
- package/dist/rollup.d.cts +4 -0
- package/dist/rollup.d.ts +4 -0
- package/dist/rollup.js +6 -0
- package/dist/rspack.cjs +6 -0
- package/dist/rspack.d.cts +4 -0
- package/dist/rspack.d.ts +4 -0
- package/dist/rspack.js +6 -0
- package/dist/vite.cjs +6 -0
- package/dist/vite.d.cts +4 -0
- package/dist/vite.d.ts +4 -0
- package/dist/vite.js +6 -0
- package/dist/webpack.cjs +6 -0
- package/dist/webpack.d.cts +4 -0
- package/dist/webpack.d.ts +4 -0
- package/dist/webpack.js +6 -0
- package/package.json +73 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createUnplugin } from "unplugin";
|
|
3
|
+
import { relative } from "path";
|
|
4
|
+
|
|
5
|
+
// src/transform.ts
|
|
6
|
+
import { parse } from "@babel/parser";
|
|
7
|
+
import MagicString from "magic-string";
|
|
8
|
+
function findComponentName(ast, jsxStart) {
|
|
9
|
+
const body = ast.program.body;
|
|
10
|
+
for (const node of body) {
|
|
11
|
+
if (!containsPosition(node, jsxStart)) continue;
|
|
12
|
+
if ((node.type === "FunctionDeclaration" || node.type === "ExportDefaultDeclaration") && containsPosition(node, jsxStart)) {
|
|
13
|
+
if (node.type === "FunctionDeclaration" && node.id) {
|
|
14
|
+
return node.id.name;
|
|
15
|
+
}
|
|
16
|
+
if (node.type === "ExportDefaultDeclaration") {
|
|
17
|
+
const decl = node.declaration;
|
|
18
|
+
if (decl.type === "FunctionDeclaration" && decl.id && typeof decl.id.name === "string") {
|
|
19
|
+
return decl.id.name;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (node.type === "VariableDeclaration") {
|
|
24
|
+
for (const declarator of node.declarations) {
|
|
25
|
+
if (declarator.id.type === "Identifier" && declarator.init && containsPosition(declarator, jsxStart)) {
|
|
26
|
+
return declarator.id.name;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (node.type === "ExportNamedDeclaration" && node.declaration) {
|
|
31
|
+
const decl = node.declaration;
|
|
32
|
+
if (decl.type === "VariableDeclaration") {
|
|
33
|
+
for (const declarator of decl.declarations) {
|
|
34
|
+
if (declarator.id.type === "Identifier" && declarator.init && containsPosition(declarator, jsxStart)) {
|
|
35
|
+
return declarator.id.name;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (decl.type === "FunctionDeclaration" && decl.id && containsPosition(decl, jsxStart)) {
|
|
40
|
+
return decl.id.name;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (node.type === "ClassDeclaration" && node.id && containsPosition(node, jsxStart)) {
|
|
44
|
+
return node.id.name;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
function containsPosition(node, pos) {
|
|
50
|
+
const start = node.start ?? -1;
|
|
51
|
+
const end = node.end ?? -1;
|
|
52
|
+
return start <= pos && pos < end;
|
|
53
|
+
}
|
|
54
|
+
function collectJSXElements(ast) {
|
|
55
|
+
const elements = [];
|
|
56
|
+
walkAST(ast.program, (node) => {
|
|
57
|
+
if (node.type !== "JSXOpeningElement") return;
|
|
58
|
+
const name = node.name;
|
|
59
|
+
if (name.type === "JSXIdentifier" && name.name === "") return;
|
|
60
|
+
if (name.type === "JSXMemberExpression" && name.property?.type === "JSXIdentifier" && name.property.name === "Fragment") return;
|
|
61
|
+
const attrs = node.attributes ?? [];
|
|
62
|
+
const hasSource = attrs.some(
|
|
63
|
+
(attr) => attr.type === "JSXAttribute" && attr.name?.type === "JSXIdentifier" && attr.name.name === "data-remarq-source"
|
|
64
|
+
);
|
|
65
|
+
const nameEnd = name.end ?? node.start + 1;
|
|
66
|
+
const loc = node.loc;
|
|
67
|
+
elements.push({
|
|
68
|
+
insertPos: nameEnd,
|
|
69
|
+
start: node.start,
|
|
70
|
+
line: loc?.start.line ?? 0,
|
|
71
|
+
column: loc?.start.column ?? 0,
|
|
72
|
+
hasSource
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
return elements;
|
|
76
|
+
}
|
|
77
|
+
function walkAST(node, visitor) {
|
|
78
|
+
if (!node || typeof node !== "object") return;
|
|
79
|
+
if (Array.isArray(node)) {
|
|
80
|
+
for (const child of node) walkAST(child, visitor);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const obj = node;
|
|
84
|
+
if (typeof obj.type === "string") {
|
|
85
|
+
visitor(obj);
|
|
86
|
+
}
|
|
87
|
+
for (const key of Object.keys(obj)) {
|
|
88
|
+
if (key === "type" || key === "start" || key === "end" || key === "loc") continue;
|
|
89
|
+
walkAST(obj[key], visitor);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function transformJSX(code, filePath) {
|
|
93
|
+
let ast;
|
|
94
|
+
try {
|
|
95
|
+
ast = parse(code, {
|
|
96
|
+
sourceType: "module",
|
|
97
|
+
plugins: ["jsx", "typescript", "decorators-legacy"],
|
|
98
|
+
sourceFilename: filePath
|
|
99
|
+
});
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const elements = collectJSXElements(ast);
|
|
104
|
+
if (!elements.length) return null;
|
|
105
|
+
const s = new MagicString(code);
|
|
106
|
+
let modified = false;
|
|
107
|
+
for (const el of elements) {
|
|
108
|
+
if (el.hasSource) continue;
|
|
109
|
+
const sourceAttr = ` data-remarq-source="${filePath}:${el.line}:${el.column}"`;
|
|
110
|
+
const componentName = findComponentName(ast, el.start);
|
|
111
|
+
const componentAttr = componentName ? ` data-remarq-component="${componentName}"` : "";
|
|
112
|
+
s.appendLeft(el.insertPos, sourceAttr + componentAttr);
|
|
113
|
+
modified = true;
|
|
114
|
+
}
|
|
115
|
+
if (!modified) return null;
|
|
116
|
+
return {
|
|
117
|
+
code: s.toString(),
|
|
118
|
+
map: s.generateMap({ hires: true })
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function transformVueSFC(code, filePath) {
|
|
122
|
+
const templateMatch = code.match(/<template(\s[^>]*)?>/);
|
|
123
|
+
if (!templateMatch) return null;
|
|
124
|
+
const templateStart = templateMatch.index + templateMatch[0].length;
|
|
125
|
+
const templateEndTag = code.lastIndexOf("</template>");
|
|
126
|
+
if (templateEndTag === -1 || templateEndTag <= templateStart) return null;
|
|
127
|
+
const templateContent = code.slice(templateStart, templateEndTag);
|
|
128
|
+
const tagRegex = /<([a-zA-Z][a-zA-Z0-9-]*(?:\.[a-zA-Z][a-zA-Z0-9-]*)*)(?=[\s/>])/g;
|
|
129
|
+
const s = new MagicString(code);
|
|
130
|
+
let modified = false;
|
|
131
|
+
let match;
|
|
132
|
+
const linesBeforeTemplate = code.slice(0, templateStart).split("\n").length;
|
|
133
|
+
while ((match = tagRegex.exec(templateContent)) !== null) {
|
|
134
|
+
const tagName = match[1];
|
|
135
|
+
if (["template", "slot", "component", "transition", "transition-group", "keep-alive", "teleport", "suspense"].includes(tagName)) continue;
|
|
136
|
+
const afterTag = templateContent.slice(match.index + match[0].length);
|
|
137
|
+
const closingBracket = afterTag.indexOf(">");
|
|
138
|
+
if (closingBracket === -1) continue;
|
|
139
|
+
const attrsPart = afterTag.slice(0, closingBracket);
|
|
140
|
+
if (attrsPart.includes("data-remarq-source")) continue;
|
|
141
|
+
const textBefore = templateContent.slice(0, match.index);
|
|
142
|
+
const lineInTemplate = textBefore.split("\n").length;
|
|
143
|
+
const line = linesBeforeTemplate + lineInTemplate - 1;
|
|
144
|
+
const lastNewline = textBefore.lastIndexOf("\n");
|
|
145
|
+
const col = lastNewline === -1 ? match.index : match.index - lastNewline - 1;
|
|
146
|
+
const insertPos = templateStart + match.index + match[0].length;
|
|
147
|
+
const sourceAttr = ` data-remarq-source="${filePath}:${line}:${col}"`;
|
|
148
|
+
const componentName = filePath.split("/").pop()?.replace(/\.vue$/, "") ?? null;
|
|
149
|
+
const componentAttr = componentName ? ` data-remarq-component="${componentName}"` : "";
|
|
150
|
+
s.appendLeft(insertPos, sourceAttr + componentAttr);
|
|
151
|
+
modified = true;
|
|
152
|
+
}
|
|
153
|
+
if (!modified) return null;
|
|
154
|
+
return {
|
|
155
|
+
code: s.toString(),
|
|
156
|
+
map: s.generateMap({ hires: true })
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/index.ts
|
|
161
|
+
var DEFAULT_INCLUDE = ["**/*.jsx", "**/*.tsx", "**/*.vue"];
|
|
162
|
+
var DEFAULT_EXCLUDE = ["node_modules/**"];
|
|
163
|
+
function createFilter(include, exclude) {
|
|
164
|
+
function toRegex(glob) {
|
|
165
|
+
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\xA7GLOBSTAR\xA7").replace(/\*/g, "[^/]*").replace(/§GLOBSTAR§/g, ".*").replace(/\?/g, "[^/]");
|
|
166
|
+
return new RegExp(`(?:^|/)${escaped}$`);
|
|
167
|
+
}
|
|
168
|
+
const includePatterns = include.map(toRegex);
|
|
169
|
+
const excludePatterns = exclude.map(toRegex);
|
|
170
|
+
return (id) => {
|
|
171
|
+
const normalized = id.split("\\").join("/");
|
|
172
|
+
if (excludePatterns.some((re) => re.test(normalized))) return false;
|
|
173
|
+
return includePatterns.some((re) => re.test(normalized));
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
var unplugin = createUnplugin((options = {}) => {
|
|
177
|
+
const include = options.include ?? DEFAULT_INCLUDE;
|
|
178
|
+
const exclude = options.exclude ?? DEFAULT_EXCLUDE;
|
|
179
|
+
const filter = createFilter(include, exclude);
|
|
180
|
+
return {
|
|
181
|
+
name: "web-remarq",
|
|
182
|
+
enforce: "pre",
|
|
183
|
+
transformInclude(id) {
|
|
184
|
+
if (!options.production && process.env.NODE_ENV === "production") return false;
|
|
185
|
+
return filter(id);
|
|
186
|
+
},
|
|
187
|
+
transform(code, id) {
|
|
188
|
+
const cwd = process.cwd();
|
|
189
|
+
const filePath = relative(cwd, id).split("\\").join("/");
|
|
190
|
+
if (id.endsWith(".vue")) {
|
|
191
|
+
return transformVueSFC(code, filePath) ?? void 0;
|
|
192
|
+
}
|
|
193
|
+
return transformJSX(code, filePath) ?? void 0;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
var index_default = unplugin;
|
|
198
|
+
var vitePlugin = unplugin.vite;
|
|
199
|
+
var rollupPlugin = unplugin.rollup;
|
|
200
|
+
var webpackPlugin = unplugin.webpack;
|
|
201
|
+
var esbuildPlugin = unplugin.esbuild;
|
|
202
|
+
var rspackPlugin = unplugin.rspack;
|
|
203
|
+
|
|
204
|
+
export {
|
|
205
|
+
index_default,
|
|
206
|
+
vitePlugin,
|
|
207
|
+
rollupPlugin,
|
|
208
|
+
webpackPlugin,
|
|
209
|
+
esbuildPlugin,
|
|
210
|
+
rspackPlugin
|
|
211
|
+
};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
|
|
2
|
+
var _unplugin = require('unplugin');
|
|
3
|
+
var _path = require('path');
|
|
4
|
+
|
|
5
|
+
// src/transform.ts
|
|
6
|
+
var _parser = require('@babel/parser');
|
|
7
|
+
var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
|
|
8
|
+
function findComponentName(ast, jsxStart) {
|
|
9
|
+
const body = ast.program.body;
|
|
10
|
+
for (const node of body) {
|
|
11
|
+
if (!containsPosition(node, jsxStart)) continue;
|
|
12
|
+
if ((node.type === "FunctionDeclaration" || node.type === "ExportDefaultDeclaration") && containsPosition(node, jsxStart)) {
|
|
13
|
+
if (node.type === "FunctionDeclaration" && node.id) {
|
|
14
|
+
return node.id.name;
|
|
15
|
+
}
|
|
16
|
+
if (node.type === "ExportDefaultDeclaration") {
|
|
17
|
+
const decl = node.declaration;
|
|
18
|
+
if (decl.type === "FunctionDeclaration" && decl.id && typeof decl.id.name === "string") {
|
|
19
|
+
return decl.id.name;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (node.type === "VariableDeclaration") {
|
|
24
|
+
for (const declarator of node.declarations) {
|
|
25
|
+
if (declarator.id.type === "Identifier" && declarator.init && containsPosition(declarator, jsxStart)) {
|
|
26
|
+
return declarator.id.name;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (node.type === "ExportNamedDeclaration" && node.declaration) {
|
|
31
|
+
const decl = node.declaration;
|
|
32
|
+
if (decl.type === "VariableDeclaration") {
|
|
33
|
+
for (const declarator of decl.declarations) {
|
|
34
|
+
if (declarator.id.type === "Identifier" && declarator.init && containsPosition(declarator, jsxStart)) {
|
|
35
|
+
return declarator.id.name;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (decl.type === "FunctionDeclaration" && decl.id && containsPosition(decl, jsxStart)) {
|
|
40
|
+
return decl.id.name;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (node.type === "ClassDeclaration" && node.id && containsPosition(node, jsxStart)) {
|
|
44
|
+
return node.id.name;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
function containsPosition(node, pos) {
|
|
50
|
+
const start = _nullishCoalesce(node.start, () => ( -1));
|
|
51
|
+
const end = _nullishCoalesce(node.end, () => ( -1));
|
|
52
|
+
return start <= pos && pos < end;
|
|
53
|
+
}
|
|
54
|
+
function collectJSXElements(ast) {
|
|
55
|
+
const elements = [];
|
|
56
|
+
walkAST(ast.program, (node) => {
|
|
57
|
+
if (node.type !== "JSXOpeningElement") return;
|
|
58
|
+
const name = node.name;
|
|
59
|
+
if (name.type === "JSXIdentifier" && name.name === "") return;
|
|
60
|
+
if (name.type === "JSXMemberExpression" && _optionalChain([name, 'access', _ => _.property, 'optionalAccess', _2 => _2.type]) === "JSXIdentifier" && name.property.name === "Fragment") return;
|
|
61
|
+
const attrs = _nullishCoalesce(node.attributes, () => ( []));
|
|
62
|
+
const hasSource = attrs.some(
|
|
63
|
+
(attr) => attr.type === "JSXAttribute" && _optionalChain([attr, 'access', _3 => _3.name, 'optionalAccess', _4 => _4.type]) === "JSXIdentifier" && attr.name.name === "data-remarq-source"
|
|
64
|
+
);
|
|
65
|
+
const nameEnd = _nullishCoalesce(name.end, () => ( node.start + 1));
|
|
66
|
+
const loc = node.loc;
|
|
67
|
+
elements.push({
|
|
68
|
+
insertPos: nameEnd,
|
|
69
|
+
start: node.start,
|
|
70
|
+
line: _nullishCoalesce(_optionalChain([loc, 'optionalAccess', _5 => _5.start, 'access', _6 => _6.line]), () => ( 0)),
|
|
71
|
+
column: _nullishCoalesce(_optionalChain([loc, 'optionalAccess', _7 => _7.start, 'access', _8 => _8.column]), () => ( 0)),
|
|
72
|
+
hasSource
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
return elements;
|
|
76
|
+
}
|
|
77
|
+
function walkAST(node, visitor) {
|
|
78
|
+
if (!node || typeof node !== "object") return;
|
|
79
|
+
if (Array.isArray(node)) {
|
|
80
|
+
for (const child of node) walkAST(child, visitor);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const obj = node;
|
|
84
|
+
if (typeof obj.type === "string") {
|
|
85
|
+
visitor(obj);
|
|
86
|
+
}
|
|
87
|
+
for (const key of Object.keys(obj)) {
|
|
88
|
+
if (key === "type" || key === "start" || key === "end" || key === "loc") continue;
|
|
89
|
+
walkAST(obj[key], visitor);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function transformJSX(code, filePath) {
|
|
93
|
+
let ast;
|
|
94
|
+
try {
|
|
95
|
+
ast = _parser.parse.call(void 0, code, {
|
|
96
|
+
sourceType: "module",
|
|
97
|
+
plugins: ["jsx", "typescript", "decorators-legacy"],
|
|
98
|
+
sourceFilename: filePath
|
|
99
|
+
});
|
|
100
|
+
} catch (e) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const elements = collectJSXElements(ast);
|
|
104
|
+
if (!elements.length) return null;
|
|
105
|
+
const s = new (0, _magicstring2.default)(code);
|
|
106
|
+
let modified = false;
|
|
107
|
+
for (const el of elements) {
|
|
108
|
+
if (el.hasSource) continue;
|
|
109
|
+
const sourceAttr = ` data-remarq-source="${filePath}:${el.line}:${el.column}"`;
|
|
110
|
+
const componentName = findComponentName(ast, el.start);
|
|
111
|
+
const componentAttr = componentName ? ` data-remarq-component="${componentName}"` : "";
|
|
112
|
+
s.appendLeft(el.insertPos, sourceAttr + componentAttr);
|
|
113
|
+
modified = true;
|
|
114
|
+
}
|
|
115
|
+
if (!modified) return null;
|
|
116
|
+
return {
|
|
117
|
+
code: s.toString(),
|
|
118
|
+
map: s.generateMap({ hires: true })
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function transformVueSFC(code, filePath) {
|
|
122
|
+
const templateMatch = code.match(/<template(\s[^>]*)?>/);
|
|
123
|
+
if (!templateMatch) return null;
|
|
124
|
+
const templateStart = templateMatch.index + templateMatch[0].length;
|
|
125
|
+
const templateEndTag = code.lastIndexOf("</template>");
|
|
126
|
+
if (templateEndTag === -1 || templateEndTag <= templateStart) return null;
|
|
127
|
+
const templateContent = code.slice(templateStart, templateEndTag);
|
|
128
|
+
const tagRegex = /<([a-zA-Z][a-zA-Z0-9-]*(?:\.[a-zA-Z][a-zA-Z0-9-]*)*)(?=[\s/>])/g;
|
|
129
|
+
const s = new (0, _magicstring2.default)(code);
|
|
130
|
+
let modified = false;
|
|
131
|
+
let match;
|
|
132
|
+
const linesBeforeTemplate = code.slice(0, templateStart).split("\n").length;
|
|
133
|
+
while ((match = tagRegex.exec(templateContent)) !== null) {
|
|
134
|
+
const tagName = match[1];
|
|
135
|
+
if (["template", "slot", "component", "transition", "transition-group", "keep-alive", "teleport", "suspense"].includes(tagName)) continue;
|
|
136
|
+
const afterTag = templateContent.slice(match.index + match[0].length);
|
|
137
|
+
const closingBracket = afterTag.indexOf(">");
|
|
138
|
+
if (closingBracket === -1) continue;
|
|
139
|
+
const attrsPart = afterTag.slice(0, closingBracket);
|
|
140
|
+
if (attrsPart.includes("data-remarq-source")) continue;
|
|
141
|
+
const textBefore = templateContent.slice(0, match.index);
|
|
142
|
+
const lineInTemplate = textBefore.split("\n").length;
|
|
143
|
+
const line = linesBeforeTemplate + lineInTemplate - 1;
|
|
144
|
+
const lastNewline = textBefore.lastIndexOf("\n");
|
|
145
|
+
const col = lastNewline === -1 ? match.index : match.index - lastNewline - 1;
|
|
146
|
+
const insertPos = templateStart + match.index + match[0].length;
|
|
147
|
+
const sourceAttr = ` data-remarq-source="${filePath}:${line}:${col}"`;
|
|
148
|
+
const componentName = _nullishCoalesce(_optionalChain([filePath, 'access', _9 => _9.split, 'call', _10 => _10("/"), 'access', _11 => _11.pop, 'call', _12 => _12(), 'optionalAccess', _13 => _13.replace, 'call', _14 => _14(/\.vue$/, "")]), () => ( null));
|
|
149
|
+
const componentAttr = componentName ? ` data-remarq-component="${componentName}"` : "";
|
|
150
|
+
s.appendLeft(insertPos, sourceAttr + componentAttr);
|
|
151
|
+
modified = true;
|
|
152
|
+
}
|
|
153
|
+
if (!modified) return null;
|
|
154
|
+
return {
|
|
155
|
+
code: s.toString(),
|
|
156
|
+
map: s.generateMap({ hires: true })
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/index.ts
|
|
161
|
+
var DEFAULT_INCLUDE = ["**/*.jsx", "**/*.tsx", "**/*.vue"];
|
|
162
|
+
var DEFAULT_EXCLUDE = ["node_modules/**"];
|
|
163
|
+
function createFilter(include, exclude) {
|
|
164
|
+
function toRegex(glob) {
|
|
165
|
+
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\xA7GLOBSTAR\xA7").replace(/\*/g, "[^/]*").replace(/§GLOBSTAR§/g, ".*").replace(/\?/g, "[^/]");
|
|
166
|
+
return new RegExp(`(?:^|/)${escaped}$`);
|
|
167
|
+
}
|
|
168
|
+
const includePatterns = include.map(toRegex);
|
|
169
|
+
const excludePatterns = exclude.map(toRegex);
|
|
170
|
+
return (id) => {
|
|
171
|
+
const normalized = id.split("\\").join("/");
|
|
172
|
+
if (excludePatterns.some((re) => re.test(normalized))) return false;
|
|
173
|
+
return includePatterns.some((re) => re.test(normalized));
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
var unplugin = _unplugin.createUnplugin.call(void 0, (options = {}) => {
|
|
177
|
+
const include = _nullishCoalesce(options.include, () => ( DEFAULT_INCLUDE));
|
|
178
|
+
const exclude = _nullishCoalesce(options.exclude, () => ( DEFAULT_EXCLUDE));
|
|
179
|
+
const filter = createFilter(include, exclude);
|
|
180
|
+
return {
|
|
181
|
+
name: "web-remarq",
|
|
182
|
+
enforce: "pre",
|
|
183
|
+
transformInclude(id) {
|
|
184
|
+
if (!options.production && process.env.NODE_ENV === "production") return false;
|
|
185
|
+
return filter(id);
|
|
186
|
+
},
|
|
187
|
+
transform(code, id) {
|
|
188
|
+
const cwd = process.cwd();
|
|
189
|
+
const filePath = _path.relative.call(void 0, cwd, id).split("\\").join("/");
|
|
190
|
+
if (id.endsWith(".vue")) {
|
|
191
|
+
return _nullishCoalesce(transformVueSFC(code, filePath), () => ( void 0));
|
|
192
|
+
}
|
|
193
|
+
return _nullishCoalesce(transformJSX(code, filePath), () => ( void 0));
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
var index_default = unplugin;
|
|
198
|
+
var vitePlugin = unplugin.vite;
|
|
199
|
+
var rollupPlugin = unplugin.rollup;
|
|
200
|
+
var webpackPlugin = unplugin.webpack;
|
|
201
|
+
var esbuildPlugin = unplugin.esbuild;
|
|
202
|
+
var rspackPlugin = unplugin.rspack;
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
exports.index_default = index_default; exports.vitePlugin = vitePlugin; exports.rollupPlugin = rollupPlugin; exports.webpackPlugin = webpackPlugin; exports.esbuildPlugin = esbuildPlugin; exports.rspackPlugin = rspackPlugin;
|
package/dist/esbuild.cjs
ADDED
package/dist/esbuild.js
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkPRGGVU7Pcjs = require('./chunk-PRGGVU7P.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
exports.default = _chunkPRGGVU7Pcjs.index_default; exports.esbuildPlugin = _chunkPRGGVU7Pcjs.esbuildPlugin; exports.rollupPlugin = _chunkPRGGVU7Pcjs.rollupPlugin; exports.rspackPlugin = _chunkPRGGVU7Pcjs.rspackPlugin; exports.vitePlugin = _chunkPRGGVU7Pcjs.vitePlugin; exports.webpackPlugin = _chunkPRGGVU7Pcjs.webpackPlugin;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import * as rollup from 'rollup';
|
|
3
|
+
import * as _unplugin from 'unplugin';
|
|
4
|
+
|
|
5
|
+
interface Options {
|
|
6
|
+
/** Glob patterns for files to include. Default: ['**\/*.jsx', '**\/*.tsx', '**\/*.vue'] */
|
|
7
|
+
include?: string[];
|
|
8
|
+
/** Glob patterns for files to exclude. Default: ['node_modules/**'] */
|
|
9
|
+
exclude?: string[];
|
|
10
|
+
/** Enable in production builds. Default: false */
|
|
11
|
+
production?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare const unplugin: _unplugin.UnpluginInstance<Options, boolean>;
|
|
14
|
+
|
|
15
|
+
declare const vitePlugin: (options: Options) => any;
|
|
16
|
+
declare const rollupPlugin: (options: Options) => rollup.Plugin<any> | rollup.Plugin<any>[];
|
|
17
|
+
declare const webpackPlugin: (options: Options) => WebpackPluginInstance;
|
|
18
|
+
declare const esbuildPlugin: (options: Options) => esbuild.Plugin;
|
|
19
|
+
declare const rspackPlugin: (options: Options) => RspackPluginInstance;
|
|
20
|
+
|
|
21
|
+
export { type Options, unplugin as default, esbuildPlugin, rollupPlugin, rspackPlugin, vitePlugin, webpackPlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import * as rollup from 'rollup';
|
|
3
|
+
import * as _unplugin from 'unplugin';
|
|
4
|
+
|
|
5
|
+
interface Options {
|
|
6
|
+
/** Glob patterns for files to include. Default: ['**\/*.jsx', '**\/*.tsx', '**\/*.vue'] */
|
|
7
|
+
include?: string[];
|
|
8
|
+
/** Glob patterns for files to exclude. Default: ['node_modules/**'] */
|
|
9
|
+
exclude?: string[];
|
|
10
|
+
/** Enable in production builds. Default: false */
|
|
11
|
+
production?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare const unplugin: _unplugin.UnpluginInstance<Options, boolean>;
|
|
14
|
+
|
|
15
|
+
declare const vitePlugin: (options: Options) => any;
|
|
16
|
+
declare const rollupPlugin: (options: Options) => rollup.Plugin<any> | rollup.Plugin<any>[];
|
|
17
|
+
declare const webpackPlugin: (options: Options) => WebpackPluginInstance;
|
|
18
|
+
declare const esbuildPlugin: (options: Options) => esbuild.Plugin;
|
|
19
|
+
declare const rspackPlugin: (options: Options) => RspackPluginInstance;
|
|
20
|
+
|
|
21
|
+
export { type Options, unplugin as default, esbuildPlugin, rollupPlugin, rspackPlugin, vitePlugin, webpackPlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
esbuildPlugin,
|
|
3
|
+
index_default,
|
|
4
|
+
rollupPlugin,
|
|
5
|
+
rspackPlugin,
|
|
6
|
+
vitePlugin,
|
|
7
|
+
webpackPlugin
|
|
8
|
+
} from "./chunk-CRVREGZW.js";
|
|
9
|
+
export {
|
|
10
|
+
index_default as default,
|
|
11
|
+
esbuildPlugin,
|
|
12
|
+
rollupPlugin,
|
|
13
|
+
rspackPlugin,
|
|
14
|
+
vitePlugin,
|
|
15
|
+
webpackPlugin
|
|
16
|
+
};
|
package/dist/rollup.cjs
ADDED
package/dist/rollup.d.ts
ADDED
package/dist/rollup.js
ADDED
package/dist/rspack.cjs
ADDED
package/dist/rspack.d.ts
ADDED
package/dist/rspack.js
ADDED
package/dist/vite.cjs
ADDED
package/dist/vite.d.cts
ADDED
package/dist/vite.d.ts
ADDED
package/dist/vite.js
ADDED
package/dist/webpack.cjs
ADDED
package/dist/webpack.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@web-remarq/unplugin",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Unplugin for web-remarq source location injection (Vite/webpack/Rollup/esbuild/Rspack)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./vite": {
|
|
16
|
+
"types": "./dist/vite.d.ts",
|
|
17
|
+
"import": "./dist/vite.js",
|
|
18
|
+
"require": "./dist/vite.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./webpack": {
|
|
21
|
+
"types": "./dist/webpack.d.ts",
|
|
22
|
+
"import": "./dist/webpack.js",
|
|
23
|
+
"require": "./dist/webpack.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./rollup": {
|
|
26
|
+
"types": "./dist/rollup.d.ts",
|
|
27
|
+
"import": "./dist/rollup.js",
|
|
28
|
+
"require": "./dist/rollup.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./esbuild": {
|
|
31
|
+
"types": "./dist/esbuild.d.ts",
|
|
32
|
+
"import": "./dist/esbuild.js",
|
|
33
|
+
"require": "./dist/esbuild.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./rspack": {
|
|
36
|
+
"types": "./dist/rspack.d.ts",
|
|
37
|
+
"import": "./dist/rspack.js",
|
|
38
|
+
"require": "./dist/rspack.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"typecheck": "tsc --noEmit"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@babel/parser": "^7.29.2",
|
|
50
|
+
"magic-string": "^0.30.21",
|
|
51
|
+
"unplugin": "^3.0.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^25.5.0",
|
|
55
|
+
"tsup": "^8.5.1",
|
|
56
|
+
"typescript": "^5.9.3"
|
|
57
|
+
},
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "https://github.com/DPostnik/web-remarq",
|
|
62
|
+
"directory": "packages/unplugin"
|
|
63
|
+
},
|
|
64
|
+
"keywords": [
|
|
65
|
+
"unplugin",
|
|
66
|
+
"vite-plugin",
|
|
67
|
+
"webpack-plugin",
|
|
68
|
+
"rollup-plugin",
|
|
69
|
+
"web-remarq",
|
|
70
|
+
"source-location",
|
|
71
|
+
"annotation"
|
|
72
|
+
]
|
|
73
|
+
}
|