diff --git a/packages/cli/src/build-stylable.ts b/packages/cli/src/build-stylable.ts index 5c03d9a09..c5aedeac2 100644 --- a/packages/cli/src/build-stylable.ts +++ b/packages/cli/src/build-stylable.ts @@ -7,7 +7,6 @@ import { createBuildIdentifier, createDefaultOptions, hasStylableCSSOutput, - NAMESPACE_RESOLVER_MODULE_REQUEST, } from './config/resolve-options'; import { DiagnosticsManager } from './diagnostics-manager'; import { createDefaultLogger, levels } from './logger'; @@ -51,7 +50,7 @@ export async function buildStylable( }), outputFiles = new Map(), requireModule = require, - resolveNamespace = requireModule(NAMESPACE_RESOLVER_MODULE_REQUEST).resolveNamespace, + resolveNamespace, configFilePath, watchOptions = {}, }: BuildStylableContext = {} @@ -92,10 +91,13 @@ export async function buildStylable( fileSystem, requireModule, projectRoot, - resolveNamespace, resolverCache, fileProcessorCache, ...config?.defaultConfig, + resolveNamespace: + resolveNamespace || + config?.defaultConfig?.resolveNamespace || + requireModule('@stylable/node').resolveNamespace, }); const { service, generatedFiles } = await build(buildOptions, { diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index f9520ee6a..b4057586c 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -16,9 +16,11 @@ async function main() { config, } = argv; const rootDir = resolve(argv.rootDir); - const { resolveNamespace } = require(require.resolve(namespaceResolver, { - paths: [rootDir], - })); + const explicitResolveNs = + namespaceResolver && + require(require.resolve(namespaceResolver, { + paths: [rootDir], + })); // const log = createLogger( @@ -42,7 +44,7 @@ async function main() { overrideBuildOptions, defaultOptions, fs, - resolveNamespace, + resolveNamespace: explicitResolveNs?.resolveNamespace, watch, log, configFilePath: config, diff --git a/packages/cli/src/config/resolve-options.ts b/packages/cli/src/config/resolve-options.ts index 0b91d3e99..5908a6280 100644 --- a/packages/cli/src/config/resolve-options.ts +++ b/packages/cli/src/config/resolve-options.ts @@ -7,8 +7,6 @@ import type { CliArguments, BuildOptions, PartialBuildOptions } from '../types'; const { join } = nodeFs; -export const NAMESPACE_RESOLVER_MODULE_REQUEST = '@stylable/node'; - export function getCliArguments(): Arguments { const defaults = createDefaultOptions(); return yargs @@ -85,10 +83,12 @@ export function getCliArguments(): Arguments { alias: 'unsr', }) .option('namespaceResolver', { + type: 'string', description: 'node request to a module that exports a stylable resolveNamespace function', alias: 'nsr', - default: NAMESPACE_RESOLVER_MODULE_REQUEST, + defaultDescription: + 'default to @stylable/node, if stylable.config resolveNamespace is undefined', }) .option('injectCSSRequest', { type: 'boolean', diff --git a/packages/cli/src/types.ts b/packages/cli/src/types.ts index 97486edf9..170c4bb1a 100644 --- a/packages/cli/src/types.ts +++ b/packages/cli/src/types.ts @@ -102,7 +102,7 @@ export interface CliArguments { bundle: string | undefined; dtsSourceMap: boolean | undefined; useNamespaceReference: boolean | undefined; - namespaceResolver: string; + namespaceResolver?: string | undefined; injectCSSRequest: boolean | undefined; cssFilename: string | undefined; cssInJs: boolean | undefined;