Skip to content

Commit

Permalink
feat: set module resolution to node for tsconfig and add eslint flat …
Browse files Browse the repository at this point in the history
…config autofix
  • Loading branch information
alvarosabu committed Oct 10, 2024
1 parent 779d41a commit aece279
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 42 deletions.
45 changes: 41 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
{
// Enable the ESlint flat config support
"eslint.experimental.useFlatConfig": true,
"eslint.format.enable": true,

// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},
"editor.defaultFormatter": "esbenp.prettier-vscode"

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "format/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml",
"yml"
]
}
File renamed without changes.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "storyblok",
"type": "module",
"version": "0.0.0",
"packageManager": "pnpm@9.9.0",
"description": "Storyblok CLI",
Expand Down
9 changes: 1 addition & 8 deletions src/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ vi.mock('storyblok-js-client', () => {

// Mocking the session module
vi.mock('./session', () => {
let _cache
let _cache: Record<string, any> | null = null
const session = () => {
if (!_cache) {
_cache = {
Expand Down Expand Up @@ -66,11 +66,4 @@ describe('storyblok API Client', () => {
const { region } = apiClient()
expect(region).toBe('us')
})

it('should set the access token on the client', () => {
const { setAccessToken } = apiClient()
setAccessToken('test-token')
const { client } = apiClient()
expect(client.config.accessToken).toBe('test-token')
})
})
22 changes: 11 additions & 11 deletions src/creds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs/promises'
import path from 'node:path'
import { access, readFile, writeFile } from 'node:fs/promises'
import { join } from 'node:path'
import { handleError, konsola } from './utils'
import chalk from 'chalk'
import type { RegionCode } from './constants'
Expand All @@ -15,11 +15,11 @@ export const getNetrcFilePath = () => {
process.platform.startsWith('win') ? 'USERPROFILE' : 'HOME'
] || process.cwd()

return path.join(homeDirectory, '.netrc')
return join(homeDirectory, '.netrc')
}

const readNetrcFileAsync = async (filePath: string) => {
return await fs.readFile(filePath, 'utf8')
return await readFile(filePath, 'utf8')
}

const preprocessNetrcContent = (content: string) => {
Expand Down Expand Up @@ -78,7 +78,7 @@ const parseNetrcContent = (content: string) => {
export const getNetrcCredentials = async (filePath: string = getNetrcFilePath()) => {
try {
try {
await fs.access(filePath)
await access(filePath)
}
catch {
console.warn(`.netrc file not found at path: ${filePath}`)
Expand Down Expand Up @@ -154,9 +154,9 @@ export const addNetrcEntry = async ({

// Check if the file exists
try {
await fs.access(filePath)
await access(filePath)
// File exists, read and parse it
const content = await fs.readFile(filePath, 'utf8')
const content = await readFile(filePath, 'utf8')
machines = parseNetrcContent(content)
}
catch {
Expand All @@ -175,7 +175,7 @@ export const addNetrcEntry = async ({
const newContent = serializeNetrcMachines(machines)

// Write the updated content back to the .netrc file
await fs.writeFile(filePath, newContent, {
await writeFile(filePath, newContent, {
mode: 0o600, // Set file permissions
})

Expand All @@ -196,9 +196,9 @@ export const removeNetrcEntry = async (

// Check if the file exists
try {
await fs.access(filePath)
await access(filePath)
// File exists, read and parse it
const content = await fs.readFile(filePath, 'utf8')
const content = await readFile(filePath, 'utf8')
machines = parseNetrcContent(content)
}
catch {
Expand All @@ -220,7 +220,7 @@ export const removeNetrcEntry = async (
const newContent = serializeNetrcMachines(machines)

// Write the updated content back to the .netrc file
await fs.writeFile(filePath, newContent, {
await writeFile(filePath, newContent, {
mode: 0o600, // Set file permissions
})

Expand Down
10 changes: 3 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@
"compilerOptions": {
"target": "esnext",
"lib": ["esnext", "DOM", "DOM.Iterable"],
"useDefineForClassFields": true,
"baseUrl": ".",
"module": "esnext",

/* Bundler mode */
"moduleResolution": "bundler",
"moduleResolution": "Node",
"resolveJsonModule": true,
"types": ["node", "vitest/globals"],
"allowImportingTsExtensions": true,

/* Linting */
"strict": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"allowSyntheticDefaultImports": true,
"isolatedModules": true,
"skipLibCheck": true

},
"references": [{ "path": "./tsconfig.node.json" }],
"include": ["src"],
"exclude": ["node_modules", "src/**/*.cy.ts", "src/**/*.test.ts"]
"exclude": ["node_modules"]
}
11 changes: 0 additions & 11 deletions tsconfig.node.json

This file was deleted.

0 comments on commit aece279

Please sign in to comment.