Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TypeScript 4.9 (satisfies) #151

Merged
merged 3 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bob-the-bundler-151-dependencies.md
@@ -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
@@ -0,0 +1,5 @@
---
"bob-the-bundler": patch
---

Support TypeScript 4.9 and satisfies operator
2 changes: 1 addition & 1 deletion package.json
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
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