vite-plugin-qingkuai 1.0.3 → 1.0.5

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 CHANGED
@@ -53,13 +53,13 @@ function getSourceFile(sourcemap, line, column) {
53
53
  }).source;
54
54
  }
55
55
 
56
- async function attachScopeForStyleSelectors(code, hash, map, sourceFile) {
56
+ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
57
57
  const processor = postcss([
58
58
  {
59
59
  postcssPlugin: "postcss-attach-scope-qingkuai",
60
60
  Rule(rule) {
61
61
  const { line, column } = rule.source.start;
62
- if (getSourceFile(map, line, column) !== sourceFile) {
62
+ if (map && getSourceFile(map, line, column) !== sourceFile) {
63
63
  return;
64
64
  }
65
65
  rule.selector = selectorParser((selectors) => {
@@ -84,7 +84,7 @@ async function attachScopeForStyleSelectors(code, hash, map, sourceFile) {
84
84
  }
85
85
  ]);
86
86
  const ret = await processor.process(code, {
87
- from: map.file,
87
+ from: sourceFile,
88
88
  map: {
89
89
  prev: map,
90
90
  annotation: false
@@ -100,10 +100,10 @@ function qingkuaiPlugin() {
100
100
  let viteConfig;
101
101
  const compileResultCache = /* @__PURE__ */ new Map();
102
102
  const qingkuaiConfigurations = /* @__PURE__ */ new Map();
103
- const qingkuaiPackageServeRE = /node_modules\/\.vite\/deps\/chunk.*$/;
103
+ const qingkuaiPackageServeRE = /node_modules\/\.vite\/deps\/chunk-.*$/;
104
104
  const confIdentifierRE = /__qk_expose_(?:dependencies|destructions)__/g;
105
105
  const styleIdRE = /^virtual:\[\d+\].*?\.qk.(?:css|s[ac]ss|less|stylus|postcss)\?\d{13}$/;
106
- const qingkuaiPackageBuildRE = /node_modules\/qingkuai\/dist\/esm\/(?:chunks|runtime)\/\w+\.js$/;
106
+ const qingkuaiPackageBuildRE = /(?:node_modules)?\/qingkuai\/dist\/esm\/(?:chunks|runtime)\/\w+\.js$/;
107
107
  return {
108
108
  name: "qingkuai-compiler",
109
109
  config(_, env) {
@@ -164,8 +164,8 @@ function qingkuaiPlugin() {
164
164
  const attachScopeResult = await attachScopeForStyleSelectors(
165
165
  preprocessRes.code,
166
166
  compileRes.hashId,
167
- assertedPreprocessMap,
168
- virtualFileName
167
+ virtualFileName,
168
+ assertedPreprocessMap
169
169
  );
170
170
  const offsetMappings = sourcemapCodec.encode(
171
171
  offsetSourceMap(
@@ -180,8 +180,8 @@ function qingkuaiPlugin() {
180
180
  map: {
181
181
  version: 3,
182
182
  mappings: offsetMappings,
183
- names: assertedPreprocessMap.names,
184
- sources: [...assertedPreprocessMap.sources.slice(0, -1), fileId]
183
+ names: assertedPreprocessMap?.names || [],
184
+ sources: [...assertedPreprocessMap ? assertedPreprocessMap.sources.slice(0, -1) : [], fileId]
185
185
  }
186
186
  };
187
187
  }
@@ -189,7 +189,7 @@ function qingkuaiPlugin() {
189
189
  async transform(src, id) {
190
190
  const qingkuaiConfig = getQingkuaiConfiguration(id);
191
191
  if (!id.endsWith(".qk")) {
192
- if (isDev && qingkuaiPackageServeRE.test(id) || !isDev && qingkuaiPackageBuildRE.test(id)) {
192
+ if (qingkuaiPackageServeRE.test(id) || qingkuaiPackageBuildRE.test(id)) {
193
193
  const ret = src.replace(confIdentifierRE, (s) => {
194
194
  switch (s) {
195
195
  case "__qk_expose_dependencies__":
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Plugin } from 'vite';
1
+ import { PluginOption } from 'vite';
2
2
 
3
- declare function qingkuaiPlugin(): Plugin;
3
+ declare function qingkuaiPlugin(): PluginOption;
4
4
 
5
5
  export { qingkuaiPlugin as default };
package/dist/index.js CHANGED
@@ -51,13 +51,13 @@ function getSourceFile(sourcemap, line, column) {
51
51
  }).source;
52
52
  }
53
53
 
54
- async function attachScopeForStyleSelectors(code, hash, map, sourceFile) {
54
+ async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
55
55
  const processor = postcss([
56
56
  {
57
57
  postcssPlugin: "postcss-attach-scope-qingkuai",
58
58
  Rule(rule) {
59
59
  const { line, column } = rule.source.start;
60
- if (getSourceFile(map, line, column) !== sourceFile) {
60
+ if (map && getSourceFile(map, line, column) !== sourceFile) {
61
61
  return;
62
62
  }
63
63
  rule.selector = selectorParser((selectors) => {
@@ -82,7 +82,7 @@ async function attachScopeForStyleSelectors(code, hash, map, sourceFile) {
82
82
  }
83
83
  ]);
84
84
  const ret = await processor.process(code, {
85
- from: map.file,
85
+ from: sourceFile,
86
86
  map: {
87
87
  prev: map,
88
88
  annotation: false
@@ -98,10 +98,10 @@ function qingkuaiPlugin() {
98
98
  let viteConfig;
99
99
  const compileResultCache = /* @__PURE__ */ new Map();
100
100
  const qingkuaiConfigurations = /* @__PURE__ */ new Map();
101
- const qingkuaiPackageServeRE = /node_modules\/\.vite\/deps\/chunk.*$/;
101
+ const qingkuaiPackageServeRE = /node_modules\/\.vite\/deps\/chunk-.*$/;
102
102
  const confIdentifierRE = /__qk_expose_(?:dependencies|destructions)__/g;
103
103
  const styleIdRE = /^virtual:\[\d+\].*?\.qk.(?:css|s[ac]ss|less|stylus|postcss)\?\d{13}$/;
104
- const qingkuaiPackageBuildRE = /node_modules\/qingkuai\/dist\/esm\/(?:chunks|runtime)\/\w+\.js$/;
104
+ const qingkuaiPackageBuildRE = /(?:node_modules)?\/qingkuai\/dist\/esm\/(?:chunks|runtime)\/\w+\.js$/;
105
105
  return {
106
106
  name: "qingkuai-compiler",
107
107
  config(_, env) {
@@ -162,8 +162,8 @@ function qingkuaiPlugin() {
162
162
  const attachScopeResult = await attachScopeForStyleSelectors(
163
163
  preprocessRes.code,
164
164
  compileRes.hashId,
165
- assertedPreprocessMap,
166
- virtualFileName
165
+ virtualFileName,
166
+ assertedPreprocessMap
167
167
  );
168
168
  const offsetMappings = encode(
169
169
  offsetSourceMap(
@@ -178,8 +178,8 @@ function qingkuaiPlugin() {
178
178
  map: {
179
179
  version: 3,
180
180
  mappings: offsetMappings,
181
- names: assertedPreprocessMap.names,
182
- sources: [...assertedPreprocessMap.sources.slice(0, -1), fileId]
181
+ names: assertedPreprocessMap?.names || [],
182
+ sources: [...assertedPreprocessMap ? assertedPreprocessMap.sources.slice(0, -1) : [], fileId]
183
183
  }
184
184
  };
185
185
  }
@@ -187,7 +187,7 @@ function qingkuaiPlugin() {
187
187
  async transform(src, id) {
188
188
  const qingkuaiConfig = getQingkuaiConfiguration(id);
189
189
  if (!id.endsWith(".qk")) {
190
- if (isDev && qingkuaiPackageServeRE.test(id) || !isDev && qingkuaiPackageBuildRE.test(id)) {
190
+ if (qingkuaiPackageServeRE.test(id) || qingkuaiPackageBuildRE.test(id)) {
191
191
  const ret = src.replace(confIdentifierRE, (s) => {
192
192
  switch (s) {
193
193
  case "__qk_expose_dependencies__":
@@ -1,2 +1,2 @@
1
- import type { Plugin } from "vite";
2
- export default function qingkuaiPlugin(): Plugin;
1
+ import type { PluginOption } from "vite";
2
+ export default function qingkuaiPlugin(): PluginOption;
@@ -1,5 +1,5 @@
1
1
  import type { SourceMap } from "./types";
2
- export declare function attachScopeForStyleSelectors(code: string, hash: string, map: SourceMap, sourceFile: string): Promise<{
2
+ export declare function attachScopeForStyleSelectors(code: string, hash: string, sourceFile: string, map: SourceMap | undefined): Promise<{
3
3
  code: string;
4
4
  mappings: string;
5
5
  }>;
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.3",
5
+ "version": "1.0.5",
6
6
  "type": "module",
7
7
  "keywords": [
8
8
  "vite",