happy-css-modules 0.3.0 → 0.5.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.
Files changed (77) hide show
  1. package/README.md +95 -48
  2. package/dist/cli.js +42 -4
  3. package/dist/cli.js.map +1 -1
  4. package/dist/cli.test.js +21 -0
  5. package/dist/cli.test.js.map +1 -1
  6. package/dist/emitter/dts.js +9 -1
  7. package/dist/emitter/dts.js.map +1 -1
  8. package/dist/index.d.ts +3 -2
  9. package/dist/index.js +2 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/integration-test/go-to-definition.test.js +9 -8
  12. package/dist/integration-test/go-to-definition.test.js.map +1 -1
  13. package/dist/loader/index.test.js +79 -1
  14. package/dist/loader/index.test.js.map +1 -1
  15. package/dist/loader/postcss.d.ts +5 -1
  16. package/dist/loader/postcss.js +26 -30
  17. package/dist/loader/postcss.js.map +1 -1
  18. package/dist/resolver/index.d.ts +3 -1
  19. package/dist/resolver/index.js +17 -14
  20. package/dist/resolver/index.js.map +1 -1
  21. package/dist/resolver/webpack-resolver.d.ts +23 -1
  22. package/dist/resolver/webpack-resolver.js +82 -59
  23. package/dist/resolver/webpack-resolver.js.map +1 -1
  24. package/dist/resolver/webpack-resolver.test.js +70 -7
  25. package/dist/resolver/webpack-resolver.test.js.map +1 -1
  26. package/dist/runner.d.ts +25 -0
  27. package/dist/runner.js +30 -12
  28. package/dist/runner.js.map +1 -1
  29. package/dist/runner.test.js +62 -11
  30. package/dist/runner.test.js.map +1 -1
  31. package/dist/test/tsserver.d.ts +10 -6
  32. package/dist/test/tsserver.js +94 -85
  33. package/dist/test/tsserver.js.map +1 -1
  34. package/dist/test/util.d.ts +1 -1
  35. package/dist/test/util.js +15 -8
  36. package/dist/test/util.js.map +1 -1
  37. package/dist/transformer/index.d.ts +3 -1
  38. package/dist/transformer/index.js +15 -9
  39. package/dist/transformer/index.js.map +1 -1
  40. package/dist/transformer/index.test.d.ts +1 -0
  41. package/dist/transformer/index.test.js +66 -0
  42. package/dist/transformer/index.test.js.map +1 -0
  43. package/dist/transformer/less-transformer.js +1 -2
  44. package/dist/transformer/less-transformer.js.map +1 -1
  45. package/dist/transformer/less-transformer.test.js +6 -6
  46. package/dist/transformer/postcss-transformer.d.ts +12 -0
  47. package/dist/transformer/postcss-transformer.js +32 -0
  48. package/dist/transformer/postcss-transformer.js.map +1 -0
  49. package/dist/transformer/postcss-transformer.test.d.ts +1 -0
  50. package/dist/transformer/postcss-transformer.test.js +176 -0
  51. package/dist/transformer/postcss-transformer.test.js.map +1 -0
  52. package/dist/transformer/scss-transformer.js +19 -64
  53. package/dist/transformer/scss-transformer.js.map +1 -1
  54. package/dist/transformer/scss-transformer.test.js +8 -8
  55. package/package.json +6 -3
  56. package/src/cli.test.ts +29 -0
  57. package/src/cli.ts +41 -4
  58. package/src/emitter/dts.ts +10 -1
  59. package/src/index.ts +8 -2
  60. package/src/integration-test/go-to-definition.test.ts +10 -8
  61. package/src/loader/index.test.ts +79 -1
  62. package/src/loader/postcss.ts +42 -40
  63. package/src/resolver/index.ts +21 -12
  64. package/src/resolver/webpack-resolver.test.ts +100 -8
  65. package/src/resolver/webpack-resolver.ts +111 -57
  66. package/src/runner.test.ts +67 -11
  67. package/src/runner.ts +56 -13
  68. package/src/test/tsserver.ts +106 -129
  69. package/src/test/util.ts +15 -9
  70. package/src/transformer/index.test.ts +71 -0
  71. package/src/transformer/index.ts +18 -8
  72. package/src/transformer/less-transformer.test.ts +6 -6
  73. package/src/transformer/less-transformer.ts +1 -2
  74. package/src/transformer/postcss-transformer.test.ts +188 -0
  75. package/src/transformer/postcss-transformer.ts +57 -0
  76. package/src/transformer/scss-transformer.test.ts +8 -8
  77. package/src/transformer/scss-transformer.ts +25 -78
@@ -45,37 +45,37 @@ test('handles less features', async () => {
45
45
  {
46
46
  name: "b_1",
47
47
  originalLocations: [
48
- { filePath: "<fixtures>/test/2.less", start: { line: 1, column: 1 }, end: { line: 1, column: 3 } },
48
+ { filePath: "<fixtures>/test/2.less", start: { line: 1, column: 1 }, end: { line: 1, column: 4 } },
49
49
  ],
50
50
  },
51
51
  {
52
52
  name: "a_1",
53
53
  originalLocations: [
54
- { filePath: "<fixtures>/test/1.less", start: { line: 2, column: 1 }, end: { line: 2, column: 3 } },
54
+ { filePath: "<fixtures>/test/1.less", start: { line: 2, column: 1 }, end: { line: 2, column: 4 } },
55
55
  ],
56
56
  },
57
57
  {
58
58
  name: "a_2",
59
59
  originalLocations: [
60
- { filePath: "<fixtures>/test/1.less", start: { line: 3, column: 1 }, end: { line: 3, column: 3 } },
60
+ { filePath: "<fixtures>/test/1.less", start: { line: 3, column: 1 }, end: { line: 3, column: 4 } },
61
61
  ],
62
62
  },
63
63
  {
64
64
  name: "a_2_1",
65
65
  originalLocations: [
66
- { filePath: "<fixtures>/test/1.less", start: { line: 6, column: 3 }, end: { line: 6, column: 7 } },
66
+ { filePath: "<fixtures>/test/1.less", start: { line: 6, column: 3 }, end: { line: 6, column: 8 } },
67
67
  ],
68
68
  },
69
69
  {
70
70
  name: "a_2_2",
71
71
  originalLocations: [
72
- { filePath: "<fixtures>/test/1.less", start: { line: 7, column: 3 }, end: { line: 7, column: 7 } },
72
+ { filePath: "<fixtures>/test/1.less", start: { line: 7, column: 3 }, end: { line: 7, column: 8 } },
73
73
  ],
74
74
  },
75
75
  {
76
76
  name: "c",
77
77
  originalLocations: [
78
- { filePath: "<fixtures>/test/3.less", start: { line: 1, column: 1 }, end: { line: 1, column: 1 } },
78
+ { filePath: "<fixtures>/test/3.less", start: { line: 1, column: 1 }, end: { line: 1, column: 2 } },
79
79
  ],
80
80
  },
81
81
  ],
@@ -2,7 +2,7 @@ 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, @typescript-eslint/consistent-type-imports
5
+ // eslint-disable-next-line @typescript-eslint/naming-convention
6
6
  function createLessPluginResolver(Less: typeof import('less'), options: TransformerOptions): Less.Plugin {
7
7
  class ResolverFileManager extends Less.FileManager {
8
8
  options: TransformerOptions;
@@ -42,7 +42,6 @@ function createLessPluginResolver(Less: typeof import('less'), options: Transfor
42
42
  }
43
43
 
44
44
  export const createLessTransformer: () => Transformer = () => {
45
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
46
45
  let less: typeof import('less');
47
46
  return async (source, options) => {
48
47
  less ??= (await import('less').catch(handleImportError('less'))).default;
@@ -0,0 +1,188 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { createRequire } from 'node:module';
3
+ import { jest } from '@jest/globals';
4
+ import dedent from 'dedent';
5
+ import { Loader } from '../loader/index.js';
6
+ import { createFixtures, getFixturePath } from '../test/util.js';
7
+ import { createPostcssTransformer } from './postcss-transformer.js';
8
+
9
+ const cwd = getFixturePath('/');
10
+ const require = createRequire(import.meta.url);
11
+
12
+ // NOTE: postcss-load-config caches the configuration file using the path as a key.
13
+ // Therefore, change the path for each test case so that a new configuration file is always used.
14
+
15
+ test('handles postcss features', async () => {
16
+ const uuid = randomUUID();
17
+ const loader = new Loader({
18
+ transformer: createPostcssTransformer({
19
+ cwd,
20
+ postcssConfig: `${uuid}/postcss.config.js`,
21
+ }),
22
+ });
23
+ createFixtures({
24
+ [`/${uuid}/postcss.config.js`]: dedent`
25
+ module.exports = {
26
+ plugins: [
27
+ require('${require.resolve('postcss-simple-vars')}'),
28
+ ],
29
+ };
30
+ `,
31
+ '/test/1.css': dedent`
32
+ $prefix: foo;
33
+ .$(prefix)_bar {}
34
+ `,
35
+ });
36
+ const result = await loader.load(getFixturePath('/test/1.css'));
37
+
38
+ expect(result).toMatchInlineSnapshot(`
39
+ {
40
+ dependencies: [],
41
+ tokens: [
42
+ {
43
+ name: "foo_bar",
44
+ originalLocations: [
45
+ { filePath: "<fixtures>/test/1.css", start: { line: 2, column: 1 }, end: { line: 2, column: 8 } },
46
+ ],
47
+ },
48
+ ],
49
+ }
50
+ `);
51
+ });
52
+
53
+ test('tracks dependencies that have been pre-bundled by postcss compiler', async () => {
54
+ const uuid = randomUUID();
55
+ const loader = new Loader({
56
+ transformer: createPostcssTransformer({
57
+ cwd,
58
+ postcssConfig: `${uuid}/postcss.config.js`,
59
+ }),
60
+ });
61
+ const loadSpy = jest.spyOn(loader, 'load');
62
+ createFixtures({
63
+ [`/${uuid}/postcss.config.js`]: dedent`
64
+ module.exports = {
65
+ plugins: [
66
+ require('${require.resolve('postcss-import')}'),
67
+ ],
68
+ };
69
+ `,
70
+ '/test/1.css': dedent`
71
+ @import './2.css';
72
+ @import './3.css';
73
+ `,
74
+ '/test/2.css': ``,
75
+ '/test/3.css': `@import './4.css'`,
76
+ '/test/4.css': ``,
77
+ });
78
+ const result = await loader.load(getFixturePath('/test/1.css'));
79
+
80
+ // The files imported using @import are pre-bundled by the compiler.
81
+ // Therefore, `Loader#load` is not called to process other files.
82
+ expect(loadSpy).toBeCalledTimes(1);
83
+ expect(loadSpy).toHaveBeenNthCalledWith(1, getFixturePath('/test/1.css'));
84
+
85
+ // The files pre-bundled by the compiler are also included in `result.dependencies`
86
+ expect(result.dependencies).toStrictEqual(['/test/2.css', '/test/3.css', '/test/4.css'].map(getFixturePath));
87
+ });
88
+
89
+ test('resolves specifier using resolver', async () => {
90
+ const uuid = randomUUID();
91
+ const loader = new Loader({
92
+ transformer: createPostcssTransformer({
93
+ cwd,
94
+ postcssConfig: `${uuid}/postcss.config.js`,
95
+ }),
96
+ });
97
+ createFixtures({
98
+ [`/${uuid}/postcss.config.js`]: dedent`
99
+ module.exports = {
100
+ plugins: [
101
+ // When using postcss-import, the resolver of happy-css-modules is ignored.
102
+ // Therefore, we test here without postcss-import.
103
+ // require('${require.resolve('postcss-import')}'),
104
+ ],
105
+ };
106
+ `,
107
+ '/test/1.css': dedent`
108
+ @import 'package';
109
+ `,
110
+ '/node_modules/package/index.css': `.a {}`,
111
+ });
112
+ const result = await loader.load(getFixturePath('/test/1.css'));
113
+ expect(result.dependencies).toStrictEqual(['/node_modules/package/index.css'].map(getFixturePath));
114
+ });
115
+
116
+ test('ignores http(s) protocol file', async () => {
117
+ const uuid = randomUUID();
118
+ const loader = new Loader({
119
+ transformer: createPostcssTransformer({
120
+ cwd,
121
+ postcssConfig: `${uuid}/postcss.config.js`,
122
+ }),
123
+ });
124
+ createFixtures({
125
+ [`/${uuid}/postcss.config.js`]: dedent`
126
+ module.exports = {
127
+ plugins: [
128
+ // When using postcss-import, the resolver of happy-css-modules is ignored.
129
+ // Therefore, we test here without postcss-import.
130
+ // require('${require.resolve('postcss-import')}'),
131
+ ],
132
+ };
133
+ `,
134
+ '/test/1.css': dedent`
135
+ @import 'http://example.com/path/http.css';
136
+ @import 'https://example.com/path/https.css';
137
+ `,
138
+ });
139
+ const result = await loader.load(getFixturePath('/test/1.css'));
140
+ expect(result.dependencies).toStrictEqual([]);
141
+ });
142
+
143
+ test('returns false if postcssrc is not found', async () => {
144
+ const uuid = randomUUID();
145
+ const transformer = createPostcssTransformer({
146
+ cwd,
147
+ postcssConfig: `${uuid}/postcss.config.js`,
148
+ });
149
+ createFixtures({
150
+ '/test/1.css': dedent`
151
+ @import 'http://example.com/path/http.css';
152
+ @import 'https://example.com/path/https.css';
153
+ `,
154
+ });
155
+ expect(
156
+ await transformer('', {
157
+ from: getFixturePath('/test/1.css'),
158
+ isIgnoredSpecifier: () => false,
159
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
160
+ resolver: jest.fn() as any,
161
+ }),
162
+ ).toBe(false);
163
+ });
164
+
165
+ test('searches config from cwd if postcssConfig option is missing', async () => {
166
+ const uuid = randomUUID();
167
+ const cwd = `/${uuid}`;
168
+ const loader = new Loader({
169
+ transformer: createPostcssTransformer({
170
+ cwd: getFixturePath(cwd),
171
+ }),
172
+ });
173
+ createFixtures({
174
+ [`/${uuid}/postcss.config.js`]: dedent`
175
+ module.exports = {
176
+ plugins: [
177
+ require('${require.resolve('postcss-simple-vars')}'),
178
+ ],
179
+ };
180
+ `,
181
+ '/test/1.css': dedent`
182
+ $prefix: foo;
183
+ .$(prefix)_bar {}
184
+ `,
185
+ });
186
+ const result = await loader.load(getFixturePath('/test/1.css'));
187
+ expect(result.tokens.map((token) => token.name)).toStrictEqual(['foo_bar']);
188
+ });
@@ -0,0 +1,57 @@
1
+ import { createRequire } from 'node:module';
2
+ import { resolve } from 'node:path';
3
+ import { default as postcss, type Message } from 'postcss';
4
+ import type { Result } from 'postcss-load-config';
5
+ import type { Transformer } from '../index.js';
6
+
7
+ const require = createRequire(import.meta.url);
8
+
9
+ const postcssrc: typeof import('postcss-load-config') = require('postcss-load-config');
10
+
11
+ //ref: https://github.com/postcss/postcss-import#dependency-message-support
12
+ interface DependencyMessage extends Message {
13
+ type: 'dependency';
14
+ file: string;
15
+ parent: string;
16
+ }
17
+ function isDependencyMessage(message: Message): message is DependencyMessage {
18
+ return message.type === 'dependency';
19
+ }
20
+
21
+ export type PostcssTransformerOptions = {
22
+ cwd?: string | undefined;
23
+ /**
24
+ * The option compatible with postcss's `--config`. It is a relative or absolute path.
25
+ * @example '.'
26
+ * @example 'postcss.config.js'
27
+ * @example '/home/user/repository/src'
28
+ */
29
+ postcssConfig?: string | undefined;
30
+ };
31
+
32
+ export const createPostcssTransformer: (postcssTransformerOptions?: PostcssTransformerOptions) => Transformer = (
33
+ postcssTransformerOptions,
34
+ ) => {
35
+ const cwd = postcssTransformerOptions?.cwd ?? process.cwd();
36
+ const configSearchPath = postcssTransformerOptions?.postcssConfig
37
+ ? resolve(cwd, postcssTransformerOptions?.postcssConfig)
38
+ : cwd;
39
+ return async (source, options) => {
40
+ // NOTE: postcss-load-config cache the configuration file so is is not reloaded.
41
+ const postcssConfig: Result | undefined = await postcssrc({ cwd }, configSearchPath).catch((e) => {
42
+ if (e instanceof Error && e.message.includes('No PostCSS Config found')) return undefined;
43
+ throw e;
44
+ });
45
+ if (postcssConfig === undefined) return false;
46
+
47
+ const result = await postcss(postcssConfig.plugins).process(source, {
48
+ ...postcssConfig.options,
49
+ from: options.from,
50
+ map: { inline: false, absolute: true },
51
+ });
52
+
53
+ const dependencies = result.messages.filter(isDependencyMessage).map((message) => message.file);
54
+
55
+ return { css: result.css, map: result.map, dependencies };
56
+ };
57
+ };
@@ -51,44 +51,44 @@ test('handles sass features', async () => {
51
51
  {
52
52
  name: "b_1",
53
53
  originalLocations: [
54
- { filePath: "<fixtures>/test/2.scss", start: { line: 1, column: 1 }, end: { line: 1, column: 3 } },
54
+ { filePath: "<fixtures>/test/2.scss", start: { line: 1, column: 1 }, end: { line: 1, column: 4 } },
55
55
  ],
56
56
  },
57
57
  {
58
58
  name: "c",
59
59
  originalLocations: [
60
- { filePath: "<fixtures>/test/3.scss", start: { line: 1, column: 1 }, end: { line: 1, column: 1 } },
60
+ { filePath: "<fixtures>/test/3.scss", start: { line: 1, column: 1 }, end: { line: 1, column: 2 } },
61
61
  ],
62
62
  },
63
63
  {
64
64
  name: "a_1",
65
65
  originalLocations: [
66
- { filePath: "<fixtures>/test/1.scss", start: { line: 3, column: 1 }, end: { line: 3, column: 3 } },
66
+ { filePath: "<fixtures>/test/1.scss", start: { line: 3, column: 1 }, end: { line: 3, column: 4 } },
67
67
  ],
68
68
  },
69
69
  {
70
70
  name: "a_2",
71
71
  originalLocations: [
72
- { filePath: "<fixtures>/test/1.scss", start: { line: 4, column: 1 }, end: { line: 4, column: 3 } },
73
- { filePath: "<fixtures>/test/1.scss", start: { line: 7, column: 3 }, end: { line: 7, column: 5 } },
72
+ { filePath: "<fixtures>/test/1.scss", start: { line: 4, column: 1 }, end: { line: 4, column: 4 } },
73
+ { filePath: "<fixtures>/test/1.scss", start: { line: 7, column: 3 }, end: { line: 7, column: 6 } },
74
74
  ],
75
75
  },
76
76
  {
77
77
  name: "a_2_1",
78
78
  originalLocations: [
79
- { filePath: "<fixtures>/test/1.scss", start: { line: 7, column: 3 }, end: { line: 7, column: 7 } },
79
+ { filePath: "<fixtures>/test/1.scss", start: { line: 7, column: 3 }, end: { line: 7, column: 8 } },
80
80
  ],
81
81
  },
82
82
  {
83
83
  name: "a_2_2",
84
84
  originalLocations: [
85
- { filePath: "<fixtures>/test/1.scss", start: { line: 8, column: 3 }, end: { line: 8, column: 7 } },
85
+ { filePath: "<fixtures>/test/1.scss", start: { line: 8, column: 3 }, end: { line: 8, column: 8 } },
86
86
  ],
87
87
  },
88
88
  {
89
89
  name: "d",
90
90
  originalLocations: [
91
- { filePath: "<fixtures>/test/4.scss", start: { line: 1, column: 1 }, end: { line: 1, column: 1 } },
91
+ { filePath: "<fixtures>/test/4.scss", start: { line: 1, column: 1 }, end: { line: 1, column: 2 } },
92
92
  ],
93
93
  },
94
94
  ],
@@ -3,92 +3,39 @@
3
3
  // Therefore, the workaround is now disabled. See
4
4
  // https://github.com/mizdra/happy-css-modules/issues/65#issuecomment-1229471950 for more information.
5
5
 
6
- import type { LegacyResult } from 'sass';
7
- import type { Transformer, TransformerOptions } from './index.js';
6
+ import type { LegacyOptions, LegacyResult } from 'sass';
7
+ import type { Transformer } from './index.js';
8
8
  import { handleImportError } from './index.js';
9
9
 
10
- // const IS_JEST_ENVIRONMENT = process.env.JEST_WORKER_ID !== undefined;
11
-
12
- // function verifyJestEnvironment() {
13
- // if (
14
- // !(
15
- // 'window' in global &&
16
- // 'location' in global &&
17
- // // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- // 'href' in (global as any).location &&
19
- // // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- // typeof (global as any).location.href === 'string' &&
21
- // // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- // (global as any).location.href.startsWith('http://')
23
- // )
24
- // ) {
25
- // throw new Error(
26
- // 'To use dart-sass with jest, dummy `global.window` and `global.location.href` must be set. See https://github.com/sass/dart-sass/issues/1692#issuecomment-1229219993 .',
27
- // );
28
- // }
29
- // }
30
-
31
- // const createImporterForJest: (from: string) => Importer<'async'> = (from) => ({
32
- // canonicalize(url) {
33
- // // NOTE: The format of `url` changes depending on the import source.
34
- // //
35
- // // - When `from === '/test/1.scss'` and `@import './2.scss'` in `/test/1.scss` is resolved, `url === '2.scss'`.
36
- // // - When `from === '/test/1.scss'` and `@import './3.scss'` in `/test/2.scss` is resolved, `url === 'file:///test/3.scss'`.
37
- // //
38
- // // That is, the paths of @import statements written to the `from` file is passed through unresolved,
39
- // // but paths written to other files is passed through resolved to absolute paths.
40
- // return new URL(url, pathToFileURL(from));
41
- // },
42
- // async load(canonicalUrl) {
43
- // return {
44
- // contents: await readFile(fileURLToPath(canonicalUrl.href), 'utf8'),
45
- // syntax: 'scss',
46
- // sourceMapUrl: canonicalUrl,
47
- // };
48
- // },
49
- // });
50
-
51
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
52
- async function renderSass(sass: typeof import('sass'), source: string, options: TransformerOptions) {
53
- return new Promise<LegacyResult>((resolve, reject) => {
54
- sass.render(
55
- {
56
- data: source,
57
- file: options.from,
58
- outFile: 'DUMMY', // Required for sourcemap output.
59
- sourceMap: true,
60
- importer: (url, prev, done) => {
61
- options
62
- .resolver(url, { request: prev })
63
- .then((resolved) => done({ file: resolved }))
64
- .catch((e) => done(e));
65
- },
66
- },
67
- (exception, result) => {
68
- if (exception) {
69
- reject(exception);
70
- } else {
71
- resolve(result!);
72
- }
73
- },
74
- );
75
- });
10
+ // For some reason, `util.promisify` does not work. Therefore, use the original promisify.
11
+ function promisifySassRender(sass: typeof import('sass')) {
12
+ return async (options: LegacyOptions<'async'>) => {
13
+ return new Promise<LegacyResult>((resolve, reject) => {
14
+ sass.render(options, (exception, result) => {
15
+ if (exception) reject(exception);
16
+ else resolve(result!);
17
+ });
18
+ });
19
+ };
76
20
  }
77
21
 
78
22
  export const createScssTransformer: () => Transformer = () => {
79
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
80
23
  let sass: typeof import('sass');
81
24
  return async (source, options) => {
82
25
  sass ??= (await import('sass').catch(handleImportError('sass'))).default;
83
- const result = await renderSass(sass, source, options);
26
+ const render = promisifySassRender(sass);
27
+ const result = await render({
28
+ data: source,
29
+ file: options.from,
30
+ outFile: 'DUMMY', // Required for sourcemap output.
31
+ sourceMap: true,
32
+ importer: (url, prev, done) => {
33
+ options
34
+ .resolver(url, { request: prev })
35
+ .then((resolved) => done({ file: resolved }))
36
+ .catch((e) => done(e));
37
+ },
38
+ });
84
39
  return { css: result.css.toString(), map: result.map!.toString(), dependencies: result.stats.includedFiles };
85
-
86
- // if (IS_JEST_ENVIRONMENT) verifyJestEnvironment();
87
- // const result = await sass.default.compileStringAsync(source, {
88
- // url: pathToFileURL(from),
89
- // sourceMap: true,
90
- // importers: IS_JEST_ENVIRONMENT ? [createImporterForJest(from)] : [],
91
- // });
92
- // return { css: result.css, map: result.sourceMap!, dependencies: result.loadedUrls };
93
40
  };
94
41
  };