@eik/common
Advanced tools
Comparing version 4.1.0 to 4.1.1
@@ -0,1 +1,8 @@ | ||
## [4.1.1](https://github.com/eik-lib/common/compare/v4.1.0...v4.1.1) (2024-08-16) | ||
### Bug Fixes | ||
* windows support ([#303](https://github.com/eik-lib/common/issues/303)) ([4e6a307](https://github.com/eik-lib/common/commit/4e6a3078861a0a03b7275bfb5b2875adda1f2c2e)) | ||
# [4.1.0](https://github.com/eik-lib/common/compare/v4.0.9...v4.1.0) (2024-08-14) | ||
@@ -2,0 +9,0 @@ |
@@ -11,3 +11,3 @@ /** | ||
import schemas from '../schemas/index.js'; | ||
import { removeTrailingSlash } from '../helpers/path-slashes.js'; | ||
import { removeTrailingSlash, ensurePosix } from '../helpers/path-slashes.js'; | ||
import typeSlug from '../helpers/type-slug.js'; | ||
@@ -156,9 +156,7 @@ import resolveFiles from '../helpers/resolve-files.js'; | ||
? destination | ||
: join(destination, localFile.relative); | ||
const packagePathname = join( | ||
// @ts-ignore | ||
typeSlug(this.type), | ||
this.name, | ||
this.version, | ||
: ensurePosix(join(destination, localFile.relative)); | ||
const packagePathname = ensurePosix( | ||
join(typeSlug(this.type), this.name, this.version), | ||
); | ||
const remoteDestination = new RemoteFileLocation( | ||
@@ -165,0 +163,0 @@ relativePathname, |
@@ -8,2 +8,3 @@ /** | ||
import mime from 'mime-types'; | ||
import { ensurePosix } from '../helpers/path-slashes.js'; | ||
@@ -24,3 +25,6 @@ /** | ||
); | ||
assert(!isAbsolute(path), '"path" must be a relative path'); | ||
assert( | ||
!isAbsolute(path), | ||
`"path" must be a relative path, got ${path}`, | ||
); | ||
@@ -41,3 +45,3 @@ /** | ||
*/ | ||
this.absolute = join(basePath, path); | ||
this.absolute = ensurePosix(join(basePath, path)); | ||
@@ -44,0 +48,0 @@ /** |
@@ -49,3 +49,5 @@ /** | ||
const relative = removeTrailingSlash( | ||
removeLeadingSlash(file.replace(this.basePath, '')), | ||
removeLeadingSlash( | ||
file.replace(/\\/g, '/').replace(this.basePath, ''), | ||
), | ||
); | ||
@@ -52,0 +54,0 @@ yield new LocalFileLocation(relative, this.basePath); |
@@ -0,1 +1,4 @@ | ||
import { sep } from 'path'; | ||
import { platform } from 'os'; | ||
/** | ||
@@ -8,3 +11,3 @@ * Add a trailing slash to a path if necessary | ||
*/ | ||
const addTrailingSlash = (val) => (val.endsWith('/') ? val : `${val}/`); | ||
export const addTrailingSlash = (val) => (val.endsWith('/') ? val : `${val}/`); | ||
@@ -18,7 +21,10 @@ /** | ||
*/ | ||
const removeTrailingSlash = (val) => | ||
val.endsWith('/') ? val.substr(0, val.length - 1) : val; | ||
export const removeTrailingSlash = (val) => | ||
// this is also used to trim from config files, which may now always use the OS's sep value. Look for both. | ||
val.endsWith('/') || val.endsWith('\\') | ||
? val.substr(0, val.length - 1) | ||
: val; | ||
/** | ||
* Add a leading slash to a path if necessary | ||
* Add a leading slash to a path if necessary, but not on Windows | ||
* | ||
@@ -29,3 +35,4 @@ * @param {string} val | ||
*/ | ||
const addLeadingSlash = (val) => (val.startsWith('/') ? val : `/${val}`); | ||
export const addLeadingSlash = (val) => | ||
val.startsWith('/') || platform() === 'win32' ? val : `/${val}`; | ||
@@ -39,9 +46,17 @@ /** | ||
*/ | ||
const removeLeadingSlash = (val) => (val.startsWith('/') ? val.substr(1) : val); | ||
export const removeLeadingSlash = (val) => | ||
val.startsWith('/') || val.startsWith('\\') ? val.substr(1) : val; | ||
export { | ||
addTrailingSlash, | ||
removeTrailingSlash, | ||
addLeadingSlash, | ||
removeLeadingSlash, | ||
}; | ||
/** | ||
* Replaces a path string's separators (/ or \) with the current OS's sep value from node:path. | ||
* @param {string} val | ||
* @returns {string} | ||
*/ | ||
export const ensureOsSep = (val) => val.replace(/\/\\/g, sep); | ||
/** | ||
* Replaces any backslash with a forward slash. | ||
* @param {string} val | ||
* @returns {string} | ||
*/ | ||
export const ensurePosix = (val) => val.replace(/\\/g, '/'); |
@@ -8,2 +8,4 @@ import { extname, join, isAbsolute, basename, sep, normalize } from 'node:path'; | ||
removeLeadingSlash, | ||
ensureOsSep, | ||
ensurePosix, | ||
} from './path-slashes.js'; | ||
@@ -27,2 +29,3 @@ import ResolvedFiles from '../classes/resolved-files.js'; | ||
} | ||
return addLeadingSlash(normalize(segmentsToKeep.join(sep))); | ||
@@ -42,3 +45,11 @@ }; | ||
Object.entries(files).map(async (definition) => { | ||
const [, source] = definition; | ||
let [, source] = definition; | ||
// The config may not always match the OS's separator. | ||
// Convert the input to OS-specific if necessary. | ||
// We convert back to always using forward slashes for glob, | ||
// but for calculating the paths relative to cwd we'd like | ||
// these to be OS-specific for now. | ||
source = ensureOsSep(source); | ||
// normalise to absolute path | ||
@@ -48,4 +59,7 @@ let pattern = isAbsolute(source) ? source : join(cwd, source); | ||
// append glob if folder | ||
if (extname(pattern) === '' && isGlob(pattern) === false) { | ||
pattern = join(pattern, '/**/*'); | ||
if ( | ||
extname(pattern) === '' && | ||
isGlob(ensurePosix(pattern)) === false | ||
) { | ||
pattern = `${pattern}${sep}**${sep}*`; | ||
} | ||
@@ -63,2 +77,7 @@ | ||
// convert glob pattern to forward slash separators | ||
// https://www.npmjs.com/package/glob#windows | ||
basePath = ensurePosix(basePath); | ||
pattern = ensurePosix(pattern); | ||
// process glob pattern into a list of existing files | ||
@@ -65,0 +84,0 @@ const resolvedFiles = await glob(pattern, { |
{ | ||
"name": "@eik/common", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"description": "Common utilities for Eik modules", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,32 +0,6 @@ | ||
/** | ||
* Add a trailing slash to a path if necessary | ||
* | ||
* @param {string} val | ||
* | ||
* @returns {string} | ||
*/ | ||
export function addTrailingSlash(val: string): string; | ||
/** | ||
* Remove a trailing slash from a path if necessary | ||
* | ||
* @param {string} val | ||
* | ||
* @returns {string} | ||
*/ | ||
export function removeTrailingSlash(val: string): string; | ||
/** | ||
* Add a leading slash to a path if necessary | ||
* | ||
* @param {string} val | ||
* | ||
* @returns {string} | ||
*/ | ||
export function addLeadingSlash(val: string): string; | ||
/** | ||
* Remove a leading slash from a path if necessary | ||
* | ||
* @param {string} val | ||
* | ||
* @returns {string} | ||
*/ | ||
export function removeLeadingSlash(val: string): string; | ||
export function ensureOsSep(val: string): string; | ||
export function ensurePosix(val: string): string; |
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
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
83429
1672