Skip to content

Commit

Permalink
fix: flow type issues and aliases property drilling
Browse files Browse the repository at this point in the history
  • Loading branch information
rayan1810 committed Dec 17, 2023
1 parent cf3f71c commit 4cdbd72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
8 changes: 4 additions & 4 deletions apps/nextjs-example/.babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ module.exports = {
runtimeInjection: false,
genConditionalClasses: true,
treeshakeCompensation: true,
aliases: {
'@/app/*': './app/*',
'@/components/*': './components/*',
},
unstable_moduleResolution: {
type: 'commonJS',
rootDir: path.join(__dirname, '../..'),
aliases: {
'@/app/*': './app/*',
'@/components/*': './components/*',
},
},
},
],
Expand Down
16 changes: 5 additions & 11 deletions packages/babel-plugin/src/utils/state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@ type ModuleResolution =
type: 'commonJS',
rootDir: string,
themeFileExtension?: string,
aliases?: any,
}
| {
type: 'haste',
themeFileExtension?: string,
aliases?: any,
}
| {
type: 'experimental_crossFileParsing',
rootDir: string,
themeFileExtension?: string,
aliases?: any,
};

export type StyleXOptions = $ReadOnly<{
Expand All @@ -49,7 +46,7 @@ export type StyleXOptions = $ReadOnly<{
treeshakeCompensation?: boolean,
genConditionalClasses: boolean,
unstable_moduleResolution: void | ModuleResolution,
aliases: any,
aliases: $ReadOnly<{ [string]: string }>,
...
}>;

Expand Down Expand Up @@ -221,12 +218,9 @@ export default class StateManager {
switch (this.options.unstable_moduleResolution?.type) {
case 'commonJS': {
const rootDir = this.options.unstable_moduleResolution.rootDir;
const aliases =
this.options.unstable_moduleResolution.aliases ??
this.options.aliases ??
undefined;
const aliases = this.options.aliases;
const themeFileExtension =
this.options.unstable_moduleResolution.themeFileExtension ??
this.options.unstable_moduleResolution?.themeFileExtension ??
'.stylex';
if (!matchesFileSuffix(themeFileExtension)(importPath)) {
return false;
Expand All @@ -250,7 +244,7 @@ export default class StateManager {
return ['themeNameRef', addFileExtension(importPath, sourceFilePath)];
}
case 'experimental_crossFileParsing': {
const aliases = this.options.aliases ?? undefined;
const aliases = this.options.aliases;
const themeFileExtension =
this.options.unstable_moduleResolution.themeFileExtension ??
'.stylex';
Expand Down Expand Up @@ -280,7 +274,7 @@ export default class StateManager {
}
}
// a function generate Regex to match the path of files with aliases
function generateAliasRegex(alias: string) {
function generateAliasRegex(alias: string): RegExp {
const regex = new RegExp('^' + alias + '/(.*)');
return regex;
}
Expand Down

0 comments on commit 4cdbd72

Please sign in to comment.