fix(core): do not use joinPathFragments for generating files (#18753)
This commit is contained in:
parent
7ea37e3bd1
commit
bbae14b9a7
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
▸ **joinPathFragments**(`...fragments`): `string`
|
▸ **joinPathFragments**(`...fragments`): `string`
|
||||||
|
|
||||||
Normalized path fragments and joins them
|
Normalized path fragments and joins them. Use this when writing paths to config files.
|
||||||
|
This should not be used to read files on disk because of the removal of Windows drive letters.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
▸ **normalizePath**(`osSpecificPath`): `string`
|
▸ **normalizePath**(`osSpecificPath`): `string`
|
||||||
|
|
||||||
Coverts an os specific path to a unix style path
|
Coverts an os specific path to a unix style path. Use this when writing paths to config files.
|
||||||
|
This should not be used to read files on disk because of the removal of Windows drive letters.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
|
|||||||
@ -120,7 +120,7 @@ function uppercase(val: string) {
|
|||||||
|
|
||||||
// later
|
// later
|
||||||
|
|
||||||
generateFiles(tree, joinPathFragments(__dirname, './files'), libraryRoot, {
|
generateFiles(tree, join(__dirname, './files'), libraryRoot, {
|
||||||
uppercase,
|
uppercase,
|
||||||
name: schema.name,
|
name: schema.name,
|
||||||
});
|
});
|
||||||
@ -141,7 +141,7 @@ This is the short version.
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// typescript file
|
// typescript file
|
||||||
generateFiles(tree, joinPathFragments(__dirname, './files'), libraryRoot, {
|
generateFiles(tree, join(__dirname, './files'), libraryRoot, {
|
||||||
shortVersion: false,
|
shortVersion: false,
|
||||||
numRepetitions: 3,
|
numRepetitions: 3,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import {
|
|||||||
typesCorsVersion,
|
typesCorsVersion,
|
||||||
typesExpressVersion,
|
typesExpressVersion,
|
||||||
} from '../../../utils/versions';
|
} from '../../../utils/versions';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
export async function addSsr(tree: Tree, options: Schema, appName: string) {
|
export async function addSsr(tree: Tree, options: Schema, appName: string) {
|
||||||
let project = readProjectConfiguration(tree, appName);
|
let project = readProjectConfiguration(tree, appName);
|
||||||
@ -34,7 +35,7 @@ export async function addSsr(tree: Tree, options: Schema, appName: string) {
|
|||||||
"import('./src/main.server');"
|
"import('./src/main.server');"
|
||||||
);
|
);
|
||||||
|
|
||||||
generateFiles(tree, joinPathFragments(__dirname, '../files'), project.root, {
|
generateFiles(tree, join(__dirname, '../files'), project.root, {
|
||||||
appName,
|
appName,
|
||||||
standalone: options.standalone,
|
standalone: options.standalone,
|
||||||
tmpl: '',
|
tmpl: '',
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import { angularDevkitVersion, nxVersion } from '../../../utils/versions';
|
|||||||
import type { ProjectMigrator } from '../migrators';
|
import type { ProjectMigrator } from '../migrators';
|
||||||
import type { GeneratorOptions } from '../schema';
|
import type { GeneratorOptions } from '../schema';
|
||||||
import type { WorkspaceRootFileTypesInfo } from './types';
|
import type { WorkspaceRootFileTypesInfo } from './types';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
export function validateWorkspace(tree: Tree): void {
|
export function validateWorkspace(tree: Tree): void {
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
@ -274,7 +275,7 @@ export async function createWorkspaceFiles(tree: Tree): Promise<void> {
|
|||||||
|
|
||||||
await jsInitGenerator(tree, { skipFormat: true });
|
await jsInitGenerator(tree, { skipFormat: true });
|
||||||
|
|
||||||
generateFiles(tree, joinPathFragments(__dirname, '../files/root'), '.', {
|
generateFiles(tree, join(__dirname, '../files/root'), '.', {
|
||||||
tmpl: '',
|
tmpl: '',
|
||||||
dot: '.',
|
dot: '.',
|
||||||
rootTsConfigPath: getRootTsConfigPathInTree(tree),
|
rootTsConfigPath: getRootTsConfigPathInTree(tree),
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import {
|
|||||||
import { lt } from 'semver';
|
import { lt } from 'semver';
|
||||||
import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
|
import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
|
||||||
import type { Schema } from '../schema';
|
import type { Schema } from '../schema';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
export function generateSSRFiles(tree: Tree, schema: Schema) {
|
export function generateSSRFiles(tree: Tree, schema: Schema) {
|
||||||
const projectConfig = readProjectConfiguration(tree, schema.project);
|
const projectConfig = readProjectConfiguration(tree, schema.project);
|
||||||
@ -16,7 +17,7 @@ export function generateSSRFiles(tree: Tree, schema: Schema) {
|
|||||||
|
|
||||||
const pathToFiles = joinPathFragments(__dirname, '..', 'files');
|
const pathToFiles = joinPathFragments(__dirname, '..', 'files');
|
||||||
|
|
||||||
generateFiles(tree, joinPathFragments(pathToFiles, 'base'), projectRoot, {
|
generateFiles(tree, join(pathToFiles, 'base'), projectRoot, {
|
||||||
...schema,
|
...schema,
|
||||||
tpl: '',
|
tpl: '',
|
||||||
});
|
});
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import {
|
|||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { NormalizedSchema, normalizeOptions } from './lib/normalize-options';
|
import { NormalizedSchema, normalizeOptions } from './lib/normalize-options';
|
||||||
import { addImport } from './lib/add-import';
|
import { addImport } from './lib/add-import';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
export async function expoComponentGenerator(host: Tree, schema: Schema) {
|
export async function expoComponentGenerator(host: Tree, schema: Schema) {
|
||||||
const options = await normalizeOptions(host, schema);
|
const options = await normalizeOptions(host, schema);
|
||||||
@ -30,7 +31,7 @@ function createComponentFiles(host: Tree, options: NormalizedSchema) {
|
|||||||
options.directory
|
options.directory
|
||||||
);
|
);
|
||||||
|
|
||||||
generateFiles(host, joinPathFragments(__dirname, './files'), componentDir, {
|
generateFiles(host, join(__dirname, './files'), componentDir, {
|
||||||
...options,
|
...options,
|
||||||
tmpl: '',
|
tmpl: '',
|
||||||
});
|
});
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import {
|
|||||||
typescriptVersion,
|
typescriptVersion,
|
||||||
} from '../../utils/versions';
|
} from '../../utils/versions';
|
||||||
import { InitSchema } from './schema';
|
import { InitSchema } from './schema';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
async function getInstalledTypescriptVersion(
|
async function getInstalledTypescriptVersion(
|
||||||
tree: Tree
|
tree: Tree
|
||||||
@ -65,7 +66,7 @@ export async function initGenerator(
|
|||||||
const tasks: GeneratorCallback[] = [];
|
const tasks: GeneratorCallback[] = [];
|
||||||
// add tsconfig.base.json
|
// add tsconfig.base.json
|
||||||
if (!getRootTsConfigFileName(tree)) {
|
if (!getRootTsConfigFileName(tree)) {
|
||||||
generateFiles(tree, joinPathFragments(__dirname, './files'), '.', {
|
generateFiles(tree, join(__dirname, './files'), '.', {
|
||||||
fileName: schema.tsConfigName ?? 'tsconfig.base.json',
|
fileName: schema.tsConfigName ?? 'tsconfig.base.json',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import {
|
|||||||
updateProjectConfiguration,
|
updateProjectConfiguration,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { CustomServerSchema } from './schema';
|
import { CustomServerSchema } from './schema';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
export async function customServerGenerator(
|
export async function customServerGenerator(
|
||||||
host: Tree,
|
host: Tree,
|
||||||
@ -52,7 +53,7 @@ export async function customServerGenerator(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
generateFiles(host, joinPathFragments(__dirname, 'files'), project.root, {
|
generateFiles(host, join(__dirname, 'files'), project.root, {
|
||||||
...options,
|
...options,
|
||||||
offsetFromRoot: offsetFromRoot(project.root),
|
offsetFromRoot: offsetFromRoot(project.root),
|
||||||
projectRoot: project.root,
|
projectRoot: project.root,
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import {
|
|||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
|
|
||||||
import { SetUpDockerOptions } from './schema';
|
import { SetUpDockerOptions } from './schema';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
function normalizeOptions(
|
function normalizeOptions(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
@ -39,7 +40,7 @@ function addDocker(tree: Tree, options: SetUpDockerOptions) {
|
|||||||
} else {
|
} else {
|
||||||
const outputPath =
|
const outputPath =
|
||||||
project.targets[`${options.buildTarget}`]?.options.outputPath;
|
project.targets[`${options.buildTarget}`]?.options.outputPath;
|
||||||
generateFiles(tree, joinPathFragments(__dirname, './files'), project.root, {
|
generateFiles(tree, join(__dirname, './files'), project.root, {
|
||||||
tmpl: '',
|
tmpl: '',
|
||||||
app: project.sourceRoot,
|
app: project.sourceRoot,
|
||||||
buildLocation: outputPath,
|
buildLocation: outputPath,
|
||||||
|
|||||||
@ -5,14 +5,16 @@ function removeWindowsDriveLetter(osSpecificPath: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Coverts an os specific path to a unix style path
|
* Coverts an os specific path to a unix style path. Use this when writing paths to config files.
|
||||||
|
* This should not be used to read files on disk because of the removal of Windows drive letters.
|
||||||
*/
|
*/
|
||||||
export function normalizePath(osSpecificPath: string): string {
|
export function normalizePath(osSpecificPath: string): string {
|
||||||
return removeWindowsDriveLetter(osSpecificPath).split('\\').join('/');
|
return removeWindowsDriveLetter(osSpecificPath).split('\\').join('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalized path fragments and joins them
|
* Normalized path fragments and joins them. Use this when writing paths to config files.
|
||||||
|
* This should not be used to read files on disk because of the removal of Windows drive letters.
|
||||||
*/
|
*/
|
||||||
export function joinPathFragments(...fragments: string[]): string {
|
export function joinPathFragments(...fragments: string[]): string {
|
||||||
return normalizePath(path.join(...fragments));
|
return normalizePath(path.join(...fragments));
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import {
|
|||||||
import { NormalizedSchema, normalizeOptions } from './lib/normalize-options';
|
import { NormalizedSchema, normalizeOptions } from './lib/normalize-options';
|
||||||
import { addImport } from './lib/add-import';
|
import { addImport } from './lib/add-import';
|
||||||
import { ensureTypescript } from '@nx/js/src/utils/typescript/ensure-typescript';
|
import { ensureTypescript } from '@nx/js/src/utils/typescript/ensure-typescript';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
export async function reactNativeComponentGenerator(
|
export async function reactNativeComponentGenerator(
|
||||||
host: Tree,
|
host: Tree,
|
||||||
@ -31,7 +32,7 @@ function createComponentFiles(host: Tree, options: NormalizedSchema) {
|
|||||||
options.directory
|
options.directory
|
||||||
);
|
);
|
||||||
|
|
||||||
generateFiles(host, joinPathFragments(__dirname, './files'), componentDir, {
|
generateFiles(host, join(__dirname, './files'), componentDir, {
|
||||||
...options,
|
...options,
|
||||||
tmpl: '',
|
tmpl: '',
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import {
|
|||||||
readProjectConfiguration,
|
readProjectConfiguration,
|
||||||
Tree,
|
Tree,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { basename, dirname, extname, relative } from 'path';
|
import { basename, dirname, extname, join, relative } from 'path';
|
||||||
import {
|
import {
|
||||||
findExportDeclarationsForJsx,
|
findExportDeclarationsForJsx,
|
||||||
getComponentNode,
|
getComponentNode,
|
||||||
@ -100,7 +100,7 @@ function generateSpecsForComponents(tree: Tree, filePath: string) {
|
|||||||
const namedImportStatement =
|
const namedImportStatement =
|
||||||
namedImports.length > 0 ? `, { ${namedImports} }` : '';
|
namedImports.length > 0 ? `, { ${namedImports} }` : '';
|
||||||
|
|
||||||
generateFiles(tree, joinPathFragments(__dirname, 'files'), componentDir, {
|
generateFiles(tree, join(__dirname, 'files'), componentDir, {
|
||||||
fileName,
|
fileName,
|
||||||
components,
|
components,
|
||||||
importStatement: defaultExport
|
importStatement: defaultExport
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import { getComponentTests } from './get-component-tests';
|
|||||||
import { NormalizedSchema } from './noramlized-schema';
|
import { NormalizedSchema } from './noramlized-schema';
|
||||||
import { Schema } from './schema';
|
import { Schema } from './schema';
|
||||||
import { ensureTypescript } from '@nx/js/src/utils/typescript/ensure-typescript';
|
import { ensureTypescript } from '@nx/js/src/utils/typescript/ensure-typescript';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
export async function componentGenerator(host: Tree, schema: Schema) {
|
export async function componentGenerator(host: Tree, schema: Schema) {
|
||||||
const options = await normalizeOptions(host, schema);
|
const options = await normalizeOptions(host, schema);
|
||||||
@ -58,7 +59,7 @@ function createComponentFiles(host: Tree, options: NormalizedSchema) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const componentTests = getComponentTests(options);
|
const componentTests = getComponentTests(options);
|
||||||
generateFiles(host, joinPathFragments(__dirname, './files'), componentDir, {
|
generateFiles(host, join(__dirname, './files'), componentDir, {
|
||||||
...options,
|
...options,
|
||||||
componentTests,
|
componentTests,
|
||||||
inSourceVitestTests: getInSourceVitestTestsTemplate(componentTests),
|
inSourceVitestTests: getInSourceVitestTestsTemplate(componentTests),
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import {
|
|||||||
import { Schema } from './schema';
|
import { Schema } from './schema';
|
||||||
import { addImport } from '../../utils/ast-utils';
|
import { addImport } from '../../utils/ast-utils';
|
||||||
import { ensureTypescript } from '@nx/js/src/utils/typescript/ensure-typescript';
|
import { ensureTypescript } from '@nx/js/src/utils/typescript/ensure-typescript';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
interface NormalizedSchema extends Schema {
|
interface NormalizedSchema extends Schema {
|
||||||
projectSourceRoot: string;
|
projectSourceRoot: string;
|
||||||
@ -38,7 +39,7 @@ function createFiles(host: Tree, options: NormalizedSchema) {
|
|||||||
options.directory
|
options.directory
|
||||||
);
|
);
|
||||||
|
|
||||||
generateFiles(host, joinPathFragments(__dirname, './files'), hookDir, {
|
generateFiles(host, join(__dirname, './files'), hookDir, {
|
||||||
...options,
|
...options,
|
||||||
tmpl: '',
|
tmpl: '',
|
||||||
});
|
});
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import {
|
|||||||
} from '../../utils/versions';
|
} from '../../utils/versions';
|
||||||
import { addStaticRouter } from '../../utils/ast-utils';
|
import { addStaticRouter } from '../../utils/ast-utils';
|
||||||
import { ensureTypescript } from '@nx/js/src/utils/typescript/ensure-typescript';
|
import { ensureTypescript } from '@nx/js/src/utils/typescript/ensure-typescript';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
let tsModule: typeof import('typescript');
|
let tsModule: typeof import('typescript');
|
||||||
|
|
||||||
@ -192,7 +193,7 @@ export async function setupSsrGenerator(tree: Tree, options: Schema) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
generateFiles(tree, joinPathFragments(__dirname, 'files'), projectRoot, {
|
generateFiles(tree, join(__dirname, 'files'), projectRoot, {
|
||||||
tmpl: '',
|
tmpl: '',
|
||||||
extraInclude:
|
extraInclude:
|
||||||
options.extraInclude?.length > 0
|
options.extraInclude?.length > 0
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import {
|
|||||||
import type { SetupTailwindOptions } from './schema';
|
import type { SetupTailwindOptions } from './schema';
|
||||||
import { addTailwindStyleImports } from './lib/add-tailwind-style-imports';
|
import { addTailwindStyleImports } from './lib/add-tailwind-style-imports';
|
||||||
import { updateProject } from './lib/update-project';
|
import { updateProject } from './lib/update-project';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
export async function setupTailwindGenerator(
|
export async function setupTailwindGenerator(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
@ -36,7 +37,7 @@ export async function setupTailwindGenerator(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
generateFiles(tree, joinPathFragments(__dirname, './files'), project.root, {
|
generateFiles(tree, join(__dirname, './files'), project.root, {
|
||||||
tmpl: '',
|
tmpl: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -108,7 +108,7 @@ function addBaseUrlToCypressConfig(tree: Tree, projectName: string) {
|
|||||||
} else if (tree.exists(cypressTs)) {
|
} else if (tree.exists(cypressTs)) {
|
||||||
// cypress >= v10
|
// cypress >= v10
|
||||||
tree.delete(cypressTs);
|
tree.delete(cypressTs);
|
||||||
generateFiles(tree, joinPathFragments(__dirname, 'files'), projectRoot, {
|
generateFiles(tree, join(__dirname, 'files'), projectRoot, {
|
||||||
tpl: '',
|
tpl: '',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -686,7 +686,7 @@ export function logResult(
|
|||||||
color: 'green',
|
color: 'green',
|
||||||
});
|
});
|
||||||
|
|
||||||
generateFiles(tree, joinPathFragments(__dirname, 'files'), '.', {
|
generateFiles(tree, join(__dirname, 'files'), '.', {
|
||||||
tmpl: '',
|
tmpl: '',
|
||||||
successfulProjects: Object.entries(
|
successfulProjects: Object.entries(
|
||||||
migrationSummary?.successfulProjects
|
migrationSummary?.successfulProjects
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import {
|
|||||||
} from '../../utils/versions';
|
} from '../../utils/versions';
|
||||||
|
|
||||||
import { addTsLibDependencies } from '@nx/js';
|
import { addTsLibDependencies } from '@nx/js';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
export async function vitestGenerator(
|
export async function vitestGenerator(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
@ -141,7 +142,7 @@ function createFiles(
|
|||||||
options: VitestGeneratorSchema,
|
options: VitestGeneratorSchema,
|
||||||
projectRoot: string
|
projectRoot: string
|
||||||
) {
|
) {
|
||||||
generateFiles(tree, joinPathFragments(__dirname, 'files'), projectRoot, {
|
generateFiles(tree, join(__dirname, 'files'), projectRoot, {
|
||||||
tmpl: '',
|
tmpl: '',
|
||||||
...options,
|
...options,
|
||||||
projectRoot,
|
projectRoot,
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import {
|
|||||||
writeJson,
|
writeJson,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { deduceDefaultBase } from '../../utilities/default-base';
|
import { deduceDefaultBase } from '../../utilities/default-base';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
export interface Schema {
|
export interface Schema {
|
||||||
name: string;
|
name: string;
|
||||||
@ -32,7 +33,7 @@ export async function ciWorkflowGenerator(host: Tree, schema: Schema) {
|
|||||||
writeJson(host, 'nx.json', appendOriginPrefix(nxJson));
|
writeJson(host, 'nx.json', appendOriginPrefix(nxJson));
|
||||||
}
|
}
|
||||||
|
|
||||||
generateFiles(host, joinPathFragments(__dirname, 'files', ci), '', options);
|
generateFiles(host, join(__dirname, 'files', ci), '', options);
|
||||||
await formatFiles(host);
|
await formatFiles(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user