vite-plugin-qingkuai 1.0.4 → 1.0.6

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
@@ -3,7 +3,6 @@
3
3
  var node_path = require('node:path');
4
4
  var node_fs = require('node:fs');
5
5
  var node_crypto = require('node:crypto');
6
- var sourceMapJs = require('source-map-js');
7
6
  var sourcemapCodec = require('@jridgewell/sourcemap-codec');
8
7
  var compiler = require('qingkuai/compiler');
9
8
  var postcss = require('postcss');
@@ -42,26 +41,12 @@ function offsetSourceMap(mappings, sourceIndex, preLine, preColumn) {
42
41
  });
43
42
  });
44
43
  }
45
- function getSourceFile(sourcemap, line, column) {
46
- const consumer = new sourceMapJs.SourceMapConsumer({
47
- ...sourcemap,
48
- version: sourcemap.version.toString()
49
- });
50
- return consumer.originalPositionFor({
51
- line,
52
- column
53
- }).source;
54
- }
55
44
 
56
45
  async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
57
46
  const processor = postcss([
58
47
  {
59
48
  postcssPlugin: "postcss-attach-scope-qingkuai",
60
49
  Rule(rule) {
61
- const { line, column } = rule.source.start;
62
- if (map && getSourceFile(map, line, column) !== sourceFile) {
63
- return;
64
- }
65
50
  rule.selector = selectorParser((selectors) => {
66
51
  selectors.each((selector) => {
67
52
  const index = selector.nodes.findLastIndex(({ type }) => {
@@ -100,10 +85,10 @@ function qingkuaiPlugin() {
100
85
  let viteConfig;
101
86
  const compileResultCache = /* @__PURE__ */ new Map();
102
87
  const qingkuaiConfigurations = /* @__PURE__ */ new Map();
103
- const qingkuaiPackageServeRE = /node_modules\/\.vite\/deps\/chunk.*$/;
88
+ const qingkuaiPackageServeRE = /node_modules\/\.vite\/deps\/chunk-.*$/;
104
89
  const confIdentifierRE = /__qk_expose_(?:dependencies|destructions)__/g;
105
90
  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$/;
91
+ const qingkuaiPackageBuildRE = /(?:node_modules)?\/qingkuai\/dist\/esm\/(?:chunks|runtime)\/\w+\.js$/;
107
92
  return {
108
93
  name: "qingkuai-compiler",
109
94
  config(_, env) {
@@ -129,7 +114,7 @@ function qingkuaiPlugin() {
129
114
  }
130
115
  if (importer?.endsWith(".qk") && !node_path.extname(id)) {
131
116
  const qingkuaiConfig = getQingkuaiConfiguration(id);
132
- return id + (qingkuaiConfig.resolveImportExtension ? ".qk" : "");
117
+ return node_path.join(node_path.dirname(importer), id + (qingkuaiConfig.resolveImportExtension ? ".qk" : ""));
133
118
  }
134
119
  },
135
120
  async load(id) {
@@ -189,7 +174,7 @@ function qingkuaiPlugin() {
189
174
  async transform(src, id) {
190
175
  const qingkuaiConfig = getQingkuaiConfiguration(id);
191
176
  if (!id.endsWith(".qk")) {
192
- if (isDev && qingkuaiPackageServeRE.test(id) || !isDev && qingkuaiPackageBuildRE.test(id)) {
177
+ if (qingkuaiPackageServeRE.test(id) || qingkuaiPackageBuildRE.test(id)) {
193
178
  const ret = src.replace(confIdentifierRE, (s) => {
194
179
  switch (s) {
195
180
  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
@@ -1,7 +1,6 @@
1
1
  import { join, basename, extname, dirname } from 'node:path';
2
2
  import { readdirSync, existsSync, readFileSync } from 'node:fs';
3
3
  import { randomBytes } from 'node:crypto';
4
- import { SourceMapConsumer } from 'source-map-js';
5
4
  import { decode, encode } from '@jridgewell/sourcemap-codec';
6
5
  import { compile, util } from 'qingkuai/compiler';
7
6
  import postcss from 'postcss';
@@ -40,26 +39,12 @@ function offsetSourceMap(mappings, sourceIndex, preLine, preColumn) {
40
39
  });
41
40
  });
42
41
  }
43
- function getSourceFile(sourcemap, line, column) {
44
- const consumer = new SourceMapConsumer({
45
- ...sourcemap,
46
- version: sourcemap.version.toString()
47
- });
48
- return consumer.originalPositionFor({
49
- line,
50
- column
51
- }).source;
52
- }
53
42
 
54
43
  async function attachScopeForStyleSelectors(code, hash, sourceFile, map) {
55
44
  const processor = postcss([
56
45
  {
57
46
  postcssPlugin: "postcss-attach-scope-qingkuai",
58
47
  Rule(rule) {
59
- const { line, column } = rule.source.start;
60
- if (map && getSourceFile(map, line, column) !== sourceFile) {
61
- return;
62
- }
63
48
  rule.selector = selectorParser((selectors) => {
64
49
  selectors.each((selector) => {
65
50
  const index = selector.nodes.findLastIndex(({ type }) => {
@@ -98,10 +83,10 @@ function qingkuaiPlugin() {
98
83
  let viteConfig;
99
84
  const compileResultCache = /* @__PURE__ */ new Map();
100
85
  const qingkuaiConfigurations = /* @__PURE__ */ new Map();
101
- const qingkuaiPackageServeRE = /node_modules\/\.vite\/deps\/chunk.*$/;
86
+ const qingkuaiPackageServeRE = /node_modules\/\.vite\/deps\/chunk-.*$/;
102
87
  const confIdentifierRE = /__qk_expose_(?:dependencies|destructions)__/g;
103
88
  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$/;
89
+ const qingkuaiPackageBuildRE = /(?:node_modules)?\/qingkuai\/dist\/esm\/(?:chunks|runtime)\/\w+\.js$/;
105
90
  return {
106
91
  name: "qingkuai-compiler",
107
92
  config(_, env) {
@@ -127,7 +112,7 @@ function qingkuaiPlugin() {
127
112
  }
128
113
  if (importer?.endsWith(".qk") && !extname(id)) {
129
114
  const qingkuaiConfig = getQingkuaiConfiguration(id);
130
- return id + (qingkuaiConfig.resolveImportExtension ? ".qk" : "");
115
+ return join(dirname(importer), id + (qingkuaiConfig.resolveImportExtension ? ".qk" : ""));
131
116
  }
132
117
  },
133
118
  async load(id) {
@@ -187,7 +172,7 @@ function qingkuaiPlugin() {
187
172
  async transform(src, id) {
188
173
  const qingkuaiConfig = getQingkuaiConfiguration(id);
189
174
  if (!id.endsWith(".qk")) {
190
- if (isDev && qingkuaiPackageServeRE.test(id) || !isDev && qingkuaiPackageBuildRE.test(id)) {
175
+ if (qingkuaiPackageServeRE.test(id) || qingkuaiPackageBuildRE.test(id)) {
191
176
  const ret = src.replace(confIdentifierRE, (s) => {
192
177
  switch (s) {
193
178
  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
  }>;
@@ -1,4 +1,2 @@
1
- import type { SourceMap } from "./types";
2
1
  import type { SourceMapMappings } from "@jridgewell/sourcemap-codec";
3
2
  export declare function offsetSourceMap(mappings: string, sourceIndex: number, preLine: number, preColumn: number): SourceMapMappings;
4
- export declare function getSourceFile(sourcemap: SourceMap, line: number, column: number): string;
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.4",
5
+ "version": "1.0.6",
6
6
  "type": "module",
7
7
  "keywords": [
8
8
  "vite",
@@ -39,7 +39,6 @@
39
39
  "dependencies": {
40
40
  "@jridgewell/sourcemap-codec": "^1.5.0",
41
41
  "postcss": "^8.5.3",
42
- "postcss-selector-parser": "^7.1.0",
43
- "source-map-js": "^1.2.1"
42
+ "postcss-selector-parser": "^7.1.0"
44
43
  }
45
44
  }