UNPKG

@nx/rspack

Version:

The Nx Plugin for Rspack contains executors and generators that support building applications using Rspack.

43 lines (42 loc) 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeAssets = normalizeAssets; const devkit_1 = require("@nx/devkit"); const fs_1 = require("fs"); const path_1 = require("path"); function normalizeAssets(assets, root, sourceRoot) { return assets.map((asset) => { if (typeof asset === 'string') { const assetPath = (0, devkit_1.normalizePath)(asset); const resolvedAssetPath = (0, path_1.resolve)(root, assetPath); const resolvedSourceRoot = (0, path_1.resolve)(root, sourceRoot); if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) { throw new Error(`The ${resolvedAssetPath} asset path must start with the project source root: ${sourceRoot}`); } const isDirectory = (0, fs_1.statSync)(resolvedAssetPath).isDirectory(); const input = isDirectory ? resolvedAssetPath : (0, path_1.dirname)(resolvedAssetPath); const output = (0, path_1.relative)(resolvedSourceRoot, (0, path_1.resolve)(root, input)); const glob = isDirectory ? '**/*' : (0, path_1.basename)(resolvedAssetPath); return { input, output, glob, }; } else { if (asset.output.startsWith('..')) { throw new Error('An asset cannot be written to a location outside of the output path.'); } const assetPath = (0, devkit_1.normalizePath)(asset.input); const resolvedAssetPath = (0, path_1.resolve)(root, assetPath); return { ...asset, input: resolvedAssetPath, // Now we remove starting slash to make rspack place it from the output root. output: asset.output.replace(/^\//, ''), }; } }); }