forked from daren.hsu/line_push
31 lines
1.3 KiB
JavaScript
31 lines
1.3 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const path_1 = __importDefault(require("path"));
|
|
const util_1 = __importDefault(require("util"));
|
|
const glob_1 = __importDefault(require("glob"));
|
|
const _1 = require(".");
|
|
const isLegacyWebpack = (ctx) => !!ctx.options;
|
|
const getRootContext = (ctx) => {
|
|
if (isLegacyWebpack(ctx)) {
|
|
return ctx.options.context;
|
|
}
|
|
return ctx.rootContext;
|
|
};
|
|
const flatten = (items) => {
|
|
const emptyItems = [];
|
|
return emptyItems.concat(...items);
|
|
};
|
|
exports.matchFiles = async (ctx, options) => {
|
|
const { patterns, globOptions } = options;
|
|
const files = await Promise.all(patterns.map(async (pattern) => {
|
|
const rootContext = getRootContext(ctx);
|
|
const absolutePattern = path_1.default.isAbsolute(pattern) ? pattern : path_1.default.resolve(rootContext, pattern);
|
|
const partialFiles = await util_1.default.promisify(glob_1.default)(absolutePattern, globOptions);
|
|
return partialFiles.filter(_1.isStyleFile);
|
|
}));
|
|
return [...new Set(flatten(files))].map(file => path_1.default.resolve(file));
|
|
};
|
|
//# sourceMappingURL=match-files.js.map
|