Skip to content

Commit

Permalink
fix: namespaceResolver cli argument should override stylable.config
Browse files Browse the repository at this point in the history
  • Loading branch information
idoros committed Nov 20, 2023
1 parent a96c5d0 commit aec07a0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
8 changes: 5 additions & 3 deletions packages/cli/src/build-stylable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,7 +50,7 @@ export async function buildStylable(
}),
outputFiles = new Map(),
requireModule = require,
resolveNamespace = requireModule(NAMESPACE_RESOLVER_MODULE_REQUEST).resolveNamespace,
resolveNamespace,
configFilePath,
watchOptions = {},
}: BuildStylableContext = {}
Expand Down Expand Up @@ -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, {
Expand Down
10 changes: 6 additions & 4 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -42,7 +44,7 @@ async function main() {
overrideBuildOptions,
defaultOptions,
fs,
resolveNamespace,
resolveNamespace: explicitResolveNs?.resolveNamespace,
watch,
log,
configFilePath: config,
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/config/resolve-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CliArguments> {
const defaults = createDefaultOptions();
return yargs
Expand Down Expand Up @@ -85,10 +83,12 @@ export function getCliArguments(): Arguments<CliArguments> {
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',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit aec07a0

Please sign in to comment.