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 processFactory(
stylableConfig?: Partial,
factoryOptions?: Partial
) {
return stylableModuleFactory(
{
fileSystem: fs,
requireModule: require,
projectRoot: '',
...stylableConfig
},
// ensure the generated module points to our own @stylable/runtime copy
// this allows @stylable/jest to be used as part of a globally installed CLI
{ runtimePath: stylableRuntimePath, ...factoryOptions }
);
}
public createModuleSource(
module: StylableModule,
moduleId: string,
stylableResult: StylableResults,
css: string,
depth: string | number,
renderableOnly = false
) {
const moduleSource = generateModuleSource(
stylableResult,
moduleId,
[],
this.options.includeCSSInJS ? `${WEBPACK_STYLABLE}.$` : 'null',
`${WEBPACK_STYLABLE}.create`,
`${WEBPACK_STYLABLE}.createRenderable`,
css,
typeof depth === 'number' ? depth.toString() : depth,
'module.' + module.exportsArgument,
this.options.experimentalHMR
? `/* Webpack HMR */ if (module && module.hot) { module.hot.accept(); }`
: '',
renderableOnly
);
return new OriginalSource(moduleSource, module.resource);
export function attachHook({
matcher,
afterCompile,
stylableConfig,
runtimePath,
ignoreJSModules,
legacyRuntime
}: Partial = {}) {
const stylableToModule = stylableModuleFactory(
{
projectRoot: 'root',
fileSystem: fs,
requireModule: require,
resolveNamespace,
...stylableConfig
},
{ runtimePath, legacyRuntime }
);
if (!matcher) {
matcher = defaultStylableMatcher;
}
const prevHook = require.extensions[HOOK_EXTENSION];
require.extensions[HOOK_EXTENSION] = function cssModulesHook(m: any, filename: string) {
() =>
createModuleSource(
res,
format,
includeCSSInJS,
undefined,
undefined,
undefined,
injectCSSRequest ? [`./${cssAssetFilename}`] : [],
compat ? '@stylable/runtime/cjs/index-legacy' : '@stylable/runtime',
compat ? ['module.exports.default = module.exports;'] : []
),
`Transform Error: ${filePath}`