From 06549a66da1b9e3082e55aea4e014f563d139975 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 16 Nov 2020 11:29:03 +0100 Subject: [PATCH 1/9] chore: update denopack and static folder --- deps/mod.ts | 16 +++++++-------- example/pages/_document.tsx | 2 +- example/public/{ => static}/logo.png | Bin example/public/{ => static}/style.css | 0 src/bundle.ts | 27 +++++++++++++------------- 5 files changed, 23 insertions(+), 22 deletions(-) rename example/public/{ => static}/logo.png (100%) rename example/public/{ => static}/style.css (100%) diff --git a/deps/mod.ts b/deps/mod.ts index 7300415..3475fe4 100644 --- a/deps/mod.ts +++ b/deps/mod.ts @@ -1,4 +1,4 @@ -export { rollup } from "https://raw.githubusercontent.com/denofn/denopack/d9b2416279ce5d9eb66af235df6bd89c1891d306/deps.ts"; +export { rollup } from "https://raw.githubusercontent.com/denofn/denopack/77aa4af97421999a14a80c3497ab5dcd64bac3f0/deps.ts"; export type { ModuleFormat, OutputAsset, @@ -11,13 +11,13 @@ export type { RollupCache, RollupOptions, RollupOutput, -} from "https://raw.githubusercontent.com/denofn/denopack/d9b2416279ce5d9eb66af235df6bd89c1891d306/deps.ts"; +} from "https://raw.githubusercontent.com/denofn/denopack/77aa4af97421999a14a80c3497ab5dcd64bac3f0/deps.ts"; -export { useCache } from "https://raw.githubusercontent.com/denofn/denopack/d9b2416279ce5d9eb66af235df6bd89c1891d306/plugin/mod.ts"; -export { pluginTerserTransform } from "https://raw.githubusercontent.com/denofn/denopack/d9b2416279ce5d9eb66af235df6bd89c1891d306/plugin/terserTransform/mod.ts"; +export { useCache } from "https://raw.githubusercontent.com/denofn/denopack/77aa4af97421999a14a80c3497ab5dcd64bac3f0/plugin/mod.ts"; +export { pluginTerserTransform } from "https://raw.githubusercontent.com/denofn/denopack/77aa4af97421999a14a80c3497ab5dcd64bac3f0/plugin/terserTransform/mod.ts"; -export { persistSourceMaps } from "https://raw.githubusercontent.com/denofn/denopack/d9b2416279ce5d9eb66af235df6bd89c1891d306/cli/persistSourceMaps.ts"; -export { emitFiles } from "https://raw.githubusercontent.com/denofn/denopack/d9b2416279ce5d9eb66af235df6bd89c1891d306/cli/emitFiles.ts"; +export { persistSourceMaps } from "https://raw.githubusercontent.com/denofn/denopack/77aa4af97421999a14a80c3497ab5dcd64bac3f0/cli/persistSourceMaps.ts"; +export { emitFiles } from "https://raw.githubusercontent.com/denofn/denopack/77aa4af97421999a14a80c3497ab5dcd64bac3f0/cli/emitFiles.ts"; // std export * as colors from "https://deno.land/std@0.77.0/fmt/colors.ts"; @@ -45,7 +45,7 @@ export { compress as brotliEncode } from "https://deno.land/x/brotli@v0.1.4/mod. import { default as _debounce } from "https://unpkg.com/lodash-es@4.17.15/debounce.js"; export const debounce = _debounce as < - T extends (...args: unknown[]) => unknown, + T extends (...args: unknown[]) => unknown >( func: T, wait?: number, @@ -53,7 +53,7 @@ export const debounce = _debounce as < leading?: boolean; maxWait?: number; trailing?: boolean; - }, + } ) => T; export { prettyBytes } from "https://raw.githubusercontent.com/BrunnerLivio/deno-pretty-bytes/db6d9ede681f666f5b6f58aa35ba5b638c820f84/prettyBytes.ts"; diff --git a/example/pages/_document.tsx b/example/pages/_document.tsx index bb7060e..079e28f 100644 --- a/example/pages/_document.tsx +++ b/example/pages/_document.tsx @@ -7,7 +7,7 @@ function Document(props: DocumentProps) { - + {props.children} diff --git a/example/public/logo.png b/example/public/static/logo.png similarity index 100% rename from example/public/logo.png rename to example/public/static/logo.png diff --git a/example/public/style.css b/example/public/static/style.css similarity index 100% rename from example/public/style.css rename to example/public/static/style.css diff --git a/src/bundle.ts b/src/bundle.ts index b598257..c61ce87 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -50,13 +50,15 @@ export async function bundle( hotRefresh: boolean; hotRefreshHost?: string; debug: boolean; - }, + } ): Promise<{ cache: RollupCache | undefined; stats: BundleStats | undefined }> { const outputOptions: OutputOptions = { dir: options.outDir, format: "es", sourcemap: true, compact: true, + chunkFileNames: "static/[name]-[hash].js", + assetFileNames: "assets/[name]-[hash][extname]", }; const tsconfig = JSON.parse(await Deno.readTextFile(options.tsconfigPath)); @@ -75,12 +77,12 @@ export async function bundle( ...useCache(tsconfig), ...(options.minify ? [ - pluginTerserTransform({ - module: true, - compress: true, - mangle: true, - }), - ] + pluginTerserTransform({ + module: true, + compress: true, + mangle: true, + }), + ] : []), ], output: outputOptions, @@ -135,7 +137,7 @@ export async function bundle( gzip: gz.length, brotli: br.length, }; - }, + } ); for await (const _ of res) { @@ -146,15 +148,14 @@ export async function bundle( const shared: Record = {}; const chunks = generated.output.filter( - (d) => d.type === "chunk", + (d) => d.type === "chunk" ) as OutputChunk[]; for (const out of chunks) { const filename = `/${out.fileName}`; if (out.facadeModuleId && out.facadeModuleId.startsWith("dext-page://")) { const page = pages.pages.find( - (p) => - p.path === out.facadeModuleId!.substring("dext-page://".length), + (p) => p.path === out.facadeModuleId!.substring("dext-page://".length) )!; const imports = [ ...flattenImports(chunks, out.fileName), @@ -207,7 +208,7 @@ export async function bundle( function flattenImports( chunks: OutputChunk[], fileName: string, - visited: string[] = [], + visited: string[] = [] ): string[] { const chunk = chunks.find((chunk) => (chunk.fileName = fileName)); if (!chunk) throw new Error("Failed to find chunk " + fileName); @@ -217,7 +218,7 @@ function flattenImports( if (visited.includes(fileName)) return []; visited.push(fileName); return [fileName, ...flattenImports(chunks, fileName, visited)]; - }), + }) ), ]; } From 72a0d595208f6904cf3a6da352d58f73e293927a Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 16 Nov 2020 11:32:50 +0100 Subject: [PATCH 2/9] reenable nightly --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95a572f..4f035ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - deno: ["v1.x"] # "nightly" is broken today + deno: ["v1.x", "nightly"] os: [macOS-latest, windows-latest, ubuntu-latest] steps: From 3dfeebf0c5298a936d305b43a230024950b6c6aa Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 16 Nov 2020 11:35:21 +0100 Subject: [PATCH 3/9] fmt --- deps/mod.ts | 4 ++-- src/bundle.ts | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/deps/mod.ts b/deps/mod.ts index 3475fe4..6b35461 100644 --- a/deps/mod.ts +++ b/deps/mod.ts @@ -45,7 +45,7 @@ export { compress as brotliEncode } from "https://deno.land/x/brotli@v0.1.4/mod. import { default as _debounce } from "https://unpkg.com/lodash-es@4.17.15/debounce.js"; export const debounce = _debounce as < - T extends (...args: unknown[]) => unknown + T extends (...args: unknown[]) => unknown, >( func: T, wait?: number, @@ -53,7 +53,7 @@ export const debounce = _debounce as < leading?: boolean; maxWait?: number; trailing?: boolean; - } + }, ) => T; export { prettyBytes } from "https://raw.githubusercontent.com/BrunnerLivio/deno-pretty-bytes/db6d9ede681f666f5b6f58aa35ba5b638c820f84/prettyBytes.ts"; diff --git a/src/bundle.ts b/src/bundle.ts index c61ce87..24b8569 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -50,7 +50,7 @@ export async function bundle( hotRefresh: boolean; hotRefreshHost?: string; debug: boolean; - } + }, ): Promise<{ cache: RollupCache | undefined; stats: BundleStats | undefined }> { const outputOptions: OutputOptions = { dir: options.outDir, @@ -77,12 +77,12 @@ export async function bundle( ...useCache(tsconfig), ...(options.minify ? [ - pluginTerserTransform({ - module: true, - compress: true, - mangle: true, - }), - ] + pluginTerserTransform({ + module: true, + compress: true, + mangle: true, + }), + ] : []), ], output: outputOptions, @@ -137,7 +137,7 @@ export async function bundle( gzip: gz.length, brotli: br.length, }; - } + }, ); for await (const _ of res) { @@ -148,14 +148,15 @@ export async function bundle( const shared: Record = {}; const chunks = generated.output.filter( - (d) => d.type === "chunk" + (d) => d.type === "chunk", ) as OutputChunk[]; for (const out of chunks) { const filename = `/${out.fileName}`; if (out.facadeModuleId && out.facadeModuleId.startsWith("dext-page://")) { const page = pages.pages.find( - (p) => p.path === out.facadeModuleId!.substring("dext-page://".length) + (p) => + p.path === out.facadeModuleId!.substring("dext-page://".length), )!; const imports = [ ...flattenImports(chunks, out.fileName), @@ -208,7 +209,7 @@ export async function bundle( function flattenImports( chunks: OutputChunk[], fileName: string, - visited: string[] = [] + visited: string[] = [], ): string[] { const chunk = chunks.find((chunk) => (chunk.fileName = fileName)); if (!chunk) throw new Error("Failed to find chunk " + fileName); @@ -218,7 +219,7 @@ function flattenImports( if (visited.includes(fileName)) return []; visited.push(fileName); return [fileName, ...flattenImports(chunks, fileName, visited)]; - }) + }), ), ]; } From 9c861a21b659a2b10f441718f9426c3ce0ca8ede Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 16 Nov 2020 14:37:10 +0100 Subject: [PATCH 4/9] debug --- src/bundle.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/bundle.ts b/src/bundle.ts index 24b8569..5ff8c0a 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -50,7 +50,7 @@ export async function bundle( hotRefresh: boolean; hotRefreshHost?: string; debug: boolean; - }, + } ): Promise<{ cache: RollupCache | undefined; stats: BundleStats | undefined }> { const outputOptions: OutputOptions = { dir: options.outDir, @@ -77,12 +77,12 @@ export async function bundle( ...useCache(tsconfig), ...(options.minify ? [ - pluginTerserTransform({ - module: true, - compress: true, - mangle: true, - }), - ] + pluginTerserTransform({ + module: true, + compress: true, + mangle: true, + }), + ] : []), ], output: outputOptions, @@ -137,7 +137,7 @@ export async function bundle( gzip: gz.length, brotli: br.length, }; - }, + } ); for await (const _ of res) { @@ -148,15 +148,15 @@ export async function bundle( const shared: Record = {}; const chunks = generated.output.filter( - (d) => d.type === "chunk", + (d) => d.type === "chunk" ) as OutputChunk[]; for (const out of chunks) { const filename = `/${out.fileName}`; + console.log(filename); if (out.facadeModuleId && out.facadeModuleId.startsWith("dext-page://")) { const page = pages.pages.find( - (p) => - p.path === out.facadeModuleId!.substring("dext-page://".length), + (p) => p.path === out.facadeModuleId!.substring("dext-page://".length) )!; const imports = [ ...flattenImports(chunks, out.fileName), @@ -209,7 +209,7 @@ export async function bundle( function flattenImports( chunks: OutputChunk[], fileName: string, - visited: string[] = [], + visited: string[] = [] ): string[] { const chunk = chunks.find((chunk) => (chunk.fileName = fileName)); if (!chunk) throw new Error("Failed to find chunk " + fileName); @@ -219,7 +219,7 @@ function flattenImports( if (visited.includes(fileName)) return []; visited.push(fileName); return [fileName, ...flattenImports(chunks, fileName, visited)]; - }), + }) ), ]; } From 4bdf1b428b6c088b04d5c36f8c9e355169393c07 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 16 Nov 2020 14:39:29 +0100 Subject: [PATCH 5/9] fmt --- src/bundle.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/bundle.ts b/src/bundle.ts index 5ff8c0a..5673221 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -50,7 +50,7 @@ export async function bundle( hotRefresh: boolean; hotRefreshHost?: string; debug: boolean; - } + }, ): Promise<{ cache: RollupCache | undefined; stats: BundleStats | undefined }> { const outputOptions: OutputOptions = { dir: options.outDir, @@ -77,12 +77,12 @@ export async function bundle( ...useCache(tsconfig), ...(options.minify ? [ - pluginTerserTransform({ - module: true, - compress: true, - mangle: true, - }), - ] + pluginTerserTransform({ + module: true, + compress: true, + mangle: true, + }), + ] : []), ], output: outputOptions, @@ -137,7 +137,7 @@ export async function bundle( gzip: gz.length, brotli: br.length, }; - } + }, ); for await (const _ of res) { @@ -148,7 +148,7 @@ export async function bundle( const shared: Record = {}; const chunks = generated.output.filter( - (d) => d.type === "chunk" + (d) => d.type === "chunk", ) as OutputChunk[]; for (const out of chunks) { @@ -156,7 +156,8 @@ export async function bundle( console.log(filename); if (out.facadeModuleId && out.facadeModuleId.startsWith("dext-page://")) { const page = pages.pages.find( - (p) => p.path === out.facadeModuleId!.substring("dext-page://".length) + (p) => + p.path === out.facadeModuleId!.substring("dext-page://".length), )!; const imports = [ ...flattenImports(chunks, out.fileName), @@ -209,7 +210,7 @@ export async function bundle( function flattenImports( chunks: OutputChunk[], fileName: string, - visited: string[] = [] + visited: string[] = [], ): string[] { const chunk = chunks.find((chunk) => (chunk.fileName = fileName)); if (!chunk) throw new Error("Failed to find chunk " + fileName); @@ -219,7 +220,7 @@ function flattenImports( if (visited.includes(fileName)) return []; visited.push(fileName); return [fileName, ...flattenImports(chunks, fileName, visited)]; - }) + }), ), ]; } From e59364a56c2dc56e1c1bcfffb79e77e5eeefc341 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 16 Nov 2020 14:42:53 +0100 Subject: [PATCH 6/9] more debug --- src/bundle.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bundle.ts b/src/bundle.ts index 5673221..eeee8bd 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -132,6 +132,7 @@ export async function bundle( await Deno.writeFile(path + ".gz", gz); const br = brotliEncode(file, undefined, 11); await Deno.writeFile(path + ".br", br); + console.log("path", path.slice(outDir.length).replace("\\", "/")) fileStats[path.slice(outDir.length).replace("\\", "/")] = { raw: file.length, gzip: gz.length, From 7f548348f39cd89ca0b72ce9020d1e74bc4d351e Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 16 Nov 2020 14:44:48 +0100 Subject: [PATCH 7/9] fmt --- src/bundle.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundle.ts b/src/bundle.ts index eeee8bd..aae4cb8 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -132,7 +132,7 @@ export async function bundle( await Deno.writeFile(path + ".gz", gz); const br = brotliEncode(file, undefined, 11); await Deno.writeFile(path + ".br", br); - console.log("path", path.slice(outDir.length).replace("\\", "/")) + console.log("path", path.slice(outDir.length).replace("\\", "/")); fileStats[path.slice(outDir.length).replace("\\", "/")] = { raw: file.length, gzip: gz.length, From 98cd205a18de52b77d3fa2a08ca81efb2cec540c Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 16 Nov 2020 14:47:42 +0100 Subject: [PATCH 8/9] fix --- src/bundle.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/bundle.ts b/src/bundle.ts index aae4cb8..acd1fb2 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -132,8 +132,7 @@ export async function bundle( await Deno.writeFile(path + ".gz", gz); const br = brotliEncode(file, undefined, 11); await Deno.writeFile(path + ".br", br); - console.log("path", path.slice(outDir.length).replace("\\", "/")); - fileStats[path.slice(outDir.length).replace("\\", "/")] = { + fileStats[path.slice(outDir.length).replaceAll("\\", "/")] = { raw: file.length, gzip: gz.length, brotli: br.length, @@ -154,7 +153,6 @@ export async function bundle( for (const out of chunks) { const filename = `/${out.fileName}`; - console.log(filename); if (out.facadeModuleId && out.facadeModuleId.startsWith("dext-page://")) { const page = pages.pages.find( (p) => From 9398b63c5e915091c4eed167d8ff82aca7181e31 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 16 Nov 2020 15:07:42 +0100 Subject: [PATCH 9/9] disable windows --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f035ed..d84b6f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: deno: ["v1.x", "nightly"] - os: [macOS-latest, windows-latest, ubuntu-latest] + os: [macOS-latest, ubuntu-latest] # disable on windows-latest because fly tls aint working there steps: - name: Disable autocrlf