@authing/native-js-ui-components 4.4.2 → 4.5.0-alpha.0

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.
@@ -1,3 +1,9 @@
1
+ /*
2
+ object-assign
3
+ (c) Sindre Sorhus
4
+ @license MIT
5
+ */
6
+
1
7
  /*
2
8
  object-assign
3
9
  (c) Sindre Sorhus
@@ -5,13 +11,24 @@ object-assign
5
11
  */
6
12
 
7
13
  /*!
8
- * The buffer module from node.js, for the browser.
9
- *
10
- * @author Feross Aboukhadijeh <http://feross.org>
11
- * @license MIT
12
- */
14
+ Copyright (c) 2018 Jed Watson.
15
+ Licensed under the MIT License (MIT), see
16
+ http://jedwatson.github.io/classnames
17
+ */
13
18
 
14
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
19
+ /*!
20
+ Copyright (c) 2018 Jed Watson.
21
+ Licensed under the MIT License (MIT), see
22
+ http://jedwatson.github.io/classnames
23
+ */
24
+
25
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
26
+
27
+ /**
28
+ * @license qrcode.react
29
+ * Copyright (c) Paul O'Shannessy
30
+ * SPDX-License-Identifier: ISC
31
+ */
15
32
 
16
33
  /** @license React v0.19.1
17
34
  * scheduler.production.min.js
@@ -22,7 +39,7 @@ object-assign
22
39
  * LICENSE file in the root directory of this source tree.
23
40
  */
24
41
 
25
- /** @license React v16.14.0
42
+ /** @license React v16.13.1
26
43
  * react-dom.production.min.js
27
44
  *
28
45
  * Copyright (c) Facebook, Inc. and its affiliates.
@@ -31,7 +48,16 @@ object-assign
31
48
  * LICENSE file in the root directory of this source tree.
32
49
  */
33
50
 
34
- /** @license React v16.14.0
51
+ /** @license React v16.13.1
52
+ * react-is.production.min.js
53
+ *
54
+ * Copyright (c) Facebook, Inc. and its affiliates.
55
+ *
56
+ * This source code is licensed under the MIT license found in the
57
+ * LICENSE file in the root directory of this source tree.
58
+ */
59
+
60
+ /** @license React v16.13.1
35
61
  * react.production.min.js
36
62
  *
37
63
  * Copyright (c) Facebook, Inc. and its affiliates.
@@ -39,3 +65,21 @@ object-assign
39
65
  * This source code is licensed under the MIT license found in the
40
66
  * LICENSE file in the root directory of this source tree.
41
67
  */
68
+
69
+ /** @preserve
70
+ * Counter block mode compatible with Dr Brian Gladman fileenc.c
71
+ * derived from CryptoJS.mode.CTR
72
+ * Jan Hruby jhruby.web@gmail.com
73
+ */
74
+
75
+ /** @preserve
76
+ (c) 2012 by Cédric Mesnil. All rights reserved.
77
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
78
+ - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
79
+ - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
80
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
81
+ */
82
+
83
+ //! moment.js
84
+
85
+ //! moment.js locale configuration
@@ -0,0 +1,35 @@
1
+ import { GuardLocalConfig, AuthenticationClient, GuardEventsKebabToCamelType } from '@authing/guard-shim-react';
2
+ import '@authing/guard-shim-react/dist/guard.min.css';
3
+ export * from '@authing/guard-shim-react';
4
+ export interface NativeGuardProps {
5
+ appId?: string;
6
+ config?: Partial<GuardLocalConfig>;
7
+ tenantId?: string;
8
+ authClient?: AuthenticationClient;
9
+ }
10
+ export interface NativeGuardConstructor {
11
+ (appId?: string | NativeGuardProps, config?: Partial<GuardLocalConfig>, tenantId?: string, authClient?: AuthenticationClient): void;
12
+ (props: NativeGuardProps): void;
13
+ }
14
+ export declare type GuardEventListeners = {
15
+ [key in keyof GuardEventsKebabToCamelType]: Exclude<Required<GuardEventsKebabToCamelType>[key], undefined>[];
16
+ };
17
+ export declare class Guard {
18
+ appId?: string;
19
+ config?: Partial<GuardLocalConfig>;
20
+ tenantId?: string;
21
+ authClient?: AuthenticationClient;
22
+ visible?: boolean;
23
+ constructor(props?: NativeGuardProps);
24
+ constructor(appId?: string, config?: Partial<GuardLocalConfig>, tenantId?: string, authClient?: AuthenticationClient);
25
+ static getGuardContainer(selector?: string | HTMLElement): Element | null;
26
+ private eventListeners;
27
+ render(): void;
28
+ render(aliginOrCb: () => void): void;
29
+ render(aliginOrCb: 'none' | 'center' | 'left' | 'right'): void;
30
+ render(aliginOrCb: 'none' | 'center' | 'left' | 'right', callback: () => void): void;
31
+ on<T extends keyof GuardEventsKebabToCamelType>(evt: T, handler: Exclude<GuardEventsKebabToCamelType[T], undefined>): void;
32
+ show(): void;
33
+ hide(): void;
34
+ unmountComponent(): void;
35
+ }
package/package.json CHANGED
@@ -1,171 +1,28 @@
1
1
  {
2
2
  "name": "@authing/native-js-ui-components",
3
- "version": "4.4.2",
4
- "framework": "Native",
5
- "private": false,
6
- "main": "lib/index.min.js",
7
- "typings": "lib/index.d.ts",
3
+ "version": "4.5.0-alpha.0",
4
+ "description": "Authing Guard for Native",
5
+ "module": "lib/index.min.js",
6
+ "types": "lib/typings/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "package.json",
10
+ "package-lock.json"
11
+ ],
8
12
  "scripts": {
9
- "start": "node scripts/start.js",
10
- "build": "node scripts/build.js",
11
- "build:lib": "node scripts/lib.js",
12
- "test": "node scripts/test.js"
13
+ "build:lib": "npm ci && node scripts/build.js",
14
+ "release:official": "npm publish --verbose --access public",
15
+ "release:alpha": "npm publish --verbose --tag=alpha --access public"
13
16
  },
14
- "publishConfig": {
15
- "access": "public",
16
- "registry": "https://registry.npmjs.org"
17
- },
18
- "eslintConfig": {
19
- "extends": [
20
- "react-app",
21
- "react-app/jest"
22
- ]
23
- },
24
- "browserslist": {
25
- "production": [
26
- ">0.2%",
27
- "not dead",
28
- "not op_mini all"
29
- ],
30
- "development": [
31
- "last 1 chrome version",
32
- "last 1 firefox version",
33
- "last 1 safari version"
34
- ]
35
- },
36
- "jest": {
37
- "roots": [
38
- "<rootDir>/src"
39
- ],
40
- "collectCoverageFrom": [
41
- "src/**/*.{js,jsx,ts,tsx}",
42
- "!src/**/*.d.ts"
43
- ],
44
- "setupFiles": [
45
- "react-app-polyfill/jsdom"
46
- ],
47
- "setupFilesAfterEnv": [
48
- "<rootDir>/src/setupTests.ts"
49
- ],
50
- "testMatch": [
51
- "<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
52
- "<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
53
- ],
54
- "testEnvironment": "jsdom",
55
- "testRunner": "/Users/lixpng/workspace/authing/ui-components/packages/native-js/node_modules/jest-circus/runner.js",
56
- "transform": {
57
- "^.+\\.(js|jsx|mjs|cjs|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
58
- "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
59
- "^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
60
- },
61
- "transformIgnorePatterns": [
62
- "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$",
63
- "^.+\\.module\\.(css|sass|scss)$"
64
- ],
65
- "modulePaths": [],
66
- "moduleNameMapper": {
67
- "^react-native$": "react-native-web",
68
- "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
69
- },
70
- "moduleFileExtensions": [
71
- "web.js",
72
- "js",
73
- "web.ts",
74
- "ts",
75
- "web.tsx",
76
- "tsx",
77
- "json",
78
- "web.jsx",
79
- "jsx",
80
- "node"
81
- ],
82
- "watchPlugins": [
83
- "jest-watch-typeahead/filename",
84
- "jest-watch-typeahead/testname"
85
- ],
86
- "resetMocks": true
87
- },
88
- "babel": {
89
- "presets": [
90
- "react-app"
91
- ]
17
+ "author": "https://github.com/authing",
18
+ "license": "MIT",
19
+ "dependencies": {
20
+ "@authing/guard-shim-react": "^4.5.0-alpha.0",
21
+ "react": "^16.13.1",
22
+ "react-dom": "^16.13.1"
92
23
  },
93
24
  "devDependencies": {
94
- "@babel/core": "7.12.3",
95
- "@pmmmwh/react-refresh-webpack-plugin": "0.4.2",
96
- "@svgr/webpack": "5.4.0",
97
- "@testing-library/jest-dom": "^5.11.4",
98
- "@testing-library/react": "^11.1.0",
99
- "@testing-library/user-event": "^12.1.10",
100
- "@types/jest": "^26.0.15",
101
- "@types/node": "^12.0.0",
102
- "@types/react": "^16.9.53",
103
- "@types/react-dom": "^16.9.8",
104
- "@typescript-eslint/eslint-plugin": "^4.5.0",
105
- "@typescript-eslint/parser": "^4.5.0",
106
- "babel-eslint": "^10.1.0",
107
- "babel-jest": "^26.6.0",
108
- "babel-loader": "8.1.0",
109
- "babel-plugin-import": "^1.13.1",
110
- "babel-plugin-named-asset-import": "^0.3.7",
111
- "babel-preset-react-app": "^10.0.0",
112
- "bfj": "^7.0.2",
113
- "camelcase": "^6.1.0",
114
- "case-sensitive-paths-webpack-plugin": "2.3.0",
115
- "css-loader": "4.3.0",
116
- "dotenv": "8.2.0",
117
- "dotenv-expand": "5.1.0",
118
- "eslint": "^7.11.0",
119
- "eslint-config-react-app": "^6.0.0",
120
- "eslint-plugin-flowtype": "^5.2.0",
121
- "eslint-plugin-import": "^2.22.1",
122
- "eslint-plugin-jest": "^24.1.0",
123
- "eslint-plugin-jsx-a11y": "^6.3.1",
124
- "eslint-plugin-react": "^7.21.5",
125
- "eslint-plugin-react-hooks": "^4.2.0",
126
- "eslint-plugin-testing-library": "^3.9.2",
127
- "eslint-webpack-plugin": "^2.1.0",
128
- "file-loader": "6.1.1",
129
- "fs-extra": "^9.0.1",
130
- "html-webpack-plugin": "4.5.0",
131
- "identity-obj-proxy": "3.0.0",
132
- "jest": "26.6.0",
133
- "jest-circus": "26.6.0",
134
- "jest-resolve": "26.6.0",
135
- "jest-watch-typeahead": "0.6.1",
136
- "less": "^3.12.2",
137
- "less-loader": "^7.0.2",
138
- "mini-css-extract-plugin": "0.11.3",
139
- "npm-dts-webpack-plugin": "^1.3.5",
140
- "optimize-css-assets-webpack-plugin": "5.0.4",
141
- "pnp-webpack-plugin": "1.6.4",
142
- "postcss-flexbugs-fixes": "4.2.1",
143
- "postcss-loader": "3.0.0",
144
- "postcss-normalize": "8.0.1",
145
- "postcss-preset-env": "6.7.0",
146
- "postcss-safe-parser": "5.0.2",
147
- "react": "16.14.0",
148
- "react-app-polyfill": "^2.0.0",
149
- "react-dev-utils": "^11.0.0",
150
- "react-dom": "16.14.0",
151
- "react-refresh": "^0.8.3",
152
- "resolve": "1.18.1",
153
- "resolve-url-loader": "^3.1.2",
154
- "sass-loader": "8.0.2",
155
- "semver": "7.3.2",
156
- "style-loader": "1.3.0",
157
- "terser-webpack-plugin": "4.2.3",
158
- "ts-pnp": "1.2.0",
159
- "typescript": "^4.0.3",
160
- "url-loader": "4.1.1",
161
- "web-vitals": "^0.2.4",
162
- "webpack": "4.44.2",
163
- "webpack-dev-server": "3.11.0",
164
- "webpack-manifest-plugin": "2.2.0",
165
- "workbox-webpack-plugin": "5.1.4"
166
- },
167
- "dependencies": {
168
- "@authing/react-ui-components": "4.4.2",
169
- "authing-js-sdk": "4.23.40"
25
+ "@types/react": "^16.9.0",
26
+ "@types/react-dom": "^16.9.0"
170
27
  }
171
- }
28
+ }
package/README.md DELETED
@@ -1,33 +0,0 @@
1
- # Authing Native JavaScript UI Components
2
-
3
- [Authing](https://authing.cn) 是一个企业级身份认证提供商,其集成了 OAuth、LDAP、OIDC 等多种身份认证和授权解决方案。此仓库包含了 Authing 提供的一些 Native JavaScript UI 组件。
4
-
5
- ## Guard
6
-
7
- Guard 是一种可嵌入的登录表单,可根据你的需求进行配置,建议用于单页面应用程序。 它使你可以轻松添加各种社会化登录方式,以便你的用户可以无缝登录,并且在不同平台拥有一致的登录体验。
8
- Guard 拥有以下基本功能:
9
-
10
- - 登录:
11
- - 账号密码登录(包括手机号 + 密码、邮箱 + 密码、用户名 + 密码);
12
- - 手机验证码登录;
13
- - 微信小程序扫码登录(需先在后台配置);
14
- - APP 扫码登录(需要接入 APP 扫码登录);
15
- - 小程序扫码登录(需先在后台配置);
16
- - 社会化登录(需要配置社会化登录);
17
- - 企业身份源登录(需要配置企业身份源);
18
- - 注册:
19
- - 账号密码注册;
20
- - 手机验证码注册;
21
- - 忘记密码以及重置密码;
22
- - MFA 认证;
23
- - 响应式特性(兼容移动端和 PC 端);
24
- - 完整的 UI 自定义功能;
25
- - 兼容主流前端 UI 库:
26
- - 原生 JavaScript 调用;
27
- - Vue 组件;
28
- - React 组件;
29
- - Angular 组件。
30
-
31
- ![Guard Demo](./static/images/guard-demo.jpg)
32
-
33
- 详细使用文档请查看 [Guard for Web](https://docs.authing.cn/sdk/guard/#guard-for-native-javascript)
package/config/env.js DELETED
@@ -1,106 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const paths = require('./paths');
6
-
7
- // Make sure that including paths.js after env.js will read .env variables.
8
- delete require.cache[require.resolve('./paths')];
9
-
10
- const NODE_ENV = process.env.NODE_ENV;
11
- if (!NODE_ENV) {
12
- throw new Error(
13
- 'The NODE_ENV environment variable is required but was not specified.'
14
- );
15
- }
16
-
17
- // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
18
- const dotenvFiles = [
19
- `${paths.dotenv}.${NODE_ENV}.local`,
20
- // Don't include `.env.local` for `test` environment
21
- // since normally you expect tests to produce the same
22
- // results for everyone
23
- NODE_ENV !== 'test' && `${paths.dotenv}.local`,
24
- `${paths.dotenv}.${NODE_ENV}`,
25
- paths.dotenv,
26
- ].filter(Boolean);
27
-
28
- // Load environment variables from .env* files. Suppress warnings using silent
29
- // if this file is missing. dotenv will never modify any environment variables
30
- // that have already been set. Variable expansion is supported in .env files.
31
- // https://github.com/motdotla/dotenv
32
- // https://github.com/motdotla/dotenv-expand
33
- dotenvFiles.forEach(dotenvFile => {
34
- if (fs.existsSync(dotenvFile)) {
35
- require('dotenv-expand')(
36
- require('dotenv').config({
37
- path: dotenvFile,
38
- })
39
- );
40
- }
41
- });
42
-
43
- // We support resolving modules according to `NODE_PATH`.
44
- // This lets you use absolute paths in imports inside large monorepos:
45
- // https://github.com/facebook/create-react-app/issues/253.
46
- // It works similar to `NODE_PATH` in Node itself:
47
- // https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
48
- // Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
49
- // Otherwise, we risk importing Node.js core modules into an app instead of webpack shims.
50
- // https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
51
- // We also resolve them to make sure all tools using them work consistently.
52
- const appDirectory = fs.realpathSync(process.cwd());
53
- process.env.NODE_PATH = (process.env.NODE_PATH || '')
54
- .split(path.delimiter)
55
- .filter(folder => folder && !path.isAbsolute(folder))
56
- .map(folder => path.resolve(appDirectory, folder))
57
- .join(path.delimiter);
58
-
59
- // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
60
- // injected into the application via DefinePlugin in webpack configuration.
61
- const REACT_APP = /^REACT_APP_/i;
62
-
63
- function getClientEnvironment(publicUrl) {
64
- const raw = Object.keys(process.env)
65
- .filter(key => REACT_APP.test(key))
66
- .reduce(
67
- (env, key) => {
68
- env[key] = process.env[key];
69
- return env;
70
- },
71
- {
72
- // Useful for determining whether we’re running in production mode.
73
- // Most importantly, it switches React into the correct mode.
74
- NODE_ENV: process.env.NODE_ENV || 'development',
75
- // Useful for resolving the correct path to static assets in `public`.
76
- // For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
77
- // This should only be used as an escape hatch. Normally you would put
78
- // images into the `src` and `import` them in code to get their paths.
79
- PUBLIC_URL: publicUrl,
80
- // We support configuring the sockjs pathname during development.
81
- // These settings let a developer run multiple simultaneous projects.
82
- // They are used as the connection `hostname`, `pathname` and `port`
83
- // in webpackHotDevClient. They are used as the `sockHost`, `sockPath`
84
- // and `sockPort` options in webpack-dev-server.
85
- WDS_SOCKET_HOST: process.env.WDS_SOCKET_HOST,
86
- WDS_SOCKET_PATH: process.env.WDS_SOCKET_PATH,
87
- WDS_SOCKET_PORT: process.env.WDS_SOCKET_PORT,
88
- // Whether or not react-refresh is enabled.
89
- // react-refresh is not 100% stable at this time,
90
- // which is why it's disabled by default.
91
- // It is defined here so it is available in the webpackHotDevClient.
92
- FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
93
- }
94
- );
95
- // Stringify all values so we can feed into webpack DefinePlugin
96
- const stringified = {
97
- 'process.env': Object.keys(raw).reduce((env, key) => {
98
- env[key] = JSON.stringify(raw[key]);
99
- return env;
100
- }, {}),
101
- };
102
-
103
- return { raw, stringified };
104
- }
105
-
106
- module.exports = getClientEnvironment;
@@ -1,66 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const crypto = require('crypto');
6
- const chalk = require('react-dev-utils/chalk');
7
- const paths = require('./paths');
8
-
9
- // Ensure the certificate and key provided are valid and if not
10
- // throw an easy to debug error
11
- function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
12
- let encrypted;
13
- try {
14
- // publicEncrypt will throw an error with an invalid cert
15
- encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
16
- } catch (err) {
17
- throw new Error(
18
- `The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`
19
- );
20
- }
21
-
22
- try {
23
- // privateDecrypt will throw an error with an invalid key
24
- crypto.privateDecrypt(key, encrypted);
25
- } catch (err) {
26
- throw new Error(
27
- `The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${
28
- err.message
29
- }`
30
- );
31
- }
32
- }
33
-
34
- // Read file and throw an error if it doesn't exist
35
- function readEnvFile(file, type) {
36
- if (!fs.existsSync(file)) {
37
- throw new Error(
38
- `You specified ${chalk.cyan(
39
- type
40
- )} in your env, but the file "${chalk.yellow(file)}" can't be found.`
41
- );
42
- }
43
- return fs.readFileSync(file);
44
- }
45
-
46
- // Get the https config
47
- // Return cert files if provided in env, otherwise just true or false
48
- function getHttpsConfig() {
49
- const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
50
- const isHttps = HTTPS === 'true';
51
-
52
- if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
53
- const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE);
54
- const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE);
55
- const config = {
56
- cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
57
- key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
58
- };
59
-
60
- validateKeyAndCerts({ ...config, keyFile, crtFile });
61
- return config;
62
- }
63
- return isHttps;
64
- }
65
-
66
- module.exports = getHttpsConfig;
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- // This is a custom Jest transformer turning style imports into empty objects.
4
- // http://facebook.github.io/jest/docs/en/webpack.html
5
-
6
- module.exports = {
7
- process() {
8
- return 'module.exports = {};';
9
- },
10
- getCacheKey() {
11
- // The output is always the same.
12
- return 'cssTransform';
13
- },
14
- };
@@ -1,40 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const camelcase = require('camelcase');
5
-
6
- // This is a custom Jest transformer turning file imports into filenames.
7
- // http://facebook.github.io/jest/docs/en/webpack.html
8
-
9
- module.exports = {
10
- process(src, filename) {
11
- const assetFilename = JSON.stringify(path.basename(filename));
12
-
13
- if (filename.match(/\.svg$/)) {
14
- // Based on how SVGR generates a component name:
15
- // https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6
16
- const pascalCaseFilename = camelcase(path.parse(filename).name, {
17
- pascalCase: true,
18
- });
19
- const componentName = `Svg${pascalCaseFilename}`;
20
- return `const React = require('react');
21
- module.exports = {
22
- __esModule: true,
23
- default: ${assetFilename},
24
- ReactComponent: React.forwardRef(function ${componentName}(props, ref) {
25
- return {
26
- $$typeof: Symbol.for('react.element'),
27
- type: 'svg',
28
- ref: ref,
29
- key: null,
30
- props: Object.assign({}, props, {
31
- children: ${assetFilename}
32
- })
33
- };
34
- }),
35
- };`;
36
- }
37
-
38
- return `module.exports = ${assetFilename};`;
39
- },
40
- };