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
|
@@ -1,11 +1,20 @@
|
|
|
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 { createScssTransformer } from './scss-transformer.js';
|
|
6
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
|
+
|
|
7
16
|
const locator = new Locator({ transformer: createScssTransformer() });
|
|
8
|
-
const loadSpy =
|
|
17
|
+
const loadSpy = vi.spyOn(locator, 'load');
|
|
9
18
|
|
|
10
19
|
afterEach(() => {
|
|
11
20
|
loadSpy.mockClear();
|
|
@@ -23,17 +32,17 @@ test('handles sass features', async () => {
|
|
|
23
32
|
.a_2_1 { dummy: ''; }
|
|
24
33
|
&_2 { dummy: ''; }
|
|
25
34
|
}
|
|
26
|
-
|
|
35
|
+
`,
|
|
27
36
|
'/test/2.scss': dedent`
|
|
28
37
|
.b_1 { dummy: ''; }
|
|
29
38
|
@mixin b_2 { dummy: ''; }
|
|
30
|
-
|
|
39
|
+
`,
|
|
31
40
|
'/test/3.scss': dedent`
|
|
32
41
|
.c { dummy: ''; }
|
|
33
|
-
|
|
42
|
+
`,
|
|
34
43
|
'/test/4.scss': dedent`
|
|
35
44
|
.d { dummy: ''; }
|
|
36
|
-
|
|
45
|
+
`,
|
|
37
46
|
});
|
|
38
47
|
const result = await locator.load(getFixturePath('/test/1.scss'));
|
|
39
48
|
|
|
@@ -42,64 +51,109 @@ test('handles sass features', async () => {
|
|
|
42
51
|
// FIXME: The sass compiler or Loader implementation needs to be fixed.
|
|
43
52
|
|
|
44
53
|
// FIXME: The end position of 'a_2_2' is incorrect.
|
|
45
|
-
expect(result).toMatchInlineSnapshot(`
|
|
54
|
+
expect(replaceFixtureDir(result)).toMatchInlineSnapshot(`
|
|
46
55
|
{
|
|
47
|
-
dependencies: [
|
|
48
|
-
|
|
56
|
+
"dependencies": [
|
|
57
|
+
"<fixtures>/test/2.scss",
|
|
58
|
+
"<fixtures>/test/3.scss",
|
|
59
|
+
],
|
|
60
|
+
"tokens": [
|
|
49
61
|
{
|
|
50
|
-
name: "b_1",
|
|
51
|
-
originalLocation: {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
},
|
|
55
73
|
},
|
|
56
74
|
},
|
|
57
75
|
{
|
|
58
|
-
name: "c",
|
|
59
|
-
originalLocation: {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
+
},
|
|
63
87
|
},
|
|
64
88
|
},
|
|
65
89
|
{
|
|
66
|
-
name: "a_1",
|
|
67
|
-
originalLocation: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
+
},
|
|
71
101
|
},
|
|
72
102
|
},
|
|
73
103
|
{
|
|
74
|
-
name: "a_2",
|
|
75
|
-
originalLocation: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
},
|
|
79
115
|
},
|
|
80
116
|
},
|
|
81
117
|
{
|
|
82
|
-
name: "a_2",
|
|
83
|
-
originalLocation: {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
+
},
|
|
87
129
|
},
|
|
88
130
|
},
|
|
89
131
|
{
|
|
90
|
-
name: "a_2_1",
|
|
91
|
-
originalLocation: {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
+
},
|
|
95
143
|
},
|
|
96
144
|
},
|
|
97
145
|
{
|
|
98
|
-
name: "a_2_2",
|
|
99
|
-
originalLocation: {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
+
},
|
|
103
157
|
},
|
|
104
158
|
},
|
|
105
159
|
],
|
|
@@ -110,13 +164,13 @@ test('handles sass features', async () => {
|
|
|
110
164
|
test('tracks dependencies that have been pre-bundled by sass compiler', async () => {
|
|
111
165
|
createFixtures({
|
|
112
166
|
'/test/1.scss': dedent`
|
|
113
|
-
|
|
114
|
-
|
|
167
|
+
@import './2.scss';
|
|
168
|
+
@import './3.scss';
|
|
115
169
|
`,
|
|
116
170
|
'/test/2.scss': dedent`
|
|
117
171
|
`,
|
|
118
172
|
'/test/3.scss': dedent`
|
|
119
|
-
|
|
173
|
+
@import './4.scss';
|
|
120
174
|
`,
|
|
121
175
|
'/test/4.scss': dedent`
|
|
122
176
|
`,
|
|
@@ -125,7 +179,7 @@ test('tracks dependencies that have been pre-bundled by sass compiler', async ()
|
|
|
125
179
|
|
|
126
180
|
// The files imported using @import are pre-bundled by the compiler.
|
|
127
181
|
// Therefore, `Locator#load` is not called to process other files.
|
|
128
|
-
expect(loadSpy).
|
|
182
|
+
expect(loadSpy).toHaveBeenCalledTimes(1);
|
|
129
183
|
expect(loadSpy).toHaveBeenNthCalledWith(1, getFixturePath('/test/1.scss'));
|
|
130
184
|
|
|
131
185
|
// The files pre-bundled by the compiler are also included in `result.dependencies`
|
|
@@ -135,8 +189,8 @@ test('tracks dependencies that have been pre-bundled by sass compiler', async ()
|
|
|
135
189
|
test('resolves specifier using resolver', async () => {
|
|
136
190
|
createFixtures({
|
|
137
191
|
'/test/1.scss': dedent`
|
|
138
|
-
|
|
139
|
-
|
|
192
|
+
@import 'package-1';
|
|
193
|
+
@import 'package-2';
|
|
140
194
|
`,
|
|
141
195
|
'/node_modules/package-1/index.css': `.a {}`,
|
|
142
196
|
'/node_modules/package-2/index.scss': `.a {}`,
|
|
@@ -150,9 +204,9 @@ test('resolves specifier using resolver', async () => {
|
|
|
150
204
|
test('ignores http(s) protocol file', async () => {
|
|
151
205
|
createFixtures({
|
|
152
206
|
'/test/1.scss': dedent`
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
207
|
+
@import 'http://example.com/path/http.css';
|
|
208
|
+
@import 'https://example.com/path/https.css';
|
|
209
|
+
@import 'https://example.com/path/scss.scss';
|
|
156
210
|
`,
|
|
157
211
|
});
|
|
158
212
|
const result = await locator.load(getFixturePath('/test/1.scss'));
|
|
@@ -1,42 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// https://github.com/mizdra/happy-css-modules/issues/65#issuecomment-1229471950 for more information.
|
|
5
|
-
|
|
6
|
-
import type { LegacyOptions, LegacyResult } from 'sass';
|
|
1
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
|
+
import type { FileImporter } from 'sass';
|
|
3
|
+
import type { StrictlyResolver } from '../locator/index.js';
|
|
7
4
|
import type { Transformer } from './index.js';
|
|
8
5
|
import { handleImportError } from './index.js';
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
else resolve(result!);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
}
|
|
7
|
+
const createFileImporter: (resolver: StrictlyResolver) => FileImporter<'async'> = (resolver) => ({
|
|
8
|
+
async findFileUrl(url, context): Promise<URL> {
|
|
9
|
+
const path = await resolver(url, { request: fileURLToPath(context.containingUrl!) });
|
|
10
|
+
return pathToFileURL(path);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
21
13
|
|
|
22
14
|
export const createScssTransformer: () => Transformer = () => {
|
|
23
15
|
let sass: typeof import('sass');
|
|
24
16
|
return async (source, options) => {
|
|
25
|
-
// eslint-disable-next-line require-atomic-updates
|
|
26
17
|
sass ??= await import('sass').catch(handleImportError('sass'));
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
data: source,
|
|
30
|
-
file: options.from,
|
|
31
|
-
outFile: 'DUMMY', // Required for sourcemap output.
|
|
18
|
+
const result = await sass.compileStringAsync(source, {
|
|
19
|
+
url: pathToFileURL(options.from),
|
|
32
20
|
sourceMap: true,
|
|
33
|
-
|
|
34
|
-
options
|
|
35
|
-
.resolver(url, { request: prev })
|
|
36
|
-
.then((resolved) => done({ file: resolved }))
|
|
37
|
-
.catch((e) => done(e));
|
|
38
|
-
},
|
|
21
|
+
importers: [createFileImporter(options.resolver)],
|
|
39
22
|
});
|
|
40
|
-
return { css: result.css.toString(), map: result.
|
|
23
|
+
return { css: result.css.toString(), map: JSON.stringify(result.sourceMap!), dependencies: result.loadedUrls };
|
|
41
24
|
};
|
|
42
25
|
};
|
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
|
}
|
package/src/util.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { constants, readFileSync } from 'fs';
|
|
2
|
-
import { access } from 'fs/promises';
|
|
3
|
-
import { join, dirname, resolve } from 'path';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
1
|
+
import { constants, readFileSync } from 'node:fs';
|
|
2
|
+
import { access } from 'node:fs/promises';
|
|
3
|
+
import { join, dirname, resolve, matchesGlob } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { resolve as importMetaResolve } from 'import-meta-resolve';
|
|
6
|
-
import { minimatch } from 'minimatch';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* The SystemError type of Node.js.
|
|
@@ -52,7 +51,6 @@ export function uniqueBy<T, U>(arr: T[], fn: (el: T) => U): T[] {
|
|
|
52
51
|
|
|
53
52
|
export function sleepSync(ms: number) {
|
|
54
53
|
const start = Date.now();
|
|
55
|
-
// eslint-disable-next-line no-empty
|
|
56
54
|
while (Date.now() - start < ms) {}
|
|
57
55
|
}
|
|
58
56
|
|
|
@@ -60,13 +58,13 @@ export async function exists(path: string): Promise<boolean> {
|
|
|
60
58
|
try {
|
|
61
59
|
await access(path, constants.F_OK);
|
|
62
60
|
return true;
|
|
63
|
-
} catch
|
|
61
|
+
} catch {
|
|
64
62
|
return false;
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
|
|
68
66
|
export function isMatchByGlob(filePath: string, pattern: string, options: { cwd: string }): boolean {
|
|
69
|
-
return
|
|
67
|
+
return matchesGlob(filePath, join(options.cwd, pattern));
|
|
70
68
|
}
|
|
71
69
|
|
|
72
70
|
export function getPackageJson() {
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
|
4
|
-
const nativeModule = require('node:module');
|
|
5
|
-
// workaround for https://github.com/facebook/jest/issues/12270#issuecomment-1194746382
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {{
|
|
8
|
-
* basedir: string;
|
|
9
|
-
* conditions?: Array<string>;
|
|
10
|
-
* defaultResolver: (path: string, options: ResolverOptions) => string;
|
|
11
|
-
* extensions?: Array<string>;
|
|
12
|
-
* moduleDirectory?: Array<string>;
|
|
13
|
-
* paths?: Array<string>;
|
|
14
|
-
* packageFilter?: (pkg: any, file: string, dir: string) => any;
|
|
15
|
-
* pathFilter?: (pkg: any, path: string, relativePath: string) => string;
|
|
16
|
-
* rootDir?: string;
|
|
17
|
-
* }} ResolverOptions
|
|
18
|
-
*/
|
|
19
|
-
/** @type {(path: string, options: ResolverOptions) => string} */
|
|
20
|
-
function resolver(module, options) {
|
|
21
|
-
const { basedir, defaultResolver } = options;
|
|
22
|
-
try {
|
|
23
|
-
return defaultResolver(module, options);
|
|
24
|
-
// eslint-disable-next-line no-unused-vars
|
|
25
|
-
}
|
|
26
|
-
catch (_error) {
|
|
27
|
-
return nativeModule.createRequire(basedir).resolve(module);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
module.exports = resolver;
|
|
31
|
-
//# sourceMappingURL=resolver.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.cjs","sourceRoot":"","sources":["../../../src/test-util/jest/resolver.cjs"],"names":[],"mappings":";;AAAA,qGAAqG;AACrG,MAAM,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAE5C,uFAAuF;AAEvF;;;;;;;;;;;;GAYG;AAEH,iEAAiE;AACjE,SAAS,QAAQ,CAAC,MAAM,EAAE,OAAO;IAC/B,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAC7C,IAAI,CAAC;QACH,OAAO,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACxC,0CAA0C;IAC5C,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,OAAO,YAAY,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export = resolver;
|
|
2
|
-
declare function resolver(path: string, options: ResolverOptions): string;
|
|
3
|
-
declare namespace resolver {
|
|
4
|
-
export { ResolverOptions };
|
|
5
|
-
}
|
|
6
|
-
type ResolverOptions = {
|
|
7
|
-
basedir: string;
|
|
8
|
-
conditions?: Array<string>;
|
|
9
|
-
defaultResolver: (path: string, options: ResolverOptions) => string;
|
|
10
|
-
extensions?: Array<string>;
|
|
11
|
-
moduleDirectory?: Array<string>;
|
|
12
|
-
paths?: Array<string>;
|
|
13
|
-
packageFilter?: (pkg: any, file: string, dir: string) => any;
|
|
14
|
-
pathFilter?: (pkg: any, path: string, relativePath: string) => string;
|
|
15
|
-
rootDir?: string;
|
|
16
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
|
2
|
-
const nativeModule = require('node:module');
|
|
3
|
-
|
|
4
|
-
// workaround for https://github.com/facebook/jest/issues/12270#issuecomment-1194746382
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {{
|
|
8
|
-
* basedir: string;
|
|
9
|
-
* conditions?: Array<string>;
|
|
10
|
-
* defaultResolver: (path: string, options: ResolverOptions) => string;
|
|
11
|
-
* extensions?: Array<string>;
|
|
12
|
-
* moduleDirectory?: Array<string>;
|
|
13
|
-
* paths?: Array<string>;
|
|
14
|
-
* packageFilter?: (pkg: any, file: string, dir: string) => any;
|
|
15
|
-
* pathFilter?: (pkg: any, path: string, relativePath: string) => string;
|
|
16
|
-
* rootDir?: string;
|
|
17
|
-
* }} ResolverOptions
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/** @type {(path: string, options: ResolverOptions) => string} */
|
|
21
|
-
function resolver(module, options) {
|
|
22
|
-
const { basedir, defaultResolver } = options;
|
|
23
|
-
try {
|
|
24
|
-
return defaultResolver(module, options);
|
|
25
|
-
// eslint-disable-next-line no-unused-vars
|
|
26
|
-
} catch (_error) {
|
|
27
|
-
return nativeModule.createRequire(basedir).resolve(module);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = resolver;
|