@machtwatch/react-script 1.2.11-alpha.28 → 1.2.11-alpha.30

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.
@@ -0,0 +1,70 @@
1
+ module.exports = () => ({
2
+ customOptions({ transform_runtime, isClient, ...loader }) {
3
+ return {
4
+ loader,
5
+ custom: { ...transform_runtime, isClient }
6
+ };
7
+ },
8
+ config(cfg) {
9
+ return {
10
+ ...cfg.options,
11
+ presets: [
12
+ [
13
+ require('@babel/preset-env'),
14
+ {
15
+ modules: false,
16
+ useBuiltIns: 'usage',
17
+ corejs: '3.22'
18
+ }
19
+ ],
20
+ require('@babel/preset-react'),
21
+
22
+ ],
23
+ plugins: [
24
+ require('@babel/plugin-transform-runtime'),
25
+ require('@babel/plugin-proposal-function-bind'),
26
+ require('@babel/plugin-proposal-export-default-from'),
27
+ require('@babel/plugin-proposal-export-namespace-from'),
28
+ require('@babel/plugin-proposal-throw-expressions'),
29
+ require('@babel/plugin-syntax-dynamic-import'),
30
+ require('@babel/plugin-proposal-json-strings'),
31
+ require('@loadable/babel-plugin'),
32
+ [require('babel-plugin-transform-imports'), {
33
+ '@machtwatch/react-ui': {
34
+ transform: '@machtwatch/react-ui/lib/${member}',
35
+ preventFullImport: true
36
+ }
37
+ }],
38
+ [require('@babel/plugin-proposal-decorators'), {
39
+ legacy: true
40
+ }],
41
+ [require('@babel/plugin-proposal-optional-chaining'), {
42
+ loose: true
43
+ }],
44
+ [require('@babel/plugin-proposal-class-properties'), {
45
+ loose: true
46
+ }],
47
+ [require('@babel/plugin-proposal-private-methods'), { loose: true }],
48
+ [require('@babel/plugin-proposal-private-property-in-object'), { loose: true }],
49
+ [require('babel-plugin-add-module-exports'), {
50
+ addDefaultProperty: true
51
+ }],
52
+ ...(cfg.options.isClient && !cfg.options.compact ? [
53
+ require.resolve('react-refresh/babel')
54
+ ] : [
55
+ ...(cfg.options.compact ? [
56
+ require('@babel/plugin-transform-react-inline-elements'),
57
+ require('@babel/plugin-transform-react-constant-elements')
58
+ ] : [])
59
+ ]),
60
+ ...(cfg.options.plugins || [])
61
+ ],
62
+ };
63
+ },
64
+ result(result) {
65
+ return {
66
+ ...result,
67
+ code: `${result.code} \n// Generated by babel-custom-loader`
68
+ };
69
+ },
70
+ });
package/config/env.js ADDED
@@ -0,0 +1,67 @@
1
+ // @remove-on-eject-begin
2
+ /**
3
+ * Copyright (c) 2015-present, Facebook, Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // @remove-on-eject-end
9
+ 'use strict';
10
+
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+
14
+ const paths = require('./paths');
15
+
16
+ // Make sure that including paths.js after env.js will read .env variables.
17
+ delete require.cache[require.resolve('./paths')];
18
+
19
+ // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
20
+ const dotenvFiles = [paths.dotenv].filter(Boolean);
21
+ const appDirectory = fs.realpathSync(process.cwd());
22
+
23
+ // Load environment variables from .env* files. Suppress warnings using silent
24
+ // if this file is missing. dotenv will never modify any environment variables
25
+ // that have already been set. Variable expansion is supported in .env files.
26
+ // https://github.com/motdotla/dotenv
27
+ // https://github.com/motdotla/dotenv-expand
28
+ dotenvFiles.forEach(dotenvFile => {
29
+ if (fs.existsSync(dotenvFile)) {
30
+ require('dotenv-expand')(
31
+ require('dotenv').config({ path: dotenvFile })
32
+ );
33
+ };
34
+ });
35
+
36
+ process.env.NODE_PATH = (process.env.NODE_PATH || '')
37
+ .split(path.delimiter)
38
+ .filter(folder => folder && !path.isAbsolute(folder))
39
+ .map(folder => path.resolve(appDirectory, folder))
40
+ .join(path.delimiter);
41
+
42
+ function getClientEnvironment(publicUrl) {
43
+ const raw = Object.keys(process.env)
44
+ .reduce(
45
+ (env, key) => {
46
+ env[key] = process.env[key];
47
+ return env;
48
+ },
49
+ {
50
+ // Useful for determining whether we’re running in production mode.
51
+ // Most importantly, it switches React into the correct mode.
52
+ NODE_ENV: process.env.NODE_ENV || 'development',
53
+ }
54
+ );
55
+
56
+ // Stringify all values so we can feed into Webpack DefinePlugin
57
+ const stringified = {
58
+ 'process.env': Object.keys(raw).reduce((env, key) => {
59
+ env[key] = JSON.stringify(raw[key]);
60
+ return env;
61
+ }, {}),
62
+ };
63
+
64
+ return { raw, stringified };
65
+ };
66
+
67
+ module.exports = getClientEnvironment;
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ const babelJest = require('babel-jest');
4
+
5
+ module.exports = babelJest.createTransformer({
6
+ babelrc: false,
7
+ presets: [
8
+ ['@babel/preset-react'],
9
+ ['@babel/preset-env', {
10
+ modules: 'auto',
11
+ useBuiltIns: 'entry',
12
+ corejs: 3,
13
+ }]
14
+ ],
15
+ plugins: [
16
+ require('@babel/plugin-transform-runtime'),
17
+ require('@babel/plugin-syntax-dynamic-import'),
18
+ require('@babel/plugin-proposal-export-default-from'),
19
+ require('babel-plugin-dynamic-import-node'),
20
+ [require('babel-plugin-transform-imports'), {
21
+ '@machtwatch/react-ui': {
22
+ transform: '@machtwatch/react-ui/lib/${member}',
23
+ preventFullImport: true
24
+ }
25
+ }]
26
+ ]
27
+ });
@@ -0,0 +1,91 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const merge = require('deepmerge');
6
+
7
+ module.exports = (resolve, rootDir, srcRoots, appConfig) => {
8
+ const toRelRootDir = f => '<rootDir>/' + path.relative(rootDir || '', f);
9
+ const extendedPath = path.join(process.cwd(), 'extended-jest.config.js');
10
+
11
+ let isExtendedConfigExisted = false;
12
+ let extendedConfig = {};
13
+
14
+ try {
15
+ isExtendedConfigExisted = fs.existsSync(extendedPath);
16
+ } catch (err) {
17
+ console.error(err.message);
18
+ }
19
+
20
+ if (isExtendedConfigExisted) {
21
+ try {
22
+ extendedConfig = require(extendedPath);
23
+ } catch (err) {
24
+ console.error(err.message);
25
+ }
26
+ }
27
+
28
+ const config = {
29
+ globals: {
30
+ CONFIG: appConfig && (appConfig.globals || appConfig),
31
+ },
32
+ setupFiles: [resolve('scripts/utils/polyfills.js')],
33
+ testMatch: [
34
+ "<rootDir>/src/shared/**/*.(spec|test).{js,jsx,mjs}"
35
+ ],
36
+ collectCoverageFrom: [
37
+ "src/shared/**/*.{js,jsx,mjs}"
38
+ ],
39
+ coverageThreshold: {
40
+ global: {
41
+ branches: 80,
42
+ functions: 80,
43
+ lines: 80,
44
+ statements: 80
45
+ }
46
+ },
47
+ coverageReporters: [
48
+ "lcov",
49
+ "html"
50
+ ],
51
+ roots: srcRoots.map(toRelRootDir),
52
+ testEnvironment: 'node',
53
+ testEnvironmentOptions: {
54
+ url: 'http://localhost'
55
+ },
56
+ transform: {
57
+ '^.+\\.(js|jsx|mjs|cjs)$': resolve('config/jest/babelTransform.js'),
58
+ '^.+\\.css$': resolve('config/jest/cssTransform.js'),
59
+ '^.+\\.(graphql)$': resolve('config/jest/graphqlTransform.js'),
60
+ '^(?!.*\\.(js|jsx|mjs|css|json|graphql)$)': resolve('config/jest/fileTransform.js'),
61
+ },
62
+ transformIgnorePatterns: [
63
+ '^.+\\.module\\.css$',
64
+ ],
65
+ moduleFileExtensions: [
66
+ 'web.js',
67
+ 'mjs',
68
+ 'js',
69
+ 'json',
70
+ 'web.jsx',
71
+ 'jsx',
72
+ 'node',
73
+ ],
74
+ testPathIgnorePatterns: [
75
+ "/node_modules/",
76
+ "<rootDir>/tests/",
77
+ "<rootDir>/src/*.js",
78
+ "<rootDir>/graphql/"
79
+ ],
80
+ setupFilesAfterEnv: [resolve('config/jest/jest-setup.js'), '<rootDir>/jest-setup.js'],
81
+ verbose: true,
82
+ };
83
+
84
+ const combinedConfig = merge(config, extendedConfig);
85
+
86
+ if (rootDir) {
87
+ config.rootDir = rootDir;
88
+ }
89
+
90
+ return combinedConfig;
91
+ };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ process() {
5
+ return {
6
+ code: 'module.exports = {};'
7
+ };
8
+ },
9
+ getCacheKey() {
10
+ // The output is always the same.
11
+ return 'cssTransform';
12
+ },
13
+ };
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+
5
+ module.exports = {
6
+ process(src, filename) {
7
+ const assetFilename = JSON.stringify(path.basename(filename));
8
+
9
+ if (filename.match(/\.svg$/)) {
10
+ return {
11
+ code: `module.exports = {
12
+ __esModule: true,
13
+ default: ${assetFilename},
14
+ ReactComponent: () => ${assetFilename},
15
+ };`
16
+ };
17
+ }
18
+
19
+ return {
20
+ code: `module.exports = ${assetFilename};`
21
+ };
22
+ },
23
+ };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const loader = require('graphql-tag/loader');
4
+
5
+ module.exports = {
6
+ process(src) {
7
+ return {
8
+ code: loader.call({ cacheable() {} }, src)
9
+ };
10
+ },
11
+ };
@@ -0,0 +1 @@
1
+ import "@testing-library/jest-dom";
@@ -0,0 +1,48 @@
1
+ // @remove-on-eject-begin
2
+ /**
3
+ * Copyright (c) 2015-present, Facebook, Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // @remove-on-eject-end
9
+ 'use strict';
10
+
11
+ const path = require('path');
12
+ const fs = require('fs');
13
+
14
+ // Make sure any symlinks in the project folder are resolved:
15
+ const appDirectory = fs.realpathSync(process.cwd());
16
+
17
+ const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
18
+ const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);
19
+
20
+ const useTemplate = appDirectory === fs.realpathSync(path.join(__dirname, '..'));
21
+
22
+ if (useTemplate) {
23
+ module.exports = {
24
+ dotenv: resolveOwn('template/.env'),
25
+ appPath: resolveOwn('template/'),
26
+ appBuild: resolveOwn('template/build'),
27
+ appPublic: resolveOwn('template/public'),
28
+ appIndexJs: resolveOwn('template/src/index.js'),
29
+ appPackageJson: resolveOwn('template/package.json'),
30
+ appSrc: resolveOwn('template/src'),
31
+ appConfig: resolveOwn('template/config/default'),
32
+ appNodeModules: resolveOwn('template/node_modules'),
33
+ };
34
+ } else {
35
+ module.exports = {
36
+ dotenv: resolveApp('.env'),
37
+ appPath: resolveApp('.'),
38
+ appBuild: resolveApp('build'),
39
+ appPublic: resolveApp('public'),
40
+ appPackageJson: resolveApp('package.json'),
41
+ appSrc: resolveApp('src'),
42
+ appConfig: resolveApp('config/default'),
43
+ appNodeModules: resolveApp('node_modules'),
44
+ };
45
+ }
46
+
47
+ module.exports.srcPaths = [module.exports.appSrc];
48
+ module.exports.useYarn = fs.existsSync(path.join(module.exports.appPath, 'yarn.lock'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machtwatch/react-script",
3
- "version": "1.2.11-alpha.28",
3
+ "version": "1.2.11-alpha.30",
4
4
  "description": "Machtwatch React script",
5
5
  "author": "Danny Reza Miloen <danny@machtwatch.co.id>",
6
6
  "contributors": [],
@@ -15,6 +15,7 @@
15
15
  },
16
16
  "files": [
17
17
  "bin",
18
+ "config",
18
19
  "scripts"
19
20
  ],
20
21
  "main": "./bin/react-script.js",
package/scripts/test.js CHANGED
@@ -9,32 +9,43 @@ process.on('unhandledRejection', err => {
9
9
 
10
10
  const jest = require('jest');
11
11
  const path = require('path');
12
+ const { createRequire } = require('module');
12
13
 
13
14
  const createJestConfig = require('../config/jest/createJestConfig');
14
15
  const paths = require('../config/paths');
15
16
 
17
+ const requireApp = createRequire(`${paths.appPath}/package.json`);
18
+ const { loadConfig } = requireApp('c12');
19
+
16
20
  require('../config/env');
17
21
 
18
- let argv = process.argv.slice(2);
22
+ async function start() {
23
+ const { config } = await loadConfig({ cwd: paths.appPath });
19
24
 
20
- if (argv.indexOf('--coverage') === -1 && argv.indexOf('--watchAll') === -1) {
21
- argv.push('--watchAll');
22
- }
25
+ let argv = process.argv.slice(2);
26
+
27
+ if (argv.indexOf('--coverage') === -1 && argv.indexOf('--watchAll') === -1) {
28
+ argv.push('--watchAll');
29
+ }
23
30
 
24
- const jestConfig = createJestConfig(
25
- relativePath => path.resolve(__dirname, '..', relativePath),
26
- path.resolve(paths.appSrc, '..'),
27
- paths.srcPaths
28
- );
31
+ const jestConfig = createJestConfig(
32
+ relativePath => path.resolve(__dirname, '..', relativePath),
33
+ path.resolve(paths.appSrc, '..'),
34
+ paths.srcPaths,
35
+ config
36
+ );
29
37
 
30
- argv.push(
31
- '--config',
32
- JSON.stringify(
33
- jestConfig
34
- )
35
- );
38
+ argv.push(
39
+ '--config',
40
+ JSON.stringify(
41
+ jestConfig
42
+ )
43
+ );
36
44
 
37
- const testEnvironment = 'jsdom';
38
- argv.push('--coverage', '--env', testEnvironment);
45
+ const testEnvironment = 'jsdom';
46
+ argv.push('--coverage', '--env', testEnvironment);
47
+
48
+ jest.run(argv);
49
+ }
39
50
 
40
- jest.run(argv);
51
+ start();