@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.
- package/LICENSE +21 -0
- package/README.md +210 -2
- package/bin/lastro.js +5 -0
- package/bin/postinstall.js +6 -0
- package/docs/hero.png +0 -0
- package/package.json +355 -4
- package/pkg/devtools/index.js +15 -0
- package/pkg/eslint-config/index.js +123 -0
- package/pkg/head/client.js +18 -0
- package/pkg/head/index.d.ts +4 -0
- package/pkg/head/index.js +30 -0
- package/pkg/image/client.js +2 -0
- package/pkg/image/index.d.ts +3 -0
- package/pkg/image/index.js +2 -0
- package/pkg/image/stubs.js +8 -0
- package/pkg/image/tnenopmoCsdroW0001erutciP____.client.js +18 -0
- package/pkg/image/tnenopmoCsdroW0001erutciP____.js +27 -0
- package/pkg/jact/client.js +108 -0
- package/pkg/jact/core.js +292 -0
- package/pkg/jact/index.d.ts +48 -0
- package/pkg/jact/jsx-runtime.d.ts +18 -0
- package/pkg/jact/jsx-runtime.js +3 -0
- package/pkg/jact/names.js +49 -0
- package/pkg/jact/server.js +66 -0
- package/pkg/jqueasy/index.d.ts +2 -0
- package/pkg/jqueasy/index.js +442 -0
- package/pkg/polyfills/es.js +1 -0
- package/pkg/polyfills/full.js +1 -0
- package/pkg/polyfills/legacy.js +3 -0
- package/pkg/polyfills/regenerator.js +1 -0
- package/pkg/polyfills/web.js +1 -0
- package/pkg/prettier-config/index.json +1 -0
- package/pkg/router/client.js +5 -0
- package/pkg/router/index.d.ts +6 -0
- package/pkg/router/index.js +7 -0
- package/pkg/router/stubs.js +12 -0
- package/pkg/router/tnenopmoCniahC___.client.js +50 -0
- package/pkg/router/tnenopmoCniahC___.js +10 -0
- package/pkg/serializer/client.js +24 -0
- package/pkg/serializer/index.js +41 -0
- package/pkg/starter/README.md +70 -0
- package/pkg/starter/lastro-env.d.ts +1 -0
- package/pkg/starter/lastro.config.js +9 -0
- package/pkg/starter/package.json +47 -0
- package/pkg/starter/pages/about.tsx +11 -0
- package/pkg/starter/pages/index.tsx +29 -0
- package/pkg/starter/pages/posts/[id].server.ts +1 -0
- package/pkg/starter/pages/posts/[id].tsx +4 -0
- package/pkg/starter/pages/posts.server.ts +1 -0
- package/pkg/starter/pages/posts.tsx +16 -0
- package/pkg/starter/tsconfig.json +5 -0
- package/pkg/telemetry/client.js +11 -0
- package/pkg/telemetry/index.js +5 -0
- package/pkg/test-utils/index.js +15 -0
- package/pkg/thoroughness/client.js +32 -0
- package/pkg/thoroughness/index.js +12 -0
- package/pkg/tsconfig/tsconfig.json +23 -0
- package/pkg/types/index.d.ts +2 -0
- package/pkg/types/index.js +2 -0
- package/scripts/assemble.cjs +37 -0
- package/src/build/assets.js +127 -0
- package/src/build/bans-plugin.js +58 -0
- package/src/build/graph.js +157 -0
- package/src/build/index.js +213 -0
- package/src/build/naming-plugin.js +62 -0
- package/src/build/routes.js +33 -0
- package/src/build/typecheck.js +16 -0
- package/src/cli.js +101 -0
- package/src/client/boot.js +38 -0
- package/src/client/clone.js +10 -0
- package/src/client/compare.js +7 -0
- package/src/client/config.js +3 -0
- package/src/client/copies.js +12 -0
- package/src/client/env.js +13 -0
- package/src/client/errors.js +11 -0
- package/src/client/features.js +101 -0
- package/src/client/heartbeat.js +38 -0
- package/src/client/idle.js +7 -0
- package/src/client/logger.js +12 -0
- package/src/client/mount.js +11 -0
- package/src/client/ready.js +7 -0
- package/src/client/state.js +14 -0
- package/src/client/vitals.js +16 -0
- package/src/client-runtime/registry.js +46 -0
- package/src/create.js +46 -0
- package/src/dev.js +36 -0
- package/src/guard.js +56 -0
- package/src/index.js +8 -0
- package/src/postinstall.js +27 -0
- package/src/preview.js +66 -0
- package/src/server/app.js +201 -0
- package/src/server/index.js +34 -0
- package/src/server/template.csr.html +48 -0
- package/src/server/template.html +12 -0
- package/src/shared/app-require.js +18 -0
- package/src/shared/audit.js +34 -0
- package/src/shared/bans.js +102 -0
- package/src/shared/config.js +40 -0
- package/src/shared/naming.js +82 -0
- package/src/shared/signal.js +36 -0
- package/src/util/natives-node.js +20 -0
- package/src/util/natives.js +67 -0
- package/test/bans.integration.js +97 -0
- package/test/bans.test.js +110 -0
- package/test/cjs-only.test.js +37 -0
- package/test/csr.test.js +61 -0
- package/test/guard.test.js +46 -0
- package/test/members.test.js +28 -0
- package/test/naming.integration.js +73 -0
- package/test/naming.test.js +44 -0
- package/test/natives.test.js +46 -0
- package/test/server.test.js +18 -0
- package/test/signal.integration.js +105 -0
- package/test/signal.test.js +33 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// Server hardening: malformed percent-encoding is a 400, not a crash; traversal stays inside dist/client.
|
|
3
|
+
const assert = require('node:assert/strict')
|
|
4
|
+
const path = require('node:path')
|
|
5
|
+
const { createApp } = require('../src/server/app')
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
const app = createApp({ distDir: path.join(__dirname, '..', '..', '..', 'examples', 'starter', 'dist') })
|
|
9
|
+
const bad = await app.fetch(new Request('http://localhost/%E0%A4%A'))
|
|
10
|
+
assert.equal(bad.status, 400)
|
|
11
|
+
const escape = await app.fetch(new Request('http://localhost/_lastro/..%2f..%2f..%2fpackage.json'))
|
|
12
|
+
assert.equal(escape.status, 404)
|
|
13
|
+
console.log('ok server: malformed % gives 400, path traversal gives 404')
|
|
14
|
+
}
|
|
15
|
+
main().catch((e) => {
|
|
16
|
+
console.error(e)
|
|
17
|
+
process.exit(1)
|
|
18
|
+
})
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// Integration: proves the build, the server and the browser each fail on the word "signal".
|
|
3
|
+
// Needs an installed Lastro app. APP_DIR defaults to the tracker's starter-lastro. Needs Chrome for the browser check.
|
|
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
|
+
const { createRequire } = require('node:module')
|
|
11
|
+
|
|
12
|
+
const APP_DIR = process.env.APP_DIR || path.join(__dirname, '..', '..', '..', 'examples', 'starter')
|
|
13
|
+
// puppeteer-core is resolved from PUPPETEER_FROM (a package.json path) or from this workspace's own node_modules.
|
|
14
|
+
const STRICT = Boolean(process.env.CI || process.env.LASTRO_STRICT)
|
|
15
|
+
function loadPuppeteer() {
|
|
16
|
+
try {
|
|
17
|
+
if (process.env.PUPPETEER_FROM) return createRequire(process.env.PUPPETEER_FROM)('puppeteer-core')
|
|
18
|
+
return require('puppeteer-core')
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const CHROME = process.env.CHROME_PATH || '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
|
|
24
|
+
const PORT = '3077'
|
|
25
|
+
const word = 'sig' + 'nal' // the test itself must not contain the word either
|
|
26
|
+
|
|
27
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'lastro-signal-'))
|
|
28
|
+
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))
|
|
29
|
+
fs.symlinkSync(path.join(APP_DIR, 'node_modules'), path.join(tmp, 'node_modules'))
|
|
30
|
+
fs.mkdirSync(path.join(tmp, 'pages'))
|
|
31
|
+
const page = (name, body) => fs.writeFileSync(path.join(tmp, 'pages', name), body)
|
|
32
|
+
page('index.tsx', 'export default function HomeComponent() { return <h1>All good</h1> }\n')
|
|
33
|
+
page('server-bad.tsx', `export default function _BadComponent() { return <p>{'sig' + 'nal'}</p> }\n`)
|
|
34
|
+
page(
|
|
35
|
+
'browser-bad.tsx',
|
|
36
|
+
`import { useCountry, useCause } from '@maxwellcohen/lastro/jact'
|
|
37
|
+
export default function _BadComponent() {
|
|
38
|
+
const [v, setV] = useCountry('fine')
|
|
39
|
+
useCause(() => { setV('sig' + 'nal') }, [])
|
|
40
|
+
return <table><tbody><tr><td>{v}</td></tr></tbody></table>
|
|
41
|
+
}
|
|
42
|
+
`,
|
|
43
|
+
)
|
|
44
|
+
const lastro = path.join(tmp, 'node_modules', '@maxwellcohen', 'lastro', 'bin', 'lastro.js')
|
|
45
|
+
const run = (args, env = {}) => spawnSync(process.execPath, [lastro, ...args], { cwd: tmp, encoding: 'utf8', env: { ...process.env, ...env } })
|
|
46
|
+
|
|
47
|
+
async function main() {
|
|
48
|
+
// 1. Build succeeds when no page contains the word.
|
|
49
|
+
let r = run(['build'])
|
|
50
|
+
assert.equal(r.status, 0, 'baseline build should pass:\n' + r.stderr + r.stdout)
|
|
51
|
+
console.log('ok build passes without the word')
|
|
52
|
+
|
|
53
|
+
// 2. Server: renderToString throws, the server answers 500.
|
|
54
|
+
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' })
|
|
55
|
+
try {
|
|
56
|
+
for (let i = 0; i < 50; i++) {
|
|
57
|
+
try { if ((await fetch(`http://127.0.0.1:${PORT}/`)).ok) break } catch {}
|
|
58
|
+
await new Promise((res) => setTimeout(res, 200))
|
|
59
|
+
}
|
|
60
|
+
const bad = await fetch(`http://127.0.0.1:${PORT}/server-bad`)
|
|
61
|
+
const text = await bad.text()
|
|
62
|
+
assert.equal(bad.status, 500)
|
|
63
|
+
assert.match(text, /Signals detected\. Signals tend to be faster/)
|
|
64
|
+
console.log('ok server answers 500 SignalDetectedError for a page that renders the word')
|
|
65
|
+
|
|
66
|
+
// 3. Browser: the jQuery renderer replaces the document with the error.
|
|
67
|
+
const puppeteer = loadPuppeteer()
|
|
68
|
+
if (!fs.existsSync(CHROME) || !puppeteer) {
|
|
69
|
+
if (STRICT) throw new Error('browser check cannot skip under CI/LASTRO_STRICT: Chrome or puppeteer-core not found (set CHROME_PATH and PUPPETEER_FROM)')
|
|
70
|
+
console.log('skip browser check: Chrome or puppeteer-core not found (set CHROME_PATH and PUPPETEER_FROM)')
|
|
71
|
+
} else {
|
|
72
|
+
const browser = await puppeteer.launch({ executablePath: CHROME, headless: true, args: ['--no-sandbox'] })
|
|
73
|
+
try {
|
|
74
|
+
const tab = await browser.newPage()
|
|
75
|
+
await tab.goto(`http://127.0.0.1:${PORT}/browser-bad`, { waitUntil: 'load' })
|
|
76
|
+
await tab.waitForFunction(() => document.body.textContent.includes('Signals tend to be faster'), { timeout: 15000 })
|
|
77
|
+
const state = await tab.evaluate(() => ({ h1: document.querySelector('h1')?.textContent, hasApp: !!document.getElementById('__lastro') }))
|
|
78
|
+
assert.equal(state.h1, 'SignalDetectedError')
|
|
79
|
+
assert.equal(state.hasApp, false)
|
|
80
|
+
console.log('ok browser replaces the whole body with SignalDetectedError when state contains the word')
|
|
81
|
+
} finally {
|
|
82
|
+
await browser.close()
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} finally {
|
|
86
|
+
server.kill('SIGTERM')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 4. Build: a page whose source contains the word fails the build.
|
|
90
|
+
page('source-bad.tsx', `// createSignal() is not welcome here\nexport default function _SComponent() { return <p>hi</p> }\n`)
|
|
91
|
+
r = run(['build'])
|
|
92
|
+
assert.notEqual(r.status, 0)
|
|
93
|
+
assert.match(r.stderr, /SignalDetectedError/)
|
|
94
|
+
console.log('ok build fails when a page source contains the word, exit', r.status)
|
|
95
|
+
console.log('\nAll signal checks (server, browser, build) behave. Lastro remains safely slow.')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
main().then(
|
|
99
|
+
() => fs.rmSync(tmp, { recursive: true, force: true }),
|
|
100
|
+
(e) => {
|
|
101
|
+
console.error(e)
|
|
102
|
+
fs.rmSync(tmp, { recursive: true, force: true })
|
|
103
|
+
process.exit(1)
|
|
104
|
+
},
|
|
105
|
+
)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// Unit checks for the signal ban: server renderer, source check, exemptions.
|
|
3
|
+
const assert = require('node:assert/strict')
|
|
4
|
+
const { join } = require('node:path')
|
|
5
|
+
const jact = require(join(__dirname, '..', '..', 'jact', 'src', 'server.js'))
|
|
6
|
+
const { assertSourceHasNoSignal, SignalDetectedError } = require('../src/shared/signal')
|
|
7
|
+
const h = jact.createElement
|
|
8
|
+
|
|
9
|
+
function throwsSignal(fn, label) {
|
|
10
|
+
assert.throws(fn, (e) => e.name === 'SignalDetectedError' && /Signals detected\. Signals tend to be faster, and Lastro cannot risk that\. Solid, Svelte, Preact, Angular and Vue use them beautifully\./.test(e.message), label)
|
|
11
|
+
console.log('ok ' + label)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Server renderer: text, attribute values, props, state, case-insensitive.
|
|
15
|
+
throwsSignal(() => jact.renderToString(h('p', null, 'This page uses a Signal')), 'text')
|
|
16
|
+
throwsSignal(() => jact.renderToString(h('p', { title: 'SIGNAL' }, 'x')), 'attribute value')
|
|
17
|
+
throwsSignal(() => jact.renderToString(h(function C(props) { return h('p', null, 'x') }, { data: { a: ['sIgNaL'] } })), 'prop value')
|
|
18
|
+
throwsSignal(() => jact.renderToString(h(function S() { const [v] = jact.useCountry('signals'); return h('p', null, 'x') }, null)), 'state value')
|
|
19
|
+
assert.throws(() => jact.useState(1), /Lastro does not recognize states\. Please use useCountry\(\)\./)
|
|
20
|
+
console.log('ok useState stub throws')
|
|
21
|
+
assert.throws(() => jact.renderToString(h('p', null, 'signal')), /Have you considered useCountry\? It re-renders everything\./)
|
|
22
|
+
console.log('ok error message mentions useCountry')
|
|
23
|
+
// Exemptions.
|
|
24
|
+
assert.equal(jact.renderToString(h('p', null, 'AbortSignal and SIGINT and SIGTERM are fine')), '<p>AbortSignal and SIGINT and SIGTERM are fine</p>')
|
|
25
|
+
console.log('ok AbortSignal / SIGINT / SIGTERM exempt')
|
|
26
|
+
|
|
27
|
+
// Source check (what the build runs on every user page and component).
|
|
28
|
+
assert.throws(() => assertSourceHasNoSignal('/app/pages/index.tsx', '// createSignal()'), SignalDetectedError)
|
|
29
|
+
console.log('ok user source containing "signal" is rejected')
|
|
30
|
+
assertSourceHasNoSignal('/app/node_modules/@maxwellcohen/lastro/src/x.js', 'const signal = new AbortController().signal')
|
|
31
|
+
assertSourceHasNoSignal('/app/pages/index.tsx', 'const s = new AbortController(); fetch(u, { signal: AbortSignal.timeout(1) })'.replace('signal: ', 'x: '))
|
|
32
|
+
console.log('ok Lastro internals and AbortSignal are exempt')
|
|
33
|
+
console.log('\nSignal unit checks passed. (Run signal.integration.js for the browser and build checks.)')
|