swc updates

This commit is contained in:
Robin Appelman 2024-06-07 22:47:28 +02:00
commit 49a100bb61
11 changed files with 2759 additions and 2515 deletions

3
.gitignore vendored
View file

@ -5,4 +5,5 @@ config.toml
.env
node_modules
*.key
*.crt
*.crt
*.c.js

834
Cargo.lock generated

File diff suppressed because it is too large Load diff

2135
build/Cargo.lock generated

File diff suppressed because it is too large Load diff

2027
build/bundlers/Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,23 +4,24 @@ version = "0.1.0"
edition = "2021"
[dependencies]
lightningcss = { version = "1.0.0-alpha.40", features = ["browserslist", "visitor"] }
lightningcss = { version = "1.0.0-alpha.57", features = ["browserslist", "visitor"] }
base64 = "0.21.0"
urlencoding = "2.1.2"
swc = "0.260.20"
swc_common = { version = "0.31.4", features = ["tty-emitter", "concurrent"] }
swc_core = { version = "0.75.20" }
swc_bundler = { version = "0.213.14" }
swc_ecma_loader = { version = "0.43.5", features = ["node", "cache"] }
swc_ecma_ast = { version = "0.103.4" }
swc_atoms = { version = "0.5.3" }
swc_ecma_parser = { version = "0.133.8", features = ["typescript"] }
swc_ecma_codegen = { version = "0.138.9" }
swc_ecma_transforms_base = { version = "0.126.10" }
swc_ecma_transforms_typescript = { version = "0.176.12" }
swc_ecma_visit = { version = "0.89.4" }
swc = "0.273.28"
swc_common = { version = "0.33", features = ["tty-emitter", "concurrent"] }
swc_core = { version = "0.90" }
swc_bundler = { version = "0.225.19" }
swc_ecma_loader = { version = "0.45.28", features = ["node", "cache"] }
swc_ecma_ast = { version = "0.112.8" }
swc_atoms = { version = "0.6.7" }
swc_ecma_parser = { version = "0.143.16", features = ["typescript"] }
swc_ecma_codegen = { version = "0.148.18" }
swc_ecma_transforms_base = { version = "0.137.21" }
swc_ecma_transforms_typescript = { version = "0.188.19" }
swc_ecma_visit = { version = "0.98.7" }
anyhow = "1.0.70"
jsx-dom-expressions = { version = "0.1", git = "https://github.com/icewind1991/swc-plugin-jsx-dom-expressions", branch = "mixed-svg" }
jsx-dom-expressions = { version = "0.1", git = "https://github.com/icewind1991/swc-plugin-jsx-dom-expressions", branch = "fix-builtin-import" }
#jsx-dom-expressions = { version = "0.1", git = "https://github.com/milomg/swc-plugin-jsx-dom-expressions" }
#jsx-dom-expressions = { version = "0.1", path = "../../../../rust/swc-plugin-jsx-dom-expressions" }
rand = "0.8.5"
fnv = "1.0.7"

View file

@ -71,10 +71,7 @@ pub fn bundle_script(script: &str) -> Vec<u8> {
fn write<W: Write>(minify: bool, cm: Arc<SourceMap>, module: &Module, out: W) {
let wr = JsWriter::new(cm.clone(), "\n", out, None);
let mut emitter = Emitter {
cfg: swc_ecma_codegen::Config {
minify,
..Default::default()
},
cfg: swc_ecma_codegen::Config::default().with_minify(minify),
cm: cm.clone(),
comments: None,
wr: if minify {
@ -152,15 +149,17 @@ impl Load for Loader {
panic!("failed to parse")
});
let program = Program::Module(module);
let top_level_mark = Mark::new();
let module = module
let program = program
.fold_with(&mut strip(top_level_mark))
.fold_with(&mut as_folder(InlineVisitor {}))
.fold_with(&mut as_folder(TransformVisitor::new(
jsx_dom_expressions::config::Config {
module_name: "solid-js/web".to_string(),
builtins: vec![
built_ins: vec![
"For".into(),
"Show".into(),
"Switch".into(),
@ -179,6 +178,8 @@ impl Load for Loader {
.fold_with(&mut hygiene())
.fold_with(&mut fixer(None));
let module = program.module().unwrap();
// if let FileName::Real(path) = &f {
// let mut out = vec![];
// write(false, self.cm.clone(), &module, &mut out);

View file

@ -14,10 +14,7 @@ pub fn bundle_style(style: &str) -> Vec<u8> {
let mut bundler = Bundler::new(
&fs,
None,
ParserOptions {
nesting: true,
..ParserOptions::default()
},
ParserOptions::default(),
);
let mut stylesheet = bundler
.bundle(Path::new(style))
@ -26,7 +23,7 @@ pub fn bundle_style(style: &str) -> Vec<u8> {
Browsers::from_browserslist(["last 2 versions"]).expect("failed to parse browserlist");
stylesheet
.minify(MinifyOptions {
targets: browsers.clone(),
targets: browsers.into(),
..MinifyOptions::default()
})
.expect("failed to minify css");
@ -40,7 +37,7 @@ pub fn bundle_style(style: &str) -> Vec<u8> {
stylesheet
.to_css(PrinterOptions {
targets: browsers,
targets: browsers.into(),
minify,
..PrinterOptions::default()
})
@ -54,7 +51,9 @@ struct InlineUrlVisitor;
impl<'i> Visitor<'i> for InlineUrlVisitor {
type Error = Infallible;
const TYPES: VisitTypes = visit_types!(URLS);
fn visit_types(&self) -> VisitTypes {
visit_types!(URLS)
}
fn visit_url(&mut self, url: &mut Url<'i>) -> Result<(), Self::Error> {
if let Some(path) = url.url.strip_prefix("inline://") {

14
flake.lock generated
View file

@ -61,16 +61,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1710687127,
"narHash": "sha256-aniO4SFoJhJffjKkk9BDnEtfA3tXkAiFOfDbPb1ua7g=",
"lastModified": 1717763955,
"narHash": "sha256-KTFz7DM0eHpsvuXky0xOmDSp+dCSsB2ODH69UDaGdIs=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "43bbce16740a3d7b2163bdd2c4cab41dae518584",
"rev": "4984dd33b2b489065500233eae7defc4659c3c59",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "release-23.11",
"ref": "release-24.05",
"type": "indirect"
}
},
@ -139,11 +139,11 @@
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1710641527,
"narHash": "sha256-R9JZEevtSyg7++LEryYJRrfyEe45azJxmu2k9VezEW0=",
"lastModified": 1717726729,
"narHash": "sha256-2WDKLjVRKWXbadnJHSOUb46PTq3D5nS89vhHTphRw1M=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "50db54295d3922a3b7a40d580b84d75150b36c34",
"rev": "7f52ac9ae95bd60c0780d6e32baea22e542e11e1",
"type": "github"
},
"original": {

View file

@ -1,7 +1,7 @@
{
inputs = {
utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/release-23.11";
nixpkgs.url = "nixpkgs/release-24.05";
rust-overlay.url = "github:oxalica/rust-overlay";
npmlock2nix.url = "github:nix-community/npmlock2nix";
npmlock2nix.flake = false;

122
module.nix Normal file
View file

@ -0,0 +1,122 @@
{
config,
lib,
pkgs,
...
}:
with lib; let
format = pkgs.formats.toml {};
configFile = format.generate "demostf-frontend.toml" {
output.target = cfg.outputPath;
mqtt = {
inherit (cfg.mqtt) hostname port username;
"password-file" = "$CREDENTIALS_DIRECTORY/mqtt_password";
};
device."password-file" = "$CREDENTIALS_DIRECTORY/device_password";
};
cfg = config.services.demostf-frontend;
in {
options.services.demostf-frontend = {
enable = mkEnableOption "Log archiver";
outputPath = mkOption {
type = types.str;
description = "Directory to save the backups into";
};
mqtt = mkOption {
type = types.submodule {
options = {
hostname = mkOption {
type = types.str;
description = "MQTT hostname";
};
port = mkOption {
type = types.port;
default = 1883;
description = "MQTT port";
};
username = mkOption {
type = types.str;
description = "MQTT username";
};
passwordFile = mkOption {
type = types.str;
description = "File containing the MQTT password";
};
};
};
description = "MQTT options";
};
devicePasswordFile = mkOption {
type = types.str;
description = "File containing the device password";
};
interval = mkOption {
type = types.str;
default = "daily";
description = "Interval to run the backup";
};
package = mkOption {
type = types.package;
defaultText = literalExpression "pkgs.tasproxy";
description = "package to use";
};
};
config = mkIf cfg.enable {
systemd.services."demostf-frontend" = {
description = "Backup tasmota configurations";
serviceConfig = {
ExecStart = "${cfg.package}/bin/demostf-frontend ${configFile}";
LoadCredential = [
"mqtt_password:${cfg.mqtt.passwordFile}"
"device_password:${cfg.devicePasswordFile}"
];
ReadWritePaths = [cfg.outputPath];
Restart = "on-failure";
DynamicUser = true;
PrivateTmp = true;
ProtectSystem = "strict";
ProtectHome = true;
NoNewPrivileges = true;
PrivateDevices = true;
ProtectClock = true;
CapabilityBoundingSet = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
SystemCallArchitectures = "native";
ProtectKernelModules = true;
RestrictNamespaces = true;
MemoryDenyWriteExecute = true;
ProtectHostname = true;
LockPersonality = true;
ProtectKernelTunables = true;
RestrictAddressFamilies = "AF_INET AF_INET6";
RestrictRealtime = true;
ProtectProc = "noaccess";
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
IPAddressDeny = "multicast";
PrivateUsers = true;
ProcSubset = "pid";
RuntimeDirectory = "demostf-frontend";
RestrictSUIDSGID = true;
};
};
systemd.timers."demostf-frontend" = {
inherit (config.systemd.services."demostf-frontend") description;
enable = true;
wantedBy = ["multi-user.target"];
timerConfig = {
OnCalendar = cfg.interval;
RandomizedDelaySec = "15m";
};
};
};
}

View file

@ -27,10 +27,12 @@ in
ln -s ${demostf-frontend-node-modules}/node_modules .
'';
doCheck = false;
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"jsx-dom-expressions-0.1.0" = "sha256-k5lLHS2umLRwZU0gaszrqCesDAxFVQXMfScT4Ry0SkI=";
"jsx-dom-expressions-0.1.0" = "sha256-5TN9FBfPYznTkpL9ZtnKv3RghX7r8c2WvSL1sc+F0cw=";
};
};
}