@itstandu/code-style 1.1.1 → 1.2.1

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
@@ -11,6 +11,7 @@ Production-ready shared ESLint + Prettier configuration library for JavaScript a
11
11
  - **Prettier v3** with Tailwind CSS support
12
12
  - Supports **JavaScript** and **TypeScript**
13
13
  - **Full file type support** - Formats all common file types: JS/JSX, TS/TSX, JSON, CSS/SCSS/LESS, HTML, Markdown, YAML, GraphQL, and more
14
+ - **Dual package exports** - Supports both CommonJS (`require`) and ES modules (`import`)
14
15
  - Framework presets: **React**, **Next.js**, **Vue**, **Angular**, **NestJS**
15
16
  - **Node.js** backend support
16
17
  - Stable import sorting with `eslint-plugin-simple-import-sort`
@@ -47,7 +48,27 @@ yarn add -D @itstandu/code-style
47
48
  bun add -d @itstandu/code-style
48
49
  ```
49
50
 
50
- **Note:** You do NOT need to install `eslint`, `prettier`, or any plugins separately. This package includes all dependencies.
51
+ **Note:**
52
+ - ESLint plugins are bundled and don't need separate installation.
53
+ - Prettier plugins are included but **Prettier requires plugins to be installed in your project's `node_modules`** (not in dependencies of this package).
54
+
55
+ **For pnpm users:** You need to install Prettier plugins in your project:
56
+
57
+ ```bash
58
+ pnpm add -D prettier @prettier/plugin-oxc @prettier/plugin-xml prettier-plugin-tailwindcss
59
+ ```
60
+
61
+ **For npm/yarn users:** Plugins should work automatically, but if you encounter issues, install them explicitly:
62
+
63
+ ```bash
64
+ # npm
65
+ npm install -D prettier @prettier/plugin-oxc @prettier/plugin-xml prettier-plugin-tailwindcss
66
+
67
+ # yarn
68
+ yarn add -D prettier @prettier/plugin-oxc @prettier/plugin-xml prettier-plugin-tailwindcss
69
+ ```
70
+
71
+ The config automatically detects and only loads plugins that are available, so it won't crash if some are missing.
51
72
 
52
73
  ## Quick Start
53
74
 
@@ -55,16 +76,18 @@ After installation, you only need to configure **2 files** to get started:
55
76
 
56
77
  ### 1. ESLint Config
57
78
 
58
- Create `eslint.config.js` (or `eslint.config.mjs`) in your project root:
79
+ Create `eslint.config.js` (CommonJS) or `eslint.config.mjs` (ES modules) in your project root:
59
80
 
60
- **For TypeScript projects:**
81
+ **CommonJS (`eslint.config.js`):**
82
+
83
+ For TypeScript projects:
61
84
  ```javascript
62
85
  const codeStyle = require('@itstandu/code-style')
63
86
 
64
87
  module.exports = [codeStyle.recommended, codeStyle.typescript, codeStyle.node]
65
88
  ```
66
89
 
67
- **For React/Next.js:**
90
+ For React/Next.js:
68
91
  ```javascript
69
92
  const codeStyle = require('@itstandu/code-style')
70
93
 
@@ -72,30 +95,38 @@ module.exports = [codeStyle.recommended, codeStyle.typescript, codeStyle.react]
72
95
  // or codeStyle.next for Next.js
73
96
  ```
74
97
 
75
- **For Vue:**
98
+ **ES Modules (`eslint.config.mjs`):**
99
+
100
+ For TypeScript projects:
76
101
  ```javascript
77
- const codeStyle = require('@itstandu/code-style')
102
+ import codeStyle from '@itstandu/code-style'
78
103
 
79
- module.exports = [codeStyle.recommended, codeStyle.vue]
104
+ export default [codeStyle.recommended, codeStyle.typescript, codeStyle.node]
80
105
  ```
81
106
 
82
- **For JavaScript-only projects:**
107
+ For React/Next.js:
83
108
  ```javascript
84
- const codeStyle = require('@itstandu/code-style')
109
+ import codeStyle from '@itstandu/code-style'
85
110
 
86
- module.exports = [codeStyle.recommended, codeStyle.javascript, codeStyle.node]
111
+ export default [codeStyle.recommended, codeStyle.typescript, codeStyle.react]
112
+ // or codeStyle.next for Next.js
87
113
  ```
88
114
 
89
115
  ### 2. Prettier Config
90
116
 
91
- Create `.prettierrc.js` (or `.prettierrc.cjs`) in your project root:
92
-
117
+ **CommonJS (`.prettierrc.js` or `.prettierrc.cjs`):**
93
118
  ```javascript
94
119
  module.exports = require('@itstandu/code-style/prettier')
95
120
  ```
96
121
 
97
- Or add to `package.json`:
122
+ **ES Modules (`.prettierrc.mjs`):**
123
+ ```javascript
124
+ import prettierConfig from '@itstandu/code-style/prettier'
125
+
126
+ export default prettierConfig
127
+ ```
98
128
 
129
+ **Or add to `package.json`:**
99
130
  ```json
100
131
  {
101
132
  "prettier": "@itstandu/code-style/prettier"
@@ -106,23 +137,59 @@ Or add to `package.json`:
106
137
 
107
138
  ## Usage
108
139
 
140
+ ### CommonJS vs ES Modules
141
+
142
+ This package supports both CommonJS and ES modules:
143
+
144
+ - **CommonJS**: Use `require()` and `module.exports` (works with `.js` files)
145
+ - **ES Modules**: Use `import` and `export` (works with `.mjs` files or `"type": "module"`)
146
+
147
+ The package automatically resolves to the correct format based on your import style.
148
+
109
149
  ### Available Presets
110
150
 
111
151
  #### Base Preset (Minimal)
152
+
153
+ **CommonJS:**
112
154
  ```javascript
155
+ const codeStyle = require('@itstandu/code-style')
113
156
  module.exports = [codeStyle.base, codeStyle.typescript, codeStyle.node]
114
157
  ```
115
158
 
159
+ **ES Modules:**
160
+ ```javascript
161
+ import codeStyle from '@itstandu/code-style'
162
+ export default [codeStyle.base, codeStyle.typescript, codeStyle.node]
163
+ ```
164
+
116
165
  #### Recommended Preset (Default, Better Safety)
166
+
167
+ **CommonJS:**
117
168
  ```javascript
169
+ const codeStyle = require('@itstandu/code-style')
118
170
  module.exports = [codeStyle.recommended, codeStyle.typescript, codeStyle.node]
119
171
  ```
120
172
 
173
+ **ES Modules:**
174
+ ```javascript
175
+ import codeStyle from '@itstandu/code-style'
176
+ export default [codeStyle.recommended, codeStyle.typescript, codeStyle.node]
177
+ ```
178
+
121
179
  #### Strict Preset (Opt-in, includes boundaries)
180
+
181
+ **CommonJS:**
122
182
  ```javascript
183
+ const codeStyle = require('@itstandu/code-style')
123
184
  module.exports = [codeStyle.strict, codeStyle.typescript, codeStyle.node]
124
185
  ```
125
186
 
187
+ **ES Modules:**
188
+ ```javascript
189
+ import codeStyle from '@itstandu/code-style'
190
+ export default [codeStyle.strict, codeStyle.typescript, codeStyle.node]
191
+ ```
192
+
126
193
  ### Framework Presets
127
194
 
128
195
  - **React**: `codeStyle.react`
package/index.mjs ADDED
@@ -0,0 +1,19 @@
1
+ import { createRequire } from 'module'
2
+ import { fileURLToPath } from 'url'
3
+ import { dirname, join } from 'path'
4
+
5
+ const __filename = fileURLToPath(import.meta.url)
6
+ const __dirname = dirname(__filename)
7
+ const require = createRequire(import.meta.url)
8
+
9
+ export const base = require(join(__dirname, 'eslint', 'base.js'))
10
+ export const javascript = require(join(__dirname, 'eslint', 'javascript.js'))
11
+ export const typescript = require(join(__dirname, 'eslint', 'typescript.js'))
12
+ export const node = require(join(__dirname, 'eslint', 'node.js'))
13
+ export const react = require(join(__dirname, 'eslint', 'react.js'))
14
+ export const next = require(join(__dirname, 'eslint', 'next.js'))
15
+ export const vue = require(join(__dirname, 'eslint', 'vue.js'))
16
+ export const angular = require(join(__dirname, 'eslint', 'angular.js'))
17
+ export const nest = require(join(__dirname, 'eslint', 'nest.js'))
18
+ export const recommended = require(join(__dirname, 'eslint', 'recommended.js'))
19
+ export const strict = require(join(__dirname, 'eslint', 'strict.js'))
package/package.json CHANGED
@@ -1,17 +1,27 @@
1
1
  {
2
2
  "name": "@itstandu/code-style",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "Production-ready shared ESLint + Prettier configuration for JavaScript and TypeScript projects",
5
5
  "type": "commonjs",
6
- "main": "index.js",
6
+ "main": "./index.js",
7
+ "module": "./index.mjs",
7
8
  "exports": {
8
- ".": "./index.js",
9
- "./prettier": "./prettier/index.cjs"
9
+ ".": {
10
+ "require": "./index.js",
11
+ "import": "./index.mjs",
12
+ "default": "./index.js"
13
+ },
14
+ "./prettier": {
15
+ "require": "./prettier/index.cjs",
16
+ "import": "./prettier/index.mjs",
17
+ "default": "./prettier/index.cjs"
18
+ }
10
19
  },
11
20
  "files": [
12
21
  "eslint",
13
22
  "prettier",
14
23
  "index.js",
24
+ "index.mjs",
15
25
  "README.md",
16
26
  ".prettierignore"
17
27
  ],
@@ -1,3 +1,22 @@
1
+ // Helper function to try requiring a plugin, returns null if not found
2
+ function tryRequire(pluginName) {
3
+ try {
4
+ return require(pluginName)
5
+ } catch (e) {
6
+ return null
7
+ }
8
+ }
9
+
10
+ // Build plugins array - only include plugins that are installed
11
+ const plugins = []
12
+ const oxcPlugin = tryRequire('@prettier/plugin-oxc')
13
+ const xmlPlugin = tryRequire('@prettier/plugin-xml')
14
+ const tailwindPlugin = tryRequire('prettier-plugin-tailwindcss')
15
+
16
+ if (oxcPlugin) plugins.push('@prettier/plugin-oxc')
17
+ if (xmlPlugin) plugins.push('@prettier/plugin-xml')
18
+ if (tailwindPlugin) plugins.push('prettier-plugin-tailwindcss')
19
+
1
20
  module.exports = {
2
21
  // Basic formatting
3
22
  semi: true,
@@ -40,10 +59,7 @@ module.exports = {
40
59
  xmlSortAttributesByKey: false,
41
60
  xmlWhitespaceSensitivity: 'strict',
42
61
 
43
- // Plugins - order matters: oxc first for parsing, tailwindcss last for class sorting
44
- plugins: [
45
- '@prettier/plugin-oxc',
46
- '@prettier/plugin-xml',
47
- 'prettier-plugin-tailwindcss',
48
- ],
62
+ // Plugins - automatically detected, only loaded if installed
63
+ // Order matters: oxc first for parsing, tailwindcss last for class sorting
64
+ plugins,
49
65
  }
@@ -0,0 +1,74 @@
1
+ import { createRequire } from 'module'
2
+ import { fileURLToPath } from 'url'
3
+ import { dirname } from 'path'
4
+
5
+ const __filename = fileURLToPath(import.meta.url)
6
+ const __dirname = dirname(__filename)
7
+ const require = createRequire(import.meta.url)
8
+
9
+ // Helper function to try requiring a plugin, returns null if not found
10
+ function tryRequire(pluginName) {
11
+ try {
12
+ require.resolve(pluginName)
13
+ return pluginName
14
+ } catch (e) {
15
+ return null
16
+ }
17
+ }
18
+
19
+ // Build plugins array - only include plugins that are installed
20
+ const plugins = []
21
+ const oxcPlugin = tryRequire('@prettier/plugin-oxc')
22
+ const xmlPlugin = tryRequire('@prettier/plugin-xml')
23
+ const tailwindPlugin = tryRequire('prettier-plugin-tailwindcss')
24
+
25
+ if (oxcPlugin) plugins.push(oxcPlugin)
26
+ if (xmlPlugin) plugins.push(xmlPlugin)
27
+ if (tailwindPlugin) plugins.push(tailwindPlugin)
28
+
29
+ export default {
30
+ // Basic formatting
31
+ semi: true,
32
+ singleQuote: true,
33
+ trailingComma: 'all',
34
+ printWidth: 80,
35
+ tabWidth: 2,
36
+ useTabs: false,
37
+
38
+ // Bracket and spacing
39
+ bracketSpacing: true,
40
+ bracketSameLine: false,
41
+ arrowParens: 'always',
42
+
43
+ // JSX/HTML specific
44
+ jsxSingleQuote: false,
45
+ singleAttributePerLine: false,
46
+
47
+ // Quotes
48
+ quoteProps: 'as-needed',
49
+
50
+ // Line endings and whitespace
51
+ endOfLine: 'lf',
52
+ proseWrap: 'preserve',
53
+ htmlWhitespaceSensitivity: 'css',
54
+
55
+ // Vue specific
56
+ vueIndentScriptAndStyle: false,
57
+
58
+ // Pragma (for legacy systems)
59
+ insertPragma: false,
60
+ requirePragma: false,
61
+
62
+ // Embedded language formatting
63
+ embeddedLanguageFormatting: 'auto',
64
+
65
+ // XML/SVG specific options
66
+ xmlQuoteAttributes: 'preserve',
67
+ xmlSelfClosingSpace: true,
68
+ xmlSortAttributesByKey: false,
69
+ xmlWhitespaceSensitivity: 'strict',
70
+
71
+ // Plugins - automatically detected, only loaded if installed
72
+ // Order matters: oxc first for parsing, tailwindcss last for class sorting
73
+ plugins,
74
+ }