tungsten 0.4.10 → 0.4.12

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.
Files changed (294) hide show
  1. package/dist/.build-complete +1 -1
  2. package/dist/AnyComponent.js +1 -1
  3. package/dist/Components.d.ts.map +1 -1
  4. package/dist/Components.js +15 -16
  5. package/dist/ContentNode.js +2 -2
  6. package/dist/DomRegion.js +1 -1
  7. package/dist/Framework.d.ts +2 -1
  8. package/dist/Framework.d.ts.map +1 -1
  9. package/dist/Framework.js +43 -34
  10. package/dist/FrameworkConfig.d.ts +16 -0
  11. package/dist/FrameworkConfig.d.ts.map +1 -1
  12. package/dist/FunctionComponentStandIn.js +8 -8
  13. package/dist/Instance/Instance.js +11 -11
  14. package/dist/RenderedContentNode.js +2 -2
  15. package/dist/RenderingNode.js +2 -2
  16. package/dist/Script.js +1 -1
  17. package/dist/Servers/DevServer.d.ts.map +1 -1
  18. package/dist/Servers/DevServer.js +29 -29
  19. package/dist/Servers/ProdServer.js +14 -14
  20. package/dist/Servers/StaticSiteServer.js +3 -3
  21. package/dist/Servers/TungstenServer.js +5 -5
  22. package/dist/Servers/devErrorPageAutoRetry.js +1 -1
  23. package/dist/Servers/hono/TungstenServerHono.js +5 -5
  24. package/dist/Servers/initStores.js +3 -3
  25. package/dist/Servers/loadEnvsDev.js +6 -6
  26. package/dist/Servers/routing.js +3 -3
  27. package/dist/Store/createStores.js +2 -2
  28. package/dist/Store/makeStore.js +2 -2
  29. package/dist/Store/registerStore.js +2 -2
  30. package/dist/TungstenApp.js +3 -3
  31. package/dist/TungstenStyleObject.js +1 -1
  32. package/dist/__deproxy.js +2 -2
  33. package/dist/_client/client.js +3 -3
  34. package/dist/alive.js +1 -1
  35. package/dist/api/getApiRoutes.js +3 -3
  36. package/dist/api/getApiRoutesHono.js +3 -3
  37. package/dist/api/getExport.js +4 -4
  38. package/dist/api/getExportDev.js +1 -1
  39. package/dist/appOutput.js +1 -1
  40. package/dist/auth/index.js +2 -2
  41. package/dist/babelPlugins/BabelAddDevCacheBust.d.ts.map +1 -1
  42. package/dist/babelPlugins/BabelAddDevCacheBust.js +4 -2
  43. package/dist/babelPlugins/BabelTransformBindDirect.js +2 -2
  44. package/dist/babelPlugins/BabelTransformBindVar.js +3 -3
  45. package/dist/babelPlugins/BabelTransformCjsToEsm.js +1 -1
  46. package/dist/babelPlugins/BabelTransformComponentState.js +2 -2
  47. package/dist/babelPlugins/BabelTransformComponentStyles.d.ts +2 -0
  48. package/dist/babelPlugins/BabelTransformComponentStyles.d.ts.map +1 -1
  49. package/dist/babelPlugins/BabelTransformComponentStyles.js +27 -11
  50. package/dist/babelPlugins/BabelTransformCssImports.js +1 -1
  51. package/dist/babelPlugins/BabelTransformDeproxyState.js +1 -1
  52. package/dist/babelPlugins/BabelTransformJsxExtensionsToJs.d.ts.map +1 -1
  53. package/dist/babelPlugins/BabelTransformJsxExtensionsToJs.js +6 -2
  54. package/dist/babelPlugins/BabelTransformPackageImports.d.ts.map +1 -1
  55. package/dist/babelPlugins/BabelTransformPackageImports.js +71 -49
  56. package/dist/babelPlugins/BabelTransformReactive.js +1 -1
  57. package/dist/babelPlugins/BabelTransformReactiveSvelteStyle.js +1 -1
  58. package/dist/babelPlugins/BabelTransformSxyFrameworkImports.js +1 -1
  59. package/dist/babelPlugins/BabelTransformUniqueComponents.js +1 -1
  60. package/dist/babelPlugins/fixImportsInSassErrorMessage.js +1 -1
  61. package/dist/babelPlugins/test.js +1 -1
  62. package/dist/babelPlugins/transformPackageImports/BabelTransformDependencyImportsCjs.js +3 -3
  63. package/dist/babelPlugins/transformPackageImports/BabelTransformDependencyImportsEsm.js +1 -1
  64. package/dist/babelPlugins/transformPackageImports/getWebLocationOfPackageFile.js +2 -2
  65. package/dist/bin/args.js +1 -1
  66. package/dist/bin/commands/build.js +5 -5
  67. package/dist/bin/commands/buildHelp.js +1 -1
  68. package/dist/bin/commands/clean.js +4 -4
  69. package/dist/bin/commands/compile.d.ts.map +1 -1
  70. package/dist/bin/commands/compile.js +24 -17
  71. package/dist/bin/commands/compileSimplePackage.js +2 -2
  72. package/dist/bin/commands/dev.d.ts.map +1 -1
  73. package/dist/bin/commands/dev.js +16 -9
  74. package/dist/bin/commands/devmon.js +4 -4
  75. package/dist/bin/commands/help.js +2 -2
  76. package/dist/bin/commands/start.js +2 -2
  77. package/dist/bin/commands/static.js +3 -3
  78. package/dist/bin/index.js +13 -13
  79. package/dist/bin/moduleLoadAnalysis.js +2 -2
  80. package/dist/browserStorage.js +2 -2
  81. package/dist/build/babel.user.common.config.d.ts +7 -2
  82. package/dist/build/babel.user.common.config.d.ts.map +1 -1
  83. package/dist/build/babel.user.common.config.js +14 -15
  84. package/dist/build/bundle.d.ts +1 -1
  85. package/dist/build/bundle.d.ts.map +1 -1
  86. package/dist/build/bundle.js +15 -7
  87. package/dist/build/bundleBabelOptions.d.ts +6 -0
  88. package/dist/build/bundleBabelOptions.d.ts.map +1 -0
  89. package/dist/build/bundleBabelOptions.js +23 -0
  90. package/dist/build/combineComponentCss.js +2 -2
  91. package/dist/build/compileJavascript.d.ts +4 -0
  92. package/dist/build/compileJavascript.d.ts.map +1 -1
  93. package/dist/build/compileJavascript.js +148 -90
  94. package/dist/build/compileStyles.js +4 -4
  95. package/dist/build/compileUserApp.d.ts +1 -1
  96. package/dist/build/compileUserApp.d.ts.map +1 -1
  97. package/dist/build/compileUserApp.js +15 -12
  98. package/dist/build/componentStylesCache.d.ts +10 -0
  99. package/dist/build/componentStylesCache.d.ts.map +1 -0
  100. package/dist/build/componentStylesCache.js +54 -0
  101. package/dist/build/copyAssets.js +1 -1
  102. package/dist/build/copyPackageModulesToPackagesFolder.js +4 -4
  103. package/dist/build/copyPublicFiles.js +1 -1
  104. package/dist/build/createClientFiles.js +3 -3
  105. package/dist/build/createInstanceConfigFile.js +2 -2
  106. package/dist/build/createPackageVirtualFileSystems.js +1 -1
  107. package/dist/build/devBundle.js +5 -5
  108. package/dist/build/devBundle.rollup.config.d.ts.map +1 -1
  109. package/dist/build/devBundle.rollup.config.js +0 -1
  110. package/dist/build/frameworkDestLocation.d.ts +1 -0
  111. package/dist/build/frameworkDestLocation.d.ts.map +1 -1
  112. package/dist/build/frameworkDestLocation.js +8 -4
  113. package/dist/build/frameworkStylesheets.js +1 -1
  114. package/dist/build/getAllSxyClientModules.js +2 -2
  115. package/dist/build/getPackageDirForFile.js +1 -1
  116. package/dist/build/getSxyClientPackageAliases.d.ts.map +1 -1
  117. package/dist/build/getSxyClientPackageAliases.js +4 -2
  118. package/dist/build/getTempDirForAppCompilation.js +1 -1
  119. package/dist/build/makeBabelRawConfig.d.ts +3 -0
  120. package/dist/build/makeBabelRawConfig.d.ts.map +1 -0
  121. package/dist/build/makeBabelRawConfig.js +12 -0
  122. package/dist/build/makeBabelUserDevConfig.d.ts +1 -1
  123. package/dist/build/makeBabelUserDevConfig.d.ts.map +1 -1
  124. package/dist/build/makeBabelUserDevConfig.js +11 -8
  125. package/dist/build/makeBabelUserProdConfig.d.ts +1 -1
  126. package/dist/build/makeBabelUserProdConfig.d.ts.map +1 -1
  127. package/dist/build/makeBabelUserProdConfig.js +10 -5
  128. package/dist/build/processPackage.js +3 -3
  129. package/dist/build/rollup.user.prod.config.d.ts.map +1 -1
  130. package/dist/build/rollup.user.prod.config.js +13 -11
  131. package/dist/build/rollupExtractComponentStylesheets.js +2 -2
  132. package/dist/build/sassImportParser.js +2 -2
  133. package/dist/build/tallyBabelPlugins.d.ts.map +1 -1
  134. package/dist/build/tallyBabelPlugins.js +2 -7
  135. package/dist/calculateImportedStaticFileLocations.js +2 -2
  136. package/dist/calledFrom.js +2 -2
  137. package/dist/compat/forwardRef.js +1 -1
  138. package/dist/compat/index.js +1 -1
  139. package/dist/componentCss/tungsten.css +2 -2
  140. package/dist/componentProxyHandlers.js +3 -3
  141. package/dist/components/Link.js +2 -2
  142. package/dist/components/PopMessages.js +3 -3
  143. package/dist/components/RawHtml.js +2 -2
  144. package/dist/components/Stylesheet.js +3 -3
  145. package/dist/components/bindable/BindableCheckbox.js +1 -1
  146. package/dist/components/bindable/BindableInput.js +1 -1
  147. package/dist/components/bindable/BindableInputNonString.js +1 -1
  148. package/dist/components/bindable/BindableInputString.js +1 -1
  149. package/dist/components/bindable/BindableInputTyped.js +1 -1
  150. package/dist/components/bindable/BindableInputTypedLegacy.js +1 -1
  151. package/dist/components/bindable/BindableRadio.js +1 -1
  152. package/dist/components/bindable/BindableSelect.js +1 -1
  153. package/dist/components/bindable/BindableTextarea.js +1 -1
  154. package/dist/components/library/RichTextEditor/RichTextEditor.js +8 -8
  155. package/dist/components/library/RichTextEditor/contentTree.js +4 -4
  156. package/dist/components/library/RichTextEditor/sanitizeAuthoredHtml.js +2 -2
  157. package/dist/components/library/__StatefulMessage/StatefulMessage.js +2 -2
  158. package/dist/components/library/index.js +2 -2
  159. package/dist/createElement.js +1 -1
  160. package/dist/defaultConfig.d.ts +0 -1
  161. package/dist/defaultConfig.d.ts.map +1 -1
  162. package/dist/defaultConfig.js +2 -2
  163. package/dist/deleteDirs.js +1 -1
  164. package/dist/env/addToEnv.js +1 -1
  165. package/dist/env/funcs.js +4 -4
  166. package/dist/env/getEnvSchemas.d.ts.map +1 -1
  167. package/dist/env/getEnvSchemas.js +10 -6
  168. package/dist/env/privateEnv.js +2 -2
  169. package/dist/env/privateEnvOrThrow.js +1 -1
  170. package/dist/env/publicEnv.js +1 -1
  171. package/dist/env/publicEnvOrThrow.js +1 -1
  172. package/dist/filePathFromUrl.js +1 -1
  173. package/dist/findProjectDir.js +1 -1
  174. package/dist/findUserConfig.js +5 -5
  175. package/dist/fixExtension.d.ts.map +1 -1
  176. package/dist/fixExtension.js +5 -3
  177. package/dist/frameworkConfigSchema.d.ts +16 -0
  178. package/dist/frameworkConfigSchema.d.ts.map +1 -1
  179. package/dist/frameworkConfigSchema.js +12 -0
  180. package/dist/getComponent.js +5 -5
  181. package/dist/getComponentDev.js +1 -1
  182. package/dist/getFrameworkDir.js +1 -1
  183. package/dist/getRoutes.js +5 -5
  184. package/dist/getRoutesDevs.js +1 -1
  185. package/dist/getUserConfig.js +7 -7
  186. package/dist/hasValidKey.js +1 -1
  187. package/dist/helpers/index.js +2 -2
  188. package/dist/hmr/applyHmrModule.js +5 -5
  189. package/dist/hmr/componentIdentity.js +2 -2
  190. package/dist/hooks/clearCurrentComponent.js +1 -1
  191. package/dist/hooks/getCurrentComponent.js +3 -3
  192. package/dist/hooks/index.js +5 -5
  193. package/dist/hooks/setCurrentComponent.js +1 -1
  194. package/dist/hooks/useCallback.js +2 -2
  195. package/dist/hooks/useEffect.js +2 -2
  196. package/dist/hooks/useInstance.js +1 -1
  197. package/dist/hooks/useMemo.js +2 -2
  198. package/dist/hooks/useState.js +3 -3
  199. package/dist/hydrate/hydrate.js +31 -31
  200. package/dist/hydrate/reconcileHydratedAttributes.js +3 -3
  201. package/dist/index.js +2 -2
  202. package/dist/indexInner.d.ts +1 -1
  203. package/dist/indexInner.d.ts.map +1 -1
  204. package/dist/indexInner.js +45 -45
  205. package/dist/innerHtmlFromProps.js +1 -1
  206. package/dist/isBrowser.js +1 -1
  207. package/dist/isDev.js +1 -1
  208. package/dist/isProd.js +1 -1
  209. package/dist/isServer.js +1 -1
  210. package/dist/jsx-runtime.js +1 -1
  211. package/dist/jsxRuntime.d.ts.map +1 -1
  212. package/dist/jsxRuntime.js +12 -7
  213. package/dist/jsxRuntimeSignals.d.ts.map +1 -1
  214. package/dist/jsxRuntimeSignals.js +15 -8
  215. package/dist/makeFinalConfig.js +1 -1
  216. package/dist/makeInstanceConfigFromFrameworkConfig.js +1 -1
  217. package/dist/makeServerRpc.js +3 -3
  218. package/dist/markOptionSelected.js +1 -1
  219. package/dist/nbsp.js +1 -1
  220. package/dist/output.js +1 -1
  221. package/dist/pop.js +2 -2
  222. package/dist/postcssPlugins/TransformCssNames.js +6 -6
  223. package/dist/postcssPlugins/parseSelectors.js +1 -1
  224. package/dist/postcssPlugins/parseSelectorsRich.js +1 -1
  225. package/dist/postcssPlugins/scopeAnimationValue.js +2 -2
  226. package/dist/propsAreEqual.js +3 -3
  227. package/dist/rawHtml/filterContentNode.js +4 -4
  228. package/dist/rawHtml/parseHtml.js +4 -4
  229. package/dist/rawHtml/sanitizeHtml.js +3 -3
  230. package/dist/rawHtml/tokenizeHtml.js +2 -2
  231. package/dist/render/addImportMap.js +2 -2
  232. package/dist/render/classComponentNodeToRenderingTree.js +4 -4
  233. package/dist/render/componentNodeToRenderingTree.js +7 -7
  234. package/dist/render/contentNodeToHtml.js +11 -11
  235. package/dist/render/contentToHtml.js +4 -4
  236. package/dist/render/contentToHtmlDev.js +1 -1
  237. package/dist/render/contentTreeToRenderingTree.js +7 -7
  238. package/dist/render/functionComponentNodeToRenderingTree.js +4 -4
  239. package/dist/render/getFunctionBodyAsString.js +1 -1
  240. package/dist/render/instantiateClassComponent.js +2 -2
  241. package/dist/render/instantiateComponent.js +3 -3
  242. package/dist/render/instantiateFunctionComponent.js +2 -2
  243. package/dist/render/printComponentNameInSource.js +1 -1
  244. package/dist/render/processHead.js +5 -5
  245. package/dist/render/processHtmlNode.js +1 -1
  246. package/dist/render/processProps.js +2 -2
  247. package/dist/render/processRenderingNodeHtml.js +6 -6
  248. package/dist/render/renderingTreeToHtml.js +16 -16
  249. package/dist/render/rootToHtml.js +2 -2
  250. package/dist/render/rootToHtmlDev.js +1 -1
  251. package/dist/requests/fetch/delete.js +2 -2
  252. package/dist/requests/fetch/get.js +3 -3
  253. package/dist/requests/fetch/patch.js +2 -2
  254. package/dist/requests/fetch/post.js +2 -2
  255. package/dist/requests/fetch/put.js +2 -2
  256. package/dist/requests/index.js +5 -5
  257. package/dist/routing/MatchedRoute.js +2 -2
  258. package/dist/routing/getPathPriority.js +1 -1
  259. package/dist/routing/matchPath.js +3 -3
  260. package/dist/routing/patternToRegex.js +1 -1
  261. package/dist/server.js +3 -3
  262. package/dist/serverModuleLocation.d.ts +3 -0
  263. package/dist/serverModuleLocation.d.ts.map +1 -0
  264. package/dist/serverModuleLocation.js +12 -0
  265. package/dist/settings.d.ts +4 -0
  266. package/dist/settings.d.ts.map +1 -1
  267. package/dist/settings.js +9 -0
  268. package/dist/standardSchema.js +1 -1
  269. package/dist/staticGen/getAppRoutes.js +3 -3
  270. package/dist/staticGen/staticGen.js +7 -7
  271. package/dist/style/jssToCss.js +3 -3
  272. package/dist/style/styleContent.js +1 -1
  273. package/dist/style/styleContentSxy.js +8 -8
  274. package/dist/style/unusedStyles.js +1 -1
  275. package/dist/sync/index.js +1 -1
  276. package/dist/syncServer/preload.js +1 -1
  277. package/dist/testing/host.js +1 -1
  278. package/dist/testing/hydrateTestApp.js +9 -9
  279. package/dist/testing/index.js +11 -11
  280. package/dist/testing/installTestStyleProcessors.js +1 -1
  281. package/dist/testing/loadEnv.js +3 -3
  282. package/dist/testing/loadEnvSetup.js +1 -1
  283. package/dist/testing/temp/componentPackageMock.js +2 -2
  284. package/dist/testing/temp/contentHtmlElements.js +2 -2
  285. package/dist/throwError.js +2 -2
  286. package/dist/timeProfiler.d.ts +1 -1
  287. package/dist/timeProfiler.d.ts.map +1 -1
  288. package/dist/timeProfiler.js +62 -26
  289. package/dist/update/integrateUpdateVdom.js +28 -28
  290. package/dist/validChildren.js +2 -2
  291. package/dist/warnOnFrameworkChange.js +2 -2
  292. package/dist/zones/react.js +3 -3
  293. package/package.json +18 -11
  294. package/types/modules.d.ts +2 -0
@@ -6,21 +6,26 @@ import fs, { promises as fsPromises } from 'fs';
6
6
  import slash from 'slash';
7
7
  import serializeJavascript from 'serialize-javascript';
8
8
  import { globby } from 'globby';
9
- import { packagesCacheFolder } from "../settings.js";
10
- import { makeBabelUserDevConfig } from "./makeBabelUserDevConfig.js";
11
- import { makeBabelUserProdConfig } from "./makeBabelUserProdConfig.js";
12
- import { cliOut, cliLog, cliError, cliWarn } from "../cliOutput.js"; // eslint-disable-line @typescript-eslint/no-unused-vars
13
- import { createTimeProfiler, isProfiling, tally } from "../timeProfiler.js";
14
- import { tallyBabelPlugins } from "./tallyBabelPlugins.js";
15
- import { TungstenError } from "../TungstenError.js";
16
- import { getFrameworkDir } from "../getFrameworkDir.js";
9
+ import { devRawBuildFolder, packagesCacheFolder, prodRawBuildFolder, stylesCacheFolder } from '../settings.js';
10
+ import { frameworkVersion } from './frameworkDestLocation.js';
11
+ import { makeBabelUserDevConfig } from './makeBabelUserDevConfig.js';
12
+ import { makeBabelUserProdConfig } from './makeBabelUserProdConfig.js';
13
+ import { makeBabelRawConfig } from './makeBabelRawConfig.js';
14
+ import { cliOut, cliLog, cliError, cliWarn } from '../cliOutput.js'; // eslint-disable-line @typescript-eslint/no-unused-vars
15
+ import { createTimeProfiler, isProfiling, tallied } from '../timeProfiler.js';
16
+ import { tallyBabelPlugins } from './tallyBabelPlugins.js';
17
+ import { TungstenError } from '../TungstenError.js';
18
+ import { getFrameworkDir } from '../getFrameworkDir.js';
17
19
  // The graph writeDependencyGraph() left behind on the previous run, naming a compiled copy of every
18
20
  // package file in the packages cache. Missing or unreadable just means everything is compiled from
19
21
  // source, which is what happened on every run before this was read back.
22
+ // Nodes are keyed by package version only, so a graph another tungsten version wrote is discarded:
23
+ // the transform may have changed. frameworkVersion here is a free option - any stamp works.
20
24
  async function loadDependencyGraph(location) {
21
25
  if (!fs.existsSync(location)) return {};
22
26
  try {
23
27
  const graphModule = await import(pathToFileURL(location).href);
28
+ if (graphModule.version !== frameworkVersion) return {};
24
29
  return graphModule.graph ?? {};
25
30
  } catch (error) {
26
31
  cliWarn(`Could not read the package cache at ${location}, compiling packages from source`);
@@ -33,6 +38,9 @@ async function loadDependencyGraph(location) {
33
38
  export async function compileJavascript(projectDir, appConfig, codeLocation, sourceLocation, styleImportBase, buildLocation, buildCodeLocation, mode, watch = true, options = {}) {
34
39
  if (options.quiet !== true) cliOut(`Compiling app code`);
35
40
  const compilePackages = options.packages !== false;
41
+ // codeLocation's .ts/.tsx are sources too, compiled to .js by babel; .d.ts is never one
42
+ const typescript = appConfig.typescript === true;
43
+ const rawBuildLocation = options.rawBuildLocation ?? join(projectDir, mode === 'dev' ? devRawBuildFolder : prodRawBuildFolder);
36
44
  let dependencyGraphDir = '';
37
45
  let dependencyGraphLocation = '';
38
46
  let oldDependencyGraph = {};
@@ -54,35 +62,48 @@ export async function compileJavascript(projectDir, appConfig, codeLocation, sou
54
62
  if (mode === 'dev') {
55
63
  dependencyGraphDir = options.packagesCacheLocation ?? join(projectDir, packagesCacheFolder);
56
64
  dependencyGraphLocation = join(dependencyGraphDir, '.dependency-graph.js');
57
- oldDependencyGraph = await loadDependencyGraph(dependencyGraphLocation);
65
+ oldDependencyGraph = options.fresh === true ? {} : await loadDependencyGraph(dependencyGraphLocation);
58
66
  dependencyGraph = {};
59
67
  importAliases = {};
60
68
  promises = [];
61
- config = makeBabelUserDevConfig(projectDir, codeLocation, sourceLocation, styleImportBase, buildLocation, buildCodeLocation, dependencyGraphDir, skipPackageCompilationFiles, oldDependencyGraph, dependencyGraph, importAliases, promises, watch, options.hmr === true, compilePackages);
69
+ config = makeBabelUserDevConfig(projectDir, codeLocation, sourceLocation, typescript, styleImportBase, buildLocation, buildCodeLocation, dependencyGraphDir, options.stylesCacheLocation ?? join(projectDir, stylesCacheFolder), options.fresh === true, skipPackageCompilationFiles, oldDependencyGraph, dependencyGraph, importAliases, promises, watch, options.hmr === true, compilePackages);
62
70
  } else {
63
- config = makeBabelUserProdConfig(projectDir, codeLocation, sourceLocation, styleImportBase, watch);
71
+ config = makeBabelUserProdConfig(projectDir, codeLocation, sourceLocation, typescript, styleImportBase, watch);
64
72
  }
65
73
  config.root = getFrameworkDir();
74
+ const rawConfig = makeBabelRawConfig(typescript);
75
+ rawConfig.root = config.root;
66
76
  // per-plugin attribution of the transform's time, only when someone is looking: the wrappers
67
77
  // run per AST node
68
78
  if (isProfiling()) {
69
79
  config.plugins = tallyBabelPlugins(config.plugins);
80
+ rawConfig.plugins = tallyBabelPlugins(rawConfig.plugins);
70
81
  if (mode === 'dev' && compilePackages) {
71
- cliWarn(`profiling serves linked packages from the packages cache -` + ` delete ${dependencyGraphDir} after rebuilding one, or this run compiles stale code`);
82
+ cliWarn(`profiling serves linked packages from the packages cache -` + ` pass --fresh after rebuilding one, or this run compiles stale code`);
72
83
  }
73
84
  }
74
85
  // compile with the API
75
86
  const codeLocationLength = codeLocation.length + 1;
87
+ // a source's path within the build: every compiled extension becomes .js
88
+ function outputRel(file) {
89
+ const rel = file.slice(codeLocationLength);
90
+ if (rel.endsWith('.jsx')) return rel.slice(0, -1);
91
+ if (typescript && rel.endsWith('.tsx')) return `${rel.slice(0, -3)}js`;
92
+ if (typescript && rel.endsWith('.ts')) return `${rel.slice(0, -2)}js`;
93
+ return rel;
94
+ }
76
95
  const transformPromises = [];
77
96
  const failedFiles = new Set();
78
97
  const pendingExportWipes = new Map();
79
98
  const exportWipeGraceMs = 5000;
99
+ // A source goes through the client pipeline, the raw one, both, or neither - see
100
+ // refreshSelections() below for what decides that
80
101
  async function transformFile(file) {
81
102
  //if (options.quiet !== true) console.log('transforming file', file)
103
+ const client = isClient(file);
104
+ const raw = isRaw(file);
105
+ if (!client && !raw) return;
82
106
  try {
83
- let rel = file.slice(codeLocationLength);
84
- if (rel.endsWith('.jsx')) rel = rel.slice(0, -1);
85
- const dest = join(buildCodeLocation, rel);
86
107
  // tsc's own watch/incremental emit can leave this file genuinely blank for a
87
108
  // stretch while it recomputes - not a write-in-progress chokidar's
88
109
  // awaitWriteFinish can wait out, but a real (if temporary) empty file on disk.
@@ -93,64 +114,12 @@ export async function compileJavascript(projectDir, appConfig, codeLocation, sou
93
114
  failedFiles.delete(file);
94
115
  return;
95
116
  }
96
- // Sync, so this can be tallied exactly - nothing else runs during it. Babel's work is
97
- // cpu-bound on one thread either way, so the async API's 291 concurrent calls bought
98
- // no parallelism, only scheduling. The plugins defer their async work into
99
- // opts.promises rather than awaiting in a visitor, which is what makes sync viable.
100
- const babelStart = performance.now();
101
- const result = babelTransformFileSync(file, config);
102
- tally('babel transform', performance.now() - babelStart);
103
- if (result === null) throw new TungstenError(`Err: babel transform on file ${file} returned null`);
104
- const {
105
- code
106
- } = result;
107
- if (code === null || code === undefined) {
108
- throw new TungstenError(`Err: code from babel transform on file ${file} was null or undefined: ${typeof code}`);
109
- }
110
- // tsc's incremental watch can, for one transient pass right after a save, emit
111
- // `export {};` for a file that previously had real exports - its own convention
112
- // for "this module has nothing to export", produced here as a self-correcting
113
- // glitch rather than a real edit (confirmed via tsc's own transient
114
- // "has no exported member" watch error). Quarantine it behind a timer rather than
115
- // overwrite the last-good compiled output immediately: tsc's follow-up pass moments
116
- // later normally retriggers this watcher with the real content, cancelling the
117
- // quarantine below. But if nothing ever corrects it (a genuine edit really does
118
- // remove every export), accept the quarantined content once the grace period lapses
119
- // instead of hiding it forever.
120
- if (code.trim() === 'export {};' && fs.existsSync(dest)) {
121
- const previousCode = fs.readFileSync(dest, 'utf8');
122
- if (previousCode.trim() !== 'export {};' && previousCode.trim() !== '') {
123
- if (!pendingExportWipes.has(file)) {
124
- const timer = setTimeout(() => {
125
- void acceptQuarantinedExportWipe(file);
126
- }, exportWipeGraceMs);
127
- pendingExportWipes.set(file, {
128
- dest,
129
- code,
130
- timer
131
- });
132
- } else {
133
- // keep the original timer (grace period counts from the first sighting),
134
- // just refresh the content that'll be written if it elapses
135
- const pending = pendingExportWipes.get(file);
136
- if (pending !== undefined) pending.code = code;
137
- }
138
- failedFiles.delete(file);
139
- return;
140
- }
117
+ if (client) {
118
+ transformTo(file, config, join(buildCodeLocation, outputRel(file)), 'babel transform', true);
141
119
  }
142
- // real content arrived - cancel any quarantine still pending for this file
143
- const pendingWipe = pendingExportWipes.get(file);
144
- if (pendingWipe !== undefined) {
145
- clearTimeout(pendingWipe.timer);
146
- pendingExportWipes.delete(file);
120
+ if (raw) {
121
+ transformTo(file, rawConfig, join(rawBuildLocation, outputRel(file)), 'babel transform (raw)', false);
147
122
  }
148
- await fsPromises.mkdir(dirname(dest), {
149
- recursive: true
150
- });
151
- //// Using the sync version here, because the promise version keeps bugging out - node bug?
152
- //await fsPromises.writeFile(dest, code)
153
- fs.writeFileSync(dest, code);
154
123
  failedFiles.delete(file);
155
124
  } catch (e) {
156
125
  failedFiles.add(file);
@@ -159,28 +128,84 @@ export async function compileJavascript(projectDir, appConfig, codeLocation, sou
159
128
  throw e;
160
129
  }
161
130
  }
131
+ // One pipeline's transform and write. Sync, so it can be tallied exactly - nothing else runs
132
+ // during it. Babel's work is cpu-bound on one thread either way, so the async API's 291
133
+ // concurrent calls bought no parallelism, only scheduling. The plugins defer their async work
134
+ // into opts.promises rather than awaiting in a visitor, which is what makes sync viable.
135
+ function transformTo(file, babelConfig, dest, tallyName, guardExportWipe) {
136
+ const result = tallied(tallyName, () => babelTransformFileSync(file, babelConfig));
137
+ if (result === null) throw new TungstenError(`Err: babel transform on file ${file} returned null`);
138
+ const {
139
+ code
140
+ } = result;
141
+ if (code === null || code === undefined) {
142
+ throw new TungstenError(`Err: code from babel transform on file ${file} was null or undefined: ${typeof code}`);
143
+ }
144
+ // tsc's incremental watch can, for one transient pass right after a save, emit
145
+ // `export {};` for a file that previously had real exports - its own convention
146
+ // for "this module has nothing to export", produced here as a self-correcting
147
+ // glitch rather than a real edit (confirmed via tsc's own transient
148
+ // "has no exported member" watch error). Quarantine it behind a timer rather than
149
+ // overwrite the last-good compiled output immediately: tsc's follow-up pass moments
150
+ // later normally retriggers this watcher with the real content, cancelling the
151
+ // quarantine below. But if nothing ever corrects it (a genuine edit really does
152
+ // remove every export), accept the quarantined content once the grace period lapses
153
+ // instead of hiding it forever. The client tree's guard only - the raw tree is not served.
154
+ if (guardExportWipe && code.trim() === 'export {};' && fs.existsSync(dest)) {
155
+ const previousCode = fs.readFileSync(dest, 'utf8');
156
+ if (previousCode.trim() !== 'export {};' && previousCode.trim() !== '') {
157
+ if (!pendingExportWipes.has(file)) {
158
+ const timer = setTimeout(() => {
159
+ void acceptQuarantinedExportWipe(file);
160
+ }, exportWipeGraceMs);
161
+ pendingExportWipes.set(file, {
162
+ dest,
163
+ code,
164
+ timer
165
+ });
166
+ } else {
167
+ // keep the original timer (grace period counts from the first sighting),
168
+ // just refresh the content that'll be written if it elapses
169
+ const pending = pendingExportWipes.get(file);
170
+ if (pending !== undefined) pending.code = code;
171
+ }
172
+ return;
173
+ }
174
+ }
175
+ // real content arrived - cancel any quarantine still pending for this file
176
+ if (guardExportWipe) {
177
+ const pendingWipe = pendingExportWipes.get(file);
178
+ if (pendingWipe !== undefined) {
179
+ clearTimeout(pendingWipe.timer);
180
+ pendingExportWipes.delete(file);
181
+ }
182
+ }
183
+ fs.mkdirSync(dirname(dest), {
184
+ recursive: true
185
+ });
186
+ //// Using the sync version here, because the promise version keeps bugging out - node bug?
187
+ fs.writeFileSync(dest, code);
188
+ }
162
189
  async function deleteTransformedFile(file) {
163
- let rel = file.slice(codeLocationLength);
164
- if (rel.endsWith('.jsx')) rel = rel.slice(0, -1);
165
- const dest = join(buildCodeLocation, rel);
166
190
  const pendingWipe = pendingExportWipes.get(file);
167
191
  if (pendingWipe !== undefined) {
168
192
  clearTimeout(pendingWipe.timer);
169
193
  pendingExportWipes.delete(file);
170
194
  }
171
- try {
172
- await fsPromises.unlink(dest);
173
- } catch (error) {
174
- const fileError = error;
175
- if (fileError.code !== 'ENOENT') throw error;
195
+ // whichever trees hold it
196
+ for (const dest of [join(buildCodeLocation, outputRel(file)), join(rawBuildLocation, outputRel(file))]) {
197
+ try {
198
+ await fsPromises.unlink(dest);
199
+ } catch (error) {
200
+ const fileError = error;
201
+ if (fileError.code !== 'ENOENT') throw error;
202
+ }
176
203
  }
177
204
  failedFiles.delete(file);
178
205
  }
179
206
  async function copyFile(file) {
180
207
  try {
181
- let rel = file.slice(codeLocationLength);
182
- if (rel.endsWith('.jsx')) rel = rel.slice(0, -1);
183
- const dest = join(buildCodeLocation, rel);
208
+ const dest = join(buildCodeLocation, outputRel(file));
184
209
  await fsPromises.mkdir(dirname(dest), {
185
210
  recursive: true
186
211
  });
@@ -194,9 +219,7 @@ export async function compileJavascript(projectDir, appConfig, codeLocation, sou
194
219
  }
195
220
  async function deleteFile(file) {
196
221
  try {
197
- let rel = file.slice(codeLocationLength);
198
- if (rel.endsWith('.jsx')) rel = rel.slice(0, -1);
199
- const dest = join(buildCodeLocation, rel);
222
+ const dest = join(buildCodeLocation, outputRel(file));
200
223
  await fsPromises.unlink(dest);
201
224
  } catch (e) {
202
225
  cliError(`Tungsten: Error deleting file ${file}`);
@@ -205,11 +228,12 @@ export async function compileJavascript(projectDir, appConfig, codeLocation, sou
205
228
  }
206
229
  }
207
230
  // get a list of files
208
- const watchGlob = slash(`${codeLocation}/**/*.js{,x}`);
231
+ const watchGlob = slash(`${codeLocation}/**/*.{js,jsx${typescript ? ',ts,tsx' : ''}}`);
209
232
  // typed rather than inferred from the pushes: it is captured by a closure below, which stops
210
233
  // typescript widening it from the pushes
211
234
  const ignored = [];
212
235
  ignored.push(slash(`${buildLocation}/**`));
236
+ if (typescript) ignored.push(slash(`${codeLocation}/**/*.d.ts`));
213
237
  if (appConfig.ignoreDirs !== undefined && appConfig.ignoreDirs !== '') {
214
238
  const ignoreDirs = typeof appConfig.ignoreDirs === 'string' ? [appConfig.ignoreDirs] : appConfig.ignoreDirs;
215
239
  ignored.push(...ignoreDirs.map(folder => slash(`${codeLocation}/${folder}/**`)));
@@ -235,6 +259,35 @@ export async function compileJavascript(projectDir, appConfig, codeLocation, sou
235
259
  }
236
260
  }
237
261
  if (appConfig.exclude !== undefined) ignored.push(slash(`${codeLocation}/${appConfig.exclude}`));
262
+ // Which sources each pipeline compiles. Unset, client is everything and raw is nothing; a file
263
+ // may be in both. Dirs and patterns are relative to codeDir. The ignores are not applied
264
+ // here - every file that reaches isClient/isRaw has already passed them, in the initial glob
265
+ // or in the watcher - so "client minus ignores" holds. Sets rather than matchers, refreshed on
266
+ // the watcher's `add`, like skipPackageCompilationFiles.
267
+ const sourceExtensions = `*.{js,jsx${typescript ? ',ts,tsx' : ''}}`;
268
+ function selectionGlobs(dirs, patterns) {
269
+ if (dirs === undefined && patterns === undefined) return null;
270
+ const list = value => value === undefined || value === '' ? [] : typeof value === 'string' ? [value] : value;
271
+ return [...list(dirs).map(dir => `${dir}/**/${sourceExtensions}`), ...list(patterns)];
272
+ }
273
+ const clientSelection = selectionGlobs(appConfig.clientDirs, appConfig.clientPatterns);
274
+ const rawSelection = selectionGlobs(appConfig.rawDirs, appConfig.rawPatterns);
275
+ let clientFiles = null;
276
+ let rawFiles = new Set();
277
+ async function selectedFiles(selection) {
278
+ const files = await globby(selection, {
279
+ cwd: codeLocation,
280
+ absolute: true
281
+ });
282
+ return new Set(files.map(file => slash(file)));
283
+ }
284
+ async function refreshSelections() {
285
+ clientFiles = clientSelection === null ? null : await selectedFiles(clientSelection);
286
+ rawFiles = rawSelection === null ? new Set() : await selectedFiles(rawSelection);
287
+ }
288
+ const isClient = file => clientFiles === null || clientFiles.has(file);
289
+ const isRaw = file => rawFiles.has(file);
290
+ await refreshSelections();
238
291
  //console.log('appConfig', appConfig)
239
292
  //console.log('ignored', ignored)
240
293
  //cliWarn(watchGlob)
@@ -276,7 +329,7 @@ export async function compileJavascript(projectDir, appConfig, codeLocation, sou
276
329
  recursive: true
277
330
  });
278
331
  }
279
- fs.writeFileSync(dependencyGraphLocation, `export const graph = ${serializeJavascript(dependencyGraph)}`);
332
+ fs.writeFileSync(dependencyGraphLocation, `export const version = ${serializeJavascript(frameworkVersion)}\n` + `export const graph = ${serializeJavascript(dependencyGraph)}`);
280
333
  }
281
334
  async function acceptQuarantinedExportWipe(file) {
282
335
  const pending = pendingExportWipes.get(file);
@@ -299,7 +352,8 @@ export async function compileJavascript(projectDir, appConfig, codeLocation, sou
299
352
  }
300
353
  await options.onCycleComplete?.({
301
354
  success,
302
- file
355
+ file,
356
+ client: true
303
357
  });
304
358
  }
305
359
  if (!watch) {
@@ -337,7 +391,10 @@ export async function compileJavascript(projectDir, appConfig, codeLocation, sou
337
391
  if (event === 'unlink') {
338
392
  await deleteTransformedFile(file);
339
393
  } else {
340
- if (event === 'add') await refreshSkipPackageCompilationFiles();
394
+ if (event === 'add') {
395
+ await refreshSkipPackageCompilationFiles();
396
+ await refreshSelections();
397
+ }
341
398
  await transformFile(file);
342
399
  }
343
400
  const failures = await settleDeferredWork();
@@ -348,7 +405,8 @@ export async function compileJavascript(projectDir, appConfig, codeLocation, sou
348
405
  }
349
406
  await options.onCycleComplete?.({
350
407
  success,
351
- file
408
+ file,
409
+ client: isClient(file)
352
410
  });
353
411
  }).catch(error => {
354
412
  cliError('Tungsten: Error completing JavaScript watch cycle');
@@ -5,10 +5,10 @@ import { pathToFileURL } from 'url';
5
5
  import { promises as fsPromises, utimesSync } from 'fs';
6
6
  import * as sass from 'sass';
7
7
  import { globby } from 'globby';
8
- import { staticFolder } from "../settings.js";
9
- import { cliError, cliOut } from "../cliOutput.js"; // eslint-disable-line @typescript-eslint/no-unused-vars
10
- import { throwError } from "../throwError.js";
11
- import { resolveSassImport, resolveScssImport } from "./resolveSassScssImports.js";
8
+ import { staticFolder } from '../settings.js';
9
+ import { cliError, cliOut } from '../cliOutput.js'; // eslint-disable-line @typescript-eslint/no-unused-vars
10
+ import { throwError } from '../throwError.js';
11
+ import { resolveSassImport, resolveScssImport } from './resolveSassScssImports.js';
12
12
  function debug(...texts) {
13
13
  //console.log(...texts)
14
14
  }
@@ -2,5 +2,5 @@ import type { CompilationInfo } from './CompilationInfo.js';
2
2
  import type { FrameworkConfigComplete } from '../FrameworkConfig.js';
3
3
  import type { Mode } from '../Mode.js';
4
4
  import { type TimeProfiler } from '../timeProfiler.js';
5
- export declare function compileUserApp(projectDir: string, appConfig: FrameworkConfigComplete, mode: Mode, profiler?: TimeProfiler, quiet?: boolean, tests?: boolean): Promise<CompilationInfo>;
5
+ export declare function compileUserApp(projectDir: string, appConfig: FrameworkConfigComplete, mode: Mode, profiler?: TimeProfiler, quiet?: boolean, tests?: boolean, fresh?: boolean): Promise<CompilationInfo>;
6
6
  //# sourceMappingURL=compileUserApp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compileUserApp.d.ts","sourceRoot":"","sources":["../../src/build/compileUserApp.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAWtC,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAI1E,wBAAsB,cAAc,CAChC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,uBAAuB,EAAE,IAAI,EAAE,IAAI,EAClE,QAAQ,GAAE,YAAwC,EAAE,KAAK,UAAQ,EAAE,KAAK,UAAQ,GACjF,OAAO,CAAC,eAAe,CAAC,CA4E1B"}
1
+ {"version":3,"file":"compileUserApp.d.ts","sourceRoot":"","sources":["../../src/build/compileUserApp.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAWtC,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAI1E,wBAAsB,cAAc,CAChC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,uBAAuB,EAAE,IAAI,EAAE,IAAI,EAClE,QAAQ,GAAE,YAAwC,EAAE,KAAK,UAAQ,EAAE,KAAK,UAAQ,EAAE,KAAK,UAAQ,GAChG,OAAO,CAAC,eAAe,CAAC,CAgF1B"}
@@ -1,15 +1,15 @@
1
1
  import { join } from 'path';
2
- import { compileJavascript } from "./compileJavascript.js";
3
- import { compileStyles } from "./compileStyles.js";
4
- import { copyAssets } from "./copyAssets.js";
5
- import { copyPublicFiles } from "./copyPublicFiles.js";
6
- import { buildCodeSubPath, bundleFolder, devBuildOuterFolder, frameworkCssFile, frameworkCssFolder, prodBuildFolder } from "../settings.js";
7
- import { combineComponentCss } from "./combineComponentCss.js";
8
- import { writeFrameworkCss } from "./frameworkStylesheets.js";
9
- import { emitReloadEvent } from "../hmr/liveReloadHub.js";
10
- import { createTimeProfiler } from "../timeProfiler.js";
2
+ import { compileJavascript } from './compileJavascript.js';
3
+ import { compileStyles } from './compileStyles.js';
4
+ import { copyAssets } from './copyAssets.js';
5
+ import { copyPublicFiles } from './copyPublicFiles.js';
6
+ import { buildCodeSubPath, bundleFolder, devBuildOuterFolder, frameworkCssFile, frameworkCssFolder, prodBuildFolder } from '../settings.js';
7
+ import { combineComponentCss } from './combineComponentCss.js';
8
+ import { writeFrameworkCss } from './frameworkStylesheets.js';
9
+ import { emitReloadEvent } from '../hmr/liveReloadHub.js';
10
+ import { createTimeProfiler } from '../timeProfiler.js';
11
11
  //import { compileEnv } from './compileEnv.js'
12
- export async function compileUserApp(projectDir, appConfig, mode, profiler = createTimeProfiler(false), quiet = false, tests = false) {
12
+ export async function compileUserApp(projectDir, appConfig, mode, profiler = createTimeProfiler(false), quiet = false, tests = false, fresh = false) {
13
13
  const codeLocation = join(projectDir, appConfig.codeDir);
14
14
  const relSourceDir = appConfig.sourceDir !== undefined && appConfig.sourceDir !== '' ? appConfig.sourceDir : appConfig.codeDir;
15
15
  const sourceLocation = join(projectDir, relSourceDir);
@@ -23,13 +23,16 @@ export async function compileUserApp(projectDir, appConfig, mode, profiler = cre
23
23
  const compileJavascriptPromise = profiler.timeProfileAsync('compile javascript', () => compileJavascript(projectDir, appConfig, codeLocation, sourceLocation, styleImportBase, buildLocation, buildCodeLocation, mode, watch, mode === 'dev' ? {
24
24
  quiet,
25
25
  tests,
26
+ fresh,
26
27
  hmr: appConfig.hmr === true,
28
+ // a raw-only file (server code) has nothing for the browser to reload
27
29
  onCycleComplete: cycle => {
28
- if (cycle.success) emitReloadEvent('js', cycle.file);
30
+ if (cycle.success && cycle.client !== false) emitReloadEvent('js', cycle.file);
29
31
  }
30
32
  } : {
31
33
  quiet,
32
- tests
34
+ tests,
35
+ fresh
33
36
  }));
34
37
  //const compileEnvPromise = compileEnv(projectDir, appConfig, codeLocation, buildLocation, mode)
35
38
  const compileStylesPromise = profiler.timeProfileAsync('compile styles', () => compileStyles(projectDir, appConfig, styleImportBase, buildLocation, watch, mode === 'dev' ? () => emitReloadEvent('css') : undefined, quiet));
@@ -0,0 +1,10 @@
1
+ export type CompiledStyles = {
2
+ css: string;
3
+ dependencies: string[];
4
+ };
5
+ export declare function makeComponentStylesCache(cacheDir: string | undefined, fresh?: boolean): {
6
+ lookup(moduleName: string, language: string, rawStyles: string): CompiledStyles | undefined;
7
+ store(moduleName: string, language: string, rawStyles: string, compiled: CompiledStyles): void;
8
+ };
9
+ export type ComponentStylesCache = ReturnType<typeof makeComponentStylesCache>;
10
+ //# sourceMappingURL=componentStylesCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"componentStylesCache.d.ts","sourceRoot":"","sources":["../../src/build/componentStylesCache.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,cAAc,GAAG;IACzB,GAAG,EAAE,MAAM,CAAA;IAEX,YAAY,EAAE,MAAM,EAAE,CAAA;CACzB,CAAA;AAoBD,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,UAAQ;uBAKzD,MAAM,YAAY,MAAM,aAAa,MAAM,GAAG,cAAc,GAAG,SAAS;sBAezE,MAAM,YAAY,MAAM,aAAa,MAAM,YAAY,cAAc;EAY9F;AAED,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAA"}
@@ -0,0 +1,54 @@
1
+ import { createHash } from 'crypto';
2
+ import fs from 'fs';
3
+ import { join } from 'path';
4
+ import { frameworkVersion } from './frameworkDestLocation.js';
5
+ const sha1 = data => createHash('sha1').update(data).digest('hex');
6
+ const blockHash = (language, rawStyles) => sha1(`${language}\0${rawStyles}`);
7
+ const fileHash = file => {
8
+ try {
9
+ return sha1(fs.readFileSync(file, 'utf8'));
10
+ } catch {
11
+ return undefined;
12
+ }
13
+ };
14
+ // fresh: every lookup misses, so everything compiles from source and the records are all rewritten
15
+ export function makeComponentStylesCache(cacheDir, fresh = false) {
16
+ // `#` (the framework module prefix) is kept out of filenames, as the css manifest does
17
+ const recordFile = (dir, moduleName) => join(dir, `${moduleName.replaceAll('#', '')}.json`);
18
+ return {
19
+ lookup(moduleName, language, rawStyles) {
20
+ if (cacheDir === undefined || fresh) return undefined;
21
+ let record;
22
+ try {
23
+ record = JSON.parse(fs.readFileSync(recordFile(cacheDir, moduleName), 'utf8'));
24
+ } catch {
25
+ return undefined;
26
+ }
27
+ if (record.version !== frameworkVersion || record.hash !== blockHash(language, rawStyles)) return undefined;
28
+ if (!Array.isArray(record.dependencies) || typeof record.css !== 'string') return undefined;
29
+ for (const dependency of record.dependencies) {
30
+ if (fileHash(dependency.file) !== dependency.hash) return undefined;
31
+ }
32
+ return {
33
+ css: record.css,
34
+ dependencies: record.dependencies.map(dependency => dependency.file)
35
+ };
36
+ },
37
+ store(moduleName, language, rawStyles, compiled) {
38
+ if (cacheDir === undefined) return;
39
+ const record = {
40
+ version: frameworkVersion,
41
+ hash: blockHash(language, rawStyles),
42
+ css: compiled.css,
43
+ dependencies: compiled.dependencies.map(file => ({
44
+ file,
45
+ hash: fileHash(file) ?? ''
46
+ }))
47
+ };
48
+ fs.mkdirSync(cacheDir, {
49
+ recursive: true
50
+ });
51
+ fs.writeFileSync(recordFile(cacheDir, moduleName), JSON.stringify(record));
52
+ }
53
+ };
54
+ }
@@ -3,7 +3,7 @@ import chokidar from 'chokidar';
3
3
  import { join, dirname } from 'path';
4
4
  import { promises as fsPromises } from 'fs';
5
5
  import { globby } from 'globby';
6
- import { cliOut } from "../cliOutput.js";
6
+ import { cliOut } from '../cliOutput.js';
7
7
  async function copyFile(assetsLocation, targetLocation, filePathFull, event) {
8
8
  const relFile = filePathFull.slice(assetsLocation.length + 1);
9
9
  const target = join(targetLocation, relFile);
@@ -1,10 +1,10 @@
1
1
  import { existsSync, promises as fsPromises } from 'fs';
2
2
  import { dirname, join } from 'path';
3
3
  import { transformSync as babelTransformSync } from '@babel/core';
4
- import { findProjectDir } from "../findProjectDir.js";
5
- import { devBuildOuterFolder, prodBuildFolder, packagesFolder } from "../settings.js";
6
- import { MakeBabelTransformDependencyImports } from "../babelPlugins/BabelTransformDependencyImportsOld.js";
7
- import { TungstenError } from "../TungstenError.js";
4
+ import { findProjectDir } from '../findProjectDir.js';
5
+ import { devBuildOuterFolder, prodBuildFolder, packagesFolder } from '../settings.js';
6
+ import { MakeBabelTransformDependencyImports } from '../babelPlugins/BabelTransformDependencyImportsOld.js';
7
+ import { TungstenError } from '../TungstenError.js';
8
8
  import { cliWarn } from 'tungsten/cliOutput.js';
9
9
  const frameworkDir = findProjectDir(import.meta.url);
10
10
  // unused!
@@ -3,7 +3,7 @@ import chokidar from 'chokidar';
3
3
  import { join, dirname } from 'path';
4
4
  import { promises as fsPromises } from 'fs';
5
5
  import { globby } from 'globby';
6
- import { cliOut } from "../cliOutput.js";
6
+ import { cliOut } from '../cliOutput.js';
7
7
  async function copyFile(assetsLocation, targetLocation, filePathFull, event) {
8
8
  const relFile = filePathFull.slice(assetsLocation.length + 1);
9
9
  const target = join(targetLocation, relFile);
@@ -1,8 +1,8 @@
1
1
  import { promises as fsPromises } from 'fs';
2
2
  import { join } from 'path';
3
- import { buildCodeSubPath, devBuildOuterFolder, prodBuildFolder, clientFolder, frameworkDistFolder, frameworkClientFolder } from "../settings.js";
4
- import { fixExtension } from "../fixExtension.js";
5
- import { findProjectDir } from "../findProjectDir.js";
3
+ import { buildCodeSubPath, devBuildOuterFolder, prodBuildFolder, clientFolder, frameworkDistFolder, frameworkClientFolder } from '../settings.js';
4
+ import { fixExtension } from '../fixExtension.js';
5
+ import { findProjectDir } from '../findProjectDir.js';
6
6
  export async function createClientFiles(config, mode, buildLocation) {
7
7
  //console.log('creating entry file')
8
8
  const specificBuildFolder = buildLocation ?? join(process.cwd(), mode === 'dev' ? devBuildOuterFolder : prodBuildFolder);
@@ -1,7 +1,7 @@
1
1
  import { promises as fsPromises } from 'fs';
2
2
  import { join, dirname } from 'path';
3
- import { devBuildOuterFolder, prodBuildFolder } from "../settings.js";
4
- import { TungstenError } from "../TungstenError.js";
3
+ import { devBuildOuterFolder, prodBuildFolder } from '../settings.js';
4
+ import { TungstenError } from '../TungstenError.js';
5
5
  export async function createInstanceConfigFile(config, mode, buildLocation) {
6
6
  //console.log('creating app config')
7
7
  const specificBuildFolder = buildLocation ?? join(process.cwd(), mode === 'dev' ? devBuildOuterFolder : prodBuildFolder);
@@ -1,4 +1,4 @@
1
- import { createPackageVirtualFileSystem } from "./createPackageVirtualFileSystem.js";
1
+ import { createPackageVirtualFileSystem } from './createPackageVirtualFileSystem.js';
2
2
  // pretty sure we aren't using this now
3
3
  export function createPackageVirtualFileSystems(packages) {
4
4
  for (const p of Object.values(packages)) {
@@ -1,9 +1,9 @@
1
1
  import { join } from 'path';
2
- import { getFrameworkDir } from "../getFrameworkDir.js";
3
- import { devBuildOuterFolder, frameworkDistFolder } from "../settings.js";
4
- import { spawnShellCommand } from "../spawnShellCommand.js";
5
- import { cliError, cliOut } from "../cliOutput.js";
6
- import { frameworkDestLocation } from "./frameworkDestLocation.js";
2
+ import { getFrameworkDir } from '../getFrameworkDir.js';
3
+ import { devBuildOuterFolder, frameworkDistFolder } from '../settings.js';
4
+ import { spawnShellCommand } from '../spawnShellCommand.js';
5
+ import { cliError, cliOut } from '../cliOutput.js';
6
+ import { frameworkDestLocation } from './frameworkDestLocation.js';
7
7
  export async function devBundle() {
8
8
  return new Promise((resolve, reject) => {
9
9
  cliOut('Creating dev bundle');
@@ -1 +1 @@
1
- {"version":3,"file":"devBundle.rollup.config.d.ts","sourceRoot":"","sources":["../../src/build/devBundle.rollup.config.ts"],"names":[],"mappings":"AAUA,KAAK,YAAY,GAAG;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACrB,CAAA;AAED,QAAA,MAAM,YAAY,EAAE,YAkBnB,CAAA;AAED,eAAe,YAAY,CAAA"}
1
+ {"version":3,"file":"devBundle.rollup.config.d.ts","sourceRoot":"","sources":["../../src/build/devBundle.rollup.config.ts"],"names":[],"mappings":"AAUA,KAAK,YAAY,GAAG;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACrB,CAAA;AAED,QAAA,MAAM,YAAY,EAAE,YAiBnB,CAAA;AAED,eAAe,YAAY,CAAA"}
@@ -20,6 +20,5 @@ const rollupConfig = {
20
20
  //filename: "stats.html",
21
21
  //template: "network"
22
22
  })]
23
- //strictDeprecations: true // help prep for upgrade to rollup 3 -- this complains about the inlineDynamicImports CLI arg
24
23
  };
25
24
  export default rollupConfig;
@@ -1,2 +1,3 @@
1
+ export declare const frameworkVersion: string;
1
2
  export declare const frameworkDestLocation: string;
2
3
  //# sourceMappingURL=frameworkDestLocation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"frameworkDestLocation.d.ts","sourceRoot":"","sources":["../../src/build/frameworkDestLocation.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,qBAAqB,QAA4E,CAAA"}
1
+ {"version":3,"file":"frameworkDestLocation.d.ts","sourceRoot":"","sources":["../../src/build/frameworkDestLocation.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,gBAAgB,EAAE,MAA4B,CAAA;AAC3D,eAAO,MAAM,qBAAqB,QAAyE,CAAA"}