vite-plugin-qingkuai 1.0.16 → 1.0.18
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/index.cjs +95 -30
- package/dist/index.js +77 -31
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var vite = require('vite');
|
|
3
4
|
var nodePath = require('node:path');
|
|
4
5
|
var nodeCrypto = require('node:crypto');
|
|
5
6
|
var compiler = require('qingkuai/compiler');
|
|
@@ -8,9 +9,37 @@ var linesAndColumns = require('lines-and-columns');
|
|
|
8
9
|
var sourcemapCodec = require('@jridgewell/sourcemap-codec');
|
|
9
10
|
var postcss = require('postcss');
|
|
10
11
|
var selectorParser = require('postcss-selector-parser');
|
|
11
|
-
var vite = require('vite');
|
|
12
12
|
var sourceMapJs = require('source-map-js');
|
|
13
13
|
|
|
14
|
+
function _interopNamespaceDefault(e) {
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
Object.keys(e).forEach(function (k) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return e[k]; }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
n.default = e;
|
|
28
|
+
return Object.freeze(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var vite__namespace = /*#__PURE__*/_interopNamespaceDefault(vite);
|
|
32
|
+
|
|
33
|
+
const globalStyle = "\n" + compiler.util.formatSourceCode(
|
|
34
|
+
`
|
|
35
|
+
/* Injected by vite-plugin-qingkuai */
|
|
36
|
+
|
|
37
|
+
*[hidden] {
|
|
38
|
+
display: none !important;
|
|
39
|
+
}
|
|
40
|
+
`
|
|
41
|
+
).replace(/^/gm, " ") + "\n";
|
|
42
|
+
|
|
14
43
|
function isUndefined(v) {
|
|
15
44
|
return void 0 === v;
|
|
16
45
|
}
|
|
@@ -123,20 +152,20 @@ function qingkuai() {
|
|
|
123
152
|
cssSourcemap = true;
|
|
124
153
|
sourcemap = config.build.sourcemap !== false;
|
|
125
154
|
}
|
|
126
|
-
const optimizeDeps = config.optimizeDeps;
|
|
127
|
-
if (!optimizeDeps) {
|
|
128
|
-
Object.assign(config, {
|
|
129
|
-
optimizeDeps: {
|
|
130
|
-
exclude: ["qingkuai"]
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
} else if (!optimizeDeps.exclude) {
|
|
134
|
-
optimizeDeps.exclude = ["qingkuai"];
|
|
135
|
-
} else {
|
|
136
|
-
optimizeDeps.exclude.push("qingkuai");
|
|
137
|
-
}
|
|
138
155
|
loadAllQingkuaiConfigurations(config.root);
|
|
139
156
|
},
|
|
157
|
+
transformIndexHtml(html) {
|
|
158
|
+
return {
|
|
159
|
+
html,
|
|
160
|
+
tags: [
|
|
161
|
+
{
|
|
162
|
+
tag: "style",
|
|
163
|
+
injectTo: "head",
|
|
164
|
+
children: globalStyle
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
};
|
|
168
|
+
},
|
|
140
169
|
resolveId(id, importer) {
|
|
141
170
|
if (styleIdRE.test(id)) {
|
|
142
171
|
return id;
|
|
@@ -166,7 +195,7 @@ function qingkuai() {
|
|
|
166
195
|
break;
|
|
167
196
|
}
|
|
168
197
|
}
|
|
169
|
-
const preprocessRes = await
|
|
198
|
+
const preprocessRes = await vite__namespace.preprocessCSS(style.code, virtualFileName, {
|
|
170
199
|
...viteConfig,
|
|
171
200
|
css: {
|
|
172
201
|
...viteConfig.css,
|
|
@@ -266,7 +295,15 @@ function qingkuai() {
|
|
|
266
295
|
})
|
|
267
296
|
};
|
|
268
297
|
}
|
|
269
|
-
const
|
|
298
|
+
const inputMap = sourcemap ? {
|
|
299
|
+
version: 3,
|
|
300
|
+
sources: [id],
|
|
301
|
+
sourcesContent: [src],
|
|
302
|
+
mappings: compileRes.mappings
|
|
303
|
+
} : void 0;
|
|
304
|
+
const transformWithEsbuild = vite__namespace.transformWithEsbuild;
|
|
305
|
+
const transformWithOxc = vite__namespace.transformWithOxc;
|
|
306
|
+
const tsCompileRes = transformWithEsbuild ? await transformWithEsbuild(
|
|
270
307
|
compiledCode,
|
|
271
308
|
id,
|
|
272
309
|
{
|
|
@@ -274,24 +311,37 @@ function qingkuai() {
|
|
|
274
311
|
loader: "ts",
|
|
275
312
|
target: "esnext"
|
|
276
313
|
},
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
314
|
+
inputMap
|
|
315
|
+
) : transformWithOxc ? await transformWithOxc(
|
|
316
|
+
compiledCode,
|
|
317
|
+
id,
|
|
318
|
+
{
|
|
319
|
+
sourcemap,
|
|
320
|
+
target: "esnext"
|
|
321
|
+
},
|
|
322
|
+
inputMap
|
|
323
|
+
) : null;
|
|
324
|
+
if (!tsCompileRes) {
|
|
325
|
+
this.error("Current Vite runtime does not provide TypeScript transform APIs.");
|
|
326
|
+
}
|
|
284
327
|
if (!sourcemap) {
|
|
285
|
-
return
|
|
328
|
+
return tsCompileRes.code;
|
|
286
329
|
}
|
|
330
|
+
const transformedMap = typeof tsCompileRes.map === "string" ? JSON.parse(tsCompileRes.map) : tsCompileRes.map;
|
|
287
331
|
return {
|
|
288
|
-
code:
|
|
332
|
+
code: tsCompileRes.code,
|
|
289
333
|
map: Object.assign(baseMap, {
|
|
290
|
-
mappings:
|
|
334
|
+
mappings: transformedMap?.mappings || compileRes.mappings
|
|
291
335
|
})
|
|
292
336
|
};
|
|
293
337
|
} catch (err) {
|
|
294
|
-
err.
|
|
338
|
+
if (err.loc.start && "index" in err.loc.start) {
|
|
339
|
+
err.pos = err.loc.start.index, this.error(err);
|
|
340
|
+
} else {
|
|
341
|
+
this.error(
|
|
342
|
+
"Qingkuai compile result is invalid. Please report this at https://github.com/qingkuai-js/qingkuai/issues and include your .qk source for reproduction."
|
|
343
|
+
);
|
|
344
|
+
}
|
|
295
345
|
}
|
|
296
346
|
}
|
|
297
347
|
};
|
|
@@ -315,10 +365,25 @@ function qingkuai() {
|
|
|
315
365
|
return config;
|
|
316
366
|
}
|
|
317
367
|
function createQingkuaiConfigurationWatcher(server) {
|
|
318
|
-
const watcher = server.watcher
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
368
|
+
const watcher = server.watcher;
|
|
369
|
+
const isQingkuaiConfig = (filePath) => {
|
|
370
|
+
return nodePath.basename(filePath) === ".qingkuairc" && !filePath.includes(`${nodePath.sep}node_modules${nodePath.sep}`);
|
|
371
|
+
};
|
|
372
|
+
watcher.on("unlink", (filePath) => {
|
|
373
|
+
if (isQingkuaiConfig(filePath)) {
|
|
374
|
+
qingkuaiConfigurations.delete(nodePath.dirname(filePath));
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
watcher.on("change", (filePath) => {
|
|
378
|
+
if (isQingkuaiConfig(filePath)) {
|
|
379
|
+
recordQingkuaiConfiguration(filePath);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
watcher.on("add", (filePath) => {
|
|
383
|
+
if (isQingkuaiConfig(filePath)) {
|
|
384
|
+
recordQingkuaiConfiguration(filePath);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
322
387
|
}
|
|
323
388
|
function loadAllQingkuaiConfigurations(workspaceDir) {
|
|
324
389
|
findFilesByName(workspaceDir, ".qingkuairc", /* @__PURE__ */ new Set(["node_modules"])).forEach((fileName) => {
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
import * as vite from 'vite';
|
|
1
2
|
import nodePath from 'node:path';
|
|
2
3
|
import nodeCrypto from 'node:crypto';
|
|
3
|
-
import { compile } from 'qingkuai/compiler';
|
|
4
|
+
import { util, compile } from 'qingkuai/compiler';
|
|
4
5
|
import nodeFs, { existsSync, readFileSync } from 'node:fs';
|
|
5
6
|
import { LinesAndColumns } from 'lines-and-columns';
|
|
6
7
|
import { decode, encode } from '@jridgewell/sourcemap-codec';
|
|
7
8
|
import postcss from 'postcss';
|
|
8
9
|
import selectorParser from 'postcss-selector-parser';
|
|
9
|
-
import { transformWithEsbuild, preprocessCSS } from 'vite';
|
|
10
10
|
import { SourceMapConsumer } from 'source-map-js';
|
|
11
11
|
|
|
12
|
+
const globalStyle = "\n" + util.formatSourceCode(
|
|
13
|
+
`
|
|
14
|
+
/* Injected by vite-plugin-qingkuai */
|
|
15
|
+
|
|
16
|
+
*[hidden] {
|
|
17
|
+
display: none !important;
|
|
18
|
+
}
|
|
19
|
+
`
|
|
20
|
+
).replace(/^/gm, " ") + "\n";
|
|
21
|
+
|
|
12
22
|
function isUndefined(v) {
|
|
13
23
|
return void 0 === v;
|
|
14
24
|
}
|
|
@@ -121,20 +131,20 @@ function qingkuai() {
|
|
|
121
131
|
cssSourcemap = true;
|
|
122
132
|
sourcemap = config.build.sourcemap !== false;
|
|
123
133
|
}
|
|
124
|
-
const optimizeDeps = config.optimizeDeps;
|
|
125
|
-
if (!optimizeDeps) {
|
|
126
|
-
Object.assign(config, {
|
|
127
|
-
optimizeDeps: {
|
|
128
|
-
exclude: ["qingkuai"]
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
} else if (!optimizeDeps.exclude) {
|
|
132
|
-
optimizeDeps.exclude = ["qingkuai"];
|
|
133
|
-
} else {
|
|
134
|
-
optimizeDeps.exclude.push("qingkuai");
|
|
135
|
-
}
|
|
136
134
|
loadAllQingkuaiConfigurations(config.root);
|
|
137
135
|
},
|
|
136
|
+
transformIndexHtml(html) {
|
|
137
|
+
return {
|
|
138
|
+
html,
|
|
139
|
+
tags: [
|
|
140
|
+
{
|
|
141
|
+
tag: "style",
|
|
142
|
+
injectTo: "head",
|
|
143
|
+
children: globalStyle
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
};
|
|
147
|
+
},
|
|
138
148
|
resolveId(id, importer) {
|
|
139
149
|
if (styleIdRE.test(id)) {
|
|
140
150
|
return id;
|
|
@@ -164,7 +174,7 @@ function qingkuai() {
|
|
|
164
174
|
break;
|
|
165
175
|
}
|
|
166
176
|
}
|
|
167
|
-
const preprocessRes = await preprocessCSS(style.code, virtualFileName, {
|
|
177
|
+
const preprocessRes = await vite.preprocessCSS(style.code, virtualFileName, {
|
|
168
178
|
...viteConfig,
|
|
169
179
|
css: {
|
|
170
180
|
...viteConfig.css,
|
|
@@ -264,7 +274,15 @@ function qingkuai() {
|
|
|
264
274
|
})
|
|
265
275
|
};
|
|
266
276
|
}
|
|
267
|
-
const
|
|
277
|
+
const inputMap = sourcemap ? {
|
|
278
|
+
version: 3,
|
|
279
|
+
sources: [id],
|
|
280
|
+
sourcesContent: [src],
|
|
281
|
+
mappings: compileRes.mappings
|
|
282
|
+
} : void 0;
|
|
283
|
+
const transformWithEsbuild = vite.transformWithEsbuild;
|
|
284
|
+
const transformWithOxc = vite.transformWithOxc;
|
|
285
|
+
const tsCompileRes = transformWithEsbuild ? await transformWithEsbuild(
|
|
268
286
|
compiledCode,
|
|
269
287
|
id,
|
|
270
288
|
{
|
|
@@ -272,24 +290,37 @@ function qingkuai() {
|
|
|
272
290
|
loader: "ts",
|
|
273
291
|
target: "esnext"
|
|
274
292
|
},
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
293
|
+
inputMap
|
|
294
|
+
) : transformWithOxc ? await transformWithOxc(
|
|
295
|
+
compiledCode,
|
|
296
|
+
id,
|
|
297
|
+
{
|
|
298
|
+
sourcemap,
|
|
299
|
+
target: "esnext"
|
|
300
|
+
},
|
|
301
|
+
inputMap
|
|
302
|
+
) : null;
|
|
303
|
+
if (!tsCompileRes) {
|
|
304
|
+
this.error("Current Vite runtime does not provide TypeScript transform APIs.");
|
|
305
|
+
}
|
|
282
306
|
if (!sourcemap) {
|
|
283
|
-
return
|
|
307
|
+
return tsCompileRes.code;
|
|
284
308
|
}
|
|
309
|
+
const transformedMap = typeof tsCompileRes.map === "string" ? JSON.parse(tsCompileRes.map) : tsCompileRes.map;
|
|
285
310
|
return {
|
|
286
|
-
code:
|
|
311
|
+
code: tsCompileRes.code,
|
|
287
312
|
map: Object.assign(baseMap, {
|
|
288
|
-
mappings:
|
|
313
|
+
mappings: transformedMap?.mappings || compileRes.mappings
|
|
289
314
|
})
|
|
290
315
|
};
|
|
291
316
|
} catch (err) {
|
|
292
|
-
err.
|
|
317
|
+
if (err.loc.start && "index" in err.loc.start) {
|
|
318
|
+
err.pos = err.loc.start.index, this.error(err);
|
|
319
|
+
} else {
|
|
320
|
+
this.error(
|
|
321
|
+
"Qingkuai compile result is invalid. Please report this at https://github.com/qingkuai-js/qingkuai/issues and include your .qk source for reproduction."
|
|
322
|
+
);
|
|
323
|
+
}
|
|
293
324
|
}
|
|
294
325
|
}
|
|
295
326
|
};
|
|
@@ -313,10 +344,25 @@ function qingkuai() {
|
|
|
313
344
|
return config;
|
|
314
345
|
}
|
|
315
346
|
function createQingkuaiConfigurationWatcher(server) {
|
|
316
|
-
const watcher = server.watcher
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
347
|
+
const watcher = server.watcher;
|
|
348
|
+
const isQingkuaiConfig = (filePath) => {
|
|
349
|
+
return nodePath.basename(filePath) === ".qingkuairc" && !filePath.includes(`${nodePath.sep}node_modules${nodePath.sep}`);
|
|
350
|
+
};
|
|
351
|
+
watcher.on("unlink", (filePath) => {
|
|
352
|
+
if (isQingkuaiConfig(filePath)) {
|
|
353
|
+
qingkuaiConfigurations.delete(nodePath.dirname(filePath));
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
watcher.on("change", (filePath) => {
|
|
357
|
+
if (isQingkuaiConfig(filePath)) {
|
|
358
|
+
recordQingkuaiConfiguration(filePath);
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
watcher.on("add", (filePath) => {
|
|
362
|
+
if (isQingkuaiConfig(filePath)) {
|
|
363
|
+
recordQingkuaiConfiguration(filePath);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
320
366
|
}
|
|
321
367
|
function loadAllQingkuaiConfigurations(workspaceDir) {
|
|
322
368
|
findFilesByName(workspaceDir, ".qingkuairc", /* @__PURE__ */ new Set(["node_modules"])).forEach((fileName) => {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "vite-plugin-qingkuai",
|
|
3
3
|
"author": "mlgq",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.18",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"vite",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"rollup": "^4.38.0",
|
|
31
31
|
"rollup-plugin-dts": "^6.2.1",
|
|
32
32
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
33
|
-
"vite": "
|
|
33
|
+
"vite": "8.0.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"qingkuai": ">=1.0.50",
|
|
37
|
-
"vite": ">=6.2.4"
|
|
37
|
+
"vite": ">=6.2.4 <9"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@jridgewell/sourcemap-codec": "^1.5.0",
|