happy-css-modules 3.2.0 → 5.0.0
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.
- package/LICENSE.txt +23 -0
- package/README.md +307 -2
- package/bin/hcm.js +1 -1
- package/dist/cli.d.ts +0 -4
- package/dist/cli.js +111 -118
- package/dist/cli.js.map +1 -1
- package/dist/emitter/dts.js +7 -8
- package/dist/emitter/dts.js.map +1 -1
- package/dist/emitter/dts.test.js +12 -12
- package/dist/emitter/file-system.js +2 -2
- package/dist/emitter/file-system.js.map +1 -1
- package/dist/emitter/file-system.test.js +1 -1
- package/dist/emitter/file-system.test.js.map +1 -1
- package/dist/emitter/index.js +1 -1
- package/dist/emitter/index.js.map +1 -1
- package/dist/emitter/index.test.js +2 -4
- package/dist/emitter/index.test.js.map +1 -1
- package/dist/emitter/source-map.js +1 -1
- package/dist/emitter/source-map.js.map +1 -1
- package/dist/emitter/source-map.test.js +1 -1
- package/dist/emitter/source-map.test.js.map +1 -1
- package/dist/integration-test/go-to-definition.test.js +403 -105
- package/dist/integration-test/go-to-definition.test.js.map +1 -1
- package/dist/locator/index.js +10 -8
- package/dist/locator/index.js.map +1 -1
- package/dist/locator/index.test.js +304 -171
- package/dist/locator/index.test.js.map +1 -1
- package/dist/locator/postcss.js +2 -3
- package/dist/locator/postcss.js.map +1 -1
- package/dist/locator/postcss.test.js +317 -73
- package/dist/locator/postcss.test.js.map +1 -1
- package/dist/logger.js +7 -6
- package/dist/logger.js.map +1 -1
- package/dist/regression-test/issue-168.test.js +3 -5
- package/dist/regression-test/issue-168.test.js.map +1 -1
- package/dist/resolver/index.d.ts +1 -1
- package/dist/resolver/index.js +3 -3
- package/dist/resolver/index.js.map +1 -1
- package/dist/resolver/node-resolver.js +1 -1
- package/dist/resolver/node-resolver.js.map +1 -1
- package/dist/resolver/relative-resolver.js +1 -1
- package/dist/resolver/relative-resolver.js.map +1 -1
- package/dist/resolver/webpack-resolver.d.ts +1 -1
- package/dist/resolver/webpack-resolver.js +4 -4
- package/dist/resolver/webpack-resolver.js.map +1 -1
- package/dist/runner.js +52 -21
- package/dist/runner.js.map +1 -1
- package/dist/runner.test.js +59 -43
- package/dist/runner.test.js.map +1 -1
- package/dist/test-util/line-column.d.ts +9 -0
- package/dist/test-util/line-column.js +16 -0
- package/dist/test-util/line-column.js.map +1 -0
- package/dist/test-util/line-column.test.d.ts +1 -0
- package/dist/test-util/line-column.test.js +21 -0
- package/dist/test-util/line-column.test.js.map +1 -0
- package/dist/test-util/tsserver.js +11 -12
- package/dist/test-util/tsserver.js.map +1 -1
- package/dist/test-util/util.d.ts +6 -0
- package/dist/test-util/util.js +23 -6
- package/dist/test-util/util.js.map +1 -1
- package/dist/transformer/index.d.ts +0 -1
- package/dist/transformer/index.js +1 -1
- package/dist/transformer/index.js.map +1 -1
- package/dist/transformer/index.test.js +17 -17
- package/dist/transformer/index.test.js.map +1 -1
- package/dist/transformer/less-transformer.js +4 -4
- package/dist/transformer/less-transformer.js.map +1 -1
- package/dist/transformer/less-transformer.test.js +76 -51
- package/dist/transformer/less-transformer.test.js.map +1 -1
- package/dist/transformer/postcss-transformer.test.js +58 -54
- package/dist/transformer/postcss-transformer.test.js.map +1 -1
- package/dist/transformer/scss-transformer.js +11 -30
- package/dist/transformer/scss-transformer.js.map +1 -1
- package/dist/transformer/scss-transformer.test.js +106 -54
- package/dist/transformer/scss-transformer.test.js.map +1 -1
- package/dist/util.js +6 -8
- package/dist/util.js.map +1 -1
- package/dist/util.test.js +2 -2
- package/dist/util.test.js.map +1 -1
- package/package.json +59 -35
- package/src/__snapshots__/runner.test.ts.snap +1 -1
- package/src/cli.ts +119 -117
- package/src/emitter/dts.test.ts +12 -12
- package/src/emitter/dts.ts +27 -28
- package/src/emitter/file-system.test.ts +1 -1
- package/src/emitter/file-system.ts +2 -2
- package/src/emitter/index.test.ts +2 -4
- package/src/emitter/index.ts +1 -1
- package/src/emitter/source-map.test.ts +1 -1
- package/src/emitter/source-map.ts +1 -1
- package/src/integration-test/go-to-definition.test.ts +405 -105
- package/src/locator/index.test.ts +304 -171
- package/src/locator/index.ts +6 -6
- package/src/locator/postcss.test.ts +317 -73
- package/src/locator/postcss.ts +2 -3
- package/src/logger.ts +6 -6
- package/src/regression-test/issue-168.test.ts +3 -5
- package/src/resolver/index.ts +4 -4
- package/src/resolver/node-resolver.ts +1 -1
- package/src/resolver/relative-resolver.ts +1 -1
- package/src/resolver/webpack-resolver.ts +5 -5
- package/src/runner.test.ts +66 -43
- package/src/runner.ts +53 -22
- package/src/test-util/line-column.test.ts +21 -0
- package/src/test-util/line-column.ts +15 -0
- package/src/test-util/tsserver.ts +11 -12
- package/src/test-util/util.ts +24 -6
- package/src/transformer/index.test.ts +17 -17
- package/src/transformer/index.ts +1 -1
- package/src/transformer/less-transformer.test.ts +74 -47
- package/src/transformer/less-transformer.ts +1 -3
- package/src/transformer/postcss-transformer.test.ts +58 -54
- package/src/transformer/scss-transformer.test.ts +108 -54
- package/src/transformer/scss-transformer.ts +13 -30
- package/src/util.test.ts +2 -2
- package/src/util.ts +6 -8
- package/dist/test-util/jest/resolver.cjs +0 -31
- package/dist/test-util/jest/resolver.cjs.map +0 -1
- package/dist/test-util/jest/resolver.d.cts +0 -16
- package/src/test-util/jest/resolver.cjs +0 -31
|
@@ -13,10 +13,10 @@ const locator = new Locator({ transformer: createDefaultTransformer({ cwd }) });
|
|
|
13
13
|
test('processes .scss with scss transformer', async () => {
|
|
14
14
|
createFixtures({
|
|
15
15
|
'/test/1.scss': dedent`
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
.a {
|
|
17
|
+
// scss feature test (nesting)
|
|
18
|
+
.a_1 { dummy: ''; }
|
|
19
|
+
}
|
|
20
20
|
`,
|
|
21
21
|
});
|
|
22
22
|
const result = await locator.load(getFixturePath('/test/1.scss'));
|
|
@@ -26,10 +26,10 @@ test('processes .scss with scss transformer', async () => {
|
|
|
26
26
|
test('processes .less with less transformer', async () => {
|
|
27
27
|
createFixtures({
|
|
28
28
|
'/test/1.less': dedent`
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
.a {
|
|
30
|
+
// less feature test (nesting)
|
|
31
|
+
.a_1 { dummy: ''; }
|
|
32
|
+
}
|
|
33
33
|
`,
|
|
34
34
|
});
|
|
35
35
|
const result = await locator.load(getFixturePath('/test/1.less'));
|
|
@@ -41,8 +41,8 @@ test('processes .css with postcss transformer if postcssrc is found', async () =
|
|
|
41
41
|
const locator1 = new Locator({ transformer: createDefaultTransformer() });
|
|
42
42
|
createFixtures({
|
|
43
43
|
'/test/1.css': dedent`
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
$prefix: foo;
|
|
45
|
+
.$(prefix)_bar {}
|
|
46
46
|
`,
|
|
47
47
|
});
|
|
48
48
|
const result1 = await locator1.load(getFixturePath('/test/1.css'));
|
|
@@ -55,15 +55,15 @@ test('processes .css with postcss transformer if postcssrc is found', async () =
|
|
|
55
55
|
});
|
|
56
56
|
createFixtures({
|
|
57
57
|
[`/${uuid}/postcss.config.js`]: dedent`
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
module.exports = {
|
|
59
|
+
plugins: [
|
|
60
|
+
require('${require.resolve('postcss-simple-vars')}'),
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
63
|
`,
|
|
64
64
|
'/test/1.css': dedent`
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
$prefix: foo;
|
|
66
|
+
.$(prefix)_bar {}
|
|
67
67
|
`,
|
|
68
68
|
});
|
|
69
69
|
const result2 = await locator2.load(getFixturePath('/test/1.css'));
|
package/src/transformer/index.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type TransformerOptions = {
|
|
|
33
33
|
/** The function to transform source code. */
|
|
34
34
|
export type Transformer = (source: string, options: TransformerOptions) => TransformResult | Promise<TransformResult>;
|
|
35
35
|
|
|
36
|
-
//
|
|
36
|
+
// oxlint-disable-next-line no-unused-vars -- TODO: pass `e` to Error's cause option
|
|
37
37
|
export const handleImportError = (packageName: string) => (e: unknown) => {
|
|
38
38
|
throw new Error(`${packageName} import failed. Did you forget to \`npm install -D ${packageName}\`?`);
|
|
39
39
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { jest } from '@jest/globals';
|
|
2
1
|
import dedent from 'dedent';
|
|
3
2
|
import { Locator } from '../locator/index.js';
|
|
4
|
-
import { createFixtures, getFixturePath } from '../test-util/util.js';
|
|
3
|
+
import { createFixtures, getFixturePath, replaceFixtureDir } from '../test-util/util.js';
|
|
5
4
|
import { createLessTransformer } from './less-transformer.js';
|
|
6
5
|
|
|
7
6
|
const locator = new Locator({ transformer: createLessTransformer() });
|
|
8
|
-
const loadSpy =
|
|
7
|
+
const loadSpy = vi.spyOn(locator, 'load');
|
|
9
8
|
|
|
10
9
|
afterEach(() => {
|
|
11
10
|
loadSpy.mockClear();
|
|
@@ -24,60 +23,92 @@ test('handles less features', async () => {
|
|
|
24
23
|
.b_1();
|
|
25
24
|
.b_2();
|
|
26
25
|
}
|
|
27
|
-
|
|
26
|
+
`,
|
|
28
27
|
'/test/2.less': dedent`
|
|
29
28
|
.b_1 { dummy: ''; }
|
|
30
29
|
.b_2() { dummy: ''; }
|
|
31
|
-
|
|
30
|
+
`,
|
|
32
31
|
'/test/3.less': dedent`
|
|
33
32
|
.c { dummy: ''; }
|
|
34
|
-
|
|
33
|
+
`,
|
|
35
34
|
});
|
|
36
35
|
const result = await locator.load(getFixturePath('/test/1.less'));
|
|
37
36
|
|
|
38
37
|
// FIXME: The end position of 'a_2_2' is incorrect.
|
|
39
|
-
expect(result).toMatchInlineSnapshot(`
|
|
38
|
+
expect(replaceFixtureDir(result)).toMatchInlineSnapshot(`
|
|
40
39
|
{
|
|
41
|
-
dependencies: [
|
|
42
|
-
|
|
40
|
+
"dependencies": [
|
|
41
|
+
"<fixtures>/test/2.less",
|
|
42
|
+
],
|
|
43
|
+
"tokens": [
|
|
43
44
|
{
|
|
44
|
-
name: "b_1",
|
|
45
|
-
originalLocation: {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
"name": "b_1",
|
|
46
|
+
"originalLocation": {
|
|
47
|
+
"end": {
|
|
48
|
+
"column": 4,
|
|
49
|
+
"line": 1,
|
|
50
|
+
},
|
|
51
|
+
"filePath": "<fixtures>/test/2.less",
|
|
52
|
+
"start": {
|
|
53
|
+
"column": 1,
|
|
54
|
+
"line": 1,
|
|
55
|
+
},
|
|
49
56
|
},
|
|
50
57
|
},
|
|
51
58
|
{
|
|
52
|
-
name: "a_1",
|
|
53
|
-
originalLocation: {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
"name": "a_1",
|
|
60
|
+
"originalLocation": {
|
|
61
|
+
"end": {
|
|
62
|
+
"column": 4,
|
|
63
|
+
"line": 2,
|
|
64
|
+
},
|
|
65
|
+
"filePath": "<fixtures>/test/1.less",
|
|
66
|
+
"start": {
|
|
67
|
+
"column": 1,
|
|
68
|
+
"line": 2,
|
|
69
|
+
},
|
|
57
70
|
},
|
|
58
71
|
},
|
|
59
72
|
{
|
|
60
|
-
name: "a_2",
|
|
61
|
-
originalLocation: {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
"name": "a_2",
|
|
74
|
+
"originalLocation": {
|
|
75
|
+
"end": {
|
|
76
|
+
"column": 4,
|
|
77
|
+
"line": 3,
|
|
78
|
+
},
|
|
79
|
+
"filePath": "<fixtures>/test/1.less",
|
|
80
|
+
"start": {
|
|
81
|
+
"column": 1,
|
|
82
|
+
"line": 3,
|
|
83
|
+
},
|
|
65
84
|
},
|
|
66
85
|
},
|
|
67
86
|
{
|
|
68
|
-
name: "a_2_1",
|
|
69
|
-
originalLocation: {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
87
|
+
"name": "a_2_1",
|
|
88
|
+
"originalLocation": {
|
|
89
|
+
"end": {
|
|
90
|
+
"column": 8,
|
|
91
|
+
"line": 6,
|
|
92
|
+
},
|
|
93
|
+
"filePath": "<fixtures>/test/1.less",
|
|
94
|
+
"start": {
|
|
95
|
+
"column": 3,
|
|
96
|
+
"line": 6,
|
|
97
|
+
},
|
|
73
98
|
},
|
|
74
99
|
},
|
|
75
100
|
{
|
|
76
|
-
name: "a_2_2",
|
|
77
|
-
originalLocation: {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
101
|
+
"name": "a_2_2",
|
|
102
|
+
"originalLocation": {
|
|
103
|
+
"end": {
|
|
104
|
+
"column": 8,
|
|
105
|
+
"line": 7,
|
|
106
|
+
},
|
|
107
|
+
"filePath": "<fixtures>/test/1.less",
|
|
108
|
+
"start": {
|
|
109
|
+
"column": 3,
|
|
110
|
+
"line": 7,
|
|
111
|
+
},
|
|
81
112
|
},
|
|
82
113
|
},
|
|
83
114
|
],
|
|
@@ -88,13 +119,13 @@ test('handles less features', async () => {
|
|
|
88
119
|
test('tracks dependencies that have been pre-bundled by less compiler', async () => {
|
|
89
120
|
createFixtures({
|
|
90
121
|
'/test/1.less': dedent`
|
|
91
|
-
|
|
92
|
-
|
|
122
|
+
@import './2.less';
|
|
123
|
+
@import './3.less';
|
|
93
124
|
`,
|
|
94
125
|
'/test/2.less': dedent`
|
|
95
126
|
`,
|
|
96
127
|
'/test/3.less': dedent`
|
|
97
|
-
|
|
128
|
+
@import './4.less';
|
|
98
129
|
`,
|
|
99
130
|
'/test/4.less': dedent`
|
|
100
131
|
`,
|
|
@@ -103,13 +134,11 @@ test('tracks dependencies that have been pre-bundled by less compiler', async ()
|
|
|
103
134
|
|
|
104
135
|
// The files imported using @import are pre-bundled by the compiler.
|
|
105
136
|
// Therefore, `Locator#load` is not called to process other files.
|
|
106
|
-
expect(loadSpy).
|
|
137
|
+
expect(loadSpy).toHaveBeenCalledTimes(1);
|
|
107
138
|
expect(loadSpy).toHaveBeenNthCalledWith(1, getFixturePath('/test/1.less'));
|
|
108
139
|
|
|
109
140
|
// The files pre-bundled by the compiler are also included in `result.dependencies`
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/require-array-sort-compare
|
|
111
141
|
expect(result.dependencies.sort()).toStrictEqual(
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/require-array-sort-compare
|
|
113
142
|
['/test/2.less', '/test/3.less', '/test/4.less'].map(getFixturePath).sort(),
|
|
114
143
|
);
|
|
115
144
|
});
|
|
@@ -117,16 +146,14 @@ test('tracks dependencies that have been pre-bundled by less compiler', async ()
|
|
|
117
146
|
test('resolves specifier using resolver', async () => {
|
|
118
147
|
createFixtures({
|
|
119
148
|
'/test/1.less': dedent`
|
|
120
|
-
|
|
121
|
-
|
|
149
|
+
@import 'package-1';
|
|
150
|
+
@import 'package-2';
|
|
122
151
|
`,
|
|
123
152
|
'/node_modules/package-1/index.css': `.a {}`,
|
|
124
153
|
'/node_modules/package-2/index.less': `.a {}`,
|
|
125
154
|
});
|
|
126
155
|
const result = await locator.load(getFixturePath('/test/1.less'));
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/require-array-sort-compare
|
|
128
156
|
expect(result.dependencies.sort()).toStrictEqual(
|
|
129
|
-
// eslint-disable-next-line @typescript-eslint/require-array-sort-compare
|
|
130
157
|
[getFixturePath('/node_modules/package-1/index.css'), getFixturePath('/node_modules/package-2/index.less')].sort(),
|
|
131
158
|
);
|
|
132
159
|
});
|
|
@@ -134,9 +161,9 @@ test('resolves specifier using resolver', async () => {
|
|
|
134
161
|
test('ignores http(s) protocol file', async () => {
|
|
135
162
|
createFixtures({
|
|
136
163
|
'/test/1.less': dedent`
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
164
|
+
@import 'http://example.com/path/http.css';
|
|
165
|
+
@import 'https://example.com/path/https.css';
|
|
166
|
+
@import 'https://example.com/path/less.less';
|
|
140
167
|
`,
|
|
141
168
|
});
|
|
142
169
|
const result = await locator.load(getFixturePath('/test/1.less'));
|
|
@@ -2,7 +2,6 @@ import type { Transformer } from '../index.js';
|
|
|
2
2
|
import type { TransformerOptions } from './index.js';
|
|
3
3
|
import { handleImportError } from './index.js';
|
|
4
4
|
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
6
5
|
function createLessPluginResolver(Less: typeof import('less'), options: TransformerOptions): Less.Plugin {
|
|
7
6
|
class ResolverFileManager extends Less.FileManager {
|
|
8
7
|
options: TransformerOptions;
|
|
@@ -32,7 +31,7 @@ function createLessPluginResolver(Less: typeof import('less'), options: Transfor
|
|
|
32
31
|
constructor(options: TransformerOptions) {
|
|
33
32
|
this.options = options;
|
|
34
33
|
}
|
|
35
|
-
public install(
|
|
34
|
+
public install(_less: LessStatic, pluginManager: Less.PluginManager): void {
|
|
36
35
|
pluginManager.addFileManager(new ResolverFileManager(this.options));
|
|
37
36
|
}
|
|
38
37
|
public minVersion: [number, number, number] = [2, 1, 1];
|
|
@@ -44,7 +43,6 @@ function createLessPluginResolver(Less: typeof import('less'), options: Transfor
|
|
|
44
43
|
export const createLessTransformer: () => Transformer = () => {
|
|
45
44
|
let less: typeof import('less');
|
|
46
45
|
return async (source, options) => {
|
|
47
|
-
// eslint-disable-next-line require-atomic-updates
|
|
48
46
|
less ??= (await import('less').catch(handleImportError('less'))).default;
|
|
49
47
|
const result = await less.render(source, {
|
|
50
48
|
filename: options.from,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
|
-
import { jest } from '@jest/globals';
|
|
4
3
|
import dedent from 'dedent';
|
|
5
4
|
import { Locator } from '../locator/index.js';
|
|
6
|
-
import { createFixtures, getFixturePath } from '../test-util/util.js';
|
|
5
|
+
import { createFixtures, getFixturePath, replaceFixtureDir } from '../test-util/util.js';
|
|
7
6
|
import { createPostcssTransformer } from './postcss-transformer.js';
|
|
8
7
|
|
|
9
8
|
const cwd = getFixturePath('/');
|
|
@@ -22,29 +21,35 @@ test('handles postcss features', async () => {
|
|
|
22
21
|
});
|
|
23
22
|
createFixtures({
|
|
24
23
|
[`/${uuid}/postcss.config.js`]: dedent`
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
module.exports = {
|
|
25
|
+
plugins: [
|
|
26
|
+
require('${require.resolve('postcss-simple-vars')}'),
|
|
27
|
+
],
|
|
28
|
+
};
|
|
30
29
|
`,
|
|
31
30
|
'/test/1.css': dedent`
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
$prefix: foo;
|
|
32
|
+
.$(prefix)_bar {}
|
|
34
33
|
`,
|
|
35
34
|
});
|
|
36
35
|
const result = await locator.load(getFixturePath('/test/1.css'));
|
|
37
36
|
|
|
38
|
-
expect(result).toMatchInlineSnapshot(`
|
|
37
|
+
expect(replaceFixtureDir(result)).toMatchInlineSnapshot(`
|
|
39
38
|
{
|
|
40
|
-
dependencies: [],
|
|
41
|
-
tokens: [
|
|
39
|
+
"dependencies": [],
|
|
40
|
+
"tokens": [
|
|
42
41
|
{
|
|
43
|
-
name: "foo_bar",
|
|
44
|
-
originalLocation: {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
"name": "foo_bar",
|
|
43
|
+
"originalLocation": {
|
|
44
|
+
"end": {
|
|
45
|
+
"column": 8,
|
|
46
|
+
"line": 2,
|
|
47
|
+
},
|
|
48
|
+
"filePath": "<fixtures>/test/1.css",
|
|
49
|
+
"start": {
|
|
50
|
+
"column": 1,
|
|
51
|
+
"line": 2,
|
|
52
|
+
},
|
|
48
53
|
},
|
|
49
54
|
},
|
|
50
55
|
],
|
|
@@ -60,18 +65,18 @@ test('tracks dependencies that have been pre-bundled by postcss compiler', async
|
|
|
60
65
|
postcssConfig: `${uuid}/postcss.config.js`,
|
|
61
66
|
}),
|
|
62
67
|
});
|
|
63
|
-
const loadSpy =
|
|
68
|
+
const loadSpy = vi.spyOn(locator, 'load');
|
|
64
69
|
createFixtures({
|
|
65
70
|
[`/${uuid}/postcss.config.js`]: dedent`
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
module.exports = {
|
|
72
|
+
plugins: [
|
|
73
|
+
require('${require.resolve('postcss-import')}'),
|
|
74
|
+
],
|
|
75
|
+
};
|
|
71
76
|
`,
|
|
72
77
|
'/test/1.css': dedent`
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
@import './2.css';
|
|
79
|
+
@import './3.css';
|
|
75
80
|
`,
|
|
76
81
|
'/test/2.css': ``,
|
|
77
82
|
'/test/3.css': `@import './4.css'`,
|
|
@@ -81,7 +86,7 @@ test('tracks dependencies that have been pre-bundled by postcss compiler', async
|
|
|
81
86
|
|
|
82
87
|
// The files imported using @import are pre-bundled by the compiler.
|
|
83
88
|
// Therefore, `Locator#load` is not called to process other files.
|
|
84
|
-
expect(loadSpy).
|
|
89
|
+
expect(loadSpy).toHaveBeenCalledTimes(1);
|
|
85
90
|
expect(loadSpy).toHaveBeenNthCalledWith(1, getFixturePath('/test/1.css'));
|
|
86
91
|
|
|
87
92
|
// The files pre-bundled by the compiler are also included in `result.dependencies`
|
|
@@ -98,16 +103,16 @@ test('resolves specifier using resolver', async () => {
|
|
|
98
103
|
});
|
|
99
104
|
createFixtures({
|
|
100
105
|
[`/${uuid}/postcss.config.js`]: dedent`
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
module.exports = {
|
|
107
|
+
plugins: [
|
|
108
|
+
// When using postcss-import, the resolver of happy-css-modules is ignored.
|
|
109
|
+
// Therefore, we test here without postcss-import.
|
|
110
|
+
// require('${require.resolve('postcss-import')}'),
|
|
111
|
+
],
|
|
112
|
+
};
|
|
108
113
|
`,
|
|
109
114
|
'/test/1.css': dedent`
|
|
110
|
-
|
|
115
|
+
@import 'package';
|
|
111
116
|
`,
|
|
112
117
|
'/node_modules/package/index.css': `.a {}`,
|
|
113
118
|
});
|
|
@@ -125,17 +130,17 @@ test('ignores http(s) protocol file', async () => {
|
|
|
125
130
|
});
|
|
126
131
|
createFixtures({
|
|
127
132
|
[`/${uuid}/postcss.config.js`]: dedent`
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
module.exports = {
|
|
134
|
+
plugins: [
|
|
135
|
+
// When using postcss-import, the resolver of happy-css-modules is ignored.
|
|
136
|
+
// Therefore, we test here without postcss-import.
|
|
137
|
+
// require('${require.resolve('postcss-import')}'),
|
|
138
|
+
],
|
|
139
|
+
};
|
|
135
140
|
`,
|
|
136
141
|
'/test/1.css': dedent`
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
@import 'http://example.com/path/http.css';
|
|
143
|
+
@import 'https://example.com/path/https.css';
|
|
139
144
|
`,
|
|
140
145
|
});
|
|
141
146
|
const result = await locator.load(getFixturePath('/test/1.css'));
|
|
@@ -150,16 +155,15 @@ test('returns false if postcssrc is not found', async () => {
|
|
|
150
155
|
});
|
|
151
156
|
createFixtures({
|
|
152
157
|
'/test/1.css': dedent`
|
|
153
|
-
|
|
154
|
-
|
|
158
|
+
@import 'http://example.com/path/http.css';
|
|
159
|
+
@import 'https://example.com/path/https.css';
|
|
155
160
|
`,
|
|
156
161
|
});
|
|
157
162
|
expect(
|
|
158
163
|
await transformer('', {
|
|
159
164
|
from: getFixturePath('/test/1.css'),
|
|
160
165
|
isIgnoredSpecifier: () => false,
|
|
161
|
-
|
|
162
|
-
resolver: jest.fn() as any,
|
|
166
|
+
resolver: vi.fn(),
|
|
163
167
|
}),
|
|
164
168
|
).toBe(false);
|
|
165
169
|
});
|
|
@@ -174,15 +178,15 @@ test('searches config from cwd if postcssConfig option is missing', async () =>
|
|
|
174
178
|
});
|
|
175
179
|
createFixtures({
|
|
176
180
|
[`/${uuid}/postcss.config.js`]: dedent`
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
181
|
+
module.exports = {
|
|
182
|
+
plugins: [
|
|
183
|
+
require('${require.resolve('postcss-simple-vars')}'),
|
|
184
|
+
],
|
|
185
|
+
};
|
|
182
186
|
`,
|
|
183
187
|
'/test/1.css': dedent`
|
|
184
|
-
|
|
185
|
-
|
|
188
|
+
$prefix: foo;
|
|
189
|
+
.$(prefix)_bar {}
|
|
186
190
|
`,
|
|
187
191
|
});
|
|
188
192
|
const result = await locator.load(getFixturePath('/test/1.css'));
|