@tarojs/rn-style-transformer 4.0.0-beta.75 → 4.0.0-beta.77

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.
Files changed (94) hide show
  1. package/LICENSE +1 -8
  2. package/dist/index.d.ts +8 -0
  3. package/dist/index.js +3 -3
  4. package/dist/index.js.map +1 -1
  5. package/dist/transforms/StyleSheet/ColorPropType.d.ts +10 -0
  6. package/dist/transforms/StyleSheet/ColorPropType.js.map +1 -1
  7. package/dist/transforms/StyleSheet/ImageResizeMode.d.ts +6 -0
  8. package/dist/transforms/StyleSheet/ImageStylePropTypes.d.ts +128 -0
  9. package/dist/transforms/StyleSheet/ImageStylePropTypes.js +1 -1
  10. package/dist/transforms/StyleSheet/ImageStylePropTypes.js.map +1 -1
  11. package/dist/transforms/StyleSheet/LayoutPropTypes.d.ts +388 -0
  12. package/dist/transforms/StyleSheet/ShadowPropTypesIOS.d.ts +45 -0
  13. package/dist/transforms/StyleSheet/ShadowPropTypesIOS.js +1 -1
  14. package/dist/transforms/StyleSheet/ShadowPropTypesIOS.js.map +1 -1
  15. package/dist/transforms/StyleSheet/StyleSheetValidation.d.ts +15 -0
  16. package/dist/transforms/StyleSheet/StyleSheetValidation.js +1 -1
  17. package/dist/transforms/StyleSheet/StyleSheetValidation.js.map +1 -1
  18. package/dist/transforms/StyleSheet/TextStylePropTypes.d.ts +191 -0
  19. package/dist/transforms/StyleSheet/TextStylePropTypes.js +1 -1
  20. package/dist/transforms/StyleSheet/TextStylePropTypes.js.map +1 -1
  21. package/dist/transforms/StyleSheet/TransformPropTypes.d.ts +67 -0
  22. package/dist/transforms/StyleSheet/TransformPropTypes.js.map +1 -1
  23. package/dist/transforms/StyleSheet/ViewStylePropTypes.d.ts +136 -0
  24. package/dist/transforms/StyleSheet/ViewStylePropTypes.js +1 -1
  25. package/dist/transforms/StyleSheet/ViewStylePropTypes.js.map +1 -1
  26. package/dist/transforms/StyleSheet/deprecatedPropType.d.ts +13 -0
  27. package/dist/transforms/StyleSheet/deprecatedPropType.js.map +1 -1
  28. package/dist/transforms/StyleSheet/index.d.ts +2 -0
  29. package/dist/transforms/StyleSheet/normalizeColor.d.ts +10 -0
  30. package/dist/transforms/StyleSheet/normalizeColor.js.map +1 -1
  31. package/dist/transforms/index.d.ts +56 -0
  32. package/dist/transforms/index.js +5 -5
  33. package/dist/transforms/index.js.map +1 -1
  34. package/dist/transforms/less.d.ts +2 -0
  35. package/dist/transforms/less.js.map +1 -1
  36. package/dist/transforms/postcss.d.ts +13 -0
  37. package/dist/transforms/postcss.js +5 -1
  38. package/dist/transforms/postcss.js.map +1 -1
  39. package/dist/transforms/sass.d.ts +2 -0
  40. package/dist/transforms/sass.js.map +1 -1
  41. package/dist/transforms/stylus.d.ts +3 -0
  42. package/dist/transforms/stylus.js +1 -1
  43. package/dist/transforms/stylus.js.map +1 -1
  44. package/dist/types/index.d.ts +206 -0
  45. package/dist/utils/index.d.ts +21 -0
  46. package/dist/utils/index.js.map +1 -1
  47. package/dist/utils/lessImport.d.ts +5 -0
  48. package/dist/utils/reporterSkip.d.ts +7 -0
  49. package/dist/utils/reporterSkip.js.map +1 -1
  50. package/package.json +32 -31
  51. package/.eslintrc.js +0 -8
  52. package/__tests__/config.spec.js +0 -203
  53. package/__tests__/index.spec.js +0 -252
  54. package/__tests__/platform.spec.js +0 -78
  55. package/__tests__/styles/b.css +0 -3
  56. package/__tests__/styles/b.less +0 -3
  57. package/__tests__/styles/b.rn.css +0 -3
  58. package/__tests__/styles/b.scss +0 -3
  59. package/__tests__/styles/b.styl +0 -3
  60. package/__tests__/styles/c.css +0 -3
  61. package/__tests__/styles/c.less +0 -5
  62. package/__tests__/styles/c.rn.scss +0 -5
  63. package/__tests__/styles/c.scss +0 -5
  64. package/__tests__/styles/d.rn.scss +0 -3
  65. package/__tests__/styles/d.scss +0 -3
  66. package/__tests__/styles/mixins.scss +0 -18
  67. package/__tests__/styles/nest.rn.less +0 -3
  68. package/__tests__/styles/variable.scss +0 -1
  69. package/babel.config.js +0 -12
  70. package/jest.config.js +0 -8
  71. package/src/config/rn-stylelint.json +0 -5
  72. package/src/index.ts +0 -52
  73. package/src/transforms/StyleSheet/ColorPropType.ts +0 -76
  74. package/src/transforms/StyleSheet/ImageResizeMode.ts +0 -50
  75. package/src/transforms/StyleSheet/ImageStylePropTypes.ts +0 -62
  76. package/src/transforms/StyleSheet/LayoutPropTypes.ts +0 -559
  77. package/src/transforms/StyleSheet/ShadowPropTypesIOS.ts +0 -48
  78. package/src/transforms/StyleSheet/StyleSheetValidation.ts +0 -81
  79. package/src/transforms/StyleSheet/TextStylePropTypes.ts +0 -123
  80. package/src/transforms/StyleSheet/TransformPropTypes.ts +0 -109
  81. package/src/transforms/StyleSheet/ViewStylePropTypes.ts +0 -61
  82. package/src/transforms/StyleSheet/deprecatedPropType.ts +0 -31
  83. package/src/transforms/StyleSheet/index.ts +0 -5
  84. package/src/transforms/StyleSheet/normalizeColor.ts +0 -369
  85. package/src/transforms/index.ts +0 -229
  86. package/src/transforms/less.ts +0 -50
  87. package/src/transforms/postcss.ts +0 -95
  88. package/src/transforms/sass.ts +0 -148
  89. package/src/transforms/stylus.ts +0 -124
  90. package/src/types/index.ts +0 -242
  91. package/src/utils/index.ts +0 -229
  92. package/src/utils/lessImport.ts +0 -50
  93. package/src/utils/reporterSkip.ts +0 -27
  94. package/tsconfig.json +0 -12
@@ -1,242 +0,0 @@
1
- import { ProcessOptions } from 'postcss'
2
- import { Options } from 'sass'
3
-
4
- // sass
5
- // https://github.com/sass/node-sass#options
6
- export interface SassConfig {
7
- sass?: SassGlobalConfig
8
- alias?: Record<string, string>
9
- options: Options
10
- additionalData?: string | ((key: string) => string)
11
- }
12
-
13
- export interface SassGlobalConfig {
14
- resource?: string | string[]
15
- projectDirectory?: string
16
- data?: string
17
- }
18
-
19
- // postcss
20
- export interface PostcssConfig {
21
- options: ProcessOptions // https://github.com/postcss/postcss#options
22
- scalable: boolean // 控制是否对 css value 进行 scalePx2dp 转换
23
- pxtransform?: {
24
- enable: boolean
25
- config: any
26
- }
27
- }
28
-
29
- // less
30
- interface SourceMapOption {
31
- sourceMapURL?: string
32
- sourceMapBasepath?: string
33
- sourceMapRootpath?: string
34
- outputSourceFiles?: boolean
35
- sourceMapFileInline?: boolean
36
- }
37
- // http://lesscss.org/usage/#less-options
38
- export interface LessOptions {
39
- sourceMap?: SourceMapOption
40
- /** Filename of the main file to be passed to less.render() */
41
- filename?: string
42
- /** The locations for less looking for files in @import rules */
43
- paths?: string[]
44
- /** True, if run the less parser and just reports errors without any output. */
45
- lint?: boolean
46
- /** Pre-load global Less.js plugins */
47
- plugins?: Plugin[]
48
- /** @deprecated If true, compress using less built-in compression. */
49
- compress?: boolean
50
- strictImports?: boolean
51
- /** If true, allow imports from insecure https hosts. */
52
- insecure?: boolean
53
- depends?: boolean
54
- maxLineLen?: number
55
- /** @deprecated If false, No color in compiling. */
56
- color?: boolean
57
- /** @deprecated False by default. */
58
- ieCompat?: boolean
59
- /** @deprecated If true, enable evaluation of JavaScript inline in `.less` files. */
60
- javascriptEnabled?: boolean
61
- /** Whether output file information and line numbers in compiled CSS code. */
62
- dumpLineNumbers?: 'comment' | string
63
- /** Add a path to every generated import and url in output css files. */
64
- rootpath?: string
65
- /** Math mode options for avoiding symbol conficts on math expressions. */
66
- math?: 'always' | 'strict' | 'parens-division' | 'parens' | 'strict-legacy' | number
67
- /** If true, stops any warnings from being shown. */
68
- silent?: boolean
69
- /** Without this option, Less attempts to guess at the output unit when it does maths. */
70
- strictUnits?: boolean
71
- /** Defines a variable that can be referenced by the file. */
72
- globalVars?: {
73
- [key: string]: string
74
- }
75
- /** Puts Var declaration at the end of base file. */
76
- modifyVars?: {
77
- [key: string]: string
78
- }
79
- /** Read files synchronously in Node.js */
80
- syncImport?: boolean
81
- }
82
-
83
- export interface LessConfig {
84
- alias?: Record<string, string>
85
- options: LessOptions
86
- additionalData?: string | ((key: string) => string)
87
- }
88
-
89
- // stylus
90
- class Evaluator { }
91
-
92
- interface Dictionary<T> {
93
- [key: string]: T
94
- }
95
-
96
- // https://stylus-lang.com/docs/js.html
97
- export interface StylusRenderOptions {
98
- globals?: Dictionary<any>
99
- functions?: Dictionary<any>
100
- imports?: string[]
101
- paths?: string[]
102
- filename?: string
103
- Evaluator?: typeof Evaluator
104
- /**
105
- * Specify Stylus plugins to use. Plugins may be passed as
106
- * strings instead of importing them in your Webpack config.
107
- *
108
- * @type {(string|Function)[]}
109
- * @default []
110
- */
111
- use: (string | ((string) => string))[]
112
- /**
113
- * Add path(s) to the import lookup paths.
114
- *
115
- * @type {string[]}
116
- * @default []
117
- */
118
- include: string[]
119
- /**
120
- * Import the specified Stylus files/paths.
121
- *
122
- * @type {string[]}
123
- * @default []
124
- */
125
- import: string[]
126
-
127
- /**
128
- * Define Stylus variables or functions.
129
- *
130
- * @type {Array|Object}
131
- * @default {}
132
- */
133
- // Array is the recommended syntax: [key, value, raw]
134
- define: Array<any> | Record<string, any>
135
- // Object is deprecated syntax (there is no possibility to specify "raw')
136
- // define: {
137
- // $development: process.env.NODE_ENV === 'development',
138
- // rawVar: 42,
139
- // },
140
-
141
- /**
142
- * Include regular CSS on @import.
143
- *
144
- * @type {boolean}
145
- * @default false
146
- */
147
- includeCSS: boolean
148
-
149
- /**
150
- * Resolve relative url()'s inside imported files.
151
- *
152
- * @see https://stylus-lang.com/docs/js.html#stylusresolveroptions
153
- *
154
- * @type {boolean|Object}
155
- * @default { nocheck: true }
156
- */
157
- // resolveURL: boolean | Record<string, any>,
158
- // resolveURL: { nocheck: true },
159
-
160
- /**
161
- * Emits comments in the generated CSS indicating the corresponding Stylus line.
162
- *
163
- * @see https://stylus-lang.com/docs/executable.html
164
- *
165
- * @type {boolean}
166
- * @default false
167
- */
168
- lineNumbers: boolean
169
- /**
170
- * @type {boolean}
171
- * @default false
172
- */
173
- disableCache: boolean
174
-
175
- /**
176
- * Move @import and @charset to the top.
177
- *
178
- * @see https://stylus-lang.com/docs/executable.html
179
- *
180
- * @type {boolean}
181
- * @default false
182
- */
183
- hoistAtrules: boolean
184
- }
185
-
186
- export interface StylusConfig {
187
- alias?: Record<string, string>
188
- options: StylusRenderOptions
189
- additionalData?: string | ((key: string) => string)
190
- }
191
-
192
- // config
193
- interface RNConfig {
194
- postcss?: PostcssConfig
195
- sass?: SassConfig
196
- less?: LessConfig
197
- stylus?: StylusConfig
198
- }
199
-
200
- export interface Config {
201
- designWidth?: number | ((size?: string | number) => number)
202
- deviceRatio?: Record<string, number>
203
- sass?: SassGlobalConfig
204
- alias?: Record<string, string>
205
- rn: RNConfig
206
- }
207
-
208
- export interface TransformOptions {
209
- dev?: boolean
210
- hot?: boolean
211
- minify?: boolean
212
- platform: 'android' | 'ios'
213
- projectRoot?: string
214
- publicPath?: string
215
- customTransformOptions?: any
216
- config: Config
217
- }
218
-
219
- // resolve
220
- export const enum ResolveLogLevelEnum {
221
- ERROR = 'error',
222
- WARNING = 'warning',
223
- }
224
-
225
- export interface ResolveStyleOptions {
226
- basedir: string
227
- platform: 'android' | 'ios'
228
- paths?: string[]
229
- logLevel?: ResolveLogLevelEnum
230
- defaultExt?: string
231
- alias?: Record<string, string>
232
- }
233
-
234
- // postcss result
235
- export interface RenderResult {
236
- css: string | Buffer
237
- map?: string | Buffer
238
- }
239
-
240
- export interface RenderAdditionalResult extends RenderResult {
241
- additionalData: string
242
- }
@@ -1,229 +0,0 @@
1
- import { printLog, processTypeEnum } from '@tarojs/helper'
2
- import * as fs from 'fs'
3
- import * as path from 'path'
4
- import * as resolve from 'resolve'
5
- import nodeModulesPaths from 'resolve/lib/node-modules-paths'
6
-
7
- import { ResolveLogLevelEnum, ResolveStyleOptions } from '../types'
8
-
9
- export function insertBefore (source?: string, additional?: string) {
10
- if (!source && !additional) {
11
- return ''
12
- }
13
- if (!source) {
14
- return additional
15
- }
16
- if (!additional) {
17
- return source
18
- }
19
- return additional + ';\n' + source
20
- }
21
-
22
- /**
23
- * sort scss source by \@use
24
- * @param source scss source
25
- * @returns sorted scss source
26
- */
27
- export function sortStyle (source) {
28
- if (!source) {
29
- return ''
30
- }
31
-
32
- if (source.indexOf('@use') === -1 && source.indexOf('@import') === -1) {
33
- return source
34
- }
35
-
36
- // @use highest priority
37
- const useReg = /@use\s+['"](.*)['"];/g
38
- const useList: string[] = []
39
- let match: RegExpExecArray | null = null
40
- while ((match = useReg.exec(source))) {
41
- useList.push(match[0])
42
- source = source.replace(match[0], '')
43
- }
44
-
45
- // css last
46
- const css = source.trim()
47
- return [...useList, css].join('\n')
48
- }
49
-
50
- export function insertAfter (source?: string, additional?: string) {
51
- if (!source && !additional) {
52
- return ''
53
- }
54
- if (!source) {
55
- return additional
56
- }
57
- if (!additional) {
58
- return source
59
- }
60
- return source + ';\n' + additional
61
- }
62
-
63
- // Iterate through the include paths and extensions to find the file variant
64
- export function findVariant (name, extensions, includePaths) {
65
- for (let i = 0; i < includePaths.length; i++) {
66
- const includePath = includePaths[i]
67
-
68
- // try to find the file iterating through the extensions, in order.
69
- const foundExtention = extensions.find(extension => {
70
- const fname = path.join(includePath, name + extension)
71
- return fs.existsSync(fname)
72
- })
73
-
74
- if (foundExtention) {
75
- return path.join(includePath, name + foundExtention)
76
- }
77
- }
78
-
79
- return ''
80
- }
81
-
82
- /**
83
- * 返回存在的文件path
84
- * @param id import id
85
- * @param opts { basedir, platform, paths }
86
- */
87
- export function resolveStyle (id: string, opts: ResolveStyleOptions) {
88
- const {
89
- basedir,
90
- platform,
91
- paths = [],
92
- alias = {},
93
- defaultExt = '',
94
- logLevel = ResolveLogLevelEnum.ERROR
95
- } = opts
96
- id = id.trim()
97
- Object.keys(alias).forEach(key => {
98
- if (id.startsWith(key)) {
99
- id = id.replace(key, alias[key])
100
- }
101
- })
102
-
103
- const { dir, name, ext: idExt } = path.parse(id)
104
- const incPaths = [path.resolve(basedir, dir)].concat(paths)
105
- const ext = idExt || defaultExt
106
-
107
- const extensions = [
108
- // add the platform specific extension, first in the array to take precedence
109
- platform === 'android' ? '.android' + ext : '.ios' + ext,
110
- '.rn' + ext,
111
- ext
112
- ]
113
-
114
- let file = ''
115
- let isNodeModulesPath = false
116
- try {
117
- if ((/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/).test(id)) {
118
- file = findVariant(name, extensions, incPaths)
119
- } else {
120
- // lookup node_modules file
121
- isNodeModulesPath = true
122
- // like `@import 'taro-ui/dist/base.css';` or `@import '~taro-ui/dist/base.css';`
123
- file = resolve.sync(path.join(dir, name).replace(/^~/, ''), { basedir, extensions })
124
- }
125
- } catch (error) { } // eslint-disable-line no-empty
126
-
127
- if (!file) {
128
- let includePaths = incPaths
129
- if (isNodeModulesPath) {
130
- includePaths = nodeModulesPaths(basedir, { extensions }, id)
131
- }
132
- const levelMessage = `
133
- 样式文件没有找到,请检查文件路径: ${id}
134
- 在 [
135
- ${includePaths.join(',\n ')}
136
- ]
137
- `
138
- if (logLevel === ResolveLogLevelEnum.ERROR) {
139
- throw new Error(levelMessage)
140
- }
141
- if (logLevel === ResolveLogLevelEnum.WARNING) {
142
- printLog(processTypeEnum.WARNING, levelMessage)
143
- return id
144
- }
145
- }
146
-
147
- return file
148
- }
149
-
150
- // copy from https://github.com/webpack-contrib/css-loader/blob/master/src/utils.js
151
- const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i
152
- const ABSOLUTE_SCHEME = /^[a-z0-9+\-.]+:/i
153
-
154
- export function normalizePath (file) {
155
- return path.sep === '\\' ? file.replace(/\\/g, '/') : file
156
- }
157
-
158
- function getURLType (source) {
159
- if (source[0] === '/') {
160
- if (source[1] === '/') {
161
- return 'scheme-relative'
162
- }
163
-
164
- return 'path-absolute'
165
- }
166
-
167
- if (IS_NATIVE_WIN32_PATH.test(source)) {
168
- return 'path-absolute'
169
- }
170
-
171
- return ABSOLUTE_SCHEME.test(source) ? 'absolute' : 'path-relative'
172
- }
173
-
174
- export function normalizeSourceMap (map, resourcePath) {
175
- let newMap = map
176
-
177
- // Some loader emit source map as string
178
- // Strip any JSON XSSI avoidance prefix from the string (as documented in the source maps specification), and then parse the string as JSON.
179
- if (typeof newMap === 'string') {
180
- newMap = JSON.parse(newMap)
181
- }
182
-
183
- delete newMap.file
184
-
185
- const { sourceRoot } = newMap
186
-
187
- delete newMap.sourceRoot
188
-
189
- if (newMap.sources) {
190
- // Source maps should use forward slash because it is URLs (https://github.com/mozilla/source-map/issues/91)
191
- // We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
192
- newMap.sources = newMap.sources.map((source) => {
193
- // Non-standard syntax from `postcss`
194
- if (source.indexOf('<') === 0) {
195
- return source
196
- }
197
-
198
- const sourceType = getURLType(source)
199
-
200
- // Do no touch `scheme-relative` and `absolute` URLs
201
- if (sourceType === 'path-relative' || sourceType === 'path-absolute') {
202
- const absoluteSource =
203
- sourceType === 'path-relative' && sourceRoot
204
- ? path.resolve(sourceRoot, normalizePath(source))
205
- : normalizePath(source)
206
-
207
- return path.relative(path.dirname(resourcePath), absoluteSource)
208
- }
209
-
210
- return source
211
- })
212
- }
213
-
214
- return newMap
215
- }
216
- // copy end
217
-
218
- export function getAdditionalData (data: string, config?: string | ((key: string) => string)) {
219
- let additionalData = ''
220
- if (typeof config !== 'undefined') {
221
- additionalData =
222
- typeof config === 'function'
223
- ? `${config(data)}`
224
- : config
225
- }
226
- return additionalData
227
- }
228
-
229
- export default {}
@@ -1,50 +0,0 @@
1
- import Less from 'less'
2
-
3
- import { resolveStyle } from './index'
4
-
5
- class LessImporter extends Less.FileManager {
6
- platform: 'android' | 'ios'
7
- alias: Record<string, string> = {}
8
-
9
- constructor (opt) {
10
- super()
11
- this.platform = opt.platform
12
- this.alias = opt.alias
13
- }
14
-
15
- supports () {
16
- return true
17
- }
18
-
19
- supportsSync () {
20
- return false
21
- }
22
-
23
- async loadFile (
24
- filename: string,
25
- currentDirectory: string,
26
- options: any,
27
- environment: any
28
- ) {
29
- const resolveOpts = {
30
- basedir: currentDirectory,
31
- alias: this.alias,
32
- platform: this.platform,
33
- defaultExt: '.less'
34
- }
35
- const rewriteFilename = resolveStyle(filename, resolveOpts)
36
-
37
- return super.loadFile(rewriteFilename, currentDirectory, options, environment)
38
- }
39
- }
40
-
41
- function makeLessImport (options) {
42
- return {
43
- install: (_, pluginManager) => {
44
- pluginManager.addFileManager(new LessImporter(options))
45
- },
46
- minVersion: [2, 7, 1]
47
- }
48
- }
49
-
50
- export default makeLessImport
@@ -1,27 +0,0 @@
1
- interface Location {
2
- line: number
3
- column: number
4
- file: string
5
- }
6
-
7
- export default function reporterSkip ({ skipRows, filename }) {
8
- return {
9
- postcssPlugin: 'postcss-reporter-skip',
10
- // @ts-ignore
11
- Once (css, result) {
12
- result.messages?.forEach((message: any) => {
13
- const { line, column, node } = message
14
-
15
- const messageInput = node?.source?.input
16
- if (messageInput) {
17
- const originLocation: Location = messageInput.origin(line, column)
18
- // 如果是原始引入的样式文件,则对拼接的代码(addionalData)函数做减法
19
- if (originLocation && originLocation.file.includes(filename)) {
20
- // force modify line,then source map cannot read origin column, value is 0.
21
- message.line -= skipRows
22
- }
23
- }
24
- })
25
- }
26
- }
27
- }
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.root.json",
3
- "compilerOptions": {
4
- "target": "ES2017",
5
- "module": "commonjs",
6
- "outDir": "dist",
7
- "esModuleInterop": true,
8
- "sourceMap": true,
9
- "rootDir": "./src"
10
- },
11
- "include": ["./src"]
12
- }