esupgrade 2025.0.0 → 2025.0.2

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.
@@ -32,6 +32,12 @@ repos:
32
32
  args: [--no-passive]
33
33
  - repo: local
34
34
  hooks:
35
+ - id: esupgrade
36
+ name: esupgrade
37
+ entry: npx .
38
+ args: [--write]
39
+ language: system
40
+ types_or: [javascript]
35
41
  - id: prettier
36
42
  name: prettier
37
43
  entry: prettier --check --write --ignore-unknown
@@ -40,14 +46,9 @@ repos:
40
46
  language: node
41
47
  additional_dependencies: ["prettier"]
42
48
  types_or: [javascript]
43
- # - id: esupgrade
44
- # name: esupgrade
45
- # entry: npx . --check
46
- # args: [--write]
47
- # language: system
48
- # types_or: [javascript]
49
49
  ci:
50
50
  autoupdate_schedule: weekly
51
51
  skip:
52
52
  - no-commit-to-branch
53
53
  - write-good
54
+ - esupgrade
@@ -1,7 +1,6 @@
1
1
  - id: esupgrade
2
2
  name: esupgrade
3
- entry: npx esupgrade --check
4
- args: [--write]
5
- language: system
6
- types: [javascript, jsx, ts, tsx]
7
- pass_filenames: true
3
+ entry: esupgrade
4
+ args: [--check, --write]
5
+ language: node
6
+ types_or: [javascript, jsx, ts, tsx]
package/README.md CHANGED
@@ -6,17 +6,14 @@
6
6
  </picture>
7
7
  </p>
8
8
 
9
- # esupgrade
9
+ # esupgrade [![npm version](https://img.shields.io/npm/v/esupgrade.svg?style=flat-square)](https://www.npmjs.com/package/esupgrade) [![coverage status](https://img.shields.io/codecov/c/github/codingjoe/esupgrade/main.svg?style=flat-square)](https://codecov.io/gh/codingjoe/esupgrade) [![license](https://img.shields.io/npm/l/esupgrade.svg?style=flat-square)](https://github.com/codingjoe/esupgrade/blob/main/LICENSE)
10
10
 
11
11
  Keeping your JavaScript and TypeScript code up to date with full browser compatibility.
12
12
 
13
13
  ## Usage
14
14
 
15
- ### CLI
16
-
17
- ```bash
18
- npx esupgrade --help
19
- ```
15
+ esupgrade is safe and meant to be used automatically on your codebase.
16
+ We recommend integrating it into your development workflow using [pre-commit].
20
17
 
21
18
  ### pre-commit
22
19
 
@@ -28,7 +25,7 @@ uvx pre-commit install
28
25
  # .pre-commit-config.yaml
29
26
  repos:
30
27
  - repo: https://github.com/codingjoe/esupgrade
31
- rev: v0.1.0 # Use the latest version
28
+ rev: 2025.0.2 # Use the latest version
32
29
  hooks:
33
30
  - id: esupgrade
34
31
  ```
@@ -37,31 +34,46 @@ repos:
37
34
  pre-commit run esupgrade --all-files
38
35
  ```
39
36
 
40
- ## Browser Support & Baseline
37
+ ### CLI
41
38
 
42
- <picture>
43
- <source media="(prefers-color-scheme: dark)" srcset="https://web-platform-dx.github.io/web-features/assets/img/baseline-widely-word-dark.svg">
44
- <source media="(prefers-color-scheme: light)" srcset="https://web-platform-dx.github.io/web-features/assets/img/baseline-widely-word.svg">
45
- <img alt="Baseline: widely available" src="https://web-platform-dx.github.io/web-features/assets/img/baseline-widely-word.svg" height="32" align="right">
46
- </picture>
39
+ ```bash
40
+ npx esupgrade --help
41
+ ```
47
42
 
48
- All transformations are based on [Web Platform Baseline](https://web.dev/baseline) features. Baseline tracks which web platform features are safe to use across browsers.
43
+ ## Browser Support & Baseline
44
+
45
+ All transformations are based on [Web Platform Baseline][baseline] features. Baseline tracks which web platform features are safe to use across browsers.
49
46
 
50
47
  By default, `esupgrade` uses **widely available** features, meaning they work in all major browsers (Chrome, Edge, Safari, Firefox) for at least 30 months. This ensures full compatibility while keeping your code modern.
51
48
 
52
49
  You can opt into **newly available** features (available in all browsers for 0-30 months) with:
53
50
 
54
51
  ```bash
55
- npx esupgrade --baseline newly-available src/
52
+ npx esupgrade --baseline newly-available <files>
56
53
  ```
57
54
 
58
- For more information about Baseline browser support, visit [web.dev/baseline](https://web.dev/baseline).
55
+ For more information about Baseline browser support, visit [web.dev/baseline][baseline].
56
+
57
+ ## Supported File Types & Languages
58
+
59
+ - `.js` - JavaScript
60
+ - `.jsx` - React/JSX
61
+ - `.ts` - TypeScript
62
+ - `.tsx` - TypeScript with JSX
63
+ - `.mjs` - ES Modules
64
+ - `.cjs` - CommonJS
59
65
 
60
66
  ## Transformations
61
67
 
62
- All transformations are safe and behavior-preserving. Here's what `esupgrade` does:
68
+ <picture>
69
+ <source media="(prefers-color-scheme: dark)" srcset="https://web-platform-dx.github.io/web-features/assets/img/baseline-widely-word-dark.svg">
70
+ <source media="(prefers-color-scheme: light)" srcset="https://web-platform-dx.github.io/web-features/assets/img/baseline-widely-word.svg">
71
+ <img alt="Baseline: widely available" src="https://web-platform-dx.github.io/web-features/assets/img/baseline-widely-word.svg" height="32" align="right">
72
+ </picture>
73
+
74
+ ### Widely available
63
75
 
64
- ### 1. `var` → `let`/`const`
76
+ #### `var` → `let`/`const`
65
77
 
66
78
  ```diff
67
79
  -var x = 1;
@@ -72,7 +84,7 @@ All transformations are safe and behavior-preserving. Here's what `esupgrade` do
72
84
  +y = 3;
73
85
  ```
74
86
 
75
- ### 2. String concatenation → Template literals
87
+ #### String concatenation → Template literals
76
88
 
77
89
  ```diff
78
90
  -const greeting = 'Hello ' + name + '!';
@@ -81,7 +93,7 @@ All transformations are safe and behavior-preserving. Here's what `esupgrade` do
81
93
  +const message = `You have ${count} items`;
82
94
  ```
83
95
 
84
- ### 3. `Array.from().forEach()` → `for...of` loops
96
+ #### `Array.from().forEach()` → `for...of` loops
85
97
 
86
98
  ```diff
87
99
  -Array.from(items).forEach(item => {
@@ -92,7 +104,7 @@ All transformations are safe and behavior-preserving. Here's what `esupgrade` do
92
104
  +}
93
105
  ```
94
106
 
95
- ### 4. `Object.assign({}, ...)` → Object spread
107
+ #### `Object.assign({}, ...)` → Object spread
96
108
 
97
109
  ```diff
98
110
  -const obj = Object.assign({}, obj1, obj2);
@@ -101,7 +113,7 @@ All transformations are safe and behavior-preserving. Here's what `esupgrade` do
101
113
  +const copy = { ...original };
102
114
  ```
103
115
 
104
- ### 5. `.concat()` → Array spread
116
+ #### `.concat()` → Array spread
105
117
 
106
118
  ```diff
107
119
  -const combined = arr1.concat(arr2, arr3);
@@ -110,7 +122,7 @@ All transformations are safe and behavior-preserving. Here's what `esupgrade` do
110
122
  +const withItem = [...array, item];
111
123
  ```
112
124
 
113
- ### 6. Function expressions → Arrow functions
125
+ #### Function expressions → Arrow functions
114
126
 
115
127
  ```diff
116
128
  -const fn = function(x) { return x * 2; };
@@ -119,34 +131,31 @@ All transformations are safe and behavior-preserving. Here's what `esupgrade` do
119
131
  +items.map(item => { return item.name; });
120
132
  ```
121
133
 
122
- **Note:** Functions using `this`, `arguments`, or `super` are not converted to preserve semantics.
134
+ > [!NOTE]
135
+ > Functions using `this`, `arguments`, or `super` are not converted to preserve semantics.
136
+
137
+ <picture>
138
+ <source media="(prefers-color-scheme: dark)" srcset="https://web-platform-dx.github.io/web-features/assets/img/baseline-newly-word-dark.svg">
139
+ <source media="(prefers-color-scheme: light)" srcset="https://web-platform-dx.github.io/web-features/assets/img/baseline-newly-word.svg">
140
+ <img alt="Baseline: Newly available" src="https://web-platform-dx.github.io/web-features/assets/img/baseline-newly-word.svg" height="32" align="right">
141
+ </picture>
142
+
143
+ ### Newly available
144
+
145
+ > [!CAUTION]
146
+ > These transformations are mainly to harden code for future releases and should be used with caution.
123
147
 
124
- ### Complete Example
148
+ #### `new Promise((resolve) => { ... })` → `Promise.try(() => { ... })`
125
149
 
126
150
  ```diff
127
- -var userName = 'John';
128
- -var userAge = 30;
129
- -var greeting = 'Hello, ' + userName + '!';
130
- +const userName = 'John';
131
- +const userAge = 30;
132
- +const greeting = `Hello, ${userName}!`;
133
-
134
- -Array.from(users).forEach(function(user) {
135
- - console.log('User: ' + user.name);
151
+ -new Promise((resolve) => {
152
+ - const result = doSomething();
153
+ - resolve(result);
136
154
  -});
137
- +for (const user of users) {
138
- + console.log(`User: ${user.name}`);
139
- +}
140
-
141
- -var settings = Object.assign({}, defaultSettings, userSettings);
142
- +const settings = { ...defaultSettings, ...userSettings };
155
+ +Promise.try(() => {
156
+ + return doSomething();
157
+ +});
143
158
  ```
144
159
 
145
- ## Supported File Types
146
-
147
- - `.js` - JavaScript
148
- - `.jsx` - React/JSX
149
- - `.ts` - TypeScript
150
- - `.tsx` - TypeScript with JSX
151
- - `.mjs` - ES Modules
152
- - `.cjs` - CommonJS
160
+ [baseline]: https://web.dev/baseline/
161
+ [pre-commit]: https://pre-commit.com/
package/bin/esupgrade.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import fs from "fs"
4
4
  import path from "path"
5
- import { Command } from "commander"
5
+ import { Command, Option } from "commander"
6
6
  import { transform } from "../src/index.js"
7
7
 
8
8
  /**
@@ -14,12 +14,11 @@ const program = new Command()
14
14
  program
15
15
  .name("esupgrade")
16
16
  .description("Auto-upgrade your JavaScript syntax")
17
- .version("0.1.0")
18
17
  .argument("[files...]", "Files or directories to process")
19
- .option(
20
- "--baseline <level>",
21
- "Set baseline level: widely-available (default) or newly-available",
22
- "widely-available",
18
+ .addOption(
19
+ new Option("--baseline <level>", "Set baseline level for transformations")
20
+ .choices(["widely-available", "newly-available"])
21
+ .default("widely-available"),
23
22
  )
24
23
  .option("--check", "Report which files need upgrading and exit with code 1 if any do")
25
24
  .option(
@@ -32,13 +31,6 @@ program
32
31
  program.help()
33
32
  }
34
33
 
35
- // Validate baseline option
36
- if (!["widely-available", "newly-available"].includes(options.baseline)) {
37
- console.error(`Error: Invalid baseline level '${options.baseline}'`)
38
- console.error(`Must be 'widely-available' or 'newly-available'`)
39
- process.exit(1)
40
- }
41
-
42
34
  // Handle check/write options - they are not mutually exclusive
43
35
  // Default: write is true unless ONLY --check is specified (no --write)
44
36
  const shouldWrite = options.write !== undefined ? options.write : !options.check
@@ -102,7 +94,7 @@ function walkDirectory(dir) {
102
94
  function processFile(filePath, options) {
103
95
  try {
104
96
  const code = fs.readFileSync(filePath, "utf8")
105
- const result = transform(code, { baseline: options.baseline })
97
+ const result = transform(code, options.baseline)
106
98
 
107
99
  if (result.modified) {
108
100
  if (options.check) {
@@ -154,13 +146,7 @@ function processFile(filePath, options) {
154
146
  }
155
147
 
156
148
  function processFiles(patterns, options) {
157
- let files = []
158
- try {
159
- files = findFiles(patterns)
160
- } catch (error) {
161
- console.error(`Error finding files: ${error.message}`)
162
- process.exit(1)
163
- }
149
+ const files = findFiles(patterns)
164
150
 
165
151
  if (files.length === 0) {
166
152
  console.log("No JavaScript files found")
@@ -1,11 +1,10 @@
1
1
  <svg xmlns="http://www.w3.org/2000/svg" width="640" height="320" font-family="Segoe UI, system-ui, sans-serif" viewBox="0 0 1280 640">
2
2
  <circle cx="260" cy="320" r="200" fill="#f7df1e"/>
3
- <path fill="none" stroke="#191919" stroke-width="48" d="m175 405 95-95 95 95m415 50"/>
4
- <path fill="none" stroke="#191919" stroke-width="48" d="m175 315 95-95 95 95m415 50"/>
5
- <text x="241" y="148" font-size="92" font-weight="bold" transform="matrix(1.6 0 0 1.6 120 120)" fill="#C9D1D9">
3
+ <path fill="none" stroke="#191919" stroke-width="48" d="m167 409 95-95 95 95m-190 -95 95-95 95 95m415 50"/>
4
+ <text x="241" y="148" fill="#c9d1d9" font-size="92" font-weight="bold" transform="matrix(1.6 0 0 1.6 120 120)">
6
5
  esupgrade
7
6
  </text>
8
- <text x="241" y="192" font-size="28" font-style="italic" transform="matrix(1.6 0 0 1.6 120 120)" fill="#C9D1D9">
7
+ <text x="241" y="192" fill="#c9d1d9" font-size="28" font-style="italic" transform="matrix(1.6 0 0 1.6 120 120)">
9
8
  Auto-upgrade your JavaScript syntax
10
9
  </text>
11
10
  </svg>
@@ -1,7 +1,6 @@
1
1
  <svg xmlns="http://www.w3.org/2000/svg" width="640" height="320" font-family="Segoe UI, system-ui, sans-serif" viewBox="0 0 1280 640">
2
2
  <circle cx="260" cy="320" r="200" fill="#f7df1e"/>
3
- <path fill="none" stroke="#191919" stroke-width="48" d="m175 405 95-95 95 95m415 50"/>
4
- <path fill="none" stroke="#191919" stroke-width="48" d="m175 315 95-95 95 95m415 50"/>
3
+ <path fill="none" stroke="#191919" stroke-width="48" d="m167 409 95-95 95 95m-190 -95 95-95 95 95m415 50"/>
5
4
  <text x="241" y="148" font-size="92" font-weight="bold" transform="matrix(1.6 0 0 1.6 120 120)">
6
5
  esupgrade
7
6
  </text>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esupgrade",
3
- "version": "2025.0.0",
3
+ "version": "2025.0.2",
4
4
  "description": "Auto-upgrade your JavaScript syntax",
5
5
  "type": "module",
6
6
  "main": "src/index.js",