diff --git a/core/_repl.ts b/core/_repl.ts index 983a9e8..5eefae0 100644 --- a/core/_repl.ts +++ b/core/_repl.ts @@ -1,7 +1,13 @@ -import type { TarStreamEntry } from "@std/tar/untar-stream"; -import { UntarStream } from "@std/tar/untar-stream"; +import type { TarStreamEntry } from "@bundle/utils/tar"; +import { UntarStream } from "@bundle/utils/tar"; import { normalize, join } from "@bundle/utils/path"; +import { getFile, setFile, PLATFORM_AUTO, TheFileSystem } from "./mod.ts"; +import { context, cancel, dispose, rebuild, } from "./mod.ts"; + +const fs = await TheFileSystem; + + // const response = await fetch("https://pkg.pr.new/@tanstack/react-query@7988"); // const content = await response.arrayBuffer(); @@ -63,36 +69,36 @@ import { normalize, join } from "@bundle/utils/path"; // console.log({ // path: join("./", path) // }) -// // setFile(args.namespace + ":" + join("./", path), uint8arr); +// setFile(fs, join("./tar/", path), uint8arr); // } // } -import { getFile, setFile, PLATFORM_AUTO, TheFileSystem } from "./mod.ts"; -import { context, cancel, dispose, rebuild, } from "./mod.ts"; -const fs = await TheFileSystem; - // console.log({ // version: await resolveVersion(`esbuild@0.18`) // }) console.log("\n"); -await setFile(fs, "/index.tsx", `\ -export * as Other from "/new.tsx"; -export * from "@okikio/animate";`); -await setFile(fs, "/new.tsx", "export * from \"@okikio/native\";"); -await setFile(fs, "/other.tsx", `\ -export * as Other from "/index.tsx"; -export * from "@okikio/emitter";`); - -console.log(await getFile(fs, "/index.tsx", "string") ) +// await setFile(fs, "/index.tsx", `\ +// export * as Other from "/new.tsx"; +// export * from "@okikio/animate";`); +// await setFile(fs, "/new.tsx", "export * from \"@okikio/native\";"); +await setFile(fs, "/new.tsx", "export * from \"https://pkg.pr.new/@tanstack/react-query@7988\"") +// await setFile(fs, "/other.tsx", `\ +// export * as Other from "/index.tsx"; +// export * from "@okikio/emitter";`); + +// console.log(await getFile(fs, "/index.tsx", "string") ) + +console.log(await getFile(fs, "/new.tsx", "string") ) console.log(fs) const ctx = await context({ - entryPoints: ["/index.tsx", "/new.tsx"], + // "/index.tsx", + entryPoints: ["/new.tsx"], esbuild: { treeShaking: true, splitting: true, @@ -116,20 +122,20 @@ console.log({ }); -await setFile(fs, "/index.tsx", `\ - export * as Other from "/new.tsx"; - export * from "spring-easing";`); -const result2 = await rebuild(ctx); +// await setFile(fs, "/index.tsx", `\ +// export * as Other from "/new.tsx"; +// export * from "spring-easing";`); +// const result2 = await rebuild(ctx); -console.log({ - result2, - // packageManifests: result2.state.packageManifests, - // // await compress( - // // result.contents.map((x: any) => x?.contents), - // // { type: "gzip" } - // // ) -}); +// console.log({ +// result2, +// // packageManifests: result2.state.packageManifests, +// // // await compress( +// // // result.contents.map((x: any) => x?.contents), +// // // { type: "gzip" } +// // // ) +// }); await cancel(ctx); await dispose(ctx); diff --git a/core/build.ts b/core/build.ts index 180fecf..d3b3125 100644 --- a/core/build.ts +++ b/core/build.ts @@ -3,6 +3,7 @@ import type { FullPackageVersion, PackageJson } from "@bundle/utils/types"; import { VirtualFileSystemPlugin } from "./plugins/fs.ts"; import { ExternalPlugin } from "./plugins/external.ts"; +import { TarballPlugin } from "./plugins/tar.ts"; import { AliasPlugin } from "./plugins/alias.ts"; import { HttpPlugin } from "./plugins/http.ts"; import { CdnPlugin } from "./plugins/cdn.ts"; @@ -73,12 +74,14 @@ export async function build(opts: BuildConfig = {}, filesystem: Promise(), - failedManifestUrls: new Set(), + failedExtensionChecks: new Set(), + failedManifestUrls: new Set(), host: DEFAULT_CDN_HOST, - versions: new Map(), + versions: new Map(), + tarballInflight: new Map(), + tarballMounts: new Map(), - packageManifests: new Map(), + packageManifests: new Map(), }); const LocalConfig = fromContext("config", StateContext)!; @@ -121,6 +124,7 @@ export async function build(opts: BuildConfig = {}, filesystem: Promise), ], @@ -211,7 +215,10 @@ export async function formatBuildResult(_ctx: BuildResultContext) { // FileSystem.clear(); // console.log({ contentsLen: contents.length }) - const packageManifests = fromContext('packageManifests', StateContext) ?? new Map(); + const packageManifests = + fromContext('packageManifests', StateContext) + ?? new Map(); + const packageSizeArr: [string, string][] = []; let totalInstallSize = 0; diff --git a/core/context.ts b/core/context.ts index a6dc7e4..d1a0201 100644 --- a/core/context.ts +++ b/core/context.ts @@ -1,9 +1,9 @@ -import type { FullPackageVersion, PackageJson } from "@bundle/utils/types"; import type { BuildConfig, ESBUILD, LocalState } from "./types.ts"; import type { BuildResult } from "./build.ts"; import { VirtualFileSystemPlugin } from "./plugins/fs.ts"; import { ExternalPlugin } from "./plugins/external.ts"; +import { TarballPlugin } from "./plugins/tar.ts"; import { AliasPlugin } from "./plugins/alias.ts"; import { HttpPlugin } from "./plugins/http.ts"; import { CdnPlugin } from "./plugins/cdn.ts"; @@ -30,11 +30,15 @@ export async function context(opts: BuildConfig = {}, filesystem = TheFileSystem filesystem: await filesystem, assets: [], config: createConfig("build", opts), - failedExtensionChecks: new Set(), - failedManifestUrls: new Set(), + failedExtensionChecks: new Set(), + failedManifestUrls: new Set(), host: DEFAULT_CDN_HOST, - versions: new Map(), - packageManifests: new Map(), + versions: new Map(), + + tarballInflight: new Map(), + tarballMounts: new Map(), + + packageManifests: new Map(), }); const LocalConfig = fromContext("config", StateContext)!; @@ -77,6 +81,7 @@ export async function context(opts: BuildConfig = {}, filesystem = TheFileSystem AliasPlugin(StateContext), ExternalPlugin(StateContext), VirtualFileSystemPlugin(StateContext), + TarballPlugin(StateContext), HttpPlugin(StateContext), CdnPlugin(StateContext.with({ origin: host }) as Context), ], diff --git a/core/types.ts b/core/types.ts index 08d41db..3ee3365 100644 --- a/core/types.ts +++ b/core/types.ts @@ -3,8 +3,9 @@ import type * as ESBUILD_WASM from "esbuild-wasm"; import type { FullPackageVersion, PackageJson } from "@bundle/utils/types"; import type { InitOptions } from "./init.ts"; -import type { IFileSystem } from "./utils/filesystem.ts"; import type { record } from "./context/context.ts"; +import type { IFileSystem } from "./utils/filesystem.ts"; +import type { TarballState } from "./plugins/tar.ts"; export type { ESBUILD, ESBUILD_WASM }; @@ -18,7 +19,7 @@ export interface CommonConfigOptions extends record { /** * Local state available to all plugins */ -export interface LocalState extends record { +export interface LocalState extends TarballState, record { filesystem: IFileSystem, /**