@parcel/transformer-sass 2.8.3 → 2.9.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/lib/SassTransformer.js +15 -55
- package/package.json +4 -4
- package/src/SassTransformer.js +4 -6
package/lib/SassTransformer.js
CHANGED
|
@@ -4,105 +4,79 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _plugin() {
|
|
9
8
|
const data = require("@parcel/plugin");
|
|
10
|
-
|
|
11
9
|
_plugin = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _path() {
|
|
19
15
|
const data = _interopRequireDefault(require("path"));
|
|
20
|
-
|
|
21
16
|
_path = function () {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _os() {
|
|
29
22
|
const data = require("os");
|
|
30
|
-
|
|
31
23
|
_os = function () {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _sourceMap() {
|
|
39
29
|
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
40
|
-
|
|
41
30
|
_sourceMap = function () {
|
|
42
31
|
return data;
|
|
43
32
|
};
|
|
44
|
-
|
|
45
33
|
return data;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
35
|
function _sass() {
|
|
49
36
|
const data = _interopRequireDefault(require("sass"));
|
|
50
|
-
|
|
51
37
|
_sass = function () {
|
|
52
38
|
return data;
|
|
53
39
|
};
|
|
54
|
-
|
|
55
40
|
return data;
|
|
56
41
|
}
|
|
57
|
-
|
|
58
42
|
function _util() {
|
|
59
43
|
const data = require("util");
|
|
60
|
-
|
|
61
44
|
_util = function () {
|
|
62
45
|
return data;
|
|
63
46
|
};
|
|
64
|
-
|
|
65
47
|
return data;
|
|
66
48
|
}
|
|
67
|
-
|
|
68
49
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
69
|
-
|
|
70
50
|
// E.g: ~library/file.sass
|
|
71
51
|
const NODE_MODULE_ALIAS_RE = /^~[^/\\]/;
|
|
72
|
-
|
|
73
52
|
var _default = new (_plugin().Transformer)({
|
|
74
53
|
async loadConfig({
|
|
75
54
|
config,
|
|
76
55
|
options
|
|
77
56
|
}) {
|
|
78
|
-
let configFile = await config.getConfig(['.sassrc', '.sassrc.json', '.sassrc.js', '.sassrc.cjs'], {
|
|
57
|
+
let configFile = await config.getConfig(['.sassrc', '.sassrc.json', '.sassrc.js', '.sassrc.cjs', '.sassrc.mjs'], {
|
|
79
58
|
packageKey: 'sass'
|
|
80
59
|
});
|
|
81
|
-
let configResult = configFile ? configFile.contents : {};
|
|
60
|
+
let configResult = configFile ? configFile.contents : {};
|
|
82
61
|
|
|
62
|
+
// Resolve relative paths from config file
|
|
83
63
|
if (configFile && configResult.includePaths) {
|
|
84
64
|
configResult.includePaths = configResult.includePaths.map(p => _path().default.resolve(_path().default.dirname(configFile.filePath), p));
|
|
85
65
|
}
|
|
86
|
-
|
|
87
|
-
if (configFile && _path().default.extname(configFile.filePath).endsWith('js')) {
|
|
88
|
-
config.invalidateOnStartup();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
66
|
if (configResult.importer === undefined) {
|
|
92
67
|
configResult.importer = [];
|
|
93
68
|
} else if (!Array.isArray(configResult.importer)) {
|
|
94
69
|
configResult.importer = [configResult.importer];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
configResult.sourceMap = true; // sources are created relative to the directory of outFile
|
|
70
|
+
}
|
|
99
71
|
|
|
72
|
+
// Always emit sourcemap
|
|
73
|
+
configResult.sourceMap = true;
|
|
74
|
+
// sources are created relative to the directory of outFile
|
|
100
75
|
configResult.outFile = _path().default.join(options.projectRoot, 'style.css.map');
|
|
101
76
|
configResult.omitSourceMapUrl = true;
|
|
102
77
|
configResult.sourceMapContents = false;
|
|
103
78
|
return configResult;
|
|
104
79
|
},
|
|
105
|
-
|
|
106
80
|
async transform({
|
|
107
81
|
asset,
|
|
108
82
|
options,
|
|
@@ -112,10 +86,10 @@ var _default = new (_plugin().Transformer)({
|
|
|
112
86
|
let rawConfig = config !== null && config !== void 0 ? config : {};
|
|
113
87
|
let sassRender = (0, _util().promisify)(_sass().default.render.bind(_sass().default));
|
|
114
88
|
let css;
|
|
115
|
-
|
|
116
89
|
try {
|
|
117
90
|
let code = await asset.getCode();
|
|
118
|
-
let result = await sassRender({
|
|
91
|
+
let result = await sassRender({
|
|
92
|
+
...rawConfig,
|
|
119
93
|
file: asset.filePath,
|
|
120
94
|
data: rawConfig.data ? rawConfig.data + _os().EOL + code : code,
|
|
121
95
|
importer: [...rawConfig.importer, resolvePathImporter({
|
|
@@ -127,13 +101,11 @@ var _default = new (_plugin().Transformer)({
|
|
|
127
101
|
indentedSyntax: typeof rawConfig.indentedSyntax === 'boolean' ? rawConfig.indentedSyntax : asset.type === 'sass'
|
|
128
102
|
});
|
|
129
103
|
css = result.css;
|
|
130
|
-
|
|
131
104
|
for (let included of result.stats.includedFiles) {
|
|
132
105
|
if (included !== asset.filePath) {
|
|
133
106
|
asset.invalidateOnFileChange(included);
|
|
134
107
|
}
|
|
135
108
|
}
|
|
136
|
-
|
|
137
109
|
if (result.map != null) {
|
|
138
110
|
let map = new (_sourceMap().default)(options.projectRoot);
|
|
139
111
|
map.addVLQMap(JSON.parse(result.map));
|
|
@@ -148,16 +120,12 @@ var _default = new (_plugin().Transformer)({
|
|
|
148
120
|
};
|
|
149
121
|
throw err;
|
|
150
122
|
}
|
|
151
|
-
|
|
152
123
|
asset.type = 'css';
|
|
153
124
|
asset.setCode(css);
|
|
154
125
|
return [asset];
|
|
155
126
|
}
|
|
156
|
-
|
|
157
127
|
});
|
|
158
|
-
|
|
159
128
|
exports.default = _default;
|
|
160
|
-
|
|
161
129
|
function resolvePathImporter({
|
|
162
130
|
asset,
|
|
163
131
|
resolve,
|
|
@@ -177,31 +145,24 @@ function resolvePathImporter({
|
|
|
177
145
|
See: https://sass-lang.com/documentation/js-api#importer
|
|
178
146
|
See also: https://github.com/sass/dart-sass/blob/006e6aa62f2417b5267ad5cdb5ba050226fab511/lib/src/importer/node/implementation.dart
|
|
179
147
|
*/
|
|
180
|
-
let paths = [_path().default.dirname(prev)];
|
|
181
148
|
|
|
149
|
+
let paths = [_path().default.dirname(prev)];
|
|
182
150
|
if (includePaths) {
|
|
183
151
|
paths.push(...includePaths);
|
|
184
152
|
}
|
|
185
|
-
|
|
186
153
|
asset.invalidateOnEnvChange('SASS_PATH');
|
|
187
|
-
|
|
188
154
|
if (options.env.SASS_PATH) {
|
|
189
155
|
paths.push(...options.env.SASS_PATH.split(process.platform === 'win32' ? ';' : ':').map(p => _path().default.resolve(options.projectRoot, p)));
|
|
190
156
|
}
|
|
191
|
-
|
|
192
157
|
const urls = [url];
|
|
193
|
-
|
|
194
158
|
const urlFileName = _path().default.basename(url);
|
|
195
|
-
|
|
196
159
|
if (urlFileName[0] !== '_') {
|
|
197
160
|
urls.push(_path().default.join(_path().default.dirname(url), `_${urlFileName}`));
|
|
198
161
|
}
|
|
199
|
-
|
|
200
162
|
if (url[0] !== '~') {
|
|
201
163
|
for (let p of paths) {
|
|
202
164
|
for (let u of urls) {
|
|
203
165
|
const filePath = _path().default.resolve(p, u);
|
|
204
|
-
|
|
205
166
|
try {
|
|
206
167
|
const contents = await asset.fs.readFile(filePath, 'utf8');
|
|
207
168
|
return {
|
|
@@ -215,17 +176,17 @@ function resolvePathImporter({
|
|
|
215
176
|
}
|
|
216
177
|
}
|
|
217
178
|
}
|
|
218
|
-
}
|
|
219
|
-
|
|
179
|
+
}
|
|
220
180
|
|
|
181
|
+
// If none of the default sass rules apply, try Parcel's resolver.
|
|
221
182
|
for (let u of urls) {
|
|
222
183
|
if (NODE_MODULE_ALIAS_RE.test(u)) {
|
|
223
184
|
u = u.slice(1);
|
|
224
185
|
}
|
|
225
|
-
|
|
226
186
|
try {
|
|
227
|
-
const filePath = await resolve(prev, u
|
|
228
|
-
|
|
187
|
+
const filePath = await resolve(prev, u, {
|
|
188
|
+
packageConditions: ['sass', 'style']
|
|
189
|
+
});
|
|
229
190
|
if (filePath) {
|
|
230
191
|
const contents = await asset.fs.readFile(filePath, 'utf8');
|
|
231
192
|
return {
|
|
@@ -238,7 +199,6 @@ function resolvePathImporter({
|
|
|
238
199
|
}
|
|
239
200
|
}
|
|
240
201
|
}
|
|
241
|
-
|
|
242
202
|
return function (rawUrl, prev, done) {
|
|
243
203
|
const url = rawUrl.replace(/^file:\/\//, '');
|
|
244
204
|
resolvePath(url, prev).then(resolved => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/transformer-sass",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"source": "src/SassTransformer.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 12.0.0",
|
|
20
|
-
"parcel": "^2.
|
|
20
|
+
"parcel": "^2.9.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/plugin": "2.
|
|
23
|
+
"@parcel/plugin": "2.9.0",
|
|
24
24
|
"@parcel/source-map": "^2.1.1",
|
|
25
25
|
"sass": "^1.38.0"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "dd9435be8afed35c5ffc161cf4b586fd6c78fc1f"
|
|
28
28
|
}
|
package/src/SassTransformer.js
CHANGED
|
@@ -12,7 +12,7 @@ const NODE_MODULE_ALIAS_RE = /^~[^/\\]/;
|
|
|
12
12
|
export default (new Transformer({
|
|
13
13
|
async loadConfig({config, options}) {
|
|
14
14
|
let configFile = await config.getConfig(
|
|
15
|
-
['.sassrc', '.sassrc.json', '.sassrc.js', '.sassrc.cjs'],
|
|
15
|
+
['.sassrc', '.sassrc.json', '.sassrc.js', '.sassrc.cjs', '.sassrc.mjs'],
|
|
16
16
|
{
|
|
17
17
|
packageKey: 'sass',
|
|
18
18
|
},
|
|
@@ -27,10 +27,6 @@ export default (new Transformer({
|
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
if (configFile && path.extname(configFile.filePath).endsWith('js')) {
|
|
31
|
-
config.invalidateOnStartup();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
30
|
if (configResult.importer === undefined) {
|
|
35
31
|
configResult.importer = [];
|
|
36
32
|
} else if (!Array.isArray(configResult.importer)) {
|
|
@@ -163,7 +159,9 @@ function resolvePathImporter({asset, resolve, includePaths, options}) {
|
|
|
163
159
|
u = u.slice(1);
|
|
164
160
|
}
|
|
165
161
|
try {
|
|
166
|
-
const filePath = await resolve(prev, u
|
|
162
|
+
const filePath = await resolve(prev, u, {
|
|
163
|
+
packageConditions: ['sass', 'style'],
|
|
164
|
+
});
|
|
167
165
|
if (filePath) {
|
|
168
166
|
const contents = await asset.fs.readFile(filePath, 'utf8');
|
|
169
167
|
return {filePath, contents};
|