scss-variable-extractor 1.6.3 → 1.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,230 +1,230 @@
1
- const {
2
- parseAngularJson,
3
- extractProjects,
4
- getProject,
5
- getDefaultProject,
6
- detectSourceDirectory,
7
- getGlobalStyleFiles,
8
- enhanceConfigFromAngularJson,
9
- findProjectForPath
10
- } = require('../src/angular-parser');
11
- const path = require('path');
12
-
13
- describe('Angular Parser', () => {
14
- const fixturesPath = path.join(__dirname, 'fixtures');
15
- const angularJsonPath = path.join(fixturesPath, 'angular.json');
16
-
17
- describe('parseAngularJson', () => {
18
- test('should parse angular.json file', () => {
19
- const config = parseAngularJson(angularJsonPath);
20
-
21
- expect(config).not.toBeNull();
22
- expect(config.raw).toBeDefined();
23
- expect(config.projects).toBeDefined();
24
- expect(config.defaultProject).toBe('subapp');
25
- expect(config.version).toBe(1);
26
- });
27
-
28
- test('should return null if angular.json not found', () => {
29
- const config = parseAngularJson('/nonexistent/path/angular.json');
30
-
31
- expect(config).toBeNull();
32
- });
33
-
34
- test('should extract projects', () => {
35
- const config = parseAngularJson(angularJsonPath);
36
-
37
- expect(config.projects.length).toBeGreaterThan(0);
38
- expect(config.projects[0].name).toBeDefined();
39
- expect(config.projects[0].type).toBeDefined();
40
- });
41
- });
42
-
43
- describe('extractProjects', () => {
44
- test('should extract all projects from angular.json', () => {
45
- const config = parseAngularJson(angularJsonPath);
46
- const projects = config.projects;
47
-
48
- expect(projects.length).toBe(2);
49
-
50
- const subapp = projects.find(p => p.name === 'subapp');
51
- expect(subapp).toBeDefined();
52
- expect(subapp.type).toBe('application');
53
- expect(subapp.prefix).toBe('app');
54
- expect(subapp.stylePreprocessor).toBe('scss');
55
-
56
- const lib = projects.find(p => p.name === 'shared-lib');
57
- expect(lib).toBeDefined();
58
- expect(lib.type).toBe('library');
59
- expect(lib.prefix).toBe('lib');
60
- });
61
-
62
- test('should detect style preprocessor', () => {
63
- const config = parseAngularJson(angularJsonPath);
64
- const subapp = config.projects.find(p => p.name === 'subapp');
65
-
66
- expect(subapp.stylePreprocessor).toBe('scss');
67
- expect(subapp.styleExt).toBe('scss');
68
- });
69
-
70
- test('should detect inline style preference', () => {
71
- const config = parseAngularJson(angularJsonPath);
72
- const subapp = config.projects.find(p => p.name === 'subapp');
73
-
74
- expect(subapp.inlineStyle).toBe(false);
75
- });
76
- });
77
-
78
- describe('getProject', () => {
79
- test('should get project by name', () => {
80
- const config = parseAngularJson(angularJsonPath);
81
- const project = getProject(config, 'subapp');
82
-
83
- expect(project).not.toBeNull();
84
- expect(project.name).toBe('subapp');
85
- expect(project.type).toBe('application');
86
- });
87
-
88
- test('should return null for nonexistent project', () => {
89
- const config = parseAngularJson(angularJsonPath);
90
- const project = getProject(config, 'nonexistent');
91
-
92
- expect(project).toBeNull();
93
- });
94
- });
95
-
96
- describe('getDefaultProject', () => {
97
- test('should get default project', () => {
98
- const config = parseAngularJson(angularJsonPath);
99
- const project = getDefaultProject(config);
100
-
101
- expect(project).not.toBeNull();
102
- expect(project.name).toBe('subapp');
103
- });
104
-
105
- test('should return first project if no default specified', () => {
106
- const config = parseAngularJson(angularJsonPath);
107
- // Temporarily remove default
108
- const originalDefault = config.defaultProject;
109
- config.defaultProject = null;
110
-
111
- const project = getDefaultProject(config);
112
-
113
- expect(project).not.toBeNull();
114
- expect(project.name).toBeDefined();
115
-
116
- // Restore
117
- config.defaultProject = originalDefault;
118
- });
119
- });
120
-
121
- describe('detectSourceDirectory', () => {
122
- test('should detect source directory for project', () => {
123
- const config = parseAngularJson(angularJsonPath);
124
- const srcDir = detectSourceDirectory(config, 'subapp');
125
-
126
- expect(srcDir).toBe('apps/subapp/src');
127
- });
128
-
129
- test('should detect source directory for default project', () => {
130
- const config = parseAngularJson(angularJsonPath);
131
- const srcDir = detectSourceDirectory(config);
132
-
133
- expect(srcDir).toBe('apps/subapp/src');
134
- });
135
-
136
- test('should return null if project not found', () => {
137
- const config = parseAngularJson(angularJsonPath);
138
- const srcDir = detectSourceDirectory(config, 'nonexistent');
139
-
140
- expect(srcDir).toBeNull();
141
- });
142
- });
143
-
144
- describe('getGlobalStyleFiles', () => {
145
- test('should get global style files', () => {
146
- const config = parseAngularJson(angularJsonPath);
147
- const styleFiles = getGlobalStyleFiles(config, 'subapp');
148
-
149
- expect(styleFiles.length).toBeGreaterThan(0);
150
- expect(styleFiles[0]).toContain('styles.scss');
151
- });
152
-
153
- test('should return empty array if no styles found', () => {
154
- const config = parseAngularJson(angularJsonPath);
155
- const styleFiles = getGlobalStyleFiles(config, 'shared-lib');
156
-
157
- expect(styleFiles).toEqual([]);
158
- });
159
- });
160
-
161
- describe('enhanceConfigFromAngularJson', () => {
162
- test('should enhance config with Angular settings', () => {
163
- const baseConfig = {
164
- threshold: 2
165
- };
166
-
167
- const enhanced = enhanceConfigFromAngularJson(angularJsonPath, baseConfig, 'subapp');
168
-
169
- expect(enhanced.src).toBe('apps/subapp/src');
170
- expect(enhanced.output).toContain('_variables.scss');
171
- expect(enhanced.angular).toBeDefined();
172
- expect(enhanced.angular.project).toBe('subapp');
173
- expect(enhanced.angular.prefix).toBe('app');
174
- expect(enhanced.angular.stylePreprocessor).toBe('scss');
175
- });
176
-
177
- test('should not override existing config values', () => {
178
- const baseConfig = {
179
- src: './custom/path',
180
- output: './custom/output.scss',
181
- threshold: 3
182
- };
183
-
184
- const enhanced = enhanceConfigFromAngularJson(angularJsonPath, baseConfig, 'subapp');
185
-
186
- expect(enhanced.src).toBe('./custom/path');
187
- expect(enhanced.output).toBe('./custom/output.scss');
188
- expect(enhanced.threshold).toBe(3);
189
- });
190
-
191
- test('should add Angular-specific ignore patterns', () => {
192
- const baseConfig = {};
193
-
194
- const enhanced = enhanceConfigFromAngularJson(angularJsonPath, baseConfig);
195
-
196
- expect(enhanced.ignore).toBeDefined();
197
- expect(enhanced.ignore).toContain('**/node_modules/**');
198
- expect(enhanced.ignore).toContain('**/.angular/**');
199
- expect(enhanced.ignore).toContain('**/dist/**');
200
- });
201
-
202
- test('should return base config if angular.json not found', () => {
203
- const baseConfig = {
204
- src: './src',
205
- threshold: 2
206
- };
207
-
208
- const enhanced = enhanceConfigFromAngularJson('/nonexistent/angular.json', baseConfig);
209
-
210
- expect(enhanced).toEqual(baseConfig);
211
- });
212
- });
213
-
214
- describe('findProjectForPath', () => {
215
- test('should find project for given path', () => {
216
- const config = parseAngularJson(angularJsonPath);
217
- const project = findProjectForPath(config, 'apps/subapp/src/app');
218
-
219
- expect(project).not.toBeNull();
220
- expect(project.name).toBe('subapp');
221
- });
222
-
223
- test('should return null for path outside projects', () => {
224
- const config = parseAngularJson(angularJsonPath);
225
- const project = findProjectForPath(config, 'some/other/path');
226
-
227
- expect(project).toBeNull();
228
- });
229
- });
230
- });
1
+ const {
2
+ parseAngularJson,
3
+ extractProjects,
4
+ getProject,
5
+ getDefaultProject,
6
+ detectSourceDirectory,
7
+ getGlobalStyleFiles,
8
+ enhanceConfigFromAngularJson,
9
+ findProjectForPath,
10
+ } = require('../src/angular-parser');
11
+ const path = require('path');
12
+
13
+ describe('Angular Parser', () => {
14
+ const fixturesPath = path.join(__dirname, 'fixtures');
15
+ const angularJsonPath = path.join(fixturesPath, 'angular.json');
16
+
17
+ describe('parseAngularJson', () => {
18
+ test('should parse angular.json file', () => {
19
+ const config = parseAngularJson(angularJsonPath);
20
+
21
+ expect(config).not.toBeNull();
22
+ expect(config.raw).toBeDefined();
23
+ expect(config.projects).toBeDefined();
24
+ expect(config.defaultProject).toBe('subapp');
25
+ expect(config.version).toBe(1);
26
+ });
27
+
28
+ test('should return null if angular.json not found', () => {
29
+ const config = parseAngularJson('/nonexistent/path/angular.json');
30
+
31
+ expect(config).toBeNull();
32
+ });
33
+
34
+ test('should extract projects', () => {
35
+ const config = parseAngularJson(angularJsonPath);
36
+
37
+ expect(config.projects.length).toBeGreaterThan(0);
38
+ expect(config.projects[0].name).toBeDefined();
39
+ expect(config.projects[0].type).toBeDefined();
40
+ });
41
+ });
42
+
43
+ describe('extractProjects', () => {
44
+ test('should extract all projects from angular.json', () => {
45
+ const config = parseAngularJson(angularJsonPath);
46
+ const projects = config.projects;
47
+
48
+ expect(projects.length).toBe(2);
49
+
50
+ const subapp = projects.find(p => p.name === 'subapp');
51
+ expect(subapp).toBeDefined();
52
+ expect(subapp.type).toBe('application');
53
+ expect(subapp.prefix).toBe('app');
54
+ expect(subapp.stylePreprocessor).toBe('scss');
55
+
56
+ const lib = projects.find(p => p.name === 'shared-lib');
57
+ expect(lib).toBeDefined();
58
+ expect(lib.type).toBe('library');
59
+ expect(lib.prefix).toBe('lib');
60
+ });
61
+
62
+ test('should detect style preprocessor', () => {
63
+ const config = parseAngularJson(angularJsonPath);
64
+ const subapp = config.projects.find(p => p.name === 'subapp');
65
+
66
+ expect(subapp.stylePreprocessor).toBe('scss');
67
+ expect(subapp.styleExt).toBe('scss');
68
+ });
69
+
70
+ test('should detect inline style preference', () => {
71
+ const config = parseAngularJson(angularJsonPath);
72
+ const subapp = config.projects.find(p => p.name === 'subapp');
73
+
74
+ expect(subapp.inlineStyle).toBe(false);
75
+ });
76
+ });
77
+
78
+ describe('getProject', () => {
79
+ test('should get project by name', () => {
80
+ const config = parseAngularJson(angularJsonPath);
81
+ const project = getProject(config, 'subapp');
82
+
83
+ expect(project).not.toBeNull();
84
+ expect(project.name).toBe('subapp');
85
+ expect(project.type).toBe('application');
86
+ });
87
+
88
+ test('should return null for nonexistent project', () => {
89
+ const config = parseAngularJson(angularJsonPath);
90
+ const project = getProject(config, 'nonexistent');
91
+
92
+ expect(project).toBeNull();
93
+ });
94
+ });
95
+
96
+ describe('getDefaultProject', () => {
97
+ test('should get default project', () => {
98
+ const config = parseAngularJson(angularJsonPath);
99
+ const project = getDefaultProject(config);
100
+
101
+ expect(project).not.toBeNull();
102
+ expect(project.name).toBe('subapp');
103
+ });
104
+
105
+ test('should return first project if no default specified', () => {
106
+ const config = parseAngularJson(angularJsonPath);
107
+ // Temporarily remove default
108
+ const originalDefault = config.defaultProject;
109
+ config.defaultProject = null;
110
+
111
+ const project = getDefaultProject(config);
112
+
113
+ expect(project).not.toBeNull();
114
+ expect(project.name).toBeDefined();
115
+
116
+ // Restore
117
+ config.defaultProject = originalDefault;
118
+ });
119
+ });
120
+
121
+ describe('detectSourceDirectory', () => {
122
+ test('should detect source directory for project', () => {
123
+ const config = parseAngularJson(angularJsonPath);
124
+ const srcDir = detectSourceDirectory(config, 'subapp');
125
+
126
+ expect(srcDir).toBe('apps/subapp/src');
127
+ });
128
+
129
+ test('should detect source directory for default project', () => {
130
+ const config = parseAngularJson(angularJsonPath);
131
+ const srcDir = detectSourceDirectory(config);
132
+
133
+ expect(srcDir).toBe('apps/subapp/src');
134
+ });
135
+
136
+ test('should return null if project not found', () => {
137
+ const config = parseAngularJson(angularJsonPath);
138
+ const srcDir = detectSourceDirectory(config, 'nonexistent');
139
+
140
+ expect(srcDir).toBeNull();
141
+ });
142
+ });
143
+
144
+ describe('getGlobalStyleFiles', () => {
145
+ test('should get global style files', () => {
146
+ const config = parseAngularJson(angularJsonPath);
147
+ const styleFiles = getGlobalStyleFiles(config, 'subapp');
148
+
149
+ expect(styleFiles.length).toBeGreaterThan(0);
150
+ expect(styleFiles[0]).toContain('styles.scss');
151
+ });
152
+
153
+ test('should return empty array if no styles found', () => {
154
+ const config = parseAngularJson(angularJsonPath);
155
+ const styleFiles = getGlobalStyleFiles(config, 'shared-lib');
156
+
157
+ expect(styleFiles).toEqual([]);
158
+ });
159
+ });
160
+
161
+ describe('enhanceConfigFromAngularJson', () => {
162
+ test('should enhance config with Angular settings', () => {
163
+ const baseConfig = {
164
+ threshold: 2,
165
+ };
166
+
167
+ const enhanced = enhanceConfigFromAngularJson(angularJsonPath, baseConfig, 'subapp');
168
+
169
+ expect(enhanced.src).toBe('apps/subapp/src');
170
+ expect(enhanced.output).toContain('_variables.scss');
171
+ expect(enhanced.angular).toBeDefined();
172
+ expect(enhanced.angular.project).toBe('subapp');
173
+ expect(enhanced.angular.prefix).toBe('app');
174
+ expect(enhanced.angular.stylePreprocessor).toBe('scss');
175
+ });
176
+
177
+ test('should not override existing config values', () => {
178
+ const baseConfig = {
179
+ src: './custom/path',
180
+ output: './custom/output.scss',
181
+ threshold: 3,
182
+ };
183
+
184
+ const enhanced = enhanceConfigFromAngularJson(angularJsonPath, baseConfig, 'subapp');
185
+
186
+ expect(enhanced.src).toBe('./custom/path');
187
+ expect(enhanced.output).toBe('./custom/output.scss');
188
+ expect(enhanced.threshold).toBe(3);
189
+ });
190
+
191
+ test('should add Angular-specific ignore patterns', () => {
192
+ const baseConfig = {};
193
+
194
+ const enhanced = enhanceConfigFromAngularJson(angularJsonPath, baseConfig);
195
+
196
+ expect(enhanced.ignore).toBeDefined();
197
+ expect(enhanced.ignore).toContain('**/node_modules/**');
198
+ expect(enhanced.ignore).toContain('**/.angular/**');
199
+ expect(enhanced.ignore).toContain('**/dist/**');
200
+ });
201
+
202
+ test('should return base config if angular.json not found', () => {
203
+ const baseConfig = {
204
+ src: './src',
205
+ threshold: 2,
206
+ };
207
+
208
+ const enhanced = enhanceConfigFromAngularJson('/nonexistent/angular.json', baseConfig);
209
+
210
+ expect(enhanced).toEqual(baseConfig);
211
+ });
212
+ });
213
+
214
+ describe('findProjectForPath', () => {
215
+ test('should find project for given path', () => {
216
+ const config = parseAngularJson(angularJsonPath);
217
+ const project = findProjectForPath(config, 'apps/subapp/src/app');
218
+
219
+ expect(project).not.toBeNull();
220
+ expect(project.name).toBe('subapp');
221
+ });
222
+
223
+ test('should return null for path outside projects', () => {
224
+ const config = parseAngularJson(angularJsonPath);
225
+ const project = findProjectForPath(config, 'some/other/path');
226
+
227
+ expect(project).toBeNull();
228
+ });
229
+ });
230
+ });