Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// dev
const cssImport = require('postcss-import');
const colorsExport = require('./colors-export');
// setup resolver for postcss-import
const ResolverFactory = require('enhanced-resolve/lib/ResolverFactory');
const NodeJsInputFileSystem = require('enhanced-resolve/lib/NodeJsInputFileSystem');
const CachedInputFileSystem = require('enhanced-resolve/lib/CachedInputFileSystem');
const { source, styleguide } = require('../../lib/path-helpers');
const { resolve } = require('../workflow/shared');
const fileSystem = new CachedInputFileSystem(new NodeJsInputFileSystem(), 60000);
const resolver = ResolverFactory.createResolver({
alias: resolve.alias,
extensions: ['.css'],
modules: [source(), 'node_modules'],
useSyncFileSystemCalls: true,
fileSystem
});
module.exports.linting = [
stylelint(),
reporter()
];
const standard = [
mixins(),
export function createInfrastructure(
projectRoot: string,
fileSystem: MinimalFS,
onProcess: (meta: StylableMeta, path: string) => StylableMeta = x => x
): StylableInfrastructure {
const eResolver = ResolverFactory.createResolver({
useSyncFileSystemCalls: true,
fileSystem
});
const fileProcessor = cachedProcessFile((from, content) => {
if (!path.isAbsolute(from)) {
from = eResolver.resolveSync({}, projectRoot, from);
}
return onProcess(process(safeParse(content, {from})), from);
}, {
readFileSync(moduleId: string) {
if (!path.isAbsolute(moduleId)) {
moduleId = eResolver.resolveSync({}, projectRoot, moduleId);
}
return fileSystem.readFileSync(moduleId, 'utf8');
},
export function createInfrastructure(
projectRoot: string,
fileSystem: MinimalFS,
onProcess?: (meta: StylableMeta, path: string) => StylableMeta,
resolveOptions: any = {},
resolveNamespace?: typeof processNamespace
): StylableInfrastructure {
const eResolver = ResolverFactory.createResolver({
useSyncFileSystemCalls: true,
fileSystem,
...resolveOptions
});
const resolvePath = (context: string | undefined = projectRoot, moduleId: string) => {
if (!path.isAbsolute(moduleId) && moduleId.charAt(0) !== '.') {
moduleId = eResolver.resolveSync({}, context, moduleId);
}
return moduleId;
};
const fileProcessor = cachedProcessFile(
(from, content) => {
return process(safeParse(content, { from: resolvePath(projectRoot, from) }), undefined, resolveNamespace);
},