@atlaspack/transformer-postcss 2.14.5-canary.48 → 2.14.5-canary.481
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/CHANGELOG.md +531 -0
- package/dist/PostCSSTransformer.js +281 -0
- package/dist/constants.js +4 -0
- package/dist/loadConfig.js +149 -0
- package/dist/loadPlugins.js +33 -0
- package/lib/PostCSSTransformer.js +13 -9
- package/lib/loadConfig.js +3 -1
- package/lib/loadPlugins.js +5 -2
- package/lib/types/PostCSSTransformer.d.ts +3 -0
- package/lib/types/constants.d.ts +1 -0
- package/lib/types/loadConfig.d.ts +17 -0
- package/lib/types/loadPlugins.d.ts +4 -0
- package/package.json +14 -9
- package/src/{PostCSSTransformer.js → PostCSSTransformer.ts} +23 -15
- package/src/{constants.js → constants.ts} +0 -2
- package/src/{loadConfig.js → loadConfig.ts} +19 -19
- package/src/{loadPlugins.js → loadPlugins.ts} +15 -9
- package/tsconfig.json +24 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import type {
|
|
4
2
|
FilePath,
|
|
5
3
|
Asset,
|
|
6
4
|
MutableAsset,
|
|
7
5
|
PluginOptions,
|
|
8
|
-
} from '@atlaspack/types';
|
|
6
|
+
} from '@atlaspack/types-internal';
|
|
9
7
|
|
|
10
8
|
import {hashString} from '@atlaspack/rust';
|
|
11
9
|
import {glob} from '@atlaspack/utils';
|
|
@@ -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,12 +75,18 @@ 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
83
|
let plugins = [...config.hydrated.plugins];
|
|
85
|
-
let cssModules:
|
|
84
|
+
let cssModules:
|
|
85
|
+
| {
|
|
86
|
+
[key: string]: string;
|
|
87
|
+
}
|
|
88
|
+
| null
|
|
89
|
+
| undefined = null;
|
|
86
90
|
if (config.hydrated.modules) {
|
|
87
91
|
asset.meta.cssModulesCompiled = 'postcss';
|
|
88
92
|
|
|
@@ -172,8 +176,10 @@ export default (new Transformer({
|
|
|
172
176
|
|
|
173
177
|
plugins.push(
|
|
174
178
|
postcssModules({
|
|
179
|
+
// @ts-expect-error TS7006
|
|
175
180
|
getJSON: (filename, json) => (cssModules = json),
|
|
176
181
|
Loader: await createLoader(asset, resolve, options),
|
|
182
|
+
// @ts-expect-error TS7006
|
|
177
183
|
generateScopedName: (name, filename) =>
|
|
178
184
|
`${name}_${hashString(
|
|
179
185
|
path.relative(options.projectRoot, filename),
|
|
@@ -183,6 +189,7 @@ export default (new Transformer({
|
|
|
183
189
|
);
|
|
184
190
|
|
|
185
191
|
if (code == null || COMPOSES_RE.test(code)) {
|
|
192
|
+
// @ts-expect-error TS7006
|
|
186
193
|
program.walkDecls((decl) => {
|
|
187
194
|
let [, importPath] = FROM_IMPORT_RE.exec(decl.value) || [];
|
|
188
195
|
if (decl.prop === 'composes' && importPath != null) {
|
|
@@ -209,7 +216,6 @@ export default (new Transformer({
|
|
|
209
216
|
}
|
|
210
217
|
}
|
|
211
218
|
|
|
212
|
-
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
|
|
213
219
|
let {messages, root} = await postcss(plugins).process(
|
|
214
220
|
program,
|
|
215
221
|
config.hydrated,
|
|
@@ -234,10 +240,9 @@ export default (new Transformer({
|
|
|
234
240
|
|
|
235
241
|
let assets = [asset];
|
|
236
242
|
if (cssModules) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
>);
|
|
243
|
+
let cssModulesList = Object.entries(cssModules) as Array<
|
|
244
|
+
[string, string]
|
|
245
|
+
>;
|
|
241
246
|
let deps = asset
|
|
242
247
|
.getDependencies()
|
|
243
248
|
.filter((dep) => dep.priority === 'sync');
|
|
@@ -252,7 +257,7 @@ export default (new Transformer({
|
|
|
252
257
|
code = cssModulesList
|
|
253
258
|
.map(
|
|
254
259
|
// This syntax enables shaking the invidual statements, so that unused classes don't even exist in JS.
|
|
255
|
-
([className, classNameHashed]) =>
|
|
260
|
+
([className, classNameHashed]: [any, any]) =>
|
|
256
261
|
`module.exports[${JSON.stringify(className)}] = ${JSON.stringify(
|
|
257
262
|
classNameHashed,
|
|
258
263
|
)};`,
|
|
@@ -268,6 +273,7 @@ export default (new Transformer({
|
|
|
268
273
|
|
|
269
274
|
assets.push({
|
|
270
275
|
type: 'js',
|
|
276
|
+
// @ts-expect-error TS2353
|
|
271
277
|
content: code,
|
|
272
278
|
});
|
|
273
279
|
}
|
|
@@ -275,9 +281,11 @@ export default (new Transformer({
|
|
|
275
281
|
},
|
|
276
282
|
|
|
277
283
|
async generate({asset, ast, options}) {
|
|
284
|
+
// @ts-expect-error TS2709
|
|
278
285
|
const postcss: Postcss = await loadPostcss(options, asset.filePath);
|
|
279
286
|
|
|
280
287
|
let code = '';
|
|
288
|
+
// @ts-expect-error TS7006
|
|
281
289
|
postcss.stringify(postcss.fromJSON(ast.program), (c) => {
|
|
282
290
|
code += c;
|
|
283
291
|
});
|
|
@@ -286,7 +294,7 @@ export default (new Transformer({
|
|
|
286
294
|
content: code,
|
|
287
295
|
};
|
|
288
296
|
},
|
|
289
|
-
})
|
|
297
|
+
}) as Transformer<unknown>;
|
|
290
298
|
|
|
291
299
|
async function createLoader(
|
|
292
300
|
asset: MutableAsset,
|
|
@@ -298,7 +306,7 @@ async function createLoader(
|
|
|
298
306
|
asset.filePath,
|
|
299
307
|
);
|
|
300
308
|
return class AtlaspackFileSystemLoader extends FileSystemLoader {
|
|
301
|
-
async fetch(composesPath, relativeTo) {
|
|
309
|
+
async fetch(composesPath: any, relativeTo: any) {
|
|
302
310
|
let importPath = composesPath.replace(/^["']|["']$/g, '');
|
|
303
311
|
let resolved = await resolve(relativeTo, importPath);
|
|
304
312
|
let rootRelativePath = path.resolve(path.dirname(relativeTo), resolved);
|
|
@@ -314,7 +322,6 @@ async function createLoader(
|
|
|
314
322
|
source,
|
|
315
323
|
rootRelativePath,
|
|
316
324
|
undefined,
|
|
317
|
-
// $FlowFixMe[method-unbinding]
|
|
318
325
|
this.fetch.bind(this),
|
|
319
326
|
);
|
|
320
327
|
return exportTokens;
|
|
@@ -326,6 +333,7 @@ async function createLoader(
|
|
|
326
333
|
};
|
|
327
334
|
}
|
|
328
335
|
|
|
336
|
+
// @ts-expect-error TS2709
|
|
329
337
|
function loadPostcss(options: PluginOptions, from: FilePath): Promise<Postcss> {
|
|
330
338
|
return options.packageManager.require('postcss', from, {
|
|
331
339
|
range: POSTCSS_RANGE,
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {
|
|
3
2
|
Config,
|
|
4
3
|
FilePath,
|
|
5
4
|
PluginOptions,
|
|
6
5
|
PluginLogger,
|
|
7
|
-
} from '@atlaspack/types';
|
|
6
|
+
} from '@atlaspack/types-internal';
|
|
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,7 +80,7 @@ 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
85
|
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.`;
|
|
86
86
|
hints.push(md`Delete __${filename}__`);
|
|
@@ -149,11 +149,11 @@ export async function load({
|
|
|
149
149
|
config,
|
|
150
150
|
options,
|
|
151
151
|
logger,
|
|
152
|
-
}: {
|
|
153
|
-
config: Config
|
|
154
|
-
options: PluginOptions
|
|
155
|
-
logger: PluginLogger
|
|
156
|
-
|
|
152
|
+
}: {
|
|
153
|
+
config: Config;
|
|
154
|
+
options: PluginOptions;
|
|
155
|
+
logger: PluginLogger;
|
|
156
|
+
}): Promise<ConfigResult | null | undefined> {
|
|
157
157
|
if (!config.isSource) {
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type {
|
|
2
|
+
FilePath,
|
|
3
|
+
PluginOptions,
|
|
4
|
+
PackageManager,
|
|
5
|
+
} from '@atlaspack/types-internal';
|
|
5
6
|
|
|
6
7
|
export default async function loadExternalPlugins(
|
|
7
|
-
plugins:
|
|
8
|
+
plugins:
|
|
9
|
+
| Array<string>
|
|
10
|
+
| {
|
|
11
|
+
readonly [pluginName: string]: unknown;
|
|
12
|
+
},
|
|
8
13
|
relative: FilePath,
|
|
9
14
|
options: PluginOptions,
|
|
10
|
-
): Promise<Array<
|
|
15
|
+
): Promise<Array<unknown>> {
|
|
11
16
|
if (Array.isArray(plugins)) {
|
|
12
17
|
return Promise.all(
|
|
13
18
|
plugins
|
|
@@ -42,12 +47,13 @@ export default async function loadExternalPlugins(
|
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
async function loadPlugin(
|
|
45
|
-
pluginArg: string |
|
|
50
|
+
pluginArg: string | any,
|
|
46
51
|
relative: FilePath,
|
|
47
|
-
options:
|
|
52
|
+
options: unknown | null | undefined = {},
|
|
48
53
|
packageManager: PackageManager,
|
|
49
54
|
shouldAutoInstall: boolean,
|
|
50
|
-
|
|
55
|
+
// @ts-expect-error TS1064
|
|
56
|
+
): unknown {
|
|
51
57
|
if (typeof pluginArg !== 'string') {
|
|
52
58
|
return pluginArg;
|
|
53
59
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.base.json",
|
|
3
|
+
"include": ["src"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"composite": true
|
|
6
|
+
},
|
|
7
|
+
"references": [
|
|
8
|
+
{
|
|
9
|
+
"path": "../../core/diagnostic/tsconfig.json"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "../../core/plugin/tsconfig.json"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "../../core/rust/tsconfig.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "../../core/types-internal/tsconfig.json"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"path": "../../core/utils/tsconfig.json"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|