@tarojs/rn-style-transformer 3.3.6 → 3.3.10

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.
@@ -3,35 +3,36 @@ 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.resolveStyle = exports.findVariant = exports.insertAfter = exports.insertBefore = void 0;
6
+ exports.getAdditionalData = exports.normalizeSourceMap = exports.normalizePath = exports.resolveStyle = exports.findVariant = exports.insertAfter = exports.insertBefore = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const helper_1 = require("@tarojs/helper");
10
- const types_1 = require("../types");
11
- function insertBefore(source, target) {
12
- if (!source && !target) {
10
+ const resolve_1 = __importDefault(require("resolve"));
11
+ const node_modules_paths_1 = __importDefault(require("resolve/lib/node-modules-paths"));
12
+ function insertBefore(source, additional) {
13
+ if (!source && !additional) {
13
14
  return '';
14
15
  }
15
16
  if (!source) {
16
- return target;
17
+ return additional;
17
18
  }
18
- if (!target) {
19
+ if (!additional) {
19
20
  return source;
20
21
  }
21
- return target + ';\n' + source;
22
+ return additional + ';\n' + source;
22
23
  }
23
24
  exports.insertBefore = insertBefore;
24
- function insertAfter(source, target) {
25
- if (!source && !target) {
25
+ function insertAfter(source, additional) {
26
+ if (!source && !additional) {
26
27
  return '';
27
28
  }
28
29
  if (!source) {
29
- return target;
30
+ return additional;
30
31
  }
31
- if (!target) {
32
+ if (!additional) {
32
33
  return source;
33
34
  }
34
- return source + ';\n' + target;
35
+ return source + ';\n' + additional;
35
36
  }
36
37
  exports.insertAfter = insertAfter;
37
38
  // Iterate through the include paths and extensions to find the file variant
@@ -56,7 +57,8 @@ exports.findVariant = findVariant;
56
57
  * @param opts { basedir, platform, paths }
57
58
  */
58
59
  function resolveStyle(id, opts) {
59
- const { basedir, platform, paths = [], alias = {}, defaultExt = '', logLevel = types_1.LogLevelEnum.ERROR } = opts;
60
+ const { basedir, platform, paths = [], alias = {}, defaultExt = '', logLevel = "error" /* ERROR */ } = opts;
61
+ id = id.trim();
60
62
  Object.keys(alias).forEach(key => {
61
63
  if (id.startsWith(key)) {
62
64
  id = id.replace(key, alias[key]);
@@ -65,24 +67,42 @@ function resolveStyle(id, opts) {
65
67
  const { dir, name, ext: idExt } = path_1.default.parse(id);
66
68
  const incPaths = [path_1.default.resolve(basedir, dir)].concat(paths);
67
69
  const ext = idExt || defaultExt;
68
- const exts = [
70
+ const extensions = [
69
71
  // add the platform specific extension, first in the array to take precedence
70
72
  platform === 'android' ? '.android' + ext : '.ios' + ext,
71
73
  '.rn' + ext,
72
74
  ext
73
75
  ];
74
- const file = findVariant(name, exts, incPaths);
76
+ let file;
77
+ let isNodeModulesPath = false;
78
+ try {
79
+ if ((/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/).test(id)) {
80
+ file = findVariant(name, extensions, incPaths);
81
+ }
82
+ else {
83
+ // lookup node_modules file
84
+ isNodeModulesPath = true;
85
+ // like `@import 'taro-ui/dist/base.css';` or `@import '~taro-ui/dist/base.css';`
86
+ file = resolve_1.default.sync(path_1.default.join(dir, name).replace(/^~/, ''), { basedir, extensions });
87
+ }
88
+ }
89
+ catch (error) {
90
+ }
75
91
  if (!file) {
92
+ let includePaths = incPaths;
93
+ if (isNodeModulesPath) {
94
+ includePaths = node_modules_paths_1.default(basedir, { extensions }, id);
95
+ }
76
96
  const levelMessage = `
77
97
  样式文件没有找到,请检查文件路径: ${id}
78
98
  在 [
79
- ${incPaths.join(',\n ')}
99
+ ${includePaths.join(',\n ')}
80
100
  ]
81
101
  `;
82
- if (logLevel === types_1.LogLevelEnum.ERROR) {
102
+ if (logLevel === "error" /* ERROR */) {
83
103
  throw new Error(levelMessage);
84
104
  }
85
- if (logLevel === types_1.LogLevelEnum.WARNING) {
105
+ if (logLevel === "warning" /* WARNING */) {
86
106
  helper_1.printLog("warning" /* WARNING */, levelMessage);
87
107
  return id;
88
108
  }
@@ -90,5 +110,68 @@ function resolveStyle(id, opts) {
90
110
  return file;
91
111
  }
92
112
  exports.resolveStyle = resolveStyle;
113
+ // copy from https://github.com/webpack-contrib/css-loader/blob/master/src/utils.js
114
+ const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
115
+ const ABSOLUTE_SCHEME = /^[a-z0-9+\-.]+:/i;
116
+ function normalizePath(file) {
117
+ return path_1.default.sep === '\\' ? file.replace(/\\/g, '/') : file;
118
+ }
119
+ exports.normalizePath = normalizePath;
120
+ function getURLType(source) {
121
+ if (source[0] === '/') {
122
+ if (source[1] === '/') {
123
+ return 'scheme-relative';
124
+ }
125
+ return 'path-absolute';
126
+ }
127
+ if (IS_NATIVE_WIN32_PATH.test(source)) {
128
+ return 'path-absolute';
129
+ }
130
+ return ABSOLUTE_SCHEME.test(source) ? 'absolute' : 'path-relative';
131
+ }
132
+ function normalizeSourceMap(map, resourcePath) {
133
+ let newMap = map;
134
+ // Some loader emit source map as string
135
+ // Strip any JSON XSSI avoidance prefix from the string (as documented in the source maps specification), and then parse the string as JSON.
136
+ if (typeof newMap === 'string') {
137
+ newMap = JSON.parse(newMap);
138
+ }
139
+ delete newMap.file;
140
+ const { sourceRoot } = newMap;
141
+ delete newMap.sourceRoot;
142
+ if (newMap.sources) {
143
+ // Source maps should use forward slash because it is URLs (https://github.com/mozilla/source-map/issues/91)
144
+ // We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
145
+ newMap.sources = newMap.sources.map((source) => {
146
+ // Non-standard syntax from `postcss`
147
+ if (source.indexOf('<') === 0) {
148
+ return source;
149
+ }
150
+ const sourceType = getURLType(source);
151
+ // Do no touch `scheme-relative` and `absolute` URLs
152
+ if (sourceType === 'path-relative' || sourceType === 'path-absolute') {
153
+ const absoluteSource = sourceType === 'path-relative' && sourceRoot
154
+ ? path_1.default.resolve(sourceRoot, normalizePath(source))
155
+ : normalizePath(source);
156
+ return path_1.default.relative(path_1.default.dirname(resourcePath), absoluteSource);
157
+ }
158
+ return source;
159
+ });
160
+ }
161
+ return newMap;
162
+ }
163
+ exports.normalizeSourceMap = normalizeSourceMap;
164
+ // copy end
165
+ function getAdditionalData(data, config) {
166
+ let additionalData = '';
167
+ if (typeof config !== 'undefined') {
168
+ additionalData =
169
+ typeof config === 'function'
170
+ ? `${config(data)}`
171
+ : config;
172
+ }
173
+ return additionalData;
174
+ }
175
+ exports.getAdditionalData = getAdditionalData;
93
176
  exports.default = {};
94
177
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,2CAA0D;AAC1D,oCAA4D;AAE5D,SAAgB,YAAY,CAAE,MAAc,EAAE,MAAc;IAC1D,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE;QACtB,OAAO,EAAE,CAAA;KACV;IACD,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,MAAM,CAAA;KACd;IACD,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,MAAM,CAAA;KACd;IACD,OAAO,MAAM,GAAG,KAAK,GAAG,MAAM,CAAA;AAChC,CAAC;AAXD,oCAWC;AAED,SAAgB,WAAW,CAAE,MAAc,EAAE,MAAc;IACzD,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE;QACtB,OAAO,EAAE,CAAA;KACV;IACD,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,MAAM,CAAA;KACd;IACD,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,MAAM,CAAA;KACd;IACD,OAAO,MAAM,GAAG,KAAK,GAAG,MAAM,CAAA;AAChC,CAAC;AAXD,kCAWC;AAED,4EAA4E;AAC5E,SAAgB,WAAW,CAAE,IAAI,EAAE,UAAU,EAAE,YAAY;IACzD,KAAK,IAAI,CAAC,GAA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AO,MAAM,KAAK,UAAU;gBAC1B,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE;gBACnB,CAAC,CAAC,MAAM,CAAA;KACb;IACD,OAAO,cAAc,CAAA;AACvB,CAAC;AATD,8CASC;AAED,kBAAe,EAAE,CAAA"}
@@ -3,40 +3,36 @@ 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
- const path_1 = __importDefault(require("path"));
6
+ const less_1 = __importDefault(require("less"));
7
7
  const index_1 = require("./index");
8
- const types_1 = require("../types");
9
- class Importer {
8
+ class Importer extends less_1.default.FileManager {
10
9
  constructor(opt) {
10
+ super();
11
11
  this.alias = {};
12
12
  this.platform = opt.platform;
13
13
  this.alias = opt.alias;
14
14
  }
15
- process(src, options) {
16
- const { fileInfo } = options;
17
- const { filename, currentDirectory: basedir } = fileInfo;
18
- if (!basedir) {
19
- return src;
20
- }
15
+ supports() {
16
+ return true;
17
+ }
18
+ supportsSync() {
19
+ return false;
20
+ }
21
+ async loadFile(filename, currentDirectory, options, environment) {
21
22
  const resolveOpts = {
22
- basedir,
23
+ basedir: currentDirectory,
23
24
  alias: this.alias,
24
25
  platform: this.platform,
25
- logLevel: types_1.LogLevelEnum.WARNING,
26
- defaultExt: path_1.default.extname(filename)
26
+ defaultExt: '.less'
27
27
  };
28
- // 解析 @import "a.less" 字符串里面的内容
29
- src = src.replace(/@import\s+['"]([^'|"]*)['"]/gi, (_, id) => {
30
- const relativePath = path_1.default.relative(basedir, index_1.resolveStyle(id.trim(), resolveOpts)).replace(/\\/g, '/');
31
- return `@import '${relativePath}';`;
32
- });
33
- return src;
28
+ const rewriteFilename = index_1.resolveStyle(filename, resolveOpts);
29
+ return super.loadFile(rewriteFilename, currentDirectory, options, environment);
34
30
  }
35
31
  }
36
32
  function makeLessImport(options) {
37
33
  return {
38
34
  install: (_, pluginManager) => {
39
- pluginManager.addPreProcessor(new Importer(options));
35
+ pluginManager.addFileManager(new Importer(options));
40
36
  },
41
37
  minVersion: [2, 7, 1]
42
38
  };
@@ -1 +1 @@
1
- {"version":3,"file":"lessImport.js","sourceRoot":"","sources":["../../src/utils/lessImport.ts"],"names":[],"mappings":";;;;;AAAA,gDAAuB;AACvB,mCAAsC;AACtC,oCAAuC;AAEvC,MAAM,QAAQ;IACZ,YAAa,GAAG;QAOhB,UAAK,GAA2B,EAAE,CAAA;QANhC,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAA;QAC5B,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAA;IACxB,CAAC;IAMD,OAAO,CAAE,GAAW,EAAE,OAAmC;QACvD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;QAC5B,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAA;QAExD,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,CAAA;SACX;QAED,MAAM,WAAW,GAAG;YAClB,OAAO;YACP,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,oBAAY,CAAC,OAAO;YAC9B,UAAU,EAAE,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;SACnC,CAAA;QAED,+BAA+B;QAC/B,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,+BAA+B,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE;YAC3D,MAAM,YAAY,GAAG,cAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,oBAAY,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;YACrG,OAAO,YAAY,YAAY,IAAI,CAAA;QACrC,CAAC,CAAC,CAAA;QAEF,OAAO,GAAG,CAAA;IACZ,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AAE,aAAa,EAAE,EAAE;YAC5B,aAAa,CAAC,cAAc,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAA;QACrD,CAAC;QACD,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;KACtB,CAAA;AACH,CAAC;AAED,kBAAe,cAAc,CAAA"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function reporterSkip({ skipRows, filename }) {
4
+ // @ts-ignore
5
+ return (css, result) => {
6
+ var _a;
7
+ (_a = result.messages) === null || _a === void 0 ? void 0 : _a.forEach((message) => {
8
+ var _a;
9
+ const { line, column, node } = message;
10
+ const messageInput = (_a = node === null || node === void 0 ? void 0 : node.source) === null || _a === void 0 ? void 0 : _a.input;
11
+ if (messageInput) {
12
+ const originLocation = messageInput.origin(line, column);
13
+ // 如果是原始引入的样式文件,则对拼接的代码(addionalData)函数做减法
14
+ if (originLocation && originLocation.file.includes(filename)) {
15
+ // force modify line,then source map cannot read origin column, value is 0.
16
+ message.line -= skipRows;
17
+ }
18
+ }
19
+ });
20
+ };
21
+ }
22
+ exports.default = reporterSkip;
23
+ //# sourceMappingURL=reporterSkip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporterSkip.js","sourceRoot":"","sources":["../../src/utils/reporterSkip.ts"],"names":[],"mappings":";;AAMA,SAAwB,YAAY,CAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE;IAC1D,aAAa;IACb,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;;QACrB,MAAA,MAAM,CAAC,QAAQ,0CAAE,OAAO,CAAC,CAAC,OAAY,EAAE,EAAE;;YACxC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;YAEtC,MAAM,YAAY,GAAG,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,0CAAE,KAAK,CAAA;YACxC,IAAI,YAAY,EAAE;gBAChB,MAAM,cAAc,GAAa,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;gBAClE,0CAA0C;gBAC1C,IAAI,cAAc,IAAI,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;oBAC5D,2EAA2E;oBAC3E,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAA;iBACzB;aACF;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC;AAjBD,+BAiBC"}
package/jest.config.js CHANGED
@@ -1,7 +1,8 @@
1
1
  module.exports = {
2
2
  verbose: true,
3
3
  transform: {
4
- '^.+\\.js$': 'babel-jest'
4
+ '^.+\\.js$': 'babel-jest',
5
+ '^.+\\.tsx?$': 'ts-jest'
5
6
  },
6
- testPathIgnorePatterns: ['/node_modules/', '/__tests__/mocks/']
7
+ testPathIgnorePatterns: ['/node_modules/']
7
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/rn-style-transformer",
3
- "version": "3.3.6",
3
+ "version": "3.3.10",
4
4
  "description": "提供Taro RN 统一处理样式文件能力",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -23,24 +23,25 @@
23
23
  "npm": ">=6.0.0"
24
24
  },
25
25
  "dependencies": {
26
- "@tarojs/helper": "3.3.6",
26
+ "@tarojs/helper": "3.3.10",
27
27
  "fbjs": "^2.0.0",
28
28
  "less": "^3.12.2",
29
29
  "postcss": "^7.0.35",
30
30
  "postcss-import": "^12.0.1",
31
- "postcss-pxtransform": "3.3.6",
31
+ "postcss-pxtransform": "3.3.10",
32
32
  "postcss-reporter": "^6.0.1",
33
33
  "prop-types": "^15.7.2",
34
34
  "sass": "^1.34.1",
35
35
  "stylelint": "^13.8.0",
36
- "stylelint-config-taro-rn": "3.3.6",
37
- "stylelint-taro-rn": "3.3.6",
36
+ "stylelint-config-taro-rn": "3.3.10",
37
+ "stylelint-taro-rn": "3.3.10",
38
38
  "stylus": "^0.54.8",
39
- "taro-css-to-react-native": "3.3.6"
39
+ "taro-css-to-react-native": "3.3.10"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/less": "^3.0.2",
43
- "@types/postcss-import": "^12.0.0"
43
+ "@types/postcss-import": "^12.0.0",
44
+ "@types/sass": "^1.16.1"
44
45
  },
45
- "gitHead": "c172d1093ed0cbf7c00cfa3d6e8012cae6dfd1fe"
46
+ "gitHead": "2eae6e5dbef3f5f12a64ed52875901550ac21924"
46
47
  }
@@ -2,12 +2,13 @@ import path from 'path'
2
2
  import transformCSS from 'taro-css-to-react-native'
3
3
  import { recursiveMerge, printLog, processTypeEnum } from '@tarojs/helper'
4
4
 
5
- import postcssTransform, { Config as PostcssConfig, getPostcssPlugins } from './postcss'
6
- import sassTransform, { Config as SassConfig, SassExternalConfig, processByExternal } from './sass'
5
+ import postcssTransform, { Config as PostcssConfig, makePostcssPlugins } from './postcss'
6
+ import sassTransform, { Config as SassConfig, SassGlobalConfig } from './sass'
7
7
  import lessTransform, { Config as LessConfig } from './less'
8
8
  import stylusTransform, { Config as StylusConfig, defaultOptions as stylusDefaultOptions } from './stylus'
9
9
  import { StyleSheetValidation } from './StyleSheet'
10
- import { TransformOptions } from '../types'
10
+ import { TransformOptions, RenderAdditionalResult } from '../types'
11
+ import { normalizeSourceMap } from '../utils'
11
12
 
12
13
  export function getWrapedCSS (css) {
13
14
  return `
@@ -38,7 +39,7 @@ function validateStyle ({ styleObject, filename }) {
38
39
  } catch (err) {
39
40
  // 先忽略掉 scalePx2dp 的报错
40
41
  if (/Invalid prop `.*` of type `string` supplied to `.*`, expected `number`[^]*/g.test(err.message)) return
41
- printLog(processTypeEnum.WARNING, err.message, filename)
42
+ printLog(processTypeEnum.WARNING, err.message, `entry file: ${filename}`)
42
43
  }
43
44
  }
44
45
  }
@@ -53,11 +54,20 @@ interface RNConfig {
53
54
  interface Config {
54
55
  designWidth: number;
55
56
  deviceRatio: { [key: number]: number };
56
- sass: SassExternalConfig;
57
+ sass: SassGlobalConfig;
57
58
  alias: Record<string, string>;
58
59
  rn: RNConfig;
59
60
  }
60
61
 
62
+ interface PostcssParam {
63
+ css: string
64
+ map: any
65
+ filename: string
66
+ additionalData: string
67
+ postcssConfig: PostcssConfig
68
+ transformOptions: TransformOptions
69
+ }
70
+
61
71
  const designWidth = 750
62
72
 
63
73
  const deviceRatio = {
@@ -66,7 +76,7 @@ const deviceRatio = {
66
76
  828: 1.81 / 2
67
77
  }
68
78
 
69
- enum StyleTypes {
79
+ const enum ProcessTypes {
70
80
  POSTCSS = 'postcss',
71
81
  SASS = 'sass',
72
82
  LESS = 'less',
@@ -74,17 +84,17 @@ enum StyleTypes {
74
84
  }
75
85
 
76
86
  const DEFAULT_RN_CONFIG = {
77
- [StyleTypes.POSTCSS]: {
87
+ [ProcessTypes.POSTCSS]: {
78
88
  options: {},
79
89
  scalable: true
80
90
  },
81
- [StyleTypes.SASS]: {
91
+ [ProcessTypes.SASS]: {
82
92
  options: {}
83
93
  },
84
- [StyleTypes.LESS]: {
94
+ [ProcessTypes.LESS]: {
85
95
  options: {}
86
96
  },
87
- [StyleTypes.STYLUS]: {
97
+ [ProcessTypes.STYLUS]: {
88
98
  options: stylusDefaultOptions
89
99
  }
90
100
  }
@@ -92,7 +102,7 @@ const DEFAULT_RN_CONFIG = {
92
102
  export default class StyleTransform {
93
103
  config: Config
94
104
 
95
- extConfigMap = new Map()
105
+ processConfigMap = new Map()
96
106
 
97
107
  constructor (config = {}) {
98
108
  this.init(config)
@@ -106,7 +116,26 @@ export default class StyleTransform {
106
116
  alias: config.alias ?? {},
107
117
  rn: recursiveMerge({}, DEFAULT_RN_CONFIG, config.rn)
108
118
  }
109
- Reflect.ownKeys(this.config.rn).forEach(key => this.extConfigMap.set(key, { ...this.config.rn[key], alias: config.alias ?? {} }))
119
+
120
+ Reflect.ownKeys(this.config.rn).forEach((key: string) => {
121
+ if (
122
+ [
123
+ ProcessTypes.SASS,
124
+ ProcessTypes.LESS,
125
+ ProcessTypes.STYLUS,
126
+ ProcessTypes.POSTCSS
127
+ ].includes(key.toLocaleLowerCase() as any)
128
+ ) {
129
+ const processConfig = {
130
+ ...this.config.rn[key],
131
+ alias: config.alias ?? {}
132
+ }
133
+ if (key.toLocaleLowerCase() === ProcessTypes.SASS) {
134
+ processConfig.sass = this.config.sass
135
+ }
136
+ this.processConfigMap.set(key, processConfig)
137
+ }
138
+ })
110
139
  }
111
140
 
112
141
  /**
@@ -116,43 +145,78 @@ export default class StyleTransform {
116
145
  * @param {object} options
117
146
  */
118
147
  async processStyle (src: string, filename: string, options: TransformOptions) {
148
+ let result: undefined | RenderAdditionalResult
119
149
  let css = src
150
+ let map: undefined | string
151
+ let additionalData = ''
120
152
  const ext = path.extname(filename)
121
- if (ext === '.less') {
122
- css = await lessTransform(src, filename, this.extConfigMap.get(StyleTypes.LESS))
123
- } else if (ext === '.sass' || ext === '.scss') {
124
- src = processByExternal(src, filename, this.config.sass)
125
- css = await sassTransform(src, filename, this.extConfigMap.get(StyleTypes.SASS), options)
126
- } else if (ext === '.styl' || ext === '.stylus') {
127
- css = await stylusTransform(src, filename, this.extConfigMap.get(StyleTypes.STYLUS))
153
+ if (/.less$/i.test(ext)) {
154
+ result = await lessTransform(src, filename, this.processConfigMap.get(ProcessTypes.LESS))
155
+ } else if (/.s(c|a)ss$/i.test(ext)) {
156
+ result = await sassTransform(src, filename, this.processConfigMap.get(ProcessTypes.SASS), options)
157
+ } else if (/.styl(us)?$/i.test(ext)) {
158
+ result = await stylusTransform(src, filename, this.processConfigMap.get(ProcessTypes.STYLUS))
159
+ }
160
+
161
+ if (result) {
162
+ css = Buffer.isBuffer(result.css) ? result.css.toString() : result.css
163
+ map = Buffer.isBuffer(result.map) ? result.map.toString() : result.map
164
+ additionalData = result.additionalData
128
165
  }
129
166
 
130
167
  // postcss 插件,比如处理平台特有样式,单位转换
131
- const cssItem = await this.postCSS(css, filename, this.extConfigMap.get(StyleTypes.POSTCSS), options)
132
- return cssItem
168
+ return await this.postCSS({
169
+ css,
170
+ map,
171
+ filename,
172
+ additionalData,
173
+ transformOptions: options,
174
+ postcssConfig: this.processConfigMap.get(ProcessTypes.POSTCSS)
175
+ })
133
176
  }
134
177
 
135
178
  /**
136
- * @description postcss处理
137
- * @param {string} css
138
- * @param {string} filename
139
- * @returns {Function | any}
179
+ * postcss处理
180
+ * @param param0 PostcssParam
181
+ * @returns {Promise | any}
140
182
  */
141
- postCSS (css, filename, postcssConfig: PostcssConfig, transformOptions: TransformOptions) {
142
- const plugins = getPostcssPlugins({
183
+ postCSS ({
184
+ css,
185
+ map,
186
+ filename,
187
+ postcssConfig,
188
+ transformOptions,
189
+ additionalData
190
+ }: PostcssParam) {
191
+ const plugins = makePostcssPlugins({
192
+ filename,
193
+ postcssConfig,
194
+ transformOptions,
143
195
  designWidth: this.config.designWidth,
144
196
  deviceRatio: this.config.deviceRatio,
145
- postcssConfig,
146
- transformOptions
197
+ additionalData: additionalData
147
198
  })
148
199
 
149
- return postcssTransform(css, filename, { options: postcssConfig.options, plugins })
150
- .then(cssString => {
151
- return {
152
- css: cssString,
153
- filename
200
+ return postcssTransform(
201
+ css,
202
+ filename,
203
+ {
204
+ plugins,
205
+ options: {
206
+ ...postcssConfig.options,
207
+ map: map && {
208
+ prev: normalizeSourceMap(map, filename),
209
+ inline: false,
210
+ annotation: false
211
+ }
154
212
  }
155
- })
213
+ }
214
+ ).then(result => {
215
+ return {
216
+ ...result,
217
+ filename
218
+ }
219
+ })
156
220
  }
157
221
 
158
222
  /**
@@ -163,15 +227,23 @@ export default class StyleTransform {
163
227
  * @return {string} JSONString
164
228
  */
165
229
  async transform (src: string, filename: string, options = {} as TransformOptions) {
166
- printLog(processTypeEnum.START, '样式文件处理开始', filename)
167
- const { css: cssSrc } = await this.processStyle(src, filename, options)
168
- // printLog(processTypeEnum.REMIND, cssSrc, filename)
230
+ // printLog(processTypeEnum.START, '样式文件处理开始', filename)
231
+ const result = await this.processStyle(src, filename, options)
232
+
169
233
  // 把 css 转换成对象 rn 的样式,接入 taro 的 css-to-react-native,比如有单位的处理
170
- const styleObject = transformCSS(cssSrc, { parseMediaQueries: true, scalable: this.config.rn.postcss.scalable })
234
+ const styleObject = transformCSS(
235
+ result.css,
236
+ {
237
+ parseMediaQueries: true,
238
+ scalable: this.config.rn.postcss.scalable
239
+ }
240
+ )
241
+
171
242
  // stylelint,转换成对象,对对象进行校验
172
243
  validateStyle({ styleObject, filename })
173
- const css = JSON.stringify(styleObject, null, 2).replace(/"(scalePx2dp\(.*?\))"/g, '$1')
174
- printLog(processTypeEnum.COMPILE, '样式文件处理完毕', filename)
244
+ const css = JSON.stringify(styleObject, null, 2)
245
+ .replace(/"(scalePx2dp\(.*?\))"/g, '$1')
246
+
175
247
  // 注入自适应方法 scalePx2dp
176
248
  return getWrapedCSS(css)
177
249
  }
@@ -1,6 +1,8 @@
1
1
  import path from 'path'
2
2
  import less from 'less'
3
3
  import makeLessImport from '../utils/lessImport'
4
+ import { insertBefore, getAdditionalData } from '../utils'
5
+ import { RenderResult, RenderAdditionalResult } from '../types'
4
6
 
5
7
  interface SourceMapOption {
6
8
  sourceMapURL?: string;
@@ -58,7 +60,7 @@ export interface Options {
58
60
  export interface Config {
59
61
  alias?: Record<string, string>
60
62
  options: Options
61
- additionalData?: string | ((string) => string)
63
+ additionalData?: string | ((key: string) => string)
62
64
  }
63
65
 
64
66
  function renderToCSS (src, filename, options = {} as any) {
@@ -73,26 +75,34 @@ function renderToCSS (src, filename, options = {} as any) {
73
75
  filename,
74
76
  plugins: plugins.concat(options.plugins || []),
75
77
  paths: paths.concat(options.paths || [])
76
- }, (err, output) => {
78
+ }, (err, result) => {
77
79
  if (err) {
78
80
  return reject(err.message)
79
81
  }
80
- resolve(output.css)
82
+ resolve(result)
81
83
  })
82
84
  })
83
85
  }
84
86
 
85
- export default function transform (src: string, filename: string, config: Config) {
86
- let data = src
87
+ export default function transform (
88
+ src: string,
89
+ filename: string,
90
+ config: Config
91
+ ) {
92
+ const additionalData = getAdditionalData(src, config.additionalData)
93
+ const data = insertBefore(src, additionalData)
87
94
 
88
- if (typeof config.additionalData !== 'undefined') {
89
- data =
90
- typeof config.additionalData === 'function'
91
- ? `${config.additionalData(data)}`
92
- : `${config.additionalData}\n${data}`
93
- }
94
- return renderToCSS(data, filename, { ...config.options, alias: config.alias })
95
- .then((css: string) => {
96
- return css
97
- })
95
+ return renderToCSS(
96
+ data,
97
+ filename,
98
+ {
99
+ sourceMap: {
100
+ outputFilename: `${filename}.map`
101
+ },
102
+ alias: config.alias,
103
+ ...config.options
104
+ }
105
+ ).then((result: RenderResult) => {
106
+ return { ...result, additionalData } as RenderAdditionalResult
107
+ })
98
108
  }