postcss-modules 7.0.0 → 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,23 +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
+
3
27
  ## 7.0.0
4
28
 
5
29
  ### Breaking
6
30
 
7
- - Dropped support for Node.js 10, 12, 14, and 15. The minimum supported Node.js version is now 18.
31
+ - Dropped support for Node.js 10, 12, 14, and 15. The minimum supported Node.js version is now 18.
8
32
 
9
33
  ### Security
10
34
 
11
- - 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`)
12
- - Bumped `jest` from 26 to 30 to drop vulnerable `node-notifier`, `sane`, and `jsdom` chains
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
13
37
 
14
38
  ### Internal
15
39
 
16
- - Regenerated Jest snapshots for the new `pretty-format` serializer (cosmetic only; emitted CSS and JSON are unchanged)
40
+ - Regenerated Jest snapshots for the new `pretty-format` serializer (cosmetic only; emitted CSS and JSON are unchanged)
17
41
 
18
42
  ## 6.0.1
19
43
 
20
- - Updated dependencies by Bill Collins (@mrginglymus)
44
+ - Updated dependencies by Bill Collins (@mrginglymus)
21
45
 
22
46
  ## 6.0.0
23
47
 
@@ -28,8 +52,8 @@ https://github.com/madyankin/postcss-modules/commit/86d8135cb5014d0b2848ef395608
28
52
 
29
53
  Parameters:
30
54
 
31
- - `file` — a module we want to resolve
32
- - `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
33
57
 
34
58
  Return value: `string | null | Promise<string | null>`
35
59
 
@@ -48,198 +72,198 @@ postcss([
48
72
 
49
73
  ### Fixed
50
74
 
51
- - #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
52
76
 
53
77
  ### Improved
54
78
 
55
- - `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
56
80
 
57
81
  ## 5.0.0
58
82
 
59
- - Fixed `composes` on Windows by @sapphi-red https://github.com/madyankin/postcss-modules/pull/135
60
- - 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
61
85
 
62
86
  ## 4.3.1
63
87
 
64
- - 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
65
89
 
66
90
  ## 4.3.0
67
91
 
68
- - 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
69
93
 
70
94
  ## 4.2.2
71
95
 
72
- - Fix the build
96
+ - Fix the build
73
97
 
74
98
  ## 4.2.1
75
99
 
76
- - 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
77
101
 
78
102
  ## 4.2.0
79
103
 
80
- - 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
81
105
 
82
106
  ## 4.1.3
83
107
 
84
- - Fixed package contents
108
+ - Fixed package contents
85
109
 
86
110
  ## 4.1.1
87
111
 
88
- - 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
89
113
 
90
114
  ## 4.1.0
91
115
 
92
- - 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
93
117
 
94
118
  ## 4.0.0
95
119
 
96
- - 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
97
121
 
98
122
  ## 3.2.2
99
123
 
100
124
  ### Fixed
101
125
 
102
- - 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
103
127
 
104
128
  ## 3.2.1
105
129
 
106
130
  ### Fixed
107
131
 
108
- - 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
109
133
 
110
134
  ## 3.2.0
111
135
 
112
136
  ### Changed
113
137
 
114
- - [`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
115
139
 
116
140
  ## 3.1.0
117
141
 
118
142
  ### Added
119
143
 
120
- - Added `exportGlobals` option
144
+ - Added `exportGlobals` option
121
145
 
122
146
  ## 3.0.0
123
147
 
124
148
  ### Changed
125
149
 
126
- - Dropped `css-modules-loader-core` dependency
127
- - [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)
128
152
 
129
153
  ### Breaking changes
130
154
 
131
- - 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/
132
156
 
133
157
  ## 2.0.0
134
158
 
135
159
  ### Added
136
160
 
137
- - [`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>
138
162
 
139
163
  ### Breaking changes
140
164
 
141
- - `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.
142
166
 
143
167
  ## 1.5.0
144
168
 
145
- - 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>
146
170
 
147
171
  ## 1.4.1
148
172
 
149
- - Rebublished the previous release. Sorry :(
173
+ - Rebublished the previous release. Sorry :(
150
174
 
151
175
  ## 1.4.0
152
176
 
153
- - 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>
154
178
 
155
179
  ## 1.3.1
156
180
 
157
- - 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>
158
182
 
159
183
  ## 1.3.0
160
184
 
161
- - Updated dependecies
162
- - Added prettier to format code
185
+ - Updated dependecies
186
+ - Added prettier to format code
163
187
 
164
188
  ## 1.2.0
165
189
 
166
- - 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>
167
191
 
168
192
  ## 1.1.0
169
193
 
170
- - 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>
171
195
 
172
196
  ## 1.0.0
173
197
 
174
- - Dropped support for Node < 6
175
- - Updated dependencies
198
+ - Dropped support for Node < 6
199
+ - Updated dependencies
176
200
 
177
201
  ## 0.8.0
178
202
 
179
- - 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>
180
204
 
181
205
  ## 0.7.1
182
206
 
183
- - 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>
184
208
 
185
209
  ## 0.7.0
186
210
 
187
- - 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>
188
212
 
189
213
  ## 0.6.4
190
214
 
191
- - 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>)
192
216
 
193
217
  ## 0.6.3
194
218
 
195
- - 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>)
196
220
 
197
221
  ## 0.6.2
198
222
 
199
- - Refactored `getDefaultPluginsList` function
223
+ - Refactored `getDefaultPluginsList` function
200
224
 
201
225
  ## 0.6.1
202
226
 
203
- - 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>)
204
228
 
205
229
  ## 0.6.0
206
230
 
207
- - Added `globalModulePaths` option (Thanks to @pospi).
208
- - Refactored all the things.
231
+ - Added `globalModulePaths` option (Thanks to @pospi).
232
+ - Refactored all the things.
209
233
 
210
234
  ## 0.5.2
211
235
 
212
- - Updated dependencies
236
+ - Updated dependencies
213
237
 
214
238
  ## 0.5.1
215
239
 
216
- - 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>)
217
241
 
218
242
  ## 0.5.0
219
243
 
220
- - Added `scopeBehaviour` option (<https://github.com/css-modules/postcss-modules/issues/22>)
221
- - Added ability to pass a string to `generateScopedName` (<https://github.com/css-modules/postcss-modules/issues/21>)
222
- - 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
223
247
 
224
248
  ## 0.4.1
225
249
 
226
- - Fixed processing errors capturing by Boris Serdiuk (@just-boris)
250
+ - Fixed processing errors capturing by Boris Serdiuk (@just-boris)
227
251
 
228
252
  ## 0.4.0
229
253
 
230
- - Added support for custom loaders by Björn Brauer (@ZauberNerd)
254
+ - Added support for custom loaders by Björn Brauer (@ZauberNerd)
231
255
 
232
256
  ## 0.3.0
233
257
 
234
- - Fixed processing for imported CSS
235
- - Added default callback for saving exported JSON
258
+ - Fixed processing for imported CSS
259
+ - Added default callback for saving exported JSON
236
260
 
237
261
  ## 0.2.0
238
262
 
239
- - Fixed JSON export with shallow imports (<https://github.com/outpunk/postcss-modules/issues/12>)
240
- - Fixed lookup paths (<https://github.com/outpunk/postcss-modules/issues/13>)
241
- - Fixed imports overriding (<https://github.com/outpunk/postcss-modules/issues/15>)
242
- - 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
243
267
 
244
268
  ## 0.1.3
245
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,33 +1,41 @@
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
- var _postcss = _interopRequireDefault(require("postcss"));
8
- var _path = _interopRequireDefault(require("path"));
9
- var _Parser = _interopRequireDefault(require("./Parser"));
10
- var _fs = require("./fs");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- // Initially copied from https://github.com/css-modules/css-modules-loader-core
13
-
14
- class Core {
15
- constructor(plugins) {
16
- this.plugins = plugins || Core.defaultPlugins;
17
- }
18
- async load(sourceString, sourcePath, trace, pathFetcher) {
19
- const parser = new _Parser.default(pathFetcher, trace);
20
- const plugins = this.plugins.concat([parser.plugin()]);
21
- const result = await (0, _postcss.default)(plugins).process(sourceString, {
22
- from: sourcePath
23
- });
24
- return {
25
- injectableSource: result.css,
26
- 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
27
19
  };
28
- }
29
20
  }
30
-
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
+ }
31
39
  // Sorts dependencies in the following way:
32
40
  // AAA comes before AA and A
33
41
  // AB comes after AA and before A
@@ -35,81 +43,76 @@ class Core {
35
43
  // This ensures that the files are always returned in the following order:
36
44
  // - In the order they were required, except
37
45
  // - After all their dependencies
38
- const traceKeySorter = (a, b) => {
39
- if (a.length < b.length) {
40
- return a < b.substring(0, a.length) ? -1 : 1;
41
- }
42
- if (a.length > b.length) {
43
- return a.substring(0, b.length) <= b ? -1 : 1;
44
- }
45
- 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;
46
54
  };
47
55
  class FileSystemLoader {
48
- constructor(root, plugins, fileResolve) {
49
- if (root === "/" && process.platform === "win32") {
50
- const cwdDrive = process.cwd().slice(0, 3);
51
- if (!/^[A-Za-z]:\\$/.test(cwdDrive)) {
52
- throw new Error(`Failed to obtain root from "${process.cwd()}".`);
53
- }
54
- 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)();
55
72
  }
56
- this.root = root;
57
- this.fileResolve = fileResolve;
58
- this.sources = {};
59
- this.traces = {};
60
- this.importNr = 0;
61
- this.core = new Core(plugins);
62
- this.tokensByFile = {};
63
- this.fs = (0, _fs.getFileSystem)();
64
- }
65
- async fetch(_newPath, relativeTo, _trace) {
66
- const newPath = _newPath.replace(/^["']|["']$/g, "");
67
- const trace = _trace || String.fromCharCode(this.importNr++);
68
- const useFileResolve = typeof this.fileResolve === "function";
69
- const fileResolvedPath = useFileResolve ? await this.fileResolve(newPath, relativeTo) : await Promise.resolve();
70
- if (fileResolvedPath && !_path.default.isAbsolute(fileResolvedPath)) {
71
- 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
+ });
72
104
  }
73
- const relativeDir = _path.default.dirname(relativeTo);
74
- const rootRelativePath = fileResolvedPath || _path.default.resolve(relativeDir, newPath);
75
- let fileRelativePath = fileResolvedPath || _path.default.resolve(_path.default.resolve(this.root, relativeDir), newPath);
76
-
77
- // if the path is not relative or absolute, try to resolve it in node_modules
78
- if (!useFileResolve && newPath[0] !== "." && !_path.default.isAbsolute(newPath)) {
79
- try {
80
- fileRelativePath = require.resolve(newPath);
81
- } catch (e) {
82
- // noop
83
- }
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("");
84
117
  }
85
- const tokens = this.tokensByFile[fileRelativePath];
86
- if (tokens) return tokens;
87
- return new Promise((resolve, reject) => {
88
- this.fs.readFile(fileRelativePath, "utf-8", async (err, source) => {
89
- if (err) reject(err);
90
- const {
91
- injectableSource,
92
- exportTokens
93
- } = await this.core.load(source, rootRelativePath, trace, this.fetch.bind(this));
94
- this.sources[fileRelativePath] = injectableSource;
95
- this.traces[trace] = fileRelativePath;
96
- this.tokensByFile[fileRelativePath] = exportTokens;
97
- resolve(exportTokens);
98
- });
99
- });
100
- }
101
- get finalSource() {
102
- const traces = this.traces;
103
- const sources = this.sources;
104
- let written = new Set();
105
- return Object.keys(traces).sort(traceKeySorter).map(key => {
106
- const filename = traces[key];
107
- if (written.has(filename)) {
108
- return null;
109
- }
110
- written.add(filename);
111
- return sources[filename];
112
- }).join("");
113
- }
114
118
  }
115
- exports.default = FileSystemLoader;