@atlaspack/transformer-postcss 2.14.5-canary.26 → 2.14.5-canary.261
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 +272 -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 +12 -7
- package/lib/loadConfig.js +2 -0
- 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
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.load = load;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const diagnostic_1 = require("@atlaspack/diagnostic");
|
|
9
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
10
|
+
// @ts-expect-error TS7016
|
|
11
|
+
const clone_1 = __importDefault(require("clone"));
|
|
12
|
+
const constants_1 = require("./constants");
|
|
13
|
+
const loadPlugins_1 = __importDefault(require("./loadPlugins"));
|
|
14
|
+
async function configHydrator(configFile, config, resolveFrom, options, logger) {
|
|
15
|
+
if (configFile == null) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
// Load the custom config...
|
|
19
|
+
let modulesConfig;
|
|
20
|
+
let configFilePlugins = (0, clone_1.default)(configFile.plugins);
|
|
21
|
+
if (configFilePlugins != null &&
|
|
22
|
+
typeof configFilePlugins === 'object' &&
|
|
23
|
+
configFilePlugins['postcss-modules'] != null) {
|
|
24
|
+
modulesConfig = configFilePlugins['postcss-modules'];
|
|
25
|
+
delete configFilePlugins['postcss-modules'];
|
|
26
|
+
}
|
|
27
|
+
if (!modulesConfig && configFile.modules) {
|
|
28
|
+
modulesConfig = {};
|
|
29
|
+
}
|
|
30
|
+
let plugins = await (0, loadPlugins_1.default)(configFilePlugins, (0, nullthrows_1.default)(resolveFrom), options);
|
|
31
|
+
// contents is either:
|
|
32
|
+
// from JSON: { plugins: { 'postcss-foo': { ...opts } } }
|
|
33
|
+
// from JS (v8): { plugins: [ { postcssPlugin: 'postcss-foo', ...visitor callback functions } ]
|
|
34
|
+
// from JS (v7): { plugins: [ [Function: ...] ]
|
|
35
|
+
let pluginArray = Array.isArray(configFilePlugins)
|
|
36
|
+
? configFilePlugins
|
|
37
|
+
: Object.keys(configFilePlugins);
|
|
38
|
+
for (let p of pluginArray) {
|
|
39
|
+
if (typeof p === 'string') {
|
|
40
|
+
config.addDevDependency({
|
|
41
|
+
specifier: p,
|
|
42
|
+
resolveFrom: (0, nullthrows_1.default)(resolveFrom),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
let redundantPlugins = pluginArray.filter((p) => p === 'autoprefixer' || p === 'postcss-preset-env');
|
|
47
|
+
if (redundantPlugins.length > 0) {
|
|
48
|
+
let filename = path_1.default.basename(resolveFrom);
|
|
49
|
+
let isPackageJson = filename === 'package.json';
|
|
50
|
+
let message;
|
|
51
|
+
let hints = [];
|
|
52
|
+
if (!isPackageJson && redundantPlugins.length === pluginArray.length) {
|
|
53
|
+
message = (0, diagnostic_1.md) `Parcel includes CSS transpilation and vendor prefixing by default. PostCSS config __${filename}__ contains only redundant plugins. Deleting it may significantly improve build performance.`;
|
|
54
|
+
hints.push((0, diagnostic_1.md) `Delete __${filename}__`);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
message = (0, diagnostic_1.md) `Parcel includes CSS transpilation and vendor prefixing by default. PostCSS config __${filename}__ contains the following redundant plugins: ${[
|
|
58
|
+
...redundantPlugins,
|
|
59
|
+
].map((p) => diagnostic_1.md.underline(p))}. Removing these may improve build performance.`;
|
|
60
|
+
hints.push((0, diagnostic_1.md) `Remove the above plugins from __${filename}__`);
|
|
61
|
+
}
|
|
62
|
+
let codeFrames;
|
|
63
|
+
if (path_1.default.extname(filename) !== '.js') {
|
|
64
|
+
let contents = await options.inputFS.readFile(resolveFrom, 'utf8');
|
|
65
|
+
let prefix = isPackageJson ? '/postcss' : '';
|
|
66
|
+
codeFrames = [
|
|
67
|
+
{
|
|
68
|
+
language: 'json',
|
|
69
|
+
filePath: resolveFrom,
|
|
70
|
+
code: contents,
|
|
71
|
+
codeHighlights: (0, diagnostic_1.generateJSONCodeHighlights)(contents, redundantPlugins.map((plugin) => ({
|
|
72
|
+
key: `${prefix}/plugins/${plugin}`,
|
|
73
|
+
type: 'key',
|
|
74
|
+
}))),
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
codeFrames = [
|
|
80
|
+
{
|
|
81
|
+
filePath: resolveFrom,
|
|
82
|
+
codeHighlights: [
|
|
83
|
+
{
|
|
84
|
+
start: { line: 1, column: 1 },
|
|
85
|
+
end: { line: 1, column: 1 },
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
logger.warn({
|
|
92
|
+
message,
|
|
93
|
+
hints,
|
|
94
|
+
documentationURL: 'https://parceljs.org/languages/css/#default-plugins',
|
|
95
|
+
codeFrames,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
raw: configFile,
|
|
100
|
+
filePath: resolveFrom,
|
|
101
|
+
hydrated: {
|
|
102
|
+
plugins,
|
|
103
|
+
from: config.searchPath,
|
|
104
|
+
to: config.searchPath,
|
|
105
|
+
modules: modulesConfig,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async function load({ config, options, logger, }) {
|
|
110
|
+
if (!config.isSource) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
let configFile = await config.getConfig([
|
|
114
|
+
'.postcssrc',
|
|
115
|
+
'.postcssrc.json',
|
|
116
|
+
'.postcssrc.js',
|
|
117
|
+
'.postcssrc.cjs',
|
|
118
|
+
'.postcssrc.mjs',
|
|
119
|
+
'postcss.config.js',
|
|
120
|
+
'postcss.config.cjs',
|
|
121
|
+
'postcss.config.mjs',
|
|
122
|
+
], { packageKey: 'postcss' });
|
|
123
|
+
let contents = null;
|
|
124
|
+
if (configFile) {
|
|
125
|
+
config.addDevDependency({
|
|
126
|
+
specifier: 'postcss',
|
|
127
|
+
resolveFrom: config.searchPath,
|
|
128
|
+
range: constants_1.POSTCSS_RANGE,
|
|
129
|
+
});
|
|
130
|
+
contents = configFile.contents;
|
|
131
|
+
let isDynamic = configFile && path_1.default.extname(configFile.filePath).endsWith('js');
|
|
132
|
+
if (isDynamic) {
|
|
133
|
+
// We have to invalidate on startup in case the config is non-deterministic,
|
|
134
|
+
// e.g. using unknown environment variables, reading from the filesystem, etc.
|
|
135
|
+
logger.warn({
|
|
136
|
+
message: 'WARNING: Using a JavaScript PostCSS config file means losing out on caching features of Parcel. Use a .postcssrc(.json) file whenever possible.',
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (typeof contents !== 'object') {
|
|
140
|
+
throw new Error('PostCSS config should be an object.');
|
|
141
|
+
}
|
|
142
|
+
if (contents.plugins == null ||
|
|
143
|
+
typeof contents.plugins !== 'object' ||
|
|
144
|
+
Object.keys(contents.plugins).length === 0) {
|
|
145
|
+
throw new Error('PostCSS config must have plugins');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return configHydrator(contents, config, configFile?.filePath, options, logger);
|
|
149
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = loadExternalPlugins;
|
|
4
|
+
async function loadExternalPlugins(plugins, relative, options) {
|
|
5
|
+
if (Array.isArray(plugins)) {
|
|
6
|
+
return Promise.all(plugins
|
|
7
|
+
.map((p) => loadPlugin(p, relative, null, options.packageManager, options.shouldAutoInstall))
|
|
8
|
+
.filter(Boolean));
|
|
9
|
+
}
|
|
10
|
+
else if (typeof plugins === 'object') {
|
|
11
|
+
let _plugins = plugins;
|
|
12
|
+
let mapPlugins = await Promise.all(Object.keys(plugins).map((p) => loadPlugin(p, relative, _plugins[p], options.packageManager, options.shouldAutoInstall)));
|
|
13
|
+
return mapPlugins.filter(Boolean);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function loadPlugin(pluginArg, relative, options = {}, packageManager, shouldAutoInstall) {
|
|
20
|
+
if (typeof pluginArg !== 'string') {
|
|
21
|
+
return pluginArg;
|
|
22
|
+
}
|
|
23
|
+
let plugin = await packageManager.require(pluginArg, relative, {
|
|
24
|
+
shouldAutoInstall,
|
|
25
|
+
});
|
|
26
|
+
plugin = plugin.default || plugin;
|
|
27
|
+
if (options != null &&
|
|
28
|
+
typeof options === 'object' &&
|
|
29
|
+
Object.keys(options).length > 0) {
|
|
30
|
+
plugin = plugin(options);
|
|
31
|
+
}
|
|
32
|
+
return plugin.default || plugin;
|
|
33
|
+
}
|
|
@@ -129,6 +129,8 @@ 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);
|
|
@@ -203,12 +205,15 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
203
205
|
shouldAutoInstall: options.shouldAutoInstall
|
|
204
206
|
});
|
|
205
207
|
plugins.push(postcssModules({
|
|
208
|
+
// @ts-expect-error TS7006
|
|
206
209
|
getJSON: (filename, json) => cssModules = json,
|
|
207
210
|
Loader: await createLoader(asset, resolve, options),
|
|
211
|
+
// @ts-expect-error TS7006
|
|
208
212
|
generateScopedName: (name, filename) => `${name}_${(0, _rust().hashString)(_path().default.relative(options.projectRoot, filename)).substr(0, 6)}`,
|
|
209
213
|
...config.hydrated.modules
|
|
210
214
|
}));
|
|
211
215
|
if (code == null || COMPOSES_RE.test(code)) {
|
|
216
|
+
// @ts-expect-error TS7006
|
|
212
217
|
program.walkDecls(decl => {
|
|
213
218
|
let [, importPath] = FROM_IMPORT_RE.exec(decl.value) || [];
|
|
214
219
|
if (decl.prop === 'composes' && importPath != null) {
|
|
@@ -233,8 +238,6 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
233
238
|
});
|
|
234
239
|
}
|
|
235
240
|
}
|
|
236
|
-
|
|
237
|
-
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
|
|
238
241
|
let {
|
|
239
242
|
messages,
|
|
240
243
|
root
|
|
@@ -262,7 +265,6 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
262
265
|
}
|
|
263
266
|
let assets = [asset];
|
|
264
267
|
if (cssModules) {
|
|
265
|
-
// $FlowFixMe
|
|
266
268
|
let cssModulesList = Object.entries(cssModules);
|
|
267
269
|
let deps = asset.getDependencies().filter(dep => dep.priority === 'sync');
|
|
268
270
|
let code;
|
|
@@ -282,6 +284,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
282
284
|
asset.symbols.set('default', 'default');
|
|
283
285
|
assets.push({
|
|
284
286
|
type: 'js',
|
|
287
|
+
// @ts-expect-error TS2353
|
|
285
288
|
content: code
|
|
286
289
|
});
|
|
287
290
|
}
|
|
@@ -292,8 +295,10 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
292
295
|
ast,
|
|
293
296
|
options
|
|
294
297
|
}) {
|
|
298
|
+
// @ts-expect-error TS2709
|
|
295
299
|
const postcss = await loadPostcss(options, asset.filePath);
|
|
296
300
|
let code = '';
|
|
301
|
+
// @ts-expect-error TS7006
|
|
297
302
|
postcss.stringify(postcss.fromJSON(ast.program), c => {
|
|
298
303
|
code += c;
|
|
299
304
|
});
|
|
@@ -306,7 +311,7 @@ async function createLoader(asset, resolve, options) {
|
|
|
306
311
|
let {
|
|
307
312
|
default: FileSystemLoader
|
|
308
313
|
} = await options.packageManager.require('postcss-modules/build/css-loader-core/loader', asset.filePath);
|
|
309
|
-
return class extends FileSystemLoader {
|
|
314
|
+
return class AtlaspackFileSystemLoader extends FileSystemLoader {
|
|
310
315
|
async fetch(composesPath, relativeTo) {
|
|
311
316
|
let importPath = composesPath.replace(/^["']|["']$/g, '');
|
|
312
317
|
let resolved = await resolve(relativeTo, importPath);
|
|
@@ -320,9 +325,7 @@ async function createLoader(asset, resolve, options) {
|
|
|
320
325
|
let source = await asset.fs.readFile(resolved, 'utf-8');
|
|
321
326
|
let {
|
|
322
327
|
exportTokens
|
|
323
|
-
} = await this.core.load(source, rootRelativePath, undefined,
|
|
324
|
-
// $FlowFixMe[method-unbinding]
|
|
325
|
-
this.fetch.bind(this));
|
|
328
|
+
} = await this.core.load(source, rootRelativePath, undefined, this.fetch.bind(this));
|
|
326
329
|
return exportTokens;
|
|
327
330
|
}
|
|
328
331
|
get finalSource() {
|
|
@@ -330,6 +333,8 @@ async function createLoader(asset, resolve, options) {
|
|
|
330
333
|
}
|
|
331
334
|
};
|
|
332
335
|
}
|
|
336
|
+
|
|
337
|
+
// @ts-expect-error TS2709
|
|
333
338
|
function loadPostcss(options, from) {
|
|
334
339
|
return options.packageManager.require('postcss', from, {
|
|
335
340
|
range: _constants.POSTCSS_RANGE,
|
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;
|
package/lib/loadPlugins.js
CHANGED
|
@@ -8,13 +8,16 @@ async function loadExternalPlugins(plugins, relative, options) {
|
|
|
8
8
|
if (Array.isArray(plugins)) {
|
|
9
9
|
return Promise.all(plugins.map(p => loadPlugin(p, relative, null, options.packageManager, options.shouldAutoInstall)).filter(Boolean));
|
|
10
10
|
} else if (typeof plugins === 'object') {
|
|
11
|
-
let
|
|
11
|
+
let _plugins = plugins;
|
|
12
|
+
let mapPlugins = await Promise.all(Object.keys(plugins).map(p => loadPlugin(p, relative, _plugins[p], options.packageManager, options.shouldAutoInstall)));
|
|
12
13
|
return mapPlugins.filter(Boolean);
|
|
13
14
|
} else {
|
|
14
15
|
return [];
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
async function loadPlugin(pluginArg, relative, options = {}, packageManager, shouldAutoInstall
|
|
18
|
+
async function loadPlugin(pluginArg, relative, options = {}, packageManager, shouldAutoInstall
|
|
19
|
+
// @ts-expect-error TS1064
|
|
20
|
+
) {
|
|
18
21
|
if (typeof pluginArg !== 'string') {
|
|
19
22
|
return pluginArg;
|
|
20
23
|
}
|
|
@@ -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-internal';
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/transformer-postcss",
|
|
3
|
-
"version": "2.14.5-canary.
|
|
3
|
+
"version": "2.14.5-canary.261+3af2f4c20",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -9,16 +9,18 @@
|
|
|
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/types/PostCSSTransformer.d.ts",
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">= 16.0.0"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@atlaspack/diagnostic": "2.14.1-canary.
|
|
19
|
-
"@atlaspack/plugin": "2.14.5-canary.
|
|
20
|
-
"@atlaspack/rust": "3.2.1-canary.
|
|
21
|
-
"@atlaspack/
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.1-canary.329+3af2f4c20",
|
|
20
|
+
"@atlaspack/plugin": "2.14.5-canary.261+3af2f4c20",
|
|
21
|
+
"@atlaspack/rust": "3.2.1-canary.261+3af2f4c20",
|
|
22
|
+
"@atlaspack/types-internal": "2.14.1-canary.329+3af2f4c20",
|
|
23
|
+
"@atlaspack/utils": "2.14.5-canary.261+3af2f4c20",
|
|
22
24
|
"clone": "^2.1.1",
|
|
23
25
|
"nullthrows": "^1.1.1",
|
|
24
26
|
"postcss-value-parser": "^4.2.0",
|
|
@@ -29,5 +31,8 @@
|
|
|
29
31
|
"postcss-modules": "^4.3.1"
|
|
30
32
|
},
|
|
31
33
|
"type": "commonjs",
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
36
|
+
},
|
|
37
|
+
"gitHead": "3af2f4c2059c2d69309e724e0ead99b4345208f4"
|
|
38
|
+
}
|
|
@@ -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
|
+
}
|