@mintlify/previewing 4.0.526 → 4.0.528
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/dist/__tests__/dev.test.d.ts +1 -0
- package/dist/__tests__/dev.test.js +125 -0
- package/dist/__tests__/downloadTargetMint.test.d.ts +1 -0
- package/dist/__tests__/downloadTargetMint.test.js +219 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/local-preview/client.d.ts +5 -3
- package/dist/local-preview/client.js +40 -57
- package/dist/local-preview/index.js +18 -107
- package/dist/local-preview/listener/generate.js +15 -21
- package/dist/local-preview/listener/generateDependentSnippets.js +23 -26
- package/dist/local-preview/listener/generatePagesWithImports.js +11 -20
- package/dist/local-preview/listener/getDocsState.js +10 -19
- package/dist/local-preview/listener/getSnippets.js +6 -15
- package/dist/local-preview/listener/index.js +45 -54
- package/dist/local-preview/listener/resolveAllImports.js +4 -13
- package/dist/local-preview/listener/update.js +14 -23
- package/dist/local-preview/listener/utils.js +6 -15
- package/dist/local-preview/run.d.ts +2 -0
- package/dist/local-preview/run.js +47 -0
- package/dist/local-preview/setupNext.d.ts +22 -0
- package/dist/local-preview/setupNext.js +41 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/util.d.ts +1 -0
- package/dist/util.js +8 -0
- package/package.json +10 -7
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import open from 'better-opn';
|
|
2
|
+
import Chalk from 'chalk';
|
|
3
|
+
import express from 'express';
|
|
4
|
+
import { createServer } from 'http';
|
|
5
|
+
import { Server as SocketServer } from 'socket.io';
|
|
6
|
+
import { NEXT_PUBLIC_PATH } from '../constants.js';
|
|
7
|
+
import { maybeFixMissingWindowsEnvVar } from '../util.js';
|
|
8
|
+
import listener from './listener/index.js';
|
|
9
|
+
import { setupNext } from './setupNext.js';
|
|
10
|
+
export const run = async (argv) => {
|
|
11
|
+
const port = argv.port || '3000';
|
|
12
|
+
const currentPort = parseInt(port, 10) || 3000;
|
|
13
|
+
const app = express();
|
|
14
|
+
const server = createServer(app);
|
|
15
|
+
const io = new SocketServer(server);
|
|
16
|
+
const requestHandler = await setupNext();
|
|
17
|
+
// next-server is bugged, public files added after starting aren't served
|
|
18
|
+
app.use('/', express.static(NEXT_PUBLIC_PATH));
|
|
19
|
+
app.all('*', (req, res) => requestHandler(req, res));
|
|
20
|
+
const onChange = () => {
|
|
21
|
+
io.emit('reload');
|
|
22
|
+
};
|
|
23
|
+
server.listen(currentPort, () => {
|
|
24
|
+
console.log(`${Chalk.green(`Your local preview is available at http://localhost:${port}`)}`);
|
|
25
|
+
// Note: We wait for this exact text to be sure the server is ready in the cli e2e test,
|
|
26
|
+
// if it changes, the test will fail/require an update.
|
|
27
|
+
console.log(`${Chalk.green('Press Ctrl+C any time to stop the local preview.')}`);
|
|
28
|
+
/**
|
|
29
|
+
* We're running into a known bug with the `open` package, where Windows machines error out because process.env.SYSTEMROOT is not set:
|
|
30
|
+
* https://github.com/sindresorhus/open/issues/292
|
|
31
|
+
*
|
|
32
|
+
* Let's use the same workaround that this project did:
|
|
33
|
+
* https://github.com/sanity-io/sanity/pull/4221/files#diff-aeb574e1becf61f21fdf87fbea709669c93d604d660dad4b0f9e24527a2fb54bR256-R262
|
|
34
|
+
*/
|
|
35
|
+
maybeFixMissingWindowsEnvVar();
|
|
36
|
+
if (argv.open) {
|
|
37
|
+
void open(`http://localhost:${port}`);
|
|
38
|
+
}
|
|
39
|
+
// exit with successful status
|
|
40
|
+
const onExit = () => {
|
|
41
|
+
process.exit(0);
|
|
42
|
+
};
|
|
43
|
+
process.on('SIGINT', onExit);
|
|
44
|
+
process.on('SIGTERM', onExit);
|
|
45
|
+
});
|
|
46
|
+
listener(onChange);
|
|
47
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When creating a standalone build, next.js outputs a server.js file that can be used as
|
|
3
|
+
* an entry point into the server. However, because we want to customize some parts of the
|
|
4
|
+
* http server (adding a socket.io server, serving the whole public directory), we
|
|
5
|
+
* create the server ourselves, and just reproduce the setup that next.js would do.
|
|
6
|
+
*
|
|
7
|
+
* Because we need to directly import from node_modules files, this solution seems very hacky,
|
|
8
|
+
* but it is arguably no more hacky than using the server.js that ships with the standalone
|
|
9
|
+
* build.
|
|
10
|
+
*
|
|
11
|
+
* This function attempts to replicate the behavior of two next.js files:
|
|
12
|
+
* - environment setup from server.js
|
|
13
|
+
* - initialization of the request handler from start-server.ts
|
|
14
|
+
*
|
|
15
|
+
* Links:
|
|
16
|
+
* - [standalone build](https://nextjs.org/docs/pages/api-reference/next-config-js/output#automatically-copying-traced-files)
|
|
17
|
+
* - [server.js](https://github.com/vercel/next.js/blob/492156b4c5e2559b2a280f7d483cd85a8e8742a9/packages/next/src/build/utils.ts#L2108-L2113) (created programmatically)
|
|
18
|
+
* - [start-server.ts](https://github.com/vercel/next.js/blob/492156b4c5e2559b2a280f7d483cd85a8e8742a9/packages/next/src/server/lib/start-server.ts#L296-L308)
|
|
19
|
+
*
|
|
20
|
+
* @returns the request handler provided by next.js
|
|
21
|
+
*/
|
|
22
|
+
export declare const setupNext: () => Promise<any>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import fse from 'fs-extra';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { CLIENT_PATH, NEXT_CONFIG_PATH, NEXT_ROUTER_SERVER_PATH, NEXT_SIDE_EFFECT_PATH, } from '../constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* When creating a standalone build, next.js outputs a server.js file that can be used as
|
|
6
|
+
* an entry point into the server. However, because we want to customize some parts of the
|
|
7
|
+
* http server (adding a socket.io server, serving the whole public directory), we
|
|
8
|
+
* create the server ourselves, and just reproduce the setup that next.js would do.
|
|
9
|
+
*
|
|
10
|
+
* Because we need to directly import from node_modules files, this solution seems very hacky,
|
|
11
|
+
* but it is arguably no more hacky than using the server.js that ships with the standalone
|
|
12
|
+
* build.
|
|
13
|
+
*
|
|
14
|
+
* This function attempts to replicate the behavior of two next.js files:
|
|
15
|
+
* - environment setup from server.js
|
|
16
|
+
* - initialization of the request handler from start-server.ts
|
|
17
|
+
*
|
|
18
|
+
* Links:
|
|
19
|
+
* - [standalone build](https://nextjs.org/docs/pages/api-reference/next-config-js/output#automatically-copying-traced-files)
|
|
20
|
+
* - [server.js](https://github.com/vercel/next.js/blob/492156b4c5e2559b2a280f7d483cd85a8e8742a9/packages/next/src/build/utils.ts#L2108-L2113) (created programmatically)
|
|
21
|
+
* - [start-server.ts](https://github.com/vercel/next.js/blob/492156b4c5e2559b2a280f7d483cd85a8e8742a9/packages/next/src/server/lib/start-server.ts#L296-L308)
|
|
22
|
+
*
|
|
23
|
+
* @returns the request handler provided by next.js
|
|
24
|
+
*/
|
|
25
|
+
export const setupNext = async () => {
|
|
26
|
+
const hostname = process.env.HOSTNAME || 'localhost';
|
|
27
|
+
const { config } = await JSON.parse(fse.readFileSync(NEXT_CONFIG_PATH, 'utf8'));
|
|
28
|
+
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(config);
|
|
29
|
+
// The server.js provided by next.js's standalone build does a similar import of this file.
|
|
30
|
+
// Not sure what side effects are being created, but want to change as little as possible.
|
|
31
|
+
// Also, Windows requires us to use `pathToFileURL` (see #899)
|
|
32
|
+
await import(pathToFileURL(NEXT_SIDE_EFFECT_PATH).href);
|
|
33
|
+
const { initialize } = await import(pathToFileURL(NEXT_ROUTER_SERVER_PATH).href);
|
|
34
|
+
const [requestHandler] = await initialize({
|
|
35
|
+
dir: CLIENT_PATH,
|
|
36
|
+
dev: false,
|
|
37
|
+
hostname,
|
|
38
|
+
minimalMode: true,
|
|
39
|
+
});
|
|
40
|
+
return requestHandler;
|
|
41
|
+
};
|