postcss-modules 7.0.0 → 8.3.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/.husky/pre-commit +1 -0
- package/.swcrc +11 -0
- package/CHANGELOG.md +95 -61
- package/README.md +30 -14
- package/build/FileSystemLoader.js +100 -97
- package/build/Parser.js +66 -64
- package/build/fs.js +25 -14
- package/build/index.js +11 -9
- package/build/localsConvention.js +52 -32
- package/build/pluginFactory.js +80 -69
- package/build/saveJSON.js +13 -11
- package/build/scoping.js +74 -49
- package/build/unquote.js +18 -15
- package/eslint.config.mjs +26 -0
- package/index.d.ts +3 -1
- package/jest.config.js +5 -0
- package/package.json +68 -67
- package/.claude/scheduled_tasks.lock +0 -1
- package/.eslintrc.js +0 -19
- package/.idea/codeStyles/Project.xml +0 -58
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/postcss-modules.iml +0 -12
- package/.idea/vcs.xml +0 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npx lint-staged
|
package/.swcrc
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,23 +1,57 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 8.2.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- New `localsConvention` value `'all'` — emit the original class name plus the camelCase and dashes-camelCase variants in one pass.
|
|
8
|
+
- New `localsConvention` value `'none'` — emit only the original class name, with no additional aliases.
|
|
9
|
+
- The function form of `localsConvention` may now return an array of strings. Every entry in the array is added to the locals map and resolves to the same value, which makes it easy to expose a single CSS class under multiple JS-friendly aliases.
|
|
10
|
+
|
|
11
|
+
Adapted from the unmerged work in [#154](https://github.com/madyankin/postcss-modules/pull/154) by @CarbonORM.
|
|
12
|
+
|
|
13
|
+
## 8.1.0
|
|
14
|
+
|
|
15
|
+
### Internal
|
|
16
|
+
|
|
17
|
+
- 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.
|
|
18
|
+
- Pinned transitive `file-type` to v22 via `overrides` to silence `@swc/cli`'s vulnerable dependency chain.
|
|
19
|
+
|
|
20
|
+
## 8.0.0
|
|
21
|
+
|
|
22
|
+
### Breaking
|
|
23
|
+
|
|
24
|
+
- Dropped support for Node.js 18. The minimum supported Node.js version is now 20.
|
|
25
|
+
|
|
26
|
+
### Updated
|
|
27
|
+
|
|
28
|
+
- 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
|
|
29
|
+
- Bumped `postcss-modules-local-by-default` to 4.2 and `postcss-modules-scope` to 3.2.1
|
|
30
|
+
- Pinned transitive `glob` to v12 via `overrides`
|
|
31
|
+
|
|
32
|
+
### Internal
|
|
33
|
+
|
|
34
|
+
- Reformatted source with Prettier 3 (whitespace only)
|
|
35
|
+
- Bumped Babel compile target from Node 10 to Node 18
|
|
36
|
+
|
|
3
37
|
## 7.0.0
|
|
4
38
|
|
|
5
39
|
### Breaking
|
|
6
40
|
|
|
7
|
-
-
|
|
41
|
+
- Dropped support for Node.js 10, 12, 14, and 15. The minimum supported Node.js version is now 18.
|
|
8
42
|
|
|
9
43
|
### Security
|
|
10
44
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
45
|
+
- 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`)
|
|
46
|
+
- Bumped `jest` from 26 to 30 to drop vulnerable `node-notifier`, `sane`, and `jsdom` chains
|
|
13
47
|
|
|
14
48
|
### Internal
|
|
15
49
|
|
|
16
|
-
-
|
|
50
|
+
- Regenerated Jest snapshots for the new `pretty-format` serializer (cosmetic only; emitted CSS and JSON are unchanged)
|
|
17
51
|
|
|
18
52
|
## 6.0.1
|
|
19
53
|
|
|
20
|
-
-
|
|
54
|
+
- Updated dependencies by Bill Collins (@mrginglymus)
|
|
21
55
|
|
|
22
56
|
## 6.0.0
|
|
23
57
|
|
|
@@ -28,8 +62,8 @@ https://github.com/madyankin/postcss-modules/commit/86d8135cb5014d0b2848ef395608
|
|
|
28
62
|
|
|
29
63
|
Parameters:
|
|
30
64
|
|
|
31
|
-
-
|
|
32
|
-
-
|
|
65
|
+
- `file` — a module we want to resolve
|
|
66
|
+
- `importer` — the file that imports the module we want to resolve
|
|
33
67
|
|
|
34
68
|
Return value: `string | null | Promise<string | null>`
|
|
35
69
|
|
|
@@ -48,198 +82,198 @@ postcss([
|
|
|
48
82
|
|
|
49
83
|
### Fixed
|
|
50
84
|
|
|
51
|
-
-
|
|
85
|
+
- #140 "'Failed to obtain root' error on Windows" fixed by Pierre LeMoine (@DrInfiniteExplorer) https://github.com/madyankin/postcss-modules/pull/144
|
|
52
86
|
|
|
53
87
|
### Improved
|
|
54
88
|
|
|
55
|
-
-
|
|
89
|
+
- `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
90
|
|
|
57
91
|
## 5.0.0
|
|
58
92
|
|
|
59
|
-
-
|
|
60
|
-
-
|
|
93
|
+
- Fixed `composes` on Windows by @sapphi-red https://github.com/madyankin/postcss-modules/pull/135
|
|
94
|
+
- 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
95
|
|
|
62
96
|
## 4.3.1
|
|
63
97
|
|
|
64
|
-
-
|
|
98
|
+
- Fixed errors when using shorthand selectors by Felix Bruns (@fxb) https://github.com/madyankin/postcss-modules/pull/130
|
|
65
99
|
|
|
66
100
|
## 4.3.0
|
|
67
101
|
|
|
68
|
-
-
|
|
102
|
+
- Updated the `generic-names` dependency to reduce packages size by Bogdan Chadkin (@TrySound) https://github.com/madyankin/postcss-modules/pull/129
|
|
69
103
|
|
|
70
104
|
## 4.2.2
|
|
71
105
|
|
|
72
|
-
-
|
|
106
|
+
- Fix the build
|
|
73
107
|
|
|
74
108
|
## 4.2.1
|
|
75
109
|
|
|
76
|
-
-
|
|
110
|
+
- Fixed the `resolve` option behaviour by @kamilic https://github.com/madyankin/postcss-modules/pull/127
|
|
77
111
|
|
|
78
112
|
## 4.2.0
|
|
79
113
|
|
|
80
|
-
-
|
|
114
|
+
- Added the `resolve` option to configure lookup paths for composes/from by @kamilic https://github.com/madyankin/postcss-modules/pull/126
|
|
81
115
|
|
|
82
116
|
## 4.1.3
|
|
83
117
|
|
|
84
|
-
-
|
|
118
|
+
- Fixed package contents
|
|
85
119
|
|
|
86
120
|
## 4.1.1
|
|
87
121
|
|
|
88
|
-
-
|
|
122
|
+
- Fixed TypeScript typings by Shuman Lim (@origin-master) https://github.com/madyankin/postcss-modules/pull/124
|
|
89
123
|
|
|
90
124
|
## 4.1.0
|
|
91
125
|
|
|
92
|
-
-
|
|
126
|
+
- Added TypeScript typings by Shuman Lim (@origin-master) https://github.com/madyankin/postcss-modules/pull/123
|
|
93
127
|
|
|
94
128
|
## 4.0.0
|
|
95
129
|
|
|
96
|
-
-
|
|
130
|
+
- Upgraded to PostCSS 8 by Evan You (@yyx990803) https://github.com/css-modules/postcss-modules/pull/114
|
|
97
131
|
|
|
98
132
|
## 3.2.2
|
|
99
133
|
|
|
100
134
|
### Fixed
|
|
101
135
|
|
|
102
|
-
-
|
|
136
|
+
- Fixed user plugins order by Tom Jenkinson (@tjenkinson) https://github.com/css-modules/postcss-modules/pull/112
|
|
103
137
|
|
|
104
138
|
## 3.2.1
|
|
105
139
|
|
|
106
140
|
### Fixed
|
|
107
141
|
|
|
108
|
-
-
|
|
142
|
+
- Fixed an issue when some plugins were running multiple times by Tom Jenkinson (@tjenkinson) https://github.com/css-modules/postcss-modules/pull/111
|
|
109
143
|
|
|
110
144
|
## 3.2.0
|
|
111
145
|
|
|
112
146
|
### Changed
|
|
113
147
|
|
|
114
|
-
-
|
|
148
|
+
- [`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
149
|
|
|
116
150
|
## 3.1.0
|
|
117
151
|
|
|
118
152
|
### Added
|
|
119
153
|
|
|
120
|
-
-
|
|
154
|
+
- Added `exportGlobals` option
|
|
121
155
|
|
|
122
156
|
## 3.0.0
|
|
123
157
|
|
|
124
158
|
### Changed
|
|
125
159
|
|
|
126
|
-
-
|
|
127
|
-
-
|
|
160
|
+
- Dropped `css-modules-loader-core` dependency
|
|
161
|
+
- [Upgraded all the dependencies](https://github.com/css-modules/postcss-modules/pull/108)
|
|
128
162
|
|
|
129
163
|
### Breaking changes
|
|
130
164
|
|
|
131
|
-
-
|
|
165
|
+
- Dropped support for unsupported Node versions. Supported versions are 10, 12 and 14+ https://nodejs.org/en/about/releases/
|
|
132
166
|
|
|
133
167
|
## 2.0.0
|
|
134
168
|
|
|
135
169
|
### Added
|
|
136
170
|
|
|
137
|
-
-
|
|
171
|
+
- [`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
172
|
|
|
139
173
|
### Breaking changes
|
|
140
174
|
|
|
141
|
-
-
|
|
175
|
+
- `camelCase` camelCase removed, use the [`localsConvention` option](https://github.com/css-modules/postcss-modules#localsconvention) instead.
|
|
142
176
|
|
|
143
177
|
## 1.5.0
|
|
144
178
|
|
|
145
|
-
-
|
|
179
|
+
- Added `hashPrefix` option by Jesse Thomson (@jessethomson) <https://github.com/css-modules/postcss-modules/pull/98>
|
|
146
180
|
|
|
147
181
|
## 1.4.1
|
|
148
182
|
|
|
149
|
-
-
|
|
183
|
+
- Rebublished the previous release. Sorry :(
|
|
150
184
|
|
|
151
185
|
## 1.4.0
|
|
152
186
|
|
|
153
|
-
-
|
|
187
|
+
- 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
188
|
|
|
155
189
|
## 1.3.1
|
|
156
190
|
|
|
157
|
-
-
|
|
191
|
+
- Move dev tools to devDependecies by Anton Khlynovskiy (@ubzey) <https://github.com/css-modules/postcss-modules/pull/85>
|
|
158
192
|
|
|
159
193
|
## 1.3.0
|
|
160
194
|
|
|
161
|
-
-
|
|
162
|
-
-
|
|
195
|
+
- Updated dependecies
|
|
196
|
+
- Added prettier to format code
|
|
163
197
|
|
|
164
198
|
## 1.2.0
|
|
165
199
|
|
|
166
|
-
-
|
|
200
|
+
- Added option to transform classes to camelCase by Igor Ribeiro (@igor-ribeiro) <https://github.com/css-modules/postcss-modules/pull/82>
|
|
167
201
|
|
|
168
202
|
## 1.1.0
|
|
169
203
|
|
|
170
|
-
-
|
|
204
|
+
- Added ability to transmit outputFileName into getJSON by @lutien <https://github.com/css-modules/postcss-modules/pull/72>
|
|
171
205
|
|
|
172
206
|
## 1.0.0
|
|
173
207
|
|
|
174
|
-
-
|
|
175
|
-
-
|
|
208
|
+
- Dropped support for Node < 6
|
|
209
|
+
- Updated dependencies
|
|
176
210
|
|
|
177
211
|
## 0.8.0
|
|
178
212
|
|
|
179
|
-
-
|
|
213
|
+
- Updated PostCSS to 6 by Alexey Litvinov (@sullenor) <https://github.com/css-modules/postcss-modules/pull/65>
|
|
180
214
|
|
|
181
215
|
## 0.7.1
|
|
182
216
|
|
|
183
|
-
-
|
|
217
|
+
- Allowed empty string as opts.root by Sharon Rolel (@Mosho1) <https://github.com/css-modules/postcss-modules/pull/56>
|
|
184
218
|
|
|
185
219
|
## 0.7.0
|
|
186
220
|
|
|
187
|
-
-
|
|
221
|
+
- Allow async getJSON by Philipp A. (@flying-sheep) <https://github.com/css-modules/postcss-modules/pull/59>
|
|
188
222
|
|
|
189
223
|
## 0.6.4
|
|
190
224
|
|
|
191
|
-
-
|
|
225
|
+
- Added the `root` option to pass the root path by Sharon Rolel (@Mosho1) (<https://github.com/css-modules/postcss-modules/pull/55>)
|
|
192
226
|
|
|
193
227
|
## 0.6.3
|
|
194
228
|
|
|
195
|
-
-
|
|
229
|
+
- Fixed regression in `isValidBehaviour` function (<https://github.com/css-modules/postcss-modules/issues/53>)
|
|
196
230
|
|
|
197
231
|
## 0.6.2
|
|
198
232
|
|
|
199
|
-
-
|
|
233
|
+
- Refactored `getDefaultPluginsList` function
|
|
200
234
|
|
|
201
235
|
## 0.6.1
|
|
202
236
|
|
|
203
|
-
-
|
|
237
|
+
- Fixed `generateScopedName` bug with multiple postcss-modules instances (<https://github.com/css-modules/postcss-modules/issues/37>)
|
|
204
238
|
|
|
205
239
|
## 0.6.0
|
|
206
240
|
|
|
207
|
-
-
|
|
208
|
-
-
|
|
241
|
+
- Added `globalModulePaths` option (Thanks to @pospi).
|
|
242
|
+
- Refactored all the things.
|
|
209
243
|
|
|
210
244
|
## 0.5.2
|
|
211
245
|
|
|
212
|
-
-
|
|
246
|
+
- Updated dependencies
|
|
213
247
|
|
|
214
248
|
## 0.5.1
|
|
215
249
|
|
|
216
|
-
-
|
|
250
|
+
- Fixed sorting for composed dependencies by Josh Johnston (@joshwnj) (<https://github.com/css-modules/postcss-modules/issues/38>)
|
|
217
251
|
|
|
218
252
|
## 0.5.0
|
|
219
253
|
|
|
220
|
-
-
|
|
221
|
-
-
|
|
222
|
-
-
|
|
254
|
+
- Added `scopeBehaviour` option (<https://github.com/css-modules/postcss-modules/issues/22>)
|
|
255
|
+
- Added ability to pass a string to `generateScopedName` (<https://github.com/css-modules/postcss-modules/issues/21>)
|
|
256
|
+
- Updated dependencies
|
|
223
257
|
|
|
224
258
|
## 0.4.1
|
|
225
259
|
|
|
226
|
-
-
|
|
260
|
+
- Fixed processing errors capturing by Boris Serdiuk (@just-boris)
|
|
227
261
|
|
|
228
262
|
## 0.4.0
|
|
229
263
|
|
|
230
|
-
-
|
|
264
|
+
- Added support for custom loaders by Björn Brauer (@ZauberNerd)
|
|
231
265
|
|
|
232
266
|
## 0.3.0
|
|
233
267
|
|
|
234
|
-
-
|
|
235
|
-
-
|
|
268
|
+
- Fixed processing for imported CSS
|
|
269
|
+
- Added default callback for saving exported JSON
|
|
236
270
|
|
|
237
271
|
## 0.2.0
|
|
238
272
|
|
|
239
|
-
-
|
|
240
|
-
-
|
|
241
|
-
-
|
|
242
|
-
-
|
|
273
|
+
- Fixed JSON export with shallow imports (<https://github.com/outpunk/postcss-modules/issues/12>)
|
|
274
|
+
- Fixed lookup paths (<https://github.com/outpunk/postcss-modules/issues/13>)
|
|
275
|
+
- Fixed imports overriding (<https://github.com/outpunk/postcss-modules/issues/15>)
|
|
276
|
+
- Global refactoring under the hood
|
|
243
277
|
|
|
244
278
|
## 0.1.3
|
|
245
279
|
|
package/README.md
CHANGED
|
@@ -191,7 +191,7 @@ postcss([
|
|
|
191
191
|
|
|
192
192
|
### localsConvention
|
|
193
193
|
|
|
194
|
-
Type: `String | (originalClassName: string, generatedClassName: string, inputFile: string) =>
|
|
194
|
+
Type: `String | (originalClassName: string, generatedClassName: string, inputFile: string) => string | string[]`
|
|
195
195
|
Default: `null`
|
|
196
196
|
|
|
197
197
|
Style of exported classnames, the keys in your json.
|
|
@@ -202,8 +202,30 @@ Style of exported classnames, the keys in your json.
|
|
|
202
202
|
| **`'camelCaseOnly'`** | `{String}` | Class names will be camelized, the original class name will be removed from the locals |
|
|
203
203
|
| **`'dashes'`** | `{String}` | Only dashes in class names will be camelized |
|
|
204
204
|
| **`'dashesOnly'`** | `{String}` | Dashes in class names will be camelized, the original class name will be removed from the locals |
|
|
205
|
+
| **`'all'`** | `{String}` | Emit the original class name plus the camelCase and dashes-camelCase variants |
|
|
206
|
+
| **`'none'`** | `{String}` | Emit only the original class name (equivalent to leaving `localsConvention` unset) |
|
|
205
207
|
|
|
206
|
-
|
|
208
|
+
For an input class `foo-bar` resolving to scoped name `_a`:
|
|
209
|
+
|
|
210
|
+
| Mode | Emitted locals |
|
|
211
|
+
| --------------- | ------------------------------------------------------------------------------------------- |
|
|
212
|
+
| `camelCase` | `{ "foo-bar": "_a", "fooBar": "_a" }` |
|
|
213
|
+
| `camelCaseOnly` | `{ "fooBar": "_a" }` |
|
|
214
|
+
| `dashes` | `{ "foo-bar": "_a", "fooBar": "_a" }` |
|
|
215
|
+
| `dashesOnly` | `{ "fooBar": "_a" }` |
|
|
216
|
+
| `all` | `{ "foo-bar": "_a", "fooBar": "_a" }` (camelCase + dashesCamelCase collapse for this input) |
|
|
217
|
+
| `none` | `{ "foo-bar": "_a" }` |
|
|
218
|
+
|
|
219
|
+
In lieu of a string, a custom function can generate the exported class names. The function may return either a single string or an array of strings; when an array is returned every entry is added to the locals map and resolves to the same value:
|
|
220
|
+
|
|
221
|
+
```js
|
|
222
|
+
postcss([
|
|
223
|
+
require("postcss-modules")({
|
|
224
|
+
localsConvention: (original, generated) => [original, generated, original.toUpperCase()],
|
|
225
|
+
}),
|
|
226
|
+
]);
|
|
227
|
+
// .foo-bar { ... } → { "foo-bar": "_a", "_a": "_a", "FOO-BAR": "_a" }
|
|
228
|
+
```
|
|
207
229
|
|
|
208
230
|
### Resolve path alias
|
|
209
231
|
|
|
@@ -212,8 +234,8 @@ It's useful when you need to resolve custom path alias.
|
|
|
212
234
|
|
|
213
235
|
Parameters:
|
|
214
236
|
|
|
215
|
-
-
|
|
216
|
-
-
|
|
237
|
+
- `file` — a module we want to resolve
|
|
238
|
+
- `importer` — the file that imports the module we want to resolve
|
|
217
239
|
|
|
218
240
|
Return value: `string | null | Promise<string | null>`
|
|
219
241
|
|
|
@@ -267,9 +289,7 @@ And you'll get the following HTML:
|
|
|
267
289
|
|
|
268
290
|
```html
|
|
269
291
|
<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>
|
|
292
|
+
<article class="_article_xkpkl_10">A PostCSS plugin to use CSS Modules everywhere</article>
|
|
273
293
|
```
|
|
274
294
|
|
|
275
295
|
### HTML
|
|
@@ -284,9 +304,7 @@ Here is our template `about.html`:
|
|
|
284
304
|
|
|
285
305
|
```html
|
|
286
306
|
<h1 css-module="title">postcss-modules</h1>
|
|
287
|
-
<article css-module="article">
|
|
288
|
-
A PostCSS plugin to use CSS Modules everywhere
|
|
289
|
-
</article>
|
|
307
|
+
<article css-module="article">A PostCSS plugin to use CSS Modules everywhere</article>
|
|
290
308
|
```
|
|
291
309
|
|
|
292
310
|
Transform it:
|
|
@@ -310,9 +328,7 @@ And you'll get the following HTML:
|
|
|
310
328
|
|
|
311
329
|
```html
|
|
312
330
|
<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>
|
|
331
|
+
<article class="_article_xkpkl_10">A PostCSS plugin to use CSS Modules everywhere</article>
|
|
316
332
|
```
|
|
317
333
|
|
|
318
334
|
## May I see the plugin in action?
|
|
@@ -329,4 +345,4 @@ npm install --save-dev postcss postcss-modules
|
|
|
329
345
|
|
|
330
346
|
## Sponsors
|
|
331
347
|
|
|
332
|
-
-
|
|
348
|
+
- 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
|
-
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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;
|