UNPKG

@herberttn/bytenode-webpack-plugin

Version:
96 lines 3.91 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.toSiblingRelativeFileLocation = exports.toLoaderFileName = exports.normalizeCodePathForWindows = exports.normalizeCodePathForUnix = exports.normalizeCodePath = exports.isTargetExtension = exports.isCompiledExtension = exports.fromTargetToCompiledExtension = exports.fromCompiledToTargetExtension = exports.createFileMatcher = void 0; const os_1 = require("os"); const path_1 = require("path"); const picomatch_1 = __importDefault(require("picomatch")); const slash_1 = __importDefault(require("slash")); const COMPILED_EXTENSION = '.jsc'; const COMPILED_EXTENSION_REGEX = new RegExp('\\' + COMPILED_EXTENSION + '$', 'i'); const LOADER_EXTENSION = '.js'; const LOADER_SUFFIX = '.loader'; const TARGET_EXTENSION = '.js'; const TARGET_EXTENSION_REGEX = new RegExp('\\' + TARGET_EXTENSION + '$', 'i'); function createFileMatcher(includes = [], excludes = []) { if (includes.length <= 0 && excludes.length <= 0) { return function bypass() { return true; }; } const includeMatchers = includes.map(createIntentMatcher); const excludeMatchers = excludes.map(createIntentMatcher); return function matches(file) { file = (0, slash_1.default)(file); for (const matcher of excludeMatchers) { if (matcher.test(file)) { return false; } } for (const matcher of includeMatchers) { if (matcher.test(file)) { return true; } } return includeMatchers.length <= 0; }; function createIntentMatcher(intent) { if (intent instanceof RegExp) { return intent; } return { test(file) { const pattern = (0, slash_1.default)(intent); const matches = (0, picomatch_1.default)(pattern, { dot: true }); return matches(file); }, }; } } exports.createFileMatcher = createFileMatcher; function fromCompiledToTargetExtension(file) { return file.replace(COMPILED_EXTENSION_REGEX, TARGET_EXTENSION); } exports.fromCompiledToTargetExtension = fromCompiledToTargetExtension; function fromTargetToCompiledExtension(file) { return file.replace(TARGET_EXTENSION_REGEX, COMPILED_EXTENSION); } exports.fromTargetToCompiledExtension = fromTargetToCompiledExtension; function isCompiledExtension(file) { return COMPILED_EXTENSION_REGEX.test(file); } exports.isCompiledExtension = isCompiledExtension; function isTargetExtension(file) { return TARGET_EXTENSION_REGEX.test(file); } exports.isTargetExtension = isTargetExtension; function normalizeCodePath(path) { if (/win32/.test((0, os_1.platform)()) && path_1.win32.isAbsolute(path)) { return normalizeCodePathForWindows(path); } return normalizeCodePathForUnix(path); } exports.normalizeCodePath = normalizeCodePath; function normalizeCodePathForUnix(path) { return (0, slash_1.default)(path); } exports.normalizeCodePathForUnix = normalizeCodePathForUnix; function normalizeCodePathForWindows(path) { path = path_1.win32.normalize(path); path = path.replace(/\\/g, '\\\\'); return path; } exports.normalizeCodePathForWindows = normalizeCodePathForWindows; function toLoaderFileName(file) { const name = (0, path_1.basename)(file); const pure = (0, path_1.basename)(name, (0, path_1.extname)(file)); return file.replace(name, pure + LOADER_SUFFIX + LOADER_EXTENSION); } exports.toLoaderFileName = toLoaderFileName; function toSiblingRelativeFileLocation(file) { return `./${(0, path_1.basename)(file)}`; } exports.toSiblingRelativeFileLocation = toSiblingRelativeFileLocation; //# sourceMappingURL=utils.js.map