Comparing version 0.0.0-canary-20240806053140 to 0.0.0-canary-20241104172400
@@ -12,2 +12,4 @@ declare function clean(path: string): Promise<void>; | ||
export { clean, getRelativePath, read, readSync, write }; | ||
declare function trimExtName(text: string): string; | ||
export { clean, getRelativePath, read, readSync, trimExtName, write }; |
@@ -0,11 +1,9 @@ | ||
import fs3 from 'fs-extra'; | ||
import { resolve, relative } from 'node:path'; | ||
import { switcher } from 'js-runtime'; | ||
// src/clean.ts | ||
import fs from "fs-extra"; | ||
async function clean(path) { | ||
return fs.remove(path); | ||
return fs3.remove(path); | ||
} | ||
// src/read.ts | ||
import { basename, extname, relative } from "path"; | ||
import fs2 from "fs-extra"; | ||
import { switcher } from "js-runtime"; | ||
function slash(path, platform = "linux") { | ||
@@ -25,5 +23,5 @@ const isWindowsPath = /^\\\\\?\\/.test(path); | ||
if (slashedPath.startsWith("../")) { | ||
return slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath))); | ||
return slashedPath; | ||
} | ||
return `./${slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath)))}`; | ||
return `./${slashedPath}`; | ||
} | ||
@@ -33,3 +31,3 @@ var reader = switcher( | ||
node: async (path) => { | ||
return fs2.readFile(path, { encoding: "utf8" }); | ||
return fs3.readFile(path, { encoding: "utf8" }); | ||
}, | ||
@@ -46,3 +44,3 @@ bun: async (path) => { | ||
node: (path) => { | ||
return fs2.readFileSync(path, { encoding: "utf8" }); | ||
return fs3.readFileSync(path, { encoding: "utf8" }); | ||
}, | ||
@@ -61,8 +59,3 @@ bun: () => { | ||
} | ||
// src/write.ts | ||
import { resolve } from "path"; | ||
import fs3 from "fs-extra"; | ||
import { switcher as switcher2 } from "js-runtime"; | ||
var writer = switcher2( | ||
var writer = switcher( | ||
{ | ||
@@ -118,3 +111,3 @@ node: async (path, data, { sanity }) => { | ||
} catch (e) { | ||
console.log(e, resolve(path)); | ||
console.error(e); | ||
} | ||
@@ -131,9 +124,10 @@ } | ||
} | ||
export { | ||
clean, | ||
getRelativePath, | ||
read, | ||
readSync, | ||
write | ||
}; | ||
// src/index.ts | ||
function trimExtName(text) { | ||
return text.replace(/\.[^/.]+$/, ""); | ||
} | ||
export { clean, getRelativePath, read, readSync, trimExtName, write }; | ||
//# sourceMappingURL=index.js.map | ||
//# sourceMappingURL=index.js.map |
@@ -17,3 +17,2 @@ type BasePath<T extends string = string> = `${T}/`; | ||
path: string; | ||
extName?: Extname; | ||
/** | ||
@@ -23,5 +22,2 @@ * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`. | ||
isTypeOnly?: boolean; | ||
/** | ||
* Add `* as` prefix to the import, this will result in: `import * as path from './path'`. | ||
*/ | ||
isNameSpace?: boolean; | ||
@@ -33,2 +29,17 @@ /** | ||
}; | ||
type Source = { | ||
name?: string; | ||
value?: string; | ||
isTypeOnly?: boolean; | ||
/** | ||
* Has const or type 'export' | ||
* @default false | ||
*/ | ||
isExportable?: boolean; | ||
/** | ||
* When set, barrel generation will add this | ||
* @default false | ||
*/ | ||
isIndexable?: boolean; | ||
}; | ||
type Export = { | ||
@@ -46,3 +57,2 @@ /** | ||
path: string; | ||
extName?: Extname; | ||
/** | ||
@@ -57,8 +67,2 @@ * Add `type` prefix to the export, this will result in: `export type { Type } from './path'`. | ||
}; | ||
declare const dataTagSymbol: unique symbol; | ||
type DataTag<Type, Value> = Type & { | ||
[dataTagSymbol]: Value; | ||
}; | ||
type UUID = string; | ||
type Source = string; | ||
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`; | ||
@@ -71,3 +75,3 @@ type Mode = 'single' | 'split'; | ||
*/ | ||
type BaseName = `${string}${Extname}`; | ||
type BaseName = `${string}.${string}`; | ||
/** | ||
@@ -79,21 +83,16 @@ * Path will be full qualified path to a specified file | ||
type OptionalPath = Path | undefined | null; | ||
type File<TMeta extends object = object, TBaseName extends BaseName = BaseName> = { | ||
type File<TMeta extends object = object> = { | ||
/** | ||
* Unique identifier to reuse later | ||
* @default crypto.randomUUID() | ||
*/ | ||
id?: string; | ||
/** | ||
* Name to be used to create the path | ||
* Based on UNIX basename, `${name}.extName` | ||
* Based on UNIX basename, `${name}.extname` | ||
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix | ||
*/ | ||
baseName: TBaseName; | ||
baseName: BaseName; | ||
/** | ||
* Path will be full qualified path to a specified file | ||
*/ | ||
path: AdvancedPath<TBaseName> | Path; | ||
source: Source; | ||
imports?: Import[]; | ||
exports?: Export[]; | ||
path: AdvancedPath<BaseName> | Path; | ||
sources: Array<Source>; | ||
imports?: Array<Import>; | ||
exports?: Array<Export>; | ||
/** | ||
@@ -109,17 +108,22 @@ * This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists | ||
meta?: TMeta; | ||
banner?: string; | ||
footer?: string; | ||
}; | ||
type ResolvedImport = Import; | ||
type ResolvedExport = Export; | ||
type ResolvedFile<TMeta extends object = object> = File<TMeta> & { | ||
/** | ||
* Override if a file can be exported by the BarrelManager | ||
* @default true | ||
* @default object-hash | ||
*/ | ||
exportable?: boolean; | ||
id: string; | ||
/** | ||
* This will override `process.env[key]` inside the `source`, see `getFileSource`. | ||
* Contains the first part of the baseName, generated based on baseName | ||
* @link https://nodejs.org/api/path.html#pathformatpathobject | ||
*/ | ||
env?: NodeJS.ProcessEnv; | ||
/** | ||
* The name of the language being used. This can be TypeScript, JavaScript and still have another ext. | ||
*/ | ||
language?: string; | ||
name: string; | ||
extname: Extname; | ||
imports: Array<ResolvedImport>; | ||
exports: Array<ResolvedExport>; | ||
}; | ||
export { type AdvancedPath, type BaseName, type DataTag, type Export, type Extname, type File, type Import, type Mode, type OptionalPath, type Path, type Source, type UUID, dataTagSymbol }; | ||
export type { AdvancedPath, BaseName, Export, Extname, File, Import, Mode, OptionalPath, Path, ResolvedExport, ResolvedFile, ResolvedImport, Source }; |
@@ -0,1 +1,3 @@ | ||
//# sourceMappingURL=types.js.map | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@kubb/fs", | ||
"version": "0.0.0-canary-20240806053140", | ||
"version": "0.0.0-canary-20241104172400", | ||
"description": "FileSystem helpers", | ||
@@ -54,10 +54,8 @@ "keywords": [ | ||
"@types/fs-extra": "^11.0.4", | ||
"prettier": "^3.3.3", | ||
"tsup": "^8.2.4", | ||
"@kubb/config-biome": "0.0.0-canary-20240806053140", | ||
"@kubb/config-ts": "0.0.0-canary-20240806053140", | ||
"@kubb/config-tsup": "0.0.0-canary-20240806053140" | ||
"tsup": "^8.3.5", | ||
"@kubb/config-ts": "0.0.0-canary-20241104172400", | ||
"@kubb/config-tsup": "0.0.0-canary-20241104172400" | ||
}, | ||
"engines": { | ||
"node": ">=18" | ||
"node": ">=20" | ||
}, | ||
@@ -64,0 +62,0 @@ "publishConfig": { |
@@ -16,8 +16,4 @@ <div align="center"> | ||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> | ||
<!-- ALL-CONTRIBUTORS-BADGE:END --> | ||
</p> | ||
<h4> | ||
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/alpha/examples/typescript" target="_blank">View Demo</a> | ||
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a> | ||
<span> · </span> | ||
@@ -31,2 +27,15 @@ <a href="https://kubb.dev/" target="_blank">Documentation</a> | ||
</div> | ||
## Supporting Kubb | ||
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider: | ||
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle) | ||
<p align="center"> | ||
<a href="https://github.com/sponsors/stijnvanhulle"> | ||
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" /> | ||
</a> | ||
</p> | ||
<!-- Badges --> | ||
@@ -33,0 +42,0 @@ |
export { clean } from './clean.ts' | ||
export { getRelativePath, read, readSync } from './read.ts' | ||
export { write } from './write.ts' | ||
export function trimExtName(text: string): string { | ||
return text.replace(/\.[^/.]+$/, '') | ||
} |
@@ -1,2 +0,2 @@ | ||
import { basename, extname, relative } from 'node:path' | ||
import { relative } from 'node:path' | ||
@@ -30,6 +30,6 @@ import fs from 'fs-extra' | ||
if (slashedPath.startsWith('../')) { | ||
return slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath))) | ||
return slashedPath | ||
} | ||
return `./${slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath)))}` | ||
return `./${slashedPath}` | ||
} | ||
@@ -36,0 +36,0 @@ |
@@ -23,3 +23,2 @@ type BasePath<T extends string = string> = `${T}/` | ||
path: string | ||
extName?: Extname | ||
/** | ||
@@ -29,5 +28,2 @@ * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`. | ||
isTypeOnly?: boolean | ||
/** | ||
* Add `* as` prefix to the import, this will result in: `import * as path from './path'`. | ||
*/ | ||
@@ -41,2 +37,18 @@ isNameSpace?: boolean | ||
export type Source = { | ||
name?: string | ||
value?: string | ||
isTypeOnly?: boolean | ||
/** | ||
* Has const or type 'export' | ||
* @default false | ||
*/ | ||
isExportable?: boolean | ||
/** | ||
* When set, barrel generation will add this | ||
* @default false | ||
*/ | ||
isIndexable?: boolean | ||
} | ||
export type Export = { | ||
@@ -54,3 +66,2 @@ /** | ||
path: string | ||
extName?: Extname | ||
/** | ||
@@ -66,10 +77,2 @@ * Add `type` prefix to the export, this will result in: `export type { Type } from './path'`. | ||
export declare const dataTagSymbol: unique symbol | ||
export type DataTag<Type, Value> = Type & { | ||
[dataTagSymbol]: Value | ||
} | ||
export type UUID = string | ||
export type Source = string | ||
export type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}` | ||
@@ -84,3 +87,3 @@ | ||
*/ | ||
export type BaseName = `${string}${Extname}` | ||
export type BaseName = `${string}.${string}` | ||
@@ -96,21 +99,16 @@ /** | ||
export type File<TMeta extends object = object, TBaseName extends BaseName = BaseName> = { | ||
export type File<TMeta extends object = object> = { | ||
/** | ||
* Unique identifier to reuse later | ||
* @default crypto.randomUUID() | ||
*/ | ||
id?: string | ||
/** | ||
* Name to be used to create the path | ||
* Based on UNIX basename, `${name}.extName` | ||
* Based on UNIX basename, `${name}.extname` | ||
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix | ||
*/ | ||
baseName: TBaseName | ||
baseName: BaseName | ||
/** | ||
* Path will be full qualified path to a specified file | ||
*/ | ||
path: AdvancedPath<TBaseName> | Path | ||
source: Source | ||
imports?: Import[] | ||
exports?: Export[] | ||
path: AdvancedPath<BaseName> | Path | ||
sources: Array<Source> | ||
imports?: Array<Import> | ||
exports?: Array<Export> | ||
/** | ||
@@ -126,15 +124,23 @@ * This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists | ||
meta?: TMeta | ||
banner?: string | ||
footer?: string | ||
} | ||
export type ResolvedImport = Import | ||
export type ResolvedExport = Export | ||
export type ResolvedFile<TMeta extends object = object> = File<TMeta> & { | ||
/** | ||
* Override if a file can be exported by the BarrelManager | ||
* @default true | ||
* @default object-hash | ||
*/ | ||
exportable?: boolean | ||
id: string | ||
/** | ||
* This will override `process.env[key]` inside the `source`, see `getFileSource`. | ||
* Contains the first part of the baseName, generated based on baseName | ||
* @link https://nodejs.org/api/path.html#pathformatpathobject | ||
*/ | ||
env?: NodeJS.ProcessEnv | ||
/** | ||
* The name of the language being used. This can be TypeScript, JavaScript and still have another ext. | ||
*/ | ||
language?: string | ||
name: string | ||
extname: Extname | ||
imports: Array<ResolvedImport> | ||
exports: Array<ResolvedExport> | ||
} |
@@ -22,2 +22,4 @@ import { resolve } from 'node:path' | ||
// await new Promise((resolve) => setTimeout(resolve, 20000)) | ||
await fs.outputFile(resolve(path), data, { encoding: 'utf-8' }) | ||
@@ -56,3 +58,3 @@ | ||
} catch (e) { | ||
console.log(e, resolve(path)) | ||
console.error(e) | ||
} | ||
@@ -59,0 +61,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
272317
4
53
8
2762