Project Init

This commit is contained in:
Muluhabt
2026-05-29 15:23:46 +03:00
commit 2fbc557aac
67387 changed files with 6063341 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
import type { Plugin } from 'vite';
import { AssetGlob } from '@nx/js/src/utils/assets/assets';
export declare function nxCopyAssetsPlugin(_assets: (string | AssetGlob)[]): Plugin;
//# sourceMappingURL=nx-copy-assets.plugin.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"nx-copy-assets.plugin.d.ts","sourceRoot":"","sources":["../../../../packages/vite/plugins/nx-copy-assets.plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAG3D,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,GAAG,MAAM,CA2C1E"}

50
node_modules/@nx/vite/plugins/nx-copy-assets.plugin.js generated vendored Normal file
View File

@@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nxCopyAssetsPlugin = nxCopyAssetsPlugin;
const node_path_1 = require("node:path");
const devkit_1 = require("@nx/devkit");
const copy_assets_handler_1 = require("@nx/js/src/utils/assets/copy-assets-handler");
function nxCopyAssetsPlugin(_assets) {
let config;
let handler;
let dispose;
if (global.NX_GRAPH_CREATION)
return;
return {
name: 'nx-copy-assets-plugin',
configResolved(_config) {
config = _config;
},
async buildStart() {
const relativeProjectRoot = (0, node_path_1.relative)(devkit_1.workspaceRoot, config.root);
const assets = _assets.map((a) => {
if (typeof a === 'string') {
return (0, devkit_1.joinPathFragments)(relativeProjectRoot, a);
}
else {
return {
...a,
input: (0, devkit_1.joinPathFragments)(relativeProjectRoot, a.input),
};
}
});
handler = new copy_assets_handler_1.CopyAssetsHandler({
rootDir: devkit_1.workspaceRoot,
projectDir: config.root,
outputDir: config.build.outDir.startsWith(config.root)
? config.build.outDir
: (0, node_path_1.join)(config.root, config.build.outDir),
assets,
});
if (this.meta.watchMode && (0, devkit_1.isDaemonEnabled)()) {
dispose = await handler.watchAndProcessOnAssetChange();
}
},
async writeBundle() {
await handler.processAllAssetsOnce();
},
async closeWatcher() {
dispose == null ? void 0 : dispose();
},
};
}

View File

@@ -0,0 +1,29 @@
import { Plugin } from 'vite';
export interface nxViteTsPathsOptions {
/**
* Enable debug logging
* If set to false, it will always ignore the debug logging even when `--verbose` or `NX_VERBOSE_LOGGING` is set to true.
* @default undefined
**/
debug?: boolean;
/**
* export fields in package.json to use for resolving
* @default [['exports', '.', 'import'], 'module', 'main']
*
* fallback resolution will use ['main', 'module']
**/
mainFields?: (string | string[])[];
/**
* extensions to check when resolving files when package.json resolution fails
* @default ['.ts', '.tsx', '.js', '.jsx', '.json', '.mjs', '.cjs']
**/
extensions?: string[];
/**
* Inform Nx whether to use the raw source or to use the built output for buildable dependencies.
* Set to `false` to use incremental builds.
* @default true
*/
buildLibsFromSource?: boolean;
}
export declare function nxViteTsPaths(options?: nxViteTsPathsOptions): Plugin;
//# sourceMappingURL=nx-tsconfig-paths.plugin.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"nx-tsconfig-paths.plugin.d.ts","sourceRoot":"","sources":["../../../../packages/vite/plugins/nx-tsconfig-paths.plugin.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAK9B,MAAM,WAAW,oBAAoB;IACnC;;;;QAII;IACJ,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;QAKI;IACJ,UAAU,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;IACnC;;;QAGI;IACJ,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GA4KzD,MAAM,CA0EZ"}

View File

@@ -0,0 +1,193 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nxViteTsPaths = nxViteTsPaths;
const devkit_1 = require("@nx/devkit");
const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
const ts_config_1 = require("@nx/js/src/utils/typescript/ts-config");
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
const tsconfig_paths_1 = require("tsconfig-paths");
const nx_tsconfig_paths_find_file_1 = require("../src/utils/nx-tsconfig-paths-find-file");
const options_utils_1 = require("../src/utils/options-utils");
const nx_vite_build_coordination_plugin_1 = require("./nx-vite-build-coordination.plugin");
function nxViteTsPaths(options = {}) {
let foundTsConfigPath;
let matchTsPathEsm;
let matchTsPathFallback;
let tsConfigPathsEsm;
let tsConfigPathsFallback;
options.extensions ??= [
'.ts',
'.tsx',
'.js',
'.jsx',
'.json',
'.mts',
'.mjs',
'.cts',
'.cjs',
'.css',
'.scss',
'.less',
];
options.mainFields ??= [['exports', '.', 'import'], 'module', 'main'];
options.buildLibsFromSource ??= true;
let projectRoot = '';
let projectRootFromWorkspaceRoot;
return {
name: 'nx-vite-ts-paths',
// Ensure the resolveId aspect of the plugin is called before vite's internal resolver
// Otherwise, issues can arise with Yarn Workspaces and Pnpm Workspaces
enforce: 'pre',
async configResolved(config) {
projectRoot = config.root;
projectRootFromWorkspaceRoot = (0, node_path_1.relative)(devkit_1.workspaceRoot, projectRoot);
foundTsConfigPath = getTsConfig(process.env.NX_TSCONFIG_PATH ??
(0, node_path_1.join)(devkit_1.workspaceRoot, 'tmp', projectRootFromWorkspaceRoot, process.env.NX_TASK_TARGET_TARGET ?? 'build', 'tsconfig.generated.json'));
if (!foundTsConfigPath)
return;
if (!options.buildLibsFromSource && !global.NX_GRAPH_CREATION) {
const projectGraph = await (0, devkit_1.createProjectGraphAsync)({
exitOnError: false,
resetDaemonClient: true,
});
// When using incremental building and the serve target is called
// we need to get the deps for the 'build' target instead.
const depsBuildTarget = process.env.NX_TASK_TARGET_TARGET === 'serve' ||
process.env.NX_TASK_TARGET_TARGET === 'test'
? 'build'
: process.env.NX_TASK_TARGET_TARGET;
const { dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(undefined, projectGraph, devkit_1.workspaceRoot, process.env.NX_TASK_TARGET_PROJECT, depsBuildTarget, process.env.NX_TASK_TARGET_CONFIGURATION);
if (process.env.NX_GENERATED_TSCONFIG_PATH) {
// This is needed for vitest browser mode because it runs two vite dev servers
// so we want to reuse the same tsconfig file for both servers
foundTsConfigPath = process.env.NX_GENERATED_TSCONFIG_PATH;
}
else {
// This tsconfig is used via the Vite ts paths plugin.
// It can be also used by other user-defined Vite plugins (e.g. for creating type declaration files).
foundTsConfigPath = (0, buildable_libs_utils_1.createTmpTsConfig)(foundTsConfigPath, devkit_1.workspaceRoot, (0, node_path_1.relative)(devkit_1.workspaceRoot, projectRoot), dependencies, true);
process.env.NX_GENERATED_TSCONFIG_PATH = foundTsConfigPath;
}
if (config.command === 'serve') {
const buildableLibraryDependencies = dependencies
.filter((dep) => dep.node.type === 'lib')
.map((dep) => dep.node.name)
.join(',');
const buildCommand = `npx nx run-many --target=${depsBuildTarget} --projects=${buildableLibraryDependencies}`;
config.plugins.push((0, nx_vite_build_coordination_plugin_1.nxViteBuildCoordinationPlugin)({ buildCommand }));
}
}
const parsed = (0, tsconfig_paths_1.loadConfig)(foundTsConfigPath);
logIt('first parsed tsconfig: ', parsed);
if (parsed.resultType === 'failed') {
throw new Error(`Failed loading tsconfig at ${foundTsConfigPath}`);
}
tsConfigPathsEsm = parsed;
matchTsPathEsm = (0, tsconfig_paths_1.createMatchPath)((0, ts_config_1.resolvePathsBaseUrl)(foundTsConfigPath), parsed.paths, options.mainFields);
const rootLevelTsConfig = getTsConfig((0, node_path_1.join)(devkit_1.workspaceRoot, 'tsconfig.base.json'));
const rootLevelParsed = (0, tsconfig_paths_1.loadConfig)(rootLevelTsConfig);
logIt('fallback parsed tsconfig: ', rootLevelParsed);
if (rootLevelParsed.resultType === 'success') {
tsConfigPathsFallback = rootLevelParsed;
matchTsPathFallback = (0, tsconfig_paths_1.createMatchPath)((0, ts_config_1.resolvePathsBaseUrl)(rootLevelTsConfig), rootLevelParsed.paths, ['main', 'module']);
}
},
resolveId(importPath) {
// Let other resolvers handle this path.
if (!foundTsConfigPath)
return null;
// Skip absolute and root-relative paths — these are filesystem paths,
// not TypeScript import specifiers. In Vite, `/foo` is a project-root-
// relative URL and must be resolved by Vite's built-in resolver, not
// by tsconfig path mapping (which would incorrectly use baseUrl).
if (importPath.startsWith('/'))
return null;
let resolvedFile;
try {
resolvedFile = matchTsPathEsm(importPath);
}
catch (e) {
logIt('Using fallback path matching.');
resolvedFile = matchTsPathFallback?.(importPath);
}
if (!resolvedFile || !(0, node_fs_1.existsSync)(resolvedFile)) {
if (tsConfigPathsEsm || tsConfigPathsFallback) {
logIt(`Unable to resolve ${importPath} with tsconfig paths. Using fallback file matching.`);
resolvedFile =
loadFileFromPaths(tsConfigPathsEsm, importPath) ||
loadFileFromPaths(tsConfigPathsFallback, importPath);
}
else {
logIt(`Unable to resolve ${importPath} with tsconfig paths`);
}
}
logIt(`Resolved ${importPath} to ${resolvedFile}`);
// Returning null defers to other resolveId functions and eventually the default resolution behavior
// https://rollupjs.org/plugin-development/#resolveid
return resolvedFile || null;
},
async writeBundle(options) {
if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)())
return;
const outDir = options.dir || 'dist';
const src = (0, node_path_1.resolve)(projectRoot, 'package.json');
const dest = (0, node_path_1.join)(outDir, 'package.json');
if ((0, node_fs_1.existsSync)(src) && !(0, node_fs_1.existsSync)(dest)) {
try {
(0, node_fs_1.copyFileSync)(src, dest);
}
catch (err) {
console.error('Error copying package.json:', err);
}
}
},
};
function getTsConfig(preferredTsConfigPath) {
const projectTsConfigPath = (0, options_utils_1.getProjectTsConfigPath)(projectRootFromWorkspaceRoot);
return [
(0, node_path_1.resolve)(preferredTsConfigPath),
projectTsConfigPath
? (0, node_path_1.resolve)((0, node_path_1.join)(devkit_1.workspaceRoot, projectTsConfigPath))
: null,
(0, node_path_1.resolve)((0, node_path_1.join)(devkit_1.workspaceRoot, 'tsconfig.base.json')),
(0, node_path_1.resolve)((0, node_path_1.join)(devkit_1.workspaceRoot, 'tsconfig.json')),
(0, node_path_1.resolve)((0, node_path_1.join)(devkit_1.workspaceRoot, 'jsconfig.json')),
]
.filter(Boolean)
.find((tsPath) => {
if ((0, node_fs_1.existsSync)(tsPath)) {
logIt('Found tsconfig at', tsPath);
return tsPath;
}
});
}
function logIt(...msg) {
if (process.env.NX_VERBOSE_LOGGING === 'true' && options?.debug !== false) {
console.debug('\n[Nx Vite TsPaths]', ...msg);
}
}
function loadFileFromPaths(tsconfig, importPath) {
logIt(`Trying to resolve file from config in ${tsconfig.configFileAbsolutePath}`);
let resolvedFile;
for (const alias in tsconfig.paths) {
const paths = tsconfig.paths[alias];
const normalizedImport = alias.replace(/\/\*$/, '');
if (importPath === normalizedImport ||
importPath.startsWith(normalizedImport + '/')) {
const joinedPath = (0, devkit_1.joinPathFragments)(tsconfig.absoluteBaseUrl, paths[0].replace(/\/\*$/, ''));
resolvedFile = (0, nx_tsconfig_paths_find_file_1.findFile)(importPath.replace(normalizedImport, joinedPath), options.extensions);
if (resolvedFile === undefined &&
options.extensions.some((ext) => importPath.endsWith(ext))) {
const foundExtension = options.extensions.find((ext) => importPath.endsWith(ext));
const pathWithoutExtension = importPath
.replace(normalizedImport, joinedPath)
.slice(0, -foundExtension.length);
resolvedFile = (0, nx_tsconfig_paths_find_file_1.findFile)(pathWithoutExtension, options.extensions);
}
}
}
return resolvedFile;
}
}

View File

@@ -0,0 +1,6 @@
import { type Plugin } from 'vite';
export interface NxViteBuildCoordinationPluginOptions {
buildCommand: string;
}
export declare function nxViteBuildCoordinationPlugin(options: NxViteBuildCoordinationPluginOptions): Plugin;
//# sourceMappingURL=nx-vite-build-coordination.plugin.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"nx-vite-build-coordination.plugin.d.ts","sourceRoot":"","sources":["../../../../packages/vite/plugins/nx-vite-build-coordination.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC;AASnC,MAAM,WAAW,oCAAoC;IACnD,YAAY,EAAE,MAAM,CAAC;CACtB;AACD,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,oCAAoC,GAC5C,MAAM,CA0ER"}

View File

@@ -0,0 +1,76 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nxViteBuildCoordinationPlugin = nxViteBuildCoordinationPlugin;
const watch_1 = require("nx/src/command-line/watch/watch");
const child_process_1 = require("child_process");
const client_1 = require("nx/src/daemon/client/client");
const output_1 = require("nx/src/utils/output");
function nxViteBuildCoordinationPlugin(options) {
let activeBuildProcess;
let unregisterFileWatcher;
async function buildChangedProjects() {
await new Promise((res) => {
activeBuildProcess = (0, child_process_1.exec)(options.buildCommand, {
windowsHide: true,
});
activeBuildProcess.stdout.pipe(process.stdout);
activeBuildProcess.stderr.pipe(process.stderr);
activeBuildProcess.on('exit', () => {
res();
});
activeBuildProcess.on('error', () => {
res();
});
});
activeBuildProcess = undefined;
}
function createFileWatcher() {
const runner = new watch_1.BatchFunctionRunner(() => buildChangedProjects());
return client_1.daemonClient.registerFileWatcher({ watchProjects: 'all' }, (err, { changedProjects, changedFiles }) => {
if (err === 'reconnecting') {
// Silent - daemon restarts automatically on lockfile changes
return;
}
else if (err === 'reconnected') {
// Silent - reconnection succeeded
return;
}
else if (err === 'closed') {
output_1.output.error({
title: `Failed to reconnect to daemon after multiple attempts`,
});
process.exit(1);
}
else if (err) {
output_1.output.error({
title: `Watch error: ${err?.message ?? 'Unknown'}`,
});
}
if (activeBuildProcess) {
activeBuildProcess.kill(2);
activeBuildProcess = undefined;
}
runner.enqueue(changedProjects, changedFiles);
});
}
let firstBuildStart = true;
return {
name: 'nx-vite-build-coordination-plugin',
async buildStart() {
if (firstBuildStart) {
firstBuildStart = false;
await buildChangedProjects();
if (client_1.daemonClient.enabled()) {
unregisterFileWatcher = await createFileWatcher();
process.on('exit', () => unregisterFileWatcher());
process.on('SIGINT', () => process.exit());
}
else {
output_1.output.warn({
title: 'Nx Daemon is not enabled. Projects will not be rebuilt when files change.',
});
}
}
},
};
}

View File

@@ -0,0 +1,17 @@
/**
* @function replaceFiles
* @param {FileReplacement[]} replacements
* @return {({name: "rollup-plugin-replace-files", enforce: "pre" | "post" | undefined, Promise<resolveId>})}
*/
export declare function replaceFiles(replacements: FileReplacement[]): {
name: string;
enforce: 'pre' | 'post' | undefined;
resolveId(source: any, importer: any, options: any): Promise<{
id: string;
}>;
};
export interface FileReplacement {
replace: string;
with: string;
}
//# sourceMappingURL=rollup-replace-files.plugin.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"rollup-replace-files.plugin.d.ts","sourceRoot":"","sources":["../../../../packages/vite/plugins/rollup-replace-files.plugin.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,eAAe,EAAE,GAAG;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;IACpC,SAAS,CACP,MAAM,EAAE,GAAG,EACX,QAAQ,EAAE,GAAG,EACb,OAAO,EAAE,GAAG,GACX,OAAO,CAAC;QACT,EAAE,EAAE,MAAM,CAAC;KACZ,CAAC,CAAC;CACJ,CAuCA;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd"}

View File

@@ -0,0 +1,45 @@
"use strict";
// source: https://github.com/Myrmod/vitejs-theming/blob/master/build-plugins/rollup/replace-files.js
Object.defineProperty(exports, "__esModule", { value: true });
exports.replaceFiles = replaceFiles;
/**
* @function replaceFiles
* @param {FileReplacement[]} replacements
* @return {({name: "rollup-plugin-replace-files", enforce: "pre" | "post" | undefined, Promise<resolveId>})}
*/
function replaceFiles(replacements) {
if (!replacements?.length) {
return null;
}
return {
name: 'rollup-plugin-replace-files',
enforce: 'pre',
async resolveId(source, importer, options) {
const resolved = await this.resolve(source, importer, {
...options,
skipSelf: true,
});
/**
* The reason we're using endsWith here is because the resolved id
* will be the absolute path to the file. We want to check if the
* file ends with the file we're trying to replace, which will be essentially
* the path from the root of our workspace.
*/
const foundReplace = replacements.find((replacement) => resolved?.id?.endsWith(replacement.replace));
if (foundReplace) {
console.info(`replace "${foundReplace.replace}" with "${foundReplace.with}"`);
try {
// return new file content
return {
id: resolved.id.replace(foundReplace.replace, foundReplace.with),
};
}
catch (err) {
console.error(err);
return null;
}
}
return null;
},
};
}