@mintlify/previewing 4.0.1522 → 4.0.1524

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.
@@ -74,28 +74,15 @@ beforeEach(() => {
74
74
  vi.clearAllMocks();
75
75
  watcher.handlers = {};
76
76
  });
77
- afterEach(() => {
78
- vi.unstubAllEnvs();
79
- });
80
77
  describe('listener package manifest changes', () => {
81
- it('treats a root package.json as a potential OpenAPI spec when the flag is off', async () => {
82
- vi.stubEnv('MINTLIFY_NATIVE_NPM_PACKAGES', undefined);
83
- await change('package.json');
84
- expect(notifyPackageInputChange).toHaveBeenCalledWith('package.json', 'potentialJsonOpenApiSpec');
85
- expect(validate).toHaveBeenCalledWith(manifest);
86
- expect(triggerRefresh).toHaveBeenCalledOnce();
87
- edited('package.json');
88
- });
89
- it('leaves a root package.json to the packages runtime when the flag is on', async () => {
90
- vi.stubEnv('MINTLIFY_NATIVE_NPM_PACKAGES', '1');
78
+ it('leaves a root package.json to the packages runtime', async () => {
91
79
  await change('package.json');
92
80
  expect(notifyPackageInputChange).toHaveBeenCalledWith('package.json', 'potentialJsonOpenApiSpec');
93
81
  expect(validate).not.toHaveBeenCalled();
94
82
  expect(triggerRefresh).not.toHaveBeenCalled();
95
83
  edited('package.json');
96
84
  });
97
- it('still parses a nested package.json when the flag is on', async () => {
98
- vi.stubEnv('MINTLIFY_NATIVE_NPM_PACKAGES', '1');
85
+ it('still parses a nested package.json', async () => {
99
86
  await change(join('snippets', 'package.json'));
100
87
  expect(validate).toHaveBeenCalledWith(manifest);
101
88
  expect(triggerRefresh).toHaveBeenCalledOnce();
@@ -1,9 +1,9 @@
1
1
  import { prebuild } from '@mintlify/prebuild';
2
2
  import { mockProcessExit } from 'vitest-mock-process';
3
3
  import { configurePreviewPath } from '../constants.js';
4
- import { dev, isNativePackagesEnabled } from '../index.js';
4
+ import { dev } from '../index.js';
5
5
  import listener from '../local-preview/listener/index.js';
6
- import { packageRoute, setPackagesRebuiltListener, startPackagesDev, } from '../local-preview/packages/index.js';
6
+ import { setPackagesRebuiltListener, startPackagesDev } from '../local-preview/packages/index.js';
7
7
  const captured = vi.hoisted(() => ({ app: undefined }));
8
8
  vi.mock('http', async (importOriginal) => {
9
9
  const actual = await importOriginal();
@@ -73,7 +73,6 @@ vi.mock('../local-preview/packages/index.js', () => ({
73
73
  const originalChdir = process.chdir;
74
74
  const processExitMock = mockProcessExit();
75
75
  const argv = { _: [], $0: '', packageName: 'mint', cliVersion: '1.0.0' };
76
- const setFlag = (value) => vi.stubEnv('MINTLIFY_NATIVE_NPM_PACKAGES', value);
77
76
  const startRun = async () => {
78
77
  const { run } = await vi.importActual('../local-preview/run.js');
79
78
  await run({ ...argv, needsUpdate: false });
@@ -97,39 +96,8 @@ beforeEach(() => {
97
96
  });
98
97
  afterEach(() => {
99
98
  process.chdir = originalChdir;
100
- vi.unstubAllEnvs();
101
99
  });
102
- describe('isNativePackagesEnabled', () => {
103
- it('is on only when MINTLIFY_NATIVE_NPM_PACKAGES is 1', () => {
104
- setFlag(undefined);
105
- expect(isNativePackagesEnabled()).toBe(false);
106
- setFlag('true');
107
- expect(isNativePackagesEnabled()).toBe(false);
108
- setFlag('0');
109
- expect(isNativePackagesEnabled()).toBe(false);
110
- setFlag('1');
111
- expect(isNativePackagesEnabled()).toBe(true);
112
- });
113
- });
114
- describe('mint dev with native npm packages off', () => {
115
- beforeEach(() => setFlag(undefined));
116
- it('skips the packages runtime and tells prebuild to ignore packages', async () => {
117
- await dev(argv);
118
- expect(processExitMock).not.toHaveBeenCalled();
119
- expect(startPackagesDev).not.toHaveBeenCalled();
120
- expect(prebuild).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({ nativePackages: false }));
121
- });
122
- it('lets /_mintlify/pkg requests fall through to the next handler', async () => {
123
- configurePreviewPath(3000);
124
- await startRun();
125
- expect(await get('/_mintlify/pkg/x/client/a.js')).toBe('next');
126
- expect(packageRoute.handler).not.toHaveBeenCalled();
127
- expect(setPackagesRebuiltListener).not.toHaveBeenCalled();
128
- expect(listener).toHaveBeenCalledWith(expect.any(Function), expect.objectContaining({ nativePackages: false }), expect.any(Promise));
129
- });
130
- });
131
- describe('mint dev with MINTLIFY_NATIVE_NPM_PACKAGES=1', () => {
132
- beforeEach(() => setFlag('1'));
100
+ describe('mint dev npm packages', () => {
133
101
  it('starts the packages runtime and tells prebuild to read packages', async () => {
134
102
  await dev(argv);
135
103
  expect(processExitMock).not.toHaveBeenCalled();
@@ -6,7 +6,6 @@ import pathUtil from 'path';
6
6
  import { CLIENT_PATH, CMD_EXEC_PATH, VERSION_PATH, NEXT_PUBLIC_PATH, NEXT_PROPS_PATH, PREVIEW_PATH, configurePreviewPath, } from '../constants.js';
7
7
  import { addLog, clearLogs } from '../logging-state.js';
8
8
  import { ErrorLog, SpinnerLog } from '../logs.js';
9
- import { isNativePackagesEnabled } from '../packages/flag.js';
10
9
  import { seedPreviewFromShared } from '../util.js';
11
10
  import { timeDev, timeDevSync } from './dev-timing.js';
12
11
  import { ensureDocsConfig } from './ensure-docs-config.js';
@@ -92,7 +91,6 @@ const startDev = async (argv) => {
92
91
  timeDevSync('switch to local client directory', () => {
93
92
  process.chdir(CLIENT_PATH);
94
93
  });
95
- const nativePackages = isNativePackagesEnabled();
96
94
  let fileImportsMap;
97
95
  try {
98
96
  const result = await timeDev('prebuild content', () => prebuild(CMD_EXEC_PATH, {
@@ -102,7 +100,7 @@ const startDev = async (argv) => {
102
100
  disablePrefetch,
103
101
  allowSourceRefs: true,
104
102
  lazyPages: true,
105
- nativePackages,
103
+ nativePackages: true,
106
104
  }));
107
105
  fileImportsMap = result?.fileImportsMap;
108
106
  }
@@ -113,8 +111,7 @@ const startDev = async (argv) => {
113
111
  await new Promise((resolve) => setTimeout(resolve, 50));
114
112
  process.exit(1);
115
113
  }
116
- if (nativePackages)
117
- await timeDev('build npm packages', () => startPackagesDev());
114
+ await timeDev('build npm packages', () => startPackagesDev());
118
115
  await timeDev('start preview runtime', () => run({ ...argv, needsUpdate, fileImportsMap }));
119
116
  };
120
117
  const dev = async (argv) => {
@@ -12,7 +12,6 @@ import pathUtil from 'path';
12
12
  import { CMD_EXEC_PATH, NEXT_PROPS_PATH, NEXT_PUBLIC_PATH, CLIENT_PATH } from '../../constants.js';
13
13
  import { addChangeLog, addErrorLog, clearErrorLogs, getCurrentErrorLogs, } from '../../logging-state.js';
14
14
  import { AddedLog, DeletedLog, EditedLog, WarningLog, InfoLog, ErrorLog } from '../../logs.js';
15
- import { isNativePackagesEnabled } from '../../packages/flag.js';
16
15
  import { reportPageCompileError, reportPageCompileSuccess } from '../on-demand-page.js';
17
16
  import { notifyPackageInputChange, writePackageBuildProps } from '../packages/index.js';
18
17
  import { clearDocsConfigCaches, getDocsConfigApiHash, getDocsConfigNavigationHash, getVariablesHash, hasDocsConfigApiChanged, hasDocsConfigNavigationChanged, hasNavigationApiReference, hadDocsConfigApiReference, hasDocsConfigVariablesChanged, updateDocsConfigHashCache, } from './docs-config-cache.js';
@@ -397,7 +396,7 @@ const onUpdateEvent = async (filename, triggerRefresh, options = {}) => {
397
396
  const importedFiles = getImportedFilesFromCache();
398
397
  const potentialCategory = getFileCategory(filename, { importedFiles });
399
398
  await notifyPackageInputChange(filename, potentialCategory);
400
- if (isNativePackagesEnabled() && isPackageManifestPath(filename))
399
+ if (isPackageManifestPath(filename))
401
400
  return null;
402
401
  if (hasTrackedReferencedFile(filename)) {
403
402
  if (await fse.pathExists(pathUtil.join(CMD_EXEC_PATH, 'docs.json'))) {
@@ -28,7 +28,7 @@ const reporter = {
28
28
  }
29
29
  },
30
30
  missingNodeModules: (docsRoot) => {
31
- addErrorLog(_jsx(ErrorLog, { message: `docs.json uses npm packages but ${path.join(docsRoot, 'node_modules')} is missing. Run npm install in ${docsRoot}; package components stay empty until then.` }));
31
+ addErrorLog(_jsx(ErrorLog, { message: `docs.json uses npm packages but ${path.join(docsRoot, 'node_modules')} is missing. Run npm install --ignore-scripts in ${docsRoot}; package components stay empty until then.` }));
32
32
  },
33
33
  configError: (message) => {
34
34
  addErrorLog(_jsx(ErrorLog, { message: `npm packages: ${message}` }));
@@ -6,7 +6,6 @@ import { Server as SocketServer } from 'socket.io';
6
6
  import { CMD_EXEC_PATH, NEXT_PUBLIC_PATH } from '../constants.js';
7
7
  import { addLog, removeSpinnerLogs } from '../logging-state.js';
8
8
  import { LaunchLog, SearchDisabledLog, UpdateLog } from '../logs.js';
9
- import { isNativePackagesEnabled } from '../packages/flag.js';
10
9
  import { maybeFixMissingWindowsEnvVar } from '../util.js';
11
10
  import { addDevTimingLog, startDevTiming, timeDev } from './dev-timing.js';
12
11
  import listener, { initializeDocsConfigHashCache, initializeFrontmatterHashCache, initializeImportCache, } from './listener/index.js';
@@ -55,7 +54,6 @@ export const run = async (argv) => {
55
54
  process.env.LOCAL_OG_PREVIEW = 'true';
56
55
  const requestHandler = await timeDev('setup Next handler', () => setupNext());
57
56
  const localIp = getLocalNetworkIp();
58
- const nativePackages = isNativePackagesEnabled();
59
57
  const apiUrl = argv.apiUrl ?? process.env.MINTLIFY_API_URL ?? 'http://localhost:5000';
60
58
  const accessToken = argv.accessToken;
61
59
  const subdomain = argv.subdomain;
@@ -63,8 +61,7 @@ export const run = async (argv) => {
63
61
  process.env.MINTLIFY_API_URL = apiUrl;
64
62
  if (subdomain)
65
63
  process.env.MINTLIFY_CLI_SUBDOMAIN = subdomain;
66
- if (nativePackages)
67
- app.use(packageRoute.prefix, packageRoute.handler);
64
+ app.use(packageRoute.prefix, packageRoute.handler);
68
65
  // next-server is bugged, public files added after starting aren't served
69
66
  app.use('/', express.static(NEXT_PUBLIC_PATH));
70
67
  app.use((req, _res, next) => {
@@ -138,8 +135,7 @@ export const run = async (argv) => {
138
135
  const onChange = () => {
139
136
  io.emit('reload');
140
137
  };
141
- if (nativePackages)
142
- setPackagesRebuiltListener(onChange);
138
+ setPackagesRebuiltListener(onChange);
143
139
  setCompileListener((event) => {
144
140
  io.emit('compiling', event);
145
141
  });
@@ -149,7 +145,8 @@ export const run = async (argv) => {
149
145
  }
150
146
  });
151
147
  const finishServerListenTiming = startDevTiming('server ready');
152
- server.listen(currentPort, () => {
148
+ const exposeOnNetwork = argv.host === true;
149
+ server.listen(currentPort, exposeOnNetwork ? undefined : 'localhost', () => {
153
150
  finishServerListenTiming();
154
151
  removeSpinnerLogs();
155
152
  if (argv.needsUpdate) {
@@ -158,7 +155,7 @@ export const run = async (argv) => {
158
155
  if (!accessToken) {
159
156
  addLog(_jsx(SearchDisabledLog, { loginCommand: `${argv.packageName} login` }));
160
157
  }
161
- addLog(_jsx(LaunchLog, { localUrl: `http://localhost:${port}`, networkUrl: localIp ? `http://${localIp}:${port}` : undefined }));
158
+ addLog(_jsx(LaunchLog, { localUrl: `http://localhost:${port}`, networkUrl: exposeOnNetwork && localIp ? `http://${localIp}:${port}` : undefined }));
162
159
  /**
163
160
  * We're running into a known bug with the `open` package, where Windows machines error out because process.env.SYSTEMROOT is not set:
164
161
  * https://github.com/sindresorhus/open/issues/292
@@ -191,7 +188,7 @@ export const run = async (argv) => {
191
188
  disablePrefetch: argv.disablePrefetch,
192
189
  allowSourceRefs: true,
193
190
  lazyPages: true,
194
- nativePackages,
191
+ nativePackages: true,
195
192
  }, watcherGate);
196
193
  await timeDev('initialize import cache', () => initializeImportCache(CMD_EXEC_PATH, argv.fileImportsMap));
197
194
  markOnDemandPagesReady();
@@ -1,3 +1,2 @@
1
1
  export { collectPackageIslands, PackageIslandCollector, resolvePageContent, type CollectedIslands, type CollectPackageIslandsInput, type PackageIslandProblem, type PageIslands, } from './collect.js';
2
- export { isNativePackagesEnabled } from './flag.js';
3
2
  export { normalizeProviderPath, readPackagesSetup, type PackagesSetup } from './setup.js';
@@ -1,3 +1,2 @@
1
1
  export { collectPackageIslands, PackageIslandCollector, resolvePageContent, } from './collect.js';
2
- export { isNativePackagesEnabled } from './flag.js';
3
2
  export { normalizeProviderPath, readPackagesSetup } from './setup.js';