Skip to content

Commit 105df51

Browse files
p0nch000nmn
authored andcommitted
Considered deno.json, fix pr review comments
Fixed flow and prettier tests failing Correct install of json5 dependency fix: Resolve alias paths to absolute paths
1 parent f81b4f1 commit 105df51

File tree

9 files changed

+389
-36
lines changed

9 files changed

+389
-36
lines changed

apps/nextjs-example/app/Counter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'use client';
1111

1212
import * as stylex from '@stylexjs/stylex';
13-
import { spacing, text, globalTokens as $ } from './globalTokens.stylex';
13+
import { spacing, text, globalTokens as $ } from '@/app/globalTokens.stylex';
1414
import { colors } from '@stylexjs/open-props/lib/colors.stylex';
1515
import { useState } from 'react';
1616

apps/nextjs-example/babel.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*
77
*
88
*/
9+
910
const path = require('path');
1011
module.exports = {
1112
presets: ['next/babel'],
@@ -19,9 +20,9 @@ module.exports = {
1920
runtimeInjection: false,
2021
genConditionalClasses: true,
2122
treeshakeCompensation: true,
22-
aliases: {
23-
'@/*': [path.join(__dirname, '*')],
24-
},
23+
// aliases: {
24+
// '@/*': [path.join(__dirname, '*')],
25+
// },
2526
unstable_moduleResolution: {
2627
type: 'commonJS',
2728
},

apps/nextjs-example/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"clean": "rimraf .next",
76
"dev": "next dev",
87
"build": "next build",
98
"start": "next start",
@@ -17,7 +16,7 @@
1716
"next": "14.0.1"
1817
},
1918
"devDependencies": {
20-
"@stylexjs/eslint-plugin": "^0.7.5",
19+
"@stylexjs/eslint-plugin": "^0.10.1",
2120
"@stylexjs/postcss-plugin": "0.10.1",
2221
"@types/node": "^22.7.6",
2322
"@types/react": "^18.3.11",

apps/nextjs-example/tsconfig.json

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4-
"lib": [
5-
"dom",
6-
"dom.iterable",
7-
"esnext"
8-
],
4+
"lib": ["dom", "dom.iterable", "esnext"],
95
"allowJs": true,
106
"skipLibCheck": true,
117
"strict": true,
@@ -23,18 +19,9 @@
2319
}
2420
],
2521
"paths": {
26-
"@/*": [
27-
"./*"
28-
],
22+
"@/*": ["./*"]
2923
}
3024
},
31-
"include": [
32-
"next-env.d.ts",
33-
"**/*.ts",
34-
"**/*.tsx",
35-
".next/types/**/*.ts"
36-
],
37-
"exclude": [
38-
"node_modules"
39-
]
40-
}
25+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
26+
"exclude": ["node_modules"]
27+
}

flow-typed/json5.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// @flow
2+
type TSConfig = {
3+
compilerOptions?: {
4+
baseUrl?: string,
5+
paths?: { [key: string]: Array<string> },
6+
},
7+
};
8+
9+
type DenoConfig = {
10+
imports?: { [key: string]: string | Array<string> },
11+
};
12+
13+
type PackageJSON = {
14+
name?: string,
15+
imports?: { [key: string]: string | Array<string> },
16+
};
17+
18+
type ConfigType = TSConfig | DenoConfig | PackageJSON;
19+
20+
declare module 'json5' {
21+
declare module.exports: {
22+
parse: (input: string) => mixed,
23+
stringify: (
24+
value: mixed,
25+
replacer?: ?Function | ?Array<mixed>,
26+
space?: string | number,
27+
) => string,
28+
};
29+
}

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*
8+
*/
9+
10+
'use strict';
11+
12+
import path from 'path';
13+
import fs from 'fs';
14+
import os from 'os';
15+
import StateManager from '../src/utils/state-manager';
16+
17+
describe('StyleX Alias Configuration', () => {
18+
let tmpDir;
19+
let state;
20+
21+
beforeEach(() => {
22+
// Create a temporary directory for our test files
23+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'stylex-test-'));
24+
25+
// Create a mock babel state
26+
state = {
27+
file: {
28+
metadata: {},
29+
},
30+
filename: path.join(tmpDir, 'src/components/Button.js'),
31+
};
32+
});
33+
34+
afterEach(() => {
35+
// Clean up temporary directory
36+
fs.rmSync(tmpDir, { recursive: true, force: true });
37+
});
38+
39+
const setupFiles = (files) => {
40+
for (const [filePath, content] of Object.entries(files)) {
41+
const fullPath = path.join(tmpDir, filePath);
42+
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
43+
fs.writeFileSync(fullPath, JSON.stringify(content, null, 2));
44+
}
45+
};
46+
47+
test('discovers aliases from package.json imports', () => {
48+
setupFiles({
49+
'package.json': {
50+
name: 'test-package',
51+
imports: {
52+
'#components': './src/components',
53+
'#utils/*': './src/utils/*',
54+
},
55+
},
56+
});
57+
58+
const manager = new StateManager(state);
59+
60+
expect(manager.options.aliases).toEqual({
61+
components: ['./src/components'],
62+
'utils/*': ['./src/utils/*'],
63+
});
64+
});
65+
66+
test('discovers aliases from tsconfig.json', () => {
67+
setupFiles({
68+
'package.json': { name: 'test-package' },
69+
'tsconfig.json': {
70+
compilerOptions: {
71+
baseUrl: '.',
72+
paths: {
73+
'@components/*': ['src/components/*'],
74+
'@utils/*': ['src/utils/*'],
75+
},
76+
},
77+
},
78+
});
79+
80+
const manager = new StateManager(state);
81+
82+
expect(manager.options.aliases).toEqual({
83+
'@components': ['src/components'],
84+
'@utils': ['src/utils'],
85+
});
86+
});
87+
88+
test('discovers aliases from deno.json', () => {
89+
setupFiles({
90+
'package.json': { name: 'test-package' },
91+
'deno.json': {
92+
imports: {
93+
'@components/': './src/components/',
94+
'@utils/': './src/utils/',
95+
},
96+
},
97+
});
98+
99+
const manager = new StateManager(state);
100+
101+
expect(manager.options.aliases).toEqual({
102+
'@components/': ['./src/components/'],
103+
'@utils/': ['./src/utils/'],
104+
});
105+
});
106+
107+
test('merges aliases from all config files', () => {
108+
setupFiles({
109+
'package.json': {
110+
name: 'test-package',
111+
imports: {
112+
'#components': './src/components',
113+
},
114+
},
115+
'tsconfig.json': {
116+
compilerOptions: {
117+
baseUrl: '.',
118+
paths: {
119+
'@utils/*': ['src/utils/*'],
120+
},
121+
},
122+
},
123+
'deno.json': {
124+
imports: {
125+
'@styles/': './src/styles/',
126+
},
127+
},
128+
});
129+
130+
const manager = new StateManager(state);
131+
132+
expect(manager.options.aliases).toEqual({
133+
components: ['./src/components'],
134+
'@utils': ['src/utils'],
135+
'@styles/': ['./src/styles/'],
136+
});
137+
});
138+
139+
test('manual configuration overrides discovered aliases', () => {
140+
setupFiles({
141+
'package.json': {
142+
name: 'test-package',
143+
imports: {
144+
'#components': './src/components',
145+
},
146+
},
147+
});
148+
149+
state.opts = {
150+
aliases: {
151+
components: './custom/path',
152+
},
153+
};
154+
155+
const manager = new StateManager(state);
156+
157+
expect(manager.options.aliases).toEqual({
158+
components: ['./custom/path'],
159+
});
160+
});
161+
162+
test('handles missing configuration files gracefully', () => {
163+
const manager = new StateManager(state);
164+
expect(manager.options.aliases).toBeNull();
165+
});
166+
167+
test('handles invalid JSON files gracefully', () => {
168+
setupFiles({
169+
'package.json': '{invalid json',
170+
'tsconfig.json': '{also invalid',
171+
'deno.json': '{more invalid',
172+
});
173+
174+
const manager = new StateManager(state);
175+
expect(manager.options.aliases).toBeNull();
176+
});
177+
});

packages/babel-plugin/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"@babel/core": "^7.25.8",
2020
"@babel/traverse": "^7.25.7",
2121
"@babel/types": "^7.25.8",
22-
"@dual-bundle/import-meta-resolve": "^4.1.0"
22+
"@dual-bundle/import-meta-resolve": "^4.1.0",
23+
"json5": "^2.2.3"
2324
},
2425
"jest": {
2526
"verbose": true,

0 commit comments

Comments
 (0)