Skip to content

Commit 4695d0b

Browse files
authored
Support TypeScript 4.9 (satisfies) (#151)
1 parent 8eb5e9f commit 4695d0b

File tree

5 files changed

+233
-128
lines changed

5 files changed

+233
-128
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"bob-the-bundler": patch
3+
---
4+
dependencies updates:
5+
- Updated dependency [`tsup@^6.5.0` ↗︎](https://www.npmjs.com/package/tsup/v/6.5.0) (from `^5.11.6`, in `dependencies`)

.changeset/flat-fireants-marry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"bob-the-bundler": patch
3+
---
4+
5+
Support TypeScript 4.9 and satisfies operator

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"rollup-plugin-generate-package-json": "^3.2.0",
4242
"rollup-plugin-typescript2": "^0.33.0",
4343
"tslib": "^2.0.0",
44-
"tsup": "^5.11.6",
44+
"tsup": "^6.5.0",
4545
"yargs": "^17.5.1",
4646
"zod": "^3.17.3"
4747
},

src/commands/runify.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ async function runify(packagePath: string, reporter: Consola) {
117117
}
118118

119119
if (isNext(pkg)) {
120-
await buildNext(cwd);
120+
const additionalRequire = pkg?.buildOptions?.runify?.next?.header ?? null;
121+
await buildNext(cwd, additionalRequire);
121122
await rewritePackageJson(pkg, cwd, (newPkg) => ({
122123
...newPkg,
123124
dependencies: pkg.dependencies,
125+
type: "commonjs",
124126
}));
125127
} else {
126128
await compile(
@@ -195,7 +197,7 @@ function isNext(pkg: any): boolean {
195197
return pkg?.dependencies?.next || pkg?.devDependencies?.next;
196198
}
197199

198-
async function buildNext(cwd: string) {
200+
async function buildNext(cwd: string, additionalRequire: string | null) {
199201
await new Promise((resolve, reject) => {
200202
const child = spawn("next", ["build"], {
201203
stdio: "inherit",
@@ -206,6 +208,17 @@ async function buildNext(cwd: string) {
206208
});
207209

208210
await fs.mkdirp(join(cwd, "dist"));
211+
if (additionalRequire) {
212+
await tsup({
213+
entryPoints: [join(cwd, additionalRequire)],
214+
outDir: join(cwd, "dist"),
215+
target: "node16",
216+
format: ["cjs"],
217+
splitting: false,
218+
skipNodeModulesBundle: true,
219+
});
220+
}
221+
209222
await Promise.all([
210223
fs.copy(join(cwd, ".next"), join(cwd, "dist/.next"), {
211224
filter(src) {
@@ -220,11 +233,15 @@ async function buildNext(cwd: string) {
220233
`#!/usr/bin/env node`,
221234
`process.on('SIGTERM', () => process.exit(0))`,
222235
`process.on('SIGINT', () => process.exit(0))`,
236+
additionalRequire
237+
? `require('${additionalRequire.replace(".ts", "")}')`
238+
: ``,
223239
`
224240
require('next/dist/server/lib/start-server').startServer({
225241
dir: __dirname,
226242
hostname: '0.0.0.0',
227-
port: parseInt(process.env.PORT)
243+
port: parseInt(process.env.PORT),
244+
conf: {},
228245
}).then(async (app)=>{
229246
const appUrl = 'http://' + app.hostname + ':' + app.port;
230247
console.log('started server on '+ app.hostname + ':' + app.port + ', url: ' + appUrl);
@@ -257,6 +274,7 @@ async function compile(
257274
splitting: false,
258275
sourcemap: true,
259276
clean: true,
277+
shims: true,
260278
skipNodeModulesBundle: false,
261279
noExternal: dependencies,
262280
external: buildOptions.external,

0 commit comments

Comments
 (0)