forked from aws-amplify/amplify-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.mjs
30 lines (28 loc) · 1007 Bytes
/
utils.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import path from 'node:path';
import * as glob from 'glob';
/**
* Return a map that contains relative file path <-> absolute file path.
* @param {string} matcher The glob matcher
* @param {{ ignore?: string[] }?} options The glob options
* @returns {object} A key value object.
*/
export const getInputForGlob = (matcher, { ignore } = {}) =>
Object.fromEntries(
glob
.sync(matcher, {
ignore: ['src/**/global.d.ts', ...(ignore ?? [])],
})
.map(file => [
// This remove `src/` as well as the file extension from each
// file, so e.g. src/nested/foo.js becomes nested/foo
path.relative(
'src',
file.slice(0, file.length - path.extname(file).length),
),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /<root>/packages/<package-name>src/nested/foo.js
path.resolve(path.resolve('.'), file),
]),
);