postcss-modules 6.0.1 → 8.1.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.
@@ -0,0 +1 @@
1
+ npx lint-staged
package/.swcrc ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "jsc": {
3
+ "parser": {
4
+ "syntax": "ecmascript"
5
+ },
6
+ "target": "es2022"
7
+ },
8
+ "module": {
9
+ "type": "commonjs"
10
+ }
11
+ }
package/CHANGELOG.md CHANGED
@@ -1,8 +1,47 @@
1
1
  # Changelog
2
2
 
3
+ ## 8.1.0
4
+
5
+ ### Internal
6
+
7
+ - Replaced Babel with swc across the entire toolchain: `@swc/cli` compiles `src/` to `build/`, `@swc/jest` transforms test files, and ESLint now uses its default `espree` parser. Removed five `@babel/*` devDependencies and the unused `@babel/register` runtime hook. The published `build/*.js` keeps the same `module.exports = (opts) => ...; module.exports.postcss = true` shape, so existing CommonJS consumers are unaffected.
8
+ - Pinned transitive `file-type` to v22 via `overrides` to silence `@swc/cli`'s vulnerable dependency chain.
9
+
10
+ ## 8.0.0
11
+
12
+ ### Breaking
13
+
14
+ - Dropped support for Node.js 18. The minimum supported Node.js version is now 20.
15
+
16
+ ### Updated
17
+
18
+ - All `devDependencies` bumped to latest: `@babel/*` 7 → 8, `eslint` 7 → 9 (now uses flat `eslint.config.mjs`), `eslint-plugin-jest` 23 → 29, `prettier` 2 → 3, `husky` 4 → 9, `lint-staged` 10 → 17, `autoprefixer` to 10.5, `postcss` to 8.5
19
+ - Bumped `postcss-modules-local-by-default` to 4.2 and `postcss-modules-scope` to 3.2.1
20
+ - Pinned transitive `glob` to v12 via `overrides`
21
+
22
+ ### Internal
23
+
24
+ - Reformatted source with Prettier 3 (whitespace only)
25
+ - Bumped Babel compile target from Node 10 to Node 18
26
+
27
+ ## 7.0.0
28
+
29
+ ### Breaking
30
+
31
+ - Dropped support for Node.js 10, 12, 14, and 15. The minimum supported Node.js version is now 18.
32
+
33
+ ### Security
34
+
35
+ - Patched 14 Dependabot security alerts in transitive dependencies (`form-data`, `lodash`, `@babel/core`, `@babel/plugin-transform-modules-systemjs`, `uuid`, `picomatch`, `flatted`, `minimatch`, `qs`, `js-yaml`, `nanoid`)
36
+ - Bumped `jest` from 26 to 30 to drop vulnerable `node-notifier`, `sane`, and `jsdom` chains
37
+
38
+ ### Internal
39
+
40
+ - Regenerated Jest snapshots for the new `pretty-format` serializer (cosmetic only; emitted CSS and JSON are unchanged)
41
+
3
42
  ## 6.0.1
4
43
 
5
- - Updated dependencies by Bill Collins (@mrginglymus)
44
+ - Updated dependencies by Bill Collins (@mrginglymus)
6
45
 
7
46
  ## 6.0.0
8
47
 
@@ -13,8 +52,8 @@ https://github.com/madyankin/postcss-modules/commit/86d8135cb5014d0b2848ef395608
13
52
 
14
53
  Parameters:
15
54
 
16
- - `file` — a module we want to resolve
17
- - `importer` — the file that imports the module we want to resolve
55
+ - `file` — a module we want to resolve
56
+ - `importer` — the file that imports the module we want to resolve
18
57
 
19
58
  Return value: `string | null | Promise<string | null>`
20
59
 
@@ -33,198 +72,198 @@ postcss([
33
72
 
34
73
  ### Fixed
35
74
 
36
- - #140 "'Failed to obtain root' error on Windows" fixed by Pierre LeMoine (@DrInfiniteExplorer) https://github.com/madyankin/postcss-modules/pull/144
75
+ - #140 "'Failed to obtain root' error on Windows" fixed by Pierre LeMoine (@DrInfiniteExplorer) https://github.com/madyankin/postcss-modules/pull/144
37
76
 
38
77
  ### Improved
39
78
 
40
- - `icss-replace-symbols` replaced with with `icss-utils` by Jason Quense (@jquense). The updated replacer works better and will replace values in selectors, which didn't work until now. https://github.com/madyankin/postcss-modules/pull/145
79
+ - `icss-replace-symbols` replaced with with `icss-utils` by Jason Quense (@jquense). The updated replacer works better and will replace values in selectors, which didn't work until now. https://github.com/madyankin/postcss-modules/pull/145
41
80
 
42
81
  ## 5.0.0
43
82
 
44
- - Fixed `composes` on Windows by @sapphi-red https://github.com/madyankin/postcss-modules/pull/135
45
- - Updated Babel to v7 by @sapphi-red. Minimal supported version of Node.js is 10 from now https://github.com/madyankin/postcss-modules/pull/134
83
+ - Fixed `composes` on Windows by @sapphi-red https://github.com/madyankin/postcss-modules/pull/135
84
+ - Updated Babel to v7 by @sapphi-red. Minimal supported version of Node.js is 10 from now https://github.com/madyankin/postcss-modules/pull/134
46
85
 
47
86
  ## 4.3.1
48
87
 
49
- - Fixed errors when using shorthand selectors by Felix Bruns (@fxb) https://github.com/madyankin/postcss-modules/pull/130
88
+ - Fixed errors when using shorthand selectors by Felix Bruns (@fxb) https://github.com/madyankin/postcss-modules/pull/130
50
89
 
51
90
  ## 4.3.0
52
91
 
53
- - Updated the `generic-names` dependency to reduce packages size by Bogdan Chadkin (@TrySound) https://github.com/madyankin/postcss-modules/pull/129
92
+ - Updated the `generic-names` dependency to reduce packages size by Bogdan Chadkin (@TrySound) https://github.com/madyankin/postcss-modules/pull/129
54
93
 
55
94
  ## 4.2.2
56
95
 
57
- - Fix the build
96
+ - Fix the build
58
97
 
59
98
  ## 4.2.1
60
99
 
61
- - Fixed the `resolve` option behaviour by @kamilic https://github.com/madyankin/postcss-modules/pull/127
100
+ - Fixed the `resolve` option behaviour by @kamilic https://github.com/madyankin/postcss-modules/pull/127
62
101
 
63
102
  ## 4.2.0
64
103
 
65
- - Added the `resolve` option to configure lookup paths for composes/from by @kamilic https://github.com/madyankin/postcss-modules/pull/126
104
+ - Added the `resolve` option to configure lookup paths for composes/from by @kamilic https://github.com/madyankin/postcss-modules/pull/126
66
105
 
67
106
  ## 4.1.3
68
107
 
69
- - Fixed package contents
108
+ - Fixed package contents
70
109
 
71
110
  ## 4.1.1
72
111
 
73
- - Fixed TypeScript typings by Shuman Lim (@origin-master) https://github.com/madyankin/postcss-modules/pull/124
112
+ - Fixed TypeScript typings by Shuman Lim (@origin-master) https://github.com/madyankin/postcss-modules/pull/124
74
113
 
75
114
  ## 4.1.0
76
115
 
77
- - Added TypeScript typings by Shuman Lim (@origin-master) https://github.com/madyankin/postcss-modules/pull/123
116
+ - Added TypeScript typings by Shuman Lim (@origin-master) https://github.com/madyankin/postcss-modules/pull/123
78
117
 
79
118
  ## 4.0.0
80
119
 
81
- - Upgraded to PostCSS 8 by Evan You (@yyx990803) https://github.com/css-modules/postcss-modules/pull/114
120
+ - Upgraded to PostCSS 8 by Evan You (@yyx990803) https://github.com/css-modules/postcss-modules/pull/114
82
121
 
83
122
  ## 3.2.2
84
123
 
85
124
  ### Fixed
86
125
 
87
- - Fixed user plugins order by Tom Jenkinson (@tjenkinson) https://github.com/css-modules/postcss-modules/pull/112
126
+ - Fixed user plugins order by Tom Jenkinson (@tjenkinson) https://github.com/css-modules/postcss-modules/pull/112
88
127
 
89
128
  ## 3.2.1
90
129
 
91
130
  ### Fixed
92
131
 
93
- - Fixed an issue when some plugins were running multiple times by Tom Jenkinson (@tjenkinson) https://github.com/css-modules/postcss-modules/pull/111
132
+ - Fixed an issue when some plugins were running multiple times by Tom Jenkinson (@tjenkinson) https://github.com/css-modules/postcss-modules/pull/111
94
133
 
95
134
  ## 3.2.0
96
135
 
97
136
  ### Changed
98
137
 
99
- - [`localsConvention` option] now supports a custom function `(originalClassName: string, generatedClassName: string, inputFile: string) => className: string` by Gregory Waxman (@Akkuma) https://github.com/css-modules/postcss-modules/pull/109
138
+ - [`localsConvention` option] now supports a custom function `(originalClassName: string, generatedClassName: string, inputFile: string) => className: string` by Gregory Waxman (@Akkuma) https://github.com/css-modules/postcss-modules/pull/109
100
139
 
101
140
  ## 3.1.0
102
141
 
103
142
  ### Added
104
143
 
105
- - Added `exportGlobals` option
144
+ - Added `exportGlobals` option
106
145
 
107
146
  ## 3.0.0
108
147
 
109
148
  ### Changed
110
149
 
111
- - Dropped `css-modules-loader-core` dependency
112
- - [Upgraded all the dependencies](https://github.com/css-modules/postcss-modules/pull/108)
150
+ - Dropped `css-modules-loader-core` dependency
151
+ - [Upgraded all the dependencies](https://github.com/css-modules/postcss-modules/pull/108)
113
152
 
114
153
  ### Breaking changes
115
154
 
116
- - Dropped support for unsupported Node versions. Supported versions are 10, 12 and 14+ https://nodejs.org/en/about/releases/
155
+ - Dropped support for unsupported Node versions. Supported versions are 10, 12 and 14+ https://nodejs.org/en/about/releases/
117
156
 
118
157
  ## 2.0.0
119
158
 
120
159
  ### Added
121
160
 
122
- - [`localsConvention` option](https://github.com/css-modules/postcss-modules#localsconvention) by Hamza Mihai Daniel (@allocenx) <https://github.com/css-modules/postcss-modules/pull/103>, <https://github.com/css-modules/postcss-modules/issues/93>
161
+ - [`localsConvention` option](https://github.com/css-modules/postcss-modules#localsconvention) by Hamza Mihai Daniel (@allocenx) <https://github.com/css-modules/postcss-modules/pull/103>, <https://github.com/css-modules/postcss-modules/issues/93>
123
162
 
124
163
  ### Breaking changes
125
164
 
126
- - `camelCase` camelCase removed, use the [`localsConvention` option](https://github.com/css-modules/postcss-modules#localsconvention) instead.
165
+ - `camelCase` camelCase removed, use the [`localsConvention` option](https://github.com/css-modules/postcss-modules#localsconvention) instead.
127
166
 
128
167
  ## 1.5.0
129
168
 
130
- - Added `hashPrefix` option by Jesse Thomson (@jessethomson) <https://github.com/css-modules/postcss-modules/pull/98>
169
+ - Added `hashPrefix` option by Jesse Thomson (@jessethomson) <https://github.com/css-modules/postcss-modules/pull/98>
131
170
 
132
171
  ## 1.4.1
133
172
 
134
- - Rebublished the previous release. Sorry :(
173
+ - Rebublished the previous release. Sorry :(
135
174
 
136
175
  ## 1.4.0
137
176
 
138
- - Added export for other plugins by Evilebot Tnawi (@evilebottnawi) <https://github.com/css-modules/postcss-modules/pull/88>, <https://github.com/css-modules/postcss-modules/issues/29>
177
+ - Added export for other plugins by Evilebot Tnawi (@evilebottnawi) <https://github.com/css-modules/postcss-modules/pull/88>, <https://github.com/css-modules/postcss-modules/issues/29>
139
178
 
140
179
  ## 1.3.1
141
180
 
142
- - Move dev tools to devDependecies by Anton Khlynovskiy (@ubzey) <https://github.com/css-modules/postcss-modules/pull/85>
181
+ - Move dev tools to devDependecies by Anton Khlynovskiy (@ubzey) <https://github.com/css-modules/postcss-modules/pull/85>
143
182
 
144
183
  ## 1.3.0
145
184
 
146
- - Updated dependecies
147
- - Added prettier to format code
185
+ - Updated dependecies
186
+ - Added prettier to format code
148
187
 
149
188
  ## 1.2.0
150
189
 
151
- - Added option to transform classes to camelCase by Igor Ribeiro (@igor-ribeiro) <https://github.com/css-modules/postcss-modules/pull/82>
190
+ - Added option to transform classes to camelCase by Igor Ribeiro (@igor-ribeiro) <https://github.com/css-modules/postcss-modules/pull/82>
152
191
 
153
192
  ## 1.1.0
154
193
 
155
- - Added ability to transmit outputFileName into getJSON by @lutien <https://github.com/css-modules/postcss-modules/pull/72>
194
+ - Added ability to transmit outputFileName into getJSON by @lutien <https://github.com/css-modules/postcss-modules/pull/72>
156
195
 
157
196
  ## 1.0.0
158
197
 
159
- - Dropped support for Node < 6
160
- - Updated dependencies
198
+ - Dropped support for Node < 6
199
+ - Updated dependencies
161
200
 
162
201
  ## 0.8.0
163
202
 
164
- - Updated PostCSS to 6 by Alexey Litvinov (@sullenor) <https://github.com/css-modules/postcss-modules/pull/65>
203
+ - Updated PostCSS to 6 by Alexey Litvinov (@sullenor) <https://github.com/css-modules/postcss-modules/pull/65>
165
204
 
166
205
  ## 0.7.1
167
206
 
168
- - Allowed empty string as opts.root by Sharon Rolel (@Mosho1) <https://github.com/css-modules/postcss-modules/pull/56>
207
+ - Allowed empty string as opts.root by Sharon Rolel (@Mosho1) <https://github.com/css-modules/postcss-modules/pull/56>
169
208
 
170
209
  ## 0.7.0
171
210
 
172
- - Allow async getJSON by Philipp A. (@flying-sheep) <https://github.com/css-modules/postcss-modules/pull/59>
211
+ - Allow async getJSON by Philipp A. (@flying-sheep) <https://github.com/css-modules/postcss-modules/pull/59>
173
212
 
174
213
  ## 0.6.4
175
214
 
176
- - Added the `root` option to pass the root path by Sharon Rolel (@Mosho1) (<https://github.com/css-modules/postcss-modules/pull/55>)
215
+ - Added the `root` option to pass the root path by Sharon Rolel (@Mosho1) (<https://github.com/css-modules/postcss-modules/pull/55>)
177
216
 
178
217
  ## 0.6.3
179
218
 
180
- - Fixed regression in `isValidBehaviour` function (<https://github.com/css-modules/postcss-modules/issues/53>)
219
+ - Fixed regression in `isValidBehaviour` function (<https://github.com/css-modules/postcss-modules/issues/53>)
181
220
 
182
221
  ## 0.6.2
183
222
 
184
- - Refactored `getDefaultPluginsList` function
223
+ - Refactored `getDefaultPluginsList` function
185
224
 
186
225
  ## 0.6.1
187
226
 
188
- - Fixed `generateScopedName` bug with multiple postcss-modules instances (<https://github.com/css-modules/postcss-modules/issues/37>)
227
+ - Fixed `generateScopedName` bug with multiple postcss-modules instances (<https://github.com/css-modules/postcss-modules/issues/37>)
189
228
 
190
229
  ## 0.6.0
191
230
 
192
- - Added `globalModulePaths` option (Thanks to @pospi).
193
- - Refactored all the things.
231
+ - Added `globalModulePaths` option (Thanks to @pospi).
232
+ - Refactored all the things.
194
233
 
195
234
  ## 0.5.2
196
235
 
197
- - Updated dependencies
236
+ - Updated dependencies
198
237
 
199
238
  ## 0.5.1
200
239
 
201
- - Fixed sorting for composed dependencies by Josh Johnston (@joshwnj) (<https://github.com/css-modules/postcss-modules/issues/38>)
240
+ - Fixed sorting for composed dependencies by Josh Johnston (@joshwnj) (<https://github.com/css-modules/postcss-modules/issues/38>)
202
241
 
203
242
  ## 0.5.0
204
243
 
205
- - Added `scopeBehaviour` option (<https://github.com/css-modules/postcss-modules/issues/22>)
206
- - Added ability to pass a string to `generateScopedName` (<https://github.com/css-modules/postcss-modules/issues/21>)
207
- - Updated dependencies
244
+ - Added `scopeBehaviour` option (<https://github.com/css-modules/postcss-modules/issues/22>)
245
+ - Added ability to pass a string to `generateScopedName` (<https://github.com/css-modules/postcss-modules/issues/21>)
246
+ - Updated dependencies
208
247
 
209
248
  ## 0.4.1
210
249
 
211
- - Fixed processing errors capturing by Boris Serdiuk (@just-boris)
250
+ - Fixed processing errors capturing by Boris Serdiuk (@just-boris)
212
251
 
213
252
  ## 0.4.0
214
253
 
215
- - Added support for custom loaders by Björn Brauer (@ZauberNerd)
254
+ - Added support for custom loaders by Björn Brauer (@ZauberNerd)
216
255
 
217
256
  ## 0.3.0
218
257
 
219
- - Fixed processing for imported CSS
220
- - Added default callback for saving exported JSON
258
+ - Fixed processing for imported CSS
259
+ - Added default callback for saving exported JSON
221
260
 
222
261
  ## 0.2.0
223
262
 
224
- - Fixed JSON export with shallow imports (<https://github.com/outpunk/postcss-modules/issues/12>)
225
- - Fixed lookup paths (<https://github.com/outpunk/postcss-modules/issues/13>)
226
- - Fixed imports overriding (<https://github.com/outpunk/postcss-modules/issues/15>)
227
- - Global refactoring under the hood
263
+ - Fixed JSON export with shallow imports (<https://github.com/outpunk/postcss-modules/issues/12>)
264
+ - Fixed lookup paths (<https://github.com/outpunk/postcss-modules/issues/13>)
265
+ - Fixed imports overriding (<https://github.com/outpunk/postcss-modules/issues/15>)
266
+ - Global refactoring under the hood
228
267
 
229
268
  ## 0.1.3
230
269
 
package/README.md CHANGED
@@ -212,8 +212,8 @@ It's useful when you need to resolve custom path alias.
212
212
 
213
213
  Parameters:
214
214
 
215
- - `file` — a module we want to resolve
216
- - `importer` — the file that imports the module we want to resolve
215
+ - `file` — a module we want to resolve
216
+ - `importer` — the file that imports the module we want to resolve
217
217
 
218
218
  Return value: `string | null | Promise<string | null>`
219
219
 
@@ -267,9 +267,7 @@ And you'll get the following HTML:
267
267
 
268
268
  ```html
269
269
  <h1 class="_title_xkpkl_5 _title_116zl_1">postcss-modules</h1>
270
- <article class="_article_xkpkl_10">
271
- A PostCSS plugin to use CSS Modules everywhere
272
- </article>
270
+ <article class="_article_xkpkl_10">A PostCSS plugin to use CSS Modules everywhere</article>
273
271
  ```
274
272
 
275
273
  ### HTML
@@ -284,9 +282,7 @@ Here is our template `about.html`:
284
282
 
285
283
  ```html
286
284
  <h1 css-module="title">postcss-modules</h1>
287
- <article css-module="article">
288
- A PostCSS plugin to use CSS Modules everywhere
289
- </article>
285
+ <article css-module="article">A PostCSS plugin to use CSS Modules everywhere</article>
290
286
  ```
291
287
 
292
288
  Transform it:
@@ -310,9 +306,7 @@ And you'll get the following HTML:
310
306
 
311
307
  ```html
312
308
  <h1 class="_title_xkpkl_5 _title_116zl_1">postcss-modules</h1>
313
- <article class="_article_xkpkl_10">
314
- A PostCSS plugin to use CSS Modules everywhere
315
- </article>
309
+ <article class="_article_xkpkl_10">A PostCSS plugin to use CSS Modules everywhere</article>
316
310
  ```
317
311
 
318
312
  ## May I see the plugin in action?
@@ -329,4 +323,4 @@ npm install --save-dev postcss postcss-modules
329
323
 
330
324
  ## Sponsors
331
325
 
332
- - Dmitry Olyenyov
326
+ - Dmitry Olyenyov
@@ -1,140 +1,118 @@
1
+ // Initially copied from https://github.com/css-modules/css-modules-loader-core
1
2
  "use strict";
2
-
3
3
  Object.defineProperty(exports, "__esModule", {
4
- value: true
4
+ value: true
5
5
  });
6
- exports.default = void 0;
7
-
8
- var _postcss = _interopRequireDefault(require("postcss"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _Parser = _interopRequireDefault(require("./Parser"));
13
-
14
- var _fs = require("./fs");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- // Initially copied from https://github.com/css-modules/css-modules-loader-core
19
- class Core {
20
- constructor(plugins) {
21
- this.plugins = plugins || Core.defaultPlugins;
22
- }
23
-
24
- async load(sourceString, sourcePath, trace, pathFetcher) {
25
- const parser = new _Parser.default(pathFetcher, trace);
26
- const plugins = this.plugins.concat([parser.plugin()]);
27
- const result = await (0, _postcss.default)(plugins).process(sourceString, {
28
- from: sourcePath
29
- });
30
- return {
31
- injectableSource: result.css,
32
- exportTokens: parser.exportTokens
6
+ Object.defineProperty(exports, "default", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return FileSystemLoader;
10
+ }
11
+ });
12
+ const _postcss = /*#__PURE__*/ _interop_require_default(require("postcss"));
13
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
14
+ const _Parser = /*#__PURE__*/ _interop_require_default(require("./Parser"));
15
+ const _fs = require("./fs");
16
+ function _interop_require_default(obj) {
17
+ return obj && obj.__esModule ? obj : {
18
+ default: obj
33
19
  };
34
- }
35
-
36
- } // Sorts dependencies in the following way:
20
+ }
21
+ class Core {
22
+ constructor(plugins){
23
+ this.plugins = plugins || Core.defaultPlugins;
24
+ }
25
+ async load(sourceString, sourcePath, trace, pathFetcher) {
26
+ const parser = new _Parser.default(pathFetcher, trace);
27
+ const plugins = this.plugins.concat([
28
+ parser.plugin()
29
+ ]);
30
+ const result = await (0, _postcss.default)(plugins).process(sourceString, {
31
+ from: sourcePath
32
+ });
33
+ return {
34
+ injectableSource: result.css,
35
+ exportTokens: parser.exportTokens
36
+ };
37
+ }
38
+ }
39
+ // Sorts dependencies in the following way:
37
40
  // AAA comes before AA and A
38
41
  // AB comes after AA and before A
39
42
  // All Bs come after all As
40
43
  // This ensures that the files are always returned in the following order:
41
44
  // - In the order they were required, except
42
45
  // - After all their dependencies
43
-
44
-
45
- const traceKeySorter = (a, b) => {
46
- if (a.length < b.length) {
47
- return a < b.substring(0, a.length) ? -1 : 1;
48
- }
49
-
50
- if (a.length > b.length) {
51
- return a.substring(0, b.length) <= b ? -1 : 1;
52
- }
53
-
54
- return a < b ? -1 : 1;
46
+ const traceKeySorter = (a, b)=>{
47
+ if (a.length < b.length) {
48
+ return a < b.substring(0, a.length) ? -1 : 1;
49
+ }
50
+ if (a.length > b.length) {
51
+ return a.substring(0, b.length) <= b ? -1 : 1;
52
+ }
53
+ return a < b ? -1 : 1;
55
54
  };
56
-
57
55
  class FileSystemLoader {
58
- constructor(root, plugins, fileResolve) {
59
- if (root === "/" && process.platform === "win32") {
60
- const cwdDrive = process.cwd().slice(0, 3);
61
-
62
- if (!/^[A-Za-z]:\\$/.test(cwdDrive)) {
63
- throw new Error(`Failed to obtain root from "${process.cwd()}".`);
64
- }
65
-
66
- root = cwdDrive;
56
+ constructor(root, plugins, fileResolve){
57
+ if (root === "/" && process.platform === "win32") {
58
+ const cwdDrive = process.cwd().slice(0, 3);
59
+ if (!/^[A-Za-z]:\\$/.test(cwdDrive)) {
60
+ throw new Error(`Failed to obtain root from "${process.cwd()}".`);
61
+ }
62
+ root = cwdDrive;
63
+ }
64
+ this.root = root;
65
+ this.fileResolve = fileResolve;
66
+ this.sources = {};
67
+ this.traces = {};
68
+ this.importNr = 0;
69
+ this.core = new Core(plugins);
70
+ this.tokensByFile = {};
71
+ this.fs = (0, _fs.getFileSystem)();
67
72
  }
68
-
69
- this.root = root;
70
- this.fileResolve = fileResolve;
71
- this.sources = {};
72
- this.traces = {};
73
- this.importNr = 0;
74
- this.core = new Core(plugins);
75
- this.tokensByFile = {};
76
- this.fs = (0, _fs.getFileSystem)();
77
- }
78
-
79
- async fetch(_newPath, relativeTo, _trace) {
80
- const newPath = _newPath.replace(/^["']|["']$/g, "");
81
-
82
- const trace = _trace || String.fromCharCode(this.importNr++);
83
-
84
- const useFileResolve = typeof this.fileResolve === "function";
85
- const fileResolvedPath = useFileResolve ? await this.fileResolve(newPath, relativeTo) : await Promise.resolve();
86
-
87
- if (fileResolvedPath && !_path.default.isAbsolute(fileResolvedPath)) {
88
- throw new Error('The returned path from the "fileResolve" option must be absolute.');
73
+ async fetch(_newPath, relativeTo, _trace) {
74
+ const newPath = _newPath.replace(/^["']|["']$/g, "");
75
+ const trace = _trace || String.fromCharCode(this.importNr++);
76
+ const useFileResolve = typeof this.fileResolve === "function";
77
+ const fileResolvedPath = useFileResolve ? await this.fileResolve(newPath, relativeTo) : await Promise.resolve();
78
+ if (fileResolvedPath && !_path.default.isAbsolute(fileResolvedPath)) {
79
+ throw new Error('The returned path from the "fileResolve" option must be absolute.');
80
+ }
81
+ const relativeDir = _path.default.dirname(relativeTo);
82
+ const rootRelativePath = fileResolvedPath || _path.default.resolve(relativeDir, newPath);
83
+ let fileRelativePath = fileResolvedPath || _path.default.resolve(_path.default.resolve(this.root, relativeDir), newPath);
84
+ // if the path is not relative or absolute, try to resolve it in node_modules
85
+ if (!useFileResolve && newPath[0] !== "." && !_path.default.isAbsolute(newPath)) {
86
+ try {
87
+ fileRelativePath = require.resolve(newPath);
88
+ } catch {
89
+ // noop
90
+ }
91
+ }
92
+ const tokens = this.tokensByFile[fileRelativePath];
93
+ if (tokens) return tokens;
94
+ return new Promise((resolve, reject)=>{
95
+ this.fs.readFile(fileRelativePath, "utf-8", async (err, source)=>{
96
+ if (err) reject(err);
97
+ const { injectableSource, exportTokens } = await this.core.load(source, rootRelativePath, trace, this.fetch.bind(this));
98
+ this.sources[fileRelativePath] = injectableSource;
99
+ this.traces[trace] = fileRelativePath;
100
+ this.tokensByFile[fileRelativePath] = exportTokens;
101
+ resolve(exportTokens);
102
+ });
103
+ });
89
104
  }
90
-
91
- const relativeDir = _path.default.dirname(relativeTo);
92
-
93
- const rootRelativePath = fileResolvedPath || _path.default.resolve(relativeDir, newPath);
94
-
95
- let fileRelativePath = fileResolvedPath || _path.default.resolve(_path.default.resolve(this.root, relativeDir), newPath); // if the path is not relative or absolute, try to resolve it in node_modules
96
-
97
-
98
- if (!useFileResolve && newPath[0] !== "." && !_path.default.isAbsolute(newPath)) {
99
- try {
100
- fileRelativePath = require.resolve(newPath);
101
- } catch (e) {// noop
102
- }
105
+ get finalSource() {
106
+ const traces = this.traces;
107
+ const sources = this.sources;
108
+ let written = new Set();
109
+ return Object.keys(traces).sort(traceKeySorter).map((key)=>{
110
+ const filename = traces[key];
111
+ if (written.has(filename)) {
112
+ return null;
113
+ }
114
+ written.add(filename);
115
+ return sources[filename];
116
+ }).join("");
103
117
  }
104
-
105
- const tokens = this.tokensByFile[fileRelativePath];
106
- if (tokens) return tokens;
107
- return new Promise((resolve, reject) => {
108
- this.fs.readFile(fileRelativePath, "utf-8", async (err, source) => {
109
- if (err) reject(err);
110
- const {
111
- injectableSource,
112
- exportTokens
113
- } = await this.core.load(source, rootRelativePath, trace, this.fetch.bind(this));
114
- this.sources[fileRelativePath] = injectableSource;
115
- this.traces[trace] = fileRelativePath;
116
- this.tokensByFile[fileRelativePath] = exportTokens;
117
- resolve(exportTokens);
118
- });
119
- });
120
- }
121
-
122
- get finalSource() {
123
- const traces = this.traces;
124
- const sources = this.sources;
125
- let written = new Set();
126
- return Object.keys(traces).sort(traceKeySorter).map(key => {
127
- const filename = traces[key];
128
-
129
- if (written.has(filename)) {
130
- return null;
131
- }
132
-
133
- written.add(filename);
134
- return sources[filename];
135
- }).join("");
136
- }
137
-
138
118
  }
139
-
140
- exports.default = FileSystemLoader;