@dcloudio/uni-cli-shared 3.0.0-alpha-3040920220508001 → 3.0.0-alpha-3040820220424004

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.
@@ -147,7 +147,17 @@ function getMac() {
147
147
  if (!item.family || (item.mac && item.mac === '00:00:00:00:00:00')) {
148
148
  continue;
149
149
  }
150
- if (item.family === 'IPv4' || item.family === 'IPv6') {
150
+ if (
151
+ // Node < v18
152
+ typeof item.family === 'string' &&
153
+ (item.family === 'IPv4' || item.family === 'IPv6')) {
154
+ mac = item.mac;
155
+ break;
156
+ }
157
+ else if (
158
+ // Node >= v18
159
+ typeof item.family === 'number' &&
160
+ (item.family === 4 || item.family === 6)) {
151
161
  mac = item.mac;
152
162
  break;
153
163
  }
@@ -3,7 +3,10 @@ export declare function initDefine(stringifyBoolean?: boolean): {
3
3
  'process.env.UNI_DEBUG': string | boolean;
4
4
  'process.env.UNI_APP_ID': string;
5
5
  'process.env.UNI_APP_NAME': string;
6
+ 'process.env.UNI_APP_VERSION_NAME': string;
7
+ 'process.env.UNI_APP_VERSION_CODE': string;
6
8
  'process.env.UNI_PLATFORM': string;
9
+ 'process.env.UNI_SUB_PLATFORM': string;
7
10
  'process.env.UNI_MP_PLUGIN': string;
8
11
  'process.env.UNI_SUBPACKAGE': string;
9
12
  'process.env.UNI_COMPILER_VERSION': string;
@@ -15,7 +15,10 @@ function initDefine(stringifyBoolean = false) {
15
15
  : isDebug,
16
16
  'process.env.UNI_APP_ID': JSON.stringify(manifestJson.appid || ''),
17
17
  'process.env.UNI_APP_NAME': JSON.stringify(manifestJson.name || ''),
18
+ 'process.env.UNI_APP_VERSION_NAME': JSON.stringify(manifestJson.versionName || ''),
19
+ 'process.env.UNI_APP_VERSION_CODE': JSON.stringify(manifestJson.versionCode || ''),
18
20
  'process.env.UNI_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM),
21
+ 'process.env.UNI_SUB_PLATFORM': JSON.stringify(process.env.UNI_SUB_PLATFORM),
19
22
  'process.env.UNI_MP_PLUGIN': JSON.stringify(process.env.UNI_MP_PLUGIN),
20
23
  'process.env.UNI_SUBPACKAGE': JSON.stringify(process.env.UNI_SUBPACKAGE),
21
24
  'process.env.UNI_COMPILER_VERSION': JSON.stringify(process.env.UNI_COMPILER_VERSION),
@@ -0,0 +1 @@
1
+ export declare function emptyCssComments(raw: string): string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emptyCssComments = void 0;
4
+ const utils_1 = require("./utils");
5
+ const blankReplacer = (s) => ' '.repeat(s.length);
6
+ function emptyCssComments(raw) {
7
+ return raw.replace(utils_1.multilineCommentsRE, blankReplacer);
8
+ }
9
+ exports.emptyCssComments = emptyCssComments;
@@ -36,5 +36,5 @@ export declare function getAssetFilename(hash: string, config: ResolvedConfig):
36
36
  * @returns output filename
37
37
  */
38
38
  export declare function assetFileNamesToFileName(assetFileNames: Exclude<OutputOptions['assetFileNames'], undefined>, file: string, contentHash: string, content: string | Buffer): string;
39
- export declare function getAssetHash(content: Buffer): string;
39
+ export declare function getAssetHash(content: Buffer | string): string;
40
40
  export declare function urlToBuiltUrl(url: string, importer: string, config: ResolvedConfig, pluginContext: PluginContext): string;
@@ -1,4 +1,4 @@
1
- import { RollupError } from 'rollup';
1
+ import { ExistingRawSourceMap, RollupError } from 'rollup';
2
2
  import { Plugin } from '../plugin';
3
3
  import { ResolvedConfig } from '../config';
4
4
  import * as Postcss from 'postcss';
@@ -38,12 +38,14 @@ export declare function cssPostPlugin(config: ResolvedConfig, { chunkCssFilename
38
38
  chunkCssFilename: (id: string) => string | void;
39
39
  chunkCssCode: (filename: string, cssCode: string) => Promise<string> | string;
40
40
  }): Plugin;
41
+ export declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): ExistingRawSourceMap;
41
42
  export declare const cssUrlRE: RegExp;
42
43
  export declare function minifyCSS(css: string, config: ResolvedConfig): Promise<string>;
43
44
  export declare function hoistAtRules(css: string): Promise<string>;
44
45
  export interface StylePreprocessorResults {
45
46
  code: string;
46
- map?: object;
47
+ map?: ExistingRawSourceMap | undefined;
48
+ additionalMap?: ExistingRawSourceMap | undefined;
47
49
  errors: RollupError[];
48
50
  deps: string[];
49
51
  }
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.hoistAtRules = exports.minifyCSS = exports.cssUrlRE = exports.cssPostPlugin = exports.cssPlugin = exports.isDirectCSSRequest = exports.isCSSRequest = exports.commonjsProxyRE = exports.cssLangRE = void 0;
29
+ exports.hoistAtRules = exports.minifyCSS = exports.cssUrlRE = exports.formatPostcssSourceMap = exports.cssPostPlugin = exports.cssPlugin = exports.isDirectCSSRequest = exports.isCSSRequest = exports.commonjsProxyRE = exports.cssLangRE = void 0;
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const fast_glob_1 = __importDefault(require("fast-glob"));
@@ -39,11 +39,13 @@ const magic_string_1 = __importDefault(require("magic-string"));
39
39
  const esbuild_1 = require("esbuild");
40
40
  const preprocess_1 = require("../../../../preprocess");
41
41
  const constants_1 = require("../../../../constants");
42
+ const cleanString_1 = require("../cleanString");
42
43
  const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`;
43
44
  exports.cssLangRE = new RegExp(cssLangs);
44
45
  const cssModuleRE = new RegExp(`\\.module${cssLangs}`);
45
46
  const directRequestRE = /(\?|&)direct\b/;
46
47
  exports.commonjsProxyRE = /\?commonjs-proxy/;
48
+ const varRE = /^var\(/i;
47
49
  const isCSSRequest = (request) => exports.cssLangRE.test(request) && !directRequestRE.test(request);
48
50
  exports.isCSSRequest = isCSSRequest;
49
51
  const isDirectCSSRequest = (request) => exports.cssLangRE.test(request) && directRequestRE.test(request);
@@ -253,7 +255,7 @@ function getCssResolversKeys(resolvers) {
253
255
  }
254
256
  async function compileCSS(id, code, config, urlReplacer, atImportResolvers, server) {
255
257
  var _a;
256
- const { modules: modulesOptions, preprocessorOptions } = config.css || {};
258
+ const { modules: modulesOptions, preprocessorOptions, devSourcemap, } = config.css || {};
257
259
  const isModule = modulesOptions !== false && cssModuleRE.test(id);
258
260
  // although at serve time it can work without processing, we do need to
259
261
  // crawl them in order to register watch dependencies.
@@ -267,9 +269,9 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
267
269
  !isModule &&
268
270
  !needInlineImport &&
269
271
  !hasUrl) {
270
- return { code };
272
+ return { code, map: null };
271
273
  }
272
- let map;
274
+ let preprocessorMap;
273
275
  let modules;
274
276
  const deps = new Set();
275
277
  // 2. pre-processors: sass etc.
@@ -297,12 +299,13 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
297
299
  }
298
300
  // important: set this for relative import resolving
299
301
  opts.filename = (0, utils_1.cleanUrl)(id);
302
+ opts.enableSourcemap = devSourcemap !== null && devSourcemap !== void 0 ? devSourcemap : false;
300
303
  const preprocessResult = await preProcessor(code, config.root, opts, atImportResolvers, !!config.nvue);
301
304
  if (preprocessResult.errors.length) {
302
305
  throw preprocessResult.errors[0];
303
306
  }
304
307
  code = preprocessResult.code;
305
- map = preprocessResult.map;
308
+ preprocessorMap = combineSourcemapsIfExists(opts.filename, preprocessResult.map, preprocessResult.additionalMap);
306
309
  if (preprocessResult.deps) {
307
310
  preprocessResult.deps.forEach((dep) => {
308
311
  // sometimes sass registers the file itself as a dep
@@ -318,6 +321,10 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
318
321
  if (needInlineImport) {
319
322
  postcssPlugins.unshift((await Promise.resolve().then(() => __importStar(require('postcss-import')))).default({
320
323
  async resolve(id, basedir) {
324
+ // const publicFile = checkPublicFile(id, config)
325
+ // if (publicFile) {
326
+ // return publicFile
327
+ // }
321
328
  const resolved = await atImportResolvers.css(id, path_1.default.join(basedir, '*'));
322
329
  if (resolved) {
323
330
  return path_1.default.resolve(resolved);
@@ -352,7 +359,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
352
359
  if (!postcssPlugins.length) {
353
360
  return {
354
361
  code,
355
- map,
362
+ map: preprocessorMap,
356
363
  };
357
364
  }
358
365
  // postcss is an unbundled dep and should be lazy imported
@@ -365,13 +372,17 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
365
372
  map: {
366
373
  inline: false,
367
374
  annotation: false,
368
- prev: map,
375
+ // postcss may return virtual files
376
+ // we cannot obtain content of them, so this needs to be enabled
377
+ sourcesContent: true,
378
+ // when "prev: preprocessorMap", the result map may include duplicate filename in `postcssResult.map.sources`
379
+ // prev: preprocessorMap,
369
380
  },
370
381
  });
371
382
  // record CSS dependencies from @imports
372
383
  for (const message of postcssResult.messages) {
373
384
  if (message.type === 'dependency') {
374
- deps.add(message.file);
385
+ deps.add((0, utils_1.normalizePath)(message.file));
375
386
  }
376
387
  else if (message.type === 'dir-dependency') {
377
388
  // https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#3-dependencies
@@ -410,14 +421,58 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
410
421
  config.logger.warn(picocolors_1.default.yellow(msg));
411
422
  }
412
423
  }
424
+ if (!devSourcemap) {
425
+ return {
426
+ ast: postcssResult,
427
+ code: postcssResult.css,
428
+ map: { mappings: '' },
429
+ modules,
430
+ deps,
431
+ };
432
+ }
433
+ const rawPostcssMap = postcssResult.map.toJSON();
434
+ const postcssMap = formatPostcssSourceMap(
435
+ // version property of rawPostcssMap is declared as string
436
+ // but actually it is a number
437
+ rawPostcssMap, (0, utils_1.cleanUrl)(id));
413
438
  return {
414
439
  ast: postcssResult,
415
440
  code: postcssResult.css,
416
- map: postcssResult.map,
441
+ map: combineSourcemapsIfExists((0, utils_1.cleanUrl)(id), postcssMap, preprocessorMap),
417
442
  modules,
418
443
  deps,
419
444
  };
420
445
  }
446
+ function formatPostcssSourceMap(rawMap, file) {
447
+ const inputFileDir = path_1.default.dirname(file);
448
+ const sources = rawMap.sources.map((source) => {
449
+ const cleanSource = (0, utils_1.cleanUrl)(decodeURIComponent(source));
450
+ // postcss returns virtual files
451
+ if (/^<.+>$/.test(cleanSource)) {
452
+ return `\0${cleanSource}`;
453
+ }
454
+ return (0, utils_1.normalizePath)(path_1.default.resolve(inputFileDir, cleanSource));
455
+ });
456
+ return {
457
+ file,
458
+ mappings: rawMap.mappings,
459
+ names: rawMap.names,
460
+ sources,
461
+ sourcesContent: rawMap.sourcesContent,
462
+ version: rawMap.version,
463
+ };
464
+ }
465
+ exports.formatPostcssSourceMap = formatPostcssSourceMap;
466
+ function combineSourcemapsIfExists(filename, map1, map2) {
467
+ return map1 && map2
468
+ ? (0, utils_1.combineSourcemaps)(filename, [
469
+ // type of version property of ExistingRawSourceMap is number
470
+ // but it is always 3
471
+ map1,
472
+ map2,
473
+ ])
474
+ : map1;
475
+ }
421
476
  async function resolvePostcssConfig(config) {
422
477
  var _a;
423
478
  let result = postcssConfigCache.get(config);
@@ -435,14 +490,23 @@ async function resolvePostcssConfig(config) {
435
490
  };
436
491
  }
437
492
  else {
493
+ const searchPath = typeof inlineOptions === 'string' ? inlineOptions : config.root;
438
494
  try {
439
- const searchPath = typeof inlineOptions === 'string' ? inlineOptions : config.root;
440
495
  // @ts-ignore
441
496
  result = await (0, postcss_load_config_1.default)({}, searchPath);
442
497
  }
443
498
  catch (e) {
444
499
  if (!/No PostCSS Config found/.test(e.message)) {
445
- throw e;
500
+ if (e instanceof Error) {
501
+ const { name, message, stack } = e;
502
+ e.name = 'Failed to load PostCSS config';
503
+ e.message = `Failed to load PostCSS config (searchPath: ${searchPath}): [${name}] ${message}\n${stack}`;
504
+ e.stack = ''; // add stack to message to retain stack
505
+ throw e;
506
+ }
507
+ else {
508
+ throw new Error(`Failed to load PostCSS config: ${e}`);
509
+ }
446
510
  }
447
511
  result = null;
448
512
  }
@@ -452,7 +516,7 @@ async function resolvePostcssConfig(config) {
452
516
  }
453
517
  // https://drafts.csswg.org/css-syntax-3/#identifier-code-point
454
518
  exports.cssUrlRE = /(?<=^|[^\w\-\u0080-\uffff])url\(\s*('[^']+'|"[^"]+"|[^'")]+)\s*\)/;
455
- const cssImageSetRE = /image-set\(([^)]+)\)/;
519
+ const cssImageSetRE = /(?<=image-set\()((?:[\w\-]+\([^\)]*\)|[^)])*)(?=\))/;
456
520
  const UrlRewritePostcssPlugin = (opts) => {
457
521
  if (!opts) {
458
522
  throw new Error('base or replace is required');
@@ -470,7 +534,9 @@ const UrlRewritePostcssPlugin = (opts) => {
470
534
  const importer = (_a = declaration.source) === null || _a === void 0 ? void 0 : _a.input.file;
471
535
  return opts.replacer(rawUrl, importer);
472
536
  };
473
- const rewriterToUse = isCssUrl ? rewriteCssUrls : rewriteCssImageSet;
537
+ const rewriterToUse = isCssImageSet
538
+ ? rewriteCssImageSet
539
+ : rewriteCssUrls;
474
540
  promises.push(rewriterToUse(declaration.value, replacerForDeclaration).then((url) => {
475
541
  declaration.value = url;
476
542
  }));
@@ -484,9 +550,16 @@ const UrlRewritePostcssPlugin = (opts) => {
484
550
  };
485
551
  UrlRewritePostcssPlugin.postcss = true;
486
552
  function rewriteCssUrls(css, replacer) {
487
- return (0, utils_1.asyncReplace)(css, exports.cssUrlRE, async (match) => {
488
- const [matched, rawUrl] = match;
489
- return await doUrlReplace(rawUrl, matched, replacer);
553
+ return (0, utils_1.asyncReplace)(css, cssImageSetRE, async (match) => {
554
+ const [, rawUrl] = match;
555
+ const url = await (0, utils_1.processSrcSet)(rawUrl, async ({ url }) => {
556
+ // the url maybe url(...)
557
+ if (exports.cssUrlRE.test(url)) {
558
+ return await rewriteCssUrls(url, replacer);
559
+ }
560
+ return await doUrlReplace(url, url, replacer);
561
+ });
562
+ return url;
490
563
  });
491
564
  }
492
565
  function rewriteCssImageSet(css, replacer) {
@@ -503,7 +576,10 @@ async function doUrlReplace(rawUrl, matched, replacer) {
503
576
  wrap = first;
504
577
  rawUrl = rawUrl.slice(1, -1);
505
578
  }
506
- if ((0, utils_1.isExternalUrl)(rawUrl) || (0, utils_1.isDataUrl)(rawUrl) || rawUrl.startsWith('#')) {
579
+ if ((0, utils_1.isExternalUrl)(rawUrl) ||
580
+ (0, utils_1.isDataUrl)(rawUrl) ||
581
+ rawUrl.startsWith('#') ||
582
+ varRE.test(rawUrl)) {
507
583
  return matched;
508
584
  }
509
585
  return `url(${wrap}${await replacer(rawUrl)}${wrap})`;
@@ -533,24 +609,29 @@ async function minifyCSS(css, config) {
533
609
  exports.minifyCSS = minifyCSS;
534
610
  async function hoistAtRules(css) {
535
611
  const s = new magic_string_1.default(css);
612
+ const cleanCss = (0, cleanString_1.emptyCssComments)(css);
613
+ let match;
536
614
  // #1845
537
615
  // CSS @import can only appear at top of the file. We need to hoist all @import
538
616
  // to top when multiple files are concatenated.
539
617
  // match until semicolon that's not in quotes
540
- s.replace(/@import\s*(?:url\([^\)]*\)|"[^"]*"|'[^']*'|[^;]*).*?;/gm, (match) => {
541
- s.appendLeft(0, match);
542
- return '';
543
- });
618
+ const atImportRE = /@import\s*(?:url\([^\)]*\)|"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'|[^;]*).*?;/gm;
619
+ while ((match = atImportRE.exec(cleanCss))) {
620
+ s.remove(match.index, match.index + match[0].length);
621
+ // Use `appendLeft` instead of `prepend` to preserve original @import order
622
+ s.appendLeft(0, match[0]);
623
+ }
544
624
  // #6333
545
625
  // CSS @charset must be the top-first in the file, hoist the first to top
626
+ const atCharsetRE = /@charset\s*(?:"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'|[^;]*).*?;/gm;
546
627
  let foundCharset = false;
547
- s.replace(/@charset\s*(?:"[^"]*"|'[^']*'|[^;]*).*?;/gm, (match) => {
628
+ while ((match = atCharsetRE.exec(cleanCss))) {
629
+ s.remove(match.index, match.index + match[0].length);
548
630
  if (!foundCharset) {
549
- s.prepend(match);
631
+ s.prepend(match[0]);
550
632
  foundCharset = true;
551
633
  }
552
- return '';
553
- });
634
+ }
554
635
  return s.toString();
555
636
  }
556
637
  exports.hoistAtRules = hoistAtRules;
@@ -577,10 +658,12 @@ const scss = async (source, root, options, resolvers, isNVue) => {
577
658
  const internalImporter = (url, importer, done) => {
578
659
  resolvers.sass(url, importer).then((resolved) => {
579
660
  if (resolved) {
580
- rebaseUrls(resolved, options.filename, options.alias, isNVue).then(done);
661
+ rebaseUrls(resolved, options.filename, options.alias, isNVue)
662
+ .then((data) => done === null || done === void 0 ? void 0 : done(data))
663
+ .catch((data) => done === null || done === void 0 ? void 0 : done(data));
581
664
  }
582
665
  else {
583
- done && done(null);
666
+ done === null || done === void 0 ? void 0 : done(null);
584
667
  }
585
668
  });
586
669
  };
@@ -590,12 +673,20 @@ const scss = async (source, root, options, resolvers, isNVue) => {
590
673
  ? importer.push(...options.importer)
591
674
  : importer.push(options.importer);
592
675
  }
676
+ const { content: data, map: additionalMap } = await getSource(source, options.filename, options.additionalData, options.enableSourcemap);
593
677
  const finalOptions = {
594
678
  ...options,
595
- data: await getSource(source, options.filename, options.additionalData),
679
+ data,
596
680
  file: options.filename,
597
681
  outFile: options.filename,
598
682
  importer,
683
+ ...(options.enableSourcemap
684
+ ? {
685
+ sourceMap: true,
686
+ omitSourceMapUrl: true,
687
+ sourceMapRoot: path_1.default.dirname(options.filename),
688
+ }
689
+ : {}),
599
690
  };
600
691
  try {
601
692
  const result = await new Promise((resolve, reject) => {
@@ -609,8 +700,13 @@ const scss = async (source, root, options, resolvers, isNVue) => {
609
700
  });
610
701
  });
611
702
  const deps = result.stats.includedFiles;
703
+ const map = result.map
704
+ ? JSON.parse(result.map.toString())
705
+ : undefined;
612
706
  return {
613
707
  code: result.css.toString(),
708
+ map,
709
+ additionalMap,
614
710
  errors: [],
615
711
  deps,
616
712
  };
@@ -673,12 +769,20 @@ async function rebaseUrls(file, rootFile, alias, isNVue = false) {
673
769
  const less = async (source, root, options, resolvers, isNVue) => {
674
770
  const nodeLess = loadPreprocessor("less" /* less */, root);
675
771
  const viteResolverPlugin = createViteLessPlugin(nodeLess, options.filename, options.alias, resolvers, isNVue);
676
- source = await getSource(source, options.filename, options.additionalData);
772
+ const { content, map: additionalMap } = await getSource(source, options.filename, options.additionalData, options.enableSourcemap);
677
773
  let result;
678
774
  try {
679
- result = await nodeLess.render(source, {
775
+ result = await nodeLess.render(content, {
680
776
  ...options,
681
777
  plugins: [viteResolverPlugin, ...(options.plugins || [])],
778
+ ...(options.enableSourcemap
779
+ ? {
780
+ sourceMap: {
781
+ outputSourceFiles: true,
782
+ sourceMapFileInline: false,
783
+ },
784
+ }
785
+ : {}),
682
786
  });
683
787
  }
684
788
  catch (e) {
@@ -692,8 +796,14 @@ const less = async (source, root, options, resolvers, isNVue) => {
692
796
  };
693
797
  return { code: '', errors: [normalizedError], deps: [] };
694
798
  }
799
+ const map = result.map && JSON.parse(result.map);
800
+ if (map) {
801
+ delete map.sourcesContent;
802
+ }
695
803
  return {
696
804
  code: result.css.toString(),
805
+ map,
806
+ additionalMap,
697
807
  deps: result.imports,
698
808
  errors: [],
699
809
  };
@@ -752,29 +862,70 @@ const styl = async (source, root, options) => {
752
862
  const nodeStylus = loadPreprocessor("stylus" /* stylus */, root);
753
863
  // Get source with preprocessor options.additionalData. Make sure a new line separator
754
864
  // is added to avoid any render error, as added stylus content may not have semi-colon separators
755
- source = await getSource(source, options.filename, options.additionalData, '\n');
865
+ const { content, map: additionalMap } = await getSource(source, options.filename, options.additionalData, options.enableSourcemap, '\n');
756
866
  // Get preprocessor options.imports dependencies as stylus
757
867
  // does not return them with its builtin `.deps()` method
758
868
  const importsDeps = ((_a = options.imports) !== null && _a !== void 0 ? _a : []).map((dep) => path_1.default.resolve(dep));
759
869
  try {
760
- const ref = nodeStylus(source, options);
761
- // if (map) ref.set('sourcemap', { inline: false, comment: false })
870
+ const ref = nodeStylus(content, options);
871
+ if (options.enableSourcemap) {
872
+ ref.set('sourcemap', {
873
+ comment: false,
874
+ inline: false,
875
+ basePath: root,
876
+ });
877
+ }
762
878
  const result = ref.render();
763
879
  // Concat imports deps with computed deps
764
880
  const deps = [...ref.deps(), ...importsDeps];
765
- return { code: result, errors: [], deps };
881
+ // @ts-expect-error sourcemap exists
882
+ const map = ref.sourcemap;
883
+ return {
884
+ code: result,
885
+ map: formatStylusSourceMap(map, root),
886
+ additionalMap,
887
+ errors: [],
888
+ deps,
889
+ };
766
890
  }
767
891
  catch (e) {
768
892
  return { code: '', errors: [e], deps: [] };
769
893
  }
770
894
  };
771
- function getSource(source, filename, additionalData, sep = '') {
895
+ function formatStylusSourceMap(mapBefore, root) {
896
+ if (!mapBefore)
897
+ return undefined;
898
+ const map = { ...mapBefore };
899
+ const resolveFromRoot = (p) => (0, utils_1.normalizePath)(path_1.default.resolve(root, p));
900
+ if (map.file) {
901
+ map.file = resolveFromRoot(map.file);
902
+ }
903
+ map.sources = map.sources.map(resolveFromRoot);
904
+ return map;
905
+ }
906
+ async function getSource(source, filename, additionalData, enableSourcemap, sep = '') {
772
907
  if (!additionalData)
773
- return source;
908
+ return { content: source };
774
909
  if (typeof additionalData === 'function') {
775
- return additionalData(source, filename);
910
+ const newContent = await additionalData(source, filename);
911
+ if (typeof newContent === 'string') {
912
+ return { content: newContent };
913
+ }
914
+ return newContent;
915
+ }
916
+ if (!enableSourcemap) {
917
+ return { content: additionalData + sep + source };
776
918
  }
777
- return additionalData + sep + source;
919
+ const ms = new magic_string_1.default(source);
920
+ ms.appendLeft(0, sep);
921
+ ms.appendLeft(0, additionalData);
922
+ const map = ms.generateMap({ hires: true });
923
+ map.file = filename;
924
+ map.sources = [filename];
925
+ return {
926
+ content: ms.toString(),
927
+ map,
928
+ };
778
929
  }
779
930
  const preProcessors = Object.freeze({
780
931
  ["less" /* less */]: less,
@@ -1,3 +1,4 @@
1
+ import type { DecodedSourceMap, RawSourceMap } from '@ampproject/remapping';
1
2
  export declare function slash(p: string): string;
2
3
  export declare const bareImportRE: RegExp;
3
4
  export declare const deepImportRE: RegExp;
@@ -10,6 +11,7 @@ export declare const externalRE: RegExp;
10
11
  export declare const isExternalUrl: (url: string) => boolean;
11
12
  export declare const dataUrlRE: RegExp;
12
13
  export declare const isDataUrl: (url: string) => boolean;
14
+ export declare const multilineCommentsRE: RegExp;
13
15
  export declare function asyncReplace(input: string, re: RegExp, replacer: (match: RegExpExecArray) => string | Promise<string>): Promise<string>;
14
16
  export declare function isObject(value: unknown): value is Record<string, any>;
15
17
  export declare function pad(source: string, n?: number): string;
@@ -26,4 +28,5 @@ interface ImageCandidate {
26
28
  descriptor: string;
27
29
  }
28
30
  export declare function processSrcSet(srcs: string, replacer: (arg: ImageCandidate) => Promise<string>): Promise<string>;
31
+ export declare function combineSourcemaps(filename: string, sourcemapList: Array<DecodedSourceMap | RawSourceMap>, excludeContent?: boolean): RawSourceMap;
29
32
  export {};
@@ -3,12 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.processSrcSet = exports.generateCodeFrame = exports.posToNumber = exports.pad = exports.isObject = exports.asyncReplace = exports.isDataUrl = exports.dataUrlRE = exports.isExternalUrl = exports.externalRE = exports.cleanUrl = exports.hashRE = exports.queryRE = exports.normalizePath = exports.isWindows = exports.deepImportRE = exports.bareImportRE = exports.slash = void 0;
6
+ exports.combineSourcemaps = exports.processSrcSet = exports.generateCodeFrame = exports.posToNumber = exports.pad = exports.isObject = exports.asyncReplace = exports.multilineCommentsRE = exports.isDataUrl = exports.dataUrlRE = exports.isExternalUrl = exports.externalRE = exports.cleanUrl = exports.hashRE = exports.queryRE = exports.normalizePath = exports.isWindows = exports.deepImportRE = exports.bareImportRE = exports.slash = void 0;
7
7
  /**
8
8
  * https://github.com/vitejs/vite/blob/main/packages/vite/src/node/utils.ts
9
9
  */
10
10
  const os_1 = __importDefault(require("os"));
11
11
  const path_1 = __importDefault(require("path"));
12
+ const remapping_1 = __importDefault(require("@ampproject/remapping"));
12
13
  function slash(p) {
13
14
  return p.replace(/\\/g, '/');
14
15
  }
@@ -30,6 +31,7 @@ exports.isExternalUrl = isExternalUrl;
30
31
  exports.dataUrlRE = /^\s*data:/i;
31
32
  const isDataUrl = (url) => exports.dataUrlRE.test(url);
32
33
  exports.isDataUrl = isDataUrl;
34
+ exports.multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm;
33
35
  async function asyncReplace(input, re, replacer) {
34
36
  let match;
35
37
  let remaining = input;
@@ -102,15 +104,17 @@ function generateCodeFrame(source, start = 0, end) {
102
104
  }
103
105
  exports.generateCodeFrame = generateCodeFrame;
104
106
  const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g;
107
+ const imageSetUrlRE = /^(?:[\w\-]+\(.*?\)|'.*?'|".*?"|\S*)/;
105
108
  async function processSrcSet(srcs, replacer) {
106
109
  const imageCandidates = srcs
107
110
  .split(',')
108
111
  .map((s) => {
109
- const [url, descriptor] = s
110
- .replace(escapedSpaceCharacters, ' ')
111
- .trim()
112
- .split(' ', 2);
113
- return { url, descriptor };
112
+ const src = s.replace(escapedSpaceCharacters, ' ').trim();
113
+ const [url] = imageSetUrlRE.exec(src) || [];
114
+ return {
115
+ url,
116
+ descriptor: src === null || src === void 0 ? void 0 : src.slice(url.length).trim(),
117
+ };
114
118
  })
115
119
  .filter(({ url }) => !!url);
116
120
  const ret = await Promise.all(imageCandidates.map(async ({ url, descriptor }) => {
@@ -127,3 +131,71 @@ async function processSrcSet(srcs, replacer) {
127
131
  return url;
128
132
  }
129
133
  exports.processSrcSet = processSrcSet;
134
+ function escapeToLinuxLikePath(path) {
135
+ if (/^[A-Z]:/.test(path)) {
136
+ return path.replace(/^([A-Z]):\//, '/windows/$1/');
137
+ }
138
+ if (/^\/[^/]/.test(path)) {
139
+ return `/linux${path}`;
140
+ }
141
+ return path;
142
+ }
143
+ function unescapeToLinuxLikePath(path) {
144
+ if (path.startsWith('/linux/')) {
145
+ return path.slice('/linux'.length);
146
+ }
147
+ if (path.startsWith('/windows/')) {
148
+ return path.replace(/^\/windows\/([A-Z])\//, '$1:/');
149
+ }
150
+ return path;
151
+ }
152
+ // based on https://github.com/sveltejs/svelte/blob/abf11bb02b2afbd3e4cac509a0f70e318c306364/src/compiler/utils/mapped_code.ts#L221
153
+ const nullSourceMap = {
154
+ names: [],
155
+ sources: [],
156
+ mappings: '',
157
+ version: 3,
158
+ };
159
+ function combineSourcemaps(filename, sourcemapList, excludeContent = true) {
160
+ if (sourcemapList.length === 0 ||
161
+ sourcemapList.every((m) => m.sources.length === 0)) {
162
+ return { ...nullSourceMap };
163
+ }
164
+ // hack for parse broken with normalized absolute paths on windows (C:/path/to/something).
165
+ // escape them to linux like paths
166
+ // also avoid mutation here to prevent breaking plugin's using cache to generate sourcemaps like vue (see #7442)
167
+ sourcemapList = sourcemapList.map((sourcemap) => {
168
+ const newSourcemaps = { ...sourcemap };
169
+ newSourcemaps.sources = sourcemap.sources.map((source) => source ? escapeToLinuxLikePath(source) : null);
170
+ if (sourcemap.sourceRoot) {
171
+ newSourcemaps.sourceRoot = escapeToLinuxLikePath(sourcemap.sourceRoot);
172
+ }
173
+ return newSourcemaps;
174
+ });
175
+ const escapedFilename = escapeToLinuxLikePath(filename);
176
+ // We don't declare type here so we can convert/fake/map as RawSourceMap
177
+ let map; //: SourceMap
178
+ let mapIndex = 1;
179
+ const useArrayInterface = sourcemapList.slice(0, -1).find((m) => m.sources.length !== 1) === undefined;
180
+ if (useArrayInterface) {
181
+ map = (0, remapping_1.default)(sourcemapList, () => null, excludeContent);
182
+ }
183
+ else {
184
+ map = (0, remapping_1.default)(sourcemapList[0], function loader(sourcefile) {
185
+ if (sourcefile === escapedFilename && sourcemapList[mapIndex]) {
186
+ return sourcemapList[mapIndex++];
187
+ }
188
+ else {
189
+ return null;
190
+ }
191
+ }, excludeContent);
192
+ }
193
+ if (!map.file) {
194
+ delete map.file;
195
+ }
196
+ // unescape the previous hack
197
+ map.sources = map.sources.map((source) => source ? unescapeToLinuxLikePath(source) : source);
198
+ map.file = filename;
199
+ return map;
200
+ }
201
+ exports.combineSourcemaps = combineSourcemaps;
package/lib/.DS_Store ADDED
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-3040920220508001",
3
+ "version": "3.0.0-alpha-3040820220424004",
4
4
  "description": "@dcloudio/uni-cli-shared",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,11 +18,12 @@
18
18
  "url": "https://github.com/dcloudio/uni-app/issues"
19
19
  },
20
20
  "dependencies": {
21
+ "@ampproject/remapping": "^2.1.2",
21
22
  "@babel/core": "^7.17.9",
22
23
  "@babel/parser": "^7.17.9",
23
24
  "@babel/types": "^7.17.0",
24
- "@dcloudio/uni-i18n": "3.0.0-alpha-3040920220508001",
25
- "@dcloudio/uni-shared": "3.0.0-alpha-3040920220508001",
25
+ "@dcloudio/uni-i18n": "3.0.0-alpha-3040820220424004",
26
+ "@dcloudio/uni-shared": "3.0.0-alpha-3040820220424004",
26
27
  "@intlify/core-base": "9.1.9",
27
28
  "@intlify/shared": "9.1.9",
28
29
  "@intlify/vue-devtools": "9.1.9",
@@ -32,7 +33,7 @@
32
33
  "@vue/compiler-sfc": "3.2.33",
33
34
  "@vue/server-renderer": "3.2.33",
34
35
  "@vue/shared": "3.2.33",
35
- "autoprefixer": "^10.4.5",
36
+ "autoprefixer": "^10.4.7",
36
37
  "base64url": "^3.0.1",
37
38
  "chokidar": "^3.5.3",
38
39
  "compare-versions": "^3.6.0",
@@ -59,13 +60,18 @@
59
60
  },
60
61
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
61
62
  "devDependencies": {
63
+ "@types/babel__core": "^7.1.19",
62
64
  "@types/debug": "^4.1.7",
65
+ "@types/estree": "^0.0.51",
63
66
  "@types/fs-extra": "^9.0.13",
64
67
  "@types/hash-sum": "^1.0.0",
65
68
  "@types/less": "^3.0.3",
66
69
  "@types/mime": "^2.0.3",
67
70
  "@types/module-alias": "^2.0.1",
71
+ "@types/resolve": "^1.20.2",
72
+ "@types/sass": "^1.43.1",
68
73
  "@types/stylus": "^0.48.36",
69
- "postcss": "^8.4.12"
74
+ "postcss": "^8.4.13",
75
+ "vue": "3.2.33"
70
76
  }
71
77
  }