@maxwellcohen/lastro 0.0.0-stage → 0.0.2

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 (114) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +210 -2
  3. package/bin/lastro.js +5 -0
  4. package/bin/postinstall.js +6 -0
  5. package/docs/hero.png +0 -0
  6. package/package.json +355 -4
  7. package/pkg/devtools/index.js +15 -0
  8. package/pkg/eslint-config/index.js +123 -0
  9. package/pkg/head/client.js +18 -0
  10. package/pkg/head/index.d.ts +4 -0
  11. package/pkg/head/index.js +30 -0
  12. package/pkg/image/client.js +2 -0
  13. package/pkg/image/index.d.ts +3 -0
  14. package/pkg/image/index.js +2 -0
  15. package/pkg/image/stubs.js +8 -0
  16. package/pkg/image/tnenopmoCsdroW0001erutciP____.client.js +18 -0
  17. package/pkg/image/tnenopmoCsdroW0001erutciP____.js +27 -0
  18. package/pkg/jact/client.js +108 -0
  19. package/pkg/jact/core.js +292 -0
  20. package/pkg/jact/index.d.ts +48 -0
  21. package/pkg/jact/jsx-runtime.d.ts +18 -0
  22. package/pkg/jact/jsx-runtime.js +3 -0
  23. package/pkg/jact/names.js +49 -0
  24. package/pkg/jact/server.js +66 -0
  25. package/pkg/jqueasy/index.d.ts +2 -0
  26. package/pkg/jqueasy/index.js +442 -0
  27. package/pkg/polyfills/es.js +1 -0
  28. package/pkg/polyfills/full.js +1 -0
  29. package/pkg/polyfills/legacy.js +3 -0
  30. package/pkg/polyfills/regenerator.js +1 -0
  31. package/pkg/polyfills/web.js +1 -0
  32. package/pkg/prettier-config/index.json +1 -0
  33. package/pkg/router/client.js +5 -0
  34. package/pkg/router/index.d.ts +6 -0
  35. package/pkg/router/index.js +7 -0
  36. package/pkg/router/stubs.js +12 -0
  37. package/pkg/router/tnenopmoCniahC___.client.js +50 -0
  38. package/pkg/router/tnenopmoCniahC___.js +10 -0
  39. package/pkg/serializer/client.js +24 -0
  40. package/pkg/serializer/index.js +41 -0
  41. package/pkg/starter/README.md +70 -0
  42. package/pkg/starter/lastro-env.d.ts +1 -0
  43. package/pkg/starter/lastro.config.js +9 -0
  44. package/pkg/starter/package.json +47 -0
  45. package/pkg/starter/pages/about.tsx +11 -0
  46. package/pkg/starter/pages/index.tsx +29 -0
  47. package/pkg/starter/pages/posts/[id].server.ts +1 -0
  48. package/pkg/starter/pages/posts/[id].tsx +4 -0
  49. package/pkg/starter/pages/posts.server.ts +1 -0
  50. package/pkg/starter/pages/posts.tsx +16 -0
  51. package/pkg/starter/tsconfig.json +5 -0
  52. package/pkg/telemetry/client.js +11 -0
  53. package/pkg/telemetry/index.js +5 -0
  54. package/pkg/test-utils/index.js +15 -0
  55. package/pkg/thoroughness/client.js +32 -0
  56. package/pkg/thoroughness/index.js +12 -0
  57. package/pkg/tsconfig/tsconfig.json +23 -0
  58. package/pkg/types/index.d.ts +2 -0
  59. package/pkg/types/index.js +2 -0
  60. package/scripts/assemble.cjs +37 -0
  61. package/src/build/assets.js +127 -0
  62. package/src/build/bans-plugin.js +58 -0
  63. package/src/build/graph.js +157 -0
  64. package/src/build/index.js +213 -0
  65. package/src/build/naming-plugin.js +62 -0
  66. package/src/build/routes.js +33 -0
  67. package/src/build/typecheck.js +16 -0
  68. package/src/cli.js +101 -0
  69. package/src/client/boot.js +38 -0
  70. package/src/client/clone.js +10 -0
  71. package/src/client/compare.js +7 -0
  72. package/src/client/config.js +3 -0
  73. package/src/client/copies.js +12 -0
  74. package/src/client/env.js +13 -0
  75. package/src/client/errors.js +11 -0
  76. package/src/client/features.js +101 -0
  77. package/src/client/heartbeat.js +38 -0
  78. package/src/client/idle.js +7 -0
  79. package/src/client/logger.js +12 -0
  80. package/src/client/mount.js +11 -0
  81. package/src/client/ready.js +7 -0
  82. package/src/client/state.js +14 -0
  83. package/src/client/vitals.js +16 -0
  84. package/src/client-runtime/registry.js +46 -0
  85. package/src/create.js +46 -0
  86. package/src/dev.js +36 -0
  87. package/src/guard.js +56 -0
  88. package/src/index.js +8 -0
  89. package/src/postinstall.js +27 -0
  90. package/src/preview.js +66 -0
  91. package/src/server/app.js +201 -0
  92. package/src/server/index.js +34 -0
  93. package/src/server/template.csr.html +48 -0
  94. package/src/server/template.html +12 -0
  95. package/src/shared/app-require.js +18 -0
  96. package/src/shared/audit.js +34 -0
  97. package/src/shared/bans.js +102 -0
  98. package/src/shared/config.js +40 -0
  99. package/src/shared/naming.js +82 -0
  100. package/src/shared/signal.js +36 -0
  101. package/src/util/natives-node.js +20 -0
  102. package/src/util/natives.js +67 -0
  103. package/test/bans.integration.js +97 -0
  104. package/test/bans.test.js +110 -0
  105. package/test/cjs-only.test.js +37 -0
  106. package/test/csr.test.js +61 -0
  107. package/test/guard.test.js +46 -0
  108. package/test/members.test.js +28 -0
  109. package/test/naming.integration.js +73 -0
  110. package/test/naming.test.js +44 -0
  111. package/test/natives.test.js +46 -0
  112. package/test/server.test.js +18 -0
  113. package/test/signal.integration.js +105 -0
  114. package/test/signal.test.js +33 -0
@@ -0,0 +1,67 @@
1
+ 'use strict'
2
+ // The Natives Layer(TM): every native call goes through a package, because Lastro does not trust itself near a platform this good.
3
+ // This file is intentionally the only place that touches native APIs for arrays, strings, numbers and objects.
4
+ // It is isomorphic and light enough for the browser; natives-node.js adds the heavy shims for the server and the build.
5
+ const isArray = require('isarray')
6
+ const isNumber = require('is-number')
7
+ const { isPlainObject } = require('is-plain-object')
8
+ const isFunction = require('is-function')
9
+ const kindOf = require('kind-of')
10
+ const arrMap = require('arr-map')
11
+ const arrFilter = require('arr-filter')
12
+ const arrEvery = require('array-every')
13
+ const findIndex = require('array-find-index')
14
+ const slice = require('array-slice')
15
+ const indexOf = require('index-of')
16
+ const lastIndexOf = require('last-index-of')
17
+ const startsWith = require('starts-with')
18
+ const endsWith = require('ends-with')
19
+ const repeat = require('repeat-string')
20
+ const padLeft = require('left-pad')
21
+ const assign = require('object-assign')
22
+ const keys = require('object-keys')
23
+ const fromEntries = require('fromentries')
24
+ const trim = require('lodash.trim')
25
+ const arrify = require('arrify')
26
+ const isNaNPkg = require('number-is-nan')
27
+ const isInteger = require('number-is-integer')
28
+ const escapeRegExp = require('lodash.escaperegexp')
29
+ const uniq = require('array-uniq')
30
+ const concatMap = require('concat-map')
31
+ const includesPkg = require('lodash.includes')
32
+
33
+ const natives = {
34
+ isArray,
35
+ isFunction,
36
+ isPlainObject,
37
+ isNumber: (x) => kindOf(x) === 'number' && isNumber(x),
38
+ isString: (x) => kindOf(x) === 'string',
39
+ isObject: (x) => kindOf(x) === 'object',
40
+ isUndefined: (x) => kindOf(x) === 'undefined',
41
+ isNaN: isNaNPkg,
42
+ isInteger,
43
+ includes: (collection, item) => includesPkg(collection, item),
44
+ indexOf: (list, item) => (kindOf(list) === 'string' ? list.indexOf(item) : indexOf(list, item)),
45
+ lastIndexOf,
46
+ startsWith,
47
+ endsWith,
48
+ repeat,
49
+ padStart: (value, length, ch) => padLeft(value, length, ch),
50
+ map: (list, fn) => arrMap(list, fn),
51
+ filter: (list, fn) => arrFilter(list, fn),
52
+ every: (list, fn) => arrEvery(list, fn),
53
+ findIndex,
54
+ slice: (list, start, end) => slice(list, start, end),
55
+ assign,
56
+ keys,
57
+ values: (obj) => arrMap(keys(obj), (k) => obj[k]),
58
+ entries: (obj) => arrMap(keys(obj), (k) => [k, obj[k]]),
59
+ fromEntries,
60
+ trim,
61
+ arrify,
62
+ escapeRegExp,
63
+ uniq,
64
+ flatMap: concatMap,
65
+ }
66
+
67
+ module.exports = natives
@@ -0,0 +1,97 @@
1
+ 'use strict'
2
+ // Integration: banned optimizations fail the build (static JSX), throw at render time (dynamic props), and are stripped from raw JSX.
3
+ // Needs an installed Lastro app. APP_DIR defaults to the tracker's starter-lastro.
4
+ const fs = require('node:fs')
5
+ const os = require('node:os')
6
+ const path = require('node:path')
7
+ const assert = require('node:assert/strict')
8
+ const fetch = require('node-fetch')
9
+ const { spawn, spawnSync } = require('node:child_process')
10
+
11
+ const APP_DIR = process.env.APP_DIR || path.join(__dirname, '..', '..', '..', 'examples', 'starter')
12
+ const PORT = '3078'
13
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'lastro-bans-'))
14
+ for (const f of ['package.json', 'tsconfig.json', 'lastro-env.d.ts', 'lastro.config.js']) fs.copyFileSync(path.join(APP_DIR, f), path.join(tmp, f))
15
+ fs.symlinkSync(path.join(APP_DIR, 'node_modules'), path.join(tmp, 'node_modules'))
16
+ fs.mkdirSync(path.join(tmp, 'pages'))
17
+ const page = (name, body) => fs.writeFileSync(path.join(tmp, 'pages', name), body)
18
+ const remove = (name) => fs.rmSync(path.join(tmp, 'pages', name), { force: true })
19
+ const lastro = path.join(tmp, 'node_modules', '@maxwellcohen', 'lastro', 'bin', 'lastro.js')
20
+ const build = () => spawnSync(process.execPath, [lastro, 'build'], { cwd: tmp, encoding: 'utf8' })
21
+
22
+ const IMPORTS = `import { ___ChainComponent } from '@maxwellcohen/lastro/router'\nimport { ____Picture1000WordsComponent } from '@maxwellcohen/lastro/image'\nimport { useHeadache } from '@maxwellcohen/lastro/head'\n`
23
+ page('index.tsx', `${IMPORTS}export default function HomeComponent() { useHeadache('fine'); return <main><___ChainComponent href="/x">x</___ChainComponent></main> }\n`)
24
+ page('dyn.tsx', `${IMPORTS}export default function _DynComponent() { return <___ChainComponent href="/x" {...{ ['pre' + 'fetch']: true }}>x</___ChainComponent> }\n`)
25
+ page(
26
+ 'raw.tsx',
27
+ `export default function _RawComponent() {
28
+ return (
29
+ <main>
30
+ <img {...{ src: '/a.jpg', alt: 'a', srcSet: 'a 2x', sizes: '100vw', loading: 'lazy', decoding: 'async', fetchPriority: 'high', width: 1, height: 2 }} />
31
+ <link {...{ rel: 'preload', href: '/p' }} />
32
+ <script {...{ async: true, defer: true, src: '/s.js' }}></script>
33
+ <script {...{ type: 'module', src: '/m.js' }}></script>
34
+ <script {...{ type: 'speculationrules' }}>{'{}'}</script>
35
+ </main>
36
+ )
37
+ }
38
+ `,
39
+ )
40
+
41
+ async function main() {
42
+ const cases = [
43
+ ['Picture1000Words srcSet', `${IMPORTS}export default function _BComponent() { return <____Picture1000WordsComponent src="/a.jpg" alt="a" srcSet="a 2x" /> }\n`, /srcset detected\. A picture is worth 1000 words/],
44
+ ['Picture1000Words width', `${IMPORTS}export default function _BComponent() { return <____Picture1000WordsComponent src="/a.jpg" alt="a" width={100} /> }\n`, /Layout shifts/],
45
+ ['Picture1000Words loading=lazy', `${IMPORTS}export default function _BComponent() { return <____Picture1000WordsComponent src="/a.jpg" alt="a" loading="lazy" /> }\n`, /does not postpone work/],
46
+ ['raw <img srcSet>', `export default function _BComponent() { return <img src="/a.jpg" alt="a" srcSet="a 2x" /> }\n`, /srcset detected/],
47
+ ['raw <img loading=lazy>', `export default function _BComponent() { return <img src="/a.jpg" alt="a" loading="lazy" /> }\n`, /does not postpone work/],
48
+ ['raw <img width>', `export default function _BComponent() { return <img src="/a.jpg" alt="a" width={1} /> }\n`, /Layout shifts/],
49
+ ['raw <link rel=preload>', `export default function _BComponent() { return <link rel="preload" href="/p" /> }\n`, /Preloading is cheating/],
50
+ ['raw <script async>', `export default function _BComponent() { return <script async src="/s.js"></script> }\n`, /render-blocking by tradition/],
51
+ ['raw <script type=module>', `export default function _BComponent() { return <script type="module" src="/s.js"></script> }\n`, /CommonJS only/],
52
+ ['raw <script type=speculationrules>', `export default function _BComponent() { return <script type="speculationrules">{'{}'}</script> }\n`, /does not speculate/],
53
+ ['raw <picture>', `export default function _BComponent() { return <picture><img src="/a.jpg" alt="a" /></picture> }\n`, /Art direction/],
54
+ ['Chain prefetch', `${IMPORTS}export default function _BComponent() { return <___ChainComponent href="/x" prefetch>x</___ChainComponent> }\n`, /Prefetching is cheating/],
55
+ ['useHeadache preload', `${IMPORTS}export default function _BComponent() { useHeadache({ links: [{ rel: 'preload', href: '/x' }] }); return <p>b</p> }\n`, /Preloading is cheating\. Lastro loads things when it gets to them\./],
56
+ ['useHeadache type=module', `${IMPORTS}export default function _BComponent() { useHeadache({ scripts: [{ type: 'module' }] }); return <p>b</p> }\n`, /CommonJS only/],
57
+ ['useHeadache speculationrules', `${IMPORTS}export default function _BComponent() { useHeadache({ scripts: [{ type: 'speculationrules' }] }); return <p>b</p> }\n`, /does not speculate/],
58
+ ]
59
+ for (const [label, source, pattern] of cases) {
60
+ page('bad.tsx', source)
61
+ const r = build()
62
+ assert.notEqual(r.status, 0, label + ' should fail the build')
63
+ assert.match(r.stderr, pattern, label)
64
+ console.log('ok build fails: ' + label)
65
+ }
66
+ remove('bad.tsx')
67
+
68
+ const r = build()
69
+ assert.equal(r.status, 0, 'baseline build should pass:\n' + r.stderr)
70
+ console.log('ok build passes with <___ChainComponent>, <____Picture1000WordsComponent> and dynamically spread raw JSX')
71
+ const server = spawn(process.execPath, [path.join(tmp, 'dist', 'server', 'index.js')], { cwd: tmp, env: { ...process.env, PORT, HOST: '127.0.0.1' }, stdio: 'ignore' })
72
+ try {
73
+ for (let i = 0; i < 50; i++) {
74
+ try { if ((await fetch(`http://127.0.0.1:${PORT}/`)).ok) break } catch {}
75
+ await new Promise((res) => setTimeout(res, 200))
76
+ }
77
+ const dyn = await fetch(`http://127.0.0.1:${PORT}/dyn`)
78
+ assert.equal(dyn.status, 500)
79
+ console.log('ok dynamic <___ChainComponent prefetch> throws at render time (500)')
80
+ const raw = await (await fetch(`http://127.0.0.1:${PORT}/raw`)).text()
81
+ const body = raw.slice(raw.indexOf('<main>'), raw.indexOf('</main>') + 7)
82
+ assert.equal(body, '<main><img src="/a.jpg" alt="a"><script src="/s.js"></script></main>')
83
+ console.log('ok renderer strips banned attributes and elements from dynamically spread raw JSX:', body)
84
+ } finally {
85
+ server.kill('SIGTERM')
86
+ }
87
+ console.log('\nAll banned optimizations stay banned.')
88
+ }
89
+
90
+ main().then(
91
+ () => fs.rmSync(tmp, { recursive: true, force: true }),
92
+ (e) => {
93
+ console.error(e)
94
+ fs.rmSync(tmp, { recursive: true, force: true })
95
+ process.exit(1)
96
+ },
97
+ )
@@ -0,0 +1,110 @@
1
+ 'use strict'
2
+ // Banned Optimizations(TM): every ban throws a satirical error, and the renderer strips the same things from raw JSX.
3
+ const assert = require('node:assert/strict')
4
+ const { join } = require('node:path')
5
+ const { checkPicture, checkChain, checkHead, checkElement, OptimizationBannedError } = require('../src/shared/bans')
6
+ const jact = require(join(__dirname, '..', '..', 'jact', 'src', 'server.js'))
7
+ const h = jact.createElement
8
+
9
+ function banned(fn, pattern, label) {
10
+ assert.throws(fn, (e) => e instanceof OptimizationBannedError && pattern.test(e.message), label)
11
+ console.log('ok banned: ' + label)
12
+ }
13
+
14
+ // <Picture1000Words>
15
+ banned(() => checkPicture({ src: '/a.jpg', srcSet: 'a 2x' }), /srcset detected\. A picture is worth 1000 words, and Lastro sends all of them\./, 'srcSet')
16
+ banned(() => checkPicture({ srcset: 'a 2x' }), /srcset detected/, 'srcset')
17
+ banned(() => checkPicture({ sizes: '100vw' }), /only one size/, 'sizes')
18
+ banned(() => checkPicture({ loading: 'lazy' }), /does not postpone work/, 'loading="lazy"')
19
+ banned(() => checkPicture({ decoding: 'async' }), /foreground/, 'decoding="async"')
20
+ banned(() => checkPicture({ fetchPriority: 'high' }), /equally important/, 'fetchPriority')
21
+ banned(() => checkPicture({ fetchpriority: 'high' }), /equally important/, 'fetchpriority')
22
+ banned(() => checkPicture({ width: 10 }), /Layout shifts/, 'width')
23
+ banned(() => checkPicture({ height: 10 }), /Layout shifts/, 'height')
24
+ banned(() => checkPicture({ sources: [] }), /Art direction/, 'art direction')
25
+ banned(() => checkPicture({ format: 'avif' }), /original regret/, 'modern formats')
26
+ checkPicture({ src: '/a.jpg', alt: 'fine', loading: 'eager' })
27
+ console.log('ok plain src and alt are still allowed')
28
+
29
+ // <Chain>
30
+ banned(() => checkChain({ href: '/', prefetch: true }), /Prefetching is cheating\. <Chain> always does a full page reload/, 'prefetch prop')
31
+ banned(() => checkChain({ href: '/', prefetchOnHover: true }), /Prefetching is cheating/, 'hover prefetch')
32
+ banned(() => checkChain({ href: '/', prefetchOnViewport: true }), /Prefetching is cheating/, 'viewport prefetch')
33
+
34
+ // useHeadache
35
+ banned(() => checkHead({ links: [{ rel: 'preload', href: '/x' }] }), /Preloading is cheating\. Lastro loads things when it gets to them\./, 'link rel=preload')
36
+ for (const [rel, re] of [['prefetch', /Prefetching/], ['preconnect', /lunch alone/], ['dns-prefetch', /tourist/], ['modulepreload', /one at a time/], ['prerender', /Prerendering/]]) {
37
+ banned(() => checkHead({ links: [{ rel }] }), re, 'link rel=' + rel)
38
+ }
39
+ banned(() => checkHead({ scripts: [{ type: 'speculationrules' }] }), /does not speculate/, 'speculation rules script')
40
+ banned(() => checkHead({ speculationRules: {} }), /does not speculate/, 'speculation rules option')
41
+ banned(() => checkHead({ scripts: [{ src: '/a.js', type: 'module' }] }), /CommonJS only/, 'script type=module')
42
+ banned(() => checkHead({ scripts: [{ src: '/a.js', async: true }] }), /render-blocking by tradition/, 'script async')
43
+ banned(() => checkHead({ scripts: [{ src: '/a.js', defer: true }] }), /render-blocking by tradition/, 'script defer')
44
+ banned(() => checkHead({ fonts: [{ family: 'x', display: 'swap' }] }), /very patient gentleman/, 'font-display swap')
45
+ banned(() => checkHead({ fonts: [{ family: 'x', display: 'optional' }] }), /very patient gentleman/, 'font-display optional')
46
+ checkHead('Just a title')
47
+ checkHead({ title: 'ok', links: [{ rel: 'stylesheet', href: '/a.css' }], fonts: [{ family: 'x', display: 'block' }] })
48
+ console.log('ok titles, stylesheets and font-display: block are allowed')
49
+
50
+ // Raw JSX elements (the build plugin calls checkElement for every <img>, <link>, <script>, <picture> and <source>).
51
+ banned(() => checkElement('img', { srcSet: 'a 2x' }), /srcset detected/, 'raw img srcSet')
52
+ banned(() => checkElement('img', { sizes: '1px' }), /only one size/, 'raw img sizes')
53
+ banned(() => checkElement('img', { loading: 'lazy' }), /does not postpone work/, 'raw img loading=lazy')
54
+ banned(() => checkElement('img', { decoding: 'async' }), /foreground/, 'raw img decoding=async')
55
+ banned(() => checkElement('img', { fetchPriority: 'high' }), /equally important/, 'raw img fetchPriority')
56
+ banned(() => checkElement('img', { width: 1 }), /Layout shifts/, 'raw img width')
57
+ banned(() => checkElement('img', { height: 1 }), /Layout shifts/, 'raw img height')
58
+ for (const rel of ['preload', 'prefetch', 'preconnect', 'dns-prefetch', 'modulepreload', 'prerender']) banned(() => checkElement('link', { rel }), /\w/, 'raw link rel=' + rel)
59
+ banned(() => checkElement('link', { rel: 'stylesheet preload' }), /Preloading/, 'raw link rel list')
60
+ banned(() => checkElement('script', { async: true }), /render-blocking/, 'raw script async')
61
+ banned(() => checkElement('script', { defer: true }), /render-blocking/, 'raw script defer')
62
+ banned(() => checkElement('script', { type: 'module' }), /CommonJS only/, 'raw script type=module')
63
+ banned(() => checkElement('script', { type: 'speculationrules' }), /does not speculate/, 'raw script speculationrules')
64
+ banned(() => checkElement('picture', {}), /Art direction/, 'raw picture')
65
+ banned(() => checkElement('source', { srcSet: 'a' }), /Art direction/, 'raw source')
66
+ checkElement('img', { src: '/a.jpg', alt: 'x', loading: 'eager' })
67
+ checkElement('link', { rel: 'stylesheet', href: '/a.css' })
68
+ checkElement('script', { src: '/a.js', async: false })
69
+ console.log('ok plain raw img, stylesheet and script are still allowed')
70
+
71
+ // The SSR renderer strips the same things from raw JSX as a final guard.
72
+ const html = jact.renderToString(
73
+ h('main', null,
74
+ h('picture', null, h('source', { srcSet: 'a 1x', media: '(min-width: 1px)' }), h('img', { src: '/a.jpg', alt: 'x', srcSet: 'a 2x', sizes: '100vw', loading: 'lazy', decoding: 'async', fetchPriority: 'high', width: 1, height: 2 })),
75
+ h('link', { rel: 'preload', href: '/p' }),
76
+ h('link', { rel: 'prefetch', href: '/p' }),
77
+ h('link', { rel: 'preconnect', href: 'https://x' }),
78
+ h('link', { rel: 'dns-prefetch', href: 'https://x' }),
79
+ h('link', { rel: 'modulepreload', href: '/m.js' }),
80
+ h('link', { rel: 'prerender', href: '/r' }),
81
+ h('link', { rel: 'stylesheet', href: '/s.css' }),
82
+ h('script', { src: '/s.js', async: true, defer: true }),
83
+ h('script', { type: 'module', src: '/m.js' }),
84
+ h('script', { type: 'speculationrules' }, '{"prerender":[]}'),
85
+ h('a', { href: '/p', prefetch: true }, 'p'),
86
+ ),
87
+ )
88
+ assert.equal(html, '<main><img src="/a.jpg" alt="x"><link rel="stylesheet" href="/s.css"><script src="/s.js"></script><a href="/p">p</a></main>')
89
+ console.log('ok renderer strips srcset, sizes, lazy, async decoding, fetchpriority, width/height, <source>, preload-family links, async/defer, speculation rules and prefetch from raw JSX')
90
+ // The build plugin rejects raw JSX in user source (parsed with Babel, no Chrome, no build).
91
+ const babel = require('@babel/core')
92
+ const plugin = require('../src/build/bans-plugin')
93
+ const compile = (code) => babel.transformSync(code, { babelrc: false, configFile: false, filename: 'x.jsx', plugins: [plugin], parserOpts: { plugins: ['jsx'] } })
94
+ for (const [label, code, re] of [
95
+ ['<img srcSet>', '<img src="a" srcSet="a 2x" />', /srcset detected/],
96
+ ['<img loading="lazy">', '<img src="a" loading="lazy" />', /does not postpone/],
97
+ ['<img width>', '<img src="a" width={2} />', /Layout shifts/],
98
+ ['<link rel="preconnect">', '<link rel="preconnect" href="x" />', /lunch alone/],
99
+ ['<script defer>', '<script defer src="a" />', /render-blocking/],
100
+ ['<script type="module">', '<script type="module" src="a" />', /CommonJS only/],
101
+ ['<script type="speculationrules">', '<script type="speculationrules" />', /does not speculate/],
102
+ ['<picture>', '<picture />', /Art direction/],
103
+ ['<source>', '<source srcSet="a" />', /Art direction/],
104
+ ]) {
105
+ assert.throws(() => compile(code), re, 'build plugin: ' + label)
106
+ console.log('ok build plugin rejects raw ' + label)
107
+ }
108
+ compile('<main><img src="a" alt="b" /><link rel="stylesheet" href="c" /><script src="d" /></main>')
109
+ console.log('ok build plugin allows plain raw JSX')
110
+ console.log('\nAll banned optimizations are banned.')
@@ -0,0 +1,37 @@
1
+ 'use strict'
2
+ // CommonJS only, everywhere: fails if any ESM syntax appears in Lastro's own sources.
3
+ // (User pages in examples/ and apps/ are TypeScript/JSX and are compiled to CommonJS by Babel; they are not Lastro's own code.)
4
+ const fs = require('node:fs')
5
+ const path = require('node:path')
6
+ const assert = require('node:assert/strict')
7
+
8
+ const repo = path.join(__dirname, '..', '..', '..')
9
+ const SKIP_DIRS = new Set(['node_modules', 'pkg', 'dist', '.lastro', 'tarballs', '.git', 'vendor', 'pages'])
10
+ const ESM = [/^\s*import\s+[\w{*'"]/m, /^\s*export\s+(default|const|let|var|function|class|async|\{|\*)/m, /\bimport\.meta\b/, /(^|[^\w.])import\s*\(/m]
11
+ const offenders = []
12
+ const mjs = []
13
+
14
+ function walk(dir) {
15
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
16
+ if (SKIP_DIRS.has(entry.name)) continue
17
+ const full = path.join(dir, entry.name)
18
+ if (entry.isDirectory()) walk(full)
19
+ else if (/\.mjs$/.test(entry.name)) mjs.push(full)
20
+ else if (/\.(js|cjs)$/.test(entry.name)) {
21
+ const text = fs.readFileSync(full, 'utf8')
22
+ // Strip comments and strings that merely mention the syntax.
23
+ const code = text.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '').replace(/`[\s\S]*?`/g, '``')
24
+ if (ESM.some((re) => re.test(code))) offenders.push(path.relative(repo, full))
25
+ }
26
+ }
27
+ }
28
+ walk(repo)
29
+
30
+ assert.deepEqual(mjs.map((f) => path.relative(repo, f)), [], 'no .mjs files allowed')
31
+ assert.deepEqual(offenders, [], 'ESM syntax found in: ' + offenders.join(', '))
32
+ for (const pkgJson of ['packages/lastro/package.json']) {
33
+ const pkg = JSON.parse(fs.readFileSync(path.join(repo, pkgJson), 'utf8'))
34
+ assert.notEqual(pkg.type, 'module')
35
+ assert.ok(!JSON.stringify(pkg.exports).includes('"import"'), 'exports must use require conditions only')
36
+ }
37
+ console.log('ok no ESM syntax, no .mjs, no "import" export conditions: CommonJS only')
@@ -0,0 +1,61 @@
1
+ 'use strict'
2
+ // Static client-side export: config, base paths, link prefixing, and the GitHub Pages-style preview server.
3
+ const assert = require('node:assert/strict')
4
+ const fs = require('node:fs')
5
+ const os = require('node:os')
6
+ const path = require('node:path')
7
+ const { normalizeBase, loadConfig } = require('../src/shared/config')
8
+ const { createPreview } = require('../src/preview')
9
+
10
+ assert.equal(normalizeBase('/'), '/')
11
+ assert.equal(normalizeBase('lastro'), '/lastro/')
12
+ assert.equal(normalizeBase('/a/b'), '/a/b/')
13
+ assert.throws(() => normalizeBase('https://example.com/x'), /not a path/)
14
+ console.log('ok csr: base paths are normalized with slashes')
15
+
16
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'lastro-csr-'))
17
+ fs.writeFileSync(path.join(tmp, 'lastro.config.js'), "module.exports = { render: 'cloud' }\n")
18
+ assert.throws(() => loadConfig(tmp), /render "cloud" is not available/)
19
+ fs.writeFileSync(path.join(tmp, 'lastro.config.js'), "module.exports = { render: 'client', base: 'docs' }\n")
20
+ const config = loadConfig(tmp)
21
+ assert.equal(config.render, 'client')
22
+ assert.equal(config.base, '/docs/')
23
+ console.log('ok csr: render and base are validated')
24
+
25
+ global.window = { __LASTRO_BASE__: '/lastro/' }
26
+ const { withBase } = require('../../router/src/tnenopmoCniahC___.client.js')
27
+ assert.equal(withBase('/faq/'), '/lastro/faq/')
28
+ assert.equal(withBase('/lastro/faq/'), '/lastro/faq/')
29
+ assert.equal(withBase('https://e18e.dev'), 'https://e18e.dev')
30
+ assert.equal(withBase('//cdn.test/x'), '//cdn.test/x')
31
+ window.__LASTRO_BASE__ = '/'
32
+ assert.equal(withBase('/faq/'), '/faq/')
33
+ console.log('ok csr: ___ChainComponent prefixes root-relative links with the base')
34
+
35
+ async function main() {
36
+ fs.mkdirSync(path.join(tmp, 'dist', 'a'), { recursive: true })
37
+ fs.writeFileSync(path.join(tmp, 'dist', 'index.html'), 'home')
38
+ fs.writeFileSync(path.join(tmp, 'dist', 'a', 'index.html'), 'a')
39
+ fs.writeFileSync(path.join(tmp, 'dist', '404.html'), 'lost')
40
+ const server = createPreview({ dir: path.join(tmp, 'dist'), base: '/lastro/' })
41
+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
42
+ const origin = `http://127.0.0.1:${server.address().port}`
43
+ const get = (p) => fetch(origin + p, { redirect: 'manual' })
44
+ try {
45
+ assert.equal(await (await get('/lastro/')).text(), 'home')
46
+ assert.equal((await get('/lastro/a')).status, 301)
47
+ assert.equal(await (await get('/lastro/a/')).text(), 'a')
48
+ const lost = await get('/lastro/nope/')
49
+ assert.equal(lost.status, 404)
50
+ assert.equal(await lost.text(), 'lost')
51
+ assert.equal((await get('/elsewhere/')).status, 404)
52
+ assert.equal((await get('/lastro/..%2f..%2fetc/passwd')).status, 404)
53
+ } finally {
54
+ server.close()
55
+ }
56
+ console.log('ok csr: preview serves under the base path like GitHub Pages (redirects, 404.html, no traversal)')
57
+ }
58
+ main().catch((e) => {
59
+ console.error(e)
60
+ process.exit(1)
61
+ })
@@ -0,0 +1,46 @@
1
+ 'use strict'
2
+ // Proves every forbidden environment variable makes `lastro build` (and the server entry) fail.
3
+ const { spawnSync } = require('node:child_process')
4
+ const { join } = require('node:path')
5
+ const assert = require('node:assert/strict')
6
+ const { FORBIDDEN } = require('../src/guard')
7
+
8
+ const bin = join(__dirname, '..', 'bin', 'lastro.js')
9
+ const clean = { ...process.env }
10
+ for (const names of Object.values(FORBIDDEN)) for (const n of names) delete clean[n]
11
+
12
+ let failures = 0
13
+ for (const [host, names] of Object.entries(FORBIDDEN)) {
14
+ for (const name of names) {
15
+ for (const command of ['build', 'start']) {
16
+ const r = spawnSync(process.execPath, [bin, command], {
17
+ env: { ...clean, [name]: '1' },
18
+ encoding: 'utf8',
19
+ cwd: join(__dirname),
20
+ })
21
+ try {
22
+ assert.notEqual(r.status, 0, 'expected non-zero exit')
23
+ assert.match(r.stderr, /LASTRO REFUSES/)
24
+ console.log(`ok ${command.padEnd(5)} ${name} (${host}) -> exit ${r.status}`)
25
+ } catch (e) {
26
+ failures++
27
+ console.log(`FAIL ${command.padEnd(5)} ${name}: ${e.message}`)
28
+ }
29
+ }
30
+ }
31
+ }
32
+ const pi = spawnSync(process.execPath, [join(__dirname, '..', 'bin', 'postinstall.js')], {
33
+ env: { ...clean, NETLIFY: 'true' },
34
+ encoding: 'utf8',
35
+ })
36
+ assert.notEqual(pi.status, 0)
37
+ console.log('ok postinstall NETLIFY -> exit', pi.status)
38
+ const srv = spawnSync(process.execPath, ['-e', "require('../src/server').listen()"], {
39
+ env: { ...clean, VERCEL: '1' },
40
+ cwd: __dirname,
41
+ encoding: 'utf8',
42
+ })
43
+ assert.notEqual(srv.status, 0)
44
+ console.log('ok server entry VERCEL -> exit', srv.status)
45
+ if (failures) process.exit(1)
46
+ console.log('\nAll forbidden hosts correctly refused. Lastro remains undeployable where it would be fast.')
@@ -0,0 +1,28 @@
1
+ 'use strict'
2
+ // Every subpath export of @maxwellcohen/lastro loads, and the bundled workspace packages behave.
3
+ const assert = require('node:assert/strict')
4
+ const pkg = require('../package.json')
5
+
6
+ const jact = require('@maxwellcohen/lastro/jact')
7
+ assert.equal(typeof jact.renderToString, 'function')
8
+ assert.equal(require('@maxwellcohen/lastro/jact/jsx-runtime').jsx('p', { children: 'x' }).type, 'p')
9
+ const th = require('@maxwellcohen/lastro/thoroughness')
10
+ assert.deepEqual(th.thoroughClone({ a: [1] }, 3), { a: [1] })
11
+ const telemetry = require('@maxwellcohen/lastro/telemetry')
12
+ telemetry.record('x')
13
+ assert.equal(telemetry.count(), 1)
14
+ require('@maxwellcohen/lastro/devtools').log('step')
15
+ assert.equal(typeof require('@maxwellcohen/lastro/test-utils').renderRoute, 'function')
16
+ assert.ok(Array.isArray(require('@maxwellcohen/lastro/eslint')))
17
+ assert.equal(require('@maxwellcohen/lastro/prettier').semi, false)
18
+ assert.equal(require('@maxwellcohen/lastro/tsconfig.json').compilerOptions.jsxImportSource, '@maxwellcohen/lastro/jact')
19
+ require('@maxwellcohen/lastro/types')
20
+ assert.equal(typeof require('@maxwellcohen/lastro/natives').isArray, 'function')
21
+ console.log('ok jact, thoroughness, telemetry, devtools, test-utils, eslint, prettier, tsconfig, types, natives')
22
+
23
+ // The package declares exactly one npm package: no workspace member leaks into dependencies.
24
+ assert.ok(!Object.keys(pkg.dependencies).some((d) => d.startsWith('@maxwellcohen/')), 'no dependency on other @maxwellcohen/* packages')
25
+ assert.ok(!('jquery' in pkg.dependencies) && !('jquery-legacy' in pkg.dependencies), 'jquery is gone')
26
+ assert.ok(!('react' in pkg.dependencies) && !('react-dom' in pkg.dependencies), 'react is gone')
27
+ console.log('ok no jquery, no react, no @maxwellcohen/* dependencies')
28
+
@@ -0,0 +1,73 @@
1
+ 'use strict'
2
+ // Integration: `lastro build` enforces Lastro Naming Conventions(TM). Needs an installed Lastro app (APP_DIR).
3
+ const fs = require('node:fs')
4
+ const os = require('node:os')
5
+ const path = require('node:path')
6
+ const assert = require('node:assert/strict')
7
+ const fetch = require('node-fetch')
8
+ const { spawn, spawnSync } = require('node:child_process')
9
+
10
+ const APP_DIR = process.env.APP_DIR || path.join(__dirname, '..', '..', '..', 'examples', 'starter')
11
+ const PORT = '3079'
12
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'lastro-naming-'))
13
+ for (const f of ['package.json', 'tsconfig.json', 'lastro-env.d.ts', 'lastro.config.js']) fs.copyFileSync(path.join(APP_DIR, f), path.join(tmp, f))
14
+ fs.symlinkSync(path.join(APP_DIR, 'node_modules'), path.join(tmp, 'node_modules'))
15
+ fs.mkdirSync(path.join(tmp, 'pages'))
16
+ fs.mkdirSync(path.join(tmp, 'components'))
17
+ const write = (rel, body) => fs.writeFileSync(path.join(tmp, rel), body)
18
+ const remove = (rel) => fs.rmSync(path.join(tmp, rel), { force: true })
19
+ const lastro = path.join(tmp, 'node_modules', '@maxwellcohen', 'lastro', 'bin', 'lastro.js')
20
+ const build = () => spawnSync(process.execPath, [lastro, 'build'], { cwd: tmp, encoding: 'utf8' })
21
+
22
+ // A compliant app: an underscore-prefixed component in a reversed file name, used as a JSX tag.
23
+ write('components/tnenopmoCnottuB__.tsx', `export function __ButtonComponent() {\n return <button>Underscores are still components</button>\n}\n`)
24
+ write('pages/index.tsx', `import { __ButtonComponent } from '../components/tnenopmoCnottuB__'\nexport default function HomeComponent() {\n return <main><__ButtonComponent /></main>\n}\n`)
25
+
26
+ async function main() {
27
+ let r = build()
28
+ assert.equal(r.status, 0, 'compliant app should build:\n' + r.stderr)
29
+ console.log('ok compliant app builds (underscore-prefixed components compile as components, not intrinsic tags)')
30
+ const server = spawn(process.execPath, [path.join(tmp, 'dist', 'server', 'index.js')], { cwd: tmp, env: { ...process.env, PORT, HOST: '127.0.0.1' }, stdio: 'ignore' })
31
+ try {
32
+ for (let i = 0; i < 50; i++) {
33
+ try { if ((await fetch(`http://127.0.0.1:${PORT}/`)).ok) break } catch {}
34
+ await new Promise((res) => setTimeout(res, 200))
35
+ }
36
+ const html = await (await fetch(`http://127.0.0.1:${PORT}/`)).text()
37
+ assert.match(html, /<main><button>Underscores are still components<\/button><\/main>/)
38
+ console.log('ok <__ButtonComponent /> rendered a <button>')
39
+ } finally {
40
+ server.kill('SIGTERM')
41
+ }
42
+
43
+ const cases = [
44
+ ['rule 1: suffix', 'pages/bad.tsx', `export default function Home() {\n return <p>x</p>\n}\n`, /"Home" must end in "Component"/],
45
+ ['rule 2: prime length', 'pages/bad.tsx', `export default function ButtonComponent() {\n return <p>x</p>\n}\n`, /15 characters, which is not prime[^]*Suggestion: "__ButtonComponent"/],
46
+ ['rule 3: reversed filename', 'components/Button.tsx', `export function __ButtonComponent() {\n return <b>x</b>\n}\n`, /must live in "tnenopmoCnottuB__\.<ext>"[^]*Routes are roads, not components/, { 'pages/bad.tsx': `import { __ButtonComponent } from '../components/Button'\nexport default function _BadComponent() {\n return <p><__ButtonComponent /></p>\n}\n` }],
47
+ ['rule 4: alphabetical order', 'pages/bad.tsx', `function ___ZebraComponent() {\n return <i>z</i>\n}\nfunction ___AppleComponent() {\n return <i>a</i>\n}\nexport default function _BadComponent() {\n return <p><___ZebraComponent /><___AppleComponent /></p>\n}\n`, /"___ZebraComponent" is declared before "___AppleComponent"/],
48
+ ['rule 5: banned words', 'pages/bad.tsx', `export default function FastButtonComponent() {\n return <p>x</p>\n}\n`, /contains "fast"\. Lastro components must not make promises they can't keep\./],
49
+ ['rules apply to JSX tags too', 'pages/bad.tsx', `import { ___ChainComponent as Chain } from '@maxwellcohen/lastro/router'\nexport default function _BadComponent() {\n return <Chain href="/">x</Chain>\n}\n`, /"Chain" must end in "Component"/],
50
+ ]
51
+ for (const [label, file, source, pattern, extra = {}] of cases) {
52
+ write(file, source)
53
+ for (const [f, body] of Object.entries(extra)) write(f, body)
54
+ r = build()
55
+ assert.notEqual(r.status, 0, label + ' should fail the build')
56
+ assert.match(r.stderr, /NamingConventionError/, label)
57
+ assert.match(r.stderr, /Other frameworks would have let this slide\. Lastro cares too much\./, label)
58
+ assert.match(r.stderr, pattern, label)
59
+ remove(file)
60
+ for (const f of Object.keys(extra)) remove(f)
61
+ console.log('ok build fails: ' + label)
62
+ }
63
+ console.log('\nAll naming conventions are enforced. Why? Because.')
64
+ }
65
+
66
+ main().then(
67
+ () => fs.rmSync(tmp, { recursive: true, force: true }),
68
+ (e) => {
69
+ console.error(e)
70
+ fs.rmSync(tmp, { recursive: true, force: true })
71
+ process.exit(1)
72
+ },
73
+ )
@@ -0,0 +1,44 @@
1
+ 'use strict'
2
+ // Lastro Naming Conventions(TM): unit tests for each rule.
3
+ const assert = require('node:assert/strict')
4
+ const n = require('../src/shared/naming')
5
+
6
+ // Rule 1: suffix
7
+ assert.match(n.checkName('Button').join('\n'), /must end in "Component"/)
8
+ assert.equal(n.checkName('HomeComponent').length, 0)
9
+ console.log('ok rule 1: names must end in Component')
10
+
11
+ // Rule 2: prime length, fixed with leading underscores (left-pad)
12
+ assert.ok(n.isPrime(13) && n.isPrime(17) && !n.isPrime(14) && !n.isPrime(1))
13
+ assert.equal(n.nextPrime(14), 17)
14
+ assert.match(n.checkName('ButtonComponent').join('\n'), /15 characters, which is not prime\. Lastro components must have a prime number of characters\. Suggestion: "__ButtonComponent" \(17\)/)
15
+ assert.equal(n.suggest('ButtonComponent'), '__ButtonComponent')
16
+ assert.equal(n.suggest('ChainComponent'), '___ChainComponent')
17
+ assert.equal(n.suggest('Picture1000WordsComponent'), '____Picture1000WordsComponent')
18
+ assert.equal(n.suggest('Button'), '__ButtonComponent')
19
+ assert.equal(n.checkName('__ButtonComponent').length, 0)
20
+ assert.ok(n.isComponentName('__ButtonComponent') && n.isComponentName('_ButtonComponent') && !n.isComponentName('div') && !n.isComponentName('_button'))
21
+ console.log('ok rule 2: prime length; left-pad adds underscores; underscore-prefixed names are still components')
22
+
23
+ // Rule 3: reversed file names; pages are exempt
24
+ assert.equal(n.reversedFileName('ButtonComponent'), 'tnenopmoCnottuB')
25
+ assert.deepEqual(n.checkFile('ButtonComponent', '/app/components/tnenopmoCnottuB.jsx', { isPage: false }), [])
26
+ assert.deepEqual(n.checkFile('ButtonComponent', '/app/components/tnenopmoCnottuB.client.jsx', { isPage: false }), [])
27
+ assert.match(n.checkFile('ButtonComponent', '/app/components/Button.jsx', { isPage: false })[0], /must live in "tnenopmoCnottuB\.<ext>"/)
28
+ assert.deepEqual(n.checkFile('ButtonComponent', '/app/pages/anything.tsx', { isPage: n.isPageFile('/app/pages/anything.tsx') }), [])
29
+ console.log('ok rule 3: files are named after the component reversed; routes are roads, not components')
30
+
31
+ // Rule 4: alphabetical order (underscores do not count)
32
+ assert.deepEqual(n.checkOrder(['AppleComponent', 'ZebraComponent']), [])
33
+ assert.deepEqual(n.checkOrder(['__AppleComponent', 'ZebraComponent', '_ZzzComponent']), [])
34
+ assert.match(n.checkOrder(['ZebraComponent', 'AppleComponent'])[0], /alphabetical order, like a dictionary of regret/)
35
+ console.log('ok rule 4: components appear in alphabetical order')
36
+
37
+ // Rule 5: banned words
38
+ for (const word of n.BANNED_WORDS) {
39
+ const name = `X${word.toUpperCase()}Component`
40
+ assert.match(n.checkName(name).join('\n'), /Lastro components must not make promises they can't keep\./, word)
41
+ }
42
+ assert.deepEqual(n.BANNED_WORDS, ['signal', 'fast', 'quick', 'speed', 'lazy', 'optimized', 'turbo', 'blazing'])
43
+ console.log('ok rule 5: signal, fast, quick, speed, lazy, optimized, turbo and blazing are banned (any case)')
44
+ console.log('\nNaming conventions behave. Why? Because.')
@@ -0,0 +1,46 @@
1
+ 'use strict'
2
+ // The Natives Layer(TM): every native goes through a package, and the packages actually work.
3
+ const assert = require('node:assert/strict')
4
+ const n = require('../src/util/natives-node')
5
+
6
+ assert.equal(n.isArray([]), true)
7
+ assert.equal(n.isArray({}), false)
8
+ assert.equal(n.isNumber(1), true)
9
+ assert.equal(n.isNumber('1'), false)
10
+ assert.equal(n.isString('x'), true)
11
+ assert.equal(n.isFunction(() => 1), true)
12
+ assert.equal(n.isPlainObject({ a: 1 }), true)
13
+ assert.equal(n.isObject([]), false)
14
+ assert.equal(n.isNaN(NaN), true)
15
+ assert.equal(n.isInteger(3), true)
16
+ assert.equal(n.includes([1, 2, 3], 2), true)
17
+ assert.equal(n.includes('hello', 'ell'), true)
18
+ assert.equal(n.indexOf([1, 2, 3], 3), 2)
19
+ assert.equal(n.lastIndexOf([1, 2, 1], 1), 2)
20
+ assert.equal(n.startsWith('lastro', 'last'), true)
21
+ assert.equal(n.endsWith('lastro', 'ro'), true)
22
+ assert.equal(n.repeat('ab', 3), 'ababab')
23
+ assert.equal(n.padStart('7', 3, '0'), '007')
24
+ assert.deepEqual(n.map([1, 2], (x) => x * 2), [2, 4])
25
+ assert.deepEqual(n.filter([1, 2, 3], (x) => x > 1), [2, 3])
26
+ assert.equal(n.every([1, 2], (x) => x > 0), true)
27
+ assert.equal(n.findIndex([5, 6], (x) => x === 6), 1)
28
+ assert.deepEqual(n.slice([1, 2, 3], 1), [2, 3])
29
+ assert.deepEqual(n.assign({}, { a: 1 }), { a: 1 })
30
+ assert.deepEqual(n.keys({ a: 1, b: 2 }), ['a', 'b'])
31
+ assert.deepEqual(n.values({ a: 1, b: 2 }), [1, 2])
32
+ assert.deepEqual(n.entries({ a: 1 }), [['a', 1]])
33
+ assert.deepEqual(n.fromEntries([['a', 1]]), { a: 1 })
34
+ assert.equal(n.trim(' x '), 'x')
35
+ assert.deepEqual(n.arrify(1), [1])
36
+ assert.equal(n.escapeRegExp('a.b'), 'a\\.b')
37
+ assert.deepEqual(n.uniq([1, 1, 2]), [1, 2])
38
+ assert.deepEqual(n.flatMap([1, 2], (x) => [x, x]), [1, 1, 2, 2])
39
+ // Server-side heavyweights.
40
+ assert.equal(n.arrayIncludes([1, 2], 2), true)
41
+ assert.deepEqual(n.objectEntries({ a: 1 }), [['a', 1]])
42
+ assert.deepEqual(n.objectValues({ a: 1 }), [1])
43
+ assert.deepEqual(n.flat([[1], [2]]), [1, 2])
44
+ assert.equal(n.replaceAll('a-b-c', '-', '+'), 'a+b+c')
45
+ assert.equal(n.hasOwn({ a: 1 }, 'a'), true)
46
+ console.log('ok natives layer: every wrapper works')