@jesscss/plugin-scss 2.0.0-alpha.7
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/LICENSE +21 -0
- package/README.md +3 -0
- package/lib/index.cjs +120 -0
- package/lib/index.js +92 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Matthew Dean
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
//#region \0rolldown/runtime.js
|
|
6
|
+
var __create = Object.create;
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
+
key = keys[i];
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: ((k) => from[k]).bind(null, key),
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
//#endregion
|
|
27
|
+
let _jesscss_core = require("@jesscss/core");
|
|
28
|
+
let _jesscss_scss_parser_jess = require("@jesscss/scss-parser/jess");
|
|
29
|
+
let node_path = require("node:path");
|
|
30
|
+
node_path = __toESM(node_path);
|
|
31
|
+
let _jesscss_style_resolver = require("@jesscss/style-resolver");
|
|
32
|
+
//#region src/index.ts
|
|
33
|
+
var ScssPlugin = class extends _jesscss_core.AbstractPlugin {
|
|
34
|
+
name = "scss";
|
|
35
|
+
supportedExtensions = [".scss"];
|
|
36
|
+
parser;
|
|
37
|
+
unitMode;
|
|
38
|
+
equalityMode;
|
|
39
|
+
constructor(opts = {}) {
|
|
40
|
+
super();
|
|
41
|
+
this.opts = opts;
|
|
42
|
+
this.unitMode = opts.unitMode ?? "preserve";
|
|
43
|
+
this.equalityMode = opts.equalityMode ?? "sass";
|
|
44
|
+
this.parser = new _jesscss_scss_parser_jess.Parser();
|
|
45
|
+
}
|
|
46
|
+
expandImport(importPath) {
|
|
47
|
+
return (0, _jesscss_style_resolver.expandScssImportCandidates)(importPath);
|
|
48
|
+
}
|
|
49
|
+
safeParse(filePath, source, parseOptions) {
|
|
50
|
+
const allowExtendSelectors = this.opts.allowExtendSelectors ?? parseOptions?.compilerOptions?.allowExtendSelectors ?? ["simple"];
|
|
51
|
+
const context = new _jesscss_core.TreeContext({
|
|
52
|
+
file: {
|
|
53
|
+
name: node_path.default.basename(filePath),
|
|
54
|
+
path: node_path.default.dirname(filePath),
|
|
55
|
+
fullPath: filePath,
|
|
56
|
+
source
|
|
57
|
+
},
|
|
58
|
+
plugin: this,
|
|
59
|
+
allowExtendSelectors,
|
|
60
|
+
unitMode: this.unitMode,
|
|
61
|
+
equalityMode: this.equalityMode,
|
|
62
|
+
collapseNesting: this.opts.collapseNesting ?? false
|
|
63
|
+
});
|
|
64
|
+
const errors = [];
|
|
65
|
+
const warnings = [];
|
|
66
|
+
let tree;
|
|
67
|
+
try {
|
|
68
|
+
const parseResult = this.parser.parse(source, "Stylesheet", { context });
|
|
69
|
+
tree = parseResult.tree;
|
|
70
|
+
if (parseResult.errors.length) for (const error of parseResult.errors) {
|
|
71
|
+
const line = error.token?.startLine ?? 1;
|
|
72
|
+
const diagnostic = (0, _jesscss_core.toDiagnostic)((0, _jesscss_core.getErrorFromParser)([error], void 0, filePath, source, { file: context.file }));
|
|
73
|
+
if (!diagnostic.lines) diagnostic.lines = (0, _jesscss_core.extractRelevantLines)(source, line);
|
|
74
|
+
if ("errors" in diagnostic) errors.push(diagnostic);
|
|
75
|
+
else warnings.push(diagnostic);
|
|
76
|
+
}
|
|
77
|
+
const lexErrors = parseResult.lexerResult?.errors ?? [];
|
|
78
|
+
if (lexErrors.length) for (const lexError of lexErrors) {
|
|
79
|
+
const line = typeof lexError.line === "number" ? lexError.line : 1;
|
|
80
|
+
const diagnostic = (0, _jesscss_core.toDiagnostic)((0, _jesscss_core.getErrorFromParser)([], [lexError], filePath, source, { file: context.file }));
|
|
81
|
+
if (!diagnostic.lines) diagnostic.lines = (0, _jesscss_core.extractRelevantLines)(source, line);
|
|
82
|
+
if ("errors" in diagnostic) errors.push(diagnostic);
|
|
83
|
+
else warnings.push(diagnostic);
|
|
84
|
+
}
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error instanceof _jesscss_core.JessError) {
|
|
87
|
+
const diagnostic = (0, _jesscss_core.toDiagnostic)(error);
|
|
88
|
+
if ("errors" in diagnostic) errors.push(diagnostic);
|
|
89
|
+
else warnings.push(diagnostic);
|
|
90
|
+
} else {
|
|
91
|
+
const message = error instanceof Error ? error.message : "Unknown parsing error";
|
|
92
|
+
errors.push({
|
|
93
|
+
code: "internal/unknown",
|
|
94
|
+
phase: "parse",
|
|
95
|
+
message,
|
|
96
|
+
reason: message,
|
|
97
|
+
fix: "Check the file syntax and ensure it is valid.",
|
|
98
|
+
file: context.file,
|
|
99
|
+
filePath,
|
|
100
|
+
line: 1,
|
|
101
|
+
column: 1,
|
|
102
|
+
lines: (0, _jesscss_core.extractRelevantLines)(source, 1)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
errors,
|
|
107
|
+
warnings
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
tree,
|
|
112
|
+
errors,
|
|
113
|
+
warnings
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const scssPlugin = ((opts) => new ScssPlugin(opts));
|
|
118
|
+
//#endregion
|
|
119
|
+
exports.ScssPlugin = ScssPlugin;
|
|
120
|
+
exports.default = scssPlugin;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { AbstractPlugin, JessError, TreeContext, extractRelevantLines, getErrorFromParser, toDiagnostic } from "@jesscss/core";
|
|
2
|
+
import { Parser } from "@jesscss/scss-parser/jess";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { expandScssImportCandidates } from "@jesscss/style-resolver";
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
var ScssPlugin = class extends AbstractPlugin {
|
|
7
|
+
name = "scss";
|
|
8
|
+
supportedExtensions = [".scss"];
|
|
9
|
+
parser;
|
|
10
|
+
unitMode;
|
|
11
|
+
equalityMode;
|
|
12
|
+
constructor(opts = {}) {
|
|
13
|
+
super();
|
|
14
|
+
this.opts = opts;
|
|
15
|
+
this.unitMode = opts.unitMode ?? "preserve";
|
|
16
|
+
this.equalityMode = opts.equalityMode ?? "sass";
|
|
17
|
+
this.parser = new Parser();
|
|
18
|
+
}
|
|
19
|
+
expandImport(importPath) {
|
|
20
|
+
return expandScssImportCandidates(importPath);
|
|
21
|
+
}
|
|
22
|
+
safeParse(filePath, source, parseOptions) {
|
|
23
|
+
const allowExtendSelectors = this.opts.allowExtendSelectors ?? parseOptions?.compilerOptions?.allowExtendSelectors ?? ["simple"];
|
|
24
|
+
const context = new TreeContext({
|
|
25
|
+
file: {
|
|
26
|
+
name: path.basename(filePath),
|
|
27
|
+
path: path.dirname(filePath),
|
|
28
|
+
fullPath: filePath,
|
|
29
|
+
source
|
|
30
|
+
},
|
|
31
|
+
plugin: this,
|
|
32
|
+
allowExtendSelectors,
|
|
33
|
+
unitMode: this.unitMode,
|
|
34
|
+
equalityMode: this.equalityMode,
|
|
35
|
+
collapseNesting: this.opts.collapseNesting ?? false
|
|
36
|
+
});
|
|
37
|
+
const errors = [];
|
|
38
|
+
const warnings = [];
|
|
39
|
+
let tree;
|
|
40
|
+
try {
|
|
41
|
+
const parseResult = this.parser.parse(source, "Stylesheet", { context });
|
|
42
|
+
tree = parseResult.tree;
|
|
43
|
+
if (parseResult.errors.length) for (const error of parseResult.errors) {
|
|
44
|
+
const line = error.token?.startLine ?? 1;
|
|
45
|
+
const diagnostic = toDiagnostic(getErrorFromParser([error], void 0, filePath, source, { file: context.file }));
|
|
46
|
+
if (!diagnostic.lines) diagnostic.lines = extractRelevantLines(source, line);
|
|
47
|
+
if ("errors" in diagnostic) errors.push(diagnostic);
|
|
48
|
+
else warnings.push(diagnostic);
|
|
49
|
+
}
|
|
50
|
+
const lexErrors = parseResult.lexerResult?.errors ?? [];
|
|
51
|
+
if (lexErrors.length) for (const lexError of lexErrors) {
|
|
52
|
+
const line = typeof lexError.line === "number" ? lexError.line : 1;
|
|
53
|
+
const diagnostic = toDiagnostic(getErrorFromParser([], [lexError], filePath, source, { file: context.file }));
|
|
54
|
+
if (!diagnostic.lines) diagnostic.lines = extractRelevantLines(source, line);
|
|
55
|
+
if ("errors" in diagnostic) errors.push(diagnostic);
|
|
56
|
+
else warnings.push(diagnostic);
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error instanceof JessError) {
|
|
60
|
+
const diagnostic = toDiagnostic(error);
|
|
61
|
+
if ("errors" in diagnostic) errors.push(diagnostic);
|
|
62
|
+
else warnings.push(diagnostic);
|
|
63
|
+
} else {
|
|
64
|
+
const message = error instanceof Error ? error.message : "Unknown parsing error";
|
|
65
|
+
errors.push({
|
|
66
|
+
code: "internal/unknown",
|
|
67
|
+
phase: "parse",
|
|
68
|
+
message,
|
|
69
|
+
reason: message,
|
|
70
|
+
fix: "Check the file syntax and ensure it is valid.",
|
|
71
|
+
file: context.file,
|
|
72
|
+
filePath,
|
|
73
|
+
line: 1,
|
|
74
|
+
column: 1,
|
|
75
|
+
lines: extractRelevantLines(source, 1)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
errors,
|
|
80
|
+
warnings
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
tree,
|
|
85
|
+
errors,
|
|
86
|
+
warnings
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const scssPlugin = ((opts) => new ScssPlugin(opts));
|
|
91
|
+
//#endregion
|
|
92
|
+
export { ScssPlugin, scssPlugin as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jesscss/plugin-scss",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"description": "An SCSS stylesheet engine for Jess",
|
|
7
|
+
"version": "2.0.0-alpha.7",
|
|
8
|
+
"main": "lib/index.cjs",
|
|
9
|
+
"types": "lib/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./lib/index.d.ts",
|
|
13
|
+
"import": "./lib/index.js",
|
|
14
|
+
"require": "./lib/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"lib"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@jesscss/core": "2.0.0-alpha.7",
|
|
23
|
+
"@jesscss/scss-parser": "2.0.0-alpha.7",
|
|
24
|
+
"@jesscss/style-resolver": "2.0.0-alpha.7"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {},
|
|
27
|
+
"author": "Matthew Dean <matthew-dean@users.noreply.github.com>",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/jesscss/jess/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/jesscss/jess#readme",
|
|
33
|
+
"type": "module",
|
|
34
|
+
"module": "lib/index.js",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"ci": "pnpm build && pnpm test",
|
|
37
|
+
"build": "pnpm compile",
|
|
38
|
+
"compile": "tsdown --tsconfig tsconfig.build.json --no-dts && tsc -p tsconfig.build.json --emitDeclarationOnly --noCheck",
|
|
39
|
+
"test": "vitest --run --passWithNoTests",
|
|
40
|
+
"lint:fix": "eslint --fix '**/*.{js,ts}'",
|
|
41
|
+
"lint": "eslint '**/*.{js,ts}'"
|
|
42
|
+
}
|
|
43
|
+
}
|