@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.
- package/__tests__/config.spec.js +1 -1
- package/__tests__/index.spec.js +12 -1
- package/__tests__/platform.spec.js +1 -1
- package/dist/transforms/index.js +71 -44
- package/dist/transforms/index.js.map +1 -1
- package/dist/transforms/less.js +9 -12
- package/dist/transforms/less.js.map +1 -1
- package/dist/transforms/postcss.js +7 -6
- package/dist/transforms/postcss.js.map +1 -1
- package/dist/transforms/sass.js +16 -24
- package/dist/transforms/sass.js.map +1 -1
- package/dist/transforms/stylus.js +14 -11
- package/dist/transforms/stylus.js.map +1 -1
- package/dist/types/index.js +0 -6
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.js +101 -18
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/lessImport.js +15 -19
- package/dist/utils/lessImport.js.map +1 -1
- package/dist/utils/reporterSkip.js +23 -0
- package/dist/utils/reporterSkip.js.map +1 -0
- package/jest.config.js +3 -2
- package/package.json +9 -8
- package/src/transforms/index.ts +113 -41
- package/src/transforms/less.ts +25 -15
- package/src/transforms/postcss.ts +10 -5
- package/src/transforms/sass.ts +36 -28
- package/src/transforms/stylus.ts +26 -14
- package/src/types/index.ts +10 -1
- package/src/utils/index.ts +112 -13
- package/src/utils/lessImport.ts +23 -24
- package/src/utils/reporterSkip.ts +24 -0
package/__tests__/config.spec.js
CHANGED
package/__tests__/index.spec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import StyleTransform, { getWrapedCSS } from '../
|
|
1
|
+
import StyleTransform, { getWrapedCSS } from '../src/transforms'
|
|
2
2
|
|
|
3
3
|
// 初始化
|
|
4
4
|
const styleTransform = new StyleTransform()
|
|
@@ -181,6 +181,17 @@ describe('style transform', () => {
|
|
|
181
181
|
}`))
|
|
182
182
|
})
|
|
183
183
|
|
|
184
|
+
it('.less tranform node_modules file import', async () => {
|
|
185
|
+
const css = await run(`
|
|
186
|
+
@import 'less/test/browser/css/global-vars/simple.css';
|
|
187
|
+
`, './__tests__/styles/a.less')
|
|
188
|
+
expect(css).toEqual(getWrapedCSS(`{
|
|
189
|
+
"test": {
|
|
190
|
+
"color": "red"
|
|
191
|
+
}
|
|
192
|
+
}`))
|
|
193
|
+
})
|
|
194
|
+
|
|
184
195
|
it('.less import source omit extension', async () => {
|
|
185
196
|
const css = await run(`
|
|
186
197
|
@import './b';
|
package/dist/transforms/index.js
CHANGED
|
@@ -27,10 +27,11 @@ const path_1 = __importDefault(require("path"));
|
|
|
27
27
|
const taro_css_to_react_native_1 = __importDefault(require("taro-css-to-react-native"));
|
|
28
28
|
const helper_1 = require("@tarojs/helper");
|
|
29
29
|
const postcss_1 = __importStar(require("./postcss"));
|
|
30
|
-
const sass_1 =
|
|
30
|
+
const sass_1 = __importDefault(require("./sass"));
|
|
31
31
|
const less_1 = __importDefault(require("./less"));
|
|
32
32
|
const stylus_1 = __importStar(require("./stylus"));
|
|
33
33
|
const StyleSheet_1 = require("./StyleSheet");
|
|
34
|
+
const utils_1 = require("../utils");
|
|
34
35
|
function getWrapedCSS(css) {
|
|
35
36
|
return `
|
|
36
37
|
import { StyleSheet, Dimensions } from 'react-native'
|
|
@@ -62,7 +63,7 @@ function validateStyle({ styleObject, filename }) {
|
|
|
62
63
|
// 先忽略掉 scalePx2dp 的报错
|
|
63
64
|
if (/Invalid prop `.*` of type `string` supplied to `.*`, expected `number`[^]*/g.test(err.message))
|
|
64
65
|
return;
|
|
65
|
-
helper_1.printLog("warning" /* WARNING */, err.message, filename);
|
|
66
|
+
helper_1.printLog("warning" /* WARNING */, err.message, `entry file: ${filename}`);
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
}
|
|
@@ -72,31 +73,24 @@ const deviceRatio = {
|
|
|
72
73
|
750: 1,
|
|
73
74
|
828: 1.81 / 2
|
|
74
75
|
};
|
|
75
|
-
var StyleTypes;
|
|
76
|
-
(function (StyleTypes) {
|
|
77
|
-
StyleTypes["POSTCSS"] = "postcss";
|
|
78
|
-
StyleTypes["SASS"] = "sass";
|
|
79
|
-
StyleTypes["LESS"] = "less";
|
|
80
|
-
StyleTypes["STYLUS"] = "stylus";
|
|
81
|
-
})(StyleTypes || (StyleTypes = {}));
|
|
82
76
|
const DEFAULT_RN_CONFIG = {
|
|
83
|
-
[
|
|
77
|
+
["postcss" /* POSTCSS */]: {
|
|
84
78
|
options: {},
|
|
85
79
|
scalable: true
|
|
86
80
|
},
|
|
87
|
-
[
|
|
81
|
+
["sass" /* SASS */]: {
|
|
88
82
|
options: {}
|
|
89
83
|
},
|
|
90
|
-
[
|
|
84
|
+
["less" /* LESS */]: {
|
|
91
85
|
options: {}
|
|
92
86
|
},
|
|
93
|
-
[
|
|
87
|
+
["stylus" /* STYLUS */]: {
|
|
94
88
|
options: stylus_1.defaultOptions
|
|
95
89
|
}
|
|
96
90
|
};
|
|
97
91
|
class StyleTransform {
|
|
98
92
|
constructor(config = {}) {
|
|
99
|
-
this.
|
|
93
|
+
this.processConfigMap = new Map();
|
|
100
94
|
this.init = (config) => {
|
|
101
95
|
var _a;
|
|
102
96
|
this.config = {
|
|
@@ -106,7 +100,21 @@ class StyleTransform {
|
|
|
106
100
|
alias: (_a = config.alias) !== null && _a !== void 0 ? _a : {},
|
|
107
101
|
rn: helper_1.recursiveMerge({}, DEFAULT_RN_CONFIG, config.rn)
|
|
108
102
|
};
|
|
109
|
-
Reflect.ownKeys(this.config.rn).forEach(
|
|
103
|
+
Reflect.ownKeys(this.config.rn).forEach((key) => {
|
|
104
|
+
var _a;
|
|
105
|
+
if ([
|
|
106
|
+
"sass" /* SASS */,
|
|
107
|
+
"less" /* LESS */,
|
|
108
|
+
"stylus" /* STYLUS */,
|
|
109
|
+
"postcss" /* POSTCSS */
|
|
110
|
+
].includes(key.toLocaleLowerCase())) {
|
|
111
|
+
const processConfig = Object.assign(Object.assign({}, this.config.rn[key]), { alias: (_a = config.alias) !== null && _a !== void 0 ? _a : {} });
|
|
112
|
+
if (key.toLocaleLowerCase() === "sass" /* SASS */) {
|
|
113
|
+
processConfig.sass = this.config.sass;
|
|
114
|
+
}
|
|
115
|
+
this.processConfigMap.set(key, processConfig);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
110
118
|
};
|
|
111
119
|
this.init(config);
|
|
112
120
|
}
|
|
@@ -117,41 +125,58 @@ class StyleTransform {
|
|
|
117
125
|
* @param {object} options
|
|
118
126
|
*/
|
|
119
127
|
async processStyle(src, filename, options) {
|
|
128
|
+
let result;
|
|
120
129
|
let css = src;
|
|
130
|
+
let map;
|
|
131
|
+
let additionalData = '';
|
|
121
132
|
const ext = path_1.default.extname(filename);
|
|
122
|
-
if (ext
|
|
123
|
-
|
|
133
|
+
if (/.less$/i.test(ext)) {
|
|
134
|
+
result = await less_1.default(src, filename, this.processConfigMap.get("less" /* LESS */));
|
|
124
135
|
}
|
|
125
|
-
else if (
|
|
126
|
-
|
|
127
|
-
css = await sass_1.default(src, filename, this.extConfigMap.get(StyleTypes.SASS), options);
|
|
136
|
+
else if (/.s(c|a)ss$/i.test(ext)) {
|
|
137
|
+
result = await sass_1.default(src, filename, this.processConfigMap.get("sass" /* SASS */), options);
|
|
128
138
|
}
|
|
129
|
-
else if (
|
|
130
|
-
|
|
139
|
+
else if (/.styl(us)?$/i.test(ext)) {
|
|
140
|
+
result = await stylus_1.default(src, filename, this.processConfigMap.get("stylus" /* STYLUS */));
|
|
141
|
+
}
|
|
142
|
+
if (result) {
|
|
143
|
+
css = Buffer.isBuffer(result.css) ? result.css.toString() : result.css;
|
|
144
|
+
map = Buffer.isBuffer(result.map) ? result.map.toString() : result.map;
|
|
145
|
+
additionalData = result.additionalData;
|
|
131
146
|
}
|
|
132
147
|
// postcss 插件,比如处理平台特有样式,单位转换
|
|
133
|
-
|
|
134
|
-
|
|
148
|
+
return await this.postCSS({
|
|
149
|
+
css,
|
|
150
|
+
map,
|
|
151
|
+
filename,
|
|
152
|
+
additionalData,
|
|
153
|
+
transformOptions: options,
|
|
154
|
+
postcssConfig: this.processConfigMap.get("postcss" /* POSTCSS */)
|
|
155
|
+
});
|
|
135
156
|
}
|
|
136
157
|
/**
|
|
137
|
-
*
|
|
138
|
-
* @param
|
|
139
|
-
* @
|
|
140
|
-
* @returns {Function | any}
|
|
158
|
+
* postcss处理
|
|
159
|
+
* @param param0 PostcssParam
|
|
160
|
+
* @returns {Promise | any}
|
|
141
161
|
*/
|
|
142
|
-
postCSS(css, filename, postcssConfig, transformOptions) {
|
|
143
|
-
const plugins = postcss_1.
|
|
162
|
+
postCSS({ css, map, filename, postcssConfig, transformOptions, additionalData }) {
|
|
163
|
+
const plugins = postcss_1.makePostcssPlugins({
|
|
164
|
+
filename,
|
|
165
|
+
postcssConfig,
|
|
166
|
+
transformOptions,
|
|
144
167
|
designWidth: this.config.designWidth,
|
|
145
168
|
deviceRatio: this.config.deviceRatio,
|
|
146
|
-
|
|
147
|
-
transformOptions
|
|
169
|
+
additionalData: additionalData
|
|
148
170
|
});
|
|
149
|
-
return postcss_1.default(css, filename, {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
171
|
+
return postcss_1.default(css, filename, {
|
|
172
|
+
plugins,
|
|
173
|
+
options: Object.assign(Object.assign({}, postcssConfig.options), { map: map && {
|
|
174
|
+
prev: utils_1.normalizeSourceMap(map, filename),
|
|
175
|
+
inline: false,
|
|
176
|
+
annotation: false
|
|
177
|
+
} })
|
|
178
|
+
}).then(result => {
|
|
179
|
+
return Object.assign(Object.assign({}, result), { filename });
|
|
155
180
|
});
|
|
156
181
|
}
|
|
157
182
|
/**
|
|
@@ -162,15 +187,17 @@ class StyleTransform {
|
|
|
162
187
|
* @return {string} JSONString
|
|
163
188
|
*/
|
|
164
189
|
async transform(src, filename, options = {}) {
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
// printLog(processTypeEnum.REMIND, cssSrc, filename)
|
|
190
|
+
// printLog(processTypeEnum.START, '样式文件处理开始', filename)
|
|
191
|
+
const result = await this.processStyle(src, filename, options);
|
|
168
192
|
// 把 css 转换成对象 rn 的样式,接入 taro 的 css-to-react-native,比如有单位的处理
|
|
169
|
-
const styleObject = taro_css_to_react_native_1.default(
|
|
193
|
+
const styleObject = taro_css_to_react_native_1.default(result.css, {
|
|
194
|
+
parseMediaQueries: true,
|
|
195
|
+
scalable: this.config.rn.postcss.scalable
|
|
196
|
+
});
|
|
170
197
|
// stylelint,转换成对象,对对象进行校验
|
|
171
198
|
validateStyle({ styleObject, filename });
|
|
172
|
-
const css = JSON.stringify(styleObject, null, 2)
|
|
173
|
-
|
|
199
|
+
const css = JSON.stringify(styleObject, null, 2)
|
|
200
|
+
.replace(/"(scalePx2dp\(.*?\))"/g, '$1');
|
|
174
201
|
// 注入自适应方法 scalePx2dp
|
|
175
202
|
return getWrapedCSS(css);
|
|
176
203
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transforms/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAuB;AACvB,wFAAmD;AACnD,2CAA0E;AAE1E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transforms/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAuB;AACvB,wFAAmD;AACnD,2CAA0E;AAE1E,qDAAyF;AACzF,kDAA8E;AAC9E,kDAA4D;AAC5D,mDAA0G;AAC1G,6CAAmD;AAEnD,oCAA6C;AAE7C,SAAgB,YAAY,CAAE,GAAG;IAC/B,OAAO;;;;;;;;;;;;;;mCAc0B,GAAG;CACrC,CAAA;AACD,CAAC;AAjBD,oCAiBC;AAED;;GAEG;AACH,SAAS,aAAa,CAAE,EAAE,WAAW,EAAE,QAAQ,EAAE;IAC/C,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE;QAC9B,IAAI;YACF,iCAA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V,IAAI,EAAE,0BAAkB,CAAC,GAAG,EAAE,QAAQ,CAAC;oBACvC,MAAM,EAAE,KAAK;oBACb,UAAU,EAAE,KAAK;iBAClB,GACF;SACF,CACF,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YACd,uCACK,MAAM,KACT,QAAQ,IACT;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,SAAS,CAAE,GAAW,EAAE,QAAgB,EAAE,UAAU,EAAsB;QAC9E,wDAAwD;QACxD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;QAE9D,4DAA4D;QAC5D,MAAM,WAAW,GAAG,kCAAY,CAC9B,MAAM,CAAC,GAAG,EACV;YACE,iBAAiB,EAAE,IAAI;YACvB,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ;SAC1C,CACF,CAAA;QAED,0BAA0B;QAC1B,aAAa,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAA;QACxC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;aAC7C,OAAO,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAA;QAE1C,qBAAqB;QACrB,OAAO,YAAY,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC;CACF;AApJD,iCAoJC"}
|
package/dist/transforms/less.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const path_1 = __importDefault(require("path"));
|
|
7
7
|
const less_1 = __importDefault(require("less"));
|
|
8
8
|
const lessImport_1 = __importDefault(require("../utils/lessImport"));
|
|
9
|
+
const utils_1 = require("../utils");
|
|
9
10
|
function renderToCSS(src, filename, options = {}) {
|
|
10
11
|
// default plugins
|
|
11
12
|
const plugins = [lessImport_1.default(options)];
|
|
@@ -13,25 +14,21 @@ function renderToCSS(src, filename, options = {}) {
|
|
|
13
14
|
const paths = [path_1.default.dirname(path_1.default.resolve(process.cwd(), filename))];
|
|
14
15
|
return new Promise((resolve, reject) => {
|
|
15
16
|
less_1.default
|
|
16
|
-
.render(src, Object.assign(Object.assign({}, options), { filename, plugins: plugins.concat(options.plugins || []), paths: paths.concat(options.paths || []) }), (err,
|
|
17
|
+
.render(src, Object.assign(Object.assign({}, options), { filename, plugins: plugins.concat(options.plugins || []), paths: paths.concat(options.paths || []) }), (err, result) => {
|
|
17
18
|
if (err) {
|
|
18
19
|
return reject(err.message);
|
|
19
20
|
}
|
|
20
|
-
resolve(
|
|
21
|
+
resolve(result);
|
|
21
22
|
});
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
25
|
function transform(src, filename, config) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
return renderToCSS(data, filename, Object.assign(Object.assign({}, config.options), { alias: config.alias }))
|
|
33
|
-
.then((css) => {
|
|
34
|
-
return css;
|
|
26
|
+
const additionalData = utils_1.getAdditionalData(src, config.additionalData);
|
|
27
|
+
const data = utils_1.insertBefore(src, additionalData);
|
|
28
|
+
return renderToCSS(data, filename, Object.assign({ sourceMap: {
|
|
29
|
+
outputFilename: `${filename}.map`
|
|
30
|
+
}, alias: config.alias }, config.options)).then((result) => {
|
|
31
|
+
return Object.assign(Object.assign({}, result), { additionalData });
|
|
35
32
|
});
|
|
36
33
|
}
|
|
37
34
|
exports.default = transform;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"less.js","sourceRoot":"","sources":["../../src/transforms/less.ts"],"names":[],"mappings":";;;;;AAAA,gDAAuB;AACvB,gDAAuB;AACvB,qEAAgD;
|
|
1
|
+
{"version":3,"file":"less.js","sourceRoot":"","sources":["../../src/transforms/less.ts"],"names":[],"mappings":";;;;;AAAA,gD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,IAAI,CAAC,CAAC,MAAoB,EAAE,EAAE;QAC9B,OAAO,gCAAK,MAAM,KAAE,cAAc,GAA4B,CAAA;IAChE,CAAC,CAAC,CAAA;AACJ,CAAC;AArBD,4BAqBC"}
|
|
@@ -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.
|
|
6
|
+
exports.makePostcssPlugins = void 0;
|
|
7
7
|
const postcss_1 = __importDefault(require("postcss"));
|
|
8
8
|
const postcss_pxtransform_1 = __importDefault(require("postcss-pxtransform"));
|
|
9
9
|
const postcss_import_1 = __importDefault(require("postcss-import"));
|
|
10
10
|
const helper_1 = require("@tarojs/helper");
|
|
11
11
|
const utils_1 = require("../utils");
|
|
12
|
+
const reporterSkip_1 = __importDefault(require("../utils/reporterSkip"));
|
|
12
13
|
const rn_stylelint_json_1 = __importDefault(require("../config/rn-stylelint.json"));
|
|
13
14
|
const defaultPxtransformOption = {
|
|
14
15
|
enable: true,
|
|
@@ -16,7 +17,7 @@ const defaultPxtransformOption = {
|
|
|
16
17
|
platform: 'rn'
|
|
17
18
|
}
|
|
18
19
|
};
|
|
19
|
-
function
|
|
20
|
+
function makePostcssPlugins({ filename, designWidth, deviceRatio, postcssConfig, transformOptions, additionalData }) {
|
|
20
21
|
if (designWidth) {
|
|
21
22
|
defaultPxtransformOption.config.designWidth = designWidth;
|
|
22
23
|
}
|
|
@@ -34,16 +35,16 @@ function getPostcssPlugins({ designWidth, deviceRatio, postcssConfig, transformO
|
|
|
34
35
|
if (pxtransformOption.enable) {
|
|
35
36
|
plugins.push(postcss_pxtransform_1.default(pxtransformOption.config));
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
+
const skipRows = additionalData ? additionalData.split('\n').length : 0;
|
|
39
|
+
plugins.push(require('stylelint')(rn_stylelint_json_1.default), reporterSkip_1.default({ skipRows, filename }), require('postcss-reporter')({ clearReportedMessages: true }));
|
|
38
40
|
return plugins;
|
|
39
41
|
}
|
|
40
|
-
exports.
|
|
42
|
+
exports.makePostcssPlugins = makePostcssPlugins;
|
|
41
43
|
function transform(src, filename, { options, plugins }) {
|
|
42
44
|
return postcss_1.default(plugins)
|
|
43
45
|
.process(src, Object.assign({ from: filename }, options))
|
|
44
46
|
.then(result => {
|
|
45
|
-
|
|
46
|
-
return css;
|
|
47
|
+
return result;
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
exports.default = transform;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postcss.js","sourceRoot":"","sources":["../../src/transforms/postcss.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAiD;AACjD,8EAA6C;AAC7C,oEAA0C;AAC1C,2CAA+C;AAC/C,oCAAuC;AACvC,oFAAyD;AAWzD,MAAM,wBAAwB,GAE1B;IACF,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE;QACN,QAAQ,EAAE,IAAI;KACf;CACF,CAAA;AAED,SAAgB,
|
|
1
|
+
{"version":3,"file":"postcss.js","sourceRoot":"","sources":["../../src/transforms/postcss.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAiD;AACjD,8EAA6C;AAC7C,oEAA0C;AAC1C,2CAA+C;AAC/C,oCAAuC;AACvC,yEAAgD;AAChD,oFAAyD;AAWzD,MAAM,wBAAwB,GAE1B;IACF,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE;QACN,QAAQ,EAAE,IAAI;KACf;CACF,CAAA;AAED,SAAgB,kBAAkB,CAAE,EAClC,QAAQ,EACR,WAAW,EACX,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,cAAc,EACf;IACC,IAAI,WAAW,EAAE;QACf,wBAAwB,CAAC,MAAM,CAAC,WAAW,GAAG,WAAW,CAAA;KAC1D;IAED,IAAI,WAAW,EAAE;QACf,wBAAwB,CAAC,MAAM,CAAC,WAAW,GAA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AC;AAND,4BAMC"}
|
package/dist/transforms/sass.js
CHANGED
|
@@ -3,7 +3,6 @@ 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.processByExternal = void 0;
|
|
7
6
|
const fs_1 = __importDefault(require("fs"));
|
|
8
7
|
const path_1 = __importDefault(require("path"));
|
|
9
8
|
const sass_1 = __importDefault(require("sass"));
|
|
@@ -18,15 +17,9 @@ function makeURL(resource, rootDir) {
|
|
|
18
17
|
function makeImportStatement(filePath, resource, rootDir) {
|
|
19
18
|
const url = makeURL(resource, rootDir);
|
|
20
19
|
const relativePath = path_1.default.relative(filePath, url).replace(/\\/g, '/'); // fix window path error
|
|
21
|
-
return `@import '
|
|
20
|
+
return `@import './${relativePath}'`;
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
* 处理 additional 配置,比如 config.sass 配置
|
|
25
|
-
* @param src
|
|
26
|
-
* @param filename
|
|
27
|
-
* @returns
|
|
28
|
-
*/
|
|
29
|
-
function processByExternal(src, filename, config) {
|
|
22
|
+
function getGlobalResource(filename, config) {
|
|
30
23
|
var _a;
|
|
31
24
|
let resource = '';
|
|
32
25
|
const projectDirectory = config.projectDirectory || process.cwd();
|
|
@@ -38,10 +31,16 @@ function processByExternal(src, filename, config) {
|
|
|
38
31
|
const resources = ((_a = config.resource) === null || _a === void 0 ? void 0 : _a.map(source => makeImportStatement(filePath, source, projectDirectory))) || [];
|
|
39
32
|
resource = resources.join(';\n');
|
|
40
33
|
}
|
|
41
|
-
|
|
42
|
-
return utils_1.
|
|
34
|
+
// https://taro-docs.jd.com/taro/docs/config-detail/#sassdata, data 覆盖 resurce 配置
|
|
35
|
+
return utils_1.insertAfter(resource, config === null || config === void 0 ? void 0 : config.data);
|
|
36
|
+
}
|
|
37
|
+
function combineResource(src, filename, config) {
|
|
38
|
+
// sass config
|
|
39
|
+
const globalResource = getGlobalResource(filename, config.sass);
|
|
40
|
+
// sass tranform config
|
|
41
|
+
const additionalData = utils_1.getAdditionalData(src, config.additionalData);
|
|
42
|
+
return utils_1.insertAfter(globalResource, additionalData);
|
|
43
43
|
}
|
|
44
|
-
exports.processByExternal = processByExternal;
|
|
45
44
|
function renderToCSS(src, filename, options, transformOptions) {
|
|
46
45
|
const defaultOpts = {
|
|
47
46
|
importer: function (...params) {
|
|
@@ -84,26 +83,19 @@ function renderToCSS(src, filename, options, transformOptions) {
|
|
|
84
83
|
reject(err);
|
|
85
84
|
}
|
|
86
85
|
else {
|
|
87
|
-
|
|
88
|
-
resolve(css);
|
|
86
|
+
resolve(result);
|
|
89
87
|
}
|
|
90
88
|
});
|
|
91
89
|
});
|
|
92
90
|
}
|
|
93
91
|
function transform(src, filename, config, transformOptions) {
|
|
94
|
-
|
|
92
|
+
const additionalData = combineResource(src, filename, config);
|
|
93
|
+
let data = utils_1.insertBefore(src, additionalData);
|
|
95
94
|
if (!data) {
|
|
96
95
|
data = `\n${data}`; // fix empty file error. reference https://github.com/sass/node-sass/blob/91c40a0bf0a3923ab9f91b82dcd479c25486235a/lib/index.js#L430
|
|
97
96
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
typeof config.additionalData === 'function'
|
|
101
|
-
? `${config.additionalData(data)}`
|
|
102
|
-
: `${config.additionalData}\n${data}`;
|
|
103
|
-
}
|
|
104
|
-
return renderToCSS(data, filename, Object.assign(Object.assign({}, config.options), { alias: config.alias }), transformOptions)
|
|
105
|
-
.then((css) => {
|
|
106
|
-
return css;
|
|
97
|
+
return renderToCSS(data, filename, Object.assign({ file: filename, outFile: `${filename}.map`, sourceMap: true, alias: config.alias }, config.options), transformOptions).then((result) => {
|
|
98
|
+
return Object.assign(Object.assign({}, result), { additionalData });
|
|
107
99
|
});
|
|
108
100
|
}
|
|
109
101
|
exports.default = transform;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sass.js","sourceRoot":"","sources":["../../src/transforms/sass.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sass.js","sourceRoot":"","sources":["../../src/transforms/sass.ts"],"names":[],"mappings":";;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,gDAAoC;AACpC,oCAAqF;AAiBrF,SAAS,OAAO,CAAE,QAAgB,EAAE,OAAe;IACjD,MAAM,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC3C,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,EAAE,CAAC,CAAA;KAC5C;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,mBAAmB,CAAE,QAAgB,EAAE,QAAgB,EAAE,OAAe;IAC/E,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACtC,MAAM,YAAY,GAAG,cAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA,CAAC,wBAAwB;IAC9F,OAAO,cAAc,YAAY,GAAG,CAAA;AACtC,CAAC;AAED,SAAS,iBAAiB,CAAE,QAAgB,EAAE,MAAwB;;IACpE,IAAI,QAAQ,GAAG,EAAE,CAAA;IACjB,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG,EAAE,CAAA;IACjE,MAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC,CAAA;IACvE,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;QACvC,QAAQ,GAAG,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAA;KAC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B,MAAc,EACd,gBAAkC;IAElC,MAAM,cAAc,GAAG,eAAe,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC7D,IAAI,IAAI,GAAG,oBAAY,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;IAE5C,IAAI,CAAC,IAAI,EAAE;QACT,IAAI,GAAG,KAAK,IAAI,EAAE,CAAA,CAAC,oIAAoI;KACxJ;IAED,OAAO,WAAW,CAChB,IAAI,EACJ,QAAQ,kBAEN,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,GAAG,QAAQ,MAAM,EAC1B,SAAS,EAAE,IAAI,EACf,KAAK,EAAE,MAAM,CAAC,KAAK,IAChB,MAAM,CAAC,OAAO,GAEnB,gBAAgB,CACjB,CAAC,IAAI,CAAC,CAAC,MAAoB,EAAE,EAAE;QAC9B,OAAO,gCAAK,MAAM,KAAE,cAAc,GAA4B,CAAA;IAChE,CAAC,CAAC,CAAA;AACJ,CAAC;AA3BD,4BA2BC"}
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.defaultOptions = void 0;
|
|
7
7
|
const stylus_1 = __importDefault(require("stylus"));
|
|
8
|
+
const utils_1 = require("../utils");
|
|
8
9
|
class Evaluator {
|
|
9
10
|
}
|
|
10
11
|
exports.defaultOptions = {
|
|
@@ -21,6 +22,11 @@ exports.defaultOptions = {
|
|
|
21
22
|
function renderToCSS(src, filename, options = {}) {
|
|
22
23
|
const stylusOptions = Object.assign({ filename }, options);
|
|
23
24
|
const styl = stylus_1.default(src, stylusOptions);
|
|
25
|
+
styl.set('sourcemap', {
|
|
26
|
+
comment: true,
|
|
27
|
+
sourceRoot: '.',
|
|
28
|
+
basePath: '.'
|
|
29
|
+
});
|
|
24
30
|
// include regular CSS on @import
|
|
25
31
|
if (stylusOptions.includeCSS) {
|
|
26
32
|
styl.set('include css', true);
|
|
@@ -82,22 +88,19 @@ function renderToCSS(src, filename, options = {}) {
|
|
|
82
88
|
reject(err);
|
|
83
89
|
}
|
|
84
90
|
else {
|
|
85
|
-
resolve(
|
|
91
|
+
resolve({
|
|
92
|
+
css,
|
|
93
|
+
map: styl.sourcemap
|
|
94
|
+
});
|
|
86
95
|
}
|
|
87
96
|
});
|
|
88
97
|
});
|
|
89
98
|
}
|
|
90
99
|
function transform(src, filename, config) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
? `${config.additionalData(data)}`
|
|
96
|
-
: `${config.additionalData}\n${data}`;
|
|
97
|
-
}
|
|
98
|
-
return renderToCSS(data, filename, config.options)
|
|
99
|
-
.then((css) => {
|
|
100
|
-
return css;
|
|
100
|
+
const additionalData = utils_1.getAdditionalData(src, config.additionalData);
|
|
101
|
+
const data = utils_1.insertBefore(src, additionalData);
|
|
102
|
+
return renderToCSS(data, filename, config.options).then((result) => {
|
|
103
|
+
return Object.assign(Object.assign({}, result), { additionalData });
|
|
101
104
|
});
|
|
102
105
|
}
|
|
103
106
|
exports.default = transform;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stylus.js","sourceRoot":"","sources":["../../src/transforms/stylus.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAE3B,MAAM,SAAS;CAAI;AAsGN,QAAA,cAAc,GAAG;IAC5B,GAAG,EAAE,EAAE;IACP,OAAO,EAAE,EAAE;IACX,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;IACV,UAAU,EAAE,KAAK;IACjB,kCAAkC;IAClC,WAAW,EAAE,KAAK;IAClB,YAAY,EAAE,KAAK;IACnB,YAAY,EAAE,KAAK;CACpB,CAAA;AAED,SAAS,WAAW,CAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAmB;IAChE,MAAM,aAAa,mBAAK,QAAQ,IAAK,OAAO,CAAE,CAAA;IAC9C,MAAM,IAAI,GAAG,gBAAM,CAAC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I,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACvB,IAAI,GAAG,EAAE;gBACP,MAAM,CAAC,GAAG,CAAC,CAAA;aACZ;iBAAM;gBACL,OAAO,CAAC;oBACN,GAAG;oBACH,GAAG,EAAE,IAAI,CAAC,SAAS;iBACpB,CAAC,CAAA;aACH;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAwB,SAAS,CAAE,GAAW,EAAE,QAAgB,EAAE,MAAc;IAC9E,MAAM,cAAc,GAAG,yBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,cAAc,CAAC,CAAA;IACpE,MAAM,IAAI,GAAG,oBAAY,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;IAE9C,OAAO,WAAW,CAChB,IAAI,EACJ,QAAQ,EACR,MAAM,CAAC,OAAO,CACf,CAAC,IAAI,CAAC,CAAC,MAAoB,EAAE,EAAE;QAC9B,OAAO,gCAAK,MAAM,KAAE,cAAc,GAA4B,CAAA;IAChE,CAAC,CAAC,CAAA;AACJ,CAAC;AAXD,4BAWC"}
|
package/dist/types/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LogLevelEnum = void 0;
|
|
4
|
-
var LogLevelEnum;
|
|
5
|
-
(function (LogLevelEnum) {
|
|
6
|
-
LogLevelEnum["ERROR"] = "error";
|
|
7
|
-
LogLevelEnum["WARNING"] = "warning";
|
|
8
|
-
})(LogLevelEnum = exports.LogLevelEnum || (exports.LogLevelEnum = {}));
|
|
9
3
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|