@tarojs/rn-style-transformer 4.0.0-beta.93 → 4.0.0-beta.94
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/LICENSE +8 -8
- package/dist/index.d.ts +8 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/transforms/StyleSheet/ColorPropType.d.ts +10 -0
- package/dist/transforms/StyleSheet/ColorPropType.js.map +1 -1
- package/dist/transforms/StyleSheet/ImageResizeMode.d.ts +6 -0
- package/dist/transforms/StyleSheet/ImageStylePropTypes.d.ts +128 -0
- package/dist/transforms/StyleSheet/ImageStylePropTypes.js +1 -1
- package/dist/transforms/StyleSheet/ImageStylePropTypes.js.map +1 -1
- package/dist/transforms/StyleSheet/LayoutPropTypes.d.ts +388 -0
- package/dist/transforms/StyleSheet/ShadowPropTypesIOS.d.ts +45 -0
- package/dist/transforms/StyleSheet/ShadowPropTypesIOS.js +1 -1
- package/dist/transforms/StyleSheet/ShadowPropTypesIOS.js.map +1 -1
- package/dist/transforms/StyleSheet/StyleSheetValidation.d.ts +15 -0
- package/dist/transforms/StyleSheet/StyleSheetValidation.js +1 -1
- package/dist/transforms/StyleSheet/StyleSheetValidation.js.map +1 -1
- package/dist/transforms/StyleSheet/TextStylePropTypes.d.ts +191 -0
- package/dist/transforms/StyleSheet/TextStylePropTypes.js +1 -1
- package/dist/transforms/StyleSheet/TextStylePropTypes.js.map +1 -1
- package/dist/transforms/StyleSheet/TransformPropTypes.d.ts +67 -0
- package/dist/transforms/StyleSheet/TransformPropTypes.js.map +1 -1
- package/dist/transforms/StyleSheet/ViewStylePropTypes.d.ts +136 -0
- package/dist/transforms/StyleSheet/ViewStylePropTypes.js +1 -1
- package/dist/transforms/StyleSheet/ViewStylePropTypes.js.map +1 -1
- package/dist/transforms/StyleSheet/deprecatedPropType.d.ts +13 -0
- package/dist/transforms/StyleSheet/deprecatedPropType.js.map +1 -1
- package/dist/transforms/StyleSheet/index.d.ts +2 -0
- package/dist/transforms/StyleSheet/normalizeColor.d.ts +10 -0
- package/dist/transforms/StyleSheet/normalizeColor.js.map +1 -1
- package/dist/transforms/index.d.ts +56 -0
- package/dist/transforms/index.js +5 -5
- package/dist/transforms/index.js.map +1 -1
- package/dist/transforms/less.d.ts +2 -0
- package/dist/transforms/less.js.map +1 -1
- package/dist/transforms/postcss.d.ts +13 -0
- package/dist/transforms/postcss.js +5 -1
- package/dist/transforms/postcss.js.map +1 -1
- package/dist/transforms/sass.d.ts +2 -0
- package/dist/transforms/sass.js +3 -0
- package/dist/transforms/sass.js.map +1 -1
- package/dist/transforms/stylus.d.ts +3 -0
- package/dist/transforms/stylus.js +1 -1
- package/dist/transforms/stylus.js.map +1 -1
- package/dist/types/index.d.ts +206 -0
- package/dist/utils/index.d.ts +21 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/lessImport.d.ts +5 -0
- package/dist/utils/reporterSkip.d.ts +7 -0
- package/dist/utils/reporterSkip.js.map +1 -1
- package/package.json +32 -31
- package/.eslintrc.js +0 -8
- package/__tests__/config.spec.js +0 -203
- package/__tests__/index.spec.js +0 -252
- package/__tests__/platform.spec.js +0 -78
- package/__tests__/styles/b.css +0 -3
- package/__tests__/styles/b.less +0 -3
- package/__tests__/styles/b.rn.css +0 -3
- package/__tests__/styles/b.scss +0 -3
- package/__tests__/styles/b.styl +0 -3
- package/__tests__/styles/c.css +0 -3
- package/__tests__/styles/c.less +0 -5
- package/__tests__/styles/c.rn.scss +0 -5
- package/__tests__/styles/c.scss +0 -5
- package/__tests__/styles/d.rn.scss +0 -3
- package/__tests__/styles/d.scss +0 -3
- package/__tests__/styles/mixins.scss +0 -18
- package/__tests__/styles/nest.rn.less +0 -3
- package/__tests__/styles/variable.scss +0 -1
- package/babel.config.js +0 -12
- package/jest.config.js +0 -8
- package/src/config/rn-stylelint.json +0 -5
- package/src/index.ts +0 -52
- package/src/transforms/StyleSheet/ColorPropType.ts +0 -76
- package/src/transforms/StyleSheet/ImageResizeMode.ts +0 -50
- package/src/transforms/StyleSheet/ImageStylePropTypes.ts +0 -62
- package/src/transforms/StyleSheet/LayoutPropTypes.ts +0 -559
- package/src/transforms/StyleSheet/ShadowPropTypesIOS.ts +0 -48
- package/src/transforms/StyleSheet/StyleSheetValidation.ts +0 -81
- package/src/transforms/StyleSheet/TextStylePropTypes.ts +0 -123
- package/src/transforms/StyleSheet/TransformPropTypes.ts +0 -109
- package/src/transforms/StyleSheet/ViewStylePropTypes.ts +0 -61
- package/src/transforms/StyleSheet/deprecatedPropType.ts +0 -31
- package/src/transforms/StyleSheet/index.ts +0 -5
- package/src/transforms/StyleSheet/normalizeColor.ts +0 -369
- package/src/transforms/index.ts +0 -229
- package/src/transforms/less.ts +0 -50
- package/src/transforms/postcss.ts +0 -95
- package/src/transforms/sass.ts +0 -148
- package/src/transforms/stylus.ts +0 -124
- package/src/types/index.ts +0 -242
- package/src/utils/index.ts +0 -229
- package/src/utils/lessImport.ts +0 -50
- package/src/utils/reporterSkip.ts +0 -27
- package/tsconfig.json +0 -12
package/package.json
CHANGED
|
@@ -1,55 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/rn-style-transformer",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
4
|
-
"description": "提供Taro RN 统一处理样式文件能力",
|
|
3
|
+
"version": "4.0.0-beta.94",
|
|
4
|
+
"description": "提供 Taro RN 统一处理样式文件能力",
|
|
5
|
+
"author": "O2Team",
|
|
6
|
+
"license": "MIT",
|
|
5
7
|
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
6
12
|
"repository": {
|
|
7
13
|
"type": "git",
|
|
8
14
|
"url": "git+https://github.com/NervJS/taro.git"
|
|
9
15
|
},
|
|
10
|
-
"license": "MIT",
|
|
11
16
|
"bugs": {
|
|
12
17
|
"url": "https://github.com/NervJS/taro/issues"
|
|
13
18
|
},
|
|
14
19
|
"engines": {
|
|
15
|
-
"node": ">= 18"
|
|
16
|
-
"npm": ">= 6"
|
|
20
|
+
"node": ">= 18"
|
|
17
21
|
},
|
|
18
22
|
"dependencies": {
|
|
19
|
-
"@babel/core": "^7.14.5",
|
|
20
|
-
"fbjs": "^2.0.0",
|
|
21
|
-
"less": "^3.12.2",
|
|
22
23
|
"@react-native/metro-babel-transformer": "^0.73.2",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"postcss-pxtransform": "4.0.0-beta.
|
|
34
|
-
"
|
|
24
|
+
"fbjs": "^3.0.5",
|
|
25
|
+
"less": "^4.2.0",
|
|
26
|
+
"postcss-import": "^16.1.0",
|
|
27
|
+
"postcss-reporter": "^7.1.0",
|
|
28
|
+
"prop-types": "^15.8.1",
|
|
29
|
+
"resolve": "^1.22.8",
|
|
30
|
+
"sass": "^1.75.0",
|
|
31
|
+
"stylelint": "^16.4.0",
|
|
32
|
+
"stylus": "^0.63.0",
|
|
33
|
+
"@tarojs/helper": "4.0.0-beta.94",
|
|
34
|
+
"postcss-pxtransform": "4.0.0-beta.94",
|
|
35
|
+
"stylelint-config-taro-rn": "4.0.0-beta.94",
|
|
36
|
+
"stylelint-taro-rn": "4.0.0-beta.94",
|
|
37
|
+
"taro-css-to-react-native": "4.0.0-beta.94"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
37
|
-
"babel
|
|
38
|
-
"
|
|
39
|
-
"jest-cli": "^29.3.1",
|
|
40
|
-
"postcss": "^8.4.18",
|
|
41
|
-
"ts-jest": "^29.0.5",
|
|
42
|
-
"typescript": "^4.7.4"
|
|
40
|
+
"@babel/core": "^7.14.5",
|
|
41
|
+
"postcss": "^8.4.38"
|
|
43
42
|
},
|
|
44
43
|
"peerDependencies": {
|
|
45
|
-
"postcss": "
|
|
44
|
+
"postcss": ">= 8"
|
|
46
45
|
},
|
|
47
46
|
"scripts": {
|
|
47
|
+
"prod": "pnpm run build",
|
|
48
|
+
"prebuild": "pnpm run clean",
|
|
49
|
+
"clean": "rimraf --impl=move-remove ./dist",
|
|
48
50
|
"build": "tsc",
|
|
49
51
|
"dev": "tsc -w",
|
|
50
|
-
"lint": "eslint .",
|
|
51
|
-
"test": "
|
|
52
|
-
"test:ci": "
|
|
53
|
-
"test:clear": "jest --clearCache"
|
|
52
|
+
"lint": "eslint src __tests__ --ext .js,.ts",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"test:ci": "vitest run --coverage"
|
|
54
55
|
}
|
|
55
56
|
}
|
package/.eslintrc.js
DELETED
package/__tests__/config.spec.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { recursiveMerge } from '@tarojs/helper'
|
|
2
|
-
import * as path from 'path'
|
|
3
|
-
|
|
4
|
-
import StyleTransform, { getWrapedCSS } from '../src/transforms'
|
|
5
|
-
|
|
6
|
-
const defaultConfig = {
|
|
7
|
-
designWidth: 750,
|
|
8
|
-
deviceRatio: {
|
|
9
|
-
640: 2.34 / 2,
|
|
10
|
-
750: 1,
|
|
11
|
-
828: 1.81 / 2
|
|
12
|
-
},
|
|
13
|
-
alias: {
|
|
14
|
-
'@': path.resolve(__dirname, './styles')
|
|
15
|
-
},
|
|
16
|
-
rn: {
|
|
17
|
-
postcss: {
|
|
18
|
-
options: {
|
|
19
|
-
plugins: []
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
sass: {
|
|
23
|
-
options: {},
|
|
24
|
-
additionalData: ''
|
|
25
|
-
},
|
|
26
|
-
less: {
|
|
27
|
-
options: {},
|
|
28
|
-
additionalData: ''
|
|
29
|
-
},
|
|
30
|
-
stylus: {
|
|
31
|
-
options: {},
|
|
32
|
-
additionalData: ''
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function run (src, filename = './__tests__/styles/a.css', debug) {
|
|
38
|
-
let options = { platform: 'android' }
|
|
39
|
-
let config
|
|
40
|
-
|
|
41
|
-
if (typeof src === 'object') {
|
|
42
|
-
({
|
|
43
|
-
src,
|
|
44
|
-
filename = './__tests__/styles/a.css',
|
|
45
|
-
options = { platform: 'android' },
|
|
46
|
-
debug,
|
|
47
|
-
config
|
|
48
|
-
} = src || {})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const mergeConfig = recursiveMerge({}, defaultConfig, config)
|
|
52
|
-
// console.log('mergeConfig', JSON.stringify(mergeConfig, null, ' '))
|
|
53
|
-
const styleTransform = new StyleTransform(mergeConfig)
|
|
54
|
-
const css = await styleTransform.transform(src, filename, options)
|
|
55
|
-
if (debug) {
|
|
56
|
-
// eslint-disable-next-line
|
|
57
|
-
console.log(filename + ' source: ', src)
|
|
58
|
-
// eslint-disable-next-line
|
|
59
|
-
console.log(filename + ' target: ', css)
|
|
60
|
-
}
|
|
61
|
-
return css
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
describe('style transform with config options', () => {
|
|
65
|
-
it('config.sass option', async () => {
|
|
66
|
-
const css = await run({
|
|
67
|
-
src: `
|
|
68
|
-
.test {
|
|
69
|
-
color: $base-color;
|
|
70
|
-
height: 10px;
|
|
71
|
-
}
|
|
72
|
-
`,
|
|
73
|
-
config: {
|
|
74
|
-
sass: {
|
|
75
|
-
resource: [
|
|
76
|
-
'__tests__/styles/variable.scss',
|
|
77
|
-
'__tests__/styles/b.css'
|
|
78
|
-
],
|
|
79
|
-
projectDirectory: path.resolve(__dirname, '..'),
|
|
80
|
-
data: '.data { width: 200px }'
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
filename: './__tests__/styles/a.scss'
|
|
84
|
-
})
|
|
85
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
86
|
-
"brn": {
|
|
87
|
-
"color": "red"
|
|
88
|
-
},
|
|
89
|
-
"data": {
|
|
90
|
-
"width": scalePx2dp(100)
|
|
91
|
-
},
|
|
92
|
-
"test": {
|
|
93
|
-
"color": "#c6538c",
|
|
94
|
-
"height": scalePx2dp(5)
|
|
95
|
-
}
|
|
96
|
-
}`))
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('config.sass option without projectDirectory', async () => {
|
|
100
|
-
const css = await run({
|
|
101
|
-
src: `
|
|
102
|
-
.test {
|
|
103
|
-
color: $base-color;
|
|
104
|
-
height: 10px;
|
|
105
|
-
}
|
|
106
|
-
`,
|
|
107
|
-
filename: './__tests__/styles/a.scss',
|
|
108
|
-
config: {
|
|
109
|
-
sass: {
|
|
110
|
-
resource: [
|
|
111
|
-
path.resolve(__dirname, 'styles/variable.scss'),
|
|
112
|
-
path.resolve(__dirname, 'styles/b.css')
|
|
113
|
-
],
|
|
114
|
-
projectDirectory: path.resolve(__dirname, '..'),
|
|
115
|
-
data: '.data { width: 200px }'
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
120
|
-
"brn": {
|
|
121
|
-
"color": "red"
|
|
122
|
-
},
|
|
123
|
-
"data": {
|
|
124
|
-
"width": scalePx2dp(100)
|
|
125
|
-
},
|
|
126
|
-
"test": {
|
|
127
|
-
"color": "#c6538c",
|
|
128
|
-
"height": scalePx2dp(5)
|
|
129
|
-
}
|
|
130
|
-
}`))
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
it('config.postcss disable pxTransform', async () => {
|
|
134
|
-
const css = await run(`
|
|
135
|
-
.test {
|
|
136
|
-
height: 10px;
|
|
137
|
-
}
|
|
138
|
-
`)
|
|
139
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
140
|
-
"test": {
|
|
141
|
-
"height": scalePx2dp(5)
|
|
142
|
-
}
|
|
143
|
-
}`))
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
it('config.postcss disable scalePx2dp', async () => {
|
|
147
|
-
const config = {
|
|
148
|
-
rn: {
|
|
149
|
-
postcss: {
|
|
150
|
-
options: {
|
|
151
|
-
plugins: []
|
|
152
|
-
},
|
|
153
|
-
scalable: false
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
const css = await run({
|
|
158
|
-
src: `
|
|
159
|
-
.test {
|
|
160
|
-
height: 10px;
|
|
161
|
-
}
|
|
162
|
-
`,
|
|
163
|
-
config
|
|
164
|
-
})
|
|
165
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
166
|
-
"test": {
|
|
167
|
-
"height": 5
|
|
168
|
-
}
|
|
169
|
-
}`))
|
|
170
|
-
})
|
|
171
|
-
it('config.alias in css', async () => {
|
|
172
|
-
const css = await run("@import '@/b.css';")
|
|
173
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
174
|
-
"brn": {
|
|
175
|
-
"color": "red"
|
|
176
|
-
}
|
|
177
|
-
}`))
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
it('config.alias in sass', async () => {
|
|
181
|
-
const css = await run({
|
|
182
|
-
src: "@import '@/b.scss';",
|
|
183
|
-
filename: './__tests__/styles/a.scss'
|
|
184
|
-
})
|
|
185
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
186
|
-
"b": {
|
|
187
|
-
"color": "red"
|
|
188
|
-
}
|
|
189
|
-
}`))
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
it('config.alias in less', async () => {
|
|
193
|
-
const css = await run({
|
|
194
|
-
src: "@import '@/b.less';",
|
|
195
|
-
filename: './__tests__/styles/a.less'
|
|
196
|
-
})
|
|
197
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
198
|
-
"b": {
|
|
199
|
-
"color": "red"
|
|
200
|
-
}
|
|
201
|
-
}`))
|
|
202
|
-
})
|
|
203
|
-
})
|
package/__tests__/index.spec.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import StyleTransform, { getWrapedCSS } from '../src/transforms'
|
|
2
|
-
|
|
3
|
-
// 初始化
|
|
4
|
-
const styleTransform = new StyleTransform({})
|
|
5
|
-
|
|
6
|
-
async function run (src, filename = './__tests__/styles/a.css', debug) {
|
|
7
|
-
let options = { platform: 'android' }
|
|
8
|
-
|
|
9
|
-
if (typeof src === 'object') {
|
|
10
|
-
({
|
|
11
|
-
src,
|
|
12
|
-
filename = './__tests__/styles/a.css',
|
|
13
|
-
options = { platform: 'android' },
|
|
14
|
-
debug
|
|
15
|
-
} = src || {})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const css = await styleTransform.transform(src, filename, options)
|
|
19
|
-
if (debug) {
|
|
20
|
-
// eslint-disable-next-line
|
|
21
|
-
console.log(filename + ' source: ', src)
|
|
22
|
-
// eslint-disable-next-line
|
|
23
|
-
console.log(filename + ' target: ', css)
|
|
24
|
-
}
|
|
25
|
-
return css
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe('style transform', () => {
|
|
29
|
-
it('.css transform basic', async () => {
|
|
30
|
-
const css = await run(`
|
|
31
|
-
.test {
|
|
32
|
-
color: red;
|
|
33
|
-
height: 10px;
|
|
34
|
-
}
|
|
35
|
-
`)
|
|
36
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
37
|
-
"test": {
|
|
38
|
-
"color": "red",
|
|
39
|
-
"height": scalePx2dp(5)
|
|
40
|
-
}
|
|
41
|
-
}`))
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('.css transform viewport unit', async () => {
|
|
45
|
-
const css = await run(`
|
|
46
|
-
.test {
|
|
47
|
-
height: 10vh;
|
|
48
|
-
}
|
|
49
|
-
`)
|
|
50
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
51
|
-
"test": {
|
|
52
|
-
"height": scaleVu2dp(10, 'vh')
|
|
53
|
-
},
|
|
54
|
-
"__viewportUnits": true
|
|
55
|
-
}`))
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('.css transform @import', async () => {
|
|
59
|
-
const css = await run(`
|
|
60
|
-
@import './b.css';
|
|
61
|
-
.test {
|
|
62
|
-
color: red;
|
|
63
|
-
}
|
|
64
|
-
`)
|
|
65
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
66
|
-
"brn": {
|
|
67
|
-
"color": "red"
|
|
68
|
-
},
|
|
69
|
-
"test": {
|
|
70
|
-
"color": "red"
|
|
71
|
-
}
|
|
72
|
-
}`))
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('.css import source omit extension', async () => {
|
|
76
|
-
const css = await run("@import './b';", './__tests__/styles/a.css')
|
|
77
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
78
|
-
"brn": {
|
|
79
|
-
"color": "red"
|
|
80
|
-
}
|
|
81
|
-
}`))
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('.sass transform basic', async () => {
|
|
85
|
-
const css = await run(`
|
|
86
|
-
.test {
|
|
87
|
-
color: red;
|
|
88
|
-
}
|
|
89
|
-
`, './__tests__/styles/a.scss')
|
|
90
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
91
|
-
"test": {
|
|
92
|
-
"color": "red"
|
|
93
|
-
}
|
|
94
|
-
}`))
|
|
95
|
-
})
|
|
96
|
-
//
|
|
97
|
-
it('.sass transform @import', async () => {
|
|
98
|
-
const css = await run(`
|
|
99
|
-
@import './b.scss';
|
|
100
|
-
.test {
|
|
101
|
-
color: red;
|
|
102
|
-
}
|
|
103
|
-
`, './__tests__/styles/a.scss')
|
|
104
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
105
|
-
"b": {
|
|
106
|
-
"color": "red"
|
|
107
|
-
},
|
|
108
|
-
"test": {
|
|
109
|
-
"color": "red"
|
|
110
|
-
}
|
|
111
|
-
}`))
|
|
112
|
-
})
|
|
113
|
-
it('.sass transform @import css file', async () => {
|
|
114
|
-
const css = await run(`
|
|
115
|
-
@import './c.css';
|
|
116
|
-
.test {
|
|
117
|
-
color: red;
|
|
118
|
-
}
|
|
119
|
-
`, './__tests__/styles/a.scss')
|
|
120
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
121
|
-
"c": {
|
|
122
|
-
"color": "red"
|
|
123
|
-
},
|
|
124
|
-
"test": {
|
|
125
|
-
"color": "red"
|
|
126
|
-
}
|
|
127
|
-
}`))
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
it('.sass transform @import with mixins', async () => {
|
|
131
|
-
const css = await run(`
|
|
132
|
-
@import './mixins.scss';
|
|
133
|
-
.test {
|
|
134
|
-
color: red;
|
|
135
|
-
@include hairline(width);
|
|
136
|
-
}
|
|
137
|
-
`, './__tests__/styles/a.scss')
|
|
138
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
139
|
-
"test": {
|
|
140
|
-
"color": "red",
|
|
141
|
-
"width": scalePx2dp(0.5)
|
|
142
|
-
}
|
|
143
|
-
}`))
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
it('.sass import source omit extension', async () => {
|
|
147
|
-
const css = await run("@import './b';", './__tests__/styles/a.scss')
|
|
148
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
149
|
-
"b": {
|
|
150
|
-
"color": "red"
|
|
151
|
-
}
|
|
152
|
-
}`))
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
it('.less transform basic', async () => {
|
|
156
|
-
const css = await run(`
|
|
157
|
-
.test {
|
|
158
|
-
color: red;
|
|
159
|
-
}
|
|
160
|
-
`, './__tests__/styles/a.less')
|
|
161
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
162
|
-
"test": {
|
|
163
|
-
"color": "red"
|
|
164
|
-
}
|
|
165
|
-
}`))
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
it('.less transform @import', async () => {
|
|
169
|
-
const css = await run(`
|
|
170
|
-
@import './b.less';
|
|
171
|
-
.test {
|
|
172
|
-
color: red;
|
|
173
|
-
}
|
|
174
|
-
`, './__tests__/styles/a.less')
|
|
175
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
176
|
-
"b": {
|
|
177
|
-
"color": "red"
|
|
178
|
-
},
|
|
179
|
-
"test": {
|
|
180
|
-
"color": "red"
|
|
181
|
-
}
|
|
182
|
-
}`))
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
it('.less tranform nest import', async () => {
|
|
186
|
-
const css = await run(`
|
|
187
|
-
@import './c.less';
|
|
188
|
-
.test {
|
|
189
|
-
color: red;
|
|
190
|
-
}
|
|
191
|
-
`, './__tests__/styles/a.less')
|
|
192
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
193
|
-
"nest": {
|
|
194
|
-
"color": "red"
|
|
195
|
-
},
|
|
196
|
-
"c": {
|
|
197
|
-
"color": "red"
|
|
198
|
-
},
|
|
199
|
-
"test": {
|
|
200
|
-
"color": "red"
|
|
201
|
-
}
|
|
202
|
-
}`))
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
it('.less tranform node_modules file import', async () => {
|
|
206
|
-
const css = await run("@import 'less/test/browser/css/global-vars/simple.css';", './__tests__/styles/a.less')
|
|
207
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
208
|
-
"test": {
|
|
209
|
-
"color": "red"
|
|
210
|
-
}
|
|
211
|
-
}`))
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
it('.less import source omit extension', async () => {
|
|
215
|
-
const css = await run("@import './b';", './__tests__/styles/a.less')
|
|
216
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
217
|
-
"b": {
|
|
218
|
-
"color": "red"
|
|
219
|
-
}
|
|
220
|
-
}`))
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
it('.styl transform basic', async () => {
|
|
224
|
-
const css = await run(`
|
|
225
|
-
.test {
|
|
226
|
-
color: red;
|
|
227
|
-
}
|
|
228
|
-
`, './__tests__/styles/a.styl')
|
|
229
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
230
|
-
"test": {
|
|
231
|
-
"color": "#f00"
|
|
232
|
-
}
|
|
233
|
-
}`))
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
it('.styl transform @import', async () => {
|
|
237
|
-
const css = await run(`
|
|
238
|
-
@import './b.styl';
|
|
239
|
-
.test {
|
|
240
|
-
color: red;
|
|
241
|
-
}
|
|
242
|
-
`, './__tests__/styles/a.styl')
|
|
243
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
244
|
-
"b": {
|
|
245
|
-
"color": "#f00"
|
|
246
|
-
},
|
|
247
|
-
"test": {
|
|
248
|
-
"color": "#f00"
|
|
249
|
-
}
|
|
250
|
-
}`))
|
|
251
|
-
})
|
|
252
|
-
})
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import StyleTransform, { getWrapedCSS } from '../src/transforms'
|
|
2
|
-
|
|
3
|
-
// 初始化config
|
|
4
|
-
const styleTransform = new StyleTransform({})
|
|
5
|
-
|
|
6
|
-
async function run (src, filename = './__tests__/styles/a.css', options = { platform: 'android' }, debug) {
|
|
7
|
-
if (typeof src === 'object') {
|
|
8
|
-
({
|
|
9
|
-
src,
|
|
10
|
-
filename = './__tests__/styles/a.css',
|
|
11
|
-
options = { platform: 'android' },
|
|
12
|
-
debug
|
|
13
|
-
} = src || {})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const css = await styleTransform.transform(src, filename, options)
|
|
17
|
-
if (debug) {
|
|
18
|
-
// eslint-disable-next-line
|
|
19
|
-
console.log(filename + ' source: ', src)
|
|
20
|
-
// eslint-disable-next-line
|
|
21
|
-
console.log(filename + ' target: ', css)
|
|
22
|
-
}
|
|
23
|
-
return css
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe('style transform in cross platform', () => {
|
|
27
|
-
it('postcss cross platform conditional compile', async () => {
|
|
28
|
-
const css = await run(`
|
|
29
|
-
.test {
|
|
30
|
-
color: red;
|
|
31
|
-
}
|
|
32
|
-
/* #ifdef rn */
|
|
33
|
-
.rn { width: 100px }
|
|
34
|
-
/* #endif */
|
|
35
|
-
/* #ifndef rn */
|
|
36
|
-
.h5 { errSet: 100px }
|
|
37
|
-
/* #endif */
|
|
38
|
-
`)
|
|
39
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
40
|
-
"test": {
|
|
41
|
-
"color": "red"
|
|
42
|
-
},
|
|
43
|
-
"rn": {
|
|
44
|
-
"width": scalePx2dp(50)
|
|
45
|
-
}
|
|
46
|
-
}`))
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('not surport style', async () => {
|
|
50
|
-
const css = await run(`
|
|
51
|
-
.test {
|
|
52
|
-
o: 0.5;
|
|
53
|
-
background: red;
|
|
54
|
-
}
|
|
55
|
-
`)
|
|
56
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
57
|
-
"test": {
|
|
58
|
-
"o": 0.5,
|
|
59
|
-
"backgroundColor": "red"
|
|
60
|
-
}
|
|
61
|
-
}`))
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('nest sass import cross platform', async () => {
|
|
65
|
-
const css = await run({
|
|
66
|
-
filename: './__tests__/styles/a.scss',
|
|
67
|
-
src: "@import './c.scss';"
|
|
68
|
-
})
|
|
69
|
-
expect(css).toEqual(getWrapedCSS(`{
|
|
70
|
-
"drn": {
|
|
71
|
-
"color": "red"
|
|
72
|
-
},
|
|
73
|
-
"crn": {
|
|
74
|
-
"color": "red"
|
|
75
|
-
}
|
|
76
|
-
}`))
|
|
77
|
-
})
|
|
78
|
-
})
|
package/__tests__/styles/b.css
DELETED
package/__tests__/styles/b.less
DELETED
package/__tests__/styles/b.scss
DELETED
package/__tests__/styles/b.styl
DELETED
package/__tests__/styles/c.css
DELETED
package/__tests__/styles/c.less
DELETED
package/__tests__/styles/c.scss
DELETED
package/__tests__/styles/d.scss
DELETED