Skip to content

Commit

Permalink
chore: remove tercer and clean-css and update to [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
buttercubz committed Mar 12, 2021
1 parent 1334e26 commit ee710b2
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 68 deletions.
38 changes: 2 additions & 36 deletions compiler/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import { URL_SVELTE_CDN } from "../src/shared/version.ts";
import { resolve, toFileUrl } from "../imports/path.ts";
import { decoder, encoder } from "../shared/encoder.ts";
import { compile, preprocess } from "./compiler.ts";
import { CleanCSS } from "../imports/clean-css.ts";
import { importToUrl } from "../shared/utils.ts";
import { rollup } from "../imports/drollup.ts";
import { minify } from "../imports/terser.ts";
import svelte from "../src/shared/bundler.js";
import { colors } from "../imports/fmt.ts";
import { BuildOptions } from "./types.ts";
Expand Down Expand Up @@ -79,7 +77,6 @@ export async function build(

async style({ attributes, filename, content }) {
let css: string | null = null;
const clear = new CleanCSS({ compatibility: "*" });

try {
// transform scss to css
Expand All @@ -93,32 +90,16 @@ export async function build(
css = code;
}

// minify css
const { styles, errors, warnings } = clear.minify(css ?? content);

if (warnings?.length) {
warnings.forEach((warning: string) => {
console.warn(colors.yellow(warning));
});
}

if (errors?.length) {
errors.forEach((errors: string) => {
console.error(colors.red(errors));
});
throw new SyntaxError(colors.red("css error")).message;
}

// asign styles
css = styles;
css = css ?? content;
} catch (error: any) {
throw new Error(
colors.red(`compiling to css ${colors.yellow(filename!)}`)
).message;
}

return {
code: css ?? content,
code: css,
};
},
},
Expand Down Expand Up @@ -156,21 +137,6 @@ export async function build(
);
}

// compress javascript to production
if (dist) {
const { code: minCode } = await minify(compiled.js.code, {
compress: false,
ecma: 2020,
mangle: true,
keep_classnames: true,
keep_fnames: true,
});

if (minCode) {
compiled.js.code = minCode;
}
}

await file.write(encoder.encode(compiled.js.code));

if (out.paths.length) {
Expand Down
1 change: 0 additions & 1 deletion imports/clean-css.ts

This file was deleted.

28 changes: 10 additions & 18 deletions imports/deps.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"meta": {
"fs": {
"url": "https://deno.land/std@0.88.0/fs/mod.ts",
"hash": "160840c03025e78d4512362c0d8d15ba41b10594a61a5456949f63c1a1797d49"
"url": "https://deno.land/std@0.90.0/fs/mod.ts",
"hash": "5c12ca0952c454e2be474b5ac65cc49288f307dbcd0360f1ae523125f4d05965"
},
"path": {
"url": "https://deno.land/std@0.88.0/path/mod.ts",
"hash": "a1a1e12dc34c12ec63e519a81782e3bdb5a2eedd21a82dafad8ee5291646f449"
"url": "https://deno.land/std@0.90.0/path/mod.ts",
"hash": "fba81713aa6df38478273602c0cdec1744234416d9c1ebc56400daf81b8977b4"
},
"fmt": {
"url": "https://denopkg.com/crewdevio/Trex@proxy/proxy/files/fmt.ts",
"hash": "5b4388adfdc1f5ad8a727f95a91c3f255cb36f430b6b4503f8f3ddacc162db53"
},
"flags": {
"url": "https://deno.land/std@0.88.0/flags/mod.ts",
"hash": "1ba1d570e2571a1b1d8783136cfa6f092669d1de82f45295a7963972fca6f279"
"url": "https://deno.land/std@0.90.0/flags/mod.ts",
"hash": "9f7cba7424af3947d05b9b24b304c40edd9f74f3a4580d54f6bbf367b241b30d"
},
"http": {
"url": "https://deno.land/std@0.88.0/http/mod.ts",
"hash": "ea4daf62b6c032db8a931fd4741c7edc60b489a8405062740fce23c4371bd257"
"url": "https://deno.land/std@0.90.0/http/mod.ts",
"hash": "573fbf4d2576d6a329d11289e2d4ea09f500eca7d84c80963fa13d57e88a22d1"
},
"assert_util": {
"url": "https://deno.land/[email protected]/_util/assert.ts",
Expand All @@ -40,17 +40,9 @@
"url": "https://deno.land/x/[email protected]/vendor/less/less.js",
"hash": "2142d07ff2b26f4044bf29ae41d85ef4c6e19f09f7156c530c414e9554a9b12e"
},
"terser": {
"url": "https://esm.sh/[email protected]",
"hash": "eaa64ba1f10950c38e11df2fc8dd2291b0f367d596bc89652318691c6b071a2d"
},
"clean-css": {
"url": "https://esm.sh/[email protected]?no-check",
"hash": "6d4758390abcd7aaf12432b1e144a4be6e7ec82bd75704ec0c74c5dbee820f78"
},
"run": {
"url": "https://deno.land/x/trex@v1.4.0/commands/run.ts",
"hash": "d021ee2ba3373e4d07e92637536079852582cc55dfa72ad3b966f0a45890f875"
"url": "https://deno.land/x/trex/commands/run.ts",
"hash": "60709d493cd22794bf66cb3ff3cb391f6f208ce2d8b2b64b854295e15509475d"
},
"drollup": {
"url": "https://deno.land/x/[email protected]+0.14.0/mod.ts",
Expand Down
2 changes: 1 addition & 1 deletion imports/flags.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.88.0/flags/mod.ts";
export * from "https://deno.land/std@0.90.0/flags/mod.ts";
2 changes: 1 addition & 1 deletion imports/fs.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.88.0/fs/mod.ts";
export * from "https://deno.land/std@0.90.0/fs/mod.ts";
2 changes: 1 addition & 1 deletion imports/http.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.88.0/http/mod.ts";
export * from "https://deno.land/std@0.90.0/http/mod.ts";
2 changes: 1 addition & 1 deletion imports/path.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.88.0/path/mod.ts";
export * from "https://deno.land/std@0.90.0/path/mod.ts";
2 changes: 1 addition & 1 deletion imports/run.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/x/trex@v1.4.0/commands/run.ts";
export * from "https://deno.land/x/trex/commands/run.ts";
1 change: 0 additions & 1 deletion imports/terser.ts

This file was deleted.

4 changes: 2 additions & 2 deletions install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
const install = async (name: string, url: string) => {
const process = Deno.run({
cmd: [
...`deno install -A -f -r --no-check --unstable -n ${name} ${url}`.split(
...`${Deno.execPath()} install -A -f -r --no-check --unstable -n ${name} ${url}`.split(
" "
),
],
Expand All @@ -22,7 +22,7 @@ async function Main() {
try {
await install("snel", "https://deno.land/x/snel/cli.ts");
await install("trex", "https://deno.land/x/trex/cli.ts");
await install("bundler", "https://deno.land/x/bundler@0.5.1/cli.ts");
await install("bundler", "https://deno.land/x/bundler@0.6.0/cli.ts");
} catch (error: any) {
console.log(error?.message);
}
Expand Down
7 changes: 3 additions & 4 deletions src/shared/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ export default (options = {}) => {
{
async script({ content, attributes, filename }) {
let code = content;
let isTs = false;
// transpile to javascript
if (attributes?.lang === "ts") {
code = await tsTranspiler(code, filename ?? "");
}
if (attributes?.lang === "ts") isTs = true;
// resolve import map calls
code = importToUrl(content, mapPattern, "map:");

return {
code,
code: isTs ? await tsTranspiler(code, filename) : code,
};
},
async style({ attributes, filename, content }) {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function stract(source: string) {
const pattern = /import(?:["'\s]*([\w\n\r\t, ]+)from\s*)?["'\s]["'\s](.*[@\w_-]+)["'\s].*$/gim;

const isSvelte = (chunk: string) =>
pattern.test(chunk) && chunk.includes(".svelte");
pattern.test(chunk) && (chunk.includes(".svelte") || chunk.includes("svelte/"));

const chunks = source.split("\n");
// get .svelte import statement
Expand Down

0 comments on commit ee710b2

Please sign in to comment.