@atlaspack/transformer-compiled-css-in-js 0.0.15-canary.4135 → 0.0.15-canary.4137
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.
|
@@ -25,13 +25,6 @@ function _index() {
|
|
|
25
25
|
};
|
|
26
26
|
return data;
|
|
27
27
|
}
|
|
28
|
-
function _path() {
|
|
29
|
-
const data = require("path");
|
|
30
|
-
_path = function () {
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
28
|
function _sourceMap() {
|
|
36
29
|
const data = _interopRequireDefault(require("@atlaspack/source-map"));
|
|
37
30
|
_sourceMap = function () {
|
|
@@ -40,7 +33,7 @@ function _sourceMap() {
|
|
|
40
33
|
return data;
|
|
41
34
|
}
|
|
42
35
|
function _diagnostic() {
|
|
43
|
-
const data = require("@atlaspack/diagnostic");
|
|
36
|
+
const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
|
|
44
37
|
_diagnostic = function () {
|
|
45
38
|
return data;
|
|
46
39
|
};
|
|
@@ -53,32 +46,26 @@ function _utils() {
|
|
|
53
46
|
};
|
|
54
47
|
return data;
|
|
55
48
|
}
|
|
49
|
+
function _transformerJs() {
|
|
50
|
+
const data = require("@atlaspack/transformer-js");
|
|
51
|
+
_transformerJs = function () {
|
|
52
|
+
return data;
|
|
53
|
+
};
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
57
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
56
58
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
57
|
-
const configFiles = ['.compiledcssrc', '.compiledcssrc.json'];
|
|
58
|
-
const PACKAGE_KEY = '@atlaspack/transformer-compiled-css-in-js';
|
|
59
59
|
var _default = exports.default = new (_plugin().Transformer)({
|
|
60
|
+
// eslint-disable-next-line require-await
|
|
60
61
|
async loadConfig({
|
|
61
62
|
config,
|
|
62
63
|
options
|
|
63
64
|
}) {
|
|
64
|
-
var _contents$importSourc;
|
|
65
65
|
if (!(0, _featureFlags().getFeatureFlag)('compiledCssInJsTransformer')) {
|
|
66
|
-
return
|
|
66
|
+
return undefined;
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
packageKey: PACKAGE_KEY
|
|
70
|
-
});
|
|
71
|
-
const contents = {
|
|
72
|
-
configPath: conf === null || conf === void 0 ? void 0 : conf.filePath,
|
|
73
|
-
importSources: ['@compiled/react', '@atlaskit/css']
|
|
74
|
-
};
|
|
75
|
-
Object.assign(contents, conf === null || conf === void 0 ? void 0 : conf.contents);
|
|
76
|
-
if (!((_contents$importSourc = contents.importSources) !== null && _contents$importSourc !== void 0 && _contents$importSourc.includes('@compiled/react'))) {
|
|
77
|
-
var _contents$importSourc2;
|
|
78
|
-
(_contents$importSourc2 = contents.importSources) === null || _contents$importSourc2 === void 0 || _contents$importSourc2.push('@compiled/react');
|
|
79
|
-
}
|
|
80
|
-
contents.extract = contents.extract && options.mode !== 'development';
|
|
81
|
-
return contents;
|
|
68
|
+
return (0, _transformerJs().loadCompiledCssInJsConfig)(config, options);
|
|
82
69
|
},
|
|
83
70
|
async transform({
|
|
84
71
|
asset,
|
|
@@ -87,12 +74,33 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
87
74
|
logger
|
|
88
75
|
}) {
|
|
89
76
|
var _config$importSources, _result$diagnostics;
|
|
90
|
-
if (!(0, _featureFlags().getFeatureFlag)('compiledCssInJsTransformer')) {
|
|
77
|
+
if (!(0, _featureFlags().getFeatureFlag)('compiledCssInJsTransformer') || !config) {
|
|
91
78
|
return [asset];
|
|
92
79
|
}
|
|
93
80
|
if (!asset.isSource && !config.extract) {
|
|
94
81
|
return [asset];
|
|
95
82
|
}
|
|
83
|
+
const code = await asset.getCode();
|
|
84
|
+
if ((_config$importSources = config.importSources) !== null && _config$importSources !== void 0 && _config$importSources.every(source => !code.includes(source) || code.includes(source + '/runtime'))) {
|
|
85
|
+
return [asset];
|
|
86
|
+
}
|
|
87
|
+
if ((0, _featureFlags().getFeatureFlag)('compiledCssInJsTransformer') && (config !== null && config !== void 0 && config.unsafeReportSafeAssetsForMigration || config !== null && config !== void 0 && config.unsafeUseSafeAssets)) {
|
|
88
|
+
asset.meta.compiledCodeHash ??= (0, _index().hashCode)(code);
|
|
89
|
+
}
|
|
90
|
+
if (config !== null && config !== void 0 && config.unsafeUseSafeAssets) {
|
|
91
|
+
if (!config.configPath) {
|
|
92
|
+
throw new Error('configPath is required when unsafeUseSafeAssets is enabled');
|
|
93
|
+
}
|
|
94
|
+
asset.meta.useRustCompiledTransform ??= (0, _index().isSafeFromJs)(asset.meta.compiledCodeHash, config.configPath);
|
|
95
|
+
}
|
|
96
|
+
if ((0, _featureFlags().getFeatureFlag)('coreTokensAndCompiledCssInJsTransform')) {
|
|
97
|
+
// Skipping if we're using the compiled CSS in JS transform from the core pass
|
|
98
|
+
return [asset];
|
|
99
|
+
}
|
|
100
|
+
if (config.unsafeUseSafeAssets && !asset.meta.useRustCompiledTransform) {
|
|
101
|
+
// Fallback to the legacy transform if we know the asset is not safe
|
|
102
|
+
return [asset];
|
|
103
|
+
}
|
|
96
104
|
const mapPromise = asset.getMap();
|
|
97
105
|
let originalMap;
|
|
98
106
|
const ensureOriginalMap = async () => {
|
|
@@ -101,10 +109,6 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
101
109
|
}
|
|
102
110
|
return originalMap;
|
|
103
111
|
};
|
|
104
|
-
const code = await asset.getCode();
|
|
105
|
-
if ((_config$importSources = config.importSources) !== null && _config$importSources !== void 0 && _config$importSources.every(source => !code.includes(source) || code.includes(source + '/runtime'))) {
|
|
106
|
-
return [asset];
|
|
107
|
-
}
|
|
108
112
|
const codeBuffer = Buffer.from(code);
|
|
109
113
|
const result = await (0, _index().applyCompiledCssInJsPlugin)(codeBuffer, {
|
|
110
114
|
filename: asset.filePath,
|
|
@@ -158,8 +162,14 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
158
162
|
};
|
|
159
163
|
const errors = diagnostics.filter(diagnostic => diagnostic.severity === 'Error' || diagnostic.severity === 'SourceError' && asset.isSource);
|
|
160
164
|
if (errors.length > 0) {
|
|
161
|
-
|
|
162
|
-
|
|
165
|
+
if (config.unsafeUseSafeAssets || config.unsafeReportSafeAssetsForMigration) {
|
|
166
|
+
for (const error of errors) {
|
|
167
|
+
logger.warn(convertDiagnostic(error));
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
throw new (_diagnostic().default)({
|
|
171
|
+
diagnostic: errors.map(convertDiagnostic)
|
|
172
|
+
});
|
|
163
173
|
}
|
|
164
174
|
}
|
|
165
175
|
const warnings = diagnostics.filter(diagnostic => diagnostic.severity === 'Warning' || diagnostic.severity === 'SourceError' && !asset.isSource);
|
|
@@ -172,10 +182,6 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
172
182
|
if (config.unsafeReportSafeAssetsForMigration) {
|
|
173
183
|
// We need to run the transform without returning the result, so we can report the safe assets
|
|
174
184
|
asset.meta.swcStyleRules = result.styleRules;
|
|
175
|
-
if (!result.codeHash) {
|
|
176
|
-
throw new Error('Code hash is required');
|
|
177
|
-
}
|
|
178
|
-
asset.meta.compiledCodeHash = result.codeHash;
|
|
179
185
|
asset.meta.compiledCssDiagnostics = result.diagnostics.map(d => d.message);
|
|
180
186
|
asset.meta.compiledBailOut = result.bailOut;
|
|
181
187
|
return [asset];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { Transformer } from '@atlaspack/plugin';
|
|
2
|
-
|
|
3
|
-
declare const _default: Transformer<CompiledCssInJsConfig>;
|
|
2
|
+
declare const _default: Transformer<import("@atlaspack/rust/index").CompiledCssInJsConfigPlugin | undefined>;
|
|
4
3
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/transformer-compiled-css-in-js",
|
|
3
|
-
"version": "0.0.15-canary.
|
|
3
|
+
"version": "0.0.15-canary.4137+f33f9c48d",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -20,16 +20,17 @@
|
|
|
20
20
|
"src"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@atlaspack/diagnostic": "2.14.1-canary.
|
|
24
|
-
"@atlaspack/feature-flags": "2.14.1-canary.
|
|
25
|
-
"@atlaspack/plugin": "2.14.5-canary.
|
|
26
|
-
"@atlaspack/rust": "3.2.1-canary.
|
|
27
|
-
"@atlaspack/source-map": "3.2.4-canary.
|
|
28
|
-
"@atlaspack/
|
|
23
|
+
"@atlaspack/diagnostic": "2.14.1-canary.426+f33f9c48d",
|
|
24
|
+
"@atlaspack/feature-flags": "2.14.1-canary.426+f33f9c48d",
|
|
25
|
+
"@atlaspack/plugin": "2.14.5-canary.358+f33f9c48d",
|
|
26
|
+
"@atlaspack/rust": "3.2.1-canary.358+f33f9c48d",
|
|
27
|
+
"@atlaspack/source-map": "3.2.4-canary.4137+f33f9c48d",
|
|
28
|
+
"@atlaspack/transformer-js": "3.2.3-canary.358+f33f9c48d",
|
|
29
|
+
"@atlaspack/utils": "2.14.5-canary.358+f33f9c48d"
|
|
29
30
|
},
|
|
30
31
|
"type": "commonjs",
|
|
31
32
|
"scripts": {
|
|
32
33
|
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
33
34
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "f33f9c48dd24b319df352d197e4a83cbb1b053bc"
|
|
35
36
|
}
|
|
@@ -4,9 +4,9 @@ import {Transformer} from '@atlaspack/plugin';
|
|
|
4
4
|
import {
|
|
5
5
|
applyCompiledCssInJsPlugin,
|
|
6
6
|
CompiledCssInJsPluginResult,
|
|
7
|
-
|
|
7
|
+
hashCode,
|
|
8
|
+
isSafeFromJs,
|
|
8
9
|
} from '@atlaspack/rust/index';
|
|
9
|
-
import {join} from 'path';
|
|
10
10
|
import SourceMap from '@atlaspack/source-map';
|
|
11
11
|
import type {Diagnostic} from '@atlaspack/diagnostic';
|
|
12
12
|
import ThrowableDiagnostic, {
|
|
@@ -14,45 +14,65 @@ import ThrowableDiagnostic, {
|
|
|
14
14
|
} from '@atlaspack/diagnostic';
|
|
15
15
|
import {remapSourceLocation} from '@atlaspack/utils';
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const PACKAGE_KEY = '@atlaspack/transformer-compiled-css-in-js';
|
|
17
|
+
import {loadCompiledCssInJsConfig} from '@atlaspack/transformer-js';
|
|
20
18
|
|
|
21
19
|
export default new Transformer({
|
|
20
|
+
// eslint-disable-next-line require-await
|
|
22
21
|
async loadConfig({config, options}) {
|
|
23
22
|
if (!getFeatureFlag('compiledCssInJsTransformer')) {
|
|
24
|
-
return
|
|
23
|
+
return undefined;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const contents: CompiledCssInJsConfig = {
|
|
36
|
-
configPath: conf?.filePath,
|
|
37
|
-
importSources: ['@compiled/react', '@atlaskit/css'],
|
|
38
|
-
};
|
|
26
|
+
return loadCompiledCssInJsConfig(config, options);
|
|
27
|
+
},
|
|
28
|
+
async transform({asset, options, config, logger}) {
|
|
29
|
+
if (!getFeatureFlag('compiledCssInJsTransformer') || !config) {
|
|
30
|
+
return [asset];
|
|
31
|
+
}
|
|
39
32
|
|
|
40
|
-
|
|
33
|
+
if (!asset.isSource && !config.extract) {
|
|
34
|
+
return [asset];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const code = await asset.getCode();
|
|
41
38
|
|
|
42
|
-
if (
|
|
43
|
-
|
|
39
|
+
if (
|
|
40
|
+
config.importSources?.every(
|
|
41
|
+
(source) =>
|
|
42
|
+
!code.includes(source) || code.includes(source + '/runtime'),
|
|
43
|
+
)
|
|
44
|
+
) {
|
|
45
|
+
return [asset];
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
if (
|
|
49
|
+
getFeatureFlag('compiledCssInJsTransformer') &&
|
|
50
|
+
(config?.unsafeReportSafeAssetsForMigration ||
|
|
51
|
+
config?.unsafeUseSafeAssets)
|
|
52
|
+
) {
|
|
53
|
+
asset.meta.compiledCodeHash ??= hashCode(code);
|
|
54
|
+
}
|
|
47
55
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
if (config?.unsafeUseSafeAssets) {
|
|
57
|
+
if (!config.configPath) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
'configPath is required when unsafeUseSafeAssets is enabled',
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
asset.meta.useRustCompiledTransform ??= isSafeFromJs(
|
|
64
|
+
asset.meta.compiledCodeHash as string,
|
|
65
|
+
config.configPath,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (getFeatureFlag('coreTokensAndCompiledCssInJsTransform')) {
|
|
70
|
+
// Skipping if we're using the compiled CSS in JS transform from the core pass
|
|
52
71
|
return [asset];
|
|
53
72
|
}
|
|
54
73
|
|
|
55
|
-
if (
|
|
74
|
+
if (config.unsafeUseSafeAssets && !asset.meta.useRustCompiledTransform) {
|
|
75
|
+
// Fallback to the legacy transform if we know the asset is not safe
|
|
56
76
|
return [asset];
|
|
57
77
|
}
|
|
58
78
|
|
|
@@ -65,15 +85,6 @@ export default new Transformer({
|
|
|
65
85
|
|
|
66
86
|
return originalMap;
|
|
67
87
|
};
|
|
68
|
-
const code = await asset.getCode();
|
|
69
|
-
if (
|
|
70
|
-
config.importSources?.every(
|
|
71
|
-
(source) =>
|
|
72
|
-
!code.includes(source) || code.includes(source + '/runtime'),
|
|
73
|
-
)
|
|
74
|
-
) {
|
|
75
|
-
return [asset];
|
|
76
|
-
}
|
|
77
88
|
|
|
78
89
|
const codeBuffer = Buffer.from(code);
|
|
79
90
|
|
|
@@ -167,8 +178,17 @@ export default new Transformer({
|
|
|
167
178
|
(diagnostic.severity === 'SourceError' && asset.isSource),
|
|
168
179
|
);
|
|
169
180
|
if (errors.length > 0) {
|
|
170
|
-
|
|
171
|
-
|
|
181
|
+
if (
|
|
182
|
+
config.unsafeUseSafeAssets ||
|
|
183
|
+
config.unsafeReportSafeAssetsForMigration
|
|
184
|
+
) {
|
|
185
|
+
for (const error of errors) {
|
|
186
|
+
logger.warn(convertDiagnostic(error));
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
throw new ThrowableDiagnostic({
|
|
190
|
+
diagnostic: errors.map(convertDiagnostic),
|
|
191
|
+
});
|
|
172
192
|
}
|
|
173
193
|
}
|
|
174
194
|
|
|
@@ -187,14 +207,11 @@ export default new Transformer({
|
|
|
187
207
|
if (config.unsafeReportSafeAssetsForMigration) {
|
|
188
208
|
// We need to run the transform without returning the result, so we can report the safe assets
|
|
189
209
|
asset.meta.swcStyleRules = result.styleRules;
|
|
190
|
-
if (!result.codeHash) {
|
|
191
|
-
throw new Error('Code hash is required');
|
|
192
|
-
}
|
|
193
|
-
asset.meta.compiledCodeHash = result.codeHash;
|
|
194
210
|
asset.meta.compiledCssDiagnostics = result.diagnostics.map(
|
|
195
211
|
(d) => d.message,
|
|
196
212
|
);
|
|
197
213
|
asset.meta.compiledBailOut = result.bailOut;
|
|
214
|
+
|
|
198
215
|
return [asset];
|
|
199
216
|
}
|
|
200
217
|
|