tailwindcss-injector 0.1.4 → 0.1.6-alpha.0

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/postcss.cjs CHANGED
@@ -27,9 +27,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  mod
28
28
  ));
29
29
 
30
- // ../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.1_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/cjs_shims.js
30
+ // ../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.2_postcss@8.4.49_tsx@4.19.2_typescript@5.7.3_yaml@2.7.0/node_modules/tsup/assets/cjs_shims.js
31
31
  var init_cjs_shims = __esm({
32
- "../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.1_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/cjs_shims.js"() {
32
+ "../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.2_postcss@8.4.49_tsx@4.19.2_typescript@5.7.3_yaml@2.7.0/node_modules/tsup/assets/cjs_shims.js"() {
33
33
  "use strict";
34
34
  }
35
35
  });
@@ -68,7 +68,7 @@ var require_is_plain_object = __commonJS({
68
68
  function isObjectObject(o) {
69
69
  return isObject(o) === true && Object.prototype.toString.call(o) === "[object Object]";
70
70
  }
71
- module.exports = function isPlainObject2(o) {
71
+ module.exports = function isPlainObject(o) {
72
72
  var ctor, prot;
73
73
  if (isObjectObject(o) === false) return false;
74
74
  ctor = o.constructor;
@@ -90,7 +90,7 @@ var require_set_value = __commonJS({
90
90
  init_cjs_shims();
91
91
  var { deleteProperty } = Reflect;
92
92
  var isPrimitive = require_is_primitive();
93
- var isPlainObject2 = require_is_plain_object();
93
+ var isPlainObject = require_is_plain_object();
94
94
  var isObject = (value) => {
95
95
  return typeof value === "object" && value !== null || typeof value === "function";
96
96
  };
@@ -171,7 +171,7 @@ var require_set_value = __commonJS({
171
171
  deleteProperty(obj, prop);
172
172
  } else if (options && options.merge) {
173
173
  const merge = options.merge === "function" ? options.merge : Object.assign;
174
- if (merge && isPlainObject2(obj[prop]) && isPlainObject2(value)) {
174
+ if (merge && isPlainObject(obj[prop]) && isPlainObject(value)) {
175
175
  obj[prop] = merge(obj[prop], value);
176
176
  } else {
177
177
  obj[prop] = value;
@@ -228,77 +228,7 @@ var _process = require('process'); var _process2 = _interopRequireDefault(_proce
228
228
  init_cjs_shims();
229
229
  var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
230
230
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
231
-
232
- // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
233
- init_cjs_shims();
234
- function isPlainObject(value) {
235
- if (value === null || typeof value !== "object") {
236
- return false;
237
- }
238
- const prototype = Object.getPrototypeOf(value);
239
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
240
- return false;
241
- }
242
- if (Symbol.iterator in value) {
243
- return false;
244
- }
245
- if (Symbol.toStringTag in value) {
246
- return Object.prototype.toString.call(value) === "[object Module]";
247
- }
248
- return true;
249
- }
250
- function _defu(baseObject, defaults, namespace = ".", merger) {
251
- if (!isPlainObject(defaults)) {
252
- return _defu(baseObject, {}, namespace, merger);
253
- }
254
- const object = Object.assign({}, defaults);
255
- for (const key in baseObject) {
256
- if (key === "__proto__" || key === "constructor") {
257
- continue;
258
- }
259
- const value = baseObject[key];
260
- if (value === null || value === void 0) {
261
- continue;
262
- }
263
- if (merger && merger(object, key, value, namespace)) {
264
- continue;
265
- }
266
- if (Array.isArray(value) && Array.isArray(object[key])) {
267
- object[key] = [...value, ...object[key]];
268
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
269
- object[key] = _defu(
270
- value,
271
- object[key],
272
- (namespace ? `${namespace}.` : "") + key.toString(),
273
- merger
274
- );
275
- } else {
276
- object[key] = value;
277
- }
278
- }
279
- return object;
280
- }
281
- function createDefu(merger) {
282
- return (...arguments_) => (
283
- // eslint-disable-next-line unicorn/no-array-reduce
284
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
285
- );
286
- }
287
- var defu = createDefu();
288
- var defuFn = createDefu((object, key, currentValue) => {
289
- if (object[key] !== void 0 && typeof currentValue === "function") {
290
- object[key] = currentValue(object[key]);
291
- return true;
292
- }
293
- });
294
- var defuArrayFn = createDefu((object, key, currentValue) => {
295
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
296
- object[key] = currentValue(object[key]);
297
- return true;
298
- }
299
- });
300
-
301
- // src/utils.ts
231
+ var _shared = require('@weapp-tailwindcss/shared');
302
232
  function removeFileExtension(filePath) {
303
233
  if (!filePath) {
304
234
  return "";
@@ -312,12 +242,6 @@ function removeFileExtension(filePath) {
312
242
  const dir = _path2.default.dirname(filePath);
313
243
  return _path2.default.join(dir, baseName);
314
244
  }
315
- var defuOverrideArray = createDefu((obj, key, value) => {
316
- if (Array.isArray(obj[key]) && Array.isArray(value)) {
317
- obj[key] = value;
318
- return true;
319
- }
320
- });
321
245
  function md5(input) {
322
246
  const hash = _crypto2.default.createHash("md5");
323
247
  hash.update(input);
@@ -334,11 +258,12 @@ function getDefaultConfig() {
334
258
  cwd: _process2.default.cwd(),
335
259
  extensions: ["wxml", "js", "ts"],
336
260
  // @import and @use (scss)
337
- insertAfterAtRulesNames: ["import", "use"]
261
+ insertAfterAtRulesNames: ["import", "use"],
262
+ insertAfterComments: ["@import"]
338
263
  };
339
264
  }
340
265
  function getConfig(options) {
341
- return defuOverrideArray(options, getDefaultConfig());
266
+ return _shared.defuOverrideArray.call(void 0, options, getDefaultConfig());
342
267
  }
343
268
 
344
269
  // src/constants.ts
@@ -443,7 +368,7 @@ async function getDepFiles(file) {
443
368
 
444
369
  // src/postcss.ts
445
370
  var creator = (options) => {
446
- const { config, filter, directiveParams, cwd, extensions, insertAfterAtRulesNames } = getConfig(options);
371
+ const { config, filter, directiveParams, cwd, extensions, insertAfterAtRulesNames, insertAfterComments } = getConfig(options);
447
372
  const extensionsGlob = `{${extensions.join(",")}}`;
448
373
  return {
449
374
  postcssPlugin,
@@ -452,7 +377,9 @@ var creator = (options) => {
452
377
  postcssPlugin: `${postcssPlugin}:post`,
453
378
  async Once(root, helpers) {
454
379
  if (filter(_optionalChain([root, 'access', _ => _.source, 'optionalAccess', _2 => _2.input]))) {
455
- const lastIndex = root.nodes.findLastIndex((x) => x.type === "atrule" && insertAfterAtRulesNames.includes(x.name));
380
+ const atruleLastIndex = root.nodes.findLastIndex((x) => x.type === "atrule" && insertAfterAtRulesNames.includes(x.name));
381
+ const commentLastIndex = root.nodes.findLastIndex((x) => x.type === "comment" && _shared.regExpTest.call(void 0, insertAfterComments, x.text));
382
+ const lastIndex = Math.max(atruleLastIndex, commentLastIndex);
456
383
  for (const params of directiveParams) {
457
384
  const node = root.nodes.find((x) => x.type === "atrule" && x.params === params);
458
385
  if (!node) {
@@ -491,7 +418,7 @@ var creator = (options) => {
491
418
  _tailwindcss2.default.call(void 0, tailwindcssConfig)
492
419
  ]).process(root, {
493
420
  from: root.source.input.file
494
- });
421
+ }).async();
495
422
  }
496
423
  }
497
424
  }
@@ -9,6 +9,7 @@ interface Options {
9
9
  directiveParams: ('base' | 'components' | 'utilities' | 'variants')[];
10
10
  extensions: string[];
11
11
  insertAfterAtRulesNames: string[];
12
+ insertAfterComments: (string | RegExp)[];
12
13
  }
13
14
 
14
15
  declare const creator: PluginCreator<Partial<Options>>;
package/dist/postcss.d.ts CHANGED
@@ -9,6 +9,7 @@ interface Options {
9
9
  directiveParams: ('base' | 'components' | 'utilities' | 'variants')[];
10
10
  extensions: string[];
11
11
  insertAfterAtRulesNames: string[];
12
+ insertAfterComments: (string | RegExp)[];
12
13
  }
13
14
 
14
15
  declare const creator: PluginCreator<Partial<Options>>;
package/dist/postcss.js CHANGED
@@ -27,9 +27,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  mod
28
28
  ));
29
29
 
30
- // ../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.1_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/esm_shims.js
30
+ // ../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.2_postcss@8.4.49_tsx@4.19.2_typescript@5.7.3_yaml@2.7.0/node_modules/tsup/assets/esm_shims.js
31
31
  var init_esm_shims = __esm({
32
- "../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.1_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/esm_shims.js"() {
32
+ "../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.2_postcss@8.4.49_tsx@4.19.2_typescript@5.7.3_yaml@2.7.0/node_modules/tsup/assets/esm_shims.js"() {
33
33
  "use strict";
34
34
  }
35
35
  });
@@ -68,7 +68,7 @@ var require_is_plain_object = __commonJS({
68
68
  function isObjectObject(o) {
69
69
  return isObject(o) === true && Object.prototype.toString.call(o) === "[object Object]";
70
70
  }
71
- module.exports = function isPlainObject2(o) {
71
+ module.exports = function isPlainObject(o) {
72
72
  var ctor, prot;
73
73
  if (isObjectObject(o) === false) return false;
74
74
  ctor = o.constructor;
@@ -90,7 +90,7 @@ var require_set_value = __commonJS({
90
90
  init_esm_shims();
91
91
  var { deleteProperty } = Reflect;
92
92
  var isPrimitive = require_is_primitive();
93
- var isPlainObject2 = require_is_plain_object();
93
+ var isPlainObject = require_is_plain_object();
94
94
  var isObject = (value) => {
95
95
  return typeof value === "object" && value !== null || typeof value === "function";
96
96
  };
@@ -171,7 +171,7 @@ var require_set_value = __commonJS({
171
171
  deleteProperty(obj, prop);
172
172
  } else if (options && options.merge) {
173
173
  const merge = options.merge === "function" ? options.merge : Object.assign;
174
- if (merge && isPlainObject2(obj[prop]) && isPlainObject2(value)) {
174
+ if (merge && isPlainObject(obj[prop]) && isPlainObject(value)) {
175
175
  obj[prop] = merge(obj[prop], value);
176
176
  } else {
177
177
  obj[prop] = value;
@@ -228,77 +228,7 @@ import process from "node:process";
228
228
  init_esm_shims();
229
229
  import crypto from "node:crypto";
230
230
  import path from "node:path";
231
-
232
- // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
233
- init_esm_shims();
234
- function isPlainObject(value) {
235
- if (value === null || typeof value !== "object") {
236
- return false;
237
- }
238
- const prototype = Object.getPrototypeOf(value);
239
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
240
- return false;
241
- }
242
- if (Symbol.iterator in value) {
243
- return false;
244
- }
245
- if (Symbol.toStringTag in value) {
246
- return Object.prototype.toString.call(value) === "[object Module]";
247
- }
248
- return true;
249
- }
250
- function _defu(baseObject, defaults, namespace = ".", merger) {
251
- if (!isPlainObject(defaults)) {
252
- return _defu(baseObject, {}, namespace, merger);
253
- }
254
- const object = Object.assign({}, defaults);
255
- for (const key in baseObject) {
256
- if (key === "__proto__" || key === "constructor") {
257
- continue;
258
- }
259
- const value = baseObject[key];
260
- if (value === null || value === void 0) {
261
- continue;
262
- }
263
- if (merger && merger(object, key, value, namespace)) {
264
- continue;
265
- }
266
- if (Array.isArray(value) && Array.isArray(object[key])) {
267
- object[key] = [...value, ...object[key]];
268
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
269
- object[key] = _defu(
270
- value,
271
- object[key],
272
- (namespace ? `${namespace}.` : "") + key.toString(),
273
- merger
274
- );
275
- } else {
276
- object[key] = value;
277
- }
278
- }
279
- return object;
280
- }
281
- function createDefu(merger) {
282
- return (...arguments_) => (
283
- // eslint-disable-next-line unicorn/no-array-reduce
284
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
285
- );
286
- }
287
- var defu = createDefu();
288
- var defuFn = createDefu((object, key, currentValue) => {
289
- if (object[key] !== void 0 && typeof currentValue === "function") {
290
- object[key] = currentValue(object[key]);
291
- return true;
292
- }
293
- });
294
- var defuArrayFn = createDefu((object, key, currentValue) => {
295
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
296
- object[key] = currentValue(object[key]);
297
- return true;
298
- }
299
- });
300
-
301
- // src/utils.ts
231
+ import { defu, defuOverrideArray, isRegexp, regExpTest } from "@weapp-tailwindcss/shared";
302
232
  function removeFileExtension(filePath) {
303
233
  if (!filePath) {
304
234
  return "";
@@ -312,12 +242,6 @@ function removeFileExtension(filePath) {
312
242
  const dir = path.dirname(filePath);
313
243
  return path.join(dir, baseName);
314
244
  }
315
- var defuOverrideArray = createDefu((obj, key, value) => {
316
- if (Array.isArray(obj[key]) && Array.isArray(value)) {
317
- obj[key] = value;
318
- return true;
319
- }
320
- });
321
245
  function md5(input) {
322
246
  const hash = crypto.createHash("md5");
323
247
  hash.update(input);
@@ -334,7 +258,8 @@ function getDefaultConfig() {
334
258
  cwd: process.cwd(),
335
259
  extensions: ["wxml", "js", "ts"],
336
260
  // @import and @use (scss)
337
- insertAfterAtRulesNames: ["import", "use"]
261
+ insertAfterAtRulesNames: ["import", "use"],
262
+ insertAfterComments: ["@import"]
338
263
  };
339
264
  }
340
265
  function getConfig(options) {
@@ -443,7 +368,7 @@ async function getDepFiles(file) {
443
368
 
444
369
  // src/postcss.ts
445
370
  var creator = (options) => {
446
- const { config, filter, directiveParams, cwd, extensions, insertAfterAtRulesNames } = getConfig(options);
371
+ const { config, filter, directiveParams, cwd, extensions, insertAfterAtRulesNames, insertAfterComments } = getConfig(options);
447
372
  const extensionsGlob = `{${extensions.join(",")}}`;
448
373
  return {
449
374
  postcssPlugin,
@@ -452,7 +377,9 @@ var creator = (options) => {
452
377
  postcssPlugin: `${postcssPlugin}:post`,
453
378
  async Once(root, helpers) {
454
379
  if (filter(root.source?.input)) {
455
- const lastIndex = root.nodes.findLastIndex((x) => x.type === "atrule" && insertAfterAtRulesNames.includes(x.name));
380
+ const atruleLastIndex = root.nodes.findLastIndex((x) => x.type === "atrule" && insertAfterAtRulesNames.includes(x.name));
381
+ const commentLastIndex = root.nodes.findLastIndex((x) => x.type === "comment" && regExpTest(insertAfterComments, x.text));
382
+ const lastIndex = Math.max(atruleLastIndex, commentLastIndex);
456
383
  for (const params of directiveParams) {
457
384
  const node = root.nodes.find((x) => x.type === "atrule" && x.params === params);
458
385
  if (!node) {
@@ -491,7 +418,7 @@ var creator = (options) => {
491
418
  tailwindcss(tailwindcssConfig)
492
419
  ]).process(root, {
493
420
  from: root.source.input.file
494
- });
421
+ }).async();
495
422
  }
496
423
  }
497
424
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tailwindcss-injector",
3
3
  "type": "module",
4
- "version": "0.1.4",
4
+ "version": "0.1.6-alpha.0",
5
5
  "description": "tsup(esbuild) build package template",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -32,10 +32,11 @@
32
32
  ],
33
33
  "dependencies": {
34
34
  "fs-extra": "^11.2.0",
35
- "htmlparser2": "^9.1.0",
36
- "magic-string": "^0.30.15",
35
+ "htmlparser2": "^10.0.0",
36
+ "magic-string": "^0.30.17",
37
37
  "postcss": "^8.4.49",
38
- "tailwindcss": "^3.4.16",
38
+ "tailwindcss": "^3.4.17",
39
+ "@weapp-tailwindcss/shared": "0.0.1-alpha.0",
39
40
  "tailwindcss-config": "0.0.0"
40
41
  },
41
42
  "scripts": {