presetter-preset-react 5.0.0 → 6.1.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.
package/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  ## Features
20
20
 
21
- **presetter-preset-react** is an opinionated preset for you to setup a React project in a fraction of time you usually take via [**presetter**](https://github.com/alvis/presetter).
21
+ **presetter-preset-react** is an extension of [**presetter-preset-web**](https://github.com/alvis/presetter) with additional tools to help you to develop a React project with ease via [**presetter**](https://github.com/alvis/presetter).
22
22
 
23
23
  - ✨ TSX support
24
24
  - 🧪 @testing-library/react
@@ -28,15 +28,31 @@
28
28
 
29
29
  [**FULL DOCUMENTATION IS AVAILABLE HERE**](https://github.com/alvis/presetter/blob/master/README.md)
30
30
 
31
- 1. Bootstrap your project with `presetter-preset-esm` & `presetter-preset-react`
31
+ ### 1. Bootstrap your project with presetter-preset-react
32
32
 
33
- ```shell
34
- npx presetter use presetter-preset presetter-preset-react
33
+ On your project root, create a `presetter.config.ts` file with the following content:
34
+
35
+ ```typescript
36
+ // presetter.config.ts
37
+
38
+ import { preset } from 'presetter';
39
+ import esm from 'presetter-preset-esm';
40
+ import react from 'presetter-preset-react';
41
+
42
+ export default preset('project name', {
43
+ // NOTE
44
+ // you don't need to extends presetter-preset-web presets here since they are already included in the react preset
45
+ // however, you may need an additional preset like presetter-preset-esm for ESM support and other basic toolings
46
+ extends: [esm, react],
47
+ override: {
48
+ // override the configuration here
49
+ },
50
+ });
35
51
  ```
36
52
 
37
- That's. One command and you're set.
53
+ Then, install your project as usual with `npm install` or any package manager you prefer.
38
54
 
39
- 2. Develop and run life cycle scripts provided by the preset
55
+ ### 2. Develop and run life cycle scripts provided by the preset
40
56
 
41
57
  At this point, all development packages specified in the preset are installed,
42
58
  and now you can try to run some example life cycle scripts (e.g. run prepare).
@@ -45,17 +61,20 @@ and now you can try to run some example life cycle scripts (e.g. run prepare).
45
61
 
46
62
  ## Project Structure
47
63
 
48
- After installation, your project file structure should resemble the following or with more configuration files if you also installed other presets such as [`presetter-preset-esm`](https://github.com/alvis/presetter/blob/master/packages/preset-esm).
64
+ After installation, your project file structure should resemble the following, or include more configuration files if you also installed other presets.
65
+
66
+ Implement your business logic under `source` and prepare tests under `spec`.
67
+ The `.d.ts` files are handy type definitions for you to import `.css` or image files in typescript.
49
68
 
50
- Implement your business logic under `source` and prepare tests under `spec`. The `.d.ts` files are handy type definitions for you to import `.css` or image files in typescript.
69
+ **NOTE** You will notice there's no additional configuration file on your root folder like other presets such as [`presetter-preset-esm`](https://github.com/alvis/presetter/blob/master/packages/preset-esm).
70
+ It's because `presetter-preset-react` extends `presetter-preset-web` which is a bundle only preset, meaning it only helps you to install the development packages specified in this preset only.
51
71
 
52
- **TIPS** You can always change the source directory to other (e.g. src) by setting the `source` variable in `.presetterrc.json`. See the [customization](https://github.com/alvis/presetter/blob/master/packages/preset-react#customization) section below for more details.
72
+ **TIPS** You can always change the source directory to other (e.g. src) by setting the `source` variable in `presetter.config.ts`. See the [customization](https://github.com/alvis/presetter/blob/master/packages/preset-essentials#customization) section below for more details.
53
73
 
54
74
  ```
55
75
  (root)
56
- ├─ .eslintrc.json
57
76
  ├─ .git
58
- ├─ .presetterrc.json
77
+ ├─ presetter.config.ts
59
78
  ├─ node_modules
60
79
  ├─ source
61
80
  │ ├─ <folders>
@@ -67,6 +86,7 @@ Implement your business logic under `source` and prepare tests under `spec`. The
67
86
  │ ├─ image.d.ts
68
87
  │ ├─ style.d.ts
69
88
  │ ├─ (type).d.ts
89
+ ├─ eslint.config.ts
70
90
  ├─ package.json
71
91
  └─ tsconfig.json
72
92
  ```
@@ -74,34 +94,16 @@ Implement your business logic under `source` and prepare tests under `spec`. The
74
94
  ## Customization
75
95
 
76
96
  By default, this preset exports a handy configuration set for a React project written in typescript.
77
- But you can further customize (either extending or replacing) the configuration by specifying the change in the config file (`.presetterrc` or `.presetterrc.json`).
78
-
79
- These settings are available in the `config` field in the config file. For directories, the setting is specified in the `variable` field.
80
-
81
- The structure of `.presetterrc` should follow the interface below:
82
-
83
- ```ts
84
- interface PresetterRC {
85
- /** name(s) of the preset e.g. presetter-preset-react */
86
- name: string | string[];
87
- /** additional configuration passed to the preset for generating the configuration files */
88
- config?: {
89
- // ┌─ configuration for other tools via other presets (e.g. presetter-preset-esm)
90
- // ...
91
-
92
- /** configuration to be merged with .eslintrc */
93
- eslint?: Record<string, unknown>;
94
- /** configuration to be merged with tsconfig.json */
95
- tsconfig?: Record<string, unknown>;
96
- /** variables to be substituted in templates */
97
- variable?: {
98
- /** the directory containing all source code (default: source) */
99
- source?: string;
100
- /** the directory containing all typing files (default: types) */
101
- types?: string;
102
- /** the directory containing all output tile (default: source) */
103
- output?: string;
104
- };
105
- };
106
- }
107
- ```
97
+
98
+ You can further customize (either extending or replacing) the configuration by specifying the changes in the config file `presetter.config.ts`.
99
+
100
+ ## Script Template Summary
101
+
102
+ - **`run build`**: Transpile source code from typescript and replace any mapped paths
103
+ - **`run clean`**: Clean up any previously transpiled code
104
+ - **`run develop -- <file path>`**: Create a service that run the specified file whenever the source has changed
105
+ - **`run test`**: Run all tests
106
+ - **`run watch`**: Rerun all tests whenever the source has change
107
+ - **`run coverage`**: Run all test with coverage report
108
+ - **`run release`**: Bump the version and automatically generate a change log
109
+ - **`run release -- --prerelease <tag>`**: Release with a prerelease tag
@@ -0,0 +1,6 @@
1
+ import type { Linter } from 'eslint';
2
+ declare const _default: import("presetter").PresetContent<{
3
+ default: Linter.Config[];
4
+ }>;
5
+ export default _default;
6
+ //# sourceMappingURL=eslint.override.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eslint.override.d.ts","sourceRoot":"","sources":["../source/eslint.override.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;aAEL,MAAM,CAAC,MAAM,EAAE;;AAA/C,wBAuGG"}
@@ -0,0 +1,103 @@
1
+ /* v8 ignore start */
2
+ import testing from 'eslint-plugin-testing-library';
3
+ import { asset } from 'presetter';
4
+ export default asset((current) => {
5
+ const configs = current?.default ?? [];
6
+ const hasTypescriptEslint = configs.some((config) => !!config.plugins?.['@typescript-eslint']);
7
+ const hasJsDoc = configs.some((config) => !!config.plugins?.jsdoc);
8
+ return {
9
+ default: [
10
+ ...configs,
11
+ {
12
+ name: 'presetter-preset-react:override:test-files',
13
+ files: ['**/__tests__/**/*.[jt]sx', '**/?(*.)+(spec|test).[jt]sx'],
14
+ ...testing.configs['flat/react'],
15
+ },
16
+ {
17
+ name: 'presetter-preset-react:override:react-files',
18
+ files: ['**/*.[jt]sx'],
19
+ rules: {
20
+ 'max-lines-per-function': [
21
+ 'warn',
22
+ {
23
+ max: 120, // extend the default to 120 lines for functional components
24
+ },
25
+ ],
26
+ ...(hasTypescriptEslint && {
27
+ '@typescript-eslint/naming-convention': [
28
+ 'error', // add PascalCase to the list for functional components
29
+ {
30
+ selector: 'default',
31
+ format: [
32
+ 'camelCase', // default
33
+ ],
34
+ leadingUnderscore: 'allow', // default
35
+ trailingUnderscore: 'allow', // default
36
+ },
37
+ {
38
+ selector: 'import',
39
+ format: [
40
+ 'camelCase', // default, for functions and variables
41
+ 'PascalCase', // default, for classes
42
+ ],
43
+ },
44
+ {
45
+ selector: 'function',
46
+ format: [
47
+ 'camelCase', // default
48
+ 'PascalCase', // for react components
49
+ ],
50
+ },
51
+ {
52
+ selector: 'objectLiteralMethod',
53
+ format: null, // disable as an object literal is likely used for assigning parameters to a third-party library
54
+ },
55
+ {
56
+ selector: 'objectLiteralProperty',
57
+ format: null, // disable as an object literal is likely used for assigning parameters to a third-party library
58
+ },
59
+ {
60
+ selector: 'parameter',
61
+ format: [
62
+ 'camelCase', // default
63
+ 'PascalCase', // for react components
64
+ ],
65
+ leadingUnderscore: 'allow', // default
66
+ trailingUnderscore: 'allow', // default
67
+ },
68
+ {
69
+ selector: 'variable',
70
+ format: [
71
+ 'PascalCase', // for react functional components
72
+ 'camelCase', // default, for variables
73
+ 'UPPER_CASE', // default, for constants
74
+ ],
75
+ leadingUnderscore: 'allow', // add _prefix to ignore the rule
76
+ trailingUnderscore: 'allow', // add _suffix to ignore the rule
77
+ },
78
+ {
79
+ selector: 'typeLike',
80
+ format: [
81
+ 'PascalCase', // default
82
+ ],
83
+ },
84
+ ],
85
+ }),
86
+ ...(hasJsDoc && {
87
+ 'jsdoc/require-returns': [
88
+ 'error', // tell us what the function is expected to return unless it's a JSX element
89
+ {
90
+ checkGetters: false,
91
+ contexts: [
92
+ "FunctionDeclaration:has(BlockStatement > ReturnStatement:not([argument.type='JSXElement']))",
93
+ "ArrowFunctionExpression:has(BlockStatement > ReturnStatement:not([argument.type='JSXElement']))",
94
+ ],
95
+ },
96
+ ],
97
+ }),
98
+ },
99
+ },
100
+ ],
101
+ };
102
+ });
103
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXNsaW50Lm92ZXJyaWRlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc291cmNlL2VzbGludC5vdmVycmlkZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxxQkFBcUI7QUFFckIsT0FBTyxPQUFPLE1BQU0sK0JBQStCLENBQUM7QUFDcEQsT0FBTyxFQUFFLEtBQUssRUFBRSxNQUFNLFdBQVcsQ0FBQztBQUlsQyxlQUFlLEtBQUssQ0FBK0IsQ0FBQyxPQUFPLEVBQUUsRUFBRTtJQUM3RCxNQUFNLE9BQU8sR0FBRyxPQUFPLEVBQUUsT0FBTyxJQUFJLEVBQUUsQ0FBQztJQUV2QyxNQUFNLG1CQUFtQixHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQ3RDLENBQUMsTUFBTSxFQUFFLEVBQUUsQ0FBQyxDQUFDLENBQUMsTUFBTSxDQUFDLE9BQU8sRUFBRSxDQUFDLG9CQUFvQixDQUFDLENBQ3JELENBQUM7SUFFRixNQUFNLFFBQVEs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s0QkFDckY7Z0NBQ0UsWUFBWSxFQUFFLEtBQUs7Z0NBQ25CLFFBQVEsRUFBRTtvQ0FDUiw2RkFBNkY7b0NBQzdGLGlHQUFpRztpQ0FDbEc7NkJBQ0Y7eUJBQ0Y7cUJBQ0YsQ0FBQztpQkFDSDthQUNGO1NBQ2lCO0tBQ3JCLENBQUM7QUFDSixDQUFDLENBQUMsQ0FBQyJ9
@@ -0,0 +1,4 @@
1
+ import type { Linter } from 'eslint';
2
+ declare const _default: Linter.Config[];
3
+ export default _default;
4
+ //# sourceMappingURL=eslint.template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eslint.template.d.ts","sourceRoot":"","sources":["../source/eslint.template.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;wBA8BhC,MAAM,CAAC,MAAM,EAAE;AA5BpB,wBA4BqB"}
@@ -0,0 +1,32 @@
1
+ /* v8 ignore start */
2
+ import react from 'eslint-plugin-react';
3
+ export default [
4
+ react.configs.flat.recommended,
5
+ react.configs.flat['jsx-runtime'],
6
+ {
7
+ name: 'presetter-preset-react',
8
+ plugins: { react },
9
+ languageOptions: {
10
+ parserOptions: {
11
+ ecmaFeatures: {
12
+ jsx: true,
13
+ },
14
+ },
15
+ },
16
+ rules: {
17
+ 'react/boolean-prop-naming': 'warn', // enforce consistent naming for boolean props
18
+ 'react/button-has-type': 'warn', // enforce button elements to contain a type attribute
19
+ 'react/destructuring-assignment': 'warn', // enforce usage of destructuring assignment in component
20
+ 'react/prop-types': 'off', // we use TypeScript for prop types
21
+ 'react/sort-comp': 'warn', // enforce component methods order
22
+ 'react/jsx-sort-props': [
23
+ 'warn', // enforce props order
24
+ {
25
+ callbacksLast: true,
26
+ shorthandFirst: true,
27
+ },
28
+ ],
29
+ },
30
+ },
31
+ ];
32
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXNsaW50LnRlbXBsYXRlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc291cmNlL2VzbGludC50ZW1wbGF0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxxQkFBcUI7QUFFckIsT0FBTyxLQUFLLE1BQU0scUJBQXFCLENBQUM7QUFJeEMsZUFBZTtJQUNiLEtBQUssQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLFdBQVc7SUFDOUIsS0FBSyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsYUFBYSxDQUFDO0lBQ2pDO1FBQ0UsSUFBSSxFQUFFLHdCQUF3QjtRQUM5QixPQUFPLEVBQUUsRUFBRSxLQUFLLEVBQUU7UUFDbEIsZUFBZSxFQUFFO1lBQ2YsYUFBYSxFQUFFO2dCQUNiLFlBQVksRUFBRTtvQkFDWixHQUFHLEVBQUUsSUFBSTtpQkFDVjthQUNGO1NBQ0Y7UUFDRCxLQUFLLEVBQUU7WUFDTCwyQkFBMkIsRUFBRSxNQUFNLEVBQUUsOENBQThDO1lBQ25GLHVCQUF1QixFQUFFLE1BQU0sRUFBRSxzREFBc0Q7WUFDdkYsZ0NBQWdDLEVBQUUsTUFBTSxFQUFFLHlEQUF5RDtZQUNuRyxrQkFBa0IsRUFBRSxLQUFLLEVBQUUsbUNBQW1DO1lBQzlELGlCQUFpQixFQUFFLE1BQU0sRUFBRSxrQ0FBa0M7WUFDN0Qsc0JBQXNCLEVBQUU7Z0JBQ3RCLE1BQU0sRUFBRSxzQkFBc0I7Z0JBQzlCO29CQUNFLGFBQWEsRUFBRSxJQUFJO29CQUNuQixjQUFjLEVBQUUsSUFBSTtpQkFDckI7YUFDRjtTQUNGO0tBQ0Y7Q0FDaUIsQ0FBQyJ9
package/lib/index.d.ts CHANGED
@@ -1,24 +1,24 @@
1
- import type { PresetAsset } from 'presetter-types';
2
1
  /** config for this preset */
3
- export type PresetConfig = {
2
+ export interface PresetConfig {
4
3
  /** configuration to be merged with .eslintrc */
5
4
  eslint?: Record<string, unknown>;
6
5
  /** configuration to be merged with tsconfig.json */
7
6
  tsconfig?: Record<string, unknown>;
8
- };
7
+ }
9
8
  /** list of configurable variables */
10
- export type Variable = {
9
+ export interface Variables {
11
10
  /** the directory containing all source code (default: source) */
12
- source?: string;
11
+ source: string;
13
12
  /** the directory containing all extra typing files (default: types) */
14
- types?: string;
13
+ types: string;
15
14
  /** the directory containing all the compiled files (default: lib) */
16
- output?: string;
15
+ output: string;
16
+ }
17
+ export declare const DEFAULT_VARIABLES: {
18
+ source: string;
19
+ types: string;
20
+ output: string;
17
21
  };
18
- export declare const DEFAULT_VARIABLE: Variable;
19
- /**
20
- * get the list of templates provided by this preset
21
- * @returns list of preset templates
22
- */
23
- export default function (): Promise<PresetAsset>;
22
+ declare const _default: import("presetter-types").Preset;
23
+ export default _default;
24
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAQnD,6BAA6B;AAC7B,MAAM,MAAM,YAAY,GAAG;IACzB,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,CAAC;AAEF,qCAAqC;AACrC,MAAM,MAAM,QAAQ,GAAG;IACrB,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,QAI9B,CAAC;AAmCF;;;GAGG;AACH,4BAAkC,OAAO,CAAC,WAAW,CAAC,CAQrD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAeA,6BAA6B;AAC7B,MAAM,WAAW,YAAY;IAC3B,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,qCAAqC;AACrC,MAAM,WAAW,SAAS;IACxB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,iBAAiB;;;;CAIT,CAAC;;AAKtB,wBA4BG"}
package/lib/index.js CHANGED
@@ -1,56 +1,41 @@
1
- /*
2
- * *** MIT LICENSE ***
3
- * -------------------------------------------------------------------------
4
- * This code may be modified and distributed under the MIT license.
5
- * See the LICENSE file for details.
6
- * -------------------------------------------------------------------------
7
- *
8
- * @summary Preset for a React project
9
- *
10
- * @author Alvis HT Tang <alvis@hilbert.space>
11
- * @license MIT
12
- * @copyright Copyright (c) 2021 - All Rights Reserved.
13
- * -------------------------------------------------------------------------
14
- */
15
- import { dirname, join, resolve } from 'node:path';
1
+ import { dirname, resolve } from 'node:path';
16
2
  import { fileURLToPath } from 'node:url';
3
+ import web from 'presetter-preset-web';
4
+ import { preset } from 'presetter-types';
5
+ import eslintOverride from './eslint.override.js';
6
+ import * as eslint from './eslint.template.js';
17
7
  const DIR = fileURLToPath(dirname(import.meta.url));
18
8
  // paths to the template directory
19
9
  const TEMPLATES = resolve(DIR, '..', 'templates');
20
- const CONFIGS = resolve(DIR, '..', 'configs');
21
- export const DEFAULT_VARIABLE = {
10
+ const OVERRIDES = resolve(DIR, '..', 'overrides');
11
+ export const DEFAULT_VARIABLES = {
22
12
  source: 'source',
23
13
  types: 'types',
24
14
  output: 'lib',
25
15
  };
26
16
  const IMAGE_TYPE = 'image.d.ts';
27
17
  const STYLE_TYPE = 'style.d.ts';
28
- const template = ({ custom: { variable: { types }, }, }) => ({
29
- /* eslint-disable @typescript-eslint/naming-convention */
30
- '.eslintrc.json': resolve(TEMPLATES, 'eslintrc.yaml'),
31
- 'tsconfig.json': resolve(TEMPLATES, 'tsconfig.yaml'),
32
- 'tsconfig.build.json': resolve(TEMPLATES, 'tsconfig.build.yaml'),
33
- [join(types, IMAGE_TYPE)]: resolve(TEMPLATES, IMAGE_TYPE),
34
- [join(types, STYLE_TYPE)]: resolve(TEMPLATES, STYLE_TYPE),
35
- /* eslint-enable @typescript-eslint/naming-convention */
18
+ export default preset('presetter-preset-react', {
19
+ extends: [web],
20
+ variables: DEFAULT_VARIABLES,
21
+ scripts: resolve(TEMPLATES, 'scripts.yaml'),
22
+ assets: ({ variables }) => ({
23
+ '.gitignore': (current, { variables }) => [
24
+ ...(current ?? []),
25
+ `/${variables.types}/${IMAGE_TYPE}`,
26
+ `/${variables.types}/${STYLE_TYPE}`,
27
+ ],
28
+ 'eslint.config.ts': eslint,
29
+ 'tsconfig.json': resolve(TEMPLATES, 'tsconfig.yaml'),
30
+ 'tsconfig.build.json': resolve(TEMPLATES, 'tsconfig.build.yaml'),
31
+ [`${variables.types}/${IMAGE_TYPE}`]: resolve(TEMPLATES, IMAGE_TYPE),
32
+ [`${variables.types}/${STYLE_TYPE}`]: resolve(TEMPLATES, STYLE_TYPE),
33
+ }),
34
+ override: {
35
+ assets: {
36
+ '.lintstagedrc.json': resolve(OVERRIDES, 'lintstaged.yaml'),
37
+ 'eslint.config.ts': eslintOverride,
38
+ },
39
+ },
36
40
  });
37
- const noSymlinks = ({ custom: { variable: { types }, }, }) => [join(types, IMAGE_TYPE), join(types, STYLE_TYPE)];
38
- const supplementaryConfig = () => ({
39
- eslint: resolve(CONFIGS, 'eslint.yaml'),
40
- gitignore: ({ custom: { variable: { types }, }, }) => [join('/', types, IMAGE_TYPE), join('/', types, STYLE_TYPE)],
41
- lintstaged: resolve(CONFIGS, 'lintstaged.yaml'),
42
- });
43
- /**
44
- * get the list of templates provided by this preset
45
- * @returns list of preset templates
46
- */
47
- export default async function () {
48
- return {
49
- scripts: resolve(TEMPLATES, 'scripts.yaml'),
50
- template,
51
- noSymlinks,
52
- supplementaryConfig,
53
- variable: DEFAULT_VARIABLE,
54
- };
55
- }
56
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zb3VyY2UvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7Ozs7Ozs7R0FhRztBQUVILE9BQU8sRUFBRSxPQUFPLEVBQUUsSUFBSSxFQUFFLE9BQU8sRUFBRSxNQUFNLFdBQVcsQ0FBQztBQUNuRCxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sVUFBVSxDQUFDO0FBSXpDLE1BQU0sR0FBRyxHQUFHLGFBQWEsQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDO0FBRXBELGtDQUFrQztBQUNsQyxNQUFNLFNBQVMsR0FBRyxPQUFPLENBQUMsR0FBRyxFQUFFLElBQUksRUFBRSxXQUFXLENBQUMsQ0FBQztBQUNsRCxNQUFNLE9BQU8sR0FBRyxPQUFPLENBQUMsR0FBRyxFQUFFLElBQUksRUFBRSxTQUFTLENBQUMsQ0FBQztBQW9COUMsTUFBTSxDQUFDLE1BQU0sZ0JBQWdCLEdBQWE7SUFDeEMsTUFBTSxFQUFFLFFBQVE7SUFDaEIsS0FBSyxFQUFFLE9BQU87SUFDZCxNQUFNLEVBQUUsS0FBSztDQUNkLENBQUM7QUFFRixNQUFNLFVBQVUsR0FBRyxZQUFZLENBQUM7QUFDaEMsTUFBTSxVQUFVLEdBQUcsWUFBW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ENBQUM7UUFDcEQscUJBQXFCLEVBQUUsT0FBTyxDQUFDLFNBQVMsRUFBRSxxQkFBcUIsQ0FBQztRQUNoRSxDQUFDLEdBQUcsU0FBUyxDQUFDLEtBQU0sSUFBSSxVQUFVLEVBQWtCLENBQUMsRUFBRSxPQUFPLENBQzVELFNBQVMsRUFDVCxVQUFVLENBQ1g7UUFDRCxDQUFDLEdBQUcsU0FBUyxDQUFDLEtBQU0sSUFBSSxVQUFVLEVBQWtCLENBQUMsRUFBRSxPQUFPLENBQzVELFNBQVMsRUFDVCxVQUFVLENBQ1g7S0FDRixDQUFDO0lBQ0YsUUFBUSxFQUFFO1FBQ1IsTUFBTSxFQUFFO1lBQ04sb0JBQW9CLEVBQUUsT0FBTyxDQUFDLFNBQVMsRUFBRSxpQkFBaUIsQ0FBQztZQUMzRCxrQkFBa0IsRUFBRSxjQUFjO1NBQ25DO0tBQ0Y7Q0FDRixDQUFDLENBQUMifQ==
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presetter-preset-react",
3
- "version": "5.0.0",
3
+ "version": "6.1.0",
4
4
  "description": "An opinionated presetter preset for a React project",
5
5
  "keywords": [
6
6
  "presetter",
@@ -15,6 +15,12 @@
15
15
  "main": "lib/index.js",
16
16
  "types": "lib/index.d.ts",
17
17
  "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "default": "./lib/index.js",
21
+ "types": "./lib/index.d.ts"
22
+ }
23
+ },
18
24
  "repository": {
19
25
  "type": "git",
20
26
  "url": "git+https://github.com/alvis/presetter.git"
@@ -24,13 +30,14 @@
24
30
  "@types/react": "^18.0.0",
25
31
  "eslint-plugin-react": "^7.0.0",
26
32
  "eslint-plugin-testing-library": "^6.0.0",
27
- "presetter": "5.0.0"
33
+ "presetter": "6.1.0",
34
+ "presetter-preset-web": "6.1.0"
28
35
  },
29
36
  "devDependencies": {
30
- "presetter": "5.0.0"
37
+ "presetter": "6.1.0"
31
38
  },
32
39
  "dependencies": {
33
- "presetter-types": "5.0.0"
40
+ "presetter-types": "6.1.0"
34
41
  },
35
42
  "scripts": {
36
43
  "build": "run build",
@@ -1,21 +0,0 @@
1
- overrides:
2
- - files:
3
- - '{source}/**/*.tsx'
4
- rules:
5
- max-lines-per-function:
6
- - error
7
- - max: 90
8
- rules:
9
- '@typescript-eslint/naming-convention':
10
- - error
11
- - selector: variable
12
- types:
13
- - function
14
- format:
15
- - camelCase
16
- - PascalCase
17
- jsdoc/require-returns: # tell us what the function is expected to return
18
- 1:
19
- contexts:
20
- - FunctionDeclaration:has(BlockStatement > ReturnStatement:not([argument.type='JSXElement']))
21
- - ArrowFunctionExpression:has(BlockStatement > ReturnStatement:not([argument.type='JSXElement']))
@@ -1,60 +0,0 @@
1
- extends:
2
- - plugin:react/recommended
3
- - plugin:react/jsx-runtime
4
- rules:
5
- react/boolean-prop-naming: warn
6
- react/button-has-type: warn
7
- react/destructuring-assignment: warn
8
- react/prop-types: off
9
- react/sort-comp: warn
10
- react/jsx-sort-props:
11
- - warn
12
- - callbacksLast: true
13
- shorthandFirst: true
14
- overrides:
15
- - files:
16
- - '**/__tests__/**/*.[jt]sx'
17
- - '**/?(*.)+(spec|test).[jt]sx'
18
- extends:
19
- - plugin:testing-library/react
20
- - files:
21
- - src/**/*.tsx
22
- rules:
23
- max-lines-per-function:
24
- - warn
25
- - max: 120
26
- '@typescript-eslint/naming-convention': # use JS/TS naming convention
27
- - error
28
- - selector: default
29
- format:
30
- - camelCase # default
31
- leadingUnderscore: allow # default
32
- trailingUnderscore: allow # default
33
- - selector: import
34
- format:
35
- - camelCase # default, for functions and variables
36
- - PascalCase # default, for classes
37
- - selector: function
38
- format:
39
- - camelCase # default
40
- - PascalCase # for react components
41
- - selector: objectLiteralMethod
42
- format: null # disable as an object literal is likely used for assigning parameters to a third-party library
43
- - selector: objectLiteralProperty
44
- format: null # disable as an object literal is likely used for assigning parameters to a third-party library
45
- - selector: parameter
46
- format:
47
- - camelCase # default
48
- - PascalCase # for react components
49
- leadingUnderscore: allow # default
50
- trailingUnderscore: allow # default
51
- - selector: variable
52
- format:
53
- - PascalCase # for react functional components
54
- - camelCase # default
55
- - UPPER_CASE # default, for constants
56
- leadingUnderscore: allow
57
- trailingUnderscore: allow
58
- - selector: typeLike
59
- format:
60
- - PascalCase # default
File without changes