transone-cli 0.6.0 → 0.6.3

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.
@@ -740,6 +740,7 @@ var MP_WEIXIN_DIALECT = {
740
740
  backgroundTextStyle: "light"
741
741
  }),
742
742
  appJsonExtras: () => ({
743
+ lazyCodeLoading: "requiredComponents",
743
744
  style: "v2",
744
745
  sitemapLocation: "sitemap.json"
745
746
  }),
@@ -853,7 +854,7 @@ class MpTarget {
853
854
  if (!config.mp) {
854
855
  throw new Error("Mini program build requires config.mp\uFF08\u8BF7\u5728 transone.config.ts \u914D\u7F6E mp \u5B57\u6BB5\uFF0C" + "\u5982 appId / pages / outDir\uFF09");
855
856
  }
856
- const { buildMiniProgram } = await import("./build-mp-004pd4h0.js");
857
+ const { buildMiniProgram } = await import("./build-mp-vk5ap2cw.js");
857
858
  return buildMiniProgram(config, this.dialect);
858
859
  }
859
860
  }
@@ -1368,7 +1369,7 @@ async function runTsc(root, tsconfig) {
1368
1369
  import { existsSync as existsSync4, mkdirSync, writeFileSync } from "fs";
1369
1370
  import { basename as basename2, join as join2 } from "path";
1370
1371
  var TRANSONE_FRAMEWORK_VERSION = "0.4.0";
1371
- var TRANSONE_CLI_VERSION = "0.6.0";
1372
+ var TRANSONE_CLI_VERSION = "0.6.3";
1372
1373
  var GITHUB_URL = "https://github.com/geektech-team/transone";
1373
1374
  function createProject(options = {}) {
1374
1375
  const root = options.root ?? process.cwd();
@@ -1522,6 +1523,7 @@ app.mount();
1522
1523
 
1523
1524
  // src/server.ts
1524
1525
  import { randomUUID } from "crypto";
1526
+ import { rm as rm4 } from "fs/promises";
1525
1527
  import {
1526
1528
  basename as basename3,
1527
1529
  extname,
@@ -1765,6 +1767,7 @@ function isRecursiveWatchUnsupported(error) {
1765
1767
  var DEVELOPMENT_URL_PREFIX = "/dev";
1766
1768
  var INVALID_DEVELOPMENT_DIRECTORY_MESSAGE = "Development output must be a subdirectory of the project root";
1767
1769
  var LIVE_RELOAD_PATH = "/__transone/reload";
1770
+ var DEVELOPMENT_OUTPUT_RETENTION_MS = 5000;
1768
1771
  var WATCHED_EXTENSIONS = new Set([
1769
1772
  ".ts",
1770
1773
  ".js",
@@ -1793,7 +1796,9 @@ async function startDevServer(options = {}) {
1793
1796
  return startWatchingDevServer(options);
1794
1797
  }
1795
1798
  const instance = await createServerInstance(options, false);
1796
- return instance.server;
1799
+ return createServerHandle(() => instance, () => {
1800
+ return;
1801
+ });
1797
1802
  }
1798
1803
  async function startWatchingDevServer(options) {
1799
1804
  let instance = await createServerInstance(options, true);
@@ -1821,7 +1826,8 @@ async function startWatchingDevServer(options) {
1821
1826
  }
1822
1827
  async function restart() {
1823
1828
  watcher.dispose();
1824
- instance.server.stop(true);
1829
+ await instance.server.stop(true);
1830
+ await instance.dispose();
1825
1831
  instance = await createServerInstance(options, true);
1826
1832
  watcher = createProjectWatcher(instance, onChange);
1827
1833
  console.log(`TransOne dev server restarted at http://${instance.server.hostname}:${instance.server.port}`);
@@ -1849,16 +1855,18 @@ async function createServerInstance(options, watch2) {
1849
1855
  const sessionId = createGenerationId();
1850
1856
  const sessionOutDir = resolve6(developmentOutDir, sessionId);
1851
1857
  const artifacts = new Map;
1852
- const buildProject = createDevelopmentBuilder(sessionId, sessionOutDir);
1858
+ const buildProject = createDevelopmentBuilder(sessionId, sessionOutDir, artifacts);
1853
1859
  const liveReload = watch2 ? createLiveReloadHub() : undefined;
1854
1860
  const bundles = new Map;
1855
1861
  const dirtyEntries = new Set;
1856
- const getBundle = async (entry) => {
1862
+ const getBundle = async (entry, acquire = false) => {
1857
1863
  const cached = bundles.get(entry);
1858
1864
  if (watch2 && cached !== undefined && !dirtyEntries.has(entry)) {
1865
+ if (acquire)
1866
+ cached.activeRequests += 1;
1859
1867
  return cached;
1860
1868
  }
1861
- const bundle = await buildProject(entry);
1869
+ const bundle = await buildProject.build(entry);
1862
1870
  if (bundle instanceof Response) {
1863
1871
  if (watch2) {
1864
1872
  dirtyEntries.add(entry);
@@ -1869,6 +1877,8 @@ async function createServerInstance(options, watch2) {
1869
1877
  bundles.set(entry, bundle);
1870
1878
  dirtyEntries.delete(entry);
1871
1879
  }
1880
+ if (acquire)
1881
+ bundle.activeRequests += 1;
1872
1882
  return bundle;
1873
1883
  };
1874
1884
  const server = Bun.serve({
@@ -1889,6 +1899,7 @@ async function createServerInstance(options, watch2) {
1889
1899
  markDirty: (entries) => {
1890
1900
  entries.forEach((entry) => dirtyEntries.add(entry));
1891
1901
  },
1902
+ dispose: buildProject.dispose,
1892
1903
  liveReload
1893
1904
  };
1894
1905
  }
@@ -1896,9 +1907,11 @@ function createServerHandle(getInstance, disposeWatcher) {
1896
1907
  return new Proxy({}, {
1897
1908
  get(_target, property) {
1898
1909
  if (property === "stop") {
1899
- return (closeActiveConnections) => {
1910
+ return async (closeActiveConnections) => {
1900
1911
  disposeWatcher();
1901
- getInstance().server.stop(closeActiveConnections);
1912
+ const instance = getInstance();
1913
+ await instance.server.stop(closeActiveConnections);
1914
+ await instance.dispose();
1902
1915
  };
1903
1916
  }
1904
1917
  const server = getInstance().server;
@@ -1912,7 +1925,7 @@ async function serveProjectRequest(request, config, pages, getBundle, artifacts,
1912
1925
  const route = pageRouteForPathname(pages, pathname);
1913
1926
  if (route !== undefined) {
1914
1927
  const entry = pages[route];
1915
- const bundle = await getBundle(entry);
1928
+ const bundle = await getBundle(entry, true);
1916
1929
  if (bundle instanceof Response) {
1917
1930
  return bundle;
1918
1931
  }
@@ -1935,10 +1948,12 @@ async function serveProjectRequest(request, config, pages, getBundle, artifacts,
1935
1948
  } catch (error) {
1936
1949
  console.error(error);
1937
1950
  return buildFailureResponse();
1951
+ } finally {
1952
+ releaseDevelopmentBundle(bundle);
1938
1953
  }
1939
1954
  }
1940
1955
  if (pathname === "/bundle.js") {
1941
- const bundle = await getBundle(config.entry);
1956
+ const bundle = await getBundle(config.entry, true);
1942
1957
  if (bundle instanceof Response) {
1943
1958
  return bundle;
1944
1959
  }
@@ -1954,6 +1969,8 @@ async function serveProjectRequest(request, config, pages, getBundle, artifacts,
1954
1969
  } catch (error) {
1955
1970
  console.error(error);
1956
1971
  return buildFailureResponse();
1972
+ } finally {
1973
+ releaseDevelopmentBundle(bundle);
1957
1974
  }
1958
1975
  }
1959
1976
  const artifact = artifacts.get(pathname);
@@ -1966,7 +1983,7 @@ async function serveProjectRequest(request, config, pages, getBundle, artifacts,
1966
1983
  });
1967
1984
  }
1968
1985
  if (pathname !== "/" && !pathname.startsWith("/api/") && !/\.[a-zA-Z0-9]+$/.test(pathname)) {
1969
- const bundle = await getBundle(config.entry);
1986
+ const bundle = await getBundle(config.entry, true);
1970
1987
  if (!(bundle instanceof Response)) {
1971
1988
  try {
1972
1989
  const { renderProjectHtml } = await import("./project-ybacfze8.js");
@@ -1987,6 +2004,8 @@ async function serveProjectRequest(request, config, pages, getBundle, artifacts,
1987
2004
  } catch (error) {
1988
2005
  console.error(error);
1989
2006
  return buildFailureResponse();
2007
+ } finally {
2008
+ releaseDevelopmentBundle(bundle);
1990
2009
  }
1991
2010
  }
1992
2011
  }
@@ -2099,17 +2118,73 @@ function isWithinOrEqual(parent, candidate) {
2099
2118
  const pathFromParent = relative4(parent, candidate);
2100
2119
  return pathFromParent === "" || pathFromParent !== ".." && !pathFromParent.startsWith(`..${sep3}`) && !isAbsolute4(pathFromParent);
2101
2120
  }
2102
- function createDevelopmentBuilder(sessionId, sessionOutDir) {
2121
+ function createDevelopmentBuilder(sessionId, sessionOutDir, artifacts) {
2103
2122
  let queue = Promise.resolve();
2104
- return (entry) => {
2105
- const result = queue.then(() => buildProjectBundle(entry, sessionId, sessionOutDir));
2123
+ let disposed = false;
2124
+ let disposal;
2125
+ const latestBundles = new Map;
2126
+ const retirementTimers = new Map;
2127
+ function retire(bundle) {
2128
+ bundle.retire = () => {
2129
+ const previousTimer = retirementTimers.get(bundle.outDir);
2130
+ if (previousTimer)
2131
+ clearTimeout(previousTimer);
2132
+ retirementTimers.delete(bundle.outDir);
2133
+ if (disposed || bundle.activeRequests > 0)
2134
+ return;
2135
+ const timer = setTimeout(() => {
2136
+ retirementTimers.delete(bundle.outDir);
2137
+ removeDevelopmentBundle(bundle, artifacts).catch((error) => console.error(error));
2138
+ }, DEVELOPMENT_OUTPUT_RETENTION_MS);
2139
+ timer.unref();
2140
+ retirementTimers.set(bundle.outDir, timer);
2141
+ };
2142
+ bundle.retire();
2143
+ }
2144
+ function build2(entry) {
2145
+ const result = queue.then(async () => {
2146
+ if (disposed)
2147
+ return buildFailureResponse();
2148
+ const bundle = await buildProjectBundle(entry, sessionId, sessionOutDir);
2149
+ if (!(bundle instanceof Response)) {
2150
+ const previous = latestBundles.get(entry);
2151
+ latestBundles.set(entry, bundle);
2152
+ if (previous)
2153
+ retire(previous);
2154
+ }
2155
+ return bundle;
2156
+ });
2106
2157
  queue = result.then(() => {
2107
2158
  return;
2108
2159
  }, () => {
2109
2160
  return;
2110
2161
  });
2111
2162
  return result;
2112
- };
2163
+ }
2164
+ function dispose() {
2165
+ if (disposal)
2166
+ return disposal;
2167
+ disposed = true;
2168
+ retirementTimers.forEach((timer) => clearTimeout(timer));
2169
+ retirementTimers.clear();
2170
+ disposal = queue.then(async () => {
2171
+ await rm4(sessionOutDir, { recursive: true, force: true });
2172
+ latestBundles.clear();
2173
+ artifacts.clear();
2174
+ });
2175
+ return disposal;
2176
+ }
2177
+ return { build: build2, dispose };
2178
+ }
2179
+ function releaseDevelopmentBundle(bundle) {
2180
+ bundle.activeRequests -= 1;
2181
+ bundle.retire?.();
2182
+ }
2183
+ async function removeDevelopmentBundle(bundle, artifacts) {
2184
+ await rm4(bundle.outDir, { recursive: true, force: true });
2185
+ for (const pathname of bundle.artifacts.keys()) {
2186
+ artifacts.delete(pathname);
2187
+ }
2113
2188
  }
2114
2189
  async function buildProjectBundle(entry, sessionId, sessionOutDir) {
2115
2190
  const generationId = createGenerationId();
@@ -2130,6 +2205,7 @@ async function buildProjectBundle(entry, sessionId, sessionOutDir) {
2130
2205
  asset: "assets/[name]-[hash].[ext]"
2131
2206
  }
2132
2207
  };
2208
+ let success = false;
2133
2209
  try {
2134
2210
  const result = await Bun.build(buildOptions);
2135
2211
  const entryArtifact = result.outputs.find(isEntryJavaScriptOutput);
@@ -2154,7 +2230,10 @@ async function buildProjectBundle(entry, sessionId, sessionOutDir) {
2154
2230
  if (!entry2) {
2155
2231
  throw new Error("Development entry output was not indexed");
2156
2232
  }
2233
+ success = true;
2157
2234
  return {
2235
+ outDir: generationOutDir,
2236
+ activeRequests: 0,
2158
2237
  entry: entry2,
2159
2238
  stylesheets: result.outputs.filter(isStylesheetOutput).map((output) => outputs.get(output)).filter((output) => output !== undefined),
2160
2239
  artifacts: pendingArtifacts
@@ -2162,6 +2241,10 @@ async function buildProjectBundle(entry, sessionId, sessionOutDir) {
2162
2241
  } catch (error) {
2163
2242
  console.error(error);
2164
2243
  return buildFailureResponse();
2244
+ } finally {
2245
+ if (!success) {
2246
+ await rm4(generationOutDir, { recursive: true, force: true });
2247
+ }
2165
2248
  }
2166
2249
  }
2167
2250
  function publishDevelopmentBundle(bundle, artifacts) {
@@ -2201,5 +2284,5 @@ function buildFailureResponse() {
2201
2284
 
2202
2285
  export { TARGET_TYPES, isTargetType, MP_TARGET_TYPES, isMpTargetType, defineConfig, resolveConfig, WebTarget, MpTarget, mpWeixinTarget, mpAlipayTarget, mpBytedanceTarget, mpXiaohongshuTarget, TargetRegistry, targetRegistry, build, createProject, startDevServer };
2203
2286
 
2204
- //# debugId=635285A08AF2FAAB64756E2164756E21
2205
- //# sourceMappingURL=index-pg5v7h1t.js.map
2287
+ //# debugId=8A1F36BF60A5A63464756E2164756E21
2288
+ //# sourceMappingURL=index-8k9x2k6m.js.map