happy-css-modules 4.0.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 +3 -4
- 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 +1 -2
- 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 +303 -169
- 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 +2 -3
- 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 +50 -18
- package/dist/runner.js.map +1 -1
- package/dist/runner.test.js +47 -32
- 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 +22 -5
- package/dist/test-util/util.js.map +1 -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 +75 -49
- package/dist/transformer/less-transformer.test.js.map +1 -1
- package/dist/transformer/postcss-transformer.test.js +56 -50
- package/dist/transformer/postcss-transformer.test.js.map +1 -1
- package/dist/transformer/scss-transformer.js +0 -1
- package/dist/transformer/scss-transformer.js.map +1 -1
- package/dist/transformer/scss-transformer.test.js +105 -52
- 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 +58 -34
- package/src/cli.ts +119 -117
- package/src/emitter/dts.test.ts +12 -12
- package/src/emitter/dts.ts +25 -26
- package/src/emitter/file-system.test.ts +1 -1
- package/src/emitter/file-system.ts +2 -2
- package/src/emitter/index.test.ts +1 -2
- 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 +303 -169
- 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 +2 -3
- 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 +54 -32
- package/src/runner.ts +51 -19
- 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 +23 -5
- package/src/transformer/index.test.ts +17 -17
- package/src/transformer/index.ts +1 -1
- package/src/transformer/less-transformer.test.ts +73 -45
- package/src/transformer/less-transformer.ts +1 -3
- package/src/transformer/postcss-transformer.test.ts +56 -50
- package/src/transformer/scss-transformer.test.ts +107 -52
- package/src/transformer/scss-transformer.ts +0 -1
- package/src/util.test.ts +2 -2
- package/src/util.ts +6 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import dedent from 'dedent';
|
|
2
2
|
import { Locator } from '../locator/index.js';
|
|
3
|
-
import { createFixtures, getFixturePath } from '../test-util/util.js';
|
|
3
|
+
import { createFixtures, getFixturePath, replaceFixtureDir } from '../test-util/util.js';
|
|
4
4
|
import { createLessTransformer } from './less-transformer.js';
|
|
5
5
|
|
|
6
6
|
const locator = new Locator({ transformer: createLessTransformer() });
|
|
@@ -23,60 +23,92 @@ test('handles less features', async () => {
|
|
|
23
23
|
.b_1();
|
|
24
24
|
.b_2();
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
`,
|
|
27
27
|
'/test/2.less': dedent`
|
|
28
28
|
.b_1 { dummy: ''; }
|
|
29
29
|
.b_2() { dummy: ''; }
|
|
30
|
-
|
|
30
|
+
`,
|
|
31
31
|
'/test/3.less': dedent`
|
|
32
32
|
.c { dummy: ''; }
|
|
33
|
-
|
|
33
|
+
`,
|
|
34
34
|
});
|
|
35
35
|
const result = await locator.load(getFixturePath('/test/1.less'));
|
|
36
36
|
|
|
37
37
|
// FIXME: The end position of 'a_2_2' is incorrect.
|
|
38
|
-
expect(result).toMatchInlineSnapshot(`
|
|
38
|
+
expect(replaceFixtureDir(result)).toMatchInlineSnapshot(`
|
|
39
39
|
{
|
|
40
|
-
dependencies: [
|
|
41
|
-
|
|
40
|
+
"dependencies": [
|
|
41
|
+
"<fixtures>/test/2.less",
|
|
42
|
+
],
|
|
43
|
+
"tokens": [
|
|
42
44
|
{
|
|
43
|
-
name: "b_1",
|
|
44
|
-
originalLocation: {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
},
|
|
48
56
|
},
|
|
49
57
|
},
|
|
50
58
|
{
|
|
51
|
-
name: "a_1",
|
|
52
|
-
originalLocation: {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
},
|
|
56
70
|
},
|
|
57
71
|
},
|
|
58
72
|
{
|
|
59
|
-
name: "a_2",
|
|
60
|
-
originalLocation: {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
+
},
|
|
64
84
|
},
|
|
65
85
|
},
|
|
66
86
|
{
|
|
67
|
-
name: "a_2_1",
|
|
68
|
-
originalLocation: {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
},
|
|
72
98
|
},
|
|
73
99
|
},
|
|
74
100
|
{
|
|
75
|
-
name: "a_2_2",
|
|
76
|
-
originalLocation: {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
+
},
|
|
80
112
|
},
|
|
81
113
|
},
|
|
82
114
|
],
|
|
@@ -87,13 +119,13 @@ test('handles less features', async () => {
|
|
|
87
119
|
test('tracks dependencies that have been pre-bundled by less compiler', async () => {
|
|
88
120
|
createFixtures({
|
|
89
121
|
'/test/1.less': dedent`
|
|
90
|
-
|
|
91
|
-
|
|
122
|
+
@import './2.less';
|
|
123
|
+
@import './3.less';
|
|
92
124
|
`,
|
|
93
125
|
'/test/2.less': dedent`
|
|
94
126
|
`,
|
|
95
127
|
'/test/3.less': dedent`
|
|
96
|
-
|
|
128
|
+
@import './4.less';
|
|
97
129
|
`,
|
|
98
130
|
'/test/4.less': dedent`
|
|
99
131
|
`,
|
|
@@ -102,13 +134,11 @@ test('tracks dependencies that have been pre-bundled by less compiler', async ()
|
|
|
102
134
|
|
|
103
135
|
// The files imported using @import are pre-bundled by the compiler.
|
|
104
136
|
// Therefore, `Locator#load` is not called to process other files.
|
|
105
|
-
expect(loadSpy).
|
|
137
|
+
expect(loadSpy).toHaveBeenCalledTimes(1);
|
|
106
138
|
expect(loadSpy).toHaveBeenNthCalledWith(1, getFixturePath('/test/1.less'));
|
|
107
139
|
|
|
108
140
|
// The files pre-bundled by the compiler are also included in `result.dependencies`
|
|
109
|
-
// eslint-disable-next-line @typescript-eslint/require-array-sort-compare
|
|
110
141
|
expect(result.dependencies.sort()).toStrictEqual(
|
|
111
|
-
// eslint-disable-next-line @typescript-eslint/require-array-sort-compare
|
|
112
142
|
['/test/2.less', '/test/3.less', '/test/4.less'].map(getFixturePath).sort(),
|
|
113
143
|
);
|
|
114
144
|
});
|
|
@@ -116,16 +146,14 @@ test('tracks dependencies that have been pre-bundled by less compiler', async ()
|
|
|
116
146
|
test('resolves specifier using resolver', async () => {
|
|
117
147
|
createFixtures({
|
|
118
148
|
'/test/1.less': dedent`
|
|
119
|
-
|
|
120
|
-
|
|
149
|
+
@import 'package-1';
|
|
150
|
+
@import 'package-2';
|
|
121
151
|
`,
|
|
122
152
|
'/node_modules/package-1/index.css': `.a {}`,
|
|
123
153
|
'/node_modules/package-2/index.less': `.a {}`,
|
|
124
154
|
});
|
|
125
155
|
const result = await locator.load(getFixturePath('/test/1.less'));
|
|
126
|
-
// eslint-disable-next-line @typescript-eslint/require-array-sort-compare
|
|
127
156
|
expect(result.dependencies.sort()).toStrictEqual(
|
|
128
|
-
// eslint-disable-next-line @typescript-eslint/require-array-sort-compare
|
|
129
157
|
[getFixturePath('/node_modules/package-1/index.css'), getFixturePath('/node_modules/package-2/index.less')].sort(),
|
|
130
158
|
);
|
|
131
159
|
});
|
|
@@ -133,9 +161,9 @@ test('resolves specifier using resolver', async () => {
|
|
|
133
161
|
test('ignores http(s) protocol file', async () => {
|
|
134
162
|
createFixtures({
|
|
135
163
|
'/test/1.less': dedent`
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
164
|
+
@import 'http://example.com/path/http.css';
|
|
165
|
+
@import 'https://example.com/path/https.css';
|
|
166
|
+
@import 'https://example.com/path/less.less';
|
|
139
167
|
`,
|
|
140
168
|
});
|
|
141
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,
|
|
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import dedent from 'dedent';
|
|
4
4
|
import { Locator } from '../locator/index.js';
|
|
5
|
-
import { createFixtures, getFixturePath } from '../test-util/util.js';
|
|
5
|
+
import { createFixtures, getFixturePath, replaceFixtureDir } from '../test-util/util.js';
|
|
6
6
|
import { createPostcssTransformer } from './postcss-transformer.js';
|
|
7
7
|
|
|
8
8
|
const cwd = getFixturePath('/');
|
|
@@ -21,29 +21,35 @@ test('handles postcss features', async () => {
|
|
|
21
21
|
});
|
|
22
22
|
createFixtures({
|
|
23
23
|
[`/${uuid}/postcss.config.js`]: dedent`
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
module.exports = {
|
|
25
|
+
plugins: [
|
|
26
|
+
require('${require.resolve('postcss-simple-vars')}'),
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
29
|
`,
|
|
30
30
|
'/test/1.css': dedent`
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
$prefix: foo;
|
|
32
|
+
.$(prefix)_bar {}
|
|
33
33
|
`,
|
|
34
34
|
});
|
|
35
35
|
const result = await locator.load(getFixturePath('/test/1.css'));
|
|
36
36
|
|
|
37
|
-
expect(result).toMatchInlineSnapshot(`
|
|
37
|
+
expect(replaceFixtureDir(result)).toMatchInlineSnapshot(`
|
|
38
38
|
{
|
|
39
|
-
dependencies: [],
|
|
40
|
-
tokens: [
|
|
39
|
+
"dependencies": [],
|
|
40
|
+
"tokens": [
|
|
41
41
|
{
|
|
42
|
-
name: "foo_bar",
|
|
43
|
-
originalLocation: {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
},
|
|
47
53
|
},
|
|
48
54
|
},
|
|
49
55
|
],
|
|
@@ -62,15 +68,15 @@ test('tracks dependencies that have been pre-bundled by postcss compiler', async
|
|
|
62
68
|
const loadSpy = vi.spyOn(locator, 'load');
|
|
63
69
|
createFixtures({
|
|
64
70
|
[`/${uuid}/postcss.config.js`]: dedent`
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
module.exports = {
|
|
72
|
+
plugins: [
|
|
73
|
+
require('${require.resolve('postcss-import')}'),
|
|
74
|
+
],
|
|
75
|
+
};
|
|
70
76
|
`,
|
|
71
77
|
'/test/1.css': dedent`
|
|
72
|
-
|
|
73
|
-
|
|
78
|
+
@import './2.css';
|
|
79
|
+
@import './3.css';
|
|
74
80
|
`,
|
|
75
81
|
'/test/2.css': ``,
|
|
76
82
|
'/test/3.css': `@import './4.css'`,
|
|
@@ -80,7 +86,7 @@ test('tracks dependencies that have been pre-bundled by postcss compiler', async
|
|
|
80
86
|
|
|
81
87
|
// The files imported using @import are pre-bundled by the compiler.
|
|
82
88
|
// Therefore, `Locator#load` is not called to process other files.
|
|
83
|
-
expect(loadSpy).
|
|
89
|
+
expect(loadSpy).toHaveBeenCalledTimes(1);
|
|
84
90
|
expect(loadSpy).toHaveBeenNthCalledWith(1, getFixturePath('/test/1.css'));
|
|
85
91
|
|
|
86
92
|
// The files pre-bundled by the compiler are also included in `result.dependencies`
|
|
@@ -97,16 +103,16 @@ test('resolves specifier using resolver', async () => {
|
|
|
97
103
|
});
|
|
98
104
|
createFixtures({
|
|
99
105
|
[`/${uuid}/postcss.config.js`]: dedent`
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
+
};
|
|
107
113
|
`,
|
|
108
114
|
'/test/1.css': dedent`
|
|
109
|
-
|
|
115
|
+
@import 'package';
|
|
110
116
|
`,
|
|
111
117
|
'/node_modules/package/index.css': `.a {}`,
|
|
112
118
|
});
|
|
@@ -124,17 +130,17 @@ test('ignores http(s) protocol file', async () => {
|
|
|
124
130
|
});
|
|
125
131
|
createFixtures({
|
|
126
132
|
[`/${uuid}/postcss.config.js`]: dedent`
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
+
};
|
|
134
140
|
`,
|
|
135
141
|
'/test/1.css': dedent`
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
@import 'http://example.com/path/http.css';
|
|
143
|
+
@import 'https://example.com/path/https.css';
|
|
138
144
|
`,
|
|
139
145
|
});
|
|
140
146
|
const result = await locator.load(getFixturePath('/test/1.css'));
|
|
@@ -149,8 +155,8 @@ test('returns false if postcssrc is not found', async () => {
|
|
|
149
155
|
});
|
|
150
156
|
createFixtures({
|
|
151
157
|
'/test/1.css': dedent`
|
|
152
|
-
|
|
153
|
-
|
|
158
|
+
@import 'http://example.com/path/http.css';
|
|
159
|
+
@import 'https://example.com/path/https.css';
|
|
154
160
|
`,
|
|
155
161
|
});
|
|
156
162
|
expect(
|
|
@@ -172,15 +178,15 @@ test('searches config from cwd if postcssConfig option is missing', async () =>
|
|
|
172
178
|
});
|
|
173
179
|
createFixtures({
|
|
174
180
|
[`/${uuid}/postcss.config.js`]: dedent`
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
181
|
+
module.exports = {
|
|
182
|
+
plugins: [
|
|
183
|
+
require('${require.resolve('postcss-simple-vars')}'),
|
|
184
|
+
],
|
|
185
|
+
};
|
|
180
186
|
`,
|
|
181
187
|
'/test/1.css': dedent`
|
|
182
|
-
|
|
183
|
-
|
|
188
|
+
$prefix: foo;
|
|
189
|
+
.$(prefix)_bar {}
|
|
184
190
|
`,
|
|
185
191
|
});
|
|
186
192
|
const result = await locator.load(getFixturePath('/test/1.css'));
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import dedent from 'dedent';
|
|
2
2
|
import { Locator } from '../locator/index.js';
|
|
3
|
-
import { createFixtures, getFixturePath } from '../test-util/util.js';
|
|
3
|
+
import { createFixtures, getFixturePath, replaceFixtureDir } from '../test-util/util.js';
|
|
4
4
|
import { createScssTransformer } from './scss-transformer.js';
|
|
5
5
|
|
|
6
|
+
vi.mock('sass', async (importOriginal) => {
|
|
7
|
+
const sass = await importOriginal<typeof import('sass')>();
|
|
8
|
+
return {
|
|
9
|
+
...sass,
|
|
10
|
+
// Suppress the warning: `Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.`
|
|
11
|
+
compileStringAsync: async (source: string, options?: Parameters<typeof sass.compileStringAsync>[1]) =>
|
|
12
|
+
sass.compileStringAsync(source, { silenceDeprecations: ['import'], ...options }),
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
|
|
6
16
|
const locator = new Locator({ transformer: createScssTransformer() });
|
|
7
17
|
const loadSpy = vi.spyOn(locator, 'load');
|
|
8
18
|
|
|
@@ -22,17 +32,17 @@ test('handles sass features', async () => {
|
|
|
22
32
|
.a_2_1 { dummy: ''; }
|
|
23
33
|
&_2 { dummy: ''; }
|
|
24
34
|
}
|
|
25
|
-
|
|
35
|
+
`,
|
|
26
36
|
'/test/2.scss': dedent`
|
|
27
37
|
.b_1 { dummy: ''; }
|
|
28
38
|
@mixin b_2 { dummy: ''; }
|
|
29
|
-
|
|
39
|
+
`,
|
|
30
40
|
'/test/3.scss': dedent`
|
|
31
41
|
.c { dummy: ''; }
|
|
32
|
-
|
|
42
|
+
`,
|
|
33
43
|
'/test/4.scss': dedent`
|
|
34
44
|
.d { dummy: ''; }
|
|
35
|
-
|
|
45
|
+
`,
|
|
36
46
|
});
|
|
37
47
|
const result = await locator.load(getFixturePath('/test/1.scss'));
|
|
38
48
|
|
|
@@ -41,64 +51,109 @@ test('handles sass features', async () => {
|
|
|
41
51
|
// FIXME: The sass compiler or Loader implementation needs to be fixed.
|
|
42
52
|
|
|
43
53
|
// FIXME: The end position of 'a_2_2' is incorrect.
|
|
44
|
-
expect(result).toMatchInlineSnapshot(`
|
|
54
|
+
expect(replaceFixtureDir(result)).toMatchInlineSnapshot(`
|
|
45
55
|
{
|
|
46
|
-
dependencies: [
|
|
47
|
-
|
|
56
|
+
"dependencies": [
|
|
57
|
+
"<fixtures>/test/2.scss",
|
|
58
|
+
"<fixtures>/test/3.scss",
|
|
59
|
+
],
|
|
60
|
+
"tokens": [
|
|
48
61
|
{
|
|
49
|
-
name: "b_1",
|
|
50
|
-
originalLocation: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
"name": "b_1",
|
|
63
|
+
"originalLocation": {
|
|
64
|
+
"end": {
|
|
65
|
+
"column": 4,
|
|
66
|
+
"line": 1,
|
|
67
|
+
},
|
|
68
|
+
"filePath": "<fixtures>/test/2.scss",
|
|
69
|
+
"start": {
|
|
70
|
+
"column": 1,
|
|
71
|
+
"line": 1,
|
|
72
|
+
},
|
|
54
73
|
},
|
|
55
74
|
},
|
|
56
75
|
{
|
|
57
|
-
name: "c",
|
|
58
|
-
originalLocation: {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
"name": "c",
|
|
77
|
+
"originalLocation": {
|
|
78
|
+
"end": {
|
|
79
|
+
"column": 2,
|
|
80
|
+
"line": 1,
|
|
81
|
+
},
|
|
82
|
+
"filePath": "<fixtures>/test/3.scss",
|
|
83
|
+
"start": {
|
|
84
|
+
"column": 1,
|
|
85
|
+
"line": 1,
|
|
86
|
+
},
|
|
62
87
|
},
|
|
63
88
|
},
|
|
64
89
|
{
|
|
65
|
-
name: "a_1",
|
|
66
|
-
originalLocation: {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
90
|
+
"name": "a_1",
|
|
91
|
+
"originalLocation": {
|
|
92
|
+
"end": {
|
|
93
|
+
"column": 4,
|
|
94
|
+
"line": 3,
|
|
95
|
+
},
|
|
96
|
+
"filePath": "<fixtures>/test/1.scss",
|
|
97
|
+
"start": {
|
|
98
|
+
"column": 1,
|
|
99
|
+
"line": 3,
|
|
100
|
+
},
|
|
70
101
|
},
|
|
71
102
|
},
|
|
72
103
|
{
|
|
73
|
-
name: "a_2",
|
|
74
|
-
originalLocation: {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
104
|
+
"name": "a_2",
|
|
105
|
+
"originalLocation": {
|
|
106
|
+
"end": {
|
|
107
|
+
"column": 4,
|
|
108
|
+
"line": 4,
|
|
109
|
+
},
|
|
110
|
+
"filePath": "<fixtures>/test/1.scss",
|
|
111
|
+
"start": {
|
|
112
|
+
"column": 1,
|
|
113
|
+
"line": 4,
|
|
114
|
+
},
|
|
78
115
|
},
|
|
79
116
|
},
|
|
80
117
|
{
|
|
81
|
-
name: "a_2",
|
|
82
|
-
originalLocation: {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
118
|
+
"name": "a_2",
|
|
119
|
+
"originalLocation": {
|
|
120
|
+
"end": {
|
|
121
|
+
"column": 6,
|
|
122
|
+
"line": 7,
|
|
123
|
+
},
|
|
124
|
+
"filePath": "<fixtures>/test/1.scss",
|
|
125
|
+
"start": {
|
|
126
|
+
"column": 3,
|
|
127
|
+
"line": 7,
|
|
128
|
+
},
|
|
86
129
|
},
|
|
87
130
|
},
|
|
88
131
|
{
|
|
89
|
-
name: "a_2_1",
|
|
90
|
-
originalLocation: {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
132
|
+
"name": "a_2_1",
|
|
133
|
+
"originalLocation": {
|
|
134
|
+
"end": {
|
|
135
|
+
"column": 8,
|
|
136
|
+
"line": 7,
|
|
137
|
+
},
|
|
138
|
+
"filePath": "<fixtures>/test/1.scss",
|
|
139
|
+
"start": {
|
|
140
|
+
"column": 3,
|
|
141
|
+
"line": 7,
|
|
142
|
+
},
|
|
94
143
|
},
|
|
95
144
|
},
|
|
96
145
|
{
|
|
97
|
-
name: "a_2_2",
|
|
98
|
-
originalLocation: {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
146
|
+
"name": "a_2_2",
|
|
147
|
+
"originalLocation": {
|
|
148
|
+
"end": {
|
|
149
|
+
"column": 8,
|
|
150
|
+
"line": 8,
|
|
151
|
+
},
|
|
152
|
+
"filePath": "<fixtures>/test/1.scss",
|
|
153
|
+
"start": {
|
|
154
|
+
"column": 3,
|
|
155
|
+
"line": 8,
|
|
156
|
+
},
|
|
102
157
|
},
|
|
103
158
|
},
|
|
104
159
|
],
|
|
@@ -109,13 +164,13 @@ test('handles sass features', async () => {
|
|
|
109
164
|
test('tracks dependencies that have been pre-bundled by sass compiler', async () => {
|
|
110
165
|
createFixtures({
|
|
111
166
|
'/test/1.scss': dedent`
|
|
112
|
-
|
|
113
|
-
|
|
167
|
+
@import './2.scss';
|
|
168
|
+
@import './3.scss';
|
|
114
169
|
`,
|
|
115
170
|
'/test/2.scss': dedent`
|
|
116
171
|
`,
|
|
117
172
|
'/test/3.scss': dedent`
|
|
118
|
-
|
|
173
|
+
@import './4.scss';
|
|
119
174
|
`,
|
|
120
175
|
'/test/4.scss': dedent`
|
|
121
176
|
`,
|
|
@@ -124,7 +179,7 @@ test('tracks dependencies that have been pre-bundled by sass compiler', async ()
|
|
|
124
179
|
|
|
125
180
|
// The files imported using @import are pre-bundled by the compiler.
|
|
126
181
|
// Therefore, `Locator#load` is not called to process other files.
|
|
127
|
-
expect(loadSpy).
|
|
182
|
+
expect(loadSpy).toHaveBeenCalledTimes(1);
|
|
128
183
|
expect(loadSpy).toHaveBeenNthCalledWith(1, getFixturePath('/test/1.scss'));
|
|
129
184
|
|
|
130
185
|
// The files pre-bundled by the compiler are also included in `result.dependencies`
|
|
@@ -134,8 +189,8 @@ test('tracks dependencies that have been pre-bundled by sass compiler', async ()
|
|
|
134
189
|
test('resolves specifier using resolver', async () => {
|
|
135
190
|
createFixtures({
|
|
136
191
|
'/test/1.scss': dedent`
|
|
137
|
-
|
|
138
|
-
|
|
192
|
+
@import 'package-1';
|
|
193
|
+
@import 'package-2';
|
|
139
194
|
`,
|
|
140
195
|
'/node_modules/package-1/index.css': `.a {}`,
|
|
141
196
|
'/node_modules/package-2/index.scss': `.a {}`,
|
|
@@ -149,9 +204,9 @@ test('resolves specifier using resolver', async () => {
|
|
|
149
204
|
test('ignores http(s) protocol file', async () => {
|
|
150
205
|
createFixtures({
|
|
151
206
|
'/test/1.scss': dedent`
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
207
|
+
@import 'http://example.com/path/http.css';
|
|
208
|
+
@import 'https://example.com/path/https.css';
|
|
209
|
+
@import 'https://example.com/path/scss.scss';
|
|
155
210
|
`,
|
|
156
211
|
});
|
|
157
212
|
const result = await locator.load(getFixturePath('/test/1.scss'));
|
|
@@ -14,7 +14,6 @@ const createFileImporter: (resolver: StrictlyResolver) => FileImporter<'async'>
|
|
|
14
14
|
export const createScssTransformer: () => Transformer = () => {
|
|
15
15
|
let sass: typeof import('sass');
|
|
16
16
|
return async (source, options) => {
|
|
17
|
-
// eslint-disable-next-line require-atomic-updates
|
|
18
17
|
sass ??= await import('sass').catch(handleImportError('sass'));
|
|
19
18
|
const result = await sass.compileStringAsync(source, {
|
|
20
19
|
url: pathToFileURL(options.from),
|
package/src/util.test.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { join } from 'path';
|
|
1
|
+
import { join } from 'node:path';
|
|
2
2
|
import { createFixtures, getFixturePath } from './test-util/util.js';
|
|
3
3
|
import { hasProp, isObject, isSystemError, unique, uniqueBy, isMatchByGlob, exists } from './util.js';
|
|
4
4
|
|
|
5
5
|
function fakeSystemError({ code }: { code: string }) {
|
|
6
6
|
const error = new Error();
|
|
7
|
-
//
|
|
7
|
+
// oxlint-disable-next-line typescript/no-explicit-any
|
|
8
8
|
(error as any).code = code;
|
|
9
9
|
return error;
|
|
10
10
|
}
|