weapp-tailwindcss 2.8.0 → 2.8.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/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var options = require('./options-7b804be0.js');
3
+ var options = require('./options-4284d635.js');
4
4
  require('micromatch');
5
5
  require('magic-string');
6
6
  require('./replace.js');
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { g as getOptions, c as createPatch } from './options-70759e98.mjs';
1
+ import { g as getOptions, c as createPatch } from './options-ad0be036.mjs';
2
2
  import 'micromatch';
3
3
  import 'magic-string';
4
4
  import './replace.mjs';
package/dist/gulp.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var stream = require('node:stream');
6
- var options = require('./options-7b804be0.js');
6
+ var options = require('./options-4284d635.js');
7
7
  require('micromatch');
8
8
  require('magic-string');
9
9
  require('./replace.js');
package/dist/gulp.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import stream from 'node:stream';
2
- import { g as getOptions, a as createTailwindcssPatcher } from './options-70759e98.mjs';
2
+ import { g as getOptions, a as createTailwindcssPatcher } from './options-ad0be036.mjs';
3
3
  import 'micromatch';
4
4
  import 'magic-string';
5
5
  import './replace.mjs';
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ var vite = require('./vite.js');
7
7
  var gulp = require('./gulp.js');
8
8
  require('node:path');
9
9
  require('node:fs');
10
- require('./options-7b804be0.js');
10
+ require('./options-4284d635.js');
11
11
  require('micromatch');
12
12
  require('magic-string');
13
13
  require('./replace.js');
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ export { UnifiedViteWeappTailwindcssPlugin } from './vite.mjs';
3
3
  export { createPlugins } from './gulp.mjs';
4
4
  import 'node:path';
5
5
  import 'node:fs';
6
- import './options-70759e98.mjs';
6
+ import './options-ad0be036.mjs';
7
7
  import 'micromatch';
8
8
  import 'magic-string';
9
9
  import './replace.mjs';
@@ -113,8 +113,9 @@ function replaceHandleValue(str, node, options, ms, offset = 0, needEscaped = fa
113
113
  if (typeof node.start === 'number' && typeof node.end === 'number') {
114
114
  const start = node.start + offset;
115
115
  const end = node.end - offset;
116
- if (start < end) {
117
- ms.update(start, end, needEscaped ? escape.jsStringEscape(rawStr) : rawStr);
116
+ if (start < end && str !== rawStr) {
117
+ const content = needEscaped ? escape.jsStringEscape(rawStr) : rawStr;
118
+ ms.update(start, end, content);
118
119
  }
119
120
  }
120
121
  return rawStr;
@@ -122,6 +123,13 @@ function replaceHandleValue(str, node, options, ms, offset = 0, needEscaped = fa
122
123
 
123
124
  const isProd = () => process.env.NODE_ENV === 'production';
124
125
 
126
+ function isEvalPath(p) {
127
+ if (p.isCallExpression()) {
128
+ const calleePath = p.get('callee');
129
+ return calleePath.isIdentifier() && calleePath.node.name === 'eval';
130
+ }
131
+ return false;
132
+ }
125
133
  function jsHandler(rawSource, options) {
126
134
  var _a;
127
135
  const ast = parser.parse(rawSource, {
@@ -132,26 +140,56 @@ function jsHandler(rawSource, options) {
132
140
  const ropt = {
133
141
  StringLiteral: {
134
142
  enter(p) {
143
+ var _a;
144
+ if (isEvalPath(p.parentPath)) {
145
+ return;
146
+ }
135
147
  const n = p.node;
136
- replaceHandleValue(n.value, n, options, ms, 1, true);
148
+ replaceHandleValue(n.value, n, options, ms, 1, (_a = options.needEscaped) !== null && _a !== void 0 ? _a : true);
137
149
  }
138
150
  },
139
151
  TemplateElement: {
140
152
  enter(p) {
153
+ if (p.parentPath.isTemplateLiteral() && isEvalPath(p.parentPath.parentPath)) {
154
+ return;
155
+ }
141
156
  const n = p.node;
142
157
  replaceHandleValue(n.value.raw, n, options, ms, 0, false);
143
158
  }
144
159
  },
145
160
  CallExpression: {
146
161
  enter(p) {
147
- const calleePath = p.get('callee');
148
- if (calleePath.isIdentifier() && calleePath.node.name === 'eval') {
162
+ if (isEvalPath(p)) {
149
163
  p.traverse({
150
164
  StringLiteral: {
151
165
  enter(s) {
152
- const res = jsHandler(s.node.value, options);
166
+ const res = jsHandler(s.node.value, Object.assign(Object.assign({}, options), { needEscaped: false }));
153
167
  if (res.code) {
154
- s.node.value = res.code;
168
+ const node = s.node;
169
+ if (typeof node.start === 'number' && typeof node.end === 'number') {
170
+ const start = node.start + 1;
171
+ const end = node.end - 1;
172
+ if (start < end && s.node.value !== res.code) {
173
+ ms.update(start, end, escape.jsStringEscape(res.code));
174
+ node.value = res.code;
175
+ }
176
+ }
177
+ }
178
+ }
179
+ },
180
+ TemplateElement: {
181
+ enter(s) {
182
+ const res = jsHandler(s.node.value.raw, options);
183
+ if (res.code) {
184
+ const node = s.node;
185
+ if (typeof node.start === 'number' && typeof node.end === 'number') {
186
+ const start = node.start;
187
+ const end = node.end;
188
+ if (start < end && s.node.value.raw !== res.code) {
189
+ ms.update(start, end, res.code);
190
+ s.node.value.raw = res.code;
191
+ }
192
+ }
155
193
  }
156
194
  }
157
195
  }
@@ -169,20 +207,25 @@ function jsHandler(rawSource, options) {
169
207
  const gopt = {
170
208
  StringLiteral: {
171
209
  enter(p) {
210
+ if (isEvalPath(p.parentPath)) {
211
+ return;
212
+ }
172
213
  const n = p.node;
173
214
  n.value = regenerateHandleValue(n.value, n, options);
174
215
  }
175
216
  },
176
217
  TemplateElement: {
177
218
  enter(p) {
219
+ if (p.parentPath.isTemplateLiteral() && isEvalPath(p.parentPath.parentPath)) {
220
+ return;
221
+ }
178
222
  const n = p.node;
179
223
  n.value.raw = regenerateHandleValue(n.value.raw, n, options);
180
224
  }
181
225
  },
182
226
  CallExpression: {
183
227
  enter(p) {
184
- const calleePath = p.get('callee');
185
- if (calleePath.isIdentifier() && calleePath.node.name === 'eval') {
228
+ if (isEvalPath(p)) {
186
229
  p.traverse({
187
230
  StringLiteral: {
188
231
  enter(s) {
@@ -191,6 +234,14 @@ function jsHandler(rawSource, options) {
191
234
  s.node.value = res.code;
192
235
  }
193
236
  }
237
+ },
238
+ TemplateElement: {
239
+ enter(s) {
240
+ const res = jsHandler(s.node.value.raw, options);
241
+ if (res.code) {
242
+ s.node.value.raw = res.code;
243
+ }
244
+ }
194
245
  }
195
246
  });
196
247
  }
@@ -82,8 +82,9 @@ function replaceHandleValue(str, node, options, ms, offset = 0, needEscaped = fa
82
82
  if (typeof node.start === 'number' && typeof node.end === 'number') {
83
83
  const start = node.start + offset;
84
84
  const end = node.end - offset;
85
- if (start < end) {
86
- ms.update(start, end, needEscaped ? jsStringEscape(rawStr) : rawStr);
85
+ if (start < end && str !== rawStr) {
86
+ const content = needEscaped ? jsStringEscape(rawStr) : rawStr;
87
+ ms.update(start, end, content);
87
88
  }
88
89
  }
89
90
  return rawStr;
@@ -91,6 +92,13 @@ function replaceHandleValue(str, node, options, ms, offset = 0, needEscaped = fa
91
92
 
92
93
  const isProd = () => process.env.NODE_ENV === 'production';
93
94
 
95
+ function isEvalPath(p) {
96
+ if (p.isCallExpression()) {
97
+ const calleePath = p.get('callee');
98
+ return calleePath.isIdentifier() && calleePath.node.name === 'eval';
99
+ }
100
+ return false;
101
+ }
94
102
  function jsHandler(rawSource, options) {
95
103
  var _a;
96
104
  const ast = parse(rawSource, {
@@ -101,26 +109,56 @@ function jsHandler(rawSource, options) {
101
109
  const ropt = {
102
110
  StringLiteral: {
103
111
  enter(p) {
112
+ var _a;
113
+ if (isEvalPath(p.parentPath)) {
114
+ return;
115
+ }
104
116
  const n = p.node;
105
- replaceHandleValue(n.value, n, options, ms, 1, true);
117
+ replaceHandleValue(n.value, n, options, ms, 1, (_a = options.needEscaped) !== null && _a !== void 0 ? _a : true);
106
118
  }
107
119
  },
108
120
  TemplateElement: {
109
121
  enter(p) {
122
+ if (p.parentPath.isTemplateLiteral() && isEvalPath(p.parentPath.parentPath)) {
123
+ return;
124
+ }
110
125
  const n = p.node;
111
126
  replaceHandleValue(n.value.raw, n, options, ms, 0, false);
112
127
  }
113
128
  },
114
129
  CallExpression: {
115
130
  enter(p) {
116
- const calleePath = p.get('callee');
117
- if (calleePath.isIdentifier() && calleePath.node.name === 'eval') {
131
+ if (isEvalPath(p)) {
118
132
  p.traverse({
119
133
  StringLiteral: {
120
134
  enter(s) {
121
- const res = jsHandler(s.node.value, options);
135
+ const res = jsHandler(s.node.value, Object.assign(Object.assign({}, options), { needEscaped: false }));
122
136
  if (res.code) {
123
- s.node.value = res.code;
137
+ const node = s.node;
138
+ if (typeof node.start === 'number' && typeof node.end === 'number') {
139
+ const start = node.start + 1;
140
+ const end = node.end - 1;
141
+ if (start < end && s.node.value !== res.code) {
142
+ ms.update(start, end, jsStringEscape(res.code));
143
+ node.value = res.code;
144
+ }
145
+ }
146
+ }
147
+ }
148
+ },
149
+ TemplateElement: {
150
+ enter(s) {
151
+ const res = jsHandler(s.node.value.raw, options);
152
+ if (res.code) {
153
+ const node = s.node;
154
+ if (typeof node.start === 'number' && typeof node.end === 'number') {
155
+ const start = node.start;
156
+ const end = node.end;
157
+ if (start < end && s.node.value.raw !== res.code) {
158
+ ms.update(start, end, res.code);
159
+ s.node.value.raw = res.code;
160
+ }
161
+ }
124
162
  }
125
163
  }
126
164
  }
@@ -138,20 +176,25 @@ function jsHandler(rawSource, options) {
138
176
  const gopt = {
139
177
  StringLiteral: {
140
178
  enter(p) {
179
+ if (isEvalPath(p.parentPath)) {
180
+ return;
181
+ }
141
182
  const n = p.node;
142
183
  n.value = regenerateHandleValue(n.value, n, options);
143
184
  }
144
185
  },
145
186
  TemplateElement: {
146
187
  enter(p) {
188
+ if (p.parentPath.isTemplateLiteral() && isEvalPath(p.parentPath.parentPath)) {
189
+ return;
190
+ }
147
191
  const n = p.node;
148
192
  n.value.raw = regenerateHandleValue(n.value.raw, n, options);
149
193
  }
150
194
  },
151
195
  CallExpression: {
152
196
  enter(p) {
153
- const calleePath = p.get('callee');
154
- if (calleePath.isIdentifier() && calleePath.node.name === 'eval') {
197
+ if (isEvalPath(p)) {
155
198
  p.traverse({
156
199
  StringLiteral: {
157
200
  enter(s) {
@@ -160,6 +203,14 @@ function jsHandler(rawSource, options) {
160
203
  s.node.value = res.code;
161
204
  }
162
205
  }
206
+ },
207
+ TemplateElement: {
208
+ enter(s) {
209
+ const res = jsHandler(s.node.value.raw, options);
210
+ if (res.code) {
211
+ s.node.value.raw = res.code;
212
+ }
213
+ }
163
214
  }
164
215
  });
165
216
  }
package/dist/types.d.ts CHANGED
@@ -39,6 +39,7 @@ export type IJsHandlerOptions = {
39
39
  mangleContext?: IMangleScopeContext;
40
40
  jsPreserveClass?: (keyword: string) => boolean | undefined;
41
41
  strategy?: UserDefinedOptions['jsEscapeStrategy'];
42
+ needEscaped?: boolean;
42
43
  };
43
44
  export interface RawSource {
44
45
  start: number;
@@ -95,6 +96,7 @@ export interface UserDefinedOptions {
95
96
  jsPreserveClass?: (keyword: string) => boolean | undefined;
96
97
  disabledDefaultTemplateHandler?: boolean;
97
98
  jsEscapeStrategy?: 'regenerate' | 'replace';
99
+ runtimeLoaderPath?: string;
98
100
  }
99
101
  export interface IMangleScopeContext {
100
102
  rawOptions: UserDefinedOptions['mangle'];
package/dist/vite.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var options = require('./options-7b804be0.js');
5
+ var options = require('./options-4284d635.js');
6
6
  var postcss = require('./postcss-4e99a8e8.js');
7
7
  var defaults = require('./defaults-c6437917.js');
8
8
  require('micromatch');
package/dist/vite.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { g as getOptions, a as createTailwindcssPatcher } from './options-70759e98.mjs';
1
+ import { g as getOptions, a as createTailwindcssPatcher } from './options-ad0be036.mjs';
2
2
  import { v as vitePluginName } from './postcss-a551ddc0.mjs';
3
3
  import { g as getGroupedEntries } from './defaults-72ea9566.mjs';
4
4
  import 'micromatch';
package/dist/webpack.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var path = require('node:path');
6
6
  var fs = require('node:fs');
7
- var options = require('./options-7b804be0.js');
7
+ var options = require('./options-4284d635.js');
8
8
  var postcss = require('./postcss-4e99a8e8.js');
9
9
  var defaults = require('./defaults-c6437917.js');
10
10
  require('micromatch');
@@ -39,7 +39,7 @@ class UnifiedWebpackPluginV5 {
39
39
  this.appType = this.options.appType;
40
40
  }
41
41
  apply(compiler) {
42
- const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templateHandler, jsHandler, setMangleRuntimeSet } = this.options;
42
+ const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templateHandler, jsHandler, setMangleRuntimeSet, runtimeLoaderPath } = this.options;
43
43
  if (disabled) {
44
44
  return;
45
45
  }
@@ -51,7 +51,7 @@ class UnifiedWebpackPluginV5 {
51
51
  return twPatcher.getClassSet();
52
52
  }
53
53
  onLoad();
54
- const loader = path__default["default"].resolve(__dirname, './weapp-tw-runtime-loader.js');
54
+ const loader = runtimeLoaderPath !== null && runtimeLoaderPath !== void 0 ? runtimeLoaderPath : path__default["default"].resolve(__dirname, './weapp-tw-runtime-loader.js');
55
55
  const isExisted = fs__default["default"].existsSync(loader);
56
56
  const WeappTwRuntimeAopLoader = {
57
57
  loader,
package/dist/webpack.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import fs from 'node:fs';
3
- import { g as getOptions, a as createTailwindcssPatcher } from './options-70759e98.mjs';
3
+ import { g as getOptions, a as createTailwindcssPatcher } from './options-ad0be036.mjs';
4
4
  import { a as pluginName } from './postcss-a551ddc0.mjs';
5
5
  import { g as getGroupedEntries } from './defaults-72ea9566.mjs';
6
6
  import 'micromatch';
@@ -30,7 +30,7 @@ class UnifiedWebpackPluginV5 {
30
30
  this.appType = this.options.appType;
31
31
  }
32
32
  apply(compiler) {
33
- const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templateHandler, jsHandler, setMangleRuntimeSet } = this.options;
33
+ const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templateHandler, jsHandler, setMangleRuntimeSet, runtimeLoaderPath } = this.options;
34
34
  if (disabled) {
35
35
  return;
36
36
  }
@@ -42,7 +42,7 @@ class UnifiedWebpackPluginV5 {
42
42
  return twPatcher.getClassSet();
43
43
  }
44
44
  onLoad();
45
- const loader = path.resolve(__dirname, './weapp-tw-runtime-loader.js');
45
+ const loader = runtimeLoaderPath !== null && runtimeLoaderPath !== void 0 ? runtimeLoaderPath : path.resolve(__dirname, './weapp-tw-runtime-loader.js');
46
46
  const isExisted = fs.existsSync(loader);
47
47
  const WeappTwRuntimeAopLoader = {
48
48
  loader,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weapp-tailwindcss",
3
- "version": "2.8.0",
3
+ "version": "2.8.1",
4
4
  "description": "把tailwindcss jit引擎,带给小程序开发者们! bring tailwindcss jit engine to miniprogram developers!",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -108,7 +108,7 @@
108
108
  "@rollup/plugin-alias": "^5.0.0",
109
109
  "@rollup/plugin-commonjs": "^25.0.4",
110
110
  "@rollup/plugin-json": "^6.0.0",
111
- "@rollup/plugin-node-resolve": "^15.1.0",
111
+ "@rollup/plugin-node-resolve": "^15.2.0",
112
112
  "@rollup/plugin-terser": "^0.4.3",
113
113
  "@rollup/plugin-typescript": "^11.1.2",
114
114
  "@tsconfig/recommended": "^1.0.2",
@@ -123,21 +123,22 @@
123
123
  "@types/loader-utils": "^2.0.3",
124
124
  "@types/lodash": "^4.14.197",
125
125
  "@types/micromatch": "^4.0.2",
126
- "@types/node": "^20.5.0",
126
+ "@types/node": "^20.5.1",
127
127
  "@types/semver": "^7.5.0",
128
128
  "@types/vinyl": "^2.0.7",
129
129
  "@types/webpack": "^5.28.1",
130
130
  "@types/webpack-sources": "^3.2.0",
131
- "@vitest/coverage-v8": "^0.34.1",
131
+ "@vitest/coverage-v8": "^0.34.2",
132
132
  "autoprefixer": "^10.4.15",
133
133
  "babel-loader": "^9.1.3",
134
- "bumpp": "^9.1.1",
134
+ "bumpp": "^9.2.0",
135
135
  "colorette": "^2.0.20",
136
136
  "cross-env": "^7.0.3",
137
137
  "css-loader": "^6.8.1",
138
138
  "dedent": "^1.5.1",
139
139
  "defu": "6.1.2",
140
140
  "del": "^7.0.0",
141
+ "domhandler": "^5.0.3",
141
142
  "eslint": "8.47.0",
142
143
  "eslint-config-icebreaker": "^1.2.2",
143
144
  "eslint-config-prettier": "^9.0.0",
@@ -148,7 +149,7 @@
148
149
  "gulp": "^4.0.2",
149
150
  "gulp-postcss": "^9.0.1",
150
151
  "html-loader": "^4.2.0",
151
- "jest": "^29.6.2",
152
+ "jest": "^29.6.3",
152
153
  "js-beautify": "^1.14.9",
153
154
  "klaw": "^4.1.0",
154
155
  "lodash": "^4.17.21",
@@ -158,7 +159,7 @@
158
159
  "postcss-load-config": "^4.0.1",
159
160
  "postcss-loader": "^7.3.3",
160
161
  "postcss-rem-to-responsive-pixel": "^5.1.3",
161
- "prettier": "^3.0.1",
162
+ "prettier": "^3.0.2",
162
163
  "promisify-loader-runner": "^1.0.0",
163
164
  "rollup": "^3.28.0",
164
165
  "rollup-plugin-visualizer": "^5.9.2",
@@ -169,16 +170,15 @@
169
170
  "ts-node": "^10.9.1",
170
171
  "ts-patch": "^3.0.2",
171
172
  "tsd": "^0.28.1",
172
- "tslib": "^2.6.1",
173
+ "tslib": "^2.6.2",
173
174
  "typescript": "^5.1.6",
174
175
  "typescript-transform-paths": "^3.4.6",
175
176
  "vinyl": "^3.0.0",
176
177
  "vite": "^4.4.9",
177
- "vitest": "^0.34.1",
178
+ "vitest": "^0.34.2",
178
179
  "weapp-tailwindcss-children": "^0.1.0",
179
180
  "webpack": "^5.88.2",
180
- "webpack-build-utils": "^0.0.4",
181
- "domhandler": "^5.0.3"
181
+ "webpack-build-utils": "^0.0.4"
182
182
  },
183
183
  "dependencies": {
184
184
  "@babel/generator": "^7.22.10",
@@ -191,12 +191,12 @@
191
191
  "@weapp-core/regex": "^1.0.0",
192
192
  "htmlparser2": "^9.0.0",
193
193
  "loader-utils": "^2.0.3",
194
- "magic-string": "^0.30.2",
194
+ "magic-string": "^0.30.3",
195
195
  "micromatch": "^4.0.5",
196
- "postcss": "8.4.27",
196
+ "postcss": "8.4.28",
197
197
  "postcss-selector-parser": "^6.0.13",
198
198
  "semver": "^7.5.4",
199
- "tailwindcss-patch": "^2.1.0"
199
+ "tailwindcss-patch": "^2.1.1"
200
200
  },
201
201
  "packageManager": "pnpm@8.6.12",
202
202
  "engines": {