vite-plugin-qingkuai 1.0.29 → 1.0.31

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/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ * text=auto eol=lf
package/dist/index.cjs CHANGED
@@ -11,6 +11,7 @@ var postcss = require('postcss');
11
11
  var selectorParser = require('postcss-selector-parser');
12
12
  var compiler = require('qingkuai/compiler');
13
13
  var sourceMapJs = require('source-map-js');
14
+ var config = require('qingkuai-language-service/config');
14
15
 
15
16
  function _interopNamespaceDefault(e) {
16
17
  var n = Object.create(null);
@@ -93,6 +94,16 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
93
94
  };
94
95
  }
95
96
 
97
+ function normalizePath(path) {
98
+ return path.replaceAll("\\", "/");
99
+ }
100
+ function isNumber(v) {
101
+ return typeof v === "number";
102
+ }
103
+ function isUndefined(v) {
104
+ return void 0 === v;
105
+ }
106
+
96
107
  const globalStyle = "\n" + compiler.util.formatSourceCode(
97
108
  `
98
109
  /* Injected by vite-plugin-qingkuai */
@@ -104,29 +115,6 @@ const globalStyle = "\n" + compiler.util.formatSourceCode(
104
115
  ).replace(/^/gm, " ") + "\n";
105
116
  const VIRTUAL_STYLE_ID_RE = /^virtual:\[\d+\].*?\.qk\.(css|s[ac]ss|less|stylus|postcss)\?\d{13}$/;
106
117
 
107
- function isNumber(v) {
108
- return typeof v === "number";
109
- }
110
- function isUndefined(v) {
111
- return void 0 === v;
112
- }
113
- function findFilesByName(dir, targetFileName, ignoreList) {
114
- const result = [];
115
- const entries = nodeFs.readdirSync(dir, { withFileTypes: true });
116
- for (const entry of entries) {
117
- if (ignoreList.has(entry.name)) {
118
- continue;
119
- }
120
- const fullPath = nodePath.join(dir, entry.name);
121
- if (entry.name === targetFileName) {
122
- result.push(fullPath);
123
- } else if (entry.isDirectory()) {
124
- result.push(...findFilesByName(fullPath, targetFileName, ignoreList));
125
- }
126
- }
127
- return result;
128
- }
129
-
130
118
  function offsetSourceMap(sourceIndices, mappings, preLine, preColumn) {
131
119
  const indices = new Set(sourceIndices);
132
120
  return sourcemapCodec.decode(mappings).map((line) => {
@@ -152,8 +140,29 @@ function qingkuai(options = {}) {
152
140
  let sourcemap;
153
141
  let cssSourcemap;
154
142
  let viteConfig;
143
+ const reportedConfigMessages = /* @__PURE__ */ new Set();
155
144
  const compileResultCache = /* @__PURE__ */ new Map();
156
- const qingkuaiConfigurations = /* @__PURE__ */ new Map();
145
+ const configResolver = config.createConfigResolver(
146
+ {
147
+ read: (filePath) => {
148
+ return nodeFs.readFileSync(filePath, "utf-8");
149
+ },
150
+ exist: (filePath) => {
151
+ return nodeFs.existsSync(filePath);
152
+ }
153
+ },
154
+ {
155
+ dir: (filePath) => {
156
+ return nodePath.resolve(nodePath.dirname(filePath));
157
+ },
158
+ resolve: (...segments) => {
159
+ return nodePath.resolve(...segments);
160
+ },
161
+ ext: nodePath.extname,
162
+ base: nodePath.basename,
163
+ relative: nodePath.relative
164
+ }
165
+ );
157
166
  if (isUndefined(options.maxScheduleDepth)) {
158
167
  options.maxScheduleDepth = 300;
159
168
  }
@@ -180,7 +189,6 @@ function qingkuai(options = {}) {
180
189
  cssSourcemap = true;
181
190
  sourcemap = config.build.sourcemap !== false;
182
191
  }
183
- loadAllQingkuaiConfigurations(config.root);
184
192
  },
185
193
  transformIndexHtml(html) {
186
194
  return {
@@ -199,10 +207,9 @@ function qingkuai(options = {}) {
199
207
  return id;
200
208
  }
201
209
  if (importer?.endsWith(".qk") && !nodePath.extname(id)) {
202
- const qingkuaiConfig = getQingkuaiConfiguration(id);
203
- return nodePath.join(
204
- nodePath.dirname(importer),
205
- id + (qingkuaiConfig.resolveImportExtension ? ".qk" : "")
210
+ const qingkuaiConfig = getQingkuaiConfig(importer);
211
+ return normalizePath(
212
+ nodePath.join(nodePath.dirname(importer), id + (qingkuaiConfig.resolveImportExtension ? ".qk" : ""))
206
213
  );
207
214
  }
208
215
  return id;
@@ -370,7 +377,7 @@ Caused by: "${fileId}".`;
370
377
  };
371
378
  },
372
379
  async transform(src, id) {
373
- if (!id.endsWith(".qk")) {
380
+ if (!(id = normalizePath(id)).endsWith(".qk")) {
374
381
  return;
375
382
  }
376
383
  try {
@@ -463,59 +470,44 @@ Caused by: "${fileId}".`;
463
470
  }
464
471
  }
465
472
  };
466
- function getQingkuaiConfiguration(id) {
467
- let config = {
468
- interpretiveComments: true,
469
- resolveImportExtension: true,
470
- preserveHtmlComments: "development"
471
- };
472
- while (true) {
473
- const dir = nodePath.dirname(id);
474
- if (dir === id) {
475
- break;
476
- }
477
- const got = qingkuaiConfigurations.get(id = dir);
478
- if (got) {
479
- config = got;
480
- break;
473
+ function getQingkuaiConfig(filePath) {
474
+ return configResolver.resolve(filePath, (configPath, message) => {
475
+ reportConfigMessage(viteConfig.logger, configPath, message);
476
+ });
477
+ }
478
+ function reportConfigMessage(logger, filePath, message) {
479
+ const key = `${filePath}\0${message.value}`;
480
+ if (reportedConfigMessages.has(key)) {
481
+ return;
482
+ }
483
+ reportedConfigMessages.add(key);
484
+ const reason = message.kind === config.ConfigParsingMessageKind.Error ? "Failed to parse configuration file" : "Configuration file";
485
+ logger.warn(`[qingkuai] ${reason} ${filePath}: ${message.value}`);
486
+ }
487
+ function forgetConfigMessages(configPath) {
488
+ const prefix = `${configPath}\0`;
489
+ for (const key of reportedConfigMessages) {
490
+ if (key.startsWith(prefix)) {
491
+ reportedConfigMessages.delete(key);
481
492
  }
482
493
  }
483
- return config;
484
494
  }
485
495
  function createQingkuaiConfigurationWatcher(server) {
486
496
  const watcher = server.watcher;
487
- const isQingkuaiConfig = (filePath) => {
488
- return nodePath.basename(filePath) === ".qingkuairc" && !filePath.includes(`${nodePath.sep}node_modules${nodePath.sep}`);
489
- };
490
- watcher.on("unlink", (filePath) => {
491
- if (isQingkuaiConfig(filePath)) {
492
- qingkuaiConfigurations.delete(nodePath.dirname(filePath));
493
- }
494
- });
495
- watcher.on("change", (filePath) => {
496
- if (isQingkuaiConfig(filePath)) {
497
- recordQingkuaiConfiguration(filePath);
498
- }
499
- });
500
- watcher.on("add", (filePath) => {
501
- if (isQingkuaiConfig(filePath)) {
502
- recordQingkuaiConfiguration(filePath);
497
+ const handleFileChange = (filePath) => {
498
+ for (const configPath of configResolver.removeCacheByPath(filePath)) {
499
+ forgetConfigMessages(configPath);
500
+ configResolver.resolve(configPath, (path, message) => {
501
+ reportConfigMessage(server.config.logger, path, message);
502
+ });
503
503
  }
504
- });
505
- }
506
- function loadAllQingkuaiConfigurations(workspaceDir) {
507
- findFilesByName(workspaceDir, ".qingkuairc", /* @__PURE__ */ new Set(["node_modules"])).forEach((fileName) => {
508
- recordQingkuaiConfiguration(fileName);
509
- });
510
- }
511
- function recordQingkuaiConfiguration(fileName) {
512
- try {
513
- qingkuaiConfigurations.set(nodePath.dirname(fileName), JSON.parse(nodeFs.readFileSync(fileName, "utf-8")));
514
- } catch {
515
- }
504
+ };
505
+ watcher.on("change", handleFileChange);
506
+ watcher.on("add", handleFileChange);
507
+ watcher.on("unlink", handleFileChange);
516
508
  }
517
509
  function getCompileOptions(id) {
518
- const qingkuaiConfig = getQingkuaiConfiguration(id);
510
+ const qingkuaiConfig = getQingkuaiConfig(id);
519
511
  const ret = {
520
512
  interpretiveComments: isUndefined(qingkuaiConfig.interpretiveComments) ? isDev : !!qingkuaiConfig.interpretiveComments,
521
513
  allowConstReactive: qingkuaiConfig.allowConstReactive !== false,
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ import postcss from 'postcss';
9
9
  import selectorParser from 'postcss-selector-parser';
10
10
  import { util, compile, isCompileError, ReactivityMode, WhitespaceMode } from 'qingkuai/compiler';
11
11
  import { SourceMapConsumer } from 'source-map-js';
12
+ import { createConfigResolver, ConfigParsingMessageKind } from 'qingkuai-language-service/config';
12
13
 
13
14
  async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
14
15
  let error;
@@ -72,6 +73,16 @@ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
72
73
  };
73
74
  }
74
75
 
76
+ function normalizePath(path) {
77
+ return path.replaceAll("\\", "/");
78
+ }
79
+ function isNumber(v) {
80
+ return typeof v === "number";
81
+ }
82
+ function isUndefined(v) {
83
+ return void 0 === v;
84
+ }
85
+
75
86
  const globalStyle = "\n" + util.formatSourceCode(
76
87
  `
77
88
  /* Injected by vite-plugin-qingkuai */
@@ -83,29 +94,6 @@ const globalStyle = "\n" + util.formatSourceCode(
83
94
  ).replace(/^/gm, " ") + "\n";
84
95
  const VIRTUAL_STYLE_ID_RE = /^virtual:\[\d+\].*?\.qk\.(css|s[ac]ss|less|stylus|postcss)\?\d{13}$/;
85
96
 
86
- function isNumber(v) {
87
- return typeof v === "number";
88
- }
89
- function isUndefined(v) {
90
- return void 0 === v;
91
- }
92
- function findFilesByName(dir, targetFileName, ignoreList) {
93
- const result = [];
94
- const entries = nodeFs.readdirSync(dir, { withFileTypes: true });
95
- for (const entry of entries) {
96
- if (ignoreList.has(entry.name)) {
97
- continue;
98
- }
99
- const fullPath = nodePath.join(dir, entry.name);
100
- if (entry.name === targetFileName) {
101
- result.push(fullPath);
102
- } else if (entry.isDirectory()) {
103
- result.push(...findFilesByName(fullPath, targetFileName, ignoreList));
104
- }
105
- }
106
- return result;
107
- }
108
-
109
97
  function offsetSourceMap(sourceIndices, mappings, preLine, preColumn) {
110
98
  const indices = new Set(sourceIndices);
111
99
  return decode(mappings).map((line) => {
@@ -131,8 +119,29 @@ function qingkuai(options = {}) {
131
119
  let sourcemap;
132
120
  let cssSourcemap;
133
121
  let viteConfig;
122
+ const reportedConfigMessages = /* @__PURE__ */ new Set();
134
123
  const compileResultCache = /* @__PURE__ */ new Map();
135
- const qingkuaiConfigurations = /* @__PURE__ */ new Map();
124
+ const configResolver = createConfigResolver(
125
+ {
126
+ read: (filePath) => {
127
+ return nodeFs.readFileSync(filePath, "utf-8");
128
+ },
129
+ exist: (filePath) => {
130
+ return nodeFs.existsSync(filePath);
131
+ }
132
+ },
133
+ {
134
+ dir: (filePath) => {
135
+ return nodePath.resolve(nodePath.dirname(filePath));
136
+ },
137
+ resolve: (...segments) => {
138
+ return nodePath.resolve(...segments);
139
+ },
140
+ ext: nodePath.extname,
141
+ base: nodePath.basename,
142
+ relative: nodePath.relative
143
+ }
144
+ );
136
145
  if (isUndefined(options.maxScheduleDepth)) {
137
146
  options.maxScheduleDepth = 300;
138
147
  }
@@ -159,7 +168,6 @@ function qingkuai(options = {}) {
159
168
  cssSourcemap = true;
160
169
  sourcemap = config.build.sourcemap !== false;
161
170
  }
162
- loadAllQingkuaiConfigurations(config.root);
163
171
  },
164
172
  transformIndexHtml(html) {
165
173
  return {
@@ -178,10 +186,9 @@ function qingkuai(options = {}) {
178
186
  return id;
179
187
  }
180
188
  if (importer?.endsWith(".qk") && !nodePath.extname(id)) {
181
- const qingkuaiConfig = getQingkuaiConfiguration(id);
182
- return nodePath.join(
183
- nodePath.dirname(importer),
184
- id + (qingkuaiConfig.resolveImportExtension ? ".qk" : "")
189
+ const qingkuaiConfig = getQingkuaiConfig(importer);
190
+ return normalizePath(
191
+ nodePath.join(nodePath.dirname(importer), id + (qingkuaiConfig.resolveImportExtension ? ".qk" : ""))
185
192
  );
186
193
  }
187
194
  return id;
@@ -349,7 +356,7 @@ Caused by: "${fileId}".`;
349
356
  };
350
357
  },
351
358
  async transform(src, id) {
352
- if (!id.endsWith(".qk")) {
359
+ if (!(id = normalizePath(id)).endsWith(".qk")) {
353
360
  return;
354
361
  }
355
362
  try {
@@ -442,59 +449,44 @@ Caused by: "${fileId}".`;
442
449
  }
443
450
  }
444
451
  };
445
- function getQingkuaiConfiguration(id) {
446
- let config = {
447
- interpretiveComments: true,
448
- resolveImportExtension: true,
449
- preserveHtmlComments: "development"
450
- };
451
- while (true) {
452
- const dir = nodePath.dirname(id);
453
- if (dir === id) {
454
- break;
455
- }
456
- const got = qingkuaiConfigurations.get(id = dir);
457
- if (got) {
458
- config = got;
459
- break;
452
+ function getQingkuaiConfig(filePath) {
453
+ return configResolver.resolve(filePath, (configPath, message) => {
454
+ reportConfigMessage(viteConfig.logger, configPath, message);
455
+ });
456
+ }
457
+ function reportConfigMessage(logger, filePath, message) {
458
+ const key = `${filePath}\0${message.value}`;
459
+ if (reportedConfigMessages.has(key)) {
460
+ return;
461
+ }
462
+ reportedConfigMessages.add(key);
463
+ const reason = message.kind === ConfigParsingMessageKind.Error ? "Failed to parse configuration file" : "Configuration file";
464
+ logger.warn(`[qingkuai] ${reason} ${filePath}: ${message.value}`);
465
+ }
466
+ function forgetConfigMessages(configPath) {
467
+ const prefix = `${configPath}\0`;
468
+ for (const key of reportedConfigMessages) {
469
+ if (key.startsWith(prefix)) {
470
+ reportedConfigMessages.delete(key);
460
471
  }
461
472
  }
462
- return config;
463
473
  }
464
474
  function createQingkuaiConfigurationWatcher(server) {
465
475
  const watcher = server.watcher;
466
- const isQingkuaiConfig = (filePath) => {
467
- return nodePath.basename(filePath) === ".qingkuairc" && !filePath.includes(`${nodePath.sep}node_modules${nodePath.sep}`);
468
- };
469
- watcher.on("unlink", (filePath) => {
470
- if (isQingkuaiConfig(filePath)) {
471
- qingkuaiConfigurations.delete(nodePath.dirname(filePath));
472
- }
473
- });
474
- watcher.on("change", (filePath) => {
475
- if (isQingkuaiConfig(filePath)) {
476
- recordQingkuaiConfiguration(filePath);
477
- }
478
- });
479
- watcher.on("add", (filePath) => {
480
- if (isQingkuaiConfig(filePath)) {
481
- recordQingkuaiConfiguration(filePath);
476
+ const handleFileChange = (filePath) => {
477
+ for (const configPath of configResolver.removeCacheByPath(filePath)) {
478
+ forgetConfigMessages(configPath);
479
+ configResolver.resolve(configPath, (path, message) => {
480
+ reportConfigMessage(server.config.logger, path, message);
481
+ });
482
482
  }
483
- });
484
- }
485
- function loadAllQingkuaiConfigurations(workspaceDir) {
486
- findFilesByName(workspaceDir, ".qingkuairc", /* @__PURE__ */ new Set(["node_modules"])).forEach((fileName) => {
487
- recordQingkuaiConfiguration(fileName);
488
- });
489
- }
490
- function recordQingkuaiConfiguration(fileName) {
491
- try {
492
- qingkuaiConfigurations.set(nodePath.dirname(fileName), JSON.parse(nodeFs.readFileSync(fileName, "utf-8")));
493
- } catch {
494
- }
483
+ };
484
+ watcher.on("change", handleFileChange);
485
+ watcher.on("add", handleFileChange);
486
+ watcher.on("unlink", handleFileChange);
495
487
  }
496
488
  function getCompileOptions(id) {
497
- const qingkuaiConfig = getQingkuaiConfiguration(id);
489
+ const qingkuaiConfig = getQingkuaiConfig(id);
498
490
  const ret = {
499
491
  interpretiveComments: isUndefined(qingkuaiConfig.interpretiveComments) ? isDev : !!qingkuaiConfig.interpretiveComments,
500
492
  allowConstReactive: qingkuaiConfig.allowConstReactive !== false,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "mlgq",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "version": "1.0.29",
6
+ "version": "1.0.31",
7
7
  "packageManager": "pnpm@9.9.0",
8
8
  "exports": {
9
9
  ".": {
@@ -22,8 +22,10 @@
22
22
  },
23
23
  "scripts": {
24
24
  "dev": "rollup -c -w",
25
+ "test": "vitest --run",
25
26
  "release": "node scripts/release.js",
26
- "build": "rimraf dist && tsc && rollup -c && rimraf dist/temp-types",
27
+ "typecheck": "tsc -p tsconfig.json",
28
+ "build": "rimraf dist && tsc -p tsconfig.build.json && rollup -c && rimraf dist/temp-types",
27
29
  "postpublish": "curl -X PUT 'https://registry-direct.npmmirror.com/-/package/vite-plugin-qingkuai/syncs'"
28
30
  },
29
31
  "devDependencies": {
@@ -37,7 +39,9 @@
37
39
  "rollup": "^4.38.0",
38
40
  "rollup-plugin-dts": "^6.2.1",
39
41
  "rollup-plugin-esbuild": "^6.2.1",
40
- "vite": "8.0.0"
42
+ "typescript": "^6.0.3",
43
+ "vite": "8.3.5",
44
+ "vitest": "4.1.10"
41
45
  },
42
46
  "peerDependencies": {
43
47
  "qingkuai": ">=1.0.104",
@@ -48,6 +52,7 @@
48
52
  "lines-and-columns": "^2.0.4",
49
53
  "postcss": "^8.5.3",
50
54
  "postcss-selector-parser": "^7.1.0",
55
+ "qingkuai-language-service": "^1.0.23",
51
56
  "source-map-js": "^1.2.1"
52
57
  },
53
58
  "keywords": [