@nx/vite 23.2.0-beta.0 → 23.2.0-beta.10

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.
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nxViteBuildCoordinationPlugin = nxViteBuildCoordinationPlugin;
4
- const watch_1 = require("nx/src/command-line/watch/watch");
5
4
  const child_process_1 = require("child_process");
6
- const client_1 = require("nx/src/daemon/client/client");
7
- const output_1 = require("nx/src/utils/output");
5
+ const internal_1 = require("@nx/devkit/internal");
6
+ const devkit_1 = require("@nx/devkit");
8
7
  function nxViteBuildCoordinationPlugin(options) {
9
8
  let activeBuildProcess;
10
9
  let unregisterFileWatcher;
@@ -40,13 +39,13 @@ function nxViteBuildCoordinationPlugin(options) {
40
39
  function createFileWatcher() {
41
40
  // Failed rebuilds in watch mode should not crash the dev server. Log and
42
41
  // keep watching so the next file change can rebuild.
43
- const runner = new watch_1.BatchFunctionRunner(() => buildChangedProjects().catch((error) => {
44
- output_1.output.error({
42
+ const runner = new internal_1.BatchFunctionRunner(() => buildChangedProjects().catch((error) => {
43
+ devkit_1.output.error({
45
44
  title: 'Failed to rebuild projects. Fix the errors and save again.',
46
45
  bodyLines: error?.message ? [error.message] : undefined,
47
46
  });
48
47
  }));
49
- return client_1.daemonClient.registerFileWatcher({ watchProjects: 'all' }, (err, data) => {
48
+ return internal_1.daemonClient.registerFileWatcher({ watchProjects: 'all' }, (err, data) => {
50
49
  if (err === 'reconnecting') {
51
50
  // Silent - daemon restarts automatically on lockfile changes
52
51
  return;
@@ -56,13 +55,13 @@ function nxViteBuildCoordinationPlugin(options) {
56
55
  return;
57
56
  }
58
57
  else if (err === 'closed') {
59
- output_1.output.error({
58
+ devkit_1.output.error({
60
59
  title: `Failed to reconnect to daemon after multiple attempts`,
61
60
  });
62
61
  process.exit(1);
63
62
  }
64
63
  else if (err) {
65
- output_1.output.error({
64
+ devkit_1.output.error({
66
65
  title: `Watch error: ${err?.message ?? 'Unknown'}`,
67
66
  });
68
67
  }
@@ -83,13 +82,13 @@ function nxViteBuildCoordinationPlugin(options) {
83
82
  if (firstBuildStart) {
84
83
  firstBuildStart = false;
85
84
  await buildChangedProjects();
86
- if (client_1.daemonClient.enabled()) {
85
+ if (internal_1.daemonClient.enabled()) {
87
86
  unregisterFileWatcher = await createFileWatcher();
88
87
  process.on('exit', () => unregisterFileWatcher());
89
88
  process.on('SIGINT', () => process.exit());
90
89
  }
91
90
  else {
92
- output_1.output.warn({
91
+ devkit_1.output.warn({
93
92
  title: 'Nx Daemon is not enabled. Projects will not be rebuilt when files change.',
94
93
  });
95
94
  }
@@ -93,17 +93,13 @@ async function* viteBuildExecutor(options, context) {
93
93
  skipPackageManager: options.skipPackageManager,
94
94
  });
95
95
  builtPackageJson.type ??= 'module';
96
- (0, devkit_1.writeJsonFile)(`${outDirRelativeToWorkspaceRoot}/package.json`, builtPackageJson);
97
96
  const packageManager = (0, devkit_1.detectPackageManager)(context.root);
98
- if (packageManager === 'bun') {
99
- devkit_1.logger.warn('Bun lockfile generation is not supported. The generated package.json will not include a lockfile. Run "bun install" in the output directory after deployment if needed.');
100
- }
101
- else {
102
- const lockFile = (0, js_1.createLockFile)(builtPackageJson, context.projectGraph, packageManager);
103
- (0, fs_1.writeFileSync)(`${outDirRelativeToWorkspaceRoot}/${(0, js_1.getLockFileName)(packageManager)}`, lockFile, {
104
- encoding: 'utf-8',
105
- });
106
- }
97
+ (0, js_1.generatePrunedDeployOutput)(builtPackageJson, context.projectGraph, projectRoot, {
98
+ outputDirectory: outDirRelativeToWorkspaceRoot,
99
+ packageManager,
100
+ workspaceRoot: context.root,
101
+ });
102
+ (0, devkit_1.writeJsonFile)(`${outDirRelativeToWorkspaceRoot}/package.json`, builtPackageJson);
107
103
  }
108
104
  // For buildable libs, copy package.json if it exists.
109
105
  else if (options.generatePackageJson !== false &&
@@ -117,9 +117,13 @@ async function getServerExtraArgs(options, configuration, buildOptionsFromBuildT
117
117
  }
118
118
  }
119
119
  if (configuration) {
120
+ const normalizeWatchOption = (watch) => {
121
+ return watch === false ? undefined : watch;
122
+ };
120
123
  serverOptions = {
121
124
  ...serverOptions,
122
- watch: buildOptionsFromBuildTarget?.watch ?? serverOptions?.watch,
125
+ watch: normalizeWatchOption(buildOptionsFromBuildTarget?.watch) ??
126
+ normalizeWatchOption(serverOptions?.watch),
123
127
  };
124
128
  otherOptions = {
125
129
  ...otherOptions,
@@ -7,8 +7,6 @@ const js_1 = require("@nx/js");
7
7
  const internal_2 = require("@nx/js/internal");
8
8
  const node_fs_1 = require("node:fs");
9
9
  const node_path_1 = require("node:path");
10
- const file_hasher_1 = require("nx/src/hasher/file-hasher");
11
- const cache_directory_1 = require("nx/src/utils/cache-directory");
12
10
  const executor_utils_1 = require("../utils/executor-utils");
13
11
  const picomatch = require("picomatch");
14
12
  /**
@@ -22,9 +20,9 @@ const viteConfigGlob = '**/vite.config.{js,ts,mjs,mts,cjs,cts}';
22
20
  exports.createNodes = [
23
21
  viteConfigGlob,
24
22
  async (configFilePaths, options, context) => {
25
- const optionsHash = (0, file_hasher_1.hashObject)(options);
23
+ const optionsHash = (0, internal_1.hashObject)(options);
26
24
  const normalizedOptions = normalizeOptions(options);
27
- const cachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, `vite-${optionsHash}.hash`);
25
+ const cachePath = (0, node_path_1.join)(internal_1.workspaceDataDirectory, `vite-${optionsHash}.hash`);
28
26
  const targetsCache = new internal_1.PluginCache(cachePath);
29
27
  const isUsingTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)();
30
28
  const { roots: projectRoots, configFiles: validConfigFiles } = configFilePaths.reduce((acc, configFile) => {
@@ -413,13 +413,9 @@ async function handleUnsupportedUserProvidedTargetsErrors(userProvidedTargetName
413
413
  Please note that converting a potentially non-compatible project to use Vite may result in unexpected behavior. Always commit
414
414
  your changes before converting a project to use Vite, and test the converted project thoroughly before deploying it.
415
415
  `);
416
- const { Confirm } = require('enquirer');
417
- const prompt = new Confirm({
418
- name: 'question',
416
+ const shouldConvert = await (0, internal_1.confirmationPrompt)({
419
417
  message: `Should we convert the ${validFoundTargetName} target to use the @nx/vite:${executor} executor?`,
420
- initial: true,
421
418
  });
422
- const shouldConvert = await prompt.run();
423
419
  if (!shouldConvert) {
424
420
  throw new Error(`The ${target} target ${userProvidedTargetName} cannot be converted to use the @nx/vite:${executor} executor.
425
421
  Please try again, either by providing a different ${target} target or by not providing a target at all (Nx will
@@ -441,13 +437,9 @@ async function handleUnknownConfiguration(projectName) {
441
437
  If you still want to convert your project to use Vite,
442
438
  please make sure to commit your changes before running this generator.
443
439
  `);
444
- const { Confirm } = require('enquirer');
445
- const prompt = new Confirm({
446
- name: 'question',
440
+ const shouldConvert = await (0, internal_1.confirmationPrompt)({
447
441
  message: `Should Nx convert your project to use Vite?`,
448
- initial: true,
449
442
  });
450
- const shouldConvert = await prompt.run();
451
443
  if (!shouldConvert) {
452
444
  throw new Error(`
453
445
  Nx could not verify that your project can be converted to use Vite.
@@ -1,4 +1,3 @@
1
1
  import { type Tree } from '@nx/devkit';
2
2
  export declare function ignoreViteTempFiles(tree: Tree, projectRoot?: string | undefined): Promise<void>;
3
3
  export declare function addViteTempFilesToGitIgnore(tree: Tree): void;
4
- export declare function isEslintInstalled(tree: Tree): boolean;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ignoreViteTempFiles = ignoreViteTempFiles;
4
4
  exports.addViteTempFilesToGitIgnore = addViteTempFilesToGitIgnore;
5
- exports.isEslintInstalled = isEslintInstalled;
6
5
  const devkit_1 = require("@nx/devkit");
6
+ const internal_1 = require("@nx/js/internal");
7
7
  const versions_1 = require("./versions");
8
8
  async function ignoreViteTempFiles(tree, projectRoot) {
9
9
  addViteTempFilesToGitIgnore(tree);
@@ -20,7 +20,9 @@ function addViteTempFilesToGitIgnore(tree) {
20
20
  tree.write('.gitignore', gitIgnoreContents);
21
21
  }
22
22
  async function ignoreViteTempFilesInEslintConfig(tree, projectRoot) {
23
- if (!isEslintInstalled(tree)) {
23
+ // Checked before `ensurePackage` so an Oxlint workspace does not install
24
+ // `@nx/eslint` only for `isEslintConfigSupported` to send it straight back.
25
+ if (!(0, internal_1.detectLinters)(tree).includes('eslint')) {
24
26
  return;
25
27
  }
26
28
  (0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
@@ -45,15 +47,3 @@ async function ignoreViteTempFilesInEslintConfig(tree, projectRoot) {
45
47
  const directory = isUsingFlatConfig ? '' : (projectRoot ?? '');
46
48
  addIgnoresToLintConfig(tree, directory, ['**/vite.config.*.timestamp*']);
47
49
  }
48
- function isEslintInstalled(tree) {
49
- try {
50
- require('eslint');
51
- return true;
52
- }
53
- catch { }
54
- // it might not be installed yet, but it might be in the tree pending install
55
- const { devDependencies, dependencies } = tree.exists('package.json')
56
- ? (0, devkit_1.readJson)(tree, 'package.json')
57
- : {};
58
- return !!devDependencies?.['eslint'] || !!dependencies?.['eslint'];
59
- }
@@ -1,3 +1,3 @@
1
- import type { Tree } from 'nx/src/generators/tree';
1
+ import { type Tree } from '@nx/devkit';
2
2
  export declare function getInstalledViteVersion(tree: Tree): string | undefined;
3
3
  export declare function getInstalledViteMajorVersion(tree: Tree): 5 | 6 | 7 | 8 | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/vite",
3
- "version": "23.2.0-beta.0",
3
+ "version": "23.2.0-beta.10",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -95,19 +95,18 @@
95
95
  },
96
96
  "dependencies": {
97
97
  "@phenomnomnominal/tsquery": "~6.2.0",
98
- "enquirer": "~2.3.6",
99
98
  "picomatch": "4.0.4",
100
99
  "tsconfig-paths": "^4.1.2",
101
100
  "semver": "^7.6.3",
102
101
  "tslib": "^2.3.0",
103
102
  "ajv": "^8.0.0",
104
- "@nx/devkit": "23.2.0-beta.0",
105
- "@nx/js": "23.2.0-beta.0",
106
- "@nx/vitest": "23.2.0-beta.0"
103
+ "@nx/devkit": "23.2.0-beta.10",
104
+ "@nx/js": "23.2.0-beta.10",
105
+ "@nx/vitest": "23.2.0-beta.10"
107
106
  },
108
107
  "devDependencies": {
109
- "@nx/eslint": "23.2.0-beta.0",
110
- "nx": "23.2.0-beta.0"
108
+ "@nx/eslint": "23.2.0-beta.10",
109
+ "nx": "23.2.0-beta.10"
111
110
  },
112
111
  "peerDependencies": {
113
112
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"