Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function resolveExternalModuleAndFn(pointer: any): any {
if (typeof pointer === 'function') {
return pointer;
}
const patternArr = pointer.split('#');
const moduleName = patternArr[0];
const functionName = patternArr[1];
const localFilePath = path.resolve(process.cwd(), moduleName);
const localFileExists = fs.existsSync(localFilePath);
const loadedModule = localFileExists ? require(localFilePath) : importFrom(process.cwd(), moduleName);
if (!(functionName in loadedModule)) {
throw new Error(`${functionName} couldn't be found in module ${moduleName}!`);
}
return loadedModule[functionName];
}
function styledComponentsTransformFactory(app) {
const importing = importFrom(process.cwd(), "styled-components");
return async function(file) {
const { ServerStyleSheet } = await importing;
file.wrap = async (render, comp) => {
const sheet = new ServerStyleSheet();
const html = render(sheet.collectStyles(comp));
const css = sheet.getStyleTags();
app.resources = app.resources.filter(
r => r.id !== `styled-components/${file.pattern.id}`
);
app.resources.push({
id: `styled-components/${file.pattern.id}`,
pattern: file.pattern.id,
async function cleanRawDistObject(rawVal, cwd, canBeFalsey): Promise {
if (Array.isArray(rawVal)) {
let importStr = (rawVal[0].startsWith('./') ||rawVal[0].startsWith('../')) ? path.join(cwd, rawVal[0]) : rawVal[0];
return [{...importFrom(cwd, importStr), name: rawVal[0]}, rawVal[1] || {}];
}
if (typeof rawVal === 'string') {
return [{build: ({cwd}) => {
return executeLifecycleScript({
config: this,
cwd,
cmd: rawVal,
isInteractive: false});
}}, {}];
}
if (!rawVal && !canBeFalsey) {
throw new Error('Cannot be false');
}
return false;
}
return (await Promise.all([
function importPlugin(name, file) {
if (typeof name === 'string') {
const cwd = file === 'unknown' ? process.cwd() : p.dirname(file)
return importFrom(cwd, `markdown-it-${name}`)
}
return name
}
async function cleanRawDistObject(rawVal, cwd, canBeFalsey) {
if (Array.isArray(rawVal)) {
let importStr = (rawVal[0].startsWith('./') || rawVal[0].startsWith('../')) ? path.join(cwd, rawVal[0]) : rawVal[0];
return [Object.assign({}, importFrom(cwd, importStr), { name: rawVal[0] }), rawVal[1] || {}];
}
if (typeof rawVal === 'string') {
return [{ build: ({ cwd }) => {
return executeLifecycleScript({
config: this,
cwd,
cmd: rawVal,
isInteractive: false
});
} }, {}];
}
if (!rawVal && !canBeFalsey) {
throw new Error('Cannot be false');
}
return false;
}
async callback(context, options, file) {
if (!shouldProcess(context.config.rootDirectory, file.filePath, options)) {
return null
}
let babelCore
try {
babelCore = importFrom(context.config.rootDirectory, 'babel-core')
} catch (error) {
if (error && error.code === 'MODULE_NOT_FOUND') {
throw new MessageIssue(
`pundle-resolver-babel is to find 'babel-core' in Project root. Are you sure you installed it?`,
)
}
throw error
}
const mergedConfigs = {
babelrc: false,
filename: file.filePath,
sourceMap: true,
highlightCode: false,
sourceFileName: file.filePath,
}
get(config, 'presets', []).forEach(function(entry) {
const [entryPreset, options = {}] = Array.isArray(entry) ? entry : [entry]
if (!options || typeof options !== 'object') {
throw new Error(`Resolved config for component '${entryPreset}' referenced ${postfix} is invalid`)
}
let preset = entryPreset
if (typeof preset === 'string') {
try {
preset = normalizeEsModules(importFrom(configDirectory, entryPreset))
} catch (error) {
error.message = `Error loading preset '${entryPreset}' referenced ${postfix}: ${error.message}`
throw error
}
}
if (typeof preset === 'function') {
preset = preset(options)
}
if (!Array.isArray(preset)) {
throw new Error(`Resolved value for preset '${entryPreset}' referenced ${postfix} is not an array`)
}
preset.forEach(function(presetEntry) {
const [entryComponent, componentOptions = {}] = Array.isArray(presetEntry) ? presetEntry : [presetEntry]
if (!componentOptions || typeof componentOptions !== 'object') {
throw new Error(
const load = async (ctx: string) => {
try {
if (typeof prefix === 'string' || !prefix) {
return await importFrom(ctx, `${prefix || ''}${_lib}`);
} else throw notFound;
} catch {
let loadLib;
if (prefix instanceof Array) {
for (const p of prefix) {
try {
loadLib = await importFrom(ctx, `${p}${_lib}`);
break;
} catch { continue; }
}
if (loadLib) return loadLib;
} else throw notFound;
}
};