@eik/common 4.1.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/lib/classes/eik-config.js +5 -7
- package/lib/classes/local-file-location.js +6 -2
- package/lib/classes/resolved-files.js +3 -1
- package/lib/helpers/path-slashes.js +27 -12
- package/lib/helpers/resolve-files.js +22 -3
- package/package.json +1 -1
- package/types/helpers/path-slashes.d.ts +2 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [4.1.1](https://github.com/eik-lib/common/compare/v4.1.0...v4.1.1) (2024-08-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* windows support ([#303](https://github.com/eik-lib/common/issues/303)) ([4e6a307](https://github.com/eik-lib/common/commit/4e6a3078861a0a03b7275bfb5b2875adda1f2c2e))
|
|
7
|
+
|
|
1
8
|
# [4.1.0](https://github.com/eik-lib/common/compare/v4.0.9...v4.1.0) (2024-08-14)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -8,7 +8,7 @@ import SingleDestMultipleSourcesError from './single-dest-multiple-source-error.
|
|
|
8
8
|
import FileMapping from './file-mapping.js';
|
|
9
9
|
import RemoteFileLocation from './remote-file-location.js';
|
|
10
10
|
import schemas from '../schemas/index.js';
|
|
11
|
-
import { removeTrailingSlash } from '../helpers/path-slashes.js';
|
|
11
|
+
import { removeTrailingSlash, ensurePosix } from '../helpers/path-slashes.js';
|
|
12
12
|
import typeSlug from '../helpers/type-slug.js';
|
|
13
13
|
import resolveFiles from '../helpers/resolve-files.js';
|
|
14
14
|
|
|
@@ -152,13 +152,11 @@ export default class EikConfig {
|
|
|
152
152
|
const shouldMapFilename = extname(destination);
|
|
153
153
|
const relativePathname = shouldMapFilename
|
|
154
154
|
? destination
|
|
155
|
-
: join(destination, localFile.relative);
|
|
156
|
-
const packagePathname =
|
|
157
|
-
|
|
158
|
-
typeSlug(this.type),
|
|
159
|
-
this.name,
|
|
160
|
-
this.version,
|
|
155
|
+
: ensurePosix(join(destination, localFile.relative));
|
|
156
|
+
const packagePathname = ensurePosix(
|
|
157
|
+
join(typeSlug(this.type), this.name, this.version),
|
|
161
158
|
);
|
|
159
|
+
|
|
162
160
|
const remoteDestination = new RemoteFileLocation(
|
|
163
161
|
relativePathname,
|
|
164
162
|
packagePathname,
|
|
@@ -5,6 +5,7 @@ import assert from 'node:assert';
|
|
|
5
5
|
import { join, extname, isAbsolute } from 'node:path';
|
|
6
6
|
// @ts-ignore
|
|
7
7
|
import mime from 'mime-types';
|
|
8
|
+
import { ensurePosix } from '../helpers/path-slashes.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Class containing information about a local file
|
|
@@ -20,7 +21,10 @@ class LocalFileLocation {
|
|
|
20
21
|
typeof basePath === 'string',
|
|
21
22
|
'"basePath" must be of type "string"',
|
|
22
23
|
);
|
|
23
|
-
assert(
|
|
24
|
+
assert(
|
|
25
|
+
!isAbsolute(path),
|
|
26
|
+
`"path" must be a relative path, got ${path}`,
|
|
27
|
+
);
|
|
24
28
|
|
|
25
29
|
/**
|
|
26
30
|
* @type {string} path to file on disk relative to this.basePath
|
|
@@ -36,7 +40,7 @@ class LocalFileLocation {
|
|
|
36
40
|
* @type {string} absolute path to file on disk,
|
|
37
41
|
* this is a concatentation of this.basePath and this.relative
|
|
38
42
|
*/
|
|
39
|
-
this.absolute = join(basePath, path);
|
|
43
|
+
this.absolute = ensurePosix(join(basePath, path));
|
|
40
44
|
|
|
41
45
|
/**
|
|
42
46
|
* @type {string} file extension with "." character included. (eg. ".json")
|
|
@@ -46,7 +46,9 @@ class ResolvedFiles {
|
|
|
46
46
|
*[Symbol.iterator]() {
|
|
47
47
|
for (const file of this[originalFiles]) {
|
|
48
48
|
const relative = removeTrailingSlash(
|
|
49
|
-
removeLeadingSlash(
|
|
49
|
+
removeLeadingSlash(
|
|
50
|
+
file.replace(/\\/g, '/').replace(this.basePath, ''),
|
|
51
|
+
),
|
|
50
52
|
);
|
|
51
53
|
yield new LocalFileLocation(relative, this.basePath);
|
|
52
54
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { sep } from 'path';
|
|
2
|
+
import { platform } from 'os';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Add a trailing slash to a path if necessary
|
|
3
6
|
*
|
|
@@ -5,7 +8,7 @@
|
|
|
5
8
|
*
|
|
6
9
|
* @returns {string}
|
|
7
10
|
*/
|
|
8
|
-
const addTrailingSlash = (val) => (val.endsWith('/') ? val : `${val}/`);
|
|
11
|
+
export const addTrailingSlash = (val) => (val.endsWith('/') ? val : `${val}/`);
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* Remove a trailing slash from a path if necessary
|
|
@@ -14,17 +17,21 @@ const addTrailingSlash = (val) => (val.endsWith('/') ? val : `${val}/`);
|
|
|
14
17
|
*
|
|
15
18
|
* @returns {string}
|
|
16
19
|
*/
|
|
17
|
-
const removeTrailingSlash = (val) =>
|
|
18
|
-
|
|
20
|
+
export const removeTrailingSlash = (val) =>
|
|
21
|
+
// this is also used to trim from config files, which may now always use the OS's sep value. Look for both.
|
|
22
|
+
val.endsWith('/') || val.endsWith('\\')
|
|
23
|
+
? val.substr(0, val.length - 1)
|
|
24
|
+
: val;
|
|
19
25
|
|
|
20
26
|
/**
|
|
21
|
-
* Add a leading slash to a path if necessary
|
|
27
|
+
* Add a leading slash to a path if necessary, but not on Windows
|
|
22
28
|
*
|
|
23
29
|
* @param {string} val
|
|
24
30
|
*
|
|
25
31
|
* @returns {string}
|
|
26
32
|
*/
|
|
27
|
-
const addLeadingSlash = (val) =>
|
|
33
|
+
export const addLeadingSlash = (val) =>
|
|
34
|
+
val.startsWith('/') || platform() === 'win32' ? val : `/${val}`;
|
|
28
35
|
|
|
29
36
|
/**
|
|
30
37
|
* Remove a leading slash from a path if necessary
|
|
@@ -33,11 +40,19 @@ const addLeadingSlash = (val) => (val.startsWith('/') ? val : `/${val}`);
|
|
|
33
40
|
*
|
|
34
41
|
* @returns {string}
|
|
35
42
|
*/
|
|
36
|
-
const removeLeadingSlash = (val) =>
|
|
43
|
+
export const removeLeadingSlash = (val) =>
|
|
44
|
+
val.startsWith('/') || val.startsWith('\\') ? val.substr(1) : val;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Replaces a path string's separators (/ or \) with the current OS's sep value from node:path.
|
|
48
|
+
* @param {string} val
|
|
49
|
+
* @returns {string}
|
|
50
|
+
*/
|
|
51
|
+
export const ensureOsSep = (val) => val.replace(/\/\\/g, sep);
|
|
37
52
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Replaces any backslash with a forward slash.
|
|
55
|
+
* @param {string} val
|
|
56
|
+
* @returns {string}
|
|
57
|
+
*/
|
|
58
|
+
export const ensurePosix = (val) => val.replace(/\\/g, '/');
|
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
removeTrailingSlash,
|
|
6
6
|
addLeadingSlash,
|
|
7
7
|
removeLeadingSlash,
|
|
8
|
+
ensureOsSep,
|
|
9
|
+
ensurePosix,
|
|
8
10
|
} from './path-slashes.js';
|
|
9
11
|
import ResolvedFiles from '../classes/resolved-files.js';
|
|
10
12
|
|
|
@@ -23,6 +25,7 @@ const pathUntilGlob = (path) => {
|
|
|
23
25
|
if (isGlob(segment)) break;
|
|
24
26
|
segmentsToKeep.push(segment);
|
|
25
27
|
}
|
|
28
|
+
|
|
26
29
|
return addLeadingSlash(normalize(segmentsToKeep.join(sep)));
|
|
27
30
|
};
|
|
28
31
|
|
|
@@ -37,13 +40,24 @@ const pathUntilGlob = (path) => {
|
|
|
37
40
|
const resolveFiles = async (files, cwd) =>
|
|
38
41
|
Promise.all(
|
|
39
42
|
Object.entries(files).map(async (definition) => {
|
|
40
|
-
|
|
43
|
+
let [, source] = definition;
|
|
44
|
+
|
|
45
|
+
// The config may not always match the OS's separator.
|
|
46
|
+
// Convert the input to OS-specific if necessary.
|
|
47
|
+
// We convert back to always using forward slashes for glob,
|
|
48
|
+
// but for calculating the paths relative to cwd we'd like
|
|
49
|
+
// these to be OS-specific for now.
|
|
50
|
+
source = ensureOsSep(source);
|
|
51
|
+
|
|
41
52
|
// normalise to absolute path
|
|
42
53
|
let pattern = isAbsolute(source) ? source : join(cwd, source);
|
|
43
54
|
|
|
44
55
|
// append glob if folder
|
|
45
|
-
if (
|
|
46
|
-
pattern
|
|
56
|
+
if (
|
|
57
|
+
extname(pattern) === '' &&
|
|
58
|
+
isGlob(ensurePosix(pattern)) === false
|
|
59
|
+
) {
|
|
60
|
+
pattern = `${pattern}${sep}**${sep}*`;
|
|
47
61
|
}
|
|
48
62
|
|
|
49
63
|
// trim off any glob
|
|
@@ -56,6 +70,11 @@ const resolveFiles = async (files, cwd) =>
|
|
|
56
70
|
);
|
|
57
71
|
}
|
|
58
72
|
|
|
73
|
+
// convert glob pattern to forward slash separators
|
|
74
|
+
// https://www.npmjs.com/package/glob#windows
|
|
75
|
+
basePath = ensurePosix(basePath);
|
|
76
|
+
pattern = ensurePosix(pattern);
|
|
77
|
+
|
|
59
78
|
// process glob pattern into a list of existing files
|
|
60
79
|
const resolvedFiles = await glob(pattern, {
|
|
61
80
|
cwd: basePath,
|
package/package.json
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Add a trailing slash to a path if necessary
|
|
3
|
-
*
|
|
4
|
-
* @param {string} val
|
|
5
|
-
*
|
|
6
|
-
* @returns {string}
|
|
7
|
-
*/
|
|
8
1
|
export function addTrailingSlash(val: string): string;
|
|
9
|
-
/**
|
|
10
|
-
* Remove a trailing slash from a path if necessary
|
|
11
|
-
*
|
|
12
|
-
* @param {string} val
|
|
13
|
-
*
|
|
14
|
-
* @returns {string}
|
|
15
|
-
*/
|
|
16
2
|
export function removeTrailingSlash(val: string): string;
|
|
17
|
-
/**
|
|
18
|
-
* Add a leading slash to a path if necessary
|
|
19
|
-
*
|
|
20
|
-
* @param {string} val
|
|
21
|
-
*
|
|
22
|
-
* @returns {string}
|
|
23
|
-
*/
|
|
24
3
|
export function addLeadingSlash(val: string): string;
|
|
25
|
-
/**
|
|
26
|
-
* Remove a leading slash from a path if necessary
|
|
27
|
-
*
|
|
28
|
-
* @param {string} val
|
|
29
|
-
*
|
|
30
|
-
* @returns {string}
|
|
31
|
-
*/
|
|
32
4
|
export function removeLeadingSlash(val: string): string;
|
|
5
|
+
export function ensureOsSep(val: string): string;
|
|
6
|
+
export function ensurePosix(val: string): string;
|