@dcloudio/uni-cli-shared 3.0.0-alpha-3060120220907001 → 3.0.0-alpha-3060120220907002

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.
@@ -9,7 +9,7 @@ const libDir = path_1.default.resolve(__dirname, '../../lib');
9
9
  function initAppProvide() {
10
10
  const cryptoDefine = [path_1.default.join(libDir, 'crypto.js'), 'default'];
11
11
  return {
12
- __f__: ['@dcloudio/uni-shared', 'formatAppLog'],
12
+ __f__: ['@dcloudio/uni-app', 'formatAppLog'],
13
13
  crypto: cryptoDefine,
14
14
  'window.crypto': cryptoDefine,
15
15
  'global.crypto': cryptoDefine,
@@ -20,7 +20,7 @@ function initAppProvide() {
20
20
  exports.initAppProvide = initAppProvide;
21
21
  function initH5Provide() {
22
22
  return {
23
- __f__: ['@dcloudio/uni-shared', 'formatH5Log'],
23
+ __f__: ['@dcloudio/uni-app', 'formatH5Log'],
24
24
  };
25
25
  }
26
26
  exports.initH5Provide = initH5Provide;
@@ -201,13 +201,26 @@ function assetFileNamesToFileName(assetFileNames, file, contentHash, content) {
201
201
  case '[hash]':
202
202
  return hash;
203
203
  case '[name]':
204
- return name;
204
+ return sanitizeFileName(name);
205
205
  }
206
206
  throw new Error(`invalid placeholder ${placeholder} in assetFileNames "${assetFileNames}"`);
207
207
  });
208
208
  return fileName;
209
209
  }
210
210
  exports.assetFileNamesToFileName = assetFileNamesToFileName;
211
+ // taken from https://github.com/rollup/rollup/blob/a8647dac0fe46c86183be8596ef7de25bc5b4e4b/src/utils/sanitizeFileName.ts
212
+ // https://datatracker.ietf.org/doc/html/rfc2396
213
+ // eslint-disable-next-line no-control-regex
214
+ const INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g;
215
+ const DRIVE_LETTER_REGEX = /^[a-z]:/i;
216
+ function sanitizeFileName(name) {
217
+ const match = DRIVE_LETTER_REGEX.exec(name);
218
+ const driveLetter = match ? match[0] : '';
219
+ // A `:` is only allowed as part of a windows drive letter (ex: C:\foo)
220
+ // Otherwise, avoid them because they can refer to NTFS alternate data streams.
221
+ return (driveLetter +
222
+ name.substring(driveLetter.length).replace(INVALID_CHAR_REGEX, '_'));
223
+ }
211
224
  /**
212
225
  * Register an asset to be emitted as part of the bundle (if necessary)
213
226
  * and returns the resolved public URL
@@ -305,6 +305,10 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
305
305
  if (preprocessResult.errors.length) {
306
306
  throw preprocessResult.errors[0];
307
307
  }
308
+ // TODO 升级
309
+ // if (preprocessResult.error) {
310
+ // throw preprocessResult.error
311
+ // }
308
312
  code = preprocessResult.code;
309
313
  preprocessorMap = combineSourcemapsIfExists(opts.filename, preprocessResult.map, preprocessResult.additionalMap);
310
314
  if (preprocessResult.deps) {
@@ -363,69 +367,81 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
363
367
  map: preprocessorMap,
364
368
  };
365
369
  }
366
- // postcss is an unbundled dep and should be lazy imported
367
- const postcssResult = await (await Promise.resolve().then(() => __importStar(require('postcss'))))
368
- .default(postcssPlugins)
369
- .process(code, {
370
- ...postcssOptions,
371
- to: id,
372
- from: id,
373
- ...(devSourcemap
374
- ? {
375
- map: {
376
- inline: false,
377
- annotation: false,
378
- // postcss may return virtual files
379
- // we cannot obtain content of them, so this needs to be enabled
380
- sourcesContent: true,
381
- // when "prev: preprocessorMap", the result map may include duplicate filename in `postcssResult.map.sources`
382
- // prev: preprocessorMap,
383
- },
384
- }
385
- : {}),
386
- });
387
- // record CSS dependencies from @imports
388
- for (const message of postcssResult.messages) {
389
- if (message.type === 'dependency') {
390
- deps.add((0, utils_1.normalizePath)(message.file));
391
- }
392
- else if (message.type === 'dir-dependency') {
393
- // https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#3-dependencies
394
- const { dir, glob: globPattern = '**' } = message;
395
- const pattern = (0, utils_1.normalizePath)(path_1.default.resolve(path_1.default.dirname(id), dir)) + `/` + globPattern;
396
- const files = fast_glob_1.default.sync(pattern, {
397
- ignore: ['**/node_modules/**'],
398
- });
399
- for (let i = 0; i < files.length; i++) {
400
- deps.add(files[i]);
370
+ let postcssResult;
371
+ try {
372
+ // postcss is an unbundled dep and should be lazy imported
373
+ postcssResult = await (await Promise.resolve().then(() => __importStar(require('postcss'))))
374
+ .default(postcssPlugins)
375
+ .process(code, {
376
+ ...postcssOptions,
377
+ to: id,
378
+ from: id,
379
+ ...(devSourcemap
380
+ ? {
381
+ map: {
382
+ inline: false,
383
+ annotation: false,
384
+ // postcss may return virtual files
385
+ // we cannot obtain content of them, so this needs to be enabled
386
+ sourcesContent: true,
387
+ // when "prev: preprocessorMap", the result map may include duplicate filename in `postcssResult.map.sources`
388
+ // prev: preprocessorMap,
389
+ },
390
+ }
391
+ : {}),
392
+ });
393
+ // record CSS dependencies from @imports
394
+ for (const message of postcssResult.messages) {
395
+ if (message.type === 'dependency') {
396
+ deps.add((0, utils_1.normalizePath)(message.file));
401
397
  }
402
- if (server) {
403
- // register glob importers so we can trigger updates on file add/remove
404
- if (!(id in server._globImporters)) {
398
+ else if (message.type === 'dir-dependency') {
399
+ // https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#3-dependencies
400
+ const { dir, glob: globPattern = '**' } = message;
401
+ const pattern = (0, utils_1.normalizePath)(path_1.default.resolve(path_1.default.dirname(id), dir)) + `/` + globPattern;
402
+ const files = fast_glob_1.default.sync(pattern, {
403
+ ignore: ['**/node_modules/**'],
404
+ });
405
+ for (let i = 0; i < files.length; i++) {
406
+ deps.add(files[i]);
407
+ }
408
+ if (server) {
409
+ // register glob importers so we can trigger updates on file add/remove
410
+ if (!(id in server._globImporters)) {
411
+ ;
412
+ server._globImporters[id] = {
413
+ module: server.moduleGraph.getModuleById(id),
414
+ importGlobs: [],
415
+ };
416
+ }
405
417
  ;
406
- server._globImporters[id] = {
407
- module: server.moduleGraph.getModuleById(id),
408
- importGlobs: [],
409
- };
418
+ server._globImporters[id].importGlobs.push({
419
+ base: config.root,
420
+ pattern,
421
+ });
410
422
  }
411
- ;
412
- server._globImporters[id].importGlobs.push({
413
- base: config.root,
414
- pattern,
415
- });
416
423
  }
417
- }
418
- else if (message.type === 'warning') {
419
- let msg = `[vite:css] ${message.text}`;
420
- if (message.line && message.column) {
421
- msg += `\n${(0, utils_1.generateCodeFrame)(code, {
422
- line: message.line,
423
- column: message.column,
424
- })}`;
424
+ else if (message.type === 'warning') {
425
+ let msg = `[vite:css] ${message.text}`;
426
+ if (message.line && message.column) {
427
+ msg += `\n${(0, utils_1.generateCodeFrame)(code, {
428
+ line: message.line,
429
+ column: message.column,
430
+ })}`;
431
+ }
432
+ config.logger.warn(picocolors_1.default.yellow(msg));
425
433
  }
426
- config.logger.warn(picocolors_1.default.yellow(msg));
427
434
  }
428
435
  }
436
+ catch (e) {
437
+ e.message = `[postcss] ${e.message}`;
438
+ e.code = code;
439
+ e.loc = {
440
+ column: e.column,
441
+ line: e.line,
442
+ };
443
+ throw e;
444
+ }
429
445
  if (!devSourcemap) {
430
446
  return {
431
447
  ast: postcssResult,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-3060120220907001",
3
+ "version": "3.0.0-alpha-3060120220907002",
4
4
  "description": "@dcloudio/uni-cli-shared",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,8 +22,8 @@
22
22
  "@babel/core": "^7.17.9",
23
23
  "@babel/parser": "^7.17.9",
24
24
  "@babel/types": "^7.17.0",
25
- "@dcloudio/uni-i18n": "3.0.0-alpha-3060120220907001",
26
- "@dcloudio/uni-shared": "3.0.0-alpha-3060120220907001",
25
+ "@dcloudio/uni-i18n": "3.0.0-alpha-3060120220907002",
26
+ "@dcloudio/uni-shared": "3.0.0-alpha-3060120220907002",
27
27
  "@intlify/core-base": "9.1.9",
28
28
  "@intlify/shared": "9.1.9",
29
29
  "@intlify/vue-devtools": "9.1.9",