Skip to content

Commit 211a7e5

Browse files
Swanand01justlevineTa5r
authored
feat: Convert CLI to TypeScript (#140)
* chore: remove .cjs files * refactor: add .ts files * refactor: update build file * feat: add prettier config * feat: add tsconfig * refactor: update package.json * refactor: add eslint rule to ignore console logs * chore: update package-lock * chore: add changeset * chore: update changeset * fix: changeset * refactor: update ESLint config for .cjs formatting * refactor: remove exports * chore: update package-lock * chore: format * chore: format * feat : add import/no-default-export eslint rule. * chore : updated files for no-default-exports. * chore : add changeset. * chore : reorder-import * temp : fix failing gh actions * fix : export default for codegen config and baseConfig * chore: cleanup up eslint ruleset * refactor: remove default exports in favor of named exports --------- Co-authored-by: Dovid Levine <david@axepress.dev> Co-authored-by: Ta5r <srv.tanay@gmail.com> Co-authored-by: Tanay Srivastava <62954323+Ta5r@users.noreply.github.com>
1 parent 3855d48 commit 211a7e5

19 files changed

+579
-191
lines changed

.changeset/shy-sites-write.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"snapwp": patch
3+
---
4+
5+
feat: Convert CLI to TypeScript

.eslintrc.cjs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,7 @@ module.exports = {
136136
},
137137
overrides: [
138138
{
139-
files: '**/*.test.ts',
140-
env: {
141-
jest: true,
142-
},
143-
},
144-
{
145-
files: [ '**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx' ],
139+
files: [ '**/*.{js,jsx,ts,tsx,cjs,mjs,cts,mts}' ],
146140
// Mandate doc block for arrow functions, class declarations, class expressions, function expressions, and method definition.
147141
rules: {
148142
'jsdoc/require-jsdoc': [
@@ -159,25 +153,10 @@ module.exports = {
159153
],
160154
},
161155
},
162-
// Rules for bin and cli files.
163-
{
164-
files: [ 'bin/**/*.js', 'bin/**/*.mjs', 'packages/cli/src/*.cjs' ],
165-
rules: {
166-
// Enable the use of console log.
167-
'no-console': 'off',
168-
// Enable the use of process-env.
169-
'n/no-process-env': 'off',
170-
},
171-
},
172-
// Disable n/no-process-env for `codegen.ts` file.
173-
{
174-
files: [ '**/codegen.ts', '**/*.test.*', '**/jest.setup.js' ],
175-
rules: {
176-
'n/no-process-env': 'off',
177-
},
178-
},
156+
157+
// Typescript files.
179158
{
180-
files: [ '**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts' ],
159+
files: [ '**/*.{ts,tsx,cts,mts}' ],
181160
excludedFiles: [
182161
'**/codegen.ts',
183162
'packages/query/src/**/tests/*',
@@ -192,12 +171,46 @@ module.exports = {
192171
project: true,
193172
},
194173
},
174+
175+
// CLI package TypeScript files
176+
{
177+
files: [
178+
'**/packages/cli/src/**/*.{ts,cts,mts}',
179+
'**/packages/cli/build.cjs',
180+
],
181+
rules: {
182+
'n/no-process-env': 'off',
183+
'no-console': 'off',
184+
},
185+
},
186+
187+
// Jest files.
188+
{
189+
files: [ '**/*.test.ts' ],
190+
env: {
191+
jest: true,
192+
},
193+
},
194+
195+
// E2E test utility files
195196
{
196-
files: [ '**/packages/e2e-tests/src/utils/*.ts' ],
197+
files: [ '**/packages/e2e-tests/src/utils/*.{ts,cts,mts}' ],
197198
rules: {
198199
'n/no-process-env': 'off',
199200
'no-console': 'off',
200201
},
201202
},
203+
204+
// Config and setup files
205+
{
206+
files: [
207+
'**/codegen.ts',
208+
'**/*.test.{js,jsx,ts,tsx,cjs,mjs,cts,mts}',
209+
'**/jest.setup.{js,cjs,mjs}',
210+
],
211+
rules: {
212+
'n/no-process-env': 'off',
213+
},
214+
},
202215
],
203216
};

config/import-resolver.cjs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
/**
22
* External dependencies.
33
*/
4-
const resolverTS = require( 'eslint-import-resolver-typescript' );
54
const path = require( 'path' );
5+
const resolverTS = require( 'eslint-import-resolver-typescript' );
66

77
exports.interfaceVersion = 2;
88

99
/**
1010
* Eslint configuration for resolving TypeScript aliases.
1111
*
12-
* @param source Import string.
13-
* @param file File-path in which alias is used.
14-
* @param config configuration.
12+
* @param {string} source Import string.
13+
* @param {string} file File-path in which alias is used.
14+
* @param {Object} config configuration.
1515
*
1616
* @return Resolved path.
1717
*/
1818
exports.resolve = function ( source, file, config ) {
1919
/**
2020
* Creates a path resolver.
2121
*
22-
* @param sourcePath Import string.
22+
* @param {string} sourcePath Import string.
2323
*
2424
* @return Path resolver.
2525
*/
@@ -53,11 +53,11 @@ exports.resolve = function ( source, file, config ) {
5353
/**
5454
* Resolves TS paths.
5555
*
56-
* @param source Import string.
57-
* @param alias Alias to search.
58-
* @param aliasPath Alias path.
59-
* @param file File-path in which alias is used.
60-
* @param resolve Path resolver.
56+
* @param {string} source Import string.
57+
* @param {string} alias Alias to search.
58+
* @param {string} aliasPath Alias path.
59+
* @param {string} file File-path in which alias is used.
60+
* @param {Function} resolve Path resolver.
6161
*
6262
* @return Resolved path on success | False if alias is not found in import string.
6363
*/

0 commit comments

Comments
 (0)