Last active
September 6, 2024 16:48
-
-
Save vladkosinov/4ee700e9a3e9fa282dcc55c80a4d753d to your computer and use it in GitHub Desktop.
tsup + sea + .node addon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node --experimental-sea-config sea-config.json | |
cp $(command -v node) ./run-gateway-pr-check | |
npx --yes postject run-gateway-pr-check NODE_SEA_BLOB run-gateway-pr-check.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 copy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"main": "./dist/run-gateway-pr-check.js", | |
"output": "run-gateway-pr-check.blob", | |
"disableExperimentalSEAWarning": true, | |
"assets": { | |
"swc.node": "./dist/swc.node" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createRequire } = require('module'); | |
const seaRequire = createRequire(__filename); | |
module.exports = seaRequire('./dist/swc.node'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { defineConfig } from 'tsup'; | |
import path from 'path'; | |
import { cp } from 'fs/promises'; | |
import { createRequire } from 'node:module'; | |
const require = createRequire(import.meta.url); | |
export default defineConfig({ | |
entry: ['../run-gateway-pr-check.ts'], | |
format: ['cjs'], | |
dts: false, | |
splitting: false, | |
sourcemap: false, | |
clean: true, | |
platform: 'node', | |
define: { | |
'process.env.NODE_ENV': JSON.stringify('production'), | |
}, | |
esbuildOptions: (options) => { | |
options.alias = { | |
...options.alias, | |
'@swc/core-linux-x64-gnu': path.resolve(__dirname, 'swc-loader.js'), | |
}; | |
}, | |
noExternal: ['*'], | |
external: [ | |
'pnpapi', | |
// all native swc modules should be externalized | |
// because tsup cant bundle them into a JS file :) | |
// but we will still need to copy them into the dist folder | |
// because project graph needs them to be present in the package | |
...['@swc/wasm', /swc.*\.node/, '@swc/core-linux-x64-musl'], | |
], | |
async onSuccess() { | |
const nativeDependencyPath = require.resolve('@swc/core-linux-x64-gnu'); | |
await cp(nativeDependencyPath, 'dist/swc.node'); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment