weapp-tailwindcss 4.8.0 → 4.8.2
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/{chunk-KMCQEHJM.js → chunk-467NHGLF.js} +52 -8
- package/dist/{chunk-3RXY3OXF.mjs → chunk-5BZA7BAP.mjs} +1 -1
- package/dist/{chunk-5RHSVID3.mjs → chunk-6OTI5FPH.mjs} +25 -15
- package/dist/{chunk-X7QD7NUX.js → chunk-ACSKKIYM.js} +76 -28
- package/dist/{chunk-UKAU6OXS.mjs → chunk-GVPBDBX4.mjs} +9 -7
- package/dist/{chunk-A5VN7CO5.js → chunk-H34KPZQW.js} +47 -4
- package/dist/{chunk-YW5YW5D4.mjs → chunk-HCXLLOIU.mjs} +47 -3
- package/dist/{chunk-GI2M6KFD.js → chunk-IXZDFEPL.js} +26 -22
- package/dist/{chunk-R3CUQGRM.js → chunk-JPLWILCP.js} +12 -10
- package/dist/{chunk-TTIRN5LZ.mjs → chunk-JW7P34IH.mjs} +50 -7
- package/dist/{chunk-QNGB574L.js → chunk-K7AD7FLJ.js} +6 -6
- package/dist/{chunk-QK5QBH6X.mjs → chunk-OJRQGFJR.mjs} +12 -8
- package/dist/{chunk-BTPDRSHI.mjs → chunk-QGH4JZRW.mjs} +1 -1
- package/dist/{chunk-XGRBCPBI.js → chunk-UJIUFWXE.js} +1 -1
- package/dist/{chunk-TTCMOWCO.mjs → chunk-W4ERVC6L.mjs} +74 -26
- package/dist/{chunk-FQ5MKRKX.js → chunk-Z6IWSDU3.js} +42 -32
- package/dist/cli.js +14 -14
- package/dist/cli.mjs +5 -5
- package/dist/core.js +9 -9
- package/dist/core.mjs +3 -3
- package/dist/css-macro/postcss.js +1 -1
- package/dist/css-macro/postcss.mjs +1 -1
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/gulp.js +5 -5
- package/dist/gulp.mjs +4 -4
- package/dist/index.js +9 -9
- package/dist/index.mjs +8 -8
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.js +3 -3
- package/dist/presets.mjs +2 -2
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.js +6 -6
- package/dist/vite.mjs +5 -5
- package/dist/webpack.d.mts +1 -0
- package/dist/webpack.d.ts +1 -0
- package/dist/webpack.js +7 -7
- package/dist/webpack.mjs +6 -6
- package/dist/webpack4.d.mts +1 -0
- package/dist/webpack4.d.ts +1 -0
- package/dist/webpack4.js +28 -24
- package/dist/webpack4.mjs +13 -9
- package/package.json +1 -1
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
var _chunkUW3WHSZ5js = require('./chunk-UW3WHSZ5.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkUJIUFWXEjs = require('./chunk-UJIUFWXE.js');
|
|
7
7
|
|
|
8
8
|
// src/context/tailwindcss.ts
|
|
9
|
+
var _fs = require('fs');
|
|
9
10
|
var _module = require('module');
|
|
10
11
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
11
12
|
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
@@ -16,7 +17,7 @@ var _logger = require('@weapp-tailwindcss/logger');
|
|
|
16
17
|
var _localpkg = require('local-pkg');
|
|
17
18
|
|
|
18
19
|
// src/tailwindcss/patcher.ts
|
|
19
|
-
|
|
20
|
+
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
|
|
@@ -46,7 +47,7 @@ function resolveModuleFromPaths(specifier, paths) {
|
|
|
46
47
|
return void 0;
|
|
47
48
|
}
|
|
48
49
|
try {
|
|
49
|
-
const req = _module.createRequire.call(void 0,
|
|
50
|
+
const req = _module.createRequire.call(void 0, _chunkUJIUFWXEjs.importMetaUrl);
|
|
50
51
|
return req.resolve(specifier, { paths });
|
|
51
52
|
} catch (e) {
|
|
52
53
|
return void 0;
|
|
@@ -163,11 +164,11 @@ function createDefaultResolvePaths(basedir) {
|
|
|
163
164
|
const cwd = _process2.default.cwd();
|
|
164
165
|
appendNodeModules(paths, cwd);
|
|
165
166
|
try {
|
|
166
|
-
const modulePath = _url.fileURLToPath.call(void 0,
|
|
167
|
+
const modulePath = _url.fileURLToPath.call(void 0, _chunkUJIUFWXEjs.importMetaUrl);
|
|
167
168
|
const candidate = _fs.existsSync.call(void 0, modulePath) && !_path2.default.extname(modulePath) ? modulePath : _path2.default.dirname(modulePath);
|
|
168
169
|
paths.add(candidate);
|
|
169
170
|
} catch (e2) {
|
|
170
|
-
paths.add(
|
|
171
|
+
paths.add(_chunkUJIUFWXEjs.importMetaUrl);
|
|
171
172
|
}
|
|
172
173
|
if (paths.size === 0) {
|
|
173
174
|
fallbackCandidates = fallbackCandidates.filter(Boolean);
|
|
@@ -463,7 +464,7 @@ function detectCallerBasedir() {
|
|
|
463
464
|
}
|
|
464
465
|
return void 0;
|
|
465
466
|
}
|
|
466
|
-
function resolveTailwindcssBasedir(basedir) {
|
|
467
|
+
function resolveTailwindcssBasedir(basedir, fallback) {
|
|
467
468
|
const envBasedirResult = pickEnvBasedir();
|
|
468
469
|
const envBasedir = _optionalChain([envBasedirResult, 'optionalAccess', _25 => _25.value]);
|
|
469
470
|
const envBasedirKey = _optionalChain([envBasedirResult, 'optionalAccess', _26 => _26.key]);
|
|
@@ -471,7 +472,7 @@ function resolveTailwindcssBasedir(basedir) {
|
|
|
471
472
|
const packageEnvBasedir = pickPackageEnvBasedir();
|
|
472
473
|
const shouldDetectCaller = !envBasedir || envBasedirIsGeneric;
|
|
473
474
|
const callerBasedir = shouldDetectCaller ? detectCallerBasedir() : void 0;
|
|
474
|
-
const anchor = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(envBasedir, () => ( packageEnvBasedir)), () => ( callerBasedir)), () => ( _process2.default.cwd()));
|
|
475
|
+
const anchor = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(envBasedir, () => ( packageEnvBasedir)), () => ( fallback)), () => ( callerBasedir)), () => ( _process2.default.cwd()));
|
|
475
476
|
if (_process2.default.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
476
477
|
_logger.logger.debug("resolveTailwindcssBasedir anchor %O", {
|
|
477
478
|
basedir,
|
|
@@ -479,6 +480,7 @@ function resolveTailwindcssBasedir(basedir) {
|
|
|
479
480
|
envBasedirKey,
|
|
480
481
|
envBasedirIsGeneric,
|
|
481
482
|
packageEnvBasedir,
|
|
483
|
+
fallback,
|
|
482
484
|
callerBasedir,
|
|
483
485
|
npm_package_json: _process2.default.env.npm_package_json,
|
|
484
486
|
cwd: _process2.default.cwd(),
|
|
@@ -494,6 +496,10 @@ function resolveTailwindcssBasedir(basedir) {
|
|
|
494
496
|
if (envBasedir && !envBasedirIsGeneric) {
|
|
495
497
|
return _path2.default.normalize(envBasedir);
|
|
496
498
|
}
|
|
499
|
+
if (fallback && fallback.trim().length > 0) {
|
|
500
|
+
const resolvedFallback = _path2.default.isAbsolute(fallback) ? fallback : _path2.default.resolve(anchor, fallback);
|
|
501
|
+
return _path2.default.normalize(resolvedFallback);
|
|
502
|
+
}
|
|
497
503
|
if (packageEnvBasedir) {
|
|
498
504
|
return _path2.default.normalize(packageEnvBasedir);
|
|
499
505
|
}
|
|
@@ -524,6 +530,43 @@ function resolveTailwindcssBasedir(basedir) {
|
|
|
524
530
|
}
|
|
525
531
|
return _path2.default.normalize(_process2.default.cwd());
|
|
526
532
|
}
|
|
533
|
+
function findNearestPackageRootFromDir(startDir) {
|
|
534
|
+
if (!startDir) {
|
|
535
|
+
return void 0;
|
|
536
|
+
}
|
|
537
|
+
let current = _path2.default.resolve(startDir);
|
|
538
|
+
while (true) {
|
|
539
|
+
const pkgPath = _path2.default.join(current, "package.json");
|
|
540
|
+
if (_fs.existsSync.call(void 0, pkgPath)) {
|
|
541
|
+
return current;
|
|
542
|
+
}
|
|
543
|
+
const parent = _path2.default.dirname(current);
|
|
544
|
+
if (parent === current) {
|
|
545
|
+
return void 0;
|
|
546
|
+
}
|
|
547
|
+
current = parent;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
function guessBasedirFromEntries(entries) {
|
|
551
|
+
if (!entries) {
|
|
552
|
+
return void 0;
|
|
553
|
+
}
|
|
554
|
+
for (const entry of entries) {
|
|
555
|
+
if (typeof entry !== "string") {
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
const trimmed = entry.trim();
|
|
559
|
+
if (!trimmed || !_path2.default.isAbsolute(trimmed)) {
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
const entryDir = _path2.default.dirname(trimmed);
|
|
563
|
+
const resolved = _nullishCoalesce(findNearestPackageRootFromDir(entryDir), () => ( entryDir));
|
|
564
|
+
if (resolved) {
|
|
565
|
+
return resolved;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return void 0;
|
|
569
|
+
}
|
|
527
570
|
function normalizeCssEntries(entries, anchor) {
|
|
528
571
|
if (!entries || entries.length === 0) {
|
|
529
572
|
return void 0;
|
|
@@ -761,7 +804,8 @@ function createTailwindcssPatcherFromContext(ctx) {
|
|
|
761
804
|
cssEntries: rawCssEntries,
|
|
762
805
|
appType
|
|
763
806
|
} = ctx;
|
|
764
|
-
const
|
|
807
|
+
const absoluteCssEntryBasedir = guessBasedirFromEntries(rawCssEntries);
|
|
808
|
+
const resolvedTailwindcssBasedir = resolveTailwindcssBasedir(tailwindcssBasedir, absoluteCssEntryBasedir);
|
|
765
809
|
ctx.tailwindcssBasedir = resolvedTailwindcssBasedir;
|
|
766
810
|
_logger.logger.debug("tailwindcss basedir resolved: %s", resolvedTailwindcssBasedir);
|
|
767
811
|
const normalizedCssEntries = normalizeCssEntries(rawCssEntries, resolvedTailwindcssBasedir);
|
|
@@ -2,8 +2,10 @@ import {
|
|
|
2
2
|
pushConcurrentTaskFactories,
|
|
3
3
|
resolveOutputSpecifier,
|
|
4
4
|
resolvePackageDir,
|
|
5
|
+
resolveTailwindcssImport,
|
|
6
|
+
rewriteTailwindcssImportsInCode,
|
|
5
7
|
toAbsoluteOutputPath
|
|
6
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-JW7P34IH.mjs";
|
|
7
9
|
import {
|
|
8
10
|
processCachedTask
|
|
9
11
|
} from "./chunk-RRHPTTCP.mjs";
|
|
@@ -18,7 +20,7 @@ import {
|
|
|
18
20
|
replaceWxml,
|
|
19
21
|
toCustomAttributesEntities,
|
|
20
22
|
vitePluginName
|
|
21
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-W4ERVC6L.mjs";
|
|
22
24
|
import {
|
|
23
25
|
getGroupedEntries
|
|
24
26
|
} from "./chunk-ZNKIYZRQ.mjs";
|
|
@@ -217,18 +219,11 @@ async function formatPostcssSourceMap(rawMap, file) {
|
|
|
217
219
|
var debug = createDebug();
|
|
218
220
|
var weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
219
221
|
var weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return null;
|
|
222
|
+
function joinPosixPath(base, subpath) {
|
|
223
|
+
if (base.endsWith("/")) {
|
|
224
|
+
return `${base}${subpath}`;
|
|
224
225
|
}
|
|
225
|
-
|
|
226
|
-
return `${weappTailwindcssDirPosix}/index.css`;
|
|
227
|
-
}
|
|
228
|
-
if (id.startsWith("tailwindcss/")) {
|
|
229
|
-
return `${weappTailwindcssDirPosix}/${id.slice("tailwindcss/".length)}`;
|
|
230
|
-
}
|
|
231
|
-
return null;
|
|
226
|
+
return `${base}/${subpath}`;
|
|
232
227
|
}
|
|
233
228
|
function isCssLikeImporter(importer) {
|
|
234
229
|
if (!importer) {
|
|
@@ -303,6 +298,7 @@ function applyLinkedResults(linked, entries, onLinkedUpdate, onApplied) {
|
|
|
303
298
|
}
|
|
304
299
|
}
|
|
305
300
|
function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
301
|
+
const rewriteCssImportsSpecified = Object.prototype.hasOwnProperty.call(options, "rewriteCssImports");
|
|
306
302
|
const opts = getCompilerContext(options);
|
|
307
303
|
const {
|
|
308
304
|
disabled,
|
|
@@ -365,12 +361,13 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
365
361
|
}
|
|
366
362
|
}
|
|
367
363
|
onLoad();
|
|
368
|
-
const
|
|
364
|
+
const shouldRewriteCssImports = opts.rewriteCssImports !== false && (rewriteCssImportsSpecified || (runtimeState.twPatcher.majorVersion ?? 0) >= 4);
|
|
365
|
+
const rewritePlugins = !shouldRewriteCssImports ? [] : [
|
|
369
366
|
{
|
|
370
367
|
name: `${vitePluginName}:rewrite-css-imports`,
|
|
371
368
|
enforce: "pre",
|
|
372
369
|
resolveId(id, importer) {
|
|
373
|
-
const replacement =
|
|
370
|
+
const replacement = resolveTailwindcssImport(id, weappTailwindcssDirPosix, { join: joinPosixPath });
|
|
374
371
|
if (!replacement) {
|
|
375
372
|
return null;
|
|
376
373
|
}
|
|
@@ -378,6 +375,19 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
378
375
|
return null;
|
|
379
376
|
}
|
|
380
377
|
return replacement;
|
|
378
|
+
},
|
|
379
|
+
transform(code, id) {
|
|
380
|
+
if (!isCSSRequest(id)) {
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
const rewritten = rewriteTailwindcssImportsInCode(code, weappTailwindcssDirPosix, { join: joinPosixPath });
|
|
384
|
+
if (!rewritten) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
code: rewritten,
|
|
389
|
+
map: null
|
|
390
|
+
};
|
|
381
391
|
}
|
|
382
392
|
}
|
|
383
393
|
];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk467NHGLFjs = require('./chunk-467NHGLF.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkZSTF2AENjs = require('./chunk-ZSTF2AEN.js');
|
|
@@ -176,8 +176,10 @@ var _promises = require('fs/promises');
|
|
|
176
176
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
177
177
|
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
178
178
|
var _logger = require('@weapp-tailwindcss/logger');
|
|
179
|
-
var PATCH_INFO_DIRNAME = ".tw-patch";
|
|
180
179
|
var PATCH_INFO_FILENAME = "tailwindcss-target.json";
|
|
180
|
+
var PATCH_INFO_CACHE_RELATIVE_PATH = _path2.default.join("node_modules", ".cache", "weapp-tailwindcss", PATCH_INFO_FILENAME);
|
|
181
|
+
var PATCH_INFO_LEGACY_RELATIVE_PATH = _path2.default.join(".tw-patch", PATCH_INFO_FILENAME);
|
|
182
|
+
var loggedInvalidPatchRecords = /* @__PURE__ */ new Set();
|
|
181
183
|
function formatRelativeToBase(targetPath, baseDir) {
|
|
182
184
|
if (!baseDir) {
|
|
183
185
|
return _path2.default.normalize(targetPath);
|
|
@@ -192,7 +194,13 @@ function formatRelativeToBase(targetPath, baseDir) {
|
|
|
192
194
|
return _path2.default.join(".", relative);
|
|
193
195
|
}
|
|
194
196
|
function getRecordFilePath(baseDir) {
|
|
195
|
-
return _path2.default.join(baseDir,
|
|
197
|
+
return _path2.default.join(baseDir, PATCH_INFO_CACHE_RELATIVE_PATH);
|
|
198
|
+
}
|
|
199
|
+
function getRecordFileCandidates(baseDir) {
|
|
200
|
+
return [
|
|
201
|
+
_path2.default.join(baseDir, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
202
|
+
_path2.default.join(baseDir, PATCH_INFO_LEGACY_RELATIVE_PATH)
|
|
203
|
+
];
|
|
196
204
|
}
|
|
197
205
|
function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
198
206
|
const packageInfo = _optionalChain([patcher, 'optionalAccess', _6 => _6.packageInfo]);
|
|
@@ -209,41 +217,61 @@ function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
|
209
217
|
const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
|
|
210
218
|
_logger.logger.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
|
|
211
219
|
}
|
|
220
|
+
function warnInvalidPatchTargetRecord(baseDir, recordPath, reason) {
|
|
221
|
+
const normalizedPath = _path2.default.normalize(recordPath);
|
|
222
|
+
if (loggedInvalidPatchRecords.has(normalizedPath)) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
loggedInvalidPatchRecords.add(normalizedPath);
|
|
226
|
+
const fileDisplay = formatRelativeToBase(normalizedPath, baseDir);
|
|
227
|
+
const baseDisplay = formatRelativeToBase(_path2.default.normalize(baseDir), _process2.default.cwd());
|
|
228
|
+
const reasonMessage = reason ? `\uFF1A${reason}` : "";
|
|
229
|
+
_logger.logger.warn(
|
|
230
|
+
`\u68C0\u6D4B\u5230\u635F\u574F\u7684 Tailwind CSS \u76EE\u6807\u8BB0\u5F55 ${fileDisplay}${reasonMessage}\u3002\u8BF7\u5728 ${baseDisplay} \u91CD\u65B0\u6267\u884C "weapp-tw patch --record-target" \u6216\u5220\u9664\u8BE5\u6587\u4EF6\u540E\u518D\u8FD0\u884C\u3002`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
212
233
|
function readPatchTargetRecord(baseDir) {
|
|
213
234
|
if (!baseDir) {
|
|
214
235
|
return void 0;
|
|
215
236
|
}
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
237
|
+
const normalizedBase = _path2.default.normalize(baseDir);
|
|
238
|
+
for (const recordPath of getRecordFileCandidates(normalizedBase)) {
|
|
239
|
+
if (!_fs.existsSync.call(void 0, recordPath)) {
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
const content = _fs.readFileSync.call(void 0, recordPath, "utf8");
|
|
244
|
+
const parsed = JSON.parse(content);
|
|
245
|
+
if (!parsed || typeof parsed.tailwindPackagePath !== "string") {
|
|
246
|
+
warnInvalidPatchTargetRecord(normalizedBase, recordPath, "\u7F3A\u5C11 tailwindPackagePath \u5B57\u6BB5");
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
baseDir: normalizedBase,
|
|
251
|
+
path: recordPath,
|
|
252
|
+
record: parsed
|
|
253
|
+
};
|
|
254
|
+
} catch (error) {
|
|
255
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
256
|
+
warnInvalidPatchTargetRecord(normalizedBase, recordPath, reason);
|
|
257
|
+
continue;
|
|
225
258
|
}
|
|
226
|
-
return {
|
|
227
|
-
path: recordPath,
|
|
228
|
-
record: parsed
|
|
229
|
-
};
|
|
230
|
-
} catch (error) {
|
|
231
|
-
_logger.logger.debug("failed to read patch target record from %s: %O", recordPath, error);
|
|
232
|
-
return void 0;
|
|
233
259
|
}
|
|
260
|
+
return void 0;
|
|
234
261
|
}
|
|
235
262
|
async function saveCliPatchTargetRecord(baseDir, patcher) {
|
|
236
263
|
if (!baseDir || !_optionalChain([patcher, 'optionalAccess', _8 => _8.packageInfo, 'optionalAccess', _9 => _9.rootPath])) {
|
|
237
264
|
return void 0;
|
|
238
265
|
}
|
|
266
|
+
const normalizedBase = _path2.default.normalize(baseDir);
|
|
239
267
|
const record = {
|
|
240
268
|
tailwindPackagePath: _path2.default.normalize(patcher.packageInfo.rootPath),
|
|
241
269
|
packageVersion: patcher.packageInfo.version,
|
|
242
270
|
recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
243
271
|
source: "cli",
|
|
244
|
-
tailwindcssBasedir:
|
|
272
|
+
tailwindcssBasedir: normalizedBase
|
|
245
273
|
};
|
|
246
|
-
const recordPath = getRecordFilePath(
|
|
274
|
+
const recordPath = getRecordFilePath(normalizedBase);
|
|
247
275
|
try {
|
|
248
276
|
await _promises.mkdir.call(void 0, _path2.default.dirname(recordPath), { recursive: true });
|
|
249
277
|
await _promises.writeFile.call(void 0, recordPath, `${JSON.stringify(record, null, 2)}
|
|
@@ -254,11 +282,29 @@ async function saveCliPatchTargetRecord(baseDir, patcher) {
|
|
|
254
282
|
return void 0;
|
|
255
283
|
}
|
|
256
284
|
}
|
|
285
|
+
function findPatchTargetRecord(baseDir) {
|
|
286
|
+
const visited = /* @__PURE__ */ new Set();
|
|
287
|
+
const fallback = _nullishCoalesce(baseDir, () => ( _process2.default.cwd()));
|
|
288
|
+
let current = _path2.default.resolve(fallback);
|
|
289
|
+
while (!visited.has(current)) {
|
|
290
|
+
const record = readPatchTargetRecord(current);
|
|
291
|
+
if (record) {
|
|
292
|
+
return record;
|
|
293
|
+
}
|
|
294
|
+
const parent = _path2.default.dirname(current);
|
|
295
|
+
if (parent === current) {
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
visited.add(current);
|
|
299
|
+
current = parent;
|
|
300
|
+
}
|
|
301
|
+
return void 0;
|
|
302
|
+
}
|
|
257
303
|
function warnIfCliPatchTargetMismatch(baseDir, patcher) {
|
|
258
304
|
if (!baseDir || !_optionalChain([patcher, 'optionalAccess', _10 => _10.packageInfo, 'optionalAccess', _11 => _11.rootPath])) {
|
|
259
305
|
return;
|
|
260
306
|
}
|
|
261
|
-
const recorded =
|
|
307
|
+
const recorded = findPatchTargetRecord(baseDir);
|
|
262
308
|
if (!recorded) {
|
|
263
309
|
return;
|
|
264
310
|
}
|
|
@@ -267,12 +313,14 @@ function warnIfCliPatchTargetMismatch(baseDir, patcher) {
|
|
|
267
313
|
if (normalizedRecorded === normalizedRuntime) {
|
|
268
314
|
return;
|
|
269
315
|
}
|
|
270
|
-
const
|
|
316
|
+
const runtimeBaseDisplay = formatRelativeToBase(_path2.default.normalize(baseDir), _process2.default.cwd());
|
|
317
|
+
const recordBaseDir = _nullishCoalesce(recorded.record.tailwindcssBasedir, () => ( recorded.baseDir));
|
|
318
|
+
const recordBaseDisplay = formatRelativeToBase(recordBaseDir, baseDir);
|
|
319
|
+
const recordedDisplay = formatRelativeToBase(normalizedRecorded, recordBaseDir);
|
|
271
320
|
const runtimeDisplay = formatRelativeToBase(normalizedRuntime, baseDir);
|
|
272
|
-
const
|
|
273
|
-
const recordFileDisplay = formatRelativeToBase(recorded.path, baseDir);
|
|
321
|
+
const recordFileDisplay = formatRelativeToBase(recorded.path, recorded.baseDir);
|
|
274
322
|
_logger.logger.warn(
|
|
275
|
-
`\u68C0\u6D4B\u5230 ${
|
|
323
|
+
`\u68C0\u6D4B\u5230 ${runtimeBaseDisplay} \u7684 Tailwind CSS \u76EE\u6807\u4E0D\u4E00\u81F4\uFF1ACLI \u5728 ${recordBaseDisplay} \u6253\u8865\u4E01\u7684\u662F ${recordedDisplay}\uFF0C\u8FD0\u884C\u65F6\u8BFB\u53D6\u7684\u662F ${runtimeDisplay}\u3002\u8BF7\u5728\u5BF9\u5E94\u5B50\u5305\u6267\u884C "weapp-tw patch --cwd ${baseDir}" \u6216\u4F7F\u7528 pnpm --filter \u9488\u5BF9\u8BE5\u5305\u6267\u884C\uFF0C\u8BB0\u5F55\u6587\u4EF6\uFF1A${recordFileDisplay}\u3002`
|
|
276
324
|
);
|
|
277
325
|
}
|
|
278
326
|
|
|
@@ -2476,7 +2524,7 @@ function createInternalCompilerContext(opts) {
|
|
|
2476
2524
|
);
|
|
2477
2525
|
ctx.escapeMap = ctx.customReplaceDictionary;
|
|
2478
2526
|
applyLoggerLevel(ctx.logLevel);
|
|
2479
|
-
const twPatcher =
|
|
2527
|
+
const twPatcher = _chunk467NHGLFjs.createTailwindcssPatcherFromContext.call(void 0, ctx);
|
|
2480
2528
|
logTailwindcssTarget("runtime", twPatcher, ctx.tailwindcssBasedir);
|
|
2481
2529
|
if (_optionalChain([twPatcher, 'access', _84 => _84.packageInfo, 'optionalAccess', _85 => _85.version])) {
|
|
2482
2530
|
_logger.logger.success(`\u5F53\u524D\u4F7F\u7528 ${_logger.pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${_logger.pc.underline(_logger.pc.bold(_logger.pc.green(twPatcher.packageInfo.version)))}`);
|
|
@@ -2506,7 +2554,7 @@ function createInternalCompilerContext(opts) {
|
|
|
2506
2554
|
await clearTailwindcssPatcherCache(previousPatcher);
|
|
2507
2555
|
}
|
|
2508
2556
|
invalidateRuntimeClassSet(previousPatcher);
|
|
2509
|
-
const nextPatcher =
|
|
2557
|
+
const nextPatcher = _chunk467NHGLFjs.createTailwindcssPatcherFromContext.call(void 0, ctx);
|
|
2510
2558
|
Object.assign(previousPatcher, nextPatcher);
|
|
2511
2559
|
ctx.twPatcher = previousPatcher;
|
|
2512
2560
|
return previousPatcher;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveTailwindcssImport
|
|
3
|
+
} from "./chunk-JW7P34IH.mjs";
|
|
1
4
|
import {
|
|
2
5
|
pluginName
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-W4ERVC6L.mjs";
|
|
4
7
|
|
|
5
8
|
// src/bundlers/webpack/shared/css-imports.ts
|
|
6
|
-
import path from "path";
|
|
7
9
|
var CSS_EXT_RE = /\.(?:css|scss|sass|less|styl|pcss)$/i;
|
|
8
10
|
function stripResourceQuery(file) {
|
|
9
11
|
let idx = file.indexOf("?");
|
|
@@ -16,7 +18,7 @@ function rewriteTailwindcssRequestForCss(data, pkgDir) {
|
|
|
16
18
|
if (!data) {
|
|
17
19
|
return;
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
const request = data.request;
|
|
20
22
|
if (!request) {
|
|
21
23
|
return;
|
|
22
24
|
}
|
|
@@ -31,11 +33,11 @@ function rewriteTailwindcssRequestForCss(data, pkgDir) {
|
|
|
31
33
|
if (!CSS_EXT_RE.test(normalizedIssuer)) {
|
|
32
34
|
return;
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
const resolved = resolveTailwindcssImport(request, pkgDir);
|
|
37
|
+
if (!resolved) {
|
|
38
|
+
return;
|
|
36
39
|
}
|
|
37
|
-
|
|
38
|
-
data.request = path.join(pkgDir, subpath);
|
|
40
|
+
data.request = resolved;
|
|
39
41
|
}
|
|
40
42
|
function applyTailwindcssCssImportRewrite(compiler, options) {
|
|
41
43
|
if (!options.enabled) {
|
|
@@ -1,16 +1,57 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkUJIUFWXEjs = require('./chunk-UJIUFWXE.js');
|
|
4
4
|
|
|
5
5
|
// src/utils/resolve-package.ts
|
|
6
6
|
var _module = require('module');
|
|
7
7
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
8
|
-
var require2 = _module.createRequire.call(void 0,
|
|
8
|
+
var require2 = _module.createRequire.call(void 0, _chunkUJIUFWXEjs.importMetaUrl);
|
|
9
9
|
function resolvePackageDir(name) {
|
|
10
10
|
const pkgPath = require2.resolve(`${name}/package.json`);
|
|
11
11
|
return _path2.default.dirname(pkgPath);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// src/bundlers/shared/css-imports.ts
|
|
15
|
+
|
|
16
|
+
var tailwindcssImportRE = /^tailwindcss(?:\/.*)?$/;
|
|
17
|
+
var tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])(tailwindcss(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
|
|
18
|
+
function normalizeTailwindcssSpecifier(specifier) {
|
|
19
|
+
if (specifier === "tailwindcss$") {
|
|
20
|
+
return "tailwindcss";
|
|
21
|
+
}
|
|
22
|
+
return specifier;
|
|
23
|
+
}
|
|
24
|
+
function getTailwindcssSubpath(specifier) {
|
|
25
|
+
if (specifier === "tailwindcss") {
|
|
26
|
+
return "index.css";
|
|
27
|
+
}
|
|
28
|
+
return specifier.slice("tailwindcss/".length);
|
|
29
|
+
}
|
|
30
|
+
function resolveTailwindcssImport(specifier, pkgDir, options) {
|
|
31
|
+
const normalized = normalizeTailwindcssSpecifier(specifier);
|
|
32
|
+
if (!tailwindcssImportRE.test(normalized)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const join = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.join]), () => ( _path2.default.join));
|
|
36
|
+
const subpath = getTailwindcssSubpath(normalized);
|
|
37
|
+
return join(pkgDir, subpath);
|
|
38
|
+
}
|
|
39
|
+
function rewriteTailwindcssImportsInCode(code, pkgDir, options) {
|
|
40
|
+
let hasReplacements = false;
|
|
41
|
+
const rewritten = code.replace(
|
|
42
|
+
tailwindcssCssImportStatementRE,
|
|
43
|
+
(full, prefix, quote, specifier, suffix) => {
|
|
44
|
+
const replacement = resolveTailwindcssImport(specifier, pkgDir, options);
|
|
45
|
+
if (!replacement) {
|
|
46
|
+
return full;
|
|
47
|
+
}
|
|
48
|
+
hasReplacements = true;
|
|
49
|
+
return `${prefix}${quote}${replacement}${suffix}`;
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
return hasReplacements ? rewritten : void 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
14
55
|
// src/bundlers/shared/module-graph.ts
|
|
15
56
|
|
|
16
57
|
var QUERY_HASH_RE = /[?#].*$/u;
|
|
@@ -111,4 +152,6 @@ function pushConcurrentTaskFactories(queue, factories, limit) {
|
|
|
111
152
|
|
|
112
153
|
|
|
113
154
|
|
|
114
|
-
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
exports.resolvePackageDir = resolvePackageDir; exports.resolveTailwindcssImport = resolveTailwindcssImport; exports.rewriteTailwindcssImportsInCode = rewriteTailwindcssImportsInCode; exports.toAbsoluteOutputPath = toAbsoluteOutputPath; exports.resolveOutputSpecifier = resolveOutputSpecifier; exports.pushConcurrentTaskFactories = pushConcurrentTaskFactories;
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-ZNKIYZRQ.mjs";
|
|
4
4
|
|
|
5
5
|
// src/context/tailwindcss.ts
|
|
6
|
+
import { existsSync as existsSync2 } from "fs";
|
|
6
7
|
import { createRequire as createRequire2 } from "module";
|
|
7
8
|
import path2 from "path";
|
|
8
9
|
import process2 from "process";
|
|
@@ -460,7 +461,7 @@ function detectCallerBasedir() {
|
|
|
460
461
|
}
|
|
461
462
|
return void 0;
|
|
462
463
|
}
|
|
463
|
-
function resolveTailwindcssBasedir(basedir) {
|
|
464
|
+
function resolveTailwindcssBasedir(basedir, fallback) {
|
|
464
465
|
const envBasedirResult = pickEnvBasedir();
|
|
465
466
|
const envBasedir = envBasedirResult?.value;
|
|
466
467
|
const envBasedirKey = envBasedirResult?.key;
|
|
@@ -468,7 +469,7 @@ function resolveTailwindcssBasedir(basedir) {
|
|
|
468
469
|
const packageEnvBasedir = pickPackageEnvBasedir();
|
|
469
470
|
const shouldDetectCaller = !envBasedir || envBasedirIsGeneric;
|
|
470
471
|
const callerBasedir = shouldDetectCaller ? detectCallerBasedir() : void 0;
|
|
471
|
-
const anchor = envBasedir ?? packageEnvBasedir ?? callerBasedir ?? process2.cwd();
|
|
472
|
+
const anchor = envBasedir ?? packageEnvBasedir ?? fallback ?? callerBasedir ?? process2.cwd();
|
|
472
473
|
if (process2.env.WEAPP_TW_DEBUG_STACK === "1") {
|
|
473
474
|
logger2.debug("resolveTailwindcssBasedir anchor %O", {
|
|
474
475
|
basedir,
|
|
@@ -476,6 +477,7 @@ function resolveTailwindcssBasedir(basedir) {
|
|
|
476
477
|
envBasedirKey,
|
|
477
478
|
envBasedirIsGeneric,
|
|
478
479
|
packageEnvBasedir,
|
|
480
|
+
fallback,
|
|
479
481
|
callerBasedir,
|
|
480
482
|
npm_package_json: process2.env.npm_package_json,
|
|
481
483
|
cwd: process2.cwd(),
|
|
@@ -491,6 +493,10 @@ function resolveTailwindcssBasedir(basedir) {
|
|
|
491
493
|
if (envBasedir && !envBasedirIsGeneric) {
|
|
492
494
|
return path2.normalize(envBasedir);
|
|
493
495
|
}
|
|
496
|
+
if (fallback && fallback.trim().length > 0) {
|
|
497
|
+
const resolvedFallback = path2.isAbsolute(fallback) ? fallback : path2.resolve(anchor, fallback);
|
|
498
|
+
return path2.normalize(resolvedFallback);
|
|
499
|
+
}
|
|
494
500
|
if (packageEnvBasedir) {
|
|
495
501
|
return path2.normalize(packageEnvBasedir);
|
|
496
502
|
}
|
|
@@ -521,6 +527,43 @@ function resolveTailwindcssBasedir(basedir) {
|
|
|
521
527
|
}
|
|
522
528
|
return path2.normalize(process2.cwd());
|
|
523
529
|
}
|
|
530
|
+
function findNearestPackageRootFromDir(startDir) {
|
|
531
|
+
if (!startDir) {
|
|
532
|
+
return void 0;
|
|
533
|
+
}
|
|
534
|
+
let current = path2.resolve(startDir);
|
|
535
|
+
while (true) {
|
|
536
|
+
const pkgPath = path2.join(current, "package.json");
|
|
537
|
+
if (existsSync2(pkgPath)) {
|
|
538
|
+
return current;
|
|
539
|
+
}
|
|
540
|
+
const parent = path2.dirname(current);
|
|
541
|
+
if (parent === current) {
|
|
542
|
+
return void 0;
|
|
543
|
+
}
|
|
544
|
+
current = parent;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
function guessBasedirFromEntries(entries) {
|
|
548
|
+
if (!entries) {
|
|
549
|
+
return void 0;
|
|
550
|
+
}
|
|
551
|
+
for (const entry of entries) {
|
|
552
|
+
if (typeof entry !== "string") {
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
const trimmed = entry.trim();
|
|
556
|
+
if (!trimmed || !path2.isAbsolute(trimmed)) {
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
const entryDir = path2.dirname(trimmed);
|
|
560
|
+
const resolved = findNearestPackageRootFromDir(entryDir) ?? entryDir;
|
|
561
|
+
if (resolved) {
|
|
562
|
+
return resolved;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return void 0;
|
|
566
|
+
}
|
|
524
567
|
function normalizeCssEntries(entries, anchor) {
|
|
525
568
|
if (!entries || entries.length === 0) {
|
|
526
569
|
return void 0;
|
|
@@ -758,7 +801,8 @@ function createTailwindcssPatcherFromContext(ctx) {
|
|
|
758
801
|
cssEntries: rawCssEntries,
|
|
759
802
|
appType
|
|
760
803
|
} = ctx;
|
|
761
|
-
const
|
|
804
|
+
const absoluteCssEntryBasedir = guessBasedirFromEntries(rawCssEntries);
|
|
805
|
+
const resolvedTailwindcssBasedir = resolveTailwindcssBasedir(tailwindcssBasedir, absoluteCssEntryBasedir);
|
|
762
806
|
ctx.tailwindcssBasedir = resolvedTailwindcssBasedir;
|
|
763
807
|
logger2.debug("tailwindcss basedir resolved: %s", resolvedTailwindcssBasedir);
|
|
764
808
|
const normalizedCssEntries = normalizeCssEntries(rawCssEntries, resolvedTailwindcssBasedir);
|