@atlaspack/transformer-tokens 1.0.12-dev-swc44-b0b390313.0 → 1.1.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/CHANGELOG.md +15 -0
- package/dist/TokensTransformer.js +81 -2
- package/lib/TokensTransformer.js +50 -2
- package/package.json +9 -10
- package/src/TokensTransformer.ts +85 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/LICENSE +0 -201
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaspack/transformer-tokens
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#942](https://github.com/atlassian-labs/atlaspack/pull/942) [`695339e`](https://github.com/atlassian-labs/atlaspack/commit/695339e4fd46df9590013c2ef4de74cb22225927) Thanks [@marcins](https://github.com/marcins)! - Improve error handling in Tokens transform
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`7cb8569`](https://github.com/atlassian-labs/atlaspack/commit/7cb85698143e381fcb887173b2bfd15f0aea7918), [`695339e`](https://github.com/atlassian-labs/atlaspack/commit/695339e4fd46df9590013c2ef4de74cb22225927)]:
|
|
12
|
+
- @atlaspack/rust@3.17.0
|
|
13
|
+
- @atlaspack/source-map@3.2.2
|
|
14
|
+
- @atlaspack/utils@3.2.8
|
|
15
|
+
- @atlaspack/types-internal@2.22.4
|
|
16
|
+
- @atlaspack/plugin@2.14.47
|
|
17
|
+
|
|
3
18
|
## 1.0.11
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -1,9 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const diagnostic_1 = require("@atlaspack/diagnostic");
|
|
39
|
+
const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
|
|
7
40
|
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
8
41
|
const plugin_1 = require("@atlaspack/plugin");
|
|
9
42
|
const rust_1 = require("@atlaspack/rust");
|
|
@@ -48,7 +81,7 @@ exports.default = new plugin_1.Transformer({
|
|
|
48
81
|
return resolvedConfig;
|
|
49
82
|
}
|
|
50
83
|
},
|
|
51
|
-
async transform({ asset, options, config }) {
|
|
84
|
+
async transform({ asset, options, config, logger }) {
|
|
52
85
|
if (!(0, feature_flags_1.getFeatureFlag)('enableTokensTransformer')) {
|
|
53
86
|
return [asset];
|
|
54
87
|
}
|
|
@@ -72,7 +105,53 @@ exports.default = new plugin_1.Transformer({
|
|
|
72
105
|
tokensOptions: {
|
|
73
106
|
...config,
|
|
74
107
|
},
|
|
108
|
+
}).catch((error) => {
|
|
109
|
+
// Re-throw with context about which file failed
|
|
110
|
+
throw new Error(`Failed to transform tokens in ${asset.filePath}: ${error.message || error}`);
|
|
75
111
|
});
|
|
112
|
+
// Check for diagnostics and convert them to proper Diagnostic objects with code frames
|
|
113
|
+
if (result.diagnostics && result.diagnostics.length > 0) {
|
|
114
|
+
const convertDiagnostic = (diagnostic) => {
|
|
115
|
+
const codeHighlights = diagnostic.code_highlights?.map((highlight) => (0, diagnostic_1.convertSourceLocationToHighlight)({
|
|
116
|
+
start: {
|
|
117
|
+
line: highlight.loc.start_line,
|
|
118
|
+
column: highlight.loc.start_col,
|
|
119
|
+
},
|
|
120
|
+
end: {
|
|
121
|
+
line: highlight.loc.end_line,
|
|
122
|
+
column: highlight.loc.end_col,
|
|
123
|
+
},
|
|
124
|
+
}, highlight.message ?? undefined));
|
|
125
|
+
const res = {
|
|
126
|
+
message: diagnostic.message,
|
|
127
|
+
codeFrames: [
|
|
128
|
+
{
|
|
129
|
+
filePath: asset.filePath,
|
|
130
|
+
code: code,
|
|
131
|
+
codeHighlights: codeHighlights ?? [],
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
hints: diagnostic.hints,
|
|
135
|
+
};
|
|
136
|
+
if (diagnostic.documentation_url) {
|
|
137
|
+
res.documentationURL = diagnostic.documentation_url;
|
|
138
|
+
}
|
|
139
|
+
return res;
|
|
140
|
+
};
|
|
141
|
+
const errors = result.diagnostics.filter((d) => d.severity === 'Error' ||
|
|
142
|
+
(d.severity === 'SourceError' && asset.isSource));
|
|
143
|
+
if (errors.length > 0) {
|
|
144
|
+
throw new diagnostic_1.default({
|
|
145
|
+
diagnostic: errors.map(convertDiagnostic),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// Log warnings
|
|
149
|
+
const warnings = result.diagnostics.filter((d) => d.severity === 'Warning' ||
|
|
150
|
+
(d.severity === 'SourceError' && !asset.isSource));
|
|
151
|
+
if (warnings.length > 0) {
|
|
152
|
+
logger.warn(warnings.map(convertDiagnostic));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
76
155
|
// Ensure this transform is invalidated when the token data changes
|
|
77
156
|
asset.invalidateOnFileChange(config.tokenDataPath);
|
|
78
157
|
// Handle sourcemap merging if sourcemap is generated
|
package/lib/TokensTransformer.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
function _diagnostic() {
|
|
8
|
-
const data = require("@atlaspack/diagnostic");
|
|
8
|
+
const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
|
|
9
9
|
_diagnostic = function () {
|
|
10
10
|
return data;
|
|
11
11
|
};
|
|
@@ -54,6 +54,8 @@ function _path() {
|
|
|
54
54
|
return data;
|
|
55
55
|
}
|
|
56
56
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
57
|
+
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); }
|
|
58
|
+
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; }
|
|
57
59
|
const CONFIG_SCHEMA = {
|
|
58
60
|
type: 'object',
|
|
59
61
|
properties: {
|
|
@@ -110,7 +112,8 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
110
112
|
async transform({
|
|
111
113
|
asset,
|
|
112
114
|
options,
|
|
113
|
-
config
|
|
115
|
+
config,
|
|
116
|
+
logger
|
|
114
117
|
}) {
|
|
115
118
|
if (!(0, _featureFlags().getFeatureFlag)('enableTokensTransformer')) {
|
|
116
119
|
return [asset];
|
|
@@ -132,8 +135,53 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
132
135
|
tokensOptions: {
|
|
133
136
|
...config
|
|
134
137
|
}
|
|
138
|
+
}).catch(error => {
|
|
139
|
+
// Re-throw with context about which file failed
|
|
140
|
+
throw new Error(`Failed to transform tokens in ${asset.filePath}: ${error.message || error}`);
|
|
135
141
|
});
|
|
136
142
|
|
|
143
|
+
// Check for diagnostics and convert them to proper Diagnostic objects with code frames
|
|
144
|
+
if (result.diagnostics && result.diagnostics.length > 0) {
|
|
145
|
+
const convertDiagnostic = diagnostic => {
|
|
146
|
+
var _diagnostic$code_high;
|
|
147
|
+
const codeHighlights = (_diagnostic$code_high = diagnostic.code_highlights) === null || _diagnostic$code_high === void 0 ? void 0 : _diagnostic$code_high.map(highlight => (0, _diagnostic().convertSourceLocationToHighlight)({
|
|
148
|
+
start: {
|
|
149
|
+
line: highlight.loc.start_line,
|
|
150
|
+
column: highlight.loc.start_col
|
|
151
|
+
},
|
|
152
|
+
end: {
|
|
153
|
+
line: highlight.loc.end_line,
|
|
154
|
+
column: highlight.loc.end_col
|
|
155
|
+
}
|
|
156
|
+
}, highlight.message ?? undefined));
|
|
157
|
+
const res = {
|
|
158
|
+
message: diagnostic.message,
|
|
159
|
+
codeFrames: [{
|
|
160
|
+
filePath: asset.filePath,
|
|
161
|
+
code: code,
|
|
162
|
+
codeHighlights: codeHighlights ?? []
|
|
163
|
+
}],
|
|
164
|
+
hints: diagnostic.hints
|
|
165
|
+
};
|
|
166
|
+
if (diagnostic.documentation_url) {
|
|
167
|
+
res.documentationURL = diagnostic.documentation_url;
|
|
168
|
+
}
|
|
169
|
+
return res;
|
|
170
|
+
};
|
|
171
|
+
const errors = result.diagnostics.filter(d => d.severity === 'Error' || d.severity === 'SourceError' && asset.isSource);
|
|
172
|
+
if (errors.length > 0) {
|
|
173
|
+
throw new (_diagnostic().default)({
|
|
174
|
+
diagnostic: errors.map(convertDiagnostic)
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Log warnings
|
|
179
|
+
const warnings = result.diagnostics.filter(d => d.severity === 'Warning' || d.severity === 'SourceError' && !asset.isSource);
|
|
180
|
+
if (warnings.length > 0) {
|
|
181
|
+
logger.warn(warnings.map(convertDiagnostic));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
137
185
|
// Ensure this transform is invalidated when the token data changes
|
|
138
186
|
asset.invalidateOnFileChange(config.tokenDataPath);
|
|
139
187
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/transformer-tokens",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,17 +16,16 @@
|
|
|
16
16
|
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.14.
|
|
20
|
-
"@atlaspack/feature-flags": "2.27.
|
|
21
|
-
"@atlaspack/
|
|
22
|
-
"@atlaspack/
|
|
23
|
-
"@atlaspack/
|
|
24
|
-
"@atlaspack/
|
|
25
|
-
"@atlaspack/
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.4",
|
|
20
|
+
"@atlaspack/feature-flags": "2.27.5",
|
|
21
|
+
"@atlaspack/types-internal": "2.22.4",
|
|
22
|
+
"@atlaspack/plugin": "2.14.47",
|
|
23
|
+
"@atlaspack/rust": "3.17.0",
|
|
24
|
+
"@atlaspack/utils": "3.2.8",
|
|
25
|
+
"@atlaspack/source-map": "3.2.2"
|
|
26
26
|
},
|
|
27
27
|
"type": "commonjs",
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
30
|
-
}
|
|
31
|
-
"gitHead": "b0b3903133091347563cb8ea34f328655c4ba0fb"
|
|
30
|
+
}
|
|
32
31
|
}
|
package/src/TokensTransformer.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
encodeJSONKeyComponent,
|
|
3
|
+
default as ThrowableDiagnostic,
|
|
4
|
+
convertSourceLocationToHighlight,
|
|
5
|
+
type Diagnostic,
|
|
6
|
+
} from '@atlaspack/diagnostic';
|
|
2
7
|
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
3
8
|
import {Transformer} from '@atlaspack/plugin';
|
|
4
9
|
import {applyTokensPlugin, TokensPluginResult} from '@atlaspack/rust';
|
|
@@ -72,7 +77,7 @@ export default new Transformer({
|
|
|
72
77
|
}
|
|
73
78
|
},
|
|
74
79
|
|
|
75
|
-
async transform({asset, options, config}) {
|
|
80
|
+
async transform({asset, options, config, logger}) {
|
|
76
81
|
if (!getFeatureFlag('enableTokensTransformer')) {
|
|
77
82
|
return [asset];
|
|
78
83
|
}
|
|
@@ -92,15 +97,84 @@ export default new Transformer({
|
|
|
92
97
|
return [asset];
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
const result = await (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
const result = await (
|
|
101
|
+
applyTokensPlugin(codeBuffer, {
|
|
102
|
+
filename: asset.filePath,
|
|
103
|
+
projectRoot: options.projectRoot,
|
|
104
|
+
isSource: asset.isSource,
|
|
105
|
+
sourceMaps: !!asset.env.sourceMap,
|
|
106
|
+
tokensOptions: {
|
|
107
|
+
...config,
|
|
108
|
+
},
|
|
109
|
+
}) as Promise<TokensPluginResult>
|
|
110
|
+
).catch((error) => {
|
|
111
|
+
// Re-throw with context about which file failed
|
|
112
|
+
throw new Error(
|
|
113
|
+
`Failed to transform tokens in ${asset.filePath}: ${error.message || error}`,
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Check for diagnostics and convert them to proper Diagnostic objects with code frames
|
|
118
|
+
if (result.diagnostics && result.diagnostics.length > 0) {
|
|
119
|
+
const convertDiagnostic = (diagnostic: any): Diagnostic => {
|
|
120
|
+
const codeHighlights = diagnostic.code_highlights?.map(
|
|
121
|
+
(highlight: any) =>
|
|
122
|
+
convertSourceLocationToHighlight(
|
|
123
|
+
{
|
|
124
|
+
start: {
|
|
125
|
+
line: highlight.loc.start_line,
|
|
126
|
+
column: highlight.loc.start_col,
|
|
127
|
+
},
|
|
128
|
+
end: {
|
|
129
|
+
line: highlight.loc.end_line,
|
|
130
|
+
column: highlight.loc.end_col,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
highlight.message ?? undefined,
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const res: Diagnostic = {
|
|
138
|
+
message: diagnostic.message,
|
|
139
|
+
codeFrames: [
|
|
140
|
+
{
|
|
141
|
+
filePath: asset.filePath,
|
|
142
|
+
code: code,
|
|
143
|
+
codeHighlights: codeHighlights ?? [],
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
hints: diagnostic.hints,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
if (diagnostic.documentation_url) {
|
|
150
|
+
res.documentationURL = diagnostic.documentation_url;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return res;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const errors = result.diagnostics.filter(
|
|
157
|
+
(d: any) =>
|
|
158
|
+
d.severity === 'Error' ||
|
|
159
|
+
(d.severity === 'SourceError' && asset.isSource),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
if (errors.length > 0) {
|
|
163
|
+
throw new ThrowableDiagnostic({
|
|
164
|
+
diagnostic: errors.map(convertDiagnostic),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Log warnings
|
|
169
|
+
const warnings = result.diagnostics.filter(
|
|
170
|
+
(d: any) =>
|
|
171
|
+
d.severity === 'Warning' ||
|
|
172
|
+
(d.severity === 'SourceError' && !asset.isSource),
|
|
173
|
+
);
|
|
174
|
+
if (warnings.length > 0) {
|
|
175
|
+
logger.warn(warnings.map(convertDiagnostic));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
104
178
|
|
|
105
179
|
// Ensure this transform is invalidated when the token data changes
|
|
106
180
|
asset.invalidateOnFileChange(config.tokenDataPath);
|