Skip to content

Commit

Permalink
Support TypeScript 4.9 (satisfies) (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed Dec 19, 2022
1 parent 8eb5e9f commit 4695d0b
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 128 deletions.
5 changes: 5 additions & 0 deletions .changeset/bob-the-bundler-151-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bob-the-bundler": patch
---
dependencies updates:
- Updated dependency [`tsup@^6.5.0` ↗︎](https://www.npmjs.com/package/tsup/v/6.5.0) (from `^5.11.6`, in `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/flat-fireants-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bob-the-bundler": patch
---

Support TypeScript 4.9 and satisfies operator
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"rollup-plugin-generate-package-json": "^3.2.0",
"rollup-plugin-typescript2": "^0.33.0",
"tslib": "^2.0.0",
"tsup": "^5.11.6",
"tsup": "^6.5.0",
"yargs": "^17.5.1",
"zod": "^3.17.3"
},
Expand Down
24 changes: 21 additions & 3 deletions src/commands/runify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ async function runify(packagePath: string, reporter: Consola) {
}

if (isNext(pkg)) {
await buildNext(cwd);
const additionalRequire = pkg?.buildOptions?.runify?.next?.header ?? null;
await buildNext(cwd, additionalRequire);
await rewritePackageJson(pkg, cwd, (newPkg) => ({
...newPkg,
dependencies: pkg.dependencies,
type: "commonjs",
}));
} else {
await compile(
Expand Down Expand Up @@ -195,7 +197,7 @@ function isNext(pkg: any): boolean {
return pkg?.dependencies?.next || pkg?.devDependencies?.next;
}

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

await fs.mkdirp(join(cwd, "dist"));
if (additionalRequire) {
await tsup({
entryPoints: [join(cwd, additionalRequire)],
outDir: join(cwd, "dist"),
target: "node16",
format: ["cjs"],
splitting: false,
skipNodeModulesBundle: true,
});
}

await Promise.all([
fs.copy(join(cwd, ".next"), join(cwd, "dist/.next"), {
filter(src) {
Expand All @@ -220,11 +233,15 @@ async function buildNext(cwd: string) {
`#!/usr/bin/env node`,
`process.on('SIGTERM', () => process.exit(0))`,
`process.on('SIGINT', () => process.exit(0))`,
additionalRequire
? `require('${additionalRequire.replace(".ts", "")}')`
: ``,
`
require('next/dist/server/lib/start-server').startServer({
dir: __dirname,
hostname: '0.0.0.0',
port: parseInt(process.env.PORT)
port: parseInt(process.env.PORT),
conf: {},
}).then(async (app)=>{
const appUrl = 'http://' + app.hostname + ':' + app.port;
console.log('started server on '+ app.hostname + ':' + app.port + ', url: ' + appUrl);
Expand Down Expand Up @@ -257,6 +274,7 @@ async function compile(
splitting: false,
sourcemap: true,
clean: true,
shims: true,
skipNodeModulesBundle: false,
noExternal: dependencies,
external: buildOptions.external,
Expand Down

0 comments on commit 4695d0b

Please sign in to comment.