zyzz 0.0.5 → 0.0.6

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 (49) hide show
  1. package/dist/babel/index.d.ts +2 -0
  2. package/dist/babel/index.d.ts.map +1 -1
  3. package/dist/babel/index.js +10 -1
  4. package/dist/babel/index.js.map +1 -1
  5. package/dist/compiler/Graph.d.ts +2 -0
  6. package/dist/compiler/Graph.d.ts.map +1 -1
  7. package/dist/compiler/Graph.js +19 -1
  8. package/dist/compiler/Graph.js.map +1 -1
  9. package/dist/compiler/Source.d.ts.map +1 -1
  10. package/dist/compiler/Source.js +5 -2
  11. package/dist/compiler/Source.js.map +1 -1
  12. package/dist/compiler/internal/Contributions.d.ts +1 -1
  13. package/dist/compiler/internal/Contributions.d.ts.map +1 -1
  14. package/dist/compiler/internal/Contributions.js +5 -3
  15. package/dist/compiler/internal/Contributions.js.map +1 -1
  16. package/dist/compiler/internal/Static.d.ts.map +1 -1
  17. package/dist/compiler/internal/Static.js +2 -0
  18. package/dist/compiler/internal/Static.js.map +1 -1
  19. package/dist/next/index.d.ts +8 -3
  20. package/dist/next/index.d.ts.map +1 -1
  21. package/dist/next/index.js +21 -10
  22. package/dist/next/index.js.map +1 -1
  23. package/dist/next/loader.d.ts +1 -0
  24. package/dist/next/loader.d.ts.map +1 -1
  25. package/dist/next/loader.js +10 -1
  26. package/dist/next/loader.js.map +1 -1
  27. package/dist/node/Reset.d.ts +3 -0
  28. package/dist/node/Reset.d.ts.map +1 -0
  29. package/dist/node/Reset.js +7 -0
  30. package/dist/node/Reset.js.map +1 -0
  31. package/dist/unplugin/index.d.ts +2 -0
  32. package/dist/unplugin/index.d.ts.map +1 -1
  33. package/dist/unplugin/index.js +2 -0
  34. package/dist/unplugin/index.js.map +1 -1
  35. package/dist/vite/index.d.ts +2 -0
  36. package/dist/vite/index.d.ts.map +1 -1
  37. package/dist/vite/index.js +38 -9
  38. package/dist/vite/index.js.map +1 -1
  39. package/package.json +1 -1
  40. package/src/babel/index.ts +23 -1
  41. package/src/compiler/Graph.ts +22 -0
  42. package/src/compiler/Source.ts +5 -1
  43. package/src/compiler/internal/Contributions.ts +5 -2
  44. package/src/compiler/internal/Static.ts +1 -0
  45. package/src/next/index.ts +34 -12
  46. package/src/next/loader.ts +16 -1
  47. package/src/node/Reset.ts +7 -0
  48. package/src/unplugin/index.ts +4 -0
  49. package/src/vite/index.ts +43 -14
package/src/vite/index.ts CHANGED
@@ -10,6 +10,7 @@ import * as Lightning from 'lightningcss'
10
10
  import * as Crypto from 'node:crypto'
11
11
  import * as Fs from 'node:fs/promises'
12
12
  import * as Path from 'node:path'
13
+ import * as Reset from '../node/Reset.js'
13
14
  import { isBuiltin } from 'node:module'
14
15
  import * as Parser from 'oxc-parser'
15
16
  import * as Walker from 'oxc-walker'
@@ -34,6 +35,8 @@ export function zyzz(options: zyzz.Options = {}): Plugin {
34
35
  options.native.units && Object.freeze({ ...options.native.units }),
35
36
  })
36
37
  : undefined
38
+ if (native && options.reset)
39
+ throw new Error('The CSS reset is only supported by web builds.')
37
40
  if (native && options.compiler === false)
38
41
  throw new Error('Native builds require source compilation.')
39
42
 
@@ -640,6 +643,7 @@ export function zyzz(options: zyzz.Options = {}): Plugin {
640
643
 
641
644
  const result = entry.compiler.compile({
642
645
  compiler: options.compiler,
646
+ reset: options.reset ? Reset.read() : undefined,
643
647
  native,
644
648
  contracts,
645
649
  development: entry.environment.mode !== 'build',
@@ -762,17 +766,39 @@ export function zyzz(options: zyzz.Options = {}): Plugin {
762
766
  for (const [key, target] of Object.entries(result.sharedAssets ?? {})) {
763
767
  const raw = target.split(/[?#]/)[0]!
764
768
 
765
- const file = await Fs.realpath(
766
- target.startsWith('app/')
767
- ? Path.join(root, decodeURIComponent(raw.slice(4)))
768
- : Path.isAbsolute(raw)
769
- ? decodeURIComponent(raw)
770
- : (() => {
771
- throw new Error('Asset path escapes the Vite graph.')
772
- })(),
773
- )
774
-
775
769
  const identity = result.sharedAssetOwners?.[key]
770
+ const path = target.startsWith('app/')
771
+ ? Path.join(root, decodeURIComponent(raw.slice(4)))
772
+ : Path.isAbsolute(raw)
773
+ ? decodeURIComponent(raw)
774
+ : undefined
775
+ if (!path) throw new Error('Asset path escapes the Vite graph.')
776
+
777
+ const asset = await (async () => {
778
+ try {
779
+ return { file: await Fs.realpath(path), package: false }
780
+ } catch (error) {
781
+ if (
782
+ (error as NodeJS.ErrnoException).code !== 'ENOENT' ||
783
+ !identity?.startsWith('app/')
784
+ )
785
+ throw error
786
+
787
+ const importer = Path.join(root, identity.slice(4))
788
+ const specifier = Path.relative(Path.dirname(importer), path)
789
+ .split(Path.sep)
790
+ .join('/')
791
+ if (specifier.startsWith('.') || Path.isAbsolute(specifier))
792
+ throw error
793
+ const resolved = await host.resolve(specifier, importer)
794
+ if (!resolved || resolved.external) throw error
795
+ return {
796
+ file: await Fs.realpath(resolved.id.split('?')[0]!),
797
+ package: true,
798
+ }
799
+ }
800
+ })()
801
+ const file = asset.file
776
802
 
777
803
  const owner = identity?.startsWith('app/')
778
804
  ? appRoot
@@ -782,9 +808,10 @@ export function zyzz(options: zyzz.Options = {}): Plugin {
782
808
 
783
809
  const relative = owner ? Path.relative(owner, file) : '..'
784
810
  if (
785
- relative === '..' ||
786
- relative.startsWith(`..${Path.sep}`) ||
787
- Path.isAbsolute(relative)
811
+ !asset.package &&
812
+ (relative === '..' ||
813
+ relative.startsWith(`..${Path.sep}`) ||
814
+ Path.isAbsolute(relative))
788
815
  )
789
816
  throw new Error('Asset path escapes its owning package.')
790
817
 
@@ -793,7 +820,7 @@ export function zyzz(options: zyzz.Options = {}): Plugin {
793
820
 
794
821
  let url: string
795
822
 
796
- if (/[?#%]/.test(file)) {
823
+ if (asset.package || /[?#%]/.test(file)) {
797
824
  if (entry.environment.mode === 'build') {
798
825
  url = await host.asset(file)
799
826
 
@@ -1465,6 +1492,8 @@ export declare namespace zyzz {
1465
1492
  readonly compiler?: boolean | undefined
1466
1493
  /** Native context captured at creation. Disables CSS delivery and initialization scripts. */
1467
1494
  readonly native?: Graph.compile.Options['native']
1495
+ /** Include the CSS reset. Defaults to false. */
1496
+ readonly reset?: boolean | undefined
1468
1497
  /**
1469
1498
  * Inline each configuration's `script()` at the start of index.html's head.
1470
1499
  * False skips injection for documents that inline the script themselves.