Skip to content

Commit eb164e1

Browse files
committed
chore: fix linter error
1 parent d08b010 commit eb164e1

File tree

20 files changed

+166
-161
lines changed

20 files changed

+166
-161
lines changed

src/build.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type {
55
TransformEntry,
66
} from './types'
77

8-
import { rm } from 'node:fs/promises'
98
import { isAbsolute, join, resolve } from 'node:path'
109
import { fileURLToPath } from 'node:url'
1110
import { consola } from 'consola'
@@ -23,7 +22,7 @@ import {
2322
filterWorkspacePackages,
2423
loadWorkspaceConfig,
2524
} from './features/workspace'
26-
import { analyzeDir, fmtPath } from './utils'
25+
import { analyzeDir } from './utils'
2726
import { startWatch } from './watch'
2827

2928
/**

src/builders/bundle.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
Plugin,
77
} from 'rolldown'
88
import type { Options as DtsOptions } from 'rolldown-plugin-dts'
9-
import type { BuildContext, BuildHooks, BundleEntry, OutputFormat, Platform, RobuildPlugin } from '../types'
9+
import type { BuildContext, BuildHooks, BundleEntry, OutputFormat, Platform } from '../types'
1010
import { mkdir, readFile, writeFile } from 'node:fs/promises'
1111
import { builtinModules } from 'node:module'
1212
import { basename, dirname, extname, join, relative, resolve } from 'node:path'
@@ -18,16 +18,15 @@ import { parseSync } from 'oxc-parser'
1818
import prettyBytes from 'pretty-bytes'
1919
import { rolldown } from 'rolldown'
2020
import { dts } from 'rolldown-plugin-dts'
21-
import { createSkipNodeModulesPlugin, getNodeModulesDependencies, getSkipNodeModulesExternalConfig } from '../features/advanced-build'
21+
import { createSkipNodeModulesPlugin } from '../features/advanced-build'
2222

2323
import { resolveChunkAddon } from '../features/banner'
2424

25-
import { createCjsDefaultPlugin } from '../features/cjs-default'
2625
import { copyFiles } from '../features/copy'
2726
import { createGlobImportPlugin } from '../features/glob-import'
2827
import { addHashToFilename, hasHash } from '../features/hash'
2928
import { createLoaderPlugin } from '../features/loaders'
30-
import { loadPlugins, PluginManager } from '../features/plugins'
29+
import { PluginManager } from '../features/plugins'
3130
import { createShimsPlugin } from '../features/shims'
3231
import { distSize, fmtPath, sideEffectSize } from '../utils'
3332
import { nodeProtocolPlugin } from './plugins/node-protocol'

src/cli/migrate.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env node
22

33
import type { MigrationResult } from '../features/migration'
4-
import { writeFile } from 'node:fs/promises'
54
import { join, resolve } from 'node:path'
65
import { cac } from 'cac'
76
import { consola } from 'consola'

src/features/advanced-build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { BuildContext, RobuildPlugin, TransformEntry } from '../types'
22
import { existsSync } from 'node:fs'
3-
import { mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises'
4-
import { basename, dirname, extname, join, relative } from 'node:path'
3+
import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
4+
import { dirname, extname, join } from 'node:path'
55

66
/**
77
* Create skip node_modules plugin

src/features/copy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CopyEntry, CopyOptions } from '../types'
1+
import type { CopyOptions } from '../types'
22
import { cp } from 'node:fs/promises'
33
import { basename, resolve } from 'node:path'
44
import { consola } from 'consola'

src/features/exports.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { BuildConfig, BuildEntry } from '../types'
22
import { readFile, writeFile } from 'node:fs/promises'
3-
import { dirname, join, relative } from 'node:path'
4-
import { glob } from 'glob'
3+
import { join } from 'node:path'
54

65
export interface ExportsConfig {
76
/**

src/features/glob-import.ts

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { glob } from 'glob'
2-
import { resolve, relative, dirname, extname, basename } from 'node:path'
3-
import { readFile } from 'node:fs/promises'
41
import type { GlobImportOptions, RobuildPlugin } from '../types'
2+
import { dirname, relative, resolve } from 'node:path'
3+
import { glob } from 'glob'
54

65
/**
76
* Create a glob import plugin for robuild
@@ -11,36 +10,37 @@ export function createGlobImportPlugin(options: GlobImportOptions = {}): Robuild
1110
enabled = false,
1211
patterns = ['**/*'],
1312
asUrls = false,
14-
eager = false
13+
eager = false,
1514
} = options
1615

1716
if (!enabled) {
1817
return {
19-
name: 'glob-import-disabled'
18+
name: 'glob-import-disabled',
2019
}
2120
}
2221

2322
return {
2423
name: 'glob-import',
2524
transform: async (code: string, id: string) => {
2625
// Look for import.meta.glob() calls
27-
const globImportRegex = /import\.meta\.glob\s*\(\s*(['"`])(.*?)\1\s*(?:,\s*({[^}]*}))?\s*\)/g
28-
26+
const globImportRegex = /import\.meta\.glob\s*\(\s*(['"`])(.*?)\1\s*(?:,\s*(\{[^}]*\})\s*)?\)/g
27+
2928
let match
3029
let hasGlobImports = false
3130
let transformedCode = code
3231

3332
while ((match = globImportRegex.exec(code)) !== null) {
3433
hasGlobImports = true
3534
const [fullMatch, quote, pattern, optionsStr] = match
36-
35+
3736
// Parse options if provided
3837
let globOptions: any = {}
3938
if (optionsStr) {
4039
try {
4140
// Simple options parsing (in real implementation, use a proper parser)
4241
globOptions = parseGlobOptions(optionsStr)
43-
} catch (error) {
42+
}
43+
catch (error) {
4444
console.warn('Failed to parse glob options:', optionsStr)
4545
}
4646
}
@@ -54,16 +54,17 @@ export function createGlobImportPlugin(options: GlobImportOptions = {}): Robuild
5454
id,
5555
isEager,
5656
isAsUrls,
57-
patterns
57+
patterns,
5858
)
5959
transformedCode = transformedCode.replace(fullMatch, replacement)
60-
} catch (error) {
60+
}
61+
catch (error) {
6162
console.error(`Failed to process glob import ${pattern}:`, error)
6263
}
6364
}
6465

6566
return hasGlobImports ? transformedCode : null
66-
}
67+
},
6768
}
6869
}
6970

@@ -75,7 +76,7 @@ async function generateGlobImport(
7576
importer: string,
7677
eager: boolean,
7778
asUrls: boolean,
78-
allowedPatterns: string[]
79+
allowedPatterns: string[],
7980
): Promise<string> {
8081
const importerDir = dirname(importer)
8182

@@ -89,9 +90,10 @@ async function generateGlobImport(
8990
try {
9091
const absolutePattern = resolve(importerDir, pattern)
9192
files = await glob(absolutePattern, {
92-
ignore: ['**/node_modules/**', '**/.git/**']
93+
ignore: ['**/node_modules/**', '**/.git/**'],
9394
})
94-
} catch (error) {
95+
}
96+
catch (error) {
9597
// In test environment, create mock files based on pattern
9698
if (pattern.includes('*.js')) {
9799
files = [resolve(importerDir, pattern.replace('*', 'module1')), resolve(importerDir, pattern.replace('*', 'module2'))]
@@ -100,7 +102,8 @@ async function generateGlobImport(
100102

101103
if (eager) {
102104
return generateEagerImport(files, importerDir, asUrls)
103-
} else {
105+
}
106+
else {
104107
return generateLazyImport(files, importerDir, asUrls)
105108
}
106109
}
@@ -119,15 +122,17 @@ function generateEagerImport(files: string[], importerDir: string, asUrls: boole
119122

120123
if (asUrls) {
121124
exports.push(` "${key}": "${relativePath}"`)
122-
} else {
125+
}
126+
else {
123127
imports.push(`import * as ${varName} from "${relativePath}";`)
124128
exports.push(` "${key}": ${varName}`)
125129
}
126130
})
127131

128132
if (asUrls) {
129133
return `{\n${exports.join(',\n')}\n}`
130-
} else {
134+
}
135+
else {
131136
return `${imports.join('\n')}\n{\n${exports.join(',\n')}\n}`
132137
}
133138
}
@@ -138,13 +143,14 @@ function generateEagerImport(files: string[], importerDir: string, asUrls: boole
138143
function generateLazyImport(files: string[], importerDir: string, asUrls: boolean): string {
139144
const exports: string[] = []
140145

141-
files.forEach(file => {
146+
files.forEach((file) => {
142147
const relativePath = relative(importerDir, file)
143148
const key = `./${relativePath}`
144149

145150
if (asUrls) {
146151
exports.push(` "${key}": "${relativePath}"`)
147-
} else {
152+
}
153+
else {
148154
exports.push(` "${key}": () => import("${relativePath}")`)
149155
}
150156
})
@@ -157,8 +163,9 @@ function generateLazyImport(files: string[], importerDir: string, asUrls: boolea
157163
*/
158164
function isPatternAllowed(pattern: string, allowedPatterns: string[]): boolean {
159165
// Simple pattern matching - in real implementation, use minimatch
160-
return allowedPatterns.some(allowed => {
161-
if (allowed === '**/*') return true
166+
return allowedPatterns.some((allowed) => {
167+
if (allowed === '**/*')
168+
return true
162169
return pattern.startsWith(allowed.replace('**/*', ''))
163170
})
164171
}
@@ -170,7 +177,7 @@ function parseGlobOptions(optionsStr: string): any {
170177
// Simple parser for basic options
171178
// In real implementation, use a proper AST parser
172179
const options: any = {}
173-
180+
174181
// Extract eager option
175182
if (optionsStr.includes('eager:') || optionsStr.includes('eager ')) {
176183
const eagerMatch = optionsStr.match(/eager\s*:\s*(true|false)/)
@@ -194,13 +201,14 @@ function parseGlobOptions(optionsStr: string): any {
194201
export function createGlobVirtualModule(
195202
pattern: string,
196203
files: string[],
197-
options: { eager?: boolean, asUrls?: boolean } = {}
204+
options: { eager?: boolean, asUrls?: boolean } = {},
198205
): string {
199206
const { eager = false, asUrls = false } = options
200207

201208
if (eager) {
202209
return generateEagerImport(files, '', asUrls)
203-
} else {
210+
}
211+
else {
204212
return generateLazyImport(files, '', asUrls)
205213
}
206214
}
@@ -210,18 +218,19 @@ export function createGlobVirtualModule(
210218
*/
211219
export async function resolveGlobPatterns(
212220
patterns: string[],
213-
cwd: string = process.cwd()
221+
cwd: string = process.cwd(),
214222
): Promise<Record<string, string[]>> {
215223
const result: Record<string, string[]> = {}
216224

217225
for (const pattern of patterns) {
218226
try {
219227
const files = await glob(pattern, {
220228
cwd,
221-
ignore: ['**/node_modules/**', '**/.git/**']
229+
ignore: ['**/node_modules/**', '**/.git/**'],
222230
})
223231
result[pattern] = files
224-
} catch (error) {
232+
}
233+
catch (error) {
225234
console.error(`Failed to resolve glob pattern ${pattern}:`, error)
226235
result[pattern] = []
227236
}
@@ -236,7 +245,7 @@ export async function resolveGlobPatterns(
236245
export async function transformGlobImports(
237246
code: string,
238247
id: string,
239-
options: GlobImportOptions = {}
248+
options: GlobImportOptions = {},
240249
): Promise<string | null> {
241250
const plugin = createGlobImportPlugin(options)
242251
if (plugin.transform) {
@@ -251,12 +260,12 @@ export async function transformGlobImports(
251260
export function extractGlobPatterns(code: string): string[] {
252261
const patterns: string[] = []
253262
const globImportRegex = /import\.meta\.glob\s*\(\s*(['"`])(.*?)\1/g
254-
263+
255264
let match
256265
while ((match = globImportRegex.exec(code)) !== null) {
257266
patterns.push(match[2])
258267
}
259-
268+
260269
return patterns
261270
}
262271

src/features/on-success.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { BuildResult, OnSuccessCallback } from '../types'
12
import { exec } from 'node:child_process'
23
import { promisify } from 'node:util'
3-
import type { BuildResult, OnSuccessCallback } from '../types'
44
import { logger } from './logger'
55

66
const execAsync = promisify(exec)
@@ -22,21 +22,23 @@ export async function executeOnSuccess(
2222
// Execute command
2323
logger.verbose(`Executing onSuccess command: ${onSuccess}`)
2424
const { stdout, stderr } = await execAsync(onSuccess, { cwd })
25-
25+
2626
if (stdout) {
2727
logger.verbose(`onSuccess stdout: ${stdout.trim()}`)
2828
}
2929
if (stderr) {
3030
logger.warn(`onSuccess stderr: ${stderr.trim()}`)
3131
}
32-
} else {
32+
}
33+
else {
3334
// Execute function
3435
logger.verbose('Executing onSuccess callback function')
3536
await onSuccess(result)
3637
}
37-
38+
3839
logger.verbose('onSuccess callback completed successfully')
39-
} catch (error) {
40+
}
41+
catch (error) {
4042
logger.error('onSuccess callback failed:', error)
4143
throw error
4244
}

0 commit comments

Comments
 (0)