@pronto-tools-and-more/sass-compiler 3.3.8
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/package.json +29 -0
- package/src/parts/Assert/Assert.js +1 -0
- package/src/parts/Callback/Callback.js +1 -0
- package/src/parts/Command/Command.js +9 -0
- package/src/parts/CommandMap/CommandMap.js +10 -0
- package/src/parts/CommandState/CommandState.js +17 -0
- package/src/parts/CompileSass/CompileSass.js +51 -0
- package/src/parts/CompileSassIndividually/CompileSassIndividually.js +82 -0
- package/src/parts/GetContent/GetContent.js +10 -0
- package/src/parts/HandleIpc/HandleIpc.js +10 -0
- package/src/parts/HandleMessage/HandleMessage.js +27 -0
- package/src/parts/InMemoryFileState/InMemoryFileState.js +11 -0
- package/src/parts/IpcChild/IpcChild.js +15 -0
- package/src/parts/IpcChildModule/IpcChildModule.js +25 -0
- package/src/parts/IpcChildType/IpcChildType.js +20 -0
- package/src/parts/IpcId/IpcId.js +9 -0
- package/src/parts/JsonRpc/JsonRpc.js +1 -0
- package/src/parts/Listen/Listen.js +8 -0
- package/src/parts/Main/Main.js +8 -0
- package/src/parts/UpdateCss/UpdateCss.js +17 -0
- package/src/sassCompilerMain.js +3 -0
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pronto-tools-and-more/sass-compiler",
|
|
3
|
+
"version": "3.3.8",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "src/sassCompilerMain.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "node --unhandled-rejections=warn --experimental-vm-modules ./node_modules/jest/bin/jest.js --detectOpenHandles --forceExit",
|
|
9
|
+
"test:watch": "node --unhandled-rejections=warn --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch",
|
|
10
|
+
"type-check": "tsc"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@lvce-editor/assert": "^1.2.0",
|
|
17
|
+
"@lvce-editor/ipc": "^9.1.0",
|
|
18
|
+
"@lvce-editor/json-rpc": "^1.3.0",
|
|
19
|
+
"@lvce-editor/verror": "^1.3.0",
|
|
20
|
+
"sass": "^1.77.2"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^20.12.7",
|
|
24
|
+
"jest": "^29.7.0"
|
|
25
|
+
},
|
|
26
|
+
"jest": {
|
|
27
|
+
"injectGlobals": false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@lvce-editor/assert";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolve } from "@lvce-editor/json-rpc";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as CompileSass from "../CompileSass/CompileSass.js";
|
|
2
|
+
import * as CompileSassIndividually from "../CompileSassIndividually/CompileSassIndividually.js";
|
|
3
|
+
import * as InMemoryFileState from "../InMemoryFileState/InMemoryFileState.js";
|
|
4
|
+
|
|
5
|
+
export const commandMap = {
|
|
6
|
+
"CompileSass.compileSass": CompileSass.compileSass,
|
|
7
|
+
"CompileSass.compileSassIndividually":
|
|
8
|
+
CompileSassIndividually.compileSassIndividually,
|
|
9
|
+
"CompileSass.set": InMemoryFileState.set,
|
|
10
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const state = {
|
|
2
|
+
commands: Object.create(null),
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export const registerCommand = (key, fn) => {
|
|
6
|
+
state.commands[key] = fn;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const registerCommands = (commandMap) => {
|
|
10
|
+
for (const [key, value] of Object.entries(commandMap)) {
|
|
11
|
+
registerCommand(key, value);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const getCommand = (key) => {
|
|
16
|
+
return state.commands[key];
|
|
17
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { VError } from "@lvce-editor/verror";
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
+
import * as sass from "sass";
|
|
4
|
+
import * as Assert from "../Assert/Assert.js";
|
|
5
|
+
import * as GetContent from "../GetContent/GetContent.js";
|
|
6
|
+
import * as UpdateCss from "../UpdateCss/UpdateCss.js";
|
|
7
|
+
|
|
8
|
+
export const compileSass = async ({
|
|
9
|
+
absolutePath = "",
|
|
10
|
+
updateDynamicResources = true,
|
|
11
|
+
sourceMap = false,
|
|
12
|
+
} = {}) => {
|
|
13
|
+
try {
|
|
14
|
+
Assert.string(absolutePath);
|
|
15
|
+
const content = GetContent.getContent(absolutePath);
|
|
16
|
+
const result = sass.compileString(content, {
|
|
17
|
+
url: pathToFileURL(absolutePath),
|
|
18
|
+
importers: [
|
|
19
|
+
{
|
|
20
|
+
canonicalize(url) {
|
|
21
|
+
return new URL(url);
|
|
22
|
+
},
|
|
23
|
+
load(canonicalUrl) {
|
|
24
|
+
const path = fileURLToPath(canonicalUrl);
|
|
25
|
+
const content = GetContent.getContent(path);
|
|
26
|
+
return {
|
|
27
|
+
contents: content,
|
|
28
|
+
syntax: "scss",
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
sourceMap,
|
|
34
|
+
});
|
|
35
|
+
let css = result.css;
|
|
36
|
+
if (updateDynamicResources) {
|
|
37
|
+
const updated = UpdateCss.updateCss(css);
|
|
38
|
+
return {
|
|
39
|
+
css: updated,
|
|
40
|
+
sourceMap: result.sourceMap,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const reverse = UpdateCss.reverseUpdateCss(css);
|
|
44
|
+
return {
|
|
45
|
+
css: reverse,
|
|
46
|
+
sourceMap: result.sourceMap,
|
|
47
|
+
};
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw new VError(error, `Failed to compile sass`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { VError } from "@lvce-editor/verror";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import * as Assert from "../Assert/Assert.js";
|
|
5
|
+
import * as CompileSass from "../CompileSass/CompileSass.js";
|
|
6
|
+
import * as InMemoryFileState from "../InMemoryFileState/InMemoryFileState.js";
|
|
7
|
+
|
|
8
|
+
const getIndividualFileNames = (contents) => {
|
|
9
|
+
const lines = contents.split("\n");
|
|
10
|
+
const individualFileNames = [];
|
|
11
|
+
for (const line of lines) {
|
|
12
|
+
if (line && line.startsWith("@import")) {
|
|
13
|
+
const match = line.slice('@import "./'.length, -2);
|
|
14
|
+
if (match.endsWith(".scss")) {
|
|
15
|
+
individualFileNames.push(match);
|
|
16
|
+
} else {
|
|
17
|
+
individualFileNames.push(match + ".scss");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return individualFileNames;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const getFileNamesToUpdate = (
|
|
25
|
+
individualFileNames,
|
|
26
|
+
rootScssFileName,
|
|
27
|
+
fileName,
|
|
28
|
+
needsFull
|
|
29
|
+
) => {
|
|
30
|
+
if (needsFull || !fileName) {
|
|
31
|
+
return individualFileNames;
|
|
32
|
+
}
|
|
33
|
+
// console.log({ individualFileNames, fileName });
|
|
34
|
+
for (const individualFileName of individualFileNames) {
|
|
35
|
+
const absolutePath = join(dirname(rootScssFileName), individualFileName);
|
|
36
|
+
if (absolutePath === fileName) {
|
|
37
|
+
return [individualFileName];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
console.info(`[pronto] no matching scss file found for ${fileName}`);
|
|
41
|
+
return [];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const compileSassIndividually = async (
|
|
45
|
+
rootScssFileName,
|
|
46
|
+
{
|
|
47
|
+
updateDynamicResources = true,
|
|
48
|
+
fileName = "",
|
|
49
|
+
needsFull = true,
|
|
50
|
+
content = undefined,
|
|
51
|
+
} = {}
|
|
52
|
+
) => {
|
|
53
|
+
try {
|
|
54
|
+
Assert.string(rootScssFileName);
|
|
55
|
+
if (fileName && content) {
|
|
56
|
+
InMemoryFileState.set(fileName, content);
|
|
57
|
+
}
|
|
58
|
+
const contents = await readFile(rootScssFileName, "utf8");
|
|
59
|
+
const individualFileNames = getIndividualFileNames(contents);
|
|
60
|
+
const toUpdate = getFileNamesToUpdate(
|
|
61
|
+
individualFileNames,
|
|
62
|
+
rootScssFileName,
|
|
63
|
+
fileName,
|
|
64
|
+
needsFull
|
|
65
|
+
);
|
|
66
|
+
const results = [];
|
|
67
|
+
for (const fileName of toUpdate) {
|
|
68
|
+
const absolutePath = join(dirname(rootScssFileName), fileName);
|
|
69
|
+
const result = await CompileSass.compileSass({
|
|
70
|
+
updateDynamicResources,
|
|
71
|
+
absolutePath,
|
|
72
|
+
});
|
|
73
|
+
results.push({
|
|
74
|
+
fileName,
|
|
75
|
+
css: result.css,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return results;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
throw new VError(error, `Failed to compile sass`);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import * as InMemoryFileState from "../InMemoryFileState/InMemoryFileState.js";
|
|
3
|
+
|
|
4
|
+
export const getContent = (uri) => {
|
|
5
|
+
const memoryResult = InMemoryFileState.get(uri);
|
|
6
|
+
if (memoryResult) {
|
|
7
|
+
return memoryResult;
|
|
8
|
+
}
|
|
9
|
+
return readFileSync(uri, "utf8");
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as HandleMessage from "../HandleMessage/HandleMessage.js";
|
|
2
|
+
|
|
3
|
+
export const handleIpc = (ipc) => {
|
|
4
|
+
if ("addEventListener" in ipc) {
|
|
5
|
+
ipc.addEventListener("message", HandleMessage.handleMessage);
|
|
6
|
+
} else if ("on" in ipc) {
|
|
7
|
+
// deprecated
|
|
8
|
+
ipc.on("message", HandleMessage.handleMessage);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as Callback from "../Callback/Callback.js";
|
|
2
|
+
import * as Command from "../Command/Command.js";
|
|
3
|
+
import * as JsonRpc from "../JsonRpc/JsonRpc.js";
|
|
4
|
+
|
|
5
|
+
const prepare = (error) => {
|
|
6
|
+
return error;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const requiresSocket = (method) => {
|
|
10
|
+
return false;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const logError = (error, prettyError) => {
|
|
14
|
+
console.error(error);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const handleMessage = (event) => {
|
|
18
|
+
return JsonRpc.handleJsonRpcMessage(
|
|
19
|
+
event.target,
|
|
20
|
+
event.data,
|
|
21
|
+
Command.execute,
|
|
22
|
+
Callback.resolve,
|
|
23
|
+
prepare,
|
|
24
|
+
logError,
|
|
25
|
+
requiresSocket,
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as IpcChildModule from "../IpcChildModule/IpcChildModule.js";
|
|
2
|
+
|
|
3
|
+
export const listen = async ({ method, ...params }) => {
|
|
4
|
+
const module = await IpcChildModule.getModule(method);
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const rawIpc = await module.listen(params);
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
if (module.signal) {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
module.signal(rawIpc);
|
|
11
|
+
}
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
const ipc = module.wrap(rawIpc);
|
|
14
|
+
return ipc;
|
|
15
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IpcChildWithElectronMessagePort,
|
|
3
|
+
IpcChildWithElectronUtilityProcess,
|
|
4
|
+
IpcChildWithNodeForkedProcess,
|
|
5
|
+
IpcChildWithNodeWorker,
|
|
6
|
+
IpcChildWithWebSocket,
|
|
7
|
+
} from "@lvce-editor/ipc";
|
|
8
|
+
import * as IpcChildType from "../IpcChildType/IpcChildType.js";
|
|
9
|
+
|
|
10
|
+
export const getModule = (method) => {
|
|
11
|
+
switch (method) {
|
|
12
|
+
case IpcChildType.NodeForkedProcess:
|
|
13
|
+
return IpcChildWithNodeForkedProcess;
|
|
14
|
+
case IpcChildType.NodeWorker:
|
|
15
|
+
return IpcChildWithNodeWorker;
|
|
16
|
+
case IpcChildType.ElectronUtilityProcess:
|
|
17
|
+
return IpcChildWithElectronUtilityProcess;
|
|
18
|
+
case IpcChildType.ElectronMessagePort:
|
|
19
|
+
return IpcChildWithElectronMessagePort;
|
|
20
|
+
case IpcChildType.WebSocket:
|
|
21
|
+
return IpcChildWithWebSocket;
|
|
22
|
+
default:
|
|
23
|
+
throw new Error("unexpected ipc type");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const NodeWorker = 1;
|
|
2
|
+
export const NodeForkedProcess = 2;
|
|
3
|
+
export const ElectronUtilityProcess = 3;
|
|
4
|
+
export const ElectronMessagePort = 4;
|
|
5
|
+
export const NodeMessagePort = 5;
|
|
6
|
+
export const WebSocket = 6;
|
|
7
|
+
|
|
8
|
+
export const Auto = () => {
|
|
9
|
+
const { argv } = process;
|
|
10
|
+
if (argv.includes("--ipc-type=node-worker")) {
|
|
11
|
+
return NodeWorker;
|
|
12
|
+
}
|
|
13
|
+
if (argv.includes("--ipc-type=node-forked-process")) {
|
|
14
|
+
return NodeForkedProcess;
|
|
15
|
+
}
|
|
16
|
+
if (argv.includes("--ipc-type=electron-utility-process")) {
|
|
17
|
+
return ElectronUtilityProcess;
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`[shared-process] unknown ipc type`);
|
|
20
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const EmbedsProcess = 2;
|
|
2
|
+
export const EmbedsWorker = 77;
|
|
3
|
+
export const ExtensionHostHelperProcess = 3;
|
|
4
|
+
export const MainProcess = -5;
|
|
5
|
+
export const ProcessExplorer = 11;
|
|
6
|
+
export const SearchProcess = 13;
|
|
7
|
+
export const SharedProcess = 1;
|
|
8
|
+
export const TerminalProcess = 7;
|
|
9
|
+
export const Unknown = 0;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@lvce-editor/json-rpc";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as HandleIpc from "../HandleIpc/HandleIpc.js";
|
|
2
|
+
import * as IpcChild from "../IpcChild/IpcChild.js";
|
|
3
|
+
import * as IpcChildType from "../IpcChildType/IpcChildType.js";
|
|
4
|
+
|
|
5
|
+
export const listen = async () => {
|
|
6
|
+
const ipc = await IpcChild.listen({ method: IpcChildType.Auto() });
|
|
7
|
+
HandleIpc.handleIpc(ipc);
|
|
8
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as CommandMap from "../CommandMap/CommandMap.js";
|
|
2
|
+
import * as CommandState from "../CommandState/CommandState.js";
|
|
3
|
+
import * as Listen from "../Listen/Listen.js";
|
|
4
|
+
|
|
5
|
+
export const main = async () => {
|
|
6
|
+
CommandState.registerCommands(CommandMap.commandMap);
|
|
7
|
+
await Listen.listen();
|
|
8
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const occurrenceSnippet = "resource://dynamic";
|
|
2
|
+
const replacementSnippet = ``;
|
|
3
|
+
|
|
4
|
+
export const updateCss = (content) => {
|
|
5
|
+
return content.replaceAll(occurrenceSnippet, replacementSnippet);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const reverseOccurrenceSnippet = "../../images";
|
|
9
|
+
|
|
10
|
+
const reverseReplacementSnippet = "resource://dynamic/storefront/images";
|
|
11
|
+
|
|
12
|
+
export const reverseUpdateCss = (content) => {
|
|
13
|
+
return content.replaceAll(
|
|
14
|
+
reverseOccurrenceSnippet,
|
|
15
|
+
reverseReplacementSnippet
|
|
16
|
+
);
|
|
17
|
+
};
|