react-nitro-bundler 0.0.0-stage → 0.0.1-alpha.7
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/package.json +25 -4
- package/src/bundle.ts +29 -0
- package/src/dev.ts +19 -0
- package/src/release.ts +38 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Margelo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
9
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
10
|
+
so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-nitro-bundler",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1-alpha.7",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"react-nitro-hermes": "0.0.1-alpha.7",
|
|
6
|
+
"rolldown": "1.2.9"
|
|
7
|
+
},
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"tag": "latest",
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/margelo/react-nitro.git",
|
|
17
|
+
"directory": "packages/bundler"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
"./package.json": "./package.json",
|
|
21
|
+
".": "./src/bundle.ts",
|
|
22
|
+
"./release": "./src/release.ts"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"src"
|
|
26
|
+
]
|
|
27
|
+
}
|
package/src/bundle.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { build } from 'rolldown'
|
|
2
|
+
|
|
3
|
+
export type BundleMode = 'development' | 'production'
|
|
4
|
+
|
|
5
|
+
export function bundle(entry: string, file?: string, mode: BundleMode = 'development') {
|
|
6
|
+
return build({
|
|
7
|
+
input: entry,
|
|
8
|
+
platform: 'neutral',
|
|
9
|
+
resolve: {
|
|
10
|
+
mainFields: ['module', 'main'],
|
|
11
|
+
},
|
|
12
|
+
transform: {
|
|
13
|
+
// Selects React's development or production build.
|
|
14
|
+
define: {
|
|
15
|
+
'process.env.NODE_ENV': JSON.stringify(mode),
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
onLog(level, log, handler) {
|
|
19
|
+
// Rolldown would otherwise turn it into a missing global at runtime.
|
|
20
|
+
handler(log.code === 'UNRESOLVED_IMPORT' ? 'error' : level, log)
|
|
21
|
+
},
|
|
22
|
+
write: Boolean(file),
|
|
23
|
+
output: {
|
|
24
|
+
file,
|
|
25
|
+
format: 'iife',
|
|
26
|
+
name: 'NitroExample',
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
}
|
package/src/dev.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { serve } from 'bun'
|
|
2
|
+
import { bundle } from './bundle'
|
|
3
|
+
|
|
4
|
+
const entry = process.argv[2]
|
|
5
|
+
if (entry === undefined) throw new Error('Usage: bun dev.ts <entry>')
|
|
6
|
+
|
|
7
|
+
serve({
|
|
8
|
+
port: 8081,
|
|
9
|
+
async fetch() {
|
|
10
|
+
const { output } = await bundle(entry)
|
|
11
|
+
|
|
12
|
+
return new Response(output[0].code, {
|
|
13
|
+
headers: {
|
|
14
|
+
'Content-Type': 'application/javascript',
|
|
15
|
+
'Cache-Control': 'no-store',
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
},
|
|
19
|
+
})
|
package/src/release.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { mkdir, mkdtemp, rename, rm } from 'node:fs/promises'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
4
|
+
import { spawn } from 'bun'
|
|
5
|
+
import { hermescPath } from 'react-nitro-hermes'
|
|
6
|
+
import { bundle } from './bundle'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Bundles production JavaScript and compiles it to Hermes bytecode with the
|
|
10
|
+
* compiler built from the pinned Hermes sources. `file` is only replaced
|
|
11
|
+
* once compilation succeeds.
|
|
12
|
+
*/
|
|
13
|
+
export async function bundleRelease(entry: string, file: string) {
|
|
14
|
+
if (!existsSync(hermescPath)) {
|
|
15
|
+
throw new Error(`${hermescPath} does not exist. Reinstall react-nitro-hermes to restore the matching compiler`)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
await mkdir(dirname(file), { recursive: true })
|
|
19
|
+
// A sibling directory keeps the final rename on the same file system.
|
|
20
|
+
const directory = await mkdtemp(join(dirname(file), '.bundle-'))
|
|
21
|
+
try {
|
|
22
|
+
const source = join(directory, 'main.js')
|
|
23
|
+
const bytecode = join(directory, 'main.hbc')
|
|
24
|
+
await bundle(entry, source, 'production')
|
|
25
|
+
|
|
26
|
+
// Match the language features JSRuntime enables for source.
|
|
27
|
+
const hermesc = spawn(
|
|
28
|
+
[hermescPath, '-O', '-g0', '-emit-binary', '-Xes6-block-scoping', '-Xasync-generators', '-out', bytecode, source],
|
|
29
|
+
{ stdout: 'inherit', stderr: 'inherit' },
|
|
30
|
+
)
|
|
31
|
+
const code = await hermesc.exited
|
|
32
|
+
if (code !== 0) throw new Error(`hermesc exited with status ${code}`)
|
|
33
|
+
|
|
34
|
+
await rename(bytecode, file)
|
|
35
|
+
} finally {
|
|
36
|
+
await rm(directory, { recursive: true, force: true })
|
|
37
|
+
}
|
|
38
|
+
}
|
package/README.md
DELETED