@atlaspack/transformer-postcss 2.14.21 → 2.14.22-typescript-17c3d1dec.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/lib/PostCSSTransformer.d.ts +3 -0
- package/lib/PostCSSTransformer.js +21 -21
- package/lib/constants.d.ts +1 -0
- package/lib/loadConfig.d.ts +17 -0
- package/lib/loadConfig.js +6 -0
- package/lib/loadPlugins.d.ts +4 -0
- package/lib/loadPlugins.js +3 -1
- package/package.json +14 -9
- package/src/{PostCSSTransformer.js → PostCSSTransformer.ts} +30 -24
- package/src/{constants.js → constants.ts} +0 -2
- package/src/{loadConfig.js → loadConfig.ts} +22 -18
- package/src/{loadPlugins.js → loadPlugins.ts} +10 -7
- package/tsconfig.json +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright (c) 2024 Atlassian US., Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -129,33 +129,32 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
129
129
|
if (!config) {
|
|
130
130
|
return [asset];
|
|
131
131
|
}
|
|
132
|
+
|
|
133
|
+
// @ts-expect-error TS2709
|
|
132
134
|
const postcss = await loadPostcss(options, asset.filePath);
|
|
133
135
|
let ast = (0, _nullthrows().default)(await asset.getAST());
|
|
134
136
|
let program = postcss.fromJSON(ast.program);
|
|
135
|
-
|
|
136
|
-
// $FlowFixMe
|
|
137
137
|
let plugins = [...config.hydrated.plugins];
|
|
138
138
|
let cssModules = null;
|
|
139
|
-
// $FlowFixMe
|
|
140
139
|
if (config.hydrated.modules) {
|
|
141
140
|
asset.meta.cssModulesCompiled = 'postcss';
|
|
142
141
|
let code = asset.isASTDirty() ? null : await asset.getCode();
|
|
143
|
-
if (
|
|
144
|
-
// $FlowFixMe
|
|
145
|
-
Object.keys(config.hydrated.modules).length === 0 && code && !isLegacy && !LEGACY_MODULE_RE.test(code)) {
|
|
146
|
-
// $FlowFixMe
|
|
142
|
+
if (Object.keys(config.hydrated.modules).length === 0 && code && !isLegacy && !LEGACY_MODULE_RE.test(code)) {
|
|
147
143
|
let filename = _path().default.basename(config.filePath);
|
|
148
144
|
let message;
|
|
149
145
|
let configKey;
|
|
150
146
|
let hint;
|
|
151
|
-
// $FlowFixMe
|
|
152
147
|
if (config.raw.modules) {
|
|
148
|
+
// @ts-expect-error TS2345
|
|
153
149
|
message = (0, _diagnostic().md)`The "modules" option in __${filename}__ can be replaced with configuration for @atlaspack/transformer-css to improve build performance.`;
|
|
154
150
|
configKey = '/modules';
|
|
151
|
+
// @ts-expect-error TS2345
|
|
155
152
|
hint = (0, _diagnostic().md)`Remove the "modules" option from __${filename}__`;
|
|
156
153
|
} else {
|
|
154
|
+
// @ts-expect-error TS2345
|
|
157
155
|
message = (0, _diagnostic().md)`The "postcss-modules" plugin in __${filename}__ can be replaced with configuration for @atlaspack/transformer-css to improve build performance.`;
|
|
158
156
|
configKey = '/plugins/postcss-modules';
|
|
157
|
+
// @ts-expect-error TS2345
|
|
159
158
|
hint = (0, _diagnostic().md)`Remove the "postcss-modules" plugin from __${filename}__`;
|
|
160
159
|
}
|
|
161
160
|
if (filename === 'package.json') {
|
|
@@ -163,18 +162,18 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
163
162
|
}
|
|
164
163
|
let hints = ['Enable the "cssModules" option for "@atlaspack/transformer-css" in your package.json'];
|
|
165
164
|
if (plugins.length === 0) {
|
|
165
|
+
// @ts-expect-error TS2345
|
|
166
166
|
message += (0, _diagnostic().md)` Since there are no other plugins, __${filename}__ can be deleted safely.`;
|
|
167
|
+
// @ts-expect-error TS2345
|
|
167
168
|
hints.push((0, _diagnostic().md)`Delete __${filename}__`);
|
|
168
169
|
} else {
|
|
169
170
|
hints.push(hint);
|
|
170
171
|
}
|
|
171
172
|
let codeFrames;
|
|
172
173
|
if (_path().default.extname(filename) !== '.js') {
|
|
173
|
-
// $FlowFixMe
|
|
174
174
|
let contents = await asset.fs.readFile(config.filePath, 'utf8');
|
|
175
175
|
codeFrames = [{
|
|
176
176
|
language: 'json',
|
|
177
|
-
// $FlowFixMe
|
|
178
177
|
filePath: config.filePath,
|
|
179
178
|
code: contents,
|
|
180
179
|
codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(contents, [{
|
|
@@ -184,7 +183,6 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
184
183
|
}];
|
|
185
184
|
} else {
|
|
186
185
|
codeFrames = [{
|
|
187
|
-
// $FlowFixMe
|
|
188
186
|
filePath: config.filePath,
|
|
189
187
|
codeHighlights: [{
|
|
190
188
|
start: {
|
|
@@ -213,13 +211,15 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
213
211
|
shouldAutoInstall: options.shouldAutoInstall
|
|
214
212
|
});
|
|
215
213
|
plugins.push(postcssModules({
|
|
214
|
+
// @ts-expect-error TS7006
|
|
216
215
|
getJSON: (filename, json) => cssModules = json,
|
|
217
216
|
Loader: await createLoader(asset, resolve, options),
|
|
217
|
+
// @ts-expect-error TS7006
|
|
218
218
|
generateScopedName: (name, filename) => `${name}_${(0, _rust().hashString)(_path().default.relative(options.projectRoot, filename)).substr(0, 6)}`,
|
|
219
|
-
// $FlowFixMe
|
|
220
219
|
...config.hydrated.modules
|
|
221
220
|
}));
|
|
222
221
|
if (code == null || COMPOSES_RE.test(code)) {
|
|
222
|
+
// @ts-expect-error TS7006
|
|
223
223
|
program.walkDecls(decl => {
|
|
224
224
|
let [, importPath] = FROM_IMPORT_RE.exec(decl.value) || [];
|
|
225
225
|
if (decl.prop === 'composes' && importPath != null) {
|
|
@@ -244,14 +244,10 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
244
244
|
});
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
|
|
248
|
-
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
|
|
249
247
|
let {
|
|
250
248
|
messages,
|
|
251
249
|
root
|
|
252
|
-
} = await postcss(plugins).process(program,
|
|
253
|
-
// $FlowFixMe
|
|
254
|
-
config.hydrated);
|
|
250
|
+
} = await postcss(plugins).process(program, config.hydrated);
|
|
255
251
|
asset.setAST({
|
|
256
252
|
type: 'postcss',
|
|
257
253
|
version: '8.2.1',
|
|
@@ -275,7 +271,6 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
275
271
|
}
|
|
276
272
|
let assets = [asset];
|
|
277
273
|
if (cssModules) {
|
|
278
|
-
// $FlowFixMe
|
|
279
274
|
let cssModulesList = Object.entries(cssModules);
|
|
280
275
|
let deps = asset.getDependencies().filter(dep => dep.priority === 'sync');
|
|
281
276
|
let code;
|
|
@@ -290,11 +285,14 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
290
285
|
}
|
|
291
286
|
asset.symbols.ensure();
|
|
292
287
|
for (let [k, v] of cssModulesList) {
|
|
288
|
+
// @ts-expect-error TS2345
|
|
293
289
|
asset.symbols.set(k, v);
|
|
294
290
|
}
|
|
291
|
+
// @ts-expect-error TS2345
|
|
295
292
|
asset.symbols.set('default', 'default');
|
|
296
293
|
assets.push({
|
|
297
294
|
type: 'js',
|
|
295
|
+
// @ts-expect-error TS2353
|
|
298
296
|
content: code
|
|
299
297
|
});
|
|
300
298
|
}
|
|
@@ -305,8 +303,10 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
305
303
|
ast,
|
|
306
304
|
options
|
|
307
305
|
}) {
|
|
306
|
+
// @ts-expect-error TS2709
|
|
308
307
|
const postcss = await loadPostcss(options, asset.filePath);
|
|
309
308
|
let code = '';
|
|
309
|
+
// @ts-expect-error TS7006
|
|
310
310
|
postcss.stringify(postcss.fromJSON(ast.program), c => {
|
|
311
311
|
code += c;
|
|
312
312
|
});
|
|
@@ -333,9 +333,7 @@ async function createLoader(asset, resolve, options) {
|
|
|
333
333
|
let source = await asset.fs.readFile(resolved, 'utf-8');
|
|
334
334
|
let {
|
|
335
335
|
exportTokens
|
|
336
|
-
} = await this.core.load(source, rootRelativePath, undefined,
|
|
337
|
-
// $FlowFixMe[method-unbinding]
|
|
338
|
-
this.fetch.bind(this));
|
|
336
|
+
} = await this.core.load(source, rootRelativePath, undefined, this.fetch.bind(this));
|
|
339
337
|
return exportTokens;
|
|
340
338
|
}
|
|
341
339
|
get finalSource() {
|
|
@@ -343,6 +341,8 @@ async function createLoader(asset, resolve, options) {
|
|
|
343
341
|
}
|
|
344
342
|
};
|
|
345
343
|
}
|
|
344
|
+
|
|
345
|
+
// @ts-expect-error TS2709
|
|
346
346
|
function loadPostcss(options, from) {
|
|
347
347
|
return options.packageManager.require('postcss', from, {
|
|
348
348
|
range: _constants.POSTCSS_RANGE,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const POSTCSS_RANGE = "^8.2.1";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Config, FilePath, PluginOptions, PluginLogger } from '@atlaspack/types';
|
|
2
|
+
type ConfigResult = {
|
|
3
|
+
raw: any;
|
|
4
|
+
filePath: string;
|
|
5
|
+
hydrated: {
|
|
6
|
+
plugins: Array<any>;
|
|
7
|
+
from: FilePath;
|
|
8
|
+
to: FilePath;
|
|
9
|
+
modules: any;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function load({ config, options, logger, }: {
|
|
13
|
+
config: Config;
|
|
14
|
+
options: PluginOptions;
|
|
15
|
+
logger: PluginLogger;
|
|
16
|
+
}): Promise<ConfigResult | null | undefined>;
|
|
17
|
+
export {};
|
package/lib/loadConfig.js
CHANGED
|
@@ -35,6 +35,8 @@ function _clone() {
|
|
|
35
35
|
var _constants = require("./constants");
|
|
36
36
|
var _loadPlugins = _interopRequireDefault(require("./loadPlugins"));
|
|
37
37
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
38
|
+
// @ts-expect-error TS7016
|
|
39
|
+
|
|
38
40
|
async function configHydrator(configFile, config, resolveFrom, options, logger) {
|
|
39
41
|
if (configFile == null) {
|
|
40
42
|
return;
|
|
@@ -72,10 +74,14 @@ async function configHydrator(configFile, config, resolveFrom, options, logger)
|
|
|
72
74
|
let message;
|
|
73
75
|
let hints = [];
|
|
74
76
|
if (!isPackageJson && redundantPlugins.length === pluginArray.length) {
|
|
77
|
+
// @ts-expect-error TS2345
|
|
75
78
|
message = (0, _diagnostic().md)`Parcel includes CSS transpilation and vendor prefixing by default. PostCSS config __${filename}__ contains only redundant plugins. Deleting it may significantly improve build performance.`;
|
|
79
|
+
// @ts-expect-error TS2345
|
|
76
80
|
hints.push((0, _diagnostic().md)`Delete __${filename}__`);
|
|
77
81
|
} else {
|
|
82
|
+
// @ts-expect-error TS2345
|
|
78
83
|
message = (0, _diagnostic().md)`Parcel includes CSS transpilation and vendor prefixing by default. PostCSS config __${filename}__ contains the following redundant plugins: ${[...redundantPlugins].map(p => _diagnostic().md.underline(p))}. Removing these may improve build performance.`;
|
|
84
|
+
// @ts-expect-error TS2345
|
|
79
85
|
hints.push((0, _diagnostic().md)`Remove the above plugins from __${filename}__`);
|
|
80
86
|
}
|
|
81
87
|
let codeFrames;
|
package/lib/loadPlugins.js
CHANGED
|
@@ -15,7 +15,9 @@ async function loadExternalPlugins(plugins, relative, options) {
|
|
|
15
15
|
return [];
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
async function loadPlugin(pluginArg, relative, options = {}, packageManager, shouldAutoInstall
|
|
18
|
+
async function loadPlugin(pluginArg, relative, options = {}, packageManager, shouldAutoInstall
|
|
19
|
+
// @ts-expect-error TS1064
|
|
20
|
+
) {
|
|
19
21
|
if (typeof pluginArg !== 'string') {
|
|
20
22
|
return pluginArg;
|
|
21
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/transformer-postcss",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.22-typescript-17c3d1dec.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -9,16 +9,17 @@
|
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
11
11
|
},
|
|
12
|
-
"main": "lib/PostCSSTransformer.js",
|
|
13
|
-
"source": "src/PostCSSTransformer.
|
|
12
|
+
"main": "./lib/PostCSSTransformer.js",
|
|
13
|
+
"source": "./src/PostCSSTransformer.ts",
|
|
14
|
+
"types": "./lib/PostCSSTransformer.d.ts",
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">= 16.0.0"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@atlaspack/diagnostic": "2.14.
|
|
19
|
-
"@atlaspack/plugin": "2.14.
|
|
20
|
-
"@atlaspack/rust": "3.4.
|
|
21
|
-
"@atlaspack/utils": "2.17.
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.2-typescript-17c3d1dec.0",
|
|
20
|
+
"@atlaspack/plugin": "2.14.22-typescript-17c3d1dec.0",
|
|
21
|
+
"@atlaspack/rust": "3.4.2-typescript-17c3d1dec.0",
|
|
22
|
+
"@atlaspack/utils": "2.17.4-typescript-17c3d1dec.0",
|
|
22
23
|
"clone": "^2.1.1",
|
|
23
24
|
"nullthrows": "^1.1.1",
|
|
24
25
|
"postcss-value-parser": "^4.2.0",
|
|
@@ -28,5 +29,9 @@
|
|
|
28
29
|
"postcss": "^8.4.5",
|
|
29
30
|
"postcss-modules": "^4.3.1"
|
|
30
31
|
},
|
|
31
|
-
"type": "commonjs"
|
|
32
|
-
|
|
32
|
+
"type": "commonjs",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "17c3d1decf641e688fcfe3ca985e80e9897b7573"
|
|
37
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import type {
|
|
4
2
|
FilePath,
|
|
5
3
|
Asset,
|
|
@@ -14,7 +12,7 @@ import nullthrows from 'nullthrows';
|
|
|
14
12
|
import path from 'path';
|
|
15
13
|
import semver from 'semver';
|
|
16
14
|
import valueParser from 'postcss-value-parser';
|
|
17
|
-
import
|
|
15
|
+
import * as Postcss from 'postcss';
|
|
18
16
|
|
|
19
17
|
import {load} from './loadConfig';
|
|
20
18
|
import {POSTCSS_RANGE} from './constants';
|
|
@@ -25,7 +23,7 @@ const FROM_IMPORT_RE = /.+from\s*(?:"|')(.*)(?:"|')\s*;?/;
|
|
|
25
23
|
const LEGACY_MODULE_RE = /@value|:export|(:global|:local|:import)(?!\s*\()/i;
|
|
26
24
|
const MODULE_BY_NAME_RE = /\.module\./;
|
|
27
25
|
|
|
28
|
-
export default
|
|
26
|
+
export default new Transformer({
|
|
29
27
|
loadConfig({config, options, logger}) {
|
|
30
28
|
return load({config, options, logger});
|
|
31
29
|
},
|
|
@@ -77,38 +75,43 @@ export default (new Transformer({
|
|
|
77
75
|
return [asset];
|
|
78
76
|
}
|
|
79
77
|
|
|
78
|
+
// @ts-expect-error TS2709
|
|
80
79
|
const postcss: Postcss = await loadPostcss(options, asset.filePath);
|
|
81
80
|
let ast = nullthrows(await asset.getAST());
|
|
82
81
|
let program = postcss.fromJSON(ast.program);
|
|
83
82
|
|
|
84
|
-
// $FlowFixMe
|
|
85
83
|
let plugins = [...config.hydrated.plugins];
|
|
86
|
-
let cssModules:
|
|
87
|
-
|
|
84
|
+
let cssModules:
|
|
85
|
+
| {
|
|
86
|
+
[key: string]: string;
|
|
87
|
+
}
|
|
88
|
+
| null
|
|
89
|
+
| undefined = null;
|
|
88
90
|
if (config.hydrated.modules) {
|
|
89
91
|
asset.meta.cssModulesCompiled = 'postcss';
|
|
90
92
|
|
|
91
93
|
let code = asset.isASTDirty() ? null : await asset.getCode();
|
|
92
94
|
if (
|
|
93
|
-
// $FlowFixMe
|
|
94
95
|
Object.keys(config.hydrated.modules).length === 0 &&
|
|
95
96
|
code &&
|
|
96
97
|
!isLegacy &&
|
|
97
98
|
!LEGACY_MODULE_RE.test(code)
|
|
98
99
|
) {
|
|
99
|
-
// $FlowFixMe
|
|
100
100
|
let filename = path.basename(config.filePath);
|
|
101
101
|
let message;
|
|
102
102
|
let configKey;
|
|
103
103
|
let hint;
|
|
104
|
-
// $FlowFixMe
|
|
105
104
|
if (config.raw.modules) {
|
|
105
|
+
// @ts-expect-error TS2345
|
|
106
106
|
message = md`The "modules" option in __${filename}__ can be replaced with configuration for @atlaspack/transformer-css to improve build performance.`;
|
|
107
107
|
configKey = '/modules';
|
|
108
|
+
// @ts-expect-error TS2345
|
|
108
109
|
hint = md`Remove the "modules" option from __${filename}__`;
|
|
109
110
|
} else {
|
|
111
|
+
// @ts-expect-error TS2345
|
|
110
112
|
message = md`The "postcss-modules" plugin in __${filename}__ can be replaced with configuration for @atlaspack/transformer-css to improve build performance.`;
|
|
111
113
|
configKey = '/plugins/postcss-modules';
|
|
114
|
+
// @ts-expect-error TS2345
|
|
112
115
|
hint = md`Remove the "postcss-modules" plugin from __${filename}__`;
|
|
113
116
|
}
|
|
114
117
|
if (filename === 'package.json') {
|
|
@@ -119,7 +122,9 @@ export default (new Transformer({
|
|
|
119
122
|
'Enable the "cssModules" option for "@atlaspack/transformer-css" in your package.json',
|
|
120
123
|
];
|
|
121
124
|
if (plugins.length === 0) {
|
|
125
|
+
// @ts-expect-error TS2345
|
|
122
126
|
message += md` Since there are no other plugins, __${filename}__ can be deleted safely.`;
|
|
127
|
+
// @ts-expect-error TS2345
|
|
123
128
|
hints.push(md`Delete __${filename}__`);
|
|
124
129
|
} else {
|
|
125
130
|
hints.push(hint);
|
|
@@ -127,12 +132,10 @@ export default (new Transformer({
|
|
|
127
132
|
|
|
128
133
|
let codeFrames;
|
|
129
134
|
if (path.extname(filename) !== '.js') {
|
|
130
|
-
// $FlowFixMe
|
|
131
135
|
let contents = await asset.fs.readFile(config.filePath, 'utf8');
|
|
132
136
|
codeFrames = [
|
|
133
137
|
{
|
|
134
138
|
language: 'json',
|
|
135
|
-
// $FlowFixMe
|
|
136
139
|
filePath: config.filePath,
|
|
137
140
|
code: contents,
|
|
138
141
|
codeHighlights: generateJSONCodeHighlights(contents, [
|
|
@@ -146,7 +149,6 @@ export default (new Transformer({
|
|
|
146
149
|
} else {
|
|
147
150
|
codeFrames = [
|
|
148
151
|
{
|
|
149
|
-
// $FlowFixMe
|
|
150
152
|
filePath: config.filePath,
|
|
151
153
|
codeHighlights: [
|
|
152
154
|
{
|
|
@@ -180,18 +182,20 @@ export default (new Transformer({
|
|
|
180
182
|
|
|
181
183
|
plugins.push(
|
|
182
184
|
postcssModules({
|
|
185
|
+
// @ts-expect-error TS7006
|
|
183
186
|
getJSON: (filename, json) => (cssModules = json),
|
|
184
187
|
Loader: await createLoader(asset, resolve, options),
|
|
188
|
+
// @ts-expect-error TS7006
|
|
185
189
|
generateScopedName: (name, filename) =>
|
|
186
190
|
`${name}_${hashString(
|
|
187
191
|
path.relative(options.projectRoot, filename),
|
|
188
192
|
).substr(0, 6)}`,
|
|
189
|
-
// $FlowFixMe
|
|
190
193
|
...config.hydrated.modules,
|
|
191
194
|
}),
|
|
192
195
|
);
|
|
193
196
|
|
|
194
197
|
if (code == null || COMPOSES_RE.test(code)) {
|
|
198
|
+
// @ts-expect-error TS7006
|
|
195
199
|
program.walkDecls((decl) => {
|
|
196
200
|
let [, importPath] = FROM_IMPORT_RE.exec(decl.value) || [];
|
|
197
201
|
if (decl.prop === 'composes' && importPath != null) {
|
|
@@ -218,10 +222,8 @@ export default (new Transformer({
|
|
|
218
222
|
}
|
|
219
223
|
}
|
|
220
224
|
|
|
221
|
-
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
|
|
222
225
|
let {messages, root} = await postcss(plugins).process(
|
|
223
226
|
program,
|
|
224
|
-
// $FlowFixMe
|
|
225
227
|
config.hydrated,
|
|
226
228
|
);
|
|
227
229
|
asset.setAST({
|
|
@@ -244,10 +246,9 @@ export default (new Transformer({
|
|
|
244
246
|
|
|
245
247
|
let assets = [asset];
|
|
246
248
|
if (cssModules) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
>);
|
|
249
|
+
let cssModulesList = Object.entries(cssModules) as Array<
|
|
250
|
+
[string, string]
|
|
251
|
+
>;
|
|
251
252
|
let deps = asset
|
|
252
253
|
.getDependencies()
|
|
253
254
|
.filter((dep) => dep.priority === 'sync');
|
|
@@ -262,7 +263,7 @@ export default (new Transformer({
|
|
|
262
263
|
code = cssModulesList
|
|
263
264
|
.map(
|
|
264
265
|
// This syntax enables shaking the invidual statements, so that unused classes don't even exist in JS.
|
|
265
|
-
([className, classNameHashed]) =>
|
|
266
|
+
([className, classNameHashed]: [any, any]) =>
|
|
266
267
|
`module.exports[${JSON.stringify(className)}] = ${JSON.stringify(
|
|
267
268
|
classNameHashed,
|
|
268
269
|
)};`,
|
|
@@ -272,12 +273,15 @@ export default (new Transformer({
|
|
|
272
273
|
|
|
273
274
|
asset.symbols.ensure();
|
|
274
275
|
for (let [k, v] of cssModulesList) {
|
|
276
|
+
// @ts-expect-error TS2345
|
|
275
277
|
asset.symbols.set(k, v);
|
|
276
278
|
}
|
|
279
|
+
// @ts-expect-error TS2345
|
|
277
280
|
asset.symbols.set('default', 'default');
|
|
278
281
|
|
|
279
282
|
assets.push({
|
|
280
283
|
type: 'js',
|
|
284
|
+
// @ts-expect-error TS2353
|
|
281
285
|
content: code,
|
|
282
286
|
});
|
|
283
287
|
}
|
|
@@ -285,9 +289,11 @@ export default (new Transformer({
|
|
|
285
289
|
},
|
|
286
290
|
|
|
287
291
|
async generate({asset, ast, options}) {
|
|
292
|
+
// @ts-expect-error TS2709
|
|
288
293
|
const postcss: Postcss = await loadPostcss(options, asset.filePath);
|
|
289
294
|
|
|
290
295
|
let code = '';
|
|
296
|
+
// @ts-expect-error TS7006
|
|
291
297
|
postcss.stringify(postcss.fromJSON(ast.program), (c) => {
|
|
292
298
|
code += c;
|
|
293
299
|
});
|
|
@@ -296,7 +302,7 @@ export default (new Transformer({
|
|
|
296
302
|
content: code,
|
|
297
303
|
};
|
|
298
304
|
},
|
|
299
|
-
})
|
|
305
|
+
}) as Transformer<unknown>;
|
|
300
306
|
|
|
301
307
|
async function createLoader(
|
|
302
308
|
asset: MutableAsset,
|
|
@@ -308,7 +314,7 @@ async function createLoader(
|
|
|
308
314
|
asset.filePath,
|
|
309
315
|
);
|
|
310
316
|
return class AtlaspackFileSystemLoader extends FileSystemLoader {
|
|
311
|
-
async fetch(composesPath, relativeTo) {
|
|
317
|
+
async fetch(composesPath: any, relativeTo: any) {
|
|
312
318
|
let importPath = composesPath.replace(/^["']|["']$/g, '');
|
|
313
319
|
let resolved = await resolve(relativeTo, importPath);
|
|
314
320
|
let rootRelativePath = path.resolve(path.dirname(relativeTo), resolved);
|
|
@@ -324,7 +330,6 @@ async function createLoader(
|
|
|
324
330
|
source,
|
|
325
331
|
rootRelativePath,
|
|
326
332
|
undefined,
|
|
327
|
-
// $FlowFixMe[method-unbinding]
|
|
328
333
|
this.fetch.bind(this),
|
|
329
334
|
);
|
|
330
335
|
return exportTokens;
|
|
@@ -336,6 +341,7 @@ async function createLoader(
|
|
|
336
341
|
};
|
|
337
342
|
}
|
|
338
343
|
|
|
344
|
+
// @ts-expect-error TS2709
|
|
339
345
|
function loadPostcss(options: PluginOptions, from: FilePath): Promise<Postcss> {
|
|
340
346
|
return options.packageManager.require('postcss', from, {
|
|
341
347
|
range: POSTCSS_RANGE,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {
|
|
3
2
|
Config,
|
|
4
3
|
FilePath,
|
|
@@ -8,21 +7,22 @@ import type {
|
|
|
8
7
|
import path from 'path';
|
|
9
8
|
import {md, generateJSONCodeHighlights} from '@atlaspack/diagnostic';
|
|
10
9
|
import nullthrows from 'nullthrows';
|
|
10
|
+
// @ts-expect-error TS7016
|
|
11
11
|
import clone from 'clone';
|
|
12
12
|
import {POSTCSS_RANGE} from './constants';
|
|
13
13
|
|
|
14
14
|
import loadExternalPlugins from './loadPlugins';
|
|
15
15
|
|
|
16
|
-
type ConfigResult = {
|
|
17
|
-
raw: any
|
|
18
|
-
filePath: string
|
|
19
|
-
hydrated: {
|
|
20
|
-
plugins: Array<any
|
|
21
|
-
from: FilePath
|
|
22
|
-
to: FilePath
|
|
23
|
-
modules: any
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
type ConfigResult = {
|
|
17
|
+
raw: any;
|
|
18
|
+
filePath: string;
|
|
19
|
+
hydrated: {
|
|
20
|
+
plugins: Array<any>;
|
|
21
|
+
from: FilePath;
|
|
22
|
+
to: FilePath;
|
|
23
|
+
modules: any;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
26
|
|
|
27
27
|
async function configHydrator(
|
|
28
28
|
configFile: any,
|
|
@@ -30,7 +30,7 @@ async function configHydrator(
|
|
|
30
30
|
resolveFrom: FilePath,
|
|
31
31
|
options: PluginOptions,
|
|
32
32
|
logger: PluginLogger,
|
|
33
|
-
): Promise
|
|
33
|
+
): Promise<ConfigResult | null | undefined> {
|
|
34
34
|
if (configFile == null) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
@@ -80,16 +80,20 @@ async function configHydrator(
|
|
|
80
80
|
let filename = path.basename(resolveFrom);
|
|
81
81
|
let isPackageJson = filename === 'package.json';
|
|
82
82
|
let message;
|
|
83
|
-
let hints = [];
|
|
83
|
+
let hints: Array<string> = [];
|
|
84
84
|
if (!isPackageJson && redundantPlugins.length === pluginArray.length) {
|
|
85
|
+
// @ts-expect-error TS2345
|
|
85
86
|
message = md`Parcel includes CSS transpilation and vendor prefixing by default. PostCSS config __${filename}__ contains only redundant plugins. Deleting it may significantly improve build performance.`;
|
|
87
|
+
// @ts-expect-error TS2345
|
|
86
88
|
hints.push(md`Delete __${filename}__`);
|
|
87
89
|
} else {
|
|
90
|
+
// @ts-expect-error TS2345
|
|
88
91
|
message = md`Parcel includes CSS transpilation and vendor prefixing by default. PostCSS config __${filename}__ contains the following redundant plugins: ${[
|
|
89
92
|
...redundantPlugins,
|
|
90
93
|
].map((p) =>
|
|
91
94
|
md.underline(p),
|
|
92
95
|
)}. Removing these may improve build performance.`;
|
|
96
|
+
// @ts-expect-error TS2345
|
|
93
97
|
hints.push(md`Remove the above plugins from __${filename}__`);
|
|
94
98
|
}
|
|
95
99
|
|
|
@@ -149,11 +153,11 @@ export async function load({
|
|
|
149
153
|
config,
|
|
150
154
|
options,
|
|
151
155
|
logger,
|
|
152
|
-
}: {
|
|
153
|
-
config: Config
|
|
154
|
-
options: PluginOptions
|
|
155
|
-
logger: PluginLogger
|
|
156
|
-
|
|
156
|
+
}: {
|
|
157
|
+
config: Config;
|
|
158
|
+
options: PluginOptions;
|
|
159
|
+
logger: PluginLogger;
|
|
160
|
+
}): Promise<ConfigResult | null | undefined> {
|
|
157
161
|
if (!config.isSource) {
|
|
158
162
|
return;
|
|
159
163
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import type {FilePath, PluginOptions} from '@atlaspack/types';
|
|
4
2
|
import type {PackageManager} from '@atlaspack/package-manager';
|
|
5
3
|
|
|
6
4
|
export default async function loadExternalPlugins(
|
|
7
|
-
plugins:
|
|
5
|
+
plugins:
|
|
6
|
+
| Array<string>
|
|
7
|
+
| {
|
|
8
|
+
readonly [pluginName: string]: unknown;
|
|
9
|
+
},
|
|
8
10
|
relative: FilePath,
|
|
9
11
|
options: PluginOptions,
|
|
10
|
-
): Promise<Array<
|
|
12
|
+
): Promise<Array<unknown>> {
|
|
11
13
|
if (Array.isArray(plugins)) {
|
|
12
14
|
return Promise.all(
|
|
13
15
|
plugins
|
|
@@ -42,12 +44,13 @@ export default async function loadExternalPlugins(
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
async function loadPlugin(
|
|
45
|
-
pluginArg: string |
|
|
47
|
+
pluginArg: string | any,
|
|
46
48
|
relative: FilePath,
|
|
47
|
-
options:
|
|
49
|
+
options: unknown | null | undefined = {},
|
|
48
50
|
packageManager: PackageManager,
|
|
49
51
|
shouldAutoInstall: boolean,
|
|
50
|
-
|
|
52
|
+
// @ts-expect-error TS1064
|
|
53
|
+
): unknown {
|
|
51
54
|
if (typeof pluginArg !== 'string') {
|
|
52
55
|
return pluginArg;
|
|
53
56
|
}
|
package/tsconfig.json
ADDED